Skip to content

Commit 13d87e9

Browse files
[GR-48869] [GR-48569] Improve crash log output.
PullRequest: graal/15712
2 parents 771bf74 + 3e082c5 commit 13d87e9

File tree

17 files changed

+427
-88
lines changed

17 files changed

+427
-88
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ public HeapImpl(int pageSize) {
128128
this.gcImpl = new GCImpl();
129129
this.runtimeCodeInfoGcSupport = new RuntimeCodeInfoGCSupportImpl();
130130
HeapParameters.initialize();
131-
DiagnosticThunkRegistry.singleton().register(new DumpHeapSettingsAndStatistics());
132-
DiagnosticThunkRegistry.singleton().register(new DumpHeapUsage());
133-
DiagnosticThunkRegistry.singleton().register(new DumpChunkInformation());
131+
DiagnosticThunkRegistry.singleton().add(new DumpHeapSettingsAndStatistics());
132+
DiagnosticThunkRegistry.singleton().add(new DumpHeapUsage());
133+
DiagnosticThunkRegistry.singleton().add(new DumpChunkInformation());
134134
}
135135

136136
@Fold
@@ -647,7 +647,7 @@ public boolean printLocationInfo(Log log, UnsignedWord value, boolean allowJavaH
647647
if (printLocationInfo(log, ptr, allowJavaHeapAccess, allowUnsafeOperations)) {
648648
if (allowJavaHeapAccess && objectHeaderImpl.pointsToObjectHeader(ptr)) {
649649
log.indent(true);
650-
SubstrateDiagnostics.printObjectInfo(log, ptr);
650+
SubstrateDiagnostics.printObjectInfo(log, ptr.toObject());
651651
log.redent(false);
652652
}
653653
return true;
@@ -875,6 +875,8 @@ public void printDiagnostics(Log log, ErrorContext context, int maxDiagnosticLev
875875
log.string("Heap base: ").zhex(KnownIntrinsics.heapBase()).newline();
876876
}
877877
log.string("Object reference size: ").signed(ConfigurationValues.getObjectLayout().getReferenceSize()).newline();
878+
log.string("Reserved object header bits: 0b").number(Heap.getHeap().getObjectHeader().getReservedBitsMask(), 2, false).newline();
879+
878880
log.string("Aligned chunk size: ").unsigned(HeapParameters.getAlignedHeapChunkSize()).newline();
879881
log.string("Large array threshold: ").unsigned(HeapParameters.getLargeArrayThreshold()).newline();
880882

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,13 @@ public boolean walkObjects(ObjectVisitor visitor) {
166166
}
167167

168168
public void logUsage(Log log, boolean logIfEmpty) {
169-
UnsignedWord chunkBytes = getChunkBytes();
169+
UnsignedWord chunkBytes;
170+
if (isEdenSpace() && !VMOperation.isGCInProgress()) {
171+
chunkBytes = HeapImpl.getAccounting().getEdenUsedBytes();
172+
} else {
173+
chunkBytes = getChunkBytes();
174+
}
175+
170176
if (logIfEmpty || chunkBytes.aboveThan(0)) {
171177
log.string(getName()).string(": ").rational(chunkBytes, GCImpl.M, 2).string("M (")
172178
.rational(accounting.getAlignedChunkBytes(), GCImpl.M, 2).string("M in ").signed(accounting.getAlignedChunkCount()).string(" aligned chunks, ")
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright (c) 2023, 2023, 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.posix.linux;
26+
27+
import org.graalvm.compiler.core.common.NumUtil;
28+
import org.graalvm.nativeimage.StackValue;
29+
import org.graalvm.nativeimage.c.type.CCharPointer;
30+
import org.graalvm.word.Pointer;
31+
import org.graalvm.word.WordFactory;
32+
33+
import com.oracle.svm.core.SubstrateDiagnostics;
34+
import com.oracle.svm.core.SubstrateDiagnostics.DiagnosticThunkRegistry;
35+
import com.oracle.svm.core.SubstrateDiagnostics.ErrorContext;
36+
import com.oracle.svm.core.c.CGlobalData;
37+
import com.oracle.svm.core.c.CGlobalDataFactory;
38+
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
39+
import com.oracle.svm.core.feature.InternalFeature;
40+
import com.oracle.svm.core.heap.RestrictHeapAccess;
41+
import com.oracle.svm.core.log.Log;
42+
import com.oracle.svm.core.os.RawFileOperationSupport;
43+
44+
class DumpLinuxOSInfo extends SubstrateDiagnostics.DiagnosticThunk {
45+
private static final CGlobalData<CCharPointer> MAX_THREADS_PATH = CGlobalDataFactory.createCString("/proc/sys/kernel/threads-max");
46+
private static final CGlobalData<CCharPointer> MAX_MAPPINGS_PATH = CGlobalDataFactory.createCString("/proc/sys/vm/max_map_count");
47+
private static final CGlobalData<CCharPointer> MAX_PID_PATH = CGlobalDataFactory.createCString("/proc/sys/kernel/pid_max");
48+
49+
@Override
50+
public int maxInvocationCount() {
51+
return 1;
52+
}
53+
54+
@Override
55+
@RestrictHeapAccess(access = RestrictHeapAccess.Access.NO_ALLOCATION, reason = "Must not allocate while printing diagnostics.")
56+
public void printDiagnostics(Log log, ErrorContext context, int maxDiagnosticLevel, int invocationCount) {
57+
log.string("OS information:").indent(true);
58+
59+
log.string("Max threads: ");
60+
printFirstLine(log, MAX_THREADS_PATH.get());
61+
log.newline();
62+
63+
log.string("Max memory mappings: ");
64+
printFirstLine(log, MAX_MAPPINGS_PATH.get());
65+
log.newline();
66+
67+
log.string("Max PID: ");
68+
printFirstLine(log, MAX_PID_PATH.get());
69+
log.newline();
70+
71+
log.indent(false);
72+
}
73+
74+
private static void printFirstLine(Log log, CCharPointer filename) {
75+
RawFileOperationSupport fs = RawFileOperationSupport.nativeByteOrder();
76+
RawFileOperationSupport.RawFileDescriptor fd = fs.open(filename, RawFileOperationSupport.FileAccessMode.READ);
77+
if (!fs.isValid(fd)) {
78+
log.string("unknown");
79+
return;
80+
}
81+
82+
try {
83+
int bufferSize = 64;
84+
CCharPointer buffer = StackValue.get(bufferSize);
85+
long readBytes = fs.read(fd, (Pointer) buffer, WordFactory.unsigned(bufferSize));
86+
int length = countLineBytes(buffer, NumUtil.safeToInt(readBytes));
87+
log.string(buffer, length);
88+
} finally {
89+
fs.close(fd);
90+
}
91+
}
92+
93+
private static int countLineBytes(CCharPointer buffer, int len) {
94+
for (int i = 0; i < len; i++) {
95+
if (buffer.read(i) == '\n') {
96+
return i;
97+
}
98+
}
99+
return len;
100+
}
101+
}
102+
103+
@AutomaticallyRegisteredFeature
104+
class DumpLinuxOSInfoFeature implements InternalFeature {
105+
@Override
106+
public void afterRegistration(AfterRegistrationAccess access) {
107+
DiagnosticThunkRegistry.singleton().addAfter(new DumpLinuxOSInfo(), SubstrateDiagnostics.DumpMachineInfo.class);
108+
}
109+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public static void printHub(@SuppressWarnings("unused") IsolateThread thread, Po
264264
@CEntryPoint(name = "svm_dbg_print_obj", include = IncludeDebugHelperMethods.class, publishAs = Publish.SymbolOnly)
265265
@CEntryPointOptions(prologue = SetThreadAndHeapBasePrologue.class, epilogue = NoEpilogue.class)
266266
public static void printObject(@SuppressWarnings("unused") IsolateThread thread, Pointer objPtr) {
267-
SubstrateDiagnostics.printObjectInfo(Log.log(), objPtr);
267+
SubstrateDiagnostics.printObjectInfo(Log.log(), objPtr.toObject());
268268
Log.log().newline();
269269
}
270270

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2023, 2023, 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;
26+
27+
import org.graalvm.compiler.api.replacements.Fold;
28+
import org.graalvm.nativeimage.ImageSingletons;
29+
30+
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
31+
import com.oracle.svm.core.util.VMError;
32+
33+
@AutomaticallyRegisteredImageSingleton
34+
public class Processor {
35+
private int lastQueriedActiveProcessorCount = -1;
36+
37+
@Fold
38+
public static Processor singleton() {
39+
return ImageSingletons.lookup(Processor.class);
40+
}
41+
42+
public int getActiveProcessorCount() {
43+
VMError.guarantee(!SubstrateUtil.HOSTED, "must not be executed during the image build");
44+
45+
int result = getActiveProcessorCount0();
46+
lastQueriedActiveProcessorCount = result;
47+
return result;
48+
}
49+
50+
private static int getActiveProcessorCount0() {
51+
int optionValue = SubstrateOptions.ActiveProcessorCount.getValue();
52+
if (optionValue > 0) {
53+
return optionValue;
54+
}
55+
56+
if (SubstrateOptions.MultiThreaded.getValue()) {
57+
return Containers.activeProcessorCount();
58+
} else {
59+
return 1;
60+
}
61+
}
62+
63+
public int getLastQueriedActiveProcessorCount() {
64+
return lastQueriedActiveProcessorCount;
65+
}
66+
}

0 commit comments

Comments
 (0)