mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8234923: Missed call_site_target nmethod dependency for non-fully initialized ConstantCallSite instance
Reviewed-by: jrose
This commit is contained in:
parent
c7bc0f7a12
commit
a6daef527e
9 changed files with 73 additions and 9 deletions
|
@ -1707,7 +1707,7 @@ void GraphBuilder::access_field(Bytecodes::Code code) {
|
||||||
// For CallSite objects add a dependency for invalidation of the optimization.
|
// For CallSite objects add a dependency for invalidation of the optimization.
|
||||||
if (field->is_call_site_target()) {
|
if (field->is_call_site_target()) {
|
||||||
ciCallSite* call_site = const_oop->as_call_site();
|
ciCallSite* call_site = const_oop->as_call_site();
|
||||||
if (!call_site->is_constant_call_site()) {
|
if (!call_site->is_fully_initialized_constant_call_site()) {
|
||||||
ciMethodHandle* target = field_value.as_object()->as_method_handle();
|
ciMethodHandle* target = field_value.as_object()->as_method_handle();
|
||||||
dependency_recorder()->assert_call_site_target_value(call_site, target);
|
dependency_recorder()->assert_call_site_target_value(call_site, target);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,18 @@
|
||||||
|
|
||||||
// ciCallSite
|
// ciCallSite
|
||||||
|
|
||||||
bool ciCallSite::is_constant_call_site() {
|
bool ciCallSite::is_fully_initialized_constant_call_site() {
|
||||||
return klass()->is_subclass_of(CURRENT_ENV->ConstantCallSite_klass());
|
if (klass()->is_subclass_of(CURRENT_ENV->ConstantCallSite_klass())) {
|
||||||
|
bool is_fully_initialized = _is_fully_initialized_cache;
|
||||||
|
if (!is_fully_initialized) { // changes monotonically: false => true
|
||||||
|
VM_ENTRY_MARK;
|
||||||
|
is_fully_initialized = (java_lang_invoke_ConstantCallSite::is_frozen(get_oop()) != JNI_FALSE);
|
||||||
|
_is_fully_initialized_cache = is_fully_initialized; // cache updated value
|
||||||
|
}
|
||||||
|
return is_fully_initialized;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
|
|
|
@ -31,13 +31,16 @@
|
||||||
//
|
//
|
||||||
// The class represents a java.lang.invoke.CallSite object.
|
// The class represents a java.lang.invoke.CallSite object.
|
||||||
class ciCallSite : public ciInstance {
|
class ciCallSite : public ciInstance {
|
||||||
public:
|
private:
|
||||||
ciCallSite(instanceHandle h_i) : ciInstance(h_i) {}
|
bool _is_fully_initialized_cache;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ciCallSite(instanceHandle h_i) : ciInstance(h_i), _is_fully_initialized_cache(false) {}
|
||||||
|
|
||||||
// What kind of ciObject is this?
|
// What kind of ciObject is this?
|
||||||
bool is_call_site() const { return true; }
|
bool is_call_site() const { return true; }
|
||||||
|
|
||||||
bool is_constant_call_site();
|
bool is_fully_initialized_constant_call_site();
|
||||||
|
|
||||||
// Return the target MethodHandle of this CallSite.
|
// Return the target MethodHandle of this CallSite.
|
||||||
ciMethodHandle* get_target() const;
|
ciMethodHandle* get_target() const;
|
||||||
|
|
|
@ -3918,6 +3918,24 @@ oop java_lang_invoke_CallSite::context_no_keepalive(oop call_site) {
|
||||||
return dep_oop;
|
return dep_oop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Support for java_lang_invoke_ConstantCallSite
|
||||||
|
|
||||||
|
int java_lang_invoke_ConstantCallSite::_is_frozen_offset;
|
||||||
|
|
||||||
|
#define CONSTANTCALLSITE_FIELDS_DO(macro) \
|
||||||
|
macro(_is_frozen_offset, k, "isFrozen", bool_signature, false)
|
||||||
|
|
||||||
|
void java_lang_invoke_ConstantCallSite::compute_offsets() {
|
||||||
|
InstanceKlass* k = SystemDictionary::ConstantCallSite_klass();
|
||||||
|
CONSTANTCALLSITE_FIELDS_DO(FIELD_COMPUTE_OFFSET);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if INCLUDE_CDS
|
||||||
|
void java_lang_invoke_ConstantCallSite::serialize_offsets(SerializeClosure* f) {
|
||||||
|
CONSTANTCALLSITE_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Support for java_lang_invoke_MethodHandleNatives_CallSiteContext
|
// Support for java_lang_invoke_MethodHandleNatives_CallSiteContext
|
||||||
|
|
||||||
int java_lang_invoke_MethodHandleNatives_CallSiteContext::_vmdependencies_offset;
|
int java_lang_invoke_MethodHandleNatives_CallSiteContext::_vmdependencies_offset;
|
||||||
|
|
|
@ -66,6 +66,7 @@
|
||||||
f(java_lang_invoke_LambdaForm) \
|
f(java_lang_invoke_LambdaForm) \
|
||||||
f(java_lang_invoke_MethodType) \
|
f(java_lang_invoke_MethodType) \
|
||||||
f(java_lang_invoke_CallSite) \
|
f(java_lang_invoke_CallSite) \
|
||||||
|
f(java_lang_invoke_ConstantCallSite) \
|
||||||
f(java_lang_invoke_MethodHandleNatives_CallSiteContext) \
|
f(java_lang_invoke_MethodHandleNatives_CallSiteContext) \
|
||||||
f(java_security_AccessControlContext) \
|
f(java_security_AccessControlContext) \
|
||||||
f(java_lang_reflect_AccessibleObject) \
|
f(java_lang_reflect_AccessibleObject) \
|
||||||
|
@ -1226,6 +1227,28 @@ public:
|
||||||
static int target_offset_in_bytes() { return _target_offset; }
|
static int target_offset_in_bytes() { return _target_offset; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Interface to java.lang.invoke.ConstantCallSite objects
|
||||||
|
|
||||||
|
class java_lang_invoke_ConstantCallSite: AllStatic {
|
||||||
|
friend class JavaClasses;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static int _is_frozen_offset;
|
||||||
|
|
||||||
|
static void compute_offsets();
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
|
||||||
|
// Accessors
|
||||||
|
static jboolean is_frozen(oop site);
|
||||||
|
|
||||||
|
// Testers
|
||||||
|
static bool is_subclass(Klass* klass) {
|
||||||
|
return klass->is_subclass_of(SystemDictionary::ConstantCallSite_klass());
|
||||||
|
}
|
||||||
|
static bool is_instance(oop obj);
|
||||||
|
};
|
||||||
|
|
||||||
// Interface to java.lang.invoke.MethodHandleNatives$CallSiteContext objects
|
// Interface to java.lang.invoke.MethodHandleNatives$CallSiteContext objects
|
||||||
|
|
||||||
#define CALLSITECONTEXT_INJECTED_FIELDS(macro) \
|
#define CALLSITECONTEXT_INJECTED_FIELDS(macro) \
|
||||||
|
|
|
@ -179,6 +179,14 @@ inline bool java_lang_invoke_CallSite::is_instance(oop obj) {
|
||||||
return obj != NULL && is_subclass(obj->klass());
|
return obj != NULL && is_subclass(obj->klass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline jboolean java_lang_invoke_ConstantCallSite::is_frozen(oop site) {
|
||||||
|
return site->bool_field(_is_frozen_offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool java_lang_invoke_ConstantCallSite::is_instance(oop obj) {
|
||||||
|
return obj != NULL && is_subclass(obj->klass());
|
||||||
|
}
|
||||||
|
|
||||||
inline bool java_lang_invoke_MethodHandleNatives_CallSiteContext::is_instance(oop obj) {
|
inline bool java_lang_invoke_MethodHandleNatives_CallSiteContext::is_instance(oop obj) {
|
||||||
return obj != NULL && is_subclass(obj->klass());
|
return obj != NULL && is_subclass(obj->klass());
|
||||||
}
|
}
|
||||||
|
|
|
@ -375,7 +375,7 @@ const Type* Type::make_constant_from_field(ciField* field, ciInstance* holder,
|
||||||
field->is_autobox_cache());
|
field->is_autobox_cache());
|
||||||
if (con_type != NULL && field->is_call_site_target()) {
|
if (con_type != NULL && field->is_call_site_target()) {
|
||||||
ciCallSite* call_site = holder->as_call_site();
|
ciCallSite* call_site = holder->as_call_site();
|
||||||
if (!call_site->is_constant_call_site()) {
|
if (!call_site->is_fully_initialized_constant_call_site()) {
|
||||||
ciMethodHandle* target = con.as_object()->as_method_handle();
|
ciMethodHandle* target = con.as_object()->as_method_handle();
|
||||||
Compile::current()->dependencies()->assert_call_site_target_value(call_site, target);
|
Compile::current()->dependencies()->assert_call_site_target_value(call_site, target);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class ConstantCallSite extends CallSite {
|
||||||
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
|
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
|
||||||
|
|
||||||
@Stable // should NOT be constant folded during instance initialization (isFrozen == false)
|
@Stable // should NOT be constant folded during instance initialization (isFrozen == false)
|
||||||
/*final*/ private boolean isFrozen;
|
/*final*/ private boolean isFrozen; // Note: This field is known to the JVM.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a call site with a permanent target.
|
* Creates a call site with a permanent target.
|
||||||
|
|
|
@ -128,7 +128,9 @@ public class CallSiteTest {
|
||||||
if (ccs != holder[0]) {
|
if (ccs != holder[0]) {
|
||||||
throw new AssertionError("different call site instances");
|
throw new AssertionError("different call site instances");
|
||||||
}
|
}
|
||||||
test(false); // should not throw
|
for (int i = 0; i < 20_000; i++) {
|
||||||
|
test(false); // should not throw
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testMutableCallSite() throws Throwable {
|
private static void testMutableCallSite() throws Throwable {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue