Skip to content

Commit 2e30ff6

Browse files
author
Kim Barrett
committedSep 21, 2020
8253311: Cleanup relocInfo constructors
Reviewed-by: kvn, thartmann
1 parent 43be5a3 commit 2e30ff6

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed
 

‎src/hotspot/share/code/relocInfo.cpp

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,26 +30,30 @@
3030
#include "memory/resourceArea.hpp"
3131
#include "memory/universe.hpp"
3232
#include "oops/compressedOops.inline.hpp"
33+
#include "oops/oop.inline.hpp"
3334
#include "runtime/flags/flagSetting.hpp"
3435
#include "runtime/stubCodeGenerator.hpp"
36+
#include "utilities/align.hpp"
3537
#include "utilities/copy.hpp"
36-
#include "oops/oop.inline.hpp"
3738

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

4041

4142
// Implementation of relocInfo
4243

4344
#ifdef ASSERT
44-
relocInfo::relocInfo(relocType t, int off, int f) {
45-
assert(t != data_prefix_tag, "cannot build a prefix this way");
46-
assert((t & type_mask) == t, "wrong type");
47-
assert((f & format_mask) == f, "wrong format");
48-
assert(off >= 0 && off < offset_limit(), "offset out off bounds");
49-
assert((off & (offset_unit-1)) == 0, "misaligned offset");
50-
(*this) = relocInfo(t, RAW_BITS, off, f);
45+
relocInfo::relocType relocInfo::check_relocType(relocType type) {
46+
assert(type != data_prefix_tag, "cannot build a prefix this way");
47+
assert((type & type_mask) == type, "wrong type");
48+
return type;
5149
}
52-
#endif
50+
51+
void relocInfo::check_offset_and_format(int offset, int format) {
52+
assert(offset >= 0 && offset < offset_limit(), "offset out off bounds");
53+
assert(is_aligned(offset, offset_unit), "misaligned offset");
54+
assert((format & format_mask) == format, "wrong format");
55+
}
56+
#endif // ASSERT
5357

5458
void relocInfo::initialize(CodeSection* dest, Relocation* reloc) {
5559
relocInfo* data = this+1; // here's where the data might go

‎src/hotspot/share/code/relocInfo.hpp

+17-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -53,10 +53,6 @@ class NativeMovConstReg;
5353
// RelocIterator
5454
// A StackObj which iterates over the relocations associated with
5555
// a range of code addresses. Can be used to operate a copy of code.
56-
// BoundRelocation
57-
// An _internal_ type shared by packers and unpackers of relocations.
58-
// It pastes together a RelocationHolder with some pointers into
59-
// code and relocInfo streams.
6056

6157

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

278-
protected:
274+
private:
279275
unsigned short _value;
280276

281-
enum RawBitsToken { RAW_BITS };
282-
relocInfo(relocType type, RawBitsToken ignore, int bits)
277+
static const enum class RawBitsToken {} RAW_BITS{};
278+
279+
relocInfo(relocType type, RawBitsToken, int bits)
283280
: _value((type << nontype_width) + bits) { }
284281

285-
relocInfo(relocType type, RawBitsToken ignore, int off, int f)
286-
: _value((type << nontype_width) + (off / (unsigned)offset_unit) + (f << offset_width)) { }
282+
static relocType check_relocType(relocType type) NOT_DEBUG({ return type; });
283+
284+
static void check_offset_and_format(int offset, int format) NOT_DEBUG_RETURN;
285+
286+
static int compute_bits(int offset, int format) {
287+
check_offset_and_format(offset, format);
288+
return (offset / offset_unit) + (format << offset_width);
289+
}
287290

288291
public:
289-
// constructor
290292
relocInfo(relocType type, int offset, int format = 0)
291-
#ifndef ASSERT
292-
{
293-
(*this) = relocInfo(type, RAW_BITS, offset, format);
294-
}
295-
#else
296-
// Put a bunch of assertions out-of-line.
297-
;
298-
#endif
293+
: relocInfo(check_relocType(type), RAW_BITS, compute_bits(offset, format)) {}
299294

300295
#define APPLY_TO_RELOCATIONS(visitor) \
301296
visitor(oop) \
@@ -376,7 +371,7 @@ class relocInfo {
376371

377372
inline friend relocInfo prefix_relocInfo(int datalen);
378373

379-
protected:
374+
private:
380375
// an immediate relocInfo optimizes a prefix with one 10-bit unsigned value
381376
static relocInfo immediate_relocInfo(int data0) {
382377
assert(fits_into_immediate(data0), "data0 in limits");
@@ -492,8 +487,8 @@ class RelocationHolder {
492487
};
493488

494489
// A RelocIterator iterates through the relocation information of a CodeBlob.
495-
// It is a variable BoundRelocation which is able to take on successive
496-
// values as it is advanced through a code stream.
490+
// It provides access to successive relocations as it is advanced through a
491+
// code stream.
497492
// Usage:
498493
// RelocIterator iter(nm);
499494
// while (iter.next()) {

0 commit comments

Comments
 (0)
Please sign in to comment.