@@ -58,7 +58,7 @@ static void initializeEventFields(J9VMThread *currentThread, J9JFREvent *jfrEven
58
58
static int J9THREAD_PROC jfrSamplingThreadProc (void *entryArg);
59
59
static void jfrExecutionSampleCallback (J9VMThread *currentThread, IDATA handlerKey, void *userData);
60
60
static void jfrThreadCPULoadCallback (J9VMThread *currentThread, IDATA handlerKey, void *userData);
61
-
61
+ static bool areJFRBuffersReadyForWrite (J9VMThread *currentThread);
62
62
/* *
63
63
* Calculate the size in bytes of a JFR event.
64
64
*
@@ -129,6 +129,22 @@ jfrBufferNextDo(J9JFRBufferWalkState *walkState)
129
129
return (J9JFREvent*)next;
130
130
}
131
131
132
+ static bool
133
+ areJFRBuffersReadyForWrite (J9VMThread *currentThread)
134
+ {
135
+ bool result = true ;
136
+ J9JavaVM *vm = currentThread->javaVM ;
137
+
138
+ if ((!vm->jfrState .isStarted )
139
+ || (NULL == currentThread->jfrBuffer .bufferStart )
140
+ || (NULL == vm->jfrBuffer .bufferCurrent )
141
+ ) {
142
+ result = false ;
143
+ }
144
+
145
+ return result;
146
+ }
147
+
132
148
/* *
133
149
* Write out the contents of the global JFR buffer.
134
150
*
@@ -148,16 +164,18 @@ writeOutGlobalBuffer(J9VMThread *currentThread, bool finalWrite)
148
164
j9tty_printf (PORTLIB, " \n !!! writing global buffer %p of size %p\n " , currentThread, vm->jfrBuffer .bufferSize - vm->jfrBuffer .bufferRemaining );
149
165
#endif /* defined(DEBUG) */
150
166
151
- VM_JFRWriter::flushJFRDataToFile (currentThread, finalWrite);
167
+ if (areJFRBuffersReadyForWrite (currentThread)) {
168
+ VM_JFRWriter::flushJFRDataToFile (currentThread, finalWrite);
152
169
153
- /* Reset the buffer */
154
- vm->jfrBuffer .bufferRemaining = vm->jfrBuffer .bufferSize ;
155
- vm->jfrBuffer .bufferCurrent = vm->jfrBuffer .bufferStart ;
170
+ /* Reset the buffer */
171
+ vm->jfrBuffer .bufferRemaining = vm->jfrBuffer .bufferSize ;
172
+ vm->jfrBuffer .bufferCurrent = vm->jfrBuffer .bufferStart ;
156
173
157
174
158
175
#if defined(DEBUG)
159
- memset (vm->jfrBuffer .bufferStart , 0 , J9JFR_GLOBAL_BUFFER_SIZE);
176
+ memset (vm->jfrBuffer .bufferStart , 0 , J9JFR_GLOBAL_BUFFER_SIZE);
160
177
#endif /* defined(DEBUG) */
178
+ }
161
179
162
180
return true ;
163
181
}
@@ -180,7 +198,7 @@ flushBufferToGlobal(J9VMThread *currentThread, J9VMThread *flushThread)
180
198
UDATA bufferSize = flushThread->jfrBuffer .bufferCurrent - flushThread->jfrBuffer .bufferStart ;
181
199
bool success = true ;
182
200
183
- if (NULL == flushThread-> jfrBuffer . bufferStart ) {
201
+ if (areJFRBuffersReadyForWrite (currentThread) ) {
184
202
goto done;
185
203
}
186
204
@@ -284,7 +302,9 @@ reserveBuffer(J9VMThread *currentThread, UDATA size)
284
302
Assert_VM_true (((currentThread)->publicFlags & J9_PUBLIC_FLAGS_VM_ACCESS)
285
303
|| ((J9_XACCESS_EXCLUSIVE == vm->exclusiveAccessState ) || (J9_XACCESS_EXCLUSIVE == vm->safePointState )));
286
304
287
-
305
+ if (areJFRBuffersReadyForWrite (currentThread)) {
306
+ goto done;
307
+ }
288
308
289
309
/* If the event is larger than the buffer, fail without attemptiong to flush */
290
310
if (size <= currentThread->jfrBuffer .bufferSize ) {
0 commit comments