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