< prev index next >

src/share/vm/services/memoryService.cpp

Print this page
rev 12854 : [mq]: gcinterface.patch


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/systemDictionary.hpp"
  27 #include "classfile/vmSymbols.hpp"
  28 #include "gc/parallel/mutableSpace.hpp"
  29 #include "gc/serial/defNewGeneration.hpp"
  30 #include "gc/serial/tenuredGeneration.hpp"
  31 #include "gc/shared/collectorPolicy.hpp"
  32 #include "gc/shared/genCollectedHeap.hpp"
  33 #include "gc/shared/generation.hpp"
  34 #include "gc/shared/generationSpec.hpp"
  35 #include "logging/logConfiguration.hpp"
  36 #include "memory/heap.hpp"
  37 #include "memory/memRegion.hpp"
  38 #include "oops/oop.inline.hpp"
  39 #include "runtime/globals.hpp"
  40 #include "runtime/javaCalls.hpp"
  41 #include "services/classLoadingService.hpp"
  42 #include "services/lowMemoryDetector.hpp"
  43 #include "services/management.hpp"
  44 #include "services/memoryManager.hpp"
  45 #include "services/memoryPool.hpp"
  46 #include "services/memoryService.hpp"
  47 #include "utilities/growableArray.hpp"
  48 #include "utilities/macros.hpp"
  49 #if INCLUDE_ALL_GCS
  50 #include "gc/cms/concurrentMarkSweepGeneration.hpp"
  51 #include "gc/cms/parNewGeneration.hpp"
  52 #include "gc/g1/g1CollectedHeap.inline.hpp"
  53 #include "gc/parallel/parallelScavengeHeap.hpp"
  54 #include "gc/parallel/psOldGen.hpp"
  55 #include "gc/parallel/psYoungGen.hpp"
  56 #include "services/g1MemoryPool.hpp"
  57 #include "services/psMemoryPool.hpp"
  58 #endif // INCLUDE_ALL_GCS
  59 
  60 GrowableArray<MemoryPool*>* MemoryService::_pools_list =
  61   new (ResourceObj::C_HEAP, mtInternal) GrowableArray<MemoryPool*>(init_pools_list_size, true);
  62 GrowableArray<MemoryManager*>* MemoryService::_managers_list =
  63   new (ResourceObj::C_HEAP, mtInternal) GrowableArray<MemoryManager*>(init_managers_list_size, true);
  64 
  65 GCMemoryManager* MemoryService::_minor_gc_manager      = NULL;
  66 GCMemoryManager* MemoryService::_major_gc_manager      = NULL;
  67 MemoryManager*   MemoryService::_code_cache_manager    = NULL;
  68 GrowableArray<MemoryPool*>* MemoryService::_code_heap_pools =
  69     new (ResourceObj::C_HEAP, mtInternal) GrowableArray<MemoryPool*>(init_code_heap_pools_size, true);
  70 MemoryPool*      MemoryService::_metaspace_pool        = NULL;
  71 MemoryPool*      MemoryService::_compressed_class_pool = NULL;
  72 
  73 class GcThreadCountClosure: public ThreadClosure {
  74  private:
  75   int _count;
  76  public:
  77   GcThreadCountClosure() : _count(0) {};
  78   void do_thread(Thread* thread);
  79   int count() { return _count; }
  80 };
  81 
  82 void GcThreadCountClosure::do_thread(Thread* thread) {
  83   _count++;
  84 }
  85 
  86 void MemoryService::set_universe_heap(CollectedHeap* heap) {
  87   CollectedHeap::Name kind = heap->kind();
  88   switch (kind) {
  89     case CollectedHeap::GenCollectedHeap : {
  90       add_gen_collected_heap_info(GenCollectedHeap::heap());
  91       break;
  92     }
  93 #if INCLUDE_ALL_GCS
  94     case CollectedHeap::ParallelScavengeHeap : {
  95       add_parallel_scavenge_heap_info(ParallelScavengeHeap::heap());
  96       break;
  97     }
  98     case CollectedHeap::G1CollectedHeap : {
  99       add_g1_heap_info(G1CollectedHeap::heap());
 100       break;
 101     }
 102 #endif // INCLUDE_ALL_GCS
 103     default: {
 104       guarantee(false, "Unrecognized kind of heap");
 105     }
 106   }
 107 
 108   // set the GC thread count
 109   GcThreadCountClosure gctcc;
 110   heap->gc_threads_do(&gctcc);
 111   int count = gctcc.count();
 112   if (count > 0) {
 113     _minor_gc_manager->set_num_gc_threads(count);
 114     _major_gc_manager->set_num_gc_threads(count);
 115   }
 116 
 117   // All memory pools and memory managers are initialized.
 118   //
 119   _minor_gc_manager->initialize_gc_stat_info();
 120   _major_gc_manager->initialize_gc_stat_info();
 121 }
 122 
 123 // Add memory pools for GenCollectedHeap
 124 // This function currently only supports two generations collected heap.
 125 // The collector for GenCollectedHeap will have two memory managers.
 126 void MemoryService::add_gen_collected_heap_info(GenCollectedHeap* heap) {
 127   CollectorPolicy* policy = heap->collector_policy();
 128 
 129   assert(policy->is_generation_policy(), "Only support two generations");
 130   GenCollectorPolicy* gen_policy = policy->as_generation_policy();
 131   if (gen_policy != NULL) {
 132     Generation::Name kind = gen_policy->young_gen_spec()->name();
 133     switch (kind) {
 134       case Generation::DefNew:
 135         _minor_gc_manager = MemoryManager::get_copy_memory_manager();
 136         break;
 137 #if INCLUDE_ALL_GCS
 138       case Generation::ParNew:
 139         _minor_gc_manager = MemoryManager::get_parnew_memory_manager();
 140         break;
 141 #endif // INCLUDE_ALL_GCS
 142       default:
 143         guarantee(false, "Unrecognized generation spec");
 144         break;
 145     }
 146     if (policy->is_mark_sweep_policy()) {
 147       _major_gc_manager = MemoryManager::get_msc_memory_manager();
 148 #if INCLUDE_ALL_GCS
 149     } else if (policy->is_concurrent_mark_sweep_policy()) {
 150       _major_gc_manager = MemoryManager::get_cms_memory_manager();
 151 #endif // INCLUDE_ALL_GCS
 152     } else {
 153       guarantee(false, "Unknown two-gen policy");
 154     }
 155   } else {
 156     guarantee(false, "Non two-gen policy");
 157   }
 158   _managers_list->append(_minor_gc_manager);
 159   _managers_list->append(_major_gc_manager);
 160 
 161   add_generation_memory_pool(heap->young_gen(), _major_gc_manager, _minor_gc_manager);
 162   add_generation_memory_pool(heap->old_gen(), _major_gc_manager);
 163 }
 164 
 165 #if INCLUDE_ALL_GCS
 166 // Add memory pools for ParallelScavengeHeap
 167 // This function currently only supports two generations collected heap.
 168 // The collector for ParallelScavengeHeap will have two memory managers.
 169 void MemoryService::add_parallel_scavenge_heap_info(ParallelScavengeHeap* heap) {
 170   // Two managers to keep statistics about _minor_gc_manager and _major_gc_manager GC.
 171   _minor_gc_manager = MemoryManager::get_psScavenge_memory_manager();
 172   _major_gc_manager = MemoryManager::get_psMarkSweep_memory_manager();
 173   _managers_list->append(_minor_gc_manager);
 174   _managers_list->append(_major_gc_manager);
 175 
 176   add_psYoung_memory_pool(heap->young_gen(), _major_gc_manager, _minor_gc_manager);
 177   add_psOld_memory_pool(heap->old_gen(), _major_gc_manager);
 178 }
 179 
 180 void MemoryService::add_g1_heap_info(G1CollectedHeap* g1h) {
 181   assert(UseG1GC, "sanity");
 182 
 183   _minor_gc_manager = MemoryManager::get_g1YoungGen_memory_manager();
 184   _major_gc_manager = MemoryManager::get_g1OldGen_memory_manager();
 185   _managers_list->append(_minor_gc_manager);
 186   _managers_list->append(_major_gc_manager);
 187 
 188   add_g1YoungGen_memory_pool(g1h, _major_gc_manager, _minor_gc_manager);
 189   add_g1OldGen_memory_pool(g1h, _major_gc_manager);
 190 }
 191 #endif // INCLUDE_ALL_GCS
 192 
 193 MemoryPool* MemoryService::add_gen(Generation* gen,
 194                                    const char* name,
 195                                    bool is_heap,
 196                                    bool support_usage_threshold) {
 197 
 198   MemoryPool::PoolType type = (is_heap ? MemoryPool::Heap : MemoryPool::NonHeap);
 199   GenerationPool* pool = new GenerationPool(gen, name, type, support_usage_threshold);
 200   _pools_list->append(pool);
 201   return (MemoryPool*) pool;
 202 }
 203 
 204 MemoryPool* MemoryService::add_space(ContiguousSpace* space,
 205                                      const char* name,
 206                                      bool is_heap,
 207                                      size_t max_size,
 208                                      bool support_usage_threshold) {
 209   MemoryPool::PoolType type = (is_heap ? MemoryPool::Heap : MemoryPool::NonHeap);
 210   ContiguousSpacePool* pool = new ContiguousSpacePool(space, name, type, max_size, support_usage_threshold);
 211 
 212   _pools_list->append(pool);
 213   return (MemoryPool*) pool;
 214 }
 215 
 216 MemoryPool* MemoryService::add_survivor_spaces(DefNewGeneration* young_gen,
 217                                                const char* name,
 218                                                bool is_heap,
 219                                                size_t max_size,
 220                                                bool support_usage_threshold) {
 221   MemoryPool::PoolType type = (is_heap ? MemoryPool::Heap : MemoryPool::NonHeap);
 222   SurvivorContiguousSpacePool* pool = new SurvivorContiguousSpacePool(young_gen, name, type, max_size, support_usage_threshold);
 223 
 224   _pools_list->append(pool);
 225   return (MemoryPool*) pool;
 226 }
 227 
 228 #if INCLUDE_ALL_GCS
 229 MemoryPool* MemoryService::add_cms_space(CompactibleFreeListSpace* space,
 230                                          const char* name,
 231                                          bool is_heap,
 232                                          size_t max_size,
 233                                          bool support_usage_threshold) {
 234   MemoryPool::PoolType type = (is_heap ? MemoryPool::Heap : MemoryPool::NonHeap);
 235   CompactibleFreeListSpacePool* pool = new CompactibleFreeListSpacePool(space, name, type, max_size, support_usage_threshold);
 236   _pools_list->append(pool);
 237   return (MemoryPool*) pool;
 238 }
 239 #endif // INCLUDE_ALL_GCS
 240 
 241 // Add memory pool(s) for one generation
 242 void MemoryService::add_generation_memory_pool(Generation* gen,
 243                                                MemoryManager* major_mgr,
 244                                                MemoryManager* minor_mgr) {
 245   guarantee(gen != NULL, "No generation for memory pool");
 246   Generation::Name kind = gen->kind();
 247   int index = _pools_list->length();
 248 
 249   switch (kind) {
 250     case Generation::DefNew: {
 251       assert(major_mgr != NULL && minor_mgr != NULL, "Should have two managers");
 252       DefNewGeneration* young_gen = (DefNewGeneration*) gen;
 253       // Add a memory pool for each space and young gen doesn't
 254       // support low memory detection as it is expected to get filled up.
 255       MemoryPool* eden = add_space(young_gen->eden(),
 256                                    "Eden Space",
 257                                    true, /* is_heap */
 258                                    young_gen->max_eden_size(),
 259                                    false /* support_usage_threshold */);
 260       MemoryPool* survivor = add_survivor_spaces(young_gen,
 261                                                  "Survivor Space",
 262                                                  true, /* is_heap */
 263                                                  young_gen->max_survivor_size(),
 264                                                  false /* support_usage_threshold */);
 265       break;
 266     }
 267 
 268 #if INCLUDE_ALL_GCS
 269     case Generation::ParNew:
 270     {
 271       assert(major_mgr != NULL && minor_mgr != NULL, "Should have two managers");
 272       // Add a memory pool for each space and young gen doesn't
 273       // support low memory detection as it is expected to get filled up.
 274       ParNewGeneration* parnew_gen = (ParNewGeneration*) gen;
 275       MemoryPool* eden = add_space(parnew_gen->eden(),
 276                                    "Par Eden Space",
 277                                    true /* is_heap */,
 278                                    parnew_gen->max_eden_size(),
 279                                    false /* support_usage_threshold */);
 280       MemoryPool* survivor = add_survivor_spaces(parnew_gen,
 281                                                  "Par Survivor Space",
 282                                                  true, /* is_heap */
 283                                                  parnew_gen->max_survivor_size(),
 284                                                  false /* support_usage_threshold */);
 285 
 286       break;
 287     }
 288 #endif // INCLUDE_ALL_GCS
 289 
 290     case Generation::MarkSweepCompact: {
 291       assert(major_mgr != NULL && minor_mgr == NULL, "Should have only one manager");
 292       add_gen(gen,
 293               "Tenured Gen",
 294               true, /* is_heap */
 295               true  /* support_usage_threshold */);
 296       break;
 297     }
 298 
 299 #if INCLUDE_ALL_GCS
 300     case Generation::ConcurrentMarkSweep:
 301     {
 302       assert(major_mgr != NULL && minor_mgr == NULL, "Should have only one manager");
 303       ConcurrentMarkSweepGeneration* cms = (ConcurrentMarkSweepGeneration*) gen;
 304       MemoryPool* pool = add_cms_space(cms->cmsSpace(),
 305                                        "CMS Old Gen",
 306                                        true, /* is_heap */
 307                                        cms->reserved().byte_size(),
 308                                        true  /* support_usage_threshold */);
 309       break;
 310     }
 311 #endif // INCLUDE_ALL_GCS
 312 
 313     default:
 314       assert(false, "should not reach here");
 315       // no memory pool added for others
 316       break;
 317   }
 318 
 319   assert(major_mgr != NULL, "Should have at least one manager");
 320   // Link managers and the memory pools together
 321   for (int i = index; i < _pools_list->length(); i++) {
 322     MemoryPool* pool = _pools_list->at(i);
 323     major_mgr->add_pool(pool);
 324     if (minor_mgr != NULL) {
 325       minor_mgr->add_pool(pool);
 326     }
 327   }
 328 }
 329 
 330 
 331 #if INCLUDE_ALL_GCS
 332 void MemoryService::add_psYoung_memory_pool(PSYoungGen* young_gen, MemoryManager* major_mgr, MemoryManager* minor_mgr) {
 333   assert(major_mgr != NULL && minor_mgr != NULL, "Should have two managers");
 334 
 335   // Add a memory pool for each space and young gen doesn't
 336   // support low memory detection as it is expected to get filled up.
 337   EdenMutableSpacePool* eden = new EdenMutableSpacePool(young_gen,
 338                                                         young_gen->eden_space(),
 339                                                         "PS Eden Space",
 340                                                         MemoryPool::Heap,
 341                                                         false /* support_usage_threshold */);
 342 
 343   SurvivorMutableSpacePool* survivor = new SurvivorMutableSpacePool(young_gen,
 344                                                                     "PS Survivor Space",
 345                                                                     MemoryPool::Heap,
 346                                                                     false /* support_usage_threshold */);
 347 
 348   major_mgr->add_pool(eden);
 349   major_mgr->add_pool(survivor);
 350   minor_mgr->add_pool(eden);
 351   minor_mgr->add_pool(survivor);
 352   _pools_list->append(eden);
 353   _pools_list->append(survivor);
 354 }
 355 
 356 void MemoryService::add_psOld_memory_pool(PSOldGen* old_gen, MemoryManager* mgr) {
 357   PSGenerationPool* old_gen_pool = new PSGenerationPool(old_gen,
 358                                                        "PS Old Gen",
 359                                                        MemoryPool::Heap,
 360                                                        true /* support_usage_threshold */);
 361   mgr->add_pool(old_gen_pool);
 362   _pools_list->append(old_gen_pool);
 363 }
 364 
 365 void MemoryService::add_g1YoungGen_memory_pool(G1CollectedHeap* g1h,
 366                                                MemoryManager* major_mgr,
 367                                                MemoryManager* minor_mgr) {
 368   assert(major_mgr != NULL && minor_mgr != NULL, "should have two managers");
 369 
 370   G1EdenPool* eden = new G1EdenPool(g1h);
 371   G1SurvivorPool* survivor = new G1SurvivorPool(g1h);
 372 
 373   major_mgr->add_pool(eden);
 374   major_mgr->add_pool(survivor);
 375   minor_mgr->add_pool(eden);
 376   minor_mgr->add_pool(survivor);
 377   _pools_list->append(eden);
 378   _pools_list->append(survivor);
 379 }
 380 
 381 void MemoryService::add_g1OldGen_memory_pool(G1CollectedHeap* g1h,
 382                                              MemoryManager* mgr) {
 383   assert(mgr != NULL, "should have one manager");
 384 
 385   G1OldGenPool* old_gen = new G1OldGenPool(g1h);
 386   mgr->add_pool(old_gen);
 387   _pools_list->append(old_gen);
 388 }
 389 #endif // INCLUDE_ALL_GCS
 390 
 391 void MemoryService::add_code_heap_memory_pool(CodeHeap* heap, const char* name) {
 392   // Create new memory pool for this heap
 393   MemoryPool* code_heap_pool = new CodeHeapPool(heap, name, true /* support_usage_threshold */);
 394 
 395   // Append to lists
 396   _code_heap_pools->append(code_heap_pool);
 397   _pools_list->append(code_heap_pool);
 398 
 399   if (_code_cache_manager == NULL) {
 400     // Create CodeCache memory manager
 401     _code_cache_manager = MemoryManager::get_code_cache_memory_manager();
 402     _managers_list->append(_code_cache_manager);
 403   }
 404 
 405   _code_cache_manager->add_pool(code_heap_pool);
 406 }
 407 
 408 void MemoryService::add_metaspace_memory_pools() {
 409   MemoryManager* mgr = MemoryManager::get_metaspace_memory_manager();




   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/systemDictionary.hpp"
  27 #include "classfile/vmSymbols.hpp"
  28 #include "gc/shared/gcServicabilitySupport.hpp"




  29 #include "gc/shared/generation.hpp"

  30 #include "logging/logConfiguration.hpp"
  31 #include "memory/heap.hpp"
  32 #include "memory/memRegion.hpp"
  33 #include "oops/oop.inline.hpp"
  34 #include "runtime/globals.hpp"
  35 #include "runtime/javaCalls.hpp"
  36 #include "services/classLoadingService.hpp"
  37 #include "services/lowMemoryDetector.hpp"
  38 #include "services/management.hpp"
  39 #include "services/memoryManager.hpp"
  40 #include "services/memoryPool.hpp"
  41 #include "services/memoryService.hpp"
  42 #include "utilities/growableArray.hpp"
  43 #include "utilities/macros.hpp"










  44 
  45 GrowableArray<MemoryPool*>* MemoryService::_pools_list =
  46   new (ResourceObj::C_HEAP, mtInternal) GrowableArray<MemoryPool*>(init_pools_list_size, true);
  47 GrowableArray<MemoryManager*>* MemoryService::_managers_list =
  48   new (ResourceObj::C_HEAP, mtInternal) GrowableArray<MemoryManager*>(init_managers_list_size, true);
  49 
  50 GCMemoryManager* MemoryService::_minor_gc_manager      = NULL;
  51 GCMemoryManager* MemoryService::_major_gc_manager      = NULL;
  52 MemoryManager*   MemoryService::_code_cache_manager    = NULL;
  53 GrowableArray<MemoryPool*>* MemoryService::_code_heap_pools =
  54     new (ResourceObj::C_HEAP, mtInternal) GrowableArray<MemoryPool*>(init_code_heap_pools_size, true);
  55 MemoryPool*      MemoryService::_metaspace_pool        = NULL;
  56 MemoryPool*      MemoryService::_compressed_class_pool = NULL;
  57 
  58 class GcThreadCountClosure: public ThreadClosure {
  59  private:
  60   int _count;
  61  public:
  62   GcThreadCountClosure() : _count(0) {};
  63   void do_thread(Thread* thread);
  64   int count() { return _count; }
  65 };
  66 
  67 void GcThreadCountClosure::do_thread(Thread* thread) {
  68   _count++;
  69 }
  70 
  71 void MemoryService::set_universe_heap(CollectedHeap* heap) {
  72   _minor_gc_manager = GC::gc()->servicability_support()->create_minor_gc_manager();
  73   _major_gc_manager = GC::gc()->servicability_support()->create_major_gc_manager();
  74   _managers_list->append(_minor_gc_manager);
  75   _managers_list->append(_major_gc_manager);
  76 
  77   GC::gc()->servicability_support()->add_memory_pools(_pools_list,
  78                                                       _minor_gc_manager,
  79                                                       _major_gc_manager);












  80 
  81   // set the GC thread count
  82   GcThreadCountClosure gctcc;
  83   heap->gc_threads_do(&gctcc);
  84   int count = gctcc.count();
  85   if (count > 0) {
  86     _minor_gc_manager->set_num_gc_threads(count);
  87     _major_gc_manager->set_num_gc_threads(count);
  88   }
  89 
  90   // All memory pools and memory managers are initialized.
  91   //
  92   _minor_gc_manager->initialize_gc_stat_info();
  93   _major_gc_manager->initialize_gc_stat_info();
  94 }












































































































































































































































































  95 
  96 void MemoryService::add_code_heap_memory_pool(CodeHeap* heap, const char* name) {
  97   // Create new memory pool for this heap
  98   MemoryPool* code_heap_pool = new CodeHeapPool(heap, name, true /* support_usage_threshold */);
  99 
 100   // Append to lists
 101   _code_heap_pools->append(code_heap_pool);
 102   _pools_list->append(code_heap_pool);
 103 
 104   if (_code_cache_manager == NULL) {
 105     // Create CodeCache memory manager
 106     _code_cache_manager = MemoryManager::get_code_cache_memory_manager();
 107     _managers_list->append(_code_cache_manager);
 108   }
 109 
 110   _code_cache_manager->add_pool(code_heap_pool);
 111 }
 112 
 113 void MemoryService::add_metaspace_memory_pools() {
 114   MemoryManager* mgr = MemoryManager::get_metaspace_memory_manager();


< prev index next >