boolean dispose() { assert Thread.holdsLock(context); Env localEnv = this.env; if (localEnv != null) { if (!activePolyglotThreads.isEmpty()) { throw new AssertionError("The language did not complete all polyglot threads but should have: " + activePolyglotThreads); } for (PolyglotThreadInfo threadInfo : context.getSeenThreads().values()) { assert threadInfo.thread != null; if (threadInfo.isPolyglotThread(context)) { // polyglot threads need to be cleaned up by the language continue; } LANGUAGE.disposeThread(localEnv, threadInfo.thread); } LANGUAGE.dispose(localEnv); env = null; return true; } return false; }
void leaveThread(Object prev, PolyglotThread thread) { assert Thread.currentThread() == thread; synchronized (context) { Map<Thread, PolyglotThreadInfo> seenThreads = context.getSeenThreads(); PolyglotThreadInfo info = seenThreads.get(thread); if (info == null) { // already disposed return; } for (PolyglotLanguageContext languageContext : context.contexts) { if (languageContext.isInitialized()) { LANGUAGE.disposeThread(languageContext.env, thread); } } activePolyglotThreads.remove(thread); context.leave(prev); seenThreads.remove(thread); } VMAccessor.INSTRUMENT.notifyThreadFinished(context.engine, context.truffleContext, thread); }
boolean dispose() { assert Thread.holdsLock(context); Env localEnv = this.env; if (localEnv != null) { if (!lazy.activePolyglotThreads.isEmpty()) { throw new AssertionError("The language did not complete all polyglot threads but should have: " + lazy.activePolyglotThreads); } for (PolyglotThreadInfo threadInfo : context.getSeenThreads().values()) { assert threadInfo.thread != null; if (threadInfo.isPolyglotThread(context)) { // polyglot threads need to be cleaned up by the language continue; } LANGUAGE.disposeThread(localEnv, threadInfo.thread); } LANGUAGE.dispose(localEnv); language.freeInstance(lazy.languageInstance); return true; } return false; }
void leaveThread(Object prev, PolyglotThread thread) { assert isInitialized(); assert Thread.currentThread() == thread; synchronized (context) { Map<Thread, PolyglotThreadInfo> seenThreads = context.getSeenThreads(); PolyglotThreadInfo info = seenThreads.get(thread); if (info == null) { // already disposed return; } for (PolyglotLanguageContext languageContext : context.contexts) { if (languageContext.isInitialized()) { LANGUAGE.disposeThread(languageContext.env, thread); } } lazy.activePolyglotThreads.remove(thread); context.leave(prev); seenThreads.remove(thread); } VMAccessor.INSTRUMENT.notifyThreadFinished(context.engine, context.truffleContext, thread); }