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;