Skip to content

Commit e59968c

Browse files
committed
[GR-34509] Early argument parsing, immutable runtime options, and prologue/epilogue changes.
PullRequest: graal/10133
2 parents 6234547 + c997e05 commit e59968c

File tree

95 files changed

+1645
-680
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1645
-680
lines changed

compiler/src/org.graalvm.compiler.options/src/org/graalvm/compiler/options/ModifiableOptionValues.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public void update(OptionKey<?> key, Object value) {
7575
newMap.put(key, encodeNull(value));
7676
}
7777
} while (!v.compareAndSet(expect, newMap));
78+
79+
key.afterValueUpdate();
7880
}
7981

8082
/**

compiler/src/org.graalvm.compiler.options/src/org/graalvm/compiler/options/OptionKey.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,10 @@ public void putIfAbsent(EconomicMap<OptionKey<?>, Object> values, Object v) {
189189
*/
190190
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, T oldValue, T newValue) {
191191
}
192+
193+
/**
194+
* Notifies this object after a value associated with this key was set or updated.
195+
*/
196+
protected void afterValueUpdate() {
197+
}
192198
}

sdk/src/org.graalvm.nativeimage/snapshot.sigtest

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ CLSS public abstract interface !annotation org.graalvm.nativeimage.c.function.CE
460460
anno 0 java.lang.annotation.Target(java.lang.annotation.ElementType[] value=[METHOD])
461461
innr public abstract interface static !annotation IsolateContext
462462
innr public abstract interface static !annotation IsolateThreadContext
463+
innr public abstract interface static ExceptionHandler
463464
innr public final static !enum Builtin
464465
innr public final static AlwaysIncluded
465466
innr public final static FatalExceptionHandler
@@ -490,8 +491,12 @@ meth public static org.graalvm.nativeimage.c.function.CEntryPoint$Builtin valueO
490491
meth public static org.graalvm.nativeimage.c.function.CEntryPoint$Builtin[] values()
491492
supr java.lang.Enum<org.graalvm.nativeimage.c.function.CEntryPoint$Builtin>
492493

494+
CLSS public abstract interface static org.graalvm.nativeimage.c.function.CEntryPoint$ExceptionHandler
495+
outer org.graalvm.nativeimage.c.function.CEntryPoint
496+
493497
CLSS public final static org.graalvm.nativeimage.c.function.CEntryPoint$FatalExceptionHandler
494498
outer org.graalvm.nativeimage.c.function.CEntryPoint
499+
intf org.graalvm.nativeimage.c.function.CEntryPoint$ExceptionHandler
495500
supr java.lang.Object
496501

497502
CLSS public abstract interface static !annotation org.graalvm.nativeimage.c.function.CEntryPoint$IsolateContext
@@ -914,7 +919,6 @@ meth public !varargs static void initializeAtBuildTime(java.lang.String[])
914919
meth public !varargs static void initializeAtRunTime(java.lang.Class<?>[])
915920
meth public !varargs static void initializeAtRunTime(java.lang.String[])
916921
supr java.lang.Object
917-
hfds MESSAGE
918922

919923
CLSS public final org.graalvm.nativeimage.hosted.RuntimeReflection
920924
meth public !varargs static void register(boolean,boolean,java.lang.reflect.Field[])
@@ -923,8 +927,8 @@ meth public !varargs static void register(boolean,java.lang.reflect.Field[])
923927
anno 0 java.lang.Deprecated()
924928
meth public !varargs static void register(java.lang.Class<?>[])
925929
meth public !varargs static void register(java.lang.reflect.Executable[])
926-
meth public !varargs static void registerAsQueried(java.lang.reflect.Executable[])
927930
meth public !varargs static void register(java.lang.reflect.Field[])
931+
meth public !varargs static void registerAsQueried(java.lang.reflect.Executable[])
928932
meth public !varargs static void registerForReflectiveInstantiation(java.lang.Class<?>[])
929933
supr java.lang.Object
930934

sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/VMRuntime.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -51,7 +51,6 @@
5151
* @since 19.0
5252
*/
5353
public final class VMRuntime {
54-
5554
/**
5655
* Initializes the VM: Runs all startup hooks that were registered during image building.
5756
* Startup hooks usually depend on option values, so it is recommended (but not required) that
@@ -63,7 +62,7 @@ public final class VMRuntime {
6362
* @since 19.0
6463
*/
6564
public static void initialize() {
66-
ImageSingletons.lookup(VMRuntimeSupport.class).executeStartupHooks();
65+
ImageSingletons.lookup(VMRuntimeSupport.class).initialize();
6766
}
6867

6968
/**

sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/c/function/CEntryPoint.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
*
120120
* @since 19.0
121121
*/
122-
final class FatalExceptionHandler {
122+
final class FatalExceptionHandler implements ExceptionHandler {
123123
private FatalExceptionHandler() {
124124
}
125125
}
@@ -284,4 +284,12 @@ enum Builtin {
284284
@Target(ElementType.PARAMETER)
285285
@interface IsolateContext {
286286
}
287+
288+
/**
289+
* Marker interface for all {@link CEntryPoint#exceptionHandler() exception handler} classes.
290+
*
291+
* @since 22.0
292+
*/
293+
interface ExceptionHandler {
294+
}
287295
}

sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/VMRuntimeSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -42,7 +42,7 @@
4242

4343
public interface VMRuntimeSupport {
4444

45-
void executeStartupHooks();
45+
void initialize();
4646

4747
void shutdown();
4848

substratevm/mx.substratevm/mx_substratevm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,9 @@ def _helloworld(native_image, javac_command, path, build_only, args):
665665
pout, pin = os.pipe()
666666
os.dup2(pin, 1) # connect stdout to pipe
667667
os.environ[envkey] = output
668-
lib.run_main(1, 'dummy') # call run_main of shared lib
668+
argc = 1
669+
argv = (ctypes.c_char_p * argc)(b'dummy')
670+
lib.run_main(argc, argv) # call run_main of shared lib
669671
call_stdout = os.read(pout, 120) # get pipe contents
670672
actual_output.append(call_stdout)
671673
os.dup2(stdout, 1) # restore original stdout

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/AbstractCollectionPolicy.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import com.oracle.svm.core.heap.PhysicalMemory;
3939
import com.oracle.svm.core.heap.ReferenceAccess;
4040
import com.oracle.svm.core.jdk.UninterruptibleUtils;
41-
import com.oracle.svm.core.option.RuntimeOptionValues;
4241
import com.oracle.svm.core.thread.VMOperation;
4342
import com.oracle.svm.core.util.UnsignedUtils;
4443
import com.oracle.svm.core.util.VMError;
@@ -277,7 +276,7 @@ protected SizeParameters computeSizeParameters(SizeParameters existing) {
277276
long optionMaxYoung = SubstrateGCOptions.MaxNewSize.getValue();
278277
if (optionMaxYoung > 0L) {
279278
maxYoung = WordFactory.unsigned(optionMaxYoung);
280-
} else if (HeapParameters.Options.MaximumYoungGenerationSizePercent.hasBeenSet(RuntimeOptionValues.singleton())) {
279+
} else if (HeapParameters.Options.MaximumYoungGenerationSizePercent.hasBeenSet()) {
281280
maxYoung = maxHeap.unsignedDivide(100).multiply(HeapParameters.getMaximumYoungGenerationSizePercent());
282281
} else {
283282
maxYoung = maxHeap.unsignedDivide(AbstractCollectionPolicy.NEW_RATIO + 1);

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/HeapChunkProvider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
import com.oracle.svm.core.FrameAccess;
3535
import com.oracle.svm.core.MemoryWalker;
36-
import com.oracle.svm.core.SubstrateGCOptions;
3736
import com.oracle.svm.core.SubstrateOptions;
3837
import com.oracle.svm.core.annotate.AlwaysInline;
3938
import com.oracle.svm.core.annotate.Uninterruptible;
@@ -146,7 +145,7 @@ void consumeAlignedChunks(AlignedHeader firstChunk, boolean keepAll) {
146145
} else {
147146
UnsignedWord freeListBytes = getBytesInUnusedChunks();
148147
UnsignedWord reserveBytes = GCImpl.getPolicy().getMaximumFreeAlignedChunksSize();
149-
UnsignedWord maxHeapFree = WordFactory.unsigned(SubstrateGCOptions.MaxHeapFree.getValue());
148+
UnsignedWord maxHeapFree = WordFactory.unsigned(HeapParameters.Options.MaxHeapFree.getValue());
150149
if (maxHeapFree.aboveThan(0)) {
151150
reserveBytes = UnsignedUtils.min(reserveBytes, maxHeapFree);
152151
}

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/HeapImpl.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
import java.util.ArrayList;
2929
import java.util.List;
3030

31-
import com.oracle.svm.core.SubstrateDiagnostics.DiagnosticThunkRegistry;
32-
import com.oracle.svm.core.SubstrateDiagnostics.ErrorContext;
33-
import com.oracle.svm.core.thread.VMThreads.SafepointBehavior;
3431
import org.graalvm.compiler.api.replacements.Fold;
3532
import org.graalvm.compiler.core.common.NumUtil;
3633
import org.graalvm.compiler.core.common.SuppressFBWarnings;
@@ -47,7 +44,10 @@
4744
import com.oracle.svm.core.MemoryWalker;
4845
import com.oracle.svm.core.SubstrateDiagnostics;
4946
import com.oracle.svm.core.SubstrateDiagnostics.DiagnosticThunk;
47+
import com.oracle.svm.core.SubstrateDiagnostics.DiagnosticThunkRegistry;
48+
import com.oracle.svm.core.SubstrateDiagnostics.ErrorContext;
5049
import com.oracle.svm.core.SubstrateOptions;
50+
import com.oracle.svm.core.SubstrateUtil;
5151
import com.oracle.svm.core.annotate.NeverInline;
5252
import com.oracle.svm.core.annotate.RestrictHeapAccess;
5353
import com.oracle.svm.core.annotate.Substitute;
@@ -74,12 +74,14 @@
7474
import com.oracle.svm.core.log.Log;
7575
import com.oracle.svm.core.nodes.CFunctionEpilogueNode;
7676
import com.oracle.svm.core.nodes.CFunctionPrologueNode;
77+
import com.oracle.svm.core.option.RuntimeOptionKey;
7778
import com.oracle.svm.core.os.CommittedMemoryProvider;
7879
import com.oracle.svm.core.snippets.KnownIntrinsics;
7980
import com.oracle.svm.core.thread.JavaThreads;
8081
import com.oracle.svm.core.thread.ThreadStatus;
8182
import com.oracle.svm.core.thread.VMOperation;
8283
import com.oracle.svm.core.thread.VMThreads;
84+
import com.oracle.svm.core.thread.VMThreads.SafepointBehavior;
8385
import com.oracle.svm.core.util.UnsignedUtils;
8486
import com.oracle.svm.core.util.UserError;
8587

@@ -641,8 +643,10 @@ public boolean printLocationInfo(Log log, UnsignedWord value, boolean allowJavaH
641643
}
642644

643645
@Override
644-
public void updateSizeParameters() {
645-
GCImpl.getPolicy().updateSizeParameters();
646+
public void optionValueChanged(RuntimeOptionKey<?> key) {
647+
if (!SubstrateUtil.HOSTED) {
648+
GCImpl.getPolicy().updateSizeParameters();
649+
}
646650
}
647651

648652
static Pointer getImageHeapStart() {
@@ -853,7 +857,7 @@ private long totalMemory() {
853857
@Substitute
854858
private long maxMemory() {
855859
PhysicalMemory.size(); // ensure physical memory size is set correctly and not estimated
856-
Heap.getHeap().updateSizeParameters();
860+
GCImpl.getPolicy().updateSizeParameters();
857861
return GCImpl.getPolicy().getMaximumHeapSize().rawValue();
858862
}
859863

0 commit comments

Comments
 (0)