relocInfo.cpp revision 3883:cd3d6a6b95d9
11573Srgrimes/* 21573Srgrimes * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 31573Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 41573Srgrimes * 51573Srgrimes * This code is free software; you can redistribute it and/or modify it 61573Srgrimes * under the terms of the GNU General Public License version 2 only, as 71573Srgrimes * published by the Free Software Foundation. 81573Srgrimes * 91573Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT 101573Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 111573Srgrimes * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 121573Srgrimes * version 2 for more details (a copy is included in the LICENSE file that 131573Srgrimes * accompanied this code). 141573Srgrimes * 151573Srgrimes * You should have received a copy of the GNU General Public License version 161573Srgrimes * 2 along with this work; if not, write to the Free Software Foundation, 171573Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 181573Srgrimes * 191573Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 201573Srgrimes * or visit www.oracle.com if you need additional information or have any 211573Srgrimes * questions. 221573Srgrimes * 231573Srgrimes */ 241573Srgrimes 251573Srgrimes#include "precompiled.hpp" 261573Srgrimes#include "code/codeCache.hpp" 271573Srgrimes#include "code/compiledIC.hpp" 281573Srgrimes#include "code/nmethod.hpp" 291573Srgrimes#include "code/relocInfo.hpp" 301573Srgrimes#include "memory/resourceArea.hpp" 311573Srgrimes#include "runtime/stubCodeGenerator.hpp" 321573Srgrimes#include "utilities/copy.hpp" 331573Srgrimes 341573Srgrimes 351573Srgrimesconst RelocationHolder RelocationHolder::none; // its type is relocInfo::none 361573Srgrimes 371573Srgrimes 381573Srgrimes// Implementation of relocInfo 391573Srgrimes 401573Srgrimes#ifdef ASSERT 411573SrgrimesrelocInfo::relocInfo(relocType t, int off, int f) { 421573Srgrimes assert(t != data_prefix_tag, "cannot build a prefix this way"); 431573Srgrimes assert((t & type_mask) == t, "wrong type"); 441573Srgrimes assert((f & format_mask) == f, "wrong format"); 451573Srgrimes assert(off >= 0 && off < offset_limit(), "offset out off bounds"); 461573Srgrimes assert((off & (offset_unit-1)) == 0, "misaligned offset"); 471573Srgrimes (*this) = relocInfo(t, RAW_BITS, off, f); 481573Srgrimes} 491573Srgrimes#endif 501573Srgrimes 511573Srgrimesvoid relocInfo::initialize(CodeSection* dest, Relocation* reloc) { 521573Srgrimes relocInfo* data = this+1; // here's where the data might go 531573Srgrimes dest->set_locs_end(data); // sync end: the next call may read dest.locs_end 541573Srgrimes reloc->pack_data_to(dest); // maybe write data into locs, advancing locs_end 551573Srgrimes relocInfo* data_limit = dest->locs_end(); 562029Sdg if (data_limit > data) { 571573Srgrimes relocInfo suffix = (*this); 581573Srgrimes data_limit = this->finish_prefix((short*) data_limit); 591573Srgrimes // Finish up with the suffix. (Hack note: pack_data_to might edit this.) 601573Srgrimes *data_limit = suffix; 611573Srgrimes dest->set_locs_end(data_limit+1); 621573Srgrimes } 631573Srgrimes} 641573Srgrimes 651573SrgrimesrelocInfo* relocInfo::finish_prefix(short* prefix_limit) { 661573Srgrimes assert(sizeof(relocInfo) == sizeof(short), "change this code"); 671573Srgrimes short* p = (short*)(this+1); 6812682Speter assert(prefix_limit >= p, "must be a valid span of data"); 691573Srgrimes int plen = prefix_limit - p; 701573Srgrimes if (plen == 0) { 711573Srgrimes debug_only(_value = 0xFFFF); 721573Srgrimes return this; // no data: remove self completely 731573Srgrimes } 741573Srgrimes if (plen == 1 && fits_into_immediate(p[0])) { 751573Srgrimes (*this) = immediate_relocInfo(p[0]); // move data inside self 761573Srgrimes return this+1; 771573Srgrimes } 781573Srgrimes // cannot compact, so just update the count and return the limit pointer 791573Srgrimes (*this) = prefix_relocInfo(plen); // write new datalen 801573Srgrimes assert(data() + datalen() == prefix_limit, "pointers must line up"); 811603Srgrimes return (relocInfo*)prefix_limit; 821603Srgrimes} 831603Srgrimes 841603Srgrimes 851603Srgrimesvoid relocInfo::set_type(relocType t) { 861573Srgrimes int old_offset = addr_offset(); 871573Srgrimes int old_format = format(); 881573Srgrimes (*this) = relocInfo(t, old_offset, old_format); 891573Srgrimes assert(type()==(int)t, "sanity check"); 901573Srgrimes assert(addr_offset()==old_offset, "sanity check"); 911573Srgrimes assert(format()==old_format, "sanity check"); 921573Srgrimes} 931573Srgrimes 941573Srgrimes 951573Srgrimesvoid relocInfo::set_format(int f) { 961573Srgrimes int old_offset = addr_offset(); 971573Srgrimes assert((f & format_mask) == f, "wrong format"); 981573Srgrimes _value = (_value & ~(format_mask << offset_width)) | (f << offset_width); 991573Srgrimes assert(addr_offset()==old_offset, "sanity check"); 1001573Srgrimes} 1011573Srgrimes 1021573Srgrimes 1031573Srgrimesvoid relocInfo::change_reloc_info_for_address(RelocIterator *itr, address pc, relocType old_type, relocType new_type) { 1041573Srgrimes bool found = false; 1051573Srgrimes while (itr->next() && !found) { 1061573Srgrimes if (itr->addr() == pc) { 1071573Srgrimes assert(itr->type()==old_type, "wrong relocInfo type found"); 1081573Srgrimes itr->current()->set_type(new_type); 1091573Srgrimes found=true; 11014523Shsu } 1111573Srgrimes } 1121573Srgrimes assert(found, "no relocInfo found for pc"); 1131573Srgrimes} 1141573Srgrimes 1151573Srgrimes 1161573Srgrimesvoid relocInfo::remove_reloc_info_for_address(RelocIterator *itr, address pc, relocType old_type) { 1171573Srgrimes change_reloc_info_for_address(itr, pc, old_type, none); 1181573Srgrimes} 1191573Srgrimes 1208870Srgrimes 1211573Srgrimes// ---------------------------------------------------------------------------------------------------- 1221573Srgrimes// Implementation of RelocIterator 1231573Srgrimes 1241573Srgrimesvoid RelocIterator::initialize(nmethod* nm, address begin, address limit) { 1251573Srgrimes initialize_misc(); 1261573Srgrimes 1271573Srgrimes if (nm == NULL && begin != NULL) { 1281573Srgrimes // allow nmethod to be deduced from beginning address 1291573Srgrimes CodeBlob* cb = CodeCache::find_blob(begin); 1301573Srgrimes nm = cb->as_nmethod_or_null(); 1311573Srgrimes } 1321573Srgrimes assert(nm != NULL, "must be able to deduce nmethod from other arguments"); 1331573Srgrimes 1341573Srgrimes _code = nm; 1351573Srgrimes _current = nm->relocation_begin() - 1; 1361573Srgrimes _end = nm->relocation_end(); 1371573Srgrimes _addr = nm->content_begin(); 1381573Srgrimes 1391573Srgrimes // Initialize code sections. 1401573Srgrimes _section_start[CodeBuffer::SECT_CONSTS] = nm->consts_begin(); 1411573Srgrimes _section_start[CodeBuffer::SECT_INSTS ] = nm->insts_begin() ; 1421573Srgrimes _section_start[CodeBuffer::SECT_STUBS ] = nm->stub_begin() ; 1431573Srgrimes 1441573Srgrimes _section_end [CodeBuffer::SECT_CONSTS] = nm->consts_end() ; 1451573Srgrimes _section_end [CodeBuffer::SECT_INSTS ] = nm->insts_end() ; 1461573Srgrimes _section_end [CodeBuffer::SECT_STUBS ] = nm->stub_end() ; 1471573Srgrimes 1481573Srgrimes assert(!has_current(), "just checking"); 1491573Srgrimes assert(begin == NULL || begin >= nm->code_begin(), "in bounds"); 1501573Srgrimes assert(limit == NULL || limit <= nm->code_end(), "in bounds"); 1511573Srgrimes set_limits(begin, limit); 1521573Srgrimes} 1531573Srgrimes 1541573Srgrimes 1551573SrgrimesRelocIterator::RelocIterator(CodeSection* cs, address begin, address limit) { 1561573Srgrimes initialize_misc(); 1571573Srgrimes 1588870Srgrimes _current = cs->locs_start()-1; 1591573Srgrimes _end = cs->locs_end(); 1601573Srgrimes _addr = cs->start(); 1611573Srgrimes _code = NULL; // Not cb->blob(); 16213156Speter 16313156Speter CodeBuffer* cb = cs->outer(); 1641573Srgrimes assert((int) SECT_LIMIT == CodeBuffer::SECT_LIMIT, "my copy must be equal"); 1651573Srgrimes for (int n = (int) CodeBuffer::SECT_FIRST; n < (int) CodeBuffer::SECT_LIMIT; n++) { 1661573Srgrimes CodeSection* cs = cb->code_section(n); 1671573Srgrimes _section_start[n] = cs->start(); 1681573Srgrimes _section_end [n] = cs->end(); 1691573Srgrimes } 1701573Srgrimes 1711573Srgrimes assert(!has_current(), "just checking"); 1721573Srgrimes 1731573Srgrimes assert(begin == NULL || begin >= cs->start(), "in bounds"); 1741573Srgrimes assert(limit == NULL || limit <= cs->end(), "in bounds"); 1758870Srgrimes set_limits(begin, limit); 1761573Srgrimes} 1771573Srgrimes 1781573Srgrimes 1791573Srgrimesenum { indexCardSize = 128 }; 1801573Srgrimesstruct RelocIndexEntry { 1811573Srgrimes jint addr_offset; // offset from header_end of an addr() 1821573Srgrimes jint reloc_offset; // offset from header_end of a relocInfo (prefix) 1831573Srgrimes}; 1841573Srgrimes 1851573Srgrimes 1861573Srgrimesbool RelocIterator::addr_in_const() const { 1871573Srgrimes const int n = CodeBuffer::SECT_CONSTS; 1888870Srgrimes return section_start(n) <= addr() && addr() < section_end(n); 1891573Srgrimes} 1901573Srgrimes 1911573Srgrimes 1921573Srgrimesstatic inline int num_cards(int code_size) { 1931573Srgrimes return (code_size-1) / indexCardSize; 1941573Srgrimes} 1951573Srgrimes 1961573Srgrimes 1971573Srgrimesint RelocIterator::locs_and_index_size(int code_size, int locs_size) { 1981573Srgrimes if (!UseRelocIndex) return locs_size; // no index 1991573Srgrimes code_size = round_to(code_size, oopSize); 2001573Srgrimes locs_size = round_to(locs_size, oopSize); 2011573Srgrimes int index_size = num_cards(code_size) * sizeof(RelocIndexEntry); 2021573Srgrimes // format of indexed relocs: 2031573Srgrimes // relocation_begin: relocInfo ... 2041573Srgrimes // index: (addr,reloc#) ... 2051573Srgrimes // indexSize :relocation_end 2061573Srgrimes return locs_size + index_size + BytesPerInt; 2071573Srgrimes} 2081573Srgrimes 2091573Srgrimes 2101573Srgrimesvoid RelocIterator::create_index(relocInfo* dest_begin, int dest_count, relocInfo* dest_end) { 2111573Srgrimes address relocation_begin = (address)dest_begin; 2121573Srgrimes address relocation_end = (address)dest_end; 2138870Srgrimes int total_size = relocation_end - relocation_begin; 2141573Srgrimes int locs_size = dest_count * sizeof(relocInfo); 2151573Srgrimes if (!UseRelocIndex) { 2161573Srgrimes Copy::fill_to_bytes(relocation_begin + locs_size, total_size-locs_size, 0); 2171573Srgrimes return; 2181573Srgrimes } 2191573Srgrimes int index_size = total_size - locs_size - BytesPerInt; // find out how much space is left 2201573Srgrimes int ncards = index_size / sizeof(RelocIndexEntry); 2211573Srgrimes assert(total_size == locs_size + index_size + BytesPerInt, "checkin'"); 2221573Srgrimes assert(index_size >= 0 && index_size % sizeof(RelocIndexEntry) == 0, "checkin'"); 2231573Srgrimes jint* index_size_addr = (jint*)relocation_end - 1; 2241573Srgrimes 2251573Srgrimes assert(sizeof(jint) == BytesPerInt, "change this code"); 2261573Srgrimes 2271573Srgrimes *index_size_addr = index_size; 2281573Srgrimes if (index_size != 0) { 2291573Srgrimes assert(index_size > 0, "checkin'"); 2301573Srgrimes 2311573Srgrimes RelocIndexEntry* index = (RelocIndexEntry *)(relocation_begin + locs_size); 2321573Srgrimes assert(index == (RelocIndexEntry*)index_size_addr - ncards, "checkin'"); 2331573Srgrimes 2341573Srgrimes // walk over the relocations, and fill in index entries as we go 2351573Srgrimes RelocIterator iter; 2361573Srgrimes const address initial_addr = NULL; 2371573Srgrimes relocInfo* const initial_current = dest_begin - 1; // biased by -1 like elsewhere 2381573Srgrimes 2391573Srgrimes iter._code = NULL; 2401573Srgrimes iter._addr = initial_addr; 2411573Srgrimes iter._limit = (address)(intptr_t)(ncards * indexCardSize); 2421573Srgrimes iter._current = initial_current; 2431573Srgrimes iter._end = dest_begin + dest_count; 2441573Srgrimes 2451573Srgrimes int i = 0; 2461573Srgrimes address next_card_addr = (address)indexCardSize; 2471573Srgrimes int addr_offset = 0; 2481573Srgrimes int reloc_offset = 0; 2491573Srgrimes while (true) { 2501573Srgrimes // Checkpoint the iterator before advancing it. 2511573Srgrimes addr_offset = iter._addr - initial_addr; 2521573Srgrimes reloc_offset = iter._current - initial_current; 2531573Srgrimes if (!iter.next()) break; 2541573Srgrimes while (iter.addr() >= next_card_addr) { 2551573Srgrimes index[i].addr_offset = addr_offset; 2561573Srgrimes index[i].reloc_offset = reloc_offset; 2571573Srgrimes i++; 2581573Srgrimes next_card_addr += indexCardSize; 2591573Srgrimes } 2601573Srgrimes } 2611573Srgrimes while (i < ncards) { 2621573Srgrimes index[i].addr_offset = addr_offset; 2631573Srgrimes index[i].reloc_offset = reloc_offset; 2641573Srgrimes i++; 2651573Srgrimes } 2661573Srgrimes } 2671573Srgrimes} 2681573Srgrimes 2691573Srgrimes 2701573Srgrimesvoid RelocIterator::set_limits(address begin, address limit) { 2718870Srgrimes int index_size = 0; 2721573Srgrimes if (UseRelocIndex && _code != NULL) { 2731573Srgrimes index_size = ((jint*)_end)[-1]; 2741573Srgrimes _end = (relocInfo*)( (address)_end - index_size - BytesPerInt ); 2751573Srgrimes } 2761573Srgrimes 2771573Srgrimes _limit = limit; 2781573Srgrimes 2791573Srgrimes // the limit affects this next stuff: 2801573Srgrimes if (begin != NULL) { 2811573Srgrimes#ifdef ASSERT 2821573Srgrimes // In ASSERT mode we do not actually use the index, but simply 28316158Sphk // check that its contents would have led us to the right answer. 2841573Srgrimes address addrCheck = _addr; 2851573Srgrimes relocInfo* infoCheck = _current; 2861573Srgrimes#endif // ASSERT 2871573Srgrimes if (index_size > 0) { 2881573Srgrimes // skip ahead 2891573Srgrimes RelocIndexEntry* index = (RelocIndexEntry*)_end; 2901573Srgrimes RelocIndexEntry* index_limit = (RelocIndexEntry*)((address)index + index_size); 29116158Sphk assert(_addr == _code->code_begin(), "_addr must be unadjusted"); 2921573Srgrimes int card = (begin - _addr) / indexCardSize; 2931573Srgrimes if (card > 0) { 2941573Srgrimes if (index+card-1 < index_limit) index += card-1; 2951573Srgrimes else index = index_limit - 1; 2961573Srgrimes#ifdef ASSERT 2971573Srgrimes addrCheck = _addr + index->addr_offset; 2981573Srgrimes infoCheck = _current + index->reloc_offset; 2991573Srgrimes#else 3001573Srgrimes // Advance the iterator immediately to the last valid state 3011573Srgrimes // for the previous card. Calling "next" will then advance 3021573Srgrimes // it to the first item on the required card. 3031573Srgrimes _addr += index->addr_offset; 3041573Srgrimes _current += index->reloc_offset; 3051573Srgrimes#endif // ASSERT 3061573Srgrimes } 3071573Srgrimes } 3081573Srgrimes 3091573Srgrimes relocInfo* backup; 3101573Srgrimes address backup_addr; 3111573Srgrimes while (true) { 3121573Srgrimes backup = _current; 3131573Srgrimes backup_addr = _addr; 3141573Srgrimes#ifdef ASSERT 3151573Srgrimes if (backup == infoCheck) { 3161573Srgrimes assert(backup_addr == addrCheck, "must match"); addrCheck = NULL; infoCheck = NULL; 3171573Srgrimes } else { 3181573Srgrimes assert(addrCheck == NULL || backup_addr <= addrCheck, "must not pass addrCheck"); 3191573Srgrimes } 3201573Srgrimes#endif // ASSERT 3211573Srgrimes if (!next() || addr() >= begin) break; 3221573Srgrimes } 3231573Srgrimes assert(addrCheck == NULL || addrCheck == backup_addr, "must have matched addrCheck"); 3241573Srgrimes assert(infoCheck == NULL || infoCheck == backup, "must have matched infoCheck"); 3251573Srgrimes // At this point, either we are at the first matching record, 3261573Srgrimes // or else there is no such record, and !has_current(). 3271573Srgrimes // In either case, revert to the immediatly preceding state. 3281573Srgrimes _current = backup; 3291573Srgrimes _addr = backup_addr; 3301573Srgrimes set_has_current(false); 3311573Srgrimes } 3321573Srgrimes} 3331573Srgrimes 3341573Srgrimes 3351573Srgrimesvoid RelocIterator::set_limit(address limit) { 3361573Srgrimes address code_end = (address)code() + code()->size(); 3371573Srgrimes assert(limit == NULL || limit <= code_end, "in bounds"); 3381573Srgrimes _limit = limit; 3391573Srgrimes} 3401573Srgrimes 3411573Srgrimes 3421573Srgrimesvoid PatchingRelocIterator:: prepass() { 3431573Srgrimes // turn breakpoints off during patching 3441573Srgrimes _init_state = (*this); // save cursor 3451573Srgrimes while (next()) { 3461573Srgrimes if (type() == relocInfo::breakpoint_type) { 3471573Srgrimes breakpoint_reloc()->set_active(false); 3481573Srgrimes } 3491573Srgrimes } 3501573Srgrimes (RelocIterator&)(*this) = _init_state; // reset cursor for client 3511573Srgrimes} 3521573Srgrimes 3531573Srgrimes 3541573Srgrimesvoid PatchingRelocIterator:: postpass() { 3551573Srgrimes // turn breakpoints back on after patching 3561573Srgrimes (RelocIterator&)(*this) = _init_state; // reset cursor again 3571573Srgrimes while (next()) { 3581573Srgrimes if (type() == relocInfo::breakpoint_type) { 3591573Srgrimes breakpoint_Relocation* bpt = breakpoint_reloc(); 3601573Srgrimes bpt->set_active(bpt->enabled()); 3611573Srgrimes } 3621573Srgrimes } 3631573Srgrimes} 3641573Srgrimes 3651573Srgrimes 3661573Srgrimes// All the strange bit-encodings are in here. 36712682Speter// The idea is to encode relocation data which are small integers 3681573Srgrimes// very efficiently (a single extra halfword). Larger chunks of 3691573Srgrimes// relocation data need a halfword header to hold their size. 3701573Srgrimesvoid RelocIterator::advance_over_prefix() { 3711573Srgrimes if (_current->is_datalen()) { 3721573Srgrimes _data = (short*) _current->data(); 3731573Srgrimes _datalen = _current->datalen(); 37412682Speter _current += _datalen + 1; // skip the embedded data & header 3751573Srgrimes } else { 3761573Srgrimes _databuf = _current->immediate(); 3771573Srgrimes _data = &_databuf; 3781573Srgrimes _datalen = 1; 37912682Speter _current++; // skip the header 38012682Speter } 3811573Srgrimes // The client will see the following relocInfo, whatever that is. 3821573Srgrimes // It is the reloc to which the preceding data applies. 3831573Srgrimes} 3841573Srgrimes 3851573Srgrimes 3861573Srgrimesvoid RelocIterator::initialize_misc() { 3871573Srgrimes set_has_current(false); 38812885Speter for (int i = (int) CodeBuffer::SECT_FIRST; i < (int) CodeBuffer::SECT_LIMIT; i++) { 3891573Srgrimes _section_start[i] = NULL; // these will be lazily computed, if needed 3901573Srgrimes _section_end [i] = NULL; 39112885Speter } 39212885Speter} 39312885Speter 39412885Speter 3951573SrgrimesRelocation* RelocIterator::reloc() { 3961573Srgrimes // (take the "switch" out-of-line) 3971573Srgrimes relocInfo::relocType t = type(); 3981573Srgrimes if (false) {} 3991573Srgrimes #define EACH_TYPE(name) \ 4008870Srgrimes else if (t == relocInfo::name##_type) { \ 4011573Srgrimes return name##_reloc(); \ 4021573Srgrimes } 4031573Srgrimes APPLY_TO_RELOCATIONS(EACH_TYPE); 4041573Srgrimes #undef EACH_TYPE 4051573Srgrimes assert(t == relocInfo::none, "must be padding"); 4068870Srgrimes return new(_rh) Relocation(); 4071573Srgrimes} 4081573Srgrimes 4091573Srgrimes 4101573Srgrimes//////// Methods for flyweight Relocation types 41112885Speter 41212885Speter 41312885SpeterRelocationHolder RelocationHolder::plus(int offset) const { 41412885Speter if (offset != 0) { 4151573Srgrimes switch (type()) { 41615533Sphk case relocInfo::none: 4171573Srgrimes break; 4181573Srgrimes case relocInfo::oop_type: 41915533Sphk { 4201573Srgrimes oop_Relocation* r = (oop_Relocation*)reloc(); 42112885Speter return oop_Relocation::spec(r->oop_index(), r->offset() + offset); 42212885Speter } 42312885Speter case relocInfo::metadata_type: 42412885Speter { 42512682Speter metadata_Relocation* r = (metadata_Relocation*)reloc(); 42615533Sphk return metadata_Relocation::spec(r->metadata_index(), r->offset() + offset); 42712682Speter } 42812682Speter default: 42912682Speter ShouldNotReachHere(); 43012885Speter } 43112885Speter } 43212682Speter return (*this); 43312682Speter} 43412682Speter 43512885Speter 43612885Spetervoid Relocation::guarantee_size() { 43712885Speter guarantee(false, "Make _relocbuf bigger!"); 43812885Speter} 43912885Speter 44012885Speter // some relocations can compute their own values 44112885Speteraddress Relocation::value() { 44212885Speter ShouldNotReachHere(); 44312682Speter return NULL; 4441573Srgrimes} 4451573Srgrimes 4461573Srgrimes 4471573Srgrimesvoid Relocation::set_value(address x) { 44812885Speter ShouldNotReachHere(); 44912885Speter} 45012885Speter 45112885Speter 45212885SpeterRelocationHolder Relocation::spec_simple(relocInfo::relocType rtype) { 4531573Srgrimes if (rtype == relocInfo::none) return RelocationHolder::none; 45412682Speter relocInfo ri = relocInfo(rtype, 0); 45512885Speter RelocIterator itr; 45612885Speter itr.set_current(ri); 45715533Sphk itr.reloc(); 45812885Speter return itr._rh; 45912885Speter} 46012682Speter 46115533Sphkint32_t Relocation::runtime_address_to_index(address runtime_address) { 46215533Sphk assert(!is_reloc_index((intptr_t)runtime_address), "must not look like an index"); 46312682Speter 46412682Speter if (runtime_address == NULL) return 0; 46512682Speter 46612885Speter StubCodeDesc* p = StubCodeDesc::desc_for(runtime_address); 46712885Speter if (p != NULL && p->begin() == runtime_address) { 46815533Sphk assert(is_reloc_index(p->index()), "there must not be too many stubs"); 46912885Speter return (int32_t)p->index(); 47012885Speter } else { 47112682Speter // Known "miscellaneous" non-stub pointers: 47215533Sphk // os::get_polling_page(), SafepointSynchronize::address_of_state() 47312885Speter if (PrintRelocations) { 47412885Speter tty->print_cr("random unregistered address in relocInfo: " INTPTR_FORMAT, runtime_address); 4751573Srgrimes } 47612885Speter#ifndef _LP64 47712885Speter return (int32_t) (intptr_t)runtime_address; 47812885Speter#else 47912682Speter // didn't fit return non-index 48012682Speter return -1; 48112682Speter#endif /* _LP64 */ 48212885Speter } 48312885Speter} 48412885Speter 48512885Speter 48612885Speteraddress Relocation::index_to_runtime_address(int32_t index) { 48712885Speter if (index == 0) return NULL; 48812885Speter 4891573Srgrimes if (is_reloc_index(index)) { 4901573Srgrimes StubCodeDesc* p = StubCodeDesc::desc_for_index(index); 4911573Srgrimes assert(p != NULL, "there must be a stub for this index"); 4921573Srgrimes return p->begin(); 4931573Srgrimes } else { 4941573Srgrimes#ifndef _LP64 4951573Srgrimes // this only works on 32bit machines 4961573Srgrimes return (address) ((intptr_t) index); 4971573Srgrimes#else 4981573Srgrimes fatal("Relocation::index_to_runtime_address, int32_t not pointer sized"); 4991573Srgrimes return NULL; 5001573Srgrimes#endif /* _LP64 */ 5011573Srgrimes } 5021573Srgrimes} 5031573Srgrimes 50412682Speteraddress Relocation::old_addr_for(address newa, 5051573Srgrimes const CodeBuffer* src, CodeBuffer* dest) { 50612682Speter int sect = dest->section_index_of(newa); 50712682Speter guarantee(sect != CodeBuffer::SECT_NONE, "lost track of this address"); 5081573Srgrimes address ostart = src->code_section(sect)->start(); 50912885Speter address nstart = dest->code_section(sect)->start(); 51012885Speter return ostart + (newa - nstart); 51112682Speter} 51212885Speter 5131573Srgrimesaddress Relocation::new_addr_for(address olda, 51412885Speter const CodeBuffer* src, CodeBuffer* dest) { 51512885Speter debug_only(const CodeBuffer* src0 = src); 51612885Speter int sect = CodeBuffer::SECT_NONE; 51712885Speter // Look for olda in the source buffer, and all previous incarnations 51812885Speter // if the source buffer has been expanded. 51912885Speter for (; src != NULL; src = src->before_expand()) { 52012885Speter sect = src->section_index_of(olda); 52112885Speter if (sect != CodeBuffer::SECT_NONE) break; 52212682Speter } 52312682Speter guarantee(sect != CodeBuffer::SECT_NONE, "lost track of this address"); 52412682Speter address ostart = src->code_section(sect)->start(); 52512885Speter address nstart = dest->code_section(sect)->start(); 52612885Speter return nstart + (olda - ostart); 52712682Speter} 52812885Speter 52912885Spetervoid Relocation::normalize_address(address& addr, const CodeSection* dest, bool allow_other_sections) { 5301573Srgrimes address addr0 = addr; 5311573Srgrimes if (addr0 == NULL || dest->allocates2(addr0)) return; 5321573Srgrimes CodeBuffer* cb = dest->outer(); 53312682Speter addr = new_addr_for(addr0, cb, cb); 5341573Srgrimes assert(allow_other_sections || dest->contains2(addr), 53512682Speter "addr must be in required section"); 53612682Speter} 53712682Speter 53812885Speter 53912885Spetervoid CallRelocation::set_destination(address x) { 5401573Srgrimes pd_set_call_destination(x); 5411573Srgrimes} 54212682Speter 54312682Spetervoid CallRelocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) { 54412682Speter // Usually a self-relative reference to an external routine. 5451573Srgrimes // On some platforms, the reference is absolute (not self-relative). 5461573Srgrimes // The enhanced use of pd_call_destination sorts this all out. 5471573Srgrimes address orig_addr = old_addr_for(addr(), src, dest); 5481573Srgrimes address callee = pd_call_destination(orig_addr); 5491573Srgrimes // Reassert the callee address, this time in the new copy of the code. 5501573Srgrimes pd_set_call_destination(callee); 5511573Srgrimes} 5521573Srgrimes 5531573Srgrimes 5541573Srgrimes//// pack/unpack methods 5551573Srgrimes 5561573Srgrimesvoid oop_Relocation::pack_data_to(CodeSection* dest) { 5571573Srgrimes short* p = (short*) dest->locs_end(); 5581573Srgrimes p = pack_2_ints_to(p, _oop_index, _offset); 5591573Srgrimes dest->set_locs_end((relocInfo*) p); 5601573Srgrimes} 5611573Srgrimes 5621573Srgrimes 5631573Srgrimesvoid oop_Relocation::unpack_data() { 5641573Srgrimes unpack_2_ints(_oop_index, _offset); 5651573Srgrimes} 5661573Srgrimes 5671573Srgrimesvoid metadata_Relocation::pack_data_to(CodeSection* dest) { 5681573Srgrimes short* p = (short*) dest->locs_end(); 5691573Srgrimes p = pack_2_ints_to(p, _metadata_index, _offset); 5701573Srgrimes dest->set_locs_end((relocInfo*) p); 5711573Srgrimes} 5721573Srgrimes 5731573Srgrimes 5741573Srgrimesvoid metadata_Relocation::unpack_data() { 5751573Srgrimes unpack_2_ints(_metadata_index, _offset); 5761573Srgrimes} 5771573Srgrimes 5781573Srgrimes 5791573Srgrimesvoid virtual_call_Relocation::pack_data_to(CodeSection* dest) { 5801573Srgrimes short* p = (short*) dest->locs_end(); 5811573Srgrimes address point = dest->locs_point(); 5821573Srgrimes 5831573Srgrimes normalize_address(_cached_value, dest); 5848870Srgrimes jint x0 = scaled_offset_null_special(_cached_value, point); 5851573Srgrimes p = pack_1_int_to(p, x0); 5861573Srgrimes dest->set_locs_end((relocInfo*) p); 5871573Srgrimes} 5881573Srgrimes 5891573Srgrimes 5901573Srgrimesvoid virtual_call_Relocation::unpack_data() { 5911573Srgrimes jint x0 = unpack_1_int(); 5921573Srgrimes address point = addr(); 5931573Srgrimes _cached_value = x0==0? NULL: address_from_scaled_offset(x0, point); 5941573Srgrimes} 5951573Srgrimes 59612682Speter 5971573Srgrimesvoid static_stub_Relocation::pack_data_to(CodeSection* dest) { 5981573Srgrimes short* p = (short*) dest->locs_end(); 5991573Srgrimes CodeSection* insts = dest->outer()->insts(); 6001573Srgrimes normalize_address(_static_call, insts); 6011573Srgrimes p = pack_1_int_to(p, scaled_offset(_static_call, insts->start())); 60214236Speter dest->set_locs_end((relocInfo*) p); 60314236Speter} 60414236Speter 6051573Srgrimesvoid static_stub_Relocation::unpack_data() { 60614236Speter address base = binding()->section_start(CodeBuffer::SECT_INSTS); 60714236Speter _static_call = address_from_scaled_offset(unpack_1_int(), base); 60814236Speter} 60914236Speter 61014236Speter 61114236Spetervoid external_word_Relocation::pack_data_to(CodeSection* dest) { 61214236Speter short* p = (short*) dest->locs_end(); 61314236Speter int32_t index = runtime_address_to_index(_target); 6141573Srgrimes#ifndef _LP64 6151573Srgrimes p = pack_1_int_to(p, index); 6161573Srgrimes#else 6178870Srgrimes if (is_reloc_index(index)) { 61814236Speter p = pack_2_ints_to(p, index, 0); 61912682Speter } else { 6201573Srgrimes jlong t = (jlong) _target; 6211573Srgrimes int32_t lo = low(t); 6221573Srgrimes int32_t hi = high(t); 62312682Speter p = pack_2_ints_to(p, lo, hi); 62412682Speter DEBUG_ONLY(jlong t1 = jlong_from(hi, lo)); 6251573Srgrimes assert(!is_reloc_index(t1) && (address) t1 == _target, "not symmetric"); 6261573Srgrimes } 6271573Srgrimes#endif /* _LP64 */ 6281573Srgrimes dest->set_locs_end((relocInfo*) p); 6291573Srgrimes} 6301573Srgrimes 6311573Srgrimes 6321573Srgrimesvoid external_word_Relocation::unpack_data() { 6331573Srgrimes#ifndef _LP64 6341573Srgrimes _target = index_to_runtime_address(unpack_1_int()); 6351573Srgrimes#else 6361573Srgrimes int32_t lo, hi; 6371573Srgrimes unpack_2_ints(lo, hi); 6381573Srgrimes jlong t = jlong_from(hi, lo);; 6391573Srgrimes if (is_reloc_index(t)) { 6401573Srgrimes _target = index_to_runtime_address(t); 6411573Srgrimes } else { 6421573Srgrimes _target = (address) t; 6431573Srgrimes } 6441573Srgrimes#endif /* _LP64 */ 6451573Srgrimes} 6461573Srgrimes 6471573Srgrimes 6481573Srgrimesvoid internal_word_Relocation::pack_data_to(CodeSection* dest) { 6491573Srgrimes short* p = (short*) dest->locs_end(); 6501573Srgrimes normalize_address(_target, dest, true); 6511573Srgrimes 6521573Srgrimes // Check whether my target address is valid within this section. 6531573Srgrimes // If not, strengthen the relocation type to point to another section. 6541573Srgrimes int sindex = _section; 6551573Srgrimes if (sindex == CodeBuffer::SECT_NONE && _target != NULL 6561573Srgrimes && (!dest->allocates(_target) || _target == dest->locs_point())) { 6571573Srgrimes sindex = dest->outer()->section_index_of(_target); 6581573Srgrimes guarantee(sindex != CodeBuffer::SECT_NONE, "must belong somewhere"); 6591573Srgrimes relocInfo* base = dest->locs_end() - 1; 6601573Srgrimes assert(base->type() == this->type(), "sanity"); 6611573Srgrimes // Change the written type, to be section_word_type instead. 6621573Srgrimes base->set_type(relocInfo::section_word_type); 6631573Srgrimes } 6641573Srgrimes 6651573Srgrimes // Note: An internal_word relocation cannot refer to its own instruction, 6661573Srgrimes // because we reserve "0" to mean that the pointer itself is embedded 6671573Srgrimes // in the code stream. We use a section_word relocation for such cases. 6682029Sdg 6692029Sdg if (sindex == CodeBuffer::SECT_NONE) { 6702029Sdg assert(type() == relocInfo::internal_word_type, "must be base class"); 6711573Srgrimes guarantee(_target == NULL || dest->allocates2(_target), "must be within the given code section"); 67214236Speter jint x0 = scaled_offset_null_special(_target, dest->locs_point()); 67314236Speter assert(!(x0 == 0 && _target != NULL), "correct encoding of null target"); 67414236Speter p = pack_1_int_to(p, x0); 67514236Speter } else { 67614236Speter assert(_target != NULL, "sanity"); 6771573Srgrimes CodeSection* sect = dest->outer()->code_section(sindex); 6782029Sdg guarantee(sect->allocates2(_target), "must be in correct section"); 6792029Sdg address base = sect->start(); 6802029Sdg jint offset = scaled_offset(_target, base); 6812029Sdg assert((uint)sindex < (uint)CodeBuffer::SECT_LIMIT, "sanity"); 6822029Sdg assert(CodeBuffer::SECT_LIMIT <= (1 << section_width), "section_width++"); 6832029Sdg p = pack_1_int_to(p, (offset << section_width) | sindex); 6842029Sdg } 6852029Sdg 6862029Sdg dest->set_locs_end((relocInfo*) p); 6872029Sdg} 6888870Srgrimes 6891573Srgrimes 6907166Sjoergvoid internal_word_Relocation::unpack_data() { 6912029Sdg jint x0 = unpack_1_int(); 6921573Srgrimes _target = x0==0? NULL: address_from_scaled_offset(x0, addr()); 6932029Sdg _section = CodeBuffer::SECT_NONE; 6944095Sdg} 6952029Sdg 6962029Sdg 6972029Sdgvoid section_word_Relocation::unpack_data() { 6982029Sdg jint x = unpack_1_int(); 6992029Sdg jint offset = (x >> section_width); 7002029Sdg int sindex = (x & ((1<<section_width)-1)); 7012029Sdg address base = binding()->section_start(sindex); 7021573Srgrimes 7032029Sdg _section = sindex; 7042029Sdg _target = address_from_scaled_offset(offset, base); 7051573Srgrimes} 7061573Srgrimes 707 708void breakpoint_Relocation::pack_data_to(CodeSection* dest) { 709 short* p = (short*) dest->locs_end(); 710 address point = dest->locs_point(); 711 712 *p++ = _bits; 713 714 assert(_target != NULL, "sanity"); 715 716 if (internal()) normalize_address(_target, dest); 717 718 jint target_bits = 719 (jint)( internal() ? scaled_offset (_target, point) 720 : runtime_address_to_index(_target) ); 721 if (settable()) { 722 // save space for set_target later 723 p = add_jint(p, target_bits); 724 } else { 725 p = add_var_int(p, target_bits); 726 } 727 728 for (int i = 0; i < instrlen(); i++) { 729 // put placeholder words until bytes can be saved 730 p = add_short(p, (short)0x7777); 731 } 732 733 dest->set_locs_end((relocInfo*) p); 734} 735 736 737void breakpoint_Relocation::unpack_data() { 738 _bits = live_bits(); 739 740 int targetlen = datalen() - 1 - instrlen(); 741 jint target_bits = 0; 742 if (targetlen == 0) target_bits = 0; 743 else if (targetlen == 1) target_bits = *(data()+1); 744 else if (targetlen == 2) target_bits = relocInfo::jint_from_data(data()+1); 745 else { ShouldNotReachHere(); } 746 747 _target = internal() ? address_from_scaled_offset(target_bits, addr()) 748 : index_to_runtime_address (target_bits); 749} 750 751 752//// miscellaneous methods 753oop* oop_Relocation::oop_addr() { 754 int n = _oop_index; 755 if (n == 0) { 756 // oop is stored in the code stream 757 return (oop*) pd_address_in_code(); 758 } else { 759 // oop is stored in table at nmethod::oops_begin 760 return code()->oop_addr_at(n); 761 } 762} 763 764 765oop oop_Relocation::oop_value() { 766 oop v = *oop_addr(); 767 // clean inline caches store a special pseudo-null 768 if (v == (oop)Universe::non_oop_word()) v = NULL; 769 return v; 770} 771 772 773void oop_Relocation::fix_oop_relocation() { 774 if (!oop_is_immediate()) { 775 // get the oop from the pool, and re-insert it into the instruction: 776 set_value(value()); 777 } 778} 779 780 781void oop_Relocation::verify_oop_relocation() { 782 if (!oop_is_immediate()) { 783 // get the oop from the pool, and re-insert it into the instruction: 784 verify_value(value()); 785 } 786} 787 788// meta data versions 789Metadata** metadata_Relocation::metadata_addr() { 790 int n = _metadata_index; 791 if (n == 0) { 792 // metadata is stored in the code stream 793 return (Metadata**) pd_address_in_code(); 794 } else { 795 // metadata is stored in table at nmethod::metadatas_begin 796 return code()->metadata_addr_at(n); 797 } 798 } 799 800 801Metadata* metadata_Relocation::metadata_value() { 802 Metadata* v = *metadata_addr(); 803 // clean inline caches store a special pseudo-null 804 if (v == (Metadata*)Universe::non_oop_word()) v = NULL; 805 return v; 806 } 807 808 809void metadata_Relocation::fix_metadata_relocation() { 810 if (!metadata_is_immediate()) { 811 // get the metadata from the pool, and re-insert it into the instruction: 812 pd_fix_value(value()); 813 } 814} 815 816 817void metadata_Relocation::verify_metadata_relocation() { 818 if (!metadata_is_immediate()) { 819 // get the metadata from the pool, and re-insert it into the instruction: 820 verify_value(value()); 821 } 822} 823 824address virtual_call_Relocation::cached_value() { 825 assert(_cached_value != NULL && _cached_value < addr(), "must precede ic_call"); 826 return _cached_value; 827} 828 829 830void virtual_call_Relocation::clear_inline_cache() { 831 // No stubs for ICs 832 // Clean IC 833 ResourceMark rm; 834 CompiledIC* icache = CompiledIC_at(this); 835 icache->set_to_clean(); 836} 837 838 839void opt_virtual_call_Relocation::clear_inline_cache() { 840 // No stubs for ICs 841 // Clean IC 842 ResourceMark rm; 843 CompiledIC* icache = CompiledIC_at(this); 844 icache->set_to_clean(); 845} 846 847 848address opt_virtual_call_Relocation::static_stub() { 849 // search for the static stub who points back to this static call 850 address static_call_addr = addr(); 851 RelocIterator iter(code()); 852 while (iter.next()) { 853 if (iter.type() == relocInfo::static_stub_type) { 854 if (iter.static_stub_reloc()->static_call() == static_call_addr) { 855 return iter.addr(); 856 } 857 } 858 } 859 return NULL; 860} 861 862 863void static_call_Relocation::clear_inline_cache() { 864 // Safe call site info 865 CompiledStaticCall* handler = compiledStaticCall_at(this); 866 handler->set_to_clean(); 867} 868 869 870address static_call_Relocation::static_stub() { 871 // search for the static stub who points back to this static call 872 address static_call_addr = addr(); 873 RelocIterator iter(code()); 874 while (iter.next()) { 875 if (iter.type() == relocInfo::static_stub_type) { 876 if (iter.static_stub_reloc()->static_call() == static_call_addr) { 877 return iter.addr(); 878 } 879 } 880 } 881 return NULL; 882} 883 884 885void static_stub_Relocation::clear_inline_cache() { 886 // Call stub is only used when calling the interpreted code. 887 // It does not really need to be cleared, except that we want to clean out the methodoop. 888 CompiledStaticCall::set_stub_to_clean(this); 889} 890 891 892void external_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) { 893 address target = _target; 894 if (target == NULL) { 895 // An absolute embedded reference to an external location, 896 // which means there is nothing to fix here. 897 return; 898 } 899 // Probably this reference is absolute, not relative, so the 900 // following is probably a no-op. 901 assert(src->section_index_of(target) == CodeBuffer::SECT_NONE, "sanity"); 902 set_value(target); 903} 904 905 906address external_word_Relocation::target() { 907 address target = _target; 908 if (target == NULL) { 909 target = pd_get_address_from_code(); 910 } 911 return target; 912} 913 914 915void internal_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) { 916 address target = _target; 917 if (target == NULL) { 918 if (addr_in_const()) { 919 target = new_addr_for(*(address*)addr(), src, dest); 920 } else { 921 target = new_addr_for(pd_get_address_from_code(), src, dest); 922 } 923 } 924 set_value(target); 925} 926 927 928address internal_word_Relocation::target() { 929 address target = _target; 930 if (target == NULL) { 931 target = pd_get_address_from_code(); 932 } 933 return target; 934} 935 936 937breakpoint_Relocation::breakpoint_Relocation(int kind, address target, bool internal) { 938 bool active = false; 939 bool enabled = (kind == initialization); 940 bool removable = (kind != safepoint); 941 bool settable = (target == NULL); 942 943 int bits = kind; 944 if (enabled) bits |= enabled_state; 945 if (internal) bits |= internal_attr; 946 if (removable) bits |= removable_attr; 947 if (settable) bits |= settable_attr; 948 949 _bits = bits | high_bit; 950 _target = target; 951 952 assert(this->kind() == kind, "kind encoded"); 953 assert(this->enabled() == enabled, "enabled encoded"); 954 assert(this->active() == active, "active encoded"); 955 assert(this->internal() == internal, "internal encoded"); 956 assert(this->removable() == removable, "removable encoded"); 957 assert(this->settable() == settable, "settable encoded"); 958} 959 960 961address breakpoint_Relocation::target() const { 962 return _target; 963} 964 965 966void breakpoint_Relocation::set_target(address x) { 967 assert(settable(), "must be settable"); 968 jint target_bits = 969 (jint)(internal() ? scaled_offset (x, addr()) 970 : runtime_address_to_index(x)); 971 short* p = &live_bits() + 1; 972 p = add_jint(p, target_bits); 973 assert(p == instrs(), "new target must fit"); 974 _target = x; 975} 976 977 978void breakpoint_Relocation::set_enabled(bool b) { 979 if (enabled() == b) return; 980 981 if (b) { 982 set_bits(bits() | enabled_state); 983 } else { 984 set_active(false); // remove the actual breakpoint insn, if any 985 set_bits(bits() & ~enabled_state); 986 } 987} 988 989 990void breakpoint_Relocation::set_active(bool b) { 991 assert(!b || enabled(), "cannot activate a disabled breakpoint"); 992 993 if (active() == b) return; 994 995 // %%% should probably seize a lock here (might not be the right lock) 996 //MutexLockerEx ml_patch(Patching_lock, true); 997 //if (active() == b) return; // recheck state after locking 998 999 if (b) { 1000 set_bits(bits() | active_state); 1001 if (instrlen() == 0) 1002 fatal("breakpoints in original code must be undoable"); 1003 pd_swap_in_breakpoint (addr(), instrs(), instrlen()); 1004 } else { 1005 set_bits(bits() & ~active_state); 1006 pd_swap_out_breakpoint(addr(), instrs(), instrlen()); 1007 } 1008} 1009 1010 1011//--------------------------------------------------------------------------------- 1012// Non-product code 1013 1014#ifndef PRODUCT 1015 1016static const char* reloc_type_string(relocInfo::relocType t) { 1017 switch (t) { 1018 #define EACH_CASE(name) \ 1019 case relocInfo::name##_type: \ 1020 return #name; 1021 1022 APPLY_TO_RELOCATIONS(EACH_CASE); 1023 #undef EACH_CASE 1024 1025 case relocInfo::none: 1026 return "none"; 1027 case relocInfo::data_prefix_tag: 1028 return "prefix"; 1029 default: 1030 return "UNKNOWN RELOC TYPE"; 1031 } 1032} 1033 1034 1035void RelocIterator::print_current() { 1036 if (!has_current()) { 1037 tty->print_cr("(no relocs)"); 1038 return; 1039 } 1040 tty->print("relocInfo@" INTPTR_FORMAT " [type=%d(%s) addr=" INTPTR_FORMAT " offset=%d", 1041 _current, type(), reloc_type_string((relocInfo::relocType) type()), _addr, _current->addr_offset()); 1042 if (current()->format() != 0) 1043 tty->print(" format=%d", current()->format()); 1044 if (datalen() == 1) { 1045 tty->print(" data=%d", data()[0]); 1046 } else if (datalen() > 0) { 1047 tty->print(" data={"); 1048 for (int i = 0; i < datalen(); i++) { 1049 tty->print("%04x", data()[i] & 0xFFFF); 1050 } 1051 tty->print("}"); 1052 } 1053 tty->print("]"); 1054 switch (type()) { 1055 case relocInfo::oop_type: 1056 { 1057 oop_Relocation* r = oop_reloc(); 1058 oop* oop_addr = NULL; 1059 oop raw_oop = NULL; 1060 oop oop_value = NULL; 1061 if (code() != NULL || r->oop_is_immediate()) { 1062 oop_addr = r->oop_addr(); 1063 raw_oop = *oop_addr; 1064 oop_value = r->oop_value(); 1065 } 1066 tty->print(" | [oop_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT " offset=%d]", 1067 oop_addr, (address)raw_oop, r->offset()); 1068 // Do not print the oop by default--we want this routine to 1069 // work even during GC or other inconvenient times. 1070 if (WizardMode && oop_value != NULL) { 1071 tty->print("oop_value=" INTPTR_FORMAT ": ", (address)oop_value); 1072 oop_value->print_value_on(tty); 1073 } 1074 break; 1075 } 1076 case relocInfo::metadata_type: 1077 { 1078 metadata_Relocation* r = metadata_reloc(); 1079 Metadata** metadata_addr = NULL; 1080 Metadata* raw_metadata = NULL; 1081 Metadata* metadata_value = NULL; 1082 if (code() != NULL || r->metadata_is_immediate()) { 1083 metadata_addr = r->metadata_addr(); 1084 raw_metadata = *metadata_addr; 1085 metadata_value = r->metadata_value(); 1086 } 1087 tty->print(" | [metadata_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT " offset=%d]", 1088 metadata_addr, (address)raw_metadata, r->offset()); 1089 if (metadata_value != NULL) { 1090 tty->print("metadata_value=" INTPTR_FORMAT ": ", (address)metadata_value); 1091 metadata_value->print_value_on(tty); 1092 } 1093 break; 1094 } 1095 case relocInfo::external_word_type: 1096 case relocInfo::internal_word_type: 1097 case relocInfo::section_word_type: 1098 { 1099 DataRelocation* r = (DataRelocation*) reloc(); 1100 tty->print(" | [target=" INTPTR_FORMAT "]", r->value()); //value==target 1101 break; 1102 } 1103 case relocInfo::static_call_type: 1104 case relocInfo::runtime_call_type: 1105 { 1106 CallRelocation* r = (CallRelocation*) reloc(); 1107 tty->print(" | [destination=" INTPTR_FORMAT "]", r->destination()); 1108 break; 1109 } 1110 case relocInfo::virtual_call_type: 1111 { 1112 virtual_call_Relocation* r = (virtual_call_Relocation*) reloc(); 1113 tty->print(" | [destination=" INTPTR_FORMAT " cached_value=" INTPTR_FORMAT "]", 1114 r->destination(), r->cached_value()); 1115 break; 1116 } 1117 case relocInfo::static_stub_type: 1118 { 1119 static_stub_Relocation* r = (static_stub_Relocation*) reloc(); 1120 tty->print(" | [static_call=" INTPTR_FORMAT "]", r->static_call()); 1121 break; 1122 } 1123 } 1124 tty->cr(); 1125} 1126 1127 1128void RelocIterator::print() { 1129 RelocIterator save_this = (*this); 1130 relocInfo* scan = _current; 1131 if (!has_current()) scan += 1; // nothing to scan here! 1132 1133 bool skip_next = has_current(); 1134 bool got_next; 1135 while (true) { 1136 got_next = (skip_next || next()); 1137 skip_next = false; 1138 1139 tty->print(" @" INTPTR_FORMAT ": ", scan); 1140 relocInfo* newscan = _current+1; 1141 if (!has_current()) newscan -= 1; // nothing to scan here! 1142 while (scan < newscan) { 1143 tty->print("%04x", *(short*)scan & 0xFFFF); 1144 scan++; 1145 } 1146 tty->cr(); 1147 1148 if (!got_next) break; 1149 print_current(); 1150 } 1151 1152 (*this) = save_this; 1153} 1154 1155// For the debugger: 1156extern "C" 1157void print_blob_locs(nmethod* nm) { 1158 nm->print(); 1159 RelocIterator iter(nm); 1160 iter.print(); 1161} 1162extern "C" 1163void print_buf_locs(CodeBuffer* cb) { 1164 FlagSetting fs(PrintRelocations, true); 1165 cb->print(); 1166} 1167#endif // !PRODUCT 1168