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