Skip to content

Commit a07a4a3

Browse files
author
Doug Simon
committed
8317422: [JVMCI] concurrency issue in MethodData creation
Reviewed-by: never, thartmann
1 parent 7ff1938 commit a07a4a3

File tree

5 files changed

+22
-24
lines changed

5 files changed

+22
-24
lines changed

src/hotspot/share/ci/ciReplay.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,7 @@ class CompileReplay : public StackObj {
843843
// method to be rewritten (number of arguments at a call for instance)
844844
method->method_holder()->link_class(CHECK);
845845
assert(method->method_data() == nullptr, "Should only be initialized once");
846-
ClassLoaderData* loader_data = method->method_holder()->class_loader_data();
847-
MethodData* method_data = MethodData::allocate(loader_data, methodHandle(THREAD, method), CHECK);
848-
method->set_method_data(method_data);
846+
method->build_profiling_method_data(methodHandle(THREAD, method), CHECK);
849847

850848
// collect and record all the needed information for later
851849
ciMethodDataRecord* rec = new_ciMethodData(method);

src/hotspot/share/jvmci/jvmciCompilerToVM.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,18 @@ C2V_VMENTRY_0(jint, getLocalVariableTableLength, (JNIEnv* env, jobject, ARGUMENT
12821282
return method->localvariable_table_length();
12831283
C2V_END
12841284

1285+
static MethodData* get_profiling_method_data(const methodHandle& method, TRAPS) {
1286+
MethodData* method_data = method->method_data();
1287+
if (method_data == nullptr) {
1288+
method->build_profiling_method_data(method, CHECK_NULL);
1289+
method_data = method->method_data();
1290+
if (method_data == nullptr) {
1291+
THROW_MSG_NULL(vmSymbols::java_lang_OutOfMemoryError(), "cannot allocate MethodData")
1292+
}
1293+
}
1294+
return method_data;
1295+
}
1296+
12851297
C2V_VMENTRY(void, reprofile, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
12861298
methodHandle method(THREAD, UNPACK_PAIR(Method, method));
12871299
MethodCounters* mcs = method->method_counters();
@@ -1297,9 +1309,7 @@ C2V_VMENTRY(void, reprofile, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
12971309

12981310
MethodData* method_data = method->method_data();
12991311
if (method_data == nullptr) {
1300-
ClassLoaderData* loader_data = method->method_holder()->class_loader_data();
1301-
method_data = MethodData::allocate(loader_data, method, CHECK);
1302-
method->set_method_data(method_data);
1312+
method_data = get_profiling_method_data(method, CHECK);
13031313
} else {
13041314
method_data->initialize();
13051315
}
@@ -2976,12 +2986,7 @@ C2V_END
29762986

29772987
C2V_VMENTRY_0(jlong, getFailedSpeculationsAddress, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
29782988
methodHandle method(THREAD, UNPACK_PAIR(Method, method));
2979-
MethodData* method_data = method->method_data();
2980-
if (method_data == nullptr) {
2981-
ClassLoaderData* loader_data = method->method_holder()->class_loader_data();
2982-
method_data = MethodData::allocate(loader_data, method, CHECK_0);
2983-
method->set_method_data(method_data);
2984-
}
2989+
MethodData* method_data = get_profiling_method_data(method, CHECK_0);
29852990
return (jlong) method_data->get_failed_speculations_address();
29862991
C2V_END
29872992

src/hotspot/share/oops/method.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Method::Method(ConstMethod* xconst, AccessFlags access_flags, Symbol* name) {
102102
set_constMethod(xconst);
103103
set_access_flags(access_flags);
104104
set_intrinsic_id(vmIntrinsics::_none);
105-
set_method_data(nullptr);
105+
clear_method_data();
106106
clear_method_counters();
107107
set_vtable_index(Method::garbage_vtable_index);
108108

@@ -127,7 +127,7 @@ void Method::deallocate_contents(ClassLoaderData* loader_data) {
127127
MetadataFactory::free_metadata(loader_data, constMethod());
128128
set_constMethod(nullptr);
129129
MetadataFactory::free_metadata(loader_data, method_data());
130-
set_method_data(nullptr);
130+
clear_method_data();
131131
MetadataFactory::free_metadata(loader_data, method_counters());
132132
clear_method_counters();
133133
// The nmethod will be gone when we get here.
@@ -1179,7 +1179,7 @@ void Method::unlink_method() {
11791179
}
11801180
NOT_PRODUCT(set_compiled_invocation_count(0);)
11811181

1182-
set_method_data(nullptr);
1182+
clear_method_data();
11831183
clear_method_counters();
11841184
remove_unshareable_flags();
11851185
}

src/hotspot/share/oops/method.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,6 @@ class Method : public Metadata {
308308
return _method_data;
309309
}
310310

311-
void set_method_data(MethodData* data);
312-
313311
MethodCounters* method_counters() const {
314312
return _method_counters;
315313
}
@@ -361,6 +359,10 @@ class Method : public Metadata {
361359
// Either called with CompiledMethod_lock held or from constructor.
362360
void clear_code();
363361

362+
void clear_method_data() {
363+
_method_data = nullptr;
364+
}
365+
364366
public:
365367
static void set_code(const methodHandle& mh, CompiledMethod* code);
366368
void set_adapter_entry(AdapterHandlerEntry* adapter) {

src/hotspot/share/oops/method.inline.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ inline address Method::from_interpreted_entry() const {
3939
return Atomic::load_acquire(&_from_interpreted_entry);
4040
}
4141

42-
inline void Method::set_method_data(MethodData* data) {
43-
// The store into method must be released. On platforms without
44-
// total store order (TSO) the reference may become visible before
45-
// the initialization of data otherwise.
46-
Atomic::release_store(&_method_data, data);
47-
}
48-
4942
inline CompiledMethod* Method::code() const {
5043
assert( check_code(), "" );
5144
return Atomic::load_acquire(&_code);

0 commit comments

Comments
 (0)