Skip to content

Commit 88c3979

Browse files
committed
8365256: RelocIterator should use indexes instead of pointers
Reviewed-by: kvn, dlong
1 parent aaff9de commit 88c3979

File tree

4 files changed

+64
-69
lines changed

4 files changed

+64
-69
lines changed

src/hotspot/share/code/codeBlob.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ CodeBlob::CodeBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size
128128
int mutable_data_size) :
129129
_oop_maps(nullptr), // will be set by set_oop_maps() call
130130
_name(name),
131-
_mutable_data(header_begin() + size), // default value is blob_end()
131+
_mutable_data(nullptr),
132132
_size(size),
133133
_relocation_size(align_up(cb->total_relocation_size(), oopSize)),
134134
_content_offset(CodeBlob::align_code_offset(header_size)),
@@ -158,10 +158,8 @@ CodeBlob::CodeBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size
158158
if (_mutable_data == nullptr) {
159159
vm_exit_out_of_memory(_mutable_data_size, OOM_MALLOC_ERROR, "codebuffer: no space for mutable data");
160160
}
161-
} else {
162-
// We need unique and valid not null address
163-
assert(_mutable_data == blob_end(), "sanity");
164161
}
162+
assert(_mutable_data != nullptr || _mutable_data_size == 0, "No mutable data => mutable data size is 0");
165163

166164
set_oop_maps(oop_maps);
167165
}
@@ -170,7 +168,7 @@ CodeBlob::CodeBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size
170168
CodeBlob::CodeBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size) :
171169
_oop_maps(nullptr),
172170
_name(name),
173-
_mutable_data(header_begin() + size), // default value is blob_end()
171+
_mutable_data(nullptr),
174172
_size(size),
175173
_relocation_size(0),
176174
_content_offset(CodeBlob::align_code_offset(header_size)),
@@ -184,9 +182,9 @@ CodeBlob::CodeBlob(const char* name, CodeBlobKind kind, int size, uint16_t heade
184182
_kind(kind),
185183
_caller_must_gc_arguments(false)
186184
{
185+
assert(_mutable_data == nullptr && _mutable_data_size == 0, "invariant");
187186
assert(is_aligned(size, oopSize), "unaligned size");
188187
assert(is_aligned(header_size, oopSize), "unaligned size");
189-
assert(_mutable_data == blob_end(), "sanity");
190188
}
191189

192190
void CodeBlob::restore_mutable_data(address reloc_data) {
@@ -197,7 +195,7 @@ void CodeBlob::restore_mutable_data(address reloc_data) {
197195
vm_exit_out_of_memory(_mutable_data_size, OOM_MALLOC_ERROR, "codebuffer: no space for mutable data");
198196
}
199197
} else {
200-
_mutable_data = blob_end(); // default value
198+
_mutable_data = nullptr;
201199
}
202200
if (_relocation_size > 0) {
203201
assert(_mutable_data_size > 0, "relocation is part of mutable data section");
@@ -206,17 +204,13 @@ void CodeBlob::restore_mutable_data(address reloc_data) {
206204
}
207205

208206
void CodeBlob::purge() {
209-
assert(_mutable_data != nullptr, "should never be null");
210-
if (_mutable_data != blob_end()) {
211-
os::free(_mutable_data);
212-
_mutable_data = blob_end(); // Valid not null address
213-
_mutable_data_size = 0;
214-
_relocation_size = 0;
215-
}
216-
if (_oop_maps != nullptr) {
217-
delete _oop_maps;
218-
_oop_maps = nullptr;
219-
}
207+
os::free(_mutable_data);
208+
_mutable_data = nullptr;
209+
_mutable_data_size = 0;
210+
delete _oop_maps;
211+
_oop_maps = nullptr;
212+
_relocation_size = 0;
213+
220214
NOT_PRODUCT(_asm_remarks.clear());
221215
NOT_PRODUCT(_dbg_strings.clear());
222216
}

src/hotspot/share/code/nmethod.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,8 +1327,8 @@ nmethod::nmethod(
13271327
"wrong mutable data size: %d != %d + %d",
13281328
_mutable_data_size, _relocation_size, metadata_size);
13291329

1330-
// native wrapper does not have read-only data but we need unique not null address
1331-
_immutable_data = blob_end();
1330+
// native wrapper does not have read-only data
1331+
_immutable_data = nullptr;
13321332
_immutable_data_size = 0;
13331333
_nul_chk_table_offset = 0;
13341334
_handler_table_offset = 0;
@@ -1510,8 +1510,7 @@ nmethod::nmethod(
15101510
assert(immutable_data != nullptr, "required");
15111511
_immutable_data = immutable_data;
15121512
} else {
1513-
// We need unique not null address
1514-
_immutable_data = blob_end();
1513+
_immutable_data = nullptr;
15151514
}
15161515
CHECKED_CAST(_nul_chk_table_offset, uint16_t, (align_up((int)dependencies->size_in_bytes(), oopSize)));
15171516
CHECKED_CAST(_handler_table_offset, uint16_t, (_nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize)));
@@ -2147,15 +2146,14 @@ void nmethod::purge(bool unregister_nmethod) {
21472146
delete ec;
21482147
ec = next;
21492148
}
2150-
if (_pc_desc_container != nullptr) {
2151-
delete _pc_desc_container;
2152-
}
2149+
2150+
delete _pc_desc_container;
21532151
delete[] _compiled_ic_data;
21542152

2155-
if (_immutable_data != blob_end()) {
2156-
os::free(_immutable_data);
2157-
_immutable_data = blob_end(); // Valid not null address
2158-
}
2153+
os::free(_immutable_data);
2154+
_immutable_data = nullptr;
2155+
_immutable_data_size = 0;
2156+
21592157
if (unregister_nmethod) {
21602158
Universe::heap()->unregister_nmethod(this);
21612159
}

src/hotspot/share/code/relocInfo.cpp

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ void relocInfo::change_reloc_info_for_address(RelocIterator *itr, address pc, re
116116
// ----------------------------------------------------------------------------------------------------
117117
// Implementation of RelocIterator
118118

119-
// A static dummy to serve as a safe pointer when there is no relocation info.
120-
static relocInfo dummy_relocInfo = relocInfo(relocInfo::none, 0);
121-
122119
void RelocIterator::initialize(nmethod* nm, address begin, address limit) {
123120
initialize_misc();
124121

@@ -130,14 +127,9 @@ void RelocIterator::initialize(nmethod* nm, address begin, address limit) {
130127
guarantee(nm != nullptr, "must be able to deduce nmethod from other arguments");
131128

132129
_code = nm;
133-
if (nm->relocation_size() == 0) {
134-
_current = &dummy_relocInfo - 1;
135-
_end = &dummy_relocInfo;
136-
} else {
137-
assert(((nm->relocation_begin() != nullptr) && (nm->relocation_end() != nullptr)), "valid start and end pointer");
138-
_current = nm->relocation_begin() - 1;
139-
_end = nm->relocation_end();
140-
}
130+
_base = nm->relocation_begin();
131+
_current = -1;
132+
_len = nm->relocation_end() - _base;
141133
_addr = nm->content_begin();
142134

143135
// Initialize code sections.
@@ -156,11 +148,21 @@ void RelocIterator::initialize(nmethod* nm, address begin, address limit) {
156148
}
157149

158150

151+
RelocIterator::RelocIterator(relocInfo& ri) {
152+
initialize_misc();
153+
_base = &ri;
154+
_len = 1;
155+
_current = -1;
156+
_limit = nullptr;
157+
_addr = 0;
158+
}
159+
159160
RelocIterator::RelocIterator(CodeSection* cs, address begin, address limit) {
160161
initialize_misc();
161162
assert(((cs->locs_start() != nullptr) && (cs->locs_end() != nullptr)), "valid start and end pointer");
162-
_current = cs->locs_start() - 1;
163-
_end = cs->locs_end();
163+
_base = cs->locs_start();
164+
_len = cs->locs_end() - _base;
165+
_current = -1;
164166
_addr = cs->start();
165167
_code = nullptr; // Not cb->blob();
166168

@@ -186,8 +188,9 @@ RelocIterator::RelocIterator(CodeBlob* cb) {
186188
} else {
187189
_code = nullptr;
188190
}
189-
_current = cb->relocation_begin() - 1;
190-
_end = cb->relocation_end();
191+
_base = cb->relocation_begin();
192+
_len = cb->relocation_end() - _base;
193+
_current = -1;
191194
_addr = cb->content_begin();
192195

193196
_section_start[CodeBuffer::SECT_CONSTS] = cb->content_begin();
@@ -216,7 +219,7 @@ void RelocIterator::set_limits(address begin, address limit) {
216219

217220
// the limit affects this next stuff:
218221
if (begin != nullptr) {
219-
relocInfo* backup;
222+
int backup;
220223
address backup_addr;
221224
while (true) {
222225
backup = _current;
@@ -238,12 +241,12 @@ void RelocIterator::set_limits(address begin, address limit) {
238241
// very efficiently (a single extra halfword). Larger chunks of
239242
// relocation data need a halfword header to hold their size.
240243
void RelocIterator::advance_over_prefix() {
241-
if (_current->is_datalen()) {
242-
_data = (short*) _current->data();
243-
_datalen = _current->datalen();
244+
if (current()->is_datalen()) {
245+
_data = (short*) current()->data();
246+
_datalen = current()->datalen();
244247
_current += _datalen + 1; // skip the embedded data & header
245248
} else {
246-
_databuf = _current->immediate();
249+
_databuf = current()->immediate();
247250
_data = &_databuf;
248251
_datalen = 1;
249252
_current++; // skip the header
@@ -350,9 +353,9 @@ void Relocation::const_verify_data_value(address x) {
350353

351354
RelocationHolder Relocation::spec_simple(relocInfo::relocType rtype) {
352355
if (rtype == relocInfo::none) return RelocationHolder::none;
353-
relocInfo ri = relocInfo(rtype, 0);
354-
RelocIterator itr;
355-
itr.set_current(ri);
356+
relocInfo ri(rtype, 0);
357+
RelocIterator itr(ri);
358+
itr.next();
356359
itr.reloc();
357360
return itr._rh;
358361
}
@@ -839,7 +842,7 @@ void RelocIterator::print_current_on(outputStream* st) {
839842
return;
840843
}
841844
st->print("relocInfo@" INTPTR_FORMAT " [type=%d(%s) addr=" INTPTR_FORMAT " offset=%d",
842-
p2i(_current), type(), relocInfo::type_name((relocInfo::relocType) type()), p2i(_addr), _current->addr_offset());
845+
p2i(current()), type(), relocInfo::type_name((relocInfo::relocType) type()), p2i(_addr), current()->addr_offset());
843846
if (current()->format() != 0)
844847
st->print(" format=%d", current()->format());
845848
if (datalen() == 1) {
@@ -990,7 +993,7 @@ void RelocIterator::print_current_on(outputStream* st) {
990993

991994
void RelocIterator::print_on(outputStream* st) {
992995
RelocIterator save_this = (*this);
993-
relocInfo* scan = _current;
996+
relocInfo* scan = current_no_check();
994997
if (!has_current()) scan += 1; // nothing to scan here!
995998

996999
bool skip_next = has_current();
@@ -1000,7 +1003,7 @@ void RelocIterator::print_on(outputStream* st) {
10001003
skip_next = false;
10011004

10021005
st->print(" @" INTPTR_FORMAT ": ", p2i(scan));
1003-
relocInfo* newscan = _current+1;
1006+
relocInfo* newscan = current_no_check()+1;
10041007
if (!has_current()) newscan -= 1; // nothing to scan here!
10051008
while (scan < newscan) {
10061009
st->print("%04x", *(short*)scan & 0xFFFF);

src/hotspot/share/code/relocInfo.hpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -562,12 +562,13 @@ class RelocIterator : public StackObj {
562562

563563
private:
564564
address _limit; // stop producing relocations after this _addr
565-
relocInfo* _current; // the current relocation information
566-
relocInfo* _end; // end marker; we're done iterating when _current == _end
565+
relocInfo* _base; // base pointer into relocInfo array
566+
int _current; // current index
567+
int _len; // length
567568
nmethod* _code; // compiled method containing _addr
568569
address _addr; // instruction to which the relocation applies
569-
short _databuf; // spare buffer for compressed data
570570
short* _data; // pointer to the relocation's data
571+
short _databuf; // spare buffer for compressed data
571572
short _datalen; // number of halfwords in _data
572573

573574
// Base addresses needed to compute targets of section_word_type relocs.
@@ -578,15 +579,14 @@ class RelocIterator : public StackObj {
578579
_datalen = !b ? -1 : 0;
579580
DEBUG_ONLY(_data = nullptr);
580581
}
581-
void set_current(relocInfo& ri) {
582-
_current = &ri;
583-
set_has_current(true);
584-
}
585582

586583
RelocationHolder _rh; // where the current relocation is allocated
587584

588-
relocInfo* current() const { assert(has_current(), "must have current");
589-
return _current; }
585+
relocInfo* current_no_check() const { return &_base[_current]; }
586+
relocInfo* current() const {
587+
assert(has_current(), "must have current");
588+
return current_no_check();
589+
}
590590

591591
void set_limits(address begin, address limit);
592592

@@ -597,6 +597,7 @@ class RelocIterator : public StackObj {
597597
void initialize(nmethod* nm, address begin, address limit);
598598

599599
RelocIterator() { initialize_misc(); }
600+
RelocIterator(relocInfo& ri);
600601

601602
public:
602603
// constructor
@@ -607,25 +608,24 @@ class RelocIterator : public StackObj {
607608
// get next reloc info, return !eos
608609
bool next() {
609610
_current++;
610-
assert(_current <= _end, "must not overrun relocInfo");
611-
if (_current == _end) {
611+
assert(_current <= _len, "must not overrun relocInfo");
612+
if (_current == _len) {
612613
set_has_current(false);
613614
return false;
614615
}
615616
set_has_current(true);
616617

617-
if (_current->is_prefix()) {
618+
if (current()->is_prefix()) {
618619
advance_over_prefix();
619620
assert(!current()->is_prefix(), "only one prefix at a time");
620621
}
621622

622-
_addr += _current->addr_offset();
623+
_addr += current()->addr_offset();
623624

624625
if (_limit != nullptr && _addr >= _limit) {
625626
set_has_current(false);
626627
return false;
627628
}
628-
629629
return true;
630630
}
631631

0 commit comments

Comments
 (0)