Skip to content

Commit 1c51045

Browse files
[GR-33548] Improve Native Image diagnostics.
PullRequest: graal/14143
2 parents 08e3ce6 + 1bf366b commit 1c51045

File tree

24 files changed

+410
-208
lines changed

24 files changed

+410
-208
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ interface LINUX extends InternalPlatform.PLATFORM_JNI, InternalPlatform.NATIVE_O
179179
* @since 21.0
180180
*/
181181
default String getOS() {
182-
return LINUX.class.getSimpleName().toLowerCase();
182+
return "linux";
183183
}
184184
}
185185

@@ -196,7 +196,7 @@ interface ANDROID extends LINUX {
196196
* @since 21.0
197197
*/
198198
default String getOS() {
199-
return ANDROID.class.getSimpleName().toLowerCase();
199+
return "android";
200200
}
201201
}
202202

@@ -221,7 +221,7 @@ interface IOS extends DARWIN {
221221
* @since 21.0
222222
*/
223223
default String getOS() {
224-
return IOS.class.getSimpleName().toLowerCase();
224+
return "ios";
225225
}
226226
}
227227

@@ -255,7 +255,7 @@ interface WINDOWS extends InternalPlatform.PLATFORM_JNI, InternalPlatform.NATIVE
255255
* @since 21.0
256256
*/
257257
default String getOS() {
258-
return WINDOWS.class.getSimpleName().toLowerCase();
258+
return "windows";
259259
}
260260
}
261261

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.graalvm.nativeimage.c.function.CEntryPoint.Publish;
2929
import org.graalvm.nativeimage.c.function.CEntryPointLiteral;
3030
import org.graalvm.nativeimage.c.struct.SizeOf;
31+
import org.graalvm.nativeimage.c.type.VoidPointer;
3132
import org.graalvm.word.PointerBase;
3233
import org.graalvm.word.WordFactory;
3334

@@ -77,7 +78,10 @@ protected void printSignalInfo(Log log, PointerBase signalInfo) {
7778
if (sigInfo.si_errno() != 0) {
7879
log.string(", si_errno: ").signed(sigInfo.si_errno());
7980
}
80-
log.string(", si_addr: ").zhex(sigInfo.si_addr());
81+
82+
VoidPointer addr = sigInfo.si_addr();
83+
log.string(", si_addr: ");
84+
printSegfaultAddressInfo(log, addr.rawValue());
8185
log.newline();
8286
}
8387
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ protected void printSignalInfo(Log log, PointerBase signalInfo) {
119119
} else {
120120
log.string(", ExceptionInformation=").zhex(operation);
121121
}
122-
log.string(" ").zhex(exInfo.addressOf(1).read());
122+
log.string(" ");
123+
printSegfaultAddressInfo(log, exInfo.addressOf(1).read());
123124
} else {
124125
if (numParameters > 0) {
125126
log.string(", ExceptionInformation=");

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,17 @@
2626

2727
import java.util.EnumSet;
2828

29+
import org.graalvm.compiler.api.replacements.Fold;
30+
import org.graalvm.nativeimage.ImageSingletons;
31+
2932
import jdk.vm.ci.code.Architecture;
3033

3134
public interface CPUFeatureAccess {
35+
@Fold
36+
static CPUFeatureAccess singleton() {
37+
return ImageSingletons.lookup(CPUFeatureAccess.class);
38+
}
39+
3240
int verifyHostSupportsArchitectureEarly();
3341

3442
void verifyHostSupportsArchitectureEarlyOrExit();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
import com.oracle.svm.core.thread.PlatformThreads;
7474
import com.oracle.svm.core.thread.ThreadListenerSupport;
7575
import com.oracle.svm.core.thread.VMThreads;
76-
import com.oracle.svm.core.util.Counter;
76+
import com.oracle.svm.core.util.CounterSupport;
7777
import com.oracle.svm.core.util.VMError;
7878

7979
@InternalVMMethod
@@ -206,7 +206,7 @@ private static void runShutdown0() {
206206
*/
207207
RuntimeSupport.getRuntimeSupport().shutdown();
208208

209-
Counter.logValues(Log.log());
209+
CounterSupport.singleton().logValues(Log.log());
210210
}
211211

212212
@Uninterruptible(reason = "Thread state not set up yet.")

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

Lines changed: 182 additions & 119 deletions
Large diffs are not rendered by default.

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
@@ -867,6 +867,9 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, String ol
867867
}
868868
};
869869

870+
@Option(help = "Specifies the number of entries that diagnostic buffers have.", type = OptionType.Debug)//
871+
public static final HostedOptionKey<Integer> DiagnosticBufferSize = new HostedOptionKey<>(30);
872+
870873
@SuppressWarnings("unused")//
871874
@APIOption(name = "configure-reflection-metadata")//
872875
@Option(help = "Enable runtime instantiation of reflection objects for non-invoked methods.", type = OptionType.Expert, deprecated = true)//

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,15 @@ private static void dumpInterruptibly(PointerBase signalInfo, RegisterDumper.Con
187187
logHandler.fatalError();
188188
}
189189

190+
protected static void printSegfaultAddressInfo(Log log, long addr) {
191+
log.zhex(addr);
192+
if (addr != 0) {
193+
long delta = addr - CurrentIsolate.getIsolate().rawValue();
194+
String sign = (delta >= 0 ? "+" : "-");
195+
log.string("(heapBase ").string(sign).signed(delta).string(")");
196+
}
197+
}
198+
190199
static class SingleIsolateSegfaultSetup implements IsolateListener {
191200

192201
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ public static void setEncodings(CodeInfo info, NonmovableObjectArray<Object> obj
314314
}
315315

316316
public static Log log(CodeInfo info, Log log) {
317-
return info.isNull() ? log.string("null") : log.string(CodeInfo.class.getName()).string("@").hex(info);
317+
return info.isNull() ? log.string("null") : log.string("CodeInfo@").hex(info);
318318
}
319319

320320
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,8 @@ static CodeInfoDecoderCounters counters() {
515515
/**
516516
* This class can be used to iterate the Java-level stack trace information for a given
517517
* instruction pointer (IP). A single physical stack frame may correspond to multiple Java-level
518-
* stack frames.
518+
* stack frames. Iteration starts in the deepest inlined method and ends at the compilation
519+
* root.
519520
*/
520521
public static class FrameInfoCursor {
521522
private final ReusableTypeReader frameInfoReader = new ReusableTypeReader();
@@ -550,6 +551,12 @@ public boolean advance() {
550551
return result != null;
551552
}
552553

554+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
555+
public boolean hasCaller() {
556+
assert result != null;
557+
return !state.isDone;
558+
}
559+
553560
/**
554561
* Returns the information for the current frame.
555562
*

0 commit comments

Comments
 (0)