Skip to content

Commit 4369856

Browse files
committed
8333130: MakeJAR2.sh uses hard-coded JDK version
Reviewed-by: lancea, darcy, sspitsyn, amenkov
1 parent 1f09467 commit 4369856

File tree

5 files changed

+132
-145
lines changed

5 files changed

+132
-145
lines changed

test/jdk/java/lang/instrument/MakeJAR2.sh

Lines changed: 0 additions & 105 deletions
This file was deleted.

test/jdk/java/lang/instrument/NativeMethodPrefixAgent.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,20 +21,6 @@
2121
* questions.
2222
*/
2323

24-
/*
25-
* @test
26-
* @bug 6263319
27-
* @requires ((vm.opt.StartFlightRecording == null) | (vm.opt.StartFlightRecording == false)) & ((vm.opt.FlightRecorder == null) | (vm.opt.FlightRecorder == false))
28-
* @summary test setNativeMethodPrefix
29-
* @author Robert Field, Sun Microsystems
30-
*
31-
* @enablePreview
32-
* @modules java.management
33-
* java.instrument
34-
* @run shell/timeout=240 MakeJAR2.sh NativeMethodPrefixAgent NativeMethodPrefixApp 'Can-Retransform-Classes: true' 'Can-Set-Native-Method-Prefix: true'
35-
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:-CheckIntrinsics -javaagent:NativeMethodPrefixAgent.jar NativeMethodPrefixApp
36-
*/
37-
3824
import asmlib.Instrumentor;
3925

4026
import java.lang.constant.ClassDesc;

test/jdk/java/lang/instrument/NativeMethodPrefixApp.java

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,25 +22,87 @@
2222
*/
2323

2424

25-
import java.io.PrintStream;
26-
import java.util.*;
25+
import java.io.File;
26+
import java.nio.file.Path;
2727
import java.lang.management.*;
28+
2829
import bootreporter.*;
30+
import jdk.test.lib.helpers.ClassFileInstaller;
31+
import jdk.test.lib.process.OutputAnalyzer;
32+
import jdk.test.lib.process.ProcessTools;
2933

34+
/*
35+
* @test
36+
* @bug 6263319
37+
* @summary test setNativeMethodPrefix
38+
* @requires ((vm.opt.StartFlightRecording == null) | (vm.opt.StartFlightRecording == false)) & ((vm.opt.FlightRecorder == null) | (vm.opt.FlightRecorder == false))
39+
* @modules java.management
40+
* java.instrument
41+
* @library /test/lib
42+
* @build bootreporter.StringIdCallback bootreporter.StringIdCallbackReporter
43+
* asmlib.Instrumentor NativeMethodPrefixAgent
44+
* @enablePreview
45+
* @comment The test uses asmlib/Instrumentor.java which relies on ClassFile API PreviewFeature.
46+
* @run driver/timeout=240 NativeMethodPrefixApp roleDriver
47+
* @comment The test uses a higher timeout to prevent test timeouts noted in JDK-6528548
48+
*/
3049
public class NativeMethodPrefixApp implements StringIdCallback {
3150

3251
// This test is fragile like a golden file test.
3352
// It assumes that a specific non-native library method will call a specific
3453
// native method. The below may need to be updated based on library changes.
3554
static String goldenNativeMethodName = "getStartupTime";
3655

37-
static boolean gotIt[] = {false, false, false};
56+
static boolean[] gotIt = {false, false, false};
57+
58+
public static void main(String[] args) throws Exception {
59+
if (args.length == 1) {
60+
if (!"roleDriver".equals(args[0])) {
61+
throw new Exception("unexpected program argument: " + args[0]);
62+
}
63+
// launch the NativeMethodPrefixApp java process after creating the necessary
64+
// infrastructure
65+
System.out.println("creating agent jar");
66+
final Path agentJar = createAgentJar();
67+
System.out.println("launching app, with javaagent jar: " + agentJar);
68+
launchApp(agentJar);
69+
} else {
70+
System.err.println("running app");
71+
new NativeMethodPrefixApp().run();
72+
}
73+
}
74+
75+
private static Path createAgentJar() throws Exception {
76+
final String testClassesDir = System.getProperty("test.classes");
77+
final Path agentJar = Path.of("NativeMethodPrefixAgent.jar");
78+
final String manifest = """
79+
Manifest-Version: 1.0
80+
Premain-Class: NativeMethodPrefixAgent
81+
Can-Retransform-Classes: true
82+
Can-Set-Native-Method-Prefix: true
83+
"""
84+
+ "Boot-Class-Path: " + testClassesDir.replace(File.separatorChar, '/') + "/"
85+
+ "\n";
86+
System.out.println("Manifest is:\n" + manifest);
87+
// create the agent jar
88+
ClassFileInstaller.writeJar(agentJar.getFileName().toString(),
89+
ClassFileInstaller.Manifest.fromString(manifest),
90+
"NativeMethodPrefixAgent",
91+
"asmlib.Instrumentor");
92+
return agentJar;
93+
}
3894

39-
public static void main(String args[]) throws Exception {
40-
(new NativeMethodPrefixApp()).run(args, System.err);
95+
private static void launchApp(final Path agentJar) throws Exception {
96+
final OutputAnalyzer oa = ProcessTools.executeTestJava(
97+
"--enable-preview", // due to usage of ClassFile API PreviewFeature in the agent
98+
"-javaagent:" + agentJar.toString(),
99+
NativeMethodPrefixApp.class.getName());
100+
oa.shouldHaveExitValue(0);
101+
// make available stdout/stderr in the logs, even in case of successful completion
102+
oa.reportDiagnosticSummary();
41103
}
42104

43-
public void run(String args[], PrintStream out) throws Exception {
105+
private void run() throws Exception {
44106
StringIdCallbackReporter.registerCallback(this);
45107
System.err.println("start");
46108

@@ -57,6 +119,7 @@ public void run(String args[], PrintStream out) throws Exception {
57119
}
58120
}
59121

122+
@Override
60123
public void tracker(String name, int id) {
61124
if (name.endsWith(goldenNativeMethodName)) {
62125
System.err.println("Tracked #" + id + ": MATCHED -- " + name);

test/jdk/java/lang/instrument/RetransformAgent.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,18 +21,6 @@
2121
* questions.
2222
*/
2323

24-
/*
25-
* @test
26-
* @bug 6274264 6274241 5070281
27-
* @summary test retransformClasses
28-
* @author Robert Field, Sun Microsystems
29-
*
30-
* @enablePreview
31-
* @modules java.instrument
32-
* @run shell/timeout=240 MakeJAR2.sh RetransformAgent RetransformApp 'Can-Retransform-Classes: true'
33-
* @run main/othervm -javaagent:RetransformAgent.jar RetransformApp
34-
*/
35-
3624
import java.lang.constant.ClassDesc;
3725
import java.lang.constant.MethodTypeDesc;
3826
import java.lang.instrument.*;

test/jdk/java/lang/instrument/RetransformApp.java

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,19 +23,74 @@
2323

2424

2525
import java.io.PrintStream;
26-
import java.util.*;
26+
import java.nio.file.Path;
2727

28+
import jdk.test.lib.process.OutputAnalyzer;
29+
import jdk.test.lib.process.ProcessTools;
30+
import jdk.test.lib.helpers.ClassFileInstaller;
31+
32+
/*
33+
* @test
34+
* @bug 6274264 6274241 5070281
35+
* @summary test retransformClasses
36+
*
37+
* @modules java.instrument
38+
* @library /test/lib
39+
* @build RetransformAgent asmlib.Instrumentor
40+
* @enablePreview
41+
* @comment The test uses asmlib/Instrumentor.java which relies on ClassFile API PreviewFeature.
42+
* @run driver/timeout=240 RetransformApp roleDriver
43+
* @comment The test uses a higher timeout to prevent test timeouts noted in JDK-6528548
44+
*/
2845
public class RetransformApp {
2946

30-
public static void main(String args[]) throws Exception {
31-
(new RetransformApp()).run(args, System.out);
47+
public static void main(String[] args) throws Exception {
48+
if (args.length == 1) {
49+
if (!"roleDriver".equals(args[0])) {
50+
throw new Exception("unexpected program argument: " + args[0]);
51+
}
52+
// launch the RetransformApp java process after creating the necessary
53+
// infrastructure
54+
System.out.println("creating agent jar");
55+
final Path agentJar = createAgentJar();
56+
System.out.println("launching app, with javaagent jar: " + agentJar);
57+
launchApp(agentJar);
58+
} else {
59+
System.err.println("running app");
60+
new RetransformApp().run(System.out);
61+
}
62+
}
63+
64+
private static Path createAgentJar() throws Exception {
65+
Path agentJar = Path.of("RetransformAgent.jar");
66+
final String manifest = """
67+
Manifest-Version: 1.0
68+
Premain-Class: RetransformAgent
69+
Can-Retransform-Classes: true
70+
""";
71+
System.out.println("Manifest is:\n" + manifest);
72+
ClassFileInstaller.writeJar(agentJar.getFileName().toString(),
73+
ClassFileInstaller.Manifest.fromString(manifest),
74+
"RetransformAgent",
75+
"asmlib.Instrumentor");
76+
return agentJar;
77+
}
78+
79+
private static void launchApp(final Path agentJar) throws Exception {
80+
final OutputAnalyzer oa = ProcessTools.executeTestJava(
81+
"--enable-preview", // due to usage of ClassFile API PreviewFeature in the agent
82+
"-javaagent:" + agentJar.toString(),
83+
RetransformApp.class.getName());
84+
oa.shouldHaveExitValue(0);
85+
// make available stdout/stderr in the logs, even in case of successful completion
86+
oa.reportDiagnosticSummary();
3287
}
3388

3489
int foo(int x) {
3590
return x * x;
3691
}
3792

38-
public void run(String args[], PrintStream out) throws Exception {
93+
public void run(PrintStream out) throws Exception {
3994
out.println("start");
4095
for (int i = 0; i < 4; i++) {
4196
if (foo(3) != 9) {

0 commit comments

Comments
 (0)