1.1 --- a/src/share/vm/classfile/classLoaderData.cpp Tue Feb 12 14:15:45 2013 -0800 1.2 +++ b/src/share/vm/classfile/classLoaderData.cpp Wed Apr 24 19:55:02 2013 +0200 1.3 @@ -66,17 +66,19 @@ 1.4 1.5 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL; 1.6 1.7 -ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous) : 1.8 +ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) : 1.9 _class_loader(h_class_loader()), 1.10 _is_anonymous(is_anonymous), _keep_alive(is_anonymous), // initially 1.11 _metaspace(NULL), _unloading(false), _klasses(NULL), 1.12 _claimed(0), _jmethod_ids(NULL), _handles(NULL), _deallocate_list(NULL), 1.13 - _next(NULL), _dependencies(), 1.14 + _next(NULL), _dependencies(dependencies), 1.15 _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true)) { 1.16 // empty 1.17 } 1.18 1.19 void ClassLoaderData::init_dependencies(TRAPS) { 1.20 + assert(!Universe::is_fully_initialized(), "should only be called when initializing"); 1.21 + assert(is_the_null_class_loader_data(), "should only call this for the null class loader"); 1.22 _dependencies.init(CHECK); 1.23 } 1.24 1.25 @@ -499,29 +501,25 @@ 1.26 // Add a new class loader data node to the list. Assign the newly created 1.27 // ClassLoaderData into the java/lang/ClassLoader object as a hidden field 1.28 ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_anonymous, TRAPS) { 1.29 - // Not assigned a class loader data yet. 1.30 - // Create one. 1.31 - ClassLoaderData* cld = new ClassLoaderData(loader, is_anonymous); 1.32 - cld->init_dependencies(THREAD); 1.33 - if (HAS_PENDING_EXCEPTION) { 1.34 - delete cld; 1.35 - return NULL; 1.36 - } 1.37 + // We need to allocate all the oops for the ClassLoaderData before allocating the 1.38 + // actual ClassLoaderData object. 1.39 + ClassLoaderData::Dependencies dependencies(CHECK_NULL); 1.40 1.41 - No_Safepoint_Verifier no_safepoints; // nothing is keeping the dependencies array in cld alive 1.42 - // make sure we don't encounter a GC until we've inserted 1.43 - // cld into the CLDG 1.44 + No_Safepoint_Verifier no_safepoints; // we mustn't GC until we've installed the 1.45 + // ClassLoaderData in the graph since the CLD 1.46 + // contains unhandled oops 1.47 + 1.48 + ClassLoaderData* cld = new ClassLoaderData(loader, is_anonymous, dependencies); 1.49 + 1.50 1.51 if (!is_anonymous) { 1.52 ClassLoaderData** cld_addr = java_lang_ClassLoader::loader_data_addr(loader()); 1.53 - if (cld_addr != NULL) { 1.54 - // First, Atomically set it 1.55 - ClassLoaderData* old = (ClassLoaderData*) Atomic::cmpxchg_ptr(cld, cld_addr, NULL); 1.56 - if (old != NULL) { 1.57 - delete cld; 1.58 - // Returns the data. 1.59 - return old; 1.60 - } 1.61 + // First, Atomically set it 1.62 + ClassLoaderData* old = (ClassLoaderData*) Atomic::cmpxchg_ptr(cld, cld_addr, NULL); 1.63 + if (old != NULL) { 1.64 + delete cld; 1.65 + // Returns the data. 1.66 + return old; 1.67 } 1.68 } 1.69