8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE

Addition of  –XX:+UnlockDiagnosticVMOptions for the test invocation for jcmd and modularization related cleanup

Reviewed-by: dholmes, mchung
diff --git a/hotspot/test/serviceability/sa/TestInstanceKlassSize.java b/hotspot/test/serviceability/sa/TestInstanceKlassSize.java
index db1ed0f..dd8deda 100644
--- a/hotspot/test/serviceability/sa/TestInstanceKlassSize.java
+++ b/hotspot/test/serviceability/sa/TestInstanceKlassSize.java
@@ -23,6 +23,7 @@
 
 import sun.jvm.hotspot.HotSpotAgent;
 import sun.jvm.hotspot.utilities.SystemDictionaryHelper;
+import sun.jvm.hotspot.oops.InstanceKlass;
 import sun.jvm.hotspot.debugger.*;
 
 import java.util.ArrayList;
@@ -44,15 +45,19 @@
  * @test
  * @library /test/lib
  * @modules java.base/jdk.internal.misc
- * @modules jdk.hotspot.agent
- * @modules jdk.hotspot.agent/sun.jvm.hotspot
- * @modules jdk.hotspot.agent/sun.jvm.hotspot.utilities
- * @modules jdk.hotspot.agent/sun.jvm.hotspot.oops
- * @compile -XDignore.symbol.file=true -Xmodule:jdk.hotspot.agent
- *          -XaddExports:java.base/jdk.internal.misc=jdk.hotspot.agent
- *          -XaddExports:java.management/java.lang.management=jdk.hotspot.agent
+ * @compile -XDignore.symbol.file=true
+ *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED
+ *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot.utilities=ALL-UNNAMED
+ *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot.oops=ALL-UNNAMED
+ *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot.debugger=ALL-UNNAMED
  *          TestInstanceKlassSize.java
- * @run main/othervm  TestInstanceKlassSize
+ * @run main/othervm
+ *          --add-modules=jdk.hotspot.agent
+ *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED
+ *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot.utilities=ALL-UNNAMED
+ *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot.oops=ALL-UNNAMED
+ *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot.debugger=ALL-UNNAMED
+ *          TestInstanceKlassSize
  */
 
 public class TestInstanceKlassSize {
@@ -112,11 +117,11 @@
                                               " java.lang.Byte",
                                           };
             String[] toolArgs = {
-                "-XX:+UnlockDiagnosticVMOptions",
                 "--add-modules=jdk.hotspot.agent",
                 "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED",
                 "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.utilities=ALL-UNNAMED",
                 "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.oops=ALL-UNNAMED",
+                "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.debugger=ALL-UNNAMED",
                 "TestInstanceKlassSize",
                 Long.toString(app.getPid())
             };
@@ -136,6 +141,8 @@
                 String jcmdInstanceKlassSize = getJcmdInstanceKlassSize(
                                                       jcmdOutput,
                                                       instanceKlassName);
+                Asserts.assertNotNull(jcmdInstanceKlassSize,
+                    "Could not get the instance klass size from the jcmd output");
                 for (String s : output.asLines()) {
                     if (s.contains(instanceKlassName)) {
                        Asserts.assertTrue(
@@ -165,10 +172,12 @@
         }
 
         for (String SAInstanceKlassName : SAInstanceKlassNames) {
-            Long size = SystemDictionaryHelper.findInstanceKlass(
-                            SAInstanceKlassName).getSize();
+            InstanceKlass ik = SystemDictionaryHelper.findInstanceKlass(
+                               SAInstanceKlassName);
+            Asserts.assertNotNull(ik,
+                String.format("Unable to find instance klass for %s", ik));
             System.out.println("SA: The size of " + SAInstanceKlassName +
-                               " is " + size);
+                               " is " + ik.getSize());
         }
         agent.detach();
     }
diff --git a/hotspot/test/serviceability/sa/TestInstanceKlassSizeForInterface.java b/hotspot/test/serviceability/sa/TestInstanceKlassSizeForInterface.java
index 0c23373..0bd8bc3 100644
--- a/hotspot/test/serviceability/sa/TestInstanceKlassSizeForInterface.java
+++ b/hotspot/test/serviceability/sa/TestInstanceKlassSizeForInterface.java
@@ -38,15 +38,20 @@
  * @test
  * @library /test/lib
  * @modules java.base/jdk.internal.misc
- * @modules jdk.hotspot.agent
- * @modules jdk.hotspot.agent/sun.jvm.hotspot
- * @modules jdk.hotspot.agent/sun.jvm.hotspot.utilities
- * @modules jdk.hotspot.agent/sun.jvm.hotspot.oops
- * @compile -XDignore.symbol.file=true -Xmodule:jdk.hotspot.agent
- *          -XaddExports:java.base/jdk.internal.misc=jdk.hotspot.agent
- *          -XaddExports:java.management/java.lang.management=jdk.hotspot.agent
+ * @compile -XDignore.symbol.file=true
+ *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED
+ *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot.utilities=ALL-UNNAMED
+ *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot.oops=ALL-UNNAMED
+ *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot.debugger=ALL-UNNAMED
  *          TestInstanceKlassSizeForInterface.java
- * @run main/othervm TestInstanceKlassSizeForInterface
+ * @run main/othervm
+ *          -XX:+UnlockDiagnosticVMOptions
+ *          --add-modules=jdk.hotspot.agent
+ *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED
+ *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot.utilities=ALL-UNNAMED
+ *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot.oops=ALL-UNNAMED
+ *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot.debugger=ALL-UNNAMED
+ *          TestInstanceKlassSizeForInterface
  */
 
 interface Language {
@@ -80,6 +85,8 @@
         for (String instanceKlassName : instanceKlassNames) {
             InstanceKlass iKlass = SystemDictionaryHelper.findInstanceKlass(
                                        instanceKlassName);
+            Asserts.assertNotNull(iKlass,
+                String.format("Unable to find instance klass for %s", instanceKlassName));
             System.out.println("SA: The size of " + instanceKlassName +
                                " is " + iKlass.getSize());
         }
@@ -106,11 +113,11 @@
 
         // Grab the pid from the current java process and pass it
         String[] toolArgs = {
-            "-XX:+UnlockDiagnosticVMOptions",
             "--add-modules=jdk.hotspot.agent",
             "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED",
             "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.utilities=ALL-UNNAMED",
             "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.oops=ALL-UNNAMED",
+            "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.debugger=ALL-UNNAMED",
             "TestInstanceKlassSizeForInterface",
             Long.toString(ProcessTools.getProcessId())
         };
@@ -138,6 +145,8 @@
             String jcmdInstanceKlassSize = getJcmdInstanceKlassSize(
                                                       jcmdOutput,
                                                       instanceKlassName);
+            Asserts.assertNotNull(jcmdInstanceKlassSize,
+                "Could not get the instance klass size from the jcmd output");
             for (String s : SAOutput.asLines()) {
                 if (s.contains(instanceKlassName)) {
                    Asserts.assertTrue(
@@ -162,7 +171,7 @@
             return;
         }
 
-        if ( args == null || args.length == 0 ) {
+        if (args == null || args.length == 0) {
             ParselTongue lang = new ParselTongue();
 
             Language ventro = new Language() {