Skip to content

Commit 533da7a

Browse files
Emit old object sample and jdk.DumpReason events. Fix testEmergencyDump purge in-flight data bug. checkstyle
gate fixes cleanup
1 parent a831599 commit 533da7a

File tree

13 files changed

+227
-111
lines changed

13 files changed

+227
-111
lines changed

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/jfr/PosixJfrEmergencyDumpSupport.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class PosixJfrEmergencyDumpSupport implements com.oracle.svm.core.jfr.Jfr
7070
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-26+2/src/hotspot/os/posix/include/jvm_md.h#L57") //
7171
private static final int JVM_MAXPATHLEN = 4096;
7272
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-26+2/src/hotspot/share/jfr/recorder/repository/jfrEmergencyDump.cpp#L47") //
73-
private static int ISO8601_LEN = 19;
73+
private static final int ISO_8601_LEN = 19;
7474
private static final byte FILE_SEPARATOR = "/".getBytes(StandardCharsets.UTF_8)[0];
7575
private static final byte DOT = ".".getBytes(StandardCharsets.UTF_8)[0];
7676
// It does not really matter what the name is.
@@ -88,37 +88,46 @@ public class PosixJfrEmergencyDumpSupport implements com.oracle.svm.core.jfr.Jfr
8888
public PosixJfrEmergencyDumpSupport() {
8989
}
9090

91+
@Override
9192
public void initialize() {
9293
pidBytes = String.valueOf(ProcessHandle.current().pid()).getBytes(StandardCharsets.UTF_8);
9394
pathBuffer = NativeMemory.calloc(JVM_MAXPATHLEN, NmtCategory.JFR);
9495
directory = WordFactory.nullPointer();
9596
}
9697

98+
@Override
9799
public void setRepositoryLocation(String dirText) {
98100
repositoryLocationBytes = dirText.getBytes(StandardCharsets.UTF_8);
99101
}
100102

103+
@Override
101104
public void setDumpPath(String dumpPathText) {
102105
dumpPathBytes = dumpPathText.getBytes(StandardCharsets.UTF_8);
103106
}
104107

108+
@Override
105109
public String getDumpPath() {
106110
if (dumpPathBytes != null) {
107111
return new String(dumpPathBytes, StandardCharsets.UTF_8);
108112
}
109113
return "";
110114
}
111115

112-
// Either use create and use the dumpfile itself, or create a new file in the repository
113-
// location.
116+
/*
117+
* Either use create and use the dumpfile itself, or create a new file in the repository
118+
* location.
119+
*/
120+
@Override
114121
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-26+3/src/hotspot/share/jfr/recorder/repository/jfrEmergencyDump.cpp#L433-L445")
115122
public RawFileDescriptor chunkPath() {
116123
if (repositoryLocationBytes == null) {
117124
if (!openEmergencyDumpFile()) {
118125
return WordFactory.nullPointer();
119126
}
120-
// We can directly use the emergency dump file name as the new chunk since there are no
121-
// other chunk files.
127+
/*
128+
* We can directly use the emergency dump file name as the new chunk since there are no
129+
* other chunk files.
130+
*/
122131
return emergencyFd;
123132
}
124133
Log.log().string("Creating a new emergency chunk file in the JFR disk repository").newline();
@@ -141,6 +150,7 @@ private RawFileDescriptor createEmergencyChunkPath() {
141150
return getFileSupport().create(getPathBuffer(), FileCreationMode.CREATE, FileAccessMode.READ_WRITE);
142151
}
143152

153+
@Override
144154
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-26+2/src/hotspot/share/jfr/recorder/repository/jfrEmergencyDump.cpp#L409-L416")
145155
public void onVmError() {
146156
Log.log().string("Attempting JFR Emergency Dump").newline();
@@ -213,12 +223,6 @@ private GrowableWordArray iterateRepository(GrowableWordArray gwa) {
213223
if (count > 0) {
214224
GrowableWordArrayAccess.qsort(gwa, 0, count - 1, PosixJfrEmergencyDumpSupport::compare);
215225
}
216-
// for (int i=0; i < count; i ++){ // todo remove
217-
// String name =
218-
// org.graalvm.nativeimage.c.type.CTypeConversion.toJavaString(GrowableWordArrayAccess.read(gwa,
219-
// i));
220-
// System.out.println("chunk file: "+ name);
221-
// }
222226
}
223227
return WordFactory.nullPointer();
224228
}
@@ -227,7 +231,7 @@ private GrowableWordArray iterateRepository(GrowableWordArray gwa) {
227231
static int compare(Word a, Word b) {
228232
CCharPointer filenameA = (CCharPointer) a;
229233
CCharPointer filenameB = (CCharPointer) b;
230-
int cmp = LibC.strncmp(filenameA, filenameB, WordFactory.unsigned(ISO8601_LEN));
234+
int cmp = LibC.strncmp(filenameA, filenameB, WordFactory.unsigned(ISO_8601_LEN));
231235
if (cmp == 0) {
232236
CCharPointer aDot = SubstrateUtil.strchr(filenameA, DOT);
233237
CCharPointer bDot = SubstrateUtil.strchr(filenameB, DOT);
@@ -306,8 +310,8 @@ private CCharPointer getRepositoryLocation() {
306310
}
307311

308312
/**
309-
* See
310-
* {@link com.oracle.svm.core.posix.jvmstat.PosixPerfMemoryProvider#restartableOpen(CCharPointer, int, int)}
313+
* See com.oracle.svm.core.posix.jvmstat.PosixPerfMemoryProvider#restartableOpen(CCharPointer,
314+
* int, int).
311315
*/
312316
@Uninterruptible(reason = "LibC.errno() must not be overwritten accidentally.")
313317
private static int restartableOpen(CCharPointer directory, int flags, int mode) {
@@ -363,8 +367,6 @@ private CCharPointer fullyQualified(CCharPointer fn) {
363367

364368
clearPathBuffer();
365369

366-
// TODO HS uses _path_buffer_file_name_offset to avoid building this part of th path each
367-
// time.
368370
// Cached in RepositoryIterator::RepositoryIterator and used in fully_qualified
369371
idx = writeToPathBuffer(repositoryLocationBytes, idx);
370372

@@ -386,7 +388,8 @@ private void clearPathBuffer() {
386388
LibC.memset(getPathBuffer(), Word.signed(0), Word.unsigned(JVM_MAXPATHLEN));
387389
}
388390

389-
private int writeToPathBuffer(byte[] bytes, int idx) {
391+
private int writeToPathBuffer(byte[] bytes, int start) {
392+
int idx = start;
390393
for (int i = 0; i < bytes.length; i++) {
391394
getPathBuffer().write(idx++, bytes[i]);
392395
}
@@ -412,6 +415,7 @@ private void closeDirectory() {
412415
}
413416
}
414417

418+
@Override
415419
public void teardown() {
416420
closeEmergencyDumpFile();
417421
closeDirectory();

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrChunkFileWriter.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import static com.oracle.svm.core.jfr.JfrThreadLocal.getJavaBufferList;
2828
import static com.oracle.svm.core.jfr.JfrThreadLocal.getNativeBufferList;
2929

30-
import java.nio.charset.StandardCharsets;
31-
3230
import com.oracle.svm.core.jfr.oldobject.JfrOldObjectRepository;
3331
import com.oracle.svm.core.nmt.NmtCategory;
3432
import jdk.graal.compiler.word.Word;
@@ -172,10 +170,10 @@ public void openFile(String outputFile) {
172170

173171
// Used by JFR emergency dump
174172
@Override
175-
public void openFile(RawFileDescriptor fd) {
173+
public void openFile(RawFileDescriptor file) {
176174
assert lock.isOwner();
177175
filename = null;
178-
this.fd = fd;
176+
fd = file;
179177
openFile0();
180178
}
181179

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrEmergencyDumpFeature.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,20 @@
2929
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
3030
import com.oracle.svm.core.feature.InternalFeature;
3131

32+
import jdk.graal.compiler.api.replacements.Fold;
33+
34+
import org.graalvm.nativeimage.ImageSingletons;
35+
3236
/**
3337
* The JFR emergency dump mechanism uses platform-specific implementations (see {@link JfrEmergencyDumpSupport}).
3438
*/
3539
@AutomaticallyRegisteredFeature
3640
public class JfrEmergencyDumpFeature implements InternalFeature {
41+
@Fold
42+
static boolean isPresent() {
43+
return ImageSingletons.contains(JfrEmergencyDumpSupport.class);
44+
}
45+
3746
@Override
3847
public boolean isInConfiguration(IsInConfigurationAccess access) {
3948
return VMInspectionOptions.hasJfrSupport();

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrEmergencyDumpSupport.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
1+
/*
2+
* Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2025, 2025, Red Hat Inc. All rights reserved.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation. Oracle designates this
9+
* particular file as subject to the "Classpath" exception as provided
10+
* by Oracle in the LICENSE file that accompanied this code.
11+
*
12+
* This code is distributed in the hope that it will be useful, but WITHOUT
13+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15+
* version 2 for more details (a copy is included in the LICENSE file that
16+
* accompanied this code).
17+
*
18+
* You should have received a copy of the GNU General Public License version
19+
* 2 along with this work; if not, write to the Free Software Foundation,
20+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21+
*
22+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23+
* or visit www.oracle.com if you need additional information or have any
24+
* questions.
25+
*/
26+
127
package com.oracle.svm.core.jfr;
28+
229
import com.oracle.svm.core.os.RawFileOperationSupport;
330
import org.graalvm.nativeimage.ImageSingletons;
431

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrEvent.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public final class JfrEvent {
7474
public static final JfrEvent ObjectAllocationSample = create("jdk.ObjectAllocationSample", 5, JfrEventFlags.SupportsThrottling);
7575
public static final JfrEvent NativeMemoryUsage = create("jdk.NativeMemoryUsage");
7676
public static final JfrEvent NativeMemoryUsageTotal = create("jdk.NativeMemoryUsageTotal");
77+
public static final JfrEvent DumpReason = create("jdk.DumpReason");
7778

7879
private final long id;
7980
private final String name;

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrFeature.java

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

2727
import java.util.Arrays;
28-
import java.util.Collections;
2928
import java.util.List;
3029

3130
import org.graalvm.nativeimage.ImageSingletons;
@@ -155,7 +154,7 @@ private static HotSpotDiagnosticMXBean getDiagnosticBean() {
155154

156155
@Override
157156
public List<Class<? extends Feature>> getRequiredFeatures() {
158-
return Arrays.asList(ThreadListenerSupportFeature.class, com.oracle.svm.core.jfr.JfrEmergencyDumpFeature.class);
157+
return Arrays.asList(ThreadListenerSupportFeature.class, JfrEmergencyDumpFeature.class);
159158
}
160159

161160
@Override

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrRecorderThread.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ private void work() {
111111
}
112112

113113
void endRecording() {
114-
// com.oracle.svm.core.jfr.SubstrateJVM.get().vmErrorRotation();
115114
lock.lock();
116115
try {
117116
SubstrateJVM.JfrEndRecordingOperation vmOp = new SubstrateJVM.JfrEndRecordingOperation();

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrSymbolRepository.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.graalvm.word.WordFactory;
3838

3939
import com.oracle.svm.core.Uninterruptible;
40-
import com.oracle.svm.core.c.struct.PinnedObjectField;
4140
import com.oracle.svm.core.collections.AbstractUninterruptibleHashtable;
4241
import com.oracle.svm.core.collections.UninterruptibleEntry;
4342
import com.oracle.svm.core.heap.Heap;
@@ -85,7 +84,6 @@ public long getSymbolId(String imageHeapString, boolean previousEpoch, boolean r
8584
return 0;
8685
}
8786

88-
assert Heap.getHeap().isInImageHeap("");
8987
assert Heap.getHeap().isInImageHeap(imageHeapString);
9088
int length = 0;
9189
length = UninterruptibleUtils.String.modifiedUTF8Length(imageHeapString, false);
@@ -102,7 +100,7 @@ public long getSymbolId(String imageHeapString, boolean previousEpoch, boolean r
102100
public long getSymbolId(PointerBase buffer, UnsignedWord length, int hash, boolean previousEpoch) {
103101
com.oracle.svm.core.util.VMError.guarantee(buffer.isNonNull());
104102
JfrSymbol symbol = StackValue.get(JfrSymbol.class);
105-
symbol.setModifiedUTF8(buffer); // *** symbol in native memory
103+
symbol.setModifiedUTF8(buffer); // symbol allocated in native memory
106104
symbol.setLength(length);
107105
symbol.setHash(hash);
108106

@@ -134,7 +132,7 @@ public long getSymbolId(PointerBase buffer, UnsignedWord length, int hash, boole
134132
JfrNativeEventWriterDataAccess.initialize(data, epochData.buffer);
135133

136134
JfrNativeEventWriter.putLong(data, newEntry.getId());
137-
JfrNativeEventWriter.putString(data, (org.graalvm.word.Pointer) newEntry.getModifiedUTF8(), (int) newEntry.getLength().rawValue());
135+
JfrNativeEventWriter.putString(data, (Pointer) newEntry.getModifiedUTF8(), (int) newEntry.getLength().rawValue());
138136
if (!JfrNativeEventWriter.commit(data)) {
139137
return 0L;
140138
}

0 commit comments

Comments
 (0)