annotate src/share/vm/gc_interface/collectedHeap.hpp @ 3860:59c790074993

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