< prev index next >

src/hotspot/share/services/memoryManager.cpp

Print this page




  48   assert(index < MemoryManager::max_num_pools, "_num_pools exceeds the max");
  49   if (index < MemoryManager::max_num_pools) {
  50     _pools[index] = pool;
  51     _num_pools++;
  52   }
  53   pool->add_manager(this);
  54   return index;
  55 }
  56 
  57 MemoryManager* MemoryManager::get_code_cache_memory_manager() {
  58   return new MemoryManager("CodeCacheManager");
  59 }
  60 
  61 MemoryManager* MemoryManager::get_metaspace_memory_manager() {
  62   return new MemoryManager("Metaspace Manager");
  63 }
  64 
  65 instanceOop MemoryManager::get_memory_manager_instance(TRAPS) {
  66   // Must do an acquire so as to force ordering of subsequent
  67   // loads from anything _memory_mgr_obj points to or implies.
  68   instanceOop mgr_obj = OrderAccess::load_acquire(&_memory_mgr_obj);
  69   if (mgr_obj == NULL) {
  70     // It's ok for more than one thread to execute the code up to the locked region.
  71     // Extra manager instances will just be gc'ed.
  72     Klass* k = Management::sun_management_ManagementFactoryHelper_klass(CHECK_0);
  73 
  74     Handle mgr_name = java_lang_String::create_from_str(name(), CHECK_0);
  75 
  76     JavaValue result(T_OBJECT);
  77     JavaCallArguments args;
  78     args.push_oop(mgr_name);    // Argument 1
  79 
  80     Symbol* method_name = NULL;
  81     Symbol* signature = NULL;
  82     if (is_gc_memory_manager()) {
  83       Klass* extKlass = Management::com_sun_management_internal_GarbageCollectorExtImpl_klass(CHECK_0);
  84       // com.sun.management.GarbageCollectorMXBean is in jdk.management module which may not be present.
  85       if (extKlass != NULL) {
  86         k = extKlass;
  87       }
  88 


 101                            ik,
 102                            method_name,
 103                            signature,
 104                            &args,
 105                            CHECK_0);
 106 
 107     instanceOop m = (instanceOop) result.get_jobject();
 108     instanceHandle mgr(THREAD, m);
 109 
 110     {
 111       // Get lock before setting _memory_mgr_obj
 112       // since another thread may have created the instance
 113       MutexLocker ml(Management_lock);
 114 
 115       // Check if another thread has created the management object.  We reload
 116       // _memory_mgr_obj here because some other thread may have initialized
 117       // it while we were executing the code before the lock.
 118       //
 119       // The lock has done an acquire, so the load can't float above it, but
 120       // we need to do a load_acquire as above.
 121       mgr_obj = OrderAccess::load_acquire(&_memory_mgr_obj);
 122       if (mgr_obj != NULL) {
 123          return mgr_obj;
 124       }
 125 
 126       // Get the address of the object we created via call_special.
 127       mgr_obj = mgr();
 128 
 129       // Use store barrier to make sure the memory accesses associated
 130       // with creating the management object are visible before publishing
 131       // its address.  The unlock will publish the store to _memory_mgr_obj
 132       // because it does a release first.
 133       OrderAccess::release_store(&_memory_mgr_obj, mgr_obj);
 134     }
 135   }
 136 
 137   return mgr_obj;
 138 }
 139 
 140 void MemoryManager::oops_do(OopClosure* f) {
 141   f->do_oop((oop*) &_memory_mgr_obj);
 142 }
 143 
 144 GCStatInfo::GCStatInfo(int num_pools) {
 145   // initialize the arrays for memory usage
 146   _before_gc_usage_array = NEW_C_HEAP_ARRAY(MemoryUsage, num_pools, mtInternal);
 147   _after_gc_usage_array  = NEW_C_HEAP_ARRAY(MemoryUsage, num_pools, mtInternal);
 148   _usage_array_size = num_pools;
 149   clear();
 150 }
 151 
 152 GCStatInfo::~GCStatInfo() {
 153   FREE_C_HEAP_ARRAY(MemoryUsage*, _before_gc_usage_array);




  48   assert(index < MemoryManager::max_num_pools, "_num_pools exceeds the max");
  49   if (index < MemoryManager::max_num_pools) {
  50     _pools[index] = pool;
  51     _num_pools++;
  52   }
  53   pool->add_manager(this);
  54   return index;
  55 }
  56 
  57 MemoryManager* MemoryManager::get_code_cache_memory_manager() {
  58   return new MemoryManager("CodeCacheManager");
  59 }
  60 
  61 MemoryManager* MemoryManager::get_metaspace_memory_manager() {
  62   return new MemoryManager("Metaspace Manager");
  63 }
  64 
  65 instanceOop MemoryManager::get_memory_manager_instance(TRAPS) {
  66   // Must do an acquire so as to force ordering of subsequent
  67   // loads from anything _memory_mgr_obj points to or implies.
  68   instanceOop mgr_obj = Atomic::load_acquire(&_memory_mgr_obj);
  69   if (mgr_obj == NULL) {
  70     // It's ok for more than one thread to execute the code up to the locked region.
  71     // Extra manager instances will just be gc'ed.
  72     Klass* k = Management::sun_management_ManagementFactoryHelper_klass(CHECK_0);
  73 
  74     Handle mgr_name = java_lang_String::create_from_str(name(), CHECK_0);
  75 
  76     JavaValue result(T_OBJECT);
  77     JavaCallArguments args;
  78     args.push_oop(mgr_name);    // Argument 1
  79 
  80     Symbol* method_name = NULL;
  81     Symbol* signature = NULL;
  82     if (is_gc_memory_manager()) {
  83       Klass* extKlass = Management::com_sun_management_internal_GarbageCollectorExtImpl_klass(CHECK_0);
  84       // com.sun.management.GarbageCollectorMXBean is in jdk.management module which may not be present.
  85       if (extKlass != NULL) {
  86         k = extKlass;
  87       }
  88 


 101                            ik,
 102                            method_name,
 103                            signature,
 104                            &args,
 105                            CHECK_0);
 106 
 107     instanceOop m = (instanceOop) result.get_jobject();
 108     instanceHandle mgr(THREAD, m);
 109 
 110     {
 111       // Get lock before setting _memory_mgr_obj
 112       // since another thread may have created the instance
 113       MutexLocker ml(Management_lock);
 114 
 115       // Check if another thread has created the management object.  We reload
 116       // _memory_mgr_obj here because some other thread may have initialized
 117       // it while we were executing the code before the lock.
 118       //
 119       // The lock has done an acquire, so the load can't float above it, but
 120       // we need to do a load_acquire as above.
 121       mgr_obj = Atomic::load_acquire(&_memory_mgr_obj);
 122       if (mgr_obj != NULL) {
 123          return mgr_obj;
 124       }
 125 
 126       // Get the address of the object we created via call_special.
 127       mgr_obj = mgr();
 128 
 129       // Use store barrier to make sure the memory accesses associated
 130       // with creating the management object are visible before publishing
 131       // its address.  The unlock will publish the store to _memory_mgr_obj
 132       // because it does a release first.
 133       Atomic::release_store(&_memory_mgr_obj, mgr_obj);
 134     }
 135   }
 136 
 137   return mgr_obj;
 138 }
 139 
 140 void MemoryManager::oops_do(OopClosure* f) {
 141   f->do_oop((oop*) &_memory_mgr_obj);
 142 }
 143 
 144 GCStatInfo::GCStatInfo(int num_pools) {
 145   // initialize the arrays for memory usage
 146   _before_gc_usage_array = NEW_C_HEAP_ARRAY(MemoryUsage, num_pools, mtInternal);
 147   _after_gc_usage_array  = NEW_C_HEAP_ARRAY(MemoryUsage, num_pools, mtInternal);
 148   _usage_array_size = num_pools;
 149   clear();
 150 }
 151 
 152 GCStatInfo::~GCStatInfo() {
 153   FREE_C_HEAP_ARRAY(MemoryUsage*, _before_gc_usage_array);


< prev index next >