@@ -267,7 +267,7 @@ class MallocMemorySummary : AllStatic {
267
267
*
268
268
* 8 9 10 11 12 13 14 15 16 ++
269
269
* +--------+--------+--------+--------+--------+--------+--------+--------+ ------------------------
270
- * ... | bucket idx | pos idx | flags | unused | canary | ... User payload ....
270
+ * ... | malloc site table marker | flags | unused | canary | ... User payload ....
271
271
* +--------+--------+--------+--------+--------+--------+--------+--------+ ------------------------
272
272
*
273
273
* Layout on 32-bit:
@@ -279,7 +279,7 @@ class MallocMemorySummary : AllStatic {
279
279
*
280
280
* 8 9 10 11 12 13 14 15 16 ++
281
281
* +--------+--------+--------+--------+--------+--------+--------+--------+ ------------------------
282
- * ... | bucket idx | pos idx | flags | unused | canary | ... User payload ....
282
+ * ... | malloc site table marker | flags | unused | canary | ... User payload ....
283
283
* +--------+--------+--------+--------+--------+--------+--------+--------+ ------------------------
284
284
*
285
285
* Notes:
@@ -294,16 +294,12 @@ class MallocMemorySummary : AllStatic {
294
294
class MallocHeader {
295
295
296
296
NOT_LP64 (uint32_t _alt_canary);
297
- size_t _size;
298
- uint16_t _bucket_idx;
299
- uint16_t _pos_idx;
300
- uint8_t _flags;
301
- uint8_t _unused;
297
+ const size_t _size;
298
+ const uint32_t _mst_marker;
299
+ const uint8_t _flags;
300
+ const uint8_t _unused;
302
301
uint16_t _canary;
303
302
304
- #define MAX_MALLOCSITE_TABLE_SIZE (USHRT_MAX - 1 )
305
- #define MAX_BUCKET_LENGTH (USHRT_MAX - 1 )
306
-
307
303
static const uint16_t _header_canary_life_mark = 0xE99E ;
308
304
static const uint16_t _header_canary_dead_mark = 0xD99D ;
309
305
static const uint16_t _footer_canary_life_mark = 0xE88E ;
@@ -314,11 +310,7 @@ class MallocHeader {
314
310
// We discount sizes larger than these
315
311
static const size_t max_reasonable_malloc_size = LP64_ONLY(256 * G) NOT_LP64(3500 * M);
316
312
317
- // If block is broken, print out a report to tty (optionally with
318
- // hex dump surrounding the broken block), then trigger a fatal error
319
- void assert_block_integrity () const ;
320
313
void print_block_on_error (outputStream* st, address bad_address) const ;
321
- void mark_block_as_dead ();
322
314
323
315
static uint16_t build_footer (uint8_t b1, uint8_t b2) { return ((uint16_t )b1 << 8 ) | (uint16_t )b2; }
324
316
@@ -328,51 +320,32 @@ class MallocHeader {
328
320
329
321
public:
330
322
331
- MallocHeader (size_t size, MEMFLAGS flags, const NativeCallStack& stack, NMT_TrackingLevel level) {
323
+ MallocHeader (size_t size, MEMFLAGS flags, const NativeCallStack& stack, uint32_t mst_marker)
324
+ : _size(size), _mst_marker(mst_marker), _flags(NMTUtil::flag_to_index(flags)),
325
+ _unused (0 ), _canary(_header_canary_life_mark)
326
+ {
332
327
assert (size < max_reasonable_malloc_size, " Too large allocation size?" );
333
-
334
- _flags = NMTUtil::flag_to_index (flags);
335
- set_size (size);
336
- if (level == NMT_detail) {
337
- size_t bucket_idx;
338
- size_t pos_idx;
339
- if (record_malloc_site (stack, size, &bucket_idx, &pos_idx, flags)) {
340
- assert (bucket_idx <= MAX_MALLOCSITE_TABLE_SIZE, " Overflow bucket index" );
341
- assert (pos_idx <= MAX_BUCKET_LENGTH, " Overflow bucket position index" );
342
- _bucket_idx = (uint16_t )bucket_idx;
343
- _pos_idx = (uint16_t )pos_idx;
344
- }
345
- }
346
-
347
- _unused = 0 ;
348
- _canary = _header_canary_life_mark;
349
328
// On 32-bit we have some bits more, use them for a second canary
350
329
// guarding the start of the header.
351
330
NOT_LP64 (_alt_canary = _header_alt_canary_life_mark;)
352
331
set_footer (_footer_canary_life_mark); // set after initializing _size
353
-
354
- MallocMemorySummary::record_malloc (size, flags);
355
- MallocMemorySummary::record_new_malloc_header (sizeof (MallocHeader));
356
332
}
357
333
358
334
inline size_t size () const { return _size; }
359
335
inline MEMFLAGS flags () const { return (MEMFLAGS)_flags; }
336
+ inline uint32_t mst_marker () const { return _mst_marker; }
360
337
bool get_stack (NativeCallStack& stack) const ;
361
338
362
- // Cleanup tracking information and mark block as dead before the memory is released.
363
- void release ();
339
+ void mark_block_as_dead ();
364
340
365
341
// If block is broken, fill in a short descriptive text in out,
366
342
// an option pointer to the corruption in p_corruption, and return false.
367
343
// Return true if block is fine.
368
344
bool check_block_integrity (char * msg, size_t msglen, address* p_corruption) const ;
369
345
370
- private:
371
- inline void set_size (size_t size) {
372
- _size = size;
373
- }
374
- bool record_malloc_site (const NativeCallStack& stack, size_t size,
375
- size_t * bucket_idx, size_t * pos_idx, MEMFLAGS flags) const ;
346
+ // If block is broken, print out a report to tty (optionally with
347
+ // hex dump surrounding the broken block), then trigger a fatal error
348
+ void assert_block_integrity () const ;
376
349
};
377
350
378
351
// This needs to be true on both 64-bit and 32-bit platforms
@@ -385,15 +358,9 @@ class MallocTracker : AllStatic {
385
358
// Initialize malloc tracker for specific tracking level
386
359
static bool initialize (NMT_TrackingLevel level);
387
360
388
- // malloc tracking header size for specific tracking level
389
- static inline size_t malloc_header_size (NMT_TrackingLevel level) {
390
- return (level == NMT_off) ? 0 : sizeof (MallocHeader);
391
- }
392
-
393
- // malloc tracking footer size for specific tracking level
394
- static inline size_t malloc_footer_size (NMT_TrackingLevel level) {
395
- return (level == NMT_off) ? 0 : sizeof (uint16_t );
396
- }
361
+ // The overhead that is incurred by switching on NMT (we need, per malloc allocation,
362
+ // space for header and 16-bit footer)
363
+ static const size_t overhead_per_malloc = sizeof (MallocHeader) + sizeof (uint16_t );
397
364
398
365
// Parameter name convention:
399
366
// memblock : the beginning address for user data
@@ -405,30 +372,11 @@ class MallocTracker : AllStatic {
405
372
406
373
// Record malloc on specified memory block
407
374
static void * record_malloc (void * malloc_base, size_t size, MEMFLAGS flags,
408
- const NativeCallStack& stack, NMT_TrackingLevel level );
375
+ const NativeCallStack& stack);
409
376
410
377
// Record free on specified memory block
411
378
static void * record_free (void * memblock);
412
379
413
- // Offset memory address to header address
414
- static inline void * get_base (void * memblock);
415
- static inline void * get_base (void * memblock, NMT_TrackingLevel level) {
416
- if (memblock == NULL || level == NMT_off) return memblock;
417
- return (char *)memblock - malloc_header_size (level);
418
- }
419
-
420
- // Get memory size
421
- static inline size_t get_size (void * memblock) {
422
- MallocHeader* header = malloc_header (memblock);
423
- return header->size ();
424
- }
425
-
426
- // Get memory type
427
- static inline MEMFLAGS get_flags (void * memblock) {
428
- MallocHeader* header = malloc_header (memblock);
429
- return header->flags ();
430
- }
431
-
432
380
static inline void record_new_arena (MEMFLAGS flags) {
433
381
MallocMemorySummary::record_new_arena (flags);
434
382
}
@@ -451,8 +399,11 @@ class MallocTracker : AllStatic {
451
399
private:
452
400
static inline MallocHeader* malloc_header (void *memblock) {
453
401
assert (memblock != NULL , " NULL pointer" );
454
- MallocHeader* header = (MallocHeader*)((char *)memblock - sizeof (MallocHeader));
455
- return header;
402
+ return (MallocHeader*)((char *)memblock - sizeof (MallocHeader));
403
+ }
404
+ static inline const MallocHeader* malloc_header (const void *memblock) {
405
+ assert (memblock != NULL , " NULL pointer" );
406
+ return (const MallocHeader*)((const char *)memblock - sizeof (MallocHeader));
456
407
}
457
408
};
458
409
1 commit comments
openjdk-notifier[bot] commentedon Feb 25, 2022
Review
Issues