3434import org .graalvm .nativeimage .IsolateThread ;
3535import org .graalvm .nativeimage .Platform ;
3636import org .graalvm .nativeimage .Platforms ;
37- import org .graalvm .word .SignedWord ;
3837import org .graalvm .word .UnsignedWord ;
3938import org .graalvm .word .WordFactory ;
4039
4544import com .oracle .svm .core .jfr .traceid .JfrTraceIdEpoch ;
4645import com .oracle .svm .core .locks .VMMutex ;
4746import com .oracle .svm .core .os .RawFileOperationSupport ;
47+ import com .oracle .svm .core .os .RawFileOperationSupport .FileAccessMode ;
48+ import com .oracle .svm .core .os .RawFileOperationSupport .FileCreationMode ;
4849import com .oracle .svm .core .os .RawFileOperationSupport .RawFileDescriptor ;
4950import com .oracle .svm .core .sampler .SamplerBuffersAccess ;
5051import com .oracle .svm .core .thread .JavaVMOperation ;
@@ -89,8 +90,8 @@ public final class JfrChunkWriter implements JfrUnlockedChunkWriter {
8990 private boolean newChunk ;
9091 private boolean isFinal ;
9192 private long lastMetadataId ;
92- private SignedWord metadataPosition ;
93- private SignedWord lastCheckpointOffset ;
93+ private long metadataPosition ;
94+ private long lastCheckpointOffset ;
9495
9596 @ Platforms (Platform .HOSTED_ONLY .class )
9697 public JfrChunkWriter (JfrGlobalMemory globalMemory , JfrStackTraceRepository stackTraceRepo , JfrMethodRepository methodRepo , JfrTypeRepository typeRepo , JfrSymbolRepository symbolRepo ,
@@ -158,8 +159,8 @@ public void openFile(String outputFile) {
158159 newChunk = true ;
159160 isFinal = false ;
160161 lastMetadataId = -1 ;
161- metadataPosition = WordFactory . signed (- 1 ) ;
162- lastCheckpointOffset = WordFactory . signed (- 1 ) ;
162+ metadataPosition = - 1 ;
163+ lastCheckpointOffset = - 1 ;
163164
164165 writeFileHeader ();
165166 }
@@ -169,7 +170,7 @@ public void write(JfrBuffer buffer) {
169170 assert lock .isOwner ();
170171 assert buffer .isNonNull ();
171172 assert buffer .getBufferType () == JfrBufferType .C_HEAP || VMOperation .isInProgressAtSafepoint () || JfrBufferNodeAccess .isLockedByCurrentThread (buffer .getNode ());
172- assert buffer .getNode () == null || !JfrBufferNodeAccess .isRetired (buffer .getNode ());
173+ assert buffer .getNode (). isNull () || !JfrBufferNodeAccess .isRetired (buffer .getNode ());
173174
174175 UnsignedWord unflushedSize = JfrBufferAccess .getUnflushedSize (buffer );
175176 if (unflushedSize .equal (0 )) {
@@ -233,38 +234,37 @@ private void writeFileHeader() {
233234 getFileSupport ().write (fd , FILE_MAGIC );
234235 getFileSupport ().writeShort (fd , JFR_VERSION_MAJOR );
235236 getFileSupport ().writeShort (fd , JFR_VERSION_MINOR );
236- assert getFileSupport ().position (fd ). equal ( CHUNK_SIZE_OFFSET ) ;
237+ assert getFileSupport ().position (fd ) == CHUNK_SIZE_OFFSET ;
237238 getFileSupport ().writeLong (fd , 0L ); // chunk size
238239 getFileSupport ().writeLong (fd , 0L ); // last checkpoint offset
239240 getFileSupport ().writeLong (fd , 0L ); // metadata position
240241 getFileSupport ().writeLong (fd , chunkStartNanos );
241242 getFileSupport ().writeLong (fd , 0L ); // durationNanos
242243 getFileSupport ().writeLong (fd , chunkStartTicks );
243244 getFileSupport ().writeLong (fd , JfrTicks .getTicksFrequency ());
244- assert getFileSupport ().position (fd ). equal ( FILE_STATE_OFFSET ) ;
245+ assert getFileSupport ().position (fd ) == FILE_STATE_OFFSET ;
245246 getFileSupport ().writeByte (fd , getAndIncrementGeneration ());
246247 getFileSupport ().writeByte (fd , (byte ) 0 ); // padding
247248 getFileSupport ().writeShort (fd , computeHeaderFlags ());
248249 }
249250
250251 private void patchFileHeader (boolean flushpoint ) {
251252 assert lock .isOwner ();
252- assert metadataPosition . greaterThan ( 0 ) ;
253- assert lastCheckpointOffset . greaterThan ( 0 ) ;
253+ assert metadataPosition > 0 ;
254+ assert lastCheckpointOffset > 0 ;
254255
255256 byte generation = flushpoint ? getAndIncrementGeneration () : COMPLETE ;
256- SignedWord currentPos = getFileSupport ().position (fd );
257- long chunkSize = currentPos .rawValue ();
257+ long currentPos = getFileSupport ().position (fd );
258258 long durationNanos = JfrTicks .currentTimeNanos () - chunkStartNanos ;
259259
260- getFileSupport ().seek (fd , WordFactory . signed ( CHUNK_SIZE_OFFSET ) );
261- getFileSupport ().writeLong (fd , chunkSize );
262- getFileSupport ().writeLong (fd , lastCheckpointOffset . rawValue () );
263- getFileSupport ().writeLong (fd , metadataPosition . rawValue () );
260+ getFileSupport ().seek (fd , CHUNK_SIZE_OFFSET );
261+ getFileSupport ().writeLong (fd , currentPos );
262+ getFileSupport ().writeLong (fd , lastCheckpointOffset );
263+ getFileSupport ().writeLong (fd , metadataPosition );
264264 getFileSupport ().writeLong (fd , chunkStartNanos );
265265 getFileSupport ().writeLong (fd , durationNanos );
266266
267- getFileSupport ().seek (fd , WordFactory . signed ( FILE_STATE_OFFSET ) );
267+ getFileSupport ().seek (fd , FILE_STATE_OFFSET );
268268 getFileSupport ().writeByte (fd , generation );
269269 getFileSupport ().writeByte (fd , (byte ) 0 );
270270 getFileSupport ().writeShort (fd , computeHeaderFlags ());
@@ -308,20 +308,20 @@ private void writeThreadCheckpoint(boolean flushpoint) {
308308 private void writeCheckpointEvent (JfrCheckpointType type , JfrRepository [] repositories , boolean writeSerializers , boolean flushpoint ) {
309309 assert lock .isOwner ();
310310
311- SignedWord start = beginEvent ();
311+ long start = beginEvent ();
312312 writeCompressedLong (JfrReservedEvent .CHECKPOINT .getId ());
313313 writeCompressedLong (JfrTicks .elapsedTicks ());
314314 writeCompressedLong (0 ); // duration
315315 writeCompressedLong (getDeltaToLastCheckpoint (start ));
316316 writeByte (type .getId ());
317317
318- SignedWord poolCountPos = getFileSupport ().position (fd );
318+ long poolCountPos = getFileSupport ().position (fd );
319319 getFileSupport ().writeInt (fd , 0 ); // pool count (patched below)
320320
321321 int poolCount = writeSerializers ? writeSerializers () : 0 ;
322322 poolCount += writeConstantPools (repositories , flushpoint );
323323
324- SignedWord currentPos = getFileSupport ().position (fd );
324+ long currentPos = getFileSupport ().position (fd );
325325 getFileSupport ().seek (fd , poolCountPos );
326326 writePaddedInt (poolCount );
327327
@@ -331,11 +331,11 @@ private void writeCheckpointEvent(JfrCheckpointType type, JfrRepository[] reposi
331331 lastCheckpointOffset = start ;
332332 }
333333
334- private long getDeltaToLastCheckpoint (SignedWord startOfNewCheckpoint ) {
335- if (lastCheckpointOffset . lessThan ( 0 ) ) {
334+ private long getDeltaToLastCheckpoint (long startOfNewCheckpoint ) {
335+ if (lastCheckpointOffset < 0 ) {
336336 return 0L ;
337337 }
338- return lastCheckpointOffset . subtract ( startOfNewCheckpoint ). rawValue () ;
338+ return lastCheckpointOffset - startOfNewCheckpoint ;
339339 }
340340
341341 private int writeSerializers () {
@@ -367,7 +367,7 @@ private void writeMetadataEvent() {
367367 return ;
368368 }
369369
370- SignedWord start = beginEvent ();
370+ long start = beginEvent ();
371371 writeCompressedLong (JfrReservedEvent .METADATA .getId ());
372372 writeCompressedLong (JfrTicks .elapsedTicks ());
373373 writeCompressedLong (0 ); // duration
@@ -381,25 +381,25 @@ private void writeMetadataEvent() {
381381
382382 public boolean shouldRotateDisk () {
383383 assert lock .isOwner ();
384- return getFileSupport ().isValid (fd ) && getFileSupport ().size (fd ). greaterThan ( WordFactory . signed ( notificationThreshold )) ;
384+ return getFileSupport ().isValid (fd ) && getFileSupport ().size (fd ) > notificationThreshold ;
385385 }
386386
387387 @ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
388- public SignedWord beginEvent () {
389- SignedWord start = getFileSupport ().position (fd );
388+ public long beginEvent () {
389+ long start = getFileSupport ().position (fd );
390390 // Write a placeholder for the size. Will be patched by endEvent,
391391 getFileSupport ().writeInt (fd , 0 );
392392 return start ;
393393 }
394394
395395 @ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
396- public void endEvent (SignedWord start ) {
397- SignedWord end = getFileSupport ().position (fd );
398- SignedWord writtenBytes = end . subtract ( start ) ;
399- assert (int ) writtenBytes . rawValue () == writtenBytes . rawValue () ;
396+ public void endEvent (long start ) {
397+ long end = getFileSupport ().position (fd );
398+ long writtenBytes = end - start ;
399+ assert (int ) writtenBytes == writtenBytes ;
400400
401401 getFileSupport ().seek (fd , start );
402- writePaddedInt (writtenBytes . rawValue () );
402+ writePaddedInt (writtenBytes );
403403 getFileSupport ().seek (fd , end );
404404 }
405405
@@ -520,8 +520,8 @@ private void traverseThreadLocalBuffers(JfrBufferList list, boolean flushpoint)
520520
521521 while (node .isNonNull ()) {
522522 JfrBufferNode next = node .getNext ();
523- boolean success = JfrBufferNodeAccess .tryLock (node );
524- if (success ) {
523+ boolean lockAcquired = JfrBufferNodeAccess .tryLock (node );
524+ if (lockAcquired ) {
525525 JfrBuffer buffer = JfrBufferNodeAccess .getBuffer (node );
526526 if (buffer .isNull ()) {
527527 list .removeNode (node , prev );
@@ -530,9 +530,9 @@ private void traverseThreadLocalBuffers(JfrBufferList list, boolean flushpoint)
530530 continue ;
531531 }
532532
533- /* Skip retired nodes as they may contain invalid data. */
534- if (! JfrBufferNodeAccess . isRetired ( node )) {
535- try {
533+ try {
534+ /* Skip retired nodes as they may contain invalid data. */
535+ if (! JfrBufferNodeAccess . isRetired ( node )) {
536536 if (flushpoint ) {
537537 /*
538538 * I/O operations may be slow, so this flushes to the global buffers
@@ -548,13 +548,13 @@ private void traverseThreadLocalBuffers(JfrBufferList list, boolean flushpoint)
548548 * reinitialize the thread-local buffers as the individual threads will
549549 * handle space reclamation on their own time.
550550 */
551- } finally {
552- JfrBufferNodeAccess .unlock (node );
553551 }
552+ } finally {
553+ JfrBufferNodeAccess .unlock (node );
554554 }
555555 }
556556
557- assert success || flushpoint ;
557+ assert lockAcquired || flushpoint ;
558558 prev = node ;
559559 node = next ;
560560 }
@@ -565,8 +565,8 @@ private void flushGlobalMemory(boolean flushpoint) {
565565 JfrBufferList buffers = globalMemory .getBuffers ();
566566 JfrBufferNode node = buffers .getHead ();
567567 while (node .isNonNull ()) {
568- boolean success = JfrBufferNodeAccess .tryLock (node );
569- if (success ) {
568+ boolean lockAcquired = JfrBufferNodeAccess .tryLock (node );
569+ if (lockAcquired ) {
570570 try {
571571 JfrBuffer buffer = JfrBufferNodeAccess .getBuffer (node );
572572 write (buffer );
@@ -575,7 +575,7 @@ private void flushGlobalMemory(boolean flushpoint) {
575575 JfrBufferNodeAccess .unlock (node );
576576 }
577577 }
578- assert success || flushpoint ;
578+ assert lockAcquired || flushpoint ;
579579 node = node .getNext ();
580580 }
581581 }
@@ -647,7 +647,7 @@ private void changeEpoch() {
647647 * accessing the currently active buffers of other threads.
648648 */
649649 @ Uninterruptible (reason = "Prevent JFR recording." )
650- private void processSamplerBuffers () {
650+ private static void processSamplerBuffers () {
651651 assert VMOperation .isInProgressAtSafepoint ();
652652 assert ThreadingSupportImpl .isRecurringCallbackPaused ();
653653
@@ -660,7 +660,7 @@ private void processSamplerBuffers() {
660660 }
661661
662662 @ Uninterruptible (reason = "Prevent JFR recording." )
663- private void processSamplerBuffers0 () {
663+ private static void processSamplerBuffers0 () {
664664 SamplerBuffersAccess .processActiveBuffers ();
665665 SamplerBuffersAccess .processFullBuffers (false );
666666 }
0 commit comments