src/share/vm/services/memoryManager.cpp

Print this page
rev 5878 : [mq]: usdt1-gone


  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/systemDictionary.hpp"
  27 #include "classfile/vmSymbols.hpp"
  28 #include "oops/oop.inline.hpp"
  29 #include "runtime/handles.inline.hpp"
  30 #include "runtime/javaCalls.hpp"
  31 #include "services/lowMemoryDetector.hpp"
  32 #include "services/management.hpp"
  33 #include "services/memoryManager.hpp"
  34 #include "services/memoryPool.hpp"
  35 #include "services/memoryService.hpp"
  36 #include "services/gcNotifier.hpp"
  37 #include "utilities/dtrace.hpp"
  38 
  39 #ifndef USDT2
  40 HS_DTRACE_PROBE_DECL8(hotspot, mem__pool__gc__begin, char*, int, char*, int,
  41   size_t, size_t, size_t, size_t);
  42 HS_DTRACE_PROBE_DECL8(hotspot, mem__pool__gc__end, char*, int, char*, int,
  43   size_t, size_t, size_t, size_t);
  44 #endif /* !USDT2 */
  45 
  46 MemoryManager::MemoryManager() {
  47   _num_pools = 0;
  48   (void)const_cast<instanceOop&>(_memory_mgr_obj = NULL);
  49 }
  50 
  51 void MemoryManager::add_pool(MemoryPool* pool) {
  52   assert(_num_pools < MemoryManager::max_num_pools, "_num_pools exceeds the max");
  53   if (_num_pools < MemoryManager::max_num_pools) {
  54     _pools[_num_pools] = pool;
  55     _num_pools++;
  56   }
  57   pool->add_manager(this);
  58 }
  59 
  60 MemoryManager* MemoryManager::get_code_cache_memory_manager() {
  61   return (MemoryManager*) new CodeCacheMemoryManager();
  62 }
  63 
  64 MemoryManager* MemoryManager::get_metaspace_memory_manager() {
  65   return (MemoryManager*) new MetaspaceMemoryManager();


 225 }
 226 
 227 void GCMemoryManager::gc_begin(bool recordGCBeginTime, bool recordPreGCUsage,
 228                                bool recordAccumulatedGCTime) {
 229   assert(_last_gc_stat != NULL && _current_gc_stat != NULL, "Just checking");
 230   if (recordAccumulatedGCTime) {
 231     _accumulated_timer.start();
 232   }
 233   // _num_collections now increases in gc_end, to count completed collections
 234   if (recordGCBeginTime) {
 235     _current_gc_stat->set_index(_num_collections+1);
 236     _current_gc_stat->set_start_time(Management::timestamp());
 237   }
 238 
 239   if (recordPreGCUsage) {
 240     // Keep memory usage of all memory pools
 241     for (int i = 0; i < MemoryService::num_memory_pools(); i++) {
 242       MemoryPool* pool = MemoryService::get_memory_pool(i);
 243       MemoryUsage usage = pool->get_memory_usage();
 244       _current_gc_stat->set_before_gc_usage(i, usage);
 245 #ifndef USDT2
 246       HS_DTRACE_PROBE8(hotspot, mem__pool__gc__begin,
 247         name(), strlen(name()),
 248         pool->name(), strlen(pool->name()),
 249         usage.init_size(), usage.used(),
 250         usage.committed(), usage.max_size());
 251 #else /* USDT2 */
 252       HOTSPOT_MEM_POOL_GC_BEGIN(
 253         (char *) name(), strlen(name()),
 254         (char *) pool->name(), strlen(pool->name()),
 255         usage.init_size(), usage.used(),
 256         usage.committed(), usage.max_size());
 257 #endif /* USDT2 */
 258     }
 259   }
 260 }
 261 
 262 // A collector MUST, even if it does not complete for some reason,
 263 // make a TraceMemoryManagerStats object where countCollection is true,
 264 // to ensure the current gc stat is placed in _last_gc_stat.
 265 void GCMemoryManager::gc_end(bool recordPostGCUsage,
 266                              bool recordAccumulatedGCTime,
 267                              bool recordGCEndTime, bool countCollection,
 268                              GCCause::Cause cause) {
 269   if (recordAccumulatedGCTime) {
 270     _accumulated_timer.stop();
 271   }
 272   if (recordGCEndTime) {
 273     _current_gc_stat->set_end_time(Management::timestamp());
 274   }
 275 
 276   if (recordPostGCUsage) {
 277     int i;
 278     // keep the last gc statistics for all memory pools
 279     for (i = 0; i < MemoryService::num_memory_pools(); i++) {
 280       MemoryPool* pool = MemoryService::get_memory_pool(i);
 281       MemoryUsage usage = pool->get_memory_usage();
 282 
 283 #ifndef USDT2
 284       HS_DTRACE_PROBE8(hotspot, mem__pool__gc__end,
 285         name(), strlen(name()),
 286         pool->name(), strlen(pool->name()),
 287         usage.init_size(), usage.used(),
 288         usage.committed(), usage.max_size());
 289 #else /* USDT2 */
 290       HOTSPOT_MEM_POOL_GC_END(
 291         (char *) name(), strlen(name()),
 292         (char *) pool->name(), strlen(pool->name()),
 293         usage.init_size(), usage.used(),
 294         usage.committed(), usage.max_size());
 295 #endif /* USDT2 */
 296 
 297       _current_gc_stat->set_after_gc_usage(i, usage);
 298     }
 299 
 300     // Set last collection usage of the memory pools managed by this collector
 301     for (i = 0; i < num_memory_pools(); i++) {
 302       MemoryPool* pool = get_memory_pool(i);
 303       MemoryUsage usage = pool->get_memory_usage();
 304 
 305       // Compare with GC usage threshold
 306       pool->set_last_collection_usage(usage);
 307       LowMemoryDetector::detect_after_gc_memory(pool);
 308     }
 309   }
 310 
 311   if (countCollection) {
 312     _num_collections++;
 313     // alternately update two objects making one public when complete
 314     {
 315       MutexLockerEx ml(_last_gc_lock, Mutex::_no_safepoint_check_flag);




  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/systemDictionary.hpp"
  27 #include "classfile/vmSymbols.hpp"
  28 #include "oops/oop.inline.hpp"
  29 #include "runtime/handles.inline.hpp"
  30 #include "runtime/javaCalls.hpp"
  31 #include "services/lowMemoryDetector.hpp"
  32 #include "services/management.hpp"
  33 #include "services/memoryManager.hpp"
  34 #include "services/memoryPool.hpp"
  35 #include "services/memoryService.hpp"
  36 #include "services/gcNotifier.hpp"
  37 #include "utilities/dtrace.hpp"
  38 







  39 MemoryManager::MemoryManager() {
  40   _num_pools = 0;
  41   (void)const_cast<instanceOop&>(_memory_mgr_obj = NULL);
  42 }
  43 
  44 void MemoryManager::add_pool(MemoryPool* pool) {
  45   assert(_num_pools < MemoryManager::max_num_pools, "_num_pools exceeds the max");
  46   if (_num_pools < MemoryManager::max_num_pools) {
  47     _pools[_num_pools] = pool;
  48     _num_pools++;
  49   }
  50   pool->add_manager(this);
  51 }
  52 
  53 MemoryManager* MemoryManager::get_code_cache_memory_manager() {
  54   return (MemoryManager*) new CodeCacheMemoryManager();
  55 }
  56 
  57 MemoryManager* MemoryManager::get_metaspace_memory_manager() {
  58   return (MemoryManager*) new MetaspaceMemoryManager();


 218 }
 219 
 220 void GCMemoryManager::gc_begin(bool recordGCBeginTime, bool recordPreGCUsage,
 221                                bool recordAccumulatedGCTime) {
 222   assert(_last_gc_stat != NULL && _current_gc_stat != NULL, "Just checking");
 223   if (recordAccumulatedGCTime) {
 224     _accumulated_timer.start();
 225   }
 226   // _num_collections now increases in gc_end, to count completed collections
 227   if (recordGCBeginTime) {
 228     _current_gc_stat->set_index(_num_collections+1);
 229     _current_gc_stat->set_start_time(Management::timestamp());
 230   }
 231 
 232   if (recordPreGCUsage) {
 233     // Keep memory usage of all memory pools
 234     for (int i = 0; i < MemoryService::num_memory_pools(); i++) {
 235       MemoryPool* pool = MemoryService::get_memory_pool(i);
 236       MemoryUsage usage = pool->get_memory_usage();
 237       _current_gc_stat->set_before_gc_usage(i, usage);







 238       HOTSPOT_MEM_POOL_GC_BEGIN(
 239         (char *) name(), strlen(name()),
 240         (char *) pool->name(), strlen(pool->name()),
 241         usage.init_size(), usage.used(),
 242         usage.committed(), usage.max_size());

 243     }
 244   }
 245 }
 246 
 247 // A collector MUST, even if it does not complete for some reason,
 248 // make a TraceMemoryManagerStats object where countCollection is true,
 249 // to ensure the current gc stat is placed in _last_gc_stat.
 250 void GCMemoryManager::gc_end(bool recordPostGCUsage,
 251                              bool recordAccumulatedGCTime,
 252                              bool recordGCEndTime, bool countCollection,
 253                              GCCause::Cause cause) {
 254   if (recordAccumulatedGCTime) {
 255     _accumulated_timer.stop();
 256   }
 257   if (recordGCEndTime) {
 258     _current_gc_stat->set_end_time(Management::timestamp());
 259   }
 260 
 261   if (recordPostGCUsage) {
 262     int i;
 263     // keep the last gc statistics for all memory pools
 264     for (i = 0; i < MemoryService::num_memory_pools(); i++) {
 265       MemoryPool* pool = MemoryService::get_memory_pool(i);
 266       MemoryUsage usage = pool->get_memory_usage();
 267 







 268       HOTSPOT_MEM_POOL_GC_END(
 269         (char *) name(), strlen(name()),
 270         (char *) pool->name(), strlen(pool->name()),
 271         usage.init_size(), usage.used(),
 272         usage.committed(), usage.max_size());

 273 
 274       _current_gc_stat->set_after_gc_usage(i, usage);
 275     }
 276 
 277     // Set last collection usage of the memory pools managed by this collector
 278     for (i = 0; i < num_memory_pools(); i++) {
 279       MemoryPool* pool = get_memory_pool(i);
 280       MemoryUsage usage = pool->get_memory_usage();
 281 
 282       // Compare with GC usage threshold
 283       pool->set_last_collection_usage(usage);
 284       LowMemoryDetector::detect_after_gc_memory(pool);
 285     }
 286   }
 287 
 288   if (countCollection) {
 289     _num_collections++;
 290     // alternately update two objects making one public when complete
 291     {
 292       MutexLockerEx ml(_last_gc_lock, Mutex::_no_safepoint_check_flag);