Path: blob/master/src/hotspot/share/code/relocInfo.cpp
40931 views
/*1* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "code/codeCache.hpp"26#include "code/compiledIC.hpp"27#include "code/nmethod.hpp"28#include "code/relocInfo.hpp"29#include "memory/resourceArea.hpp"30#include "memory/universe.hpp"31#include "oops/compressedOops.inline.hpp"32#include "oops/oop.inline.hpp"33#include "runtime/flags/flagSetting.hpp"34#include "runtime/stubCodeGenerator.hpp"35#include "utilities/align.hpp"36#include "utilities/copy.hpp"3738const RelocationHolder RelocationHolder::none; // its type is relocInfo::none394041// Implementation of relocInfo4243#ifdef ASSERT44relocInfo::relocType relocInfo::check_relocType(relocType type) {45assert(type != data_prefix_tag, "cannot build a prefix this way");46assert((type & type_mask) == type, "wrong type");47return type;48}4950void relocInfo::check_offset_and_format(int offset, int format) {51assert(offset >= 0 && offset < offset_limit(), "offset out off bounds");52assert(is_aligned(offset, offset_unit), "misaligned offset");53assert((format & format_mask) == format, "wrong format");54}55#endif // ASSERT5657void relocInfo::initialize(CodeSection* dest, Relocation* reloc) {58relocInfo* data = this+1; // here's where the data might go59dest->set_locs_end(data); // sync end: the next call may read dest.locs_end60reloc->pack_data_to(dest); // maybe write data into locs, advancing locs_end61relocInfo* data_limit = dest->locs_end();62if (data_limit > data) {63relocInfo suffix = (*this);64data_limit = this->finish_prefix((short*) data_limit);65// Finish up with the suffix. (Hack note: pack_data_to might edit this.)66*data_limit = suffix;67dest->set_locs_end(data_limit+1);68}69}7071relocInfo* relocInfo::finish_prefix(short* prefix_limit) {72assert(sizeof(relocInfo) == sizeof(short), "change this code");73short* p = (short*)(this+1);74assert(prefix_limit >= p, "must be a valid span of data");75int plen = prefix_limit - p;76if (plen == 0) {77debug_only(_value = 0xFFFF);78return this; // no data: remove self completely79}80if (plen == 1 && fits_into_immediate(p[0])) {81(*this) = immediate_relocInfo(p[0]); // move data inside self82return this+1;83}84// cannot compact, so just update the count and return the limit pointer85(*this) = prefix_relocInfo(plen); // write new datalen86assert(data() + datalen() == prefix_limit, "pointers must line up");87return (relocInfo*)prefix_limit;88}8990void relocInfo::set_type(relocType t) {91int old_offset = addr_offset();92int old_format = format();93(*this) = relocInfo(t, old_offset, old_format);94assert(type()==(int)t, "sanity check");95assert(addr_offset()==old_offset, "sanity check");96assert(format()==old_format, "sanity check");97}9899void relocInfo::change_reloc_info_for_address(RelocIterator *itr, address pc, relocType old_type, relocType new_type) {100bool found = false;101while (itr->next() && !found) {102if (itr->addr() == pc) {103assert(itr->type()==old_type, "wrong relocInfo type found");104itr->current()->set_type(new_type);105found=true;106}107}108assert(found, "no relocInfo found for pc");109}110111112// ----------------------------------------------------------------------------------------------------113// Implementation of RelocIterator114115void RelocIterator::initialize(CompiledMethod* nm, address begin, address limit) {116initialize_misc();117118if (nm == NULL && begin != NULL) {119// allow nmethod to be deduced from beginning address120CodeBlob* cb = CodeCache::find_blob(begin);121nm = (cb != NULL) ? cb->as_compiled_method_or_null() : NULL;122}123guarantee(nm != NULL, "must be able to deduce nmethod from other arguments");124125_code = nm;126_current = nm->relocation_begin() - 1;127_end = nm->relocation_end();128_addr = nm->content_begin();129130// Initialize code sections.131_section_start[CodeBuffer::SECT_CONSTS] = nm->consts_begin();132_section_start[CodeBuffer::SECT_INSTS ] = nm->insts_begin() ;133_section_start[CodeBuffer::SECT_STUBS ] = nm->stub_begin() ;134135_section_end [CodeBuffer::SECT_CONSTS] = nm->consts_end() ;136_section_end [CodeBuffer::SECT_INSTS ] = nm->insts_end() ;137_section_end [CodeBuffer::SECT_STUBS ] = nm->stub_end() ;138139assert(!has_current(), "just checking");140assert(begin == NULL || begin >= nm->code_begin(), "in bounds");141assert(limit == NULL || limit <= nm->code_end(), "in bounds");142set_limits(begin, limit);143}144145146RelocIterator::RelocIterator(CodeSection* cs, address begin, address limit) {147initialize_misc();148149_current = cs->locs_start()-1;150_end = cs->locs_end();151_addr = cs->start();152_code = NULL; // Not cb->blob();153154CodeBuffer* cb = cs->outer();155assert((int) SECT_LIMIT == CodeBuffer::SECT_LIMIT, "my copy must be equal");156for (int n = (int) CodeBuffer::SECT_FIRST; n < (int) CodeBuffer::SECT_LIMIT; n++) {157CodeSection* cs = cb->code_section(n);158_section_start[n] = cs->start();159_section_end [n] = cs->end();160}161162assert(!has_current(), "just checking");163164assert(begin == NULL || begin >= cs->start(), "in bounds");165assert(limit == NULL || limit <= cs->end(), "in bounds");166set_limits(begin, limit);167}168169bool RelocIterator::addr_in_const() const {170const int n = CodeBuffer::SECT_CONSTS;171return section_start(n) <= addr() && addr() < section_end(n);172}173174175void RelocIterator::set_limits(address begin, address limit) {176_limit = limit;177178// the limit affects this next stuff:179if (begin != NULL) {180relocInfo* backup;181address backup_addr;182while (true) {183backup = _current;184backup_addr = _addr;185if (!next() || addr() >= begin) break;186}187// At this point, either we are at the first matching record,188// or else there is no such record, and !has_current().189// In either case, revert to the immediatly preceding state.190_current = backup;191_addr = backup_addr;192set_has_current(false);193}194}195196197// All the strange bit-encodings are in here.198// The idea is to encode relocation data which are small integers199// very efficiently (a single extra halfword). Larger chunks of200// relocation data need a halfword header to hold their size.201void RelocIterator::advance_over_prefix() {202if (_current->is_datalen()) {203_data = (short*) _current->data();204_datalen = _current->datalen();205_current += _datalen + 1; // skip the embedded data & header206} else {207_databuf = _current->immediate();208_data = &_databuf;209_datalen = 1;210_current++; // skip the header211}212// The client will see the following relocInfo, whatever that is.213// It is the reloc to which the preceding data applies.214}215216217void RelocIterator::initialize_misc() {218set_has_current(false);219for (int i = (int) CodeBuffer::SECT_FIRST; i < (int) CodeBuffer::SECT_LIMIT; i++) {220_section_start[i] = NULL; // these will be lazily computed, if needed221_section_end [i] = NULL;222}223}224225226Relocation* RelocIterator::reloc() {227// (take the "switch" out-of-line)228relocInfo::relocType t = type();229if (false) {}230#define EACH_TYPE(name) \231else if (t == relocInfo::name##_type) { \232return name##_reloc(); \233}234APPLY_TO_RELOCATIONS(EACH_TYPE);235#undef EACH_TYPE236assert(t == relocInfo::none, "must be padding");237return new(_rh) Relocation(t);238}239240241//////// Methods for flyweight Relocation types242243244RelocationHolder RelocationHolder::plus(int offset) const {245if (offset != 0) {246switch (type()) {247case relocInfo::none:248break;249case relocInfo::oop_type:250{251oop_Relocation* r = (oop_Relocation*)reloc();252return oop_Relocation::spec(r->oop_index(), r->offset() + offset);253}254case relocInfo::metadata_type:255{256metadata_Relocation* r = (metadata_Relocation*)reloc();257return metadata_Relocation::spec(r->metadata_index(), r->offset() + offset);258}259default:260ShouldNotReachHere();261}262}263return (*this);264}265266// some relocations can compute their own values267address Relocation::value() {268ShouldNotReachHere();269return NULL;270}271272273void Relocation::set_value(address x) {274ShouldNotReachHere();275}276277void Relocation::const_set_data_value(address x) {278#ifdef _LP64279if (format() == relocInfo::narrow_oop_in_const) {280*(narrowOop*)addr() = CompressedOops::encode(cast_to_oop(x));281} else {282#endif283*(address*)addr() = x;284#ifdef _LP64285}286#endif287}288289void Relocation::const_verify_data_value(address x) {290#ifdef _LP64291if (format() == relocInfo::narrow_oop_in_const) {292guarantee(*(narrowOop*)addr() == CompressedOops::encode(cast_to_oop(x)), "must agree");293} else {294#endif295guarantee(*(address*)addr() == x, "must agree");296#ifdef _LP64297}298#endif299}300301302RelocationHolder Relocation::spec_simple(relocInfo::relocType rtype) {303if (rtype == relocInfo::none) return RelocationHolder::none;304relocInfo ri = relocInfo(rtype, 0);305RelocIterator itr;306itr.set_current(ri);307itr.reloc();308return itr._rh;309}310311address Relocation::old_addr_for(address newa,312const CodeBuffer* src, CodeBuffer* dest) {313int sect = dest->section_index_of(newa);314guarantee(sect != CodeBuffer::SECT_NONE, "lost track of this address");315address ostart = src->code_section(sect)->start();316address nstart = dest->code_section(sect)->start();317return ostart + (newa - nstart);318}319320address Relocation::new_addr_for(address olda,321const CodeBuffer* src, CodeBuffer* dest) {322debug_only(const CodeBuffer* src0 = src);323int sect = CodeBuffer::SECT_NONE;324// Look for olda in the source buffer, and all previous incarnations325// if the source buffer has been expanded.326for (; src != NULL; src = src->before_expand()) {327sect = src->section_index_of(olda);328if (sect != CodeBuffer::SECT_NONE) break;329}330guarantee(sect != CodeBuffer::SECT_NONE, "lost track of this address");331address ostart = src->code_section(sect)->start();332address nstart = dest->code_section(sect)->start();333return nstart + (olda - ostart);334}335336void Relocation::normalize_address(address& addr, const CodeSection* dest, bool allow_other_sections) {337address addr0 = addr;338if (addr0 == NULL || dest->allocates2(addr0)) return;339CodeBuffer* cb = dest->outer();340addr = new_addr_for(addr0, cb, cb);341assert(allow_other_sections || dest->contains2(addr),342"addr must be in required section");343}344345346void CallRelocation::set_destination(address x) {347pd_set_call_destination(x);348}349350void CallRelocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {351// Usually a self-relative reference to an external routine.352// On some platforms, the reference is absolute (not self-relative).353// The enhanced use of pd_call_destination sorts this all out.354address orig_addr = old_addr_for(addr(), src, dest);355address callee = pd_call_destination(orig_addr);356// Reassert the callee address, this time in the new copy of the code.357pd_set_call_destination(callee);358}359360361//// pack/unpack methods362363void oop_Relocation::pack_data_to(CodeSection* dest) {364short* p = (short*) dest->locs_end();365p = pack_2_ints_to(p, _oop_index, _offset);366dest->set_locs_end((relocInfo*) p);367}368369370void oop_Relocation::unpack_data() {371unpack_2_ints(_oop_index, _offset);372}373374void metadata_Relocation::pack_data_to(CodeSection* dest) {375short* p = (short*) dest->locs_end();376p = pack_2_ints_to(p, _metadata_index, _offset);377dest->set_locs_end((relocInfo*) p);378}379380381void metadata_Relocation::unpack_data() {382unpack_2_ints(_metadata_index, _offset);383}384385386void virtual_call_Relocation::pack_data_to(CodeSection* dest) {387short* p = (short*) dest->locs_end();388address point = dest->locs_point();389390normalize_address(_cached_value, dest);391jint x0 = scaled_offset_null_special(_cached_value, point);392p = pack_2_ints_to(p, x0, _method_index);393dest->set_locs_end((relocInfo*) p);394}395396397void virtual_call_Relocation::unpack_data() {398jint x0 = 0;399unpack_2_ints(x0, _method_index);400address point = addr();401_cached_value = x0==0? NULL: address_from_scaled_offset(x0, point);402}403404void runtime_call_w_cp_Relocation::pack_data_to(CodeSection * dest) {405short* p = pack_1_int_to((short *)dest->locs_end(), (jint)(_offset >> 2));406dest->set_locs_end((relocInfo*) p);407}408409void runtime_call_w_cp_Relocation::unpack_data() {410_offset = unpack_1_int() << 2;411}412413void static_stub_Relocation::pack_data_to(CodeSection* dest) {414short* p = (short*) dest->locs_end();415CodeSection* insts = dest->outer()->insts();416normalize_address(_static_call, insts);417p = pack_1_int_to(p, scaled_offset(_static_call, insts->start()));418dest->set_locs_end((relocInfo*) p);419}420421void static_stub_Relocation::unpack_data() {422address base = binding()->section_start(CodeBuffer::SECT_INSTS);423jint offset = unpack_1_int();424_static_call = address_from_scaled_offset(offset, base);425}426427void trampoline_stub_Relocation::pack_data_to(CodeSection* dest ) {428short* p = (short*) dest->locs_end();429CodeSection* insts = dest->outer()->insts();430normalize_address(_owner, insts);431p = pack_1_int_to(p, scaled_offset(_owner, insts->start()));432dest->set_locs_end((relocInfo*) p);433}434435void trampoline_stub_Relocation::unpack_data() {436address base = binding()->section_start(CodeBuffer::SECT_INSTS);437_owner = address_from_scaled_offset(unpack_1_int(), base);438}439440void external_word_Relocation::pack_data_to(CodeSection* dest) {441short* p = (short*) dest->locs_end();442#ifndef _LP64443p = pack_1_int_to(p, (int32_t) (intptr_t)_target);444#else445jlong t = (jlong) _target;446int32_t lo = low(t);447int32_t hi = high(t);448p = pack_2_ints_to(p, lo, hi);449#endif /* _LP64 */450dest->set_locs_end((relocInfo*) p);451}452453454void external_word_Relocation::unpack_data() {455#ifndef _LP64456_target = (address) (intptr_t)unpack_1_int();457#else458jint lo, hi;459unpack_2_ints(lo, hi);460jlong t = jlong_from(hi, lo);;461_target = (address) t;462#endif /* _LP64 */463}464465466void internal_word_Relocation::pack_data_to(CodeSection* dest) {467short* p = (short*) dest->locs_end();468normalize_address(_target, dest, true);469470// Check whether my target address is valid within this section.471// If not, strengthen the relocation type to point to another section.472int sindex = _section;473if (sindex == CodeBuffer::SECT_NONE && _target != NULL474&& (!dest->allocates(_target) || _target == dest->locs_point())) {475sindex = dest->outer()->section_index_of(_target);476guarantee(sindex != CodeBuffer::SECT_NONE, "must belong somewhere");477relocInfo* base = dest->locs_end() - 1;478assert(base->type() == this->type(), "sanity");479// Change the written type, to be section_word_type instead.480base->set_type(relocInfo::section_word_type);481}482483// Note: An internal_word relocation cannot refer to its own instruction,484// because we reserve "0" to mean that the pointer itself is embedded485// in the code stream. We use a section_word relocation for such cases.486487if (sindex == CodeBuffer::SECT_NONE) {488assert(type() == relocInfo::internal_word_type, "must be base class");489guarantee(_target == NULL || dest->allocates2(_target), "must be within the given code section");490jint x0 = scaled_offset_null_special(_target, dest->locs_point());491assert(!(x0 == 0 && _target != NULL), "correct encoding of null target");492p = pack_1_int_to(p, x0);493} else {494assert(_target != NULL, "sanity");495CodeSection* sect = dest->outer()->code_section(sindex);496guarantee(sect->allocates2(_target), "must be in correct section");497address base = sect->start();498jint offset = scaled_offset(_target, base);499assert((uint)sindex < (uint)CodeBuffer::SECT_LIMIT, "sanity");500assert(CodeBuffer::SECT_LIMIT <= (1 << section_width), "section_width++");501p = pack_1_int_to(p, (offset << section_width) | sindex);502}503504dest->set_locs_end((relocInfo*) p);505}506507508void internal_word_Relocation::unpack_data() {509jint x0 = unpack_1_int();510_target = x0==0? NULL: address_from_scaled_offset(x0, addr());511_section = CodeBuffer::SECT_NONE;512}513514515void section_word_Relocation::unpack_data() {516jint x = unpack_1_int();517jint offset = (x >> section_width);518int sindex = (x & ((1<<section_width)-1));519address base = binding()->section_start(sindex);520521_section = sindex;522_target = address_from_scaled_offset(offset, base);523}524525//// miscellaneous methods526oop* oop_Relocation::oop_addr() {527int n = _oop_index;528if (n == 0) {529// oop is stored in the code stream530return (oop*) pd_address_in_code();531} else {532// oop is stored in table at nmethod::oops_begin533return code()->oop_addr_at(n);534}535}536537538oop oop_Relocation::oop_value() {539// clean inline caches store a special pseudo-null540if (Universe::contains_non_oop_word(oop_addr())) {541return NULL;542}543return *oop_addr();544}545546547void oop_Relocation::fix_oop_relocation() {548if (!oop_is_immediate()) {549// get the oop from the pool, and re-insert it into the instruction:550set_value(value());551}552}553554555void oop_Relocation::verify_oop_relocation() {556if (!oop_is_immediate()) {557// get the oop from the pool, and re-insert it into the instruction:558verify_value(value());559}560}561562// meta data versions563Metadata** metadata_Relocation::metadata_addr() {564int n = _metadata_index;565if (n == 0) {566// metadata is stored in the code stream567return (Metadata**) pd_address_in_code();568} else {569// metadata is stored in table at nmethod::metadatas_begin570return code()->metadata_addr_at(n);571}572}573574575Metadata* metadata_Relocation::metadata_value() {576Metadata* v = *metadata_addr();577// clean inline caches store a special pseudo-null578if (v == (Metadata*)Universe::non_oop_word()) v = NULL;579return v;580}581582583void metadata_Relocation::fix_metadata_relocation() {584if (!metadata_is_immediate()) {585// get the metadata from the pool, and re-insert it into the instruction:586pd_fix_value(value());587}588}589590address virtual_call_Relocation::cached_value() {591assert(_cached_value != NULL && _cached_value < addr(), "must precede ic_call");592return _cached_value;593}594595Method* virtual_call_Relocation::method_value() {596CompiledMethod* cm = code();597if (cm == NULL) return (Method*)NULL;598Metadata* m = cm->metadata_at(_method_index);599assert(m != NULL || _method_index == 0, "should be non-null for non-zero index");600assert(m == NULL || m->is_method(), "not a method");601return (Method*)m;602}603604bool virtual_call_Relocation::clear_inline_cache() {605// No stubs for ICs606// Clean IC607ResourceMark rm;608CompiledIC* icache = CompiledIC_at(this);609return icache->set_to_clean();610}611612613void opt_virtual_call_Relocation::pack_data_to(CodeSection* dest) {614short* p = (short*) dest->locs_end();615p = pack_1_int_to(p, _method_index);616dest->set_locs_end((relocInfo*) p);617}618619void opt_virtual_call_Relocation::unpack_data() {620_method_index = unpack_1_int();621}622623Method* opt_virtual_call_Relocation::method_value() {624CompiledMethod* cm = code();625if (cm == NULL) return (Method*)NULL;626Metadata* m = cm->metadata_at(_method_index);627assert(m != NULL || _method_index == 0, "should be non-null for non-zero index");628assert(m == NULL || m->is_method(), "not a method");629return (Method*)m;630}631632template<typename CompiledICorStaticCall>633static bool set_to_clean_no_ic_refill(CompiledICorStaticCall* ic) {634guarantee(ic->set_to_clean(), "Should not need transition stubs");635return true;636}637638bool opt_virtual_call_Relocation::clear_inline_cache() {639// No stubs for ICs640// Clean IC641ResourceMark rm;642CompiledIC* icache = CompiledIC_at(this);643return set_to_clean_no_ic_refill(icache);644}645646address opt_virtual_call_Relocation::static_stub() {647// search for the static stub who points back to this static call648address static_call_addr = addr();649RelocIterator iter(code());650while (iter.next()) {651if (iter.type() == relocInfo::static_stub_type) {652static_stub_Relocation* stub_reloc = iter.static_stub_reloc();653if (stub_reloc->static_call() == static_call_addr) {654return iter.addr();655}656}657}658return NULL;659}660661Method* static_call_Relocation::method_value() {662CompiledMethod* cm = code();663if (cm == NULL) return (Method*)NULL;664Metadata* m = cm->metadata_at(_method_index);665assert(m != NULL || _method_index == 0, "should be non-null for non-zero index");666assert(m == NULL || m->is_method(), "not a method");667return (Method*)m;668}669670void static_call_Relocation::pack_data_to(CodeSection* dest) {671short* p = (short*) dest->locs_end();672p = pack_1_int_to(p, _method_index);673dest->set_locs_end((relocInfo*) p);674}675676void static_call_Relocation::unpack_data() {677_method_index = unpack_1_int();678}679680bool static_call_Relocation::clear_inline_cache() {681// Safe call site info682CompiledStaticCall* handler = this->code()->compiledStaticCall_at(this);683return set_to_clean_no_ic_refill(handler);684}685686687address static_call_Relocation::static_stub() {688// search for the static stub who points back to this static call689address static_call_addr = addr();690RelocIterator iter(code());691while (iter.next()) {692if (iter.type() == relocInfo::static_stub_type) {693static_stub_Relocation* stub_reloc = iter.static_stub_reloc();694if (stub_reloc->static_call() == static_call_addr) {695return iter.addr();696}697}698}699return NULL;700}701702// Finds the trampoline address for a call. If no trampoline stub is703// found NULL is returned which can be handled by the caller.704address trampoline_stub_Relocation::get_trampoline_for(address call, nmethod* code) {705// There are no relocations available when the code gets relocated706// because of CodeBuffer expansion.707if (code->relocation_size() == 0)708return NULL;709710RelocIterator iter(code, call);711while (iter.next()) {712if (iter.type() == relocInfo::trampoline_stub_type) {713if (iter.trampoline_stub_reloc()->owner() == call) {714return iter.addr();715}716}717}718719return NULL;720}721722bool static_stub_Relocation::clear_inline_cache() {723// Call stub is only used when calling the interpreted code.724// It does not really need to be cleared, except that we want to clean out the methodoop.725CompiledDirectStaticCall::set_stub_to_clean(this);726return true;727}728729730void external_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {731if (_target != NULL) {732// Probably this reference is absolute, not relative, so the following is733// probably a no-op.734set_value(_target);735}736// If target is NULL, this is an absolute embedded reference to an external737// location, which means there is nothing to fix here. In either case, the738// resulting target should be an "external" address.739postcond(src->section_index_of(target()) == CodeBuffer::SECT_NONE);740postcond(dest->section_index_of(target()) == CodeBuffer::SECT_NONE);741}742743744address external_word_Relocation::target() {745address target = _target;746if (target == NULL) {747target = pd_get_address_from_code();748}749return target;750}751752753void internal_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {754address target = _target;755if (target == NULL) {756target = new_addr_for(this->target(), src, dest);757}758set_value(target);759}760761762address internal_word_Relocation::target() {763address target = _target;764if (target == NULL) {765if (addr_in_const()) {766target = *(address*)addr();767} else {768target = pd_get_address_from_code();769}770}771return target;772}773774//---------------------------------------------------------------------------------775// Non-product code776777#ifndef PRODUCT778779static const char* reloc_type_string(relocInfo::relocType t) {780switch (t) {781#define EACH_CASE(name) \782case relocInfo::name##_type: \783return #name;784785APPLY_TO_RELOCATIONS(EACH_CASE);786#undef EACH_CASE787788case relocInfo::none:789return "none";790case relocInfo::data_prefix_tag:791return "prefix";792default:793return "UNKNOWN RELOC TYPE";794}795}796797798void RelocIterator::print_current() {799if (!has_current()) {800tty->print_cr("(no relocs)");801return;802}803tty->print("relocInfo@" INTPTR_FORMAT " [type=%d(%s) addr=" INTPTR_FORMAT " offset=%d",804p2i(_current), type(), reloc_type_string((relocInfo::relocType) type()), p2i(_addr), _current->addr_offset());805if (current()->format() != 0)806tty->print(" format=%d", current()->format());807if (datalen() == 1) {808tty->print(" data=%d", data()[0]);809} else if (datalen() > 0) {810tty->print(" data={");811for (int i = 0; i < datalen(); i++) {812tty->print("%04x", data()[i] & 0xFFFF);813}814tty->print("}");815}816tty->print("]");817switch (type()) {818case relocInfo::oop_type:819{820oop_Relocation* r = oop_reloc();821oop* oop_addr = NULL;822oop raw_oop = NULL;823oop oop_value = NULL;824if (code() != NULL || r->oop_is_immediate()) {825oop_addr = r->oop_addr();826raw_oop = *oop_addr;827oop_value = r->oop_value();828}829tty->print(" | [oop_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT " offset=%d]",830p2i(oop_addr), p2i(raw_oop), r->offset());831// Do not print the oop by default--we want this routine to832// work even during GC or other inconvenient times.833if (WizardMode && oop_value != NULL) {834tty->print("oop_value=" INTPTR_FORMAT ": ", p2i(oop_value));835if (oopDesc::is_oop(oop_value)) {836oop_value->print_value_on(tty);837}838}839break;840}841case relocInfo::metadata_type:842{843metadata_Relocation* r = metadata_reloc();844Metadata** metadata_addr = NULL;845Metadata* raw_metadata = NULL;846Metadata* metadata_value = NULL;847if (code() != NULL || r->metadata_is_immediate()) {848metadata_addr = r->metadata_addr();849raw_metadata = *metadata_addr;850metadata_value = r->metadata_value();851}852tty->print(" | [metadata_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT " offset=%d]",853p2i(metadata_addr), p2i(raw_metadata), r->offset());854if (metadata_value != NULL) {855tty->print("metadata_value=" INTPTR_FORMAT ": ", p2i(metadata_value));856metadata_value->print_value_on(tty);857}858break;859}860case relocInfo::external_word_type:861case relocInfo::internal_word_type:862case relocInfo::section_word_type:863{864DataRelocation* r = (DataRelocation*) reloc();865tty->print(" | [target=" INTPTR_FORMAT "]", p2i(r->value())); //value==target866break;867}868case relocInfo::static_call_type:869{870static_call_Relocation* r = (static_call_Relocation*) reloc();871tty->print(" | [destination=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",872p2i(r->destination()), p2i(r->method_value()));873break;874}875case relocInfo::runtime_call_type:876case relocInfo::runtime_call_w_cp_type:877{878CallRelocation* r = (CallRelocation*) reloc();879tty->print(" | [destination=" INTPTR_FORMAT "]", p2i(r->destination()));880break;881}882case relocInfo::virtual_call_type:883{884virtual_call_Relocation* r = (virtual_call_Relocation*) reloc();885tty->print(" | [destination=" INTPTR_FORMAT " cached_value=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",886p2i(r->destination()), p2i(r->cached_value()), p2i(r->method_value()));887break;888}889case relocInfo::static_stub_type:890{891static_stub_Relocation* r = (static_stub_Relocation*) reloc();892tty->print(" | [static_call=" INTPTR_FORMAT "]", p2i(r->static_call()));893break;894}895case relocInfo::trampoline_stub_type:896{897trampoline_stub_Relocation* r = (trampoline_stub_Relocation*) reloc();898tty->print(" | [trampoline owner=" INTPTR_FORMAT "]", p2i(r->owner()));899break;900}901case relocInfo::opt_virtual_call_type:902{903opt_virtual_call_Relocation* r = (opt_virtual_call_Relocation*) reloc();904tty->print(" | [destination=" INTPTR_FORMAT " metadata=" INTPTR_FORMAT "]",905p2i(r->destination()), p2i(r->method_value()));906break;907}908default:909break;910}911tty->cr();912}913914915void RelocIterator::print() {916RelocIterator save_this = (*this);917relocInfo* scan = _current;918if (!has_current()) scan += 1; // nothing to scan here!919920bool skip_next = has_current();921bool got_next;922while (true) {923got_next = (skip_next || next());924skip_next = false;925926tty->print(" @" INTPTR_FORMAT ": ", p2i(scan));927relocInfo* newscan = _current+1;928if (!has_current()) newscan -= 1; // nothing to scan here!929while (scan < newscan) {930tty->print("%04x", *(short*)scan & 0xFFFF);931scan++;932}933tty->cr();934935if (!got_next) break;936print_current();937}938939(*this) = save_this;940}941942// For the debugger:943extern "C"944void print_blob_locs(nmethod* nm) {945nm->print();946RelocIterator iter(nm);947iter.print();948}949extern "C"950void print_buf_locs(CodeBuffer* cb) {951FlagSetting fs(PrintRelocations, true);952cb->print();953}954#endif // !PRODUCT955956957