Skip to content

Commit

Permalink
8316271: JfrJvmtiAgent::retransformClasses failed: JVMTI_ERROR_FAILS_…
Browse files Browse the repository at this point in the history
…VERIFICATION

Reviewed-by: egahlin
  • Loading branch information
Markus Grönlund committed Oct 30, 2023
1 parent 88b9cda commit c4c66ab
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ private void makeInstrumented() {
// if (!settingsMethod(eventConfiguration.settingX)) goto fail;
codeBuilder.aload(0);
getEventConfiguration(codeBuilder);
codeBuilder.checkcast(TYPE_EVENT_CONFIGURATION);
codeBuilder.ldc(index);
invokevirtual(codeBuilder, TYPE_EVENT_CONFIGURATION, METHOD_EVENT_CONFIGURATION_GET_SETTING);
MethodTypeDesc mdesc = MethodTypeDesc.ofDescriptor("(" + sd.paramType().descriptorString() + ")Z");
Expand Down Expand Up @@ -712,6 +711,7 @@ private void getEventWriter(CodeBuilder codeBuilder) {
private void getEventConfiguration(CodeBuilder codeBuilder) {
if (untypedEventConfiguration) {
codeBuilder.getstatic(getEventClassDesc(), FIELD_EVENT_CONFIGURATION.name(), TYPE_OBJECT);
codeBuilder.checkcast(TYPE_EVENT_CONFIGURATION);
} else {
codeBuilder.getstatic(getEventClassDesc(), FIELD_EVENT_CONFIGURATION.name(), TYPE_EVENT_CONFIGURATION);
}
Expand Down
61 changes: 61 additions & 0 deletions test/jdk/jdk/jfr/jvm/TestVerifyInstrumentation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2023, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package jdk.jfr.jvm;

import jdk.jfr.Recording;
import jdk.test.lib.jfr.EventNames;

/**
* @test
* @bug 8316271
* @key jfr
* @requires vm.hasJFR
* @library /test/lib
* @run main/othervm -Xverify:all jdk.jfr.jvm.TestVerifyInstrumentation
*/
public class TestVerifyInstrumentation {
private final static String EVENT_NAME = EventNames.ThreadSleep;

public static void main(String[] args) {
// This thread sleep wil load the jdk.internal.event.ThreadSleepEvent
// before JFR has started recording. This will set the type of the static
// field EventConfiguration to become untyped, i.e. java.lang.Object.
// Before issuing an invokevirtual instructions for this receiver, we must perform
// the proper type conversion, i.e. a downcast to type EventConfiguration using
// a conditional checkcast. -Xverify:all asserts this is ok.
//
// If not ok, the following exception is thrown as part of retransformation:
//
// java.lang.RuntimeException: JfrJvmtiAgent::retransformClasses failed: JVMTI_ERROR_FAILS_VERIFICATION.
//
try {
Thread.sleep(1);
} catch (InterruptedException ie) {}
try (Recording recording = new Recording()) {
recording.enable(EVENT_NAME).withoutThreshold().withStackTrace();
recording.start();
recording.stop();
}
}
}

1 comment on commit c4c66ab

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.