Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/GetOwnedMonitorInfo/GetOwnedMonitorInfoTest.java
41155 views
/*1* Copyright (c) 2017, 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 818516427* @summary Checks that a contended monitor does not show up in the list of owned monitors28* @requires vm.jvmti29* @compile GetOwnedMonitorInfoTest.java30* @run main/othervm/native -agentlib:GetOwnedMonitorInfoTest GetOwnedMonitorInfoTest31*/3233import java.io.PrintStream;3435public class GetOwnedMonitorInfoTest {3637static {38try {39System.loadLibrary("GetOwnedMonitorInfoTest");40} catch (UnsatisfiedLinkError ule) {41System.err.println("Could not load GetOwnedMonitorInfoTest library");42System.err.println("java.library.path: "43+ System.getProperty("java.library.path"));44throw ule;45}46}4748private static native int check();49private static native boolean hasEventPosted();5051public static void main(String[] args) throws Exception {52final GetOwnedMonitorInfoTest lock = new GetOwnedMonitorInfoTest();5354Thread t1 = new Thread(() -> {55synchronized (lock) {56System.out.println("Thread in sync section: "57+ Thread.currentThread().getName());58}59});6061// Make sure t1 contends on the monitor.62synchronized (lock) {63System.out.println("Main starting worker thread.");64t1.start();6566// Wait for the MonitorContendedEnter event67while (!hasEventPosted()) {68System.out.println("Main waiting for event.");69Thread.sleep(100);70}71}7273t1.join();7475if (check() != 0) {76throw new RuntimeException("FAILED status returned from the agent");77}78}79}808182