annotate src/share/vm/code/relocInfo.cpp @ 2222:d673ef06fe96

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