1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
104 // platform-independent. PlatformEvent provides park(), unpark(), etc., and
105 // is abstract -- that is, a PlatformEvent should never be instantiated except
106 // as part of a ParkEvent.
107 // Equivalently we could have defined a platform-independent base-class that
108 // exported Allocate(), Release(), etc. The platform-specific class would extend
109 // that base-class, adding park(), unpark(), etc.
110 //
111 // A word of caution: The JVM uses 2 very similar constructs:
112 // 1. ParkEvent are used for Java-level "monitor" synchronization.
113 // 2. Parkers are used by JSR166-JUC park-unpark.
114 //
115 // We'll want to eventually merge these redundant facilities and use ParkEvent.
116
117
118 class ParkEvent : public os::PlatformEvent {
119 private:
120 ParkEvent * FreeNext ;
121
122 // Current association
123 Thread * AssociatedWith ;
124 intptr_t RawThreadIdentity ; // LWPID etc
125 volatile int Incarnation ;
126
127 // diagnostic : keep track of last thread to wake this thread.
128 // this is useful for construction of dependency graphs.
129 void * LastWaker ;
130
131 public:
132 // MCS-CLH list linkage and Native Mutex/Monitor
133 ParkEvent * volatile ListNext ;
134 ParkEvent * volatile ListPrev ;
135 volatile intptr_t OnList ;
136 volatile int TState ;
137 volatile int Notified ; // for native monitor construct
138 volatile int IsWaiting ; // Enqueued on WaitSet
139
140
141 private:
142 static ParkEvent * volatile FreeList ;
143 static volatile int ListLock ;
144
145 // It's prudent to mark the dtor as "private"
146 // ensuring that it's not visible outside the package.
147 // Unfortunately gcc warns about such usage, so
148 // we revert to the less desirable "protected" visibility.
149 // The other compilers accept private dtors.
150
151 protected: // Ensure dtor is never invoked
152 ~ParkEvent() { guarantee (0, "invariant") ; }
153
154 ParkEvent() : PlatformEvent() {
155 AssociatedWith = NULL ;
156 FreeNext = NULL ;
157 ListNext = NULL ;
158 ListPrev = NULL ;
159 OnList = 0 ;
160 TState = 0 ;
161 Notified = 0 ;
162 IsWaiting = 0 ;
163 }
164
165 // We use placement-new to force ParkEvent instances to be
166 // aligned on 256-byte address boundaries. This ensures that the least
167 // significant byte of a ParkEvent address is always 0.
168
169 void * operator new (size_t sz) throw();
170 void operator delete (void * a) ;
171
172 public:
173 static ParkEvent * Allocate (Thread * t) ;
174 static void Release (ParkEvent * e) ;
175 } ;
176
177 #endif // SHARE_VM_RUNTIME_PARK_HPP
|
1 /*
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
104 // platform-independent. PlatformEvent provides park(), unpark(), etc., and
105 // is abstract -- that is, a PlatformEvent should never be instantiated except
106 // as part of a ParkEvent.
107 // Equivalently we could have defined a platform-independent base-class that
108 // exported Allocate(), Release(), etc. The platform-specific class would extend
109 // that base-class, adding park(), unpark(), etc.
110 //
111 // A word of caution: The JVM uses 2 very similar constructs:
112 // 1. ParkEvent are used for Java-level "monitor" synchronization.
113 // 2. Parkers are used by JSR166-JUC park-unpark.
114 //
115 // We'll want to eventually merge these redundant facilities and use ParkEvent.
116
117
118 class ParkEvent : public os::PlatformEvent {
119 private:
120 ParkEvent * FreeNext ;
121
122 // Current association
123 Thread * AssociatedWith ;
124
125 public:
126 // MCS-CLH list linkage and Native Mutex/Monitor
127 ParkEvent * volatile ListNext ;
128 volatile intptr_t OnList ;
129 volatile int TState ;
130 volatile int Notified ; // for native monitor construct
131
132 private:
133 static ParkEvent * volatile FreeList ;
134 static volatile int ListLock ;
135
136 // It's prudent to mark the dtor as "private"
137 // ensuring that it's not visible outside the package.
138 // Unfortunately gcc warns about such usage, so
139 // we revert to the less desirable "protected" visibility.
140 // The other compilers accept private dtors.
141
142 protected: // Ensure dtor is never invoked
143 ~ParkEvent() { guarantee (0, "invariant") ; }
144
145 ParkEvent() : PlatformEvent() {
146 AssociatedWith = NULL ;
147 FreeNext = NULL ;
148 ListNext = NULL ;
149 OnList = 0 ;
150 TState = 0 ;
151 Notified = 0 ;
152 }
153
154 // We use placement-new to force ParkEvent instances to be
155 // aligned on 256-byte address boundaries. This ensures that the least
156 // significant byte of a ParkEvent address is always 0.
157
158 void * operator new (size_t sz) throw();
159 void operator delete (void * a) ;
160
161 public:
162 static ParkEvent * Allocate (Thread * t) ;
163 static void Release (ParkEvent * e) ;
164 } ;
165
166 #endif // SHARE_VM_RUNTIME_PARK_HPP
|