Skip to content

Commit 3c5db12

Browse files
committedOct 25, 2024
8342857: SA: Heap iterator makes incorrect assumptions about TLAB layout
Reviewed-by: cjplummer, rkennke, lmesnik
1 parent 4635351 commit 3c5db12

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed
 

‎src/hotspot/share/gc/shared/vmStructs_gc.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
nonstatic_field(CardTableBarrierSet, _defer_initial_card_mark, bool) \
9292
nonstatic_field(CardTableBarrierSet, _card_table, CardTable*) \
9393
\
94+
static_field(CollectedHeap, _lab_alignment_reserve, size_t) \
9495
nonstatic_field(CollectedHeap, _reserved, MemRegion) \
9596
nonstatic_field(CollectedHeap, _is_stw_gc_active, bool) \
9697
nonstatic_field(CollectedHeap, _total_collections, unsigned int) \

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -75,11 +75,11 @@ private long alignmentReserve() {
7575
}
7676

7777
private long endReserve() {
78-
long minFillerArraySize = Array.baseOffsetInBytes(BasicType.T_INT);
78+
long labAlignmentReserve = VM.getVM().getLabAlignmentReserve();
7979
long reserveForAllocationPrefetch = VM.getVM().getReserveForAllocationPrefetch();
8080
long heapWordSize = VM.getVM().getHeapWordSize();
8181

82-
return Math.max(minFillerArraySize, reserveForAllocationPrefetch * heapWordSize);
82+
return Math.max(labAlignmentReserve, reserveForAllocationPrefetch) * heapWordSize;
8383
}
8484

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

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

+29-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -127,6 +127,7 @@ public class VM {
127127
private ReversePtrs revPtrs;
128128
private VMRegImpl vmregImpl;
129129
private int reserveForAllocationPrefetch;
130+
private int labAlignmentReserve;
130131

131132
// System.getProperties from debuggee VM
132133
private Properties sysProps;
@@ -138,12 +139,12 @@ public class VM {
138139
private Flag[] commandLineFlags;
139140
private Map<String, Flag> flagsMap;
140141

141-
private static Type intType;
142-
private static Type uintType;
143-
private static Type intxType;
144-
private static Type uintxType;
145-
private static Type sizetType;
146-
private static Type uint64tType;
142+
private static CIntegerType intType;
143+
private static CIntegerType uintType;
144+
private static CIntegerType intxType;
145+
private static CIntegerType uintxType;
146+
private static CIntegerType sizetType;
147+
private static CIntegerType uint64tType;
147148
private static CIntegerType boolType;
148149
private Boolean sharingEnabled;
149150
private Boolean compressedOopsEnabled;
@@ -432,17 +433,29 @@ private VM(TypeDataBase db, JVMDebugger debugger, boolean isBigEndian) {
432433
vmRelease = CStringUtilities.getString(releaseAddr);
433434
Address vmInternalInfoAddr = vmVersion.getAddressField("_s_internal_vm_info_string").getValue();
434435
vmInternalInfo = CStringUtilities.getString(vmInternalInfoAddr);
435-
436-
Type threadLocalAllocBuffer = db.lookupType("ThreadLocalAllocBuffer");
437-
CIntegerType intType = (CIntegerType) db.lookupType("int");
438-
CIntegerField reserveForAllocationPrefetchField = threadLocalAllocBuffer.getCIntegerField("_reserve_for_allocation_prefetch");
439-
reserveForAllocationPrefetch = (int)reserveForAllocationPrefetchField.getCInteger(intType);
440436
} catch (Exception exp) {
441437
throw new RuntimeException("can't determine target's VM version : " + exp.getMessage());
442438
}
443439

444440
checkVMVersion(vmRelease);
445441

442+
// Initialize common primitive types
443+
intType = (CIntegerType) db.lookupType("int");
444+
uintType = (CIntegerType) db.lookupType("uint");
445+
intxType = (CIntegerType) db.lookupType("intx");
446+
uintxType = (CIntegerType) db.lookupType("uintx");
447+
sizetType = (CIntegerType) db.lookupType("size_t");
448+
uint64tType = (CIntegerType) db.lookupType("uint64_t");
449+
boolType = (CIntegerType) db.lookupType("bool");
450+
451+
Type threadLocalAllocBuffer = db.lookupType("ThreadLocalAllocBuffer");
452+
CIntegerField reserveForAllocationPrefetchField = threadLocalAllocBuffer.getCIntegerField("_reserve_for_allocation_prefetch");
453+
reserveForAllocationPrefetch = (int)reserveForAllocationPrefetchField.getCInteger(intType);
454+
455+
Type collectedHeap = db.lookupType("CollectedHeap");
456+
CIntegerField labAlignmentReserveField = collectedHeap.getCIntegerField("_lab_alignment_reserve");
457+
labAlignmentReserve = (int)labAlignmentReserveField.getCInteger(sizetType);
458+
446459
invocationEntryBCI = db.lookupIntConstant("InvocationEntryBci").intValue();
447460

448461
// We infer the presence of JVMTI from the presence of the InstanceKlass::_breakpoints field.
@@ -493,14 +506,6 @@ private VM(TypeDataBase db, JVMDebugger debugger, boolean isBigEndian) {
493506
Flags_WAS_SET_ON_COMMAND_LINE = db.lookupIntConstant("JVMFlag::WAS_SET_ON_COMMAND_LINE").intValue();
494507
oopSize = db.lookupIntConstant("oopSize").intValue();
495508

496-
intType = db.lookupType("int");
497-
uintType = db.lookupType("uint");
498-
intxType = db.lookupType("intx");
499-
uintxType = db.lookupType("uintx");
500-
sizetType = db.lookupType("size_t");
501-
uint64tType = db.lookupType("uint64_t");
502-
boolType = (CIntegerType) db.lookupType("bool");
503-
504509
minObjAlignmentInBytes = getObjectAlignmentInBytes();
505510
if ((minObjAlignmentInBytes & (minObjAlignmentInBytes - 1)) != 0) {
506511
throw new RuntimeException("Object alignment " + minObjAlignmentInBytes + " is not power of two");
@@ -929,6 +934,10 @@ public int getReserveForAllocationPrefetch() {
929934
return reserveForAllocationPrefetch;
930935
}
931936

937+
public int getLabAlignmentReserve() {
938+
return labAlignmentReserve;
939+
}
940+
932941
public boolean isSharingEnabled() {
933942
if (sharingEnabled == null) {
934943
Address address = VM.getVM().getDebugger().lookup(null, "UseSharedSpaces");

0 commit comments

Comments
 (0)
Please sign in to comment.