8247766: [aarch64] guarantee(val < (1U << nbits)) failed: Field too big for insn

Reviewed-by: neliasso, aph
This commit is contained in:
Patric Hedlin 2020-07-27 10:56:51 +02:00
parent 31753ef9bf
commit 761a92d7c9
5 changed files with 60 additions and 30 deletions

View File

@ -554,14 +554,7 @@ class Address {
void lea(MacroAssembler *, Register) const;
static bool offset_ok_for_immed(int64_t offset, int shift) {
unsigned mask = (1 << shift) - 1;
if (offset < 0 || offset & mask) {
return (uabs(offset) < (1 << (20 - 12))); // Unscaled offset
} else {
return ((offset >> shift) < (1 << (21 - 10 + 1))); // Scaled, unsigned offset
}
}
static bool offset_ok_for_immed(int64_t offset, uint shift);
};
// Convience classes

View File

@ -30,4 +30,16 @@
#include "asm/codeBuffer.hpp"
#include "code/codeCache.hpp"
inline bool Address::offset_ok_for_immed(int64_t offset, uint shift) {
uint mask = (1 << shift) - 1;
if (offset < 0 || (offset & mask) != 0) {
// Unscaled signed offset, encoded in a signed imm9 field.
return Assembler::is_simm9(offset);
} else {
// Scaled unsigned offset, encoded in an unsigned imm12:_ field.
return Assembler::is_uimm12(offset >> shift);
}
}
#endif // CPU_AARCH64_ASSEMBLER_AARCH64_INLINE_HPP

View File

@ -211,6 +211,19 @@ Address LIR_Assembler::as_Address_lo(LIR_Address* addr) {
// FIXME: This needs to be much more clever. See x86.
}
// Ensure a valid Address (base + offset) to a stack-slot. If stack access is
// not encodable as a base + (immediate) offset, generate an explicit address
// calculation to hold the address in a temporary register.
Address LIR_Assembler::stack_slot_address(int index, uint size, Register tmp, int adjust) {
precond(size == 4 || size == 8);
Address addr = frame_map()->address_for_slot(index, adjust);
precond(addr.getMode() == Address::base_plus_offset);
precond(addr.base() == sp);
precond(addr.offset() > 0);
uint mask = size - 1;
assert((addr.offset() & mask) == 0, "scaled offsets only");
return __ legitimize_address(addr, size, tmp);
}
void LIR_Assembler::osr_entry() {
offsets()->set_value(CodeOffsets::OSR_Entry, code_offset());
@ -735,32 +748,38 @@ void LIR_Assembler::reg2reg(LIR_Opr src, LIR_Opr dest) {
}
void LIR_Assembler::reg2stack(LIR_Opr src, LIR_Opr dest, BasicType type, bool pop_fpu_stack) {
precond(src->is_register() && dest->is_stack());
uint const c_sz32 = sizeof(uint32_t);
uint const c_sz64 = sizeof(uint64_t);
if (src->is_single_cpu()) {
int index = dest->single_stack_ix();
if (is_reference_type(type)) {
__ str(src->as_register(), frame_map()->address_for_slot(dest->single_stack_ix()));
__ str(src->as_register(), stack_slot_address(index, c_sz64, rscratch1));
__ verify_oop(src->as_register());
} else if (type == T_METADATA || type == T_DOUBLE || type == T_ADDRESS) {
__ str(src->as_register(), frame_map()->address_for_slot(dest->single_stack_ix()));
__ str(src->as_register(), stack_slot_address(index, c_sz64, rscratch1));
} else {
__ strw(src->as_register(), frame_map()->address_for_slot(dest->single_stack_ix()));
__ strw(src->as_register(), stack_slot_address(index, c_sz32, rscratch1));
}
} else if (src->is_double_cpu()) {
Address dest_addr_LO = frame_map()->address_for_slot(dest->double_stack_ix(), lo_word_offset_in_bytes);
int index = dest->double_stack_ix();
Address dest_addr_LO = stack_slot_address(index, c_sz64, rscratch1, lo_word_offset_in_bytes);
__ str(src->as_register_lo(), dest_addr_LO);
} else if (src->is_single_fpu()) {
Address dest_addr = frame_map()->address_for_slot(dest->single_stack_ix());
__ strs(src->as_float_reg(), dest_addr);
int index = dest->single_stack_ix();
__ strs(src->as_float_reg(), stack_slot_address(index, c_sz32, rscratch1));
} else if (src->is_double_fpu()) {
Address dest_addr = frame_map()->address_for_slot(dest->double_stack_ix());
__ strd(src->as_double_reg(), dest_addr);
int index = dest->double_stack_ix();
__ strd(src->as_double_reg(), stack_slot_address(index, c_sz64, rscratch1));
} else {
ShouldNotReachHere();
}
}
@ -845,30 +864,34 @@ void LIR_Assembler::reg2mem(LIR_Opr src, LIR_Opr dest, BasicType type, LIR_Patch
void LIR_Assembler::stack2reg(LIR_Opr src, LIR_Opr dest, BasicType type) {
assert(src->is_stack(), "should not call otherwise");
assert(dest->is_register(), "should not call otherwise");
precond(src->is_stack() && dest->is_register());
uint const c_sz32 = sizeof(uint32_t);
uint const c_sz64 = sizeof(uint64_t);
if (dest->is_single_cpu()) {
int index = src->single_stack_ix();
if (is_reference_type(type)) {
__ ldr(dest->as_register(), frame_map()->address_for_slot(src->single_stack_ix()));
__ ldr(dest->as_register(), stack_slot_address(index, c_sz64, rscratch1));
__ verify_oop(dest->as_register());
} else if (type == T_METADATA || type == T_ADDRESS) {
__ ldr(dest->as_register(), frame_map()->address_for_slot(src->single_stack_ix()));
__ ldr(dest->as_register(), stack_slot_address(index, c_sz64, rscratch1));
} else {
__ ldrw(dest->as_register(), frame_map()->address_for_slot(src->single_stack_ix()));
__ ldrw(dest->as_register(), stack_slot_address(index, c_sz32, rscratch1));
}
} else if (dest->is_double_cpu()) {
Address src_addr_LO = frame_map()->address_for_slot(src->double_stack_ix(), lo_word_offset_in_bytes);
int index = src->double_stack_ix();
Address src_addr_LO = stack_slot_address(index, c_sz64, rscratch1, lo_word_offset_in_bytes);
__ ldr(dest->as_register_lo(), src_addr_LO);
} else if (dest->is_single_fpu()) {
Address src_addr = frame_map()->address_for_slot(src->single_stack_ix());
__ ldrs(dest->as_float_reg(), src_addr);
int index = src->single_stack_ix();
__ ldrs(dest->as_float_reg(), stack_slot_address(index, c_sz32, rscratch1));
} else if (dest->is_double_fpu()) {
Address src_addr = frame_map()->address_for_slot(src->double_stack_ix());
__ ldrd(dest->as_double_reg(), src_addr);
int index = src->double_stack_ix();
__ ldrd(dest->as_double_reg(), stack_slot_address(index, c_sz64, rscratch1));
} else {
ShouldNotReachHere();

View File

@ -45,10 +45,12 @@ friend class ArrayCopyStub;
bool is_literal_address(LIR_Address* addr);
// When we need to use something other than rscratch1 use this
// method.
// When we need to use something other than rscratch1 use this method.
Address as_Address(LIR_Address* addr, Register tmp);
// Ensure we have a valid Address (base+offset) to a stack-slot.
Address stack_slot_address(int index, uint shift, Register tmp, int adjust = 0);
// Record the type of the receiver in ReceiverTypeData
void type_profile_helper(Register mdo,
ciMethodData *md, ciProfileData *data,

View File

@ -26,7 +26,7 @@
#ifndef CPU_AARCH64_MACROASSEMBLER_AARCH64_HPP
#define CPU_AARCH64_MACROASSEMBLER_AARCH64_HPP
#include "asm/assembler.hpp"
#include "asm/assembler.inline.hpp"
#include "oops/compressedOops.hpp"
#include "utilities/powerOfTwo.hpp"