changeset 4994:e5ef592bb7e0

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
author sspitsyn
date Fri, 07 Feb 2014 16:10:06 -0800
parents 07ddad7ad2ac
children 2628a61dff77
files src/share/vm/oops/instanceKlass.cpp src/share/vm/oops/instanceKlass.hpp src/share/vm/prims/methodHandles.cpp src/share/vm/prims/methodHandles.hpp
diffstat 4 files changed, 34 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/oops/instanceKlass.cpp	Fri Feb 07 16:08:18 2014 -0800
+++ b/src/share/vm/oops/instanceKlass.cpp	Fri Feb 07 16:10:06 2014 -0800
@@ -2339,15 +2339,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/src/share/vm/oops/instanceKlass.hpp	Fri Feb 07 16:08:18 2014 -0800
+++ b/src/share/vm/oops/instanceKlass.hpp	Fri Feb 07 16:10:06 2014 -0800
@@ -977,7 +977,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/src/share/vm/prims/methodHandles.cpp	Fri Feb 07 16:08:18 2014 -0800
+++ b/src/share/vm/prims/methodHandles.cpp	Fri Feb 07 16:10:06 2014 -0800
@@ -252,7 +252,8 @@
   // If relevant, the vtable or itable value is stored as vmindex.
   // This is done eagerly, since it is readily available without
   // constructing any new objects.
-  instanceKlass::cast(m->method_holder())->add_member_name(mname);
+  instanceKlass::cast(m->method_holder())->add_member_name(m->method_idnum(), mname);
+
   return mname();
 }
 
@@ -305,7 +306,6 @@
   // because they unambiguously identify the field.
   // Although the fieldDescriptor::_index would also identify the field,
   // we do not use it, because it is harder to decode.
-  instanceKlass::cast(field_holder())->add_member_name(mname);
   return mname();
 }
 
@@ -978,7 +978,8 @@
 // MemberNameTable
 //
 
-MemberNameTable::MemberNameTable() : GrowableArray<jweak>(10, true) {
+MemberNameTable::MemberNameTable(int methods_cnt)
+                  : GrowableArray<jweak>(methods_cnt, true) {
   assert_locked_or_safepoint(MemberNameTable_lock);
 }
 
@@ -992,29 +993,17 @@
   }
 }
 
-// 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;
 }
 
 oop MemberNameTable::find_member_name_by_method(methodOop old_method) {
--- a/src/share/vm/prims/methodHandles.hpp	Fri Feb 07 16:08:18 2014 -0800
+++ b/src/share/vm/prims/methodHandles.hpp	Fri Feb 07 16:10:06 2014 -0800
@@ -232,13 +232,14 @@
 //------------------------------------------------------------------------------
 // MemberNameTable
 //
+
 class MemberNameTable : public GrowableArray<jweak> {
  public:
-  MemberNameTable();
+  MemberNameTable(int methods_cnt);
   ~MemberNameTable();
-  void add_member_name(jweak mem_name_wref);
- private:
-  int find_member_name(oop mem_name);
+
+  void add_member_name(int index, jweak mem_name_ref);
+  oop  get_member_name(int index);
 
  public:
   // RedefineClasses() API support: