use of com.oracle.truffle.api.instrumentation.ContextsListener in project graal by oracle.
the class AllocatedBytesInstrument method onCreate.
@Override
protected synchronized void onCreate(Env env) {
env.getInstrumenter().attachContextsListener(new ContextsListener() {
@Override
public void onContextCreated(TruffleContext c) {
}
@Override
public void onLanguageContextCreated(TruffleContext context, LanguageInfo language) {
}
@Override
public void onLanguageContextInitialized(TruffleContext context, LanguageInfo language) {
try {
InteropLibrary interopLibrary = InteropLibrary.getUncached();
Object polyglotBindings = env.getPolyglotBindings();
if (!interopLibrary.isMemberExisting(polyglotBindings, GET_ALLOCATED_BYTES)) {
interopLibrary.writeMember(polyglotBindings, GET_ALLOCATED_BYTES, new GetAllocatedBytesFunction());
}
} catch (UnsupportedMessageException | UnknownIdentifierException | UnsupportedTypeException e) {
throw CompilerDirectives.shouldNotReachHere("Exception during interop.");
}
}
@Override
public void onLanguageContextFinalized(TruffleContext context, LanguageInfo language) {
}
@Override
public void onLanguageContextDisposed(TruffleContext context, LanguageInfo language) {
}
@Override
public void onContextClosed(TruffleContext context) {
}
}, true);
env.getInstrumenter().attachThreadsListener(new ThreadsListener() {
@Override
public void onThreadInitialized(TruffleContext context, Thread thread) {
synchronized (AllocatedBytesInstrument.this) {
threads.add(thread);
}
}
@Override
public void onThreadDisposed(TruffleContext context, Thread thread) {
synchronized (AllocatedBytesInstrument.this) {
threads.remove(thread);
}
}
}, true);
}
Aggregations