421 _method_ordering = Universe::the_empty_int_array();
422 }
423 }
424
425 // create a new array of vtable_indices for default methods
426 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
427 Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
428 assert(default_vtable_indices() == NULL, "only create once");
429 set_default_vtable_indices(vtable_indices);
430 return vtable_indices;
431 }
432
433 InstanceKlass::InstanceKlass(const ClassFileParser& parser, unsigned kind, KlassID id) :
434 Klass(id),
435 _nest_members(NULL),
436 _nest_host_index(0),
437 _nest_host(NULL),
438 _static_field_size(parser.static_field_size()),
439 _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
440 _itable_len(parser.itable_size()),
441 _reference_type(parser.reference_type())
442 {
443 set_vtable_length(parser.vtable_size());
444 set_kind(kind);
445 set_access_flags(parser.access_flags());
446 set_is_unsafe_anonymous(parser.is_unsafe_anonymous());
447 set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
448 false));
449
450 assert(NULL == _methods, "underlying memory not zeroed?");
451 assert(is_instance_klass(), "is layout incorrect?");
452 assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
453
454 if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
455 SystemDictionaryShared::init_dumptime_info(this);
456 }
457 }
458
459 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
460 Array<Method*>* methods) {
1054 JvmtiExport::clear_detected_exception(jt);
1055 }
1056 DTRACE_CLASSINIT_PROBE_WAIT(error, -1, wait);
1057 if (e->is_a(SystemDictionary::Error_klass())) {
1058 THROW_OOP(e());
1059 } else {
1060 JavaCallArguments args(e);
1061 THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(),
1062 vmSymbols::throwable_void_signature(),
1063 &args);
1064 }
1065 }
1066 DTRACE_CLASSINIT_PROBE_WAIT(end, -1, wait);
1067 }
1068
1069
1070 void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) {
1071 Handle h_init_lock(THREAD, init_lock());
1072 if (h_init_lock() != NULL) {
1073 ObjectLocker ol(h_init_lock, THREAD);
1074 set_init_state(state);
1075 fence_and_clear_init_lock();
1076 ol.notify_all(CHECK);
1077 } else {
1078 assert(h_init_lock() != NULL, "The initialization state should never be set twice");
1079 set_init_state(state);
1080 }
1081 }
1082
1083 Klass* InstanceKlass::implementor() const {
1084 Klass* volatile* k = adr_implementor();
1085 if (k == NULL) {
1086 return NULL;
1087 } else {
1088 // This load races with inserts, and therefore needs acquire.
1089 Klass* kls = OrderAccess::load_acquire(k);
1090 if (kls != NULL && !kls->is_loader_alive()) {
1091 return NULL; // don't return unloaded class
1092 } else {
1093 return kls;
1094 }
1095 }
1096 }
1097
1098
3693
3694 JNIid* current = this;
3695 while (current != NULL) {
3696 guarantee(current->holder() == holder, "Invalid klass in JNIid");
3697 #ifdef ASSERT
3698 int o = current->offset();
3699 if (current->is_static_field_id()) {
3700 guarantee(o >= first_field_offset && o < end_field_offset, "Invalid static field offset in JNIid");
3701 }
3702 #endif
3703 current = current->next();
3704 }
3705 }
3706
3707 void InstanceKlass::set_init_state(ClassState state) {
3708 #ifdef ASSERT
3709 bool good_state = is_shared() ? (_init_state <= state)
3710 : (_init_state < state);
3711 assert(good_state || state == allocated, "illegal state transition");
3712 #endif
3713 _init_state = (u1)state;
3714 }
3715
3716 #if INCLUDE_JVMTI
3717
3718 // RedefineClasses() support for previous versions
3719
3720 // Globally, there is at least one previous version of a class to walk
3721 // during class unloading, which is saved because old methods in the class
3722 // are still running. Otherwise the previous version list is cleaned up.
3723 bool InstanceKlass::_has_previous_versions = false;
3724
3725 // Returns true if there are previous versions of a class for class
3726 // unloading only. Also resets the flag to false. purge_previous_version
3727 // will set the flag to true if there are any left, i.e., if there's any
3728 // work to do for next time. This is to avoid the expensive code cache
3729 // walk in CLDG::clean_deallocate_lists().
3730 bool InstanceKlass::has_previous_versions_and_reset() {
3731 bool ret = _has_previous_versions;
3732 log_trace(redefine, class, iklass, purge)("Class unloading: has_previous_versions = %s",
|
421 _method_ordering = Universe::the_empty_int_array();
422 }
423 }
424
425 // create a new array of vtable_indices for default methods
426 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
427 Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
428 assert(default_vtable_indices() == NULL, "only create once");
429 set_default_vtable_indices(vtable_indices);
430 return vtable_indices;
431 }
432
433 InstanceKlass::InstanceKlass(const ClassFileParser& parser, unsigned kind, KlassID id) :
434 Klass(id),
435 _nest_members(NULL),
436 _nest_host_index(0),
437 _nest_host(NULL),
438 _static_field_size(parser.static_field_size()),
439 _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
440 _itable_len(parser.itable_size()),
441 _init_thread(NULL),
442 _init_state(allocated),
443 _reference_type(parser.reference_type())
444 {
445 set_vtable_length(parser.vtable_size());
446 set_kind(kind);
447 set_access_flags(parser.access_flags());
448 set_is_unsafe_anonymous(parser.is_unsafe_anonymous());
449 set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
450 false));
451
452 assert(NULL == _methods, "underlying memory not zeroed?");
453 assert(is_instance_klass(), "is layout incorrect?");
454 assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
455
456 if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
457 SystemDictionaryShared::init_dumptime_info(this);
458 }
459 }
460
461 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
462 Array<Method*>* methods) {
1056 JvmtiExport::clear_detected_exception(jt);
1057 }
1058 DTRACE_CLASSINIT_PROBE_WAIT(error, -1, wait);
1059 if (e->is_a(SystemDictionary::Error_klass())) {
1060 THROW_OOP(e());
1061 } else {
1062 JavaCallArguments args(e);
1063 THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(),
1064 vmSymbols::throwable_void_signature(),
1065 &args);
1066 }
1067 }
1068 DTRACE_CLASSINIT_PROBE_WAIT(end, -1, wait);
1069 }
1070
1071
1072 void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) {
1073 Handle h_init_lock(THREAD, init_lock());
1074 if (h_init_lock() != NULL) {
1075 ObjectLocker ol(h_init_lock, THREAD);
1076 set_init_thread(NULL); // reset _init_thread before changing _init_state
1077 set_init_state(state);
1078 fence_and_clear_init_lock();
1079 ol.notify_all(CHECK);
1080 } else {
1081 assert(h_init_lock() != NULL, "The initialization state should never be set twice");
1082 set_init_thread(NULL); // reset _init_thread before changing _init_state
1083 set_init_state(state);
1084 }
1085 }
1086
1087 Klass* InstanceKlass::implementor() const {
1088 Klass* volatile* k = adr_implementor();
1089 if (k == NULL) {
1090 return NULL;
1091 } else {
1092 // This load races with inserts, and therefore needs acquire.
1093 Klass* kls = OrderAccess::load_acquire(k);
1094 if (kls != NULL && !kls->is_loader_alive()) {
1095 return NULL; // don't return unloaded class
1096 } else {
1097 return kls;
1098 }
1099 }
1100 }
1101
1102
3697
3698 JNIid* current = this;
3699 while (current != NULL) {
3700 guarantee(current->holder() == holder, "Invalid klass in JNIid");
3701 #ifdef ASSERT
3702 int o = current->offset();
3703 if (current->is_static_field_id()) {
3704 guarantee(o >= first_field_offset && o < end_field_offset, "Invalid static field offset in JNIid");
3705 }
3706 #endif
3707 current = current->next();
3708 }
3709 }
3710
3711 void InstanceKlass::set_init_state(ClassState state) {
3712 #ifdef ASSERT
3713 bool good_state = is_shared() ? (_init_state <= state)
3714 : (_init_state < state);
3715 assert(good_state || state == allocated, "illegal state transition");
3716 #endif
3717 assert(_init_thread == NULL, "should be cleared before state change");
3718 _init_state = (u1)state;
3719 }
3720
3721 #if INCLUDE_JVMTI
3722
3723 // RedefineClasses() support for previous versions
3724
3725 // Globally, there is at least one previous version of a class to walk
3726 // during class unloading, which is saved because old methods in the class
3727 // are still running. Otherwise the previous version list is cleaned up.
3728 bool InstanceKlass::_has_previous_versions = false;
3729
3730 // Returns true if there are previous versions of a class for class
3731 // unloading only. Also resets the flag to false. purge_previous_version
3732 // will set the flag to true if there are any left, i.e., if there's any
3733 // work to do for next time. This is to avoid the expensive code cache
3734 // walk in CLDG::clean_deallocate_lists().
3735 bool InstanceKlass::has_previous_versions_and_reset() {
3736 bool ret = _has_previous_versions;
3737 log_trace(redefine, class, iklass, purge)("Class unloading: has_previous_versions = %s",
|