Skip to content

Commit f191598

Browse files
Simplify @RestrictHeapAccess and minor safepoint-related changes.
1 parent f4ac886 commit f191598

File tree

33 files changed

+168
-172
lines changed

33 files changed

+168
-172
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,7 @@ public <T> boolean visitNativeImageHeapRegion(T region, MemoryWalker.NativeImage
359359
}
360360

361361
@Override
362-
@RestrictHeapAccess(access = RestrictHeapAccess.Access.UNRESTRICTED, overridesCallers = true, //
363-
reason = "Allocation is fine: this method traverses only the image heap.")
362+
@RestrictHeapAccess(access = RestrictHeapAccess.Access.UNRESTRICTED, reason = "Allocation is fine: this method traverses only the image heap.")
364363
public boolean visitObject(Object o) {
365364
if (o instanceof Class<?>) {
366365
list.add((Class<?>) o);

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/pthread/PthreadVMLockSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public static boolean initialize() {
164164
}
165165

166166
@Uninterruptible(reason = "Called from uninterruptible code.", calleeMustBe = false)
167-
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "Must not allocate in fatal error handling.", overridesCallers = true)
167+
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "Must not allocate in fatal error handling.")
168168
protected static void checkResult(int result, String functionName) {
169169
if (result != 0) {
170170
/*

substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsSubstrateSegfaultHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
package com.oracle.svm.core.windows;
2626

2727
import static com.oracle.svm.core.annotate.RestrictHeapAccess.Access.NO_ALLOCATION;
28-
import static com.oracle.svm.core.annotate.RestrictHeapAccess.Access.NO_HEAP_ACCESS;
2928
import static com.oracle.svm.core.windows.headers.ErrHandlingAPI.EXCEPTION_ACCESS_VIOLATION;
3029
import static com.oracle.svm.core.windows.headers.ErrHandlingAPI.EXCEPTION_IN_PAGE_ERROR;
3130

@@ -91,7 +90,7 @@ protected void installInternal() {
9190
@CEntryPoint(include = CEntryPoint.NotIncludedAutomatically.class)
9291
@CEntryPointOptions(prologue = NoPrologue.class, epilogue = NoEpilogue.class, publishAs = Publish.SymbolOnly)
9392
@Uninterruptible(reason = "Must be uninterruptible until we get immune to safepoints.")
94-
@RestrictHeapAccess(access = NO_HEAP_ACCESS, reason = "We have yet to enter the isolate.")
93+
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "Must not allocate in segfault signal handler.")
9594
private static int handler(ErrHandlingAPI.EXCEPTION_POINTERS exceptionInfo) {
9695
ErrHandlingAPI.EXCEPTION_RECORD exceptionRecord = exceptionInfo.ExceptionRecord();
9796
if (exceptionRecord.ExceptionCode() != ErrHandlingAPI.EXCEPTION_ACCESS_VIOLATION()) {
@@ -142,7 +141,7 @@ protected void printSignalInfo(Log log, PointerBase signalInfo) {
142141
}
143142

144143
@Uninterruptible(reason = "Called from uninterruptible code.")
145-
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "Must not allocate in segfault handler.", overridesCallers = true)
144+
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "Must not allocate in segfault handler.")
146145
private static RuntimeException shouldNotReachHere() {
147146
throw VMError.shouldNotReachHere();
148147
}

substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsVMLockSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public static void initialize() {
159159
}
160160

161161
@Uninterruptible(reason = "Called from uninterruptible code.", calleeMustBe = false)
162-
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "Must not allocate in fatal error handling.", overridesCallers = true)
162+
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "Must not allocate in fatal error handling.")
163163
static void checkResult(int result, String functionName) {
164164
if (result == 0) {
165165
/*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private static void methodPointerNotCompiledHandler() {
7474
}
7575

7676
@Uninterruptible(reason = "Prevent safepoints until everything is set up for printing the fatal error.", calleeMustBe = false)
77-
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "Must not allocate in fatal error handling.", overridesCallers = true)
77+
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "Must not allocate in fatal error handling.")
7878
private static void failFatally(Pointer callerSP, CodePointer callerIP, String message) {
7979
SafepointBehavior.preventSafepoints();
8080
StackOverflowCheck.singleton().disableStackOverflowChecksForFatalError();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ public void printDiagnostics(Log log, ErrorContext context, int maxDiagnosticLev
625625
if (allowJavaHeapAccess) {
626626
Thread threadObj = JavaThreads.fromVMThread(thread);
627627
log.string(" \"").string(threadObj.getName()).string("\" - ").zhex(Word.objectToUntrackedPointer(threadObj));
628-
if (threadObj.isDaemon()) {
628+
if (threadObj != null && threadObj.isDaemon()) {
629629
log.string(", daemon");
630630
}
631631
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void install() {
118118

119119
/** Called from the platform dependent segfault handler to enter the isolate. */
120120
@Uninterruptible(reason = "Called from uninterruptible code.")
121-
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "Must not allocate in segfault handler.", overridesCallers = true)
121+
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "Must not allocate in segfault handler.")
122122
protected static boolean tryEnterIsolate(RegisterDumper.Context context) {
123123
// Check if we have sufficient information to enter the correct isolate.
124124
Isolate isolate = SingleIsolateSegfaultSetup.singleton().getIsolate();
@@ -152,7 +152,7 @@ protected static boolean tryEnterIsolate(RegisterDumper.Context context) {
152152

153153
/** Called from the platform dependent segfault handler to print diagnostics. */
154154
@Uninterruptible(reason = "Must be uninterruptible until we get immune to safepoints.", calleeMustBe = false)
155-
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "Must not allocate in segfault handler.", overridesCallers = true)
155+
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "Must not allocate in segfault handler.")
156156
protected static void dump(PointerBase signalInfo, RegisterDumper.Context context) {
157157
SafepointBehavior.preventSafepoints();
158158
StackOverflowCheck.singleton().disableStackOverflowChecksForFatalError();

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/annotate/RestrictHeapAccess.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
public @interface RestrictHeapAccess {
3939
enum Access {
4040
UNRESTRICTED,
41-
NO_ALLOCATION,
42-
NO_HEAP_ACCESS;
41+
NO_ALLOCATION;
4342

4443
public boolean isMoreRestrictiveThan(Access other) {
4544
return ordinal() > other.ordinal();
@@ -48,14 +47,8 @@ public boolean isMoreRestrictiveThan(Access other) {
4847

4948
Access access();
5049

51-
/**
52-
* When {@link #overridesCallers} is enabled and this method is (transitively) called from a
53-
* caller with restricted heap access, override the caller's restrictions with those of this
54-
* method from {@link #access}.
55-
*/
50+
// Unnecessary, will be removed in GR-34779.
5651
boolean overridesCallers() default false;
5752

5853
String reason();
59-
60-
boolean mayBeInlined() default false;
6154
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/FrameInfoDecoder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected static boolean isFrameInfoMatch(long frameInfoIndex, NonmovableArray<B
7979
}
8080

8181
public interface FrameInfoQueryResultAllocator {
82-
@RestrictHeapAccess(reason = "Whitelisted because some implementations can allocate.", access = RestrictHeapAccess.Access.UNRESTRICTED, overridesCallers = true)
82+
@RestrictHeapAccess(reason = "Whitelisted because some implementations can allocate.", access = RestrictHeapAccess.Access.UNRESTRICTED)
8383
FrameInfoQueryResult newFrameInfoQueryResult();
8484
}
8585

@@ -104,25 +104,25 @@ public interface ValueInfoAllocator {
104104

105105
static class HeapBasedValueInfoAllocator implements ValueInfoAllocator {
106106
@Override
107-
@RestrictHeapAccess(reason = "Whitelisted because some implementations can allocate.", access = RestrictHeapAccess.Access.UNRESTRICTED, overridesCallers = true)
107+
@RestrictHeapAccess(reason = "Whitelisted because some implementations can allocate.", access = RestrictHeapAccess.Access.UNRESTRICTED)
108108
public ValueInfo newValueInfo() {
109109
return new ValueInfo();
110110
}
111111

112112
@Override
113-
@RestrictHeapAccess(reason = "Whitelisted because some implementations can allocate.", access = RestrictHeapAccess.Access.UNRESTRICTED, overridesCallers = true)
113+
@RestrictHeapAccess(reason = "Whitelisted because some implementations can allocate.", access = RestrictHeapAccess.Access.UNRESTRICTED)
114114
public ValueInfo[] newValueInfoArray(int len) {
115115
return new ValueInfo[len];
116116
}
117117

118118
@Override
119-
@RestrictHeapAccess(reason = "Whitelisted because some implementations can allocate.", access = RestrictHeapAccess.Access.UNRESTRICTED, overridesCallers = true)
119+
@RestrictHeapAccess(reason = "Whitelisted because some implementations can allocate.", access = RestrictHeapAccess.Access.UNRESTRICTED)
120120
public ValueInfo[][] newValueInfoArrayArray(int len) {
121121
return new ValueInfo[len][];
122122
}
123123

124124
@Override
125-
@RestrictHeapAccess(reason = "Whitelisted because some implementations can allocate.", access = RestrictHeapAccess.Access.UNRESTRICTED, overridesCallers = true)
125+
@RestrictHeapAccess(reason = "Whitelisted because some implementations can allocate.", access = RestrictHeapAccess.Access.UNRESTRICTED)
126126
public void decodeConstant(ValueInfo valueInfo, NonmovableObjectArray<?> frameInfoObjectConstants) {
127127
switch (valueInfo.type) {
128128
case DefaultConstant:

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/CEntryPointSnippets.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ public static int reportExceptionSnippet(Throwable exception) {
565565

566566
@Uninterruptible(reason = "Avoid StackOverflowError and safepoints until they are disabled permanently", calleeMustBe = false)
567567
@SubstrateForeignCallTarget(stubCallingConvention = false)
568-
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "Must not allocate in fatal error handling.", overridesCallers = true)
568+
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "Must not allocate in fatal error handling.")
569569
private static int reportException(Throwable exception) {
570570
SafepointBehavior.preventSafepoints();
571571
StackOverflowCheck.singleton().disableStackOverflowChecksForFatalError();
@@ -576,7 +576,7 @@ private static int reportException(Throwable exception) {
576576
return CEntryPointErrors.UNSPECIFIED; // unreachable
577577
}
578578

579-
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "Must not allocate in fatal error handling.", overridesCallers = true)
579+
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "Must not allocate in fatal error handling.")
580580
private static void logException(Throwable exception) {
581581
try {
582582
Log.log().exception(exception);

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/DeoptTester.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static class Options {
7575
private static final StackFrameVisitor collectPcVisitor = new StackFrameVisitor() {
7676

7777
@Override
78-
@RestrictHeapAccess(access = RestrictHeapAccess.Access.UNRESTRICTED, overridesCallers = true, reason = "Only deals with IPs, not Objects.")
78+
@RestrictHeapAccess(access = RestrictHeapAccess.Access.UNRESTRICTED, reason = "Only deals with IPs, not Objects.")
7979
public boolean visitFrame(Pointer sp, CodePointer ip, CodeInfo codeInfo, DeoptimizedFrame deoptimizedFrame) {
8080
handledPCs.add(ip.rawValue());
8181
return true;

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/StackOverflowCheckImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ private static void throwNewStackOverflowError() {
277277
}
278278

279279
@Uninterruptible(reason = "Allow allocation now that yellow zone is available for new stack frames", calleeMustBe = false)
280-
@RestrictHeapAccess(reason = "Allow allocation now that yellow zone is available for new stack frames", overridesCallers = true, access = Access.UNRESTRICTED)
280+
@RestrictHeapAccess(reason = "Allow allocation now that yellow zone is available for new stack frames", access = Access.UNRESTRICTED)
281281
private static StackOverflowError newStackOverflowError() {
282282
/*
283283
* Now that the yellow zone is enabled, we can allocate the error and collect the stack

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public interface ObjectReferenceVisitor {
4141
* not part of an object.
4242
* @return {@code true} if visiting should continue, {@code false} if visiting should stop.
4343
*/
44-
@RestrictHeapAccess(access = RestrictHeapAccess.Access.UNRESTRICTED, overridesCallers = true, reason = "Some implementations allocate.")
44+
@RestrictHeapAccess(access = RestrictHeapAccess.Access.UNRESTRICTED, reason = "Some implementations allocate.")
4545
boolean visitObjectReference(Pointer objRef, boolean compressed, Object holderObject);
4646

4747
/**
@@ -50,7 +50,7 @@ public interface ObjectReferenceVisitor {
5050
* the object reference points in order to get the start of the referenced object.
5151
*/
5252
@AlwaysInline("GC performance")
53-
@RestrictHeapAccess(access = RestrictHeapAccess.Access.UNRESTRICTED, overridesCallers = true, reason = "Some implementations allocate.")
53+
@RestrictHeapAccess(access = RestrictHeapAccess.Access.UNRESTRICTED, reason = "Some implementations allocate.")
5454
default boolean visitObjectReferenceInline(Pointer objRef, int innerOffset, boolean compressed, Object holderObject) {
5555
VMError.guarantee(innerOffset == 0, "visitor does not support derived references");
5656
return visitObjectReference(objRef, compressed, holderObject);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ private static boolean isInitializationDisallowed() {
141141
!CEntryPointSnippets.isIsolateInitialized() || StackOverflowCheck.singleton().isYellowZoneAvailable();
142142
}
143143

144-
@RestrictHeapAccess(access = RestrictHeapAccess.Access.UNRESTRICTED, overridesCallers = true, reason = "Only called if allocation is allowed.")
144+
@RestrictHeapAccess(access = RestrictHeapAccess.Access.UNRESTRICTED, reason = "Only called if allocation is allowed.")
145145
private static void doInitialize() {
146146
long memoryLimit = Containers.memoryLimitInBytes();
147147
cachedSize = memoryLimit == Containers.UNKNOWN

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/VMErrorSubstitutions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public class VMErrorSubstitutions {
9999
* uninterruptible
100100
*/
101101
@Uninterruptible(reason = "Allow VMError to be used in uninterruptible code.")
102-
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "Must not allocate in fatal error handling.", overridesCallers = true)
102+
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "Must not allocate in fatal error handling.")
103103
static RuntimeException shouldNotReachHere(CodePointer callerIP, String msg, Throwable ex) {
104104
ThreadStackPrinter.printBacktrace();
105105

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/log/FunctionPointerLogHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package com.oracle.svm.core.log;
2626

27+
import com.oracle.svm.core.annotate.RestrictHeapAccess;
2728
import org.graalvm.nativeimage.ImageSingletons;
2829
import org.graalvm.nativeimage.LogHandler;
2930
import org.graalvm.nativeimage.c.function.CFunctionPointer;
@@ -81,6 +82,7 @@ public Log enterFatalContext(CodePointer callerIP, String msg, Throwable ex) {
8182
*/
8283
class FatalLog extends RealLog {
8384
@Override
85+
@RestrictHeapAccess(access = RestrictHeapAccess.Access.NO_ALLOCATION, reason = "Must not allocate when logging.")
8486
protected Log rawBytes(CCharPointer bytes, UnsignedWord length) {
8587
if (fatalLogFunctionPointer.isNonNull()) {
8688
fatalLogFunctionPointer.invoke(bytes, length);
@@ -91,6 +93,7 @@ protected Log rawBytes(CCharPointer bytes, UnsignedWord length) {
9193
}
9294

9395
@Override
96+
@RestrictHeapAccess(access = RestrictHeapAccess.Access.NO_ALLOCATION, reason = "Must not allocate when logging.")
9497
public Log flush() {
9598
if (fatalLogFunctionPointer.isNull()) {
9699
FunctionPointerLogHandler.this.flush();

0 commit comments

Comments
 (0)