Skip to content

Commit 68b2057

Browse files
author
Boris Ulasevich
committedJun 15, 2022
8287373: remove unnecessary paddings in generated code
Reviewed-by: kvn
1 parent 2471f8f commit 68b2057

File tree

9 files changed

+64
-33
lines changed

9 files changed

+64
-33
lines changed
 

‎src/hotspot/cpu/x86/sharedRuntime_x86_32.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2632,7 +2632,7 @@ SafepointBlob* SharedRuntime::generate_handler_blob(address call_ptr, int poll_t
26322632

26332633
// allocate space for the code
26342634
// setup code generation tools
2635-
CodeBuffer buffer("handler_blob", 1024, 512);
2635+
CodeBuffer buffer("handler_blob", 2048, 1024);
26362636
MacroAssembler* masm = new MacroAssembler(&buffer);
26372637

26382638
const Register java_thread = rdi; // callee-saved for VC++

‎src/hotspot/share/asm/codeBuffer.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,14 @@ CodeBuffer::CodeBuffer(CodeBlob* blob) DEBUG_ONLY(: Scrubber(this, sizeof(*this)
9696
}
9797

9898
void CodeBuffer::initialize(csize_t code_size, csize_t locs_size) {
99-
// Compute maximal alignment.
100-
int align = _insts.alignment();
10199
// Always allow for empty slop around each section.
102100
int slop = (int) CodeSection::end_slop();
103101

102+
assert(SECT_LIMIT == 3, "total_size explicitly lists all section alignments");
103+
int total_size = code_size + _consts.alignment() + _insts.alignment() + _stubs.alignment() + SECT_LIMIT * slop;
104+
104105
assert(blob() == NULL, "only once");
105-
set_blob(BufferBlob::create(_name, code_size + (align+slop) * (SECT_LIMIT+1)));
106+
set_blob(BufferBlob::create(_name, total_size));
106107
if (blob() == NULL) {
107108
// The assembler constructor will throw a fatal on an empty CodeBuffer.
108109
return; // caller must test this

‎src/hotspot/share/asm/codeBuffer.hpp

+25-6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "code/oopRecorder.hpp"
2929
#include "code/relocInfo.hpp"
30+
#include "compiler/compiler_globals.hpp"
3031
#include "utilities/align.hpp"
3132
#include "utilities/debug.hpp"
3233
#include "utilities/macros.hpp"
@@ -251,16 +252,19 @@ class CodeSection {
251252
void relocate(address at, RelocationHolder const& rspec, int format = 0);
252253
void relocate(address at, relocInfo::relocType rtype, int format = 0, jint method_index = 0);
253254

254-
// alignment requirement for starting offset
255-
// Requirements are that the instruction area and the
256-
// stubs area must start on CodeEntryAlignment, and
257-
// the ctable on sizeof(jdouble)
258-
int alignment() const { return MAX2((int)sizeof(jdouble), (int)CodeEntryAlignment); }
255+
static int alignment(int section);
256+
int alignment() { return alignment(_index); }
259257

260258
// Slop between sections, used only when allocating temporary BufferBlob buffers.
261259
static csize_t end_slop() { return MAX2((int)sizeof(jdouble), (int)CodeEntryAlignment); }
262260

263-
csize_t align_at_start(csize_t off) const { return (csize_t) align_up(off, alignment()); }
261+
csize_t align_at_start(csize_t off, int section) const {
262+
return (csize_t) align_up(off, alignment(section));
263+
}
264+
265+
csize_t align_at_start(csize_t off) const {
266+
return (csize_t) align_up(off, alignment(_index));
267+
}
264268

265269
// Ensure there's enough space left in the current section.
266270
// Return true if there was an expansion.
@@ -702,4 +706,19 @@ inline bool CodeSection::maybe_expand_to_ensure_remaining(csize_t amount) {
702706
return false;
703707
}
704708

709+
inline int CodeSection::alignment(int section) {
710+
if (section == CodeBuffer::SECT_CONSTS) {
711+
return (int) sizeof(jdouble);
712+
}
713+
if (section == CodeBuffer::SECT_INSTS) {
714+
return (int) CodeEntryAlignment;
715+
}
716+
if (CodeBuffer::SECT_STUBS) {
717+
// CodeBuffer installer expects sections to be HeapWordSize aligned
718+
return HeapWordSize;
719+
}
720+
ShouldNotReachHere();
721+
return 0;
722+
}
723+
705724
#endif // SHARE_ASM_CODEBUFFER_HPP

‎src/hotspot/share/jvmci/jvmciCodeInstaller.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,13 @@ JVMCI::CodeInstallResult CodeInstaller::initialize_buffer(CodeBuffer& buffer, bo
662662
// section itself so they don't need to be accounted for in the
663663
// locs_buffer above.
664664
int stubs_size = estimate_stubs_size(JVMCI_CHECK_OK);
665-
int total_size = align_up(_code_size, buffer.insts()->alignment()) + align_up(_constants_size, buffer.consts()->alignment()) + align_up(stubs_size, buffer.stubs()->alignment());
665+
666+
assert((CodeBuffer::SECT_INSTS == CodeBuffer::SECT_STUBS - 1) &&
667+
(CodeBuffer::SECT_CONSTS == CodeBuffer::SECT_INSTS - 1), "sections order: consts, insts, stubs");
668+
// buffer content: [constants + code_align] + [code + stubs_align] + [stubs]
669+
int total_size = align_up(_constants_size, CodeSection::alignment(CodeBuffer::SECT_INSTS)) +
670+
align_up(_code_size, CodeSection::alignment(CodeBuffer::SECT_STUBS)) +
671+
stubs_size;
666672

667673
if (check_size && total_size > JVMCINMethodSizeLimit) {
668674
return JVMCI::code_too_large;

‎test/hotspot/jtreg/compiler/jvmci/errors/TestInvalidCompilationResult.java

+21-18
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,12 @@ public boolean equals(Object obj) {
8585
}
8686
}
8787

88+
// DataSectionAlignment value matches the alignment sizeof(jdouble) of the CodeBuffer::SECT_CONSTS code section
89+
static final int validDataSectionAlignment = 8;
90+
8891
@Test(expected = JVMCIError.class)
8992
public void testInvalidAssumption() {
90-
installEmptyCode(new Site[0], new Assumption[]{new InvalidAssumption()}, new Comment[0], 16, new DataPatch[0], null);
93+
installEmptyCode(new Site[0], new Assumption[]{new InvalidAssumption()}, new Comment[0], validDataSectionAlignment, new DataPatch[0], null);
9194
}
9295

9396
@Test(expected = JVMCIError.class)
@@ -97,101 +100,101 @@ public void testInvalidAlignment() {
97100

98101
@Test(expected = NullPointerException.class)
99102
public void testNullDataPatchInDataSection() {
100-
installEmptyCode(new Site[0], new Assumption[0], new Comment[0], 16, new DataPatch[]{null}, null);
103+
installEmptyCode(new Site[0], new Assumption[0], new Comment[0], validDataSectionAlignment, new DataPatch[]{null}, null);
101104
}
102105

103106
@Test(expected = NullPointerException.class)
104107
public void testNullReferenceInDataSection() {
105-
installEmptyCode(new Site[0], new Assumption[0], new Comment[0], 16, new DataPatch[]{new DataPatch(0, null)}, null);
108+
installEmptyCode(new Site[0], new Assumption[0], new Comment[0], validDataSectionAlignment, new DataPatch[]{new DataPatch(0, null)}, null);
106109
}
107110

108111
@Test(expected = JVMCIError.class)
109112
public void testInvalidDataSectionReference() {
110113
DataSectionReference ref = new DataSectionReference();
111114
ref.setOffset(0);
112-
installEmptyCode(new Site[0], new Assumption[0], new Comment[0], 16, new DataPatch[]{new DataPatch(0, ref)}, null);
115+
installEmptyCode(new Site[0], new Assumption[0], new Comment[0], validDataSectionAlignment, new DataPatch[]{new DataPatch(0, ref)}, null);
113116
}
114117

115118
@Test(expected = JVMCIError.class)
116119
public void testInvalidNarrowMethodInDataSection() {
117120
HotSpotConstant c = (HotSpotConstant) dummyMethod.getEncoding();
118121
ConstantReference ref = new ConstantReference((VMConstant) c.compress());
119-
installEmptyCode(new Site[0], new Assumption[0], new Comment[0], 16, new DataPatch[]{new DataPatch(0, ref)}, null);
122+
installEmptyCode(new Site[0], new Assumption[0], new Comment[0], validDataSectionAlignment, new DataPatch[]{new DataPatch(0, ref)}, null);
120123
}
121124

122125
@Test(expected = NullPointerException.class)
123126
public void testNullConstantInDataSection() {
124127
ConstantReference ref = new ConstantReference(null);
125-
installEmptyCode(new Site[0], new Assumption[0], new Comment[0], 16, new DataPatch[]{new DataPatch(0, ref)}, null);
128+
installEmptyCode(new Site[0], new Assumption[0], new Comment[0], validDataSectionAlignment, new DataPatch[]{new DataPatch(0, ref)}, null);
126129
}
127130

128131
@Test(expected = JVMCIError.class)
129132
public void testInvalidConstantInDataSection() {
130133
ConstantReference ref = new ConstantReference(new InvalidVMConstant());
131-
installEmptyCode(new Site[0], new Assumption[0], new Comment[0], 16, new DataPatch[]{new DataPatch(0, ref)}, null);
134+
installEmptyCode(new Site[0], new Assumption[0], new Comment[0], validDataSectionAlignment, new DataPatch[]{new DataPatch(0, ref)}, null);
132135
}
133136

134137
@Test(expected = NullPointerException.class)
135138
public void testNullReferenceInCode() {
136-
installEmptyCode(new Site[]{new DataPatch(0, null)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null);
139+
installEmptyCode(new Site[]{new DataPatch(0, null)}, new Assumption[0], new Comment[0], validDataSectionAlignment, new DataPatch[0], null);
137140
}
138141

139142
@Test(expected = NullPointerException.class)
140143
public void testNullConstantInCode() {
141144
ConstantReference ref = new ConstantReference(null);
142-
installEmptyCode(new Site[]{new DataPatch(0, ref)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null);
145+
installEmptyCode(new Site[]{new DataPatch(0, ref)}, new Assumption[0], new Comment[0], validDataSectionAlignment, new DataPatch[0], null);
143146
}
144147

145148
@Test(expected = JVMCIError.class)
146149
public void testInvalidConstantInCode() {
147150
ConstantReference ref = new ConstantReference(new InvalidVMConstant());
148-
installEmptyCode(new Site[]{new DataPatch(0, ref)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null);
151+
installEmptyCode(new Site[]{new DataPatch(0, ref)}, new Assumption[0], new Comment[0], validDataSectionAlignment, new DataPatch[0], null);
149152
}
150153

151154
@Test(expected = JVMCIError.class)
152155
public void testInvalidReference() {
153156
InvalidReference ref = new InvalidReference();
154-
installEmptyCode(new Site[]{new DataPatch(0, ref)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null);
157+
installEmptyCode(new Site[]{new DataPatch(0, ref)}, new Assumption[0], new Comment[0], validDataSectionAlignment, new DataPatch[0], null);
155158
}
156159

157160
@Test(expected = JVMCIError.class)
158161
public void testOutOfBoundsDataSectionReference() {
159162
DataSectionReference ref = new DataSectionReference();
160163
ref.setOffset(0x1000);
161-
installEmptyCode(new Site[]{new DataPatch(0, ref)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null);
164+
installEmptyCode(new Site[]{new DataPatch(0, ref)}, new Assumption[0], new Comment[0], validDataSectionAlignment, new DataPatch[0], null);
162165
}
163166

164167
@Test(expected = JVMCIError.class)
165168
public void testInvalidMark() {
166-
installEmptyCode(new Site[]{new Mark(0, new Object())}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null);
169+
installEmptyCode(new Site[]{new Mark(0, new Object())}, new Assumption[0], new Comment[0], validDataSectionAlignment, new DataPatch[0], null);
167170
}
168171

169172
@Test(expected = JVMCIError.class)
170173
public void testInvalidMarkInt() {
171-
installEmptyCode(new Site[]{new Mark(0, -1)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null);
174+
installEmptyCode(new Site[]{new Mark(0, -1)}, new Assumption[0], new Comment[0], validDataSectionAlignment, new DataPatch[0], null);
172175
}
173176

174177
@Test(expected = NullPointerException.class)
175178
public void testNullSite() {
176-
installEmptyCode(new Site[]{null}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null);
179+
installEmptyCode(new Site[]{null}, new Assumption[0], new Comment[0], validDataSectionAlignment, new DataPatch[0], null);
177180
}
178181

179182
@Test(expected = JVMCIError.class)
180183
public void testInfopointMissingDebugInfo() {
181184
Infopoint info = new Infopoint(0, null, InfopointReason.METHOD_START);
182-
installEmptyCode(new Site[]{info}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null);
185+
installEmptyCode(new Site[]{info}, new Assumption[0], new Comment[0], validDataSectionAlignment, new DataPatch[0], null);
183186
}
184187

185188
@Test(expected = JVMCIError.class)
186189
public void testSafepointMissingDebugInfo() {
187190
Infopoint info = new Infopoint(0, null, InfopointReason.SAFEPOINT);
188191
StackSlot deoptRescueSlot = StackSlot.get(null, 0, true);
189-
installEmptyCode(new Site[]{info}, new Assumption[0], new Comment[0], 16, new DataPatch[0], deoptRescueSlot);
192+
installEmptyCode(new Site[]{info}, new Assumption[0], new Comment[0], validDataSectionAlignment, new DataPatch[0], deoptRescueSlot);
190193
}
191194

192195
@Test(expected = JVMCIError.class)
193196
public void testInvalidDeoptRescueSlot() {
194197
StackSlot deoptRescueSlot = StackSlot.get(null, -1, false);
195-
installEmptyCode(new Site[]{}, new Assumption[0], new Comment[0], 16, new DataPatch[0], deoptRescueSlot);
198+
installEmptyCode(new Site[]{}, new Assumption[0], new Comment[0], validDataSectionAlignment, new DataPatch[0], deoptRescueSlot);
196199
}
197200
}

‎test/hotspot/jtreg/compiler/jvmci/errors/TestInvalidDebugInfo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private void test(VirtualObject[] vobj, JavaValue[] values, JavaKind[] slotKinds
9797
BytecodeFrame frame = new BytecodeFrame(null, dummyMethod, 0, false, false, values, slotKinds, locals, stack, locks);
9898
DebugInfo info = new DebugInfo(frame, vobj);
9999
info.setReferenceMap(new HotSpotReferenceMap(new Location[0], new Location[0], new int[0], 8));
100-
installEmptyCode(new Site[]{new Infopoint(0, info, InfopointReason.SAFEPOINT)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], deoptRescueSlot);
100+
installEmptyCode(new Site[]{new Infopoint(0, info, InfopointReason.SAFEPOINT)}, new Assumption[0], new Comment[0], 8, new DataPatch[0], deoptRescueSlot);
101101
}
102102

103103
@Test(expected = NullPointerException.class)

‎test/hotspot/jtreg/compiler/jvmci/errors/TestInvalidOopMap.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private void test(ReferenceMap refMap) {
6767
BytecodePosition pos = new BytecodePosition(null, dummyMethod, 0);
6868
DebugInfo info = new DebugInfo(pos);
6969
info.setReferenceMap(refMap);
70-
installEmptyCode(new Site[]{new Infopoint(0, info, InfopointReason.SAFEPOINT)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], StackSlot.get(null, 0, true));
70+
installEmptyCode(new Site[]{new Infopoint(0, info, InfopointReason.SAFEPOINT)}, new Assumption[0], new Comment[0], 8, new DataPatch[0], StackSlot.get(null, 0, true));
7171
}
7272

7373
@Test(expected = NullPointerException.class)

‎test/hotspot/jtreg/compiler/jvmci/events/JvmciNotifyInstallEventTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,11 @@ private void runTest() {
116116
}
117117
HotSpotResolvedJavaMethod method = CTVMUtilities
118118
.getResolvedMethod(SimpleClass.class, testMethod);
119+
int dataSectionAlignment = 8; // CodeBuffer::SECT_CONSTS code section alignment
119120
HotSpotCompiledCode compiledCode = new HotSpotCompiledNmethod(METHOD_NAME,
120121
new byte[0], 0, new Site[0], new Assumption[0],
121122
new ResolvedJavaMethod[]{method}, new Comment[0], new byte[0],
122-
16, new DataPatch[0], false, 0, null,
123+
dataSectionAlignment, new DataPatch[0], false, 0, null,
123124
method, 0, 1, 0L, false);
124125
codeCache.installCode(method, compiledCode, /* installedCode = */ null,
125126
/* speculationLog = */ null, /* isDefault = */ false);

‎test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/TestAssembler.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ public HotSpotCompiledCode finish(HotSpotResolvedJavaMethod method) {
316316
Site[] finishedSites = sites.toArray(new Site[0]);
317317
byte[] finishedData = data.finish();
318318
DataPatch[] finishedDataPatches = dataPatches.toArray(new DataPatch[0]);
319-
return new HotSpotCompiledNmethod(method.getName(), finishedCode, finishedCode.length, finishedSites, new Assumption[0], new ResolvedJavaMethod[]{method}, new Comment[0], finishedData, 16,
319+
int dataSectionAlignment = 8; // CodeBuffer::SECT_CONSTS code section alignment
320+
return new HotSpotCompiledNmethod(method.getName(), finishedCode, finishedCode.length, finishedSites, new Assumption[0], new ResolvedJavaMethod[]{method}, new Comment[0], finishedData, dataSectionAlignment,
320321
finishedDataPatches, false, frameSize, deoptRescue, method, 0, id, 0L, false);
321322
}
322323

0 commit comments

Comments
 (0)
Please sign in to comment.