use of org.graalvm.polyglot.Instrument in project graal by oracle.
the class PolyglotEngineImpl method ensureClosed.
@Override
public synchronized void ensureClosed(boolean cancelIfExecuting, boolean ignoreCloseFailure) {
if (!closed) {
PolyglotContextImpl[] localContexts = contexts.toArray(new PolyglotContextImpl[0]);
/*
* Check ahead of time for open contexts to fail early and avoid closing only some
* contexts.
*/
if (!cancelIfExecuting && !ignoreCloseFailure) {
for (PolyglotContextImpl context : localContexts) {
synchronized (context) {
if (context.hasActiveOtherThread(false)) {
throw new IllegalStateException(String.format("One of the context instances is currently executing. " + "Set cancelIfExecuting to true to stop the execution on this thread."));
}
}
}
}
for (PolyglotContextImpl context : localContexts) {
try {
boolean closeCompleted = context.closeImpl(cancelIfExecuting, cancelIfExecuting);
if (!closeCompleted && !cancelIfExecuting && !ignoreCloseFailure) {
throw new IllegalStateException(String.format("One of the context instances is currently executing. " + "Set cancelIfExecuting to true to stop the execution on this thread."));
}
} catch (Throwable e) {
if (!ignoreCloseFailure) {
throw e;
}
}
}
if (cancelIfExecuting) {
getCancelHandler().waitForClosing(localContexts);
}
contexts.clear();
for (Instrument instrument : idToPublicInstrument.values()) {
PolyglotInstrument instrumentImpl = (PolyglotInstrument) getAPIAccess().getImpl(instrument);
try {
instrumentImpl.ensureClosed();
} catch (Throwable e) {
if (!ignoreCloseFailure) {
throw e;
}
}
}
for (PolyglotLanguage language : idToLanguage.values()) {
if (language.isInitialized()) {
language.requireProfile().notifyEngineDisposed();
}
}
ENGINES.remove(this);
closed = true;
}
}
Aggregations