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