1 /*
   2  * Copyright (c) 2014, 2019, 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
  26  * @bug 8059510
  27  * @summary Test jcmd VM.symboltable, VM.stringtable and VM.systemdictionary options
  28  * @library /test/lib
  29  * @run main/othervm -XX:+UnlockDiagnosticVMOptions DumpSymbolAndStringTable
  30  */
  31 import jdk.test.lib.cds.CDSTestUtils;
  32 import jdk.test.lib.process.ProcessTools;
  33 import jdk.test.lib.process.OutputAnalyzer;
  34 import jdk.test.lib.JDKToolFinder;
  35 
  36 public class DumpSymbolAndStringTable {
  37     private static final String my_string = "DumpSymbolAndStringTable";
  38     public static void main(String[] args) throws Exception {
  39         // Grab my own PID
  40         String pid = Long.toString(ProcessTools.getProcessId());
  41 
  42         ProcessBuilder pb = new ProcessBuilder();
  43         pb.command(new String[] {JDKToolFinder.getJDKTool("jcmd"), pid, "VM.symboltable", "-verbose"});
  44         OutputAnalyzer output = CDSTestUtils.executeAndLog(pb, "jcmd-symboltable");
  45         try {
  46             output.shouldContain("24 2: DumpSymbolAndStringTable\n");
  47         } catch (RuntimeException e) {
  48             output.shouldContain("Unknown diagnostic command");
  49         }
  50 
  51         pb.command(new String[] {JDKToolFinder.getJDKTool("jcmd"), pid, "VM.stringtable", "-verbose"});
  52         output = CDSTestUtils.executeAndLog(pb, "jcmd-stringtable");
  53         try {
  54             output.shouldContain("24: DumpSymbolAndStringTable");
  55         } catch (RuntimeException e) {
  56             output.shouldContain("Unknown diagnostic command");
  57         }
  58 
  59         pb.command(new String[] {JDKToolFinder.getJDKTool("jcmd"), pid, "VM.systemdictionary"});
  60         output = CDSTestUtils.executeAndLog(pb, "jcmd-systemdictionary");
  61         try {
  62             output.shouldContain("System Dictionary for 'app' class loader statistics:");
  63             output.shouldContain("Number of buckets");
  64             output.shouldContain("Number of entries");
  65             output.shouldContain("Maximum bucket size");
  66         } catch (RuntimeException e) {
  67             output.shouldContain("Unknown diagnostic command");
  68         }
  69 
  70         pb.command(new String[] {JDKToolFinder.getJDKTool("jcmd"), pid, "VM.systemdictionary", "-verbose"});
  71         output = CDSTestUtils.executeAndLog(pb, "jcmd-systemdictionary");
  72         try {
  73             output.shouldContain("Dictionary for loader data: 0x");
  74             output.shouldContain("^java.lang.String");
  75         } catch (RuntimeException e) {
  76             output.shouldContain("Unknown diagnostic command");
  77         }
  78     }
  79 }