Skip to content

Commit

Permalink
Translate encoded graphs referencing assumptions in the image heap.
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-hofer committed Apr 21, 2023
1 parent e477eb5 commit af4734e
Showing 1 changed file with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@
import org.graalvm.nativeimage.c.function.CEntryPoint;

import com.oracle.svm.core.deopt.SubstrateInstalledCode;
import com.oracle.svm.core.meta.SubstrateObjectConstant;
import com.oracle.svm.graal.isolated.ClientHandle;
import com.oracle.svm.graal.isolated.ClientIsolateThread;
import com.oracle.svm.graal.isolated.CompilerHandle;
import com.oracle.svm.graal.isolated.CompilerIsolateThread;
import com.oracle.svm.graal.isolated.ImageHeapObjects;
import com.oracle.svm.graal.isolated.ImageHeapRef;
import com.oracle.svm.graal.isolated.IsolatedCodeInstallBridge;
import com.oracle.svm.graal.isolated.IsolatedCompileClient;
import com.oracle.svm.graal.isolated.IsolatedCompileContext;
Expand All @@ -52,9 +55,22 @@

public final class IsolatedTruffleRuntimeSupport {
public static Consumer<OptimizedAssumptionDependency> registerOptimizedAssumptionDependency(JavaConstant optimizedAssumptionConstant) {
@SuppressWarnings("unchecked")
ClientHandle<OptimizedAssumption> assumptionHandle = (ClientHandle<OptimizedAssumption>) ((IsolatedObjectConstant) optimizedAssumptionConstant).getHandle();
ClientHandle<Consumer<OptimizedAssumptionDependency>> consumerHandle = registerOptimizedAssumptionDependency0(IsolatedCompileContext.get().getClient(), assumptionHandle);
ClientHandle<Consumer<OptimizedAssumptionDependency>> consumerHandle;
if (optimizedAssumptionConstant instanceof IsolatedObjectConstant) {
@SuppressWarnings("unchecked")
ClientHandle<OptimizedAssumption> assumptionHandle = (ClientHandle<OptimizedAssumption>) ((IsolatedObjectConstant) optimizedAssumptionConstant).getHandle();
consumerHandle = registerOptimizedAssumptionDependency0(IsolatedCompileContext.get().getClient(), assumptionHandle);
} else {
/*
* Assumptions can be image heap objects referenced by direct object constants in
* encoded graphs, so translate those to the object in the client isolate. This is in
* line with what we do elsewhere such as in IsolateAwareConstantReflectionProvider. As
* in those cases, it is crucial that such assumption constants are accessed only via
* the appropriate isolate-aware providers during compilation.
*/
ImageHeapRef<OptimizedAssumption> assumptionRef = ImageHeapObjects.ref(SubstrateObjectConstant.asObject(OptimizedAssumption.class, optimizedAssumptionConstant));
consumerHandle = registerImageHeapOptimizedAssumptionDependency0(IsolatedCompileContext.get().getClient(), assumptionRef);
}
if (consumerHandle.equal(IsolatedHandles.nullHandle())) {
return null;
}
Expand All @@ -76,6 +92,18 @@ private static ClientHandle<Consumer<OptimizedAssumptionDependency>> registerOpt
@SuppressWarnings("unused") ClientIsolateThread client, ClientHandle<OptimizedAssumption> assumptionHandle) {

OptimizedAssumption assumption = IsolatedCompileClient.get().unhand(assumptionHandle);
return registerOptimizedAssumptionDependency1(assumption);
}

@CEntryPoint(include = CEntryPoint.NotIncludedAutomatically.class, publishAs = CEntryPoint.Publish.NotPublished)
private static ClientHandle<Consumer<OptimizedAssumptionDependency>> registerImageHeapOptimizedAssumptionDependency0(
@SuppressWarnings("unused") ClientIsolateThread client, ImageHeapRef<OptimizedAssumption> assumptionRef) {

OptimizedAssumption assumption = ImageHeapObjects.deref(assumptionRef);
return registerOptimizedAssumptionDependency1(assumption);
}

private static ClientHandle<Consumer<OptimizedAssumptionDependency>> registerOptimizedAssumptionDependency1(OptimizedAssumption assumption) {
Consumer<OptimizedAssumptionDependency> observer = assumption.registerDependency();
return IsolatedCompileClient.get().hand(observer);
}
Expand Down

0 comments on commit af4734e

Please sign in to comment.