< prev index next >

src/hotspot/share/runtime/biasedLocking.cpp

Print this page
rev 57156 : imported patch 8234796-v3


  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  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/classLoaderDataGraph.hpp"
  27 #include "jfr/jfrEvents.hpp"
  28 #include "jfr/support/jfrThreadId.hpp"
  29 #include "logging/log.hpp"
  30 #include "memory/resourceArea.hpp"
  31 #include "oops/klass.inline.hpp"
  32 #include "oops/markWord.hpp"
  33 #include "oops/oop.inline.hpp"
  34 #include "runtime/atomic.hpp"
  35 #include "runtime/basicLock.hpp"
  36 #include "runtime/biasedLocking.hpp"
  37 #include "runtime/handles.inline.hpp"

  38 #include "runtime/task.hpp"
  39 #include "runtime/threadSMR.hpp"
  40 #include "runtime/vframe.hpp"
  41 #include "runtime/vmThread.hpp"
  42 #include "runtime/vmOperations.hpp"
  43 
  44 
  45 static bool _biased_locking_enabled = false;
  46 BiasedLockingCounters BiasedLocking::_counters;
  47 
  48 static GrowableArray<Handle>*   _preserved_oop_stack  = NULL;
  49 static GrowableArray<markWord>* _preserved_mark_stack = NULL;
  50 
  51 static void enable_biased_locking(InstanceKlass* k) {
  52   k->set_prototype_header(markWord::biased_locking_prototype());
  53 }
  54 
  55 static void enable_biased_locking() {
  56   _biased_locking_enabled = true;
  57   log_info(biasedlocking)("Biased locking enabled");


 483     , _safepoint_id(0) {}
 484 
 485   virtual VMOp_Type type() const { return VMOp_BulkRevokeBias; }
 486 
 487   virtual void doit() {
 488     BiasedLocking::bulk_revoke_at_safepoint((*_obj)(), _bulk_rebias, _requesting_thread);
 489     _safepoint_id = SafepointSynchronize::safepoint_id();
 490     clean_up_cached_monitor_info();
 491   }
 492 
 493   bool is_bulk_rebias() const {
 494     return _bulk_rebias;
 495   }
 496 
 497   uint64_t safepoint_id() const {
 498     return _safepoint_id;
 499   }
 500 };
 501 
 502 
 503 class RevokeOneBias : public ThreadClosure {
 504 protected:
 505   Handle _obj;
 506   JavaThread* _requesting_thread;
 507   JavaThread* _biased_locker;
 508   BiasedLocking::Condition _status_code;
 509   traceid _biased_locker_id;
 510 
 511 public:
 512   RevokeOneBias(Handle obj, JavaThread* requesting_thread, JavaThread* biased_locker)
 513     : _obj(obj)

 514     , _requesting_thread(requesting_thread)
 515     , _biased_locker(biased_locker)
 516     , _status_code(BiasedLocking::NOT_BIASED)
 517     , _biased_locker_id(0) {}
 518 
 519   void do_thread(Thread* target) {
 520     assert(target == _biased_locker, "Wrong thread");
 521 
 522     oop o = _obj();
 523     markWord mark = o->mark();
 524 
 525     if (!mark.has_bias_pattern()) {
 526       return;
 527     }
 528 
 529     markWord prototype = o->klass()->prototype_header();
 530     if (!prototype.has_bias_pattern()) {
 531       // This object has a stale bias from before the handshake
 532       // was requested. If we fail this race, the object's bias
 533       // has been revoked by another thread so we simply return.




  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  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/classLoaderDataGraph.hpp"
  27 #include "jfr/jfrEvents.hpp"
  28 #include "jfr/support/jfrThreadId.hpp"
  29 #include "logging/log.hpp"
  30 #include "memory/resourceArea.hpp"
  31 #include "oops/klass.inline.hpp"
  32 #include "oops/markWord.hpp"
  33 #include "oops/oop.inline.hpp"
  34 #include "runtime/atomic.hpp"
  35 #include "runtime/basicLock.hpp"
  36 #include "runtime/biasedLocking.hpp"
  37 #include "runtime/handles.inline.hpp"
  38 #include "runtime/handshake.hpp"
  39 #include "runtime/task.hpp"
  40 #include "runtime/threadSMR.hpp"
  41 #include "runtime/vframe.hpp"
  42 #include "runtime/vmThread.hpp"
  43 #include "runtime/vmOperations.hpp"
  44 
  45 
  46 static bool _biased_locking_enabled = false;
  47 BiasedLockingCounters BiasedLocking::_counters;
  48 
  49 static GrowableArray<Handle>*   _preserved_oop_stack  = NULL;
  50 static GrowableArray<markWord>* _preserved_mark_stack = NULL;
  51 
  52 static void enable_biased_locking(InstanceKlass* k) {
  53   k->set_prototype_header(markWord::biased_locking_prototype());
  54 }
  55 
  56 static void enable_biased_locking() {
  57   _biased_locking_enabled = true;
  58   log_info(biasedlocking)("Biased locking enabled");


 484     , _safepoint_id(0) {}
 485 
 486   virtual VMOp_Type type() const { return VMOp_BulkRevokeBias; }
 487 
 488   virtual void doit() {
 489     BiasedLocking::bulk_revoke_at_safepoint((*_obj)(), _bulk_rebias, _requesting_thread);
 490     _safepoint_id = SafepointSynchronize::safepoint_id();
 491     clean_up_cached_monitor_info();
 492   }
 493 
 494   bool is_bulk_rebias() const {
 495     return _bulk_rebias;
 496   }
 497 
 498   uint64_t safepoint_id() const {
 499     return _safepoint_id;
 500   }
 501 };
 502 
 503 
 504 class RevokeOneBias : public HandshakeClosure {
 505 protected:
 506   Handle _obj;
 507   JavaThread* _requesting_thread;
 508   JavaThread* _biased_locker;
 509   BiasedLocking::Condition _status_code;
 510   traceid _biased_locker_id;
 511 
 512 public:
 513   RevokeOneBias(Handle obj, JavaThread* requesting_thread, JavaThread* biased_locker)
 514     : HandshakeClosure("RevokeOneBias")
 515     , _obj(obj)
 516     , _requesting_thread(requesting_thread)
 517     , _biased_locker(biased_locker)
 518     , _status_code(BiasedLocking::NOT_BIASED)
 519     , _biased_locker_id(0) {}
 520 
 521   void do_thread(Thread* target) {
 522     assert(target == _biased_locker, "Wrong thread");
 523 
 524     oop o = _obj();
 525     markWord mark = o->mark();
 526 
 527     if (!mark.has_bias_pattern()) {
 528       return;
 529     }
 530 
 531     markWord prototype = o->klass()->prototype_header();
 532     if (!prototype.has_bias_pattern()) {
 533       // This object has a stale bias from before the handshake
 534       // was requested. If we fail this race, the object's bias
 535       // has been revoked by another thread so we simply return.


< prev index next >