Skip to content
Permalink
Browse files

8234923: Missed call_site_target nmethod dependency for non-fully ini…

…tialized ConstantCallSite instance

Reviewed-by: jrose
  • Loading branch information
Vladimir Ivanov
Vladimir Ivanov committed Dec 3, 2019
1 parent c7bc0f7 commit a6daef527edfb9fbc0f2f4db14dd3054c63e085a
@@ -1707,7 +1707,7 @@ void GraphBuilder::access_field(Bytecodes::Code code) {
// For CallSite objects add a dependency for invalidation of the optimization.
if (field->is_call_site_target()) {
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();
dependency_recorder()->assert_call_site_target_value(call_site, target);
}
@@ -29,8 +29,18 @@

// ciCallSite

bool ciCallSite::is_constant_call_site() {
return klass()->is_subclass_of(CURRENT_ENV->ConstantCallSite_klass());
bool ciCallSite::is_fully_initialized_constant_call_site() {
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.
class ciCallSite : public ciInstance {
public:
ciCallSite(instanceHandle h_i) : ciInstance(h_i) {}
private:
bool _is_fully_initialized_cache;

public:
ciCallSite(instanceHandle h_i) : ciInstance(h_i), _is_fully_initialized_cache(false) {}

// What kind of ciObject is this?
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.
ciMethodHandle* get_target() const;
@@ -3918,6 +3918,24 @@ oop java_lang_invoke_CallSite::context_no_keepalive(oop call_site) {
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

int java_lang_invoke_MethodHandleNatives_CallSiteContext::_vmdependencies_offset;
@@ -66,6 +66,7 @@
f(java_lang_invoke_LambdaForm) \
f(java_lang_invoke_MethodType) \
f(java_lang_invoke_CallSite) \
f(java_lang_invoke_ConstantCallSite) \
f(java_lang_invoke_MethodHandleNatives_CallSiteContext) \
f(java_security_AccessControlContext) \
f(java_lang_reflect_AccessibleObject) \
@@ -1226,6 +1227,28 @@ class java_lang_invoke_CallSite: AllStatic {
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

#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());
}

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) {
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());
if (con_type != NULL && field->is_call_site_target()) {
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();
Compile::current()->dependencies()->assert_call_site_target_value(call_site, target);
}
@@ -39,7 +39,7 @@
private static final Unsafe UNSAFE = Unsafe.getUnsafe();

@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.
@@ -128,7 +128,9 @@ private static void testConstantCallSite() throws Throwable {
if (ccs != holder[0]) {
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 {

0 comments on commit a6daef5

Please sign in to comment.
You can’t perform that action at this time.