From 03afec16f8abecb845eb14db5b51eaac9131a3c8 Mon Sep 17 00:00:00 2001 From: Coleen Phillimore Date: Tue, 20 Dec 2022 14:09:22 +0000 Subject: [PATCH] 8298162: Test PrintClasses hits assert when run with code that retransform classes Reviewed-by: dholmes, mgronlun --- src/hotspot/share/runtime/fieldDescriptor.cpp | 6 ++++-- test/hotspot/jtreg/runtime/CommandLine/PrintClasses.java | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/hotspot/share/runtime/fieldDescriptor.cpp b/src/hotspot/share/runtime/fieldDescriptor.cpp index c90ad16651d..d642d65f5cb 100644 --- a/src/hotspot/share/runtime/fieldDescriptor.cpp +++ b/src/hotspot/share/runtime/fieldDescriptor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -102,7 +102,9 @@ void fieldDescriptor::reinitialize(InstanceKlass* ik, int index) { if (_cp.is_null() || field_holder() != ik) { _cp = constantPoolHandle(Thread::current(), ik->constants()); // _cp should now reference ik's constant pool; i.e., ik is now field_holder. - assert(field_holder() == ik, "must be already initialized to this class"); + // If the class is a scratch class, the constant pool points to the original class, + // but that's ok because of constant pool merging. + assert(field_holder() == ik || ik->is_scratch_class(), "must be already initialized to this class"); } FieldInfo* f = ik->field(index); _access_flags = accessFlags_from(f->access_flags()); diff --git a/test/hotspot/jtreg/runtime/CommandLine/PrintClasses.java b/test/hotspot/jtreg/runtime/CommandLine/PrintClasses.java index 7c45e2ea02f..65ae6b16081 100644 --- a/test/hotspot/jtreg/runtime/CommandLine/PrintClasses.java +++ b/test/hotspot/jtreg/runtime/CommandLine/PrintClasses.java @@ -30,6 +30,15 @@ * @run main/othervm PrintClasses */ +/* + * @test + * @bug 8298162 + * @summary Test jcmd VM.classes with JFR + * @requires vm.hasJFR + * @library /test/lib + * @run main/othervm -XX:StartFlightRecording PrintClasses + */ + import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.JDKToolFinder;