src/share/vm/code/relocInfo.cpp

Thu, 20 May 2010 06:34:23 -0700

author
twisti
date
Thu, 20 May 2010 06:34:23 -0700
changeset 1918
1a5913bf5e19
parent 435
a61af66fc99e
child 1934
e9ff18c4ace7
permissions
-rw-r--r--

6951083: oops and relocations should part of nmethod not CodeBlob
Summary: This moves the oops from Codeblob to nmethod.
Reviewed-by: kvn, never

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

mercurial