< prev index next >

src/hotspot/share/services/memoryPool.cpp

Print this page




  60   _usage_threshold = new ThresholdSupport(support_usage_threshold, support_usage_threshold);
  61   // gc usage threshold supports only high threshold
  62   _gc_usage_threshold = new ThresholdSupport(support_gc_threshold, support_gc_threshold);
  63 }
  64 
  65 void MemoryPool::add_manager(MemoryManager* mgr) {
  66   assert(_num_managers < MemoryPool::max_num_managers, "_num_managers exceeds the max");
  67   if (_num_managers < MemoryPool::max_num_managers) {
  68     _managers[_num_managers] = mgr;
  69     _num_managers++;
  70   }
  71 }
  72 
  73 
  74 // Returns an instanceHandle of a MemoryPool object.
  75 // It creates a MemoryPool instance when the first time
  76 // this function is called.
  77 instanceOop MemoryPool::get_memory_pool_instance(TRAPS) {
  78   // Must do an acquire so as to force ordering of subsequent
  79   // loads from anything _memory_pool_obj points to or implies.
  80   instanceOop pool_obj = OrderAccess::load_acquire(&_memory_pool_obj);
  81   if (pool_obj == NULL) {
  82     // It's ok for more than one thread to execute the code up to the locked region.
  83     // Extra pool instances will just be gc'ed.
  84     InstanceKlass* ik = Management::sun_management_ManagementFactoryHelper_klass(CHECK_NULL);
  85 
  86     Handle pool_name = java_lang_String::create_from_str(_name, CHECK_NULL);
  87     jlong usage_threshold_value = (_usage_threshold->is_high_threshold_supported() ? 0 : -1L);
  88     jlong gc_usage_threshold_value = (_gc_usage_threshold->is_high_threshold_supported() ? 0 : -1L);
  89 
  90     JavaValue result(T_OBJECT);
  91     JavaCallArguments args;
  92     args.push_oop(pool_name);           // Argument 1
  93     args.push_int((int) is_heap());     // Argument 2
  94 
  95     Symbol* method_name = vmSymbols::createMemoryPool_name();
  96     Symbol* signature = vmSymbols::createMemoryPool_signature();
  97 
  98     args.push_long(usage_threshold_value);    // Argument 3
  99     args.push_long(gc_usage_threshold_value); // Argument 4
 100 
 101     JavaCalls::call_static(&result,
 102                            ik,
 103                            method_name,
 104                            signature,
 105                            &args,
 106                            CHECK_NULL);
 107 
 108     instanceOop p = (instanceOop) result.get_jobject();
 109     instanceHandle pool(THREAD, p);
 110 
 111     {
 112       // Get lock since another thread may have create the instance
 113       MutexLocker ml(Management_lock);
 114 
 115       // Check if another thread has created the pool.  We reload
 116       // _memory_pool_obj here because some other thread may have
 117       // initialized 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,
 120       // but we need to do a load_acquire as above.
 121       pool_obj = OrderAccess::load_acquire(&_memory_pool_obj);
 122       if (pool_obj != NULL) {
 123          return pool_obj;
 124       }
 125 
 126       // Get the address of the object we created via call_special.
 127       pool_obj = pool();
 128 
 129       // Use store barrier to make sure the memory accesses associated
 130       // with creating the pool are visible before publishing its address.
 131       // The unlock will publish the store to _memory_pool_obj because
 132       // it does a release first.
 133       OrderAccess::release_store(&_memory_pool_obj, pool_obj);
 134     }
 135   }
 136 
 137   return pool_obj;
 138 }
 139 
 140 inline static size_t get_max_value(size_t val1, size_t val2) {
 141     return (val1 > val2 ? val1 : val2);
 142 }
 143 
 144 void MemoryPool::record_peak_memory_usage() {
 145   // Caller in JDK is responsible for synchronization -
 146   // acquire the lock for this memory pool before calling VM
 147   MemoryUsage usage = get_memory_usage();
 148   size_t peak_used = get_max_value(usage.used(), _peak_usage.used());
 149   size_t peak_committed = get_max_value(usage.committed(), _peak_usage.committed());
 150   size_t peak_max_size = get_max_value(usage.max_size(), _peak_usage.max_size());
 151 
 152   _peak_usage = MemoryUsage(initial_size(), peak_used, peak_committed, peak_max_size);
 153 }




  60   _usage_threshold = new ThresholdSupport(support_usage_threshold, support_usage_threshold);
  61   // gc usage threshold supports only high threshold
  62   _gc_usage_threshold = new ThresholdSupport(support_gc_threshold, support_gc_threshold);
  63 }
  64 
  65 void MemoryPool::add_manager(MemoryManager* mgr) {
  66   assert(_num_managers < MemoryPool::max_num_managers, "_num_managers exceeds the max");
  67   if (_num_managers < MemoryPool::max_num_managers) {
  68     _managers[_num_managers] = mgr;
  69     _num_managers++;
  70   }
  71 }
  72 
  73 
  74 // Returns an instanceHandle of a MemoryPool object.
  75 // It creates a MemoryPool instance when the first time
  76 // this function is called.
  77 instanceOop MemoryPool::get_memory_pool_instance(TRAPS) {
  78   // Must do an acquire so as to force ordering of subsequent
  79   // loads from anything _memory_pool_obj points to or implies.
  80   instanceOop pool_obj = Atomic::load_acquire(&_memory_pool_obj);
  81   if (pool_obj == NULL) {
  82     // It's ok for more than one thread to execute the code up to the locked region.
  83     // Extra pool instances will just be gc'ed.
  84     InstanceKlass* ik = Management::sun_management_ManagementFactoryHelper_klass(CHECK_NULL);
  85 
  86     Handle pool_name = java_lang_String::create_from_str(_name, CHECK_NULL);
  87     jlong usage_threshold_value = (_usage_threshold->is_high_threshold_supported() ? 0 : -1L);
  88     jlong gc_usage_threshold_value = (_gc_usage_threshold->is_high_threshold_supported() ? 0 : -1L);
  89 
  90     JavaValue result(T_OBJECT);
  91     JavaCallArguments args;
  92     args.push_oop(pool_name);           // Argument 1
  93     args.push_int((int) is_heap());     // Argument 2
  94 
  95     Symbol* method_name = vmSymbols::createMemoryPool_name();
  96     Symbol* signature = vmSymbols::createMemoryPool_signature();
  97 
  98     args.push_long(usage_threshold_value);    // Argument 3
  99     args.push_long(gc_usage_threshold_value); // Argument 4
 100 
 101     JavaCalls::call_static(&result,
 102                            ik,
 103                            method_name,
 104                            signature,
 105                            &args,
 106                            CHECK_NULL);
 107 
 108     instanceOop p = (instanceOop) result.get_jobject();
 109     instanceHandle pool(THREAD, p);
 110 
 111     {
 112       // Get lock since another thread may have create the instance
 113       MutexLocker ml(Management_lock);
 114 
 115       // Check if another thread has created the pool.  We reload
 116       // _memory_pool_obj here because some other thread may have
 117       // initialized 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,
 120       // but we need to do a load_acquire as above.
 121       pool_obj = Atomic::load_acquire(&_memory_pool_obj);
 122       if (pool_obj != NULL) {
 123          return pool_obj;
 124       }
 125 
 126       // Get the address of the object we created via call_special.
 127       pool_obj = pool();
 128 
 129       // Use store barrier to make sure the memory accesses associated
 130       // with creating the pool are visible before publishing its address.
 131       // The unlock will publish the store to _memory_pool_obj because
 132       // it does a release first.
 133       Atomic::release_store(&_memory_pool_obj, pool_obj);
 134     }
 135   }
 136 
 137   return pool_obj;
 138 }
 139 
 140 inline static size_t get_max_value(size_t val1, size_t val2) {
 141     return (val1 > val2 ? val1 : val2);
 142 }
 143 
 144 void MemoryPool::record_peak_memory_usage() {
 145   // Caller in JDK is responsible for synchronization -
 146   // acquire the lock for this memory pool before calling VM
 147   MemoryUsage usage = get_memory_usage();
 148   size_t peak_used = get_max_value(usage.used(), _peak_usage.used());
 149   size_t peak_committed = get_max_value(usage.committed(), _peak_usage.committed());
 150   size_t peak_max_size = get_max_value(usage.max_size(), _peak_usage.max_size());
 151 
 152   _peak_usage = MemoryUsage(initial_size(), peak_used, peak_committed, peak_max_size);
 153 }


< prev index next >