@@ -66,6 +66,7 @@ enum MetadataTypeID {
66
66
ThreadEndID = 3 ,
67
67
ThreadSleepID = 4 ,
68
68
ThreadParkID = 5 ,
69
+ MonitorEnterID = 6 ,
69
70
MonitorWaitID = 7 ,
70
71
JVMInformationID = 87 ,
71
72
OSInformationID = 88 ,
@@ -140,6 +141,8 @@ class VM_JFRChunkWriter {
140
141
static constexpr int JFR_CHUNK_HEADER_SIZE = 68 ;
141
142
142
143
/* conservative sizing for JFR chunk */
144
+ static constexpr int LEB128_32_SIZE = 5 ;
145
+ static constexpr int LEB128_64_SIZE = 9 ;
143
146
static constexpr int STRING_HEADER_LENGTH = sizeof (U_64);
144
147
static constexpr int CHECKPOINT_EVENT_HEADER_AND_FOOTER = 68 ;
145
148
static constexpr int STRING_CONSTANT_SIZE = 128 ;
@@ -159,6 +162,7 @@ class VM_JFRChunkWriter {
159
162
static constexpr int THREAD_END_EVENT_SIZE = (4 * sizeof (U_64)) + sizeof (U_32);
160
163
static constexpr int THREAD_SLEEP_EVENT_SIZE = (7 * sizeof (U_64)) + sizeof (U_32);
161
164
static constexpr int MONITOR_WAIT_EVENT_SIZE = (9 * sizeof (U_64)) + sizeof (U_32);
165
+ static constexpr int MONITOR_ENTER_EVENT_SIZE = sizeof (U_32) + (3 * LEB128_64_SIZE) + (5 * LEB128_32_SIZE);
162
166
static constexpr int THREAD_PARK_EVENT_SIZE = (9 * sizeof (U_64)) + sizeof (U_32);
163
167
static constexpr int JVM_INFORMATION_EVENT_SIZE = 3000 ;
164
168
static constexpr int PHYSICAL_MEMORY_EVENT_SIZE = (4 * sizeof (U_64)) + sizeof (U_32);
@@ -366,6 +370,8 @@ class VM_JFRChunkWriter {
366
370
367
371
pool_do (_constantPoolTypes.getMonitorWaitTable (), &writeMonitorWaitEvent, _bufferWriter);
368
372
373
+ pool_do (_constantPoolTypes.getMonitorEnterTable (), &writeMonitorEnterEvent, _bufferWriter);
374
+
369
375
pool_do (_constantPoolTypes.getThreadParkTable (), &writeThreadParkEvent, _bufferWriter);
370
376
371
377
pool_do (_constantPoolTypes.getCPULoadTable (), &writeCPULoadEvent, _bufferWriter);
@@ -583,6 +589,45 @@ class VM_JFRChunkWriter {
583
589
writeEventSize (_bufferWriter, dataStart);
584
590
}
585
591
592
+ static void
593
+ writeMonitorEnterEvent (void *anElement, void *userData)
594
+ {
595
+ MonitorEnterEntry *entry = (MonitorEnterEntry *)anElement;
596
+ VM_BufferWriter *_bufferWriter = (VM_BufferWriter *)userData;
597
+
598
+ /* reserve size field */
599
+ U_8 *dataStart = _bufferWriter->getAndIncCursor (sizeof (U_32));
600
+
601
+ /* write event type */
602
+ _bufferWriter->writeLEB128 (MonitorEnterID);
603
+
604
+ /* write start time - this is when the sleep started not when it ended so we
605
+ * need to subtract the duration since the event is emitted when the sleep ends.
606
+ */
607
+ _bufferWriter->writeLEB128 (entry->ticks - entry->duration );
608
+
609
+ /* write duration time which is always in ticks, in our case nanos */
610
+ _bufferWriter->writeLEB128 (entry->duration );
611
+
612
+ /* write event thread index */
613
+ _bufferWriter->writeLEB128 (entry->eventThreadIndex );
614
+
615
+ /* stacktrace index */
616
+ _bufferWriter->writeLEB128 (entry->stackTraceIndex );
617
+
618
+ /* monitor class index */
619
+ _bufferWriter->writeLEB128 (entry->monitorClass );
620
+
621
+ /* notifier thread index */
622
+ _bufferWriter->writeLEB128 (entry->previousOwnerThread );
623
+
624
+ /* address of monitor */
625
+ _bufferWriter->writeLEB128 (entry->monitorAddress );
626
+
627
+ /* write size */
628
+ writeEventSize (_bufferWriter, dataStart);
629
+ }
630
+
586
631
static void
587
632
writeThreadParkEvent (void *anElement, void *userData)
588
633
{
@@ -797,6 +842,8 @@ class VM_JFRChunkWriter {
797
842
798
843
requiredBufferSize += (_constantPoolTypes.getMonitorWaitCount () * MONITOR_WAIT_EVENT_SIZE);
799
844
845
+ requiredBufferSize += (_constantPoolTypes.getMonitorEnterCount () * MONITOR_ENTER_EVENT_SIZE);
846
+
800
847
requiredBufferSize += (_constantPoolTypes.getThreadParkCount () * THREAD_PARK_EVENT_SIZE);
801
848
802
849
requiredBufferSize += JVM_INFORMATION_EVENT_SIZE;
0 commit comments