提交 4ebeac0e 编写于 作者: V vlivanov

8141420: Compiler runtime entries don't hold Klass* from being GCed

Reviewed-by: kvn, coleenp
上级 efb66a69
...@@ -312,6 +312,7 @@ JRT_ENTRY(void, Runtime1::new_instance(JavaThread* thread, Klass* klass)) ...@@ -312,6 +312,7 @@ JRT_ENTRY(void, Runtime1::new_instance(JavaThread* thread, Klass* klass))
NOT_PRODUCT(_new_instance_slowcase_cnt++;) NOT_PRODUCT(_new_instance_slowcase_cnt++;)
assert(klass->is_klass(), "not a class"); assert(klass->is_klass(), "not a class");
Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
instanceKlassHandle h(thread, klass); instanceKlassHandle h(thread, klass);
h->check_valid_for_instantiation(true, CHECK); h->check_valid_for_instantiation(true, CHECK);
// make sure klass is initialized // make sure klass is initialized
...@@ -347,6 +348,7 @@ JRT_ENTRY(void, Runtime1::new_object_array(JavaThread* thread, Klass* array_klas ...@@ -347,6 +348,7 @@ JRT_ENTRY(void, Runtime1::new_object_array(JavaThread* thread, Klass* array_klas
// anymore after new_objArray() and no GC can happen before. // anymore after new_objArray() and no GC can happen before.
// (This may have to change if this code changes!) // (This may have to change if this code changes!)
assert(array_klass->is_klass(), "not a class"); assert(array_klass->is_klass(), "not a class");
Handle holder(THREAD, array_klass->klass_holder()); // keep the klass alive
Klass* elem_klass = ObjArrayKlass::cast(array_klass)->element_klass(); Klass* elem_klass = ObjArrayKlass::cast(array_klass)->element_klass();
objArrayOop obj = oopFactory::new_objArray(elem_klass, length, CHECK); objArrayOop obj = oopFactory::new_objArray(elem_klass, length, CHECK);
thread->set_vm_result(obj); thread->set_vm_result(obj);
...@@ -363,6 +365,7 @@ JRT_ENTRY(void, Runtime1::new_multi_array(JavaThread* thread, Klass* klass, int ...@@ -363,6 +365,7 @@ JRT_ENTRY(void, Runtime1::new_multi_array(JavaThread* thread, Klass* klass, int
assert(klass->is_klass(), "not a class"); assert(klass->is_klass(), "not a class");
assert(rank >= 1, "rank must be nonzero"); assert(rank >= 1, "rank must be nonzero");
Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
oop obj = ArrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK); oop obj = ArrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK);
thread->set_vm_result(obj); thread->set_vm_result(obj);
JRT_END JRT_END
......
...@@ -231,22 +231,17 @@ JRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(Klass* klass, JavaThread* thre ...@@ -231,22 +231,17 @@ JRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(Klass* klass, JavaThread* thre
// These checks are cheap to make and support reflective allocation. // These checks are cheap to make and support reflective allocation.
int lh = klass->layout_helper(); int lh = klass->layout_helper();
if (Klass::layout_helper_needs_slow_path(lh) if (Klass::layout_helper_needs_slow_path(lh) || !InstanceKlass::cast(klass)->is_initialized()) {
|| !InstanceKlass::cast(klass)->is_initialized()) { Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
KlassHandle kh(THREAD, klass); klass->check_valid_for_instantiation(false, THREAD);
kh->check_valid_for_instantiation(false, THREAD);
if (!HAS_PENDING_EXCEPTION) { if (!HAS_PENDING_EXCEPTION) {
InstanceKlass::cast(kh())->initialize(THREAD); InstanceKlass::cast(klass)->initialize(THREAD);
}
if (!HAS_PENDING_EXCEPTION) {
klass = kh();
} else {
klass = NULL;
} }
} }
if (klass != NULL) { if (!HAS_PENDING_EXCEPTION) {
// Scavenge and allocate an instance. // Scavenge and allocate an instance.
Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
oop result = InstanceKlass::cast(klass)->allocate_instance(THREAD); oop result = InstanceKlass::cast(klass)->allocate_instance(THREAD);
thread->set_vm_result(result); thread->set_vm_result(result);
...@@ -286,6 +281,7 @@ JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(Klass* array_type, int len, JavaT ...@@ -286,6 +281,7 @@ JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(Klass* array_type, int len, JavaT
// Although the oopFactory likes to work with the elem_type, // Although the oopFactory likes to work with the elem_type,
// the compiler prefers the array_type, since it must already have // the compiler prefers the array_type, since it must already have
// that latter value in hand for the fast path. // that latter value in hand for the fast path.
Handle holder(THREAD, array_type->klass_holder()); // keep the array klass alive
Klass* elem_type = ObjArrayKlass::cast(array_type)->element_klass(); Klass* elem_type = ObjArrayKlass::cast(array_type)->element_klass();
result = oopFactory::new_objArray(elem_type, len, THREAD); result = oopFactory::new_objArray(elem_type, len, THREAD);
} }
...@@ -364,6 +360,7 @@ JRT_ENTRY(void, OptoRuntime::multianewarray2_C(Klass* elem_type, int len1, int l ...@@ -364,6 +360,7 @@ JRT_ENTRY(void, OptoRuntime::multianewarray2_C(Klass* elem_type, int len1, int l
jint dims[2]; jint dims[2];
dims[0] = len1; dims[0] = len1;
dims[1] = len2; dims[1] = len2;
Handle holder(THREAD, elem_type->klass_holder()); // keep the klass alive
oop obj = ArrayKlass::cast(elem_type)->multi_allocate(2, dims, THREAD); oop obj = ArrayKlass::cast(elem_type)->multi_allocate(2, dims, THREAD);
deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION); deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
thread->set_vm_result(obj); thread->set_vm_result(obj);
...@@ -380,6 +377,7 @@ JRT_ENTRY(void, OptoRuntime::multianewarray3_C(Klass* elem_type, int len1, int l ...@@ -380,6 +377,7 @@ JRT_ENTRY(void, OptoRuntime::multianewarray3_C(Klass* elem_type, int len1, int l
dims[0] = len1; dims[0] = len1;
dims[1] = len2; dims[1] = len2;
dims[2] = len3; dims[2] = len3;
Handle holder(THREAD, elem_type->klass_holder()); // keep the klass alive
oop obj = ArrayKlass::cast(elem_type)->multi_allocate(3, dims, THREAD); oop obj = ArrayKlass::cast(elem_type)->multi_allocate(3, dims, THREAD);
deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION); deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
thread->set_vm_result(obj); thread->set_vm_result(obj);
...@@ -397,6 +395,7 @@ JRT_ENTRY(void, OptoRuntime::multianewarray4_C(Klass* elem_type, int len1, int l ...@@ -397,6 +395,7 @@ JRT_ENTRY(void, OptoRuntime::multianewarray4_C(Klass* elem_type, int len1, int l
dims[1] = len2; dims[1] = len2;
dims[2] = len3; dims[2] = len3;
dims[3] = len4; dims[3] = len4;
Handle holder(THREAD, elem_type->klass_holder()); // keep the klass alive
oop obj = ArrayKlass::cast(elem_type)->multi_allocate(4, dims, THREAD); oop obj = ArrayKlass::cast(elem_type)->multi_allocate(4, dims, THREAD);
deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION); deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
thread->set_vm_result(obj); thread->set_vm_result(obj);
...@@ -415,6 +414,7 @@ JRT_ENTRY(void, OptoRuntime::multianewarray5_C(Klass* elem_type, int len1, int l ...@@ -415,6 +414,7 @@ JRT_ENTRY(void, OptoRuntime::multianewarray5_C(Klass* elem_type, int len1, int l
dims[2] = len3; dims[2] = len3;
dims[3] = len4; dims[3] = len4;
dims[4] = len5; dims[4] = len5;
Handle holder(THREAD, elem_type->klass_holder()); // keep the klass alive
oop obj = ArrayKlass::cast(elem_type)->multi_allocate(5, dims, THREAD); oop obj = ArrayKlass::cast(elem_type)->multi_allocate(5, dims, THREAD);
deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION); deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
thread->set_vm_result(obj); thread->set_vm_result(obj);
...@@ -432,6 +432,7 @@ JRT_ENTRY(void, OptoRuntime::multianewarrayN_C(Klass* elem_type, arrayOopDesc* d ...@@ -432,6 +432,7 @@ JRT_ENTRY(void, OptoRuntime::multianewarrayN_C(Klass* elem_type, arrayOopDesc* d
jint *c_dims = NEW_RESOURCE_ARRAY(jint, len); jint *c_dims = NEW_RESOURCE_ARRAY(jint, len);
Copy::conjoint_jints_atomic(j_dims, c_dims, len); Copy::conjoint_jints_atomic(j_dims, c_dims, len);
Handle holder(THREAD, elem_type->klass_holder()); // keep the klass alive
oop obj = ArrayKlass::cast(elem_type)->multi_allocate(len, c_dims, THREAD); oop obj = ArrayKlass::cast(elem_type)->multi_allocate(len, c_dims, THREAD);
deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION); deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
thread->set_vm_result(obj); thread->set_vm_result(obj);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册