Skip to content

Commit 6b77069

Browse files
committed
8291830: jvmti/RedefineClasses/StressRedefine failed: assert(!is_null(v)) failed: narrow klass value can never be zero
Reviewed-by: mdoerr Backport-of: fb6fd03233b0eb001e2995d20a079b6af31d2b9b
1 parent b3417d8 commit 6b77069

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

src/hotspot/share/oops/klass.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "precompiled.hpp"
2626
#include "classfile/classLoaderData.inline.hpp"
2727
#include "classfile/dictionary.hpp"
28-
#include "classfile/javaClasses.hpp"
28+
#include "classfile/javaClasses.inline.hpp"
2929
#include "classfile/systemDictionary.hpp"
3030
#include "classfile/vmSymbols.hpp"
3131
#include "gc/shared/collectedHeap.inline.hpp"
@@ -735,7 +735,7 @@ void Klass::verify_on(outputStream* st) {
735735
}
736736

737737
if (java_mirror_no_keepalive() != NULL) {
738-
guarantee(oopDesc::is_oop(java_mirror_no_keepalive()), "should be instance");
738+
guarantee(java_lang_Class::is_instance(java_mirror_no_keepalive()), "should be instance");
739739
}
740740
}
741741

src/hotspot/share/oops/klass.hpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,8 @@ class Klass : public Metadata {
269269
// Both mirrors are on the ClassLoaderData::_handles list already so no
270270
// barriers are needed.
271271
void set_java_mirror_handle(OopHandle mirror) { _java_mirror = mirror; }
272-
OopHandle java_mirror_handle() const {
273-
return _java_mirror;
274-
}
272+
OopHandle java_mirror_handle() const { return _java_mirror; }
273+
void swap_java_mirror_handle(OopHandle& mirror) { _java_mirror.swap(mirror); }
275274

276275
// modifier flags
277276
jint modifier_flags() const { return _modifier_flags; }

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, 2018, 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
@@ -43,6 +43,10 @@ class OopHandle {
4343
OopHandle() : _obj(NULL) {}
4444
OopHandle(oop* w) : _obj(w) {}
4545

46+
void swap(OopHandle& copy) {
47+
::swap(_obj, copy._obj);
48+
}
49+
4650
inline oop resolve() const;
4751
inline oop peek() const;
4852

src/hotspot/share/prims/jvmtiThreadState.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,14 @@ class RedefineVerifyMark : public StackObj {
411411
JvmtiThreadState *state) : _state(state), _scratch_class(scratch_class)
412412
{
413413
_state->set_class_versions_map(the_class, scratch_class);
414-
_scratch_mirror = _scratch_class->java_mirror_handle();
415-
_scratch_class->set_java_mirror_handle(the_class->java_mirror_handle());
414+
_scratch_mirror = the_class->java_mirror_handle(); // this is a copy that is swapped
415+
_scratch_class->swap_java_mirror_handle(_scratch_mirror);
416416
}
417417

418418
~RedefineVerifyMark() {
419419
// Restore the scratch class's mirror, so when scratch_class is removed
420420
// the correct mirror pointing to it can be cleared.
421-
_scratch_class->set_java_mirror_handle(_scratch_mirror);
421+
_scratch_class->swap_java_mirror_handle(_scratch_mirror);
422422
_state->clear_class_versions_map();
423423
}
424424
};

0 commit comments

Comments
 (0)