< prev index next >

test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/HelloDynamic.java

Print this page

        

@@ -30,10 +30,14 @@
  * @build Hello
  * @run driver ClassFileInstaller -jar hello.jar Hello
  * @run driver HelloDynamic
  */
 
+import java.io.IOException;
+import java.net.ServerSocket;
+import jtreg.SkippedException;
+
 public class HelloDynamic extends DynamicArchiveTestBase {
     public static void main(String[] args) throws Exception {
         runTest(HelloDynamic::testDefaultBase);
         runTest(HelloDynamic::testCustomBase);
     }

@@ -50,10 +54,34 @@
         String baseArchiveName = getNewArchiveName("base");
         dumpBaseArchive(baseArchiveName);
         doTest(baseArchiveName, topArchiveName);
     }
 
+    private static int jdwpPort = -1;
+
+    private static String getJdwpOptions() throws Exception {
+        return "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=" + getJdwpPort();
+    }
+
+    public static int getJdwpPort() throws Exception {
+        if (jdwpPort == -1) {
+            jdwpPort = findFreePort();
+            if (jdwpPort == -1) {
+                throw new SkippedException("Can not find available port for JDWP");
+            }
+        }
+        return jdwpPort;
+    }
+
+    private static int findFreePort() {
+        try (ServerSocket socket = new ServerSocket(0)) {
+            return socket.getLocalPort();
+        } catch (IOException e) {
+        }
+        return -1;
+    }
+
     private static void doTest(String baseArchiveName, String topArchiveName) throws Exception {
         String appJar = ClassFileInstaller.getJarPath("hello.jar");
         String mainClass = "Hello";
         dump2(baseArchiveName, topArchiveName,
              "-Xlog:cds",

@@ -69,7 +97,21 @@
             "-cp", appJar, mainClass)
             .assertNormalExit(output -> {
                     output.shouldContain("Hello source: shared objects file")
                           .shouldHaveExitValue(0);
                 });
+
+        // Sanity test with JDWP options.
+        // Test with the default base archive should be sufficient.
+        if (baseArchiveName == null) {
+            run2(baseArchiveName, topArchiveName,
+                getJdwpOptions(),
+                "-Xlog:class+load",
+                "-Xlog:cds+dynamic=debug,cds=debug",
+                "-cp", appJar, mainClass)
+                .assertNormalExit(output -> {
+                    output.shouldContain("Hello source: shared objects file")
+                          .shouldHaveExitValue(0);
+                    });
+        }
     }
 }
< prev index next >