Skip to content

Commit

Permalink
[GR-48578] Backport of: Classpath isolation does not work with polygl…
Browse files Browse the repository at this point in the history
…ot isolate.

PullRequest: graal/15540
  • Loading branch information
tzezula committed Sep 12, 2023
2 parents 1ad3c3b + 732176f commit f03c3e7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,10 @@ public final AbstractPolyglotImpl getNext() {
return next;
}

public final AbstractPolyglotImpl getNextOrNull() {
return next;
}

public final void setIO(IOAccessor ioAccess) {
Objects.requireNonNull(ioAccess, "IOAccess must be non null.");
this.io = ioAccess;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,8 @@ public abstract <T, G> Iterator<T> mergeHostGuestFrames(Object polyglotEngine, S
public abstract TruffleFile getInternalResource(Object owner, String resourceId) throws IOException;

public abstract Collection<String> getResourceIds(String componentId);

public abstract void setIsolatePolyglot(AbstractPolyglotImpl instance);
}

public abstract static class LanguageSupport extends Support {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1988,7 +1988,12 @@ public Object installGuestToHostCodeCache(Object polyglotContextImpl, Object cac

@Override
public AutoCloseable createPolyglotThreadScope() {
return PolyglotImpl.findInstance().getRootImpl().createThreadScope();
AbstractPolyglotImpl impl = PolyglotImpl.findIsolatePolyglot();
if (impl != null) {
return impl.createThreadScope();
} else {
return null;
}
}

@Override
Expand Down Expand Up @@ -2117,6 +2122,11 @@ public Collection<String> getResourceIds(String componentId) {
}
throw new IllegalArgumentException(componentId);
}

@Override
public void setIsolatePolyglot(AbstractPolyglotImpl instance) {
PolyglotImpl.setIsolatePolyglot(instance);
}
}

abstract static class AbstractClassLoaderSupplier implements Supplier<ClassLoader> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public final class PolyglotImpl extends AbstractPolyglotImpl {
private PolyglotValueDispatch disconnectedBigIntegerHostValue;
private volatile Object defaultFileSystemContext;

private static volatile AbstractPolyglotImpl isolatePolyglot;

/**
* Internal method do not use.
*/
Expand Down Expand Up @@ -158,6 +160,16 @@ static PolyglotImpl findInstance() {
return (PolyglotImpl) polyglot;
}

static AbstractPolyglotImpl findIsolatePolyglot() {
return isolatePolyglot;
}

static void setIsolatePolyglot(AbstractPolyglotImpl instance) {
assert instance != null;
assert isolatePolyglot == null;
isolatePolyglot = instance;
}

PolyglotEngineImpl getPreinitializedEngine() {
return preInitializedEngineRef.get();
}
Expand All @@ -174,13 +186,21 @@ public void initialize() {
@Override
public Object initializeModuleToUnnamedAccess(Lookup unnamedLookup, Object unnamedAccess, Object unnamedAPIAccess, Object unnamedIOAccess, Object unnamedManagementAccess) {
ModuleToUnnamedBridge bridge = ModuleToUnnamedBridge.create(unnamedLookup, unnamedAccess, unnamedAPIAccess, unnamedIOAccess, unnamedManagementAccess);
setConstructors(Objects.requireNonNull(bridge.getAPIAccess()));
setIO(Objects.requireNonNull(bridge.getIOAccess()));
setMonitoring(Objects.requireNonNull(bridge.getManagementAccess()));
initialize();
AbstractPolyglotImpl impl = getRootImpl();
while (impl != null) {
initializeModuleToUnnamedBridge(impl, bridge);
impl = impl.getNextOrNull();
}
return bridge.getModuleAccess();
}

private static void initializeModuleToUnnamedBridge(AbstractPolyglotImpl impl, ModuleToUnnamedBridge bridge) {
impl.setConstructors(Objects.requireNonNull(bridge.getAPIAccess()));
impl.setIO(Objects.requireNonNull(bridge.getIOAccess()));
impl.setMonitoring(Objects.requireNonNull(bridge.getManagementAccess()));
impl.initialize();
}

@Override
public Object buildLimits(long statementLimit, Predicate<Object> statementLimitSourceFilter,
Consumer<Object> onLimit) {
Expand Down

0 comments on commit f03c3e7

Please sign in to comment.