Skip to content

Commit 5cbff24

Browse files
committed
8315406: [REDO] serviceability/jdwp/AllModulesCommandTest.java ignores VM flags
Reviewed-by: cjplummer, dcubed
1 parent 7a08e6b commit 5cbff24

File tree

3 files changed

+13
-60
lines changed

3 files changed

+13
-60
lines changed

test/hotspot/jtreg/serviceability/jdwp/AllModulesCommandTest.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2023, 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
@@ -72,12 +72,6 @@ public void onDebuggeeSendingCompleted() {
7272
jdwpLatch.countDown();
7373
}
7474

75-
@Override
76-
public void onDebuggeeError(String message) {
77-
System.err.println("Debuggee error: '" + message + "'");
78-
System.exit(1);
79-
}
80-
8175
private void doJdwp() throws Exception {
8276
try {
8377
// Establish JDWP socket connection

test/hotspot/jtreg/serviceability/jdwp/DebuggeeLauncher.java

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2023, 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,9 +22,9 @@
2222
*/
2323

2424
import java.util.StringTokenizer;
25-
import jdk.test.lib.JDKToolFinder;
2625
import jdk.test.lib.JDWP;
2726
import static jdk.test.lib.Asserts.assertFalse;
27+
import jdk.test.lib.process.ProcessTools;
2828

2929
/**
3030
* Launches the debuggee with the necessary JDWP options and handles the output
@@ -45,21 +45,14 @@ public interface Listener {
4545
*/
4646
void onDebuggeeSendingCompleted();
4747

48-
/**
49-
* Callback to handle any debuggee error
50-
*
51-
* @param line line from the debuggee's stderr
52-
*/
53-
void onDebuggeeError(String line);
5448
}
5549

5650
private int jdwpPort = -1;
57-
private static final String CLS_DIR = System.getProperty("test.classes", "").trim();
5851
private static final String DEBUGGEE = "AllModulesCommandTestDebuggee";
52+
private static final String JDWP_OPT = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0";
53+
5954
private Process p;
6055
private final Listener listener;
61-
private StreamHandler inputHandler;
62-
private StreamHandler errorHandler;
6356

6457
/**
6558
* @param listener the listener we report the debuggee events to
@@ -70,36 +63,20 @@ public DebuggeeLauncher(Listener listener) {
7063

7164
/**
7265
* Starts the debuggee with the necessary JDWP options and handles the
73-
* debuggee's stdout and stderr outputs
66+
* debuggee's stdout output. stderr might contain jvm output, which is just printed to the log.
7467
*
7568
* @throws Throwable
7669
*/
7770
public void launchDebuggee() throws Throwable {
7871

79-
ProcessBuilder pb = new ProcessBuilder(getCommand());
72+
ProcessBuilder pb = ProcessTools.createTestJvm(JDWP_OPT, DEBUGGEE);
8073
p = pb.start();
81-
inputHandler = new StreamHandler(p.getInputStream(), this);
82-
errorHandler = new StreamHandler(p.getErrorStream(), this);
74+
StreamHandler inputHandler = new StreamHandler(p.getInputStream(), this);
75+
StreamHandler errorHandler = new StreamHandler(p.getErrorStream(), l -> System.out.println("[stderr]: " + l));
8376
inputHandler.start();
8477
errorHandler.start();
8578
}
8679

87-
/**
88-
* Command to start the debuggee with the JDWP options and using the JDK
89-
* under test
90-
*
91-
* @return the command
92-
*/
93-
private String[] getCommand() {
94-
return new String[]{
95-
JDKToolFinder.getTestJDKTool("java"),
96-
getJdwpOptions(),
97-
"-cp",
98-
CLS_DIR,
99-
DEBUGGEE
100-
};
101-
}
102-
10380
/**
10481
* Terminates the debuggee
10582
*/
@@ -109,15 +86,6 @@ public void terminateDebuggee() {
10986
}
11087
}
11188

112-
/**
113-
* Debuggee JDWP options
114-
*
115-
* @return the JDWP options to start the debuggee with
116-
*/
117-
private static String getJdwpOptions() {
118-
return "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0";
119-
}
120-
12189
/**
12290
* Gets JDWP port debuggee is listening on.
12391
*
@@ -129,16 +97,8 @@ public int getJdwpPort() {
12997
}
13098

13199
@Override
132-
public void onStringRead(StreamHandler handler, String line) {
133-
if (handler.equals(errorHandler)) {
134-
terminateDebuggee();
135-
listener.onDebuggeeError(line);
136-
} else {
137-
processDebuggeeOutput(line);
138-
}
139-
}
140-
141-
private void processDebuggeeOutput(String line) {
100+
public void onStringRead(String line) {
101+
System.out.println("[stdout]: " + line);
142102
if (jdwpPort == -1) {
143103
JDWP.ListenAddress addr = JDWP.parseListenAddress(line);
144104
if (addr != null) {

test/hotspot/jtreg/serviceability/jdwp/StreamHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ public class StreamHandler implements Runnable {
3737
public interface Listener {
3838
/**
3939
* Called when a line has been read from the process output stream
40-
* @param handler this StreamHandler
4140
* @param s the line
4241
*/
43-
void onStringRead(StreamHandler handler, String s);
42+
void onStringRead(String s);
4443
}
4544

4645
private final ExecutorService executor;
@@ -71,7 +70,7 @@ public void run() {
7170
BufferedReader br = new BufferedReader(new InputStreamReader(is));
7271
String line;
7372
while ((line = br.readLine()) != null) {
74-
listener.onStringRead(this, line);
73+
listener.onStringRead(line);
7574
}
7675
} catch (Exception x) {
7776
throw new RuntimeException(x);

0 commit comments

Comments
 (0)