Skip to content

Commit 957eb61

Browse files
Yudi ZhengDoug Simon
authored andcommitted
8331429: [JVMCI] Cleanup JVMCIRuntime allocation routines
Reviewed-by: dlong, dnsimon
1 parent 2f10a31 commit 957eb61

File tree

4 files changed

+71
-113
lines changed

4 files changed

+71
-113
lines changed

src/hotspot/share/gc/shared/memAllocator.hpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,17 @@ class InternalOOMEMark: public StackObj {
125125

126126
public:
127127
explicit InternalOOMEMark(JavaThread* thread) {
128-
if (thread != nullptr) {
129-
_outer = thread->is_in_internal_oome_mark();
130-
thread->set_is_in_internal_oome_mark(true);
131-
_thread = thread;
132-
} else {
133-
_outer = false;
134-
_thread = nullptr;
135-
}
128+
assert(thread != nullptr, "nullptr is not supported");
129+
_outer = thread->is_in_internal_oome_mark();
130+
thread->set_is_in_internal_oome_mark(true);
131+
_thread = thread;
136132
}
137133

138134
~InternalOOMEMark() {
139-
if (_thread != nullptr) {
140-
// Check that only InternalOOMEMark sets
141-
// JavaThread::_is_in_internal_oome_mark
142-
assert(_thread->is_in_internal_oome_mark(), "must be");
143-
_thread->set_is_in_internal_oome_mark(_outer);
144-
}
135+
// Check that only InternalOOMEMark sets
136+
// JavaThread::_is_in_internal_oome_mark
137+
assert(_thread->is_in_internal_oome_mark(), "must be");
138+
_thread->set_is_in_internal_oome_mark(_outer);
145139
}
146140

147141
JavaThread* thread() const { return _thread; }

src/hotspot/share/jvmci/jvmciRuntime.cpp

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class RetryableAllocationMark {
102102
private:
103103
InternalOOMEMark _iom;
104104
public:
105-
RetryableAllocationMark(JavaThread* thread, bool activate) : _iom(activate ? thread : nullptr) {}
105+
RetryableAllocationMark(JavaThread* thread) : _iom(thread) {}
106106
~RetryableAllocationMark() {
107107
JavaThread* THREAD = _iom.thread(); // For exception macros.
108108
if (THREAD != nullptr) {
@@ -117,34 +117,29 @@ class RetryableAllocationMark {
117117
}
118118
};
119119

120-
JRT_BLOCK_ENTRY(void, JVMCIRuntime::new_instance_common(JavaThread* current, Klass* klass, bool null_on_fail))
120+
JRT_BLOCK_ENTRY(void, JVMCIRuntime::new_instance_or_null(JavaThread* current, Klass* klass))
121121
JRT_BLOCK;
122122
assert(klass->is_klass(), "not a class");
123123
Handle holder(current, klass->klass_holder()); // keep the klass alive
124124
InstanceKlass* h = InstanceKlass::cast(klass);
125125
{
126-
RetryableAllocationMark ram(current, null_on_fail);
126+
RetryableAllocationMark ram(current);
127127
h->check_valid_for_instantiation(true, CHECK);
128-
oop obj;
129-
if (null_on_fail) {
130-
if (!h->is_initialized()) {
131-
// Cannot re-execute class initialization without side effects
132-
// so return without attempting the initialization
133-
return;
134-
}
135-
} else {
136-
// make sure klass is initialized
137-
h->initialize(CHECK);
128+
if (!h->is_initialized()) {
129+
// Cannot re-execute class initialization without side effects
130+
// so return without attempting the initialization
131+
current->set_vm_result(nullptr);
132+
return;
138133
}
139134
// allocate instance and return via TLS
140-
obj = h->allocate_instance(CHECK);
135+
oop obj = h->allocate_instance(CHECK);
141136
current->set_vm_result(obj);
142137
}
143138
JRT_BLOCK_END;
144139
SharedRuntime::on_slowpath_allocation_exit(current);
145140
JRT_END
146141

147-
JRT_BLOCK_ENTRY(void, JVMCIRuntime::new_array_common(JavaThread* current, Klass* array_klass, jint length, bool null_on_fail))
142+
JRT_BLOCK_ENTRY(void, JVMCIRuntime::new_array_or_null(JavaThread* current, Klass* array_klass, jint length))
148143
JRT_BLOCK;
149144
// Note: no handle for klass needed since they are not used
150145
// anymore after new_objArray() and no GC can happen before.
@@ -153,27 +148,21 @@ JRT_BLOCK_ENTRY(void, JVMCIRuntime::new_array_common(JavaThread* current, Klass*
153148
oop obj;
154149
if (array_klass->is_typeArray_klass()) {
155150
BasicType elt_type = TypeArrayKlass::cast(array_klass)->element_type();
156-
RetryableAllocationMark ram(current, null_on_fail);
151+
RetryableAllocationMark ram(current);
157152
obj = oopFactory::new_typeArray(elt_type, length, CHECK);
158153
} else {
159154
Handle holder(current, array_klass->klass_holder()); // keep the klass alive
160155
Klass* elem_klass = ObjArrayKlass::cast(array_klass)->element_klass();
161-
RetryableAllocationMark ram(current, null_on_fail);
156+
RetryableAllocationMark ram(current);
162157
obj = oopFactory::new_objArray(elem_klass, length, CHECK);
163158
}
164159
// This is pretty rare but this runtime patch is stressful to deoptimization
165160
// if we deoptimize here so force a deopt to stress the path.
166161
if (DeoptimizeALot) {
167162
static int deopts = 0;
168-
// Alternate between deoptimizing and raising an error (which will also cause a deopt)
169163
if (deopts++ % 2 == 0) {
170-
if (null_on_fail) {
171-
// Drop the allocation
172-
obj = nullptr;
173-
} else {
174-
ResourceMark rm(current);
175-
THROW(vmSymbols::java_lang_OutOfMemoryError());
176-
}
164+
// Drop the allocation
165+
obj = nullptr;
177166
} else {
178167
deopt_caller();
179168
}
@@ -183,42 +172,38 @@ JRT_BLOCK_ENTRY(void, JVMCIRuntime::new_array_common(JavaThread* current, Klass*
183172
SharedRuntime::on_slowpath_allocation_exit(current);
184173
JRT_END
185174

186-
JRT_ENTRY(void, JVMCIRuntime::new_multi_array_common(JavaThread* current, Klass* klass, int rank, jint* dims, bool null_on_fail))
175+
JRT_ENTRY(void, JVMCIRuntime::new_multi_array_or_null(JavaThread* current, Klass* klass, int rank, jint* dims))
187176
assert(klass->is_klass(), "not a class");
188177
assert(rank >= 1, "rank must be nonzero");
189178
Handle holder(current, klass->klass_holder()); // keep the klass alive
190-
RetryableAllocationMark ram(current, null_on_fail);
179+
RetryableAllocationMark ram(current);
191180
oop obj = ArrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK);
192181
current->set_vm_result(obj);
193182
JRT_END
194183

195-
JRT_ENTRY(void, JVMCIRuntime::dynamic_new_array_common(JavaThread* current, oopDesc* element_mirror, jint length, bool null_on_fail))
196-
RetryableAllocationMark ram(current, null_on_fail);
184+
JRT_ENTRY(void, JVMCIRuntime::dynamic_new_array_or_null(JavaThread* current, oopDesc* element_mirror, jint length))
185+
RetryableAllocationMark ram(current);
197186
oop obj = Reflection::reflect_new_array(element_mirror, length, CHECK);
198187
current->set_vm_result(obj);
199188
JRT_END
200189

201-
JRT_ENTRY(void, JVMCIRuntime::dynamic_new_instance_common(JavaThread* current, oopDesc* type_mirror, bool null_on_fail))
190+
JRT_ENTRY(void, JVMCIRuntime::dynamic_new_instance_or_null(JavaThread* current, oopDesc* type_mirror))
202191
InstanceKlass* klass = InstanceKlass::cast(java_lang_Class::as_Klass(type_mirror));
203192

204193
if (klass == nullptr) {
205194
ResourceMark rm(current);
206195
THROW(vmSymbols::java_lang_InstantiationException());
207196
}
208-
RetryableAllocationMark ram(current, null_on_fail);
197+
RetryableAllocationMark ram(current);
209198

210199
// Create new instance (the receiver)
211200
klass->check_valid_for_instantiation(false, CHECK);
212201

213-
if (null_on_fail) {
214-
if (!klass->is_initialized()) {
215-
// Cannot re-execute class initialization without side effects
216-
// so return without attempting the initialization
217-
return;
218-
}
219-
} else {
220-
// Make sure klass gets initialized
221-
klass->initialize(CHECK);
202+
if (!klass->is_initialized()) {
203+
// Cannot re-execute class initialization without side effects
204+
// so return without attempting the initialization
205+
current->set_vm_result(nullptr);
206+
return;
222207
}
223208

224209
oop obj = klass->allocate_instance(CHECK);

src/hotspot/share/jvmci/jvmciRuntime.hpp

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -504,34 +504,16 @@ class JVMCIRuntime: public CHeapObj<mtJVMCI> {
504504

505505
static BasicType kindToBasicType(const Handle& kind, TRAPS);
506506

507-
static void new_instance_common(JavaThread* current, Klass* klass, bool null_on_fail);
508-
static void new_array_common(JavaThread* current, Klass* klass, jint length, bool null_on_fail);
509-
static void new_multi_array_common(JavaThread* current, Klass* klass, int rank, jint* dims, bool null_on_fail);
510-
static void dynamic_new_array_common(JavaThread* current, oopDesc* element_mirror, jint length, bool null_on_fail);
511-
static void dynamic_new_instance_common(JavaThread* current, oopDesc* type_mirror, bool null_on_fail);
512-
513507
// The following routines are called from compiled JVMCI code
514508

515-
// When allocation fails, these stubs:
516-
// 1. Exercise -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError handling and also
517-
// post a JVMTI_EVENT_RESOURCE_EXHAUSTED event if the failure is an OutOfMemroyError
518-
// 2. Return null with a pending exception.
519-
// Compiled code must ensure these stubs are not called twice for the same allocation
520-
// site due to the non-repeatable side effects in the case of OOME.
521-
static void new_instance(JavaThread* current, Klass* klass) { new_instance_common(current, klass, false); }
522-
static void new_array(JavaThread* current, Klass* klass, jint length) { new_array_common(current, klass, length, false); }
523-
static void new_multi_array(JavaThread* current, Klass* klass, int rank, jint* dims) { new_multi_array_common(current, klass, rank, dims, false); }
524-
static void dynamic_new_array(JavaThread* current, oopDesc* element_mirror, jint length) { dynamic_new_array_common(current, element_mirror, length, false); }
525-
static void dynamic_new_instance(JavaThread* current, oopDesc* type_mirror) { dynamic_new_instance_common(current, type_mirror, false); }
526-
527-
// When allocation fails, these stubs return null and have no pending exception. Compiled code
528-
// can use these stubs if a failed allocation will be retried (e.g., by deoptimizing and
529-
// re-executing in the interpreter).
530-
static void new_instance_or_null(JavaThread* thread, Klass* klass) { new_instance_common(thread, klass, true); }
531-
static void new_array_or_null(JavaThread* thread, Klass* klass, jint length) { new_array_common(thread, klass, length, true); }
532-
static void new_multi_array_or_null(JavaThread* thread, Klass* klass, int rank, jint* dims) { new_multi_array_common(thread, klass, rank, dims, true); }
533-
static void dynamic_new_array_or_null(JavaThread* thread, oopDesc* element_mirror, jint length) { dynamic_new_array_common(thread, element_mirror, length, true); }
534-
static void dynamic_new_instance_or_null(JavaThread* thread, oopDesc* type_mirror) { dynamic_new_instance_common(thread, type_mirror, true); }
509+
// When allocation fails, these stubs return null and have no pending OutOfMemoryError exception.
510+
// Compiled code can use these stubs if a failed allocation will be retried (e.g., by deoptimizing
511+
// and re-executing in the interpreter).
512+
static void new_instance_or_null(JavaThread* thread, Klass* klass);
513+
static void new_array_or_null(JavaThread* thread, Klass* klass, jint length);
514+
static void new_multi_array_or_null(JavaThread* thread, Klass* klass, int rank, jint* dims);
515+
static void dynamic_new_array_or_null(JavaThread* thread, oopDesc* element_mirror, jint length);
516+
static void dynamic_new_instance_or_null(JavaThread* thread, oopDesc* type_mirror);
535517

536518
static void vm_message(jboolean vmError, jlong format, jlong v1, jlong v2, jlong v3);
537519
static jint identity_hash_code(JavaThread* current, oopDesc* obj);

src/hotspot/share/jvmci/vmStructs_jvmci.cpp

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@
251251
nonstatic_field(Klass, _modifier_flags, jint) \
252252
nonstatic_field(Klass, _access_flags, AccessFlags) \
253253
nonstatic_field(Klass, _class_loader_data, ClassLoaderData*) \
254+
nonstatic_field(Klass, _bitmap, uintx) \
255+
nonstatic_field(Klass, _hash_slot, uint8_t) \
254256
\
255257
nonstatic_field(LocalVariableTableElement, start_bci, u2) \
256258
nonstatic_field(LocalVariableTableElement, length, u2) \
@@ -381,6 +383,7 @@
381383
static_field(StubRoutines, _bigIntegerRightShiftWorker, address) \
382384
static_field(StubRoutines, _bigIntegerLeftShiftWorker, address) \
383385
static_field(StubRoutines, _cont_thaw, address) \
386+
static_field(StubRoutines, _lookup_secondary_supers_table_slow_path_stub, address) \
384387
\
385388
nonstatic_field(Thread, _tlab, ThreadLocalAllocBuffer) \
386389
nonstatic_field(Thread, _allocated_bytes, jlong) \
@@ -800,39 +803,33 @@
800803
declare_function(Deoptimization::uncommon_trap) \
801804
declare_function(Deoptimization::unpack_frames) \
802805
\
803-
declare_function(JVMCIRuntime::new_instance) \
804-
declare_function(JVMCIRuntime::new_array) \
805-
declare_function(JVMCIRuntime::new_multi_array) \
806-
declare_function(JVMCIRuntime::dynamic_new_array) \
807-
declare_function(JVMCIRuntime::dynamic_new_instance) \
808-
\
809-
declare_function(JVMCIRuntime::new_instance_or_null) \
810-
declare_function(JVMCIRuntime::new_array_or_null) \
811-
declare_function(JVMCIRuntime::new_multi_array_or_null) \
812-
declare_function(JVMCIRuntime::dynamic_new_array_or_null) \
813-
declare_function(JVMCIRuntime::dynamic_new_instance_or_null) \
814-
\
815-
declare_function(JVMCIRuntime::invoke_static_method_one_arg) \
816-
\
817-
declare_function(JVMCIRuntime::vm_message) \
818-
declare_function(JVMCIRuntime::identity_hash_code) \
819-
declare_function(JVMCIRuntime::exception_handler_for_pc) \
820-
declare_function(JVMCIRuntime::monitorenter) \
821-
declare_function(JVMCIRuntime::monitorexit) \
822-
declare_function(JVMCIRuntime::object_notify) \
823-
declare_function(JVMCIRuntime::object_notifyAll) \
824-
declare_function(JVMCIRuntime::throw_and_post_jvmti_exception) \
825-
declare_function(JVMCIRuntime::throw_klass_external_name_exception) \
826-
declare_function(JVMCIRuntime::throw_class_cast_exception) \
827-
declare_function(JVMCIRuntime::log_primitive) \
828-
declare_function(JVMCIRuntime::log_object) \
829-
declare_function(JVMCIRuntime::log_printf) \
830-
declare_function(JVMCIRuntime::vm_error) \
831-
declare_function(JVMCIRuntime::load_and_clear_exception) \
832-
G1GC_ONLY(declare_function(JVMCIRuntime::write_barrier_pre)) \
833-
G1GC_ONLY(declare_function(JVMCIRuntime::write_barrier_post)) \
834-
declare_function(JVMCIRuntime::validate_object) \
835-
\
806+
declare_function(JVMCIRuntime::new_instance_or_null) \
807+
declare_function(JVMCIRuntime::new_array_or_null) \
808+
declare_function(JVMCIRuntime::new_multi_array_or_null) \
809+
declare_function(JVMCIRuntime::dynamic_new_array_or_null) \
810+
declare_function(JVMCIRuntime::dynamic_new_instance_or_null) \
811+
\
812+
declare_function(JVMCIRuntime::invoke_static_method_one_arg) \
813+
\
814+
declare_function(JVMCIRuntime::vm_message) \
815+
declare_function(JVMCIRuntime::identity_hash_code) \
816+
declare_function(JVMCIRuntime::exception_handler_for_pc) \
817+
declare_function(JVMCIRuntime::monitorenter) \
818+
declare_function(JVMCIRuntime::monitorexit) \
819+
declare_function(JVMCIRuntime::object_notify) \
820+
declare_function(JVMCIRuntime::object_notifyAll) \
821+
declare_function(JVMCIRuntime::throw_and_post_jvmti_exception) \
822+
declare_function(JVMCIRuntime::throw_klass_external_name_exception) \
823+
declare_function(JVMCIRuntime::throw_class_cast_exception) \
824+
declare_function(JVMCIRuntime::log_primitive) \
825+
declare_function(JVMCIRuntime::log_object) \
826+
declare_function(JVMCIRuntime::log_printf) \
827+
declare_function(JVMCIRuntime::vm_error) \
828+
declare_function(JVMCIRuntime::load_and_clear_exception) \
829+
G1GC_ONLY(declare_function(JVMCIRuntime::write_barrier_pre)) \
830+
G1GC_ONLY(declare_function(JVMCIRuntime::write_barrier_post)) \
831+
declare_function(JVMCIRuntime::validate_object) \
832+
\
836833
declare_function(JVMCIRuntime::test_deoptimize_call_int)
837834

838835

0 commit comments

Comments
 (0)