25 #include "precompiled.hpp" 26 #include "logging/log.hpp" 27 #include "memory/resourceArea.hpp" 28 #include "oops/klass.inline.hpp" 29 #include "oops/markOop.hpp" 30 #include "oops/oop.inline.hpp" 31 #include "runtime/atomic.hpp" 32 #include "runtime/basicLock.hpp" 33 #include "runtime/biasedLocking.hpp" 34 #include "runtime/task.hpp" 35 #include "runtime/vframe.hpp" 36 #include "runtime/vmThread.hpp" 37 #include "runtime/vm_operations.hpp" 38 39 static bool _biased_locking_enabled = false; 40 BiasedLockingCounters BiasedLocking::_counters; 41 42 static GrowableArray<Handle>* _preserved_oop_stack = NULL; 43 static GrowableArray<markOop>* _preserved_mark_stack = NULL; 44 45 static void enable_biased_locking(Klass* k) { 46 k->set_prototype_header(markOopDesc::biased_locking_prototype()); 47 } 48 49 class VM_EnableBiasedLocking: public VM_Operation { 50 private: 51 bool _is_cheap_allocated; 52 public: 53 VM_EnableBiasedLocking(bool is_cheap_allocated) { _is_cheap_allocated = is_cheap_allocated; } 54 VMOp_Type type() const { return VMOp_EnableBiasedLocking; } 55 Mode evaluation_mode() const { return _is_cheap_allocated ? _async_safepoint : _safepoint; } 56 bool is_cheap_allocated() const { return _is_cheap_allocated; } 57 58 void doit() { 59 // Iterate the system dictionary enabling biased locking for all 60 // currently loaded classes 61 SystemDictionary::classes_do(enable_biased_locking); 62 // Indicate that future instances should enable it as well 63 _biased_locking_enabled = true; 64 65 log_info(biasedlocking)("Biased locking enabled"); 66 } 67 68 bool allow_nested_vm_operations() const { return false; } 69 }; 70 71 72 // One-shot PeriodicTask subclass for enabling biased locking 73 class EnableBiasedLockingTask : public PeriodicTask { 74 public: 75 EnableBiasedLockingTask(size_t interval_time) : PeriodicTask(interval_time) {} 76 77 virtual void task() { 78 // Use async VM operation to avoid blocking the Watcher thread. 79 // VM Thread will free C heap storage. 80 VM_EnableBiasedLocking *op = new VM_EnableBiasedLocking(true); 81 VMThread::execute(op); | 25 #include "precompiled.hpp" 26 #include "logging/log.hpp" 27 #include "memory/resourceArea.hpp" 28 #include "oops/klass.inline.hpp" 29 #include "oops/markOop.hpp" 30 #include "oops/oop.inline.hpp" 31 #include "runtime/atomic.hpp" 32 #include "runtime/basicLock.hpp" 33 #include "runtime/biasedLocking.hpp" 34 #include "runtime/task.hpp" 35 #include "runtime/vframe.hpp" 36 #include "runtime/vmThread.hpp" 37 #include "runtime/vm_operations.hpp" 38 39 static bool _biased_locking_enabled = false; 40 BiasedLockingCounters BiasedLocking::_counters; 41 42 static GrowableArray<Handle>* _preserved_oop_stack = NULL; 43 static GrowableArray<markOop>* _preserved_mark_stack = NULL; 44 45 class EnableBiasedLocking : public KlassClosure { 46 void do_klass(Klass* k) { 47 if (k->is_instance_klass()) { 48 k->set_prototype_header(markOopDesc::biased_locking_prototype()); 49 } 50 } 51 }; 52 53 class VM_EnableBiasedLocking: public VM_Operation { 54 private: 55 bool _is_cheap_allocated; 56 public: 57 VM_EnableBiasedLocking(bool is_cheap_allocated) { _is_cheap_allocated = is_cheap_allocated; } 58 VMOp_Type type() const { return VMOp_EnableBiasedLocking; } 59 Mode evaluation_mode() const { return _is_cheap_allocated ? _async_safepoint : _safepoint; } 60 bool is_cheap_allocated() const { return _is_cheap_allocated; } 61 62 void doit() { 63 // Iterate the system dictionary enabling biased locking for all 64 // currently loaded classes 65 EnableBiasedLocking enable_biased_locking; 66 ClassLoaderDataGraph::loaded_classes_do(&enable_biased_locking); 67 // Indicate that future instances should enable it as well 68 _biased_locking_enabled = true; 69 70 log_info(biasedlocking)("Biased locking enabled"); 71 } 72 73 bool allow_nested_vm_operations() const { return false; } 74 }; 75 76 77 // One-shot PeriodicTask subclass for enabling biased locking 78 class EnableBiasedLockingTask : public PeriodicTask { 79 public: 80 EnableBiasedLockingTask(size_t interval_time) : PeriodicTask(interval_time) {} 81 82 virtual void task() { 83 // Use async VM operation to avoid blocking the Watcher thread. 84 // VM Thread will free C heap storage. 85 VM_EnableBiasedLocking *op = new VM_EnableBiasedLocking(true); 86 VMThread::execute(op); |