Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/GetOwnedMonitorStackDepthInfo/GetOwnedMonitorStackDepthInfoTest.java
41153 views
/*1* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/222324/**25* @test26* @bug 815362927* @summary Need to cover JVMTI's GetOwnedMonitorStackDepthInfo function28* @requires vm.jvmti29* @compile GetOwnedMonitorStackDepthInfoTest.java30* @run main/othervm/native -agentlib:GetOwnedMonitorStackDepthInfoTest GetOwnedMonitorStackDepthInfoTest31*/323334public class GetOwnedMonitorStackDepthInfoTest {3536static {37try {38System.loadLibrary("GetOwnedMonitorStackDepthInfoTest");39} catch (UnsatisfiedLinkError ule) {40System.err.println("Could not load GetOwnedMonitorStackDepthInfoTest library");41System.err.println("java.library.path: "42+ System.getProperty("java.library.path"));43throw ule;44}45}4647private static native int verifyOwnedMonitors();4849private static volatile int results = -1;505152public static void main(String[] args) throws Exception {5354new GetOwnedMonitorStackDepthInfoTest().runTest();5556}5758public void runTest() throws Exception {59final Object lock1 = new Lock1();60Thread t1 = new Thread(() -> {61synchronized (lock1) {62System.out.println("Thread in sync section 1: "63+ Thread.currentThread().getName());64test1();65}66});6768t1.start();69t1.join();7071if (results != 0) {72throw new RuntimeException("FAILED status returned from the agent");73}7475}7677private synchronized void test1() {78test2();79}8081private void test2() {82Object lock2 = new Lock2();83synchronized (lock2) {84System.out.println("Thread in sync section 2: "85+ Thread.currentThread().getName());86results = verifyOwnedMonitors();87}8889}9091private static class Lock1 {9293}9495private static class Lock2 {9697}98}99100101102