annotate src/share/vm/code/relocInfo.cpp @ 9437:115188e14c15

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