src/share/vm/runtime/osThread.hpp

Thu, 10 May 2012 15:44:19 +0200

author
nloodin
date
Thu, 10 May 2012 15:44:19 +0200
changeset 3783
7432b9db36ff
parent 3709
0105f367a14c
child 3796
960a442eae91
permissions
-rw-r--r--

7165755: OS Information much longer on linux than other platforms
Reviewed-by: sla, dholmes

duke@435 1 /*
rbackman@3709 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_RUNTIME_OSTHREAD_HPP
stefank@2314 26 #define SHARE_VM_RUNTIME_OSTHREAD_HPP
stefank@2314 27
stefank@2314 28 #include "runtime/frame.hpp"
stefank@2314 29 #include "runtime/handles.hpp"
stefank@2314 30 #include "runtime/javaFrameAnchor.hpp"
stefank@2314 31 #include "runtime/objectMonitor.hpp"
stefank@2314 32 #include "utilities/top.hpp"
stefank@2314 33
duke@435 34 // The OSThread class holds OS-specific thread information. It is equivalent
duke@435 35 // to the sys_thread_t structure of the classic JVM implementation.
duke@435 36
duke@435 37 // The thread states represented by the ThreadState values are platform-specific
duke@435 38 // and are likely to be only approximate, because most OSes don't give you access
duke@435 39 // to precise thread state information.
duke@435 40
duke@435 41 // Note: the ThreadState is legacy code and is not correctly implemented.
duke@435 42 // Uses of ThreadState need to be replaced by the state in the JavaThread.
duke@435 43
duke@435 44 enum ThreadState {
duke@435 45 ALLOCATED, // Memory has been allocated but not initialized
duke@435 46 INITIALIZED, // The thread has been initialized but yet started
duke@435 47 RUNNABLE, // Has been started and is runnable, but not necessarily running
duke@435 48 MONITOR_WAIT, // Waiting on a contended monitor lock
duke@435 49 CONDVAR_WAIT, // Waiting on a condition variable
duke@435 50 OBJECT_WAIT, // Waiting on an Object.wait() call
duke@435 51 BREAKPOINTED, // Suspended at breakpoint
duke@435 52 SLEEPING, // Thread.sleep()
duke@435 53 ZOMBIE // All done, but not reclaimed yet
duke@435 54 };
duke@435 55
duke@435 56 // I'd make OSThread a ValueObj embedded in Thread to avoid an indirection, but
duke@435 57 // the assembler test in java.cpp expects that it can install the OSThread of
duke@435 58 // the main thread into its own Thread at will.
duke@435 59
duke@435 60
duke@435 61 class OSThread: public CHeapObj {
duke@435 62 friend class VMStructs;
duke@435 63 private:
duke@435 64 //void* _start_proc; // Thread start routine
duke@435 65 OSThreadStartFunc _start_proc; // Thread start routine
duke@435 66 void* _start_parm; // Thread start routine parameter
duke@435 67 volatile ThreadState _state; // Thread state *hint*
dholmes@2668 68 volatile jint _interrupted; // Thread.isInterrupted state
duke@435 69
duke@435 70 // Note: _interrupted must be jint, so that Java intrinsics can access it.
duke@435 71 // The value stored there must be either 0 or 1. It must be possible
duke@435 72 // for Java to emulate Thread.currentThread().isInterrupted() by performing
duke@435 73 // the double indirection Thread::current()->_osthread->_interrupted.
duke@435 74
duke@435 75 // Methods
duke@435 76 public:
duke@435 77 void set_state(ThreadState state) { _state = state; }
duke@435 78 ThreadState get_state() { return _state; }
duke@435 79
duke@435 80 // Constructor
duke@435 81 OSThread(OSThreadStartFunc start_proc, void* start_parm);
duke@435 82
duke@435 83 // Destructor
duke@435 84 ~OSThread();
duke@435 85
duke@435 86 // Accessors
duke@435 87 OSThreadStartFunc start_proc() const { return _start_proc; }
duke@435 88 void set_start_proc(OSThreadStartFunc start_proc) { _start_proc = start_proc; }
duke@435 89 void* start_parm() const { return _start_parm; }
duke@435 90 void set_start_parm(void* start_parm) { _start_parm = start_parm; }
duke@435 91
dholmes@2668 92 volatile bool interrupted() const { return _interrupted != 0; }
duke@435 93 void set_interrupted(bool z) { _interrupted = z ? 1 : 0; }
duke@435 94
duke@435 95 // Printing
duke@435 96 void print_on(outputStream* st) const;
duke@435 97 void print() const { print_on(tty); }
duke@435 98
duke@435 99 // For java intrinsics:
duke@435 100 static ByteSize interrupted_offset() { return byte_offset_of(OSThread, _interrupted); }
rbackman@3709 101 static ByteSize thread_id_offset() { return byte_offset_of(OSThread, _thread_id); }
duke@435 102
duke@435 103 // Platform dependent stuff
stefank@2314 104 #ifdef TARGET_OS_FAMILY_linux
stefank@2314 105 # include "osThread_linux.hpp"
stefank@2314 106 #endif
stefank@2314 107 #ifdef TARGET_OS_FAMILY_solaris
stefank@2314 108 # include "osThread_solaris.hpp"
stefank@2314 109 #endif
stefank@2314 110 #ifdef TARGET_OS_FAMILY_windows
stefank@2314 111 # include "osThread_windows.hpp"
stefank@2314 112 #endif
never@3156 113 #ifdef TARGET_OS_FAMILY_bsd
never@3156 114 # include "osThread_bsd.hpp"
never@3156 115 #endif
stefank@2314 116
duke@435 117 };
duke@435 118
duke@435 119
duke@435 120 // Utility class for use with condition variables:
duke@435 121 class OSThreadWaitState : public StackObj {
duke@435 122 OSThread* _osthread;
duke@435 123 ThreadState _old_state;
duke@435 124 public:
duke@435 125 OSThreadWaitState(OSThread* osthread, bool is_object_wait) {
duke@435 126 _osthread = osthread;
duke@435 127 _old_state = osthread->get_state();
duke@435 128 if (is_object_wait) {
duke@435 129 osthread->set_state(OBJECT_WAIT);
duke@435 130 } else {
duke@435 131 osthread->set_state(CONDVAR_WAIT);
duke@435 132 }
duke@435 133 }
duke@435 134 ~OSThreadWaitState() {
duke@435 135 _osthread->set_state(_old_state);
duke@435 136 }
duke@435 137 };
duke@435 138
duke@435 139
duke@435 140 // Utility class for use with contended monitors:
duke@435 141 class OSThreadContendState : public StackObj {
duke@435 142 OSThread* _osthread;
duke@435 143 ThreadState _old_state;
duke@435 144 public:
duke@435 145 OSThreadContendState(OSThread* osthread) {
duke@435 146 _osthread = osthread;
duke@435 147 _old_state = osthread->get_state();
duke@435 148 osthread->set_state(MONITOR_WAIT);
duke@435 149 }
duke@435 150 ~OSThreadContendState() {
duke@435 151 _osthread->set_state(_old_state);
duke@435 152 }
duke@435 153 };
stefank@2314 154
stefank@2314 155 #endif // SHARE_VM_RUNTIME_OSTHREAD_HPP

mercurial