304 "Allocation buffer index out-of-bounds: " CSETSTATE_FORMAT, dest.value()); 305 assert(_alloc_buffers[dest.value()] != NULL, 306 "Allocation buffer is NULL: " CSETSTATE_FORMAT, dest.value()); 307 return _alloc_buffers[dest.value()]; 308 } 309 310 virtual void flush_and_retire_stats(); 311 312 virtual void waste(size_t& wasted, size_t& undo_wasted); 313 }; 314 315 // G1ArchiveRegionMap is a boolean array used to mark G1 regions as 316 // archive regions. This allows a quick check for whether an object 317 // should not be marked because it is in an archive region. 318 class G1ArchiveRegionMap : public G1BiasedMappedArray<bool> { 319 protected: 320 bool default_value() const { return false; } 321 }; 322 323 // G1ArchiveAllocator is used to allocate memory in archive 324 // regions. Such regions are not modifiable by GC, being neither 325 // scavenged nor compacted, or even marked in the object header. 326 // They can contain no pointers to non-archive heap regions, 327 class G1ArchiveAllocator : public CHeapObj<mtGC> { 328 protected: 329 G1CollectedHeap* _g1h; 330 331 // The current allocation region 332 HeapRegion* _allocation_region; 333 334 // Regions allocated for the current archive range. 335 GrowableArray<HeapRegion*> _allocated_regions; 336 337 // The number of bytes used in the current range. 338 size_t _summary_bytes_used; 339 340 // Current allocation window within the current region. 341 HeapWord* _bottom; 342 HeapWord* _top; 343 HeapWord* _max; 344 345 // Allocate a new region for this archive allocator. 346 // Allocation is from the top of the reserved heap downward. 347 bool alloc_new_region(); 348 349 public: 350 G1ArchiveAllocator(G1CollectedHeap* g1h) : 351 _g1h(g1h), 352 _allocation_region(NULL), 353 _allocated_regions((ResourceObj::set_allocation_type((address) &_allocated_regions, 354 ResourceObj::C_HEAP), 355 2), true /* C_Heap */), 356 _summary_bytes_used(0), 357 _bottom(NULL), 358 _top(NULL), 359 _max(NULL) { } 360 361 virtual ~G1ArchiveAllocator() { 362 assert(_allocation_region == NULL, "_allocation_region not NULL"); 363 } 364 365 static G1ArchiveAllocator* create_allocator(G1CollectedHeap* g1h); 366 367 // Allocate memory for an individual object. 368 HeapWord* archive_mem_allocate(size_t word_size); 369 370 // Return the memory ranges used in the current archive, after 371 // aligning to the requested alignment. 372 void complete_archive(GrowableArray<MemRegion>* ranges, 373 size_t end_alignment_in_bytes); 374 375 // The number of bytes allocated by this allocator. 376 size_t used() { 377 return _summary_bytes_used; 378 } 379 380 // Clear the count of bytes allocated in prior G1 regions. This 381 // must be done when recalculate_use is used to reset the counter 382 // for the generic allocator, since it counts bytes in all G1 383 // regions, including those still associated with this allocator. 384 void clear_used() { 385 _summary_bytes_used = 0; 386 } 387 388 // Create the _archive_region_map which is used to identify archive objects. 389 static inline void enable_archive_object_check(); 390 391 // Set the regions containing the specified address range as archive/non-archive. 392 static inline void set_range_archive(MemRegion range, bool is_archive); 393 394 static inline bool is_archive_object(oop object); 395 396 private: 397 static bool _archive_check_enabled; 398 static G1ArchiveRegionMap _archive_region_map; 399 400 // Check if an object is in an archive region using the _archive_region_map. 401 static inline bool in_archive_range(oop object); 402 403 // Check if archive object checking is enabled, to avoid calling in_archive_range 404 // unnecessarily. 405 static inline bool archive_check_enabled(); 406 }; 407 408 #endif // SHARE_VM_GC_G1_G1ALLOCATOR_HPP | 304 "Allocation buffer index out-of-bounds: " CSETSTATE_FORMAT, dest.value()); 305 assert(_alloc_buffers[dest.value()] != NULL, 306 "Allocation buffer is NULL: " CSETSTATE_FORMAT, dest.value()); 307 return _alloc_buffers[dest.value()]; 308 } 309 310 virtual void flush_and_retire_stats(); 311 312 virtual void waste(size_t& wasted, size_t& undo_wasted); 313 }; 314 315 // G1ArchiveRegionMap is a boolean array used to mark G1 regions as 316 // archive regions. This allows a quick check for whether an object 317 // should not be marked because it is in an archive region. 318 class G1ArchiveRegionMap : public G1BiasedMappedArray<bool> { 319 protected: 320 bool default_value() const { return false; } 321 }; 322 323 // G1ArchiveAllocator is used to allocate memory in archive 324 // regions. Such regions are not scavenged nor compacted by GC. 325 // There are two types of archive regions, which are 326 // differ in the kind of references allowed for the contained objects: 327 // 328 // - 'Closed' archive region contain no references outside of archive 329 // regions. The region is immutable by GC. GC does not mark object 330 // header in 'closed' archive region. 331 // - An 'open' archive region may contain references pointing to 332 // non-archive heap region. GC can adjust pointers and mark object 333 // header in 'open' archive region. 334 class G1ArchiveAllocator : public CHeapObj<mtGC> { 335 protected: 336 bool _open; // Indicate if the region is 'open' archive. 337 G1CollectedHeap* _g1h; 338 339 // The current allocation region 340 HeapRegion* _allocation_region; 341 342 // Regions allocated for the current archive range. 343 GrowableArray<HeapRegion*> _allocated_regions; 344 345 // The number of bytes used in the current range. 346 size_t _summary_bytes_used; 347 348 // Current allocation window within the current region. 349 HeapWord* _bottom; 350 HeapWord* _top; 351 HeapWord* _max; 352 353 // Allocate a new region for this archive allocator. 354 // Allocation is from the top of the reserved heap downward. 355 bool alloc_new_region(); 356 357 public: 358 G1ArchiveAllocator(G1CollectedHeap* g1h, bool open) : 359 _g1h(g1h), 360 _allocation_region(NULL), 361 _allocated_regions((ResourceObj::set_allocation_type((address) &_allocated_regions, 362 ResourceObj::C_HEAP), 363 2), true /* C_Heap */), 364 _summary_bytes_used(0), 365 _bottom(NULL), 366 _top(NULL), 367 _max(NULL), 368 _open(open) { } 369 370 virtual ~G1ArchiveAllocator() { 371 assert(_allocation_region == NULL, "_allocation_region not NULL"); 372 } 373 374 static G1ArchiveAllocator* create_allocator(G1CollectedHeap* g1h, bool open); 375 376 // Allocate memory for an individual object. 377 HeapWord* archive_mem_allocate(size_t word_size); 378 379 // Return the memory ranges used in the current archive, after 380 // aligning to the requested alignment. 381 void complete_archive(GrowableArray<MemRegion>* ranges, 382 size_t end_alignment_in_bytes); 383 384 // The number of bytes allocated by this allocator. 385 size_t used() { 386 return _summary_bytes_used; 387 } 388 389 // Clear the count of bytes allocated in prior G1 regions. This 390 // must be done when recalculate_use is used to reset the counter 391 // for the generic allocator, since it counts bytes in all G1 392 // regions, including those still associated with this allocator. 393 void clear_used() { 394 _summary_bytes_used = 0; 395 } 396 397 // Create the _archive_region_map which is used to identify archive objects. 398 static inline void enable_archive_object_check(); 399 400 // Set the regions containing the specified address range as archive/non-archive. 401 static inline void set_range_archive(MemRegion range, bool open); 402 403 // Check if the object is in closed archive 404 static inline bool is_closed_archive_object(oop object); 405 // Check if the object is in open archive 406 static inline bool is_open_archive_object(oop object); 407 // Check if the object is either in closed archive or open archive 408 static inline bool is_archive_object(oop object); 409 410 private: 411 static bool _archive_check_enabled; 412 static G1ArchiveRegionMap _closed_archive_region_map; 413 static G1ArchiveRegionMap _open_archive_region_map; 414 415 // Check if an object is in a closed archive region using the _closed_archive_region_map. 416 static inline bool in_closed_archive_range(oop object); 417 // Check if an object is in open archive region using the _open_archive_region_map. 418 static inline bool in_open_archive_range(oop object); 419 420 // Check if archive object checking is enabled, to avoid calling in_open/closed_archive_range 421 // unnecessarily. 422 static inline bool archive_check_enabled(); 423 }; 424 425 #endif // SHARE_VM_GC_G1_G1ALLOCATOR_HPP |