Skip to content

Commit

Permalink
8297830: aarch64: Make Address a discriminated union internally
Browse files Browse the repository at this point in the history
Reviewed-by: aph, dcubed
  • Loading branch information
Kim Barrett committed Dec 1, 2022
1 parent 391599b commit 5a5ced3
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 95 deletions.
62 changes: 35 additions & 27 deletions src/hotspot/cpu/aarch64/assembler_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,25 +126,23 @@ extern "C" {
#define __ as->

void Address::lea(MacroAssembler *as, Register r) const {
Relocation* reloc = _rspec.reloc();
relocInfo::relocType rtype = (relocInfo::relocType) reloc->type();

switch(_mode) {
case base_plus_offset: {
if (_offset == 0 && _base == r) // it's a nop
if (offset() == 0 && base() == r) // it's a nop
break;
if (_offset > 0)
__ add(r, _base, _offset);
if (offset() > 0)
__ add(r, base(), offset());
else
__ sub(r, _base, -_offset);
__ sub(r, base(), -offset());
break;
}
case base_plus_offset_reg: {
__ add(r, _base, _index, _ext.op(), MAX2(_ext.shift(), 0));
__ add(r, base(), index(), ext().op(), MAX2(ext().shift(), 0));
break;
}
case literal: {
if (rtype == relocInfo::none)
as->code_section()->relocate(as->inst_mark(), rspec());
if (rspec().type() == relocInfo::none)
__ mov(r, target());
else
__ movptr(r, (uint64_t)target());
Expand Down Expand Up @@ -237,44 +235,54 @@ void Assembler::add_sub_immediate(Instruction_aarch64 &current_insn,

#undef starti

Address::Address(address target, relocInfo::relocType rtype) : _mode(literal){
_target = target;
#ifdef ASSERT

void Address::assert_is_literal() const {
assert(_mode == literal, "addressing mode is non-literal: %d", _mode);
}

void Address::assert_is_nonliteral() const {
assert(_mode != literal, "unexpected literal addressing mode");
assert(_mode != no_mode, "unexpected no_mode addressing mode");
}

#endif // ASSERT

static RelocationHolder address_relocation(address target, relocInfo::relocType rtype) {
switch (rtype) {
case relocInfo::oop_type:
case relocInfo::metadata_type:
// Oops are a special case. Normally they would be their own section
// but in cases like icBuffer they are literals in the code stream that
// we don't have a section for. We use none so that we get a literal address
// which is always patchable.
break;
return RelocationHolder::none;
case relocInfo::external_word_type:
_rspec = external_word_Relocation::spec(target);
break;
return external_word_Relocation::spec(target);
case relocInfo::internal_word_type:
_rspec = internal_word_Relocation::spec(target);
break;
return internal_word_Relocation::spec(target);
case relocInfo::opt_virtual_call_type:
_rspec = opt_virtual_call_Relocation::spec();
break;
return opt_virtual_call_Relocation::spec();
case relocInfo::static_call_type:
_rspec = static_call_Relocation::spec();
break;
return static_call_Relocation::spec();
case relocInfo::runtime_call_type:
_rspec = runtime_call_Relocation::spec();
break;
return runtime_call_Relocation::spec();
case relocInfo::poll_type:
case relocInfo::poll_return_type:
_rspec = Relocation::spec_simple(rtype);
break;
return Relocation::spec_simple(rtype);
case relocInfo::none:
_rspec = RelocationHolder::none;
break;
return RelocationHolder::none;
default:
ShouldNotReachHere();
break;
return RelocationHolder::none;
}
}

Address::Address(address target, relocInfo::relocType rtype) :
_mode(literal),
_literal(target, address_relocation(target, rtype))
{}

void Assembler::b(const Address &dest) {
code_section()->relocate(pc(), dest.rspec());
b(dest.target());
Expand Down

1 comment on commit 5a5ced3

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.