1 /*
2 * Copyright (c) 2003, 2013, 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 *
1003 if (owning_thread != NULL) {
1004 // The monitor's owner either has to be the current thread, at safepoint
1005 // or it has to be suspended. Any of these conditions will prevent both
1006 // contending and waiting threads from modifying the state of
1007 // the monitor.
1008 if (!at_safepoint && !JvmtiEnv::is_thread_fully_suspended(owning_thread, true, &debug_bits)) {
1009 // Don't worry! This return of JVMTI_ERROR_THREAD_NOT_SUSPENDED
1010 // will not make it back to the JVM/TI agent. The error code will
1011 // get intercepted in JvmtiEnv::GetObjectMonitorUsage() which
1012 // will retry the call via a VM_GetObjectMonitorUsage VM op.
1013 return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
1014 }
1015 HandleMark hm;
1016 Handle th(owning_thread->threadObj());
1017 ret.owner = (jthread)jni_reference(calling_thread, th);
1018 }
1019 // implied else: no owner
1020 }
1021
1022 if (owning_thread != NULL) { // monitor is owned
1023 if ((address)owning_thread == owner) {
1024 // the owner field is the JavaThread *
1025 assert(mon != NULL,
1026 "must have heavyweight monitor with JavaThread * owner");
1027 ret.entry_count = mon->recursions() + 1;
1028 } else {
1029 // The owner field is the Lock word on the JavaThread's stack
1030 // so the recursions field is not valid. We have to count the
1031 // number of recursive monitor entries the hard way. We pass
1032 // a handle to survive any GCs along the way.
1033 ResourceMark rm;
1034 ret.entry_count = count_locked_objects(owning_thread, hobj);
1035 }
1036 }
1037 // implied else: entry_count == 0
1038 }
1039
1040 int nWant,nWait;
1041 if (mon != NULL) {
1042 // this object has a heavyweight monitor
1043 nWant = mon->contentions(); // # of threads contending for monitor
1044 nWait = mon->waiters(); // # of threads in Object.wait()
1045 ret.waiter_count = nWant + nWait;
1046 ret.notify_waiter_count = nWait;
1047 } else {
1048 // this object has a lightweight monitor
1049 ret.waiter_count = 0;
1050 ret.notify_waiter_count = 0;
1051 }
1052
1053 // Allocate memory for heavyweight and lightweight monitor.
1054 jvmtiError err;
1055 err = allocate(ret.waiter_count * sizeof(jthread *), (unsigned char**)&ret.waiters);
|
1 /*
2 * Copyright (c) 2003, 2014, 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 *
1003 if (owning_thread != NULL) {
1004 // The monitor's owner either has to be the current thread, at safepoint
1005 // or it has to be suspended. Any of these conditions will prevent both
1006 // contending and waiting threads from modifying the state of
1007 // the monitor.
1008 if (!at_safepoint && !JvmtiEnv::is_thread_fully_suspended(owning_thread, true, &debug_bits)) {
1009 // Don't worry! This return of JVMTI_ERROR_THREAD_NOT_SUSPENDED
1010 // will not make it back to the JVM/TI agent. The error code will
1011 // get intercepted in JvmtiEnv::GetObjectMonitorUsage() which
1012 // will retry the call via a VM_GetObjectMonitorUsage VM op.
1013 return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
1014 }
1015 HandleMark hm;
1016 Handle th(owning_thread->threadObj());
1017 ret.owner = (jthread)jni_reference(calling_thread, th);
1018 }
1019 // implied else: no owner
1020 }
1021
1022 if (owning_thread != NULL) { // monitor is owned
1023 // The recursions field of a monitor does not reflect recursions
1024 // as lightweight locks before inflating the monitor are not included.
1025 // We have to count the number of recursive monitor entries the hard way.
1026 // We pass a handle to survive any GCs along the way.
1027 ResourceMark rm;
1028 ret.entry_count = count_locked_objects(owning_thread, hobj);
1029 }
1030 // implied else: entry_count == 0
1031 }
1032
1033 int nWant,nWait;
1034 if (mon != NULL) {
1035 // this object has a heavyweight monitor
1036 nWant = mon->contentions(); // # of threads contending for monitor
1037 nWait = mon->waiters(); // # of threads in Object.wait()
1038 ret.waiter_count = nWant + nWait;
1039 ret.notify_waiter_count = nWait;
1040 } else {
1041 // this object has a lightweight monitor
1042 ret.waiter_count = 0;
1043 ret.notify_waiter_count = 0;
1044 }
1045
1046 // Allocate memory for heavyweight and lightweight monitor.
1047 jvmtiError err;
1048 err = allocate(ret.waiter_count * sizeof(jthread *), (unsigned char**)&ret.waiters);
|