Skip to content

Commit 6a1b793

Browse files
Simplifications and better control over diagnostic thunks.
1 parent cd0de35 commit 6a1b793

File tree

25 files changed

+502
-411
lines changed

25 files changed

+502
-411
lines changed

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

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

27+
import com.oracle.svm.core.SubstrateDiagnostics.ErrorContext;
2728
import org.graalvm.compiler.nodes.java.ArrayLengthNode;
2829
import org.graalvm.compiler.options.Option;
2930
import org.graalvm.compiler.word.Word;
@@ -33,6 +34,7 @@
3334
import org.graalvm.word.UnsignedWord;
3435
import org.graalvm.word.WordFactory;
3536

37+
import com.oracle.svm.core.SubstrateDiagnostics;
3638
import com.oracle.svm.core.SubstrateDiagnostics.DiagnosticThunk;
3739
import com.oracle.svm.core.SubstrateDiagnostics.DiagnosticThunkRegister;
3840
import com.oracle.svm.core.annotate.AlwaysInline;
@@ -132,13 +134,13 @@ public void noteObject(Object o) {
132134
}
133135

134136
@Override
135-
public int baseInvocations() {
137+
public int maxInvocations() {
136138
return 1;
137139
}
138140

139141
@Override
140142
@RestrictHeapAccess(access = RestrictHeapAccess.Access.NO_ALLOCATION, reason = "Must not allocate during printing diagnostics.")
141-
public void printDiagnostics(Log log, int invocationCount) {
143+
public void printDiagnostics(Log log, ErrorContext context, int maxDiagnosticLevel, int invocationCount) {
142144
if (historyCount > 0) {
143145
log.string("[GreyToBlackObjectVisitor.RealDiagnosticReporter.invoke:")
144146
.string(" history / count: ")

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

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

31+
import com.oracle.svm.core.SubstrateDiagnostics.ErrorContext;
3132
import org.graalvm.compiler.api.replacements.Fold;
3233
import org.graalvm.compiler.core.common.NumUtil;
3334
import org.graalvm.compiler.core.common.SuppressFBWarnings;
@@ -43,7 +44,6 @@
4344

4445
import com.oracle.svm.core.MemoryWalker;
4546
import com.oracle.svm.core.SubstrateDiagnostics;
46-
import com.oracle.svm.core.SubstrateDiagnostics.DiagnosticLevel;
4747
import com.oracle.svm.core.SubstrateDiagnostics.DiagnosticThunk;
4848
import com.oracle.svm.core.SubstrateOptions;
4949
import com.oracle.svm.core.annotate.NeverInline;
@@ -612,7 +612,7 @@ public Reference<?> getAndClearReferencePendingList() {
612612
}
613613

614614
@Override
615-
public boolean printLocationInfo(Log log, UnsignedWord value, int diagnosticLevel) {
615+
public boolean printLocationInfo(Log log, UnsignedWord value, boolean allowJavaHeapAccess, boolean allowUnsafeOperations) {
616616
if (SubstrateOptions.SpawnIsolates.getValue()) {
617617
Pointer heapBase = KnownIntrinsics.heapBase();
618618
if (value.equal(heapBase)) {
@@ -625,8 +625,8 @@ public boolean printLocationInfo(Log log, UnsignedWord value, int diagnosticLeve
625625
}
626626

627627
Pointer ptr = (Pointer) value;
628-
if (printLocationInfo(log, ptr, diagnosticLevel)) {
629-
if (DiagnosticLevel.isJavaHeapAccessAllowed(diagnosticLevel) && objectHeaderImpl.pointsToObjectHeader(ptr)) {
628+
if (printLocationInfo(log, ptr, allowJavaHeapAccess, allowUnsafeOperations)) {
629+
if (allowJavaHeapAccess && objectHeaderImpl.pointsToObjectHeader(ptr)) {
630630
DynamicHub hub = objectHeaderImpl.readDynamicHubFromPointer(ptr);
631631
log.indent(true);
632632
log.string("hub=").string(hub.getName());
@@ -647,7 +647,7 @@ static Pointer getImageHeapStart() {
647647
}
648648
}
649649

650-
private boolean printLocationInfo(Log log, Pointer ptr, int diagnosticLevel) {
650+
private boolean printLocationInfo(Log log, Pointer ptr, boolean allowJavaHeapAccess, boolean allowUnsafeOperations) {
651651
if (imageHeapInfo.isInReadOnlyPrimitivePartition(ptr)) {
652652
log.string("points into the image heap (read-only primitives)");
653653
return true;
@@ -676,7 +676,7 @@ private boolean printLocationInfo(Log log, Pointer ptr, int diagnosticLevel) {
676676
return true;
677677
}
678678

679-
if (DiagnosticLevel.isJavaHeapAccessAllowed(diagnosticLevel)) {
679+
if (allowJavaHeapAccess) {
680680
// Accessing spaces and chunks is safe if we prevent a GC.
681681
if (isInYoungGen(ptr)) {
682682
log.string("points into the young generation");
@@ -687,7 +687,7 @@ private boolean printLocationInfo(Log log, Pointer ptr, int diagnosticLevel) {
687687
}
688688
}
689689

690-
if (DiagnosticLevel.isUnsafeAccessAllowed(diagnosticLevel) || VMOperation.isInProgressAtSafepoint()) {
690+
if (allowUnsafeOperations || VMOperation.isInProgressAtSafepoint()) {
691691
// If we are not at a safepoint, then it is unsafe to access thread locals of another
692692
// thread as the IsolateThread could be freed at any time.
693693
return printTlabInfo(log, ptr);
@@ -781,19 +781,19 @@ private static boolean printTlabInfo(Log log, Pointer ptr, IsolateThread thread)
781781

782782
@Uninterruptible(reason = "This whole method is unsafe, so it is only uninterruptible to satisfy the checks.")
783783
private static Descriptor getTlabUnsafe(IsolateThread thread) {
784-
assert SubstrateDiagnostics.isInProgressByCurrentThread() : "can cause crashes, so it may only be used while printing diagnostics";
784+
assert SubstrateDiagnostics.isFatalErrorHandlingThread() : "can cause crashes, so it may only be used while printing diagnostics";
785785
return ThreadLocalAllocation.getTlab(thread);
786786
}
787787

788788
private static class DumpHeapSettingsAndStatistics extends DiagnosticThunk {
789789
@Override
790-
public int baseInvocations() {
790+
public int maxInvocations() {
791791
return 1;
792792
}
793793

794794
@Override
795795
@RestrictHeapAccess(access = RestrictHeapAccess.Access.NO_ALLOCATION, reason = "Must not allocate while printing diagnostics.")
796-
public void printDiagnostics(Log log, int invocationCount) {
796+
public void printDiagnostics(Log log, ErrorContext context, int maxDiagnosticLevel, int invocationCount) {
797797
GCImpl gc = GCImpl.getGCImpl();
798798

799799
log.string("Heap settings and statistics:").indent(true);
@@ -813,13 +813,13 @@ public void printDiagnostics(Log log, int invocationCount) {
813813

814814
private static class DumpChunkInformation extends DiagnosticThunk {
815815
@Override
816-
public int baseInvocations() {
816+
public int maxInvocations() {
817817
return 1;
818818
}
819819

820820
@Override
821821
@RestrictHeapAccess(access = RestrictHeapAccess.Access.NO_ALLOCATION, reason = "Must not allocate while printing diagnostics.")
822-
public void printDiagnostics(Log log, int invocationCount) {
822+
public void printDiagnostics(Log log, ErrorContext context, int maxDiagnosticLevel, int invocationCount) {
823823
HeapImpl heap = HeapImpl.getHeapImpl();
824824
heap.logImageHeapPartitionBoundaries(log);
825825
zapValuesToLog(log).newline();

substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/AMD64CalleeSavedRegisters.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -167,36 +167,36 @@ private AMD64Address calleeSaveAddress(AMD64MacroAssembler asm, int frameSize, R
167167
}
168168

169169
@Override
170-
public void dumpRegisters(Log log, Pointer callerSP, boolean printLocationInfo, boolean allowJavaHeapAccess, boolean allowUnsafeAccess) {
170+
public void dumpRegisters(Log log, Pointer callerSP, boolean printLocationInfo, boolean allowJavaHeapAccess, boolean allowUnsafeOperations) {
171171
log.string("Callee saved registers (sp=").zhex(callerSP).string(")").indent(true);
172172
/*
173173
* The loop to print all registers is manually unrolled so that the register order is
174174
* defined, and also so that the lookup of the "offset in frame" can be constant folded at
175175
* image build time using a @Fold method.
176176
*/
177-
dumpReg(log, "RAX ", callerSP, offsetInFrameOrNull(AMD64.rax), printLocationInfo, allowJavaHeapAccess, allowUnsafeAccess);
178-
dumpReg(log, "RBX ", callerSP, offsetInFrameOrNull(AMD64.rbx), printLocationInfo, allowJavaHeapAccess, allowUnsafeAccess);
179-
dumpReg(log, "RCX ", callerSP, offsetInFrameOrNull(AMD64.rcx), printLocationInfo, allowJavaHeapAccess, allowUnsafeAccess);
180-
dumpReg(log, "RDX ", callerSP, offsetInFrameOrNull(AMD64.rdx), printLocationInfo, allowJavaHeapAccess, allowUnsafeAccess);
181-
dumpReg(log, "RBP ", callerSP, offsetInFrameOrNull(AMD64.rbp), printLocationInfo, allowJavaHeapAccess, allowUnsafeAccess);
182-
dumpReg(log, "RSI ", callerSP, offsetInFrameOrNull(AMD64.rsi), printLocationInfo, allowJavaHeapAccess, allowUnsafeAccess);
183-
dumpReg(log, "RDI ", callerSP, offsetInFrameOrNull(AMD64.rdi), printLocationInfo, allowJavaHeapAccess, allowUnsafeAccess);
184-
dumpReg(log, "RSP ", callerSP, offsetInFrameOrNull(AMD64.rsp), printLocationInfo, allowJavaHeapAccess, allowUnsafeAccess);
185-
dumpReg(log, "R8 ", callerSP, offsetInFrameOrNull(AMD64.r8), printLocationInfo, allowJavaHeapAccess, allowUnsafeAccess);
186-
dumpReg(log, "R9 ", callerSP, offsetInFrameOrNull(AMD64.r9), printLocationInfo, allowJavaHeapAccess, allowUnsafeAccess);
187-
dumpReg(log, "R10 ", callerSP, offsetInFrameOrNull(AMD64.r10), printLocationInfo, allowJavaHeapAccess, allowUnsafeAccess);
188-
dumpReg(log, "R11 ", callerSP, offsetInFrameOrNull(AMD64.r11), printLocationInfo, allowJavaHeapAccess, allowUnsafeAccess);
189-
dumpReg(log, "R12 ", callerSP, offsetInFrameOrNull(AMD64.r12), printLocationInfo, allowJavaHeapAccess, allowUnsafeAccess);
190-
dumpReg(log, "R13 ", callerSP, offsetInFrameOrNull(AMD64.r13), printLocationInfo, allowJavaHeapAccess, allowUnsafeAccess);
191-
dumpReg(log, "R14 ", callerSP, offsetInFrameOrNull(AMD64.r14), printLocationInfo, allowJavaHeapAccess, allowUnsafeAccess);
192-
dumpReg(log, "R15 ", callerSP, offsetInFrameOrNull(AMD64.r15), printLocationInfo, allowJavaHeapAccess, allowUnsafeAccess);
177+
dumpReg(log, "RAX ", callerSP, offsetInFrameOrNull(AMD64.rax), printLocationInfo, allowJavaHeapAccess, allowUnsafeOperations);
178+
dumpReg(log, "RBX ", callerSP, offsetInFrameOrNull(AMD64.rbx), printLocationInfo, allowJavaHeapAccess, allowUnsafeOperations);
179+
dumpReg(log, "RCX ", callerSP, offsetInFrameOrNull(AMD64.rcx), printLocationInfo, allowJavaHeapAccess, allowUnsafeOperations);
180+
dumpReg(log, "RDX ", callerSP, offsetInFrameOrNull(AMD64.rdx), printLocationInfo, allowJavaHeapAccess, allowUnsafeOperations);
181+
dumpReg(log, "RBP ", callerSP, offsetInFrameOrNull(AMD64.rbp), printLocationInfo, allowJavaHeapAccess, allowUnsafeOperations);
182+
dumpReg(log, "RSI ", callerSP, offsetInFrameOrNull(AMD64.rsi), printLocationInfo, allowJavaHeapAccess, allowUnsafeOperations);
183+
dumpReg(log, "RDI ", callerSP, offsetInFrameOrNull(AMD64.rdi), printLocationInfo, allowJavaHeapAccess, allowUnsafeOperations);
184+
dumpReg(log, "RSP ", callerSP, offsetInFrameOrNull(AMD64.rsp), printLocationInfo, allowJavaHeapAccess, allowUnsafeOperations);
185+
dumpReg(log, "R8 ", callerSP, offsetInFrameOrNull(AMD64.r8), printLocationInfo, allowJavaHeapAccess, allowUnsafeOperations);
186+
dumpReg(log, "R9 ", callerSP, offsetInFrameOrNull(AMD64.r9), printLocationInfo, allowJavaHeapAccess, allowUnsafeOperations);
187+
dumpReg(log, "R10 ", callerSP, offsetInFrameOrNull(AMD64.r10), printLocationInfo, allowJavaHeapAccess, allowUnsafeOperations);
188+
dumpReg(log, "R11 ", callerSP, offsetInFrameOrNull(AMD64.r11), printLocationInfo, allowJavaHeapAccess, allowUnsafeOperations);
189+
dumpReg(log, "R12 ", callerSP, offsetInFrameOrNull(AMD64.r12), printLocationInfo, allowJavaHeapAccess, allowUnsafeOperations);
190+
dumpReg(log, "R13 ", callerSP, offsetInFrameOrNull(AMD64.r13), printLocationInfo, allowJavaHeapAccess, allowUnsafeOperations);
191+
dumpReg(log, "R14 ", callerSP, offsetInFrameOrNull(AMD64.r14), printLocationInfo, allowJavaHeapAccess, allowUnsafeOperations);
192+
dumpReg(log, "R15 ", callerSP, offsetInFrameOrNull(AMD64.r15), printLocationInfo, allowJavaHeapAccess, allowUnsafeOperations);
193193
log.indent(false);
194194
}
195195

196-
private static void dumpReg(Log log, String label, Pointer callerSP, int offsetInFrameOrNull, boolean printLocationInfo, boolean allowJavaHeapAccess, boolean allowUnsafeAccess) {
196+
private static void dumpReg(Log log, String label, Pointer callerSP, int offsetInFrameOrNull, boolean printLocationInfo, boolean allowJavaHeapAccess, boolean allowUnsafeOperations) {
197197
if (offsetInFrameOrNull != 0) {
198198
long value = callerSP.readLong(offsetInFrameOrNull);
199-
RegisterDumper.dumpReg(log, label, value, printLocationInfo, allowJavaHeapAccess, allowUnsafeAccess);
199+
RegisterDumper.dumpReg(log, label, value, printLocationInfo, allowJavaHeapAccess, allowUnsafeOperations);
200200
}
201201
}
202202

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixLogHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void flush() {
7979

8080
@Override
8181
public void fatalError() {
82-
if (SubstrateDiagnostics.isInProgress()) {
82+
if (SubstrateDiagnostics.isFatalErrorHandlingInProgress()) {
8383
// Delay the shutdown a bit if another thread has something important to report.
8484
VMThreads.singleton().nativeSleep(3000);
8585
}

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/UContextRegisterDumper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import com.oracle.svm.core.posix.headers.Signal.ucontext_t;
3333

3434
public interface UContextRegisterDumper extends RegisterDumper {
35-
void dumpRegisters(Log log, ucontext_t uContext, boolean printLocationInfo, boolean allowJavaHeapAccess);
35+
void dumpRegisters(Log log, ucontext_t uContext, boolean printLocationInfo, boolean allowJavaHeapAccess, boolean allowUnsafeOperations);
3636

3737
PointerBase getHeapBase(ucontext_t uContext);
3838

@@ -43,8 +43,8 @@ public interface UContextRegisterDumper extends RegisterDumper {
4343
PointerBase getIP(ucontext_t uContext);
4444

4545
@Override
46-
default void dumpRegisters(Log log, Context context, boolean printLocationInfo, boolean allowJavaHeapAccess) {
47-
dumpRegisters(log, (ucontext_t) context, printLocationInfo, allowJavaHeapAccess);
46+
default void dumpRegisters(Log log, Context context, boolean printLocationInfo, boolean allowJavaHeapAccess, boolean allowUnsafeOperations) {
47+
dumpRegisters(log, (ucontext_t) context, printLocationInfo, allowJavaHeapAccess, allowUnsafeOperations);
4848
}
4949

5050
@Override

0 commit comments

Comments
 (0)