110 // and move the resulting raw monitor implementation over to the JVMTI directories.
111 // Ideally, the raw monitor implementation would be built on top of
112 // park-unpark and nothing else.
113 //
114 // raw monitors are used mainly by JVMTI
115 // The raw monitor implementation borrows the ObjectMonitor structure,
116 // but the operators are degenerate and extremely simple.
117 //
118 // Mixed use of a single objectMonitor instance -- as both a raw monitor
119 // and a normal java monitor -- is not permissible.
120 //
121 // Note that we use the single RawMonitor_lock to protect queue operations for
122 // _all_ raw monitors. This is a scalability impediment, but since raw monitor usage
123 // is deprecated and rare, this is not of concern. The RawMonitor_lock can not
124 // be held indefinitely. The critical sections must be short and bounded.
125 //
126 // -------------------------------------------------------------------------
127
128 int JvmtiRawMonitor::SimpleEnter (Thread * Self) {
129 for (;;) {
130 if (Atomic::cmpxchg(Self, &_owner, (void*)NULL) == NULL) {
131 return OS_OK ;
132 }
133
134 ObjectWaiter Node (Self) ;
135 Self->_ParkEvent->reset() ; // strictly optional
136 Node.TState = ObjectWaiter::TS_ENTER ;
137
138 RawMonitor_lock->lock_without_safepoint_check() ;
139 Node._next = _EntryList ;
140 _EntryList = &Node ;
141 OrderAccess::fence() ;
142 if (_owner == NULL && Atomic::cmpxchg(Self, &_owner, (void*)NULL) == NULL) {
143 _EntryList = Node._next ;
144 RawMonitor_lock->unlock() ;
145 return OS_OK ;
146 }
147 RawMonitor_lock->unlock() ;
148 while (Node.TState == ObjectWaiter::TS_ENTER) {
149 Self->_ParkEvent->park() ;
150 }
151 }
152 }
153
154 int JvmtiRawMonitor::SimpleExit (Thread * Self) {
155 guarantee (_owner == Self, "invariant") ;
156 OrderAccess::release_store(&_owner, (void*)NULL) ;
157 OrderAccess::fence() ;
158 if (_EntryList == NULL) return OS_OK ;
159 ObjectWaiter * w ;
160
161 RawMonitor_lock->lock_without_safepoint_check() ;
162 w = _EntryList ;
|
110 // and move the resulting raw monitor implementation over to the JVMTI directories.
111 // Ideally, the raw monitor implementation would be built on top of
112 // park-unpark and nothing else.
113 //
114 // raw monitors are used mainly by JVMTI
115 // The raw monitor implementation borrows the ObjectMonitor structure,
116 // but the operators are degenerate and extremely simple.
117 //
118 // Mixed use of a single objectMonitor instance -- as both a raw monitor
119 // and a normal java monitor -- is not permissible.
120 //
121 // Note that we use the single RawMonitor_lock to protect queue operations for
122 // _all_ raw monitors. This is a scalability impediment, but since raw monitor usage
123 // is deprecated and rare, this is not of concern. The RawMonitor_lock can not
124 // be held indefinitely. The critical sections must be short and bounded.
125 //
126 // -------------------------------------------------------------------------
127
128 int JvmtiRawMonitor::SimpleEnter (Thread * Self) {
129 for (;;) {
130 if (Atomic::replace_if_null(Self, &_owner)) {
131 return OS_OK ;
132 }
133
134 ObjectWaiter Node (Self) ;
135 Self->_ParkEvent->reset() ; // strictly optional
136 Node.TState = ObjectWaiter::TS_ENTER ;
137
138 RawMonitor_lock->lock_without_safepoint_check() ;
139 Node._next = _EntryList ;
140 _EntryList = &Node ;
141 OrderAccess::fence() ;
142 if (_owner == NULL && Atomic::replace_if_null(Self, &_owner)) {
143 _EntryList = Node._next ;
144 RawMonitor_lock->unlock() ;
145 return OS_OK ;
146 }
147 RawMonitor_lock->unlock() ;
148 while (Node.TState == ObjectWaiter::TS_ENTER) {
149 Self->_ParkEvent->park() ;
150 }
151 }
152 }
153
154 int JvmtiRawMonitor::SimpleExit (Thread * Self) {
155 guarantee (_owner == Self, "invariant") ;
156 OrderAccess::release_store(&_owner, (void*)NULL) ;
157 OrderAccess::fence() ;
158 if (_EntryList == NULL) return OS_OK ;
159 ObjectWaiter * w ;
160
161 RawMonitor_lock->lock_without_safepoint_check() ;
162 w = _EntryList ;
|