Skip to content

Commit fb6fd03

Browse files
committed
8291830: jvmti/RedefineClasses/StressRedefine failed: assert(!is_null(v)) failed: narrow klass value can never be zero
Reviewed-by: sspitsyn, eosterlund, kbarrett
1 parent 1b92465 commit fb6fd03

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

src/hotspot/share/classfile/classLoaderData.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ void ClassLoaderData::add_to_deallocate_list(Metadata* m) {
824824
_deallocate_list = new (mtClass) GrowableArray<Metadata*>(100, mtClass);
825825
}
826826
_deallocate_list->append_if_missing(m);
827+
ResourceMark rm;
827828
log_debug(class, loader, data)("deallocate added for %s", m->print_value_string());
828829
ClassLoaderDataGraph::set_should_clean_deallocate_lists();
829830
}

src/hotspot/share/oops/klass.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include "cds/heapShared.hpp"
2828
#include "classfile/classLoaderData.inline.hpp"
2929
#include "classfile/classLoaderDataGraph.inline.hpp"
30-
#include "classfile/javaClasses.hpp"
30+
#include "classfile/javaClasses.inline.hpp"
3131
#include "classfile/moduleEntry.hpp"
3232
#include "classfile/systemDictionary.hpp"
3333
#include "classfile/systemDictionaryShared.hpp"
@@ -65,10 +65,6 @@ oop Klass::java_mirror_no_keepalive() const {
6565
return _java_mirror.peek();
6666
}
6767

68-
void Klass::replace_java_mirror(oop mirror) {
69-
_java_mirror.replace(mirror);
70-
}
71-
7268
bool Klass::is_cloneable() const {
7369
return _access_flags.is_cloneable_fast() ||
7470
is_subtype_of(vmClasses::Cloneable_klass());
@@ -788,7 +784,7 @@ void Klass::verify_on(outputStream* st) {
788784
}
789785

790786
if (java_mirror_no_keepalive() != NULL) {
791-
guarantee(oopDesc::is_oop(java_mirror_no_keepalive()), "should be instance");
787+
guarantee(java_lang_Class::is_instance(java_mirror_no_keepalive()), "should be instance");
792788
}
793789
}
794790

src/hotspot/share/oops/klass.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ class Klass : public Metadata {
269269
void set_archived_java_mirror(oop m) NOT_CDS_JAVA_HEAP_RETURN;
270270

271271
// Temporary mirror switch used by RedefineClasses
272-
void replace_java_mirror(oop mirror);
272+
OopHandle java_mirror_handle() const { return _java_mirror; }
273+
void swap_java_mirror_handle(OopHandle& mirror) { _java_mirror.swap(mirror); }
273274

274275
// Set java mirror OopHandle to NULL for CDS
275276
// This leaves the OopHandle in the CLD, but that's ok, you can't release them.

src/hotspot/share/oops/oopHandle.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -55,6 +55,10 @@ class OopHandle {
5555
return *this;
5656
}
5757

58+
void swap(OopHandle& copy) {
59+
::swap(_obj, copy._obj);
60+
}
61+
5862
inline oop resolve() const;
5963
inline oop peek() const;
6064

src/hotspot/share/prims/jvmtiRedefineClasses.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1324,22 +1324,22 @@ class RedefineVerifyMark : public StackObj {
13241324
private:
13251325
JvmtiThreadState* _state;
13261326
Klass* _scratch_class;
1327-
Handle _scratch_mirror;
1327+
OopHandle _scratch_mirror;
13281328

13291329
public:
13301330

13311331
RedefineVerifyMark(Klass* the_class, Klass* scratch_class,
13321332
JvmtiThreadState* state) : _state(state), _scratch_class(scratch_class)
13331333
{
13341334
_state->set_class_versions_map(the_class, scratch_class);
1335-
_scratch_mirror = Handle(_state->get_thread(), _scratch_class->java_mirror());
1336-
_scratch_class->replace_java_mirror(the_class->java_mirror());
1335+
_scratch_mirror = the_class->java_mirror_handle(); // this is a copy that is swapped
1336+
_scratch_class->swap_java_mirror_handle(_scratch_mirror);
13371337
}
13381338

13391339
~RedefineVerifyMark() {
13401340
// Restore the scratch class's mirror, so when scratch_class is removed
13411341
// the correct mirror pointing to it can be cleared.
1342-
_scratch_class->replace_java_mirror(_scratch_mirror());
1342+
_scratch_class->swap_java_mirror_handle(_scratch_mirror);
13431343
_state->clear_class_versions_map();
13441344
}
13451345
};

0 commit comments

Comments
 (0)