comparison src/share/vm/classfile/classLoaderData.cpp @ 10184:9d75bcd7c890

8013136: NPG: Parallel class loading tests fail after fix for JDK-8011802 Summary: Move initialization of dependencies to before allocation of CLD Reviewed-by: stefank, coleenp
author mgerdin
date Wed, 24 Apr 2013 19:55:02 +0200
parents 868d87ed63c8
children d58c62b7447d
comparison
equal deleted inserted replaced
10183:868d87ed63c8 10184:9d75bcd7c890
64 #include "utilities/growableArray.hpp" 64 #include "utilities/growableArray.hpp"
65 #include "utilities/ostream.hpp" 65 #include "utilities/ostream.hpp"
66 66
67 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL; 67 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL;
68 68
69 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous) : 69 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) :
70 _class_loader(h_class_loader()), 70 _class_loader(h_class_loader()),
71 _is_anonymous(is_anonymous), _keep_alive(is_anonymous), // initially 71 _is_anonymous(is_anonymous), _keep_alive(is_anonymous), // initially
72 _metaspace(NULL), _unloading(false), _klasses(NULL), 72 _metaspace(NULL), _unloading(false), _klasses(NULL),
73 _claimed(0), _jmethod_ids(NULL), _handles(NULL), _deallocate_list(NULL), 73 _claimed(0), _jmethod_ids(NULL), _handles(NULL), _deallocate_list(NULL),
74 _next(NULL), _dependencies(), 74 _next(NULL), _dependencies(dependencies),
75 _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true)) { 75 _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true)) {
76 // empty 76 // empty
77 } 77 }
78 78
79 void ClassLoaderData::init_dependencies(TRAPS) { 79 void ClassLoaderData::init_dependencies(TRAPS) {
80 assert(!Universe::is_fully_initialized(), "should only be called when initializing");
81 assert(is_the_null_class_loader_data(), "should only call this for the null class loader");
80 _dependencies.init(CHECK); 82 _dependencies.init(CHECK);
81 } 83 }
82 84
83 void ClassLoaderData::Dependencies::init(TRAPS) { 85 void ClassLoaderData::Dependencies::init(TRAPS) {
84 // Create empty dependencies array to add to. CMS requires this to be 86 // Create empty dependencies array to add to. CMS requires this to be
497 ClassLoaderData* ClassLoaderDataGraph::_saved_head = NULL; 499 ClassLoaderData* ClassLoaderDataGraph::_saved_head = NULL;
498 500
499 // Add a new class loader data node to the list. Assign the newly created 501 // Add a new class loader data node to the list. Assign the newly created
500 // ClassLoaderData into the java/lang/ClassLoader object as a hidden field 502 // ClassLoaderData into the java/lang/ClassLoader object as a hidden field
501 ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_anonymous, TRAPS) { 503 ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_anonymous, TRAPS) {
502 // Not assigned a class loader data yet. 504 // We need to allocate all the oops for the ClassLoaderData before allocating the
503 // Create one. 505 // actual ClassLoaderData object.
504 ClassLoaderData* cld = new ClassLoaderData(loader, is_anonymous); 506 ClassLoaderData::Dependencies dependencies(CHECK_NULL);
505 cld->init_dependencies(THREAD); 507
506 if (HAS_PENDING_EXCEPTION) { 508 No_Safepoint_Verifier no_safepoints; // we mustn't GC until we've installed the
507 delete cld; 509 // ClassLoaderData in the graph since the CLD
508 return NULL; 510 // contains unhandled oops
509 } 511
510 512 ClassLoaderData* cld = new ClassLoaderData(loader, is_anonymous, dependencies);
511 No_Safepoint_Verifier no_safepoints; // nothing is keeping the dependencies array in cld alive 513
512 // make sure we don't encounter a GC until we've inserted
513 // cld into the CLDG
514 514
515 if (!is_anonymous) { 515 if (!is_anonymous) {
516 ClassLoaderData** cld_addr = java_lang_ClassLoader::loader_data_addr(loader()); 516 ClassLoaderData** cld_addr = java_lang_ClassLoader::loader_data_addr(loader());
517 if (cld_addr != NULL) { 517 // First, Atomically set it
518 // First, Atomically set it 518 ClassLoaderData* old = (ClassLoaderData*) Atomic::cmpxchg_ptr(cld, cld_addr, NULL);
519 ClassLoaderData* old = (ClassLoaderData*) Atomic::cmpxchg_ptr(cld, cld_addr, NULL); 519 if (old != NULL) {
520 if (old != NULL) { 520 delete cld;
521 delete cld; 521 // Returns the data.
522 // Returns the data. 522 return old;
523 return old;
524 }
525 } 523 }
526 } 524 }
527 525
528 // We won the race, and therefore the task of adding the data to the list of 526 // We won the race, and therefore the task of adding the data to the list of
529 // class loader data 527 // class loader data