8178712: ResourceMark may be missing inside initialize_[vi]table
Summary: Clean up use of ResourceMark within initialize_[vi]table.
Reviewed-by: ccheung, iklam, jiangli
--- a/src/hotspot/share/oops/arrayKlass.cpp Thu Jul 12 16:28:31 2018 +0200
+++ b/src/hotspot/share/oops/arrayKlass.cpp Mon Jul 16 09:06:33 2018 -0400
@@ -100,7 +100,6 @@
// Initialization of vtables and mirror object is done separatly from base_create_array_klass,
// since a GC can happen. At this point all instance variables of the ArrayKlass must be setup.
void ArrayKlass::complete_create_array_klass(ArrayKlass* k, Klass* super_klass, ModuleEntry* module_entry, TRAPS) {
- ResourceMark rm(THREAD);
k->initialize_supers(super_klass, NULL, CHECK);
k->vtable().initialize_vtable(false, CHECK);
--- a/src/hotspot/share/oops/instanceKlass.cpp Thu Jul 12 16:28:31 2018 +0200
+++ b/src/hotspot/share/oops/instanceKlass.cpp Mon Jul 16 09:06:33 2018 -0400
@@ -821,7 +821,6 @@
ClassLoaderData * loader_data = class_loader_data();
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);
}
@@ -2326,7 +2325,6 @@
// point to old or obsolete entries. RedefineClasses doesn't fix up
// 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);
}
--- a/src/hotspot/share/oops/klassVtable.cpp Thu Jul 12 16:28:31 2018 +0200
+++ b/src/hotspot/share/oops/klassVtable.cpp Mon Jul 16 09:06:33 2018 -0400
@@ -257,7 +257,7 @@
// Interfaces do not need interface methods in their vtables
// This includes miranda methods and during later processing, default methods
if (!ik()->is_interface()) {
- initialized = fill_in_mirandas(initialized);
+ initialized = fill_in_mirandas(initialized, THREAD);
}
// In class hierarchies where the accessibility is not increasing (i.e., going from private ->
@@ -364,7 +364,7 @@
bool klassVtable::update_inherited_vtable(InstanceKlass* klass, const methodHandle& target_method,
int super_vtable_len, int default_index,
bool checkconstraints, TRAPS) {
- ResourceMark rm;
+ ResourceMark rm(THREAD);
bool allocate_new = true;
assert(klass->is_instance_klass(), "must be InstanceKlass");
@@ -902,7 +902,8 @@
// return the new value of initialized.
// Miranda methods use vtable entries, but do not get assigned a vtable_index
// The vtable_index is discovered by searching from the end of the vtable
-int klassVtable::fill_in_mirandas(int initialized) {
+int klassVtable::fill_in_mirandas(int initialized, TRAPS) {
+ ResourceMark rm(THREAD);
GrowableArray<Method*> mirandas(20);
get_mirandas(&mirandas, NULL, ik()->super(), ik()->methods(),
ik()->default_methods(), ik()->local_interfaces(),
@@ -910,7 +911,6 @@
for (int i = 0; i < mirandas.length(); i++) {
if (log_develop_is_enabled(Trace, vtables)) {
Method* meth = mirandas.at(i);
- ResourceMark rm(Thread::current());
LogTarget(Trace, vtables) lt;
LogStream ls(lt);
if (meth != NULL) {
@@ -1085,7 +1085,7 @@
if (_klass->is_interface()) {
// This needs to go after vtable indices are assigned but
// before implementors need to know the number of itable indices.
- assign_itable_indices_for_interface(_klass);
+ assign_itable_indices_for_interface(_klass, THREAD);
}
// Cannot be setup doing bootstrapping, interfaces don't have
@@ -1098,6 +1098,7 @@
guarantee(size_offset_table() >= 1, "too small");
int num_interfaces = size_offset_table() - 1;
if (num_interfaces > 0) {
+ ResourceMark rm(THREAD);
log_develop_debug(itables)("%3d: Initializing itables for %s", ++initialize_count,
_klass->name()->as_C_string());
@@ -1130,8 +1131,9 @@
return true;
}
-int klassItable::assign_itable_indices_for_interface(Klass* klass) {
+int klassItable::assign_itable_indices_for_interface(Klass* klass, TRAPS) {
// an interface does not have an itable, but its methods need to be numbered
+ ResourceMark rm(THREAD);
log_develop_debug(itables)("%3d: Initializing itable indices for interface %s",
++initialize_count, klass->name()->as_C_string());
Array<Method*>* methods = InstanceKlass::cast(klass)->methods();
@@ -1143,7 +1145,6 @@
assert(!m->is_final_method(), "no final interface methods");
// If m is already assigned a vtable index, do not disturb it.
if (log_develop_is_enabled(Trace, itables)) {
- ResourceMark rm;
LogTarget(Trace, itables) lt;
LogStream ls(lt);
assert(m != NULL, "methods can never be null");
@@ -1507,6 +1508,7 @@
oop* end_of_obj = (oop*)_klass + _klass->size();
oop* end_of_vtable = (oop *)&table()[_length];
if (end_of_vtable > end_of_obj) {
+ ResourceMark rm;
fatal("klass %s: klass object too short (vtable extends beyond end)",
_klass->internal_name());
}
--- a/src/hotspot/share/oops/klassVtable.hpp Thu Jul 12 16:28:31 2018 +0200
+++ b/src/hotspot/share/oops/klassVtable.hpp Mon Jul 16 09:06:33 2018 -0400
@@ -141,7 +141,7 @@
// support for miranda methods
bool is_miranda_entry_at(int i);
- int fill_in_mirandas(int initialized);
+ int fill_in_mirandas(int initialized, TRAPS);
static bool is_miranda(Method* m, Array<Method*>* class_methods,
Array<Method*>* default_methods, const Klass* super,
bool is_interface);
@@ -328,7 +328,7 @@
#endif // INCLUDE_JVMTI
// Setup of itable
- static int assign_itable_indices_for_interface(Klass* klass);
+ static int assign_itable_indices_for_interface(Klass* klass, TRAPS);
static int method_count_for_interface(Klass* klass);
static int compute_itable_size(Array<Klass*>* transitive_interfaces);
static void setup_itable_offset_table(InstanceKlass* klass);
--- a/src/hotspot/share/prims/jvmtiRedefineClasses.cpp Thu Jul 12 16:28:31 2018 +0200
+++ b/src/hotspot/share/prims/jvmtiRedefineClasses.cpp Mon Jul 16 09:06:33 2018 -0400
@@ -4098,17 +4098,14 @@
// Initialize the vtable and interface table after
// methods have been rewritten
- {
- ResourceMark rm(THREAD);
- // no exception should happen here since we explicitly
- // do not check loader constraints.
- // 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);
- assert(!HAS_PENDING_EXCEPTION || (THREAD->pending_exception()->is_a(SystemDictionary::ThreadDeath_klass())), "redefine exception");
- }
+ // no exception should happen here since we explicitly
+ // do not check loader constraints.
+ // 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);
+ assert(!HAS_PENDING_EXCEPTION || (THREAD->pending_exception()->is_a(SystemDictionary::ThreadDeath_klass())), "redefine exception");
// Leave arrays of jmethodIDs and itable index cache unchanged