57 _bottom = _end; // Force future contains() queries to return false.
58 return remaining;
59 }
60
61 // Fill in remaining space with a dummy object and invalidate the PLAB. Returns
62 // the amount of remaining space.
63 size_t retire_internal();
64
65 void add_undo_waste(HeapWord* obj, size_t word_sz);
66
67 // Undo the last allocation in the buffer, which is required to be of the
68 // "obj" of the given "word_sz".
69 void undo_last_allocation(HeapWord* obj, size_t word_sz);
70
71 public:
72 // Initializes the buffer to be empty, but with the given "word_sz".
73 // Must get initialized with "set_buf" for an allocation to succeed.
74 PLAB(size_t word_sz);
75 virtual ~PLAB() {}
76
77 // Minimum PLAB size.
78 static size_t min_size();
79 // Maximum PLAB size.
80 static size_t max_size();
81
82 // If an allocation of the given "word_sz" can be satisfied within the
83 // buffer, do the allocation, returning a pointer to the start of the
84 // allocated block. If the allocation request cannot be satisfied,
85 // return NULL.
86 HeapWord* allocate(size_t word_sz) {
87 HeapWord* res = _top;
88 if (pointer_delta(_end, _top) >= word_sz) {
89 _top = _top + word_sz;
90 return res;
91 } else {
92 return NULL;
93 }
94 }
95
96 // Allocate the object aligned to "alignment_in_bytes".
97 inline HeapWord* allocate_aligned(size_t word_sz, unsigned short alignment_in_bytes);
98
99 // Undo any allocation in the buffer, which is required to be of the
100 // "obj" of the given "word_sz".
101 void undo_allocation(HeapWord* obj, size_t word_sz);
102
103 // The total (word) size of the buffer, including both allocated and
104 // unallocated space.
105 size_t word_sz() { return _word_sz; }
106
107 size_t waste() { return _wasted; }
108 size_t undo_waste() { return _undo_wasted; }
109
110 // Should only be done if we are about to reset with a new buffer of the
111 // given size.
112 void set_word_size(size_t new_word_sz) {
113 assert(new_word_sz > AlignmentReserve, "Too small");
114 _word_sz = new_word_sz;
115 }
116
117 // The number of words of unallocated space remaining in the buffer.
118 size_t words_remaining() {
119 assert(_end >= _top, "Negative buffer");
120 return pointer_delta(_end, _top, HeapWordSize);
121 }
122
123 bool contains(void* addr) {
124 return (void*)_bottom <= addr && addr < (void*)_hard_end;
125 }
126
127 // Sets the space of the buffer to be [buf, space+word_sz()).
128 virtual void set_buf(HeapWord* buf) {
129 _bottom = buf;
130 _top = _bottom;
131 _hard_end = _bottom + word_sz();
132 _end = _hard_end - AlignmentReserve;
133 assert(_end >= _top, "Negative buffer");
134 // In support of ergonomic sizing
135 _allocated += word_sz();
136 }
137
138 // Flush allocation statistics into the given PLABStats supporting ergonomic
139 // sizing of PLAB's and retire the current buffer. To be called at the end of
140 // GC.
141 virtual void flush_and_retire_stats(PLABStats* stats);
142
143 // Fills in the unallocated portion of the buffer with a garbage object and updates
144 // statistics. To be called during GC.
145 virtual void retire();
146
147 void print() PRODUCT_RETURN;
148 };
|
57 _bottom = _end; // Force future contains() queries to return false.
58 return remaining;
59 }
60
61 // Fill in remaining space with a dummy object and invalidate the PLAB. Returns
62 // the amount of remaining space.
63 size_t retire_internal();
64
65 void add_undo_waste(HeapWord* obj, size_t word_sz);
66
67 // Undo the last allocation in the buffer, which is required to be of the
68 // "obj" of the given "word_sz".
69 void undo_last_allocation(HeapWord* obj, size_t word_sz);
70
71 public:
72 // Initializes the buffer to be empty, but with the given "word_sz".
73 // Must get initialized with "set_buf" for an allocation to succeed.
74 PLAB(size_t word_sz);
75 virtual ~PLAB() {}
76
77 static size_t size_required_for_allocation(size_t word_size) { return word_size + AlignmentReserve; }
78
79 // Minimum PLAB size.
80 static size_t min_size();
81 // Maximum PLAB size.
82 static size_t max_size();
83
84 // If an allocation of the given "word_sz" can be satisfied within the
85 // buffer, do the allocation, returning a pointer to the start of the
86 // allocated block. If the allocation request cannot be satisfied,
87 // return NULL.
88 HeapWord* allocate(size_t word_sz) {
89 HeapWord* res = _top;
90 if (pointer_delta(_end, _top) >= word_sz) {
91 _top = _top + word_sz;
92 return res;
93 } else {
94 return NULL;
95 }
96 }
97
98 // Allocate the object aligned to "alignment_in_bytes".
99 inline HeapWord* allocate_aligned(size_t word_sz, unsigned short alignment_in_bytes);
100
101 // Undo any allocation in the buffer, which is required to be of the
102 // "obj" of the given "word_sz".
103 void undo_allocation(HeapWord* obj, size_t word_sz);
104
105 // The total (word) size of the buffer, including both allocated and
106 // unallocated space.
107 size_t word_sz() { return _word_sz; }
108
109 size_t waste() { return _wasted; }
110 size_t undo_waste() { return _undo_wasted; }
111
112 // The number of words of unallocated space remaining in the buffer.
113 size_t words_remaining() {
114 assert(_end >= _top, "Negative buffer");
115 return pointer_delta(_end, _top, HeapWordSize);
116 }
117
118 bool contains(void* addr) {
119 return (void*)_bottom <= addr && addr < (void*)_hard_end;
120 }
121
122 // Sets the space of the buffer to be [buf, space+word_sz()).
123 virtual void set_buf(HeapWord* buf, size_t new_word_sz) {
124 assert(new_word_sz > AlignmentReserve, "Too small");
125 _word_sz = new_word_sz;
126
127 _bottom = buf;
128 _top = _bottom;
129 _hard_end = _bottom + word_sz();
130 _end = _hard_end - AlignmentReserve;
131 assert(_end >= _top, "Negative buffer");
132 // In support of ergonomic sizing
133 _allocated += word_sz();
134 }
135
136 // Flush allocation statistics into the given PLABStats supporting ergonomic
137 // sizing of PLAB's and retire the current buffer. To be called at the end of
138 // GC.
139 virtual void flush_and_retire_stats(PLABStats* stats);
140
141 // Fills in the unallocated portion of the buffer with a garbage object and updates
142 // statistics. To be called during GC.
143 virtual void retire();
144
145 void print() PRODUCT_RETURN;
146 };
|