Skip to content

Commit

Permalink
Merge pull request ibmruntimes#51 from JasonFengJ9/delayattach
Browse files Browse the repository at this point in the history
Ensure AttachAPI initialized  before starting attaching tests
  • Loading branch information
pshipton authored Oct 3, 2023
2 parents ac53f88 + 09c1c4d commit 9e4783d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 12 additions & 0 deletions test/jdk/com/sun/tools/attach/warnings/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@
* questions.
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2023, 2023 All Rights Reserved
* ===========================================================================
*/

import java.io.DataOutputStream;
import java.net.InetAddress;
import java.net.Socket;

import openj9.internal.tools.attach.target.AttachHandler;

/**
* The "application" launched by DyamicLoadWarningTest.
*
Expand All @@ -39,6 +47,10 @@ public static void main(String[] args) throws Exception {

// send pid
long pid = ProcessHandle.current().pid();
while (!AttachHandler.isAttachApiInitialized()) {
// delay 2s to allow AttachAPI initialization
Thread.currentThread().sleep(100);
}
out.writeLong(pid);

// wait for shutdown
Expand Down
12 changes: 10 additions & 2 deletions test/jdk/com/sun/tools/attach/warnings/DynamicLoadWarningTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@
* questions.
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2023, 2023 All Rights Reserved
* ===========================================================================
*/

/*
* @test
* @bug 8307478
* @summary Test that a warning is printed when an agent is dynamically loaded
* @requires vm.jvmti
* @modules jdk.attach jdk.jcmd
* @library /test/lib /test/jdk
* @build Application JavaAgent
* @build JavaAgent
* @compile --add-exports java.base/openj9.internal.tools.attach.target=ALL-UNNAMED Application.java
* @run junit/othervm/native DynamicLoadWarningTest
*/

Expand Down Expand Up @@ -272,7 +279,8 @@ OutputAnalyzer run() throws Exception {

// launch application with the given VM options, waiting for it to terminate
Stream<String> s1 = Stream.of(vmopts);
Stream<String> s2 = Stream.of("Application", Integer.toString(listener.getLocalPort()));
String addExports = "--add-exports=java.base/openj9.internal.tools.attach.target=ALL-UNNAMED";
Stream<String> s2 = Stream.of(addExports, "Application", Integer.toString(listener.getLocalPort()));
String[] opts = Stream.concat(s1, s2).toArray(String[]::new);
OutputAnalyzer outputAnalyzer = ProcessTools
.executeTestJava(opts)
Expand Down

0 comments on commit 9e4783d

Please sign in to comment.