test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackLock.java
changeset 48113 af9e4669ca18
child 48178 88ec5fca7726
equal deleted inserted replaced
48112:a3d565e72f51 48113:af9e4669ca18
       
     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 import java.io.IOException;
       
    25 import java.io.OutputStream;
       
    26 import java.util.ArrayList;
       
    27 import java.util.List;
       
    28 import jdk.test.lib.apps.LingeredApp;
       
    29 import jdk.test.lib.Asserts;
       
    30 import jdk.test.lib.JDKToolLauncher;
       
    31 import jdk.test.lib.Platform;
       
    32 import jdk.test.lib.process.OutputAnalyzer;
       
    33 import jdk.test.lib.process.ProcessTools;
       
    34 import jdk.test.lib.Utils;
       
    35 
       
    36 /*
       
    37  * @test
       
    38  * @library /test/lib
       
    39  * @run main/othervm TestJhsdbJstackLock
       
    40  */
       
    41 
       
    42 public class TestJhsdbJstackLock {
       
    43 
       
    44     public static void main (String... args) throws Exception {
       
    45 
       
    46         LingeredApp app = null;
       
    47 
       
    48         if (!Platform.shouldSAAttach()) {
       
    49             System.out.println("SA attach not expected to work - test skipped.");
       
    50             return;
       
    51         }
       
    52 
       
    53         try {
       
    54             List<String> vmArgs = new ArrayList<String>(Utils.getVmOptions());
       
    55 
       
    56             app = new LingeredAppWithLock();
       
    57             LingeredApp.startApp(vmArgs, app);
       
    58             System.out.println ("Started LingeredApp with pid " + app.getPid());
       
    59 
       
    60             JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
       
    61             launcher.addToolArg("jstack");
       
    62             launcher.addToolArg("--pid");
       
    63             launcher.addToolArg(Long.toString(app.getPid()));
       
    64 
       
    65             ProcessBuilder pb = new ProcessBuilder();
       
    66             pb.command(launcher.getCommand());
       
    67             Process jhsdb = pb.start();
       
    68 
       
    69             jhsdb.waitFor();
       
    70 
       
    71             OutputAnalyzer out = new OutputAnalyzer(jhsdb);
       
    72             System.out.println(out.getStdout());
       
    73             System.err.println(out.getStderr());
       
    74 
       
    75             out.shouldMatch("^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Class for LingeredAppWithLock\\)$");
       
    76             out.shouldMatch("^\\s+- waiting to lock <0x[0-9a-f]+> \\(a java\\.lang\\.Class for LingeredAppWithLock\\)$");
       
    77             out.shouldMatch("^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Thread\\)$");
       
    78             out.shouldMatch("^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Class for int\\)$");
       
    79             out.stderrShouldBeEmpty();
       
    80 
       
    81             System.out.println("Test Completed");
       
    82         } finally {
       
    83             LingeredApp.stopApp(app);
       
    84         }
       
    85     }
       
    86 }