1.1 --- a/src/share/vm/classfile/systemDictionary.cpp Fri Nov 06 16:05:59 2009 -0500 1.2 +++ b/src/share/vm/classfile/systemDictionary.cpp Wed Nov 11 15:49:38 2009 -0500 1.3 @@ -99,6 +99,15 @@ 1.4 return java_lang_Class::parallelCapable(class_loader()); 1.5 } 1.6 // ---------------------------------------------------------------------------- 1.7 +// ParallelDefineClass flag does not apply to bootclass loader 1.8 +bool SystemDictionary::is_parallelDefine(Handle class_loader) { 1.9 + if (class_loader.is_null()) return false; 1.10 + if (AllowParallelDefineClass && java_lang_Class::parallelCapable(class_loader())) { 1.11 + return true; 1.12 + } 1.13 + return false; 1.14 +} 1.15 +// ---------------------------------------------------------------------------- 1.16 // Resolving of classes 1.17 1.18 // Forwards to resolve_or_null 1.19 @@ -724,13 +733,13 @@ 1.20 // Do actual loading 1.21 k = load_instance_class(name, class_loader, THREAD); 1.22 1.23 - // For UnsyncloadClass and AllowParallelDefineClass only: 1.24 + // For UnsyncloadClass only 1.25 // If they got a linkageError, check if a parallel class load succeeded. 1.26 // If it did, then for bytecode resolution the specification requires 1.27 // that we return the same result we did for the other thread, i.e. the 1.28 // successfully loaded instanceKlass 1.29 // Should not get here for classloaders that support parallelism 1.30 - // with the new cleaner mechanism 1.31 + // with the new cleaner mechanism, even with AllowParallelDefineClass 1.32 // Bootstrap goes through here to allow for an extra guarantee check 1.33 if (UnsyncloadClass || (class_loader.is_null())) { 1.34 if (k.is_null() && HAS_PENDING_EXCEPTION 1.35 @@ -1483,14 +1492,17 @@ 1.36 } 1.37 1.38 // Support parallel classloading 1.39 -// Initial implementation for bootstrap classloader 1.40 -// For custom class loaders that support parallel classloading, 1.41 +// All parallel class loaders, including bootstrap classloader 1.42 +// lock a placeholder entry for this class/class_loader pair 1.43 +// to allow parallel defines of different classes for this class loader 1.44 // With AllowParallelDefine flag==true, in case they do not synchronize around 1.45 // FindLoadedClass/DefineClass, calls, we check for parallel 1.46 // loading for them, wait if a defineClass is in progress 1.47 // and return the initial requestor's results 1.48 +// This flag does not apply to the bootstrap classloader. 1.49 // With AllowParallelDefine flag==false, call through to define_instance_class 1.50 // which will throw LinkageError: duplicate class definition. 1.51 +// False is the requested default. 1.52 // For better performance, the class loaders should synchronize 1.53 // findClass(), i.e. FindLoadedClass/DefineClassIfAbsent or they 1.54 // potentially waste time reading and parsing the bytestream. 1.55 @@ -1511,9 +1523,11 @@ 1.56 { 1.57 MutexLocker mu(SystemDictionary_lock, THREAD); 1.58 // First check if class already defined 1.59 - klassOop check = find_class(d_index, d_hash, name_h, class_loader); 1.60 - if (check != NULL) { 1.61 - return(instanceKlassHandle(THREAD, check)); 1.62 + if (UnsyncloadClass || (is_parallelDefine(class_loader))) { 1.63 + klassOop check = find_class(d_index, d_hash, name_h, class_loader); 1.64 + if (check != NULL) { 1.65 + return(instanceKlassHandle(THREAD, check)); 1.66 + } 1.67 } 1.68 1.69 // Acquire define token for this class/classloader 1.70 @@ -1529,7 +1543,7 @@ 1.71 // Only special cases allow parallel defines and can use other thread's results 1.72 // Other cases fall through, and may run into duplicate defines 1.73 // caught by finding an entry in the SystemDictionary 1.74 - if ((UnsyncloadClass || AllowParallelDefineClass) && (probe->instanceKlass() != NULL)) { 1.75 + if ((UnsyncloadClass || is_parallelDefine(class_loader)) && (probe->instanceKlass() != NULL)) { 1.76 probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS); 1.77 placeholders()->find_and_remove(p_index, p_hash, name_h, class_loader, THREAD); 1.78 SystemDictionary_lock->notify_all();