# HG changeset patch # User coleenp # Date 1323214131 18000 # Node ID 52b5d32fbfafc37bc23d913b96d7fd37bf4e7aed # Parent da4dd142ea01ed0bcfded9dd73d28e0e2cddffe8 7117052: instanceKlass::_init_state can be u1 type Summary: Change instanceKlass::_init_state field to u1 type. Reviewed-by: bdelsart, coleenp, dholmes, phh, never Contributed-by: Jiangli Zhou diff -r da4dd142ea01 -r 52b5d32fbfaf src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp --- a/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp Tue Nov 29 14:44:44 2011 -0500 +++ b/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp Tue Dec 06 18:28:51 2011 -0500 @@ -2455,7 +2455,7 @@ op->obj()->as_register() == O0 && op->klass()->as_register() == G5, "must be"); if (op->init_check()) { - __ ld(op->klass()->as_register(), + __ ldub(op->klass()->as_register(), instanceKlass::init_state_offset_in_bytes() + sizeof(oopDesc), op->tmp1()->as_register()); add_debug_info_for_null_check_here(op->stub()->info()); diff -r da4dd142ea01 -r 52b5d32fbfaf src/cpu/sparc/vm/c1_Runtime1_sparc.cpp --- a/src/cpu/sparc/vm/c1_Runtime1_sparc.cpp Tue Nov 29 14:44:44 2011 -0500 +++ b/src/cpu/sparc/vm/c1_Runtime1_sparc.cpp Tue Dec 06 18:28:51 2011 -0500 @@ -398,7 +398,7 @@ if (id == fast_new_instance_init_check_id) { // make sure the klass is initialized - __ ld(G5_klass, instanceKlass::init_state_offset_in_bytes() + sizeof(oopDesc), G3_t1); + __ ldub(G5_klass, instanceKlass::init_state_offset_in_bytes() + sizeof(oopDesc), G3_t1); __ cmp_and_br_short(G3_t1, instanceKlass::fully_initialized, Assembler::notEqual, Assembler::pn, slow_path); } #ifdef ASSERT diff -r da4dd142ea01 -r 52b5d32fbfaf src/cpu/sparc/vm/templateTable_sparc.cpp --- a/src/cpu/sparc/vm/templateTable_sparc.cpp Tue Nov 29 14:44:44 2011 -0500 +++ b/src/cpu/sparc/vm/templateTable_sparc.cpp Tue Dec 06 18:28:51 2011 -0500 @@ -3350,7 +3350,7 @@ __ ld_ptr(Rscratch, Roffset, RinstanceKlass); // make sure klass is fully initialized: - __ ld(RinstanceKlass, instanceKlass::init_state_offset_in_bytes() + sizeof(oopDesc), G3_scratch); + __ ldub(RinstanceKlass, instanceKlass::init_state_offset_in_bytes() + sizeof(oopDesc), G3_scratch); __ cmp(G3_scratch, instanceKlass::fully_initialized); __ br(Assembler::notEqual, false, Assembler::pn, slow_case); __ delayed()->ld(RinstanceKlass, Klass::layout_helper_offset_in_bytes() + sizeof(oopDesc), Roffset); diff -r da4dd142ea01 -r 52b5d32fbfaf src/cpu/x86/vm/c1_LIRAssembler_x86.cpp --- a/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp Tue Nov 29 14:44:44 2011 -0500 +++ b/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp Tue Dec 06 18:28:51 2011 -0500 @@ -1557,7 +1557,7 @@ void LIR_Assembler::emit_alloc_obj(LIR_OpAllocObj* op) { if (op->init_check()) { - __ cmpl(Address(op->klass()->as_register(), + __ cmpb(Address(op->klass()->as_register(), instanceKlass::init_state_offset_in_bytes() + sizeof(oopDesc)), instanceKlass::fully_initialized); add_debug_info_for_null_check_here(op->stub()->info()); diff -r da4dd142ea01 -r 52b5d32fbfaf src/cpu/x86/vm/c1_Runtime1_x86.cpp --- a/src/cpu/x86/vm/c1_Runtime1_x86.cpp Tue Nov 29 14:44:44 2011 -0500 +++ b/src/cpu/x86/vm/c1_Runtime1_x86.cpp Tue Dec 06 18:28:51 2011 -0500 @@ -1011,7 +1011,7 @@ if (id == fast_new_instance_init_check_id) { // make sure the klass is initialized - __ cmpl(Address(klass, instanceKlass::init_state_offset_in_bytes() + sizeof(oopDesc)), instanceKlass::fully_initialized); + __ cmpb(Address(klass, instanceKlass::init_state_offset_in_bytes() + sizeof(oopDesc)), instanceKlass::fully_initialized); __ jcc(Assembler::notEqual, slow_path); } diff -r da4dd142ea01 -r 52b5d32fbfaf src/cpu/x86/vm/templateTable_x86_32.cpp --- a/src/cpu/x86/vm/templateTable_x86_32.cpp Tue Nov 29 14:44:44 2011 -0500 +++ b/src/cpu/x86/vm/templateTable_x86_32.cpp Tue Dec 06 18:28:51 2011 -0500 @@ -3188,7 +3188,7 @@ // make sure klass is initialized & doesn't have finalizer // make sure klass is fully initialized - __ cmpl(Address(rcx, instanceKlass::init_state_offset_in_bytes() + sizeof(oopDesc)), instanceKlass::fully_initialized); + __ cmpb(Address(rcx, instanceKlass::init_state_offset_in_bytes() + sizeof(oopDesc)), instanceKlass::fully_initialized); __ jcc(Assembler::notEqual, slow_case); // get instance_size in instanceKlass (scaled to a count of bytes) diff -r da4dd142ea01 -r 52b5d32fbfaf src/cpu/x86/vm/templateTable_x86_64.cpp --- a/src/cpu/x86/vm/templateTable_x86_64.cpp Tue Nov 29 14:44:44 2011 -0500 +++ b/src/cpu/x86/vm/templateTable_x86_64.cpp Tue Dec 06 18:28:51 2011 -0500 @@ -3235,7 +3235,7 @@ // make sure klass is initialized & doesn't have finalizer // make sure klass is fully initialized - __ cmpl(Address(rsi, + __ cmpb(Address(rsi, instanceKlass::init_state_offset_in_bytes() + sizeof(oopDesc)), instanceKlass::fully_initialized); diff -r da4dd142ea01 -r 52b5d32fbfaf src/share/vm/ci/ciInstanceKlass.cpp --- a/src/share/vm/ci/ciInstanceKlass.cpp Tue Nov 29 14:44:44 2011 -0500 +++ b/src/share/vm/ci/ciInstanceKlass.cpp Tue Dec 06 18:28:51 2011 -0500 @@ -54,7 +54,7 @@ _flags = ciFlags(access_flags); _has_finalizer = access_flags.has_finalizer(); _has_subklass = ik->subklass() != NULL; - _init_state = (instanceKlass::ClassState)ik->get_init_state(); + _init_state = ik->init_state(); _nonstatic_field_size = ik->nonstatic_field_size(); _has_nonstatic_fields = ik->has_nonstatic_fields(); _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields: @@ -118,7 +118,7 @@ void ciInstanceKlass::compute_shared_init_state() { GUARDED_VM_ENTRY( instanceKlass* ik = get_instanceKlass(); - _init_state = (instanceKlass::ClassState)ik->get_init_state(); + _init_state = ik->init_state(); ) } diff -r da4dd142ea01 -r 52b5d32fbfaf src/share/vm/memory/dump.cpp --- a/src/share/vm/memory/dump.cpp Tue Nov 29 14:44:44 2011 -0500 +++ b/src/share/vm/memory/dump.cpp Tue Dec 06 18:28:51 2011 -0500 @@ -1402,7 +1402,7 @@ instanceKlass* ik = (instanceKlass*) k; // Link the class to cause the bytecodes to be rewritten and the // cpcache to be created. - if (ik->get_init_state() < instanceKlass::linked) { + if (ik->init_state() < instanceKlass::linked) { ik->link_class(THREAD); guarantee(!HAS_PENDING_EXCEPTION, "exception in class rewriting"); } @@ -1535,7 +1535,7 @@ // are loaded in order that the related data structures (klass, // cpCache, Sting constants) are located together. - if (ik->get_init_state() < instanceKlass::linked) { + if (ik->init_state() < instanceKlass::linked) { ik->link_class(THREAD); guarantee(!(HAS_PENDING_EXCEPTION), "exception in class rewriting"); } diff -r da4dd142ea01 -r 52b5d32fbfaf src/share/vm/oops/instanceKlass.cpp --- a/src/share/vm/oops/instanceKlass.cpp Tue Nov 29 14:44:44 2011 -0500 +++ b/src/share/vm/oops/instanceKlass.cpp Tue Dec 06 18:28:51 2011 -0500 @@ -208,7 +208,7 @@ // abort if someone beat us to the initialization if (!this_oop->is_not_initialized()) return; // note: not equivalent to is_initialized() - ClassState old_state = this_oop->_init_state; + ClassState old_state = this_oop->init_state(); link_class_impl(this_oop, true, THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; @@ -2479,7 +2479,7 @@ bool good_state = as_klassOop()->is_shared() ? (_init_state <= state) : (_init_state < state); assert(good_state || state == allocated, "illegal state transition"); - _init_state = state; + _init_state = (u1)state; } #endif diff -r da4dd142ea01 -r 52b5d32fbfaf src/share/vm/oops/instanceKlass.hpp --- a/src/share/vm/oops/instanceKlass.hpp Tue Nov 29 14:44:44 2011 -0500 +++ b/src/share/vm/oops/instanceKlass.hpp Tue Dec 06 18:28:51 2011 -0500 @@ -233,7 +233,6 @@ u2 _minor_version; // minor version number of class file u2 _major_version; // major version number of class file - ClassState _init_state; // state of class Thread* _init_thread; // Pointer to current thread doing initialization (to handle recusive initialization) int _vtable_len; // length of Java vtable (in words) int _itable_len; // length of Java itable (in words) @@ -257,6 +256,11 @@ JvmtiCachedClassFieldMap* _jvmti_cached_class_field_map; // JVMTI: used during heap iteration volatile u2 _idnum_allocated_count; // JNI/JVMTI: increments with the addition of methods, old ids don't change + // Class states are defined as ClassState (see above). + // Place the _init_state here to utilize the unused 2-byte after + // _idnum_allocated_count. + u1 _init_state; // state of class + // Compact the following four boolean flags into 1-bit each. These four flags // were defined as separate boolean fields and each was 1-byte before. Since // there are 2 bytes unused after the _idnum_allocated_count field, place the @@ -393,7 +397,7 @@ bool is_being_initialized() const { return _init_state == being_initialized; } bool is_in_error_state() const { return _init_state == initialization_error; } bool is_reentrant_initialization(Thread *thread) { return thread == _init_thread; } - int get_init_state() { return _init_state; } // Useful for debugging + ClassState init_state() { return (ClassState)_init_state; } bool is_rewritten() const { return (_misc_flags & REWRITTEN) != 0; } // defineClass specified verification @@ -778,7 +782,7 @@ #ifdef ASSERT void set_init_state(ClassState state); #else - void set_init_state(ClassState state) { _init_state = state; } + void set_init_state(ClassState state) { _init_state = (u1)state; } #endif void set_rewritten() { _misc_flags |= REWRITTEN; } void set_init_thread(Thread *thread) { _init_thread = thread; } diff -r da4dd142ea01 -r 52b5d32fbfaf src/share/vm/opto/library_call.cpp --- a/src/share/vm/opto/library_call.cpp Tue Nov 29 14:44:44 2011 -0500 +++ b/src/share/vm/opto/library_call.cpp Tue Dec 06 18:28:51 2011 -0500 @@ -2807,7 +2807,9 @@ // Serializable.class or Object[].class. The runtime will handle it. // But we must make an explicit check for initialization. Node* insp = basic_plus_adr(kls, instanceKlass::init_state_offset_in_bytes() + sizeof(oopDesc)); - Node* inst = make_load(NULL, insp, TypeInt::INT, T_INT); + // Use T_BOOLEAN for instanceKlass::_init_state so the compiler + // can generate code to load it as unsigned byte. + Node* inst = make_load(NULL, insp, TypeInt::UBYTE, T_BOOLEAN); Node* bits = intcon(instanceKlass::fully_initialized); Node* test = _gvn.transform( new (C, 3) SubINode(inst, bits) ); // The 'test' is non-zero if we need to take a slow path. diff -r da4dd142ea01 -r 52b5d32fbfaf src/share/vm/opto/parseHelper.cpp --- a/src/share/vm/opto/parseHelper.cpp Tue Nov 29 14:44:44 2011 -0500 +++ b/src/share/vm/opto/parseHelper.cpp Tue Dec 06 18:28:51 2011 -0500 @@ -230,7 +230,9 @@ Node* init_state_offset = _gvn.MakeConX(instanceKlass::init_state_offset_in_bytes() + klassOopDesc::klass_part_offset_in_bytes()); adr_node = basic_plus_adr(kls, kls, init_state_offset); - Node* init_state = make_load(NULL, adr_node, TypeInt::INT, T_INT); + // Use T_BOOLEAN for instanceKlass::_init_state so the compiler + // can generate code to load it as unsigned byte. + Node* init_state = make_load(NULL, adr_node, TypeInt::UBYTE, T_BOOLEAN); Node* being_init = _gvn.intcon(instanceKlass::being_initialized); tst = Bool( CmpI( init_state, being_init), BoolTest::eq); iff = create_and_map_if(control(), tst, PROB_ALWAYS, COUNT_UNKNOWN); diff -r da4dd142ea01 -r 52b5d32fbfaf src/share/vm/runtime/vmStructs.cpp --- a/src/share/vm/runtime/vmStructs.cpp Tue Nov 29 14:44:44 2011 -0500 +++ b/src/share/vm/runtime/vmStructs.cpp Tue Dec 06 18:28:51 2011 -0500 @@ -310,7 +310,7 @@ nonstatic_field(instanceKlass, _misc_flags, u1) \ nonstatic_field(instanceKlass, _minor_version, u2) \ nonstatic_field(instanceKlass, _major_version, u2) \ - nonstatic_field(instanceKlass, _init_state, instanceKlass::ClassState) \ + nonstatic_field(instanceKlass, _init_state, u1) \ nonstatic_field(instanceKlass, _init_thread, Thread*) \ nonstatic_field(instanceKlass, _vtable_len, int) \ nonstatic_field(instanceKlass, _itable_len, int) \