|
37 | 37 | #include "utilities/copy.hpp" |
38 | 38 |
|
39 | 39 | size_t ThreadLocalAllocBuffer::_max_size = 0; |
| 40 | +int ThreadLocalAllocBuffer::_reserve_for_allocation_prefetch = 0; |
40 | 41 | unsigned int ThreadLocalAllocBuffer::_target_refills = 0; |
41 | 42 |
|
42 | 43 | ThreadLocalAllocBuffer::ThreadLocalAllocBuffer() : |
@@ -224,6 +225,30 @@ void ThreadLocalAllocBuffer::startup_initialization() { |
224 | 225 | // abort during VM initialization. |
225 | 226 | _target_refills = MAX2(_target_refills, 2U); |
226 | 227 |
|
| 228 | +#ifdef COMPILER2 |
| 229 | + // If the C2 compiler is present, extra space is needed at the end of |
| 230 | + // TLABs, otherwise prefetching instructions generated by the C2 |
| 231 | + // compiler will fault (due to accessing memory outside of heap). |
| 232 | + // The amount of space is the max of the number of lines to |
| 233 | + // prefetch for array and for instance allocations. (Extra space must be |
| 234 | + // reserved to accommodate both types of allocations.) |
| 235 | + // |
| 236 | + // Only SPARC-specific BIS instructions are known to fault. (Those |
| 237 | + // instructions are generated if AllocatePrefetchStyle==3 and |
| 238 | + // AllocatePrefetchInstr==1). To be on the safe side, however, |
| 239 | + // extra space is reserved for all combinations of |
| 240 | + // AllocatePrefetchStyle and AllocatePrefetchInstr. |
| 241 | + // |
| 242 | + // If the C2 compiler is not present, no space is reserved. |
| 243 | + |
| 244 | + // +1 for rounding up to next cache line, +1 to be safe |
| 245 | + if (CompilerConfig::is_c2_or_jvmci_compiler_enabled()) { |
| 246 | + int lines = MAX2(AllocatePrefetchLines, AllocateInstancePrefetchLines) + 2; |
| 247 | + _reserve_for_allocation_prefetch = (AllocatePrefetchDistance + AllocatePrefetchStepSize * lines) / |
| 248 | + (int)HeapWordSize; |
| 249 | + } |
| 250 | +#endif |
| 251 | + |
227 | 252 | // During jvm startup, the main thread is initialized |
228 | 253 | // before the heap is initialized. So reinitialize it now. |
229 | 254 | guarantee(Thread::current()->is_Java_thread(), "tlab initialization thread not Java thread"); |
@@ -429,7 +454,8 @@ void ThreadLocalAllocStats::publish() { |
429 | 454 | } |
430 | 455 |
|
431 | 456 | size_t ThreadLocalAllocBuffer::end_reserve() { |
432 | | - return CollectedHeap::lab_alignment_reserve(); |
| 457 | + size_t reserve_size = CollectedHeap::lab_alignment_reserve(); |
| 458 | + return MAX2(reserve_size, (size_t)_reserve_for_allocation_prefetch); |
433 | 459 | } |
434 | 460 |
|
435 | 461 | const HeapWord* ThreadLocalAllocBuffer::start_relaxed() const { |
|
0 commit comments