8164035: compiler/profiling/spectrapredefineclass_classloaders/Launcher.java failing with Agent JAR not found or no Agent-Class attribute
Reviewed-by: kvn
This commit is contained in:
parent
ee1cbde17b
commit
c645d7bb87
hotspot/test/compiler/profiling
spectrapredefineclass
spectrapredefineclass_classloaders
@ -24,10 +24,12 @@
|
|||||||
package compiler.profiling.spectrapredefineclass;
|
package compiler.profiling.spectrapredefineclass;
|
||||||
|
|
||||||
import com.sun.tools.attach.VirtualMachine;
|
import com.sun.tools.attach.VirtualMachine;
|
||||||
|
import jdk.test.lib.Utils;
|
||||||
|
|
||||||
import java.lang.instrument.ClassFileTransformer;
|
import java.lang.instrument.ClassFileTransformer;
|
||||||
import java.lang.instrument.Instrumentation;
|
import java.lang.instrument.Instrumentation;
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.security.ProtectionDomain;
|
import java.security.ProtectionDomain;
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
@ -67,8 +69,7 @@ class Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class Agent implements ClassFileTransformer {
|
public class Agent implements ClassFileTransformer {
|
||||||
|
public static final String AGENT_JAR = Paths.get(Utils.TEST_CLASSES, "agent.jar").toString();
|
||||||
|
|
||||||
static public boolean m2(A a) {
|
static public boolean m2(A a) {
|
||||||
boolean res = false;
|
boolean res = false;
|
||||||
if (a.getClass() == B.class) {
|
if (a.getClass() == B.class) {
|
||||||
@ -95,7 +96,7 @@ public class Agent implements ClassFileTransformer {
|
|||||||
// Redefine class
|
// Redefine class
|
||||||
try {
|
try {
|
||||||
VirtualMachine vm = VirtualMachine.attach(pid);
|
VirtualMachine vm = VirtualMachine.attach(pid);
|
||||||
vm.loadAgent(System.getProperty("test.classes",".") + "/agent.jar", "");
|
vm.loadAgent(AGENT_JAR, "");
|
||||||
vm.detach();
|
vm.detach();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
* @modules java.base/jdk.internal.misc
|
* @modules java.base/jdk.internal.misc
|
||||||
* java.instrument
|
* java.instrument
|
||||||
* java.management
|
* java.management
|
||||||
* @build compiler.profiling.spectrapredefineclass_classloaders.Agent
|
* @build compiler.profiling.spectrapredefineclass.Agent
|
||||||
* @run driver ClassFileInstaller compiler.profiling.spectrapredefineclass.Agent
|
* @run driver ClassFileInstaller compiler.profiling.spectrapredefineclass.Agent
|
||||||
* @run driver compiler.profiling.spectrapredefineclass.Launcher
|
* @run driver compiler.profiling.spectrapredefineclass.Launcher
|
||||||
* @run main/othervm -XX:-TieredCompilation -XX:-BackgroundCompilation
|
* @run main/othervm -XX:-TieredCompilation -XX:-BackgroundCompilation
|
||||||
@ -39,23 +39,33 @@
|
|||||||
|
|
||||||
package compiler.profiling.spectrapredefineclass;
|
package compiler.profiling.spectrapredefineclass;
|
||||||
|
|
||||||
import jdk.test.lib.JDKToolFinder;
|
import jdk.test.lib.JDKToolLauncher;
|
||||||
|
import jdk.test.lib.OutputAnalyzer;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
public class Launcher {
|
public class Launcher {
|
||||||
|
private static final String MANIFEST = "MANIFEST.MF";
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
try (PrintWriter pw = new PrintWriter(MANIFEST)) {
|
||||||
|
pw.println("Agent-Class: " + Agent.class.getName());
|
||||||
|
pw.println("Can-Retransform-Classes: true");
|
||||||
|
}
|
||||||
|
|
||||||
PrintWriter pw = new PrintWriter("MANIFEST.MF");
|
JDKToolLauncher jar = JDKToolLauncher.create("jar")
|
||||||
pw.println("Agent-Class: " + Launcher.class.getPackage().getName() +".Agent");
|
.addToolArg("cmf")
|
||||||
pw.println("Can-Retransform-Classes: true");
|
.addToolArg(MANIFEST)
|
||||||
pw.close();
|
.addToolArg(Agent.AGENT_JAR)
|
||||||
|
.addToolArg(Agent.class.getName().replace('.', File.separatorChar) + ".class");
|
||||||
|
|
||||||
ProcessBuilder pb = new ProcessBuilder();
|
ProcessBuilder pb = new ProcessBuilder(jar.getCommand());
|
||||||
pb.command(new String[] { JDKToolFinder.getJDKTool("jar"), "cmf", "MANIFEST.MF",
|
try {
|
||||||
System.getProperty("test.classes",".") + "/agent.jar",
|
OutputAnalyzer output = new OutputAnalyzer(pb.start());
|
||||||
"compiler/profiling/spectrapredefineclass/Agent.class".replace('/', File.separatorChar)});
|
output.shouldHaveExitValue(0);
|
||||||
pb.start().waitFor();
|
} catch (IOException ex) {
|
||||||
|
throw new Error("TESTBUG: jar failed.", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
package compiler.profiling.spectrapredefineclass_classloaders;
|
package compiler.profiling.spectrapredefineclass_classloaders;
|
||||||
|
|
||||||
import com.sun.tools.attach.VirtualMachine;
|
import com.sun.tools.attach.VirtualMachine;
|
||||||
|
import jdk.test.lib.Utils;
|
||||||
|
|
||||||
import java.lang.instrument.ClassFileTransformer;
|
import java.lang.instrument.ClassFileTransformer;
|
||||||
import java.lang.instrument.Instrumentation;
|
import java.lang.instrument.Instrumentation;
|
||||||
@ -32,14 +33,16 @@ import java.lang.reflect.Method;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.security.ProtectionDomain;
|
import java.security.ProtectionDomain;
|
||||||
|
|
||||||
public class Agent implements ClassFileTransformer {
|
public class Agent implements ClassFileTransformer {
|
||||||
|
public static final String AGENT_JAR = Paths.get(Utils.TEST_CLASSES, "agent.jar").toString();
|
||||||
public static ClassLoader newClassLoader() {
|
public static ClassLoader newClassLoader() {
|
||||||
try {
|
try {
|
||||||
return new URLClassLoader(new URL[] {
|
return new URLClassLoader(new URL[] {
|
||||||
Paths.get(System.getProperty("test.classes",".")).toUri().toURL(),
|
Paths.get(Utils.TEST_CLASSES).toUri().toURL(),
|
||||||
}, null);
|
}, null);
|
||||||
} catch (MalformedURLException e){
|
} catch (MalformedURLException e){
|
||||||
throw new RuntimeException("Unexpected URL conversion failure", e);
|
throw new RuntimeException("Unexpected URL conversion failure", e);
|
||||||
@ -76,7 +79,7 @@ public class Agent implements ClassFileTransformer {
|
|||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
try {
|
try {
|
||||||
VirtualMachine vm = VirtualMachine.attach(pid);
|
VirtualMachine vm = VirtualMachine.attach(pid);
|
||||||
vm.loadAgent(System.getProperty("test.classes",".") + "/agent.jar", "");
|
vm.loadAgent(AGENT_JAR, "");
|
||||||
vm.detach();
|
vm.detach();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -39,26 +39,36 @@
|
|||||||
* -XX:ReservedCodeCacheSize=3M
|
* -XX:ReservedCodeCacheSize=3M
|
||||||
* compiler.profiling.spectrapredefineclass_classloaders.Agent
|
* compiler.profiling.spectrapredefineclass_classloaders.Agent
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package compiler.profiling.spectrapredefineclass_classloaders;
|
package compiler.profiling.spectrapredefineclass_classloaders;
|
||||||
|
|
||||||
import jdk.test.lib.JDKToolFinder;
|
import jdk.test.lib.JDKToolLauncher;
|
||||||
|
import jdk.test.lib.OutputAnalyzer;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
public class Launcher {
|
public class Launcher {
|
||||||
public static void main(String[] args) throws Exception {
|
private static final String MANIFEST = "MANIFEST.MF";
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
try (PrintWriter pw = new PrintWriter(MANIFEST)) {
|
||||||
|
pw.println("Agent-Class: " + Agent.class.getName());
|
||||||
|
pw.println("Can-Retransform-Classes: true");
|
||||||
|
}
|
||||||
|
|
||||||
PrintWriter pw = new PrintWriter("MANIFEST.MF");
|
JDKToolLauncher jar = JDKToolLauncher.create("jar")
|
||||||
|
.addToolArg("cmf")
|
||||||
|
.addToolArg(MANIFEST)
|
||||||
|
.addToolArg(Agent.AGENT_JAR)
|
||||||
|
.addToolArg(Agent.class.getName().replace('.', File.separatorChar) + ".class");
|
||||||
|
|
||||||
pw.println("Agent-Class: " + Launcher.class.getPackage().getName() + ".Agent");
|
ProcessBuilder pb = new ProcessBuilder(jar.getCommand());
|
||||||
pw.println("Can-Retransform-Classes: true");
|
try {
|
||||||
pw.close();
|
OutputAnalyzer output = new OutputAnalyzer(pb.start());
|
||||||
|
output.shouldHaveExitValue(0);
|
||||||
ProcessBuilder pb = new ProcessBuilder();
|
} catch (IOException ex) {
|
||||||
pb.command(new String[]{JDKToolFinder.getJDKTool("jar"), "cmf", "MANIFEST.MF",
|
throw new Error("TESTBUG: jar failed.", ex);
|
||||||
System.getProperty("test.classes", ".") + "/agent.jar",
|
}
|
||||||
"compiler/profiling/spectrapredefineclass/Agent.class".replace('/', File.separatorChar)});
|
|
||||||
pb.start().waitFor();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user