Skip to content

Commit

Permalink
8291830: jvmti/RedefineClasses/StressRedefine failed: assert(!is_null…
Browse files Browse the repository at this point in the history
…(v)) failed: narrow klass value can never be zero

Reviewed-by: sspitsyn, eosterlund, kbarrett
  • Loading branch information
coleenp committed Dec 2, 2022
1 parent 1b92465 commit fb6fd03
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/hotspot/share/classfile/classLoaderData.cpp
Expand Up @@ -824,6 +824,7 @@ void ClassLoaderData::add_to_deallocate_list(Metadata* m) {
_deallocate_list = new (mtClass) GrowableArray<Metadata*>(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();
}
Expand Down
8 changes: 2 additions & 6 deletions src/hotspot/share/oops/klass.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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");
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/oops/klass.hpp
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion 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
Expand Down Expand Up @@ -55,6 +55,10 @@ class OopHandle {
return *this;
}

void swap(OopHandle& copy) {
::swap(_obj, copy._obj);
}

inline oop resolve() const;
inline oop peek() const;

Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/share/prims/jvmtiRedefineClasses.cpp
Expand Up @@ -1324,22 +1324,22 @@ class RedefineVerifyMark : public StackObj {
private:
JvmtiThreadState* _state;
Klass* _scratch_class;
Handle _scratch_mirror;
OopHandle _scratch_mirror;

public:

RedefineVerifyMark(Klass* the_class, Klass* scratch_class,
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();
}
};
Expand Down

3 comments on commit fb6fd03

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheRealMDoerr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on fb6fd03 Jun 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheRealMDoerr the backport was successfully created on the branch TheRealMDoerr-backport-fb6fd032 in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit fb6fd032 from the openjdk/jdk repository.

The commit being backported was authored by Coleen Phillimore on 2 Dec 2022 and was reviewed by Serguei Spitsyn, Erik Österlund and Kim Barrett.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev.git TheRealMDoerr-backport-fb6fd032:TheRealMDoerr-backport-fb6fd032
$ git checkout TheRealMDoerr-backport-fb6fd032
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev.git TheRealMDoerr-backport-fb6fd032

Please sign in to comment.