@@ -70,7 +70,7 @@ public class PosixJfrEmergencyDumpSupport implements com.oracle.svm.core.jfr.Jfr
70
70
@ BasedOnJDKFile ("https://github.com/openjdk/jdk/blob/jdk-26+2/src/hotspot/os/posix/include/jvm_md.h#L57" ) //
71
71
private static final int JVM_MAXPATHLEN = 4096 ;
72
72
@ 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 ;
74
74
private static final byte FILE_SEPARATOR = "/" .getBytes (StandardCharsets .UTF_8 )[0 ];
75
75
private static final byte DOT = "." .getBytes (StandardCharsets .UTF_8 )[0 ];
76
76
// It does not really matter what the name is.
@@ -88,37 +88,46 @@ public class PosixJfrEmergencyDumpSupport implements com.oracle.svm.core.jfr.Jfr
88
88
public PosixJfrEmergencyDumpSupport () {
89
89
}
90
90
91
+ @ Override
91
92
public void initialize () {
92
93
pidBytes = String .valueOf (ProcessHandle .current ().pid ()).getBytes (StandardCharsets .UTF_8 );
93
94
pathBuffer = NativeMemory .calloc (JVM_MAXPATHLEN , NmtCategory .JFR );
94
95
directory = WordFactory .nullPointer ();
95
96
}
96
97
98
+ @ Override
97
99
public void setRepositoryLocation (String dirText ) {
98
100
repositoryLocationBytes = dirText .getBytes (StandardCharsets .UTF_8 );
99
101
}
100
102
103
+ @ Override
101
104
public void setDumpPath (String dumpPathText ) {
102
105
dumpPathBytes = dumpPathText .getBytes (StandardCharsets .UTF_8 );
103
106
}
104
107
108
+ @ Override
105
109
public String getDumpPath () {
106
110
if (dumpPathBytes != null ) {
107
111
return new String (dumpPathBytes , StandardCharsets .UTF_8 );
108
112
}
109
113
return "" ;
110
114
}
111
115
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
114
121
@ BasedOnJDKFile ("https://github.com/openjdk/jdk/blob/jdk-26+3/src/hotspot/share/jfr/recorder/repository/jfrEmergencyDump.cpp#L433-L445" )
115
122
public RawFileDescriptor chunkPath () {
116
123
if (repositoryLocationBytes == null ) {
117
124
if (!openEmergencyDumpFile ()) {
118
125
return WordFactory .nullPointer ();
119
126
}
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
+ */
122
131
return emergencyFd ;
123
132
}
124
133
Log .log ().string ("Creating a new emergency chunk file in the JFR disk repository" ).newline ();
@@ -141,6 +150,7 @@ private RawFileDescriptor createEmergencyChunkPath() {
141
150
return getFileSupport ().create (getPathBuffer (), FileCreationMode .CREATE , FileAccessMode .READ_WRITE );
142
151
}
143
152
153
+ @ Override
144
154
@ BasedOnJDKFile ("https://github.com/openjdk/jdk/blob/jdk-26+2/src/hotspot/share/jfr/recorder/repository/jfrEmergencyDump.cpp#L409-L416" )
145
155
public void onVmError () {
146
156
Log .log ().string ("Attempting JFR Emergency Dump" ).newline ();
@@ -213,12 +223,6 @@ private GrowableWordArray iterateRepository(GrowableWordArray gwa) {
213
223
if (count > 0 ) {
214
224
GrowableWordArrayAccess .qsort (gwa , 0 , count - 1 , PosixJfrEmergencyDumpSupport ::compare );
215
225
}
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
- // }
222
226
}
223
227
return WordFactory .nullPointer ();
224
228
}
@@ -227,7 +231,7 @@ private GrowableWordArray iterateRepository(GrowableWordArray gwa) {
227
231
static int compare (Word a , Word b ) {
228
232
CCharPointer filenameA = (CCharPointer ) a ;
229
233
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 ));
231
235
if (cmp == 0 ) {
232
236
CCharPointer aDot = SubstrateUtil .strchr (filenameA , DOT );
233
237
CCharPointer bDot = SubstrateUtil .strchr (filenameB , DOT );
@@ -306,8 +310,8 @@ private CCharPointer getRepositoryLocation() {
306
310
}
307
311
308
312
/**
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).
311
315
*/
312
316
@ Uninterruptible (reason = "LibC.errno() must not be overwritten accidentally." )
313
317
private static int restartableOpen (CCharPointer directory , int flags , int mode ) {
@@ -363,8 +367,6 @@ private CCharPointer fullyQualified(CCharPointer fn) {
363
367
364
368
clearPathBuffer ();
365
369
366
- // TODO HS uses _path_buffer_file_name_offset to avoid building this part of th path each
367
- // time.
368
370
// Cached in RepositoryIterator::RepositoryIterator and used in fully_qualified
369
371
idx = writeToPathBuffer (repositoryLocationBytes , idx );
370
372
@@ -386,7 +388,8 @@ private void clearPathBuffer() {
386
388
LibC .memset (getPathBuffer (), Word .signed (0 ), Word .unsigned (JVM_MAXPATHLEN ));
387
389
}
388
390
389
- private int writeToPathBuffer (byte [] bytes , int idx ) {
391
+ private int writeToPathBuffer (byte [] bytes , int start ) {
392
+ int idx = start ;
390
393
for (int i = 0 ; i < bytes .length ; i ++) {
391
394
getPathBuffer ().write (idx ++, bytes [i ]);
392
395
}
@@ -412,6 +415,7 @@ private void closeDirectory() {
412
415
}
413
416
}
414
417
418
+ @ Override
415
419
public void teardown () {
416
420
closeEmergencyDumpFile ();
417
421
closeDirectory ();
0 commit comments