提交 d8b131b4 编写于 作者: R rbackman

8022675: Redundant class init check

Reviewed-by: kvn, twisti
上级 2b9c5258
...@@ -213,6 +213,7 @@ class LibraryCallKit : public GraphKit { ...@@ -213,6 +213,7 @@ class LibraryCallKit : public GraphKit {
void insert_pre_barrier(Node* base_oop, Node* offset, Node* pre_val, bool need_mem_bar); void insert_pre_barrier(Node* base_oop, Node* offset, Node* pre_val, bool need_mem_bar);
bool inline_unsafe_access(bool is_native_ptr, bool is_store, BasicType type, bool is_volatile); bool inline_unsafe_access(bool is_native_ptr, bool is_store, BasicType type, bool is_volatile);
bool inline_unsafe_prefetch(bool is_native_ptr, bool is_store, bool is_static); bool inline_unsafe_prefetch(bool is_native_ptr, bool is_store, bool is_static);
static bool klass_needs_init_guard(Node* kls);
bool inline_unsafe_allocate(); bool inline_unsafe_allocate();
bool inline_unsafe_copyMemory(); bool inline_unsafe_copyMemory();
bool inline_native_currentThread(); bool inline_native_currentThread();
...@@ -2892,8 +2893,21 @@ bool LibraryCallKit::inline_unsafe_fence(vmIntrinsics::ID id) { ...@@ -2892,8 +2893,21 @@ bool LibraryCallKit::inline_unsafe_fence(vmIntrinsics::ID id) {
} }
} }
bool LibraryCallKit::klass_needs_init_guard(Node* kls) {
if (!kls->is_Con()) {
return true;
}
const TypeKlassPtr* klsptr = kls->bottom_type()->isa_klassptr();
if (klsptr == NULL) {
return true;
}
ciInstanceKlass* ik = klsptr->klass()->as_instance_klass();
// don't need a guard for a klass that is already initialized
return !ik->is_initialized();
}
//----------------------------inline_unsafe_allocate--------------------------- //----------------------------inline_unsafe_allocate---------------------------
// public native Object sun.mics.Unsafe.allocateInstance(Class<?> cls); // public native Object sun.misc.Unsafe.allocateInstance(Class<?> cls);
bool LibraryCallKit::inline_unsafe_allocate() { bool LibraryCallKit::inline_unsafe_allocate() {
if (callee()->is_static()) return false; // caller must have the capability! if (callee()->is_static()) return false; // caller must have the capability!
...@@ -2905,6 +2919,8 @@ bool LibraryCallKit::inline_unsafe_allocate() { ...@@ -2905,6 +2919,8 @@ bool LibraryCallKit::inline_unsafe_allocate() {
kls = null_check(kls); kls = null_check(kls);
if (stopped()) return true; // argument was like int.class if (stopped()) return true; // argument was like int.class
Node* test = NULL;
if (LibraryCallKit::klass_needs_init_guard(kls)) {
// Note: The argument might still be an illegal value like // Note: The argument might still be an illegal value like
// Serializable.class or Object[].class. The runtime will handle it. // Serializable.class or Object[].class. The runtime will handle it.
// But we must make an explicit check for initialization. // But we must make an explicit check for initialization.
...@@ -2913,8 +2929,9 @@ bool LibraryCallKit::inline_unsafe_allocate() { ...@@ -2913,8 +2929,9 @@ bool LibraryCallKit::inline_unsafe_allocate() {
// can generate code to load it as unsigned byte. // can generate code to load it as unsigned byte.
Node* inst = make_load(NULL, insp, TypeInt::UBYTE, T_BOOLEAN); Node* inst = make_load(NULL, insp, TypeInt::UBYTE, T_BOOLEAN);
Node* bits = intcon(InstanceKlass::fully_initialized); Node* bits = intcon(InstanceKlass::fully_initialized);
Node* test = _gvn.transform(new (C) SubINode(inst, bits)); test = _gvn.transform(new (C) SubINode(inst, bits));
// The 'test' is non-zero if we need to take a slow path. // The 'test' is non-zero if we need to take a slow path.
}
Node* obj = new_instance(kls, test); Node* obj = new_instance(kls, test);
set_result(obj); set_result(obj);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册