@@ -64,9 +64,6 @@ class OopMapCacheEntry: private InterpreterOopMap {
64
64
public:
65
65
OopMapCacheEntry () : InterpreterOopMap() {
66
66
_next = nullptr ;
67
- #ifdef ASSERT
68
- _resource_allocate_bit_mask = false ;
69
- #endif
70
67
}
71
68
};
72
69
@@ -175,9 +172,13 @@ class VerifyClosure : public OffsetClosure {
175
172
176
173
InterpreterOopMap::InterpreterOopMap () {
177
174
initialize ();
178
- #ifdef ASSERT
179
- _resource_allocate_bit_mask = true ;
180
- #endif
175
+ }
176
+
177
+ InterpreterOopMap::~InterpreterOopMap () {
178
+ if (has_valid_mask () && mask_size () > small_mask_limit) {
179
+ assert (_bit_mask[0 ] != 0 , " should have pointer to C heap" );
180
+ FREE_C_HEAP_ARRAY (uintptr_t , _bit_mask[0 ]);
181
+ }
181
182
}
182
183
183
184
bool InterpreterOopMap::is_empty () const {
@@ -397,35 +398,24 @@ void OopMapCacheEntry::deallocate(OopMapCacheEntry* const entry) {
397
398
398
399
// Implementation of OopMapCache
399
400
400
- void InterpreterOopMap::resource_copy (OopMapCacheEntry* from) {
401
- assert (_resource_allocate_bit_mask,
402
- " Should not resource allocate the _bit_mask" );
401
+ void InterpreterOopMap::copy_from (const OopMapCacheEntry* src) {
402
+ // The expectation is that this InterpreterOopMap is recently created
403
+ // and empty. It is used to get a copy of a cached entry.
404
+ assert (!has_valid_mask (), " InterpreterOopMap object can only be filled once" );
405
+ assert (src->has_valid_mask (), " Cannot copy entry with an invalid mask" );
403
406
404
- set_method (from ->method ());
405
- set_bci (from ->bci ());
406
- set_mask_size (from ->mask_size ());
407
- set_expression_stack_size (from ->expression_stack_size ());
408
- _num_oops = from ->num_oops ();
407
+ set_method (src ->method ());
408
+ set_bci (src ->bci ());
409
+ set_mask_size (src ->mask_size ());
410
+ set_expression_stack_size (src ->expression_stack_size ());
411
+ _num_oops = src ->num_oops ();
409
412
410
413
// Is the bit mask contained in the entry?
411
- if (from->mask_size () <= small_mask_limit) {
412
- memcpy ((void *)_bit_mask, (void *)from->_bit_mask ,
413
- mask_word_size () * BytesPerWord);
414
+ if (src->mask_size () <= small_mask_limit) {
415
+ memcpy (_bit_mask, src->_bit_mask , mask_word_size () * BytesPerWord);
414
416
} else {
415
- // The expectation is that this InterpreterOopMap is a recently created
416
- // and empty. It is used to get a copy of a cached entry.
417
- // If the bit mask has a value, it should be in the
418
- // resource area.
419
- assert (_bit_mask[0 ] == 0 ||
420
- Thread::current ()->resource_area ()->contains ((void *)_bit_mask[0 ]),
421
- " The bit mask should have been allocated from a resource area" );
422
- // Allocate the bit_mask from a Resource area for performance. Allocating
423
- // from the C heap as is done for OopMapCache has a significant
424
- // performance impact.
425
- _bit_mask[0 ] = (uintptr_t ) NEW_RESOURCE_ARRAY (uintptr_t , mask_word_size ());
426
- assert (_bit_mask[0 ] != 0 , " bit mask was not allocated" );
427
- memcpy ((void *) _bit_mask[0 ], (void *) from->_bit_mask [0 ],
428
- mask_word_size () * BytesPerWord);
417
+ _bit_mask[0 ] = (uintptr_t ) NEW_C_HEAP_ARRAY (uintptr_t , mask_word_size (), mtClass);
418
+ memcpy ((void *) _bit_mask[0 ], (void *) src->_bit_mask [0 ], mask_word_size () * BytesPerWord);
429
419
}
430
420
}
431
421
@@ -508,7 +498,7 @@ void OopMapCache::lookup(const methodHandle& method,
508
498
for (int i = 0 ; i < probe_depth; i++) {
509
499
OopMapCacheEntry *entry = entry_at (probe + i);
510
500
if (entry != nullptr && !entry->is_empty () && entry->match (method, bci)) {
511
- entry_for->resource_copy (entry);
501
+ entry_for->copy_from (entry);
512
502
assert (!entry_for->is_empty (), " A non-empty oop map should be returned" );
513
503
log_debug (interpreter, oopmap)(" - found at hash %d" , probe + i);
514
504
return ;
@@ -522,7 +512,7 @@ void OopMapCache::lookup(const methodHandle& method,
522
512
OopMapCacheEntry* tmp = NEW_C_HEAP_OBJ (OopMapCacheEntry, mtClass);
523
513
tmp->initialize ();
524
514
tmp->fill (method, bci);
525
- entry_for->resource_copy (tmp);
515
+ entry_for->copy_from (tmp);
526
516
527
517
if (method->should_not_be_cached ()) {
528
518
// It is either not safe or not a good idea to cache this Method*
@@ -622,6 +612,8 @@ void OopMapCache::compute_one_oop_map(const methodHandle& method, int bci, Inter
622
612
OopMapCacheEntry* tmp = NEW_C_HEAP_OBJ (OopMapCacheEntry, mtClass);
623
613
tmp->initialize ();
624
614
tmp->fill (method, bci);
625
- entry->resource_copy (tmp);
615
+ if (tmp->has_valid_mask ()) {
616
+ entry->copy_from (tmp);
617
+ }
626
618
OopMapCacheEntry::deallocate (tmp);
627
619
}
0 commit comments