Skip to content

Commit 80925fa

Browse files
author
duke
committed
Backport 4378789
1 parent de686f8 commit 80925fa

File tree

7 files changed

+69
-3
lines changed

7 files changed

+69
-3
lines changed

src/hotspot/cpu/ppc/ppc.ad

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6335,8 +6335,36 @@ instruct loadConD_Ex(regD dst, immD src) %{
63356335
// Prefetch instructions.
63366336
// Must be safe to execute with invalid address (cannot fault).
63376337

6338+
// Special prefetch versions which use the dcbz instruction.
6339+
instruct prefetch_alloc_zero(indirectMemory mem, iRegLsrc src) %{
6340+
match(PrefetchAllocation (AddP mem src));
6341+
predicate(AllocatePrefetchStyle == 3);
6342+
ins_cost(MEMORY_REF_COST);
6343+
6344+
format %{ "PREFETCH $mem, 2, $src \t// Prefetch write-many with zero" %}
6345+
size(4);
6346+
ins_encode %{
6347+
__ dcbz($src$$Register, $mem$$base$$Register);
6348+
%}
6349+
ins_pipe(pipe_class_memory);
6350+
%}
6351+
6352+
instruct prefetch_alloc_zero_no_offset(indirectMemory mem) %{
6353+
match(PrefetchAllocation mem);
6354+
predicate(AllocatePrefetchStyle == 3);
6355+
ins_cost(MEMORY_REF_COST);
6356+
6357+
format %{ "PREFETCH $mem, 2 \t// Prefetch write-many with zero" %}
6358+
size(4);
6359+
ins_encode %{
6360+
__ dcbz($mem$$base$$Register);
6361+
%}
6362+
ins_pipe(pipe_class_memory);
6363+
%}
6364+
63386365
instruct prefetch_alloc(indirectMemory mem, iRegLsrc src) %{
63396366
match(PrefetchAllocation (AddP mem src));
6367+
predicate(AllocatePrefetchStyle != 3);
63406368
ins_cost(MEMORY_REF_COST);
63416369

63426370
format %{ "PREFETCH $mem, 2, $src \t// Prefetch write-many" %}
@@ -6349,6 +6377,7 @@ instruct prefetch_alloc(indirectMemory mem, iRegLsrc src) %{
63496377

63506378
instruct prefetch_alloc_no_offset(indirectMemory mem) %{
63516379
match(PrefetchAllocation mem);
6380+
predicate(AllocatePrefetchStyle != 3);
63526381
ins_cost(MEMORY_REF_COST);
63536382

63546383
format %{ "PREFETCH $mem, 2 \t// Prefetch write-many" %}

src/hotspot/share/gc/shared/threadLocalAllocBuffer.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "utilities/copy.hpp"
3838

3939
size_t ThreadLocalAllocBuffer::_max_size = 0;
40+
int ThreadLocalAllocBuffer::_reserve_for_allocation_prefetch = 0;
4041
unsigned int ThreadLocalAllocBuffer::_target_refills = 0;
4142

4243
ThreadLocalAllocBuffer::ThreadLocalAllocBuffer() :
@@ -224,6 +225,30 @@ void ThreadLocalAllocBuffer::startup_initialization() {
224225
// abort during VM initialization.
225226
_target_refills = MAX2(_target_refills, 2U);
226227

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+
227252
// During jvm startup, the main thread is initialized
228253
// before the heap is initialized. So reinitialize it now.
229254
guarantee(Thread::current()->is_Java_thread(), "tlab initialization thread not Java thread");
@@ -429,7 +454,8 @@ void ThreadLocalAllocStats::publish() {
429454
}
430455

431456
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);
433459
}
434460

435461
const HeapWord* ThreadLocalAllocBuffer::start_relaxed() const {

src/hotspot/share/gc/shared/threadLocalAllocBuffer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class ThreadLocalAllocBuffer: public CHeapObj<mtThread> {
5858
size_t _allocated_before_last_gc; // total bytes allocated up until the last gc
5959

6060
static size_t _max_size; // maximum size of any TLAB
61+
static int _reserve_for_allocation_prefetch; // Reserve at the end of the TLAB
6162
static unsigned _target_refills; // expected number of refills between GCs
6263

6364
unsigned _number_of_refills;

src/hotspot/share/opto/macro.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1914,7 +1914,8 @@ Node* PhaseMacroExpand::prefetch_allocation(Node* i_o, Node*& needgc_false,
19141914
transform_later(cache_adr);
19151915
cache_adr = new CastP2XNode(needgc_false, cache_adr);
19161916
transform_later(cache_adr);
1917-
// Address is aligned to execute prefetch to the beginning of cache line size.
1917+
// Address is aligned to execute prefetch to the beginning of cache line size
1918+
// (it is important when BIS instruction is used on SPARC as prefetch).
19181919
Node* mask = _igvn.MakeConX(~(intptr_t)(step_size-1));
19191920
cache_adr = new AndXNode(cache_adr, mask);
19201921
transform_later(cache_adr);

src/hotspot/share/runtime/vmStructs.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@
353353
nonstatic_field(ThreadLocalAllocBuffer, _pf_top, HeapWord*) \
354354
nonstatic_field(ThreadLocalAllocBuffer, _desired_size, size_t) \
355355
nonstatic_field(ThreadLocalAllocBuffer, _refill_waste_limit, size_t) \
356+
static_field(ThreadLocalAllocBuffer, _reserve_for_allocation_prefetch, int) \
356357
static_field(ThreadLocalAllocBuffer, _target_refills, unsigned) \
357358
nonstatic_field(ThreadLocalAllocBuffer, _number_of_refills, unsigned) \
358359
nonstatic_field(ThreadLocalAllocBuffer, _refill_waste, unsigned) \

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/ThreadLocalAllocBuffer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ private long alignmentReserve() {
7676

7777
private long endReserve() {
7878
long labAlignmentReserve = VM.getVM().getLabAlignmentReserve();
79+
long reserveForAllocationPrefetch = VM.getVM().getReserveForAllocationPrefetch();
7980
long heapWordSize = VM.getVM().getHeapWordSize();
8081

81-
return labAlignmentReserve * heapWordSize;
82+
return Math.max(labAlignmentReserve, reserveForAllocationPrefetch) * heapWordSize;
8283
}
8384

8485
/** Support for iteration over heap -- not sure how this will

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/VM.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public class VM {
123123
private int invocationEntryBCI;
124124
private ReversePtrs revPtrs;
125125
private VMRegImpl vmregImpl;
126+
private int reserveForAllocationPrefetch;
126127
private int labAlignmentReserve;
127128

128129
// System.getProperties from debuggee VM
@@ -446,6 +447,8 @@ private VM(TypeDataBase db, JVMDebugger debugger, boolean isBigEndian) {
446447
boolType = (CIntegerType) db.lookupType("bool");
447448

448449
Type threadLocalAllocBuffer = db.lookupType("ThreadLocalAllocBuffer");
450+
CIntegerField reserveForAllocationPrefetchField = threadLocalAllocBuffer.getCIntegerField("_reserve_for_allocation_prefetch");
451+
reserveForAllocationPrefetch = (int)reserveForAllocationPrefetchField.getCInteger(intType);
449452

450453
Type collectedHeap = db.lookupType("CollectedHeap");
451454
CIntegerField labAlignmentReserveField = collectedHeap.getCIntegerField("_lab_alignment_reserve");
@@ -912,6 +915,10 @@ public String getVMInternalInfo() {
912915
return vmInternalInfo;
913916
}
914917

918+
public int getReserveForAllocationPrefetch() {
919+
return reserveForAllocationPrefetch;
920+
}
921+
915922
public int getLabAlignmentReserve() {
916923
return labAlignmentReserve;
917924
}

0 commit comments

Comments
 (0)