8219904: ClassCastException when calling FlightRecorderMXBean#getRecordings()
Reviewed-by: egahlin, mseledtsov
This commit is contained in:
parent
52d7a61e8d
commit
9c35471ae0
src/jdk.management.jfr/share/classes/jdk/management/jfr
test/jdk/jdk/jfr/jmx
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2020, 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
|
||||
@ -51,7 +51,7 @@ public final class RecordingInfo {
|
||||
private final String state;
|
||||
private final boolean dumpOnExit;
|
||||
private final long size;
|
||||
private final boolean disk;
|
||||
private final boolean toDisk;
|
||||
private final long maxAge;
|
||||
private final long maxSize;
|
||||
private final long startTime;
|
||||
@ -67,7 +67,7 @@ public final class RecordingInfo {
|
||||
state = recording.getState().toString();
|
||||
dumpOnExit = recording.getDumpOnExit();
|
||||
size = recording.getSize();
|
||||
disk = recording.isToDisk();
|
||||
toDisk = recording.isToDisk();
|
||||
|
||||
Duration d = recording.getMaxAge();
|
||||
if (d == null) {
|
||||
@ -87,12 +87,17 @@ public final class RecordingInfo {
|
||||
}
|
||||
|
||||
private RecordingInfo(CompositeData cd) {
|
||||
id = (int) cd.get("id");
|
||||
id = (long) cd.get("id");
|
||||
name = (String) cd.get("name");
|
||||
state = (String) cd.get("state");
|
||||
dumpOnExit = (boolean) cd.get("dumpOnExit");
|
||||
size = (long) cd.get("size");
|
||||
disk = (boolean) cd.get("disk");
|
||||
if(cd.containsKey("toDisk")){
|
||||
toDisk = (boolean) cd.get("toDisk");
|
||||
} else {
|
||||
// Before JDK-8219904 was fixed, the element name was disk, so for compatibility
|
||||
toDisk = (boolean) cd.get("disk");
|
||||
}
|
||||
maxAge = (Long) cd.get("maxAge");
|
||||
maxSize = (Long) cd.get("maxSize");
|
||||
startTime = (Long) cd.get("startTime");
|
||||
@ -290,7 +295,7 @@ public final class RecordingInfo {
|
||||
* @return {@code true} if recording is to disk, {@code false} otherwise
|
||||
*/
|
||||
public boolean isToDisk() {
|
||||
return disk;
|
||||
return toDisk;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -342,7 +347,7 @@ public final class RecordingInfo {
|
||||
* <td>{@code Long}</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <th scope="row">disk</th>
|
||||
* <th scope="row">toDisk</th>
|
||||
* <td>{@code Boolean}</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
|
@ -36,6 +36,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sun.tools.attach.VirtualMachine;
|
||||
import jdk.jfr.EventType;
|
||||
import jdk.jfr.FlightRecorder;
|
||||
import jdk.jfr.Recording;
|
||||
@ -52,7 +53,15 @@ import jdk.test.lib.Utils;
|
||||
import jdk.test.lib.jfr.CommonHelper;
|
||||
import jdk.test.lib.jfr.Events;
|
||||
|
||||
import javax.management.JMX;
|
||||
import javax.management.MBeanServerConnection;
|
||||
import javax.management.ObjectName;
|
||||
import javax.management.remote.JMXConnector;
|
||||
import javax.management.remote.JMXConnectorFactory;
|
||||
import javax.management.remote.JMXServiceURL;
|
||||
|
||||
public class JmxHelper {
|
||||
private static final String LOCAL_CONNECTION_ADDRESS = "com.sun.management.jmxremote.localConnectorAddress";
|
||||
|
||||
public static RecordingInfo getJmxRecording(long recId) {
|
||||
for (RecordingInfo r : getFlighteRecorderMXBean().getRecordings()) {
|
||||
@ -279,4 +288,18 @@ public class JmxHelper {
|
||||
return ManagementFactory.getPlatformMXBean(FlightRecorderMXBean.class);
|
||||
}
|
||||
|
||||
public static long getPID(){
|
||||
return ManagementFactory.getRuntimeMXBean().getPid();
|
||||
}
|
||||
|
||||
public static FlightRecorderMXBean getFlighteRecorderMXBean(long pid) throws Exception {
|
||||
VirtualMachine targetVM = VirtualMachine.attach("" + pid);
|
||||
String jmxServiceUrl = targetVM.getAgentProperties().getProperty(LOCAL_CONNECTION_ADDRESS);
|
||||
JMXServiceURL jmxURL = new JMXServiceURL(jmxServiceUrl);
|
||||
JMXConnector connector = JMXConnectorFactory.connect(jmxURL);
|
||||
MBeanServerConnection connection = connector.getMBeanServerConnection();
|
||||
|
||||
ObjectName objectName = new ObjectName("jdk.management.jfr:type=FlightRecorder");
|
||||
return JMX.newMXBeanProxy(connection, objectName, FlightRecorderMXBean.class);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2020, 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
|
||||
@ -35,7 +35,7 @@ import jdk.management.jfr.RecordingInfo;
|
||||
* @key jfr
|
||||
* @requires vm.hasJFR
|
||||
* @library /test/lib /test/jdk
|
||||
* @run main/othervm jdk.jfr.jmx.TestGetRecordings
|
||||
* @run main/othervm -Djdk.attach.allowAttachSelf=true -Dcom.sun.management.jmxremote jdk.jfr.jmx.TestGetRecordings
|
||||
*/
|
||||
public class TestGetRecordings {
|
||||
public static void main(String[] args) throws Throwable {
|
||||
@ -46,5 +46,11 @@ public class TestGetRecordings {
|
||||
JmxHelper.verifyNotExists(recId, preCreateRecordings);
|
||||
bean.closeRecording(recId);
|
||||
JmxHelper.verifyNotExists(recId, bean.getRecordings());
|
||||
|
||||
long selfPID = JmxHelper.getPID();
|
||||
FlightRecorderMXBean remoteBean = JmxHelper.getFlighteRecorderMXBean(selfPID);
|
||||
long remoteRecId = remoteBean.newRecording();
|
||||
remoteBean.getRecordings();
|
||||
remoteBean.closeRecording(remoteRecId);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user