void createInstrument(Object vmObject, String[] expectedServices, OptionValues optionValues) { InstrumentClientInstrumenter instrumenter = ((InstrumentClientInstrumenter) instrumenterMap.get(vmObject)); instrumenter.env.options = optionValues; instrumenter.create(expectedServices); }
private boolean findType(String name, Class<?> type) { if (type == null) { return false; } if (type.getName().equals(name) || (type.getCanonicalName() != null && type.getCanonicalName().equals(name))) { return true; } if (findType(name, type.getSuperclass())) { return true; } for (Class<?> inter : type.getInterfaces()) { if (findType(name, inter)) { return true; } } return false; }
/** * Handles exceptions from non-language instrumentation code that must not be allowed to alter * guest language execution semantics. Normal response is to log and continue. */ @TruffleBoundary static void exceptionEventForClientInstrument(EventBinding.Source<?> b, String eventName, Throwable t) { assert !b.isLanguageBinding(); if (t instanceof ThreadDeath) { // Terminates guest language execution immediately throw (ThreadDeath) t; } final Object currentVm = AccessorInstrumentHandler.engineAccess().getCurrentVM(); if (b.getInstrumenter() instanceof EngineInstrumenter || (currentVm != null && AccessorInstrumentHandler.engineAccess().isInstrumentExceptionsAreThrown(currentVm))) { throw sthrow(RuntimeException.class, t); } // Exception is a failure in (non-language) instrumentation code; log and continue InstrumentClientInstrumenter instrumenter = (InstrumentClientInstrumenter) b.getInstrumenter(); Class<?> instrumentClass = instrumenter.getInstrumentClass(); String message = String.format("Event %s failed for instrument class %s and listener/factory %s.", // eventName, instrumentClass.getName(), b.getElement()); Exception exception = new Exception(message, t); PrintStream stream = new PrintStream(instrumenter.getEnv().err()); exception.printStackTrace(stream); }
/** * Handles exceptions from non-language instrumentation code that must not be allowed to alter * guest language execution semantics. Normal response is to log and continue. */ @TruffleBoundary static void exceptionEventForClientInstrument(EventBinding.Source<?> b, String eventName, Throwable t) { assert !b.isLanguageBinding(); if (t instanceof ThreadDeath) { // Terminates guest language execution immediately throw (ThreadDeath) t; } // Exception is a failure in (non-language) instrumentation code; log and continue InstrumentClientInstrumenter instrumenter = (InstrumentClientInstrumenter) b.getInstrumenter(); Class<?> instrumentClass = instrumenter.getInstrumentClass(); String message = String.format("Event %s failed for instrument class %s and listener/factory %s.", // eventName, instrumentClass.getName(), b.getElement()); Exception exception = new Exception(message, t); PrintStream stream = new PrintStream(instrumenter.getEnv().err()); exception.printStackTrace(stream); }
void create(String[] expectedServices) { if (TRACE) { trace("Create instrument %s class %s %n", instrument, instrumentClass); } try { services = env.onCreate(instrument); if (expectedServices != null && !TruffleOptions.AOT) { checkServices(expectedServices); } } catch (Throwable e) { failInstrumentInitialization(env, String.format("Failed calling onCreate of instrument class %s", instrumentClass.getName()), e); return; } if (TRACE) { trace("Created instrument %s class %s %n", instrument, instrumentClass); } }
private boolean findType(String name, Class<?> type) { if (type == null) { return false; } if (type.getName().equals(name) || (type.getCanonicalName() != null && type.getCanonicalName().equals(name))) { return true; } if (findType(name, type.getSuperclass())) { return true; } for (Class<?> inter : type.getInterfaces()) { if (findType(name, inter)) { return true; } } return false; }
void initializeInstrument(Object vmObject, Class<?> instrumentClass) { Env env = new Env(vmObject, out, err, in, messageInterceptor); env.instrumenter = new InstrumentClientInstrumenter(env, instrumentClass); if (TRACE) { trace("Initialize instrument class %s %n", instrumentClass); } try { env.instrumenter.instrument = (TruffleInstrument) instrumentClass.getDeclaredConstructor().newInstance(); } catch (Exception e) { failInstrumentInitialization(env, String.format("Failed to create new instrumenter class %s", instrumentClass.getName()), e); return; } if (TRACE) { trace("Initialized instrument %s class %s %n", env.instrumenter.instrument, instrumentClass); } addInstrumenter(vmObject, env.instrumenter); }
void initializeInstrument(Object vmObject, Class<?> instrumentClass) { Env env = new Env(vmObject, out, err, in); env.instrumenter = new InstrumentClientInstrumenter(env, instrumentClass); if (TRACE) { trace("Initialize instrument class %s %n", instrumentClass); } try { env.instrumenter.instrument = (TruffleInstrument) instrumentClass.newInstance(); } catch (InstantiationException | IllegalAccessException e) { failInstrumentInitialization(env, String.format("Failed to create new instrumenter class %s", instrumentClass.getName()), e); return; } if (TRACE) { trace("Initialized instrument %s class %s %n", env.instrumenter.instrument, instrumentClass); } addInstrumenter(vmObject, env.instrumenter); }
@Override public Set<Class<?>> queryTags(Node node) { return queryTagsImpl(node, null); }
@Override public Set<Class<?>> queryTags(Node node) { return queryTagsImpl(node, null); }
void create(String[] expectedServices) { if (TRACE) { trace("Create instrument %s class %s %n", instrument, instrumentClass); } services = env.onCreate(instrument); if (expectedServices != null && !TruffleOptions.AOT) { checkServices(expectedServices); } if (TRACE) { trace("Created instrument %s class %s %n", instrument, instrumentClass); } }
private boolean checkServices(String[] expectedServices) { LOOP: for (String name : expectedServices) { for (Object obj : services) { if (findType(name, obj.getClass())) { continue LOOP; } } failInstrumentInitialization(env, String.format("%s declares service %s but doesn't register it", instrumentClass.getName(), name), null); } return true; }
void createInstrument(Object vmObject, String[] expectedServices, OptionValues optionValues) { InstrumentClientInstrumenter instrumenter = ((InstrumentClientInstrumenter) instrumenterMap.get(vmObject)); instrumenter.env.options = optionValues; instrumenter.create(expectedServices); }
private boolean checkServices(String[] expectedServices) { LOOP: for (String name : expectedServices) { for (Object obj : services) { if (findType(name, obj.getClass())) { continue LOOP; } } failInstrumentInitialization(env, String.format("%s declares service %s but doesn't register it", instrumentClass.getName(), name), null); } return true; }