diff --git a/src/hotspot/share/classfile/classLoaderData.cpp b/src/hotspot/share/classfile/classLoaderData.cpp index adb7463b6bf6b..c09c702367138 100644 --- a/src/hotspot/share/classfile/classLoaderData.cpp +++ b/src/hotspot/share/classfile/classLoaderData.cpp @@ -824,6 +824,7 @@ void ClassLoaderData::add_to_deallocate_list(Metadata* m) { _deallocate_list = new (mtClass) GrowableArray(100, mtClass); } _deallocate_list->append_if_missing(m); + ResourceMark rm; log_debug(class, loader, data)("deallocate added for %s", m->print_value_string()); ClassLoaderDataGraph::set_should_clean_deallocate_lists(); } diff --git a/src/hotspot/share/oops/klass.cpp b/src/hotspot/share/oops/klass.cpp index 521d688833d89..00d55fce477a6 100644 --- a/src/hotspot/share/oops/klass.cpp +++ b/src/hotspot/share/oops/klass.cpp @@ -27,7 +27,7 @@ #include "cds/heapShared.hpp" #include "classfile/classLoaderData.inline.hpp" #include "classfile/classLoaderDataGraph.inline.hpp" -#include "classfile/javaClasses.hpp" +#include "classfile/javaClasses.inline.hpp" #include "classfile/moduleEntry.hpp" #include "classfile/systemDictionary.hpp" #include "classfile/systemDictionaryShared.hpp" @@ -65,10 +65,6 @@ oop Klass::java_mirror_no_keepalive() const { return _java_mirror.peek(); } -void Klass::replace_java_mirror(oop mirror) { - _java_mirror.replace(mirror); -} - bool Klass::is_cloneable() const { return _access_flags.is_cloneable_fast() || is_subtype_of(vmClasses::Cloneable_klass()); @@ -788,7 +784,7 @@ void Klass::verify_on(outputStream* st) { } if (java_mirror_no_keepalive() != NULL) { - guarantee(oopDesc::is_oop(java_mirror_no_keepalive()), "should be instance"); + guarantee(java_lang_Class::is_instance(java_mirror_no_keepalive()), "should be instance"); } } diff --git a/src/hotspot/share/oops/klass.hpp b/src/hotspot/share/oops/klass.hpp index d624acbcb15bc..d251c998ebf30 100644 --- a/src/hotspot/share/oops/klass.hpp +++ b/src/hotspot/share/oops/klass.hpp @@ -269,7 +269,8 @@ class Klass : public Metadata { void set_archived_java_mirror(oop m) NOT_CDS_JAVA_HEAP_RETURN; // Temporary mirror switch used by RedefineClasses - void replace_java_mirror(oop mirror); + OopHandle java_mirror_handle() const { return _java_mirror; } + void swap_java_mirror_handle(OopHandle& mirror) { _java_mirror.swap(mirror); } // Set java mirror OopHandle to NULL for CDS // This leaves the OopHandle in the CLD, but that's ok, you can't release them. diff --git a/src/hotspot/share/oops/oopHandle.hpp b/src/hotspot/share/oops/oopHandle.hpp index 4a304b968f236..fd4c9679219e7 100644 --- a/src/hotspot/share/oops/oopHandle.hpp +++ b/src/hotspot/share/oops/oopHandle.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2022, 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 @@ -55,6 +55,10 @@ class OopHandle { return *this; } + void swap(OopHandle& copy) { + ::swap(_obj, copy._obj); + } + inline oop resolve() const; inline oop peek() const; diff --git a/src/hotspot/share/prims/jvmtiRedefineClasses.cpp b/src/hotspot/share/prims/jvmtiRedefineClasses.cpp index 189a9b12167ce..9cea6247112eb 100644 --- a/src/hotspot/share/prims/jvmtiRedefineClasses.cpp +++ b/src/hotspot/share/prims/jvmtiRedefineClasses.cpp @@ -1324,7 +1324,7 @@ class RedefineVerifyMark : public StackObj { private: JvmtiThreadState* _state; Klass* _scratch_class; - Handle _scratch_mirror; + OopHandle _scratch_mirror; public: @@ -1332,14 +1332,14 @@ class RedefineVerifyMark : public StackObj { JvmtiThreadState* state) : _state(state), _scratch_class(scratch_class) { _state->set_class_versions_map(the_class, scratch_class); - _scratch_mirror = Handle(_state->get_thread(), _scratch_class->java_mirror()); - _scratch_class->replace_java_mirror(the_class->java_mirror()); + _scratch_mirror = the_class->java_mirror_handle(); // this is a copy that is swapped + _scratch_class->swap_java_mirror_handle(_scratch_mirror); } ~RedefineVerifyMark() { // Restore the scratch class's mirror, so when scratch_class is removed // the correct mirror pointing to it can be cleared. - _scratch_class->replace_java_mirror(_scratch_mirror()); + _scratch_class->swap_java_mirror_handle(_scratch_mirror); _state->clear_class_versions_map(); } };