Fri, 30 Nov 2012 12:01:34 -0800
Merge
1.1 --- a/src/share/vm/asm/codeBuffer.cpp Thu Nov 29 13:55:49 2012 -0800 1.2 +++ b/src/share/vm/asm/codeBuffer.cpp Fri Nov 30 12:01:34 2012 -0800 1.3 @@ -492,6 +492,26 @@ 1.4 dest->verify_section_allocation(); 1.5 } 1.6 1.7 +// Anonymous classes need mirror to keep the metadata alive but 1.8 +// for regular classes, the class_loader is sufficient. 1.9 +static void append_oop_references(GrowableArray<oop>* oops, Klass* k) { 1.10 + if (k->oop_is_instance()) { 1.11 + InstanceKlass* ik = InstanceKlass::cast(k); 1.12 + if (ik->is_anonymous()) { 1.13 + oop o = ik->java_mirror(); 1.14 + assert (o != NULL, "should have a mirror"); 1.15 + if (!oops->contains(o)) { 1.16 + oops->append(o); 1.17 + } 1.18 + return; // only need the mirror 1.19 + } 1.20 + } 1.21 + oop cl = k->class_loader(); 1.22 + if (cl != NULL && !oops->contains(cl)) { 1.23 + oops->append(cl); 1.24 + } 1.25 +} 1.26 + 1.27 void CodeBuffer::finalize_oop_references(methodHandle mh) { 1.28 No_Safepoint_Verifier nsv; 1.29 1.30 @@ -509,7 +529,6 @@ 1.31 if (md->metadata_is_immediate()) { 1.32 Metadata* m = md->metadata_value(); 1.33 if (oop_recorder()->is_real(m)) { 1.34 - oop o = NULL; 1.35 if (m->is_methodData()) { 1.36 m = ((MethodData*)m)->method(); 1.37 } 1.38 @@ -517,16 +536,13 @@ 1.39 m = ((Method*)m)->method_holder(); 1.40 } 1.41 if (m->is_klass()) { 1.42 - o = ((Klass*)m)->class_loader(); 1.43 + append_oop_references(&oops, (Klass*)m); 1.44 } else { 1.45 // XXX This will currently occur for MDO which don't 1.46 // have a backpointer. This has to be fixed later. 1.47 m->print(); 1.48 ShouldNotReachHere(); 1.49 } 1.50 - if (o != NULL && oops.find(o) == -1) { 1.51 - oops.append(o); 1.52 - } 1.53 } 1.54 } 1.55 } 1.56 @@ -537,7 +553,6 @@ 1.57 for (int i = 0; i < oop_recorder()->metadata_count(); i++) { 1.58 Metadata* m = oop_recorder()->metadata_at(i); 1.59 if (oop_recorder()->is_real(m)) { 1.60 - oop o = NULL; 1.61 if (m->is_methodData()) { 1.62 m = ((MethodData*)m)->method(); 1.63 } 1.64 @@ -545,24 +560,18 @@ 1.65 m = ((Method*)m)->method_holder(); 1.66 } 1.67 if (m->is_klass()) { 1.68 - o = ((Klass*)m)->class_loader(); 1.69 + append_oop_references(&oops, (Klass*)m); 1.70 } else { 1.71 m->print(); 1.72 ShouldNotReachHere(); 1.73 } 1.74 - if (o != NULL && oops.find(o) == -1) { 1.75 - oops.append(o); 1.76 - } 1.77 } 1.78 } 1.79 1.80 } 1.81 1.82 // Add the class loader of Method* for the nmethod itself 1.83 - oop cl = mh->method_holder()->class_loader(); 1.84 - if (cl != NULL) { 1.85 - oops.append(cl); 1.86 - } 1.87 + append_oop_references(&oops, mh->method_holder()); 1.88 1.89 // Add any oops that we've found 1.90 Thread* thread = Thread::current();
2.1 --- a/src/share/vm/ci/ciReplay.cpp Thu Nov 29 13:55:49 2012 -0800 2.2 +++ b/src/share/vm/ci/ciReplay.cpp Fri Nov 30 12:01:34 2012 -0800 2.3 @@ -31,7 +31,7 @@ 2.4 #include "memory/resourceArea.hpp" 2.5 #include "utilities/copy.hpp" 2.6 2.7 -#ifdef ASSERT 2.8 +#ifndef PRODUCT 2.9 2.10 // ciReplay 2.11 2.12 @@ -939,4 +939,4 @@ 2.13 ciMethodRecord* rec = replay_state->find_ciMethodRecord(method); 2.14 return rec != NULL; 2.15 } 2.16 -#endif 2.17 +#endif // PRODUCT
3.1 --- a/src/share/vm/ci/ciReplay.hpp Thu Nov 29 13:55:49 2012 -0800 3.2 +++ b/src/share/vm/ci/ciReplay.hpp Fri Nov 30 12:01:34 2012 -0800 3.3 @@ -32,7 +32,7 @@ 3.4 class ciReplay { 3.5 CI_PACKAGE_ACCESS 3.6 3.7 -#ifdef ASSERT 3.8 +#ifndef PRODUCT 3.9 private: 3.10 static int replay_impl(TRAPS); 3.11
4.1 --- a/src/share/vm/classfile/classFileParser.cpp Thu Nov 29 13:55:49 2012 -0800 4.2 +++ b/src/share/vm/classfile/classFileParser.cpp Fri Nov 30 12:01:34 2012 -0800 4.3 @@ -2949,7 +2949,7 @@ 4.4 4.5 4.6 instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name, 4.7 - Handle class_loader, 4.8 + ClassLoaderData* loader_data, 4.9 Handle protection_domain, 4.10 KlassHandle host_klass, 4.11 GrowableArray<Handle>* cp_patches, 4.12 @@ -2963,7 +2963,7 @@ 4.13 // original class bytes. 4.14 unsigned char *cached_class_file_bytes = NULL; 4.15 jint cached_class_file_length; 4.16 - ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader()); 4.17 + Handle class_loader(THREAD, loader_data->class_loader()); 4.18 bool has_default_methods = false; 4.19 ResourceMark rm(THREAD); 4.20 4.21 @@ -3004,7 +3004,7 @@ 4.22 unsigned char* ptr = cfs->buffer(); 4.23 unsigned char* end_ptr = cfs->buffer() + cfs->length(); 4.24 4.25 - JvmtiExport::post_class_file_load_hook(name, class_loader, protection_domain, 4.26 + JvmtiExport::post_class_file_load_hook(name, class_loader(), protection_domain, 4.27 &ptr, &end_ptr, 4.28 &cached_class_file_bytes, 4.29 &cached_class_file_length); 4.30 @@ -4003,8 +4003,7 @@ 4.31 assert(k->size_helper() > 0, "layout_helper is initialized"); 4.32 if ((!RegisterFinalizersAtInit && k->has_finalizer()) 4.33 || k->is_abstract() || k->is_interface() 4.34 - || (k->name() == vmSymbols::java_lang_Class() 4.35 - && k->class_loader_data()->is_the_null_class_loader_data()) 4.36 + || (k->name() == vmSymbols::java_lang_Class() && k->class_loader() == NULL) 4.37 || k->size_helper() >= FastAllocateSizeLimit) { 4.38 // Forbid fast-path allocation. 4.39 jint lh = Klass::instance_layout_helper(k->size_helper(), true);
5.1 --- a/src/share/vm/classfile/classFileParser.hpp Thu Nov 29 13:55:49 2012 -0800 5.2 +++ b/src/share/vm/classfile/classFileParser.hpp Fri Nov 30 12:01:34 2012 -0800 5.3 @@ -363,16 +363,16 @@ 5.4 // "parsed_name" is updated by this method, and is the name found 5.5 // while parsing the stream. 5.6 instanceKlassHandle parseClassFile(Symbol* name, 5.7 - Handle class_loader, 5.8 + ClassLoaderData* loader_data, 5.9 Handle protection_domain, 5.10 TempNewSymbol& parsed_name, 5.11 bool verify, 5.12 TRAPS) { 5.13 KlassHandle no_host_klass; 5.14 - return parseClassFile(name, class_loader, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD); 5.15 + return parseClassFile(name, loader_data, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD); 5.16 } 5.17 instanceKlassHandle parseClassFile(Symbol* name, 5.18 - Handle class_loader, 5.19 + ClassLoaderData* loader_data, 5.20 Handle protection_domain, 5.21 KlassHandle host_klass, 5.22 GrowableArray<Handle>* cp_patches,
6.1 --- a/src/share/vm/classfile/classLoader.cpp Thu Nov 29 13:55:49 2012 -0800 6.2 +++ b/src/share/vm/classfile/classLoader.cpp Fri Nov 30 12:01:34 2012 -0800 6.3 @@ -26,6 +26,7 @@ 6.4 #include "classfile/classFileParser.hpp" 6.5 #include "classfile/classFileStream.hpp" 6.6 #include "classfile/classLoader.hpp" 6.7 +#include "classfile/classLoaderData.inline.hpp" 6.8 #include "classfile/javaClasses.hpp" 6.9 #include "classfile/systemDictionary.hpp" 6.10 #include "classfile/vmSymbols.hpp" 6.11 @@ -910,11 +911,11 @@ 6.12 6.13 // class file found, parse it 6.14 ClassFileParser parser(stream); 6.15 - Handle class_loader; 6.16 + ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data(); 6.17 Handle protection_domain; 6.18 TempNewSymbol parsed_name = NULL; 6.19 instanceKlassHandle result = parser.parseClassFile(h_name, 6.20 - class_loader, 6.21 + loader_data, 6.22 protection_domain, 6.23 parsed_name, 6.24 false,
7.1 --- a/src/share/vm/classfile/classLoaderData.cpp Thu Nov 29 13:55:49 2012 -0800 7.2 +++ b/src/share/vm/classfile/classLoaderData.cpp Fri Nov 30 12:01:34 2012 -0800 7.3 @@ -65,13 +65,19 @@ 7.4 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL; 7.5 7.6 ClassLoaderData::ClassLoaderData(Handle h_class_loader) : _class_loader(h_class_loader()), 7.7 - _metaspace(NULL), _unloading(false), _klasses(NULL), 7.8 - _claimed(0), _jmethod_ids(NULL), _handles(NULL), 7.9 - _deallocate_list(NULL), _next(NULL), 7.10 + _metaspace(NULL), _unloading(false), _keep_alive(false), _klasses(NULL), 7.11 + _claimed(0), _jmethod_ids(NULL), _handles(NULL), _deallocate_list(NULL), 7.12 + _next(NULL), _dependencies(NULL), 7.13 _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true)) { 7.14 // empty 7.15 } 7.16 7.17 +void ClassLoaderData::init_dependencies(TRAPS) { 7.18 + // Create empty dependencies array to add to. CMS requires this to be 7.19 + // an oop so that it can track additions via card marks. We think. 7.20 + _dependencies = (oop)oopFactory::new_objectArray(2, CHECK); 7.21 +} 7.22 + 7.23 bool ClassLoaderData::claim() { 7.24 if (_claimed == 1) { 7.25 return false; 7.26 @@ -86,6 +92,7 @@ 7.27 } 7.28 7.29 f->do_oop(&_class_loader); 7.30 + f->do_oop(&_dependencies); 7.31 _handles->oops_do(f); 7.32 if (klass_closure != NULL) { 7.33 classes_do(klass_closure); 7.34 @@ -110,70 +117,100 @@ 7.35 ClassLoaderData * const from_cld = this; 7.36 ClassLoaderData * const to_cld = k->class_loader_data(); 7.37 7.38 - // Records dependency between non-null class loaders only. 7.39 - if (to_cld->is_the_null_class_loader_data() || from_cld->is_the_null_class_loader_data()) { 7.40 + // Dependency to the null class loader data doesn't need to be recorded 7.41 + // because the null class loader data never goes away. 7.42 + if (to_cld->is_the_null_class_loader_data()) { 7.43 return; 7.44 } 7.45 7.46 - // Check that this dependency isn't from the same or parent class_loader 7.47 - oop to = to_cld->class_loader(); 7.48 - oop from = from_cld->class_loader(); 7.49 + oop to; 7.50 + if (to_cld->is_anonymous()) { 7.51 + // Anonymous class dependencies are through the mirror. 7.52 + to = k->java_mirror(); 7.53 + } else { 7.54 + to = to_cld->class_loader(); 7.55 7.56 - oop curr = from; 7.57 - while (curr != NULL) { 7.58 - if (curr == to) { 7.59 - return; // this class loader is in the parent list, no need to add it. 7.60 + // If from_cld is anonymous, even if it's class_loader is a parent of 'to' 7.61 + // we still have to add it. The class_loader won't keep from_cld alive. 7.62 + if (!from_cld->is_anonymous()) { 7.63 + // Check that this dependency isn't from the same or parent class_loader 7.64 + oop from = from_cld->class_loader(); 7.65 + 7.66 + oop curr = from; 7.67 + while (curr != NULL) { 7.68 + if (curr == to) { 7.69 + return; // this class loader is in the parent list, no need to add it. 7.70 + } 7.71 + curr = java_lang_ClassLoader::parent(curr); 7.72 + } 7.73 } 7.74 - curr = java_lang_ClassLoader::parent(curr); 7.75 } 7.76 7.77 // It's a dependency we won't find through GC, add it. This is relatively rare 7.78 - from_cld->add_dependency(to_cld, CHECK); 7.79 + // Must handle over GC point. 7.80 + Handle dependency(THREAD, to); 7.81 + from_cld->add_dependency(dependency, CHECK); 7.82 } 7.83 7.84 -bool ClassLoaderData::has_dependency(ClassLoaderData* dependency) { 7.85 - oop loader = dependency->class_loader(); 7.86 7.87 - // Get objArrayOop out of the class_loader oop and see if this dependency 7.88 - // is there. Don't safepoint! These are all oops. 7.89 - // Dependency list is (oop class_loader, objArrayOop next) 7.90 - objArrayOop ok = (objArrayOop)java_lang_ClassLoader::dependencies(class_loader()); 7.91 +void ClassLoaderData::add_dependency(Handle dependency, TRAPS) { 7.92 + // Check first if this dependency is already in the list. 7.93 + // Save a pointer to the last to add to under the lock. 7.94 + objArrayOop ok = (objArrayOop)_dependencies; 7.95 + objArrayOop last = NULL; 7.96 while (ok != NULL) { 7.97 - if (ok->obj_at(0) == loader) { 7.98 - return true; 7.99 + last = ok; 7.100 + if (ok->obj_at(0) == dependency()) { 7.101 + // Don't need to add it 7.102 + return; 7.103 } 7.104 ok = (objArrayOop)ok->obj_at(1); 7.105 } 7.106 - return false; 7.107 + 7.108 + // Create a new dependency node with fields for (class_loader or mirror, next) 7.109 + objArrayOop deps = oopFactory::new_objectArray(2, CHECK); 7.110 + deps->obj_at_put(0, dependency()); 7.111 + 7.112 + // Must handle over more GC points 7.113 + objArrayHandle new_dependency(THREAD, deps); 7.114 + 7.115 + // Add the dependency under lock 7.116 + assert (last != NULL, "dependencies should be initialized"); 7.117 + objArrayHandle last_handle(THREAD, last); 7.118 + locked_add_dependency(last_handle, new_dependency); 7.119 } 7.120 7.121 -void ClassLoaderData::add_dependency(ClassLoaderData* dependency, TRAPS) { 7.122 - // Minimize the number of duplicates in the list. 7.123 - if (has_dependency(dependency)) { 7.124 - return; 7.125 +void ClassLoaderData::locked_add_dependency(objArrayHandle last_handle, 7.126 + objArrayHandle new_dependency) { 7.127 + 7.128 + // Have to lock and put the new dependency on the end of the dependency 7.129 + // array so the card mark for CMS sees that this dependency is new. 7.130 + // Can probably do this lock free with some effort. 7.131 + MutexLockerEx ml(metaspace_lock(), Mutex::_no_safepoint_check_flag); 7.132 + 7.133 + oop loader_or_mirror = new_dependency->obj_at(0); 7.134 + 7.135 + // Since the dependencies are only added, add to the end. 7.136 + objArrayOop end = last_handle(); 7.137 + objArrayOop last = NULL; 7.138 + while (end != NULL) { 7.139 + last = end; 7.140 + // check again if another thread added it to the end. 7.141 + if (end->obj_at(0) == loader_or_mirror) { 7.142 + // Don't need to add it 7.143 + return; 7.144 + } 7.145 + end = (objArrayOop)end->obj_at(1); 7.146 } 7.147 - 7.148 - // Create a new dependency node with fields for (class_loader, next) 7.149 - objArrayOop deps = oopFactory::new_objectArray(2, CHECK); 7.150 - deps->obj_at_put(0, dependency->class_loader()); 7.151 - 7.152 - // Add this lock free, using compare and exchange, need barriers for GC 7.153 - // Do the barrier first. 7.154 - HeapWord* addr = java_lang_ClassLoader::dependencies_addr(class_loader()); 7.155 - while (true) { 7.156 - oop old_dependency = java_lang_ClassLoader::dependencies(class_loader()); 7.157 - deps->obj_at_put(1, old_dependency); 7.158 - 7.159 - oop newold = oopDesc::atomic_compare_exchange_oop((oop)deps, addr, old_dependency, true); 7.160 - if (newold == old_dependency) { 7.161 - update_barrier_set((void*)addr, (oop)deps); 7.162 - // we won the race to add this dependency 7.163 - break; 7.164 - } 7.165 + assert (last != NULL, "dependencies should be initialized"); 7.166 + // fill in the first element with the oop in new_dependency. 7.167 + if (last->obj_at(0) == NULL) { 7.168 + last->obj_at_put(0, new_dependency->obj_at(0)); 7.169 + } else { 7.170 + last->obj_at_put(1, new_dependency()); 7.171 } 7.172 } 7.173 7.174 - 7.175 void ClassLoaderDataGraph::clear_claimed_marks() { 7.176 for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) { 7.177 cld->clear_claimed(); 7.178 @@ -187,7 +224,7 @@ 7.179 // link the new item into the list 7.180 _klasses = k; 7.181 7.182 - if (TraceClassLoaderData && k->class_loader_data() != NULL) { 7.183 + if (TraceClassLoaderData && Verbose && k->class_loader_data() != NULL) { 7.184 ResourceMark rm; 7.185 tty->print_cr("[TraceClassLoaderData] Adding k: " PTR_FORMAT " %s to CLD: " 7.186 PTR_FORMAT " loader: " PTR_FORMAT " %s", 7.187 @@ -195,8 +232,7 @@ 7.188 k->external_name(), 7.189 k->class_loader_data(), 7.190 k->class_loader(), 7.191 - k->class_loader() != NULL ? k->class_loader()->klass()->external_name() : "NULL" 7.192 - ); 7.193 + loader_name()); 7.194 } 7.195 } 7.196 7.197 @@ -221,6 +257,38 @@ 7.198 ShouldNotReachHere(); // should have found this class!! 7.199 } 7.200 7.201 + 7.202 +bool ClassLoaderData::is_anonymous() const { 7.203 + Klass* k = _klasses; 7.204 + return (_keep_alive || (k != NULL && k->oop_is_instance() && 7.205 + InstanceKlass::cast(k)->is_anonymous())); 7.206 +} 7.207 + 7.208 +void ClassLoaderData::unload() { 7.209 + _unloading = true; 7.210 + 7.211 + if (TraceClassLoaderData) { 7.212 + ResourceMark rm; 7.213 + tty->print("[ClassLoaderData: unload loader data "PTR_FORMAT, this); 7.214 + tty->print(" for instance "PTR_FORMAT" of %s", class_loader(), 7.215 + loader_name()); 7.216 + if (is_anonymous()) { 7.217 + tty->print(" for anonymous class "PTR_FORMAT " ", _klasses); 7.218 + } 7.219 + tty->print_cr("]"); 7.220 + } 7.221 +} 7.222 + 7.223 +bool ClassLoaderData::is_alive(BoolObjectClosure* is_alive_closure) const { 7.224 + bool alive = 7.225 + is_anonymous() ? 7.226 + is_alive_closure->do_object_b(_klasses->java_mirror()) : 7.227 + class_loader() == NULL || is_alive_closure->do_object_b(class_loader()); 7.228 + assert(!alive || claimed(), "must be claimed"); 7.229 + return alive; 7.230 +} 7.231 + 7.232 + 7.233 ClassLoaderData::~ClassLoaderData() { 7.234 Metaspace *m = _metaspace; 7.235 if (m != NULL) { 7.236 @@ -263,8 +331,8 @@ 7.237 if (_metaspace != NULL) { 7.238 return _metaspace; 7.239 } 7.240 - if (class_loader() == NULL) { 7.241 - assert(this == the_null_class_loader_data(), "Must be"); 7.242 + if (this == the_null_class_loader_data()) { 7.243 + assert (class_loader() == NULL, "Must be"); 7.244 size_t word_size = Metaspace::first_chunk_word_size(); 7.245 set_metaspace(new Metaspace(_metaspace_lock, word_size)); 7.246 } else { 7.247 @@ -325,12 +393,19 @@ 7.248 } 7.249 } 7.250 7.251 -#ifndef PRODUCT 7.252 -void ClassLoaderData::print_loader(ClassLoaderData *loader_data, outputStream* out) { 7.253 - oop class_loader = loader_data->class_loader(); 7.254 - out->print("%s", SystemDictionary::loader_name(class_loader)); 7.255 +// These anonymous class loaders are to contain classes used for JSR292 7.256 +ClassLoaderData* ClassLoaderData::anonymous_class_loader_data(oop loader, TRAPS) { 7.257 + // Add a new class loader data to the graph. 7.258 + ClassLoaderData* cld = ClassLoaderDataGraph::add(NULL, loader, CHECK_NULL); 7.259 + return cld; 7.260 } 7.261 7.262 +const char* ClassLoaderData::loader_name() { 7.263 + // Handles null class loader 7.264 + return SystemDictionary::loader_name(class_loader()); 7.265 +} 7.266 + 7.267 +#ifndef PRODUCT 7.268 // Define to dump klasses 7.269 #undef CLD_DUMP_KLASSES 7.270 7.271 @@ -338,8 +413,7 @@ 7.272 ResourceMark rm; 7.273 out->print("ClassLoaderData CLD: "PTR_FORMAT", loader: "PTR_FORMAT", loader_klass: "PTR_FORMAT" %s {", 7.274 this, class_loader(), 7.275 - class_loader() != NULL ? class_loader()->klass() : NULL, 7.276 - class_loader() != NULL ? class_loader()->klass()->external_name() : "NULL"); 7.277 + class_loader() != NULL ? class_loader()->klass() : NULL, loader_name()); 7.278 if (claimed()) out->print(" claimed "); 7.279 if (is_unloading()) out->print(" unloading "); 7.280 out->print(" handles " INTPTR_FORMAT, handles()); 7.281 @@ -373,8 +447,8 @@ 7.282 void ClassLoaderData::verify() { 7.283 oop cl = class_loader(); 7.284 7.285 - guarantee(this == class_loader_data(cl), "Must be the same"); 7.286 - guarantee(cl != NULL || this == ClassLoaderData::the_null_class_loader_data(), "must be"); 7.287 + guarantee(this == class_loader_data(cl) || is_anonymous(), "Must be the same"); 7.288 + guarantee(cl != NULL || this == ClassLoaderData::the_null_class_loader_data() || is_anonymous(), "must be"); 7.289 7.290 // Verify the integrity of the allocated space. 7.291 if (metaspace_or_null() != NULL) { 7.292 @@ -387,6 +461,7 @@ 7.293 } 7.294 } 7.295 7.296 + 7.297 // GC root of class loader data created. 7.298 ClassLoaderData* ClassLoaderDataGraph::_head = NULL; 7.299 ClassLoaderData* ClassLoaderDataGraph::_unloading = NULL; 7.300 @@ -395,19 +470,25 @@ 7.301 7.302 // Add a new class loader data node to the list. Assign the newly created 7.303 // ClassLoaderData into the java/lang/ClassLoader object as a hidden field 7.304 -ClassLoaderData* ClassLoaderDataGraph::add(ClassLoaderData** cld_addr, Handle loader_data) { 7.305 +ClassLoaderData* ClassLoaderDataGraph::add(ClassLoaderData** cld_addr, Handle loader, TRAPS) { 7.306 // Not assigned a class loader data yet. 7.307 // Create one. 7.308 ClassLoaderData* *list_head = &_head; 7.309 ClassLoaderData* next = _head; 7.310 - ClassLoaderData* cld = new ClassLoaderData(loader_data); 7.311 + ClassLoaderData* cld = new ClassLoaderData(loader); 7.312 7.313 - // First, Atomically set it. 7.314 - ClassLoaderData* old = (ClassLoaderData*) Atomic::cmpxchg_ptr(cld, cld_addr, NULL); 7.315 - if (old != NULL) { 7.316 - delete cld; 7.317 - // Returns the data. 7.318 - return old; 7.319 + if (cld_addr != NULL) { 7.320 + // First, Atomically set it 7.321 + ClassLoaderData* old = (ClassLoaderData*) Atomic::cmpxchg_ptr(cld, cld_addr, NULL); 7.322 + if (old != NULL) { 7.323 + delete cld; 7.324 + // Returns the data. 7.325 + return old; 7.326 + } 7.327 + } else { 7.328 + // Disallow unloading for this CLD during initialization if there is no 7.329 + // class_loader oop to link this to. 7.330 + cld->set_keep_alive(true); 7.331 } 7.332 7.333 // We won the race, and therefore the task of adding the data to the list of 7.334 @@ -417,16 +498,22 @@ 7.335 ClassLoaderData* exchanged = (ClassLoaderData*)Atomic::cmpxchg_ptr(cld, list_head, next); 7.336 if (exchanged == next) { 7.337 if (TraceClassLoaderData) { 7.338 + ResourceMark rm; 7.339 tty->print("[ClassLoaderData: "); 7.340 tty->print("create class loader data "PTR_FORMAT, cld); 7.341 - tty->print(" for instance "PTR_FORMAT" of ", cld->class_loader()); 7.342 - loader_data->klass()->name()->print_symbol_on(tty); 7.343 + tty->print(" for instance "PTR_FORMAT" of %s", cld->class_loader(), 7.344 + cld->loader_name()); 7.345 tty->print_cr("]"); 7.346 } 7.347 + // Create dependencies after the CLD is added to the list. Otherwise, 7.348 + // the GC GC will not find the CLD and the _class_loader field will 7.349 + // not be updated. 7.350 + cld->init_dependencies(CHECK_NULL); 7.351 return cld; 7.352 } 7.353 next = exchanged; 7.354 } while (true); 7.355 + 7.356 } 7.357 7.358 void ClassLoaderDataGraph::oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim) { 7.359 @@ -435,9 +522,19 @@ 7.360 } 7.361 } 7.362 7.363 +void ClassLoaderDataGraph::keep_alive_oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim) { 7.364 + for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) { 7.365 + if (cld->keep_alive()) { 7.366 + cld->oops_do(f, klass_closure, must_claim); 7.367 + } 7.368 + } 7.369 +} 7.370 + 7.371 void ClassLoaderDataGraph::always_strong_oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim) { 7.372 if (ClassUnloading) { 7.373 ClassLoaderData::the_null_class_loader_data()->oops_do(f, klass_closure, must_claim); 7.374 + // keep any special CLDs alive. 7.375 + ClassLoaderDataGraph::keep_alive_oops_do(f, klass_closure, must_claim); 7.376 } else { 7.377 ClassLoaderDataGraph::oops_do(f, klass_closure, must_claim); 7.378 } 7.379 @@ -516,9 +613,10 @@ 7.380 } 7.381 #endif // PRODUCT 7.382 7.383 + 7.384 // Move class loader data from main list to the unloaded list for unloading 7.385 // and deallocation later. 7.386 -bool ClassLoaderDataGraph::do_unloading(BoolObjectClosure* is_alive) { 7.387 +bool ClassLoaderDataGraph::do_unloading(BoolObjectClosure* is_alive_closure) { 7.388 ClassLoaderData* data = _head; 7.389 ClassLoaderData* prev = NULL; 7.390 bool seen_dead_loader = false; 7.391 @@ -527,8 +625,7 @@ 7.392 bool has_redefined_a_class = JvmtiExport::has_redefined_a_class(); 7.393 MetadataOnStackMark md_on_stack; 7.394 while (data != NULL) { 7.395 - if (data->class_loader() == NULL || is_alive->do_object_b(data->class_loader())) { 7.396 - assert(data->claimed(), "class loader data must have been claimed"); 7.397 + if (data->keep_alive() || data->is_alive(is_alive_closure)) { 7.398 if (has_redefined_a_class) { 7.399 data->classes_do(InstanceKlass::purge_previous_versions); 7.400 } 7.401 @@ -539,13 +636,7 @@ 7.402 } 7.403 seen_dead_loader = true; 7.404 ClassLoaderData* dead = data; 7.405 - dead->mark_for_unload(); 7.406 - if (TraceClassLoaderData) { 7.407 - tty->print("[ClassLoaderData: unload loader data "PTR_FORMAT, dead); 7.408 - tty->print(" for instance "PTR_FORMAT" of ", dead->class_loader()); 7.409 - dead->class_loader()->klass()->name()->print_symbol_on(tty); 7.410 - tty->print_cr("]"); 7.411 - } 7.412 + dead->unload(); 7.413 data = data->next(); 7.414 // Remove from loader list. 7.415 if (prev != NULL) {
8.1 --- a/src/share/vm/classfile/classLoaderData.hpp Thu Nov 29 13:55:49 2012 -0800 8.2 +++ b/src/share/vm/classfile/classLoaderData.hpp Fri Nov 30 12:01:34 2012 -0800 8.3 @@ -62,13 +62,14 @@ 8.4 // CMS support. 8.5 static ClassLoaderData* _saved_head; 8.6 8.7 - static ClassLoaderData* add(ClassLoaderData** loader_data_addr, Handle class_loader); 8.8 + static ClassLoaderData* add(ClassLoaderData** loader_data_addr, Handle class_loader, TRAPS); 8.9 public: 8.10 - static ClassLoaderData* find_or_create(Handle class_loader); 8.11 + static ClassLoaderData* find_or_create(Handle class_loader, TRAPS); 8.12 static void purge(); 8.13 static void clear_claimed_marks(); 8.14 static void oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim); 8.15 static void always_strong_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim); 8.16 + static void keep_alive_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim); 8.17 static void classes_do(KlassClosure* klass_closure); 8.18 static bool do_unloading(BoolObjectClosure* is_alive); 8.19 8.20 @@ -101,10 +102,13 @@ 8.21 8.22 oop _class_loader; // oop used to uniquely identify a class loader 8.23 // class loader or a canonical class path 8.24 + oop _dependencies; // oop to hold dependencies from this class loader 8.25 + // data to others. 8.26 Metaspace * _metaspace; // Meta-space where meta-data defined by the 8.27 // classes in the class loader are allocated. 8.28 Mutex* _metaspace_lock; // Locks the metaspace for allocations and setup. 8.29 bool _unloading; // true if this class loader goes away 8.30 + bool _keep_alive; // if this CLD can be unloaded for anonymous loaders 8.31 volatile int _claimed; // true if claimed, for example during GC traces. 8.32 // To avoid applying oop closure more than once. 8.33 // Has to be an int because we cas it. 8.34 @@ -129,8 +133,8 @@ 8.35 static Metaspace* _ro_metaspace; 8.36 static Metaspace* _rw_metaspace; 8.37 8.38 - bool has_dependency(ClassLoaderData* cld); 8.39 - void add_dependency(ClassLoaderData* to_loader_data, TRAPS); 8.40 + void add_dependency(Handle dependency, TRAPS); 8.41 + void locked_add_dependency(objArrayHandle last, objArrayHandle new_dependency); 8.42 8.43 void set_next(ClassLoaderData* next) { _next = next; } 8.44 ClassLoaderData* next() const { return _next; } 8.45 @@ -150,7 +154,9 @@ 8.46 bool claimed() const { return _claimed == 1; } 8.47 bool claim(); 8.48 8.49 - void mark_for_unload() { _unloading = true; } 8.50 + void unload(); 8.51 + bool keep_alive() const { return _keep_alive; } 8.52 + bool is_alive(BoolObjectClosure* is_alive_closure) const; 8.53 8.54 void classes_do(void f(InstanceKlass*)); 8.55 8.56 @@ -168,6 +174,8 @@ 8.57 return _the_null_class_loader_data; 8.58 } 8.59 8.60 + bool is_anonymous() const; 8.61 + 8.62 static void init_null_class_loader_data() { 8.63 assert(_the_null_class_loader_data == NULL, "cannot initialize twice"); 8.64 assert(ClassLoaderDataGraph::_head == NULL, "cannot initialize twice"); 8.65 @@ -194,6 +202,9 @@ 8.66 assert(!(is_the_null_class_loader_data() && _unloading), "The null class loader can never be unloaded"); 8.67 return _unloading; 8.68 } 8.69 + // Anonymous class loader data doesn't have anything to keep them from 8.70 + // being unloaded during parsing the anonymous class. 8.71 + void set_keep_alive(bool value) { _keep_alive = value; } 8.72 8.73 unsigned int identity_hash() { 8.74 return _class_loader == NULL ? 0 : _class_loader->identity_hash(); 8.75 @@ -211,15 +222,18 @@ 8.76 void print_value_on(outputStream* out) const PRODUCT_RETURN; 8.77 void dump(outputStream * const out) PRODUCT_RETURN; 8.78 void verify(); 8.79 + const char* loader_name(); 8.80 8.81 jobject add_handle(Handle h); 8.82 void add_class(Klass* k); 8.83 void remove_class(Klass* k); 8.84 void record_dependency(Klass* to, TRAPS); 8.85 + void init_dependencies(TRAPS); 8.86 8.87 void add_to_deallocate_list(Metadata* m); 8.88 8.89 static ClassLoaderData* class_loader_data(oop loader); 8.90 + static ClassLoaderData* anonymous_class_loader_data(oop loader, TRAPS); 8.91 static void print_loader(ClassLoaderData *loader_data, outputStream *out); 8.92 8.93 // CDS support
9.1 --- a/src/share/vm/classfile/classLoaderData.inline.hpp Thu Nov 29 13:55:49 2012 -0800 9.2 +++ b/src/share/vm/classfile/classLoaderData.inline.hpp Fri Nov 30 12:01:34 2012 -0800 9.3 @@ -33,7 +33,7 @@ 9.4 } 9.5 9.6 9.7 -inline ClassLoaderData *ClassLoaderDataGraph::find_or_create(Handle loader) { 9.8 +inline ClassLoaderData *ClassLoaderDataGraph::find_or_create(Handle loader, TRAPS) { 9.9 assert(loader() != NULL,"Must be a class loader"); 9.10 // Gets the class loader data out of the java/lang/ClassLoader object, if non-null 9.11 // it's already in the loader_data, so no need to add 9.12 @@ -42,5 +42,5 @@ 9.13 if (loader_data_id) { 9.14 return loader_data_id; 9.15 } 9.16 - return ClassLoaderDataGraph::add(loader_data_addr, loader); 9.17 + return ClassLoaderDataGraph::add(loader_data_addr, loader, THREAD); 9.18 }
10.1 --- a/src/share/vm/classfile/dictionary.cpp Thu Nov 29 13:55:49 2012 -0800 10.2 +++ b/src/share/vm/classfile/dictionary.cpp Fri Nov 30 12:01:34 2012 -0800 10.3 @@ -580,7 +580,7 @@ 10.4 // class loader must be present; a null class loader is the 10.5 // boostrap loader 10.6 guarantee(loader_data != NULL || DumpSharedSpaces || 10.7 - loader_data->is_the_null_class_loader_data() || 10.8 + loader_data->class_loader() == NULL || 10.9 loader_data->class_loader()->is_instance(), 10.10 "checking type of class_loader"); 10.11 e->verify();
11.1 --- a/src/share/vm/classfile/javaClasses.cpp Thu Nov 29 13:55:49 2012 -0800 11.2 +++ b/src/share/vm/classfile/javaClasses.cpp Fri Nov 30 12:01:34 2012 -0800 11.3 @@ -2544,8 +2544,8 @@ 11.4 11.5 void java_lang_invoke_MemberName::set_vmtarget(oop mname, Metadata* ref) { 11.6 assert(is_instance(mname), "wrong type"); 11.7 -#ifdef ASSERT 11.8 // check the type of the vmtarget 11.9 + oop dependency = NULL; 11.10 if (ref != NULL) { 11.11 switch (flags(mname) & (MN_IS_METHOD | 11.12 MN_IS_CONSTRUCTOR | 11.13 @@ -2553,28 +2553,21 @@ 11.14 case MN_IS_METHOD: 11.15 case MN_IS_CONSTRUCTOR: 11.16 assert(ref->is_method(), "should be a method"); 11.17 + dependency = ((Method*)ref)->method_holder()->java_mirror(); 11.18 break; 11.19 case MN_IS_FIELD: 11.20 assert(ref->is_klass(), "should be a class"); 11.21 + dependency = ((Klass*)ref)->java_mirror(); 11.22 break; 11.23 default: 11.24 ShouldNotReachHere(); 11.25 } 11.26 } 11.27 -#endif //ASSERT 11.28 mname->address_field_put(_vmtarget_offset, (address)ref); 11.29 - oop loader = NULL; 11.30 - if (ref != NULL) { 11.31 - if (ref->is_klass()) { 11.32 - loader = ((Klass*)ref)->class_loader(); 11.33 - } else if (ref->is_method()) { 11.34 - loader = ((Method*)ref)->method_holder()->class_loader(); 11.35 - } else { 11.36 - ShouldNotReachHere(); 11.37 - } 11.38 - } 11.39 - // Add a reference to the loader to ensure the metadata is kept alive 11.40 - mname->obj_field_put(_vmloader_offset, loader); 11.41 + // Add a reference to the loader (actually mirror because anonymous classes will not have 11.42 + // distinct loaders) to ensure the metadata is kept alive 11.43 + // This mirror may be different than the one in clazz field. 11.44 + mname->obj_field_put(_vmloader_offset, dependency); 11.45 } 11.46 11.47 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) { 11.48 @@ -2739,7 +2732,6 @@ 11.49 11.50 bool java_lang_ClassLoader::offsets_computed = false; 11.51 int java_lang_ClassLoader::_loader_data_offset = -1; 11.52 -int java_lang_ClassLoader::_dependencies_offset = -1; 11.53 int java_lang_ClassLoader::parallelCapable_offset = -1; 11.54 11.55 ClassLoaderData** java_lang_ClassLoader::loader_data_addr(oop loader) { 11.56 @@ -2751,18 +2743,6 @@ 11.57 return *java_lang_ClassLoader::loader_data_addr(loader); 11.58 } 11.59 11.60 -oop java_lang_ClassLoader::dependencies(oop loader) { 11.61 - return loader->obj_field(_dependencies_offset); 11.62 -} 11.63 - 11.64 -HeapWord* java_lang_ClassLoader::dependencies_addr(oop loader) { 11.65 - if (UseCompressedOops) { 11.66 - return (HeapWord*)loader->obj_field_addr<narrowOop>(_dependencies_offset); 11.67 - } else { 11.68 - return (HeapWord*)loader->obj_field_addr<oop>(_dependencies_offset); 11.69 - } 11.70 -} 11.71 - 11.72 void java_lang_ClassLoader::compute_offsets() { 11.73 assert(!offsets_computed, "offsets should be initialized only once"); 11.74 offsets_computed = true;
12.1 --- a/src/share/vm/classfile/javaClasses.hpp Thu Nov 29 13:55:49 2012 -0800 12.2 +++ b/src/share/vm/classfile/javaClasses.hpp Fri Nov 30 12:01:34 2012 -0800 12.3 @@ -1125,8 +1125,7 @@ 12.4 // Interface to java.lang.ClassLoader objects 12.5 12.6 #define CLASSLOADER_INJECTED_FIELDS(macro) \ 12.7 - macro(java_lang_ClassLoader, loader_data, intptr_signature, false) \ 12.8 - macro(java_lang_ClassLoader, dependencies, object_signature, false) 12.9 + macro(java_lang_ClassLoader, loader_data, intptr_signature, false) 12.10 12.11 class java_lang_ClassLoader : AllStatic { 12.12 private: 12.13 @@ -1135,7 +1134,6 @@ 12.14 hc_parent_offset = 0 12.15 }; 12.16 static int _loader_data_offset; 12.17 - static int _dependencies_offset; 12.18 static bool offsets_computed; 12.19 static int parent_offset; 12.20 static int parallelCapable_offset; 12.21 @@ -1146,9 +1144,6 @@ 12.22 static ClassLoaderData** loader_data_addr(oop loader); 12.23 static ClassLoaderData* loader_data(oop loader); 12.24 12.25 - static oop dependencies(oop loader); 12.26 - static HeapWord* dependencies_addr(oop loader); 12.27 - 12.28 static oop parent(oop loader); 12.29 static bool isAncestor(oop loader, oop cl); 12.30
13.1 --- a/src/share/vm/classfile/loaderConstraints.cpp Thu Nov 29 13:55:49 2012 -0800 13.2 +++ b/src/share/vm/classfile/loaderConstraints.cpp Fri Nov 30 12:01:34 2012 -0800 13.3 @@ -118,7 +118,7 @@ 13.4 probe->name()->as_C_string()); 13.5 for (int i = 0; i < probe->num_loaders(); i++) { 13.6 tty->print_cr("[ [%d]: %s", i, 13.7 - SystemDictionary::loader_name(probe->loader_data(i))); 13.8 + probe->loader_data(i)->loader_name()); 13.9 } 13.10 } 13.11 } 13.12 @@ -129,7 +129,7 @@ 13.13 if (TraceLoaderConstraints) { 13.14 ResourceMark rm; 13.15 tty->print_cr("[Purging loader %s from constraint for name %s", 13.16 - SystemDictionary::loader_name(probe->loader_data(n)), 13.17 + probe->loader_data(n)->loader_name(), 13.18 probe->name()->as_C_string() 13.19 ); 13.20 } 13.21 @@ -145,7 +145,7 @@ 13.22 tty->print_cr("[New loader list:"); 13.23 for (int i = 0; i < probe->num_loaders(); i++) { 13.24 tty->print_cr("[ [%d]: %s", i, 13.25 - SystemDictionary::loader_name(probe->loader_data(i))); 13.26 + probe->loader_data(i)->loader_name()); 13.27 } 13.28 } 13.29 13.30 @@ -400,7 +400,7 @@ 13.31 13.32 for (int i = 0; i < p1->num_loaders(); i++) { 13.33 tty->print_cr("[ [%d]: %s", i, 13.34 - SystemDictionary::loader_name(p1->loader_data(i))); 13.35 + p1->loader_data(i)->loader_name()); 13.36 } 13.37 if (p1->klass() == NULL) { 13.38 tty->print_cr("[... and setting class object]");
14.1 --- a/src/share/vm/classfile/systemDictionary.cpp Thu Nov 29 13:55:49 2012 -0800 14.2 +++ b/src/share/vm/classfile/systemDictionary.cpp Fri Nov 30 12:01:34 2012 -0800 14.3 @@ -106,9 +106,9 @@ 14.4 } 14.5 14.6 14.7 -ClassLoaderData* SystemDictionary::register_loader(Handle class_loader) { 14.8 +ClassLoaderData* SystemDictionary::register_loader(Handle class_loader, TRAPS) { 14.9 if (class_loader() == NULL) return ClassLoaderData::the_null_class_loader_data(); 14.10 - return ClassLoaderDataGraph::find_or_create(class_loader); 14.11 + return ClassLoaderDataGraph::find_or_create(class_loader, CHECK_NULL); 14.12 } 14.13 14.14 // ---------------------------------------------------------------------------- 14.15 @@ -591,7 +591,7 @@ 14.16 // UseNewReflection 14.17 // Fix for 4474172; see evaluation for more details 14.18 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); 14.19 - ClassLoaderData *loader_data = register_loader(class_loader); 14.20 + ClassLoaderData *loader_data = register_loader(class_loader, CHECK_NULL); 14.21 14.22 // Do lookup to see if class already exist and the protection domain 14.23 // has the right access 14.24 @@ -888,7 +888,7 @@ 14.25 // of the call to resolve_instance_class_or_null(). 14.26 // See evaluation 6790209 and 4474172 for more details. 14.27 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); 14.28 - ClassLoaderData* loader_data = register_loader(class_loader); 14.29 + ClassLoaderData* loader_data = register_loader(class_loader, CHECK_NULL); 14.30 14.31 unsigned int d_hash = dictionary()->compute_hash(class_name, loader_data); 14.32 int d_index = dictionary()->hash_to_index(d_hash); 14.33 @@ -948,6 +948,18 @@ 14.34 TRAPS) { 14.35 TempNewSymbol parsed_name = NULL; 14.36 14.37 + ClassLoaderData* loader_data; 14.38 + if (host_klass.not_null()) { 14.39 + // Create a new CLD for anonymous class, that uses the same class loader 14.40 + // as the host_klass 14.41 + assert(EnableInvokeDynamic, ""); 14.42 + guarantee(host_klass->class_loader() == class_loader(), "should be the same"); 14.43 + loader_data = ClassLoaderData::anonymous_class_loader_data(class_loader(), CHECK_NULL); 14.44 + loader_data->record_dependency(host_klass(), CHECK_NULL); 14.45 + } else { 14.46 + loader_data = ClassLoaderData::class_loader_data(class_loader()); 14.47 + } 14.48 + 14.49 // Parse the stream. Note that we do this even though this klass might 14.50 // already be present in the SystemDictionary, otherwise we would not 14.51 // throw potential ClassFormatErrors. 14.52 @@ -959,7 +971,7 @@ 14.53 // java.lang.Object through resolve_or_fail, not this path. 14.54 14.55 instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name, 14.56 - class_loader, 14.57 + loader_data, 14.58 protection_domain, 14.59 host_klass, 14.60 cp_patches, 14.61 @@ -973,8 +985,6 @@ 14.62 // Parsed name could be null if we threw an error before we got far 14.63 // enough along to parse it -- in that case, there is nothing to clean up. 14.64 if (parsed_name != NULL) { 14.65 - ClassLoaderData* loader_data = class_loader_data(class_loader); 14.66 - 14.67 unsigned int p_hash = placeholders()->compute_hash(parsed_name, 14.68 loader_data); 14.69 int p_index = placeholders()->hash_to_index(p_hash); 14.70 @@ -987,9 +997,8 @@ 14.71 14.72 if (host_klass.not_null() && k.not_null()) { 14.73 assert(EnableInvokeDynamic, ""); 14.74 + k->set_host_klass(host_klass()); 14.75 // If it's anonymous, initialize it now, since nobody else will. 14.76 - k->class_loader_data()->record_dependency(host_klass(), CHECK_NULL); 14.77 - k->set_host_klass(host_klass()); 14.78 14.79 { 14.80 MutexLocker mu_r(Compile_lock, THREAD); 14.81 @@ -1002,11 +1011,11 @@ 14.82 } 14.83 14.84 // Rewrite and patch constant pool here. 14.85 - k->link_class(THREAD); 14.86 + k->link_class(CHECK_NULL); 14.87 if (cp_patches != NULL) { 14.88 k->constants()->patch_resolved_references(cp_patches); 14.89 } 14.90 - k->eager_initialize(THREAD); 14.91 + k->eager_initialize(CHECK_NULL); 14.92 14.93 // notify jvmti 14.94 if (JvmtiExport::should_post_class_load()) { 14.95 @@ -1039,7 +1048,7 @@ 14.96 DoObjectLock = false; 14.97 } 14.98 14.99 - ClassLoaderData* loader_data = register_loader(class_loader); 14.100 + ClassLoaderData* loader_data = register_loader(class_loader, CHECK_NULL); 14.101 14.102 // Make sure we are synchronized on the class loader before we proceed 14.103 Handle lockObject = compute_loader_lock_object(class_loader, THREAD); 14.104 @@ -1059,7 +1068,7 @@ 14.105 // java.lang.Object through resolve_or_fail, not this path. 14.106 14.107 instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name, 14.108 - class_loader, 14.109 + loader_data, 14.110 protection_domain, 14.111 parsed_name, 14.112 verify, 14.113 @@ -2343,6 +2352,7 @@ 14.114 14.115 // Helper for unpacking the return value from linkMethod and linkCallSite. 14.116 static methodHandle unpack_method_and_appendix(Handle mname, 14.117 + KlassHandle accessing_klass, 14.118 objArrayHandle appendix_box, 14.119 Handle* appendix_result, 14.120 TRAPS) { 14.121 @@ -2361,6 +2371,12 @@ 14.122 #endif //PRODUCT 14.123 } 14.124 (*appendix_result) = Handle(THREAD, appendix); 14.125 + // the target is stored in the cpCache and if a reference to this 14.126 + // MethodName is dropped we need a way to make sure the 14.127 + // class_loader containing this method is kept alive. 14.128 + // FIXME: the appendix might also preserve this dependency. 14.129 + ClassLoaderData* this_key = InstanceKlass::cast(accessing_klass())->class_loader_data(); 14.130 + this_key->record_dependency(m->method_holder(), CHECK_NULL); // Can throw OOM 14.131 return methodHandle(THREAD, m); 14.132 } 14.133 } 14.134 @@ -2405,7 +2421,7 @@ 14.135 &args, CHECK_(empty)); 14.136 Handle mname(THREAD, (oop) result.get_jobject()); 14.137 (*method_type_result) = method_type; 14.138 - return unpack_method_and_appendix(mname, appendix_box, appendix_result, THREAD); 14.139 + return unpack_method_and_appendix(mname, accessing_klass, appendix_box, appendix_result, THREAD); 14.140 } 14.141 14.142 14.143 @@ -2596,7 +2612,7 @@ 14.144 &args, CHECK_(empty)); 14.145 Handle mname(THREAD, (oop) result.get_jobject()); 14.146 (*method_type_result) = method_type; 14.147 - return unpack_method_and_appendix(mname, appendix_box, appendix_result, THREAD); 14.148 + return unpack_method_and_appendix(mname, caller, appendix_box, appendix_result, THREAD); 14.149 } 14.150 14.151 // Since the identity hash code for symbols changes when the symbols are
15.1 --- a/src/share/vm/classfile/systemDictionary.hpp Thu Nov 29 13:55:49 2012 -0800 15.2 +++ b/src/share/vm/classfile/systemDictionary.hpp Fri Nov 30 12:01:34 2012 -0800 15.3 @@ -471,7 +471,7 @@ 15.4 static void compute_java_system_loader(TRAPS); 15.5 15.6 // Register a new class loader 15.7 - static ClassLoaderData* register_loader(Handle class_loader); 15.8 + static ClassLoaderData* register_loader(Handle class_loader, TRAPS); 15.9 private: 15.10 // Mirrors for primitive classes (created eagerly) 15.11 static oop check_mirror(oop m) { 15.12 @@ -531,7 +531,7 @@ 15.13 InstanceKlass::cast((loader)->klass())->name()->as_C_string() ); 15.14 } 15.15 static const char* loader_name(ClassLoaderData* loader_data) { 15.16 - return (loader_data->is_the_null_class_loader_data() ? "<bootloader>" : 15.17 + return (loader_data->class_loader() == NULL ? "<bootloader>" : 15.18 InstanceKlass::cast((loader_data->class_loader())->klass())->name()->as_C_string() ); 15.19 } 15.20
16.1 --- a/src/share/vm/compiler/compileBroker.cpp Thu Nov 29 13:55:49 2012 -0800 16.2 +++ b/src/share/vm/compiler/compileBroker.cpp Fri Nov 30 12:01:34 2012 -0800 16.3 @@ -269,10 +269,12 @@ 16.4 const char* comment, 16.5 bool is_blocking) { 16.6 assert(!_lock->is_locked(), "bad locking"); 16.7 + InstanceKlass* holder = method->method_holder(); 16.8 16.9 _compile_id = compile_id; 16.10 _method = method(); 16.11 - _method_loader = JNIHandles::make_global(_method->method_holder()->class_loader()); 16.12 + _method_holder = JNIHandles::make_global( 16.13 + holder->is_anonymous() ? holder->java_mirror(): holder->class_loader()); 16.14 _osr_bci = osr_bci; 16.15 _is_blocking = is_blocking; 16.16 _comp_level = comp_level; 16.17 @@ -283,7 +285,7 @@ 16.18 _code_handle = NULL; 16.19 16.20 _hot_method = NULL; 16.21 - _hot_method_loader = NULL; 16.22 + _hot_method_holder = NULL; 16.23 _hot_count = hot_count; 16.24 _time_queued = 0; // tidy 16.25 _comment = comment; 16.26 @@ -295,8 +297,12 @@ 16.27 _hot_method = _method; 16.28 } else { 16.29 _hot_method = hot_method(); 16.30 + // only add loader or mirror if different from _method_holder 16.31 + InstanceKlass* hot_holder = hot_method->method_holder(); 16.32 + _hot_method_holder = JNIHandles::make_global( 16.33 + hot_holder->is_anonymous() ? hot_holder->java_mirror() : 16.34 + hot_holder->class_loader()); 16.35 } 16.36 - _hot_method_loader = JNIHandles::make_global(_hot_method->method_holder()->class_loader()); 16.37 } 16.38 } 16.39 16.40 @@ -321,8 +327,8 @@ 16.41 void CompileTask::free() { 16.42 set_code(NULL); 16.43 assert(!_lock->is_locked(), "Should not be locked when freed"); 16.44 - JNIHandles::destroy_global(_method_loader); 16.45 - JNIHandles::destroy_global(_hot_method_loader); 16.46 + JNIHandles::destroy_global(_method_holder); 16.47 + JNIHandles::destroy_global(_hot_method_holder); 16.48 } 16.49 16.50
17.1 --- a/src/share/vm/compiler/compileBroker.hpp Thu Nov 29 13:55:49 2012 -0800 17.2 +++ b/src/share/vm/compiler/compileBroker.hpp Fri Nov 30 12:01:34 2012 -0800 17.3 @@ -43,7 +43,7 @@ 17.4 Monitor* _lock; 17.5 uint _compile_id; 17.6 Method* _method; 17.7 - jobject _method_loader; 17.8 + jobject _method_holder; 17.9 int _osr_bci; 17.10 bool _is_complete; 17.11 bool _is_success; 17.12 @@ -56,7 +56,7 @@ 17.13 // Fields used for logging why the compilation was initiated: 17.14 jlong _time_queued; // in units of os::elapsed_counter() 17.15 Method* _hot_method; // which method actually triggered this task 17.16 - jobject _hot_method_loader; 17.17 + jobject _hot_method_holder; 17.18 int _hot_count; // information about its invocation counter 17.19 const char* _comment; // more info about the task 17.20
18.1 --- a/src/share/vm/memory/metachunk.hpp Thu Nov 29 13:55:49 2012 -0800 18.2 +++ b/src/share/vm/memory/metachunk.hpp Fri Nov 30 12:01:34 2012 -0800 18.3 @@ -123,9 +123,7 @@ 18.4 18.5 void assert_is_mangled() const {/* Don't check "\*/} 18.6 18.7 -#ifdef ASSERT 18.8 - void mangle(); 18.9 -#endif // ASSERT 18.10 + NOT_PRODUCT(void mangle();) 18.11 18.12 void print_on(outputStream* st) const; 18.13 void verify();
19.1 --- a/src/share/vm/memory/metaspace.cpp Thu Nov 29 13:55:49 2012 -0800 19.2 +++ b/src/share/vm/memory/metaspace.cpp Fri Nov 30 12:01:34 2012 -0800 19.3 @@ -109,7 +109,6 @@ 19.4 size_t Metablock::_overhead = 0; 19.5 #endif 19.6 19.7 - 19.8 // Pointer to list of Metachunks. 19.9 class ChunkList VALUE_OBJ_CLASS_SPEC { 19.10 // List of free chunks 19.11 @@ -326,10 +325,12 @@ 19.12 bool expand_by(size_t words, bool pre_touch = false); 19.13 bool shrink_by(size_t words); 19.14 19.15 +#ifdef ASSERT 19.16 // Debug support 19.17 static void verify_virtual_space_total(); 19.18 static void verify_virtual_space_count(); 19.19 void mangle(); 19.20 +#endif 19.21 19.22 void print_on(outputStream* st) const; 19.23 }; 19.24 @@ -622,8 +623,8 @@ 19.25 void locked_print_chunks_in_use_on(outputStream* st) const; 19.26 19.27 void verify(); 19.28 + NOT_PRODUCT(void mangle_freed_chunks();) 19.29 #ifdef ASSERT 19.30 - void mangle_freed_chunks(); 19.31 void verify_allocation_total(); 19.32 #endif 19.33 }; 19.34 @@ -712,7 +713,7 @@ 19.35 bottom(), top(), end(), word_size()); 19.36 } 19.37 19.38 -#ifdef ASSERT 19.39 +#ifndef PRODUCT 19.40 void Metachunk::mangle() { 19.41 // Mangle the payload of the chunk and not the links that 19.42 // maintain list of chunks. 19.43 @@ -720,7 +721,7 @@ 19.44 size_t word_size = capacity_word_size() - overhead(); 19.45 Copy::fill_to_words(start, word_size, metadata_chunk_initialize); 19.46 } 19.47 -#endif // ASSERT 19.48 +#endif // PRODUCT 19.49 19.50 void Metachunk::verify() { 19.51 #ifdef ASSERT 19.52 @@ -918,10 +919,12 @@ 19.53 vs->high_boundary()); 19.54 } 19.55 19.56 +#ifdef ASSERT 19.57 void VirtualSpaceNode::mangle() { 19.58 size_t word_size = capacity_words_in_vs(); 19.59 Copy::fill_to_words((HeapWord*) low(), word_size, 0xf1f1f1f1); 19.60 } 19.61 +#endif // ASSERT 19.62 19.63 // VirtualSpaceList methods 19.64 // Space allocated from the VirtualSpace 19.65 @@ -1986,16 +1989,14 @@ 19.66 locked_print_chunks_in_use_on(gclog_or_tty); 19.67 } 19.68 19.69 + // Mangle freed memory. 19.70 + NOT_PRODUCT(mangle_freed_chunks();) 19.71 + 19.72 // Have to update before the chunks_in_use lists are emptied 19.73 // below. 19.74 chunk_manager->inc_free_chunks_total(sum_capacity_in_chunks_in_use(), 19.75 sum_count_in_chunks_in_use()); 19.76 19.77 -#ifdef ASSERT 19.78 - // Mangle freed memory. 19.79 - mangle_freed_chunks(); 19.80 -#endif // ASSERT 19.81 - 19.82 // Add all the chunks in use by this space manager 19.83 // to the global list of free chunks. 19.84 19.85 @@ -2274,7 +2275,7 @@ 19.86 " waste " SIZE_FORMAT, curr_total, used, free, capacity, waste); 19.87 } 19.88 19.89 -#ifdef ASSERT 19.90 +#ifndef PRODUCT 19.91 void SpaceManager::mangle_freed_chunks() { 19.92 for (ChunkIndex index = SmallIndex; 19.93 index < NumberOfInUseLists; 19.94 @@ -2292,11 +2293,16 @@ 19.95 } 19.96 } 19.97 } 19.98 -#endif // ASSERT 19.99 +#endif // PRODUCT 19.100 19.101 19.102 // MetaspaceAux 19.103 19.104 +size_t MetaspaceAux::used_in_bytes() { 19.105 + return (Metaspace::class_space_list()->used_words_sum() + 19.106 + Metaspace::space_list()->used_words_sum()) * BytesPerWord; 19.107 +} 19.108 + 19.109 size_t MetaspaceAux::used_in_bytes(Metaspace::MetadataType mdtype) { 19.110 size_t used = 0; 19.111 ClassLoaderDataGraphMetaspaceIterator iter; 19.112 @@ -2325,6 +2331,11 @@ 19.113 // The total words available for metadata allocation. This 19.114 // uses Metaspace capacity_words() which is the total words 19.115 // in chunks allocated for a Metaspace. 19.116 +size_t MetaspaceAux::capacity_in_bytes() { 19.117 + return (Metaspace::class_space_list()->capacity_words_sum() + 19.118 + Metaspace::space_list()->capacity_words_sum()) * BytesPerWord; 19.119 +} 19.120 + 19.121 size_t MetaspaceAux::capacity_in_bytes(Metaspace::MetadataType mdtype) { 19.122 size_t capacity = free_chunks_total(mdtype); 19.123 ClassLoaderDataGraphMetaspaceIterator iter; 19.124 @@ -2337,6 +2348,11 @@ 19.125 return capacity * BytesPerWord; 19.126 } 19.127 19.128 +size_t MetaspaceAux::reserved_in_bytes() { 19.129 + return (Metaspace::class_space_list()->virtual_space_total() + 19.130 + Metaspace::space_list()->virtual_space_total()) * BytesPerWord; 19.131 +} 19.132 + 19.133 size_t MetaspaceAux::reserved_in_bytes(Metaspace::MetadataType mdtype) { 19.134 size_t reserved = (mdtype == Metaspace::ClassType) ? 19.135 Metaspace::class_space_list()->virtual_space_total() :
20.1 --- a/src/share/vm/memory/metaspace.hpp Thu Nov 29 13:55:49 2012 -0800 20.2 +++ b/src/share/vm/memory/metaspace.hpp Fri Nov 30 12:01:34 2012 -0800 20.3 @@ -156,25 +156,16 @@ 20.4 20.5 public: 20.6 // Total of space allocated to metadata in all Metaspaces 20.7 - static size_t used_in_bytes() { 20.8 - return used_in_bytes(Metaspace::ClassType) + 20.9 - used_in_bytes(Metaspace::NonClassType); 20.10 - } 20.11 + static size_t used_in_bytes(); 20.12 20.13 // Total of available space in all Metaspaces 20.14 // Total of capacity allocated to all Metaspaces. This includes 20.15 // space in Metachunks not yet allocated and in the Metachunk 20.16 // freelist. 20.17 - static size_t capacity_in_bytes() { 20.18 - return capacity_in_bytes(Metaspace::ClassType) + 20.19 - capacity_in_bytes(Metaspace::NonClassType); 20.20 - } 20.21 + static size_t capacity_in_bytes(); 20.22 20.23 // Total space reserved in all Metaspaces 20.24 - static size_t reserved_in_bytes() { 20.25 - return reserved_in_bytes(Metaspace::ClassType) + 20.26 - reserved_in_bytes(Metaspace::NonClassType); 20.27 - } 20.28 + static size_t reserved_in_bytes(); 20.29 20.30 static size_t min_chunk_size(); 20.31
21.1 --- a/src/share/vm/memory/universe.cpp Thu Nov 29 13:55:49 2012 -0800 21.2 +++ b/src/share/vm/memory/universe.cpp Fri Nov 30 12:01:34 2012 -0800 21.3 @@ -407,6 +407,10 @@ 21.4 assert(i == _fullgc_alot_dummy_array->length(), "just checking"); 21.5 } 21.6 #endif 21.7 + 21.8 + // Initialize dependency array for null class loader 21.9 + ClassLoaderData::the_null_class_loader_data()->init_dependencies(CHECK); 21.10 + 21.11 } 21.12 21.13 // CDS support for patching vtables in metadata in the shared archive.
22.1 --- a/src/share/vm/oops/constantPool.cpp Thu Nov 29 13:55:49 2012 -0800 22.2 +++ b/src/share/vm/oops/constantPool.cpp Fri Nov 30 12:01:34 2012 -0800 22.3 @@ -340,9 +340,7 @@ 22.4 do_resolve = this_oop->tag_at(which).is_unresolved_klass(); 22.5 if (do_resolve) { 22.6 ClassLoaderData* this_key = this_oop->pool_holder()->class_loader_data(); 22.7 - if (!this_key->is_the_null_class_loader_data()) { 22.8 - this_key->record_dependency(k(), CHECK_NULL); // Can throw OOM 22.9 - } 22.10 + this_key->record_dependency(k(), CHECK_NULL); // Can throw OOM 22.11 this_oop->klass_at_put(which, k()); 22.12 } 22.13 }
23.1 --- a/src/share/vm/oops/klass.cpp Thu Nov 29 13:55:49 2012 -0800 23.2 +++ b/src/share/vm/oops/klass.cpp Fri Nov 30 12:01:34 2012 -0800 23.3 @@ -373,29 +373,22 @@ 23.4 debug_only(verify();) 23.5 } 23.6 23.7 -void Klass::remove_from_sibling_list() { 23.8 - // remove receiver from sibling list 23.9 - InstanceKlass* super = superklass(); 23.10 - assert(super != NULL || this == SystemDictionary::Object_klass(), "should have super"); 23.11 - if (super == NULL) return; // special case: class Object 23.12 - if (super->subklass() == this) { 23.13 - // first subklass 23.14 - super->set_subklass(_next_sibling); 23.15 - } else { 23.16 - Klass* sib = super->subklass(); 23.17 - while (sib->next_sibling() != this) { 23.18 - sib = sib->next_sibling(); 23.19 - }; 23.20 - sib->set_next_sibling(_next_sibling); 23.21 - } 23.22 -} 23.23 - 23.24 bool Klass::is_loader_alive(BoolObjectClosure* is_alive) { 23.25 assert(is_metadata(), "p is not meta-data"); 23.26 assert(ClassLoaderDataGraph::contains((address)this), "is in the metaspace"); 23.27 + 23.28 +#ifdef ASSERT 23.29 // The class is alive iff the class loader is alive. 23.30 oop loader = class_loader(); 23.31 - return (loader == NULL) || is_alive->do_object_b(loader); 23.32 + bool loader_alive = (loader == NULL) || is_alive->do_object_b(loader); 23.33 +#endif // ASSERT 23.34 + 23.35 + // The class is alive if it's mirror is alive (which should be marked if the 23.36 + // loader is alive) unless it's an anoymous class. 23.37 + bool mirror_alive = is_alive->do_object_b(java_mirror()); 23.38 + assert(!mirror_alive || loader_alive, "loader must be alive if the mirror is" 23.39 + " but not the other way around with anonymous classes"); 23.40 + return mirror_alive; 23.41 } 23.42 23.43 void Klass::clean_weak_klass_links(BoolObjectClosure* is_alive) { 23.44 @@ -416,10 +409,10 @@ 23.45 Klass* sub = current->subklass_oop(); 23.46 while (sub != NULL && !sub->is_loader_alive(is_alive)) { 23.47 #ifndef PRODUCT 23.48 - if (TraceClassUnloading && WizardMode) { 23.49 - ResourceMark rm; 23.50 + if (TraceClassUnloading && WizardMode) { 23.51 + ResourceMark rm; 23.52 tty->print_cr("[Unlinking class (subclass) %s]", sub->external_name()); 23.53 - } 23.54 + } 23.55 #endif 23.56 sub = sub->next_sibling_oop(); 23.57 } 23.58 @@ -431,16 +424,16 @@ 23.59 // Find and set the first alive sibling 23.60 Klass* sibling = current->next_sibling_oop(); 23.61 while (sibling != NULL && !sibling->is_loader_alive(is_alive)) { 23.62 - if (TraceClassUnloading && WizardMode) { 23.63 - ResourceMark rm; 23.64 + if (TraceClassUnloading && WizardMode) { 23.65 + ResourceMark rm; 23.66 tty->print_cr("[Unlinking class (sibling) %s]", sibling->external_name()); 23.67 - } 23.68 + } 23.69 sibling = sibling->next_sibling_oop(); 23.70 - } 23.71 + } 23.72 current->set_next_sibling(sibling); 23.73 if (sibling != NULL) { 23.74 stack.push(sibling); 23.75 -} 23.76 + } 23.77 23.78 // Clean the implementors list and method data. 23.79 if (current->oop_is_instance()) { 23.80 @@ -554,7 +547,11 @@ 23.81 InstanceKlass* ik = (InstanceKlass*) this; 23.82 if (ik->is_anonymous()) { 23.83 assert(EnableInvokeDynamic, ""); 23.84 - intptr_t hash = ik->java_mirror()->identity_hash(); 23.85 + intptr_t hash = 0; 23.86 + if (ik->java_mirror() != NULL) { 23.87 + // java_mirror might not be created yet, return 0 as hash. 23.88 + hash = ik->java_mirror()->identity_hash(); 23.89 + } 23.90 char hash_buf[40]; 23.91 sprintf(hash_buf, "/" UINTX_FORMAT, (uintx)hash); 23.92 size_t hash_len = strlen(hash_buf);
24.1 --- a/src/share/vm/oops/klass.hpp Thu Nov 29 13:55:49 2012 -0800 24.2 +++ b/src/share/vm/oops/klass.hpp Fri Nov 30 12:01:34 2012 -0800 24.3 @@ -267,7 +267,6 @@ 24.4 Klass* subklass() const; 24.5 Klass* next_sibling() const; 24.6 void append_to_sibling_list(); // add newly created receiver to superklass' subklass list 24.7 - void remove_from_sibling_list(); // remove receiver from sibling list 24.8 24.9 void set_next_link(Klass* k) { _next_link = k; } 24.10 Klass* next_link() const { return _next_link; } // The next klass defined by the class loader. 24.11 @@ -581,8 +580,8 @@ 24.12 // garbage collection support 24.13 virtual void oops_do(OopClosure* cl); 24.14 24.15 - // Checks if the class loader is alive. 24.16 - // Iff the class loader is alive the Klass is considered alive. 24.17 + // Iff the class loader (or mirror for anonymous classes) is alive the 24.18 + // Klass is considered alive. 24.19 // The is_alive closure passed in depends on the Garbage Collector used. 24.20 bool is_loader_alive(BoolObjectClosure* is_alive); 24.21
25.1 --- a/src/share/vm/oops/objArrayKlass.cpp Thu Nov 29 13:55:49 2012 -0800 25.2 +++ b/src/share/vm/oops/objArrayKlass.cpp Fri Nov 30 12:01:34 2012 -0800 25.3 @@ -88,11 +88,6 @@ 25.4 } 25.5 if (!supers_exist) { 25.6 // Oops. Not allocated yet. Back out, allocate it, and retry. 25.7 -#ifndef PRODUCT 25.8 - if (WizardMode) { 25.9 - tty->print_cr("Must retry array klass creation for depth %d",n); 25.10 - } 25.11 -#endif 25.12 KlassHandle ek; 25.13 { 25.14 MutexUnlocker mu(MultiArray_lock);
26.1 --- a/src/share/vm/prims/unsafe.cpp Thu Nov 29 13:55:49 2012 -0800 26.2 +++ b/src/share/vm/prims/unsafe.cpp Fri Nov 30 12:01:34 2012 -0800 26.3 @@ -996,7 +996,7 @@ 26.4 // not just a literal string. For such ldc instructions, the verifier uses the 26.5 // type Object instead of String, if the loaded constant is not in fact a String. 26.6 26.7 -static oop 26.8 +static instanceKlassHandle 26.9 Unsafe_DefineAnonymousClass_impl(JNIEnv *env, 26.10 jclass host_class, jbyteArray data, jobjectArray cp_patches_jh, 26.11 HeapWord* *temp_alloc, 26.12 @@ -1073,32 +1073,39 @@ 26.13 anon_klass = instanceKlassHandle(THREAD, anonk); 26.14 } 26.15 26.16 - // let caller initialize it as needed... 26.17 - 26.18 - return anon_klass->java_mirror(); 26.19 + return anon_klass; 26.20 } 26.21 26.22 UNSAFE_ENTRY(jclass, Unsafe_DefineAnonymousClass(JNIEnv *env, jobject unsafe, jclass host_class, jbyteArray data, jobjectArray cp_patches_jh)) 26.23 { 26.24 + instanceKlassHandle anon_klass; 26.25 + jobject res_jh = NULL; 26.26 + 26.27 UnsafeWrapper("Unsafe_DefineAnonymousClass"); 26.28 ResourceMark rm(THREAD); 26.29 26.30 HeapWord* temp_alloc = NULL; 26.31 26.32 - jobject res_jh = NULL; 26.33 - 26.34 - { oop res_oop = Unsafe_DefineAnonymousClass_impl(env, 26.35 - host_class, data, cp_patches_jh, 26.36 + anon_klass = Unsafe_DefineAnonymousClass_impl(env, host_class, data, 26.37 + cp_patches_jh, 26.38 &temp_alloc, THREAD); 26.39 - if (res_oop != NULL) 26.40 - res_jh = JNIHandles::make_local(env, res_oop); 26.41 - } 26.42 + if (anon_klass() != NULL) 26.43 + res_jh = JNIHandles::make_local(env, anon_klass->java_mirror()); 26.44 26.45 // try/finally clause: 26.46 if (temp_alloc != NULL) { 26.47 FREE_C_HEAP_ARRAY(HeapWord, temp_alloc, mtInternal); 26.48 } 26.49 26.50 + // The anonymous class loader data has been artificially been kept alive to 26.51 + // this point. The mirror and any instances of this class have to keep 26.52 + // it alive afterwards. 26.53 + if (anon_klass() != NULL) { 26.54 + anon_klass->class_loader_data()->set_keep_alive(false); 26.55 + } 26.56 + 26.57 + // let caller initialize it as needed... 26.58 + 26.59 return (jclass) res_jh; 26.60 } 26.61 UNSAFE_END
27.1 --- a/test/runtime/8003720/Asmator.java Thu Nov 29 13:55:49 2012 -0800 27.2 +++ b/test/runtime/8003720/Asmator.java Fri Nov 30 12:01:34 2012 -0800 27.3 @@ -1,9 +1,34 @@ 27.4 -import com.sun.xml.internal.ws.org.objectweb.asm.*; 27.5 +/* 27.6 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 27.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 27.8 + * 27.9 + * This code is free software; you can redistribute it and/or modify it 27.10 + * under the terms of the GNU General Public License version 2 only, as 27.11 + * published by the Free Software Foundation. 27.12 + * 27.13 + * This code is distributed in the hope that it will be useful, but WITHOUT 27.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 27.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27.16 + * version 2 for more details (a copy is included in the LICENSE file that 27.17 + * accompanied this code). 27.18 + * 27.19 + * You should have received a copy of the GNU General Public License version 27.20 + * 2 along with this work; if not, write to the Free Software Foundation, 27.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 27.22 + * 27.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 27.24 + * or visit www.oracle.com if you need additional information or have any 27.25 + * questions. 27.26 + * 27.27 + */ 27.28 + 27.29 +import jdk.internal.org.objectweb.asm.*; 27.30 27.31 class Asmator { 27.32 static byte[] fixup(byte[] buf) throws java.io.IOException { 27.33 ClassReader cr = new ClassReader(buf); 27.34 - ClassWriter cw = new ClassWriter(0) { 27.35 + ClassWriter cw = new ClassWriter(0); 27.36 + ClassVisitor cv = new ClassVisitor(Opcodes.ASM4, cw) { 27.37 public MethodVisitor visitMethod( 27.38 final int access, 27.39 final String name, 27.40 @@ -25,7 +50,7 @@ 27.41 return mv; 27.42 } 27.43 }; 27.44 - cr.accept(cw, 0); 27.45 + cr.accept(cv, 0); 27.46 return cw.toByteArray(); 27.47 } 27.48 }
28.1 --- a/test/runtime/8003720/Test8003720.java Thu Nov 29 13:55:49 2012 -0800 28.2 +++ b/test/runtime/8003720/Test8003720.java Fri Nov 30 12:01:34 2012 -0800 28.3 @@ -26,7 +26,7 @@ 28.4 * @test 28.5 * @bug 8003720 28.6 * @summary Method in interpreter stack frame can be deallocated 28.7 - * @compile -XDignore.symbol.file Victim.java 28.8 + * @compile -XDignore.symbol.file -source 1.7 -target 1.7 Victim.java 28.9 * @run main/othervm -Xverify:all -Xint Test8003720 28.10 */ 28.11