1 /* 2 * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 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_GC_SHARED_SPACE_HPP 26 #define SHARE_GC_SHARED_SPACE_HPP 27 28 #include "gc/shared/blockOffsetTable.hpp" 29 #include "gc/shared/cardTable.hpp" 30 #include "gc/shared/workgroup.hpp" 31 #include "memory/allocation.hpp" 32 #include "memory/iterator.hpp" 33 #include "memory/memRegion.hpp" 34 #include "oops/markWord.hpp" 35 #include "runtime/mutexLocker.hpp" 36 #include "utilities/align.hpp" 37 #include "utilities/macros.hpp" 38 39 // A space is an abstraction for the "storage units" backing 40 // up the generation abstraction. It includes specific 41 // implementations for keeping track of free and used space, 42 // for iterating over objects and free blocks, etc. 43 44 // Forward decls. 45 class Space; 46 class BlockOffsetArray; 47 class BlockOffsetArrayContigSpace; 48 class Generation; 49 class CompactibleSpace; 50 class BlockOffsetTable; 51 class CardTableRS; 52 class DirtyCardToOopClosure; 53 54 // A Space describes a heap area. Class Space is an abstract 55 // base class. 56 // 57 // Space supports allocation, size computation and GC support is provided. 58 // 59 // Invariant: bottom() and end() are on page_size boundaries and 60 // bottom() <= top() <= end() 61 // top() is inclusive and end() is exclusive. 62 63 class Space: public CHeapObj<mtGC> { 64 friend class VMStructs; 65 protected: 66 HeapWord* _bottom; 67 HeapWord* _end; 68 69 // Used in support of save_marks() 70 HeapWord* _saved_mark_word; 71 72 Space(): 73 _bottom(NULL), _end(NULL) { } 74 75 public: 76 // Accessors 77 HeapWord* bottom() const { return _bottom; } 78 HeapWord* end() const { return _end; } 79 virtual void set_bottom(HeapWord* value) { _bottom = value; } 80 virtual void set_end(HeapWord* value) { _end = value; } 81 82 virtual HeapWord* saved_mark_word() const { return _saved_mark_word; } 83 84 void set_saved_mark_word(HeapWord* p) { _saved_mark_word = p; } 85 86 // Returns true if this object has been allocated since a 87 // generation's "save_marks" call. 88 virtual bool obj_allocated_since_save_marks(const oop obj) const { 89 return cast_from_oop<HeapWord*>(obj) >= saved_mark_word(); 90 } 91 92 // Returns a subregion of the space containing only the allocated objects in 93 // the space. 94 virtual MemRegion used_region() const = 0; 95 96 // Returns a region that is guaranteed to contain (at least) all objects 97 // allocated at the time of the last call to "save_marks". If the space 98 // initializes its DirtyCardToOopClosure's specifying the "contig" option 99 // (that is, if the space is contiguous), then this region must contain only 100 // such objects: the memregion will be from the bottom of the region to the 101 // saved mark. Otherwise, the "obj_allocated_since_save_marks" method of 102 // the space must distinguish between objects in the region allocated before 103 // and after the call to save marks. 104 MemRegion used_region_at_save_marks() const { 105 return MemRegion(bottom(), saved_mark_word()); 106 } 107 108 // Initialization. 109 // "initialize" should be called once on a space, before it is used for 110 // any purpose. The "mr" arguments gives the bounds of the space, and 111 // the "clear_space" argument should be true unless the memory in "mr" is 112 // known to be zeroed. 113 virtual void initialize(MemRegion mr, bool clear_space, bool mangle_space); 114 115 // The "clear" method must be called on a region that may have 116 // had allocation performed in it, but is now to be considered empty. 117 virtual void clear(bool mangle_space); 118 119 // For detecting GC bugs. Should only be called at GC boundaries, since 120 // some unused space may be used as scratch space during GC's. 121 // We also call this when expanding a space to satisfy an allocation 122 // request. See bug #4668531 123 virtual void mangle_unused_area() = 0; 124 virtual void mangle_unused_area_complete() = 0; 125 126 // Testers 127 bool is_empty() const { return used() == 0; } 128 bool not_empty() const { return used() > 0; } 129 130 // Returns true iff the given the space contains the 131 // given address as part of an allocated object. For 132 // certain kinds of spaces, this might be a potentially 133 // expensive operation. To prevent performance problems 134 // on account of its inadvertent use in product jvm's, 135 // we restrict its use to assertion checks only. 136 bool is_in(const void* p) const { 137 return used_region().contains(p); 138 } 139 bool is_in(oop obj) const { 140 return is_in((void*)obj); 141 } 142 143 // Returns true iff the given reserved memory of the space contains the 144 // given address. 145 bool is_in_reserved(const void* p) const { return _bottom <= p && p < _end; } 146 147 // Returns true iff the given block is not allocated. 148 virtual bool is_free_block(const HeapWord* p) const = 0; 149 150 // Test whether p is double-aligned 151 static bool is_aligned(void* p) { 152 return ::is_aligned(p, sizeof(double)); 153 } 154 155 // Size computations. Sizes are in bytes. 156 size_t capacity() const { return byte_size(bottom(), end()); } 157 virtual size_t used() const = 0; 158 virtual size_t free() const = 0; 159 160 // Iterate over all the ref-containing fields of all objects in the 161 // space, calling "cl.do_oop" on each. Fields in objects allocated by 162 // applications of the closure are not included in the iteration. 163 virtual void oop_iterate(OopIterateClosure* cl); 164 165 // Iterate over all objects in the space, calling "cl.do_object" on 166 // each. Objects allocated by applications of the closure are not 167 // included in the iteration. 168 virtual void object_iterate(ObjectClosure* blk) = 0; 169 170 // Create and return a new dirty card to oop closure. Can be 171 // overridden to return the appropriate type of closure 172 // depending on the type of space in which the closure will 173 // operate. ResourceArea allocated. 174 virtual DirtyCardToOopClosure* new_dcto_cl(OopIterateClosure* cl, 175 CardTable::PrecisionStyle precision, 176 HeapWord* boundary); 177 178 // If "p" is in the space, returns the address of the start of the 179 // "block" that contains "p". We say "block" instead of "object" since 180 // some heaps may not pack objects densely; a chunk may either be an 181 // object or a non-object. If "p" is not in the space, return NULL. 182 virtual HeapWord* block_start_const(const void* p) const = 0; 183 184 // The non-const version may have benevolent side effects on the data 185 // structure supporting these calls, possibly speeding up future calls. 186 // The default implementation, however, is simply to call the const 187 // version. 188 virtual HeapWord* block_start(const void* p); 189 190 // Requires "addr" to be the start of a chunk, and returns its size. 191 // "addr + size" is required to be the start of a new chunk, or the end 192 // of the active area of the heap. 193 virtual size_t block_size(const HeapWord* addr) const = 0; 194 195 // Requires "addr" to be the start of a block, and returns "TRUE" iff 196 // the block is an object. 197 virtual bool block_is_obj(const HeapWord* addr) const = 0; 198 199 // Requires "addr" to be the start of a block, and returns "TRUE" iff 200 // the block is an object and the object is alive. 201 virtual bool obj_is_alive(const HeapWord* addr) const; 202 203 // Allocation (return NULL if full). Assumes the caller has established 204 // mutually exclusive access to the space. 205 virtual HeapWord* allocate(size_t word_size) = 0; 206 207 // Allocation (return NULL if full). Enforces mutual exclusion internally. 208 virtual HeapWord* par_allocate(size_t word_size) = 0; 209 210 #if INCLUDE_SERIALGC 211 // Mark-sweep-compact support: all spaces can update pointers to objects 212 // moving as a part of compaction. 213 virtual void adjust_pointers() = 0; 214 #endif 215 216 virtual void print() const; 217 virtual void print_on(outputStream* st) const; 218 virtual void print_short() const; 219 virtual void print_short_on(outputStream* st) const; 220 221 222 // IF "this" is a ContiguousSpace, return it, else return NULL. 223 virtual ContiguousSpace* toContiguousSpace() { 224 return NULL; 225 } 226 227 // Debugging 228 virtual void verify() const = 0; 229 }; 230 231 // A MemRegionClosure (ResourceObj) whose "do_MemRegion" function applies an 232 // OopClosure to (the addresses of) all the ref-containing fields that could 233 // be modified by virtue of the given MemRegion being dirty. (Note that 234 // because of the imprecise nature of the write barrier, this may iterate 235 // over oops beyond the region.) 236 // This base type for dirty card to oop closures handles memory regions 237 // in non-contiguous spaces with no boundaries, and should be sub-classed 238 // to support other space types. See ContiguousDCTOC for a sub-class 239 // that works with ContiguousSpaces. 240 241 class DirtyCardToOopClosure: public MemRegionClosureRO { 242 protected: 243 OopIterateClosure* _cl; 244 Space* _sp; 245 CardTable::PrecisionStyle _precision; 246 HeapWord* _boundary; // If non-NULL, process only non-NULL oops 247 // pointing below boundary. 248 HeapWord* _min_done; // ObjHeadPreciseArray precision requires 249 // a downwards traversal; this is the 250 // lowest location already done (or, 251 // alternatively, the lowest address that 252 // shouldn't be done again. NULL means infinity.) 253 NOT_PRODUCT(HeapWord* _last_bottom;) 254 NOT_PRODUCT(HeapWord* _last_explicit_min_done;) 255 256 // Get the actual top of the area on which the closure will 257 // operate, given where the top is assumed to be (the end of the 258 // memory region passed to do_MemRegion) and where the object 259 // at the top is assumed to start. For example, an object may 260 // start at the top but actually extend past the assumed top, 261 // in which case the top becomes the end of the object. 262 virtual HeapWord* get_actual_top(HeapWord* top, HeapWord* top_obj); 263 264 // Walk the given memory region from bottom to (actual) top 265 // looking for objects and applying the oop closure (_cl) to 266 // them. The base implementation of this treats the area as 267 // blocks, where a block may or may not be an object. Sub- 268 // classes should override this to provide more accurate 269 // or possibly more efficient walking. 270 virtual void walk_mem_region(MemRegion mr, HeapWord* bottom, HeapWord* top); 271 272 public: 273 DirtyCardToOopClosure(Space* sp, OopIterateClosure* cl, 274 CardTable::PrecisionStyle precision, 275 HeapWord* boundary) : 276 _cl(cl), _sp(sp), _precision(precision), _boundary(boundary), 277 _min_done(NULL) { 278 NOT_PRODUCT(_last_bottom = NULL); 279 NOT_PRODUCT(_last_explicit_min_done = NULL); 280 } 281 282 void do_MemRegion(MemRegion mr); 283 284 void set_min_done(HeapWord* min_done) { 285 _min_done = min_done; 286 NOT_PRODUCT(_last_explicit_min_done = _min_done); 287 } 288 #ifndef PRODUCT 289 void set_last_bottom(HeapWord* last_bottom) { 290 _last_bottom = last_bottom; 291 } 292 #endif 293 }; 294 295 // A structure to represent a point at which objects are being copied 296 // during compaction. 297 class CompactPoint : public StackObj { 298 public: 299 Generation* gen; 300 CompactibleSpace* space; 301 HeapWord* threshold; 302 303 CompactPoint(Generation* g = NULL) : 304 gen(g), space(NULL), threshold(0) {} 305 }; 306 307 // A space that supports compaction operations. This is usually, but not 308 // necessarily, a space that is normally contiguous. But, for example, a 309 // free-list-based space whose normal collection is a mark-sweep without 310 // compaction could still support compaction in full GC's. 311 // 312 // The compaction operations are implemented by the 313 // scan_and_{adjust_pointers,compact,forward} function templates. 314 // The following are, non-virtual, auxiliary functions used by these function templates: 315 // - scan_limit() 316 // - scanned_block_is_obj() 317 // - scanned_block_size() 318 // - adjust_obj_size() 319 // - obj_size() 320 // These functions are to be used exclusively by the scan_and_* function templates, 321 // and must be defined for all (non-abstract) subclasses of CompactibleSpace. 322 // 323 // NOTE: Any subclasses to CompactibleSpace wanting to change/define the behavior 324 // in any of the auxiliary functions must also override the corresponding 325 // prepare_for_compaction/adjust_pointers/compact functions using them. 326 // If not, such changes will not be used or have no effect on the compaction operations. 327 // 328 // This translates to the following dependencies: 329 // Overrides/definitions of 330 // - scan_limit 331 // - scanned_block_is_obj 332 // - scanned_block_size 333 // require override/definition of prepare_for_compaction(). 334 // Similar dependencies exist between 335 // - adjust_obj_size and adjust_pointers() 336 // - obj_size and compact(). 337 // 338 // Additionally, this also means that changes to block_size() or block_is_obj() that 339 // should be effective during the compaction operations must provide a corresponding 340 // definition of scanned_block_size/scanned_block_is_obj respectively. 341 class CompactibleSpace: public Space { 342 friend class VMStructs; 343 private: 344 HeapWord* _compaction_top; 345 CompactibleSpace* _next_compaction_space; 346 347 // Auxiliary functions for scan_and_{forward,adjust_pointers,compact} support. 348 inline size_t adjust_obj_size(size_t size) const { 349 return size; 350 } 351 352 inline size_t obj_size(const HeapWord* addr) const; 353 354 template <class SpaceType> 355 static inline void verify_up_to_first_dead(SpaceType* space) NOT_DEBUG_RETURN; 356 357 template <class SpaceType> 358 static inline void clear_empty_region(SpaceType* space); 359 360 public: 361 CompactibleSpace() : 362 _compaction_top(NULL), _next_compaction_space(NULL) {} 363 364 virtual void initialize(MemRegion mr, bool clear_space, bool mangle_space); 365 virtual void clear(bool mangle_space); 366 367 // Used temporarily during a compaction phase to hold the value 368 // top should have when compaction is complete. 369 HeapWord* compaction_top() const { return _compaction_top; } 370 371 void set_compaction_top(HeapWord* value) { 372 assert(value == NULL || (value >= bottom() && value <= end()), 373 "should point inside space"); 374 _compaction_top = value; 375 } 376 377 // Perform operations on the space needed after a compaction 378 // has been performed. 379 virtual void reset_after_compaction() = 0; 380 381 // Returns the next space (in the current generation) to be compacted in 382 // the global compaction order. Also is used to select the next 383 // space into which to compact. 384 385 virtual CompactibleSpace* next_compaction_space() const { 386 return _next_compaction_space; 387 } 388 389 void set_next_compaction_space(CompactibleSpace* csp) { 390 _next_compaction_space = csp; 391 } 392 393 #if INCLUDE_SERIALGC 394 // MarkSweep support phase2 395 396 // Start the process of compaction of the current space: compute 397 // post-compaction addresses, and insert forwarding pointers. The fields 398 // "cp->gen" and "cp->compaction_space" are the generation and space into 399 // which we are currently compacting. This call updates "cp" as necessary, 400 // and leaves the "compaction_top" of the final value of 401 // "cp->compaction_space" up-to-date. Offset tables may be updated in 402 // this phase as if the final copy had occurred; if so, "cp->threshold" 403 // indicates when the next such action should be taken. 404 virtual void prepare_for_compaction(CompactPoint* cp) = 0; 405 // MarkSweep support phase3 406 virtual void adjust_pointers(); 407 // MarkSweep support phase4 408 virtual void compact(); 409 #endif // INCLUDE_SERIALGC 410 411 // The maximum percentage of objects that can be dead in the compacted 412 // live part of a compacted space ("deadwood" support.) 413 virtual size_t allowed_dead_ratio() const { return 0; }; 414 415 // Some contiguous spaces may maintain some data structures that should 416 // be updated whenever an allocation crosses a boundary. This function 417 // returns the first such boundary. 418 // (The default implementation returns the end of the space, so the 419 // boundary is never crossed.) 420 virtual HeapWord* initialize_threshold() { return end(); } 421 422 // "q" is an object of the given "size" that should be forwarded; 423 // "cp" names the generation ("gen") and containing "this" (which must 424 // also equal "cp->space"). "compact_top" is where in "this" the 425 // next object should be forwarded to. If there is room in "this" for 426 // the object, insert an appropriate forwarding pointer in "q". 427 // If not, go to the next compaction space (there must 428 // be one, since compaction must succeed -- we go to the first space of 429 // the previous generation if necessary, updating "cp"), reset compact_top 430 // and then forward. In either case, returns the new value of "compact_top". 431 // If the forwarding crosses "cp->threshold", invokes the "cross_threshold" 432 // function of the then-current compaction space, and updates "cp->threshold 433 // accordingly". 434 template <bool ALT_FWD> 435 HeapWord* forward(oop q, size_t size, CompactPoint* cp, 436 HeapWord* compact_top); 437 438 // Return a size with adjustments as required of the space. 439 virtual size_t adjust_object_size_v(size_t size) const { return size; } 440 441 void set_first_dead(HeapWord* value) { _first_dead = value; } 442 void set_end_of_live(HeapWord* value) { _end_of_live = value; } 443 444 protected: 445 // Used during compaction. 446 HeapWord* _first_dead; 447 HeapWord* _end_of_live; 448 449 // This the function is invoked when an allocation of an object covering 450 // "start" to "end occurs crosses the threshold; returns the next 451 // threshold. (The default implementation does nothing.) 452 virtual HeapWord* cross_threshold(HeapWord* start, HeapWord* the_end) { 453 return end(); 454 } 455 456 // Below are template functions for scan_and_* algorithms (avoiding virtual calls). 457 // The space argument should be a subclass of CompactibleSpace, implementing 458 // scan_limit(), scanned_block_is_obj(), and scanned_block_size(), 459 // and possibly also overriding obj_size(), and adjust_obj_size(). 460 // These functions should avoid virtual calls whenever possible. 461 462 #if INCLUDE_SERIALGC 463 // Frequently calls adjust_obj_size(). 464 template <bool ALT_FWD, class SpaceType> 465 static inline void scan_and_adjust_pointers(SpaceType* space); 466 #endif 467 468 // Frequently calls obj_size(). 469 template <bool ALT_FWD, class SpaceType> 470 static inline void scan_and_compact(SpaceType* space); 471 472 // Frequently calls scanned_block_is_obj() and scanned_block_size(). 473 // Requires the scan_limit() function. 474 template <bool ALT_FWD, class SpaceType> 475 static inline void scan_and_forward(SpaceType* space, CompactPoint* cp); 476 }; 477 478 class GenSpaceMangler; 479 480 // A space in which the free area is contiguous. It therefore supports 481 // faster allocation, and compaction. 482 class ContiguousSpace: public CompactibleSpace { 483 friend class VMStructs; 484 // Allow scan_and_forward function to call (private) overrides for auxiliary functions on this class 485 template <bool ALT_FWD, typename SpaceType> 486 friend void CompactibleSpace::scan_and_forward(SpaceType* space, CompactPoint* cp); 487 488 private: 489 // Auxiliary functions for scan_and_forward support. 490 // See comments for CompactibleSpace for more information. 491 inline HeapWord* scan_limit() const { 492 return top(); 493 } 494 495 inline bool scanned_block_is_obj(const HeapWord* addr) const { 496 return true; // Always true, since scan_limit is top 497 } 498 499 inline size_t scanned_block_size(const HeapWord* addr) const; 500 501 protected: 502 HeapWord* _top; 503 // A helper for mangling the unused area of the space in debug builds. 504 GenSpaceMangler* _mangler; 505 506 GenSpaceMangler* mangler() { return _mangler; } 507 508 // Allocation helpers (return NULL if full). 509 inline HeapWord* allocate_impl(size_t word_size); 510 inline HeapWord* par_allocate_impl(size_t word_size); 511 512 public: 513 ContiguousSpace(); 514 ~ContiguousSpace(); 515 516 virtual void initialize(MemRegion mr, bool clear_space, bool mangle_space); 517 virtual void clear(bool mangle_space); 518 519 // Accessors 520 HeapWord* top() const { return _top; } 521 void set_top(HeapWord* value) { _top = value; } 522 523 void set_saved_mark() { _saved_mark_word = top(); } 524 void reset_saved_mark() { _saved_mark_word = bottom(); } 525 526 bool saved_mark_at_top() const { return saved_mark_word() == top(); } 527 528 // In debug mode mangle (write it with a particular bit 529 // pattern) the unused part of a space. 530 531 // Used to save the an address in a space for later use during mangling. 532 void set_top_for_allocations(HeapWord* v) PRODUCT_RETURN; 533 // Used to save the space's current top for later use during mangling. 534 void set_top_for_allocations() PRODUCT_RETURN; 535 536 // Mangle regions in the space from the current top up to the 537 // previously mangled part of the space. 538 void mangle_unused_area() PRODUCT_RETURN; 539 // Mangle [top, end) 540 void mangle_unused_area_complete() PRODUCT_RETURN; 541 542 // Do some sparse checking on the area that should have been mangled. 543 void check_mangled_unused_area(HeapWord* limit) PRODUCT_RETURN; 544 // Check the complete area that should have been mangled. 545 // This code may be NULL depending on the macro DEBUG_MANGLING. 546 void check_mangled_unused_area_complete() PRODUCT_RETURN; 547 548 // Size computations: sizes in bytes. 549 size_t capacity() const { return byte_size(bottom(), end()); } 550 size_t used() const { return byte_size(bottom(), top()); } 551 size_t free() const { return byte_size(top(), end()); } 552 553 virtual bool is_free_block(const HeapWord* p) const; 554 555 // In a contiguous space we have a more obvious bound on what parts 556 // contain objects. 557 MemRegion used_region() const { return MemRegion(bottom(), top()); } 558 559 // Allocation (return NULL if full) 560 virtual HeapWord* allocate(size_t word_size); 561 virtual HeapWord* par_allocate(size_t word_size); 562 563 // Iteration 564 void oop_iterate(OopIterateClosure* cl); 565 void object_iterate(ObjectClosure* blk); 566 567 // Compaction support 568 virtual void reset_after_compaction() { 569 assert(compaction_top() >= bottom() && compaction_top() <= end(), "should point inside space"); 570 set_top(compaction_top()); 571 } 572 573 // Override. 574 DirtyCardToOopClosure* new_dcto_cl(OopIterateClosure* cl, 575 CardTable::PrecisionStyle precision, 576 HeapWord* boundary); 577 578 // Apply "blk->do_oop" to the addresses of all reference fields in objects 579 // starting with the _saved_mark_word, which was noted during a generation's 580 // save_marks and is required to denote the head of an object. 581 // Fields in objects allocated by applications of the closure 582 // *are* included in the iteration. 583 // Updates _saved_mark_word to point to just after the last object 584 // iterated over. 585 template <typename OopClosureType> 586 void oop_since_save_marks_iterate(OopClosureType* blk); 587 588 // Same as object_iterate, but starting from "mark", which is required 589 // to denote the start of an object. Objects allocated by 590 // applications of the closure *are* included in the iteration. 591 virtual void object_iterate_from(HeapWord* mark, ObjectClosure* blk); 592 593 // Very inefficient implementation. 594 virtual HeapWord* block_start_const(const void* p) const; 595 size_t block_size(const HeapWord* p) const; 596 // If a block is in the allocated area, it is an object. 597 bool block_is_obj(const HeapWord* p) const { return p < top(); } 598 599 // Addresses for inlined allocation 600 HeapWord** top_addr() { return &_top; } 601 HeapWord** end_addr() { return &_end; } 602 603 #if INCLUDE_SERIALGC 604 // Overrides for more efficient compaction support. 605 void prepare_for_compaction(CompactPoint* cp); 606 #endif 607 608 virtual void print_on(outputStream* st) const; 609 610 // Checked dynamic downcasts. 611 virtual ContiguousSpace* toContiguousSpace() { 612 return this; 613 } 614 615 // Debugging 616 virtual void verify() const; 617 618 // Used to increase collection frequency. "factor" of 0 means entire 619 // space. 620 void allocate_temporary_filler(int factor); 621 }; 622 623 624 // A dirty card to oop closure that does filtering. 625 // It knows how to filter out objects that are outside of the _boundary. 626 class FilteringDCTOC : public DirtyCardToOopClosure { 627 protected: 628 // Override. 629 void walk_mem_region(MemRegion mr, 630 HeapWord* bottom, HeapWord* top); 631 632 // Walk the given memory region, from bottom to top, applying 633 // the given oop closure to (possibly) all objects found. The 634 // given oop closure may or may not be the same as the oop 635 // closure with which this closure was created, as it may 636 // be a filtering closure which makes use of the _boundary. 637 // We offer two signatures, so the FilteringClosure static type is 638 // apparent. 639 virtual void walk_mem_region_with_cl(MemRegion mr, 640 HeapWord* bottom, HeapWord* top, 641 OopIterateClosure* cl) = 0; 642 virtual void walk_mem_region_with_cl(MemRegion mr, 643 HeapWord* bottom, HeapWord* top, 644 FilteringClosure* cl) = 0; 645 646 public: 647 FilteringDCTOC(Space* sp, OopIterateClosure* cl, 648 CardTable::PrecisionStyle precision, 649 HeapWord* boundary) : 650 DirtyCardToOopClosure(sp, cl, precision, boundary) {} 651 }; 652 653 // A dirty card to oop closure for contiguous spaces 654 // (ContiguousSpace and sub-classes). 655 // It is a FilteringClosure, as defined above, and it knows: 656 // 657 // 1. That the actual top of any area in a memory region 658 // contained by the space is bounded by the end of the contiguous 659 // region of the space. 660 // 2. That the space is really made up of objects and not just 661 // blocks. 662 663 class ContiguousSpaceDCTOC : public FilteringDCTOC { 664 protected: 665 // Overrides. 666 HeapWord* get_actual_top(HeapWord* top, HeapWord* top_obj); 667 668 virtual void walk_mem_region_with_cl(MemRegion mr, 669 HeapWord* bottom, HeapWord* top, 670 OopIterateClosure* cl); 671 virtual void walk_mem_region_with_cl(MemRegion mr, 672 HeapWord* bottom, HeapWord* top, 673 FilteringClosure* cl); 674 675 public: 676 ContiguousSpaceDCTOC(ContiguousSpace* sp, OopIterateClosure* cl, 677 CardTable::PrecisionStyle precision, 678 HeapWord* boundary) : 679 FilteringDCTOC(sp, cl, precision, boundary) 680 {} 681 }; 682 683 // A ContigSpace that Supports an efficient "block_start" operation via 684 // a BlockOffsetArray (whose BlockOffsetSharedArray may be shared with 685 // other spaces.) This is the abstract base class for old generation 686 // (tenured) spaces. 687 688 class OffsetTableContigSpace: public ContiguousSpace { 689 friend class VMStructs; 690 protected: 691 BlockOffsetArrayContigSpace _offsets; 692 Mutex _par_alloc_lock; 693 694 public: 695 // Constructor 696 OffsetTableContigSpace(BlockOffsetSharedArray* sharedOffsetArray, 697 MemRegion mr); 698 699 void set_bottom(HeapWord* value); 700 void set_end(HeapWord* value); 701 702 void clear(bool mangle_space); 703 704 inline HeapWord* block_start_const(const void* p) const; 705 706 // Add offset table update. 707 virtual inline HeapWord* allocate(size_t word_size); 708 inline HeapWord* par_allocate(size_t word_size); 709 710 // MarkSweep support phase3 711 virtual HeapWord* initialize_threshold(); 712 virtual HeapWord* cross_threshold(HeapWord* start, HeapWord* end); 713 714 virtual void print_on(outputStream* st) const; 715 716 // Debugging 717 void verify() const; 718 }; 719 720 721 // Class TenuredSpace is used by TenuredGeneration 722 723 class TenuredSpace: public OffsetTableContigSpace { 724 friend class VMStructs; 725 protected: 726 // Mark sweep support 727 size_t allowed_dead_ratio() const; 728 public: 729 // Constructor 730 TenuredSpace(BlockOffsetSharedArray* sharedOffsetArray, 731 MemRegion mr) : 732 OffsetTableContigSpace(sharedOffsetArray, mr) {} 733 }; 734 #endif // SHARE_GC_SHARED_SPACE_HPP