comparison src/share/vm/graal/graalRuntime.cpp @ 12433:808348377021

Fix inconsistent oops in slow path allocation
author Christos Kotselidis <christos.kotselidis@oracle.com>
date Wed, 16 Oct 2013 01:05:14 +0200
parents 2dfccd93510a
children 43e004461248
comparison
equal deleted inserted replaced
12415:083e90f11c93 12433:808348377021
54 Deoptimization::deoptimize_frame(thread, caller_frame.id(), Deoptimization::Reason_constraint); 54 Deoptimization::deoptimize_frame(thread, caller_frame.id(), Deoptimization::Reason_constraint);
55 assert(caller_is_deopted(), "Must be deoptimized"); 55 assert(caller_is_deopted(), "Must be deoptimized");
56 } 56 }
57 } 57 }
58 58
59 JRT_ENTRY(void, GraalRuntime::new_instance(JavaThread* thread, Klass* klass)) 59 JRT_BLOCK_ENTRY(void, GraalRuntime::new_instance(JavaThread* thread, Klass* klass))
60 JRT_BLOCK;
60 assert(klass->is_klass(), "not a class"); 61 assert(klass->is_klass(), "not a class");
61 instanceKlassHandle h(thread, klass); 62 instanceKlassHandle h(thread, klass);
62 h->check_valid_for_instantiation(true, CHECK); 63 h->check_valid_for_instantiation(true, CHECK);
63 // make sure klass is initialized 64 // make sure klass is initialized
64 h->initialize(CHECK); 65 h->initialize(CHECK);
65 // allocate instance and return via TLS 66 // allocate instance and return via TLS
66 oop obj = h->allocate_instance(CHECK); 67 oop obj = h->allocate_instance(CHECK);
68 thread->set_vm_result(obj);
69 JRT_BLOCK_END;
70
67 if (GraalDeferredInitBarriers) { 71 if (GraalDeferredInitBarriers) {
68 obj = Universe::heap()->new_store_pre_barrier(thread, obj); 72 new_store_pre_barrier(thread);
69 } 73 }
70 thread->set_vm_result(obj); 74 JRT_END
71 JRT_END 75
72 76 JRT_BLOCK_ENTRY(void, GraalRuntime::new_array(JavaThread* thread, Klass* array_klass, jint length))
73 JRT_ENTRY(void, GraalRuntime::new_array(JavaThread* thread, Klass* array_klass, jint length)) 77 JRT_BLOCK;
74 // Note: no handle for klass needed since they are not used 78 // Note: no handle for klass needed since they are not used
75 // anymore after new_objArray() and no GC can happen before. 79 // anymore after new_objArray() and no GC can happen before.
76 // (This may have to change if this code changes!) 80 // (This may have to change if this code changes!)
77 assert(array_klass->is_klass(), "not a class"); 81 assert(array_klass->is_klass(), "not a class");
78 oop obj; 82 oop obj;
81 obj = oopFactory::new_typeArray(elt_type, length, CHECK); 85 obj = oopFactory::new_typeArray(elt_type, length, CHECK);
82 } else { 86 } else {
83 Klass* elem_klass = ObjArrayKlass::cast(array_klass)->element_klass(); 87 Klass* elem_klass = ObjArrayKlass::cast(array_klass)->element_klass();
84 obj = oopFactory::new_objArray(elem_klass, length, CHECK); 88 obj = oopFactory::new_objArray(elem_klass, length, CHECK);
85 } 89 }
86 if (GraalDeferredInitBarriers) {
87 obj = Universe::heap()->new_store_pre_barrier(thread, obj);
88 }
89 thread->set_vm_result(obj); 90 thread->set_vm_result(obj);
90 // This is pretty rare but this runtime patch is stressful to deoptimization 91 // This is pretty rare but this runtime patch is stressful to deoptimization
91 // if we deoptimize here so force a deopt to stress the path. 92 // if we deoptimize here so force a deopt to stress the path.
92 if (DeoptimizeALot) { 93 if (DeoptimizeALot) {
93 static int deopts = 0; 94 static int deopts = 0;
97 THROW(vmSymbols::java_lang_OutOfMemoryError()); 98 THROW(vmSymbols::java_lang_OutOfMemoryError());
98 } else { 99 } else {
99 deopt_caller(); 100 deopt_caller();
100 } 101 }
101 } 102 }
102 JRT_END 103 JRT_BLOCK_END;
104
105 if (GraalDeferredInitBarriers) {
106 new_store_pre_barrier(thread);
107 }
108 JRT_END
109
110 void GraalRuntime::new_store_pre_barrier(JavaThread* thread) {
111 // After any safepoint, just before going back to compiled code,
112 // we inform the GC that we will be doing initializing writes to
113 // this object in the future without emitting card-marks, so
114 // GC may take any compensating steps.
115 // NOTE: Keep this code consistent with GraphKit::store_barrier.
116
117 oop new_obj = thread->vm_result();
118 if (new_obj == NULL) return;
119
120 assert(Universe::heap()->can_elide_tlab_store_barriers(),
121 "compiler must check this first");
122 // GC may decide to give back a safer copy of new_obj.
123 new_obj = Universe::heap()->new_store_pre_barrier(thread, new_obj);
124 thread->set_vm_result(new_obj);
125 }
103 126
104 JRT_ENTRY(void, GraalRuntime::new_multi_array(JavaThread* thread, Klass* klass, int rank, jint* dims)) 127 JRT_ENTRY(void, GraalRuntime::new_multi_array(JavaThread* thread, Klass* klass, int rank, jint* dims))
105 assert(klass->is_klass(), "not a class"); 128 assert(klass->is_klass(), "not a class");
106 assert(rank >= 1, "rank must be nonzero"); 129 assert(rank >= 1, "rank must be nonzero");
107 oop obj = ArrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK); 130 oop obj = ArrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK);