Skip to content

Commit 7ed3399

Browse files
Changed the name of the option that is used to disable automatic reference handling.
1 parent 9bcea63 commit 7ed3399

File tree

8 files changed

+32
-84
lines changed

8 files changed

+32
-84
lines changed

substratevm/mx.substratevm/mx_substratevm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,9 +991,9 @@ def _native_image_launcher_extra_jvm_args():
991991
'-H:-DeleteLocalSymbols',
992992

993993

994-
# No VM-internal threads may be spawned for libgraal and the reference handler is executed manually.
994+
# No VM-internal threads may be spawned for libgraal and the reference handling is executed manually.
995995
'-H:-AllowVMInternalThreads',
996-
'-R:ReferenceHandlerMode=0',
996+
'-R:-AutomaticReferenceHandling',
997997
],
998998
),
999999
],

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/IsolateArgumentParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
*/
5757
public class IsolateArgumentParser {
5858
private static final RuntimeOptionKey<?>[] OPTIONS = {SubstrateGCOptions.MinHeapSize, SubstrateGCOptions.MaxHeapSize, SubstrateGCOptions.MaxNewSize,
59-
SubstrateOptions.ConcealedOptions.ReferenceHandlerMode};
59+
SubstrateOptions.ConcealedOptions.UseReferenceHandlerThread, SubstrateOptions.ConcealedOptions.AutomaticReferenceHandling};
6060
private static final int OPTION_COUNT = OPTIONS.length;
6161
private static final CGlobalData<CCharPointer> OPTION_NAMES = CGlobalDataFactory.createBytes(IsolateArgumentParser::createOptionNames);
6262
private static final CGlobalData<CIntPointer> OPTION_NAME_POSITIONS = CGlobalDataFactory.createBytes(IsolateArgumentParser::createOptionNamePosition);

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -572,28 +572,12 @@ public Boolean getValue(OptionValues values) {
572572
public static final HostedOptionKey<Boolean> UseDedicatedVMOperationThread = new HostedOptionKey<>(false);
573573

574574
/** Use {@link ReferenceHandler#useDedicatedThread()} instead. */
575-
@Option(help = "Determines how reference handling is done. " +
576-
"0 - reference handling can only be executed manually, " +
577-
"1 - reference handling is done in a dedicated reference handler thread, " +
578-
"2 - (deprecated) reference handling is done in regular Java threads.", type = OptionType.Expert) //
579-
public static final RuntimeOptionKey<Integer> ReferenceHandlerMode = new ImmutableRuntimeOptionKey<>(null) {
580-
@Override
581-
public Integer getValueOrDefault(UnmodifiableEconomicMap<OptionKey<?>, Object> values) {
582-
if (!values.containsKey(this)) {
583-
if (AllowVMInternalThreads.getValueOrDefault(values)) {
584-
return com.oracle.svm.core.heap.ReferenceHandlerMode.UseDedicatedThread;
585-
} else {
586-
return com.oracle.svm.core.heap.ReferenceHandlerMode.UseRegularJavaThreads;
587-
}
588-
}
589-
return super.getValueOrDefault(values);
590-
}
575+
@Option(help = "Populate reference queues in a separate thread rather than after a garbage collection.", type = OptionType.Expert) //
576+
public static final RuntimeOptionKey<Boolean> UseReferenceHandlerThread = new ImmutableRuntimeOptionKey<>(true);
591577

592-
@Override
593-
public Integer getValue(OptionValues values) {
594-
return getValueOrDefault(values.getMap());
595-
}
596-
};
578+
/** Use {@link ReferenceHandler#isExecutedManually()} instead. */
579+
@Option(help = "Determines if the reference handling is executed automatically or manually.", type = OptionType.Expert) //
580+
public static final RuntimeOptionKey<Boolean> AutomaticReferenceHandling = new ImmutableRuntimeOptionKey<>(true);
597581
}
598582

599583
@Option(help = "Overwrites the available number of processors provided by the OS. Any value <= 0 means using the processor count from the OS.")//

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/Heap.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.graalvm.word.Pointer;
3939
import org.graalvm.word.UnsignedWord;
4040

41+
import com.oracle.svm.core.SubstrateOptions;
4142
import com.oracle.svm.core.annotate.Uninterruptible;
4243
import com.oracle.svm.core.hub.DynamicHub;
4344
import com.oracle.svm.core.hub.PredefinedClassesSupport;
@@ -199,10 +200,10 @@ public List<Class<?>> getLoadedClasses() {
199200

200201
/**
201202
* If the automatic reference handling is disabled (see
202-
* {@link ReferenceHandlerMode#ExecuteManually}), then this method can be called to do the
203-
* reference handling manually. On execution, the current thread will enqueue pending
204-
* {@link Reference}s into their corresponding {@link ReferenceQueue}s and it will execute
205-
* pending cleaners.
203+
* {@link SubstrateOptions.ConcealedOptions#AutomaticReferenceHandling}), then this method can
204+
* be called to do the reference handling manually. On execution, the current thread will
205+
* enqueue pending {@link Reference}s into their corresponding {@link ReferenceQueue}s and it
206+
* will execute pending cleaners.
206207
*
207208
* This method must not be called from within a VM operation as this could result in deadlocks.
208209
* Furthermore, it is up to the caller to ensure that this method is only called in places where

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/ReferenceHandler.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,23 @@
3535
public final class ReferenceHandler {
3636
public static boolean useDedicatedThread() {
3737
if (ReferenceHandlerThread.isSupported()) {
38-
int optionIndex = IsolateArgumentParser.getOptionIndex(SubstrateOptions.ConcealedOptions.ReferenceHandlerMode);
39-
return IsolateArgumentParser.getIntOptionValue(optionIndex) == ReferenceHandlerMode.UseDedicatedThread;
38+
int useReferenceHandlerThread = IsolateArgumentParser.getOptionIndex(SubstrateOptions.ConcealedOptions.UseReferenceHandlerThread);
39+
int automaticReferenceHandling = IsolateArgumentParser.getOptionIndex(SubstrateOptions.ConcealedOptions.AutomaticReferenceHandling);
40+
return IsolateArgumentParser.getBooleanOptionValue(useReferenceHandlerThread) && IsolateArgumentParser.getBooleanOptionValue(automaticReferenceHandling);
4041
}
4142
return false;
4243
}
4344

4445
public static boolean useRegularJavaThread() {
45-
int optionIndex = IsolateArgumentParser.getOptionIndex(SubstrateOptions.ConcealedOptions.ReferenceHandlerMode);
46-
return IsolateArgumentParser.getIntOptionValue(optionIndex) == ReferenceHandlerMode.UseRegularJavaThreads;
46+
int useReferenceHandlerThread = IsolateArgumentParser.getOptionIndex(SubstrateOptions.ConcealedOptions.UseReferenceHandlerThread);
47+
int automaticReferenceHandling = IsolateArgumentParser.getOptionIndex(SubstrateOptions.ConcealedOptions.AutomaticReferenceHandling);
48+
return (!ReferenceHandlerThread.isSupported() || !IsolateArgumentParser.getBooleanOptionValue(useReferenceHandlerThread)) &&
49+
IsolateArgumentParser.getBooleanOptionValue(automaticReferenceHandling);
4750
}
4851

4952
public static boolean isExecutedManually() {
50-
int optionIndex = IsolateArgumentParser.getOptionIndex(SubstrateOptions.ConcealedOptions.ReferenceHandlerMode);
51-
return IsolateArgumentParser.getIntOptionValue(optionIndex) == ReferenceHandlerMode.ExecuteManually;
53+
int automaticReferenceHandling = IsolateArgumentParser.getOptionIndex(SubstrateOptions.ConcealedOptions.AutomaticReferenceHandling);
54+
return !IsolateArgumentParser.getBooleanOptionValue(automaticReferenceHandling);
5255
}
5356

5457
public static void processPendingReferencesInRegularThread() {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/ReferenceHandlerMode.java

Lines changed: 0 additions & 46 deletions
This file was deleted.

substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalEntryPoints.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.Arrays;
3333
import java.util.Map;
3434

35+
import com.oracle.svm.core.heap.Heap;
3536
import org.graalvm.collections.EconomicMap;
3637
import org.graalvm.compiler.debug.GlobalMetrics;
3738
import org.graalvm.compiler.hotspot.CompilationContext;
@@ -248,6 +249,12 @@ private static long compileMethod(PointerBase jniEnv,
248249
UNSAFE.putInt(stackTraceAddress, length);
249250
UNSAFE.copyMemory(stackTrace, ARRAY_BYTE_BASE_OFFSET, null, stackTraceAddress + Integer.BYTES, length);
250251
return 0L;
252+
} finally {
253+
/*
254+
* libgraal doesn't use a dedicated reference handler thread, so we trigger the
255+
* reference handling manually when a compilation finishes.
256+
*/
257+
Heap.getHeap().doReferenceHandling();
251258
}
252259
}
253260
}

substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/isolated/IsolatedGraalUtils.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.lang.reflect.Array;
2828
import java.nio.ByteBuffer;
2929

30-
import com.oracle.svm.core.heap.ReferenceHandlerMode;
3130
import org.graalvm.collections.EconomicMap;
3231
import org.graalvm.collections.UnmodifiableMapCursor;
3332
import org.graalvm.compiler.code.CompilationResult;
@@ -68,7 +67,7 @@ public static CompilerIsolateThread createCompilationIsolate() {
6867
builder.reservedAddressSpaceSize(WordFactory.signed(addressSpaceSize));
6968
}
7069
// Compilation isolates do the reference handling manually to avoid the extra thread.
71-
builder.appendArgument(getOptionString(SubstrateOptions.ConcealedOptions.ReferenceHandlerMode, ReferenceHandlerMode.ExecuteManually));
70+
builder.appendArgument(getOptionString(SubstrateOptions.ConcealedOptions.AutomaticReferenceHandling, false));
7271
CreateIsolateParameters params = builder.build();
7372
CompilerIsolateThread isolate = (CompilerIsolateThread) Isolates.createIsolate(params);
7473
initializeCompilationIsolate(isolate);
@@ -193,8 +192,8 @@ public static void applyClientRuntimeOptionValues(PointerBase encodedOptionsPtr,
193192
RuntimeOptionValues.singleton().update(options);
194193
}
195194

196-
private static String getOptionString(RuntimeOptionKey<Integer> option, int value) {
197-
return "-XX:" + option.getName() + "=" + value;
195+
private static String getOptionString(RuntimeOptionKey<Boolean> option, boolean value) {
196+
return "-XX:" + (value ? "+" : "-") + option.getName();
198197
}
199198

200199
private IsolatedGraalUtils() {

0 commit comments

Comments
 (0)