< prev index next >

src/hotspot/share/prims/jvmtiRawMonitor.cpp

Print this page


   1 /*
   2  * Copyright (c) 2003, 2019, 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  *


 150        Self->_ParkEvent->park() ;
 151     }
 152   }
 153 }
 154 
 155 int JvmtiRawMonitor::SimpleExit (Thread * Self) {
 156   guarantee (_owner == Self, "invariant") ;
 157   OrderAccess::release_store(&_owner, (void*)NULL) ;
 158   OrderAccess::fence() ;
 159   if (_EntryList == NULL) return OS_OK ;
 160   ObjectWaiter * w ;
 161 
 162   RawMonitor_lock->lock_without_safepoint_check() ;
 163   w = _EntryList ;
 164   if (w != NULL) {
 165       _EntryList = w->_next ;
 166   }
 167   RawMonitor_lock->unlock() ;
 168   if (w != NULL) {
 169       guarantee (w ->TState == ObjectWaiter::TS_ENTER, "invariant") ;
 170       // Once we set TState to TS_RUN the waiting thread can complete
 171       // SimpleEnter and 'w' is pointing into random stack space. So we have
 172       // to ensure we extract the ParkEvent (which is in type-stable memory)
 173       // before we set the state, and then don't access 'w'.
 174       ParkEvent * ev = w->_event ;
 175       OrderAccess::loadstore();
 176       w->TState = ObjectWaiter::TS_RUN ;
 177       OrderAccess::fence() ;
 178       ev->unpark() ;
 179   }
 180   return OS_OK ;
 181 }
 182 
 183 int JvmtiRawMonitor::SimpleWait (Thread * Self, jlong millis) {
 184   guarantee (_owner == Self  , "invariant") ;
 185   guarantee (_recursions == 0, "invariant") ;
 186 
 187   ObjectWaiter Node (Self) ;
 188   Node._notified = 0 ;
 189   Node.TState    = ObjectWaiter::TS_WAIT ;
 190 
 191   RawMonitor_lock->lock_without_safepoint_check() ;
 192   Node._next     = _WaitSet ;
 193   _WaitSet       = &Node ;
 194   RawMonitor_lock->unlock() ;
 195 
 196   SimpleExit (Self) ;
 197   guarantee (_owner != Self, "invariant") ;
 198 
 199   int ret = OS_OK ;
 200   if (millis <= 0) {
 201     Self->_ParkEvent->park();
 202   } else {
 203     ret = Self->_ParkEvent->park(millis);
 204   }
 205 
 206   // If thread still resides on the waitset then unlink it.
 207   // Double-checked locking -- the usage is safe in this context
 208   // as TState is volatile and the lock-unlock operators are
 209   // serializing (barrier-equivalent).
 210 
 211   if (Node.TState == ObjectWaiter::TS_WAIT) {
 212     RawMonitor_lock->lock_without_safepoint_check() ;
 213     if (Node.TState == ObjectWaiter::TS_WAIT) {
 214       // Simple O(n) unlink, but performance isn't critical here.
 215       ObjectWaiter * p ;
 216       ObjectWaiter * q = NULL ;
 217       for (p = _WaitSet ; p != &Node; p = p->_next) {
 218          q = p ;
 219       }
 220       guarantee (p == &Node, "invariant") ;
 221       if (q == NULL) {
 222         guarantee (p == _WaitSet, "invariant") ;
 223         _WaitSet = p->_next ;
 224       } else {
 225         guarantee (p == q->_next, "invariant") ;
 226         q->_next = p->_next ;
 227       }
 228       Node.TState = ObjectWaiter::TS_RUN ;


   1 /*
   2  * Copyright (c) 2003, 2018, 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  *


 150        Self->_ParkEvent->park() ;
 151     }
 152   }
 153 }
 154 
 155 int JvmtiRawMonitor::SimpleExit (Thread * Self) {
 156   guarantee (_owner == Self, "invariant") ;
 157   OrderAccess::release_store(&_owner, (void*)NULL) ;
 158   OrderAccess::fence() ;
 159   if (_EntryList == NULL) return OS_OK ;
 160   ObjectWaiter * w ;
 161 
 162   RawMonitor_lock->lock_without_safepoint_check() ;
 163   w = _EntryList ;
 164   if (w != NULL) {
 165       _EntryList = w->_next ;
 166   }
 167   RawMonitor_lock->unlock() ;
 168   if (w != NULL) {
 169       guarantee (w ->TState == ObjectWaiter::TS_ENTER, "invariant") ;




 170       ParkEvent * ev = w->_event ;

 171       w->TState = ObjectWaiter::TS_RUN ;
 172       OrderAccess::fence() ;
 173       ev->unpark() ;
 174   }
 175   return OS_OK ;
 176 }
 177 
 178 int JvmtiRawMonitor::SimpleWait (Thread * Self, jlong millis) {
 179   guarantee (_owner == Self  , "invariant") ;
 180   guarantee (_recursions == 0, "invariant") ;
 181 
 182   ObjectWaiter Node (Self) ;
 183   Node._notified = 0 ;
 184   Node.TState    = ObjectWaiter::TS_WAIT ;
 185 
 186   RawMonitor_lock->lock_without_safepoint_check() ;
 187   Node._next     = _WaitSet ;
 188   _WaitSet       = &Node ;
 189   RawMonitor_lock->unlock() ;
 190 
 191   SimpleExit (Self) ;
 192   guarantee (_owner != Self, "invariant") ;
 193 
 194   int ret = OS_OK ;
 195   if (millis <= 0) {
 196     Self->_ParkEvent->park();
 197   } else {
 198     ret = Self->_ParkEvent->park(millis);
 199   }
 200 
 201   // If thread still resides on the waitset then unlink it.
 202   // Double-checked locking -- the usage is safe in this context
 203   // as we TState is volatile and the lock-unlock operators are
 204   // serializing (barrier-equivalent).
 205 
 206   if (Node.TState == ObjectWaiter::TS_WAIT) {
 207     RawMonitor_lock->lock_without_safepoint_check() ;
 208     if (Node.TState == ObjectWaiter::TS_WAIT) {
 209       // Simple O(n) unlink, but performance isn't critical here.
 210       ObjectWaiter * p ;
 211       ObjectWaiter * q = NULL ;
 212       for (p = _WaitSet ; p != &Node; p = p->_next) {
 213          q = p ;
 214       }
 215       guarantee (p == &Node, "invariant") ;
 216       if (q == NULL) {
 217         guarantee (p == _WaitSet, "invariant") ;
 218         _WaitSet = p->_next ;
 219       } else {
 220         guarantee (p == q->_next, "invariant") ;
 221         q->_next = p->_next ;
 222       }
 223       Node.TState = ObjectWaiter::TS_RUN ;


< prev index next >