Skip to content

Commit

Permalink
8315406: [REDO] serviceability/jdwp/AllModulesCommandTest.java ignore…
Browse files Browse the repository at this point in the history
…s VM flags

Reviewed-by: cjplummer, dcubed
  • Loading branch information
lmesnik committed Sep 6, 2023
1 parent 7a08e6b commit 5cbff24
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023, 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
Expand Down Expand Up @@ -72,12 +72,6 @@ public void onDebuggeeSendingCompleted() {
jdwpLatch.countDown();
}

@Override
public void onDebuggeeError(String message) {
System.err.println("Debuggee error: '" + message + "'");
System.exit(1);
}

private void doJdwp() throws Exception {
try {
// Establish JDWP socket connection
Expand Down
60 changes: 10 additions & 50 deletions test/hotspot/jtreg/serviceability/jdwp/DebuggeeLauncher.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023, 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
Expand All @@ -22,9 +22,9 @@
*/

import java.util.StringTokenizer;
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.JDWP;
import static jdk.test.lib.Asserts.assertFalse;
import jdk.test.lib.process.ProcessTools;

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

/**
* Callback to handle any debuggee error
*
* @param line line from the debuggee's stderr
*/
void onDebuggeeError(String line);
}

private int jdwpPort = -1;
private static final String CLS_DIR = System.getProperty("test.classes", "").trim();
private static final String DEBUGGEE = "AllModulesCommandTestDebuggee";
private static final String JDWP_OPT = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0";

private Process p;
private final Listener listener;
private StreamHandler inputHandler;
private StreamHandler errorHandler;

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

/**
* Starts the debuggee with the necessary JDWP options and handles the
* debuggee's stdout and stderr outputs
* debuggee's stdout output. stderr might contain jvm output, which is just printed to the log.
*
* @throws Throwable
*/
public void launchDebuggee() throws Throwable {

ProcessBuilder pb = new ProcessBuilder(getCommand());
ProcessBuilder pb = ProcessTools.createTestJvm(JDWP_OPT, DEBUGGEE);
p = pb.start();
inputHandler = new StreamHandler(p.getInputStream(), this);
errorHandler = new StreamHandler(p.getErrorStream(), this);
StreamHandler inputHandler = new StreamHandler(p.getInputStream(), this);
StreamHandler errorHandler = new StreamHandler(p.getErrorStream(), l -> System.out.println("[stderr]: " + l));
inputHandler.start();
errorHandler.start();
}

/**
* Command to start the debuggee with the JDWP options and using the JDK
* under test
*
* @return the command
*/
private String[] getCommand() {
return new String[]{
JDKToolFinder.getTestJDKTool("java"),
getJdwpOptions(),
"-cp",
CLS_DIR,
DEBUGGEE
};
}

/**
* Terminates the debuggee
*/
Expand All @@ -109,15 +86,6 @@ public void terminateDebuggee() {
}
}

/**
* Debuggee JDWP options
*
* @return the JDWP options to start the debuggee with
*/
private static String getJdwpOptions() {
return "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0";
}

/**
* Gets JDWP port debuggee is listening on.
*
Expand All @@ -129,16 +97,8 @@ public int getJdwpPort() {
}

@Override
public void onStringRead(StreamHandler handler, String line) {
if (handler.equals(errorHandler)) {
terminateDebuggee();
listener.onDebuggeeError(line);
} else {
processDebuggeeOutput(line);
}
}

private void processDebuggeeOutput(String line) {
public void onStringRead(String line) {
System.out.println("[stdout]: " + line);
if (jdwpPort == -1) {
JDWP.ListenAddress addr = JDWP.parseListenAddress(line);
if (addr != null) {
Expand Down
5 changes: 2 additions & 3 deletions test/hotspot/jtreg/serviceability/jdwp/StreamHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ public class StreamHandler implements Runnable {
public interface Listener {
/**
* Called when a line has been read from the process output stream
* @param handler this StreamHandler
* @param s the line
*/
void onStringRead(StreamHandler handler, String s);
void onStringRead(String s);
}

private final ExecutorService executor;
Expand Down Expand Up @@ -71,7 +70,7 @@ public void run() {
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = br.readLine()) != null) {
listener.onStringRead(this, line);
listener.onStringRead(line);
}
} catch (Exception x) {
throw new RuntimeException(x);
Expand Down

5 comments on commit 5cbff24

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 5cbff24 Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 5cbff24 Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin the backport was successfully created on the branch backport-GoeLin-5cbff246 in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 5cbff246 from the openjdk/jdk repository.

The commit being backported was authored by Leonid Mesnik on 6 Sep 2023 and was reviewed by Chris Plummer and Daniel D. Daugherty.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-GoeLin-5cbff246:backport-GoeLin-5cbff246
$ git checkout backport-GoeLin-5cbff246
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-GoeLin-5cbff246

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 5cbff24 Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 5cbff24 Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin the backport was successfully created on the branch backport-GoeLin-5cbff246-master in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 5cbff246 from the openjdk/jdk repository.

The commit being backported was authored by Leonid Mesnik on 6 Sep 2023 and was reviewed by Chris Plummer and Daniel D. Daugherty.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev.git backport-GoeLin-5cbff246-master:backport-GoeLin-5cbff246-master
$ git checkout backport-GoeLin-5cbff246-master
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev.git backport-GoeLin-5cbff246-master

Please sign in to comment.