src/hotspot/share/gc/cms/cmsHeap.cpp
author stefank
Mon, 07 May 2018 14:42:05 +0200
changeset 50033 000c697c81db
parent 49734 f946776e9354
child 50297 580744d900c8
permissions -rw-r--r--
8202639: Use concrete Generation classes in SerialHeap and CMSHeap Reviewed-by: eosterlund, ehelin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47622
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
     1
/*
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
     4
 *
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
     8
 *
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    13
 * accompanied this code).
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    14
 *
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    18
 *
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    21
 * questions.
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    22
 *
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    23
 */
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    24
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    25
#include "precompiled.hpp"
49733
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49628
diff changeset
    26
#include "gc/cms/cmsCardTable.hpp"
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    27
#include "gc/cms/compactibleFreeListSpace.hpp"
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    28
#include "gc/cms/concurrentMarkSweepGeneration.hpp"
47622
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    29
#include "gc/cms/concurrentMarkSweepThread.hpp"
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    30
#include "gc/cms/cmsHeap.hpp"
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    31
#include "gc/cms/parNewGeneration.hpp"
47622
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    32
#include "gc/cms/vmCMSOperations.hpp"
49734
f946776e9354 8201244: Clean out unnecessary includes of heap headers
stefank
parents: 49733
diff changeset
    33
#include "gc/shared/genCollectedHeap.hpp"
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    34
#include "gc/shared/genMemoryPools.hpp"
47622
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    35
#include "gc/shared/genOopClosures.inline.hpp"
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    36
#include "gc/shared/strongRootsScope.hpp"
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    37
#include "gc/shared/workgroup.hpp"
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    38
#include "oops/oop.inline.hpp"
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    39
#include "runtime/vmThread.hpp"
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    40
#include "services/memoryManager.hpp"
47622
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    41
#include "utilities/stack.inline.hpp"
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    42
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    43
class CompactibleFreeListSpacePool : public CollectedMemoryPool {
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    44
private:
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    45
  CompactibleFreeListSpace* _space;
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    46
public:
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    47
  CompactibleFreeListSpacePool(CompactibleFreeListSpace* space,
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    48
                               const char* name,
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    49
                               size_t max_size,
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    50
                               bool support_usage_threshold) :
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    51
    CollectedMemoryPool(name, space->capacity(), max_size, support_usage_threshold),
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    52
    _space(space) {
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    53
  }
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    54
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    55
  MemoryUsage get_memory_usage() {
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    56
    size_t max_heap_size   = (available_for_allocation() ? max_size() : 0);
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    57
    size_t used      = used_in_bytes();
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    58
    size_t committed = _space->capacity();
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    59
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    60
    return MemoryUsage(initial_size(), used, committed, max_heap_size);
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    61
  }
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    62
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    63
  size_t used_in_bytes() {
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    64
    return _space->used();
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    65
  }
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    66
};
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    67
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    68
CMSHeap::CMSHeap(GenCollectorPolicy *policy) :
49049
effb50eeea4e 8198528: Move GenerationSpecs from GenCollectorPolicy to GenCollectedHeap
stefank
parents: 49043
diff changeset
    69
    GenCollectedHeap(policy,
effb50eeea4e 8198528: Move GenerationSpecs from GenCollectorPolicy to GenCollectedHeap
stefank
parents: 49043
diff changeset
    70
                     Generation::ParNew,
49050
170c7b36aea6 8198530: Move _gc_policy_counters from GenCollectorPolicy to GenCollectedHeap
stefank
parents: 49049
diff changeset
    71
                     Generation::ConcurrentMarkSweep,
170c7b36aea6 8198530: Move _gc_policy_counters from GenCollectorPolicy to GenCollectedHeap
stefank
parents: 49049
diff changeset
    72
                     "ParNew::CMS"),
49049
effb50eeea4e 8198528: Move GenerationSpecs from GenCollectorPolicy to GenCollectedHeap
stefank
parents: 49043
diff changeset
    73
    _eden_pool(NULL),
effb50eeea4e 8198528: Move GenerationSpecs from GenCollectorPolicy to GenCollectedHeap
stefank
parents: 49043
diff changeset
    74
    _survivor_pool(NULL),
effb50eeea4e 8198528: Move GenerationSpecs from GenCollectorPolicy to GenCollectedHeap
stefank
parents: 49043
diff changeset
    75
    _old_pool(NULL) {
47622
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    76
  _workers = new WorkGang("GC Thread", ParallelGCThreads,
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    77
                          /* are_GC_task_threads */true,
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    78
                          /* are_ConcurrentGC_threads */false);
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    79
  _workers->initialize_workers();
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    80
}
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    81
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    82
jint CMSHeap::initialize() {
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    83
  jint status = GenCollectedHeap::initialize();
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    84
  if (status != JNI_OK) return status;
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    85
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    86
  // If we are running CMS, create the collector responsible
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    87
  // for collecting the CMS generations.
47657
28b2dbe488f1 8189390: Assert in TestOptionsWithRanges.java
sangheki
parents: 47636
diff changeset
    88
  if (!create_cms_collector()) {
28b2dbe488f1 8189390: Assert in TestOptionsWithRanges.java
sangheki
parents: 47636
diff changeset
    89
    return JNI_ENOMEM;
28b2dbe488f1 8189390: Assert in TestOptionsWithRanges.java
sangheki
parents: 47636
diff changeset
    90
  }
47622
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    91
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    92
  return JNI_OK;
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    93
}
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
    94
49733
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49628
diff changeset
    95
CardTableRS* CMSHeap::create_rem_set(const MemRegion& reserved_region) {
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49628
diff changeset
    96
  return new CMSCardTable(reserved_region);
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49628
diff changeset
    97
}
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49628
diff changeset
    98
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
    99
void CMSHeap::initialize_serviceability() {
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   100
  _young_manager = new GCMemoryManager("ParNew", "end of minor GC");
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   101
  _old_manager = new GCMemoryManager("ConcurrentMarkSweep", "end of major GC");
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   102
50033
000c697c81db 8202639: Use concrete Generation classes in SerialHeap and CMSHeap
stefank
parents: 49734
diff changeset
   103
  ParNewGeneration* young = young_gen();
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   104
  _eden_pool = new ContiguousSpacePool(young->eden(),
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   105
                                       "Par Eden Space",
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   106
                                       young->max_eden_size(),
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   107
                                       false);
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   108
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   109
  _survivor_pool = new SurvivorContiguousSpacePool(young,
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   110
                                                   "Par Survivor Space",
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   111
                                                   young->max_survivor_size(),
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   112
                                                   false);
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   113
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   114
  ConcurrentMarkSweepGeneration* old = (ConcurrentMarkSweepGeneration*) old_gen();
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   115
  _old_pool = new CompactibleFreeListSpacePool(old->cmsSpace(),
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   116
                                               "CMS Old Gen",
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   117
                                               old->reserved().byte_size(),
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   118
                                               true);
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   119
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   120
  _young_manager->add_pool(_eden_pool);
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   121
  _young_manager->add_pool(_survivor_pool);
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   122
  young->set_gc_manager(_young_manager);
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   123
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   124
  _old_manager->add_pool(_eden_pool);
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   125
  _old_manager->add_pool(_survivor_pool);
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   126
  _old_manager->add_pool(_old_pool);
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   127
  old ->set_gc_manager(_old_manager);
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   128
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   129
}
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   130
47622
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   131
CMSHeap* CMSHeap::heap() {
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   132
  CollectedHeap* heap = Universe::heap();
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   133
  assert(heap != NULL, "Uninitialized access to CMSHeap::heap()");
49628
88478047bc8f 8199918: Shorten names of CollectedHeap::Name members
pliden
parents: 49050
diff changeset
   134
  assert(heap->kind() == CollectedHeap::CMS, "Invalid name");
50033
000c697c81db 8202639: Use concrete Generation classes in SerialHeap and CMSHeap
stefank
parents: 49734
diff changeset
   135
  return static_cast<CMSHeap*>(heap);
47622
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   136
}
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   137
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   138
void CMSHeap::gc_threads_do(ThreadClosure* tc) const {
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   139
  assert(workers() != NULL, "should have workers here");
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   140
  workers()->threads_do(tc);
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   141
  ConcurrentMarkSweepThread::threads_do(tc);
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   142
}
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   143
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   144
void CMSHeap::print_gc_threads_on(outputStream* st) const {
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   145
  assert(workers() != NULL, "should have workers here");
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   146
  workers()->print_worker_threads_on(st);
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   147
  ConcurrentMarkSweepThread::print_all_on(st);
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   148
}
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   149
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   150
void CMSHeap::print_on_error(outputStream* st) const {
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   151
  GenCollectedHeap::print_on_error(st);
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   152
  st->cr();
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   153
  CMSCollector::print_on_error(st);
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   154
}
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   155
47657
28b2dbe488f1 8189390: Assert in TestOptionsWithRanges.java
sangheki
parents: 47636
diff changeset
   156
bool CMSHeap::create_cms_collector() {
47622
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   157
  assert(old_gen()->kind() == Generation::ConcurrentMarkSweep,
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   158
         "Unexpected generation kinds");
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   159
  CMSCollector* collector =
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   160
    new CMSCollector((ConcurrentMarkSweepGeneration*) old_gen(),
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   161
                     rem_set(),
49043
092dc3d38bdc 8198373: Remove CollectorPolicy::is/as functions
stefank
parents: 48168
diff changeset
   162
                     (ConcurrentMarkSweepPolicy*) gen_policy());
47622
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   163
47657
28b2dbe488f1 8189390: Assert in TestOptionsWithRanges.java
sangheki
parents: 47636
diff changeset
   164
  if (collector == NULL || !collector->completed_initialization()) {
28b2dbe488f1 8189390: Assert in TestOptionsWithRanges.java
sangheki
parents: 47636
diff changeset
   165
    if (collector) {
28b2dbe488f1 8189390: Assert in TestOptionsWithRanges.java
sangheki
parents: 47636
diff changeset
   166
      delete collector; // Be nice in embedded situation
28b2dbe488f1 8189390: Assert in TestOptionsWithRanges.java
sangheki
parents: 47636
diff changeset
   167
    }
47622
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   168
    vm_shutdown_during_initialization("Could not create CMS collector");
47657
28b2dbe488f1 8189390: Assert in TestOptionsWithRanges.java
sangheki
parents: 47636
diff changeset
   169
    return false;
47622
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   170
  }
47657
28b2dbe488f1 8189390: Assert in TestOptionsWithRanges.java
sangheki
parents: 47636
diff changeset
   171
  return true; // success
47622
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   172
}
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   173
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   174
void CMSHeap::collect(GCCause::Cause cause) {
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   175
  if (should_do_concurrent_full_gc(cause)) {
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   176
    // Mostly concurrent full collection.
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   177
    collect_mostly_concurrent(cause);
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   178
  } else {
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   179
    GenCollectedHeap::collect(cause);
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   180
  }
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   181
}
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   182
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   183
bool CMSHeap::should_do_concurrent_full_gc(GCCause::Cause cause) {
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   184
  switch (cause) {
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   185
    case GCCause::_gc_locker:           return GCLockerInvokesConcurrent;
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   186
    case GCCause::_java_lang_system_gc:
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   187
    case GCCause::_dcmd_gc_run:         return ExplicitGCInvokesConcurrent;
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   188
    default:                            return false;
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   189
  }
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   190
}
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   191
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   192
void CMSHeap::collect_mostly_concurrent(GCCause::Cause cause) {
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   193
  assert(!Heap_lock->owned_by_self(), "Should not own Heap_lock");
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   194
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   195
  MutexLocker ml(Heap_lock);
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   196
  // Read the GC counts while holding the Heap_lock
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   197
  unsigned int full_gc_count_before = total_full_collections();
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   198
  unsigned int gc_count_before      = total_collections();
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   199
  {
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   200
    MutexUnlocker mu(Heap_lock);
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   201
    VM_GenCollectFullConcurrent op(gc_count_before, full_gc_count_before, cause);
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   202
    VMThread::execute(&op);
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   203
  }
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   204
}
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   205
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   206
void CMSHeap::stop() {
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   207
  ConcurrentMarkSweepThread::cmst()->stop();
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   208
}
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   209
47636
52d46d7e3454 8188919: Generalize GC thread suspend/resume at safepoints
eosterlund
parents: 47622
diff changeset
   210
void CMSHeap::safepoint_synchronize_begin() {
52d46d7e3454 8188919: Generalize GC thread suspend/resume at safepoints
eosterlund
parents: 47622
diff changeset
   211
  ConcurrentMarkSweepThread::synchronize(false);
52d46d7e3454 8188919: Generalize GC thread suspend/resume at safepoints
eosterlund
parents: 47622
diff changeset
   212
}
52d46d7e3454 8188919: Generalize GC thread suspend/resume at safepoints
eosterlund
parents: 47622
diff changeset
   213
52d46d7e3454 8188919: Generalize GC thread suspend/resume at safepoints
eosterlund
parents: 47622
diff changeset
   214
void CMSHeap::safepoint_synchronize_end() {
52d46d7e3454 8188919: Generalize GC thread suspend/resume at safepoints
eosterlund
parents: 47622
diff changeset
   215
  ConcurrentMarkSweepThread::desynchronize(false);
52d46d7e3454 8188919: Generalize GC thread suspend/resume at safepoints
eosterlund
parents: 47622
diff changeset
   216
}
52d46d7e3454 8188919: Generalize GC thread suspend/resume at safepoints
eosterlund
parents: 47622
diff changeset
   217
47622
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   218
void CMSHeap::cms_process_roots(StrongRootsScope* scope,
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   219
                                bool young_gen_as_roots,
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   220
                                ScanningOption so,
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   221
                                bool only_strong_roots,
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   222
                                OopsInGenClosure* root_closure,
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   223
                                CLDClosure* cld_closure) {
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   224
  MarkingCodeBlobClosure mark_code_closure(root_closure, !CodeBlobToOopClosure::FixRelocations);
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   225
  OopsInGenClosure* weak_roots = only_strong_roots ? NULL : root_closure;
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   226
  CLDClosure* weak_cld_closure = only_strong_roots ? NULL : cld_closure;
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   227
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   228
  process_roots(scope, so, root_closure, weak_roots, cld_closure, weak_cld_closure, &mark_code_closure);
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   229
  if (!only_strong_roots) {
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   230
    process_string_table_roots(scope, root_closure);
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   231
  }
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   232
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   233
  if (young_gen_as_roots &&
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   234
      !_process_strong_tasks->is_task_claimed(GCH_PS_younger_gens)) {
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   235
    root_closure->set_generation(young_gen());
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   236
    young_gen()->oop_iterate(root_closure);
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   237
    root_closure->reset_generation();
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   238
  }
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   239
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   240
  _process_strong_tasks->all_tasks_completed(scope->n_threads());
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   241
}
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   242
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   243
void CMSHeap::gc_prologue(bool full) {
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   244
  always_do_update_barrier = false;
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   245
  GenCollectedHeap::gc_prologue(full);
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   246
};
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   247
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   248
void CMSHeap::gc_epilogue(bool full) {
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   249
  GenCollectedHeap::gc_epilogue(full);
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   250
  always_do_update_barrier = true;
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents:
diff changeset
   251
};
48168
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   252
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   253
GrowableArray<GCMemoryManager*> CMSHeap::memory_managers() {
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   254
  GrowableArray<GCMemoryManager*> memory_managers(2);
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   255
  memory_managers.append(_young_manager);
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   256
  memory_managers.append(_old_manager);
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   257
  return memory_managers;
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   258
}
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   259
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   260
GrowableArray<MemoryPool*> CMSHeap::memory_pools() {
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   261
  GrowableArray<MemoryPool*> memory_pools(3);
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   262
  memory_pools.append(_eden_pool);
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   263
  memory_pools.append(_survivor_pool);
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   264
  memory_pools.append(_old_pool);
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   265
  return memory_pools;
cb5d2d4453d0 8191564: Refactor GC related servicability code into GC specific subclasses
rkennke
parents: 47657
diff changeset
   266
}