提交 4ed25238 编写于 作者: K kevinw

8162795: [REDO] MemberNameTable doesn't purge stale entries

Summary: Re-application of the change in JDK-8152271.
Reviewed-by: coleenp, sspitsyn
上级 fc2bb1ec
/* /*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -2852,6 +2852,15 @@ void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) { ...@@ -2852,6 +2852,15 @@ void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
mname->address_field_put(_vmindex_offset, (address) index); mname->address_field_put(_vmindex_offset, (address) index);
} }
bool java_lang_invoke_MemberName::equals(oop mn1, oop mn2) {
if (mn1 == mn2) {
return true;
}
return (vmtarget(mn1) == vmtarget(mn2) && flags(mn1) == flags(mn2) &&
vmindex(mn1) == vmindex(mn2) &&
clazz(mn1) == clazz(mn2));
}
oop java_lang_invoke_LambdaForm::vmentry(oop lform) { oop java_lang_invoke_LambdaForm::vmentry(oop lform) {
assert(is_instance(lform), "wrong type"); assert(is_instance(lform), "wrong type");
return lform->obj_field(_vmentry_offset); return lform->obj_field(_vmentry_offset);
......
/* /*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -1132,6 +1132,8 @@ class java_lang_invoke_MemberName: AllStatic { ...@@ -1132,6 +1132,8 @@ class java_lang_invoke_MemberName: AllStatic {
static int flags_offset_in_bytes() { return _flags_offset; } static int flags_offset_in_bytes() { return _flags_offset; }
static int vmtarget_offset_in_bytes() { return _vmtarget_offset; } static int vmtarget_offset_in_bytes() { return _vmtarget_offset; }
static int vmindex_offset_in_bytes() { return _vmindex_offset; } static int vmindex_offset_in_bytes() { return _vmindex_offset; }
static bool equals(oop mt1, oop mt2);
}; };
......
...@@ -3062,7 +3062,7 @@ nmethod* InstanceKlass::lookup_osr_nmethod(const Method* m, int bci, int comp_le ...@@ -3062,7 +3062,7 @@ nmethod* InstanceKlass::lookup_osr_nmethod(const Method* m, int bci, int comp_le
return NULL; return NULL;
} }
bool InstanceKlass::add_member_name(Handle mem_name) { oop InstanceKlass::add_member_name(Handle mem_name, bool intern) {
jweak mem_name_wref = JNIHandles::make_weak_global(mem_name); jweak mem_name_wref = JNIHandles::make_weak_global(mem_name);
MutexLocker ml(MemberNameTable_lock); MutexLocker ml(MemberNameTable_lock);
DEBUG_ONLY(No_Safepoint_Verifier nsv); DEBUG_ONLY(No_Safepoint_Verifier nsv);
...@@ -3072,7 +3072,7 @@ bool InstanceKlass::add_member_name(Handle mem_name) { ...@@ -3072,7 +3072,7 @@ bool InstanceKlass::add_member_name(Handle mem_name) {
// is called! // is called!
Method* method = (Method*)java_lang_invoke_MemberName::vmtarget(mem_name()); Method* method = (Method*)java_lang_invoke_MemberName::vmtarget(mem_name());
if (method->is_obsolete()) { if (method->is_obsolete()) {
return false; return NULL;
} else if (method->is_old()) { } else if (method->is_old()) {
// Replace method with redefined version // Replace method with redefined version
java_lang_invoke_MemberName::set_vmtarget(mem_name(), method_with_idnum(method->method_idnum())); java_lang_invoke_MemberName::set_vmtarget(mem_name(), method_with_idnum(method->method_idnum()));
...@@ -3081,8 +3081,11 @@ bool InstanceKlass::add_member_name(Handle mem_name) { ...@@ -3081,8 +3081,11 @@ bool InstanceKlass::add_member_name(Handle mem_name) {
if (_member_names == NULL) { if (_member_names == NULL) {
_member_names = new (ResourceObj::C_HEAP, mtClass) MemberNameTable(idnum_allocated_count()); _member_names = new (ResourceObj::C_HEAP, mtClass) MemberNameTable(idnum_allocated_count());
} }
_member_names->add_member_name(mem_name_wref); if (intern) {
return true; return _member_names->find_or_add_member_name(mem_name_wref);
} else {
return _member_names->add_member_name(mem_name_wref);
}
} }
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
......
...@@ -1130,7 +1130,7 @@ public: ...@@ -1130,7 +1130,7 @@ public:
// JSR-292 support // JSR-292 support
MemberNameTable* member_names() { return _member_names; } MemberNameTable* member_names() { return _member_names; }
void set_member_names(MemberNameTable* member_names) { _member_names = member_names; } void set_member_names(MemberNameTable* member_names) { _member_names = member_names; }
bool add_member_name(Handle member_name); oop add_member_name(Handle member_name, bool intern);
public: public:
// JVMTI support // JVMTI support
......
...@@ -643,7 +643,7 @@ JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle)) ...@@ -643,7 +643,7 @@ JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle))
// This can safepoint and redefine method, so need both new_obj and method // This can safepoint and redefine method, so need both new_obj and method
// in a handle, for two different reasons. new_obj can move, method can be // in a handle, for two different reasons. new_obj can move, method can be
// deleted if nothing is using it on the stack. // deleted if nothing is using it on the stack.
m->method_holder()->add_member_name(new_obj()); m->method_holder()->add_member_name(new_obj(), false);
} }
} }
......
...@@ -173,7 +173,7 @@ oop MethodHandles::init_MemberName(Handle mname, Handle target) { ...@@ -173,7 +173,7 @@ oop MethodHandles::init_MemberName(Handle mname, Handle target) {
return NULL; return NULL;
} }
oop MethodHandles::init_method_MemberName(Handle mname, CallInfo& info) { oop MethodHandles::init_method_MemberName(Handle mname, CallInfo& info, bool intern) {
assert(info.resolved_appendix().is_null(), "only normal methods here"); assert(info.resolved_appendix().is_null(), "only normal methods here");
methodHandle m = info.resolved_method(); methodHandle m = info.resolved_method();
KlassHandle m_klass = m->method_holder(); KlassHandle m_klass = m->method_holder();
...@@ -270,13 +270,7 @@ oop MethodHandles::init_method_MemberName(Handle mname, CallInfo& info) { ...@@ -270,13 +270,7 @@ oop MethodHandles::init_method_MemberName(Handle mname, CallInfo& info) {
// If relevant, the vtable or itable value is stored as vmindex. // If relevant, the vtable or itable value is stored as vmindex.
// This is done eagerly, since it is readily available without // This is done eagerly, since it is readily available without
// constructing any new objects. // constructing any new objects.
// TO DO: maybe intern mname_oop return m->method_holder()->add_member_name(mname, intern);
if (m->method_holder()->add_member_name(mname)) {
return mname();
} else {
// Redefinition caused this to fail. Return NULL (and an exception?)
return NULL;
}
} }
oop MethodHandles::init_field_MemberName(Handle mname, fieldDescriptor& fd, bool is_setter) { oop MethodHandles::init_field_MemberName(Handle mname, fieldDescriptor& fd, bool is_setter) {
...@@ -917,7 +911,9 @@ int MethodHandles::find_MemberNames(KlassHandle k, ...@@ -917,7 +911,9 @@ int MethodHandles::find_MemberNames(KlassHandle k,
if (!java_lang_invoke_MemberName::is_instance(result())) if (!java_lang_invoke_MemberName::is_instance(result()))
return -99; // caller bug! return -99; // caller bug!
CallInfo info(m); CallInfo info(m);
oop saved = MethodHandles::init_method_MemberName(result, info); // Since this is going through the methods to create MemberNames, don't search
// for matching methods already in the table
oop saved = MethodHandles::init_method_MemberName(result, info, /*intern*/false);
if (saved != result()) if (saved != result())
results->obj_at_put(rfill-1, saved); // show saved instance to user results->obj_at_put(rfill-1, saved); // show saved instance to user
} else if (++overflow >= overflow_limit) { } else if (++overflow >= overflow_limit) {
...@@ -949,9 +945,34 @@ MemberNameTable::~MemberNameTable() { ...@@ -949,9 +945,34 @@ MemberNameTable::~MemberNameTable() {
} }
} }
void MemberNameTable::add_member_name(jweak mem_name_wref) { oop MemberNameTable::add_member_name(jweak mem_name_wref) {
assert_locked_or_safepoint(MemberNameTable_lock); assert_locked_or_safepoint(MemberNameTable_lock);
this->push(mem_name_wref); this->push(mem_name_wref);
return JNIHandles::resolve(mem_name_wref);
}
oop MemberNameTable::find_or_add_member_name(jweak mem_name_wref) {
assert_locked_or_safepoint(MemberNameTable_lock);
oop new_mem_name = JNIHandles::resolve(mem_name_wref);
// Find matching member name in the list.
// This is linear because these are short lists.
int len = this->length();
int new_index = len;
for (int idx = 0; idx < len; idx++) {
oop mname = JNIHandles::resolve(this->at(idx));
if (mname == NULL) {
new_index = idx;
continue;
}
if (java_lang_invoke_MemberName::equals(new_mem_name, mname)) {
JNIHandles::destroy_weak_global(mem_name_wref);
return mname;
}
}
// Not found, push the new one, or reuse empty slot
this->at_put_grow(new_index, mem_name_wref);
return new_mem_name;
} }
#if INCLUDE_JVMTI #if INCLUDE_JVMTI
......
/* /*
* Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -60,7 +60,7 @@ class MethodHandles: AllStatic { ...@@ -60,7 +60,7 @@ class MethodHandles: AllStatic {
static Handle new_MemberName(TRAPS); // must be followed by init_MemberName static Handle new_MemberName(TRAPS); // must be followed by init_MemberName
static oop init_MemberName(Handle mname_h, Handle target_h); // compute vmtarget/vmindex from target static oop init_MemberName(Handle mname_h, Handle target_h); // compute vmtarget/vmindex from target
static oop init_field_MemberName(Handle mname_h, fieldDescriptor& fd, bool is_setter = false); static oop init_field_MemberName(Handle mname_h, fieldDescriptor& fd, bool is_setter = false);
static oop init_method_MemberName(Handle mname_h, CallInfo& info); static oop init_method_MemberName(Handle mname_h, CallInfo& info, bool intern = true);
static int method_ref_kind(Method* m, bool do_dispatch_if_possible = true); static int method_ref_kind(Method* m, bool do_dispatch_if_possible = true);
static int find_MemberNames(KlassHandle k, Symbol* name, Symbol* sig, static int find_MemberNames(KlassHandle k, Symbol* name, Symbol* sig,
int mflags, KlassHandle caller, int mflags, KlassHandle caller,
...@@ -236,7 +236,8 @@ class MemberNameTable : public GrowableArray<jweak> { ...@@ -236,7 +236,8 @@ class MemberNameTable : public GrowableArray<jweak> {
public: public:
MemberNameTable(int methods_cnt); MemberNameTable(int methods_cnt);
~MemberNameTable(); ~MemberNameTable();
void add_member_name(jweak mem_name_ref); oop add_member_name(jweak mem_name_ref);
oop find_or_add_member_name(jweak mem_name_ref);
#if INCLUDE_JVMTI #if INCLUDE_JVMTI
// RedefineClasses() API support: // RedefineClasses() API support:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册