hotspot/src/share/vm/services/memoryService.cpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 1374 4c24294029a9
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_memoryService.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
GrowableArray<MemoryPool*>* MemoryService::_pools_list =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
  new (ResourceObj::C_HEAP) GrowableArray<MemoryPool*>(init_pools_list_size, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
GrowableArray<MemoryManager*>* MemoryService::_managers_list =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  new (ResourceObj::C_HEAP) GrowableArray<MemoryManager*>(init_managers_list_size, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
GCMemoryManager* MemoryService::_minor_gc_manager = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
GCMemoryManager* MemoryService::_major_gc_manager = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
MemoryPool*      MemoryService::_code_heap_pool   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
class GcThreadCountClosure: public ThreadClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  int _count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  GcThreadCountClosure() : _count(0) {};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  void do_thread(Thread* thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  int count() { return _count; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
void GcThreadCountClosure::do_thread(Thread* thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  _count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
void MemoryService::set_universe_heap(CollectedHeap* heap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  CollectedHeap::Name kind = heap->kind();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  switch (kind) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    case CollectedHeap::GenCollectedHeap : {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
      add_gen_collected_heap_info(GenCollectedHeap::heap());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
#ifndef SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    case CollectedHeap::ParallelScavengeHeap : {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
      add_parallel_scavenge_heap_info(ParallelScavengeHeap::heap());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
#endif // SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    default: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      guarantee(false, "Not recognized kind of heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  // set the GC thread count
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  GcThreadCountClosure gctcc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  heap->gc_threads_do(&gctcc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  int count = gctcc.count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  if (count > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    _minor_gc_manager->set_num_gc_threads(count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    _major_gc_manager->set_num_gc_threads(count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // All memory pools and memory managers are initialized.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  _minor_gc_manager->initialize_gc_stat_info();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  _major_gc_manager->initialize_gc_stat_info();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
// Add memory pools for GenCollectedHeap
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
// This function currently only supports two generations collected heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
// The collector for GenCollectedHeap will have two memory managers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
void MemoryService::add_gen_collected_heap_info(GenCollectedHeap* heap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  CollectorPolicy* policy = heap->collector_policy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  assert(policy->is_two_generation_policy(), "Only support two generations");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  guarantee(heap->n_gens() == 2, "Only support two-generation heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  TwoGenerationCollectorPolicy* two_gen_policy = policy->as_two_generation_policy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  if (two_gen_policy != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    GenerationSpec** specs = two_gen_policy->generations();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    Generation::Name kind = specs[0]->name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    switch (kind) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
      case Generation::DefNew:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
        _minor_gc_manager = MemoryManager::get_copy_memory_manager();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
#ifndef SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
      case Generation::ParNew:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      case Generation::ASParNew:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
        _minor_gc_manager = MemoryManager::get_parnew_memory_manager();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
#endif // SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
        guarantee(false, "Unrecognized generation spec");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    if (policy->is_mark_sweep_policy()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      _major_gc_manager = MemoryManager::get_msc_memory_manager();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
#ifndef SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    } else if (policy->is_concurrent_mark_sweep_policy()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      _major_gc_manager = MemoryManager::get_cms_memory_manager();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
#endif // SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      guarantee(false, "Unknown two-gen policy");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    guarantee(false, "Non two-gen policy");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  _managers_list->append(_minor_gc_manager);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  _managers_list->append(_major_gc_manager);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  add_generation_memory_pool(heap->get_gen(minor), _major_gc_manager, _minor_gc_manager);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  add_generation_memory_pool(heap->get_gen(major), _major_gc_manager);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  PermGen::Name name = policy->permanent_generation()->name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  switch (name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    case PermGen::MarkSweepCompact: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
      CompactingPermGenGen* perm_gen = (CompactingPermGenGen*) heap->perm_gen();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      add_compact_perm_gen_memory_pool(perm_gen, _major_gc_manager);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
#ifndef SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    case PermGen::ConcurrentMarkSweep: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
      CMSPermGenGen* cms_gen = (CMSPermGenGen*) heap->perm_gen();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
      add_cms_perm_gen_memory_pool(cms_gen, _major_gc_manager);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
#endif // SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
      guarantee(false, "Unrecognized perm generation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
        break;
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
#ifndef SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
// Add memory pools for ParallelScavengeHeap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
// This function currently only supports two generations collected heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
// The collector for ParallelScavengeHeap will have two memory managers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
void MemoryService::add_parallel_scavenge_heap_info(ParallelScavengeHeap* heap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // Two managers to keep statistics about _minor_gc_manager and _major_gc_manager GC.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  _minor_gc_manager = MemoryManager::get_psScavenge_memory_manager();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  _major_gc_manager = MemoryManager::get_psMarkSweep_memory_manager();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  _managers_list->append(_minor_gc_manager);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  _managers_list->append(_major_gc_manager);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  add_psYoung_memory_pool(heap->young_gen(), _major_gc_manager, _minor_gc_manager);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  add_psOld_memory_pool(heap->old_gen(), _major_gc_manager);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  add_psPerm_memory_pool(heap->perm_gen(), _major_gc_manager);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
#endif // SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
MemoryPool* MemoryService::add_gen(Generation* gen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
                                   const char* name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
                                   bool is_heap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
                                   bool support_usage_threshold) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  MemoryPool::PoolType type = (is_heap ? MemoryPool::Heap : MemoryPool::NonHeap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  GenerationPool* pool = new GenerationPool(gen, name, type, support_usage_threshold);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  _pools_list->append(pool);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  return (MemoryPool*) pool;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
MemoryPool* MemoryService::add_space(ContiguousSpace* space,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
                                     const char* name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
                                     bool is_heap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
                                     size_t max_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
                                     bool support_usage_threshold) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  MemoryPool::PoolType type = (is_heap ? MemoryPool::Heap : MemoryPool::NonHeap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  ContiguousSpacePool* pool = new ContiguousSpacePool(space, name, type, max_size, support_usage_threshold);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  _pools_list->append(pool);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  return (MemoryPool*) pool;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
MemoryPool* MemoryService::add_survivor_spaces(DefNewGeneration* gen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
                                               const char* name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
                                               bool is_heap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
                                               size_t max_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
                                               bool support_usage_threshold) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  MemoryPool::PoolType type = (is_heap ? MemoryPool::Heap : MemoryPool::NonHeap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  SurvivorContiguousSpacePool* pool = new SurvivorContiguousSpacePool(gen, name, type, max_size, support_usage_threshold);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  _pools_list->append(pool);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  return (MemoryPool*) pool;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
#ifndef SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
MemoryPool* MemoryService::add_cms_space(CompactibleFreeListSpace* space,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
                                         const char* name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
                                         bool is_heap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
                                         size_t max_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
                                         bool support_usage_threshold) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  MemoryPool::PoolType type = (is_heap ? MemoryPool::Heap : MemoryPool::NonHeap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  CompactibleFreeListSpacePool* pool = new CompactibleFreeListSpacePool(space, name, type, max_size, support_usage_threshold);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  _pools_list->append(pool);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  return (MemoryPool*) pool;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
#endif // SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
// Add memory pool(s) for one generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
void MemoryService::add_generation_memory_pool(Generation* gen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
                                               MemoryManager* major_mgr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
                                               MemoryManager* minor_mgr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  Generation::Name kind = gen->kind();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  int index = _pools_list->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  switch (kind) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    case Generation::DefNew: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      assert(major_mgr != NULL && minor_mgr != NULL, "Should have two managers");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
      DefNewGeneration* young_gen = (DefNewGeneration*) gen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
      // Add a memory pool for each space and young gen doesn't
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
      // support low memory detection as it is expected to get filled up.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
      MemoryPool* eden = add_space(young_gen->eden(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
                                   "Eden Space",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
                                   true, /* is_heap */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
                                   young_gen->max_eden_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
                                   false /* support_usage_threshold */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
      MemoryPool* survivor = add_survivor_spaces(young_gen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
                                                 "Survivor Space",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
                                                 true, /* is_heap */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
                                                 young_gen->max_survivor_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
                                                 false /* support_usage_threshold */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
#ifndef SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    case Generation::ParNew:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    case Generation::ASParNew:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
      assert(major_mgr != NULL && minor_mgr != NULL, "Should have two managers");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
      // Add a memory pool for each space and young gen doesn't
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
      // support low memory detection as it is expected to get filled up.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
      ParNewGeneration* parnew_gen = (ParNewGeneration*) gen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
      MemoryPool* eden = add_space(parnew_gen->eden(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
                                   "Par Eden Space",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
                                   true /* is_heap */,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
                                   parnew_gen->max_eden_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
                                   false /* support_usage_threshold */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
      MemoryPool* survivor = add_survivor_spaces(parnew_gen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
                                                 "Par Survivor Space",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
                                                 true, /* is_heap */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
                                                 parnew_gen->max_survivor_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
                                                 false /* support_usage_threshold */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
#endif // SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    case Generation::MarkSweepCompact: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
      assert(major_mgr != NULL && minor_mgr == NULL, "Should have only one manager");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
      add_gen(gen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
              "Tenured Gen",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
              true, /* is_heap */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
              true  /* support_usage_threshold */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
#ifndef SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    case Generation::ConcurrentMarkSweep:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    case Generation::ASConcurrentMarkSweep:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
      assert(major_mgr != NULL && minor_mgr == NULL, "Should have only one manager");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
      ConcurrentMarkSweepGeneration* cms = (ConcurrentMarkSweepGeneration*) gen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
      MemoryPool* pool = add_cms_space(cms->cmsSpace(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
                                       "CMS Old Gen",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
                                       true, /* is_heap */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
                                       cms->reserved().byte_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
                                       true  /* support_usage_threshold */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
#endif // SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
      assert(false, "should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
      // no memory pool added for others
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  assert(major_mgr != NULL, "Should have at least one manager");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  // Link managers and the memory pools together
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  for (int i = index; i < _pools_list->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    MemoryPool* pool = _pools_list->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    major_mgr->add_pool(pool);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    if (minor_mgr != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
      minor_mgr->add_pool(pool);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
void MemoryService::add_compact_perm_gen_memory_pool(CompactingPermGenGen* perm_gen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
                                                     MemoryManager* mgr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  PermanentGenerationSpec* spec = perm_gen->spec();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  size_t max_size = spec->max_size() - spec->read_only_size() - spec->read_write_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  MemoryPool* pool = add_space(perm_gen->unshared_space(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
                               "Perm Gen",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
                                false, /* is_heap */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
                                max_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
                                true   /* support_usage_threshold */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  mgr->add_pool(pool);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  if (UseSharedSpaces) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    pool = add_space(perm_gen->ro_space(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
                     "Perm Gen [shared-ro]",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
                     false, /* is_heap */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
                     spec->read_only_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
                     true   /* support_usage_threshold */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    mgr->add_pool(pool);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    pool = add_space(perm_gen->rw_space(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
                     "Perm Gen [shared-rw]",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
                     false, /* is_heap */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
                     spec->read_write_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
                     true   /* support_usage_threshold */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    mgr->add_pool(pool);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
#ifndef SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
void MemoryService::add_cms_perm_gen_memory_pool(CMSPermGenGen* cms_gen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
                                                 MemoryManager* mgr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  MemoryPool* pool = add_cms_space(cms_gen->cmsSpace(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
                                   "CMS Perm Gen",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
                                   false, /* is_heap */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
                                   cms_gen->reserved().byte_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
                                   true   /* support_usage_threshold */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  mgr->add_pool(pool);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
void MemoryService::add_psYoung_memory_pool(PSYoungGen* gen, MemoryManager* major_mgr, MemoryManager* minor_mgr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  assert(major_mgr != NULL && minor_mgr != NULL, "Should have two managers");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  // Add a memory pool for each space and young gen doesn't
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  // support low memory detection as it is expected to get filled up.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  EdenMutableSpacePool* eden = new EdenMutableSpacePool(gen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
                                                        gen->eden_space(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
                                                        "PS Eden Space",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
                                                        MemoryPool::Heap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
                                                        false /* support_usage_threshold */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  SurvivorMutableSpacePool* survivor = new SurvivorMutableSpacePool(gen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
                                                                    "PS Survivor Space",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
                                                                    MemoryPool::Heap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
                                                                    false /* support_usage_threshold */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  major_mgr->add_pool(eden);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  major_mgr->add_pool(survivor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  minor_mgr->add_pool(eden);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  minor_mgr->add_pool(survivor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  _pools_list->append(eden);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  _pools_list->append(survivor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
void MemoryService::add_psOld_memory_pool(PSOldGen* gen, MemoryManager* mgr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  PSGenerationPool* old_gen = new PSGenerationPool(gen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
                                                   "PS Old Gen",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
                                                   MemoryPool::Heap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
                                                   true /* support_usage_threshold */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  mgr->add_pool(old_gen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  _pools_list->append(old_gen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
void MemoryService::add_psPerm_memory_pool(PSPermGen* gen, MemoryManager* mgr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  PSGenerationPool* perm_gen = new PSGenerationPool(gen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
                                                    "PS Perm Gen",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
                                                    MemoryPool::NonHeap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
                                                    true /* support_usage_threshold */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  mgr->add_pool(perm_gen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  _pools_list->append(perm_gen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
#endif // SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
void MemoryService::add_code_heap_memory_pool(CodeHeap* heap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  _code_heap_pool = new CodeHeapPool(heap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
                                     "Code Cache",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
                                     true /* support_usage_threshold */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  MemoryManager* mgr = MemoryManager::get_code_cache_memory_manager();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  mgr->add_pool(_code_heap_pool);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  _pools_list->append(_code_heap_pool);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  _managers_list->append(mgr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
MemoryManager* MemoryService::get_memory_manager(instanceHandle mh) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  for (int i = 0; i < _managers_list->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    MemoryManager* mgr = _managers_list->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    if (mgr->is_manager(mh)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
      return mgr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
MemoryPool* MemoryService::get_memory_pool(instanceHandle ph) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  for (int i = 0; i < _pools_list->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
    MemoryPool* pool = _pools_list->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
    if (pool->is_pool(ph)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
      return pool;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
void MemoryService::track_memory_usage() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  // Track the peak memory usage
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  for (int i = 0; i < _pools_list->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
    MemoryPool* pool = _pools_list->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    pool->record_peak_memory_usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  // Detect low memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  LowMemoryDetector::detect_low_memory();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
void MemoryService::track_memory_pool_usage(MemoryPool* pool) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  // Track the peak memory usage
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  pool->record_peak_memory_usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  // Detect low memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  if (LowMemoryDetector::is_enabled(pool)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
    LowMemoryDetector::detect_low_memory(pool);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
void MemoryService::gc_begin(bool fullGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  GCMemoryManager* mgr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  if (fullGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
    mgr = _major_gc_manager;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    mgr = _minor_gc_manager;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  assert(mgr->is_gc_memory_manager(), "Sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  mgr->gc_begin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  // Track the peak memory usage when GC begins
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  for (int i = 0; i < _pools_list->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
    MemoryPool* pool = _pools_list->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    pool->record_peak_memory_usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
void MemoryService::gc_end(bool fullGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  GCMemoryManager* mgr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  if (fullGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
    mgr = (GCMemoryManager*) _major_gc_manager;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
    mgr = (GCMemoryManager*) _minor_gc_manager;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  assert(mgr->is_gc_memory_manager(), "Sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  // register the GC end statistics and memory usage
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  mgr->gc_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
void MemoryService::oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  for (i = 0; i < _pools_list->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    MemoryPool* pool = _pools_list->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
    pool->oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  for (i = 0; i < _managers_list->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    MemoryManager* mgr = _managers_list->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
    mgr->oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
bool MemoryService::set_verbose(bool verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  MutexLocker m(Management_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  // verbose will be set to the previous value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  bool succeed = CommandLineFlags::boolAtPut((char*)"PrintGC", &verbose, MANAGEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  assert(succeed, "Setting PrintGC flag fails");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  ClassLoadingService::reset_trace_class_unloading();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  return verbose;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
Handle MemoryService::create_MemoryUsage_obj(MemoryUsage usage, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  klassOop k = Management::java_lang_management_MemoryUsage_klass(CHECK_NH);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  instanceKlassHandle ik(THREAD, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  instanceHandle obj = ik->allocate_instance_handle(CHECK_NH);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  JavaValue result(T_VOID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  JavaCallArguments args(10);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  args.push_oop(obj);                         // receiver
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  args.push_long(usage.init_size_as_jlong()); // Argument 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  args.push_long(usage.used_as_jlong());      // Argument 2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  args.push_long(usage.committed_as_jlong()); // Argument 3
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  args.push_long(usage.max_size_as_jlong());  // Argument 4
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  JavaCalls::call_special(&result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
                          ik,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
                          vmSymbolHandles::object_initializer_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
                          vmSymbolHandles::long_long_long_long_void_signature(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
                          &args,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
                          CHECK_NH);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
  return obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
// GC manager type depends on the type of Generation. Depending the space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
// availablity and vm option the gc uses major gc manager or minor gc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
// manager or both. The type of gc manager depends on the generation kind.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
// For DefNew, ParNew and ASParNew generation doing scavange gc uses minor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
// gc manager (so _fullGC is set to false ) and for other generation kind
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
// DOing mark-sweep-compact uses major gc manager (so _fullGC is set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
// to true).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
TraceMemoryManagerStats::TraceMemoryManagerStats(Generation::Name kind) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  switch (kind) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
    case Generation::DefNew:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
#ifndef SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
    case Generation::ParNew:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
    case Generation::ASParNew:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
#endif // SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
      _fullGC=false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
    case Generation::MarkSweepCompact:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
#ifndef SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
    case Generation::ConcurrentMarkSweep:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    case Generation::ASConcurrentMarkSweep:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
#endif // SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
      _fullGC=true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
      assert(false, "Unrecognized gc generation kind.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
  MemoryService::gc_begin(_fullGC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
TraceMemoryManagerStats::TraceMemoryManagerStats(bool fullGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
  _fullGC = fullGC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  MemoryService::gc_begin(_fullGC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
TraceMemoryManagerStats::~TraceMemoryManagerStats() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
  MemoryService::gc_end(_fullGC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
}