< prev index next >

test/runtime/SharedArchiveFile/SASymbolTableTest.java

Print this page




  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test SASymbolTableTest
  26  * @summary Walk symbol table using SA, with and without CDS.
  27  * Started failing on 2016.06.24 due to 8160376 on MacOS X so quarantine
  28  * it on that platform:
  29  * @requires os.family != "mac"
  30  * @library /test/lib
  31  * @modules java.base/jdk.internal.misc
  32  *          jdk.hotspot.agent/sun.jvm.hotspot.oops
  33  *          jdk.hotspot.agent/sun.jvm.hotspot.memory
  34  *          jdk.hotspot.agent/sun.jvm.hotspot.runtime
  35  *          jdk.hotspot.agent/sun.jvm.hotspot.tools
  36  *          java.management
  37  * @build SASymbolTableTestAgent SASymbolTableTestAttachee
  38  * @run main SASymbolTableTest
  39  */
  40 


  41 import jdk.test.lib.process.ProcessTools;
  42 import jdk.test.lib.process.OutputAnalyzer;
  43 import jdk.test.lib.JDKToolFinder;
  44 import jdk.test.lib.Platform;

  45 
  46 /*
  47  * The purpose of this test is to validate that we can use SA to
  48  * attach a process and walk its SymbolTable, regardless whether
  49  * the attachee process runs in CDS mode or not.
  50  *
  51  * SASymbolTableTest Just sets up the agent and attachee processes.
  52  * The SymbolTable walking is done in the SASymbolTableTestAgent class.
  53  */
  54 public class SASymbolTableTest {
  55     static String jsaName = "./SASymbolTableTest.jsa";

  56 
  57     public static void main(String[] args) throws Exception {
  58         if (!Platform.shouldSAAttach()) {
  59             System.out.println("SA attach not expected to work - test skipped.");
  60             return;
  61         }
  62         createArchive();
  63         run(true);
  64         run(false);
  65     }
  66 
  67     private static void createArchive()  throws Exception {
  68         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  69             "-XX:+UnlockDiagnosticVMOptions",
  70             "-XX:SharedArchiveFile=" + jsaName,
  71             "-Xshare:dump");
  72 
  73         OutputAnalyzer output = new OutputAnalyzer(pb.start());
  74         output.shouldContain("Loading classes to share");
  75         output.shouldHaveExitValue(0);
  76     }
  77 
  78     private static void run(boolean useArchive) throws Exception {
  79         String flag = useArchive ? "auto" : "off";
  80 

  81         // (1) Launch the attachee process
  82         ProcessBuilder attachee = ProcessTools.createJavaProcessBuilder(

  83             "-XX:+UnlockDiagnosticVMOptions",
  84             "-XX:SharedArchiveFile=" + jsaName,
  85             "-Xshare:" + flag,
  86             "-showversion",                // so we can see "sharing" in the output
  87             "SASymbolTableTestAttachee");
  88 
  89         final Process p = attachee.start();
  90 
  91         // (2) Launch the agent process
  92         long pid = p.getPid();
  93         System.out.println("Attaching agent " + pid);
  94         ProcessBuilder tool = ProcessTools.createJavaProcessBuilder(
  95             "--add-modules=jdk.hotspot.agent",
  96             "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.oops=ALL-UNNAMED",
  97             "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.memory=ALL-UNNAMED",
  98             "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.runtime=ALL-UNNAMED",
  99             "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.tools=ALL-UNNAMED",
 100             "SASymbolTableTestAgent",
 101             Long.toString(pid));
 102         OutputAnalyzer output = ProcessTools.executeProcess(tool);
 103         System.out.println(output.getOutput());
 104         output.shouldHaveExitValue(0);
 105 
 106         Thread t = new Thread() {
 107                 public void run() {
 108                     try {
 109                         OutputAnalyzer output = new OutputAnalyzer(p);
 110                         System.out.println("STDOUT[");
 111                         System.out.print(output.getStdout());




 112                         System.out.println("]");
 113                         System.out.println("STDERR[");
 114                         System.out.print(output.getStderr());
 115                         System.out.println("]");
 116                     } catch (Throwable t) {
 117                         t.printStackTrace();
 118                     }


 119                 }
 120             };
 121         t.start();
 122 
 123         Thread.sleep(2 * 1000);
 124         p.destroy();
 125         t.join();
 126     }
 127 }


  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test SASymbolTableTest
  26  * @summary Walk symbol table using SA, with and without CDS.
  27  * Started failing on 2016.06.24 due to 8160376 on MacOS X so quarantine
  28  * it on that platform:
  29  * @requires os.family != "mac"
  30  * @library /test/lib
  31  * @modules java.base/jdk.internal.misc
  32  *          jdk.hotspot.agent/sun.jvm.hotspot.oops
  33  *          jdk.hotspot.agent/sun.jvm.hotspot.memory
  34  *          jdk.hotspot.agent/sun.jvm.hotspot.runtime
  35  *          jdk.hotspot.agent/sun.jvm.hotspot.tools
  36  *          java.management
  37  * @build SASymbolTableTestAgent
  38  * @run main SASymbolTableTest
  39  */
  40 
  41 import java.util.Arrays;
  42 import java.util.List;
  43 import jdk.test.lib.process.ProcessTools;
  44 import jdk.test.lib.process.OutputAnalyzer;
  45 import jdk.test.lib.JDKToolFinder;
  46 import jdk.test.lib.Platform;
  47 import jdk.test.lib.apps.LingeredApp;
  48 
  49 /*
  50  * The purpose of this test is to validate that we can use SA to
  51  * attach a process and walk its SymbolTable, regardless whether
  52  * the attachee process runs in CDS mode or not.
  53  *
  54  * SASymbolTableTest Just sets up the agent and attachee processes.
  55  * The SymbolTable walking is done in the SASymbolTableTestAgent class.
  56  */
  57 public class SASymbolTableTest {
  58     static String jsaName = "./SASymbolTableTest.jsa";
  59     private static LingeredApp theApp = null;
  60 
  61     public static void main(String[] args) throws Exception {
  62         if (!Platform.shouldSAAttach()) {
  63             System.out.println("SA attach not expected to work - test skipped.");
  64             return;
  65         }
  66         createArchive();
  67         run(true);
  68         run(false);
  69     }
  70 
  71     private static void createArchive()  throws Exception {
  72         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  73             "-XX:+UnlockDiagnosticVMOptions",
  74             "-XX:SharedArchiveFile=" + jsaName,
  75             "-Xshare:dump");
  76 
  77         OutputAnalyzer output = new OutputAnalyzer(pb.start());
  78         output.shouldContain("Loading classes to share");
  79         output.shouldHaveExitValue(0);
  80     }
  81 
  82     private static void run(boolean useArchive) throws Exception {
  83         String flag = useArchive ? "auto" : "off";
  84 
  85         try {
  86             // (1) Launch the attachee process
  87             System.out.println("Starting LingeredApp");
  88             List<String> vmOpts = Arrays.asList(
  89                     "-XX:+UnlockDiagnosticVMOptions",
  90                     "-XX:SharedArchiveFile=" + jsaName,
  91                     "-Xshare:" + flag,
  92                     "-showversion");                // so we can see "sharing" in the output

  93 
  94             theApp = LingeredApp.startApp(vmOpts);
  95 
  96             // (2) Launch the agent process
  97             long pid = theApp.getPid();
  98             System.out.println("Attaching agent to " + pid );
  99             ProcessBuilder tool = ProcessTools.createJavaProcessBuilder(
 100                     "--add-modules=jdk.hotspot.agent",
 101                     "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.oops=ALL-UNNAMED",
 102                     "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.memory=ALL-UNNAMED",
 103                     "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.runtime=ALL-UNNAMED",
 104                     "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.tools=ALL-UNNAMED",
 105                     "SASymbolTableTestAgent",
 106                     Long.toString(pid));
 107             OutputAnalyzer output = ProcessTools.executeProcess(tool);







 108             System.out.println("STDOUT[");
 109             System.out.println(output.getOutput());
 110             if (output.getStdout().contains("connected too early")) {
 111                 System.out.println("SymbolTable not created by VM - test skipped");
 112                 return;
 113             }
 114             System.out.println("]");
 115             System.out.println("STDERR[");
 116             System.out.print(output.getStderr());
 117             System.out.println("]");
 118             output.shouldHaveExitValue(0);
 119         } catch (Exception ex) {
 120             throw new RuntimeException("Test ERROR " + ex, ex);
 121         } finally {
 122             LingeredApp.stopApp(theApp);
 123         }






 124     }
 125 }
< prev index next >