--- old/src/jdk.management.jfr/share/classes/jdk/management/jfr/RecordingInfo.java 2019-11-29 00:25:31.309541871 +0900 +++ new/src/jdk.management.jfr/share/classes/jdk/management/jfr/RecordingInfo.java 2019-11-29 00:25:31.197541107 +0900 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2019, 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 @@ 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 @@ 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 @@ } 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 @@ * @return {@code true} if recording is to disk, {@code false} otherwise */ public boolean isToDisk() { - return disk; + return toDisk; } /** @@ -342,7 +347,7 @@ * {@code Long} * * - * disk + * toDisk * {@code Boolean} * * --- old/test/jdk/jdk/jfr/jmx/JmxHelper.java 2019-11-29 00:25:31.577543700 +0900 +++ new/test/jdk/jdk/jfr/jmx/JmxHelper.java 2019-11-29 00:25:31.457542881 +0900 @@ -36,6 +36,7 @@ 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.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 @@ 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); + } } --- old/test/jdk/jdk/jfr/jmx/TestGetRecordings.java 2019-11-29 00:25:31.857545610 +0900 +++ new/test/jdk/jdk/jfr/jmx/TestGetRecordings.java 2019-11-29 00:25:31.741544818 +0900 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2019, 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 @@ * @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 @@ 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); } }