# HG changeset patch # User Christos Kotselidis # Date 1381878314 -7200 # Node ID 80834837702173924bd49ac27f74cfc1988f177e # Parent 083e90f11c93d7a4898c18a7aeec2113476d836d Fix inconsistent oops in slow path allocation diff -r 083e90f11c93 -r 808348377021 src/share/vm/graal/graalRuntime.cpp --- a/src/share/vm/graal/graalRuntime.cpp Tue Oct 15 02:07:33 2013 +0200 +++ b/src/share/vm/graal/graalRuntime.cpp Wed Oct 16 01:05:14 2013 +0200 @@ -56,7 +56,8 @@ } } -JRT_ENTRY(void, GraalRuntime::new_instance(JavaThread* thread, Klass* klass)) +JRT_BLOCK_ENTRY(void, GraalRuntime::new_instance(JavaThread* thread, Klass* klass)) + JRT_BLOCK; assert(klass->is_klass(), "not a class"); instanceKlassHandle h(thread, klass); h->check_valid_for_instantiation(true, CHECK); @@ -64,13 +65,16 @@ h->initialize(CHECK); // allocate instance and return via TLS oop obj = h->allocate_instance(CHECK); + thread->set_vm_result(obj); + JRT_BLOCK_END; + if (GraalDeferredInitBarriers) { - obj = Universe::heap()->new_store_pre_barrier(thread, obj); + new_store_pre_barrier(thread); } - thread->set_vm_result(obj); JRT_END -JRT_ENTRY(void, GraalRuntime::new_array(JavaThread* thread, Klass* array_klass, jint length)) +JRT_BLOCK_ENTRY(void, GraalRuntime::new_array(JavaThread* thread, Klass* array_klass, jint length)) + JRT_BLOCK; // Note: no handle for klass needed since they are not used // anymore after new_objArray() and no GC can happen before. // (This may have to change if this code changes!) @@ -83,9 +87,6 @@ Klass* elem_klass = ObjArrayKlass::cast(array_klass)->element_klass(); obj = oopFactory::new_objArray(elem_klass, length, CHECK); } - if (GraalDeferredInitBarriers) { - obj = Universe::heap()->new_store_pre_barrier(thread, obj); - } thread->set_vm_result(obj); // This is pretty rare but this runtime patch is stressful to deoptimization // if we deoptimize here so force a deopt to stress the path. @@ -99,8 +100,30 @@ deopt_caller(); } } + JRT_BLOCK_END; + + if (GraalDeferredInitBarriers) { + new_store_pre_barrier(thread); + } JRT_END +void GraalRuntime::new_store_pre_barrier(JavaThread* thread) { + // After any safepoint, just before going back to compiled code, + // we inform the GC that we will be doing initializing writes to + // this object in the future without emitting card-marks, so + // GC may take any compensating steps. + // NOTE: Keep this code consistent with GraphKit::store_barrier. + + oop new_obj = thread->vm_result(); + if (new_obj == NULL) return; + + assert(Universe::heap()->can_elide_tlab_store_barriers(), + "compiler must check this first"); + // GC may decide to give back a safer copy of new_obj. + new_obj = Universe::heap()->new_store_pre_barrier(thread, new_obj); + thread->set_vm_result(new_obj); +} + JRT_ENTRY(void, GraalRuntime::new_multi_array(JavaThread* thread, Klass* klass, int rank, jint* dims)) assert(klass->is_klass(), "not a class"); assert(rank >= 1, "rank must be nonzero"); diff -r 083e90f11c93 -r 808348377021 src/share/vm/graal/graalRuntime.hpp --- a/src/share/vm/graal/graalRuntime.hpp Tue Oct 15 02:07:33 2013 +0200 +++ b/src/share/vm/graal/graalRuntime.hpp Wed Oct 16 01:05:14 2013 +0200 @@ -56,6 +56,7 @@ static void write_barrier_pre(JavaThread* thread, oopDesc* obj); static void write_barrier_post(JavaThread* thread, void* card); static jboolean validate_object(JavaThread* thread, oopDesc* parent, oopDesc* child); + static void new_store_pre_barrier(JavaThread* thread); }; #endif // SHARE_VM_GRAAL_GRAAL_RUNTIME_HPP