comparison src/share/vm/classfile/systemDictionary.cpp @ 515:a0401dc51d0b

6791656: nsk defclass0 asserts handles.hpp Reviewed-by: phh, xlu
author acorn
date Thu, 08 Jan 2009 16:27:28 -0500
parents c81d2ef51ca3
children dca06e7f503d
comparison
equal deleted inserted replaced
514:c81d2ef51ca3 515:a0401dc51d0b
1469 // potentially waste time reading and parsing the bytestream. 1469 // potentially waste time reading and parsing the bytestream.
1470 // Note: VM callers should ensure consistency of k/class_name,class_loader 1470 // Note: VM callers should ensure consistency of k/class_name,class_loader
1471 instanceKlassHandle SystemDictionary::find_or_define_instance_class(symbolHandle class_name, Handle class_loader, instanceKlassHandle k, TRAPS) { 1471 instanceKlassHandle SystemDictionary::find_or_define_instance_class(symbolHandle class_name, Handle class_loader, instanceKlassHandle k, TRAPS) {
1472 1472
1473 instanceKlassHandle nh = instanceKlassHandle(); // null Handle 1473 instanceKlassHandle nh = instanceKlassHandle(); // null Handle
1474 1474 symbolHandle name_h(THREAD, k->name()); // passed in class_name may be null
1475 unsigned int d_hash = dictionary()->compute_hash(class_name, class_loader); 1475
1476 unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader);
1476 int d_index = dictionary()->hash_to_index(d_hash); 1477 int d_index = dictionary()->hash_to_index(d_hash);
1477 1478
1478 // Hold SD lock around find_class and placeholder creation for DEFINE_CLASS 1479 // Hold SD lock around find_class and placeholder creation for DEFINE_CLASS
1479 unsigned int p_hash = placeholders()->compute_hash(class_name, class_loader); 1480 unsigned int p_hash = placeholders()->compute_hash(name_h, class_loader);
1480 int p_index = placeholders()->hash_to_index(p_hash); 1481 int p_index = placeholders()->hash_to_index(p_hash);
1481 PlaceholderEntry* probe; 1482 PlaceholderEntry* probe;
1482 1483
1483 { 1484 {
1484 MutexLocker mu(SystemDictionary_lock, THREAD); 1485 MutexLocker mu(SystemDictionary_lock, THREAD);
1485 // First check if class already defined 1486 // First check if class already defined
1486 klassOop check = find_class(d_index, d_hash, class_name, class_loader); 1487 klassOop check = find_class(d_index, d_hash, name_h, class_loader);
1487 if (check != NULL) { 1488 if (check != NULL) {
1488 return(instanceKlassHandle(THREAD, check)); 1489 return(instanceKlassHandle(THREAD, check));
1489 } 1490 }
1490 1491
1491 // Acquire define token for this class/classloader 1492 // Acquire define token for this class/classloader
1492 symbolHandle nullsymbolHandle; 1493 symbolHandle nullsymbolHandle;
1493 probe = placeholders()->find_and_add(p_index, p_hash, class_name, class_loader, PlaceholderTable::DEFINE_CLASS, nullsymbolHandle, THREAD); 1494 probe = placeholders()->find_and_add(p_index, p_hash, name_h, class_loader, PlaceholderTable::DEFINE_CLASS, nullsymbolHandle, THREAD);
1494 // Wait if another thread defining in parallel 1495 // Wait if another thread defining in parallel
1495 // All threads wait - even those that will throw duplicate class: otherwise 1496 // All threads wait - even those that will throw duplicate class: otherwise
1496 // caller is surprised by LinkageError: duplicate, but findLoadedClass fails 1497 // caller is surprised by LinkageError: duplicate, but findLoadedClass fails
1497 // if other thread has not finished updating dictionary 1498 // if other thread has not finished updating dictionary
1498 while (probe->definer() != NULL) { 1499 while (probe->definer() != NULL) {
1501 // Only special cases allow parallel defines and can use other thread's results 1502 // Only special cases allow parallel defines and can use other thread's results
1502 // Other cases fall through, and may run into duplicate defines 1503 // Other cases fall through, and may run into duplicate defines
1503 // caught by finding an entry in the SystemDictionary 1504 // caught by finding an entry in the SystemDictionary
1504 if ((UnsyncloadClass || AllowParallelDefineClass) && (probe->instanceKlass() != NULL)) { 1505 if ((UnsyncloadClass || AllowParallelDefineClass) && (probe->instanceKlass() != NULL)) {
1505 probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS); 1506 probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS);
1506 placeholders()->find_and_remove(p_index, p_hash, class_name, class_loader, THREAD); 1507 placeholders()->find_and_remove(p_index, p_hash, name_h, class_loader, THREAD);
1507 SystemDictionary_lock->notify_all(); 1508 SystemDictionary_lock->notify_all();
1508 #ifdef ASSERT 1509 #ifdef ASSERT
1509 klassOop check = find_class(d_index, d_hash, class_name, class_loader); 1510 klassOop check = find_class(d_index, d_hash, name_h, class_loader);
1510 assert(check != NULL, "definer missed recording success"); 1511 assert(check != NULL, "definer missed recording success");
1511 #endif 1512 #endif
1512 return(instanceKlassHandle(THREAD, probe->instanceKlass())); 1513 return(instanceKlassHandle(THREAD, probe->instanceKlass()));
1513 } else { 1514 } else {
1514 // This thread will define the class (even if earlier thread tried and had an error) 1515 // This thread will define the class (even if earlier thread tried and had an error)
1521 Handle linkage_exception = Handle(); // null handle 1522 Handle linkage_exception = Handle(); // null handle
1522 1523
1523 // definer must notify any waiting threads 1524 // definer must notify any waiting threads
1524 { 1525 {
1525 MutexLocker mu(SystemDictionary_lock, THREAD); 1526 MutexLocker mu(SystemDictionary_lock, THREAD);
1526 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, class_name, class_loader); 1527 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name_h, class_loader);
1527 assert(probe != NULL, "DEFINE_CLASS placeholder lost?"); 1528 assert(probe != NULL, "DEFINE_CLASS placeholder lost?");
1528 if (probe != NULL) { 1529 if (probe != NULL) {
1529 if (HAS_PENDING_EXCEPTION) { 1530 if (HAS_PENDING_EXCEPTION) {
1530 linkage_exception = Handle(THREAD,PENDING_EXCEPTION); 1531 linkage_exception = Handle(THREAD,PENDING_EXCEPTION);
1531 CLEAR_PENDING_EXCEPTION; 1532 CLEAR_PENDING_EXCEPTION;
1532 } else { 1533 } else {
1533 probe->set_instanceKlass(k()); 1534 probe->set_instanceKlass(k());
1534 } 1535 }
1535 probe->set_definer(NULL); 1536 probe->set_definer(NULL);
1536 probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS); 1537 probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS);
1537 placeholders()->find_and_remove(p_index, p_hash, class_name, class_loader, THREAD); 1538 placeholders()->find_and_remove(p_index, p_hash, name_h, class_loader, THREAD);
1538 SystemDictionary_lock->notify_all(); 1539 SystemDictionary_lock->notify_all();
1539 } 1540 }
1540 } 1541 }
1541 1542
1542 // Can't throw exception while holding lock due to rank ordering 1543 // Can't throw exception while holding lock due to rank ordering