Skip to content

Commit 761a92d

Browse files
author
Patric Hedlin
committedJul 27, 2020
8247766: [aarch64] guarantee(val < (1U << nbits)) failed: Field too big for insn
Reviewed-by: neliasso, aph
1 parent 31753ef commit 761a92d

5 files changed

+60
-30
lines changed
 

‎src/hotspot/cpu/aarch64/assembler_aarch64.hpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -554,14 +554,7 @@ class Address {
554554

555555
void lea(MacroAssembler *, Register) const;
556556

557-
static bool offset_ok_for_immed(int64_t offset, int shift) {
558-
unsigned mask = (1 << shift) - 1;
559-
if (offset < 0 || offset & mask) {
560-
return (uabs(offset) < (1 << (20 - 12))); // Unscaled offset
561-
} else {
562-
return ((offset >> shift) < (1 << (21 - 10 + 1))); // Scaled, unsigned offset
563-
}
564-
}
557+
static bool offset_ok_for_immed(int64_t offset, uint shift);
565558
};
566559

567560
// Convience classes

‎src/hotspot/cpu/aarch64/assembler_aarch64.inline.hpp

+12
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,16 @@
3030
#include "asm/codeBuffer.hpp"
3131
#include "code/codeCache.hpp"
3232

33+
34+
inline bool Address::offset_ok_for_immed(int64_t offset, uint shift) {
35+
uint mask = (1 << shift) - 1;
36+
if (offset < 0 || (offset & mask) != 0) {
37+
// Unscaled signed offset, encoded in a signed imm9 field.
38+
return Assembler::is_simm9(offset);
39+
} else {
40+
// Scaled unsigned offset, encoded in an unsigned imm12:_ field.
41+
return Assembler::is_uimm12(offset >> shift);
42+
}
43+
}
44+
3345
#endif // CPU_AARCH64_ASSEMBLER_AARCH64_INLINE_HPP

‎src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp

+42-19
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,19 @@ Address LIR_Assembler::as_Address_lo(LIR_Address* addr) {
211211
// FIXME: This needs to be much more clever. See x86.
212212
}
213213

214+
// Ensure a valid Address (base + offset) to a stack-slot. If stack access is
215+
// not encodable as a base + (immediate) offset, generate an explicit address
216+
// calculation to hold the address in a temporary register.
217+
Address LIR_Assembler::stack_slot_address(int index, uint size, Register tmp, int adjust) {
218+
precond(size == 4 || size == 8);
219+
Address addr = frame_map()->address_for_slot(index, adjust);
220+
precond(addr.getMode() == Address::base_plus_offset);
221+
precond(addr.base() == sp);
222+
precond(addr.offset() > 0);
223+
uint mask = size - 1;
224+
assert((addr.offset() & mask) == 0, "scaled offsets only");
225+
return __ legitimize_address(addr, size, tmp);
226+
}
214227

215228
void LIR_Assembler::osr_entry() {
216229
offsets()->set_value(CodeOffsets::OSR_Entry, code_offset());
@@ -735,32 +748,38 @@ void LIR_Assembler::reg2reg(LIR_Opr src, LIR_Opr dest) {
735748
}
736749

737750
void LIR_Assembler::reg2stack(LIR_Opr src, LIR_Opr dest, BasicType type, bool pop_fpu_stack) {
751+
precond(src->is_register() && dest->is_stack());
752+
753+
uint const c_sz32 = sizeof(uint32_t);
754+
uint const c_sz64 = sizeof(uint64_t);
755+
738756
if (src->is_single_cpu()) {
757+
int index = dest->single_stack_ix();
739758
if (is_reference_type(type)) {
740-
__ str(src->as_register(), frame_map()->address_for_slot(dest->single_stack_ix()));
759+
__ str(src->as_register(), stack_slot_address(index, c_sz64, rscratch1));
741760
__ verify_oop(src->as_register());
742761
} else if (type == T_METADATA || type == T_DOUBLE || type == T_ADDRESS) {
743-
__ str(src->as_register(), frame_map()->address_for_slot(dest->single_stack_ix()));
762+
__ str(src->as_register(), stack_slot_address(index, c_sz64, rscratch1));
744763
} else {
745-
__ strw(src->as_register(), frame_map()->address_for_slot(dest->single_stack_ix()));
764+
__ strw(src->as_register(), stack_slot_address(index, c_sz32, rscratch1));
746765
}
747766

748767
} else if (src->is_double_cpu()) {
749-
Address dest_addr_LO = frame_map()->address_for_slot(dest->double_stack_ix(), lo_word_offset_in_bytes);
768+
int index = dest->double_stack_ix();
769+
Address dest_addr_LO = stack_slot_address(index, c_sz64, rscratch1, lo_word_offset_in_bytes);
750770
__ str(src->as_register_lo(), dest_addr_LO);
751771

752772
} else if (src->is_single_fpu()) {
753-
Address dest_addr = frame_map()->address_for_slot(dest->single_stack_ix());
754-
__ strs(src->as_float_reg(), dest_addr);
773+
int index = dest->single_stack_ix();
774+
__ strs(src->as_float_reg(), stack_slot_address(index, c_sz32, rscratch1));
755775

756776
} else if (src->is_double_fpu()) {
757-
Address dest_addr = frame_map()->address_for_slot(dest->double_stack_ix());
758-
__ strd(src->as_double_reg(), dest_addr);
777+
int index = dest->double_stack_ix();
778+
__ strd(src->as_double_reg(), stack_slot_address(index, c_sz64, rscratch1));
759779

760780
} else {
761781
ShouldNotReachHere();
762782
}
763-
764783
}
765784

766785

@@ -845,30 +864,34 @@ void LIR_Assembler::reg2mem(LIR_Opr src, LIR_Opr dest, BasicType type, LIR_Patch
845864

846865

847866
void LIR_Assembler::stack2reg(LIR_Opr src, LIR_Opr dest, BasicType type) {
848-
assert(src->is_stack(), "should not call otherwise");
849-
assert(dest->is_register(), "should not call otherwise");
867+
precond(src->is_stack() && dest->is_register());
868+
869+
uint const c_sz32 = sizeof(uint32_t);
870+
uint const c_sz64 = sizeof(uint64_t);
850871

851872
if (dest->is_single_cpu()) {
873+
int index = src->single_stack_ix();
852874
if (is_reference_type(type)) {
853-
__ ldr(dest->as_register(), frame_map()->address_for_slot(src->single_stack_ix()));
875+
__ ldr(dest->as_register(), stack_slot_address(index, c_sz64, rscratch1));
854876
__ verify_oop(dest->as_register());
855877
} else if (type == T_METADATA || type == T_ADDRESS) {
856-
__ ldr(dest->as_register(), frame_map()->address_for_slot(src->single_stack_ix()));
878+
__ ldr(dest->as_register(), stack_slot_address(index, c_sz64, rscratch1));
857879
} else {
858-
__ ldrw(dest->as_register(), frame_map()->address_for_slot(src->single_stack_ix()));
880+
__ ldrw(dest->as_register(), stack_slot_address(index, c_sz32, rscratch1));
859881
}
860882

861883
} else if (dest->is_double_cpu()) {
862-
Address src_addr_LO = frame_map()->address_for_slot(src->double_stack_ix(), lo_word_offset_in_bytes);
884+
int index = src->double_stack_ix();
885+
Address src_addr_LO = stack_slot_address(index, c_sz64, rscratch1, lo_word_offset_in_bytes);
863886
__ ldr(dest->as_register_lo(), src_addr_LO);
864887

865888
} else if (dest->is_single_fpu()) {
866-
Address src_addr = frame_map()->address_for_slot(src->single_stack_ix());
867-
__ ldrs(dest->as_float_reg(), src_addr);
889+
int index = src->single_stack_ix();
890+
__ ldrs(dest->as_float_reg(), stack_slot_address(index, c_sz32, rscratch1));
868891

869892
} else if (dest->is_double_fpu()) {
870-
Address src_addr = frame_map()->address_for_slot(src->double_stack_ix());
871-
__ ldrd(dest->as_double_reg(), src_addr);
893+
int index = src->double_stack_ix();
894+
__ ldrd(dest->as_double_reg(), stack_slot_address(index, c_sz64, rscratch1));
872895

873896
} else {
874897
ShouldNotReachHere();

‎src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ friend class ArrayCopyStub;
4545

4646
bool is_literal_address(LIR_Address* addr);
4747

48-
// When we need to use something other than rscratch1 use this
49-
// method.
48+
// When we need to use something other than rscratch1 use this method.
5049
Address as_Address(LIR_Address* addr, Register tmp);
5150

51+
// Ensure we have a valid Address (base+offset) to a stack-slot.
52+
Address stack_slot_address(int index, uint shift, Register tmp, int adjust = 0);
53+
5254
// Record the type of the receiver in ReceiverTypeData
5355
void type_profile_helper(Register mdo,
5456
ciMethodData *md, ciProfileData *data,

‎src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#ifndef CPU_AARCH64_MACROASSEMBLER_AARCH64_HPP
2727
#define CPU_AARCH64_MACROASSEMBLER_AARCH64_HPP
2828

29-
#include "asm/assembler.hpp"
29+
#include "asm/assembler.inline.hpp"
3030
#include "oops/compressedOops.hpp"
3131
#include "utilities/powerOfTwo.hpp"
3232

0 commit comments

Comments
 (0)
Please sign in to comment.