test/runtime/SharedArchiveFile/SASymbolTableTest.java

Print this page


   1 /*
   2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  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  * @library /test/lib
  28  * @modules java.base/jdk.internal.misc
  29  *          jdk.hotspot.agent/sun.jvm.hotspot.oops
  30  *          jdk.hotspot.agent/sun.jvm.hotspot.memory
  31  *          jdk.hotspot.agent/sun.jvm.hotspot.runtime
  32  *          jdk.hotspot.agent/sun.jvm.hotspot.tools
  33  *          java.management
  34  * @build SASymbolTableTestAgent
  35  * @run main SASymbolTableTest
  36  */
  37 
  38 import java.util.Arrays;
  39 import java.util.List;

  40 import jdk.test.lib.process.ProcessTools;
  41 import jdk.test.lib.process.OutputAnalyzer;
  42 import jdk.test.lib.JDKToolFinder;
  43 import jdk.test.lib.Platform;
  44 import jdk.test.lib.apps.LingeredApp;
  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     private static LingeredApp theApp = null;
  57 

  58     public static void main(String[] args) throws Exception {
  59         if (!Platform.shouldSAAttach()) {
  60             System.out.println("SA attach not expected to work - test skipped.");
  61             return;
  62         }
  63         createArchive();

  64         run(true);
  65         run(false);
  66     }
  67 
  68     private static void createArchive()  throws Exception {
  69         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  70             "-XX:+UnlockDiagnosticVMOptions",
  71             "-XX:SharedArchiveFile=" + jsaName,
  72             "-Xshare:dump");
  73 
  74         OutputAnalyzer output = new OutputAnalyzer(pb.start());
  75         output.shouldContain("Loading classes to share");
  76         output.shouldHaveExitValue(0);
  77     }
  78 
  79     private static void run(boolean useArchive) throws Exception {
  80         String flag = useArchive ? "auto" : "off";
  81 
  82         try {
  83             // (1) Launch the attachee process
  84             System.out.println("Starting LingeredApp");
  85             List<String> vmOpts = Arrays.asList(
  86                     "-XX:+UnlockDiagnosticVMOptions",
  87                     "-XX:SharedArchiveFile=" + jsaName,
  88                     "-Xshare:" + flag,
  89                     "-showversion");                // so we can see "sharing" in the output
  90 
  91             theApp = LingeredApp.startApp(vmOpts);
  92 
  93             // (2) Launch the agent process
  94             long pid = theApp.getPid();
  95             System.out.println("Attaching agent to " + pid );
  96             ProcessBuilder tool = ProcessTools.createJavaProcessBuilder(
  97                     "--add-modules=jdk.hotspot.agent",


   1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  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  * @library /test/lib
  28  * @modules java.base/jdk.internal.misc
  29  *          jdk.hotspot.agent/sun.jvm.hotspot.oops
  30  *          jdk.hotspot.agent/sun.jvm.hotspot.memory
  31  *          jdk.hotspot.agent/sun.jvm.hotspot.runtime
  32  *          jdk.hotspot.agent/sun.jvm.hotspot.tools
  33  *          java.management
  34  * @build SASymbolTableTestAgent
  35  * @run main SASymbolTableTest
  36  */
  37 
  38 import java.util.Arrays;
  39 import java.util.List;
  40 import jdk.test.lib.cds.CDSTestUtils;
  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 import jdk.test.lib.apps.LingeredApp;
  46 
  47 /*
  48  * The purpose of this test is to validate that we can use SA to
  49  * attach a process and walk its SymbolTable, regardless whether
  50  * the attachee process runs in CDS mode or not.
  51  *
  52  * SASymbolTableTest Just sets up the agent and attachee processes.
  53  * The SymbolTable walking is done in the SASymbolTableTestAgent class.
  54  */
  55 public class SASymbolTableTest {
  56     static String jsaName = "./SASymbolTableTest.jsa";
  57     private static LingeredApp theApp = null;
  58 
  59 
  60     public static void main(String[] args) throws Exception {
  61         if (!Platform.shouldSAAttach()) {
  62             System.out.println("SA attach not expected to work - test skipped.");
  63             return;
  64         }
  65 
  66         CDSTestUtils.createArchiveAndCheck();
  67         run(true);
  68         run(false);
  69     }
  70 










  71 
  72     private static void run(boolean useArchive) throws Exception {
  73         String flag = useArchive ? "auto" : "off";
  74 
  75         try {
  76             // (1) Launch the attachee process
  77             System.out.println("Starting LingeredApp");
  78             List<String> vmOpts = Arrays.asList(
  79                     "-XX:+UnlockDiagnosticVMOptions",
  80                     "-XX:SharedArchiveFile=" + jsaName,
  81                     "-Xshare:" + flag,
  82                     "-showversion");                // so we can see "sharing" in the output
  83 
  84             theApp = LingeredApp.startApp(vmOpts);
  85 
  86             // (2) Launch the agent process
  87             long pid = theApp.getPid();
  88             System.out.println("Attaching agent to " + pid );
  89             ProcessBuilder tool = ProcessTools.createJavaProcessBuilder(
  90                     "--add-modules=jdk.hotspot.agent",