src/share/vm/gc_interface/collectedHeap.hpp

Thu, 15 Aug 2013 10:52:18 +0200

author
johnc
date
Thu, 15 Aug 2013 10:52:18 +0200
changeset 5548
5888334c9c24
parent 5237
f2110083203d
child 5863
85c1ca43713f
permissions
-rw-r--r--

7145569: G1: optimize nmethods scanning
Summary: Add a list of nmethods to the RSet for a region that contain references into the region. Skip scanning the code cache during root scanning and scan the nmethod lists during RSet scanning instead.
Reviewed-by: tschatzl, brutisso, mgerdin, twisti, kvn

duke@435 1 /*
sla@5237 2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_HPP
stefank@2314 26 #define SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_HPP
stefank@2314 27
stefank@2314 28 #include "gc_interface/gcCause.hpp"
sla@5237 29 #include "gc_implementation/shared/gcWhen.hpp"
stefank@2314 30 #include "memory/allocation.hpp"
stefank@2314 31 #include "memory/barrierSet.hpp"
stefank@2314 32 #include "runtime/handles.hpp"
stefank@2314 33 #include "runtime/perfData.hpp"
stefank@2314 34 #include "runtime/safepoint.hpp"
never@3499 35 #include "utilities/events.hpp"
stefank@2314 36
duke@435 37 // A "CollectedHeap" is an implementation of a java heap for HotSpot. This
duke@435 38 // is an abstract class: there may be many different kinds of heaps. This
duke@435 39 // class defines the functions that a heap must implement, and contains
duke@435 40 // infrastructure common to all heaps.
duke@435 41
sla@5237 42 class AdaptiveSizePolicy;
duke@435 43 class BarrierSet;
sla@5237 44 class CollectorPolicy;
sla@5237 45 class GCHeapSummary;
sla@5237 46 class GCTimer;
sla@5237 47 class GCTracer;
sla@5237 48 class MetaspaceSummary;
sla@5237 49 class Thread;
duke@435 50 class ThreadClosure;
sla@5237 51 class VirtualSpaceSummary;
johnc@5548 52 class nmethod;
duke@435 53
never@3499 54 class GCMessage : public FormatBuffer<1024> {
never@3499 55 public:
never@3499 56 bool is_before;
never@3499 57
never@3499 58 public:
never@3499 59 GCMessage() {}
never@3499 60 };
never@3499 61
never@3499 62 class GCHeapLog : public EventLogBase<GCMessage> {
never@3499 63 private:
never@3499 64 void log_heap(bool before);
never@3499 65
never@3499 66 public:
never@3499 67 GCHeapLog() : EventLogBase<GCMessage>("GC Heap History") {}
never@3499 68
never@3499 69 void log_heap_before() {
never@3499 70 log_heap(true);
never@3499 71 }
never@3499 72 void log_heap_after() {
never@3499 73 log_heap(false);
never@3499 74 }
never@3499 75 };
never@3499 76
duke@435 77 //
duke@435 78 // CollectedHeap
duke@435 79 // SharedHeap
duke@435 80 // GenCollectedHeap
duke@435 81 // G1CollectedHeap
duke@435 82 // ParallelScavengeHeap
duke@435 83 //
zgu@3900 84 class CollectedHeap : public CHeapObj<mtInternal> {
duke@435 85 friend class VMStructs;
duke@435 86 friend class IsGCActiveMark; // Block structured external access to _is_gc_active
duke@435 87
duke@435 88 #ifdef ASSERT
duke@435 89 static int _fire_out_of_memory_count;
duke@435 90 #endif
duke@435 91
jcoomes@916 92 // Used for filler objects (static, but initialized in ctor).
jcoomes@916 93 static size_t _filler_array_max_size;
jcoomes@916 94
never@3499 95 GCHeapLog* _gc_heap_log;
never@3499 96
ysr@1601 97 // Used in support of ReduceInitialCardMarks; only consulted if COMPILER2 is being used
ysr@1601 98 bool _defer_initial_card_mark;
ysr@1601 99
duke@435 100 protected:
duke@435 101 MemRegion _reserved;
duke@435 102 BarrierSet* _barrier_set;
duke@435 103 bool _is_gc_active;
jmasa@3357 104 uint _n_par_threads;
jmasa@2188 105
duke@435 106 unsigned int _total_collections; // ... started
duke@435 107 unsigned int _total_full_collections; // ... started
duke@435 108 NOT_PRODUCT(volatile size_t _promotion_failure_alot_count;)
duke@435 109 NOT_PRODUCT(volatile size_t _promotion_failure_alot_gc_number;)
duke@435 110
duke@435 111 // Reason for current garbage collection. Should be set to
duke@435 112 // a value reflecting no collection between collections.
duke@435 113 GCCause::Cause _gc_cause;
duke@435 114 GCCause::Cause _gc_lastcause;
duke@435 115 PerfStringVariable* _perf_gc_cause;
duke@435 116 PerfStringVariable* _perf_gc_lastcause;
duke@435 117
duke@435 118 // Constructor
duke@435 119 CollectedHeap();
duke@435 120
ysr@1601 121 // Do common initializations that must follow instance construction,
ysr@1601 122 // for example, those needing virtual calls.
ysr@1601 123 // This code could perhaps be moved into initialize() but would
ysr@1601 124 // be slightly more awkward because we want the latter to be a
ysr@1601 125 // pure virtual.
ysr@1601 126 void pre_initialize();
ysr@1601 127
tonyp@2971 128 // Create a new tlab. All TLAB allocations must go through this.
duke@435 129 virtual HeapWord* allocate_new_tlab(size_t size);
duke@435 130
duke@435 131 // Accumulate statistics on all tlabs.
duke@435 132 virtual void accumulate_statistics_all_tlabs();
duke@435 133
duke@435 134 // Reinitialize tlabs before resuming mutators.
duke@435 135 virtual void resize_all_tlabs();
duke@435 136
duke@435 137 // Allocate from the current thread's TLAB, with broken-out slow path.
sla@5237 138 inline static HeapWord* allocate_from_tlab(KlassHandle klass, Thread* thread, size_t size);
sla@5237 139 static HeapWord* allocate_from_tlab_slow(KlassHandle klass, Thread* thread, size_t size);
duke@435 140
duke@435 141 // Allocate an uninitialized block of the given size, or returns NULL if
duke@435 142 // this is impossible.
sla@5237 143 inline static HeapWord* common_mem_allocate_noinit(KlassHandle klass, size_t size, TRAPS);
duke@435 144
duke@435 145 // Like allocate_init, but the block returned by a successful allocation
duke@435 146 // is guaranteed initialized to zeros.
sla@5237 147 inline static HeapWord* common_mem_allocate_init(KlassHandle klass, size_t size, TRAPS);
duke@435 148
duke@435 149 // Helper functions for (VM) allocation.
brutisso@3675 150 inline static void post_allocation_setup_common(KlassHandle klass, HeapWord* obj);
duke@435 151 inline static void post_allocation_setup_no_klass_install(KlassHandle klass,
brutisso@3675 152 HeapWord* objPtr);
duke@435 153
brutisso@3675 154 inline static void post_allocation_setup_obj(KlassHandle klass, HeapWord* obj);
duke@435 155
duke@435 156 inline static void post_allocation_setup_array(KlassHandle klass,
brutisso@3675 157 HeapWord* obj, int length);
duke@435 158
duke@435 159 // Clears an allocated object.
duke@435 160 inline static void init_obj(HeapWord* obj, size_t size);
duke@435 161
jcoomes@916 162 // Filler object utilities.
jcoomes@916 163 static inline size_t filler_array_hdr_size();
jcoomes@916 164 static inline size_t filler_array_min_size();
jcoomes@916 165
jcoomes@916 166 DEBUG_ONLY(static void fill_args_check(HeapWord* start, size_t words);)
johnc@1600 167 DEBUG_ONLY(static void zap_filler_array(HeapWord* start, size_t words, bool zap = true);)
jcoomes@916 168
jcoomes@916 169 // Fill with a single array; caller must ensure filler_array_min_size() <=
jcoomes@916 170 // words <= filler_array_max_size().
johnc@1600 171 static inline void fill_with_array(HeapWord* start, size_t words, bool zap = true);
jcoomes@916 172
jcoomes@916 173 // Fill with a single object (either an int array or a java.lang.Object).
johnc@1600 174 static inline void fill_with_object_impl(HeapWord* start, size_t words, bool zap = true);
jcoomes@916 175
sla@5237 176 virtual void trace_heap(GCWhen::Type when, GCTracer* tracer);
sla@5237 177
duke@435 178 // Verification functions
duke@435 179 virtual void check_for_bad_heap_word_value(HeapWord* addr, size_t size)
duke@435 180 PRODUCT_RETURN;
duke@435 181 virtual void check_for_non_bad_heap_word_value(HeapWord* addr, size_t size)
duke@435 182 PRODUCT_RETURN;
jmasa@977 183 debug_only(static void check_for_valid_allocation_state();)
duke@435 184
duke@435 185 public:
duke@435 186 enum Name {
duke@435 187 Abstract,
duke@435 188 SharedHeap,
duke@435 189 GenCollectedHeap,
duke@435 190 ParallelScavengeHeap,
duke@435 191 G1CollectedHeap
duke@435 192 };
duke@435 193
brutisso@3668 194 static inline size_t filler_array_max_size() {
brutisso@3668 195 return _filler_array_max_size;
brutisso@3668 196 }
brutisso@3668 197
duke@435 198 virtual CollectedHeap::Name kind() const { return CollectedHeap::Abstract; }
duke@435 199
duke@435 200 /**
duke@435 201 * Returns JNI error code JNI_ENOMEM if memory could not be allocated,
duke@435 202 * and JNI_OK on success.
duke@435 203 */
duke@435 204 virtual jint initialize() = 0;
duke@435 205
duke@435 206 // In many heaps, there will be a need to perform some initialization activities
duke@435 207 // after the Universe is fully formed, but before general heap allocation is allowed.
duke@435 208 // This is the correct place to place such initialization methods.
duke@435 209 virtual void post_initialize() = 0;
duke@435 210
duke@435 211 MemRegion reserved_region() const { return _reserved; }
coleenp@548 212 address base() const { return (address)reserved_region().start(); }
duke@435 213
duke@435 214 virtual size_t capacity() const = 0;
duke@435 215 virtual size_t used() const = 0;
duke@435 216
duke@435 217 // Return "true" if the part of the heap that allocates Java
duke@435 218 // objects has reached the maximal committed limit that it can
duke@435 219 // reach, without a garbage collection.
duke@435 220 virtual bool is_maximal_no_gc() const = 0;
duke@435 221
duke@435 222 // Support for java.lang.Runtime.maxMemory(): return the maximum amount of
duke@435 223 // memory that the vm could make available for storing 'normal' java objects.
duke@435 224 // This is based on the reserved address space, but should not include space
coleenp@4037 225 // that the vm uses internally for bookkeeping or temporary storage
coleenp@4037 226 // (e.g., in the case of the young gen, one of the survivor
duke@435 227 // spaces).
duke@435 228 virtual size_t max_capacity() const = 0;
duke@435 229
duke@435 230 // Returns "TRUE" if "p" points into the reserved area of the heap.
duke@435 231 bool is_in_reserved(const void* p) const {
duke@435 232 return _reserved.contains(p);
duke@435 233 }
duke@435 234
duke@435 235 bool is_in_reserved_or_null(const void* p) const {
duke@435 236 return p == NULL || is_in_reserved(p);
duke@435 237 }
duke@435 238
stefank@3335 239 // Returns "TRUE" iff "p" points into the committed areas of the heap.
stefank@3335 240 // Since this method can be expensive in general, we restrict its
duke@435 241 // use to assertion checking only.
duke@435 242 virtual bool is_in(const void* p) const = 0;
duke@435 243
duke@435 244 bool is_in_or_null(const void* p) const {
duke@435 245 return p == NULL || is_in(p);
duke@435 246 }
duke@435 247
coleenp@4037 248 bool is_in_place(Metadata** p) {
coleenp@4037 249 return !Universe::heap()->is_in(p);
coleenp@4037 250 }
coleenp@4037 251 bool is_in_place(oop* p) { return Universe::heap()->is_in(p); }
coleenp@4037 252 bool is_in_place(narrowOop* p) {
coleenp@4037 253 oop o = oopDesc::load_decode_heap_oop_not_null(p);
coleenp@4037 254 return Universe::heap()->is_in((const void*)o);
coleenp@4037 255 }
coleenp@4037 256
duke@435 257 // Let's define some terms: a "closed" subset of a heap is one that
duke@435 258 //
duke@435 259 // 1) contains all currently-allocated objects, and
duke@435 260 //
duke@435 261 // 2) is closed under reference: no object in the closed subset
duke@435 262 // references one outside the closed subset.
duke@435 263 //
duke@435 264 // Membership in a heap's closed subset is useful for assertions.
duke@435 265 // Clearly, the entire heap is a closed subset, so the default
duke@435 266 // implementation is to use "is_in_reserved". But this may not be too
duke@435 267 // liberal to perform useful checking. Also, the "is_in" predicate
duke@435 268 // defines a closed subset, but may be too expensive, since "is_in"
duke@435 269 // verifies that its argument points to an object head. The
duke@435 270 // "closed_subset" method allows a heap to define an intermediate
duke@435 271 // predicate, allowing more precise checking than "is_in_reserved" at
duke@435 272 // lower cost than "is_in."
duke@435 273
duke@435 274 // One important case is a heap composed of disjoint contiguous spaces,
duke@435 275 // such as the Garbage-First collector. Such heaps have a convenient
duke@435 276 // closed subset consisting of the allocated portions of those
duke@435 277 // contiguous spaces.
duke@435 278
duke@435 279 // Return "TRUE" iff the given pointer points into the heap's defined
duke@435 280 // closed subset (which defaults to the entire heap).
duke@435 281 virtual bool is_in_closed_subset(const void* p) const {
duke@435 282 return is_in_reserved(p);
duke@435 283 }
duke@435 284
duke@435 285 bool is_in_closed_subset_or_null(const void* p) const {
duke@435 286 return p == NULL || is_in_closed_subset(p);
duke@435 287 }
duke@435 288
jmasa@2909 289 #ifdef ASSERT
jmasa@2909 290 // Returns true if "p" is in the part of the
jmasa@2909 291 // heap being collected.
jmasa@2909 292 virtual bool is_in_partial_collection(const void *p) = 0;
jmasa@2909 293 #endif
jmasa@2909 294
jrose@1424 295 // An object is scavengable if its location may move during a scavenge.
jrose@1424 296 // (A scavenge is a GC which is not a full GC.)
jmasa@2909 297 virtual bool is_scavengable(const void *p) = 0;
jrose@1424 298
duke@435 299 void set_gc_cause(GCCause::Cause v) {
duke@435 300 if (UsePerfData) {
duke@435 301 _gc_lastcause = _gc_cause;
duke@435 302 _perf_gc_lastcause->set_value(GCCause::to_string(_gc_lastcause));
duke@435 303 _perf_gc_cause->set_value(GCCause::to_string(v));
duke@435 304 }
duke@435 305 _gc_cause = v;
duke@435 306 }
duke@435 307 GCCause::Cause gc_cause() { return _gc_cause; }
duke@435 308
jmasa@2188 309 // Number of threads currently working on GC tasks.
jmasa@3357 310 uint n_par_threads() { return _n_par_threads; }
jmasa@2188 311
jmasa@2188 312 // May be overridden to set additional parallelism.
jmasa@3357 313 virtual void set_par_threads(uint t) { _n_par_threads = t; };
jmasa@2188 314
never@3205 315 // Allocate and initialize instances of Class
never@3205 316 static oop Class_obj_allocate(KlassHandle klass, int size, KlassHandle real_klass, TRAPS);
never@3205 317
duke@435 318 // General obj/array allocation facilities.
duke@435 319 inline static oop obj_allocate(KlassHandle klass, int size, TRAPS);
duke@435 320 inline static oop array_allocate(KlassHandle klass, int size, int length, TRAPS);
kvn@3157 321 inline static oop array_allocate_nozero(KlassHandle klass, int size, int length, TRAPS);
duke@435 322
coleenp@4037 323 inline static void post_allocation_install_obj_klass(KlassHandle klass,
coleenp@4037 324 oop obj);
duke@435 325
duke@435 326 // Raw memory allocation facilities
duke@435 327 // The obj and array allocate methods are covers for these methods.
coleenp@4037 328 // mem_allocate() should never be
tonyp@2971 329 // called to allocate TLABs, only individual objects.
duke@435 330 virtual HeapWord* mem_allocate(size_t size,
duke@435 331 bool* gc_overhead_limit_was_exceeded) = 0;
duke@435 332
jcoomes@916 333 // Utilities for turning raw memory into filler objects.
jcoomes@916 334 //
jcoomes@916 335 // min_fill_size() is the smallest region that can be filled.
jcoomes@916 336 // fill_with_objects() can fill arbitrary-sized regions of the heap using
jcoomes@916 337 // multiple objects. fill_with_object() is for regions known to be smaller
jcoomes@916 338 // than the largest array of integers; it uses a single object to fill the
jcoomes@916 339 // region and has slightly less overhead.
jcoomes@916 340 static size_t min_fill_size() {
jcoomes@916 341 return size_t(align_object_size(oopDesc::header_size()));
jcoomes@916 342 }
jcoomes@916 343
johnc@1600 344 static void fill_with_objects(HeapWord* start, size_t words, bool zap = true);
jcoomes@916 345
johnc@1600 346 static void fill_with_object(HeapWord* start, size_t words, bool zap = true);
johnc@1600 347 static void fill_with_object(MemRegion region, bool zap = true) {
johnc@1600 348 fill_with_object(region.start(), region.word_size(), zap);
jcoomes@916 349 }
johnc@1600 350 static void fill_with_object(HeapWord* start, HeapWord* end, bool zap = true) {
johnc@1600 351 fill_with_object(start, pointer_delta(end, start), zap);
jcoomes@916 352 }
jcoomes@916 353
duke@435 354 // Some heaps may offer a contiguous region for shared non-blocking
duke@435 355 // allocation, via inlined code (by exporting the address of the top and
duke@435 356 // end fields defining the extent of the contiguous allocation region.)
duke@435 357
duke@435 358 // This function returns "true" iff the heap supports this kind of
duke@435 359 // allocation. (Default is "no".)
duke@435 360 virtual bool supports_inline_contig_alloc() const {
duke@435 361 return false;
duke@435 362 }
duke@435 363 // These functions return the addresses of the fields that define the
duke@435 364 // boundaries of the contiguous allocation area. (These fields should be
duke@435 365 // physically near to one another.)
duke@435 366 virtual HeapWord** top_addr() const {
duke@435 367 guarantee(false, "inline contiguous allocation not supported");
duke@435 368 return NULL;
duke@435 369 }
duke@435 370 virtual HeapWord** end_addr() const {
duke@435 371 guarantee(false, "inline contiguous allocation not supported");
duke@435 372 return NULL;
duke@435 373 }
duke@435 374
duke@435 375 // Some heaps may be in an unparseable state at certain times between
duke@435 376 // collections. This may be necessary for efficient implementation of
duke@435 377 // certain allocation-related activities. Calling this function before
duke@435 378 // attempting to parse a heap ensures that the heap is in a parsable
duke@435 379 // state (provided other concurrent activity does not introduce
duke@435 380 // unparsability). It is normally expected, therefore, that this
duke@435 381 // method is invoked with the world stopped.
duke@435 382 // NOTE: if you override this method, make sure you call
duke@435 383 // super::ensure_parsability so that the non-generational
duke@435 384 // part of the work gets done. See implementation of
duke@435 385 // CollectedHeap::ensure_parsability and, for instance,
duke@435 386 // that of GenCollectedHeap::ensure_parsability().
duke@435 387 // The argument "retire_tlabs" controls whether existing TLABs
duke@435 388 // are merely filled or also retired, thus preventing further
duke@435 389 // allocation from them and necessitating allocation of new TLABs.
duke@435 390 virtual void ensure_parsability(bool retire_tlabs);
duke@435 391
duke@435 392 // Return an estimate of the maximum allocation that could be performed
duke@435 393 // without triggering any collection or expansion activity. In a
duke@435 394 // generational collector, for example, this is probably the largest
duke@435 395 // allocation that could be supported (without expansion) in the youngest
duke@435 396 // generation. It is "unsafe" because no locks are taken; the result
duke@435 397 // should be treated as an approximation, not a guarantee, for use in
duke@435 398 // heuristic resizing decisions.
duke@435 399 virtual size_t unsafe_max_alloc() = 0;
duke@435 400
duke@435 401 // Section on thread-local allocation buffers (TLABs)
duke@435 402 // If the heap supports thread-local allocation buffers, it should override
duke@435 403 // the following methods:
duke@435 404 // Returns "true" iff the heap supports thread-local allocation buffers.
duke@435 405 // The default is "no".
duke@435 406 virtual bool supports_tlab_allocation() const {
duke@435 407 return false;
duke@435 408 }
duke@435 409 // The amount of space available for thread-local allocation buffers.
duke@435 410 virtual size_t tlab_capacity(Thread *thr) const {
duke@435 411 guarantee(false, "thread-local allocation buffers not supported");
duke@435 412 return 0;
duke@435 413 }
duke@435 414 // An estimate of the maximum allocation that could be performed
duke@435 415 // for thread-local allocation buffers without triggering any
duke@435 416 // collection or expansion activity.
duke@435 417 virtual size_t unsafe_max_tlab_alloc(Thread *thr) const {
duke@435 418 guarantee(false, "thread-local allocation buffers not supported");
duke@435 419 return 0;
duke@435 420 }
ysr@1462 421
duke@435 422 // Can a compiler initialize a new object without store barriers?
duke@435 423 // This permission only extends from the creation of a new object
ysr@1462 424 // via a TLAB up to the first subsequent safepoint. If such permission
ysr@1462 425 // is granted for this heap type, the compiler promises to call
ysr@1462 426 // defer_store_barrier() below on any slow path allocation of
ysr@1462 427 // a new object for which such initializing store barriers will
ysr@1462 428 // have been elided.
ysr@777 429 virtual bool can_elide_tlab_store_barriers() const = 0;
ysr@777 430
duke@435 431 // If a compiler is eliding store barriers for TLAB-allocated objects,
duke@435 432 // there is probably a corresponding slow path which can produce
duke@435 433 // an object allocated anywhere. The compiler's runtime support
duke@435 434 // promises to call this function on such a slow-path-allocated
duke@435 435 // object before performing initializations that have elided
ysr@1462 436 // store barriers. Returns new_obj, or maybe a safer copy thereof.
ysr@1601 437 virtual oop new_store_pre_barrier(JavaThread* thread, oop new_obj);
ysr@1462 438
ysr@1462 439 // Answers whether an initializing store to a new object currently
ysr@1601 440 // allocated at the given address doesn't need a store
ysr@1462 441 // barrier. Returns "true" if it doesn't need an initializing
ysr@1462 442 // store barrier; answers "false" if it does.
ysr@1462 443 virtual bool can_elide_initializing_store_barrier(oop new_obj) = 0;
ysr@1462 444
ysr@1601 445 // If a compiler is eliding store barriers for TLAB-allocated objects,
ysr@1601 446 // we will be informed of a slow-path allocation by a call
ysr@1601 447 // to new_store_pre_barrier() above. Such a call precedes the
ysr@1601 448 // initialization of the object itself, and no post-store-barriers will
ysr@1601 449 // be issued. Some heap types require that the barrier strictly follows
ysr@1601 450 // the initializing stores. (This is currently implemented by deferring the
ysr@1601 451 // barrier until the next slow-path allocation or gc-related safepoint.)
ysr@1601 452 // This interface answers whether a particular heap type needs the card
ysr@1601 453 // mark to be thus strictly sequenced after the stores.
ysr@1601 454 virtual bool card_mark_must_follow_store() const = 0;
ysr@1601 455
ysr@1462 456 // If the CollectedHeap was asked to defer a store barrier above,
ysr@1462 457 // this informs it to flush such a deferred store barrier to the
ysr@1462 458 // remembered set.
ysr@1462 459 virtual void flush_deferred_store_barrier(JavaThread* thread);
duke@435 460
duke@435 461 // Does this heap support heap inspection (+PrintClassHistogram?)
ysr@777 462 virtual bool supports_heap_inspection() const = 0;
duke@435 463
duke@435 464 // Perform a collection of the heap; intended for use in implementing
duke@435 465 // "System.gc". This probably implies as full a collection as the
duke@435 466 // "CollectedHeap" supports.
duke@435 467 virtual void collect(GCCause::Cause cause) = 0;
duke@435 468
coleenp@4037 469 // Perform a full collection
coleenp@4037 470 virtual void do_full_collection(bool clear_all_soft_refs) = 0;
coleenp@4037 471
duke@435 472 // This interface assumes that it's being called by the
duke@435 473 // vm thread. It collects the heap assuming that the
duke@435 474 // heap lock is already held and that we are executing in
duke@435 475 // the context of the vm thread.
coleenp@4037 476 virtual void collect_as_vm_thread(GCCause::Cause cause);
coleenp@4037 477
coleenp@4037 478 // Callback from VM_CollectForMetadataAllocation operation.
coleenp@4037 479 MetaWord* satisfy_failed_metadata_allocation(ClassLoaderData* loader_data,
coleenp@4037 480 size_t size,
coleenp@4037 481 Metaspace::MetadataType mdtype);
duke@435 482
duke@435 483 // Returns the barrier set for this heap
duke@435 484 BarrierSet* barrier_set() { return _barrier_set; }
duke@435 485
duke@435 486 // Returns "true" iff there is a stop-world GC in progress. (I assume
duke@435 487 // that it should answer "false" for the concurrent part of a concurrent
duke@435 488 // collector -- dld).
duke@435 489 bool is_gc_active() const { return _is_gc_active; }
duke@435 490
duke@435 491 // Total number of GC collections (started)
duke@435 492 unsigned int total_collections() const { return _total_collections; }
duke@435 493 unsigned int total_full_collections() const { return _total_full_collections;}
duke@435 494
duke@435 495 // Increment total number of GC collections (started)
duke@435 496 // Should be protected but used by PSMarkSweep - cleanup for 1.4.2
duke@435 497 void increment_total_collections(bool full = false) {
duke@435 498 _total_collections++;
duke@435 499 if (full) {
duke@435 500 increment_total_full_collections();
duke@435 501 }
duke@435 502 }
duke@435 503
duke@435 504 void increment_total_full_collections() { _total_full_collections++; }
duke@435 505
duke@435 506 // Return the AdaptiveSizePolicy for the heap.
duke@435 507 virtual AdaptiveSizePolicy* size_policy() = 0;
duke@435 508
jmasa@1822 509 // Return the CollectorPolicy for the heap
jmasa@1822 510 virtual CollectorPolicy* collector_policy() const = 0;
jmasa@1822 511
coleenp@4037 512 void oop_iterate_no_header(OopClosure* cl);
coleenp@4037 513
duke@435 514 // Iterate over all the ref-containing fields of all objects, calling
coleenp@4037 515 // "cl.do_oop" on each.
coleenp@4037 516 virtual void oop_iterate(ExtendedOopClosure* cl) = 0;
duke@435 517
duke@435 518 // Iterate over all objects, calling "cl.do_object" on each.
duke@435 519 virtual void object_iterate(ObjectClosure* cl) = 0;
duke@435 520
jmasa@952 521 // Similar to object_iterate() except iterates only
jmasa@952 522 // over live objects.
jmasa@952 523 virtual void safe_object_iterate(ObjectClosure* cl) = 0;
jmasa@952 524
duke@435 525 // NOTE! There is no requirement that a collector implement these
duke@435 526 // functions.
duke@435 527 //
duke@435 528 // A CollectedHeap is divided into a dense sequence of "blocks"; that is,
duke@435 529 // each address in the (reserved) heap is a member of exactly
duke@435 530 // one block. The defining characteristic of a block is that it is
duke@435 531 // possible to find its size, and thus to progress forward to the next
duke@435 532 // block. (Blocks may be of different sizes.) Thus, blocks may
duke@435 533 // represent Java objects, or they might be free blocks in a
duke@435 534 // free-list-based heap (or subheap), as long as the two kinds are
duke@435 535 // distinguishable and the size of each is determinable.
duke@435 536
duke@435 537 // Returns the address of the start of the "block" that contains the
duke@435 538 // address "addr". We say "blocks" instead of "object" since some heaps
duke@435 539 // may not pack objects densely; a chunk may either be an object or a
duke@435 540 // non-object.
duke@435 541 virtual HeapWord* block_start(const void* addr) const = 0;
duke@435 542
duke@435 543 // Requires "addr" to be the start of a chunk, and returns its size.
duke@435 544 // "addr + size" is required to be the start of a new chunk, or the end
duke@435 545 // of the active area of the heap.
duke@435 546 virtual size_t block_size(const HeapWord* addr) const = 0;
duke@435 547
duke@435 548 // Requires "addr" to be the start of a block, and returns "TRUE" iff
duke@435 549 // the block is an object.
duke@435 550 virtual bool block_is_obj(const HeapWord* addr) const = 0;
duke@435 551
duke@435 552 // Returns the longest time (in ms) that has elapsed since the last
duke@435 553 // time that any part of the heap was examined by a garbage collection.
duke@435 554 virtual jlong millis_since_last_gc() = 0;
duke@435 555
duke@435 556 // Perform any cleanup actions necessary before allowing a verification.
duke@435 557 virtual void prepare_for_verify() = 0;
duke@435 558
ysr@1050 559 // Generate any dumps preceding or following a full gc
sla@5237 560 void pre_full_gc_dump(GCTimer* timer);
sla@5237 561 void post_full_gc_dump(GCTimer* timer);
sla@5237 562
sla@5237 563 VirtualSpaceSummary create_heap_space_summary();
sla@5237 564 GCHeapSummary create_heap_summary();
sla@5237 565
sla@5237 566 MetaspaceSummary create_metaspace_summary();
ysr@1050 567
tonyp@3269 568 // Print heap information on the given outputStream.
duke@435 569 virtual void print_on(outputStream* st) const = 0;
tonyp@3269 570 // The default behavior is to call print_on() on tty.
tonyp@3269 571 virtual void print() const {
tonyp@3269 572 print_on(tty);
tonyp@3269 573 }
tonyp@3269 574 // Print more detailed heap information on the given
sla@5237 575 // outputStream. The default behavior is to call print_on(). It is
tonyp@3269 576 // up to each subclass to override it and add any additional output
tonyp@3269 577 // it needs.
tonyp@3269 578 virtual void print_extended_on(outputStream* st) const {
tonyp@3269 579 print_on(st);
tonyp@3269 580 }
duke@435 581
stefank@4904 582 virtual void print_on_error(outputStream* st) const {
stefank@4904 583 st->print_cr("Heap:");
stefank@4904 584 print_extended_on(st);
stefank@4904 585 st->cr();
stefank@4904 586
stefank@4904 587 _barrier_set->print_on(st);
stefank@4904 588 }
stefank@4904 589
duke@435 590 // Print all GC threads (other than the VM thread)
duke@435 591 // used by this heap.
duke@435 592 virtual void print_gc_threads_on(outputStream* st) const = 0;
tonyp@3269 593 // The default behavior is to call print_gc_threads_on() on tty.
tonyp@3269 594 void print_gc_threads() {
tonyp@3269 595 print_gc_threads_on(tty);
tonyp@3269 596 }
duke@435 597 // Iterator for all GC threads (other than VM thread)
duke@435 598 virtual void gc_threads_do(ThreadClosure* tc) const = 0;
duke@435 599
duke@435 600 // Print any relevant tracing info that flags imply.
duke@435 601 // Default implementation does nothing.
duke@435 602 virtual void print_tracing_info() const = 0;
duke@435 603
sla@5237 604 void print_heap_before_gc();
sla@5237 605 void print_heap_after_gc();
sla@5237 606
johnc@5548 607 // Registering and unregistering an nmethod (compiled code) with the heap.
johnc@5548 608 // Override with specific mechanism for each specialized heap type.
johnc@5548 609 virtual void register_nmethod(nmethod* nm);
johnc@5548 610 virtual void unregister_nmethod(nmethod* nm);
johnc@5548 611
sla@5237 612 void trace_heap_before_gc(GCTracer* gc_tracer);
sla@5237 613 void trace_heap_after_gc(GCTracer* gc_tracer);
never@3499 614
duke@435 615 // Heap verification
brutisso@3711 616 virtual void verify(bool silent, VerifyOption option) = 0;
duke@435 617
duke@435 618 // Non product verification and debugging.
duke@435 619 #ifndef PRODUCT
duke@435 620 // Support for PromotionFailureALot. Return true if it's time to cause a
duke@435 621 // promotion failure. The no-argument version uses
duke@435 622 // this->_promotion_failure_alot_count as the counter.
duke@435 623 inline bool promotion_should_fail(volatile size_t* count);
duke@435 624 inline bool promotion_should_fail();
duke@435 625
duke@435 626 // Reset the PromotionFailureALot counters. Should be called at the end of a
sla@5237 627 // GC in which promotion failure occurred.
duke@435 628 inline void reset_promotion_should_fail(volatile size_t* count);
duke@435 629 inline void reset_promotion_should_fail();
duke@435 630 #endif // #ifndef PRODUCT
duke@435 631
duke@435 632 #ifdef ASSERT
duke@435 633 static int fired_fake_oom() {
duke@435 634 return (CIFireOOMAt > 1 && _fire_out_of_memory_count >= CIFireOOMAt);
duke@435 635 }
duke@435 636 #endif
jmasa@2188 637
jmasa@2188 638 public:
jmasa@2188 639 // This is a convenience method that is used in cases where
jmasa@2188 640 // the actual number of GC worker threads is not pertinent but
jmasa@2188 641 // only whether there more than 0. Use of this method helps
jmasa@2188 642 // reduce the occurrence of ParallelGCThreads to uses where the
jmasa@2188 643 // actual number may be germane.
jmasa@2188 644 static bool use_parallel_gc_threads() { return ParallelGCThreads > 0; }
stefank@3335 645
stefank@3335 646 /////////////// Unit tests ///////////////
stefank@3335 647
stefank@3335 648 NOT_PRODUCT(static void test_is_in();)
duke@435 649 };
duke@435 650
duke@435 651 // Class to set and reset the GC cause for a CollectedHeap.
duke@435 652
duke@435 653 class GCCauseSetter : StackObj {
duke@435 654 CollectedHeap* _heap;
duke@435 655 GCCause::Cause _previous_cause;
duke@435 656 public:
duke@435 657 GCCauseSetter(CollectedHeap* heap, GCCause::Cause cause) {
duke@435 658 assert(SafepointSynchronize::is_at_safepoint(),
duke@435 659 "This method manipulates heap state without locking");
duke@435 660 _heap = heap;
duke@435 661 _previous_cause = _heap->gc_cause();
duke@435 662 _heap->set_gc_cause(cause);
duke@435 663 }
duke@435 664
duke@435 665 ~GCCauseSetter() {
duke@435 666 assert(SafepointSynchronize::is_at_safepoint(),
duke@435 667 "This method manipulates heap state without locking");
duke@435 668 _heap->set_gc_cause(_previous_cause);
duke@435 669 }
duke@435 670 };
stefank@2314 671
stefank@2314 672 #endif // SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_HPP

mercurial