Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8253311: Cleanup relocInfo constructors
Reviewed-by: kvn, thartmann
  • Loading branch information
Kim Barrett committed Sep 21, 2020
1 parent 43be5a3 commit 2e30ff6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 32 deletions.
24 changes: 14 additions & 10 deletions src/hotspot/share/code/relocInfo.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,26 +30,30 @@
#include "memory/resourceArea.hpp"
#include "memory/universe.hpp"
#include "oops/compressedOops.inline.hpp"
#include "oops/oop.inline.hpp"
#include "runtime/flags/flagSetting.hpp"
#include "runtime/stubCodeGenerator.hpp"
#include "utilities/align.hpp"
#include "utilities/copy.hpp"
#include "oops/oop.inline.hpp"

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


// Implementation of relocInfo

#ifdef ASSERT
relocInfo::relocInfo(relocType t, int off, int f) {
assert(t != data_prefix_tag, "cannot build a prefix this way");
assert((t & type_mask) == t, "wrong type");
assert((f & format_mask) == f, "wrong format");
assert(off >= 0 && off < offset_limit(), "offset out off bounds");
assert((off & (offset_unit-1)) == 0, "misaligned offset");
(*this) = relocInfo(t, RAW_BITS, off, f);
relocInfo::relocType relocInfo::check_relocType(relocType type) {
assert(type != data_prefix_tag, "cannot build a prefix this way");
assert((type & type_mask) == type, "wrong type");
return type;
}
#endif

void relocInfo::check_offset_and_format(int offset, int format) {
assert(offset >= 0 && offset < offset_limit(), "offset out off bounds");
assert(is_aligned(offset, offset_unit), "misaligned offset");
assert((format & format_mask) == format, "wrong format");
}
#endif // ASSERT

void relocInfo::initialize(CodeSection* dest, Relocation* reloc) {
relocInfo* data = this+1; // here's where the data might go
Expand Down
39 changes: 17 additions & 22 deletions src/hotspot/share/code/relocInfo.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -53,10 +53,6 @@ class NativeMovConstReg;
// RelocIterator
// A StackObj which iterates over the relocations associated with
// a range of code addresses. Can be used to operate a copy of code.
// BoundRelocation
// An _internal_ type shared by packers and unpackers of relocations.
// It pastes together a RelocationHolder with some pointers into
// code and relocInfo streams.


// Notes on relocType:
Expand Down Expand Up @@ -275,27 +271,26 @@ class relocInfo {
type_mask = 15 // A mask which selects only the above values
};

protected:
private:
unsigned short _value;

enum RawBitsToken { RAW_BITS };
relocInfo(relocType type, RawBitsToken ignore, int bits)
static const enum class RawBitsToken {} RAW_BITS{};

relocInfo(relocType type, RawBitsToken, int bits)
: _value((type << nontype_width) + bits) { }

relocInfo(relocType type, RawBitsToken ignore, int off, int f)
: _value((type << nontype_width) + (off / (unsigned)offset_unit) + (f << offset_width)) { }
static relocType check_relocType(relocType type) NOT_DEBUG({ return type; });

static void check_offset_and_format(int offset, int format) NOT_DEBUG_RETURN;

static int compute_bits(int offset, int format) {
check_offset_and_format(offset, format);
return (offset / offset_unit) + (format << offset_width);
}

public:
// constructor
relocInfo(relocType type, int offset, int format = 0)
#ifndef ASSERT
{
(*this) = relocInfo(type, RAW_BITS, offset, format);
}
#else
// Put a bunch of assertions out-of-line.
;
#endif
: relocInfo(check_relocType(type), RAW_BITS, compute_bits(offset, format)) {}

#define APPLY_TO_RELOCATIONS(visitor) \
visitor(oop) \
Expand Down Expand Up @@ -376,7 +371,7 @@ class relocInfo {

inline friend relocInfo prefix_relocInfo(int datalen);

protected:
private:
// an immediate relocInfo optimizes a prefix with one 10-bit unsigned value
static relocInfo immediate_relocInfo(int data0) {
assert(fits_into_immediate(data0), "data0 in limits");
Expand Down Expand Up @@ -492,8 +487,8 @@ class RelocationHolder {
};

// A RelocIterator iterates through the relocation information of a CodeBlob.
// It is a variable BoundRelocation which is able to take on successive
// values as it is advanced through a code stream.
// It provides access to successive relocations as it is advanced through a
// code stream.
// Usage:
// RelocIterator iter(nm);
// while (iter.next()) {
Expand Down

1 comment on commit 2e30ff6

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 2e30ff6 Sep 21, 2020

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.