Skip to content

Commit

Permalink
8209595: MonitorVmStartTerminate.java timed out
Browse files Browse the repository at this point in the history
Reviewed-by: sspitsyn, cjplummer, lmesnik
  • Loading branch information
kevinjwalls committed Oct 20, 2023
1 parent 2121575 commit a045258
Showing 1 changed file with 41 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public static void main(String... args) throws Exception {
System.out.println("Waiting for all processes to get started notification");
listener.started.acquire(PROCESS_COUNT);

System.out.println("Terminating all processes");
for (JavaProcess javaProcess : javaProcesses) {
javaProcess.terminate();
}
Expand Down Expand Up @@ -138,7 +139,7 @@ public void disconnected(HostEvent arg0) {
}

private void releaseStarted(Set<Integer> ids) {
System.out.println("realeaseStarted(" + ids + ")");
System.out.println("releaseStarted(" + ids + ")");
for (Integer id : ids) {
releaseStarted(id);
}
Expand All @@ -149,11 +150,12 @@ private void releaseStarted(Integer id) {
if (hasMainArgs(id, jp.getMainArgsIdentifier())) {
// store id for terminated identification
jp.setId(id);
System.out.println("RELEASED (id=" + jp.getId() + ", args=" + jp.getMainArgsIdentifier() + ")");
System.out.println("RELEASED started (id=" + jp.getId() + ", args=" + jp.getMainArgsIdentifier() + ")");
started.release();
return;
}
}
System.out.println("releaseStarted: not a test pid: " + id);
}

private void releaseTerminated(Set<Integer> ids) {
Expand All @@ -166,23 +168,44 @@ private void releaseTerminated(Set<Integer> ids) {
private void releaseTerminated(Integer id) {
for (JavaProcess jp : processes) {
if (id.equals(jp.getId())) {
System.out.println("RELEASED (id=" + jp.getId() + ", args=" + jp.getMainArgsIdentifier() + ")");
System.out.println("RELEASED terminated (id=" + jp.getId() + ", args=" + jp.getMainArgsIdentifier() + ")");
terminated.release();
return;
}
}
}

private static final int ARGS_ATTEMPTS = 3;

private boolean hasMainArgs(Integer id, String args) {
VmIdentifier vmid = null;
try {
VmIdentifier vmid = new VmIdentifier("//" + id.intValue());
MonitoredVm target = host.getMonitoredVm(vmid);
String monitoredArgs = MonitoredVmUtil.mainArgs(target);
if (monitoredArgs != null && monitoredArgs.contains(args)) {
return true;
vmid = new VmIdentifier("//" + id.intValue());
} catch (URISyntaxException e) {
System.out.println("hasMainArgs(" + id + "): " + e);
return false;
}
// Retry a failing attempt to check arguments for a match,
// as not recognizing a test process will cause timeout and failure.
for (int i = 0; i < ARGS_ATTEMPTS; i++) {
try {
MonitoredVm target = host.getMonitoredVm(vmid);
String monitoredArgs = MonitoredVmUtil.mainArgs(target);
System.out.println("hasMainArgs(" + id + "): has main args: '" + monitoredArgs + "'");
if (monitoredArgs == null || monitoredArgs.equals("Unknown")) {
System.out.println("hasMainArgs(" + id + "): retry" );
takeNap();
continue;
} else if (monitoredArgs.contains(args)) {
return true;
} else {
return false;
}
} catch (MonitorException e) {
// Process probably not running or not ours, e.g.
// sun.jvmstat.monitor.MonitorException: Could not attach to PID
System.out.println("hasMainArgs(" + id + "): " + e);
}
} catch (URISyntaxException | MonitorException e) {
// ok. process probably not running
}
return false;
}
Expand Down Expand Up @@ -247,14 +270,6 @@ private static void waitForRemoval(Path path) {
}
}

private static void takeNap() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// ignore
}
}

private final String mainArgsIdentifier;
private final ShutdownHook shutdownHook;
private volatile Integer id;
Expand Down Expand Up @@ -322,4 +337,12 @@ public String getMainArgsIdentifier() {
return mainArgsIdentifier;
}
}

public static void takeNap() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// ignore
}
}
}

3 comments on commit a045258

@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 a045258 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 a045258 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-a045258a 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 a045258a from the openjdk/jdk repository.

The commit being backported was authored by Kevin Walls on 20 Oct 2023 and was reviewed by Serguei Spitsyn, Chris Plummer and Leonid Mesnik.

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-a045258a:backport-GoeLin-a045258a
$ git checkout backport-GoeLin-a045258a
# 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-a045258a

Please sign in to comment.