1.1 --- a/src/share/vm/opto/library_call.cpp Tue Aug 20 10:57:50 2013 -0700 1.2 +++ b/src/share/vm/opto/library_call.cpp Thu Aug 08 03:16:56 2013 +0200 1.3 @@ -213,6 +213,7 @@ 1.4 void insert_pre_barrier(Node* base_oop, Node* offset, Node* pre_val, bool need_mem_bar); 1.5 bool inline_unsafe_access(bool is_native_ptr, bool is_store, BasicType type, bool is_volatile); 1.6 bool inline_unsafe_prefetch(bool is_native_ptr, bool is_store, bool is_static); 1.7 + static bool klass_needs_init_guard(Node* kls); 1.8 bool inline_unsafe_allocate(); 1.9 bool inline_unsafe_copyMemory(); 1.10 bool inline_native_currentThread(); 1.11 @@ -2892,8 +2893,21 @@ 1.12 } 1.13 } 1.14 1.15 +bool LibraryCallKit::klass_needs_init_guard(Node* kls) { 1.16 + if (!kls->is_Con()) { 1.17 + return true; 1.18 + } 1.19 + const TypeKlassPtr* klsptr = kls->bottom_type()->isa_klassptr(); 1.20 + if (klsptr == NULL) { 1.21 + return true; 1.22 + } 1.23 + ciInstanceKlass* ik = klsptr->klass()->as_instance_klass(); 1.24 + // don't need a guard for a klass that is already initialized 1.25 + return !ik->is_initialized(); 1.26 +} 1.27 + 1.28 //----------------------------inline_unsafe_allocate--------------------------- 1.29 -// public native Object sun.mics.Unsafe.allocateInstance(Class<?> cls); 1.30 +// public native Object sun.misc.Unsafe.allocateInstance(Class<?> cls); 1.31 bool LibraryCallKit::inline_unsafe_allocate() { 1.32 if (callee()->is_static()) return false; // caller must have the capability! 1.33 1.34 @@ -2905,16 +2919,19 @@ 1.35 kls = null_check(kls); 1.36 if (stopped()) return true; // argument was like int.class 1.37 1.38 - // Note: The argument might still be an illegal value like 1.39 - // Serializable.class or Object[].class. The runtime will handle it. 1.40 - // But we must make an explicit check for initialization. 1.41 - Node* insp = basic_plus_adr(kls, in_bytes(InstanceKlass::init_state_offset())); 1.42 - // Use T_BOOLEAN for InstanceKlass::_init_state so the compiler 1.43 - // can generate code to load it as unsigned byte. 1.44 - Node* inst = make_load(NULL, insp, TypeInt::UBYTE, T_BOOLEAN); 1.45 - Node* bits = intcon(InstanceKlass::fully_initialized); 1.46 - Node* test = _gvn.transform(new (C) SubINode(inst, bits)); 1.47 - // The 'test' is non-zero if we need to take a slow path. 1.48 + Node* test = NULL; 1.49 + if (LibraryCallKit::klass_needs_init_guard(kls)) { 1.50 + // Note: The argument might still be an illegal value like 1.51 + // Serializable.class or Object[].class. The runtime will handle it. 1.52 + // But we must make an explicit check for initialization. 1.53 + Node* insp = basic_plus_adr(kls, in_bytes(InstanceKlass::init_state_offset())); 1.54 + // Use T_BOOLEAN for InstanceKlass::_init_state so the compiler 1.55 + // can generate code to load it as unsigned byte. 1.56 + Node* inst = make_load(NULL, insp, TypeInt::UBYTE, T_BOOLEAN); 1.57 + Node* bits = intcon(InstanceKlass::fully_initialized); 1.58 + test = _gvn.transform(new (C) SubINode(inst, bits)); 1.59 + // The 'test' is non-zero if we need to take a slow path. 1.60 + } 1.61 1.62 Node* obj = new_instance(kls, test); 1.63 set_result(obj);