author | david |
Fri, 09 Oct 2015 09:42:33 +0200 | |
changeset 33148 | 68fa8b6c4340 |
parent 24952 | 953481cd953d |
child 33198 | b37ad9fbf681 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
22872
diff
changeset
|
2 |
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
14626
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
13728
diff
changeset
|
26 |
#include "code/codeCache.hpp" |
7397 | 27 |
#include "code/compiledIC.hpp" |
28 |
#include "code/nmethod.hpp" |
|
29 |
#include "code/relocInfo.hpp" |
|
30 |
#include "memory/resourceArea.hpp" |
|
31 |
#include "runtime/stubCodeGenerator.hpp" |
|
32 |
#include "utilities/copy.hpp" |
|
1 | 33 |
|
34 |
const RelocationHolder RelocationHolder::none; // its type is relocInfo::none |
|
35 |
||
36 |
||
37 |
// Implementation of relocInfo |
|
38 |
||
39 |
#ifdef ASSERT |
|
40 |
relocInfo::relocInfo(relocType t, int off, int f) { |
|
41 |
assert(t != data_prefix_tag, "cannot build a prefix this way"); |
|
42 |
assert((t & type_mask) == t, "wrong type"); |
|
43 |
assert((f & format_mask) == f, "wrong format"); |
|
44 |
assert(off >= 0 && off < offset_limit(), "offset out off bounds"); |
|
45 |
assert((off & (offset_unit-1)) == 0, "misaligned offset"); |
|
46 |
(*this) = relocInfo(t, RAW_BITS, off, f); |
|
47 |
} |
|
48 |
#endif |
|
49 |
||
50 |
void relocInfo::initialize(CodeSection* dest, Relocation* reloc) { |
|
51 |
relocInfo* data = this+1; // here's where the data might go |
|
52 |
dest->set_locs_end(data); // sync end: the next call may read dest.locs_end |
|
53 |
reloc->pack_data_to(dest); // maybe write data into locs, advancing locs_end |
|
54 |
relocInfo* data_limit = dest->locs_end(); |
|
55 |
if (data_limit > data) { |
|
56 |
relocInfo suffix = (*this); |
|
57 |
data_limit = this->finish_prefix((short*) data_limit); |
|
58 |
// Finish up with the suffix. (Hack note: pack_data_to might edit this.) |
|
59 |
*data_limit = suffix; |
|
60 |
dest->set_locs_end(data_limit+1); |
|
61 |
} |
|
62 |
} |
|
63 |
||
64 |
relocInfo* relocInfo::finish_prefix(short* prefix_limit) { |
|
65 |
assert(sizeof(relocInfo) == sizeof(short), "change this code"); |
|
66 |
short* p = (short*)(this+1); |
|
67 |
assert(prefix_limit >= p, "must be a valid span of data"); |
|
68 |
int plen = prefix_limit - p; |
|
69 |
if (plen == 0) { |
|
70 |
debug_only(_value = 0xFFFF); |
|
71 |
return this; // no data: remove self completely |
|
72 |
} |
|
73 |
if (plen == 1 && fits_into_immediate(p[0])) { |
|
74 |
(*this) = immediate_relocInfo(p[0]); // move data inside self |
|
75 |
return this+1; |
|
76 |
} |
|
77 |
// cannot compact, so just update the count and return the limit pointer |
|
78 |
(*this) = prefix_relocInfo(plen); // write new datalen |
|
79 |
assert(data() + datalen() == prefix_limit, "pointers must line up"); |
|
80 |
return (relocInfo*)prefix_limit; |
|
81 |
} |
|
82 |
||
83 |
||
84 |
void relocInfo::set_type(relocType t) { |
|
85 |
int old_offset = addr_offset(); |
|
86 |
int old_format = format(); |
|
87 |
(*this) = relocInfo(t, old_offset, old_format); |
|
88 |
assert(type()==(int)t, "sanity check"); |
|
89 |
assert(addr_offset()==old_offset, "sanity check"); |
|
90 |
assert(format()==old_format, "sanity check"); |
|
91 |
} |
|
92 |
||
93 |
||
94 |
void relocInfo::set_format(int f) { |
|
95 |
int old_offset = addr_offset(); |
|
96 |
assert((f & format_mask) == f, "wrong format"); |
|
97 |
_value = (_value & ~(format_mask << offset_width)) | (f << offset_width); |
|
98 |
assert(addr_offset()==old_offset, "sanity check"); |
|
99 |
} |
|
100 |
||
101 |
||
102 |
void relocInfo::change_reloc_info_for_address(RelocIterator *itr, address pc, relocType old_type, relocType new_type) { |
|
103 |
bool found = false; |
|
104 |
while (itr->next() && !found) { |
|
105 |
if (itr->addr() == pc) { |
|
106 |
assert(itr->type()==old_type, "wrong relocInfo type found"); |
|
107 |
itr->current()->set_type(new_type); |
|
108 |
found=true; |
|
109 |
} |
|
110 |
} |
|
111 |
assert(found, "no relocInfo found for pc"); |
|
112 |
} |
|
113 |
||
114 |
||
115 |
void relocInfo::remove_reloc_info_for_address(RelocIterator *itr, address pc, relocType old_type) { |
|
116 |
change_reloc_info_for_address(itr, pc, old_type, none); |
|
117 |
} |
|
118 |
||
119 |
||
120 |
// ---------------------------------------------------------------------------------------------------- |
|
121 |
// Implementation of RelocIterator |
|
122 |
||
5686
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1
diff
changeset
|
123 |
void RelocIterator::initialize(nmethod* nm, address begin, address limit) { |
1 | 124 |
initialize_misc(); |
125 |
||
5686
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1
diff
changeset
|
126 |
if (nm == NULL && begin != NULL) { |
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1
diff
changeset
|
127 |
// allow nmethod to be deduced from beginning address |
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1
diff
changeset
|
128 |
CodeBlob* cb = CodeCache::find_blob(begin); |
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1
diff
changeset
|
129 |
nm = cb->as_nmethod_or_null(); |
1 | 130 |
} |
5686
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1
diff
changeset
|
131 |
assert(nm != NULL, "must be able to deduce nmethod from other arguments"); |
1 | 132 |
|
5686
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1
diff
changeset
|
133 |
_code = nm; |
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1
diff
changeset
|
134 |
_current = nm->relocation_begin() - 1; |
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1
diff
changeset
|
135 |
_end = nm->relocation_end(); |
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
136 |
_addr = nm->content_begin(); |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
137 |
|
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
138 |
// Initialize code sections. |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
139 |
_section_start[CodeBuffer::SECT_CONSTS] = nm->consts_begin(); |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
140 |
_section_start[CodeBuffer::SECT_INSTS ] = nm->insts_begin() ; |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
141 |
_section_start[CodeBuffer::SECT_STUBS ] = nm->stub_begin() ; |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
142 |
|
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
143 |
_section_end [CodeBuffer::SECT_CONSTS] = nm->consts_end() ; |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
144 |
_section_end [CodeBuffer::SECT_INSTS ] = nm->insts_end() ; |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
145 |
_section_end [CodeBuffer::SECT_STUBS ] = nm->stub_end() ; |
1 | 146 |
|
147 |
assert(!has_current(), "just checking"); |
|
6418 | 148 |
assert(begin == NULL || begin >= nm->code_begin(), "in bounds"); |
149 |
assert(limit == NULL || limit <= nm->code_end(), "in bounds"); |
|
1 | 150 |
set_limits(begin, limit); |
151 |
} |
|
152 |
||
153 |
||
154 |
RelocIterator::RelocIterator(CodeSection* cs, address begin, address limit) { |
|
155 |
initialize_misc(); |
|
156 |
||
157 |
_current = cs->locs_start()-1; |
|
158 |
_end = cs->locs_end(); |
|
159 |
_addr = cs->start(); |
|
160 |
_code = NULL; // Not cb->blob(); |
|
161 |
||
162 |
CodeBuffer* cb = cs->outer(); |
|
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
163 |
assert((int) SECT_LIMIT == CodeBuffer::SECT_LIMIT, "my copy must be equal"); |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
164 |
for (int n = (int) CodeBuffer::SECT_FIRST; n < (int) CodeBuffer::SECT_LIMIT; n++) { |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
165 |
CodeSection* cs = cb->code_section(n); |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
166 |
_section_start[n] = cs->start(); |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
167 |
_section_end [n] = cs->end(); |
1 | 168 |
} |
169 |
||
170 |
assert(!has_current(), "just checking"); |
|
171 |
||
172 |
assert(begin == NULL || begin >= cs->start(), "in bounds"); |
|
173 |
assert(limit == NULL || limit <= cs->end(), "in bounds"); |
|
174 |
set_limits(begin, limit); |
|
175 |
} |
|
176 |
||
177 |
||
178 |
enum { indexCardSize = 128 }; |
|
179 |
struct RelocIndexEntry { |
|
180 |
jint addr_offset; // offset from header_end of an addr() |
|
181 |
jint reloc_offset; // offset from header_end of a relocInfo (prefix) |
|
182 |
}; |
|
183 |
||
184 |
||
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
185 |
bool RelocIterator::addr_in_const() const { |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
186 |
const int n = CodeBuffer::SECT_CONSTS; |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
187 |
return section_start(n) <= addr() && addr() < section_end(n); |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
188 |
} |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
189 |
|
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
190 |
|
1 | 191 |
static inline int num_cards(int code_size) { |
192 |
return (code_size-1) / indexCardSize; |
|
193 |
} |
|
194 |
||
195 |
||
196 |
int RelocIterator::locs_and_index_size(int code_size, int locs_size) { |
|
197 |
if (!UseRelocIndex) return locs_size; // no index |
|
198 |
code_size = round_to(code_size, oopSize); |
|
199 |
locs_size = round_to(locs_size, oopSize); |
|
200 |
int index_size = num_cards(code_size) * sizeof(RelocIndexEntry); |
|
201 |
// format of indexed relocs: |
|
202 |
// relocation_begin: relocInfo ... |
|
203 |
// index: (addr,reloc#) ... |
|
204 |
// indexSize :relocation_end |
|
205 |
return locs_size + index_size + BytesPerInt; |
|
206 |
} |
|
207 |
||
208 |
||
209 |
void RelocIterator::create_index(relocInfo* dest_begin, int dest_count, relocInfo* dest_end) { |
|
210 |
address relocation_begin = (address)dest_begin; |
|
211 |
address relocation_end = (address)dest_end; |
|
212 |
int total_size = relocation_end - relocation_begin; |
|
213 |
int locs_size = dest_count * sizeof(relocInfo); |
|
214 |
if (!UseRelocIndex) { |
|
215 |
Copy::fill_to_bytes(relocation_begin + locs_size, total_size-locs_size, 0); |
|
216 |
return; |
|
217 |
} |
|
218 |
int index_size = total_size - locs_size - BytesPerInt; // find out how much space is left |
|
219 |
int ncards = index_size / sizeof(RelocIndexEntry); |
|
220 |
assert(total_size == locs_size + index_size + BytesPerInt, "checkin'"); |
|
221 |
assert(index_size >= 0 && index_size % sizeof(RelocIndexEntry) == 0, "checkin'"); |
|
222 |
jint* index_size_addr = (jint*)relocation_end - 1; |
|
223 |
||
224 |
assert(sizeof(jint) == BytesPerInt, "change this code"); |
|
225 |
||
226 |
*index_size_addr = index_size; |
|
227 |
if (index_size != 0) { |
|
228 |
assert(index_size > 0, "checkin'"); |
|
229 |
||
230 |
RelocIndexEntry* index = (RelocIndexEntry *)(relocation_begin + locs_size); |
|
231 |
assert(index == (RelocIndexEntry*)index_size_addr - ncards, "checkin'"); |
|
232 |
||
233 |
// walk over the relocations, and fill in index entries as we go |
|
234 |
RelocIterator iter; |
|
235 |
const address initial_addr = NULL; |
|
236 |
relocInfo* const initial_current = dest_begin - 1; // biased by -1 like elsewhere |
|
237 |
||
238 |
iter._code = NULL; |
|
239 |
iter._addr = initial_addr; |
|
240 |
iter._limit = (address)(intptr_t)(ncards * indexCardSize); |
|
241 |
iter._current = initial_current; |
|
242 |
iter._end = dest_begin + dest_count; |
|
243 |
||
244 |
int i = 0; |
|
245 |
address next_card_addr = (address)indexCardSize; |
|
246 |
int addr_offset = 0; |
|
247 |
int reloc_offset = 0; |
|
248 |
while (true) { |
|
249 |
// Checkpoint the iterator before advancing it. |
|
250 |
addr_offset = iter._addr - initial_addr; |
|
251 |
reloc_offset = iter._current - initial_current; |
|
252 |
if (!iter.next()) break; |
|
253 |
while (iter.addr() >= next_card_addr) { |
|
254 |
index[i].addr_offset = addr_offset; |
|
255 |
index[i].reloc_offset = reloc_offset; |
|
256 |
i++; |
|
257 |
next_card_addr += indexCardSize; |
|
258 |
} |
|
259 |
} |
|
260 |
while (i < ncards) { |
|
261 |
index[i].addr_offset = addr_offset; |
|
262 |
index[i].reloc_offset = reloc_offset; |
|
263 |
i++; |
|
264 |
} |
|
265 |
} |
|
266 |
} |
|
267 |
||
268 |
||
269 |
void RelocIterator::set_limits(address begin, address limit) { |
|
270 |
int index_size = 0; |
|
271 |
if (UseRelocIndex && _code != NULL) { |
|
272 |
index_size = ((jint*)_end)[-1]; |
|
273 |
_end = (relocInfo*)( (address)_end - index_size - BytesPerInt ); |
|
274 |
} |
|
275 |
||
276 |
_limit = limit; |
|
277 |
||
278 |
// the limit affects this next stuff: |
|
279 |
if (begin != NULL) { |
|
280 |
#ifdef ASSERT |
|
281 |
// In ASSERT mode we do not actually use the index, but simply |
|
282 |
// check that its contents would have led us to the right answer. |
|
283 |
address addrCheck = _addr; |
|
284 |
relocInfo* infoCheck = _current; |
|
285 |
#endif // ASSERT |
|
286 |
if (index_size > 0) { |
|
287 |
// skip ahead |
|
288 |
RelocIndexEntry* index = (RelocIndexEntry*)_end; |
|
289 |
RelocIndexEntry* index_limit = (RelocIndexEntry*)((address)index + index_size); |
|
6418 | 290 |
assert(_addr == _code->code_begin(), "_addr must be unadjusted"); |
1 | 291 |
int card = (begin - _addr) / indexCardSize; |
292 |
if (card > 0) { |
|
293 |
if (index+card-1 < index_limit) index += card-1; |
|
294 |
else index = index_limit - 1; |
|
295 |
#ifdef ASSERT |
|
296 |
addrCheck = _addr + index->addr_offset; |
|
297 |
infoCheck = _current + index->reloc_offset; |
|
298 |
#else |
|
299 |
// Advance the iterator immediately to the last valid state |
|
300 |
// for the previous card. Calling "next" will then advance |
|
301 |
// it to the first item on the required card. |
|
302 |
_addr += index->addr_offset; |
|
303 |
_current += index->reloc_offset; |
|
304 |
#endif // ASSERT |
|
305 |
} |
|
306 |
} |
|
307 |
||
308 |
relocInfo* backup; |
|
309 |
address backup_addr; |
|
310 |
while (true) { |
|
311 |
backup = _current; |
|
312 |
backup_addr = _addr; |
|
313 |
#ifdef ASSERT |
|
314 |
if (backup == infoCheck) { |
|
315 |
assert(backup_addr == addrCheck, "must match"); addrCheck = NULL; infoCheck = NULL; |
|
316 |
} else { |
|
317 |
assert(addrCheck == NULL || backup_addr <= addrCheck, "must not pass addrCheck"); |
|
318 |
} |
|
319 |
#endif // ASSERT |
|
320 |
if (!next() || addr() >= begin) break; |
|
321 |
} |
|
322 |
assert(addrCheck == NULL || addrCheck == backup_addr, "must have matched addrCheck"); |
|
323 |
assert(infoCheck == NULL || infoCheck == backup, "must have matched infoCheck"); |
|
324 |
// At this point, either we are at the first matching record, |
|
325 |
// or else there is no such record, and !has_current(). |
|
326 |
// In either case, revert to the immediatly preceding state. |
|
327 |
_current = backup; |
|
328 |
_addr = backup_addr; |
|
329 |
set_has_current(false); |
|
330 |
} |
|
331 |
} |
|
332 |
||
333 |
||
334 |
void RelocIterator::set_limit(address limit) { |
|
335 |
address code_end = (address)code() + code()->size(); |
|
336 |
assert(limit == NULL || limit <= code_end, "in bounds"); |
|
337 |
_limit = limit; |
|
338 |
} |
|
339 |
||
340 |
// All the strange bit-encodings are in here. |
|
341 |
// The idea is to encode relocation data which are small integers |
|
342 |
// very efficiently (a single extra halfword). Larger chunks of |
|
343 |
// relocation data need a halfword header to hold their size. |
|
344 |
void RelocIterator::advance_over_prefix() { |
|
345 |
if (_current->is_datalen()) { |
|
346 |
_data = (short*) _current->data(); |
|
347 |
_datalen = _current->datalen(); |
|
348 |
_current += _datalen + 1; // skip the embedded data & header |
|
349 |
} else { |
|
350 |
_databuf = _current->immediate(); |
|
351 |
_data = &_databuf; |
|
352 |
_datalen = 1; |
|
353 |
_current++; // skip the header |
|
354 |
} |
|
355 |
// The client will see the following relocInfo, whatever that is. |
|
356 |
// It is the reloc to which the preceding data applies. |
|
357 |
} |
|
358 |
||
359 |
||
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
360 |
void RelocIterator::initialize_misc() { |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
361 |
set_has_current(false); |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
362 |
for (int i = (int) CodeBuffer::SECT_FIRST; i < (int) CodeBuffer::SECT_LIMIT; i++) { |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
363 |
_section_start[i] = NULL; // these will be lazily computed, if needed |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
364 |
_section_end [i] = NULL; |
1 | 365 |
} |
366 |
} |
|
367 |
||
368 |
||
369 |
Relocation* RelocIterator::reloc() { |
|
370 |
// (take the "switch" out-of-line) |
|
371 |
relocInfo::relocType t = type(); |
|
372 |
if (false) {} |
|
373 |
#define EACH_TYPE(name) \ |
|
374 |
else if (t == relocInfo::name##_type) { \ |
|
375 |
return name##_reloc(); \ |
|
376 |
} |
|
377 |
APPLY_TO_RELOCATIONS(EACH_TYPE); |
|
378 |
#undef EACH_TYPE |
|
379 |
assert(t == relocInfo::none, "must be padding"); |
|
380 |
return new(_rh) Relocation(); |
|
381 |
} |
|
382 |
||
383 |
||
384 |
//////// Methods for flyweight Relocation types |
|
385 |
||
386 |
||
387 |
RelocationHolder RelocationHolder::plus(int offset) const { |
|
388 |
if (offset != 0) { |
|
389 |
switch (type()) { |
|
390 |
case relocInfo::none: |
|
391 |
break; |
|
392 |
case relocInfo::oop_type: |
|
393 |
{ |
|
394 |
oop_Relocation* r = (oop_Relocation*)reloc(); |
|
395 |
return oop_Relocation::spec(r->oop_index(), r->offset() + offset); |
|
396 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
397 |
case relocInfo::metadata_type: |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
398 |
{ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
399 |
metadata_Relocation* r = (metadata_Relocation*)reloc(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
400 |
return metadata_Relocation::spec(r->metadata_index(), r->offset() + offset); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
401 |
} |
1 | 402 |
default: |
403 |
ShouldNotReachHere(); |
|
404 |
} |
|
405 |
} |
|
406 |
return (*this); |
|
407 |
} |
|
408 |
||
409 |
||
410 |
void Relocation::guarantee_size() { |
|
411 |
guarantee(false, "Make _relocbuf bigger!"); |
|
412 |
} |
|
413 |
||
414 |
// some relocations can compute their own values |
|
415 |
address Relocation::value() { |
|
416 |
ShouldNotReachHere(); |
|
417 |
return NULL; |
|
418 |
} |
|
419 |
||
420 |
||
421 |
void Relocation::set_value(address x) { |
|
422 |
ShouldNotReachHere(); |
|
423 |
} |
|
424 |
||
425 |
||
426 |
RelocationHolder Relocation::spec_simple(relocInfo::relocType rtype) { |
|
427 |
if (rtype == relocInfo::none) return RelocationHolder::none; |
|
428 |
relocInfo ri = relocInfo(rtype, 0); |
|
429 |
RelocIterator itr; |
|
430 |
itr.set_current(ri); |
|
431 |
itr.reloc(); |
|
432 |
return itr._rh; |
|
433 |
} |
|
434 |
||
435 |
int32_t Relocation::runtime_address_to_index(address runtime_address) { |
|
9111
c100c09c66f2
6777083: assert(target != __null,"must not be null")
never
parents:
8724
diff
changeset
|
436 |
assert(!is_reloc_index((intptr_t)runtime_address), "must not look like an index"); |
1 | 437 |
|
438 |
if (runtime_address == NULL) return 0; |
|
439 |
||
440 |
StubCodeDesc* p = StubCodeDesc::desc_for(runtime_address); |
|
441 |
if (p != NULL && p->begin() == runtime_address) { |
|
9111
c100c09c66f2
6777083: assert(target != __null,"must not be null")
never
parents:
8724
diff
changeset
|
442 |
assert(is_reloc_index(p->index()), "there must not be too many stubs"); |
1 | 443 |
return (int32_t)p->index(); |
444 |
} else { |
|
445 |
// Known "miscellaneous" non-stub pointers: |
|
446 |
// os::get_polling_page(), SafepointSynchronize::address_of_state() |
|
447 |
if (PrintRelocations) { |
|
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
24952
diff
changeset
|
448 |
tty->print_cr("random unregistered address in relocInfo: " INTPTR_FORMAT, p2i(runtime_address)); |
1 | 449 |
} |
450 |
#ifndef _LP64 |
|
451 |
return (int32_t) (intptr_t)runtime_address; |
|
452 |
#else |
|
453 |
// didn't fit return non-index |
|
454 |
return -1; |
|
455 |
#endif /* _LP64 */ |
|
456 |
} |
|
457 |
} |
|
458 |
||
459 |
||
460 |
address Relocation::index_to_runtime_address(int32_t index) { |
|
461 |
if (index == 0) return NULL; |
|
462 |
||
9111
c100c09c66f2
6777083: assert(target != __null,"must not be null")
never
parents:
8724
diff
changeset
|
463 |
if (is_reloc_index(index)) { |
1 | 464 |
StubCodeDesc* p = StubCodeDesc::desc_for_index(index); |
465 |
assert(p != NULL, "there must be a stub for this index"); |
|
466 |
return p->begin(); |
|
467 |
} else { |
|
468 |
#ifndef _LP64 |
|
469 |
// this only works on 32bit machines |
|
470 |
return (address) ((intptr_t) index); |
|
471 |
#else |
|
472 |
fatal("Relocation::index_to_runtime_address, int32_t not pointer sized"); |
|
473 |
return NULL; |
|
474 |
#endif /* _LP64 */ |
|
475 |
} |
|
476 |
} |
|
477 |
||
478 |
address Relocation::old_addr_for(address newa, |
|
479 |
const CodeBuffer* src, CodeBuffer* dest) { |
|
480 |
int sect = dest->section_index_of(newa); |
|
481 |
guarantee(sect != CodeBuffer::SECT_NONE, "lost track of this address"); |
|
482 |
address ostart = src->code_section(sect)->start(); |
|
483 |
address nstart = dest->code_section(sect)->start(); |
|
484 |
return ostart + (newa - nstart); |
|
485 |
} |
|
486 |
||
487 |
address Relocation::new_addr_for(address olda, |
|
488 |
const CodeBuffer* src, CodeBuffer* dest) { |
|
489 |
debug_only(const CodeBuffer* src0 = src); |
|
490 |
int sect = CodeBuffer::SECT_NONE; |
|
491 |
// Look for olda in the source buffer, and all previous incarnations |
|
492 |
// if the source buffer has been expanded. |
|
493 |
for (; src != NULL; src = src->before_expand()) { |
|
494 |
sect = src->section_index_of(olda); |
|
495 |
if (sect != CodeBuffer::SECT_NONE) break; |
|
496 |
} |
|
497 |
guarantee(sect != CodeBuffer::SECT_NONE, "lost track of this address"); |
|
498 |
address ostart = src->code_section(sect)->start(); |
|
499 |
address nstart = dest->code_section(sect)->start(); |
|
500 |
return nstart + (olda - ostart); |
|
501 |
} |
|
502 |
||
503 |
void Relocation::normalize_address(address& addr, const CodeSection* dest, bool allow_other_sections) { |
|
504 |
address addr0 = addr; |
|
505 |
if (addr0 == NULL || dest->allocates2(addr0)) return; |
|
506 |
CodeBuffer* cb = dest->outer(); |
|
507 |
addr = new_addr_for(addr0, cb, cb); |
|
508 |
assert(allow_other_sections || dest->contains2(addr), |
|
509 |
"addr must be in required section"); |
|
510 |
} |
|
511 |
||
512 |
||
513 |
void CallRelocation::set_destination(address x) { |
|
514 |
pd_set_call_destination(x); |
|
515 |
} |
|
516 |
||
517 |
void CallRelocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) { |
|
518 |
// Usually a self-relative reference to an external routine. |
|
519 |
// On some platforms, the reference is absolute (not self-relative). |
|
520 |
// The enhanced use of pd_call_destination sorts this all out. |
|
521 |
address orig_addr = old_addr_for(addr(), src, dest); |
|
522 |
address callee = pd_call_destination(orig_addr); |
|
523 |
// Reassert the callee address, this time in the new copy of the code. |
|
524 |
pd_set_call_destination(callee); |
|
525 |
} |
|
526 |
||
527 |
||
528 |
//// pack/unpack methods |
|
529 |
||
530 |
void oop_Relocation::pack_data_to(CodeSection* dest) { |
|
531 |
short* p = (short*) dest->locs_end(); |
|
532 |
p = pack_2_ints_to(p, _oop_index, _offset); |
|
533 |
dest->set_locs_end((relocInfo*) p); |
|
534 |
} |
|
535 |
||
536 |
||
537 |
void oop_Relocation::unpack_data() { |
|
538 |
unpack_2_ints(_oop_index, _offset); |
|
539 |
} |
|
540 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
541 |
void metadata_Relocation::pack_data_to(CodeSection* dest) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
542 |
short* p = (short*) dest->locs_end(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
543 |
p = pack_2_ints_to(p, _metadata_index, _offset); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
544 |
dest->set_locs_end((relocInfo*) p); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
545 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
546 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
547 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
548 |
void metadata_Relocation::unpack_data() { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
549 |
unpack_2_ints(_metadata_index, _offset); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
550 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
551 |
|
1 | 552 |
|
553 |
void virtual_call_Relocation::pack_data_to(CodeSection* dest) { |
|
554 |
short* p = (short*) dest->locs_end(); |
|
555 |
address point = dest->locs_point(); |
|
556 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
557 |
normalize_address(_cached_value, dest); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
558 |
jint x0 = scaled_offset_null_special(_cached_value, point); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
559 |
p = pack_1_int_to(p, x0); |
1 | 560 |
dest->set_locs_end((relocInfo*) p); |
561 |
} |
|
562 |
||
563 |
||
564 |
void virtual_call_Relocation::unpack_data() { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
565 |
jint x0 = unpack_1_int(); |
1 | 566 |
address point = addr(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
567 |
_cached_value = x0==0? NULL: address_from_scaled_offset(x0, point); |
1 | 568 |
} |
569 |
||
570 |
||
571 |
void static_stub_Relocation::pack_data_to(CodeSection* dest) { |
|
572 |
short* p = (short*) dest->locs_end(); |
|
573 |
CodeSection* insts = dest->outer()->insts(); |
|
574 |
normalize_address(_static_call, insts); |
|
575 |
p = pack_1_int_to(p, scaled_offset(_static_call, insts->start())); |
|
576 |
dest->set_locs_end((relocInfo*) p); |
|
577 |
} |
|
578 |
||
579 |
void static_stub_Relocation::unpack_data() { |
|
580 |
address base = binding()->section_start(CodeBuffer::SECT_INSTS); |
|
581 |
_static_call = address_from_scaled_offset(unpack_1_int(), base); |
|
582 |
} |
|
583 |
||
22813
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
584 |
void trampoline_stub_Relocation::pack_data_to(CodeSection* dest ) { |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
585 |
short* p = (short*) dest->locs_end(); |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
586 |
CodeSection* insts = dest->outer()->insts(); |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
587 |
normalize_address(_owner, insts); |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
588 |
p = pack_1_int_to(p, scaled_offset(_owner, insts->start())); |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
589 |
dest->set_locs_end((relocInfo*) p); |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
590 |
} |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
591 |
|
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
592 |
void trampoline_stub_Relocation::unpack_data() { |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
593 |
address base = binding()->section_start(CodeBuffer::SECT_INSTS); |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
594 |
_owner = address_from_scaled_offset(unpack_1_int(), base); |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
595 |
} |
1 | 596 |
|
597 |
void external_word_Relocation::pack_data_to(CodeSection* dest) { |
|
598 |
short* p = (short*) dest->locs_end(); |
|
599 |
int32_t index = runtime_address_to_index(_target); |
|
600 |
#ifndef _LP64 |
|
601 |
p = pack_1_int_to(p, index); |
|
602 |
#else |
|
9111
c100c09c66f2
6777083: assert(target != __null,"must not be null")
never
parents:
8724
diff
changeset
|
603 |
if (is_reloc_index(index)) { |
1 | 604 |
p = pack_2_ints_to(p, index, 0); |
605 |
} else { |
|
606 |
jlong t = (jlong) _target; |
|
607 |
int32_t lo = low(t); |
|
608 |
int32_t hi = high(t); |
|
609 |
p = pack_2_ints_to(p, lo, hi); |
|
610 |
DEBUG_ONLY(jlong t1 = jlong_from(hi, lo)); |
|
9111
c100c09c66f2
6777083: assert(target != __null,"must not be null")
never
parents:
8724
diff
changeset
|
611 |
assert(!is_reloc_index(t1) && (address) t1 == _target, "not symmetric"); |
1 | 612 |
} |
613 |
#endif /* _LP64 */ |
|
614 |
dest->set_locs_end((relocInfo*) p); |
|
615 |
} |
|
616 |
||
617 |
||
618 |
void external_word_Relocation::unpack_data() { |
|
619 |
#ifndef _LP64 |
|
620 |
_target = index_to_runtime_address(unpack_1_int()); |
|
621 |
#else |
|
622 |
int32_t lo, hi; |
|
623 |
unpack_2_ints(lo, hi); |
|
624 |
jlong t = jlong_from(hi, lo);; |
|
9111
c100c09c66f2
6777083: assert(target != __null,"must not be null")
never
parents:
8724
diff
changeset
|
625 |
if (is_reloc_index(t)) { |
1 | 626 |
_target = index_to_runtime_address(t); |
627 |
} else { |
|
628 |
_target = (address) t; |
|
629 |
} |
|
630 |
#endif /* _LP64 */ |
|
631 |
} |
|
632 |
||
633 |
||
634 |
void internal_word_Relocation::pack_data_to(CodeSection* dest) { |
|
635 |
short* p = (short*) dest->locs_end(); |
|
636 |
normalize_address(_target, dest, true); |
|
637 |
||
638 |
// Check whether my target address is valid within this section. |
|
639 |
// If not, strengthen the relocation type to point to another section. |
|
640 |
int sindex = _section; |
|
641 |
if (sindex == CodeBuffer::SECT_NONE && _target != NULL |
|
642 |
&& (!dest->allocates(_target) || _target == dest->locs_point())) { |
|
643 |
sindex = dest->outer()->section_index_of(_target); |
|
644 |
guarantee(sindex != CodeBuffer::SECT_NONE, "must belong somewhere"); |
|
645 |
relocInfo* base = dest->locs_end() - 1; |
|
646 |
assert(base->type() == this->type(), "sanity"); |
|
647 |
// Change the written type, to be section_word_type instead. |
|
648 |
base->set_type(relocInfo::section_word_type); |
|
649 |
} |
|
650 |
||
651 |
// Note: An internal_word relocation cannot refer to its own instruction, |
|
652 |
// because we reserve "0" to mean that the pointer itself is embedded |
|
653 |
// in the code stream. We use a section_word relocation for such cases. |
|
654 |
||
655 |
if (sindex == CodeBuffer::SECT_NONE) { |
|
656 |
assert(type() == relocInfo::internal_word_type, "must be base class"); |
|
657 |
guarantee(_target == NULL || dest->allocates2(_target), "must be within the given code section"); |
|
658 |
jint x0 = scaled_offset_null_special(_target, dest->locs_point()); |
|
659 |
assert(!(x0 == 0 && _target != NULL), "correct encoding of null target"); |
|
660 |
p = pack_1_int_to(p, x0); |
|
661 |
} else { |
|
662 |
assert(_target != NULL, "sanity"); |
|
663 |
CodeSection* sect = dest->outer()->code_section(sindex); |
|
664 |
guarantee(sect->allocates2(_target), "must be in correct section"); |
|
665 |
address base = sect->start(); |
|
666 |
jint offset = scaled_offset(_target, base); |
|
667 |
assert((uint)sindex < (uint)CodeBuffer::SECT_LIMIT, "sanity"); |
|
668 |
assert(CodeBuffer::SECT_LIMIT <= (1 << section_width), "section_width++"); |
|
669 |
p = pack_1_int_to(p, (offset << section_width) | sindex); |
|
670 |
} |
|
671 |
||
672 |
dest->set_locs_end((relocInfo*) p); |
|
673 |
} |
|
674 |
||
675 |
||
676 |
void internal_word_Relocation::unpack_data() { |
|
677 |
jint x0 = unpack_1_int(); |
|
678 |
_target = x0==0? NULL: address_from_scaled_offset(x0, addr()); |
|
679 |
_section = CodeBuffer::SECT_NONE; |
|
680 |
} |
|
681 |
||
682 |
||
683 |
void section_word_Relocation::unpack_data() { |
|
684 |
jint x = unpack_1_int(); |
|
685 |
jint offset = (x >> section_width); |
|
686 |
int sindex = (x & ((1<<section_width)-1)); |
|
687 |
address base = binding()->section_start(sindex); |
|
688 |
||
689 |
_section = sindex; |
|
690 |
_target = address_from_scaled_offset(offset, base); |
|
691 |
} |
|
692 |
||
693 |
//// miscellaneous methods |
|
694 |
oop* oop_Relocation::oop_addr() { |
|
695 |
int n = _oop_index; |
|
696 |
if (n == 0) { |
|
697 |
// oop is stored in the code stream |
|
698 |
return (oop*) pd_address_in_code(); |
|
699 |
} else { |
|
5686
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1
diff
changeset
|
700 |
// oop is stored in table at nmethod::oops_begin |
1 | 701 |
return code()->oop_addr_at(n); |
702 |
} |
|
703 |
} |
|
704 |
||
705 |
||
706 |
oop oop_Relocation::oop_value() { |
|
707 |
oop v = *oop_addr(); |
|
708 |
// clean inline caches store a special pseudo-null |
|
709 |
if (v == (oop)Universe::non_oop_word()) v = NULL; |
|
710 |
return v; |
|
711 |
} |
|
712 |
||
713 |
||
714 |
void oop_Relocation::fix_oop_relocation() { |
|
715 |
if (!oop_is_immediate()) { |
|
716 |
// get the oop from the pool, and re-insert it into the instruction: |
|
717 |
set_value(value()); |
|
718 |
} |
|
719 |
} |
|
720 |
||
721 |
||
8724
693c6b883b54
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
8107
diff
changeset
|
722 |
void oop_Relocation::verify_oop_relocation() { |
693c6b883b54
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
8107
diff
changeset
|
723 |
if (!oop_is_immediate()) { |
693c6b883b54
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
8107
diff
changeset
|
724 |
// get the oop from the pool, and re-insert it into the instruction: |
693c6b883b54
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
8107
diff
changeset
|
725 |
verify_value(value()); |
693c6b883b54
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
8107
diff
changeset
|
726 |
} |
693c6b883b54
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
8107
diff
changeset
|
727 |
} |
693c6b883b54
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
8107
diff
changeset
|
728 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
729 |
// meta data versions |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
730 |
Metadata** metadata_Relocation::metadata_addr() { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
731 |
int n = _metadata_index; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
732 |
if (n == 0) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
733 |
// metadata is stored in the code stream |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
734 |
return (Metadata**) pd_address_in_code(); |
1 | 735 |
} else { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
736 |
// metadata is stored in table at nmethod::metadatas_begin |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
737 |
return code()->metadata_addr_at(n); |
1 | 738 |
} |
739 |
} |
|
740 |
||
741 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
742 |
Metadata* metadata_Relocation::metadata_value() { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
743 |
Metadata* v = *metadata_addr(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
744 |
// clean inline caches store a special pseudo-null |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
745 |
if (v == (Metadata*)Universe::non_oop_word()) v = NULL; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
746 |
return v; |
1 | 747 |
} |
748 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
749 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
750 |
void metadata_Relocation::fix_metadata_relocation() { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
751 |
if (!metadata_is_immediate()) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
752 |
// get the metadata from the pool, and re-insert it into the instruction: |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
753 |
pd_fix_value(value()); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
754 |
} |
1 | 755 |
} |
756 |
||
757 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
758 |
void metadata_Relocation::verify_metadata_relocation() { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
759 |
if (!metadata_is_immediate()) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
760 |
// get the metadata from the pool, and re-insert it into the instruction: |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
761 |
verify_value(value()); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
762 |
} |
1 | 763 |
} |
764 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
765 |
address virtual_call_Relocation::cached_value() { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
766 |
assert(_cached_value != NULL && _cached_value < addr(), "must precede ic_call"); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
767 |
return _cached_value; |
1 | 768 |
} |
769 |
||
770 |
||
771 |
void virtual_call_Relocation::clear_inline_cache() { |
|
772 |
// No stubs for ICs |
|
773 |
// Clean IC |
|
774 |
ResourceMark rm; |
|
775 |
CompiledIC* icache = CompiledIC_at(this); |
|
776 |
icache->set_to_clean(); |
|
777 |
} |
|
778 |
||
779 |
||
780 |
void opt_virtual_call_Relocation::clear_inline_cache() { |
|
781 |
// No stubs for ICs |
|
782 |
// Clean IC |
|
783 |
ResourceMark rm; |
|
784 |
CompiledIC* icache = CompiledIC_at(this); |
|
785 |
icache->set_to_clean(); |
|
786 |
} |
|
787 |
||
788 |
||
789 |
address opt_virtual_call_Relocation::static_stub() { |
|
790 |
// search for the static stub who points back to this static call |
|
791 |
address static_call_addr = addr(); |
|
792 |
RelocIterator iter(code()); |
|
793 |
while (iter.next()) { |
|
794 |
if (iter.type() == relocInfo::static_stub_type) { |
|
795 |
if (iter.static_stub_reloc()->static_call() == static_call_addr) { |
|
796 |
return iter.addr(); |
|
797 |
} |
|
798 |
} |
|
799 |
} |
|
800 |
return NULL; |
|
801 |
} |
|
802 |
||
803 |
||
804 |
void static_call_Relocation::clear_inline_cache() { |
|
805 |
// Safe call site info |
|
806 |
CompiledStaticCall* handler = compiledStaticCall_at(this); |
|
807 |
handler->set_to_clean(); |
|
808 |
} |
|
809 |
||
810 |
||
811 |
address static_call_Relocation::static_stub() { |
|
812 |
// search for the static stub who points back to this static call |
|
813 |
address static_call_addr = addr(); |
|
814 |
RelocIterator iter(code()); |
|
815 |
while (iter.next()) { |
|
816 |
if (iter.type() == relocInfo::static_stub_type) { |
|
817 |
if (iter.static_stub_reloc()->static_call() == static_call_addr) { |
|
818 |
return iter.addr(); |
|
819 |
} |
|
820 |
} |
|
821 |
} |
|
822 |
return NULL; |
|
823 |
} |
|
824 |
||
22813
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
825 |
// Finds the trampoline address for a call. If no trampoline stub is |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
826 |
// found NULL is returned which can be handled by the caller. |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
827 |
address trampoline_stub_Relocation::get_trampoline_for(address call, nmethod* code) { |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
828 |
// There are no relocations available when the code gets relocated |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
829 |
// because of CodeBuffer expansion. |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
830 |
if (code->relocation_size() == 0) |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
831 |
return NULL; |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
832 |
|
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
833 |
RelocIterator iter(code, call); |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
834 |
while (iter.next()) { |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
835 |
if (iter.type() == relocInfo::trampoline_stub_type) { |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
836 |
if (iter.trampoline_stub_reloc()->owner() == call) { |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
837 |
return iter.addr(); |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
838 |
} |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
839 |
} |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
840 |
} |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
841 |
|
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
842 |
return NULL; |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
843 |
} |
1 | 844 |
|
845 |
void static_stub_Relocation::clear_inline_cache() { |
|
846 |
// Call stub is only used when calling the interpreted code. |
|
847 |
// It does not really need to be cleared, except that we want to clean out the methodoop. |
|
848 |
CompiledStaticCall::set_stub_to_clean(this); |
|
849 |
} |
|
850 |
||
851 |
||
852 |
void external_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) { |
|
853 |
address target = _target; |
|
854 |
if (target == NULL) { |
|
855 |
// An absolute embedded reference to an external location, |
|
856 |
// which means there is nothing to fix here. |
|
857 |
return; |
|
858 |
} |
|
859 |
// Probably this reference is absolute, not relative, so the |
|
860 |
// following is probably a no-op. |
|
861 |
assert(src->section_index_of(target) == CodeBuffer::SECT_NONE, "sanity"); |
|
862 |
set_value(target); |
|
863 |
} |
|
864 |
||
865 |
||
866 |
address external_word_Relocation::target() { |
|
867 |
address target = _target; |
|
868 |
if (target == NULL) { |
|
869 |
target = pd_get_address_from_code(); |
|
870 |
} |
|
871 |
return target; |
|
872 |
} |
|
873 |
||
874 |
||
875 |
void internal_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) { |
|
876 |
address target = _target; |
|
877 |
if (target == NULL) { |
|
24952
953481cd953d
8044538: assert(which != imm_operand) failed: instruction is not a movq reg, imm64
thartmann
parents:
24424
diff
changeset
|
878 |
target = new_addr_for(this->target(), src, dest); |
1 | 879 |
} |
880 |
set_value(target); |
|
881 |
} |
|
882 |
||
883 |
||
884 |
address internal_word_Relocation::target() { |
|
885 |
address target = _target; |
|
886 |
if (target == NULL) { |
|
24952
953481cd953d
8044538: assert(which != imm_operand) failed: instruction is not a movq reg, imm64
thartmann
parents:
24424
diff
changeset
|
887 |
if (addr_in_const()) { |
953481cd953d
8044538: assert(which != imm_operand) failed: instruction is not a movq reg, imm64
thartmann
parents:
24424
diff
changeset
|
888 |
target = *(address*)addr(); |
953481cd953d
8044538: assert(which != imm_operand) failed: instruction is not a movq reg, imm64
thartmann
parents:
24424
diff
changeset
|
889 |
} else { |
953481cd953d
8044538: assert(which != imm_operand) failed: instruction is not a movq reg, imm64
thartmann
parents:
24424
diff
changeset
|
890 |
target = pd_get_address_from_code(); |
953481cd953d
8044538: assert(which != imm_operand) failed: instruction is not a movq reg, imm64
thartmann
parents:
24424
diff
changeset
|
891 |
} |
1 | 892 |
} |
893 |
return target; |
|
894 |
} |
|
895 |
||
896 |
//--------------------------------------------------------------------------------- |
|
897 |
// Non-product code |
|
898 |
||
899 |
#ifndef PRODUCT |
|
900 |
||
901 |
static const char* reloc_type_string(relocInfo::relocType t) { |
|
902 |
switch (t) { |
|
903 |
#define EACH_CASE(name) \ |
|
904 |
case relocInfo::name##_type: \ |
|
905 |
return #name; |
|
906 |
||
907 |
APPLY_TO_RELOCATIONS(EACH_CASE); |
|
908 |
#undef EACH_CASE |
|
909 |
||
910 |
case relocInfo::none: |
|
911 |
return "none"; |
|
912 |
case relocInfo::data_prefix_tag: |
|
913 |
return "prefix"; |
|
914 |
default: |
|
915 |
return "UNKNOWN RELOC TYPE"; |
|
916 |
} |
|
917 |
} |
|
918 |
||
919 |
||
920 |
void RelocIterator::print_current() { |
|
921 |
if (!has_current()) { |
|
922 |
tty->print_cr("(no relocs)"); |
|
923 |
return; |
|
924 |
} |
|
7427 | 925 |
tty->print("relocInfo@" INTPTR_FORMAT " [type=%d(%s) addr=" INTPTR_FORMAT " offset=%d", |
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
24952
diff
changeset
|
926 |
p2i(_current), type(), reloc_type_string((relocInfo::relocType) type()), p2i(_addr), _current->addr_offset()); |
1 | 927 |
if (current()->format() != 0) |
928 |
tty->print(" format=%d", current()->format()); |
|
929 |
if (datalen() == 1) { |
|
930 |
tty->print(" data=%d", data()[0]); |
|
931 |
} else if (datalen() > 0) { |
|
932 |
tty->print(" data={"); |
|
933 |
for (int i = 0; i < datalen(); i++) { |
|
934 |
tty->print("%04x", data()[i] & 0xFFFF); |
|
935 |
} |
|
936 |
tty->print("}"); |
|
937 |
} |
|
938 |
tty->print("]"); |
|
939 |
switch (type()) { |
|
940 |
case relocInfo::oop_type: |
|
941 |
{ |
|
942 |
oop_Relocation* r = oop_reloc(); |
|
943 |
oop* oop_addr = NULL; |
|
944 |
oop raw_oop = NULL; |
|
945 |
oop oop_value = NULL; |
|
946 |
if (code() != NULL || r->oop_is_immediate()) { |
|
947 |
oop_addr = r->oop_addr(); |
|
948 |
raw_oop = *oop_addr; |
|
949 |
oop_value = r->oop_value(); |
|
950 |
} |
|
951 |
tty->print(" | [oop_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT " offset=%d]", |
|
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
24952
diff
changeset
|
952 |
p2i(oop_addr), p2i(raw_oop), r->offset()); |
1 | 953 |
// Do not print the oop by default--we want this routine to |
954 |
// work even during GC or other inconvenient times. |
|
955 |
if (WizardMode && oop_value != NULL) { |
|
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
24952
diff
changeset
|
956 |
tty->print("oop_value=" INTPTR_FORMAT ": ", p2i(oop_value)); |
1 | 957 |
oop_value->print_value_on(tty); |
958 |
} |
|
959 |
break; |
|
960 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
961 |
case relocInfo::metadata_type: |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
962 |
{ |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
963 |
metadata_Relocation* r = metadata_reloc(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
964 |
Metadata** metadata_addr = NULL; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
965 |
Metadata* raw_metadata = NULL; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
966 |
Metadata* metadata_value = NULL; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
967 |
if (code() != NULL || r->metadata_is_immediate()) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
968 |
metadata_addr = r->metadata_addr(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
969 |
raw_metadata = *metadata_addr; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
970 |
metadata_value = r->metadata_value(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
971 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
972 |
tty->print(" | [metadata_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT " offset=%d]", |
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
24952
diff
changeset
|
973 |
p2i(metadata_addr), p2i(raw_metadata), r->offset()); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
974 |
if (metadata_value != NULL) { |
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
24952
diff
changeset
|
975 |
tty->print("metadata_value=" INTPTR_FORMAT ": ", p2i(metadata_value)); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
976 |
metadata_value->print_value_on(tty); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
977 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
978 |
break; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
979 |
} |
1 | 980 |
case relocInfo::external_word_type: |
981 |
case relocInfo::internal_word_type: |
|
982 |
case relocInfo::section_word_type: |
|
983 |
{ |
|
984 |
DataRelocation* r = (DataRelocation*) reloc(); |
|
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
24952
diff
changeset
|
985 |
tty->print(" | [target=" INTPTR_FORMAT "]", p2i(r->value())); //value==target |
1 | 986 |
break; |
987 |
} |
|
988 |
case relocInfo::static_call_type: |
|
989 |
case relocInfo::runtime_call_type: |
|
990 |
{ |
|
991 |
CallRelocation* r = (CallRelocation*) reloc(); |
|
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
24952
diff
changeset
|
992 |
tty->print(" | [destination=" INTPTR_FORMAT "]", p2i(r->destination())); |
1 | 993 |
break; |
994 |
} |
|
995 |
case relocInfo::virtual_call_type: |
|
996 |
{ |
|
997 |
virtual_call_Relocation* r = (virtual_call_Relocation*) reloc(); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
998 |
tty->print(" | [destination=" INTPTR_FORMAT " cached_value=" INTPTR_FORMAT "]", |
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
24952
diff
changeset
|
999 |
p2i(r->destination()), p2i(r->cached_value())); |
1 | 1000 |
break; |
1001 |
} |
|
1002 |
case relocInfo::static_stub_type: |
|
1003 |
{ |
|
1004 |
static_stub_Relocation* r = (static_stub_Relocation*) reloc(); |
|
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
24952
diff
changeset
|
1005 |
tty->print(" | [static_call=" INTPTR_FORMAT "]", p2i(r->static_call())); |
1 | 1006 |
break; |
1007 |
} |
|
22813
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
1008 |
case relocInfo::trampoline_stub_type: |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
1009 |
{ |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
1010 |
trampoline_stub_Relocation* r = (trampoline_stub_Relocation*) reloc(); |
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
24952
diff
changeset
|
1011 |
tty->print(" | [trampoline owner=" INTPTR_FORMAT "]", p2i(r->owner())); |
22813
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
1012 |
break; |
422557569a6b
8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents:
18446
diff
changeset
|
1013 |
} |
1 | 1014 |
} |
1015 |
tty->cr(); |
|
1016 |
} |
|
1017 |
||
1018 |
||
1019 |
void RelocIterator::print() { |
|
1020 |
RelocIterator save_this = (*this); |
|
1021 |
relocInfo* scan = _current; |
|
1022 |
if (!has_current()) scan += 1; // nothing to scan here! |
|
1023 |
||
1024 |
bool skip_next = has_current(); |
|
1025 |
bool got_next; |
|
1026 |
while (true) { |
|
1027 |
got_next = (skip_next || next()); |
|
1028 |
skip_next = false; |
|
1029 |
||
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
24952
diff
changeset
|
1030 |
tty->print(" @" INTPTR_FORMAT ": ", p2i(scan)); |
1 | 1031 |
relocInfo* newscan = _current+1; |
1032 |
if (!has_current()) newscan -= 1; // nothing to scan here! |
|
1033 |
while (scan < newscan) { |
|
1034 |
tty->print("%04x", *(short*)scan & 0xFFFF); |
|
1035 |
scan++; |
|
1036 |
} |
|
1037 |
tty->cr(); |
|
1038 |
||
1039 |
if (!got_next) break; |
|
1040 |
print_current(); |
|
1041 |
} |
|
1042 |
||
1043 |
(*this) = save_this; |
|
1044 |
} |
|
1045 |
||
1046 |
// For the debugger: |
|
1047 |
extern "C" |
|
5686
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1
diff
changeset
|
1048 |
void print_blob_locs(nmethod* nm) { |
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1
diff
changeset
|
1049 |
nm->print(); |
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1
diff
changeset
|
1050 |
RelocIterator iter(nm); |
1 | 1051 |
iter.print(); |
1052 |
} |
|
1053 |
extern "C" |
|
1054 |
void print_buf_locs(CodeBuffer* cb) { |
|
1055 |
FlagSetting fs(PrintRelocations, true); |
|
1056 |
cb->print(); |
|
1057 |
} |
|
1058 |
#endif // !PRODUCT |