hotspot/src/share/vm/services/lowMemoryDetector.cpp
author jprovino
Mon, 04 Apr 2016 12:57:48 -0400
changeset 37248 11a660dbbb8e
parent 32728 c94c99524ae9
child 40014 5cdf4815deca
permissions -rw-r--r--
8132524: Missing includes to resourceArea.hpp Summary: Files that use ResourceMark are missing the include of resourceArea.hpp Reviewed-by: tschatzl, jwilhelm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 32728
diff changeset
     2
 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4571
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4571
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4571
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "classfile/vmSymbols.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 32728
diff changeset
    28
#include "memory/resourceArea.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "runtime/interfaceSupport.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "runtime/java.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "runtime/javaCalls.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "runtime/mutex.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "runtime/mutexLocker.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
#include "services/lowMemoryDetector.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
#include "services/management.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
volatile bool LowMemoryDetector::_enabled_for_collected_pools = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
volatile jint LowMemoryDetector::_disabled_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
bool LowMemoryDetector::has_pending_requests() {
8110
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
    42
  assert(Service_lock->owned_by_self(), "Must own Service_lock");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  bool has_requests = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  int num_memory_pools = MemoryService::num_memory_pools();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  for (int i = 0; i < num_memory_pools; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    MemoryPool* pool = MemoryService::get_memory_pool(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    SensorInfo* sensor = pool->usage_sensor();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    if (sensor != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
      has_requests = has_requests || sensor->has_pending_requests();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    SensorInfo* gc_sensor = pool->gc_usage_sensor();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    if (gc_sensor != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
      has_requests = has_requests || gc_sensor->has_pending_requests();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  return has_requests;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
8110
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
    60
void LowMemoryDetector::process_sensor_changes(TRAPS) {
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
    61
  ResourceMark rm(THREAD);
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
    62
  HandleMark hm(THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
8110
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
    64
  // No need to hold Service_lock to call out to Java
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
    65
  int num_memory_pools = MemoryService::num_memory_pools();
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
    66
  for (int i = 0; i < num_memory_pools; i++) {
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
    67
    MemoryPool* pool = MemoryService::get_memory_pool(i);
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
    68
    SensorInfo* sensor = pool->usage_sensor();
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
    69
    SensorInfo* gc_sensor = pool->gc_usage_sensor();
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
    70
    if (sensor != NULL && sensor->has_pending_requests()) {
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
    71
      sensor->process_pending_requests(CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    }
8110
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
    73
    if (gc_sensor != NULL && gc_sensor->has_pending_requests()) {
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
    74
      gc_sensor->process_pending_requests(CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
// This method could be called from any Java threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
// and also VMThread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
void LowMemoryDetector::detect_low_memory() {
8110
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
    82
  MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  bool has_pending_requests = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  int num_memory_pools = MemoryService::num_memory_pools();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  for (int i = 0; i < num_memory_pools; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    MemoryPool* pool = MemoryService::get_memory_pool(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    SensorInfo* sensor = pool->usage_sensor();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    if (sensor != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
        pool->usage_threshold()->is_high_threshold_supported() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
        pool->usage_threshold()->high_threshold() != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      MemoryUsage usage = pool->get_memory_usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      sensor->set_gauge_sensor_level(usage,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
                                     pool->usage_threshold());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
      has_pending_requests = has_pending_requests || sensor->has_pending_requests();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  if (has_pending_requests) {
8110
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
   100
    Service_lock->notify_all();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
// This method could be called from any Java threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
// and also VMThread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
void LowMemoryDetector::detect_low_memory(MemoryPool* pool) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  SensorInfo* sensor = pool->usage_sensor();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  if (sensor == NULL ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      !pool->usage_threshold()->is_high_threshold_supported() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
      pool->usage_threshold()->high_threshold() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  {
8110
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
   115
    MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    MemoryUsage usage = pool->get_memory_usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    sensor->set_gauge_sensor_level(usage,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
                                   pool->usage_threshold());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    if (sensor->has_pending_requests()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      // notify sensor state update
8110
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
   122
      Service_lock->notify_all();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
// Only called by VMThread at GC time
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
void LowMemoryDetector::detect_after_gc_memory(MemoryPool* pool) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  SensorInfo* sensor = pool->gc_usage_sensor();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  if (sensor == NULL ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
      !pool->gc_usage_threshold()->is_high_threshold_supported() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      pool->gc_usage_threshold()->high_threshold() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  {
8110
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
   137
    MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    MemoryUsage usage = pool->get_last_collection_usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    sensor->set_counter_sensor_level(usage, pool->gc_usage_threshold());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    if (sensor->has_pending_requests()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
      // notify sensor state update
8110
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
   144
      Service_lock->notify_all();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
// recompute enabled flag
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
void LowMemoryDetector::recompute_enabled_for_collected_pools() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  bool enabled = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  int num_memory_pools = MemoryService::num_memory_pools();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  for (int i=0; i<num_memory_pools; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    MemoryPool* pool = MemoryService::get_memory_pool(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    if (pool->is_collected_pool() && is_enabled(pool)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      enabled = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  _enabled_for_collected_pools = enabled;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
SensorInfo::SensorInfo() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  _sensor_obj = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  _sensor_on = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  _sensor_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  _pending_trigger_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  _pending_clear_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
// When this method is used, the memory usage is monitored
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
// as a gauge attribute.  Sensor notifications (trigger or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
// clear) is only emitted at the first time it crosses
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
// a threshold.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
// High and low thresholds are designed to provide a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
// hysteresis mechanism to avoid repeated triggering
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
// of notifications when the attribute value makes small oscillations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
// around the high or low threshold value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
// The sensor will be triggered if:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
//  (1) the usage is crossing above the high threshold and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
//      the sensor is currently off and no pending
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
//      trigger requests; or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
//  (2) the usage is crossing above the high threshold and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
//      the sensor will be off (i.e. sensor is currently on
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
//      and has pending clear requests).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
// Subsequent crossings of the high threshold value do not cause
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
// any triggers unless the usage becomes less than the low threshold.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
// The sensor will be cleared if:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
//  (1) the usage is crossing below the low threshold and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
//      the sensor is currently on and no pending
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
//      clear requests; or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
//  (2) the usage is crossing below the low threshold and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
//      the sensor will be on (i.e. sensor is currently off
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
//      and has pending trigger requests).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
// Subsequent crossings of the low threshold value do not cause
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
// any clears unless the usage becomes greater than or equal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
// to the high threshold.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
//
32728
c94c99524ae9 8080999: MemoryPoolMXBean.getUsageThresholdCount() returns incorrect value
thartmann
parents: 24424
diff changeset
   204
// If the current level is between high and low threshold, no change.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
void SensorInfo::set_gauge_sensor_level(MemoryUsage usage, ThresholdSupport* high_low_threshold) {
32728
c94c99524ae9 8080999: MemoryPoolMXBean.getUsageThresholdCount() returns incorrect value
thartmann
parents: 24424
diff changeset
   207
  assert(Service_lock->owned_by_self(), "Must own Service_lock");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  assert(high_low_threshold->is_high_threshold_supported(), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  bool is_over_high = high_low_threshold->is_high_threshold_crossed(usage);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  bool is_below_low = high_low_threshold->is_low_threshold_crossed(usage);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  assert(!(is_over_high && is_below_low), "Can't be both true");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  if (is_over_high &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
        ((!_sensor_on && _pending_trigger_count == 0) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
         _pending_clear_count > 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    // low memory detected and need to increment the trigger pending count
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    // if the sensor is off or will be off due to _pending_clear_ > 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    // Request to trigger the sensor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    _pending_trigger_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    _usage = usage;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    if (_pending_clear_count > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
      // non-zero pending clear requests indicates that there are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
      // pending requests to clear this sensor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
      // This trigger request needs to clear this clear count
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
      // since the resulting sensor flag should be on.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
      _pending_clear_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  } else if (is_below_low &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
               ((_sensor_on && _pending_clear_count == 0) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
                (_pending_trigger_count > 0 && _pending_clear_count == 0))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    // memory usage returns below the threshold
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    // Request to clear the sensor if the sensor is on or will be on due to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    // _pending_trigger_count > 0 and also no clear request
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    _pending_clear_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
// When this method is used, the memory usage is monitored as a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
// simple counter attribute.  The sensor will be triggered
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
// whenever the usage is crossing the threshold to keep track
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
// of the number of times the VM detects such a condition occurs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
// High and low thresholds are designed to provide a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
// hysteresis mechanism to avoid repeated triggering
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
// of notifications when the attribute value makes small oscillations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
// around the high or low threshold value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
// The sensor will be triggered if:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
//   - the usage is crossing above the high threshold regardless
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
//     of the current sensor state.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
// The sensor will be cleared if:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
//  (1) the usage is crossing below the low threshold and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
//      the sensor is currently on; or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
//  (2) the usage is crossing below the low threshold and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
//      the sensor will be on (i.e. sensor is currently off
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
//      and has pending trigger requests).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
void SensorInfo::set_counter_sensor_level(MemoryUsage usage, ThresholdSupport* counter_threshold) {
32728
c94c99524ae9 8080999: MemoryPoolMXBean.getUsageThresholdCount() returns incorrect value
thartmann
parents: 24424
diff changeset
   262
  assert(Service_lock->owned_by_self(), "Must own Service_lock");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  assert(counter_threshold->is_high_threshold_supported(), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  bool is_over_high = counter_threshold->is_high_threshold_crossed(usage);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  bool is_below_low = counter_threshold->is_low_threshold_crossed(usage);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  assert(!(is_over_high && is_below_low), "Can't be both true");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  if (is_over_high) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    _pending_trigger_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    _usage = usage;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    _pending_clear_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  } else if (is_below_low && (_sensor_on || _pending_trigger_count > 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    _pending_clear_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
void SensorInfo::oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  f->do_oop((oop*) &_sensor_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
void SensorInfo::process_pending_requests(TRAPS) {
32728
c94c99524ae9 8080999: MemoryPoolMXBean.getUsageThresholdCount() returns incorrect value
thartmann
parents: 24424
diff changeset
   284
  assert(has_pending_requests(), "Must have pending request");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  int pending_count = pending_trigger_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  if (pending_clear_count() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    clear(pending_count, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    trigger(pending_count, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
void SensorInfo::trigger(int count, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  assert(count <= _pending_trigger_count, "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  if (_sensor_obj != NULL) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 8110
diff changeset
   298
    Klass* k = Management::sun_management_Sensor_klass(CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    instanceKlassHandle sensorKlass (THREAD, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    Handle sensor_h(THREAD, _sensor_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    Handle usage_h = MemoryService::create_MemoryUsage_obj(_usage, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    JavaValue result(T_VOID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    JavaCallArguments args(sensor_h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    args.push_int((int) count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    args.push_oop(usage_h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    JavaCalls::call_virtual(&result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
                            sensorKlass,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   310
                            vmSymbols::trigger_name(),
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   311
                            vmSymbols::trigger_method_signature(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
                            &args,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
                            CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  {
8110
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
   317
    // Holds Service_lock and update the sensor state
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 8076
diff changeset
   318
    MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
32728
c94c99524ae9 8080999: MemoryPoolMXBean.getUsageThresholdCount() returns incorrect value
thartmann
parents: 24424
diff changeset
   319
    assert(_pending_trigger_count > 0, "Must have pending trigger");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    _sensor_on = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    _sensor_count += count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    _pending_trigger_count = _pending_trigger_count - count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
void SensorInfo::clear(int count, TRAPS) {
32728
c94c99524ae9 8080999: MemoryPoolMXBean.getUsageThresholdCount() returns incorrect value
thartmann
parents: 24424
diff changeset
   327
  {
c94c99524ae9 8080999: MemoryPoolMXBean.getUsageThresholdCount() returns incorrect value
thartmann
parents: 24424
diff changeset
   328
    // Holds Service_lock and update the sensor state
c94c99524ae9 8080999: MemoryPoolMXBean.getUsageThresholdCount() returns incorrect value
thartmann
parents: 24424
diff changeset
   329
    MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
c94c99524ae9 8080999: MemoryPoolMXBean.getUsageThresholdCount() returns incorrect value
thartmann
parents: 24424
diff changeset
   330
    if (_pending_clear_count == 0) {
c94c99524ae9 8080999: MemoryPoolMXBean.getUsageThresholdCount() returns incorrect value
thartmann
parents: 24424
diff changeset
   331
      // Bail out if we lost a race to set_*_sensor_level() which may have
c94c99524ae9 8080999: MemoryPoolMXBean.getUsageThresholdCount() returns incorrect value
thartmann
parents: 24424
diff changeset
   332
      // reactivated the sensor in the meantime because it was triggered again.
c94c99524ae9 8080999: MemoryPoolMXBean.getUsageThresholdCount() returns incorrect value
thartmann
parents: 24424
diff changeset
   333
      return;
c94c99524ae9 8080999: MemoryPoolMXBean.getUsageThresholdCount() returns incorrect value
thartmann
parents: 24424
diff changeset
   334
    }
c94c99524ae9 8080999: MemoryPoolMXBean.getUsageThresholdCount() returns incorrect value
thartmann
parents: 24424
diff changeset
   335
    _sensor_on = false;
c94c99524ae9 8080999: MemoryPoolMXBean.getUsageThresholdCount() returns incorrect value
thartmann
parents: 24424
diff changeset
   336
    _sensor_count += count;
c94c99524ae9 8080999: MemoryPoolMXBean.getUsageThresholdCount() returns incorrect value
thartmann
parents: 24424
diff changeset
   337
    _pending_clear_count = 0;
c94c99524ae9 8080999: MemoryPoolMXBean.getUsageThresholdCount() returns incorrect value
thartmann
parents: 24424
diff changeset
   338
    _pending_trigger_count = _pending_trigger_count - count;
c94c99524ae9 8080999: MemoryPoolMXBean.getUsageThresholdCount() returns incorrect value
thartmann
parents: 24424
diff changeset
   339
  }
c94c99524ae9 8080999: MemoryPoolMXBean.getUsageThresholdCount() returns incorrect value
thartmann
parents: 24424
diff changeset
   340
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  if (_sensor_obj != NULL) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 8110
diff changeset
   342
    Klass* k = Management::sun_management_Sensor_klass(CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
    instanceKlassHandle sensorKlass (THREAD, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    Handle sensor(THREAD, _sensor_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    JavaValue result(T_VOID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    JavaCallArguments args(sensor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    args.push_int((int) count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    JavaCalls::call_virtual(&result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
                            sensorKlass,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   351
                            vmSymbols::clear_name(),
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   352
                            vmSymbols::int_void_signature(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
                            &args,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
                            CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
//--------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
// Non-product code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
void SensorInfo::print() {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 15228
diff changeset
   363
  tty->print_cr("%s count = " SIZE_FORMAT " pending_triggers = %d pending_clears = %d",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
                (_sensor_on ? "on" : "off"),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
                _sensor_count, _pending_trigger_count, _pending_clear_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
#endif // PRODUCT