src/share/vm/code/relocInfo.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial