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