1 /*
2 * Copyright (c) 1997, 2018, 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 *
1030 // The stackSize field is only present starting in 1.4
1031 if (_stackSize_offset > 0) {
1032 assert(JDK_Version::is_gte_jdk14x_version(), "sanity check");
1033 return java_thread->long_field(_stackSize_offset);
1034 } else {
1035 return 0;
1036 }
1037 }
1038
1039 // Write the thread status value to threadStatus field in java.lang.Thread java class.
1040 void java_lang_Thread::set_thread_status(oop java_thread,
1041 java_lang_Thread::ThreadStatus status) {
1042 // The threadStatus is only present starting in 1.5
1043 if (_thread_status_offset > 0) {
1044 java_thread->int_field_put(_thread_status_offset, status);
1045 }
1046 }
1047
1048 // Read thread status value from threadStatus field in java.lang.Thread java class.
1049 java_lang_Thread::ThreadStatus java_lang_Thread::get_thread_status(oop java_thread) {
1050 assert(Thread::current()->is_Watcher_thread() || Thread::current()->is_VM_thread() ||
1051 JavaThread::current()->thread_state() == _thread_in_vm,
1052 "Java Thread is not running in vm");
1053 // The threadStatus is only present starting in 1.5
1054 if (_thread_status_offset > 0) {
1055 return (java_lang_Thread::ThreadStatus)java_thread->int_field(_thread_status_offset);
1056 } else {
1057 // All we can easily figure out is if it is alive, but that is
1058 // enough info for a valid unknown status.
1059 // These aren't restricted to valid set ThreadStatus values, so
1060 // use JVMTI values and cast.
1061 JavaThread* thr = java_lang_Thread::thread(java_thread);
1062 if (thr == NULL) {
1063 // the thread hasn't run yet or is in the process of exiting
1064 return NEW;
1065 }
1066 return (java_lang_Thread::ThreadStatus)JVMTI_THREAD_STATE_ALIVE;
1067 }
1068 }
1069
1070
|
1 /*
2 * Copyright (c) 1997, 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 *
1030 // The stackSize field is only present starting in 1.4
1031 if (_stackSize_offset > 0) {
1032 assert(JDK_Version::is_gte_jdk14x_version(), "sanity check");
1033 return java_thread->long_field(_stackSize_offset);
1034 } else {
1035 return 0;
1036 }
1037 }
1038
1039 // Write the thread status value to threadStatus field in java.lang.Thread java class.
1040 void java_lang_Thread::set_thread_status(oop java_thread,
1041 java_lang_Thread::ThreadStatus status) {
1042 // The threadStatus is only present starting in 1.5
1043 if (_thread_status_offset > 0) {
1044 java_thread->int_field_put(_thread_status_offset, status);
1045 }
1046 }
1047
1048 // Read thread status value from threadStatus field in java.lang.Thread java class.
1049 java_lang_Thread::ThreadStatus java_lang_Thread::get_thread_status(oop java_thread) {
1050 assert((EnableJFR && Threads_lock->owned_by_self()) || Thread::current()->is_Watcher_thread() || Thread::current()->is_VM_thread() ||
1051 JavaThread::current()->thread_state() == _thread_in_vm,
1052 "Java Thread is not running in vm");
1053 // The threadStatus is only present starting in 1.5
1054 if (_thread_status_offset > 0) {
1055 return (java_lang_Thread::ThreadStatus)java_thread->int_field(_thread_status_offset);
1056 } else {
1057 // All we can easily figure out is if it is alive, but that is
1058 // enough info for a valid unknown status.
1059 // These aren't restricted to valid set ThreadStatus values, so
1060 // use JVMTI values and cast.
1061 JavaThread* thr = java_lang_Thread::thread(java_thread);
1062 if (thr == NULL) {
1063 // the thread hasn't run yet or is in the process of exiting
1064 return NEW;
1065 }
1066 return (java_lang_Thread::ThreadStatus)JVMTI_THREAD_STATE_ALIVE;
1067 }
1068 }
1069
1070
|