Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement static field base and offset substitutions for Unsafe #3284

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.security.ProtectionDomain;
import java.util.function.Function;

import com.oracle.svm.core.StaticFieldsSupport;
import org.graalvm.compiler.nodes.extended.MembarNode;
import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
import org.graalvm.nativeimage.Platform;
Expand Down Expand Up @@ -206,14 +207,13 @@ public void ensureClassInitialized(Class<?> c) {
DynamicHub.fromClass(c).ensureInitialized();
}

@Substitute
private long staticFieldOffset(Field f) {
throw VMError.unsupportedFeature("Unsupported method of Unsafe");
}

@Substitute
private Object staticFieldBase(Field f) {
throw VMError.unsupportedFeature("Unsupported method of Unsafe");
if (f.getType().isPrimitive()) {
return StaticFieldsSupport.getStaticPrimitiveFields();
} else {
return StaticFieldsSupport.getStaticObjectFields();
}
}

@Substitute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public long objectFieldOffset(Target_java_lang_reflect_Field field) {
if (offset > 0) {
return offset;
}

throw VMError.unsupportedFeature("The offset of " + field + " is accessed without the field being first registered as unsafe accessed. " +
"Please register the field as unsafe accessed. You can do so with a reflection configuration that " +
"contains an entry for the field with the attribute \"allowUnsafeAccess\": true. Such a configuration " +
Expand All @@ -67,4 +68,9 @@ public long objectFieldOffset(Class<?> c, String name) {
throw new InternalError();
}
}

@Substitute
private long staticFieldOffset(Target_java_lang_reflect_Field f) {
return f.offset;
ivan-ristovic marked this conversation as resolved.
Show resolved Hide resolved
}
}