Fri, 06 Dec 2019 12:42:29 +0100
8235243: handle VS2017 15.9 and VS2019 in abstract_vm_version
8235325: build failure on Linux after 8235243
Reviewed-by: dholmes, mdoerr
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 |
goetz@6461 | 108 | #ifdef TARGET_OS_FAMILY_aix |
goetz@6461 | 109 | # include "osThread_aix.hpp" |
goetz@6461 | 110 | #endif |
never@3156 | 111 | #ifdef TARGET_OS_FAMILY_bsd |
never@3156 | 112 | # include "osThread_bsd.hpp" |
never@3156 | 113 | #endif |
stefank@2314 | 114 | |
rbackman@3796 | 115 | public: |
rbackman@3796 | 116 | static ByteSize thread_id_offset() { return byte_offset_of(OSThread, _thread_id); } |
rbackman@3796 | 117 | static size_t thread_id_size() { return sizeof(thread_id_t); } |
rbackman@3796 | 118 | |
rbackman@3796 | 119 | thread_id_t thread_id() const { return _thread_id; } |
rbackman@3796 | 120 | |
rbackman@3796 | 121 | void set_thread_id(thread_id_t id) { _thread_id = id; } |
rbackman@3796 | 122 | |
rbackman@3796 | 123 | private: |
rbackman@3796 | 124 | // _thread_id is kernel thread id (similar to LWP id on Solaris). Each |
rbackman@3796 | 125 | // thread has a unique thread_id (BsdThreads or NPTL). It can be used |
rbackman@3796 | 126 | // to access /proc. |
rbackman@3796 | 127 | thread_id_t _thread_id; |
duke@435 | 128 | }; |
duke@435 | 129 | |
duke@435 | 130 | |
duke@435 | 131 | // Utility class for use with condition variables: |
duke@435 | 132 | class OSThreadWaitState : public StackObj { |
duke@435 | 133 | OSThread* _osthread; |
duke@435 | 134 | ThreadState _old_state; |
duke@435 | 135 | public: |
duke@435 | 136 | OSThreadWaitState(OSThread* osthread, bool is_object_wait) { |
duke@435 | 137 | _osthread = osthread; |
duke@435 | 138 | _old_state = osthread->get_state(); |
duke@435 | 139 | if (is_object_wait) { |
duke@435 | 140 | osthread->set_state(OBJECT_WAIT); |
duke@435 | 141 | } else { |
duke@435 | 142 | osthread->set_state(CONDVAR_WAIT); |
duke@435 | 143 | } |
duke@435 | 144 | } |
duke@435 | 145 | ~OSThreadWaitState() { |
duke@435 | 146 | _osthread->set_state(_old_state); |
duke@435 | 147 | } |
duke@435 | 148 | }; |
duke@435 | 149 | |
duke@435 | 150 | |
duke@435 | 151 | // Utility class for use with contended monitors: |
duke@435 | 152 | class OSThreadContendState : public StackObj { |
duke@435 | 153 | OSThread* _osthread; |
duke@435 | 154 | ThreadState _old_state; |
duke@435 | 155 | public: |
duke@435 | 156 | OSThreadContendState(OSThread* osthread) { |
duke@435 | 157 | _osthread = osthread; |
duke@435 | 158 | _old_state = osthread->get_state(); |
duke@435 | 159 | osthread->set_state(MONITOR_WAIT); |
duke@435 | 160 | } |
duke@435 | 161 | ~OSThreadContendState() { |
duke@435 | 162 | _osthread->set_state(_old_state); |
duke@435 | 163 | } |
duke@435 | 164 | }; |
stefank@2314 | 165 | |
stefank@2314 | 166 | #endif // SHARE_VM_RUNTIME_OSTHREAD_HPP |