Skip to content

Commit f3ca0ca

Browse files
author
Boris Ulasevich
committed
8293999: [JVMCI] need support for aligned constants in generated code larger than 8 bytes
Reviewed-by: dlong, dnsimon
1 parent 8aa1526 commit f3ca0ca

File tree

5 files changed

+36
-28
lines changed

5 files changed

+36
-28
lines changed

src/hotspot/cpu/arm/arm.ad

+2-1
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,9 @@ void MachConstantBaseNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const {
236236

237237
Register r = as_Register(ra_->get_encode(this));
238238
CodeSection* consts_section = __ code()->consts();
239+
CodeSection* insts_section = __ code()->insts();
239240
// constants section size is aligned according to the align_at_start settings of the next section
240-
int consts_size = CodeSection::align_at_start(consts_section->size(), CodeBuffer::SECT_INSTS);
241+
int consts_size = insts_section->align_at_start(consts_section->size());
241242
assert(constant_table.size() == consts_size, "must be: %d == %d", constant_table.size(), consts_size);
242243

243244
// Materialize the constant table base.

src/hotspot/share/asm/codeBuffer.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,21 @@ void CodeSection::expand_locs(int new_capacity) {
422422
}
423423
}
424424

425+
int CodeSection::alignment() const {
426+
if (_index == CodeBuffer::SECT_CONSTS) {
427+
// CodeBuffer controls the alignment of the constants section
428+
return _outer->_const_section_alignment;
429+
}
430+
if (_index == CodeBuffer::SECT_INSTS) {
431+
return (int) CodeEntryAlignment;
432+
}
433+
if (_index == CodeBuffer::SECT_STUBS) {
434+
// CodeBuffer installer expects sections to be HeapWordSize aligned
435+
return HeapWordSize;
436+
}
437+
ShouldNotReachHere();
438+
return 0;
439+
}
425440

426441
/// Support for emitting the code to its final location.
427442
/// The pattern is the same for all functions.

src/hotspot/share/asm/codeBuffer.hpp

+13-22
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/growableArray.hpp"
@@ -256,18 +257,13 @@ class CodeSection {
256257
void relocate(address at, RelocationHolder const& rspec, int format = 0);
257258
void relocate(address at, relocInfo::relocType rtype, int format = 0, jint method_index = 0);
258259

259-
static int alignment(int section);
260-
int alignment() { return alignment(_index); }
260+
int alignment() const;
261261

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

265-
static csize_t align_at_start(csize_t off, int section) {
266-
return (csize_t) align_up(off, alignment(section));
267-
}
268-
269265
csize_t align_at_start(csize_t off) const {
270-
return align_at_start(off, _index);
266+
return (csize_t) align_up(off, alignment());
271267
}
272268

273269
// Ensure there's enough space left in the current section.
@@ -431,6 +427,8 @@ class CodeBuffer: public StackObj DEBUG_ONLY(COMMA private Scrubber) {
431427
SharedTrampolineRequests* _shared_trampoline_requests; // used to collect requests for shared trampolines
432428
bool _finalize_stubs; // Indicate if we need to finalize stubs to make CodeBuffer final.
433429

430+
int _const_section_alignment;
431+
434432
#ifndef PRODUCT
435433
AsmRemarks _asm_remarks;
436434
DbgStrings _dbg_strings;
@@ -456,6 +454,10 @@ class CodeBuffer: public StackObj DEBUG_ONLY(COMMA private Scrubber) {
456454
_insts.initialize_outer(this, SECT_INSTS);
457455
_stubs.initialize_outer(this, SECT_STUBS);
458456

457+
// Default is to align on 8 bytes. A compiler can change this
458+
// if larger alignment (e.g., 32-byte vector masks) is required.
459+
_const_section_alignment = (int) sizeof(jdouble);
460+
459461
#ifndef PRODUCT
460462
_decode_begin = NULL;
461463
// Collect block comments, but restrict collection to cases where a disassembly is output.
@@ -709,6 +711,10 @@ class CodeBuffer: public StackObj DEBUG_ONLY(COMMA private Scrubber) {
709711
// Request for a shared stub to the interpreter
710712
void shared_stub_to_interp_for(ciMethod* callee, csize_t call_offset);
711713

714+
void set_const_section_alignment(int align) {
715+
_const_section_alignment = align_up(align, HeapWordSize);
716+
}
717+
712718
#ifndef PRODUCT
713719
public:
714720
// Printing / Decoding
@@ -746,19 +752,4 @@ inline bool CodeSection::maybe_expand_to_ensure_remaining(csize_t amount) {
746752
return false;
747753
}
748754

749-
inline int CodeSection::alignment(int section) {
750-
if (section == CodeBuffer::SECT_CONSTS) {
751-
return (int) sizeof(jdouble);
752-
}
753-
if (section == CodeBuffer::SECT_INSTS) {
754-
return (int) CodeEntryAlignment;
755-
}
756-
if (section == CodeBuffer::SECT_STUBS) {
757-
// CodeBuffer installer expects sections to be HeapWordSize aligned
758-
return HeapWordSize;
759-
}
760-
ShouldNotReachHere();
761-
return 0;
762-
}
763-
764755
#endif // SHARE_ASM_CODEBUFFER_HPP

src/hotspot/share/jvmci/jvmciCodeInstaller.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ JVMCI::CodeInstallResult CodeInstaller::install(JVMCICompiler* compiler,
687687
_instructions = buffer.insts();
688688
_constants = buffer.consts();
689689

690-
initialize_fields(stream, code_flags, method, JVMCI_CHECK_OK);
690+
initialize_fields(stream, code_flags, method, buffer, JVMCI_CHECK_OK);
691691
JVMCI::CodeInstallResult result = initialize_buffer(compiled_code, buffer, stream, code_flags, JVMCI_CHECK_OK);
692692

693693
u4 available = stream->available();
@@ -770,7 +770,7 @@ JVMCI::CodeInstallResult CodeInstaller::install(JVMCICompiler* compiler,
770770
return result;
771771
}
772772

773-
void CodeInstaller::initialize_fields(HotSpotCompiledCodeStream* stream, u1 code_flags, methodHandle& method, JVMCI_TRAPS) {
773+
void CodeInstaller::initialize_fields(HotSpotCompiledCodeStream* stream, u1 code_flags, methodHandle& method, CodeBuffer& buffer, JVMCI_TRAPS) {
774774
if (!method.is_null()) {
775775
_parameter_count = method->size_of_parameters();
776776
JVMCI_event_2("installing code for %s", method->name_and_sig_as_C_string());
@@ -797,6 +797,7 @@ void CodeInstaller::initialize_fields(HotSpotCompiledCodeStream* stream, u1 code
797797
// Pre-calculate the constants section size. This is required for PC-relative addressing.
798798
u4 data_section_size = stream->read_u4("dataSectionSize");
799799
u1 data_section_alignment = stream->read_u1("dataSectionAlignment");
800+
buffer.set_const_section_alignment(data_section_alignment);
800801
if ((_constants->alignment() % data_section_alignment) != 0) {
801802
JVMCI_ERROR("invalid data section alignment: %d [constants alignment: %d]%s",
802803
data_section_alignment, _constants->alignment(), stream->context());
@@ -851,8 +852,8 @@ JVMCI::CodeInstallResult CodeInstaller::initialize_buffer(JVMCIObject compiled_c
851852
assert((CodeBuffer::SECT_INSTS == CodeBuffer::SECT_STUBS - 1) &&
852853
(CodeBuffer::SECT_CONSTS == CodeBuffer::SECT_INSTS - 1), "sections order: consts, insts, stubs");
853854
// buffer content: [constants + code_align] + [code + stubs_align] + [stubs]
854-
int total_size = align_up(_constants_size, CodeSection::alignment(CodeBuffer::SECT_INSTS)) +
855-
align_up(_code_size, CodeSection::alignment(CodeBuffer::SECT_STUBS)) +
855+
int total_size = align_up(_constants_size, buffer.insts()->alignment()) +
856+
align_up(_code_size, buffer.stubs()->alignment()) +
856857
stubs_size;
857858

858859
if (total_size > JVMCINMethodSizeLimit) {

src/hotspot/share/jvmci/jvmciCodeInstaller.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class CodeInstaller : public StackObj {
361361
GrowableArray<MonitorValue*>* read_monitor_values(HotSpotCompiledCodeStream* stream, u1 frame_flags, JVMCI_TRAPS);
362362

363363
// extract the fields of the HotSpotCompiledCode
364-
void initialize_fields(HotSpotCompiledCodeStream* stream, u1 code_flags, methodHandle& method, JVMCI_TRAPS);
364+
void initialize_fields(HotSpotCompiledCodeStream* stream, u1 code_flags, methodHandle& method, CodeBuffer& buffer, JVMCI_TRAPS);
365365
void initialize_dependencies(HotSpotCompiledCodeStream* stream, u1 code_flags, OopRecorder* oop_recorder, JVMCI_TRAPS);
366366

367367
int estimate_stubs_size(HotSpotCompiledCodeStream* stream, JVMCI_TRAPS);

0 commit comments

Comments
 (0)