comparison src/share/vm/memory/universe.cpp @ 12022:85147f28faba

8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32 Summary: ActiveMethodOopsCache was used to keep track of old versions of some methods that are cached in Universe but is buggy with permgen removal and not needed anymore Reviewed-by: sspitsyn, dcubed, mseledtsov
author coleenp
date Mon, 12 Aug 2013 17:24:54 -0400
parents 71180a6e5080
children 3cce976666d9 740e263c80c6
comparison
equal deleted inserted replaced
12021:bd0e82136b03 12022:85147f28faba
103 oop Universe::_system_thread_group = NULL; 103 oop Universe::_system_thread_group = NULL;
104 objArrayOop Universe::_the_empty_class_klass_array = NULL; 104 objArrayOop Universe::_the_empty_class_klass_array = NULL;
105 Array<Klass*>* Universe::_the_array_interfaces_array = NULL; 105 Array<Klass*>* Universe::_the_array_interfaces_array = NULL;
106 oop Universe::_the_null_string = NULL; 106 oop Universe::_the_null_string = NULL;
107 oop Universe::_the_min_jint_string = NULL; 107 oop Universe::_the_min_jint_string = NULL;
108 LatestMethodOopCache* Universe::_finalizer_register_cache = NULL; 108 LatestMethodCache* Universe::_finalizer_register_cache = NULL;
109 LatestMethodOopCache* Universe::_loader_addClass_cache = NULL; 109 LatestMethodCache* Universe::_loader_addClass_cache = NULL;
110 LatestMethodOopCache* Universe::_pd_implies_cache = NULL; 110 LatestMethodCache* Universe::_pd_implies_cache = NULL;
111 ActiveMethodOopsCache* Universe::_reflect_invoke_cache = NULL;
112 oop Universe::_out_of_memory_error_java_heap = NULL; 111 oop Universe::_out_of_memory_error_java_heap = NULL;
113 oop Universe::_out_of_memory_error_metaspace = NULL; 112 oop Universe::_out_of_memory_error_metaspace = NULL;
114 oop Universe::_out_of_memory_error_class_metaspace = NULL; 113 oop Universe::_out_of_memory_error_class_metaspace = NULL;
115 oop Universe::_out_of_memory_error_array_size = NULL; 114 oop Universe::_out_of_memory_error_array_size = NULL;
116 oop Universe::_out_of_memory_error_gc_overhead_limit = NULL; 115 oop Universe::_out_of_memory_error_gc_overhead_limit = NULL;
223 f->do_ptr((void**)&_the_empty_short_array); 222 f->do_ptr((void**)&_the_empty_short_array);
224 f->do_ptr((void**)&_the_empty_method_array); 223 f->do_ptr((void**)&_the_empty_method_array);
225 f->do_ptr((void**)&_the_empty_klass_array); 224 f->do_ptr((void**)&_the_empty_klass_array);
226 _finalizer_register_cache->serialize(f); 225 _finalizer_register_cache->serialize(f);
227 _loader_addClass_cache->serialize(f); 226 _loader_addClass_cache->serialize(f);
228 _reflect_invoke_cache->serialize(f);
229 _pd_implies_cache->serialize(f); 227 _pd_implies_cache->serialize(f);
230 } 228 }
231 229
232 void Universe::check_alignment(uintx size, uintx alignment, const char* name) { 230 void Universe::check_alignment(uintx size, uintx alignment, const char* name) {
233 if (size < alignment || size % alignment != 0) { 231 if (size < alignment || size % alignment != 0) {
647 // DumpSharedSpaces. 645 // DumpSharedSpaces.
648 ClassLoaderData::init_null_class_loader_data(); 646 ClassLoaderData::init_null_class_loader_data();
649 647
650 // We have a heap so create the Method* caches before 648 // We have a heap so create the Method* caches before
651 // Metaspace::initialize_shared_spaces() tries to populate them. 649 // Metaspace::initialize_shared_spaces() tries to populate them.
652 Universe::_finalizer_register_cache = new LatestMethodOopCache(); 650 Universe::_finalizer_register_cache = new LatestMethodCache();
653 Universe::_loader_addClass_cache = new LatestMethodOopCache(); 651 Universe::_loader_addClass_cache = new LatestMethodCache();
654 Universe::_pd_implies_cache = new LatestMethodOopCache(); 652 Universe::_pd_implies_cache = new LatestMethodCache();
655 Universe::_reflect_invoke_cache = new ActiveMethodOopsCache();
656 653
657 if (UseSharedSpaces) { 654 if (UseSharedSpaces) {
658 // Read the data structures supporting the shared spaces (shared 655 // Read the data structures supporting the shared spaces (shared
659 // system dictionary, symbol table, etc.). After that, access to 656 // system dictionary, symbol table, etc.). After that, access to
660 // the file (other than the mapped regions) is no longer needed, and 657 // the file (other than the mapped regions) is no longer needed, and
1086 InstanceKlass::cast(SystemDictionary::Finalizer_klass())->link_class(CHECK_false); 1083 InstanceKlass::cast(SystemDictionary::Finalizer_klass())->link_class(CHECK_false);
1087 Method* m = InstanceKlass::cast(SystemDictionary::Finalizer_klass())->find_method( 1084 Method* m = InstanceKlass::cast(SystemDictionary::Finalizer_klass())->find_method(
1088 vmSymbols::register_method_name(), 1085 vmSymbols::register_method_name(),
1089 vmSymbols::register_method_signature()); 1086 vmSymbols::register_method_signature());
1090 if (m == NULL || !m->is_static()) { 1087 if (m == NULL || !m->is_static()) {
1091 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodException(), 1088 tty->print_cr("Unable to link/verify Finalizer.register method");
1092 "java.lang.ref.Finalizer.register", false); 1089 return false; // initialization failed (cannot throw exception yet)
1093 } 1090 }
1094 Universe::_finalizer_register_cache->init( 1091 Universe::_finalizer_register_cache->init(
1095 SystemDictionary::Finalizer_klass(), m, CHECK_false); 1092 SystemDictionary::Finalizer_klass(), m);
1096
1097 // Resolve on first use and initialize class.
1098 // Note: No race-condition here, since a resolve will always return the same result
1099
1100 // Setup method for security checks
1101 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_reflect_Method(), true, CHECK_false);
1102 k_h = instanceKlassHandle(THREAD, k);
1103 k_h->link_class(CHECK_false);
1104 m = k_h->find_method(vmSymbols::invoke_name(), vmSymbols::object_object_array_object_signature());
1105 if (m == NULL || m->is_static()) {
1106 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodException(),
1107 "java.lang.reflect.Method.invoke", false);
1108 }
1109 Universe::_reflect_invoke_cache->init(k_h(), m, CHECK_false);
1110 1093
1111 // Setup method for registering loaded classes in class loader vector 1094 // Setup method for registering loaded classes in class loader vector
1112 InstanceKlass::cast(SystemDictionary::ClassLoader_klass())->link_class(CHECK_false); 1095 InstanceKlass::cast(SystemDictionary::ClassLoader_klass())->link_class(CHECK_false);
1113 m = InstanceKlass::cast(SystemDictionary::ClassLoader_klass())->find_method(vmSymbols::addClass_name(), vmSymbols::class_void_signature()); 1096 m = InstanceKlass::cast(SystemDictionary::ClassLoader_klass())->find_method(vmSymbols::addClass_name(), vmSymbols::class_void_signature());
1114 if (m == NULL || m->is_static()) { 1097 if (m == NULL || m->is_static()) {
1115 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodException(), 1098 tty->print_cr("Unable to link/verify ClassLoader.addClass method");
1116 "java.lang.ClassLoader.addClass", false); 1099 return false; // initialization failed (cannot throw exception yet)
1117 } 1100 }
1118 Universe::_loader_addClass_cache->init( 1101 Universe::_loader_addClass_cache->init(
1119 SystemDictionary::ClassLoader_klass(), m, CHECK_false); 1102 SystemDictionary::ClassLoader_klass(), m);
1120 1103
1121 // Setup method for checking protection domain 1104 // Setup method for checking protection domain
1122 InstanceKlass::cast(SystemDictionary::ProtectionDomain_klass())->link_class(CHECK_false); 1105 InstanceKlass::cast(SystemDictionary::ProtectionDomain_klass())->link_class(CHECK_false);
1123 m = InstanceKlass::cast(SystemDictionary::ProtectionDomain_klass())-> 1106 m = InstanceKlass::cast(SystemDictionary::ProtectionDomain_klass())->
1124 find_method(vmSymbols::impliesCreateAccessControlContext_name(), 1107 find_method(vmSymbols::impliesCreateAccessControlContext_name(),
1130 // <init> function before java_lang_Class is linked. Print error and exit. 1113 // <init> function before java_lang_Class is linked. Print error and exit.
1131 tty->print_cr("ProtectionDomain.impliesCreateAccessControlContext() has the wrong linkage"); 1114 tty->print_cr("ProtectionDomain.impliesCreateAccessControlContext() has the wrong linkage");
1132 return false; // initialization failed 1115 return false; // initialization failed
1133 } 1116 }
1134 Universe::_pd_implies_cache->init( 1117 Universe::_pd_implies_cache->init(
1135 SystemDictionary::ProtectionDomain_klass(), m, CHECK_false);; 1118 SystemDictionary::ProtectionDomain_klass(), m);;
1136 } 1119 }
1137 1120
1138 // The folowing is initializing converter functions for serialization in 1121 // The folowing is initializing converter functions for serialization in
1139 // JVM.cpp. If we clean up the StrictMath code above we may want to find 1122 // JVM.cpp. If we clean up the StrictMath code above we may want to find
1140 // a better solution for this as well. 1123 // a better solution for this as well.
1453 verify_mark_mask(); 1436 verify_mark_mask();
1454 verify_mark_bits(); 1437 verify_mark_bits();
1455 } 1438 }
1456 1439
1457 1440
1458 void CommonMethodOopCache::init(Klass* k, Method* m, TRAPS) { 1441 void LatestMethodCache::init(Klass* k, Method* m) {
1459 if (!UseSharedSpaces) { 1442 if (!UseSharedSpaces) {
1460 _klass = k; 1443 _klass = k;
1461 } 1444 }
1462 #ifndef PRODUCT 1445 #ifndef PRODUCT
1463 else { 1446 else {
1469 _method_idnum = m->method_idnum(); 1452 _method_idnum = m->method_idnum();
1470 assert(_method_idnum >= 0, "sanity check"); 1453 assert(_method_idnum >= 0, "sanity check");
1471 } 1454 }
1472 1455
1473 1456
1474 ActiveMethodOopsCache::~ActiveMethodOopsCache() { 1457 Method* LatestMethodCache::get_method() {
1475 if (_prev_methods != NULL) {
1476 delete _prev_methods;
1477 _prev_methods = NULL;
1478 }
1479 }
1480
1481
1482 void ActiveMethodOopsCache::add_previous_version(Method* method) {
1483 assert(Thread::current()->is_VM_thread(),
1484 "only VMThread can add previous versions");
1485
1486 // Only append the previous method if it is executing on the stack.
1487 if (method->on_stack()) {
1488
1489 if (_prev_methods == NULL) {
1490 // This is the first previous version so make some space.
1491 // Start with 2 elements under the assumption that the class
1492 // won't be redefined much.
1493 _prev_methods = new (ResourceObj::C_HEAP, mtClass) GrowableArray<Method*>(2, true);
1494 }
1495
1496 // RC_TRACE macro has an embedded ResourceMark
1497 RC_TRACE(0x00000100,
1498 ("add: %s(%s): adding prev version ref for cached method @%d",
1499 method->name()->as_C_string(), method->signature()->as_C_string(),
1500 _prev_methods->length()));
1501
1502 _prev_methods->append(method);
1503 }
1504
1505
1506 // Since the caller is the VMThread and we are at a safepoint, this is a good
1507 // time to clear out unused method references.
1508
1509 if (_prev_methods == NULL) return;
1510
1511 for (int i = _prev_methods->length() - 1; i >= 0; i--) {
1512 Method* method = _prev_methods->at(i);
1513 assert(method != NULL, "weak method ref was unexpectedly cleared");
1514
1515 if (!method->on_stack()) {
1516 // This method isn't running anymore so remove it
1517 _prev_methods->remove_at(i);
1518 MetadataFactory::free_metadata(method->method_holder()->class_loader_data(), method);
1519 } else {
1520 // RC_TRACE macro has an embedded ResourceMark
1521 RC_TRACE(0x00000400,
1522 ("add: %s(%s): previous cached method @%d is alive",
1523 method->name()->as_C_string(), method->signature()->as_C_string(), i));
1524 }
1525 }
1526 } // end add_previous_version()
1527
1528
1529 bool ActiveMethodOopsCache::is_same_method(const Method* method) const {
1530 InstanceKlass* ik = InstanceKlass::cast(klass());
1531 const Method* check_method = ik->method_with_idnum(method_idnum());
1532 assert(check_method != NULL, "sanity check");
1533 if (check_method == method) {
1534 // done with the easy case
1535 return true;
1536 }
1537
1538 if (_prev_methods != NULL) {
1539 // The cached method has been redefined at least once so search
1540 // the previous versions for a match.
1541 for (int i = 0; i < _prev_methods->length(); i++) {
1542 check_method = _prev_methods->at(i);
1543 if (check_method == method) {
1544 // a previous version matches
1545 return true;
1546 }
1547 }
1548 }
1549
1550 // either no previous versions or no previous version matched
1551 return false;
1552 }
1553
1554
1555 Method* LatestMethodOopCache::get_Method() {
1556 if (klass() == NULL) return NULL; 1458 if (klass() == NULL) return NULL;
1557 InstanceKlass* ik = InstanceKlass::cast(klass()); 1459 InstanceKlass* ik = InstanceKlass::cast(klass());
1558 Method* m = ik->method_with_idnum(method_idnum()); 1460 Method* m = ik->method_with_idnum(method_idnum());
1559 assert(m != NULL, "sanity check"); 1461 assert(m != NULL, "sanity check");
1560 return m; 1462 return m;