95 |
95 |
96 bool SystemDictionary::is_parallelCapable(Handle class_loader) { |
96 bool SystemDictionary::is_parallelCapable(Handle class_loader) { |
97 if (UnsyncloadClass || class_loader.is_null()) return true; |
97 if (UnsyncloadClass || class_loader.is_null()) return true; |
98 if (AlwaysLockClassLoader) return false; |
98 if (AlwaysLockClassLoader) return false; |
99 return java_lang_Class::parallelCapable(class_loader()); |
99 return java_lang_Class::parallelCapable(class_loader()); |
|
100 } |
|
101 // ---------------------------------------------------------------------------- |
|
102 // ParallelDefineClass flag does not apply to bootclass loader |
|
103 bool SystemDictionary::is_parallelDefine(Handle class_loader) { |
|
104 if (class_loader.is_null()) return false; |
|
105 if (AllowParallelDefineClass && java_lang_Class::parallelCapable(class_loader())) { |
|
106 return true; |
|
107 } |
|
108 return false; |
100 } |
109 } |
101 // ---------------------------------------------------------------------------- |
110 // ---------------------------------------------------------------------------- |
102 // Resolving of classes |
111 // Resolving of classes |
103 |
112 |
104 // Forwards to resolve_or_null |
113 // Forwards to resolve_or_null |
722 if (!class_has_been_loaded) { |
731 if (!class_has_been_loaded) { |
723 |
732 |
724 // Do actual loading |
733 // Do actual loading |
725 k = load_instance_class(name, class_loader, THREAD); |
734 k = load_instance_class(name, class_loader, THREAD); |
726 |
735 |
727 // For UnsyncloadClass and AllowParallelDefineClass only: |
736 // For UnsyncloadClass only |
728 // If they got a linkageError, check if a parallel class load succeeded. |
737 // If they got a linkageError, check if a parallel class load succeeded. |
729 // If it did, then for bytecode resolution the specification requires |
738 // If it did, then for bytecode resolution the specification requires |
730 // that we return the same result we did for the other thread, i.e. the |
739 // that we return the same result we did for the other thread, i.e. the |
731 // successfully loaded instanceKlass |
740 // successfully loaded instanceKlass |
732 // Should not get here for classloaders that support parallelism |
741 // Should not get here for classloaders that support parallelism |
733 // with the new cleaner mechanism |
742 // with the new cleaner mechanism, even with AllowParallelDefineClass |
734 // Bootstrap goes through here to allow for an extra guarantee check |
743 // Bootstrap goes through here to allow for an extra guarantee check |
735 if (UnsyncloadClass || (class_loader.is_null())) { |
744 if (UnsyncloadClass || (class_loader.is_null())) { |
736 if (k.is_null() && HAS_PENDING_EXCEPTION |
745 if (k.is_null() && HAS_PENDING_EXCEPTION |
737 && PENDING_EXCEPTION->is_a(SystemDictionary::linkageError_klass())) { |
746 && PENDING_EXCEPTION->is_a(SystemDictionary::linkageError_klass())) { |
738 MutexLocker mu(SystemDictionary_lock, THREAD); |
747 MutexLocker mu(SystemDictionary_lock, THREAD); |
1481 |
1490 |
1482 } |
1491 } |
1483 } |
1492 } |
1484 |
1493 |
1485 // Support parallel classloading |
1494 // Support parallel classloading |
1486 // Initial implementation for bootstrap classloader |
1495 // All parallel class loaders, including bootstrap classloader |
1487 // For custom class loaders that support parallel classloading, |
1496 // lock a placeholder entry for this class/class_loader pair |
|
1497 // to allow parallel defines of different classes for this class loader |
1488 // With AllowParallelDefine flag==true, in case they do not synchronize around |
1498 // With AllowParallelDefine flag==true, in case they do not synchronize around |
1489 // FindLoadedClass/DefineClass, calls, we check for parallel |
1499 // FindLoadedClass/DefineClass, calls, we check for parallel |
1490 // loading for them, wait if a defineClass is in progress |
1500 // loading for them, wait if a defineClass is in progress |
1491 // and return the initial requestor's results |
1501 // and return the initial requestor's results |
|
1502 // This flag does not apply to the bootstrap classloader. |
1492 // With AllowParallelDefine flag==false, call through to define_instance_class |
1503 // With AllowParallelDefine flag==false, call through to define_instance_class |
1493 // which will throw LinkageError: duplicate class definition. |
1504 // which will throw LinkageError: duplicate class definition. |
|
1505 // False is the requested default. |
1494 // For better performance, the class loaders should synchronize |
1506 // For better performance, the class loaders should synchronize |
1495 // findClass(), i.e. FindLoadedClass/DefineClassIfAbsent or they |
1507 // findClass(), i.e. FindLoadedClass/DefineClassIfAbsent or they |
1496 // potentially waste time reading and parsing the bytestream. |
1508 // potentially waste time reading and parsing the bytestream. |
1497 // Note: VM callers should ensure consistency of k/class_name,class_loader |
1509 // Note: VM callers should ensure consistency of k/class_name,class_loader |
1498 instanceKlassHandle SystemDictionary::find_or_define_instance_class(symbolHandle class_name, Handle class_loader, instanceKlassHandle k, TRAPS) { |
1510 instanceKlassHandle SystemDictionary::find_or_define_instance_class(symbolHandle class_name, Handle class_loader, instanceKlassHandle k, TRAPS) { |
1509 PlaceholderEntry* probe; |
1521 PlaceholderEntry* probe; |
1510 |
1522 |
1511 { |
1523 { |
1512 MutexLocker mu(SystemDictionary_lock, THREAD); |
1524 MutexLocker mu(SystemDictionary_lock, THREAD); |
1513 // First check if class already defined |
1525 // First check if class already defined |
1514 klassOop check = find_class(d_index, d_hash, name_h, class_loader); |
1526 if (UnsyncloadClass || (is_parallelDefine(class_loader))) { |
1515 if (check != NULL) { |
1527 klassOop check = find_class(d_index, d_hash, name_h, class_loader); |
1516 return(instanceKlassHandle(THREAD, check)); |
1528 if (check != NULL) { |
|
1529 return(instanceKlassHandle(THREAD, check)); |
|
1530 } |
1517 } |
1531 } |
1518 |
1532 |
1519 // Acquire define token for this class/classloader |
1533 // Acquire define token for this class/classloader |
1520 symbolHandle nullsymbolHandle; |
1534 symbolHandle nullsymbolHandle; |
1521 probe = placeholders()->find_and_add(p_index, p_hash, name_h, class_loader, PlaceholderTable::DEFINE_CLASS, nullsymbolHandle, THREAD); |
1535 probe = placeholders()->find_and_add(p_index, p_hash, name_h, class_loader, PlaceholderTable::DEFINE_CLASS, nullsymbolHandle, THREAD); |
1527 SystemDictionary_lock->wait(); |
1541 SystemDictionary_lock->wait(); |
1528 } |
1542 } |
1529 // Only special cases allow parallel defines and can use other thread's results |
1543 // Only special cases allow parallel defines and can use other thread's results |
1530 // Other cases fall through, and may run into duplicate defines |
1544 // Other cases fall through, and may run into duplicate defines |
1531 // caught by finding an entry in the SystemDictionary |
1545 // caught by finding an entry in the SystemDictionary |
1532 if ((UnsyncloadClass || AllowParallelDefineClass) && (probe->instanceKlass() != NULL)) { |
1546 if ((UnsyncloadClass || is_parallelDefine(class_loader)) && (probe->instanceKlass() != NULL)) { |
1533 probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS); |
1547 probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS); |
1534 placeholders()->find_and_remove(p_index, p_hash, name_h, class_loader, THREAD); |
1548 placeholders()->find_and_remove(p_index, p_hash, name_h, class_loader, THREAD); |
1535 SystemDictionary_lock->notify_all(); |
1549 SystemDictionary_lock->notify_all(); |
1536 #ifdef ASSERT |
1550 #ifdef ASSERT |
1537 klassOop check = find_class(d_index, d_hash, name_h, class_loader); |
1551 klassOop check = find_class(d_index, d_hash, name_h, class_loader); |