< prev index next >

src/hotspot/share/gc/z/zMarkStackAllocator.cpp

Print this page

149     free_magazine(magazine);
150   }
151 }
152 
153 ZMarkStackMagazine* ZMarkStackAllocator::create_magazine_from_space(uintptr_t addr, size_t size) {
154   assert(is_aligned(size, ZMarkStackSize), "Invalid size");
155 
156   // Use first stack as magazine
157   ZMarkStackMagazine* const magazine = new ((void*)addr) ZMarkStackMagazine();
158   for (size_t i = ZMarkStackSize; i < size; i += ZMarkStackSize) {
159     ZMarkStack* const stack = new ((void*)(addr + i)) ZMarkStack();
160     const bool success = magazine->push(stack);
161     assert(success, "Magazine should never get full");
162   }
163 
164   return magazine;
165 }
166 
167 ZMarkStackMagazine* ZMarkStackAllocator::alloc_magazine() {
168   // Try allocating from the free list first
169   ZMarkStackMagazine* const magazine = _freelist.pop_atomic();
170   if (magazine != NULL) {
171     return magazine;
172   }
173 
174   // Allocate new magazine
175   const uintptr_t addr = _space.alloc(ZMarkStackMagazineSize);
176   if (addr == 0) {
177     return NULL;
178   }
179 
180   return create_magazine_from_space(addr, ZMarkStackMagazineSize);
181 }
182 
183 void ZMarkStackAllocator::free_magazine(ZMarkStackMagazine* magazine) {
184   _freelist.push_atomic(magazine);
185 }

149     free_magazine(magazine);
150   }
151 }
152 
153 ZMarkStackMagazine* ZMarkStackAllocator::create_magazine_from_space(uintptr_t addr, size_t size) {
154   assert(is_aligned(size, ZMarkStackSize), "Invalid size");
155 
156   // Use first stack as magazine
157   ZMarkStackMagazine* const magazine = new ((void*)addr) ZMarkStackMagazine();
158   for (size_t i = ZMarkStackSize; i < size; i += ZMarkStackSize) {
159     ZMarkStack* const stack = new ((void*)(addr + i)) ZMarkStack();
160     const bool success = magazine->push(stack);
161     assert(success, "Magazine should never get full");
162   }
163 
164   return magazine;
165 }
166 
167 ZMarkStackMagazine* ZMarkStackAllocator::alloc_magazine() {
168   // Try allocating from the free list first
169   ZMarkStackMagazine* const magazine = _freelist.pop();
170   if (magazine != NULL) {
171     return magazine;
172   }
173 
174   // Allocate new magazine
175   const uintptr_t addr = _space.alloc(ZMarkStackMagazineSize);
176   if (addr == 0) {
177     return NULL;
178   }
179 
180   return create_magazine_from_space(addr, ZMarkStackMagazineSize);
181 }
182 
183 void ZMarkStackAllocator::free_magazine(ZMarkStackMagazine* magazine) {
184   _freelist.push(magazine);
185 }
< prev index next >