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
acorn@2233 | 1 | /* |
coleenp@5614 | 2 | * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
acorn@2233 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
acorn@2233 | 4 | * |
acorn@2233 | 5 | * This code is free software; you can redistribute it and/or modify it |
acorn@2233 | 6 | * under the terms of the GNU General Public License version 2 only, as |
acorn@2233 | 7 | * published by the Free Software Foundation. |
acorn@2233 | 8 | * |
acorn@2233 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
acorn@2233 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
acorn@2233 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
acorn@2233 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
acorn@2233 | 13 | * accompanied this code). |
acorn@2233 | 14 | * |
acorn@2233 | 15 | * You should have received a copy of the GNU General Public License version |
acorn@2233 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
acorn@2233 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
acorn@2233 | 18 | * |
acorn@2233 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
acorn@2233 | 20 | * or visit www.oracle.com if you need additional information or have any |
acorn@2233 | 21 | * questions. |
acorn@2233 | 22 | * |
acorn@2233 | 23 | */ |
stefank@2314 | 24 | |
stefank@2314 | 25 | #ifndef SHARE_VM_RUNTIME_PARK_HPP |
stefank@2314 | 26 | #define SHARE_VM_RUNTIME_PARK_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "utilities/debug.hpp" |
stefank@2314 | 29 | #include "utilities/globalDefinitions.hpp" |
acorn@2233 | 30 | /* |
acorn@2233 | 31 | * Per-thread blocking support for JSR166. See the Java-level |
acorn@2233 | 32 | * Documentation for rationale. Basically, park acts like wait, unpark |
acorn@2233 | 33 | * like notify. |
acorn@2233 | 34 | * |
acorn@2233 | 35 | * 6271289 -- |
acorn@2233 | 36 | * To avoid errors where an os thread expires but the JavaThread still |
acorn@2233 | 37 | * exists, Parkers are immortal (type-stable) and are recycled across |
acorn@2233 | 38 | * new threads. This parallels the ParkEvent implementation. |
acorn@2233 | 39 | * Because park-unpark allow spurious wakeups it is harmless if an |
acorn@2233 | 40 | * unpark call unparks a new thread using the old Parker reference. |
acorn@2233 | 41 | * |
acorn@2233 | 42 | * In the future we'll want to think about eliminating Parker and using |
acorn@2233 | 43 | * ParkEvent instead. There's considerable duplication between the two |
acorn@2233 | 44 | * services. |
acorn@2233 | 45 | * |
acorn@2233 | 46 | */ |
acorn@2233 | 47 | |
acorn@2233 | 48 | class Parker : public os::PlatformParker { |
acorn@2233 | 49 | private: |
acorn@2233 | 50 | volatile int _counter ; |
acorn@2233 | 51 | Parker * FreeNext ; |
acorn@2233 | 52 | JavaThread * AssociatedWith ; // Current association |
acorn@2233 | 53 | |
acorn@2233 | 54 | public: |
acorn@2233 | 55 | Parker() : PlatformParker() { |
acorn@2233 | 56 | _counter = 0 ; |
acorn@2233 | 57 | FreeNext = NULL ; |
acorn@2233 | 58 | AssociatedWith = NULL ; |
acorn@2233 | 59 | } |
acorn@2233 | 60 | protected: |
acorn@2233 | 61 | ~Parker() { ShouldNotReachHere(); } |
acorn@2233 | 62 | public: |
acorn@2233 | 63 | // For simplicity of interface with Java, all forms of park (indefinite, |
acorn@2233 | 64 | // relative, and absolute) are multiplexed into one call. |
acorn@2233 | 65 | void park(bool isAbsolute, jlong time); |
acorn@2233 | 66 | void unpark(); |
acorn@2233 | 67 | |
acorn@2233 | 68 | // Lifecycle operators |
acorn@2233 | 69 | static Parker * Allocate (JavaThread * t) ; |
acorn@2233 | 70 | static void Release (Parker * e) ; |
acorn@2233 | 71 | private: |
acorn@2233 | 72 | static Parker * volatile FreeList ; |
acorn@2233 | 73 | static volatile int ListLock ; |
acorn@2233 | 74 | |
acorn@2233 | 75 | }; |
acorn@2233 | 76 | |
acorn@2233 | 77 | ///////////////////////////////////////////////////////////// |
acorn@2233 | 78 | // |
acorn@2233 | 79 | // ParkEvents are type-stable and immortal. |
acorn@2233 | 80 | // |
acorn@2233 | 81 | // Lifecycle: Once a ParkEvent is associated with a thread that ParkEvent remains |
acorn@2233 | 82 | // associated with the thread for the thread's entire lifetime - the relationship is |
acorn@2233 | 83 | // stable. A thread will be associated at most one ParkEvent. When the thread |
acorn@2233 | 84 | // expires, the ParkEvent moves to the EventFreeList. New threads attempt to allocate from |
acorn@2233 | 85 | // the EventFreeList before creating a new Event. Type-stability frees us from |
acorn@2233 | 86 | // worrying about stale Event or Thread references in the objectMonitor subsystem. |
acorn@2233 | 87 | // (A reference to ParkEvent is always valid, even though the event may no longer be associated |
acorn@2233 | 88 | // with the desired or expected thread. A key aspect of this design is that the callers of |
acorn@2233 | 89 | // park, unpark, etc must tolerate stale references and spurious wakeups). |
acorn@2233 | 90 | // |
acorn@2233 | 91 | // Only the "associated" thread can block (park) on the ParkEvent, although |
acorn@2233 | 92 | // any other thread can unpark a reachable parkevent. Park() is allowed to |
acorn@2233 | 93 | // return spuriously. In fact park-unpark a really just an optimization to |
acorn@2233 | 94 | // avoid unbounded spinning and surrender the CPU to be a polite system citizen. |
acorn@2233 | 95 | // A degenerate albeit "impolite" park-unpark implementation could simply return. |
acorn@2233 | 96 | // See http://blogs.sun.com/dave for more details. |
acorn@2233 | 97 | // |
acorn@2233 | 98 | // Eventually I'd like to eliminate Events and ObjectWaiters, both of which serve as |
acorn@2233 | 99 | // thread proxies, and simply make the THREAD structure type-stable and persistent. |
acorn@2233 | 100 | // Currently, we unpark events associated with threads, but ideally we'd just |
acorn@2233 | 101 | // unpark threads. |
acorn@2233 | 102 | // |
acorn@2233 | 103 | // The base-class, PlatformEvent, is platform-specific while the ParkEvent is |
acorn@2233 | 104 | // platform-independent. PlatformEvent provides park(), unpark(), etc., and |
acorn@2233 | 105 | // is abstract -- that is, a PlatformEvent should never be instantiated except |
acorn@2233 | 106 | // as part of a ParkEvent. |
acorn@2233 | 107 | // Equivalently we could have defined a platform-independent base-class that |
acorn@2233 | 108 | // exported Allocate(), Release(), etc. The platform-specific class would extend |
acorn@2233 | 109 | // that base-class, adding park(), unpark(), etc. |
acorn@2233 | 110 | // |
acorn@2233 | 111 | // A word of caution: The JVM uses 2 very similar constructs: |
acorn@2233 | 112 | // 1. ParkEvent are used for Java-level "monitor" synchronization. |
acorn@2233 | 113 | // 2. Parkers are used by JSR166-JUC park-unpark. |
acorn@2233 | 114 | // |
acorn@2233 | 115 | // We'll want to eventually merge these redundant facilities and use ParkEvent. |
acorn@2233 | 116 | |
acorn@2233 | 117 | |
acorn@2233 | 118 | class ParkEvent : public os::PlatformEvent { |
acorn@2233 | 119 | private: |
acorn@2233 | 120 | ParkEvent * FreeNext ; |
acorn@2233 | 121 | |
acorn@2233 | 122 | // Current association |
acorn@2233 | 123 | Thread * AssociatedWith ; |
acorn@2233 | 124 | intptr_t RawThreadIdentity ; // LWPID etc |
acorn@2233 | 125 | volatile int Incarnation ; |
acorn@2233 | 126 | |
acorn@2233 | 127 | // diagnostic : keep track of last thread to wake this thread. |
acorn@2233 | 128 | // this is useful for construction of dependency graphs. |
acorn@2233 | 129 | void * LastWaker ; |
acorn@2233 | 130 | |
acorn@2233 | 131 | public: |
acorn@2233 | 132 | // MCS-CLH list linkage and Native Mutex/Monitor |
acorn@2233 | 133 | ParkEvent * volatile ListNext ; |
acorn@2233 | 134 | ParkEvent * volatile ListPrev ; |
acorn@2233 | 135 | volatile intptr_t OnList ; |
acorn@2233 | 136 | volatile int TState ; |
acorn@2233 | 137 | volatile int Notified ; // for native monitor construct |
acorn@2233 | 138 | volatile int IsWaiting ; // Enqueued on WaitSet |
acorn@2233 | 139 | |
acorn@2233 | 140 | |
acorn@2233 | 141 | private: |
acorn@2233 | 142 | static ParkEvent * volatile FreeList ; |
acorn@2233 | 143 | static volatile int ListLock ; |
acorn@2233 | 144 | |
acorn@2233 | 145 | // It's prudent to mark the dtor as "private" |
acorn@2233 | 146 | // ensuring that it's not visible outside the package. |
acorn@2233 | 147 | // Unfortunately gcc warns about such usage, so |
acorn@2233 | 148 | // we revert to the less desirable "protected" visibility. |
acorn@2233 | 149 | // The other compilers accept private dtors. |
acorn@2233 | 150 | |
acorn@2233 | 151 | protected: // Ensure dtor is never invoked |
acorn@2233 | 152 | ~ParkEvent() { guarantee (0, "invariant") ; } |
acorn@2233 | 153 | |
acorn@2233 | 154 | ParkEvent() : PlatformEvent() { |
acorn@2233 | 155 | AssociatedWith = NULL ; |
acorn@2233 | 156 | FreeNext = NULL ; |
acorn@2233 | 157 | ListNext = NULL ; |
acorn@2233 | 158 | ListPrev = NULL ; |
acorn@2233 | 159 | OnList = 0 ; |
acorn@2233 | 160 | TState = 0 ; |
acorn@2233 | 161 | Notified = 0 ; |
acorn@2233 | 162 | IsWaiting = 0 ; |
acorn@2233 | 163 | } |
acorn@2233 | 164 | |
acorn@2233 | 165 | // We use placement-new to force ParkEvent instances to be |
acorn@2233 | 166 | // aligned on 256-byte address boundaries. This ensures that the least |
acorn@2233 | 167 | // significant byte of a ParkEvent address is always 0. |
acorn@2233 | 168 | |
coleenp@5614 | 169 | void * operator new (size_t sz) throw(); |
acorn@2233 | 170 | void operator delete (void * a) ; |
acorn@2233 | 171 | |
acorn@2233 | 172 | public: |
acorn@2233 | 173 | static ParkEvent * Allocate (Thread * t) ; |
acorn@2233 | 174 | static void Release (ParkEvent * e) ; |
acorn@2233 | 175 | } ; |
stefank@2314 | 176 | |
stefank@2314 | 177 | #endif // SHARE_VM_RUNTIME_PARK_HPP |