src/hotspot/share/services/memoryService.cpp
author shade
Fri, 13 Apr 2018 10:31:49 +0200
branchepsilon-gc-branch
changeset 56422 b09629f4b243
parent 56348 f3b0961adb3c
parent 49593 4dd58ecc9912
child 56625 380796df44a9
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
49393
93fe2fc5c093 8199472: Fix non-PCH build after JDK-8199319
simonis
parents: 48168
diff changeset
     2
 * Copyright (c) 2003, 2018, 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: 4459
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4459
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: 4459
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: 6245
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6245
diff changeset
    26
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6245
diff changeset
    27
#include "classfile/vmSymbols.hpp"
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
    28
#include "gc/shared/collectedHeap.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33794
diff changeset
    29
#include "logging/logConfiguration.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6245
diff changeset
    30
#include "memory/heap.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6245
diff changeset
    31
#include "memory/memRegion.hpp"
49593
4dd58ecc9912 8200105: Remove cyclic dependency between oop.inline.hpp and collectedHeap.inline.hpp
stefank
parents: 49393
diff changeset
    32
#include "memory/resourceArea.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6245
diff changeset
    33
#include "oops/oop.inline.hpp"
18444
8adb4bc92f18 8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents: 16453
diff changeset
    34
#include "runtime/globals.hpp"
49393
93fe2fc5c093 8199472: Fix non-PCH build after JDK-8199319
simonis
parents: 48168
diff changeset
    35
#include "runtime/handles.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6245
diff changeset
    36
#include "runtime/javaCalls.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6245
diff changeset
    37
#include "services/classLoadingService.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6245
diff changeset
    38
#include "services/lowMemoryDetector.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6245
diff changeset
    39
#include "services/management.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6245
diff changeset
    40
#include "services/memoryManager.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6245
diff changeset
    41
#include "services/memoryPool.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6245
diff changeset
    42
#include "services/memoryService.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6245
diff changeset
    43
#include "utilities/growableArray.hpp"
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 13728
diff changeset
    44
#include "utilities/macros.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
GrowableArray<MemoryPool*>* MemoryService::_pools_list =
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 9623
diff changeset
    47
  new (ResourceObj::C_HEAP, mtInternal) GrowableArray<MemoryPool*>(init_pools_list_size, true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
GrowableArray<MemoryManager*>* MemoryService::_managers_list =
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 9623
diff changeset
    49
  new (ResourceObj::C_HEAP, mtInternal) GrowableArray<MemoryManager*>(init_managers_list_size, true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25485
diff changeset
    51
MemoryManager*   MemoryService::_code_cache_manager    = NULL;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25485
diff changeset
    52
GrowableArray<MemoryPool*>* MemoryService::_code_heap_pools =
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25485
diff changeset
    53
    new (ResourceObj::C_HEAP, mtInternal) GrowableArray<MemoryPool*>(init_code_heap_pools_size, true);
18444
8adb4bc92f18 8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents: 16453
diff changeset
    54
MemoryPool*      MemoryService::_metaspace_pool        = NULL;
8adb4bc92f18 8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents: 16453
diff changeset
    55
MemoryPool*      MemoryService::_compressed_class_pool = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
class GcThreadCountClosure: public ThreadClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  int _count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  GcThreadCountClosure() : _count(0) {};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  void do_thread(Thread* thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  int count() { return _count; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
void GcThreadCountClosure::do_thread(Thread* thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  _count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
void MemoryService::set_universe_heap(CollectedHeap* heap) {
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
    71
  ResourceMark rm; // For internal allocations in GrowableArray.
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
    72
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
    73
  GrowableArray<MemoryPool*> gc_mem_pools = heap->memory_pools();
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
    74
  _pools_list->appendAll(&gc_mem_pools);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // set the GC thread count
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  GcThreadCountClosure gctcc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  heap->gc_threads_do(&gctcc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  int count = gctcc.count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
    81
  GrowableArray<GCMemoryManager*> gc_memory_managers = heap->memory_managers();
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
    82
  for (int i = 0; i < gc_memory_managers.length(); i++) {
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
    83
    GCMemoryManager* gc_manager = gc_memory_managers.at(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
    85
    if (count > 0) {
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
    86
      gc_manager->set_num_gc_threads(count);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    }
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
    88
    gc_manager->initialize_gc_stat_info();
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
    89
    _managers_list->append(gc_manager);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25485
diff changeset
    93
void MemoryService::add_code_heap_memory_pool(CodeHeap* heap, const char* name) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25485
diff changeset
    94
  // Create new memory pool for this heap
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25485
diff changeset
    95
  MemoryPool* code_heap_pool = new CodeHeapPool(heap, name, true /* support_usage_threshold */);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25485
diff changeset
    96
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25485
diff changeset
    97
  // Append to lists
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25485
diff changeset
    98
  _code_heap_pools->append(code_heap_pool);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25485
diff changeset
    99
  _pools_list->append(code_heap_pool);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25485
diff changeset
   101
  if (_code_cache_manager == NULL) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25485
diff changeset
   102
    // Create CodeCache memory manager
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25485
diff changeset
   103
    _code_cache_manager = MemoryManager::get_code_cache_memory_manager();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25485
diff changeset
   104
    _managers_list->append(_code_cache_manager);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25485
diff changeset
   105
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25485
diff changeset
   106
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25485
diff changeset
   107
  _code_cache_manager->add_pool(code_heap_pool);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
18444
8adb4bc92f18 8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents: 16453
diff changeset
   110
void MemoryService::add_metaspace_memory_pools() {
8adb4bc92f18 8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents: 16453
diff changeset
   111
  MemoryManager* mgr = MemoryManager::get_metaspace_memory_manager();
8adb4bc92f18 8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents: 16453
diff changeset
   112
8adb4bc92f18 8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents: 16453
diff changeset
   113
  _metaspace_pool = new MetaspacePool();
8adb4bc92f18 8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents: 16453
diff changeset
   114
  mgr->add_pool(_metaspace_pool);
8adb4bc92f18 8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents: 16453
diff changeset
   115
  _pools_list->append(_metaspace_pool);
8adb4bc92f18 8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents: 16453
diff changeset
   116
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 18444
diff changeset
   117
  if (UseCompressedClassPointers) {
18444
8adb4bc92f18 8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents: 16453
diff changeset
   118
    _compressed_class_pool = new CompressedKlassSpacePool();
8adb4bc92f18 8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents: 16453
diff changeset
   119
    mgr->add_pool(_compressed_class_pool);
8adb4bc92f18 8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents: 16453
diff changeset
   120
    _pools_list->append(_compressed_class_pool);
8adb4bc92f18 8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents: 16453
diff changeset
   121
  }
8adb4bc92f18 8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents: 16453
diff changeset
   122
8adb4bc92f18 8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents: 16453
diff changeset
   123
  _managers_list->append(mgr);
8adb4bc92f18 8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents: 16453
diff changeset
   124
}
8adb4bc92f18 8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents: 16453
diff changeset
   125
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
MemoryManager* MemoryService::get_memory_manager(instanceHandle mh) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  for (int i = 0; i < _managers_list->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    MemoryManager* mgr = _managers_list->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    if (mgr->is_manager(mh)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
      return mgr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
MemoryPool* MemoryService::get_memory_pool(instanceHandle ph) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  for (int i = 0; i < _pools_list->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    MemoryPool* pool = _pools_list->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    if (pool->is_pool(ph)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
      return pool;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
void MemoryService::track_memory_usage() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  // Track the peak memory usage
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  for (int i = 0; i < _pools_list->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    MemoryPool* pool = _pools_list->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    pool->record_peak_memory_usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // Detect low memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  LowMemoryDetector::detect_low_memory();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
void MemoryService::track_memory_pool_usage(MemoryPool* pool) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // Track the peak memory usage
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  pool->record_peak_memory_usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  // Detect low memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  if (LowMemoryDetector::is_enabled(pool)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    LowMemoryDetector::detect_low_memory(pool);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
   167
void MemoryService::gc_begin(GCMemoryManager* manager, bool recordGCBeginTime,
6245
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   168
                             bool recordAccumulatedGCTime,
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   169
                             bool recordPreGCUsage, bool recordPeakUsage) {
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   170
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
   171
  manager->gc_begin(recordGCBeginTime, recordPreGCUsage, recordAccumulatedGCTime);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  // Track the peak memory usage when GC begins
6245
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   174
  if (recordPeakUsage) {
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   175
    for (int i = 0; i < _pools_list->length(); i++) {
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   176
      MemoryPool* pool = _pools_list->at(i);
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   177
      pool->record_peak_memory_usage();
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   178
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
   182
void MemoryService::gc_end(GCMemoryManager* manager, bool recordPostGCUsage,
6245
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   183
                           bool recordAccumulatedGCTime,
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8921
diff changeset
   184
                           bool recordGCEndTime, bool countCollection,
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8921
diff changeset
   185
                           GCCause::Cause cause) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  // register the GC end statistics and memory usage
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
   187
  manager->gc_end(recordPostGCUsage, recordAccumulatedGCTime, recordGCEndTime,
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
   188
                  countCollection, cause);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
void MemoryService::oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  for (i = 0; i < _pools_list->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    MemoryPool* pool = _pools_list->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    pool->oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  for (i = 0; i < _managers_list->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    MemoryManager* mgr = _managers_list->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    mgr->oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
bool MemoryService::set_verbose(bool verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  MutexLocker m(Management_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  // verbose will be set to the previous value
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33794
diff changeset
   207
  if (verbose) {
35520
0efb779f41a5 8147464: Use LogConfiguration::configure_stdout() instead of parse_log_arguments
brutisso
parents: 35228
diff changeset
   208
    LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(gc));
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33794
diff changeset
   209
  } else {
35520
0efb779f41a5 8147464: Use LogConfiguration::configure_stdout() instead of parse_log_arguments
brutisso
parents: 35228
diff changeset
   210
    LogConfiguration::configure_stdout(LogLevel::Off, true, LOG_TAGS(gc));
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33794
diff changeset
   211
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  ClassLoadingService::reset_trace_class_unloading();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  return verbose;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
Handle MemoryService::create_MemoryUsage_obj(MemoryUsage usage, TRAPS) {
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 35520
diff changeset
   218
  InstanceKlass* ik = Management::java_lang_management_MemoryUsage_klass(CHECK_NH);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  instanceHandle obj = ik->allocate_instance_handle(CHECK_NH);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  JavaValue result(T_VOID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  JavaCallArguments args(10);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  args.push_oop(obj);                         // receiver
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  args.push_long(usage.init_size_as_jlong()); // Argument 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  args.push_long(usage.used_as_jlong());      // Argument 2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  args.push_long(usage.committed_as_jlong()); // Argument 3
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  args.push_long(usage.max_size_as_jlong());  // Argument 4
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  JavaCalls::call_special(&result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
                          ik,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   232
                          vmSymbols::object_initializer_name(),
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   233
                          vmSymbols::long_long_long_long_void_signature(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
                          &args,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
                          CHECK_NH);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  return obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
}
33794
41ef3dc95179 8140482: Various minor code improvements (runtime)
goetz
parents: 33105
diff changeset
   238
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
   239
TraceMemoryManagerStats::TraceMemoryManagerStats(GCMemoryManager* gc_memory_manager,
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8921
diff changeset
   240
                                                 GCCause::Cause cause,
6245
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   241
                                                 bool recordGCBeginTime,
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   242
                                                 bool recordPreGCUsage,
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   243
                                                 bool recordPeakUsage,
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   244
                                                 bool recordPostGCUsage,
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   245
                                                 bool recordAccumulatedGCTime,
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   246
                                                 bool recordGCEndTime,
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   247
                                                 bool countCollection) {
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
   248
  initialize(gc_memory_manager, cause, recordGCBeginTime, recordPreGCUsage, recordPeakUsage,
6245
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   249
             recordPostGCUsage, recordAccumulatedGCTime, recordGCEndTime,
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   250
             countCollection);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
}
6245
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   252
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   253
// for a subclass to create then initialize an instance before invoking
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   254
// the MemoryService
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
   255
void TraceMemoryManagerStats::initialize(GCMemoryManager* gc_memory_manager,
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8921
diff changeset
   256
                                         GCCause::Cause cause,
6245
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   257
                                         bool recordGCBeginTime,
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   258
                                         bool recordPreGCUsage,
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   259
                                         bool recordPeakUsage,
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   260
                                         bool recordPostGCUsage,
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   261
                                         bool recordAccumulatedGCTime,
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   262
                                         bool recordGCEndTime,
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   263
                                         bool countCollection) {
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
   264
  _gc_memory_manager = gc_memory_manager;
6245
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   265
  _recordGCBeginTime = recordGCBeginTime;
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   266
  _recordPreGCUsage = recordPreGCUsage;
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   267
  _recordPeakUsage = recordPeakUsage;
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   268
  _recordPostGCUsage = recordPostGCUsage;
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   269
  _recordAccumulatedGCTime = recordAccumulatedGCTime;
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   270
  _recordGCEndTime = recordGCEndTime;
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   271
  _countCollection = countCollection;
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8921
diff changeset
   272
  _cause = cause;
6245
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   273
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
   274
  MemoryService::gc_begin(_gc_memory_manager, _recordGCBeginTime, _recordAccumulatedGCTime,
6245
c37d2cf6de1a 6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents: 5547
diff changeset
   275
                          _recordPreGCUsage, _recordPeakUsage);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
TraceMemoryManagerStats::~TraceMemoryManagerStats() {
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47819
diff changeset
   279
  MemoryService::gc_end(_gc_memory_manager, _recordPostGCUsage, _recordAccumulatedGCTime,
9623
151c0b638488 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8921
diff changeset
   280
                        _recordGCEndTime, _countCollection, _cause);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
}