17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_GC_SHARED_COLLECTEDHEAP_HPP
26 #define SHARE_VM_GC_SHARED_COLLECTEDHEAP_HPP
27
28 #include "gc/shared/gcCause.hpp"
29 #include "gc/shared/gcWhen.hpp"
30 #include "memory/allocation.hpp"
31 #include "runtime/handles.hpp"
32 #include "runtime/perfData.hpp"
33 #include "runtime/safepoint.hpp"
34 #include "utilities/debug.hpp"
35 #include "utilities/events.hpp"
36 #include "utilities/formatBuffer.hpp"
37
38 // A "CollectedHeap" is an implementation of a java heap for HotSpot. This
39 // is an abstract class: there may be many different kinds of heaps. This
40 // class defines the functions that a heap must implement, and contains
41 // infrastructure common to all heaps.
42
43 class AdaptiveSizePolicy;
44 class BarrierSet;
45 class CollectorPolicy;
46 class GCHeapSummary;
47 class GCTimer;
48 class GCTracer;
49 class MetaspaceSummary;
50 class Thread;
51 class ThreadClosure;
52 class VirtualSpaceSummary;
53 class WorkGang;
54 class nmethod;
55
56 class GCMessage : public FormatBuffer<1024> {
57 public:
58 bool is_before;
59
60 public:
61 GCMessage() {}
62 };
63
64 class CollectedHeap;
65
66 class GCHeapLog : public EventLogBase<GCMessage> {
67 private:
68 void log_heap(CollectedHeap* heap, bool before);
200 CMSHeap
201 };
202
203 static inline size_t filler_array_max_size() {
204 return _filler_array_max_size;
205 }
206
207 virtual Name kind() const = 0;
208
209 virtual const char* name() const = 0;
210
211 /**
212 * Returns JNI error code JNI_ENOMEM if memory could not be allocated,
213 * and JNI_OK on success.
214 */
215 virtual jint initialize() = 0;
216
217 // In many heaps, there will be a need to perform some initialization activities
218 // after the Universe is fully formed, but before general heap allocation is allowed.
219 // This is the correct place to place such initialization methods.
220 virtual void post_initialize() = 0;
221
222 // Stop any onging concurrent work and prepare for exit.
223 virtual void stop() {}
224
225 // Stop and resume concurrent GC threads interfering with safepoint operations
226 virtual void safepoint_synchronize_begin() {}
227 virtual void safepoint_synchronize_end() {}
228
229 void initialize_reserved_region(HeapWord *start, HeapWord *end);
230 MemRegion reserved_region() const { return _reserved; }
231 address base() const { return (address)reserved_region().start(); }
232
233 virtual size_t capacity() const = 0;
234 virtual size_t used() const = 0;
235
236 // Return "true" if the part of the heap that allocates Java
237 // objects has reached the maximal committed limit that it can
238 // reach, without a garbage collection.
239 virtual bool is_maximal_no_gc() const = 0;
240
468 bool is_gc_active() const { return _is_gc_active; }
469
470 // Total number of GC collections (started)
471 unsigned int total_collections() const { return _total_collections; }
472 unsigned int total_full_collections() const { return _total_full_collections;}
473
474 // Increment total number of GC collections (started)
475 // Should be protected but used by PSMarkSweep - cleanup for 1.4.2
476 void increment_total_collections(bool full = false) {
477 _total_collections++;
478 if (full) {
479 increment_total_full_collections();
480 }
481 }
482
483 void increment_total_full_collections() { _total_full_collections++; }
484
485 // Return the CollectorPolicy for the heap
486 virtual CollectorPolicy* collector_policy() const = 0;
487
488 // Iterate over all objects, calling "cl.do_object" on each.
489 virtual void object_iterate(ObjectClosure* cl) = 0;
490
491 // Similar to object_iterate() except iterates only
492 // over live objects.
493 virtual void safe_object_iterate(ObjectClosure* cl) = 0;
494
495 // NOTE! There is no requirement that a collector implement these
496 // functions.
497 //
498 // A CollectedHeap is divided into a dense sequence of "blocks"; that is,
499 // each address in the (reserved) heap is a member of exactly
500 // one block. The defining characteristic of a block is that it is
501 // possible to find its size, and thus to progress forward to the next
502 // block. (Blocks may be of different sizes.) Thus, blocks may
503 // represent Java objects, or they might be free blocks in a
504 // free-list-based heap (or subheap), as long as the two kinds are
505 // distinguishable and the size of each is determinable.
506
507 // Returns the address of the start of the "block" that contains the
512
513 // Requires "addr" to be the start of a chunk, and returns its size.
514 // "addr + size" is required to be the start of a new chunk, or the end
515 // of the active area of the heap.
516 virtual size_t block_size(const HeapWord* addr) const = 0;
517
518 // Requires "addr" to be the start of a block, and returns "TRUE" iff
519 // the block is an object.
520 virtual bool block_is_obj(const HeapWord* addr) const = 0;
521
522 // Returns the longest time (in ms) that has elapsed since the last
523 // time that any part of the heap was examined by a garbage collection.
524 virtual jlong millis_since_last_gc() = 0;
525
526 // Perform any cleanup actions necessary before allowing a verification.
527 virtual void prepare_for_verify() = 0;
528
529 // Generate any dumps preceding or following a full gc
530 private:
531 void full_gc_dump(GCTimer* timer, bool before);
532 public:
533 void pre_full_gc_dump(GCTimer* timer);
534 void post_full_gc_dump(GCTimer* timer);
535
536 VirtualSpaceSummary create_heap_space_summary();
537 GCHeapSummary create_heap_summary();
538
539 MetaspaceSummary create_metaspace_summary();
540
541 // Print heap information on the given outputStream.
542 virtual void print_on(outputStream* st) const = 0;
543 // The default behavior is to call print_on() on tty.
544 virtual void print() const {
545 print_on(tty);
546 }
547 // Print more detailed heap information on the given
548 // outputStream. The default behavior is to call print_on(). It is
549 // up to each subclass to override it and add any additional output
550 // it needs.
551 virtual void print_extended_on(outputStream* st) const {
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_GC_SHARED_COLLECTEDHEAP_HPP
26 #define SHARE_VM_GC_SHARED_COLLECTEDHEAP_HPP
27
28 #include "gc/shared/gcCause.hpp"
29 #include "gc/shared/gcWhen.hpp"
30 #include "memory/allocation.hpp"
31 #include "runtime/handles.hpp"
32 #include "runtime/perfData.hpp"
33 #include "runtime/safepoint.hpp"
34 #include "utilities/debug.hpp"
35 #include "utilities/events.hpp"
36 #include "utilities/formatBuffer.hpp"
37 #include "utilities/growableArray.hpp"
38
39 // A "CollectedHeap" is an implementation of a java heap for HotSpot. This
40 // is an abstract class: there may be many different kinds of heaps. This
41 // class defines the functions that a heap must implement, and contains
42 // infrastructure common to all heaps.
43
44 class AdaptiveSizePolicy;
45 class BarrierSet;
46 class CollectorPolicy;
47 class GCHeapSummary;
48 class GCTimer;
49 class GCTracer;
50 class GCMemoryManager;
51 class MemoryPool;
52 class MetaspaceSummary;
53 class Thread;
54 class ThreadClosure;
55 class VirtualSpaceSummary;
56 class WorkGang;
57 class nmethod;
58
59 class GCMessage : public FormatBuffer<1024> {
60 public:
61 bool is_before;
62
63 public:
64 GCMessage() {}
65 };
66
67 class CollectedHeap;
68
69 class GCHeapLog : public EventLogBase<GCMessage> {
70 private:
71 void log_heap(CollectedHeap* heap, bool before);
203 CMSHeap
204 };
205
206 static inline size_t filler_array_max_size() {
207 return _filler_array_max_size;
208 }
209
210 virtual Name kind() const = 0;
211
212 virtual const char* name() const = 0;
213
214 /**
215 * Returns JNI error code JNI_ENOMEM if memory could not be allocated,
216 * and JNI_OK on success.
217 */
218 virtual jint initialize() = 0;
219
220 // In many heaps, there will be a need to perform some initialization activities
221 // after the Universe is fully formed, but before general heap allocation is allowed.
222 // This is the correct place to place such initialization methods.
223 virtual void post_initialize();
224
225 // Stop any onging concurrent work and prepare for exit.
226 virtual void stop() {}
227
228 // Stop and resume concurrent GC threads interfering with safepoint operations
229 virtual void safepoint_synchronize_begin() {}
230 virtual void safepoint_synchronize_end() {}
231
232 void initialize_reserved_region(HeapWord *start, HeapWord *end);
233 MemRegion reserved_region() const { return _reserved; }
234 address base() const { return (address)reserved_region().start(); }
235
236 virtual size_t capacity() const = 0;
237 virtual size_t used() const = 0;
238
239 // Return "true" if the part of the heap that allocates Java
240 // objects has reached the maximal committed limit that it can
241 // reach, without a garbage collection.
242 virtual bool is_maximal_no_gc() const = 0;
243
471 bool is_gc_active() const { return _is_gc_active; }
472
473 // Total number of GC collections (started)
474 unsigned int total_collections() const { return _total_collections; }
475 unsigned int total_full_collections() const { return _total_full_collections;}
476
477 // Increment total number of GC collections (started)
478 // Should be protected but used by PSMarkSweep - cleanup for 1.4.2
479 void increment_total_collections(bool full = false) {
480 _total_collections++;
481 if (full) {
482 increment_total_full_collections();
483 }
484 }
485
486 void increment_total_full_collections() { _total_full_collections++; }
487
488 // Return the CollectorPolicy for the heap
489 virtual CollectorPolicy* collector_policy() const = 0;
490
491 virtual GrowableArray<GCMemoryManager*> memory_managers() = 0;
492 virtual GrowableArray<MemoryPool*> memory_pools() = 0;
493
494 // Iterate over all objects, calling "cl.do_object" on each.
495 virtual void object_iterate(ObjectClosure* cl) = 0;
496
497 // Similar to object_iterate() except iterates only
498 // over live objects.
499 virtual void safe_object_iterate(ObjectClosure* cl) = 0;
500
501 // NOTE! There is no requirement that a collector implement these
502 // functions.
503 //
504 // A CollectedHeap is divided into a dense sequence of "blocks"; that is,
505 // each address in the (reserved) heap is a member of exactly
506 // one block. The defining characteristic of a block is that it is
507 // possible to find its size, and thus to progress forward to the next
508 // block. (Blocks may be of different sizes.) Thus, blocks may
509 // represent Java objects, or they might be free blocks in a
510 // free-list-based heap (or subheap), as long as the two kinds are
511 // distinguishable and the size of each is determinable.
512
513 // Returns the address of the start of the "block" that contains the
518
519 // Requires "addr" to be the start of a chunk, and returns its size.
520 // "addr + size" is required to be the start of a new chunk, or the end
521 // of the active area of the heap.
522 virtual size_t block_size(const HeapWord* addr) const = 0;
523
524 // Requires "addr" to be the start of a block, and returns "TRUE" iff
525 // the block is an object.
526 virtual bool block_is_obj(const HeapWord* addr) const = 0;
527
528 // Returns the longest time (in ms) that has elapsed since the last
529 // time that any part of the heap was examined by a garbage collection.
530 virtual jlong millis_since_last_gc() = 0;
531
532 // Perform any cleanup actions necessary before allowing a verification.
533 virtual void prepare_for_verify() = 0;
534
535 // Generate any dumps preceding or following a full gc
536 private:
537 void full_gc_dump(GCTimer* timer, bool before);
538
539 virtual void initialize_serviceability() = 0;
540
541 public:
542 void pre_full_gc_dump(GCTimer* timer);
543 void post_full_gc_dump(GCTimer* timer);
544
545 VirtualSpaceSummary create_heap_space_summary();
546 GCHeapSummary create_heap_summary();
547
548 MetaspaceSummary create_metaspace_summary();
549
550 // Print heap information on the given outputStream.
551 virtual void print_on(outputStream* st) const = 0;
552 // The default behavior is to call print_on() on tty.
553 virtual void print() const {
554 print_on(tty);
555 }
556 // Print more detailed heap information on the given
557 // outputStream. The default behavior is to call print_on(). It is
558 // up to each subclass to override it and add any additional output
559 // it needs.
560 virtual void print_extended_on(outputStream* st) const {
|