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