Skip to content

Commit 5a2e87b

Browse files
Add debug helper methods.
1 parent 1aaee99 commit 5a2e87b

File tree

9 files changed

+366
-10
lines changed

9 files changed

+366
-10
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
import com.oracle.svm.core.heap.ReferenceHandlerThread;
6969
import com.oracle.svm.core.heap.ReferenceInternals;
7070
import com.oracle.svm.core.heap.RuntimeCodeInfoGCSupport;
71-
import com.oracle.svm.core.hub.DynamicHub;
7271
import com.oracle.svm.core.jdk.UninterruptibleUtils.AtomicReference;
7372
import com.oracle.svm.core.locks.VMCondition;
7473
import com.oracle.svm.core.locks.VMMutex;
@@ -643,9 +642,8 @@ public boolean printLocationInfo(Log log, UnsignedWord value, boolean allowJavaH
643642
Pointer ptr = (Pointer) value;
644643
if (printLocationInfo(log, ptr, allowJavaHeapAccess, allowUnsafeOperations)) {
645644
if (allowJavaHeapAccess && objectHeaderImpl.pointsToObjectHeader(ptr)) {
646-
DynamicHub hub = objectHeaderImpl.readDynamicHubFromPointer(ptr);
647645
log.indent(true);
648-
log.string("hub=").string(hub.getName());
646+
SubstrateDiagnostics.printObjectInfo(log, ptr);
649647
log.redent(false);
650648
}
651649
return true;

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,14 @@ public DynamicHub dynamicHubFromObjectHeader(UnsignedWord header) {
142142
return (DynamicHub) objectValue;
143143
}
144144

145+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
145146
@Override
146147
public Pointer readPotentialDynamicHubFromPointer(Pointer ptr) {
147148
UnsignedWord potentialHeader = ObjectHeaderImpl.readHeaderFromPointer(ptr);
148149
UnsignedWord pointerBits = clearBits(potentialHeader);
149150
if (ReferenceAccess.singleton().haveCompressedReferences()) {
150-
UnsignedWord compressedBits = pointerBits.unsignedShiftRight(getCompressionShift());
151-
return KnownIntrinsics.heapBase().add(compressedBits.shiftLeft(getCompressionShift()));
151+
UnsignedWord compressedBits = pointerBits.unsignedShiftRight(ObjectHeader.getCompressionShift());
152+
return KnownIntrinsics.heapBase().add(compressedBits.shiftLeft(ObjectHeader.getCompressionShift()));
152153
} else {
153154
return (Pointer) pointerBits;
154155
}
@@ -378,9 +379,4 @@ static int getReferenceSize() {
378379
static boolean hasBase() {
379380
return ImageSingletons.lookup(CompressEncoding.class).hasBase();
380381
}
381-
382-
@Fold
383-
static int getCompressionShift() {
384-
return ReferenceAccess.singleton().getCompressEncoding().getShift();
385-
}
386382
}

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

Lines changed: 329 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import com.oracle.svm.core.deopt.DeoptimizedFrame;
6868
import com.oracle.svm.core.deopt.Deoptimizer;
6969
import com.oracle.svm.core.heap.Heap;
70+
import com.oracle.svm.core.hub.DynamicHub;
7071
import com.oracle.svm.core.jdk.UninterruptibleUtils.AtomicWord;
7172
import com.oracle.svm.core.locks.VMLockSupport;
7273
import com.oracle.svm.core.log.Log;
@@ -133,6 +134,18 @@ public static void printLocationInfo(Log log, UnsignedWord value, boolean allowJ
133134
}
134135
}
135136

137+
public static void printObjectInfo(Log log, Pointer ptr) {
138+
DynamicHub objHub = Heap.getHeap().getObjectHeader().readDynamicHubFromPointer(ptr);
139+
if (objHub == SubstrateUtil.cast(DynamicHub.class, DynamicHub.class)) {
140+
// The pointer is already a hub, so print some information about the hub.
141+
DynamicHub hub = (DynamicHub) ptr.toObject();
142+
log.string("is the hub of ").string(hub.getName());
143+
} else {
144+
// The pointer is an object, so print some information about the object's hub.
145+
log.string("is an object with hub=").string(objHub.getName());
146+
}
147+
}
148+
136149
/**
137150
* See {@link #printInformation(Log, Pointer, CodePointer, RegisterDumper.Context, boolean)}.
138151
*/

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,9 @@ public static int codeAlignment() {
528528
@Option(help = "Determines if VM internal threads (e.g., a dedicated VM operation or reference handling thread) are allowed in this image.", type = OptionType.Expert) //
529529
public static final HostedOptionKey<Boolean> AllowVMInternalThreads = new HostedOptionKey<>(true);
530530

531+
@Option(help = "Determines if debugging-specific helper methods are embedded into the image. Those methods can be called directly from the debugger to obtain or print additional information.", type = OptionType.Debug) //
532+
public static final HostedOptionKey<Boolean> IncludeDebugHelperMethods = new HostedOptionKey<>(false);
533+
531534
@APIOption(name = "-g", fixedValue = "2", customHelp = "generate debugging information")//
532535
@Option(help = "Insert debug info into the generated native image or library")//
533536
public static final HostedOptionKey<Integer> GenerateDebugInfo = new HostedOptionKey<>(0) {

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

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

27+
import org.graalvm.compiler.api.replacements.Fold;
2728
import org.graalvm.compiler.word.Word;
2829
import org.graalvm.nativeimage.Platform;
2930
import org.graalvm.nativeimage.Platforms;
@@ -70,11 +71,13 @@ public static DynamicHub readDynamicHubFromObject(Object o) {
7071
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
7172
public abstract DynamicHub readDynamicHubFromPointer(Pointer ptr);
7273

74+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
7375
public abstract Pointer readPotentialDynamicHubFromPointer(Pointer ptr);
7476

7577
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
7678
public abstract void initializeHeaderOfNewObject(Pointer objectPointer, Word objectHeader);
7779

80+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
7881
public boolean pointsToObjectHeader(Pointer ptr) {
7982
Pointer potentialDynamicHub = readPotentialDynamicHubFromPointer(ptr);
8083
if (Heap.getHeap().isInImageHeap(potentialDynamicHub)) {
@@ -84,4 +87,8 @@ public boolean pointsToObjectHeader(Pointer ptr) {
8487
return false;
8588
}
8689

90+
@Fold
91+
protected static int getCompressionShift() {
92+
return ReferenceAccess.singleton().getCompressEncoding().getShift();
93+
}
8794
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,14 +580,17 @@ public String getName() {
580580
return name;
581581
}
582582

583+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
583584
public boolean isInstanceClass() {
584585
return HubType.isInstance(hubType);
585586
}
586587

588+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
587589
public boolean isStoredContinuationClass() {
588590
return HubType.isStoredContinuation(hubType);
589591
}
590592

593+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
591594
public boolean isReferenceInstanceClass() {
592595
return HubType.isReferenceInstance(hubType);
593596
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/HubType.java

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

2727
import com.oracle.svm.core.annotate.DuplicatedInNativeCode;
28+
import com.oracle.svm.core.annotate.Uninterruptible;
2829

2930
@DuplicatedInNativeCode
3031
public enum HubType {
@@ -44,22 +45,27 @@ public enum HubType {
4445
this.value = value;
4546
}
4647

48+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
4749
public int getValue() {
4850
return value;
4951
}
5052

53+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
5154
public static boolean isInstance(int hubType) {
5255
return hubType <= StoredContinuation.getValue();
5356
}
5457

58+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
5559
public static boolean isReferenceInstance(int hubType) {
5660
return hubType == InstanceReference.getValue();
5761
}
5862

63+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
5964
public static boolean isStoredContinuation(int hubType) {
6065
return hubType == StoredContinuation.getValue();
6166
}
6267

68+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
6369
public static boolean isArray(int hubType) {
6470
return hubType >= TypeArray.getValue();
6571
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/LayoutEncoding.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ public static boolean isAbstract(int encoding) {
150150
return encoding == ABSTRACT_VALUE;
151151
}
152152

153+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
153154
public static boolean isInstance(int encoding) {
154155
return encoding > LAST_SPECIAL_VALUE;
155156
}

0 commit comments

Comments
 (0)