Skip to content

Commit a6daef5

Browse files
author
Vladimir Ivanov
committedDec 3, 2019
8234923: Missed call_site_target nmethod dependency for non-fully initialized ConstantCallSite instance
Reviewed-by: jrose
1 parent c7bc0f7 commit a6daef5

File tree

9 files changed

+73
-9
lines changed

9 files changed

+73
-9
lines changed
 

‎src/hotspot/share/c1/c1_GraphBuilder.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,7 @@ void GraphBuilder::access_field(Bytecodes::Code code) {
17071707
// For CallSite objects add a dependency for invalidation of the optimization.
17081708
if (field->is_call_site_target()) {
17091709
ciCallSite* call_site = const_oop->as_call_site();
1710-
if (!call_site->is_constant_call_site()) {
1710+
if (!call_site->is_fully_initialized_constant_call_site()) {
17111711
ciMethodHandle* target = field_value.as_object()->as_method_handle();
17121712
dependency_recorder()->assert_call_site_target_value(call_site, target);
17131713
}

‎src/hotspot/share/ci/ciCallSite.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,18 @@
2929

3030
// ciCallSite
3131

32-
bool ciCallSite::is_constant_call_site() {
33-
return klass()->is_subclass_of(CURRENT_ENV->ConstantCallSite_klass());
32+
bool ciCallSite::is_fully_initialized_constant_call_site() {
33+
if (klass()->is_subclass_of(CURRENT_ENV->ConstantCallSite_klass())) {
34+
bool is_fully_initialized = _is_fully_initialized_cache;
35+
if (!is_fully_initialized) { // changes monotonically: false => true
36+
VM_ENTRY_MARK;
37+
is_fully_initialized = (java_lang_invoke_ConstantCallSite::is_frozen(get_oop()) != JNI_FALSE);
38+
_is_fully_initialized_cache = is_fully_initialized; // cache updated value
39+
}
40+
return is_fully_initialized;
41+
} else {
42+
return false;
43+
}
3444
}
3545

3646
// ------------------------------------------------------------------

‎src/hotspot/share/ci/ciCallSite.hpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@
3131
//
3232
// The class represents a java.lang.invoke.CallSite object.
3333
class ciCallSite : public ciInstance {
34-
public:
35-
ciCallSite(instanceHandle h_i) : ciInstance(h_i) {}
34+
private:
35+
bool _is_fully_initialized_cache;
36+
37+
public:
38+
ciCallSite(instanceHandle h_i) : ciInstance(h_i), _is_fully_initialized_cache(false) {}
3639

3740
// What kind of ciObject is this?
3841
bool is_call_site() const { return true; }
3942

40-
bool is_constant_call_site();
43+
bool is_fully_initialized_constant_call_site();
4144

4245
// Return the target MethodHandle of this CallSite.
4346
ciMethodHandle* get_target() const;

‎src/hotspot/share/classfile/javaClasses.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -3918,6 +3918,24 @@ oop java_lang_invoke_CallSite::context_no_keepalive(oop call_site) {
39183918
return dep_oop;
39193919
}
39203920

3921+
// Support for java_lang_invoke_ConstantCallSite
3922+
3923+
int java_lang_invoke_ConstantCallSite::_is_frozen_offset;
3924+
3925+
#define CONSTANTCALLSITE_FIELDS_DO(macro) \
3926+
macro(_is_frozen_offset, k, "isFrozen", bool_signature, false)
3927+
3928+
void java_lang_invoke_ConstantCallSite::compute_offsets() {
3929+
InstanceKlass* k = SystemDictionary::ConstantCallSite_klass();
3930+
CONSTANTCALLSITE_FIELDS_DO(FIELD_COMPUTE_OFFSET);
3931+
}
3932+
3933+
#if INCLUDE_CDS
3934+
void java_lang_invoke_ConstantCallSite::serialize_offsets(SerializeClosure* f) {
3935+
CONSTANTCALLSITE_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
3936+
}
3937+
#endif
3938+
39213939
// Support for java_lang_invoke_MethodHandleNatives_CallSiteContext
39223940

39233941
int java_lang_invoke_MethodHandleNatives_CallSiteContext::_vmdependencies_offset;

‎src/hotspot/share/classfile/javaClasses.hpp

+23
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
f(java_lang_invoke_LambdaForm) \
6767
f(java_lang_invoke_MethodType) \
6868
f(java_lang_invoke_CallSite) \
69+
f(java_lang_invoke_ConstantCallSite) \
6970
f(java_lang_invoke_MethodHandleNatives_CallSiteContext) \
7071
f(java_security_AccessControlContext) \
7172
f(java_lang_reflect_AccessibleObject) \
@@ -1226,6 +1227,28 @@ class java_lang_invoke_CallSite: AllStatic {
12261227
static int target_offset_in_bytes() { return _target_offset; }
12271228
};
12281229

1230+
// Interface to java.lang.invoke.ConstantCallSite objects
1231+
1232+
class java_lang_invoke_ConstantCallSite: AllStatic {
1233+
friend class JavaClasses;
1234+
1235+
private:
1236+
static int _is_frozen_offset;
1237+
1238+
static void compute_offsets();
1239+
1240+
public:
1241+
static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1242+
// Accessors
1243+
static jboolean is_frozen(oop site);
1244+
1245+
// Testers
1246+
static bool is_subclass(Klass* klass) {
1247+
return klass->is_subclass_of(SystemDictionary::ConstantCallSite_klass());
1248+
}
1249+
static bool is_instance(oop obj);
1250+
};
1251+
12291252
// Interface to java.lang.invoke.MethodHandleNatives$CallSiteContext objects
12301253

12311254
#define CALLSITECONTEXT_INJECTED_FIELDS(macro) \

‎src/hotspot/share/classfile/javaClasses.inline.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ inline bool java_lang_invoke_CallSite::is_instance(oop obj) {
179179
return obj != NULL && is_subclass(obj->klass());
180180
}
181181

182+
inline jboolean java_lang_invoke_ConstantCallSite::is_frozen(oop site) {
183+
return site->bool_field(_is_frozen_offset);
184+
}
185+
186+
inline bool java_lang_invoke_ConstantCallSite::is_instance(oop obj) {
187+
return obj != NULL && is_subclass(obj->klass());
188+
}
189+
182190
inline bool java_lang_invoke_MethodHandleNatives_CallSiteContext::is_instance(oop obj) {
183191
return obj != NULL && is_subclass(obj->klass());
184192
}

‎src/hotspot/share/opto/type.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ const Type* Type::make_constant_from_field(ciField* field, ciInstance* holder,
375375
field->is_autobox_cache());
376376
if (con_type != NULL && field->is_call_site_target()) {
377377
ciCallSite* call_site = holder->as_call_site();
378-
if (!call_site->is_constant_call_site()) {
378+
if (!call_site->is_fully_initialized_constant_call_site()) {
379379
ciMethodHandle* target = con.as_object()->as_method_handle();
380380
Compile::current()->dependencies()->assert_call_site_target_value(call_site, target);
381381
}

‎src/java.base/share/classes/java/lang/invoke/ConstantCallSite.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class ConstantCallSite extends CallSite {
3939
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
4040

4141
@Stable // should NOT be constant folded during instance initialization (isFrozen == false)
42-
/*final*/ private boolean isFrozen;
42+
/*final*/ private boolean isFrozen; // Note: This field is known to the JVM.
4343

4444
/**
4545
* Creates a call site with a permanent target.

‎test/jdk/java/lang/invoke/CallSiteTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ private static void testConstantCallSite() throws Throwable {
128128
if (ccs != holder[0]) {
129129
throw new AssertionError("different call site instances");
130130
}
131-
test(false); // should not throw
131+
for (int i = 0; i < 20_000; i++) {
132+
test(false); // should not throw
133+
}
132134
}
133135

134136
private static void testMutableCallSite() throws Throwable {

0 commit comments

Comments
 (0)
Please sign in to comment.