8014288: perf regression in nashorn JDK-8008448.js test after 8008511 changes
Summary: The fix of perf regression is to use method_idnum() for direct indexing into NMT
Reviewed-by: twisti, kvn, coleenp, dholmes
Contributed-by: serguei.spitsyn@oracle.com
--- a/hotspot/src/share/vm/oops/instanceKlass.cpp Thu May 23 17:39:32 2013 +0200
+++ b/hotspot/src/share/vm/oops/instanceKlass.cpp Thu May 23 23:04:33 2013 -0700
@@ -2754,15 +2754,28 @@
return NULL;
}
-void InstanceKlass::add_member_name(Handle mem_name) {
+void InstanceKlass::add_member_name(int index, Handle mem_name) {
jweak mem_name_wref = JNIHandles::make_weak_global(mem_name);
MutexLocker ml(MemberNameTable_lock);
+ assert(0 <= index && index < idnum_allocated_count(), "index is out of bounds");
DEBUG_ONLY(No_Safepoint_Verifier nsv);
if (_member_names == NULL) {
- _member_names = new (ResourceObj::C_HEAP, mtClass) MemberNameTable();
+ _member_names = new (ResourceObj::C_HEAP, mtClass) MemberNameTable(idnum_allocated_count());
}
- _member_names->add_member_name(mem_name_wref);
+ _member_names->add_member_name(index, mem_name_wref);
+}
+
+oop InstanceKlass::get_member_name(int index) {
+ MutexLocker ml(MemberNameTable_lock);
+ assert(0 <= index && index < idnum_allocated_count(), "index is out of bounds");
+ DEBUG_ONLY(No_Safepoint_Verifier nsv);
+
+ if (_member_names == NULL) {
+ return NULL;
+ }
+ oop mem_name =_member_names->get_member_name(index);
+ return mem_name;
}
// -----------------------------------------------------------------------------------------------------
--- a/hotspot/src/share/vm/oops/instanceKlass.hpp Thu May 23 17:39:32 2013 +0200
+++ b/hotspot/src/share/vm/oops/instanceKlass.hpp Thu May 23 23:04:33 2013 -0700
@@ -1022,7 +1022,8 @@
// JSR-292 support
MemberNameTable* member_names() { return _member_names; }
void set_member_names(MemberNameTable* member_names) { _member_names = member_names; }
- void add_member_name(Handle member_name);
+ void add_member_name(int index, Handle member_name);
+ oop get_member_name(int index);
public:
// JVMTI support
--- a/hotspot/src/share/vm/prims/methodHandles.cpp Thu May 23 17:39:32 2013 +0200
+++ b/hotspot/src/share/vm/prims/methodHandles.cpp Thu May 23 23:04:33 2013 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -232,7 +232,8 @@
// This is done eagerly, since it is readily available without
// constructing any new objects.
// TO DO: maybe intern mname_oop
- m->method_holder()->add_member_name(mname);
+ m->method_holder()->add_member_name(m->method_idnum(), mname);
+
return mname();
}
@@ -301,7 +302,6 @@
// Although the fieldDescriptor::_index would also identify the field,
// we do not use it, because it is harder to decode.
// TO DO: maybe intern mname_oop
- InstanceKlass::cast(field_holder())->add_member_name(mname);
return mname();
}
@@ -943,7 +943,8 @@
// MemberNameTable
//
-MemberNameTable::MemberNameTable() : GrowableArray<jweak>(10, true) {
+MemberNameTable::MemberNameTable(int methods_cnt)
+ : GrowableArray<jweak>(methods_cnt, true) {
assert_locked_or_safepoint(MemberNameTable_lock);
}
@@ -957,29 +958,18 @@
}
}
-// Return entry index if found, return -1 otherwise.
-int MemberNameTable::find_member_name(oop mem_name) {
+void MemberNameTable::add_member_name(int index, jweak mem_name_wref) {
assert_locked_or_safepoint(MemberNameTable_lock);
- int len = this->length();
-
- for (int idx = 0; idx < len; idx++) {
- jweak ref = this->at(idx);
- oop entry = JNIHandles::resolve(ref);
- if (entry == mem_name) {
- return idx;
- }
- }
- return -1;
+ this->at_put_grow(index, mem_name_wref);
}
-void MemberNameTable::add_member_name(jweak mem_name_wref) {
+// Return a member name oop or NULL.
+oop MemberNameTable::get_member_name(int index) {
assert_locked_or_safepoint(MemberNameTable_lock);
- oop mem_name = JNIHandles::resolve(mem_name_wref);
- // Each member name may appear just once: add only if not found
- if (find_member_name(mem_name) == -1) {
- this->append(mem_name_wref);
- }
+ jweak ref = this->at(index);
+ oop mem_name = JNIHandles::resolve(ref);
+ return mem_name;
}
#if INCLUDE_JVMTI
--- a/hotspot/src/share/vm/prims/methodHandles.hpp Thu May 23 17:39:32 2013 +0200
+++ b/hotspot/src/share/vm/prims/methodHandles.hpp Thu May 23 23:04:33 2013 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -219,7 +219,6 @@
}
};
-
//------------------------------------------------------------------------------
// MethodHandlesAdapterGenerator
//
@@ -233,13 +232,13 @@
//------------------------------------------------------------------------------
// MemberNameTable
//
+
class MemberNameTable : public GrowableArray<jweak> {
public:
- MemberNameTable();
+ MemberNameTable(int methods_cnt);
~MemberNameTable();
- void add_member_name(jweak mem_name_ref);
- private:
- int find_member_name(oop mem_name);
+ void add_member_name(int index, jweak mem_name_ref);
+ oop get_member_name(int index);
#if INCLUDE_JVMTI
public: