src/share/vm/runtime/osThread.hpp

Wed, 18 Sep 2013 07:02:10 -0700

author
dcubed
date
Wed, 18 Sep 2013 07:02:10 -0700
changeset 5743
63147986a428
parent 3900
d2a62e0f25eb
child 6461
bdd155477289
permissions
-rw-r--r--

8019835: Strings interned in different threads equal but does not ==
Summary: Add -XX:+VerifyStringTableAtExit option and code to verify StringTable invariants.
Reviewed-by: rdurbin, sspitsyn, coleenp

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
zgu@3900 61 class OSThread: public CHeapObj<mtThread> {
duke@435 62 friend class VMStructs;
duke@435 63 private:
duke@435 64 OSThreadStartFunc _start_proc; // Thread start routine
duke@435 65 void* _start_parm; // Thread start routine parameter
duke@435 66 volatile ThreadState _state; // Thread state *hint*
dholmes@2668 67 volatile jint _interrupted; // Thread.isInterrupted state
duke@435 68
duke@435 69 // Note: _interrupted must be jint, so that Java intrinsics can access it.
duke@435 70 // The value stored there must be either 0 or 1. It must be possible
duke@435 71 // for Java to emulate Thread.currentThread().isInterrupted() by performing
duke@435 72 // the double indirection Thread::current()->_osthread->_interrupted.
duke@435 73
duke@435 74 // Methods
duke@435 75 public:
duke@435 76 void set_state(ThreadState state) { _state = state; }
duke@435 77 ThreadState get_state() { return _state; }
duke@435 78
duke@435 79 OSThread(OSThreadStartFunc start_proc, void* start_parm);
duke@435 80 ~OSThread();
duke@435 81
duke@435 82 // Accessors
duke@435 83 OSThreadStartFunc start_proc() const { return _start_proc; }
duke@435 84 void set_start_proc(OSThreadStartFunc start_proc) { _start_proc = start_proc; }
duke@435 85 void* start_parm() const { return _start_parm; }
duke@435 86 void set_start_parm(void* start_parm) { _start_parm = start_parm; }
duke@435 87
dholmes@2668 88 volatile bool interrupted() const { return _interrupted != 0; }
duke@435 89 void set_interrupted(bool z) { _interrupted = z ? 1 : 0; }
duke@435 90
duke@435 91 // Printing
duke@435 92 void print_on(outputStream* st) const;
duke@435 93 void print() const { print_on(tty); }
duke@435 94
duke@435 95 // For java intrinsics:
duke@435 96 static ByteSize interrupted_offset() { return byte_offset_of(OSThread, _interrupted); }
duke@435 97
duke@435 98 // Platform dependent stuff
stefank@2314 99 #ifdef TARGET_OS_FAMILY_linux
stefank@2314 100 # include "osThread_linux.hpp"
stefank@2314 101 #endif
stefank@2314 102 #ifdef TARGET_OS_FAMILY_solaris
stefank@2314 103 # include "osThread_solaris.hpp"
stefank@2314 104 #endif
stefank@2314 105 #ifdef TARGET_OS_FAMILY_windows
stefank@2314 106 # include "osThread_windows.hpp"
stefank@2314 107 #endif
never@3156 108 #ifdef TARGET_OS_FAMILY_bsd
never@3156 109 # include "osThread_bsd.hpp"
never@3156 110 #endif
stefank@2314 111
rbackman@3796 112 public:
rbackman@3796 113 static ByteSize thread_id_offset() { return byte_offset_of(OSThread, _thread_id); }
rbackman@3796 114 static size_t thread_id_size() { return sizeof(thread_id_t); }
rbackman@3796 115
rbackman@3796 116 thread_id_t thread_id() const { return _thread_id; }
rbackman@3796 117
rbackman@3796 118 void set_thread_id(thread_id_t id) { _thread_id = id; }
rbackman@3796 119
rbackman@3796 120 private:
rbackman@3796 121 // _thread_id is kernel thread id (similar to LWP id on Solaris). Each
rbackman@3796 122 // thread has a unique thread_id (BsdThreads or NPTL). It can be used
rbackman@3796 123 // to access /proc.
rbackman@3796 124 thread_id_t _thread_id;
duke@435 125 };
duke@435 126
duke@435 127
duke@435 128 // Utility class for use with condition variables:
duke@435 129 class OSThreadWaitState : public StackObj {
duke@435 130 OSThread* _osthread;
duke@435 131 ThreadState _old_state;
duke@435 132 public:
duke@435 133 OSThreadWaitState(OSThread* osthread, bool is_object_wait) {
duke@435 134 _osthread = osthread;
duke@435 135 _old_state = osthread->get_state();
duke@435 136 if (is_object_wait) {
duke@435 137 osthread->set_state(OBJECT_WAIT);
duke@435 138 } else {
duke@435 139 osthread->set_state(CONDVAR_WAIT);
duke@435 140 }
duke@435 141 }
duke@435 142 ~OSThreadWaitState() {
duke@435 143 _osthread->set_state(_old_state);
duke@435 144 }
duke@435 145 };
duke@435 146
duke@435 147
duke@435 148 // Utility class for use with contended monitors:
duke@435 149 class OSThreadContendState : public StackObj {
duke@435 150 OSThread* _osthread;
duke@435 151 ThreadState _old_state;
duke@435 152 public:
duke@435 153 OSThreadContendState(OSThread* osthread) {
duke@435 154 _osthread = osthread;
duke@435 155 _old_state = osthread->get_state();
duke@435 156 osthread->set_state(MONITOR_WAIT);
duke@435 157 }
duke@435 158 ~OSThreadContendState() {
duke@435 159 _osthread->set_state(_old_state);
duke@435 160 }
duke@435 161 };
stefank@2314 162
stefank@2314 163 #endif // SHARE_VM_RUNTIME_OSTHREAD_HPP

mercurial