1 /*
2 * Copyright (c) 2000, 2016, 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 *
1238
1239 UNSAFE_ENTRY(void, Unsafe_Park(JNIEnv *env, jobject unsafe, jboolean isAbsolute, jlong time))
1240 UnsafeWrapper("Unsafe_Park");
1241 EventThreadPark event;
1242 #ifndef USDT2
1243 HS_DTRACE_PROBE3(hotspot, thread__park__begin, thread->parker(), (int) isAbsolute, time);
1244 #else /* USDT2 */
1245 HOTSPOT_THREAD_PARK_BEGIN(
1246 (uintptr_t) thread->parker(), (int) isAbsolute, time);
1247 #endif /* USDT2 */
1248 JavaThreadParkedState jtps(thread, time != 0);
1249 thread->parker()->park(isAbsolute != 0, time);
1250 #ifndef USDT2
1251 HS_DTRACE_PROBE1(hotspot, thread__park__end, thread->parker());
1252 #else /* USDT2 */
1253 HOTSPOT_THREAD_PARK_END(
1254 (uintptr_t) thread->parker());
1255 #endif /* USDT2 */
1256 if (event.should_commit()) {
1257 oop obj = thread->current_park_blocker();
1258 event.set_klass((obj != NULL) ? obj->klass() : NULL);
1259 event.set_timeout(time);
1260 event.set_address((obj != NULL) ? (TYPE_ADDRESS) cast_from_oop<uintptr_t>(obj) : 0);
1261 event.commit();
1262 }
1263 UNSAFE_END
1264
1265 UNSAFE_ENTRY(void, Unsafe_Unpark(JNIEnv *env, jobject unsafe, jobject jthread))
1266 UnsafeWrapper("Unsafe_Unpark");
1267 Parker* p = NULL;
1268 if (jthread != NULL) {
1269 oop java_thread = JNIHandles::resolve_non_null(jthread);
1270 if (java_thread != NULL) {
1271 jlong lp = java_lang_Thread::park_event(java_thread);
1272 if (lp != 0) {
1273 // This cast is OK even though the jlong might have been read
1274 // non-atomically on 32bit systems, since there, one word will
1275 // always be zero anyway and the value set is always the same
1276 p = (Parker*)addr_from_java(lp);
1277 } else {
1278 // Grab lock if apparently null or using older version of library
|
1 /*
2 * Copyright (c) 2000, 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 *
1238
1239 UNSAFE_ENTRY(void, Unsafe_Park(JNIEnv *env, jobject unsafe, jboolean isAbsolute, jlong time))
1240 UnsafeWrapper("Unsafe_Park");
1241 EventThreadPark event;
1242 #ifndef USDT2
1243 HS_DTRACE_PROBE3(hotspot, thread__park__begin, thread->parker(), (int) isAbsolute, time);
1244 #else /* USDT2 */
1245 HOTSPOT_THREAD_PARK_BEGIN(
1246 (uintptr_t) thread->parker(), (int) isAbsolute, time);
1247 #endif /* USDT2 */
1248 JavaThreadParkedState jtps(thread, time != 0);
1249 thread->parker()->park(isAbsolute != 0, time);
1250 #ifndef USDT2
1251 HS_DTRACE_PROBE1(hotspot, thread__park__end, thread->parker());
1252 #else /* USDT2 */
1253 HOTSPOT_THREAD_PARK_END(
1254 (uintptr_t) thread->parker());
1255 #endif /* USDT2 */
1256 if (event.should_commit()) {
1257 oop obj = thread->current_park_blocker();
1258 event.set_parkedClass((obj != NULL) ? obj->klass() : NULL);
1259 event.set_timeout(time);
1260 event.set_address((obj != NULL) ? (TYPE_ADDRESS) cast_from_oop<uintptr_t>(obj) : 0);
1261 event.commit();
1262 }
1263 UNSAFE_END
1264
1265 UNSAFE_ENTRY(void, Unsafe_Unpark(JNIEnv *env, jobject unsafe, jobject jthread))
1266 UnsafeWrapper("Unsafe_Unpark");
1267 Parker* p = NULL;
1268 if (jthread != NULL) {
1269 oop java_thread = JNIHandles::resolve_non_null(jthread);
1270 if (java_thread != NULL) {
1271 jlong lp = java_lang_Thread::park_event(java_thread);
1272 if (lp != 0) {
1273 // This cast is OK even though the jlong might have been read
1274 // non-atomically on 32bit systems, since there, one word will
1275 // always be zero anyway and the value set is always the same
1276 p = (Parker*)addr_from_java(lp);
1277 } else {
1278 // Grab lock if apparently null or using older version of library
|