comparison src/share/vm/memory/metaspace.cpp @ 7176:59c790074993

8003635: NPG: AsynchGetCallTrace broken by Method* virtual call Summary: Make metaspace::contains be lock free and used to see if something is in metaspace, also compare Method* with vtbl pointer. Reviewed-by: dholmes, sspitsyn, dcubed, jmasa
author coleenp
date Wed, 28 Nov 2012 17:50:21 -0500
parents 6bc207d87e5d
children 5fafdef522c6
comparison
equal deleted inserted replaced
7175:b51dc8df86e5 7176:59c790074993
34 #include "memory/metaspaceShared.hpp" 34 #include "memory/metaspaceShared.hpp"
35 #include "memory/resourceArea.hpp" 35 #include "memory/resourceArea.hpp"
36 #include "memory/universe.hpp" 36 #include "memory/universe.hpp"
37 #include "runtime/globals.hpp" 37 #include "runtime/globals.hpp"
38 #include "runtime/mutex.hpp" 38 #include "runtime/mutex.hpp"
39 #include "runtime/orderAccess.hpp"
39 #include "services/memTracker.hpp" 40 #include "services/memTracker.hpp"
40 #include "utilities/copy.hpp" 41 #include "utilities/copy.hpp"
41 #include "utilities/debug.hpp" 42 #include "utilities/debug.hpp"
42 43
43 typedef BinaryTreeDictionary<Metablock, FreeList> BlockTreeDictionary; 44 typedef BinaryTreeDictionary<Metablock, FreeList> BlockTreeDictionary;
1005 VirtualSpaceNode* new_entry = new VirtualSpaceNode(vs_byte_size); 1006 VirtualSpaceNode* new_entry = new VirtualSpaceNode(vs_byte_size);
1006 if (!new_entry->initialize()) { 1007 if (!new_entry->initialize()) {
1007 delete new_entry; 1008 delete new_entry;
1008 return false; 1009 return false;
1009 } else { 1010 } else {
1011 // ensure lock-free iteration sees fully initialized node
1012 OrderAccess::storestore();
1010 link_vs(new_entry, vs_word_size); 1013 link_vs(new_entry, vs_word_size);
1011 return true; 1014 return true;
1012 } 1015 }
1013 } 1016 }
1014 1017
1094 node->print_on(st); 1097 node->print_on(st);
1095 } 1098 }
1096 } 1099 }
1097 } 1100 }
1098 1101
1099 #ifndef PRODUCT
1100 bool VirtualSpaceList::contains(const void *ptr) { 1102 bool VirtualSpaceList::contains(const void *ptr) {
1101 VirtualSpaceNode* list = virtual_space_list(); 1103 VirtualSpaceNode* list = virtual_space_list();
1102 VirtualSpaceListIterator iter(list); 1104 VirtualSpaceListIterator iter(list);
1103 while (iter.repeat()) { 1105 while (iter.repeat()) {
1104 VirtualSpaceNode* node = iter.get_next(); 1106 VirtualSpaceNode* node = iter.get_next();
1106 return true; 1108 return true;
1107 } 1109 }
1108 } 1110 }
1109 return false; 1111 return false;
1110 } 1112 }
1111 #endif // PRODUCT
1112 1113
1113 1114
1114 // MetaspaceGC methods 1115 // MetaspaceGC methods
1115 1116
1116 // VM_CollectForMetadataAllocation is the vm operation used to GC. 1117 // VM_CollectForMetadataAllocation is the vm operation used to GC.
2737 vsm()->print_on(out); 2738 vsm()->print_on(out);
2738 class_vsm()->print_on(out); 2739 class_vsm()->print_on(out);
2739 } 2740 }
2740 } 2741 }
2741 2742
2742 #ifndef PRODUCT 2743 bool Metaspace::contains(const void * ptr) {
2743 bool Metaspace::contains(const void * ptr) const {
2744 if (MetaspaceShared::is_in_shared_space(ptr)) { 2744 if (MetaspaceShared::is_in_shared_space(ptr)) {
2745 return true; 2745 return true;
2746 } 2746 }
2747 MutexLockerEx cl(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag); 2747 // This is checked while unlocked. As long as the virtualspaces are added
2748 // at the end, the pointer will be in one of them. The virtual spaces
2749 // aren't deleted presently. When they are, some sort of locking might
2750 // be needed. Note, locking this can cause inversion problems with the
2751 // caller in MetaspaceObj::is_metadata() function.
2748 return space_list()->contains(ptr) || class_space_list()->contains(ptr); 2752 return space_list()->contains(ptr) || class_space_list()->contains(ptr);
2749 } 2753 }
2750 #endif
2751 2754
2752 void Metaspace::verify() { 2755 void Metaspace::verify() {
2753 vsm()->verify(); 2756 vsm()->verify();
2754 class_vsm()->verify(); 2757 class_vsm()->verify();
2755 } 2758 }