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();
    }
  }
}
void GCMemoryManager::gc_begin(bool recordGCBeginTime, bool recordPreGCUsage,
                               bool recordAccumulatedGCTime) {
  assert(_last_gc_stat != NULL && _current_gc_stat != NULL, "Just checking");
  if (recordAccumulatedGCTime) {
    _accumulated_timer.start();
  }
  // _num_collections now increases in gc_end, to count completed collections
  if (recordGCBeginTime) {
    _current_gc_stat->set_index(_num_collections+1);
    _current_gc_stat->set_start_time(Management::timestamp());
  }

  if (recordPreGCUsage) {
    // Keep memory usage of all memory pools
    for (int i = 0; i < MemoryService::num_memory_pools(); i++) {
      MemoryPool* pool = MemoryService::get_memory_pool(i);
      MemoryUsage usage = pool->get_memory_usage();
      _current_gc_stat->set_before_gc_usage(i, usage);
#ifndef USDT2
      HS_DTRACE_PROBE8(hotspot, mem__pool__gc__begin,
        name(), strlen(name()),
        pool->name(), strlen(pool->name()),
        usage.init_size(), usage.used(),
        usage.committed(), usage.max_size());
#else /* USDT2 */
      HOTSPOT_MEM_POOL_GC_BEGIN(
        (char *) name(), strlen(name()),
        (char *) pool->name(), strlen(pool->name()),
        usage.init_size(), usage.used(),
        usage.committed(), usage.max_size());
#endif /* USDT2 */
    }
  }
}
Example #4
0
void GCMemoryManager::gc_begin() {
  assert(_last_gc_stat != NULL, "Just checking");
  _accumulated_timer.start();
  _num_collections++;
  _last_gc_stat->set_index(_num_collections);
  _last_gc_stat->set_start_time(Management::timestamp());

  // Keep memory usage of all memory pools
  for (int i = 0; i < MemoryService::num_memory_pools(); i++) {
    MemoryPool* pool = MemoryService::get_memory_pool(i);
    MemoryUsage usage = pool->get_memory_usage();
    _last_gc_stat->set_before_gc_usage(i, usage);
    HS_DTRACE_PROBE8(hotspot, mem__pool__gc__begin,
      name(), strlen(name()),
      pool->name(), strlen(pool->name()),
      usage.init_size(), usage.used(),
      usage.committed(), usage.max_size());
  }
}
// This method could be called from any Java threads
// and also VMThread.
void LowMemoryDetector::detect_low_memory() {
  MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);

  bool has_pending_requests = false;
  int num_memory_pools = MemoryService::num_memory_pools();
  for (int i = 0; i < num_memory_pools; i++) {
    MemoryPool* pool = MemoryService::get_memory_pool(i);
    SensorInfo* sensor = pool->usage_sensor();
    if (sensor != NULL &&
        pool->usage_threshold()->is_high_threshold_supported() &&
        pool->usage_threshold()->high_threshold() != 0) {
      MemoryUsage usage = pool->get_memory_usage();
      sensor->set_gauge_sensor_level(usage,
                                     pool->usage_threshold());
      has_pending_requests = has_pending_requests || sensor->has_pending_requests();
    }
  }

  if (has_pending_requests) {
    Service_lock->notify_all();
  }
}