Skip to content

8160404: RelocationHolder constructors have bugs #3513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hotspot/cpu/ppc/assembler_ppc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class AddressLiteral {

protected:
// creation
AddressLiteral() : _address(NULL), _rspec(NULL) {}
AddressLiteral() : _address(NULL), _rspec() {}

public:
AddressLiteral(address addr, RelocationHolder const& rspec)
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/s390/assembler_s390.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class AddressLiteral {

protected:
// creation
AddressLiteral() : _address(NULL), _rspec(NULL) {}
AddressLiteral() : _address(NULL), _rspec() {}

public:
AddressLiteral(address addr, RelocationHolder const& rspec)
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/x86/assembler_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2343,7 +2343,7 @@ void Assembler::jmp_literal(address dest, RelocationHolder const& rspec) {
assert(dest != NULL, "must have a target");
intptr_t disp = dest - (pc() + sizeof(int32_t));
assert(is_simm32(disp), "must be 32bit offset (jmp)");
emit_data(disp, rspec.reloc(), call32_operand);
emit_data(disp, rspec, call32_operand);
}

void Assembler::jmpb_0(Label& L, const char* file, int line) {
Expand Down
41 changes: 39 additions & 2 deletions src/hotspot/share/code/relocInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#include "utilities/align.hpp"
#include "utilities/copy.hpp"

#include <new>
#include <type_traits>

const RelocationHolder RelocationHolder::none; // its type is relocInfo::none


Expand Down Expand Up @@ -235,12 +238,44 @@ Relocation* RelocIterator::reloc() {
APPLY_TO_RELOCATIONS(EACH_TYPE);
#undef EACH_TYPE
assert(t == relocInfo::none, "must be padding");
return new(_rh) Relocation(t);
_rh = RelocationHolder::none;
return _rh.reloc();
}

// Verify all the destructors are trivial, so we don't need to worry about
// destroying old contents of a RelocationHolder being assigned or destroyed.
#define VERIFY_TRIVIALLY_DESTRUCTIBLE_AUX(Reloc) \
static_assert(std::is_trivially_destructible<Reloc>::value, "must be");

//////// Methods for flyweight Relocation types
#define VERIFY_TRIVIALLY_DESTRUCTIBLE(name) \
VERIFY_TRIVIALLY_DESTRUCTIBLE_AUX(PASTE_TOKENS(name, _Relocation));

APPLY_TO_RELOCATIONS(VERIFY_TRIVIALLY_DESTRUCTIBLE)
VERIFY_TRIVIALLY_DESTRUCTIBLE_AUX(Relocation)

#undef VERIFY_TRIVIALLY_DESTRUCTIBLE_AUX
#undef VERIFY_TRIVIALLY_DESTRUCTIBLE

// Define all the copy_into functions. These rely on all Relocation types
// being trivially destructible (verified above). So it doesn't matter
// whether the target holder has been previously initialized or not. There's
// no need to consider that distinction and destruct the relocation in an
// already initialized holder.
#define DEFINE_COPY_INTO_AUX(Reloc) \
void Reloc::copy_into(RelocationHolder& holder) const { \
copy_into_helper(*this, holder); \
}

#define DEFINE_COPY_INTO(name) \
DEFINE_COPY_INTO_AUX(PASTE_TOKENS(name, _Relocation))

APPLY_TO_RELOCATIONS(DEFINE_COPY_INTO)
DEFINE_COPY_INTO_AUX(Relocation)

#undef DEFINE_COPY_INTO_AUX
#undef DEFINE_COPY_INTO

//////// Methods for RelocationHolder

RelocationHolder RelocationHolder::plus(int offset) const {
if (offset != 0) {
Expand All @@ -264,6 +299,8 @@ RelocationHolder RelocationHolder::plus(int offset) const {
return (*this);
}

//////// Methods for flyweight Relocation types

// some relocations can compute their own values
address Relocation::value() {
ShouldNotReachHere();
Expand Down
Loading