src/share/vm/runtime/synchronizer.cpp

Print this page


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


 356   debug_only(if (StrictSafepointChecks) _thread->check_for_valid_safepoint_state(false);)
 357   _obj = obj;
 358 
 359   if (_dolock) {
 360     TEVENT (ObjectLocker) ;
 361 
 362     ObjectSynchronizer::fast_enter(_obj, &_lock, false, _thread);
 363   }
 364 }
 365 
 366 ObjectLocker::~ObjectLocker() {
 367   if (_dolock) {
 368     ObjectSynchronizer::fast_exit(_obj(), &_lock, _thread);
 369   }
 370 }
 371 
 372 
 373 // -----------------------------------------------------------------------------
 374 //  Wait/Notify/NotifyAll
 375 // NOTE: must use heavy weight monitor to handle wait()
 376 void ObjectSynchronizer::wait(Handle obj, jlong millis, TRAPS) {
 377   if (UseBiasedLocking) {
 378     BiasedLocking::revoke_and_rebias(obj, false, THREAD);
 379     assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
 380   }
 381   if (millis < 0) {
 382     TEVENT (wait - throw IAX) ;
 383     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
 384   }
 385   ObjectMonitor* monitor = ObjectSynchronizer::inflate(THREAD, obj());
 386   DTRACE_MONITOR_WAIT_PROBE(monitor, obj(), THREAD, millis);
 387   monitor->wait(millis, true, THREAD);
 388 
 389   /* This dummy call is in place to get around dtrace bug 6254741.  Once
 390      that's fixed we can uncomment the following line and remove the call */
 391   // DTRACE_MONITOR_PROBE(waited, monitor, obj(), THREAD);
 392   dtrace_waited_probe(monitor, obj, THREAD);
 393 }
 394 
 395 void ObjectSynchronizer::waitUninterruptibly (Handle obj, jlong millis, TRAPS) {
 396   if (UseBiasedLocking) {
 397     BiasedLocking::revoke_and_rebias(obj, false, THREAD);
 398     assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
 399   }
 400   if (millis < 0) {
 401     TEVENT (wait - throw IAX) ;
 402     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
 403   }
 404   ObjectSynchronizer::inflate(THREAD, obj()) -> wait(millis, false, THREAD) ;
 405 }
 406 
 407 void ObjectSynchronizer::notify(Handle obj, TRAPS) {
 408  if (UseBiasedLocking) {
 409     BiasedLocking::revoke_and_rebias(obj, false, THREAD);
 410     assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
 411   }
 412 


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


 356   debug_only(if (StrictSafepointChecks) _thread->check_for_valid_safepoint_state(false);)
 357   _obj = obj;
 358 
 359   if (_dolock) {
 360     TEVENT (ObjectLocker) ;
 361 
 362     ObjectSynchronizer::fast_enter(_obj, &_lock, false, _thread);
 363   }
 364 }
 365 
 366 ObjectLocker::~ObjectLocker() {
 367   if (_dolock) {
 368     ObjectSynchronizer::fast_exit(_obj(), &_lock, _thread);
 369   }
 370 }
 371 
 372 
 373 // -----------------------------------------------------------------------------
 374 //  Wait/Notify/NotifyAll
 375 // NOTE: must use heavy weight monitor to handle wait()
 376 int ObjectSynchronizer::wait(Handle obj, jlong millis, TRAPS) {
 377   if (UseBiasedLocking) {
 378     BiasedLocking::revoke_and_rebias(obj, false, THREAD);
 379     assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
 380   }
 381   if (millis < 0) {
 382     TEVENT (wait - throw IAX) ;
 383     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
 384   }
 385   ObjectMonitor* monitor = ObjectSynchronizer::inflate(THREAD, obj());
 386   DTRACE_MONITOR_WAIT_PROBE(monitor, obj(), THREAD, millis);
 387   monitor->wait(millis, true, THREAD);
 388 
 389   /* This dummy call is in place to get around dtrace bug 6254741.  Once
 390      that's fixed we can uncomment the following line and remove the call */
 391   // DTRACE_MONITOR_PROBE(waited, monitor, obj(), THREAD);
 392   return dtrace_waited_probe(monitor, obj, THREAD);
 393 }
 394 
 395 void ObjectSynchronizer::waitUninterruptibly (Handle obj, jlong millis, TRAPS) {
 396   if (UseBiasedLocking) {
 397     BiasedLocking::revoke_and_rebias(obj, false, THREAD);
 398     assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
 399   }
 400   if (millis < 0) {
 401     TEVENT (wait - throw IAX) ;
 402     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
 403   }
 404   ObjectSynchronizer::inflate(THREAD, obj()) -> wait(millis, false, THREAD) ;
 405 }
 406 
 407 void ObjectSynchronizer::notify(Handle obj, TRAPS) {
 408  if (UseBiasedLocking) {
 409     BiasedLocking::revoke_and_rebias(obj, false, THREAD);
 410     assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
 411   }
 412