src/share/vm/gc_interface/collectedHeap.hpp

Thu, 30 Oct 2014 10:51:06 +0100

author
sjohanss
date
Thu, 30 Oct 2014 10:51:06 +0100
changeset 7298
ef9eda2c1abe
parent 7160
c10b463abc6e
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

8061234: ResourceContext.requestAccurateUpdate() is unreliable
Summary: Changing copy_allocation_context_stats to return if there are more stats available after the copy.
Reviewed-by: rriggs, jcoomes

duke@435 1 /*
coleenp@6626 2 * Copyright (c) 2001, 2014, 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
coleenp@6627 154 inline static void post_allocation_setup_obj(KlassHandle klass, HeapWord* obj, int size);
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
pliden@6690 211 // Stop any onging concurrent work and prepare for exit.
pliden@6690 212 virtual void stop() {}
pliden@6690 213
duke@435 214 MemRegion reserved_region() const { return _reserved; }
coleenp@548 215 address base() const { return (address)reserved_region().start(); }
duke@435 216
duke@435 217 virtual size_t capacity() const = 0;
duke@435 218 virtual size_t used() const = 0;
duke@435 219
duke@435 220 // Return "true" if the part of the heap that allocates Java
duke@435 221 // objects has reached the maximal committed limit that it can
duke@435 222 // reach, without a garbage collection.
duke@435 223 virtual bool is_maximal_no_gc() const = 0;
duke@435 224
duke@435 225 // Support for java.lang.Runtime.maxMemory(): return the maximum amount of
duke@435 226 // memory that the vm could make available for storing 'normal' java objects.
duke@435 227 // This is based on the reserved address space, but should not include space
coleenp@4037 228 // that the vm uses internally for bookkeeping or temporary storage
coleenp@4037 229 // (e.g., in the case of the young gen, one of the survivor
duke@435 230 // spaces).
duke@435 231 virtual size_t max_capacity() const = 0;
duke@435 232
duke@435 233 // Returns "TRUE" if "p" points into the reserved area of the heap.
duke@435 234 bool is_in_reserved(const void* p) const {
duke@435 235 return _reserved.contains(p);
duke@435 236 }
duke@435 237
duke@435 238 bool is_in_reserved_or_null(const void* p) const {
duke@435 239 return p == NULL || is_in_reserved(p);
duke@435 240 }
duke@435 241
stefank@3335 242 // Returns "TRUE" iff "p" points into the committed areas of the heap.
stefank@3335 243 // Since this method can be expensive in general, we restrict its
duke@435 244 // use to assertion checking only.
duke@435 245 virtual bool is_in(const void* p) const = 0;
duke@435 246
duke@435 247 bool is_in_or_null(const void* p) const {
duke@435 248 return p == NULL || is_in(p);
duke@435 249 }
duke@435 250
coleenp@4037 251 bool is_in_place(Metadata** p) {
coleenp@4037 252 return !Universe::heap()->is_in(p);
coleenp@4037 253 }
coleenp@4037 254 bool is_in_place(oop* p) { return Universe::heap()->is_in(p); }
coleenp@4037 255 bool is_in_place(narrowOop* p) {
coleenp@4037 256 oop o = oopDesc::load_decode_heap_oop_not_null(p);
coleenp@4037 257 return Universe::heap()->is_in((const void*)o);
coleenp@4037 258 }
coleenp@4037 259
duke@435 260 // Let's define some terms: a "closed" subset of a heap is one that
duke@435 261 //
duke@435 262 // 1) contains all currently-allocated objects, and
duke@435 263 //
duke@435 264 // 2) is closed under reference: no object in the closed subset
duke@435 265 // references one outside the closed subset.
duke@435 266 //
duke@435 267 // Membership in a heap's closed subset is useful for assertions.
duke@435 268 // Clearly, the entire heap is a closed subset, so the default
duke@435 269 // implementation is to use "is_in_reserved". But this may not be too
duke@435 270 // liberal to perform useful checking. Also, the "is_in" predicate
duke@435 271 // defines a closed subset, but may be too expensive, since "is_in"
duke@435 272 // verifies that its argument points to an object head. The
duke@435 273 // "closed_subset" method allows a heap to define an intermediate
duke@435 274 // predicate, allowing more precise checking than "is_in_reserved" at
duke@435 275 // lower cost than "is_in."
duke@435 276
duke@435 277 // One important case is a heap composed of disjoint contiguous spaces,
duke@435 278 // such as the Garbage-First collector. Such heaps have a convenient
duke@435 279 // closed subset consisting of the allocated portions of those
duke@435 280 // contiguous spaces.
duke@435 281
duke@435 282 // Return "TRUE" iff the given pointer points into the heap's defined
duke@435 283 // closed subset (which defaults to the entire heap).
duke@435 284 virtual bool is_in_closed_subset(const void* p) const {
duke@435 285 return is_in_reserved(p);
duke@435 286 }
duke@435 287
duke@435 288 bool is_in_closed_subset_or_null(const void* p) const {
duke@435 289 return p == NULL || is_in_closed_subset(p);
duke@435 290 }
duke@435 291
jmasa@2909 292 #ifdef ASSERT
jmasa@2909 293 // Returns true if "p" is in the part of the
jmasa@2909 294 // heap being collected.
jmasa@2909 295 virtual bool is_in_partial_collection(const void *p) = 0;
jmasa@2909 296 #endif
jmasa@2909 297
jrose@1424 298 // An object is scavengable if its location may move during a scavenge.
jrose@1424 299 // (A scavenge is a GC which is not a full GC.)
jmasa@2909 300 virtual bool is_scavengable(const void *p) = 0;
jrose@1424 301
duke@435 302 void set_gc_cause(GCCause::Cause v) {
duke@435 303 if (UsePerfData) {
duke@435 304 _gc_lastcause = _gc_cause;
duke@435 305 _perf_gc_lastcause->set_value(GCCause::to_string(_gc_lastcause));
duke@435 306 _perf_gc_cause->set_value(GCCause::to_string(v));
duke@435 307 }
duke@435 308 _gc_cause = v;
duke@435 309 }
duke@435 310 GCCause::Cause gc_cause() { return _gc_cause; }
duke@435 311
jmasa@2188 312 // Number of threads currently working on GC tasks.
jmasa@3357 313 uint n_par_threads() { return _n_par_threads; }
jmasa@2188 314
jmasa@2188 315 // May be overridden to set additional parallelism.
jmasa@3357 316 virtual void set_par_threads(uint t) { _n_par_threads = t; };
jmasa@2188 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
jmasa@7031 354 // Return the address "addr" aligned by "alignment_in_bytes" if such
jmasa@7031 355 // an address is below "end". Return NULL otherwise.
jmasa@7031 356 inline static HeapWord* align_allocation_or_fail(HeapWord* addr,
jmasa@7031 357 HeapWord* end,
jmasa@7031 358 unsigned short alignment_in_bytes);
jmasa@7031 359
duke@435 360 // Some heaps may offer a contiguous region for shared non-blocking
duke@435 361 // allocation, via inlined code (by exporting the address of the top and
duke@435 362 // end fields defining the extent of the contiguous allocation region.)
duke@435 363
duke@435 364 // This function returns "true" iff the heap supports this kind of
duke@435 365 // allocation. (Default is "no".)
duke@435 366 virtual bool supports_inline_contig_alloc() const {
duke@435 367 return false;
duke@435 368 }
duke@435 369 // These functions return the addresses of the fields that define the
duke@435 370 // boundaries of the contiguous allocation area. (These fields should be
duke@435 371 // physically near to one another.)
duke@435 372 virtual HeapWord** top_addr() const {
duke@435 373 guarantee(false, "inline contiguous allocation not supported");
duke@435 374 return NULL;
duke@435 375 }
duke@435 376 virtual HeapWord** end_addr() const {
duke@435 377 guarantee(false, "inline contiguous allocation not supported");
duke@435 378 return NULL;
duke@435 379 }
duke@435 380
duke@435 381 // Some heaps may be in an unparseable state at certain times between
duke@435 382 // collections. This may be necessary for efficient implementation of
duke@435 383 // certain allocation-related activities. Calling this function before
duke@435 384 // attempting to parse a heap ensures that the heap is in a parsable
duke@435 385 // state (provided other concurrent activity does not introduce
duke@435 386 // unparsability). It is normally expected, therefore, that this
duke@435 387 // method is invoked with the world stopped.
duke@435 388 // NOTE: if you override this method, make sure you call
duke@435 389 // super::ensure_parsability so that the non-generational
duke@435 390 // part of the work gets done. See implementation of
duke@435 391 // CollectedHeap::ensure_parsability and, for instance,
duke@435 392 // that of GenCollectedHeap::ensure_parsability().
duke@435 393 // The argument "retire_tlabs" controls whether existing TLABs
duke@435 394 // are merely filled or also retired, thus preventing further
duke@435 395 // allocation from them and necessitating allocation of new TLABs.
duke@435 396 virtual void ensure_parsability(bool retire_tlabs);
duke@435 397
duke@435 398 // Section on thread-local allocation buffers (TLABs)
duke@435 399 // If the heap supports thread-local allocation buffers, it should override
duke@435 400 // the following methods:
duke@435 401 // Returns "true" iff the heap supports thread-local allocation buffers.
duke@435 402 // The default is "no".
brutisso@6376 403 virtual bool supports_tlab_allocation() const = 0;
brutisso@6376 404
duke@435 405 // The amount of space available for thread-local allocation buffers.
brutisso@6376 406 virtual size_t tlab_capacity(Thread *thr) const = 0;
brutisso@6376 407
brutisso@6376 408 // The amount of used space for thread-local allocation buffers for the given thread.
brutisso@6376 409 virtual size_t tlab_used(Thread *thr) const = 0;
brutisso@6376 410
brutisso@6376 411 virtual size_t max_tlab_size() const;
brutisso@6376 412
duke@435 413 // An estimate of the maximum allocation that could be performed
duke@435 414 // for thread-local allocation buffers without triggering any
duke@435 415 // collection or expansion activity.
duke@435 416 virtual size_t unsafe_max_tlab_alloc(Thread *thr) const {
duke@435 417 guarantee(false, "thread-local allocation buffers not supported");
duke@435 418 return 0;
duke@435 419 }
ysr@1462 420
duke@435 421 // Can a compiler initialize a new object without store barriers?
duke@435 422 // This permission only extends from the creation of a new object
ysr@1462 423 // via a TLAB up to the first subsequent safepoint. If such permission
ysr@1462 424 // is granted for this heap type, the compiler promises to call
ysr@1462 425 // defer_store_barrier() below on any slow path allocation of
ysr@1462 426 // a new object for which such initializing store barriers will
ysr@1462 427 // have been elided.
ysr@777 428 virtual bool can_elide_tlab_store_barriers() const = 0;
ysr@777 429
duke@435 430 // If a compiler is eliding store barriers for TLAB-allocated objects,
duke@435 431 // there is probably a corresponding slow path which can produce
duke@435 432 // an object allocated anywhere. The compiler's runtime support
duke@435 433 // promises to call this function on such a slow-path-allocated
duke@435 434 // object before performing initializations that have elided
ysr@1462 435 // store barriers. Returns new_obj, or maybe a safer copy thereof.
ysr@1601 436 virtual oop new_store_pre_barrier(JavaThread* thread, oop new_obj);
ysr@1462 437
ysr@1462 438 // Answers whether an initializing store to a new object currently
ysr@1601 439 // allocated at the given address doesn't need a store
ysr@1462 440 // barrier. Returns "true" if it doesn't need an initializing
ysr@1462 441 // store barrier; answers "false" if it does.
ysr@1462 442 virtual bool can_elide_initializing_store_barrier(oop new_obj) = 0;
ysr@1462 443
ysr@1601 444 // If a compiler is eliding store barriers for TLAB-allocated objects,
ysr@1601 445 // we will be informed of a slow-path allocation by a call
ysr@1601 446 // to new_store_pre_barrier() above. Such a call precedes the
ysr@1601 447 // initialization of the object itself, and no post-store-barriers will
ysr@1601 448 // be issued. Some heap types require that the barrier strictly follows
ysr@1601 449 // the initializing stores. (This is currently implemented by deferring the
ysr@1601 450 // barrier until the next slow-path allocation or gc-related safepoint.)
ysr@1601 451 // This interface answers whether a particular heap type needs the card
ysr@1601 452 // mark to be thus strictly sequenced after the stores.
ysr@1601 453 virtual bool card_mark_must_follow_store() const = 0;
ysr@1601 454
ysr@1462 455 // If the CollectedHeap was asked to defer a store barrier above,
ysr@1462 456 // this informs it to flush such a deferred store barrier to the
ysr@1462 457 // remembered set.
ysr@1462 458 virtual void flush_deferred_store_barrier(JavaThread* thread);
duke@435 459
duke@435 460 // Does this heap support heap inspection (+PrintClassHistogram?)
ysr@777 461 virtual bool supports_heap_inspection() const = 0;
duke@435 462
duke@435 463 // Perform a collection of the heap; intended for use in implementing
duke@435 464 // "System.gc". This probably implies as full a collection as the
duke@435 465 // "CollectedHeap" supports.
duke@435 466 virtual void collect(GCCause::Cause cause) = 0;
duke@435 467
coleenp@4037 468 // Perform a full collection
coleenp@4037 469 virtual void do_full_collection(bool clear_all_soft_refs) = 0;
coleenp@4037 470
duke@435 471 // This interface assumes that it's being called by the
duke@435 472 // vm thread. It collects the heap assuming that the
duke@435 473 // heap lock is already held and that we are executing in
duke@435 474 // the context of the vm thread.
coleenp@4037 475 virtual void collect_as_vm_thread(GCCause::Cause cause);
coleenp@4037 476
duke@435 477 // Returns the barrier set for this heap
duke@435 478 BarrierSet* barrier_set() { return _barrier_set; }
duke@435 479
duke@435 480 // Returns "true" iff there is a stop-world GC in progress. (I assume
duke@435 481 // that it should answer "false" for the concurrent part of a concurrent
duke@435 482 // collector -- dld).
duke@435 483 bool is_gc_active() const { return _is_gc_active; }
duke@435 484
duke@435 485 // Total number of GC collections (started)
duke@435 486 unsigned int total_collections() const { return _total_collections; }
duke@435 487 unsigned int total_full_collections() const { return _total_full_collections;}
duke@435 488
duke@435 489 // Increment total number of GC collections (started)
duke@435 490 // Should be protected but used by PSMarkSweep - cleanup for 1.4.2
duke@435 491 void increment_total_collections(bool full = false) {
duke@435 492 _total_collections++;
duke@435 493 if (full) {
duke@435 494 increment_total_full_collections();
duke@435 495 }
duke@435 496 }
duke@435 497
duke@435 498 void increment_total_full_collections() { _total_full_collections++; }
duke@435 499
duke@435 500 // Return the AdaptiveSizePolicy for the heap.
duke@435 501 virtual AdaptiveSizePolicy* size_policy() = 0;
duke@435 502
jmasa@1822 503 // Return the CollectorPolicy for the heap
jmasa@1822 504 virtual CollectorPolicy* collector_policy() const = 0;
jmasa@1822 505
coleenp@4037 506 void oop_iterate_no_header(OopClosure* cl);
coleenp@4037 507
duke@435 508 // Iterate over all the ref-containing fields of all objects, calling
coleenp@4037 509 // "cl.do_oop" on each.
coleenp@4037 510 virtual void oop_iterate(ExtendedOopClosure* cl) = 0;
duke@435 511
duke@435 512 // Iterate over all objects, calling "cl.do_object" on each.
duke@435 513 virtual void object_iterate(ObjectClosure* cl) = 0;
duke@435 514
jmasa@952 515 // Similar to object_iterate() except iterates only
jmasa@952 516 // over live objects.
jmasa@952 517 virtual void safe_object_iterate(ObjectClosure* cl) = 0;
jmasa@952 518
duke@435 519 // NOTE! There is no requirement that a collector implement these
duke@435 520 // functions.
duke@435 521 //
duke@435 522 // A CollectedHeap is divided into a dense sequence of "blocks"; that is,
duke@435 523 // each address in the (reserved) heap is a member of exactly
duke@435 524 // one block. The defining characteristic of a block is that it is
duke@435 525 // possible to find its size, and thus to progress forward to the next
duke@435 526 // block. (Blocks may be of different sizes.) Thus, blocks may
duke@435 527 // represent Java objects, or they might be free blocks in a
duke@435 528 // free-list-based heap (or subheap), as long as the two kinds are
duke@435 529 // distinguishable and the size of each is determinable.
duke@435 530
duke@435 531 // Returns the address of the start of the "block" that contains the
duke@435 532 // address "addr". We say "blocks" instead of "object" since some heaps
duke@435 533 // may not pack objects densely; a chunk may either be an object or a
duke@435 534 // non-object.
duke@435 535 virtual HeapWord* block_start(const void* addr) const = 0;
duke@435 536
duke@435 537 // Requires "addr" to be the start of a chunk, and returns its size.
duke@435 538 // "addr + size" is required to be the start of a new chunk, or the end
duke@435 539 // of the active area of the heap.
duke@435 540 virtual size_t block_size(const HeapWord* addr) const = 0;
duke@435 541
duke@435 542 // Requires "addr" to be the start of a block, and returns "TRUE" iff
duke@435 543 // the block is an object.
duke@435 544 virtual bool block_is_obj(const HeapWord* addr) const = 0;
duke@435 545
duke@435 546 // Returns the longest time (in ms) that has elapsed since the last
duke@435 547 // time that any part of the heap was examined by a garbage collection.
duke@435 548 virtual jlong millis_since_last_gc() = 0;
duke@435 549
duke@435 550 // Perform any cleanup actions necessary before allowing a verification.
duke@435 551 virtual void prepare_for_verify() = 0;
duke@435 552
ysr@1050 553 // Generate any dumps preceding or following a full gc
sla@5237 554 void pre_full_gc_dump(GCTimer* timer);
sla@5237 555 void post_full_gc_dump(GCTimer* timer);
sla@5237 556
sla@5237 557 VirtualSpaceSummary create_heap_space_summary();
sla@5237 558 GCHeapSummary create_heap_summary();
sla@5237 559
sla@5237 560 MetaspaceSummary create_metaspace_summary();
ysr@1050 561
tonyp@3269 562 // Print heap information on the given outputStream.
duke@435 563 virtual void print_on(outputStream* st) const = 0;
tonyp@3269 564 // The default behavior is to call print_on() on tty.
tonyp@3269 565 virtual void print() const {
tonyp@3269 566 print_on(tty);
tonyp@3269 567 }
tonyp@3269 568 // Print more detailed heap information on the given
sla@5237 569 // outputStream. The default behavior is to call print_on(). It is
tonyp@3269 570 // up to each subclass to override it and add any additional output
tonyp@3269 571 // it needs.
tonyp@3269 572 virtual void print_extended_on(outputStream* st) const {
tonyp@3269 573 print_on(st);
tonyp@3269 574 }
duke@435 575
stefank@4904 576 virtual void print_on_error(outputStream* st) const {
stefank@4904 577 st->print_cr("Heap:");
stefank@4904 578 print_extended_on(st);
stefank@4904 579 st->cr();
stefank@4904 580
stefank@4904 581 _barrier_set->print_on(st);
stefank@4904 582 }
stefank@4904 583
duke@435 584 // Print all GC threads (other than the VM thread)
duke@435 585 // used by this heap.
duke@435 586 virtual void print_gc_threads_on(outputStream* st) const = 0;
tonyp@3269 587 // The default behavior is to call print_gc_threads_on() on tty.
tonyp@3269 588 void print_gc_threads() {
tonyp@3269 589 print_gc_threads_on(tty);
tonyp@3269 590 }
duke@435 591 // Iterator for all GC threads (other than VM thread)
duke@435 592 virtual void gc_threads_do(ThreadClosure* tc) const = 0;
duke@435 593
duke@435 594 // Print any relevant tracing info that flags imply.
duke@435 595 // Default implementation does nothing.
duke@435 596 virtual void print_tracing_info() const = 0;
duke@435 597
sla@5237 598 void print_heap_before_gc();
sla@5237 599 void print_heap_after_gc();
sla@5237 600
johnc@5548 601 // Registering and unregistering an nmethod (compiled code) with the heap.
johnc@5548 602 // Override with specific mechanism for each specialized heap type.
johnc@5548 603 virtual void register_nmethod(nmethod* nm);
johnc@5548 604 virtual void unregister_nmethod(nmethod* nm);
johnc@5548 605
sla@5237 606 void trace_heap_before_gc(GCTracer* gc_tracer);
sla@5237 607 void trace_heap_after_gc(GCTracer* gc_tracer);
never@3499 608
duke@435 609 // Heap verification
brutisso@3711 610 virtual void verify(bool silent, VerifyOption option) = 0;
duke@435 611
duke@435 612 // Non product verification and debugging.
duke@435 613 #ifndef PRODUCT
duke@435 614 // Support for PromotionFailureALot. Return true if it's time to cause a
duke@435 615 // promotion failure. The no-argument version uses
duke@435 616 // this->_promotion_failure_alot_count as the counter.
duke@435 617 inline bool promotion_should_fail(volatile size_t* count);
duke@435 618 inline bool promotion_should_fail();
duke@435 619
duke@435 620 // Reset the PromotionFailureALot counters. Should be called at the end of a
sla@5237 621 // GC in which promotion failure occurred.
duke@435 622 inline void reset_promotion_should_fail(volatile size_t* count);
duke@435 623 inline void reset_promotion_should_fail();
duke@435 624 #endif // #ifndef PRODUCT
duke@435 625
duke@435 626 #ifdef ASSERT
duke@435 627 static int fired_fake_oom() {
duke@435 628 return (CIFireOOMAt > 1 && _fire_out_of_memory_count >= CIFireOOMAt);
duke@435 629 }
duke@435 630 #endif
jmasa@2188 631
jmasa@2188 632 public:
jmasa@2188 633 // This is a convenience method that is used in cases where
jmasa@2188 634 // the actual number of GC worker threads is not pertinent but
jmasa@2188 635 // only whether there more than 0. Use of this method helps
jmasa@2188 636 // reduce the occurrence of ParallelGCThreads to uses where the
jmasa@2188 637 // actual number may be germane.
jmasa@2188 638 static bool use_parallel_gc_threads() { return ParallelGCThreads > 0; }
stefank@3335 639
jcoomes@7160 640 // Copy the current allocation context statistics for the specified contexts.
jcoomes@7160 641 // For each context in contexts, set the corresponding entries in the totals
jcoomes@7160 642 // and accuracy arrays to the current values held by the statistics. Each
jcoomes@7160 643 // array should be of length len.
sjohanss@7298 644 // Returns true if there are more stats available.
sjohanss@7298 645 virtual bool copy_allocation_context_stats(const jint* contexts,
jcoomes@7160 646 jlong* totals,
jcoomes@7160 647 jbyte* accuracy,
sjohanss@7298 648 jint len) {
sjohanss@7298 649 return false;
sjohanss@7298 650 }
jcoomes@7160 651
stefank@3335 652 /////////////// Unit tests ///////////////
stefank@3335 653
stefank@3335 654 NOT_PRODUCT(static void test_is_in();)
duke@435 655 };
duke@435 656
duke@435 657 // Class to set and reset the GC cause for a CollectedHeap.
duke@435 658
duke@435 659 class GCCauseSetter : StackObj {
duke@435 660 CollectedHeap* _heap;
duke@435 661 GCCause::Cause _previous_cause;
duke@435 662 public:
duke@435 663 GCCauseSetter(CollectedHeap* heap, GCCause::Cause cause) {
duke@435 664 assert(SafepointSynchronize::is_at_safepoint(),
duke@435 665 "This method manipulates heap state without locking");
duke@435 666 _heap = heap;
duke@435 667 _previous_cause = _heap->gc_cause();
duke@435 668 _heap->set_gc_cause(cause);
duke@435 669 }
duke@435 670
duke@435 671 ~GCCauseSetter() {
duke@435 672 assert(SafepointSynchronize::is_at_safepoint(),
duke@435 673 "This method manipulates heap state without locking");
duke@435 674 _heap->set_gc_cause(_previous_cause);
duke@435 675 }
duke@435 676 };
stefank@2314 677
stefank@2314 678 #endif // SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_HPP

mercurial