Skip to content

Commit b077c83

Browse files
Add support for --sun-misc-unsafe-memory-access=
1 parent 9900223 commit b077c83

File tree

5 files changed

+34
-3
lines changed
  • espresso-shared/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile
  • espresso/src

5 files changed

+34
-3
lines changed

espresso-shared/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile/JavaVersion.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ public boolean java23OrEarlier() {
199199
return version <= 23;
200200
}
201201

202+
public boolean java23OrLater() {
203+
return version >= 23;
204+
}
205+
202206
public boolean java24OrEarlier() {
203207
return version <= 24;
204208
}

espresso/src/com.oracle.truffle.espresso.launcher/src/com/oracle/truffle/espresso/launcher/EspressoLauncher.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,13 @@ protected List<String> preprocessArguments(List<String> arguments, Map<String, S
328328
} else if (arg.startsWith("-Xshare:")) {
329329
String value = arg.substring("-Xshare:".length());
330330
espressoOptions.put("java.CDS", value);
331+
} else if (arg.startsWith("--sun-misc-unsafe-memory-access")) {
332+
String value = args.getValue(arg, "sun.misc.Unsafe memory access");
333+
espressoOptions.put("java.SunMiscUnsafeMemoryAccess", value);
331334
} else if (arg.startsWith("-XX:")) {
332335
handleXXArg(arg, unrecognized);
333-
} else
334-
// -Dsystem.property=value
335-
if (arg.startsWith("-D")) {
336+
} else if (arg.startsWith("-D")) {
337+
// -Dsystem.property=value
336338
String key = arg.substring("-D".length());
337339
int splitAt = key.indexOf("=");
338340
String value = "";

espresso/src/com.oracle.truffle.espresso.libjavavm/src/com/oracle/truffle/espresso/libjavavm/Arguments.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ public static int setupContext(Context.Builder builder, JNIJavaVMInitArgs args,
223223
} else if (optionString.startsWith("-Xshare:")) {
224224
String value = optionString.substring("-Xshare:".length());
225225
builder.option("java.CDS", value);
226+
} else if (optionString.startsWith("--sun-misc-unsafe-memory-access=")) {
227+
String value = optionString.substring("--sun-misc-unsafe-memory-access=".length());
228+
builder.option("java.SunMiscUnsafeMemoryAccess", value);
226229
} else if (optionString.startsWith("-XX:")) {
227230
handler.handleXXArg(optionString);
228231
} else if (optionString.startsWith("--help:")) {

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/EspressoOptions.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,20 @@ public enum XShareOption {
749749
usageSyntax = "<duration in ms>") //
750750
public static final OptionKey<Integer> ThreadRequestGracePeriod = new OptionKey<>(100);
751751

752+
public enum MemoryAccessOption {
753+
allow,
754+
warn,
755+
debug,
756+
deny,
757+
defaultValue // undocumented sentinel value
758+
}
759+
760+
@Option(help = "Allow or deny usage of unsupported API sun.misc.Unsafe", //
761+
category = OptionCategory.EXPERT, //
762+
stability = OptionStability.EXPERIMENTAL, //
763+
usageSyntax = "allow|warn|debug|deny") //
764+
public static final OptionKey<MemoryAccessOption> SunMiscUnsafeMemoryAccess = new OptionKey<>(MemoryAccessOption.defaultValue);
765+
752766
/**
753767
* Property used to force liveness analysis to also be applied by the interpreter. For testing
754768
* purpose only. Use a host property rather than an option. An option would slow interpreter

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/vm/VM.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
import com.oracle.truffle.api.source.SourceSection;
9090
import com.oracle.truffle.espresso.EspressoLanguage;
9191
import com.oracle.truffle.espresso.EspressoOptions;
92+
import com.oracle.truffle.espresso.EspressoOptions.MemoryAccessOption;
9293
import com.oracle.truffle.espresso.blocking.GuestInterruptedException;
9394
import com.oracle.truffle.espresso.cds.CDSSupport;
9495
import com.oracle.truffle.espresso.classfile.ClasspathEntry;
@@ -2545,6 +2546,13 @@ private PropertiesMap buildPropertiesMap() {
25452546
map.setPropertyIfExists("jdk.module.illegal.native.access", options.get(EspressoOptions.IllegalNativeAccess), "IllegalNativeAccess");
25462547
}
25472548

2549+
if (getJavaVersion().java23OrLater()) {
2550+
MemoryAccessOption memoryAccessOption = options.get(EspressoOptions.SunMiscUnsafeMemoryAccess);
2551+
if (memoryAccessOption != MemoryAccessOption.defaultValue) {
2552+
map.set("sun.misc.unsafe.memory.access", memoryAccessOption.name(), "SunMiscUnsafeMemoryAccess");
2553+
}
2554+
}
2555+
25482556
// Applications expect different formats e.g. 1.8 vs. 11
25492557
String specVersion = getJavaVersion().java8OrEarlier()
25502558
? "1." + getJavaVersion()

0 commit comments

Comments
 (0)