Skip to content

Commit 9824e64

Browse files
committed
8291830: jvmti/RedefineClasses/StressRedefine failed: assert(!is_null(v)) failed: narrow klass value can never be zero
Backport-of: fb6fd03233b0eb001e2995d20a079b6af31d2b9b
1 parent 2e5a402 commit 9824e64

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
@@ -821,6 +821,7 @@ void ClassLoaderData::add_to_deallocate_list(Metadata* m) {
821821
_deallocate_list = new (ResourceObj::C_HEAP, mtClass) GrowableArray<Metadata*>(100, mtClass);
822822
}
823823
_deallocate_list->append_if_missing(m);
824+
ResourceMark rm;
824825
log_debug(class, loader, data)("deallocate added for %s", m->print_value_string());
825826
ClassLoaderDataGraph::set_should_clean_deallocate_lists();
826827
}

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"
@@ -63,10 +63,6 @@ oop Klass::java_mirror_no_keepalive() const {
6363
return _java_mirror.peek();
6464
}
6565

66-
void Klass::replace_java_mirror(oop mirror) {
67-
_java_mirror.replace(mirror);
68-
}
69-
7066
bool Klass::is_cloneable() const {
7167
return _access_flags.is_cloneable_fast() ||
7268
is_subtype_of(vmClasses::Cloneable_klass());
@@ -786,7 +782,7 @@ void Klass::verify_on(outputStream* st) {
786782
}
787783

788784
if (java_mirror_no_keepalive() != NULL) {
789-
guarantee(oopDesc::is_oop(java_mirror_no_keepalive()), "should be instance");
785+
guarantee(java_lang_Class::is_instance(java_mirror_no_keepalive()), "should be instance");
790786
}
791787
}
792788

src/hotspot/share/oops/klass.hpp

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

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

273274
// Set java mirror OopHandle to NULL for CDS
274275
// 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
@@ -1318,22 +1318,22 @@ class RedefineVerifyMark : public StackObj {
13181318
private:
13191319
JvmtiThreadState* _state;
13201320
Klass* _scratch_class;
1321-
Handle _scratch_mirror;
1321+
OopHandle _scratch_mirror;
13221322

13231323
public:
13241324

13251325
RedefineVerifyMark(Klass* the_class, Klass* scratch_class,
13261326
JvmtiThreadState* state) : _state(state), _scratch_class(scratch_class)
13271327
{
13281328
_state->set_class_versions_map(the_class, scratch_class);
1329-
_scratch_mirror = Handle(_state->get_thread(), _scratch_class->java_mirror());
1330-
_scratch_class->replace_java_mirror(the_class->java_mirror());
1329+
_scratch_mirror = the_class->java_mirror_handle(); // this is a copy that is swapped
1330+
_scratch_class->swap_java_mirror_handle(_scratch_mirror);
13311331
}
13321332

13331333
~RedefineVerifyMark() {
13341334
// Restore the scratch class's mirror, so when scratch_class is removed
13351335
// the correct mirror pointing to it can be cleared.
1336-
_scratch_class->replace_java_mirror(_scratch_mirror());
1336+
_scratch_class->swap_java_mirror_handle(_scratch_mirror);
13371337
_state->clear_class_versions_map();
13381338
}
13391339
};

0 commit comments

Comments
 (0)