@@ -49,6 +49,8 @@ const int RECORDING_BUFFER_LIMIT = RECORDING_BUFFER_SIZE - 4096;
49
49
const int MAX_STRING_LENGTH = 8191 ;
50
50
const u64 MAX_JLONG = 0x7fffffffffffffffULL ;
51
51
const u64 MIN_JLONG = 0x8000000000000000ULL ;
52
+ const int MAX_JFR_EVENT_SIZE = 256 ;
53
+ const int JFR_EVENT_FLUSH_THRESHOLD = RECORDING_BUFFER_LIMIT - MAX_JFR_EVENT_SIZE;
52
54
53
55
54
56
static SpinLock _rec_lock (1 );
@@ -718,7 +720,7 @@ class Recording {
718
720
buf->reset ();
719
721
}
720
722
721
- void flushIfNeeded (Buffer* buf, int limit = RECORDING_BUFFER_LIMIT ) {
723
+ void flushIfNeeded (Buffer* buf, int limit = JFR_EVENT_FLUSH_THRESHOLD ) {
722
724
if (buf->offset () >= limit) {
723
725
flush (buf);
724
726
}
@@ -1197,6 +1199,12 @@ class Recording {
1197
1199
}
1198
1200
}
1199
1201
1202
+ void writeEventSizePrefix (Buffer* buf, int start) {
1203
+ int size = buf->offset () - start;
1204
+ assert (size < MAX_JFR_EVENT_SIZE);
1205
+ buf->put8 (start, size);
1206
+ }
1207
+
1200
1208
void recordExecutionSample (Buffer* buf, int tid, u32 call_trace_id, ExecutionEvent* event) {
1201
1209
int start = buf->skip (1 );
1202
1210
buf->putVar64 (T_EXECUTION_SAMPLE);
@@ -1206,7 +1214,7 @@ class Recording {
1206
1214
buf->putVar64 (event->_thread_state );
1207
1215
buf->putVar64 (event->_weight );
1208
1216
writeContext (buf, Contexts::get (tid));
1209
- buf-> put8 (start, buf-> offset () - start);
1217
+ writeEventSizePrefix ( buf, start);
1210
1218
flushIfNeeded (buf);
1211
1219
}
1212
1220
@@ -1219,7 +1227,7 @@ class Recording {
1219
1227
buf->putVar64 (event->_thread_state );
1220
1228
buf->putVar64 (event->_weight );
1221
1229
writeContext (buf, Contexts::get (tid));
1222
- buf-> put8 (start, buf-> offset () - start);
1230
+ writeEventSizePrefix ( buf, start);
1223
1231
flushIfNeeded (buf);
1224
1232
}
1225
1233
@@ -1233,8 +1241,8 @@ class Recording {
1233
1241
buf->putVar64 (event->_num_failed_samples );
1234
1242
buf->putVar64 (event->_num_exited_threads );
1235
1243
buf->putVar64 (event->_num_permission_denied );
1236
- buf-> put8 (start, buf-> offset () - start);
1237
- flushIfNeeded (buf);
1244
+ writeEventSizePrefix ( buf, start);
1245
+ flushIfNeeded (buf);
1238
1246
}
1239
1247
1240
1248
void recordTraceRoot (Buffer* buf, int tid, TraceRootEvent* event) {
@@ -1246,7 +1254,7 @@ class Recording {
1246
1254
buf->put8 (0 );
1247
1255
buf->putVar32 (event->_label );
1248
1256
buf->putVar64 (event->_local_root_span_id );
1249
- buf-> put8 (start, buf-> offset () - start);
1257
+ writeEventSizePrefix ( buf, start);
1250
1258
flushIfNeeded (buf);
1251
1259
}
1252
1260
@@ -1260,7 +1268,7 @@ class Recording {
1260
1268
buf->putVar64 (event->_size );
1261
1269
buf->putFloat (event->_weight );
1262
1270
writeContext (buf, Contexts::get (tid));
1263
- buf-> put8 (start, buf-> offset () - start);
1271
+ writeEventSizePrefix ( buf, start);
1264
1272
flushIfNeeded (buf);
1265
1273
}
1266
1274
@@ -1275,7 +1283,7 @@ class Recording {
1275
1283
buf->putVar64 (event->_alloc ._size );
1276
1284
buf->putFloat (event->_alloc ._weight );
1277
1285
writeContext (buf, event->_ctx );
1278
- buf-> put8 (start, buf-> offset () - start);
1286
+ writeEventSizePrefix ( buf, start);
1279
1287
flushIfNeeded (buf);
1280
1288
}
1281
1289
@@ -1290,7 +1298,7 @@ class Recording {
1290
1298
buf->put8 (0 );
1291
1299
buf->putVar64 (event->_address );
1292
1300
writeContext (buf, Contexts::get (tid));
1293
- buf-> put8 (start, buf-> offset () - start);
1301
+ writeEventSizePrefix ( buf, start);
1294
1302
flushIfNeeded (buf);
1295
1303
}
1296
1304
@@ -1305,7 +1313,7 @@ class Recording {
1305
1313
buf->putVar64 (event->_timeout );
1306
1314
buf->putVar64 (MIN_JLONG);
1307
1315
buf->putVar64 (event->_address );
1308
- buf-> put8 (start, buf-> offset () - start);
1316
+ writeEventSizePrefix ( buf, start);
1309
1317
flushIfNeeded (buf);
1310
1318
}
1311
1319
@@ -1316,7 +1324,7 @@ class Recording {
1316
1324
buf->putFloat (proc_user);
1317
1325
buf->putFloat (proc_system);
1318
1326
buf->putFloat (machine_total);
1319
- buf-> put8 (start, buf-> offset () - start);
1327
+ writeEventSizePrefix ( buf, start);
1320
1328
flushIfNeeded (buf);
1321
1329
}
1322
1330
0 commit comments