annotate src/share/vm/code/relocInfo.cpp @ 12860:a0cf41abef5d

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