40 friend class VMStructs;
41 private:
42 bool _survivor_is_full;
43 bool _old_is_full;
44 protected:
45 G1CollectedHeap* _g1h;
46
47 virtual MutatorAllocRegion* mutator_alloc_region(AllocationContext_t context) = 0;
48
49 virtual bool survivor_is_full(AllocationContext_t context) const;
50 virtual bool old_is_full(AllocationContext_t context) const;
51
52 virtual void set_survivor_full(AllocationContext_t context);
53 virtual void set_old_full(AllocationContext_t context);
54
55 // Accessors to the allocation regions.
56 virtual SurvivorGCAllocRegion* survivor_gc_alloc_region(AllocationContext_t context) = 0;
57 virtual OldGCAllocRegion* old_gc_alloc_region(AllocationContext_t context) = 0;
58
59 // Allocation attempt during GC for a survivor object / PLAB.
60 inline HeapWord* survivor_attempt_allocation(size_t word_size,
61 AllocationContext_t context);
62 // Allocation attempt during GC for an old object / PLAB.
63 inline HeapWord* old_attempt_allocation(size_t word_size,
64 AllocationContext_t context);
65 public:
66 G1Allocator(G1CollectedHeap* heap) : _g1h(heap), _survivor_is_full(false), _old_is_full(false) { }
67 virtual ~G1Allocator() { }
68
69 static G1Allocator* create_allocator(G1CollectedHeap* g1h);
70
71 #ifdef ASSERT
72 // Do we currently have an active mutator region to allocate into?
73 bool has_mutator_alloc_region(AllocationContext_t context) { return mutator_alloc_region(context)->get() != NULL; }
74 #endif
75 virtual void init_mutator_alloc_region() = 0;
76 virtual void release_mutator_alloc_region() = 0;
77
78 virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info);
79 virtual void release_gc_alloc_regions(EvacuationInfo& evacuation_info) = 0;
80 virtual void abandon_gc_alloc_regions() = 0;
81
82 // Management of retained regions.
83
84 virtual bool is_retained_old_region(HeapRegion* hr) = 0;
85 void reuse_retained_old_region(EvacuationInfo& evacuation_info,
86 OldGCAllocRegion* old,
87 HeapRegion** retained);
88
89 // Allocate blocks of memory during mutator time.
90
91 inline HeapWord* attempt_allocation(size_t word_size, AllocationContext_t context);
92 inline HeapWord* attempt_allocation_locked(size_t word_size, AllocationContext_t context);
93 inline HeapWord* attempt_allocation_force(size_t word_size, AllocationContext_t context);
94
95 size_t unsafe_max_tlab_alloc(AllocationContext_t context);
96
97 // Allocate blocks of memory during garbage collection. Will ensure an
98 // allocation region, either by picking one or expanding the
99 // heap, and then allocate a block of the given size. The block
100 // may not be a humongous - it must fit into a single heap region.
101 HeapWord* par_allocate_during_gc(InCSetState dest,
102 size_t word_size,
103 AllocationContext_t context);
104
105 virtual size_t used_in_alloc_regions() = 0;
106 };
107
108 // The default allocation region manager for G1. Provides a single mutator, survivor
109 // and old generation allocation region.
110 // Can retain the (single) old generation allocation region across GCs.
111 class G1DefaultAllocator : public G1Allocator {
112 protected:
113 // Alloc region used to satisfy mutator allocation requests.
114 MutatorAllocRegion _mutator_alloc_region;
115
116 // Alloc region used to satisfy allocation requests by the GC for
117 // survivor objects.
118 SurvivorGCAllocRegion _survivor_gc_alloc_region;
119
120 // Alloc region used to satisfy allocation requests by the GC for
121 // old objects.
122 OldGCAllocRegion _old_gc_alloc_region;
|
40 friend class VMStructs;
41 private:
42 bool _survivor_is_full;
43 bool _old_is_full;
44 protected:
45 G1CollectedHeap* _g1h;
46
47 virtual MutatorAllocRegion* mutator_alloc_region(AllocationContext_t context) = 0;
48
49 virtual bool survivor_is_full(AllocationContext_t context) const;
50 virtual bool old_is_full(AllocationContext_t context) const;
51
52 virtual void set_survivor_full(AllocationContext_t context);
53 virtual void set_old_full(AllocationContext_t context);
54
55 // Accessors to the allocation regions.
56 virtual SurvivorGCAllocRegion* survivor_gc_alloc_region(AllocationContext_t context) = 0;
57 virtual OldGCAllocRegion* old_gc_alloc_region(AllocationContext_t context) = 0;
58
59 // Allocation attempt during GC for a survivor object / PLAB.
60 inline HeapWord* survivor_attempt_allocation(size_t min_word_size,
61 size_t desired_word_size,
62 size_t* actual_word_size,
63 AllocationContext_t context);
64 // Allocation attempt during GC for an old object / PLAB.
65 inline HeapWord* old_attempt_allocation(size_t min_word_size,
66 size_t desired_word_size,
67 size_t* actual_word_size,
68 AllocationContext_t context);
69 public:
70 G1Allocator(G1CollectedHeap* heap) : _g1h(heap), _survivor_is_full(false), _old_is_full(false) { }
71 virtual ~G1Allocator() { }
72
73 static G1Allocator* create_allocator(G1CollectedHeap* g1h);
74
75 #ifdef ASSERT
76 // Do we currently have an active mutator region to allocate into?
77 bool has_mutator_alloc_region(AllocationContext_t context) { return mutator_alloc_region(context)->get() != NULL; }
78 #endif
79 virtual void init_mutator_alloc_region() = 0;
80 virtual void release_mutator_alloc_region() = 0;
81
82 virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info);
83 virtual void release_gc_alloc_regions(EvacuationInfo& evacuation_info) = 0;
84 virtual void abandon_gc_alloc_regions() = 0;
85
86 // Management of retained regions.
87
88 virtual bool is_retained_old_region(HeapRegion* hr) = 0;
89 void reuse_retained_old_region(EvacuationInfo& evacuation_info,
90 OldGCAllocRegion* old,
91 HeapRegion** retained);
92
93 // Allocate blocks of memory during mutator time.
94
95 inline HeapWord* attempt_allocation(size_t word_size, AllocationContext_t context);
96 inline HeapWord* attempt_allocation_locked(size_t word_size, AllocationContext_t context);
97 inline HeapWord* attempt_allocation_force(size_t word_size, AllocationContext_t context);
98
99 size_t unsafe_max_tlab_alloc(AllocationContext_t context);
100
101 // Allocate blocks of memory during garbage collection. Will ensure an
102 // allocation region, either by picking one or expanding the
103 // heap, and then allocate a block of the given size. The block
104 // may not be a humongous - it must fit into a single heap region.
105 HeapWord* par_allocate_during_gc(InCSetState dest,
106 size_t word_size,
107 AllocationContext_t context);
108
109 HeapWord* par_allocate_during_gc(InCSetState dest,
110 size_t min_word_size,
111 size_t desired_word_size,
112 size_t* actual_word_size,
113 AllocationContext_t context);
114
115 virtual size_t used_in_alloc_regions() = 0;
116 };
117
118 // The default allocation region manager for G1. Provides a single mutator, survivor
119 // and old generation allocation region.
120 // Can retain the (single) old generation allocation region across GCs.
121 class G1DefaultAllocator : public G1Allocator {
122 protected:
123 // Alloc region used to satisfy mutator allocation requests.
124 MutatorAllocRegion _mutator_alloc_region;
125
126 // Alloc region used to satisfy allocation requests by the GC for
127 // survivor objects.
128 SurvivorGCAllocRegion _survivor_gc_alloc_region;
129
130 // Alloc region used to satisfy allocation requests by the GC for
131 // old objects.
132 OldGCAllocRegion _old_gc_alloc_region;
|