src/share/vm/runtime/park.hpp

Thu, 24 May 2018 20:03:11 +0800

author
aoqi
date
Thu, 24 May 2018 20:03:11 +0800
changeset 8868
91ddc23482a4
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Increase MaxHeapSize for better performance on MIPS

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

mercurial