comparison src/share/vm/oops/instanceKlass.cpp @ 10408:836a62f43af9

Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author Doug Simon <doug.simon@oracle.com>
date Wed, 19 Jun 2013 10:45:56 +0200
parents 89e4d67fdd2a 6c138b9851fb
children 6b0fd0964b87
comparison
equal deleted inserted replaced
10086:e0fb8a213650 10408:836a62f43af9
52 #include "runtime/fieldDescriptor.hpp" 52 #include "runtime/fieldDescriptor.hpp"
53 #include "runtime/handles.inline.hpp" 53 #include "runtime/handles.inline.hpp"
54 #include "runtime/javaCalls.hpp" 54 #include "runtime/javaCalls.hpp"
55 #include "runtime/mutexLocker.hpp" 55 #include "runtime/mutexLocker.hpp"
56 #include "runtime/thread.inline.hpp" 56 #include "runtime/thread.inline.hpp"
57 #include "services/classLoadingService.hpp"
57 #include "services/threadService.hpp" 58 #include "services/threadService.hpp"
58 #include "utilities/dtrace.hpp" 59 #include "utilities/dtrace.hpp"
59 #include "utilities/macros.hpp" 60 #include "utilities/macros.hpp"
60 #if INCLUDE_ALL_GCS 61 #if INCLUDE_ALL_GCS
61 #include "gc_implementation/concurrentMarkSweep/cmsOopClosures.inline.hpp" 62 #include "gc_implementation/concurrentMarkSweep/cmsOopClosures.inline.hpp"
265 set_transitive_interfaces(NULL); 266 set_transitive_interfaces(NULL);
266 init_implementor(); 267 init_implementor();
267 set_fields(NULL, 0); 268 set_fields(NULL, 0);
268 set_constants(NULL); 269 set_constants(NULL);
269 set_class_loader_data(NULL); 270 set_class_loader_data(NULL);
270 set_protection_domain(NULL);
271 set_signers(NULL);
272 set_source_file_name(NULL); 271 set_source_file_name(NULL);
273 set_source_debug_extension(NULL, 0); 272 set_source_debug_extension(NULL, 0);
274 set_array_name(NULL); 273 set_array_name(NULL);
275 set_inner_classes(NULL); 274 set_inner_classes(NULL);
276 set_static_oop_field_count(0); 275 set_static_oop_field_count(0);
277 set_nonstatic_field_size(0); 276 set_nonstatic_field_size(0);
278 set_is_marked_dependent(false); 277 set_is_marked_dependent(false);
279 set_init_state(InstanceKlass::allocated); 278 set_init_state(InstanceKlass::allocated);
280 set_init_thread(NULL); 279 set_init_thread(NULL);
281 set_init_lock(NULL);
282 set_reference_type(rt); 280 set_reference_type(rt);
283 set_oop_map_cache(NULL); 281 set_oop_map_cache(NULL);
284 set_jni_ids(NULL); 282 set_jni_ids(NULL);
285 set_osr_nmethods_head(NULL); 283 set_osr_nmethods_head(NULL);
286 set_breakpoints(NULL); 284 set_breakpoints(NULL);
405 if (inner_classes() != Universe::the_empty_short_array()) { 403 if (inner_classes() != Universe::the_empty_short_array()) {
406 MetadataFactory::free_array<jushort>(loader_data, inner_classes()); 404 MetadataFactory::free_array<jushort>(loader_data, inner_classes());
407 } 405 }
408 set_inner_classes(NULL); 406 set_inner_classes(NULL);
409 407
410 // Null out Java heap objects, although these won't be walked to keep
411 // alive once this InstanceKlass is deallocated.
412 set_protection_domain(NULL);
413 set_signers(NULL);
414 set_init_lock(NULL);
415
416 // We should deallocate the Annotations instance 408 // We should deallocate the Annotations instance
417 MetadataFactory::free_metadata(loader_data, annotations()); 409 MetadataFactory::free_metadata(loader_data, annotations());
418 set_annotations(NULL); 410 set_annotations(NULL);
419 } 411 }
420 412
421 volatile oop InstanceKlass::init_lock() const {
422 volatile oop lock = _init_lock; // read once
423 assert((oop)lock != NULL || !is_not_initialized(), // initialized or in_error state
424 "only fully initialized state can have a null lock");
425 return lock;
426 }
427
428 // Set the initialization lock to null so the object can be GC'ed. Any racing
429 // threads to get this lock will see a null lock and will not lock.
430 // That's okay because they all check for initialized state after getting
431 // the lock and return.
432 void InstanceKlass::fence_and_clear_init_lock() {
433 // make sure previous stores are all done, notably the init_state.
434 OrderAccess::storestore();
435 klass_oop_store(&_init_lock, NULL);
436 assert(!is_not_initialized(), "class must be initialized now");
437 }
438
439
440 bool InstanceKlass::should_be_initialized() const { 413 bool InstanceKlass::should_be_initialized() const {
441 return !is_initialized(); 414 return !is_initialized();
442 } 415 }
443 416
444 klassVtable* InstanceKlass::vtable() const { 417 klassVtable* InstanceKlass::vtable() const {
467 instanceKlassHandle this_oop(thread, this); 440 instanceKlassHandle this_oop(thread, this);
468 eager_initialize_impl(this_oop); 441 eager_initialize_impl(this_oop);
469 } 442 }
470 } 443 }
471 444
445 // JVMTI spec thinks there are signers and protection domain in the
446 // instanceKlass. These accessors pretend these fields are there.
447 // The hprof specification also thinks these fields are in InstanceKlass.
448 oop InstanceKlass::protection_domain() const {
449 // return the protection_domain from the mirror
450 return java_lang_Class::protection_domain(java_mirror());
451 }
452
453 // To remove these from requires an incompatible change and CCC request.
454 objArrayOop InstanceKlass::signers() const {
455 // return the signers from the mirror
456 return java_lang_Class::signers(java_mirror());
457 }
458
459 volatile oop InstanceKlass::init_lock() const {
460 // return the init lock from the mirror
461 return java_lang_Class::init_lock(java_mirror());
462 }
472 463
473 void InstanceKlass::eager_initialize_impl(instanceKlassHandle this_oop) { 464 void InstanceKlass::eager_initialize_impl(instanceKlassHandle this_oop) {
474 EXCEPTION_MARK; 465 EXCEPTION_MARK;
475 volatile oop init_lock = this_oop->init_lock(); 466 volatile oop init_lock = this_oop->init_lock();
476 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); 467 ObjectLocker ol(init_lock, THREAD);
477 468
478 // abort if someone beat us to the initialization 469 // abort if someone beat us to the initialization
479 if (!this_oop->is_not_initialized()) return; // note: not equivalent to is_initialized() 470 if (!this_oop->is_not_initialized()) return; // note: not equivalent to is_initialized()
480 471
481 ClassState old_state = this_oop->init_state(); 472 ClassState old_state = this_oop->init_state();
490 if( old_state != this_oop->_init_state ) 481 if( old_state != this_oop->_init_state )
491 this_oop->set_init_state (old_state); 482 this_oop->set_init_state (old_state);
492 } else { 483 } else {
493 // linking successfull, mark class as initialized 484 // linking successfull, mark class as initialized
494 this_oop->set_init_state (fully_initialized); 485 this_oop->set_init_state (fully_initialized);
495 this_oop->fence_and_clear_init_lock();
496 // trace 486 // trace
497 if (TraceClassInitialization) { 487 if (TraceClassInitialization) {
498 ResourceMark rm(THREAD); 488 ResourceMark rm(THREAD);
499 tty->print_cr("[Initialized %s without side effects]", this_oop->external_name()); 489 tty->print_cr("[Initialized %s without side effects]", this_oop->external_name());
500 } 490 }
617 PerfClassTraceTime::CLASS_LINK); 607 PerfClassTraceTime::CLASS_LINK);
618 608
619 // verification & rewriting 609 // verification & rewriting
620 { 610 {
621 volatile oop init_lock = this_oop->init_lock(); 611 volatile oop init_lock = this_oop->init_lock();
622 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); 612 ObjectLocker ol(init_lock, THREAD);
623 // rewritten will have been set if loader constraint error found 613 // rewritten will have been set if loader constraint error found
624 // on an earlier link attempt 614 // on an earlier link attempt
625 // don't verify or rewrite if already rewritten 615 // don't verify or rewrite if already rewritten
626 616
627 if (!this_oop->is_linked()) { 617 if (!this_oop->is_linked()) {
740 730
741 // refer to the JVM book page 47 for description of steps 731 // refer to the JVM book page 47 for description of steps
742 // Step 1 732 // Step 1
743 { 733 {
744 volatile oop init_lock = this_oop->init_lock(); 734 volatile oop init_lock = this_oop->init_lock();
745 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); 735 ObjectLocker ol(init_lock, THREAD);
746 736
747 Thread *self = THREAD; // it's passed the current thread 737 Thread *self = THREAD; // it's passed the current thread
748 738
749 // Step 2 739 // Step 2
750 // If we were to use wait() instead of waitInterruptibly() then 740 // If we were to use wait() instead of waitInterruptibly() then
888 set_initialization_state_and_notify_impl(kh, state, CHECK); 878 set_initialization_state_and_notify_impl(kh, state, CHECK);
889 } 879 }
890 880
891 void InstanceKlass::set_initialization_state_and_notify_impl(instanceKlassHandle this_oop, ClassState state, TRAPS) { 881 void InstanceKlass::set_initialization_state_and_notify_impl(instanceKlassHandle this_oop, ClassState state, TRAPS) {
892 volatile oop init_lock = this_oop->init_lock(); 882 volatile oop init_lock = this_oop->init_lock();
893 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); 883 ObjectLocker ol(init_lock, THREAD);
894 this_oop->set_init_state(state); 884 this_oop->set_init_state(state);
895 this_oop->fence_and_clear_init_lock();
896 ol.notify_all(CHECK); 885 ol.notify_all(CHECK);
897 } 886 }
898 887
899 // The embedded _implementor field can only record one implementor. 888 // The embedded _implementor field can only record one implementor.
900 // When there are more than one implementors, the _implementor field 889 // When there are more than one implementors, the _implementor field
1901 #endif //PRODUCT 1890 #endif //PRODUCT
1902 1891
1903 1892
1904 // Garbage collection 1893 // Garbage collection
1905 1894
1906 void InstanceKlass::oops_do(OopClosure* cl) {
1907 Klass::oops_do(cl);
1908
1909 cl->do_oop(adr_protection_domain());
1910 cl->do_oop(adr_signers());
1911 cl->do_oop(adr_init_lock());
1912
1913 // Don't walk the arrays since they are walked from the ClassLoaderData objects.
1914 }
1915
1916 #ifdef ASSERT 1895 #ifdef ASSERT
1917 template <class T> void assert_is_in(T *p) { 1896 template <class T> void assert_is_in(T *p) {
1918 T heap_oop = oopDesc::load_heap_oop(p); 1897 T heap_oop = oopDesc::load_heap_oop(p);
1919 if (!oopDesc::is_null(heap_oop)) { 1898 if (!oopDesc::is_null(heap_oop)) {
1920 oop o = oopDesc::decode_heap_oop_not_null(heap_oop); 1899 oop o = oopDesc::decode_heap_oop_not_null(heap_oop);
2259 for (int i = 0; i < methods()->length(); i++) { 2238 for (int i = 0; i < methods()->length(); i++) {
2260 Method* m = methods()->at(i); 2239 Method* m = methods()->at(i);
2261 m->remove_unshareable_info(); 2240 m->remove_unshareable_info();
2262 } 2241 }
2263 2242
2264 // Need to reinstate when reading back the class.
2265 set_init_lock(NULL);
2266
2267 // do array classes also. 2243 // do array classes also.
2268 array_klasses_do(remove_unshareable_in_class); 2244 array_klasses_do(remove_unshareable_in_class);
2269 } 2245 }
2270 2246
2271 void restore_unshareable_in_class(Klass* k, TRAPS) { 2247 void restore_unshareable_in_class(Klass* k, TRAPS) {
2293 ResourceMark rm(THREAD); 2269 ResourceMark rm(THREAD);
2294 ik->vtable()->initialize_vtable(false, CHECK); 2270 ik->vtable()->initialize_vtable(false, CHECK);
2295 ik->itable()->initialize_itable(false, CHECK); 2271 ik->itable()->initialize_itable(false, CHECK);
2296 } 2272 }
2297 2273
2298 // Allocate a simple java object for a lock.
2299 // This needs to be a java object because during class initialization
2300 // it can be held across a java call.
2301 typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK);
2302 Handle h(THREAD, (oop)r);
2303 ik->set_init_lock(h());
2304
2305 // restore constant pool resolved references 2274 // restore constant pool resolved references
2306 ik->constants()->restore_unshareable_info(CHECK); 2275 ik->constants()->restore_unshareable_info(CHECK);
2307 2276
2308 ik->array_klasses_do(restore_unshareable_in_class, CHECK); 2277 ik->array_klasses_do(restore_unshareable_in_class, CHECK);
2309 } 2278 }
2310 2279
2311 static void clear_all_breakpoints(Method* m) { 2280 static void clear_all_breakpoints(Method* m) {
2312 m->clear_all_breakpoints(); 2281 m->clear_all_breakpoints();
2313 } 2282 }
2314 2283
2284
2285 void InstanceKlass::notify_unload_class(InstanceKlass* ik) {
2286 // notify the debugger
2287 if (JvmtiExport::should_post_class_unload()) {
2288 JvmtiExport::post_class_unload(ik);
2289 }
2290
2291 // notify ClassLoadingService of class unload
2292 ClassLoadingService::notify_class_unloaded(ik);
2293 }
2294
2295 void InstanceKlass::release_C_heap_structures(InstanceKlass* ik) {
2296 // Clean up C heap
2297 ik->release_C_heap_structures();
2298 ik->constants()->release_C_heap_structures();
2299 }
2300
2315 void InstanceKlass::release_C_heap_structures() { 2301 void InstanceKlass::release_C_heap_structures() {
2302
2303 // Can't release the constant pool here because the constant pool can be
2304 // deallocated separately from the InstanceKlass for default methods and
2305 // redefine classes.
2306
2316 // Deallocate oop map cache 2307 // Deallocate oop map cache
2317 if (_oop_map_cache != NULL) { 2308 if (_oop_map_cache != NULL) {
2318 delete _oop_map_cache; 2309 delete _oop_map_cache;
2319 _oop_map_cache = NULL; 2310 _oop_map_cache = NULL;
2320 } 2311 }
2325 2316
2326 jmethodID* jmeths = methods_jmethod_ids_acquire(); 2317 jmethodID* jmeths = methods_jmethod_ids_acquire();
2327 if (jmeths != (jmethodID*)NULL) { 2318 if (jmeths != (jmethodID*)NULL) {
2328 release_set_methods_jmethod_ids(NULL); 2319 release_set_methods_jmethod_ids(NULL);
2329 FreeHeap(jmeths); 2320 FreeHeap(jmeths);
2321 }
2322
2323 // Deallocate MemberNameTable
2324 {
2325 Mutex* lock_or_null = SafepointSynchronize::is_at_safepoint() ? NULL : MemberNameTable_lock;
2326 MutexLockerEx ml(lock_or_null, Mutex::_no_safepoint_check_flag);
2327 MemberNameTable* mnt = member_names();
2328 if (mnt != NULL) {
2329 delete mnt;
2330 set_member_names(NULL);
2331 }
2330 } 2332 }
2331 2333
2332 int* indices = methods_cached_itable_indices_acquire(); 2334 int* indices = methods_cached_itable_indices_acquire();
2333 if (indices != (int*)NULL) { 2335 if (indices != (int*)NULL) {
2334 release_set_methods_cached_itable_indices(NULL); 2336 release_set_methods_cached_itable_indices(NULL);
2714 } 2716 }
2715 // Remember to unlock again 2717 // Remember to unlock again
2716 OsrList_lock->unlock(); 2718 OsrList_lock->unlock();
2717 } 2719 }
2718 2720
2719 nmethod* InstanceKlass::lookup_osr_nmethod(Method* const m, int bci, int comp_level, bool match_level) const { 2721 nmethod* InstanceKlass::lookup_osr_nmethod(const Method* m, int bci, int comp_level, bool match_level) const {
2720 // This is a short non-blocking critical region, so the no safepoint check is ok. 2722 // This is a short non-blocking critical region, so the no safepoint check is ok.
2721 OsrList_lock->lock_without_safepoint_check(); 2723 OsrList_lock->lock_without_safepoint_check();
2722 nmethod* osr = osr_nmethods_head(); 2724 nmethod* osr = osr_nmethods_head();
2723 nmethod* best = NULL; 2725 nmethod* best = NULL;
2724 while (osr != NULL) { 2726 while (osr != NULL) {
2755 return best; 2757 return best;
2756 } 2758 }
2757 return NULL; 2759 return NULL;
2758 } 2760 }
2759 2761
2762 void InstanceKlass::add_member_name(int index, Handle mem_name) {
2763 jweak mem_name_wref = JNIHandles::make_weak_global(mem_name);
2764 MutexLocker ml(MemberNameTable_lock);
2765 assert(0 <= index && index < idnum_allocated_count(), "index is out of bounds");
2766 DEBUG_ONLY(No_Safepoint_Verifier nsv);
2767
2768 if (_member_names == NULL) {
2769 _member_names = new (ResourceObj::C_HEAP, mtClass) MemberNameTable(idnum_allocated_count());
2770 }
2771 _member_names->add_member_name(index, mem_name_wref);
2772 }
2773
2774 oop InstanceKlass::get_member_name(int index) {
2775 MutexLocker ml(MemberNameTable_lock);
2776 assert(0 <= index && index < idnum_allocated_count(), "index is out of bounds");
2777 DEBUG_ONLY(No_Safepoint_Verifier nsv);
2778
2779 if (_member_names == NULL) {
2780 return NULL;
2781 }
2782 oop mem_name =_member_names->get_member_name(index);
2783 return mem_name;
2784 }
2785
2760 // ----------------------------------------------------------------------------------------------------- 2786 // -----------------------------------------------------------------------------------------------------
2761 // Printing 2787 // Printing
2762 2788
2763 #ifndef PRODUCT 2789 #ifndef PRODUCT
2764 2790
2815 if (class_loader_data() != NULL) { 2841 if (class_loader_data() != NULL) {
2816 st->print(BULLET"class loader data: "); 2842 st->print(BULLET"class loader data: ");
2817 class_loader_data()->print_value_on(st); 2843 class_loader_data()->print_value_on(st);
2818 st->cr(); 2844 st->cr();
2819 } 2845 }
2820 st->print(BULLET"protection domain: "); ((InstanceKlass*)this)->protection_domain()->print_value_on(st); st->cr();
2821 st->print(BULLET"host class: "); host_klass()->print_value_on_maybe_null(st); st->cr(); 2846 st->print(BULLET"host class: "); host_klass()->print_value_on_maybe_null(st); st->cr();
2822 st->print(BULLET"signers: "); signers()->print_value_on(st); st->cr();
2823 st->print(BULLET"init_lock: "); ((oop)_init_lock)->print_value_on(st); st->cr();
2824 if (source_file_name() != NULL) { 2847 if (source_file_name() != NULL) {
2825 st->print(BULLET"source file: "); 2848 st->print(BULLET"source file: ");
2826 source_file_name()->print_value_on(st); 2849 source_file_name()->print_value_on(st);
2827 st->cr(); 2850 st->cr();
2828 } 2851 }
3019 int n = 0; 3042 int n = 0;
3020 n += (sz->_methods_array_bytes = sz->count_array(methods())); 3043 n += (sz->_methods_array_bytes = sz->count_array(methods()));
3021 n += (sz->_method_ordering_bytes = sz->count_array(method_ordering())); 3044 n += (sz->_method_ordering_bytes = sz->count_array(method_ordering()));
3022 n += (sz->_local_interfaces_bytes = sz->count_array(local_interfaces())); 3045 n += (sz->_local_interfaces_bytes = sz->count_array(local_interfaces()));
3023 n += (sz->_transitive_interfaces_bytes = sz->count_array(transitive_interfaces())); 3046 n += (sz->_transitive_interfaces_bytes = sz->count_array(transitive_interfaces()));
3024 n += (sz->_signers_bytes = sz->count_array(signers()));
3025 n += (sz->_fields_bytes = sz->count_array(fields())); 3047 n += (sz->_fields_bytes = sz->count_array(fields()));
3026 n += (sz->_inner_classes_bytes = sz->count_array(inner_classes())); 3048 n += (sz->_inner_classes_bytes = sz->count_array(inner_classes()));
3027 sz->_ro_bytes += n; 3049 sz->_ro_bytes += n;
3028 3050
3029 const ConstantPool* cp = constants(); 3051 const ConstantPool* cp = constants();
3185 } 3207 }
3186 if (constants() != NULL) { 3208 if (constants() != NULL) {
3187 guarantee(constants()->is_metadata(), "should be in metaspace"); 3209 guarantee(constants()->is_metadata(), "should be in metaspace");
3188 guarantee(constants()->is_constantPool(), "should be constant pool"); 3210 guarantee(constants()->is_constantPool(), "should be constant pool");
3189 } 3211 }
3190 if (protection_domain() != NULL) { 3212 const Klass* host = host_klass();
3191 guarantee(protection_domain()->is_oop(), "should be oop"); 3213 if (host != NULL) {
3192 } 3214 guarantee(host->is_metadata(), "should be in metaspace");
3193 if (host_klass() != NULL) { 3215 guarantee(host->is_klass(), "should be klass");
3194 guarantee(host_klass()->is_metadata(), "should be in metaspace");
3195 guarantee(host_klass()->is_klass(), "should be klass");
3196 }
3197 if (signers() != NULL) {
3198 guarantee(signers()->is_objArray(), "should be obj array");
3199 } 3216 }
3200 } 3217 }
3201 3218
3202 void InstanceKlass::oop_verify_on(oop obj, outputStream* st) { 3219 void InstanceKlass::oop_verify_on(oop obj, outputStream* st) {
3203 Klass::oop_verify_on(obj, st); 3220 Klass::oop_verify_on(obj, st);