Skip to content

Commit 5a24737

Browse files
[GR-70171] Add common infrastructure for native GCs such as G1.
PullRequest: graal/22377
2 parents a87582b + 8b54a79 commit 5a24737

File tree

28 files changed

+2364
-29
lines changed

28 files changed

+2364
-29
lines changed

substratevm/mx.substratevm/mx_substratevm_namespace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
ignore_files = {"copy_x86.hpp", "copy_aarch64.hpp", "osThread_linux.hpp"}
4141
ignore_includes = {"CPU_HEADER(copy)", "OS_HEADER(osThread)"}
4242

43-
files_with_cpp_guard = {"sharedGCStructs.hpp"}
43+
files_with_cpp_guard = {"sharedGCStructs.h", "g1GCStructs.h"}
4444

4545
SVM_NAMESPACE = "svm_namespace"
4646

substratevm/mx.substratevm/suite.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,6 +2104,7 @@
21042104
"dependency:com.oracle.svm.native.jvm.posix/*",
21052105
"dependency:com.oracle.svm.native.libcontainer/*",
21062106
"file:debug/include",
2107+
"file:src/com.oracle.svm.core/src/com/oracle/svm/core/gc/shared/include",
21072108
],
21082109
},
21092110
},

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public String getName() {
153153
}
154154

155155
@Override
156+
@Platforms(Platform.HOSTED_ONLY.class)
156157
public String getDefaultMaxHeapSize() {
157158
return String.format("%s%% of RAM", SerialAndEpsilonGCOptions.MaximumHeapSizePercent.getValue());
158159
}

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ public HostedOptionKey<ReplacingLocatableMultiOptionValue.DelimitedString> multi
588588

589589
@Option(help = "Please use '--gc=*' instead. Possible values are listed with '--help'.")//
590590
public static final HostedOptionKey<ReplacingLocatableMultiOptionValue.DelimitedString> SupportedGCs = new HostedOptionKey<>(
591-
ReplacingLocatableMultiOptionValue.DelimitedString.buildWithCommaDelimiter(GCOptionValue.SERIAL.getValue())) {
591+
ReplacingLocatableMultiOptionValue.DelimitedString.buildWithCommaDelimiter(GCOptionValue.Serial.getValue())) {
592592
@Override
593593
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, ReplacingLocatableMultiOptionValue.DelimitedString oldValue,
594594
ReplacingLocatableMultiOptionValue.DelimitedString newValue) {
@@ -602,17 +602,16 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Replacing
602602

603603
super.onValueUpdate(values, oldValue, newValue);
604604
}
605-
606605
};
607606

608607
@Fold
609608
public static boolean useSerialGC() {
610-
return !SubstrateOptions.SupportedGCs.hasBeenSet() || SubstrateOptions.SupportedGCs.getValue().contains(GCOptionValue.SERIAL.getValue());
609+
return !SubstrateOptions.SupportedGCs.hasBeenSet() || SubstrateOptions.SupportedGCs.getValue().contains(GCOptionValue.Serial.getValue());
611610
}
612611

613612
@Fold
614613
public static boolean useEpsilonGC() {
615-
return SubstrateOptions.SupportedGCs.getValue().contains(GCOptionValue.EPSILON.getValue());
614+
return SubstrateOptions.SupportedGCs.getValue().contains(GCOptionValue.Epsilon.getValue());
616615
}
617616

618617
@Fold
@@ -629,9 +628,9 @@ public static class DeprecatedOptions {
629628
@Override
630629
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean oldValue, Boolean newValue) {
631630
if (newValue) {
632-
SubstrateOptions.SupportedGCs.update(values, ReplacingLocatableMultiOptionValue.DelimitedString.buildWithCommaDelimiter(GCOptionValue.SERIAL.getValue()));
631+
SubstrateOptions.SupportedGCs.update(values, ReplacingLocatableMultiOptionValue.DelimitedString.buildWithCommaDelimiter(GCOptionValue.Serial.getValue()));
633632
} else if (!values.containsKey(SubstrateOptions.SupportedGCs) ||
634-
((ReplacingLocatableMultiOptionValue.DelimitedString) values.get(SubstrateOptions.SupportedGCs)).contains(GCOptionValue.SERIAL.getValue())) {
633+
((ReplacingLocatableMultiOptionValue.DelimitedString) values.get(SubstrateOptions.SupportedGCs)).contains(GCOptionValue.Serial.getValue())) {
635634
SubstrateOptions.SupportedGCs.update(values, ReplacingLocatableMultiOptionValue.DelimitedString.buildWithCommaDelimiter());
636635
}
637636
}
@@ -644,8 +643,8 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean o
644643
@Override
645644
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean oldValue, Boolean newValue) {
646645
if (newValue) {
647-
SubstrateOptions.SupportedGCs.update(values, ReplacingLocatableMultiOptionValue.DelimitedString.buildWithCommaDelimiter(GCOptionValue.EPSILON.getValue()));
648-
} else if (((AccumulatingLocatableMultiOptionValue.Strings) values.get(SubstrateOptions.SupportedGCs)).contains(GCOptionValue.EPSILON.getValue())) {
646+
SubstrateOptions.SupportedGCs.update(values, ReplacingLocatableMultiOptionValue.DelimitedString.buildWithCommaDelimiter(GCOptionValue.Epsilon.getValue()));
647+
} else if (((AccumulatingLocatableMultiOptionValue.Strings) values.get(SubstrateOptions.SupportedGCs)).contains(GCOptionValue.Epsilon.getValue())) {
649648
SubstrateOptions.SupportedGCs.update(values, ReplacingLocatableMultiOptionValue.DelimitedString.buildWithCommaDelimiter());
650649
}
651650
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[[rule]]
2+
files = "*"
3+
all = [
4+
"christian.haeubl@oracle.com",
5+
]
6+
any = [
7+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.gc.shared;
26+
27+
import org.graalvm.nativeimage.Isolate;
28+
import org.graalvm.nativeimage.IsolateThread;
29+
30+
import com.oracle.svm.core.Uninterruptible;
31+
import com.oracle.svm.core.c.function.CEntryPointOptions.Prologue;
32+
import com.oracle.svm.core.graal.nodes.WriteCurrentVMThreadNode;
33+
import com.oracle.svm.core.graal.snippets.CEntryPointSnippets;
34+
35+
/**
36+
* Prologue that only initializes the base registers so that a thread can execute SVM code.
37+
* Unattached threads need to pass null as the {@link IsolateThread}, so that this prologue behaves
38+
* the same as {@link InitializeReservedRegistersForUnattachedThread}.
39+
*/
40+
public class InitializeReservedRegistersForPossiblyUnattachedThread implements Prologue {
41+
@Uninterruptible(reason = "prologue")
42+
@SuppressWarnings("unused")
43+
public static void enter(Isolate heapBase, IsolateThread thread) {
44+
CEntryPointSnippets.initBaseRegisters(heapBase);
45+
WriteCurrentVMThreadNode.writeCurrentVMThread(thread);
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.gc.shared;
26+
27+
import org.graalvm.nativeimage.Isolate;
28+
29+
import com.oracle.svm.core.Uninterruptible;
30+
import com.oracle.svm.core.c.function.CEntryPointOptions.Prologue;
31+
import com.oracle.svm.core.graal.nodes.WriteCurrentVMThreadNode;
32+
import com.oracle.svm.core.graal.snippets.CEntryPointSnippets;
33+
34+
import jdk.graal.compiler.word.Word;
35+
36+
/**
37+
* Prologue that only initializes the base registers so that an unattached thread can execute SVM
38+
* code.
39+
*/
40+
public final class InitializeReservedRegistersForUnattachedThread implements Prologue {
41+
@Uninterruptible(reason = "prologue")
42+
@SuppressWarnings("unused")
43+
public static void enter(Isolate heapBase) {
44+
CEntryPointSnippets.initBaseRegisters(heapBase);
45+
WriteCurrentVMThreadNode.writeCurrentVMThread(Word.nullPointer());
46+
}
47+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.gc.shared;
26+
27+
/** Defines which debug-levels are supported for GCs such as G1. */
28+
public enum NativeGCDebugLevel {
29+
Product("", 0),
30+
FastDebug("-fastdebug", 1),
31+
Debug("-debug", 2);
32+
33+
private final String libSuffix;
34+
private final int index;
35+
36+
NativeGCDebugLevel(String libSuffix, int index) {
37+
this.libSuffix = libSuffix;
38+
this.index = index;
39+
}
40+
41+
public String getLibSuffix() {
42+
return libSuffix;
43+
}
44+
45+
public int getIndex() {
46+
return index;
47+
}
48+
49+
public static NativeGCDebugLevel fromString(String value) {
50+
return switch (value) {
51+
case "product" -> Product;
52+
case "fastdebug" -> FastDebug;
53+
case "debug" -> Debug;
54+
default -> null;
55+
};
56+
}
57+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.gc.shared;
26+
27+
import java.util.Collections;
28+
import java.util.List;
29+
30+
import org.graalvm.nativeimage.c.CContext;
31+
32+
import com.oracle.svm.core.c.ProjectHeaderFile;
33+
34+
/**
35+
* Determines which header files must be included when building a native-image that uses a GC such
36+
* as G1.
37+
*/
38+
public class NativeGCHeaderFiles implements CContext.Directives {
39+
@Override
40+
public boolean isInConfiguration() {
41+
return UseNativeGC.get();
42+
}
43+
44+
@Override
45+
public List<String> getHeaderFiles() {
46+
return Collections.singletonList(ProjectHeaderFile.resolve("", "include/sharedGCStructs.h"));
47+
}
48+
}

0 commit comments

Comments
 (0)