314 |
314 |
315 // Convenience functions for logical bottom and end |
315 // Convenience functions for logical bottom and end |
316 MetaWord* bottom() const { return (MetaWord*) _virtual_space.low(); } |
316 MetaWord* bottom() const { return (MetaWord*) _virtual_space.low(); } |
317 MetaWord* end() const { return (MetaWord*) _virtual_space.high(); } |
317 MetaWord* end() const { return (MetaWord*) _virtual_space.high(); } |
318 |
318 |
|
319 bool contains(const void* ptr) { return ptr >= low() && ptr < high(); } |
|
320 |
319 size_t reserved_words() const { return _virtual_space.reserved_size() / BytesPerWord; } |
321 size_t reserved_words() const { return _virtual_space.reserved_size() / BytesPerWord; } |
320 size_t committed_words() const { return _virtual_space.actual_committed_size() / BytesPerWord; } |
322 size_t committed_words() const { return _virtual_space.actual_committed_size() / BytesPerWord; } |
321 |
323 |
322 bool is_pre_committed() const { return _virtual_space.special(); } |
324 bool is_pre_committed() const { return _virtual_space.special(); } |
323 |
325 |
555 void inc_committed_words(size_t v); |
557 void inc_committed_words(size_t v); |
556 void dec_committed_words(size_t v); |
558 void dec_committed_words(size_t v); |
557 void inc_virtual_space_count(); |
559 void inc_virtual_space_count(); |
558 void dec_virtual_space_count(); |
560 void dec_virtual_space_count(); |
559 |
561 |
|
562 bool contains(const void* ptr); |
|
563 |
560 // Unlink empty VirtualSpaceNodes and free it. |
564 // Unlink empty VirtualSpaceNodes and free it. |
561 void purge(ChunkManager* chunk_manager); |
565 void purge(ChunkManager* chunk_manager); |
562 |
566 |
563 void print_on(outputStream* st) const; |
567 void print_on(outputStream* st) const; |
564 |
568 |
639 |
643 |
640 private: |
644 private: |
641 // Accessors |
645 // Accessors |
642 Metachunk* chunks_in_use(ChunkIndex index) const { return _chunks_in_use[index]; } |
646 Metachunk* chunks_in_use(ChunkIndex index) const { return _chunks_in_use[index]; } |
643 void set_chunks_in_use(ChunkIndex index, Metachunk* v) { |
647 void set_chunks_in_use(ChunkIndex index, Metachunk* v) { |
644 // ensure lock-free iteration sees fully initialized node |
|
645 OrderAccess::storestore(); |
|
646 _chunks_in_use[index] = v; |
648 _chunks_in_use[index] = v; |
647 } |
649 } |
648 |
650 |
649 BlockFreelist* block_freelists() const { |
651 BlockFreelist* block_freelists() const { |
650 return (BlockFreelist*) &_block_freelists; |
652 return (BlockFreelist*) &_block_freelists; |
755 |
757 |
756 void dump(outputStream* const out) const; |
758 void dump(outputStream* const out) const; |
757 void print_on(outputStream* st) const; |
759 void print_on(outputStream* st) const; |
758 void locked_print_chunks_in_use_on(outputStream* st) const; |
760 void locked_print_chunks_in_use_on(outputStream* st) const; |
759 |
761 |
760 bool contains(const void *ptr); |
|
761 |
|
762 void verify(); |
762 void verify(); |
763 void verify_chunk_size(Metachunk* chunk); |
763 void verify_chunk_size(Metachunk* chunk); |
764 NOT_PRODUCT(void mangle_freed_chunks();) |
764 NOT_PRODUCT(void mangle_freed_chunks();) |
765 #ifdef ASSERT |
765 #ifdef ASSERT |
766 void verify_allocated_blocks_words(); |
766 void verify_allocated_blocks_words(); |
1076 |
1076 |
1077 // Walk the list of VirtualSpaceNodes and delete |
1077 // Walk the list of VirtualSpaceNodes and delete |
1078 // nodes with a 0 container_count. Remove Metachunks in |
1078 // nodes with a 0 container_count. Remove Metachunks in |
1079 // the node from their respective freelists. |
1079 // the node from their respective freelists. |
1080 void VirtualSpaceList::purge(ChunkManager* chunk_manager) { |
1080 void VirtualSpaceList::purge(ChunkManager* chunk_manager) { |
|
1081 assert(SafepointSynchronize::is_at_safepoint(), "must be called at safepoint for contains to work"); |
1081 assert_lock_strong(SpaceManager::expand_lock()); |
1082 assert_lock_strong(SpaceManager::expand_lock()); |
1082 // Don't use a VirtualSpaceListIterator because this |
1083 // Don't use a VirtualSpaceListIterator because this |
1083 // list is being changed and a straightforward use of an iterator is not safe. |
1084 // list is being changed and a straightforward use of an iterator is not safe. |
1084 VirtualSpaceNode* purged_vsl = NULL; |
1085 VirtualSpaceNode* purged_vsl = NULL; |
1085 VirtualSpaceNode* prev_vsl = virtual_space_list(); |
1086 VirtualSpaceNode* prev_vsl = virtual_space_list(); |
1109 prev_vsl = vsl; |
1110 prev_vsl = vsl; |
1110 } |
1111 } |
1111 } |
1112 } |
1112 #ifdef ASSERT |
1113 #ifdef ASSERT |
1113 if (purged_vsl != NULL) { |
1114 if (purged_vsl != NULL) { |
1114 // List should be stable enough to use an iterator here. |
1115 // List should be stable enough to use an iterator here. |
1115 VirtualSpaceListIterator iter(virtual_space_list()); |
1116 VirtualSpaceListIterator iter(virtual_space_list()); |
1116 while (iter.repeat()) { |
1117 while (iter.repeat()) { |
1117 VirtualSpaceNode* vsl = iter.get_next(); |
1118 VirtualSpaceNode* vsl = iter.get_next(); |
1118 assert(vsl != purged_vsl, "Purge of vsl failed"); |
1119 assert(vsl != purged_vsl, "Purge of vsl failed"); |
1119 } |
1120 } |
1120 } |
1121 } |
1121 #endif |
1122 #endif |
|
1123 } |
|
1124 |
|
1125 |
|
1126 // This function looks at the mmap regions in the metaspace without locking. |
|
1127 // The chunks are added with store ordering and not deleted except for at |
|
1128 // unloading time during a safepoint. |
|
1129 bool VirtualSpaceList::contains(const void* ptr) { |
|
1130 // List should be stable enough to use an iterator here because removing virtual |
|
1131 // space nodes is only allowed at a safepoint. |
|
1132 VirtualSpaceListIterator iter(virtual_space_list()); |
|
1133 while (iter.repeat()) { |
|
1134 VirtualSpaceNode* vsn = iter.get_next(); |
|
1135 if (vsn->contains(ptr)) { |
|
1136 return true; |
|
1137 } |
|
1138 } |
|
1139 return false; |
1122 } |
1140 } |
1123 |
1141 |
1124 void VirtualSpaceList::retire_current_virtual_space() { |
1142 void VirtualSpaceList::retire_current_virtual_space() { |
1125 assert_lock_strong(SpaceManager::expand_lock()); |
1143 assert_lock_strong(SpaceManager::expand_lock()); |
1126 |
1144 |
2432 } |
2452 } |
2433 |
2453 |
2434 return result; |
2454 return result; |
2435 } |
2455 } |
2436 |
2456 |
2437 // This function looks at the chunks in the metaspace without locking. |
|
2438 // The chunks are added with store ordering and not deleted except for at |
|
2439 // unloading time. |
|
2440 bool SpaceManager::contains(const void *ptr) { |
|
2441 for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) |
|
2442 { |
|
2443 Metachunk* curr = chunks_in_use(i); |
|
2444 while (curr != NULL) { |
|
2445 if (curr->contains(ptr)) return true; |
|
2446 curr = curr->next(); |
|
2447 } |
|
2448 } |
|
2449 return false; |
|
2450 } |
|
2451 |
|
2452 void SpaceManager::verify() { |
2457 void SpaceManager::verify() { |
2453 // If there are blocks in the dictionary, then |
2458 // If there are blocks in the dictionary, then |
2454 // verification of chunks does not work since |
2459 // verification of chunks does not work since |
2455 // being in the dictionary alters a chunk. |
2460 // being in the dictionary alters a chunk. |
2456 if (block_freelists()->total_size() == 0) { |
2461 if (block_freelists()->total_size() == 0) { |
3536 } |
3541 } |
3537 } |
3542 } |
3538 } |
3543 } |
3539 |
3544 |
3540 bool Metaspace::contains(const void* ptr) { |
3545 bool Metaspace::contains(const void* ptr) { |
3541 if (vsm()->contains(ptr)) return true; |
3546 if (UseSharedSpaces && MetaspaceShared::is_in_shared_space(ptr)) { |
3542 if (using_class_space()) { |
3547 return true; |
3543 return class_vsm()->contains(ptr); |
3548 } |
3544 } |
3549 |
3545 return false; |
3550 if (using_class_space() && get_space_list(ClassType)->contains(ptr)) { |
|
3551 return true; |
|
3552 } |
|
3553 |
|
3554 return get_space_list(NonClassType)->contains(ptr); |
3546 } |
3555 } |
3547 |
3556 |
3548 void Metaspace::verify() { |
3557 void Metaspace::verify() { |
3549 vsm()->verify(); |
3558 vsm()->verify(); |
3550 if (using_class_space()) { |
3559 if (using_class_space()) { |