Example #1
0
void GCMemoryManager::gc_end() {
  _accumulated_timer.stop();
  _last_gc_stat->set_end_time(Management::timestamp());

  int i;
  // keep the last gc statistics for all memory pools
  for (i = 0; i < MemoryService::num_memory_pools(); i++) {
    MemoryPool* pool = MemoryService::get_memory_pool(i);
    MemoryUsage usage = pool->get_memory_usage();

    HS_DTRACE_PROBE8(hotspot, mem__pool__gc__end,
      name(), strlen(name()),
      pool->name(), strlen(pool->name()),
      usage.init_size(), usage.used(),
      usage.committed(), usage.max_size());

    _last_gc_stat->set_after_gc_usage(i, usage);
  }

  // Set last collection usage of the memory pools managed by this collector
  for (i = 0; i < num_memory_pools(); i++) {
    MemoryPool* pool = get_memory_pool(i);
    MemoryUsage usage = pool->get_memory_usage();

    // Compare with GC usage threshold
    pool->set_last_collection_usage(usage);
    LowMemoryDetector::detect_after_gc_memory(pool);
  }
}
// A collector MUST, even if it does not complete for some reason,
// make a TraceMemoryManagerStats object where countCollection is true,
// to ensure the current gc stat is placed in _last_gc_stat.
void GCMemoryManager::gc_end(bool recordPostGCUsage,
                             bool recordAccumulatedGCTime,
                             bool recordGCEndTime, bool countCollection,
                             GCCause::Cause cause) {
  if (recordAccumulatedGCTime) {
    _accumulated_timer.stop();
  }
  if (recordGCEndTime) {
    _current_gc_stat->set_end_time(Management::timestamp());
  }

  if (recordPostGCUsage) {
    int i;
    // keep the last gc statistics for all memory pools
    for (i = 0; i < MemoryService::num_memory_pools(); i++) {
      MemoryPool* pool = MemoryService::get_memory_pool(i);
      MemoryUsage usage = pool->get_memory_usage();

      HS_DTRACE_PROBE8(hotspot, mem__pool__gc__end,
        name(), strlen(name()),
        pool->name(), strlen(pool->name()),
        usage.init_size(), usage.used(),
        usage.committed(), usage.max_size());

      _current_gc_stat->set_after_gc_usage(i, usage);
    }

    // Set last collection usage of the memory pools managed by this collector
    for (i = 0; i < num_memory_pools(); i++) {
      MemoryPool* pool = get_memory_pool(i);
      MemoryUsage usage = pool->get_memory_usage();

      // Compare with GC usage threshold
      pool->set_last_collection_usage(usage);
      LowMemoryDetector::detect_after_gc_memory(pool);
    }
    if(is_notification_enabled()) {
      bool isMajorGC = this == MemoryService::get_major_gc_manager();
      GCNotifier::pushNotification(this, isMajorGC ? "end of major GC" : "end of minor GC",
                                   GCCause::to_string(cause));
    }
  }
  if (countCollection) {
    _num_collections++;
    // alternately update two objects making one public when complete
    {
      MutexLockerEx ml(_last_gc_lock, Mutex::_no_safepoint_check_flag);
      GCStatInfo *tmp = _last_gc_stat;
      _last_gc_stat = _current_gc_stat;
      _current_gc_stat = tmp;
      // reset the current stat for diagnosability purposes
      _current_gc_stat->clear();
    }
  }
}