1 /*
   2  * Copyright (c) 2017, Red Hat, Inc. and/or its affiliates.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   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 "gc/serial/defNewGeneration.hpp"
  27 #include "gc/serial/serialGCServicabilitySupport.hpp"
  28 #include "gc/shared/genCollectedHeap.hpp"
  29 #include "services/memoryManager.hpp"
  30 #include "services/memoryPool.hpp"
  31 
  32 class CopyMemoryManager : public GCMemoryManager {
  33 private:
  34 public:
  35   CopyMemoryManager() : GCMemoryManager() {}
  36 
  37   const char* name() { return "Copy"; }
  38 };
  39 
  40 class MSCMemoryManager : public GCMemoryManager {
  41 private:
  42 public:
  43   MSCMemoryManager() : GCMemoryManager() {}
  44 
  45   const char* name() { return "MarkSweepCompact"; }
  46 };
  47 
  48 GCMemoryManager* SerialGCServicabilitySupport::create_minor_gc_manager() {
  49   return new CopyMemoryManager();
  50 }
  51 
  52 GCMemoryManager* SerialGCServicabilitySupport::create_major_gc_manager() {
  53   return new MSCMemoryManager();
  54 }
  55 
  56 void SerialGCServicabilitySupport::add_memory_pools(GrowableArray<MemoryPool*>* pools_list,
  57                                                     GCMemoryManager* minor_mgr,
  58                                                     GCMemoryManager* major_mgr) {
  59   GenCollectedHeap* heap = GenCollectedHeap::heap();
  60   DefNewGeneration* young_gen = (DefNewGeneration*) heap->young_gen();
  61 
  62   // Add a memory pool for each space and young gen doesn't
  63   // support low memory detection as it is expected to get filled up.
  64   MemoryPool* eden = new ContiguousSpacePool(young_gen->eden(),
  65                                              "Eden Space",
  66                                              MemoryPool::Heap,
  67                                              young_gen->max_eden_size(),
  68                                              false /* support_usage_threshold */);
  69   MemoryPool* survivor = new SurvivorContiguousSpacePool(young_gen,
  70                                                          "Survivor Space",
  71                                                          MemoryPool::Heap,
  72                                                          young_gen->max_survivor_size(),
  73                                                          false /* support_usage_threshold */);
  74   GenerationPool* old = new GenerationPool(heap->old_gen(), "Tenured Gen", MemoryPool::Heap, true);
  75 
  76   pools_list->append(eden);
  77   pools_list->append(survivor);
  78   pools_list->append(old);
  79 
  80   minor_mgr->add_pool(eden);
  81   minor_mgr->add_pool(survivor);
  82 
  83   major_mgr->add_pool(eden);
  84   major_mgr->add_pool(survivor);
  85   major_mgr->add_pool(old);
  86 }