parallelScavengeHeap.hpp 8.8 KB
Newer Older
D
duke 已提交
1
/*
S
sla 已提交
2
 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
22 23 24
 *
 */

25 26 27
#ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PARALLELSCAVENGEHEAP_HPP
#define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PARALLELSCAVENGEHEAP_HPP

28
#include "gc_implementation/parallelScavenge/generationSizer.hpp"
29 30 31 32 33
#include "gc_implementation/parallelScavenge/objectStartArray.hpp"
#include "gc_implementation/parallelScavenge/psGCAdaptivePolicyCounters.hpp"
#include "gc_implementation/parallelScavenge/psOldGen.hpp"
#include "gc_implementation/parallelScavenge/psYoungGen.hpp"
#include "gc_implementation/shared/gcPolicyCounters.hpp"
S
sla 已提交
34
#include "gc_implementation/shared/gcWhen.hpp"
35
#include "gc_interface/collectedHeap.inline.hpp"
36
#include "memory/collectorPolicy.hpp"
37 38
#include "utilities/ostream.hpp"

D
duke 已提交
39
class AdjoiningGenerations;
S
sla 已提交
40
class GCHeapSummary;
D
duke 已提交
41
class GCTaskManager;
S
sla 已提交
42 43
class PSAdaptiveSizePolicy;
class PSHeapSummary;
D
duke 已提交
44 45 46 47 48 49 50 51

class ParallelScavengeHeap : public CollectedHeap {
  friend class VMStructs;
 private:
  static PSYoungGen* _young_gen;
  static PSOldGen*   _old_gen;

  // Sizing policy for entire heap
52 53
  static PSAdaptiveSizePolicy*       _size_policy;
  static PSGCAdaptivePolicyCounters* _gc_policy_counters;
D
duke 已提交
54 55 56

  static ParallelScavengeHeap* _psh;

57 58
  GenerationSizer* _collector_policy;

D
duke 已提交
59 60 61
  // Collection of generations that are adjacent in the
  // space reserved for the heap.
  AdjoiningGenerations* _gens;
62
  unsigned int _death_march_count;
D
duke 已提交
63

64 65
  // The task manager
  static GCTaskManager* _gc_task_manager;
D
duke 已提交
66

S
sla 已提交
67 68
  void trace_heap(GCWhen::Type when, GCTracer* tracer);

D
duke 已提交
69 70 71 72
 protected:
  static inline size_t total_invocations();
  HeapWord* allocate_new_tlab(size_t size);

73 74 75 76
  inline bool should_alloc_in_eden(size_t size) const;
  inline void death_march_check(HeapWord* const result, size_t size);
  HeapWord* mem_allocate_old_gen(size_t size);

D
duke 已提交
77
 public:
78
  ParallelScavengeHeap() : CollectedHeap(), _death_march_count(0) { }
79

D
duke 已提交
80 81 82 83 84 85 86 87 88 89
  // For use by VM operations
  enum CollectionType {
    Scavenge,
    MarkSweep
  };

  ParallelScavengeHeap::Name kind() const {
    return CollectedHeap::ParallelScavengeHeap;
  }

90
  virtual CollectorPolicy* collector_policy() const { return (CollectorPolicy*) _collector_policy; }
91

92 93
  static PSYoungGen* young_gen() { return _young_gen; }
  static PSOldGen* old_gen()     { return _old_gen; }
D
duke 已提交
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110

  virtual PSAdaptiveSizePolicy* size_policy() { return _size_policy; }

  static PSGCAdaptivePolicyCounters* gc_policy_counters() { return _gc_policy_counters; }

  static ParallelScavengeHeap* heap();

  static GCTaskManager* const gc_task_manager() { return _gc_task_manager; }

  AdjoiningGenerations* gens() { return _gens; }

  // Returns JNI_OK on success
  virtual jint initialize();

  void post_initialize();
  void update_counters();

111 112 113 114 115 116 117 118
  // The alignment used for the various areas
  size_t space_alignment()      { return _collector_policy->space_alignment(); }
  size_t generation_alignment() { return _collector_policy->gen_alignment(); }

  // Return the (conservative) maximum heap alignment
  static size_t conservative_max_heap_alignment() {
    return CollectorPolicy::compute_heap_alignment();
  }
D
duke 已提交
119 120 121 122

  size_t capacity() const;
  size_t used() const;

123
  // Return "true" if all generations have reached the
D
duke 已提交
124 125 126 127
  // maximal committed limit that they can reach, without a garbage
  // collection.
  virtual bool is_maximal_no_gc() const;

128 129 130 131 132 133
  // Return true if the reference points to an object that
  // can be moved in a partial collection.  For currently implemented
  // generational collectors that means during a collection of
  // the young gen.
  virtual bool is_scavengable(const void* addr);

D
duke 已提交
134 135 136 137 138 139 140 141 142 143
  // Does this heap support heap inspection? (+PrintClassHistogram)
  bool supports_heap_inspection() const { return true; }

  size_t max_capacity() const;

  // Whether p is in the allocated part of the heap
  bool is_in(const void* p) const;

  bool is_in_reserved(const void* p) const;

144 145 146 147
#ifdef ASSERT
  virtual bool is_in_partial_collection(const void *p);
#endif

148 149
  bool is_in_young(oop p);  // reserved part
  bool is_in_old(oop p);    // reserved part
D
duke 已提交
150 151 152 153 154 155

  // Memory allocation.   "gc_time_limit_was_exceeded" will
  // be set to true if the adaptive size policy determine that
  // an excessive amount of time is being spent doing collections
  // and caused a NULL to be returned.  If a NULL is not returned,
  // "gc_time_limit_was_exceeded" has an undefined meaning.
156
  HeapWord* mem_allocate(size_t size, bool* gc_overhead_limit_was_exceeded);
157 158 159 160 161

  // Allocation attempt(s) during a safepoint. It should never be called
  // to allocate a new TLAB as this allocation might be satisfied out
  // of the old generation.
  HeapWord* failed_mem_allocate(size_t size);
D
duke 已提交
162 163 164 165 166 167 168 169 170 171 172 173

  // Support for System.gc()
  void collect(GCCause::Cause cause);

  // These also should be called by the vm thread at a safepoint (e.g., from a
  // VM operation).
  //
  // The first collects the young generation only, unless the scavenge fails; it
  // will then attempt a full gc.  The second collects the entire heap; if
  // maximum_compaction is true, it will compact everything and clear all soft
  // references.
  inline void invoke_scavenge();
174 175 176

  // Perform a full collection
  virtual void do_full_collection(bool clear_all_soft_refs);
D
duke 已提交
177 178

  bool supports_inline_contig_alloc() const { return !UseNUMA; }
179 180 181

  HeapWord** top_addr() const { return !UseNUMA ? young_gen()->top_addr() : (HeapWord**)-1; }
  HeapWord** end_addr() const { return !UseNUMA ? young_gen()->end_addr() : (HeapWord**)-1; }
D
duke 已提交
182 183 184 185 186 187 188 189

  void ensure_parsability(bool retire_tlabs);
  void accumulate_statistics_all_tlabs();
  void resize_all_tlabs();

  bool supports_tlab_allocation() const { return true; }

  size_t tlab_capacity(Thread* thr) const;
B
brutisso 已提交
190
  size_t tlab_used(Thread* thr) const;
D
duke 已提交
191 192
  size_t unsafe_max_tlab_alloc(Thread* thr) const;

193 194 195 196 197 198 199
  // Can a compiler initialize a new object without store barriers?
  // This permission only extends from the creation of a new object
  // via a TLAB up to the first subsequent safepoint.
  virtual bool can_elide_tlab_store_barriers() const {
    return true;
  }

200 201 202 203
  virtual bool card_mark_must_follow_store() const {
    return false;
  }

204 205 206 207
  // Return true if we don't we need a store barrier for
  // initializing stores to an object at this address.
  virtual bool can_elide_initializing_store_barrier(oop new_obj);

208
  void oop_iterate(ExtendedOopClosure* cl);
D
duke 已提交
209
  void object_iterate(ObjectClosure* cl);
210
  void safe_object_iterate(ObjectClosure* cl) { object_iterate(cl); }
D
duke 已提交
211 212 213 214 215 216 217 218

  HeapWord* block_start(const void* addr) const;
  size_t block_size(const HeapWord* addr) const;
  bool block_is_obj(const HeapWord* addr) const;

  jlong millis_since_last_gc();

  void prepare_for_verify();
S
sla 已提交
219
  PSHeapSummary create_ps_heap_summary();
220
  virtual void print_on(outputStream* st) const;
221
  virtual void print_on_error(outputStream* st) const;
D
duke 已提交
222 223 224 225
  virtual void print_gc_threads_on(outputStream* st) const;
  virtual void gc_threads_do(ThreadClosure* tc) const;
  virtual void print_tracing_info() const;

226
  void verify(bool silent, VerifyOption option /* ignored */);
D
duke 已提交
227 228 229 230 231 232 233 234 235 236

  void print_heap_change(size_t prev_used);

  // Resize the young generation.  The reserved space for the
  // generation may be expanded in preparation for the resize.
  void resize_young_gen(size_t eden_size, size_t survivor_size);

  // Resize the old generation.  The reserved space for the
  // generation may be expanded in preparation for the resize.
  void resize_old_gen(size_t desired_free_space);
237 238 239 240 241 242

  // Save the tops of the spaces in all generations
  void record_gen_tops_before_GC() PRODUCT_RETURN;

  // Mangle the unused parts of all spaces in the heap
  void gen_mangle_unused_area() PRODUCT_RETURN;
243 244 245

  // Call these in sequential code around the processing of strong roots.
  class ParStrongRootsScope : public MarkingCodeBlobClosure::MarkScope {
246
   public:
247 248 249
    ParStrongRootsScope();
    ~ParStrongRootsScope();
  };
D
duke 已提交
250 251
};

252
#endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PARALLELSCAVENGEHEAP_HPP