Skip to content

Commit 0bfa636

Browse files
author
Boris Ulasevich
committed
8352426: RelocIterator should correctly handle nullptr address of relocation data
Reviewed-by: dlong, vlivanov, kvn
1 parent b7ffd22 commit 0bfa636

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/hotspot/share/code/relocInfo.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ 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+
119122
void RelocIterator::initialize(nmethod* nm, address begin, address limit) {
120123
initialize_misc();
121124

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

129132
_code = nm;
130-
_current = nm->relocation_begin() - 1;
131-
_end = nm->relocation_end();
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+
}
132141
_addr = nm->content_begin();
133142

134143
// Initialize code sections.
@@ -150,7 +159,7 @@ void RelocIterator::initialize(nmethod* nm, address begin, address limit) {
150159
RelocIterator::RelocIterator(CodeSection* cs, address begin, address limit) {
151160
initialize_misc();
152161
assert(((cs->locs_start() != nullptr) && (cs->locs_end() != nullptr)), "valid start and end pointer");
153-
_current = cs->locs_start()-1;
162+
_current = cs->locs_start() - 1;
154163
_end = cs->locs_end();
155164
_addr = cs->start();
156165
_code = nullptr; // Not cb->blob();

0 commit comments

Comments
 (0)