src/share/vm/runtime/osThread.hpp

Thu, 10 Apr 2008 15:49:16 -0400

author
sbohne
date
Thu, 10 Apr 2008 15:49:16 -0400
changeset 528
c6ff24ceec1c
parent 435
a61af66fc99e
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6686407: Fix for 6666698 broke -XX:BiasedLockingStartupDelay=0
Summary: Stack allocated VM_EnableBiasedLocking op must be marked as such
Reviewed-by: xlu, acorn, never, dholmes

duke@435 1 /*
duke@435 2 * Copyright 1997-2005 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // The OSThread class holds OS-specific thread information. It is equivalent
duke@435 26 // to the sys_thread_t structure of the classic JVM implementation.
duke@435 27
duke@435 28 // The thread states represented by the ThreadState values are platform-specific
duke@435 29 // and are likely to be only approximate, because most OSes don't give you access
duke@435 30 // to precise thread state information.
duke@435 31
duke@435 32 // Note: the ThreadState is legacy code and is not correctly implemented.
duke@435 33 // Uses of ThreadState need to be replaced by the state in the JavaThread.
duke@435 34
duke@435 35 enum ThreadState {
duke@435 36 ALLOCATED, // Memory has been allocated but not initialized
duke@435 37 INITIALIZED, // The thread has been initialized but yet started
duke@435 38 RUNNABLE, // Has been started and is runnable, but not necessarily running
duke@435 39 MONITOR_WAIT, // Waiting on a contended monitor lock
duke@435 40 CONDVAR_WAIT, // Waiting on a condition variable
duke@435 41 OBJECT_WAIT, // Waiting on an Object.wait() call
duke@435 42 BREAKPOINTED, // Suspended at breakpoint
duke@435 43 SLEEPING, // Thread.sleep()
duke@435 44 ZOMBIE // All done, but not reclaimed yet
duke@435 45 };
duke@435 46
duke@435 47 // I'd make OSThread a ValueObj embedded in Thread to avoid an indirection, but
duke@435 48 // the assembler test in java.cpp expects that it can install the OSThread of
duke@435 49 // the main thread into its own Thread at will.
duke@435 50
duke@435 51
duke@435 52 class OSThread: public CHeapObj {
duke@435 53 friend class VMStructs;
duke@435 54 private:
duke@435 55 //void* _start_proc; // Thread start routine
duke@435 56 OSThreadStartFunc _start_proc; // Thread start routine
duke@435 57 void* _start_parm; // Thread start routine parameter
duke@435 58 volatile ThreadState _state; // Thread state *hint*
duke@435 59 jint _interrupted; // Thread.isInterrupted state
duke@435 60
duke@435 61 // Note: _interrupted must be jint, so that Java intrinsics can access it.
duke@435 62 // The value stored there must be either 0 or 1. It must be possible
duke@435 63 // for Java to emulate Thread.currentThread().isInterrupted() by performing
duke@435 64 // the double indirection Thread::current()->_osthread->_interrupted.
duke@435 65
duke@435 66 // Methods
duke@435 67 public:
duke@435 68 void set_state(ThreadState state) { _state = state; }
duke@435 69 ThreadState get_state() { return _state; }
duke@435 70
duke@435 71 // Constructor
duke@435 72 OSThread(OSThreadStartFunc start_proc, void* start_parm);
duke@435 73
duke@435 74 // Destructor
duke@435 75 ~OSThread();
duke@435 76
duke@435 77 // Accessors
duke@435 78 OSThreadStartFunc start_proc() const { return _start_proc; }
duke@435 79 void set_start_proc(OSThreadStartFunc start_proc) { _start_proc = start_proc; }
duke@435 80 void* start_parm() const { return _start_parm; }
duke@435 81 void set_start_parm(void* start_parm) { _start_parm = start_parm; }
duke@435 82
duke@435 83 bool interrupted() const { return _interrupted != 0; }
duke@435 84 void set_interrupted(bool z) { _interrupted = z ? 1 : 0; }
duke@435 85
duke@435 86 // Printing
duke@435 87 void print_on(outputStream* st) const;
duke@435 88 void print() const { print_on(tty); }
duke@435 89
duke@435 90 // For java intrinsics:
duke@435 91 static ByteSize interrupted_offset() { return byte_offset_of(OSThread, _interrupted); }
duke@435 92
duke@435 93 // Platform dependent stuff
duke@435 94 #include "incls/_osThread_pd.hpp.incl"
duke@435 95 };
duke@435 96
duke@435 97
duke@435 98 // Utility class for use with condition variables:
duke@435 99 class OSThreadWaitState : public StackObj {
duke@435 100 OSThread* _osthread;
duke@435 101 ThreadState _old_state;
duke@435 102 public:
duke@435 103 OSThreadWaitState(OSThread* osthread, bool is_object_wait) {
duke@435 104 _osthread = osthread;
duke@435 105 _old_state = osthread->get_state();
duke@435 106 if (is_object_wait) {
duke@435 107 osthread->set_state(OBJECT_WAIT);
duke@435 108 } else {
duke@435 109 osthread->set_state(CONDVAR_WAIT);
duke@435 110 }
duke@435 111 }
duke@435 112 ~OSThreadWaitState() {
duke@435 113 _osthread->set_state(_old_state);
duke@435 114 }
duke@435 115 };
duke@435 116
duke@435 117
duke@435 118 // Utility class for use with contended monitors:
duke@435 119 class OSThreadContendState : public StackObj {
duke@435 120 OSThread* _osthread;
duke@435 121 ThreadState _old_state;
duke@435 122 public:
duke@435 123 OSThreadContendState(OSThread* osthread) {
duke@435 124 _osthread = osthread;
duke@435 125 _old_state = osthread->get_state();
duke@435 126 osthread->set_state(MONITOR_WAIT);
duke@435 127 }
duke@435 128 ~OSThreadContendState() {
duke@435 129 _osthread->set_state(_old_state);
duke@435 130 }
duke@435 131 };

mercurial