2017-08-07 19:34:21 +00:00
|
|
|
/*
|
2023-04-11 05:49:54 +00:00
|
|
|
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
|
2017-08-07 19:34:21 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
2023-11-30 09:46:26 +00:00
|
|
|
* @bug 8185164 8320515
|
|
|
|
* @summary Checks that a contended monitor does not show up in the list of owned monitors.
|
|
|
|
* 8320515 piggy-backs on this test and injects an owned monitor with a dead object,
|
|
|
|
and checks that that monitor isn't exposed to GetOwnedMonitorInfo.
|
2020-08-21 22:49:09 +00:00
|
|
|
* @requires vm.jvmti
|
2023-04-11 05:49:54 +00:00
|
|
|
* @compile GetOwnedMonitorInfoTest.java
|
|
|
|
* @run main/othervm/native -agentlib:GetOwnedMonitorInfoTest GetOwnedMonitorInfoTest
|
2017-08-07 19:34:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import java.io.PrintStream;
|
|
|
|
|
|
|
|
public class GetOwnedMonitorInfoTest {
|
|
|
|
|
|
|
|
static {
|
|
|
|
try {
|
|
|
|
System.loadLibrary("GetOwnedMonitorInfoTest");
|
|
|
|
} catch (UnsatisfiedLinkError ule) {
|
|
|
|
System.err.println("Could not load GetOwnedMonitorInfoTest library");
|
|
|
|
System.err.println("java.library.path: "
|
|
|
|
+ System.getProperty("java.library.path"));
|
|
|
|
throw ule;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-30 09:46:26 +00:00
|
|
|
private static native void jniMonitorEnter(Object obj);
|
2017-08-07 19:34:21 +00:00
|
|
|
private static native int check();
|
|
|
|
private static native boolean hasEventPosted();
|
|
|
|
|
2023-11-30 09:46:26 +00:00
|
|
|
private static void jniMonitorEnterAndLetObjectDie() {
|
|
|
|
// The monitor iterator used by GetOwnedMonitorInfo used to
|
|
|
|
// assert when an owned monitor with a dead object was found.
|
|
|
|
// Inject this situation into this test that performs other
|
|
|
|
// GetOwnedMonitorInfo testing.
|
|
|
|
Object obj = new Object() {};
|
|
|
|
jniMonitorEnter(obj);
|
|
|
|
if (!Thread.holdsLock(obj)) {
|
|
|
|
throw new RuntimeException("The object is not locked");
|
|
|
|
}
|
|
|
|
obj = null;
|
|
|
|
System.gc();
|
|
|
|
}
|
|
|
|
|
2017-08-07 19:34:21 +00:00
|
|
|
public static void main(String[] args) throws Exception {
|
2023-11-30 09:46:26 +00:00
|
|
|
runTest(true, true);
|
|
|
|
runTest(true, false);
|
|
|
|
runTest(false, true);
|
|
|
|
runTest(false, false);
|
8284161: Implementation of Virtual Threads (Preview)
Co-authored-by: Ron Pressler <rpressler@openjdk.org>
Co-authored-by: Alan Bateman <alanb@openjdk.org>
Co-authored-by: Erik Österlund <eosterlund@openjdk.org>
Co-authored-by: Andrew Haley <aph@openjdk.org>
Co-authored-by: Rickard Bäckman <rbackman@openjdk.org>
Co-authored-by: Markus Grönlund <mgronlun@openjdk.org>
Co-authored-by: Leonid Mesnik <lmesnik@openjdk.org>
Co-authored-by: Serguei Spitsyn <sspitsyn@openjdk.org>
Co-authored-by: Chris Plummer <cjplummer@openjdk.org>
Co-authored-by: Coleen Phillimore <coleenp@openjdk.org>
Co-authored-by: Robbin Ehn <rehn@openjdk.org>
Co-authored-by: Stefan Karlsson <stefank@openjdk.org>
Co-authored-by: Thomas Schatzl <tschatzl@openjdk.org>
Co-authored-by: Sergey Kuksenko <skuksenko@openjdk.org>
Reviewed-by: lancea, eosterlund, rehn, sspitsyn, stefank, tschatzl, dfuchs, lmesnik, dcubed, kevinw, amenkov, dlong, mchung, psandoz, bpb, coleenp, smarks, egahlin, mseledtsov, coffeys, darcy
2022-05-07 08:06:16 +00:00
|
|
|
}
|
|
|
|
|
2023-11-30 09:46:26 +00:00
|
|
|
public static void runTest(boolean isVirtual, boolean jni) throws Exception {
|
8284161: Implementation of Virtual Threads (Preview)
Co-authored-by: Ron Pressler <rpressler@openjdk.org>
Co-authored-by: Alan Bateman <alanb@openjdk.org>
Co-authored-by: Erik Österlund <eosterlund@openjdk.org>
Co-authored-by: Andrew Haley <aph@openjdk.org>
Co-authored-by: Rickard Bäckman <rbackman@openjdk.org>
Co-authored-by: Markus Grönlund <mgronlun@openjdk.org>
Co-authored-by: Leonid Mesnik <lmesnik@openjdk.org>
Co-authored-by: Serguei Spitsyn <sspitsyn@openjdk.org>
Co-authored-by: Chris Plummer <cjplummer@openjdk.org>
Co-authored-by: Coleen Phillimore <coleenp@openjdk.org>
Co-authored-by: Robbin Ehn <rehn@openjdk.org>
Co-authored-by: Stefan Karlsson <stefank@openjdk.org>
Co-authored-by: Thomas Schatzl <tschatzl@openjdk.org>
Co-authored-by: Sergey Kuksenko <skuksenko@openjdk.org>
Reviewed-by: lancea, eosterlund, rehn, sspitsyn, stefank, tschatzl, dfuchs, lmesnik, dcubed, kevinw, amenkov, dlong, mchung, psandoz, bpb, coleenp, smarks, egahlin, mseledtsov, coffeys, darcy
2022-05-07 08:06:16 +00:00
|
|
|
var threadFactory = isVirtual ? Thread.ofVirtual().factory() : Thread.ofPlatform().factory();
|
2017-08-07 19:34:21 +00:00
|
|
|
final GetOwnedMonitorInfoTest lock = new GetOwnedMonitorInfoTest();
|
|
|
|
|
8284161: Implementation of Virtual Threads (Preview)
Co-authored-by: Ron Pressler <rpressler@openjdk.org>
Co-authored-by: Alan Bateman <alanb@openjdk.org>
Co-authored-by: Erik Österlund <eosterlund@openjdk.org>
Co-authored-by: Andrew Haley <aph@openjdk.org>
Co-authored-by: Rickard Bäckman <rbackman@openjdk.org>
Co-authored-by: Markus Grönlund <mgronlun@openjdk.org>
Co-authored-by: Leonid Mesnik <lmesnik@openjdk.org>
Co-authored-by: Serguei Spitsyn <sspitsyn@openjdk.org>
Co-authored-by: Chris Plummer <cjplummer@openjdk.org>
Co-authored-by: Coleen Phillimore <coleenp@openjdk.org>
Co-authored-by: Robbin Ehn <rehn@openjdk.org>
Co-authored-by: Stefan Karlsson <stefank@openjdk.org>
Co-authored-by: Thomas Schatzl <tschatzl@openjdk.org>
Co-authored-by: Sergey Kuksenko <skuksenko@openjdk.org>
Reviewed-by: lancea, eosterlund, rehn, sspitsyn, stefank, tschatzl, dfuchs, lmesnik, dcubed, kevinw, amenkov, dlong, mchung, psandoz, bpb, coleenp, smarks, egahlin, mseledtsov, coffeys, darcy
2022-05-07 08:06:16 +00:00
|
|
|
Thread t1 = threadFactory.newThread(() -> {
|
2023-11-30 09:46:26 +00:00
|
|
|
Thread.currentThread().setName("Worker-Thread");
|
|
|
|
|
|
|
|
if (jni) {
|
|
|
|
jniMonitorEnterAndLetObjectDie();
|
|
|
|
}
|
|
|
|
|
2017-08-07 19:34:21 +00:00
|
|
|
synchronized (lock) {
|
|
|
|
System.out.println("Thread in sync section: "
|
|
|
|
+ Thread.currentThread().getName());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Make sure t1 contends on the monitor.
|
|
|
|
synchronized (lock) {
|
|
|
|
System.out.println("Main starting worker thread.");
|
|
|
|
t1.start();
|
|
|
|
|
|
|
|
// Wait for the MonitorContendedEnter event
|
|
|
|
while (!hasEventPosted()) {
|
|
|
|
System.out.println("Main waiting for event.");
|
|
|
|
Thread.sleep(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t1.join();
|
|
|
|
|
|
|
|
if (check() != 0) {
|
|
|
|
throw new RuntimeException("FAILED status returned from the agent");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|