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_VM_GC_IMPLEMENTATION_PARNEW_PARGCALLOCBUFFER_HPP 26 #define SHARE_VM_GC_IMPLEMENTATION_PARNEW_PARGCALLOCBUFFER_HPP 27 28 #include "gc_implementation/shared/gcUtil.hpp" 29 #include "memory/allocation.hpp" 30 #include "runtime/atomic.hpp" 31 #include "utilities/globalDefinitions.hpp" 32 33 // Forward declarations. 34 class PLABStats; 35 36 // A per-thread allocation buffer used during GC. 37 class ParGCAllocBuffer: public CHeapObj<mtGC> { 38 protected: 39 char head[32]; 40 size_t _word_sz; // In HeapWord units 41 HeapWord* _bottom; 42 HeapWord* _top; 43 HeapWord* _end; // Last allocatable address + 1 44 HeapWord* _hard_end; // _end + AlignmentReserve 45 // In support of ergonomic sizing of PLAB's 46 size_t _allocated; // in HeapWord units 47 size_t _wasted; // in HeapWord units 48 char tail[32]; 49 static size_t AlignmentReserve; 50 51 // Force future allocations to fail and queries for contains() 52 // to return false. Returns the amount of unused space in this PLAB. 53 size_t invalidate() { 54 _end = _hard_end; 55 size_t remaining = pointer_delta(_end, _top); // Calculate remaining space. 56 _top = _end; // Force future allocations to fail. 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 public: 66 // Initializes the buffer to be empty, but with the given "word_sz". 67 // Must get initialized with "set_buf" for an allocation to succeed. 68 ParGCAllocBuffer(size_t word_sz); 69 virtual ~ParGCAllocBuffer() {} 70 71 // Minimum PLAB size. 72 static size_t min_size(); 73 // Maximum PLAB size. 74 static size_t max_size(); 75 76 // If an allocation of the given "word_sz" can be satisfied within the 77 // buffer, do the allocation, returning a pointer to the start of the 78 // allocated block. If the allocation request cannot be satisfied, 79 // return NULL. 80 HeapWord* allocate(size_t word_sz) { 81 HeapWord* res = _top; 82 if (pointer_delta(_end, _top) >= word_sz) { 83 _top = _top + word_sz; 84 return res; 85 } else { 86 return NULL; 87 } 88 } 89 149 size_t _unused; // Unused in last buffer 150 size_t _desired_plab_sz;// Output of filter (below), suitably trimmed and quantized 151 AdaptiveWeightedAverage 152 _filter; // Integrator with decay 153 154 void reset() { 155 _allocated = 0; 156 _wasted = 0; 157 _unused = 0; 158 } 159 public: 160 PLABStats(size_t desired_plab_sz_, unsigned wt) : 161 _allocated(0), 162 _wasted(0), 163 _unused(0), 164 _desired_plab_sz(desired_plab_sz_), 165 _filter(wt) 166 { } 167 168 static const size_t min_size() { 169 return ParGCAllocBuffer::min_size(); 170 } 171 172 static const size_t max_size() { 173 return ParGCAllocBuffer::max_size(); 174 } 175 176 size_t desired_plab_sz() { 177 return _desired_plab_sz; 178 } 179 180 // Updates the current desired PLAB size. Computes the new desired PLAB size, 181 // updates _desired_plab_sz and clears sensor accumulators. 182 void adjust_desired_plab_sz(uint no_of_gc_workers); 183 184 void add_allocated(size_t v) { 185 Atomic::add_ptr(v, &_allocated); 186 } 187 188 void add_unused(size_t v) { 189 Atomic::add_ptr(v, &_unused); 190 } 191 192 void add_wasted(size_t v) { 193 Atomic::add_ptr(v, &_wasted); 194 } 195 }; 196 197 #endif // SHARE_VM_GC_IMPLEMENTATION_PARNEW_PARGCALLOCBUFFER_HPP | 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_VM_GC_IMPLEMENTATION_PARNEW_PLAB_HPP 26 #define SHARE_VM_GC_IMPLEMENTATION_PARNEW_PLAB_HPP 27 28 #include "gc_implementation/shared/gcUtil.hpp" 29 #include "memory/allocation.hpp" 30 #include "runtime/atomic.hpp" 31 #include "utilities/globalDefinitions.hpp" 32 33 // Forward declarations. 34 class PLABStats; 35 36 // A per-thread allocation buffer used during GC. 37 class PLAB: public CHeapObj<mtGC> { 38 protected: 39 char head[32]; 40 size_t _word_sz; // In HeapWord units 41 HeapWord* _bottom; 42 HeapWord* _top; 43 HeapWord* _end; // Last allocatable address + 1 44 HeapWord* _hard_end; // _end + AlignmentReserve 45 // In support of ergonomic sizing of PLAB's 46 size_t _allocated; // in HeapWord units 47 size_t _wasted; // in HeapWord units 48 char tail[32]; 49 static size_t AlignmentReserve; 50 51 // Force future allocations to fail and queries for contains() 52 // to return false. Returns the amount of unused space in this PLAB. 53 size_t invalidate() { 54 _end = _hard_end; 55 size_t remaining = pointer_delta(_end, _top); // Calculate remaining space. 56 _top = _end; // Force future allocations to fail. 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 public: 66 // Initializes the buffer to be empty, but with the given "word_sz". 67 // Must get initialized with "set_buf" for an allocation to succeed. 68 PLAB(size_t word_sz); 69 virtual ~PLAB() {} 70 71 // Minimum PLAB size. 72 static size_t min_size(); 73 // Maximum PLAB size. 74 static size_t max_size(); 75 76 // If an allocation of the given "word_sz" can be satisfied within the 77 // buffer, do the allocation, returning a pointer to the start of the 78 // allocated block. If the allocation request cannot be satisfied, 79 // return NULL. 80 HeapWord* allocate(size_t word_sz) { 81 HeapWord* res = _top; 82 if (pointer_delta(_end, _top) >= word_sz) { 83 _top = _top + word_sz; 84 return res; 85 } else { 86 return NULL; 87 } 88 } 89 149 size_t _unused; // Unused in last buffer 150 size_t _desired_plab_sz;// Output of filter (below), suitably trimmed and quantized 151 AdaptiveWeightedAverage 152 _filter; // Integrator with decay 153 154 void reset() { 155 _allocated = 0; 156 _wasted = 0; 157 _unused = 0; 158 } 159 public: 160 PLABStats(size_t desired_plab_sz_, unsigned wt) : 161 _allocated(0), 162 _wasted(0), 163 _unused(0), 164 _desired_plab_sz(desired_plab_sz_), 165 _filter(wt) 166 { } 167 168 static const size_t min_size() { 169 return PLAB::min_size(); 170 } 171 172 static const size_t max_size() { 173 return PLAB::max_size(); 174 } 175 176 size_t desired_plab_sz() { 177 return _desired_plab_sz; 178 } 179 180 // Updates the current desired PLAB size. Computes the new desired PLAB size, 181 // updates _desired_plab_sz and clears sensor accumulators. 182 void adjust_desired_plab_sz(uint no_of_gc_workers); 183 184 void add_allocated(size_t v) { 185 Atomic::add_ptr(v, &_allocated); 186 } 187 188 void add_unused(size_t v) { 189 Atomic::add_ptr(v, &_unused); 190 } 191 192 void add_wasted(size_t v) { 193 Atomic::add_ptr(v, &_wasted); 194 } 195 }; 196 197 #endif // SHARE_VM_GC_IMPLEMENTATION_PARNEW_PLAB_HPP |