Skip to content

Commit

Permalink
Fix FrameWithoutBoxing.ASSERTIONS_ENABLED state in native-image
Browse files Browse the repository at this point in the history
  • Loading branch information
gilles-duboscq committed Mar 30, 2023
1 parent 128b2fe commit 21161ad
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import org.graalvm.home.impl.DefaultHomeFinder;
import org.graalvm.nativeimage.AnnotationAccess;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.hosted.FieldValueTransformer;
import org.graalvm.nativeimage.hosted.RuntimeClassInitialization;
import org.graalvm.nativeimage.hosted.RuntimeReflection;
import org.graalvm.nativeimage.impl.ConfigurationCondition;
Expand All @@ -90,6 +91,7 @@
import com.oracle.svm.core.BuildArtifacts;
import com.oracle.svm.core.NeverInline;
import com.oracle.svm.core.ParsingReason;
import com.oracle.svm.core.RuntimeAssertionsSupport;
import com.oracle.svm.core.annotate.Alias;
import com.oracle.svm.core.annotate.AnnotateOriginal;
import com.oracle.svm.core.annotate.Delete;
Expand Down Expand Up @@ -456,6 +458,22 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
if (needsAllEncodings) {
ImageSingletons.lookup(RuntimeResourceSupport.class).addResources(ConfigurationCondition.alwaysTrue(), "org/graalvm/shadowed/org/jcodings/tables/.*bin$");
}
Class<?> frameClass = config.findClassByName("com.oracle.truffle.api.impl.FrameWithoutBoxing");
config.registerFieldValueTransformer(config.findField(frameClass, "ASSERTIONS_ENABLED"), new AssertionStatusFieldTransformer(frameClass));
}

private static class AssertionStatusFieldTransformer implements FieldValueTransformer {
private final Class<?> clazz;

public AssertionStatusFieldTransformer(Class<?> clazz) {
this.clazz = clazz;
}

@Override
public Object transform(Object receiver, Object originalValue) {
boolean assertionsEnabled = RuntimeAssertionsSupport.singleton().desiredAssertionStatus(clazz);
return assertionsEnabled;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ private static Unsafe initUnsafe() {
}

public FrameWithoutBoxing(FrameDescriptor descriptor, Object[] arguments) {
// Make sure the state of ASSERTIONS_ENABLED matches with
// the state of assertions at runtime
// This can be an issue since this class is initialized at build time in native-image
assert ASSERTIONS_ENABLED;
/*
* Important note: Make sure this frame reference does not escape to any other method in
* this constructor, otherwise the immutable invariant for frame final fields may not hold.
Expand Down

0 comments on commit 21161ad

Please sign in to comment.