changeset 46408:70aab0c2ea8b

8178350: klassVtable and klassItable should be ValueObj Reviewed-by: coleenp
author iklam
date Thu, 13 Apr 2017 01:56:01 -0700
parents 32baebe49efe
children b8e6a56681f5
files hotspot/src/share/vm/code/vtableStubs.cpp hotspot/src/share/vm/interpreter/linkResolver.cpp hotspot/src/share/vm/memory/universe.cpp hotspot/src/share/vm/oops/arrayKlass.cpp hotspot/src/share/vm/oops/instanceKlass.cpp hotspot/src/share/vm/oops/instanceKlass.hpp hotspot/src/share/vm/oops/klass.cpp hotspot/src/share/vm/oops/klass.hpp hotspot/src/share/vm/oops/klassVtable.cpp hotspot/src/share/vm/oops/klassVtable.hpp hotspot/src/share/vm/oops/method.cpp hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp hotspot/src/share/vm/prims/methodHandles.cpp hotspot/src/share/vm/utilities/debug.cpp
diffstat 14 files changed, 56 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/hotspot/src/share/vm/code/vtableStubs.cpp	Mon Apr 24 21:34:24 2017 +0200
+++ b/hotspot/src/share/vm/code/vtableStubs.cpp	Thu Apr 13 01:56:01 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2014, 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.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -218,11 +218,11 @@
   HandleMark hm;
   Klass* klass = receiver->klass();
   InstanceKlass* ik = InstanceKlass::cast(klass);
-  klassVtable* vt = ik->vtable();
+  klassVtable vt = ik->vtable();
   ik->print();
   fatal("bad compiled vtable dispatch: receiver " INTPTR_FORMAT ", "
         "index %d (vtable length %d)",
-        p2i(receiver), index, vt->length());
+        p2i(receiver), index, vt.length());
 }
 
 #endif // PRODUCT
--- a/hotspot/src/share/vm/interpreter/linkResolver.cpp	Mon Apr 24 21:34:24 2017 +0200
+++ b/hotspot/src/share/vm/interpreter/linkResolver.cpp	Thu Apr 13 01:56:01 2017 -0700
@@ -150,8 +150,6 @@
     kind = CallInfo::vtable_call;
   } else if (!resolved_klass->is_interface()) {
     // A default or miranda method.  Compute the vtable index.
-    ResourceMark rm;
-    klassVtable* vt = resolved_klass->vtable();
     index = LinkResolver::vtable_index_of_interface_method(resolved_klass,
                            resolved_method);
     assert(index >= 0 , "we should have valid vtable index at this point");
@@ -163,7 +161,7 @@
 #ifdef ASSERT
     // Ensure that this is really the case.
     Klass* object_klass = SystemDictionary::Object_klass();
-    Method * object_resolved_method = object_klass->vtable()->method_at(index);
+    Method * object_resolved_method = object_klass->vtable().method_at(index);
     assert(object_resolved_method->name() == resolved_method->name(),
       "Object and interface method names should match at vtable index %d, %s != %s",
       index, object_resolved_method->name()->as_C_string(), resolved_method->name()->as_C_string());
@@ -400,9 +398,8 @@
   }
   if (vtable_index == Method::invalid_vtable_index) {
     // get vtable_index for miranda methods
-    ResourceMark rm;
-    klassVtable *vt = ik->vtable();
-    vtable_index = vt->index_of_miranda(name, signature);
+    klassVtable vt = ik->vtable();
+    vtable_index = vt.index_of_miranda(name, signature);
   }
   return vtable_index;
 }
--- a/hotspot/src/share/vm/memory/universe.cpp	Mon Apr 24 21:34:24 2017 +0200
+++ b/hotspot/src/share/vm/memory/universe.cpp	Thu Apr 13 01:56:01 2017 -0700
@@ -526,8 +526,7 @@
 // In case those ever change we use handles for oops
 void Universe::reinitialize_vtable_of(Klass* ko, TRAPS) {
   // init vtable of k and all subclasses
-  klassVtable* vt = ko->vtable();
-  if (vt) vt->initialize_vtable(false, CHECK);
+  ko->vtable().initialize_vtable(false, CHECK);
   if (ko->is_instance_klass()) {
     for (Klass* sk = ko->subklass();
          sk != NULL;
@@ -539,7 +538,7 @@
 
 
 void initialize_itable_for_klass(Klass* k, TRAPS) {
-  InstanceKlass::cast(k)->itable()->initialize_itable(false, CHECK);
+  InstanceKlass::cast(k)->itable().initialize_itable(false, CHECK);
 }
 
 
--- a/hotspot/src/share/vm/oops/arrayKlass.cpp	Mon Apr 24 21:34:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/arrayKlass.cpp	Thu Apr 13 01:56:01 2017 -0700
@@ -99,7 +99,7 @@
 void ArrayKlass::complete_create_array_klass(ArrayKlass* k, Klass* super_klass, ModuleEntry* module_entry, TRAPS) {
   ResourceMark rm(THREAD);
   k->initialize_supers(super_klass, CHECK);
-  k->vtable()->initialize_vtable(false, CHECK);
+  k->vtable().initialize_vtable(false, CHECK);
 
   // During bootstrapping, before java.base is defined, the module_entry may not be present yet.
   // These classes will be put on a fixup list and their module fields will be patched once
--- a/hotspot/src/share/vm/oops/instanceKlass.cpp	Mon Apr 24 21:34:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/instanceKlass.cpp	Thu Apr 13 01:56:01 2017 -0700
@@ -373,8 +373,8 @@
   return !is_initialized();
 }
 
-klassItable* InstanceKlass::itable() const {
-  return new klassItable(const_cast<InstanceKlass*>(this));
+klassItable InstanceKlass::itable() const {
+  return klassItable(const_cast<InstanceKlass*>(this));
 }
 
 void InstanceKlass::eager_initialize(Thread *thread) {
@@ -621,15 +621,14 @@
       if (!(is_shared() &&
             loader_data->is_the_null_class_loader_data())) {
         ResourceMark rm(THREAD);
-        vtable()->initialize_vtable(true, CHECK_false);
-        itable()->initialize_itable(true, CHECK_false);
+        vtable().initialize_vtable(true, CHECK_false);
+        itable().initialize_itable(true, CHECK_false);
       }
 #ifdef ASSERT
       else {
-        ResourceMark rm(THREAD);
-        vtable()->verify(tty, true);
+        vtable().verify(tty, true);
         // In case itable verification is ever added.
-        // itable()->verify(tty, true);
+        // itable().verify(tty, true);
       }
 #endif
       set_init_state(linked);
@@ -807,8 +806,8 @@
   // Step 9
   if (!HAS_PENDING_EXCEPTION) {
     set_initialization_state_and_notify(fully_initialized, CHECK);
-    { ResourceMark rm(THREAD);
-      debug_only(vtable()->verify(tty, true);)
+    {
+      debug_only(vtable().verify(tty, true);)
     }
   }
   else {
@@ -2041,8 +2040,8 @@
     // vtables in the shared system dictionary, only the main one.
     // It also redefines the itable too so fix that too.
     ResourceMark rm(THREAD);
-    vtable()->initialize_vtable(false, CHECK);
-    itable()->initialize_itable(false, CHECK);
+    vtable().initialize_vtable(false, CHECK);
+    itable().initialize_itable(false, CHECK);
   }
 
   // restore constant pool resolved references
@@ -3212,10 +3211,9 @@
 
   // Verify vtables
   if (is_linked()) {
-    ResourceMark rm;
     // $$$ This used to be done only for m/s collections.  Doing it
     // always seemed a valid generalization.  (DLD -- 6/00)
-    vtable()->verify(st);
+    vtable().verify(st);
   }
 
   // Verify first subklass
--- a/hotspot/src/share/vm/oops/instanceKlass.hpp	Mon Apr 24 21:34:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/instanceKlass.hpp	Thu Apr 13 01:56:01 2017 -0700
@@ -1127,7 +1127,7 @@
   }
 
   // Java itable
-  klassItable* itable() const;        // return new klassItable wrapper
+  klassItable itable() const;        // return klassItable wrapper
   Method* method_at_itable(Klass* holder, int index, TRAPS);
 
 #if INCLUDE_JVMTI
--- a/hotspot/src/share/vm/oops/klass.cpp	Mon Apr 24 21:34:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/klass.cpp	Thu Apr 13 01:56:01 2017 -0700
@@ -696,8 +696,8 @@
   guarantee(obj->klass()->is_klass(), "klass field is not a klass");
 }
 
-klassVtable* Klass::vtable() const {
-  return new klassVtable(const_cast<Klass*>(this), start_of_vtable(), vtable_length() / vtableEntry::size());
+klassVtable Klass::vtable() const {
+  return klassVtable(const_cast<Klass*>(this), start_of_vtable(), vtable_length() / vtableEntry::size());
 }
 
 vtableEntry* Klass::start_of_vtable() const {
--- a/hotspot/src/share/vm/oops/klass.hpp	Mon Apr 24 21:34:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/klass.hpp	Thu Apr 13 01:56:01 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * 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.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -399,7 +399,7 @@
 #endif
 
   // vtables
-  klassVtable* vtable() const;
+  klassVtable vtable() const;
   int vtable_length() const { return _vtable_len; }
 
   // subclass check
--- a/hotspot/src/share/vm/oops/klassVtable.cpp	Mon Apr 24 21:34:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/klassVtable.cpp	Thu Apr 13 01:56:01 2017 -0700
@@ -136,22 +136,22 @@
     // methods from super class for shared class, as that was already done
     // during archiving time. However, if Jvmti has redefined a class,
     // copy super class's vtable in case the super class has changed.
-    return super->vtable()->length();
+    return super->vtable().length();
   } else {
     // copy methods from superKlass
-    klassVtable* superVtable = super->vtable();
-    assert(superVtable->length() <= _length, "vtable too short");
+    klassVtable superVtable = super->vtable();
+    assert(superVtable.length() <= _length, "vtable too short");
 #ifdef ASSERT
-    superVtable->verify(tty, true);
+    superVtable.verify(tty, true);
 #endif
-    superVtable->copy_vtable_to(table());
+    superVtable.copy_vtable_to(table());
     if (log_develop_is_enabled(Trace, vtables)) {
       ResourceMark rm;
       log_develop_trace(vtables)("copy vtable from %s to %s size %d",
                                  super->internal_name(), klass()->internal_name(),
                                  _length);
     }
-    return superVtable->length();
+    return superVtable.length();
   }
 }
 
@@ -290,9 +290,9 @@
   InstanceKlass* superk = initialsuper;
   while (superk != NULL && superk->super() != NULL) {
     InstanceKlass* supersuperklass = InstanceKlass::cast(superk->super());
-    klassVtable* ssVtable = supersuperklass->vtable();
-    if (vtable_index < ssVtable->length()) {
-      Method* super_method = ssVtable->method_at(vtable_index);
+    klassVtable ssVtable = supersuperklass->vtable();
+    if (vtable_index < ssVtable.length()) {
+      Method* super_method = ssVtable.method_at(vtable_index);
 #ifndef PRODUCT
       Symbol* name= target_method()->name();
       Symbol* signature = target_method()->signature();
@@ -445,8 +445,8 @@
     if (is_preinitialized_vtable()) {
       // If this is a shared class, the vtable is already in the final state (fully
       // initialized). Need to look at the super's vtable.
-      klassVtable* superVtable = super->vtable();
-      super_method = superVtable->method_at(i);
+      klassVtable superVtable = super->vtable();
+      super_method = superVtable.method_at(i);
     } else {
       super_method = method_at(i);
     }
@@ -1249,17 +1249,6 @@
   }
 }
 
-// Update entry for specific Method*
-void klassItable::initialize_with_method(Method* m) {
-  itableMethodEntry* ime = method_entry(0);
-  for(int i = 0; i < _size_method_table; i++) {
-    if (ime->method() == m) {
-      ime->initialize(m);
-    }
-    ime++;
-  }
-}
-
 #if INCLUDE_JVMTI
 // search the itable for uses of either obsolete or EMCP methods
 void klassItable::adjust_method_entries(InstanceKlass* holder, bool * trace_name_printed) {
@@ -1488,9 +1477,9 @@
   Klass* super = _klass->super();
   if (super != NULL) {
     InstanceKlass* sk = InstanceKlass::cast(super);
-    klassVtable* vt = sk->vtable();
-    for (int i = 0; i < vt->length(); i++) {
-      verify_against(st, vt, i);
+    klassVtable vt = sk->vtable();
+    for (int i = 0; i < vt.length(); i++) {
+      verify_against(st, &vt, i);
     }
   }
 }
@@ -1557,8 +1546,7 @@
 
   static void do_class(Klass* k) {
     Klass* kl = k;
-    klassVtable* vt = kl->vtable();
-    if (vt == NULL) return;
+    klassVtable vt = kl->vtable();
     no_klasses++;
     if (kl->is_instance_klass()) {
       no_instance_klasses++;
@@ -1566,9 +1554,9 @@
     }
     if (kl->is_array_klass()) {
       no_array_klasses++;
-      sum_of_array_vtable_len += vt->length();
+      sum_of_array_vtable_len += vt.length();
     }
-    sum_of_vtable_len += vt->length();
+    sum_of_vtable_len += vt.length();
   }
 
   static void compute() {
--- a/hotspot/src/share/vm/oops/klassVtable.hpp	Mon Apr 24 21:34:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/klassVtable.hpp	Thu Apr 13 01:56:01 2017 -0700
@@ -41,7 +41,7 @@
 
 class vtableEntry;
 
-class klassVtable : public ResourceObj {
+class klassVtable VALUE_OBJ_CLASS_SPEC {
   Klass*       _klass;            // my klass
   int          _tableOffset;      // offset of start of vtable data within klass
   int          _length;           // length of vtable (number of entries)
@@ -288,7 +288,7 @@
 //    -- vtable for interface 2 ---
 //    ...
 //
-class klassItable : public ResourceObj {
+class klassItable VALUE_OBJ_CLASS_SPEC {
  private:
   InstanceKlass*       _klass;             // my klass
   int                  _table_offset;      // offset of start of itable data within klass (in words)
@@ -310,9 +310,6 @@
   // Initialization
   void initialize_itable(bool checkconstraints, TRAPS);
 
-  // Updates
-  void initialize_with_method(Method* m);
-
 #if INCLUDE_JVMTI
   // RedefineClasses() API support:
   // if any entry of this itable points to any of old_methods,
--- a/hotspot/src/share/vm/oops/method.cpp	Mon Apr 24 21:34:24 2017 +0200
+++ b/hotspot/src/share/vm/oops/method.cpp	Thu Apr 13 01:56:01 2017 -0700
@@ -1191,7 +1191,6 @@
   }
 
   assert(ik->is_subclass_of(method_holder()), "should be subklass");
-  assert(ik->vtable() != NULL, "vtable should exist");
   if (!has_vtable_index()) {
     return false;
   } else {
--- a/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp	Mon Apr 24 21:34:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp	Thu Apr 13 01:56:01 2017 -0700
@@ -3272,7 +3272,7 @@
   // If the class being redefined is java.lang.Object, we need to fix all
   // array class vtables also
   if (k->is_array_klass() && _the_class == SystemDictionary::Object_klass()) {
-    k->vtable()->adjust_method_entries(the_class, &trace_name_printed);
+    k->vtable().adjust_method_entries(the_class, &trace_name_printed);
 
   } else if (k->is_instance_klass()) {
     HandleMark hm(_thread);
@@ -3315,7 +3315,7 @@
       // ik->vtable() creates a wrapper object; rm cleans it up
       ResourceMark rm(_thread);
 
-      ik->vtable()->adjust_method_entries(the_class, &trace_name_printed);
+      ik->vtable().adjust_method_entries(the_class, &trace_name_printed);
       ik->adjust_default_methods(the_class, &trace_name_printed);
     }
 
@@ -3329,10 +3329,8 @@
     if (ik->itable_length() > 0 && (_the_class->is_interface()
         || _the_class == SystemDictionary::internal_Unsafe_klass()
         || ik->is_subclass_of(_the_class))) {
-      // ik->itable() creates a wrapper object; rm cleans it up
       ResourceMark rm(_thread);
-
-      ik->itable()->adjust_method_entries(the_class, &trace_name_printed);
+      ik->itable().adjust_method_entries(the_class, &trace_name_printed);
     }
 
     // The constant pools in other classes (other_cp) can refer to
@@ -3957,8 +3955,8 @@
     // compare_and_normalize_class_versions has already checked:
     //  - classloaders unchanged, signatures unchanged
     //  - all instanceKlasses for redefined classes reused & contents updated
-    the_class->vtable()->initialize_vtable(false, THREAD);
-    the_class->itable()->initialize_itable(false, THREAD);
+    the_class->vtable().initialize_vtable(false, THREAD);
+    the_class->itable().initialize_itable(false, THREAD);
     assert(!HAS_PENDING_EXCEPTION || (THREAD->pending_exception()->is_a(SystemDictionary::ThreadDeath_klass())), "redefine exception");
   }
 
@@ -4093,12 +4091,12 @@
   // a vtable should never contain old or obsolete methods
   ResourceMark rm(_thread);
   if (k->vtable_length() > 0 &&
-      !k->vtable()->check_no_old_or_obsolete_entries()) {
+      !k->vtable().check_no_old_or_obsolete_entries()) {
     if (log_is_enabled(Trace, redefine, class, obsolete, metadata)) {
       log_trace(redefine, class, obsolete, metadata)
         ("klassVtable::check_no_old_or_obsolete_entries failure -- OLD or OBSOLETE method found -- class: %s",
          k->signature_name());
-      k->vtable()->dump_vtable();
+      k->vtable().dump_vtable();
     }
     no_old_methods = false;
   }
@@ -4109,12 +4107,12 @@
 
     // an itable should never contain old or obsolete methods
     if (ik->itable_length() > 0 &&
-        !ik->itable()->check_no_old_or_obsolete_entries()) {
+        !ik->itable().check_no_old_or_obsolete_entries()) {
       if (log_is_enabled(Trace, redefine, class, obsolete, metadata)) {
         log_trace(redefine, class, obsolete, metadata)
           ("klassItable::check_no_old_or_obsolete_entries failure -- OLD or OBSOLETE method found -- class: %s",
            ik->signature_name());
-        ik->itable()->dump_itable();
+        ik->itable().dump_itable();
       }
       no_old_methods = false;
     }
--- a/hotspot/src/share/vm/prims/methodHandles.cpp	Mon Apr 24 21:34:24 2017 +0200
+++ b/hotspot/src/share/vm/prims/methodHandles.cpp	Thu Apr 13 01:56:01 2017 -0700
@@ -218,7 +218,7 @@
         m_klass_non_interface = SystemDictionary::Object_klass();
 #ifdef ASSERT
         { ResourceMark rm;
-          Method* m2 = m_klass_non_interface->vtable()->method_at(vmindex);
+          Method* m2 = m_klass_non_interface->vtable().method_at(vmindex);
           assert(m->name() == m2->name() && m->signature() == m2->signature(),
                  "at %d, %s != %s", vmindex,
                  m->name_and_sig_as_C_string(), m2->name_and_sig_as_C_string());
--- a/hotspot/src/share/vm/utilities/debug.cpp	Mon Apr 24 21:34:24 2017 +0200
+++ b/hotspot/src/share/vm/utilities/debug.cpp	Thu Apr 13 01:56:01 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * 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.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -490,7 +490,7 @@
 extern "C" void dump_vtable(address p) {
   Command c("dump_vtable");
   Klass* k = (Klass*)p;
-  k->vtable()->print();
+  k->vtable().print();
 }