src/share/vm/asm/codeBuffer.cpp

Mon, 09 Aug 2010 17:51:56 -0700

author
never
date
Mon, 09 Aug 2010 17:51:56 -0700
changeset 2044
f4f596978298
parent 2040
0e35fa8ebccd
child 2103
3e8fbc61cee8
permissions
-rw-r--r--

Merge

duke@435 1 /*
trims@1907 2 * Copyright (c) 1997, 2009, 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
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 # include "incls/_codeBuffer.cpp.incl"
duke@435 27
duke@435 28 // The structure of a CodeSection:
duke@435 29 //
duke@435 30 // _start -> +----------------+
duke@435 31 // | machine code...|
duke@435 32 // _end -> |----------------|
duke@435 33 // | |
duke@435 34 // | (empty) |
duke@435 35 // | |
duke@435 36 // | |
duke@435 37 // +----------------+
duke@435 38 // _limit -> | |
duke@435 39 //
duke@435 40 // _locs_start -> +----------------+
duke@435 41 // |reloc records...|
duke@435 42 // |----------------|
duke@435 43 // _locs_end -> | |
duke@435 44 // | |
duke@435 45 // | (empty) |
duke@435 46 // | |
duke@435 47 // | |
duke@435 48 // +----------------+
duke@435 49 // _locs_limit -> | |
duke@435 50 // The _end (resp. _limit) pointer refers to the first
duke@435 51 // unused (resp. unallocated) byte.
duke@435 52
duke@435 53 // The structure of the CodeBuffer while code is being accumulated:
duke@435 54 //
duke@435 55 // _total_start -> \
duke@435 56 // _insts._start -> +----------------+
duke@435 57 // | |
duke@435 58 // | Code |
duke@435 59 // | |
duke@435 60 // _stubs._start -> |----------------|
duke@435 61 // | |
duke@435 62 // | Stubs | (also handlers for deopt/exception)
duke@435 63 // | |
duke@435 64 // _consts._start -> |----------------|
duke@435 65 // | |
duke@435 66 // | Constants |
duke@435 67 // | |
duke@435 68 // +----------------+
duke@435 69 // + _total_size -> | |
duke@435 70 //
duke@435 71 // When the code and relocations are copied to the code cache,
duke@435 72 // the empty parts of each section are removed, and everything
duke@435 73 // is copied into contiguous locations.
duke@435 74
duke@435 75 typedef CodeBuffer::csize_t csize_t; // file-local definition
duke@435 76
duke@435 77 // external buffer, in a predefined CodeBlob or other buffer area
duke@435 78 // Important: The code_start must be taken exactly, and not realigned.
duke@435 79 CodeBuffer::CodeBuffer(address code_start, csize_t code_size) {
duke@435 80 assert(code_start != NULL, "sanity");
duke@435 81 initialize_misc("static buffer");
duke@435 82 initialize(code_start, code_size);
duke@435 83 assert(verify_section_allocation(), "initial use of buffer OK");
duke@435 84 }
duke@435 85
duke@435 86 void CodeBuffer::initialize(csize_t code_size, csize_t locs_size) {
duke@435 87 // Compute maximal alignment.
duke@435 88 int align = _insts.alignment();
duke@435 89 // Always allow for empty slop around each section.
duke@435 90 int slop = (int) CodeSection::end_slop();
duke@435 91
duke@435 92 assert(blob() == NULL, "only once");
duke@435 93 set_blob(BufferBlob::create(_name, code_size + (align+slop) * (SECT_LIMIT+1)));
duke@435 94 if (blob() == NULL) {
duke@435 95 // The assembler constructor will throw a fatal on an empty CodeBuffer.
duke@435 96 return; // caller must test this
duke@435 97 }
duke@435 98
duke@435 99 // Set up various pointers into the blob.
duke@435 100 initialize(_total_start, _total_size);
duke@435 101
duke@435 102 assert((uintptr_t)code_begin() % CodeEntryAlignment == 0, "instruction start not code entry aligned");
duke@435 103
duke@435 104 pd_initialize();
duke@435 105
duke@435 106 if (locs_size != 0) {
duke@435 107 _insts.initialize_locs(locs_size / sizeof(relocInfo));
duke@435 108 }
duke@435 109
duke@435 110 assert(verify_section_allocation(), "initial use of blob is OK");
duke@435 111 }
duke@435 112
duke@435 113
duke@435 114 CodeBuffer::~CodeBuffer() {
duke@435 115 // If we allocate our code buffer from the CodeCache
duke@435 116 // via a BufferBlob, and it's not permanent, then
duke@435 117 // free the BufferBlob.
duke@435 118 // The rest of the memory will be freed when the ResourceObj
duke@435 119 // is released.
duke@435 120 assert(verify_section_allocation(), "final storage configuration still OK");
duke@435 121 for (CodeBuffer* cb = this; cb != NULL; cb = cb->before_expand()) {
duke@435 122 // Previous incarnations of this buffer are held live, so that internal
duke@435 123 // addresses constructed before expansions will not be confused.
duke@435 124 cb->free_blob();
duke@435 125 }
never@996 126
never@996 127 // free any overflow storage
never@996 128 delete _overflow_arena;
never@996 129
duke@435 130 #ifdef ASSERT
kvn@2040 131 // Save allocation type to execute assert in ~ResourceObj()
kvn@2040 132 // which is called after this destructor.
kvn@2040 133 ResourceObj::allocation_type at = _default_oop_recorder.get_allocation_type();
duke@435 134 Copy::fill_to_bytes(this, sizeof(*this), badResourceValue);
kvn@2040 135 ResourceObj::set_allocation_type((address)(&_default_oop_recorder), at);
duke@435 136 #endif
duke@435 137 }
duke@435 138
duke@435 139 void CodeBuffer::initialize_oop_recorder(OopRecorder* r) {
duke@435 140 assert(_oop_recorder == &_default_oop_recorder && _default_oop_recorder.is_unused(), "do this once");
duke@435 141 DEBUG_ONLY(_default_oop_recorder.oop_size()); // force unused OR to be frozen
duke@435 142 _oop_recorder = r;
duke@435 143 }
duke@435 144
duke@435 145 void CodeBuffer::initialize_section_size(CodeSection* cs, csize_t size) {
duke@435 146 assert(cs != &_insts, "insts is the memory provider, not the consumer");
duke@435 147 #ifdef ASSERT
duke@435 148 for (int n = (int)SECT_INSTS+1; n < (int)SECT_LIMIT; n++) {
duke@435 149 CodeSection* prevCS = code_section(n);
duke@435 150 if (prevCS == cs) break;
duke@435 151 assert(!prevCS->is_allocated(), "section allocation must be in reverse order");
duke@435 152 }
duke@435 153 #endif
duke@435 154 csize_t slop = CodeSection::end_slop(); // margin between sections
duke@435 155 int align = cs->alignment();
duke@435 156 assert(is_power_of_2(align), "sanity");
duke@435 157 address start = _insts._start;
duke@435 158 address limit = _insts._limit;
duke@435 159 address middle = limit - size;
duke@435 160 middle -= (intptr_t)middle & (align-1); // align the division point downward
duke@435 161 guarantee(middle - slop > start, "need enough space to divide up");
duke@435 162 _insts._limit = middle - slop; // subtract desired space, plus slop
duke@435 163 cs->initialize(middle, limit - middle);
duke@435 164 assert(cs->start() == middle, "sanity");
duke@435 165 assert(cs->limit() == limit, "sanity");
duke@435 166 // give it some relocations to start with, if the main section has them
duke@435 167 if (_insts.has_locs()) cs->initialize_locs(1);
duke@435 168 }
duke@435 169
duke@435 170 void CodeBuffer::freeze_section(CodeSection* cs) {
duke@435 171 CodeSection* next_cs = (cs == consts())? NULL: code_section(cs->index()+1);
duke@435 172 csize_t frozen_size = cs->size();
duke@435 173 if (next_cs != NULL) {
duke@435 174 frozen_size = next_cs->align_at_start(frozen_size);
duke@435 175 }
duke@435 176 address old_limit = cs->limit();
duke@435 177 address new_limit = cs->start() + frozen_size;
duke@435 178 relocInfo* old_locs_limit = cs->locs_limit();
duke@435 179 relocInfo* new_locs_limit = cs->locs_end();
duke@435 180 // Patch the limits.
duke@435 181 cs->_limit = new_limit;
duke@435 182 cs->_locs_limit = new_locs_limit;
duke@435 183 cs->_frozen = true;
duke@435 184 if (!next_cs->is_allocated() && !next_cs->is_frozen()) {
duke@435 185 // Give remaining buffer space to the following section.
duke@435 186 next_cs->initialize(new_limit, old_limit - new_limit);
duke@435 187 next_cs->initialize_shared_locs(new_locs_limit,
duke@435 188 old_locs_limit - new_locs_limit);
duke@435 189 }
duke@435 190 }
duke@435 191
duke@435 192 void CodeBuffer::set_blob(BufferBlob* blob) {
duke@435 193 _blob = blob;
duke@435 194 if (blob != NULL) {
duke@435 195 address start = blob->instructions_begin();
duke@435 196 address end = blob->instructions_end();
duke@435 197 // Round up the starting address.
duke@435 198 int align = _insts.alignment();
duke@435 199 start += (-(intptr_t)start) & (align-1);
duke@435 200 _total_start = start;
duke@435 201 _total_size = end - start;
duke@435 202 } else {
duke@435 203 #ifdef ASSERT
duke@435 204 // Clean out dangling pointers.
duke@435 205 _total_start = badAddress;
duke@435 206 _insts._start = _insts._end = badAddress;
duke@435 207 _stubs._start = _stubs._end = badAddress;
duke@435 208 _consts._start = _consts._end = badAddress;
duke@435 209 #endif //ASSERT
duke@435 210 }
duke@435 211 }
duke@435 212
duke@435 213 void CodeBuffer::free_blob() {
duke@435 214 if (_blob != NULL) {
duke@435 215 BufferBlob::free(_blob);
duke@435 216 set_blob(NULL);
duke@435 217 }
duke@435 218 }
duke@435 219
duke@435 220 const char* CodeBuffer::code_section_name(int n) {
duke@435 221 #ifdef PRODUCT
duke@435 222 return NULL;
duke@435 223 #else //PRODUCT
duke@435 224 switch (n) {
duke@435 225 case SECT_INSTS: return "insts";
duke@435 226 case SECT_STUBS: return "stubs";
duke@435 227 case SECT_CONSTS: return "consts";
duke@435 228 default: return NULL;
duke@435 229 }
duke@435 230 #endif //PRODUCT
duke@435 231 }
duke@435 232
duke@435 233 int CodeBuffer::section_index_of(address addr) const {
duke@435 234 for (int n = 0; n < (int)SECT_LIMIT; n++) {
duke@435 235 const CodeSection* cs = code_section(n);
duke@435 236 if (cs->allocates(addr)) return n;
duke@435 237 }
duke@435 238 return SECT_NONE;
duke@435 239 }
duke@435 240
duke@435 241 int CodeBuffer::locator(address addr) const {
duke@435 242 for (int n = 0; n < (int)SECT_LIMIT; n++) {
duke@435 243 const CodeSection* cs = code_section(n);
duke@435 244 if (cs->allocates(addr)) {
duke@435 245 return locator(addr - cs->start(), n);
duke@435 246 }
duke@435 247 }
duke@435 248 return -1;
duke@435 249 }
duke@435 250
duke@435 251 address CodeBuffer::locator_address(int locator) const {
duke@435 252 if (locator < 0) return NULL;
duke@435 253 address start = code_section(locator_sect(locator))->start();
duke@435 254 return start + locator_pos(locator);
duke@435 255 }
duke@435 256
duke@435 257 address CodeBuffer::decode_begin() {
duke@435 258 address begin = _insts.start();
duke@435 259 if (_decode_begin != NULL && _decode_begin > begin)
duke@435 260 begin = _decode_begin;
duke@435 261 return begin;
duke@435 262 }
duke@435 263
duke@435 264
duke@435 265 GrowableArray<int>* CodeBuffer::create_patch_overflow() {
duke@435 266 if (_overflow_arena == NULL) {
duke@435 267 _overflow_arena = new Arena();
duke@435 268 }
duke@435 269 return new (_overflow_arena) GrowableArray<int>(_overflow_arena, 8, 0, 0);
duke@435 270 }
duke@435 271
duke@435 272
duke@435 273 // Helper function for managing labels and their target addresses.
duke@435 274 // Returns a sensible address, and if it is not the label's final
duke@435 275 // address, notes the dependency (at 'branch_pc') on the label.
duke@435 276 address CodeSection::target(Label& L, address branch_pc) {
duke@435 277 if (L.is_bound()) {
duke@435 278 int loc = L.loc();
duke@435 279 if (index() == CodeBuffer::locator_sect(loc)) {
duke@435 280 return start() + CodeBuffer::locator_pos(loc);
duke@435 281 } else {
duke@435 282 return outer()->locator_address(loc);
duke@435 283 }
duke@435 284 } else {
duke@435 285 assert(allocates2(branch_pc), "sanity");
duke@435 286 address base = start();
duke@435 287 int patch_loc = CodeBuffer::locator(branch_pc - base, index());
duke@435 288 L.add_patch_at(outer(), patch_loc);
duke@435 289
duke@435 290 // Need to return a pc, doesn't matter what it is since it will be
duke@435 291 // replaced during resolution later.
coleenp@548 292 // Don't return NULL or badAddress, since branches shouldn't overflow.
coleenp@548 293 // Don't return base either because that could overflow displacements
coleenp@548 294 // for shorter branches. It will get checked when bound.
coleenp@548 295 return branch_pc;
duke@435 296 }
duke@435 297 }
duke@435 298
duke@435 299 void CodeSection::relocate(address at, RelocationHolder const& spec, int format) {
duke@435 300 Relocation* reloc = spec.reloc();
duke@435 301 relocInfo::relocType rtype = (relocInfo::relocType) reloc->type();
duke@435 302 if (rtype == relocInfo::none) return;
duke@435 303
duke@435 304 // The assertion below has been adjusted, to also work for
duke@435 305 // relocation for fixup. Sometimes we want to put relocation
duke@435 306 // information for the next instruction, since it will be patched
duke@435 307 // with a call.
duke@435 308 assert(start() <= at && at <= end()+1,
duke@435 309 "cannot relocate data outside code boundaries");
duke@435 310
duke@435 311 if (!has_locs()) {
duke@435 312 // no space for relocation information provided => code cannot be
duke@435 313 // relocated. Make sure that relocate is only called with rtypes
duke@435 314 // that can be ignored for this kind of code.
duke@435 315 assert(rtype == relocInfo::none ||
duke@435 316 rtype == relocInfo::runtime_call_type ||
duke@435 317 rtype == relocInfo::internal_word_type||
duke@435 318 rtype == relocInfo::section_word_type ||
duke@435 319 rtype == relocInfo::external_word_type,
duke@435 320 "code needs relocation information");
duke@435 321 // leave behind an indication that we attempted a relocation
duke@435 322 DEBUG_ONLY(_locs_start = _locs_limit = (relocInfo*)badAddress);
duke@435 323 return;
duke@435 324 }
duke@435 325
duke@435 326 // Advance the point, noting the offset we'll have to record.
duke@435 327 csize_t offset = at - locs_point();
duke@435 328 set_locs_point(at);
duke@435 329
duke@435 330 // Test for a couple of overflow conditions; maybe expand the buffer.
duke@435 331 relocInfo* end = locs_end();
duke@435 332 relocInfo* req = end + relocInfo::length_limit;
duke@435 333 // Check for (potential) overflow
duke@435 334 if (req >= locs_limit() || offset >= relocInfo::offset_limit()) {
duke@435 335 req += (uint)offset / (uint)relocInfo::offset_limit();
duke@435 336 if (req >= locs_limit()) {
duke@435 337 // Allocate or reallocate.
duke@435 338 expand_locs(locs_count() + (req - end));
duke@435 339 // reload pointer
duke@435 340 end = locs_end();
duke@435 341 }
duke@435 342 }
duke@435 343
duke@435 344 // If the offset is giant, emit filler relocs, of type 'none', but
duke@435 345 // each carrying the largest possible offset, to advance the locs_point.
duke@435 346 while (offset >= relocInfo::offset_limit()) {
duke@435 347 assert(end < locs_limit(), "adjust previous paragraph of code");
duke@435 348 *end++ = filler_relocInfo();
duke@435 349 offset -= filler_relocInfo().addr_offset();
duke@435 350 }
duke@435 351
duke@435 352 // If it's a simple reloc with no data, we'll just write (rtype | offset).
duke@435 353 (*end) = relocInfo(rtype, offset, format);
duke@435 354
duke@435 355 // If it has data, insert the prefix, as (data_prefix_tag | data1), data2.
duke@435 356 end->initialize(this, reloc);
duke@435 357 }
duke@435 358
duke@435 359 void CodeSection::initialize_locs(int locs_capacity) {
duke@435 360 assert(_locs_start == NULL, "only one locs init step, please");
duke@435 361 // Apply a priori lower limits to relocation size:
duke@435 362 csize_t min_locs = MAX2(size() / 16, (csize_t)4);
duke@435 363 if (locs_capacity < min_locs) locs_capacity = min_locs;
duke@435 364 relocInfo* locs_start = NEW_RESOURCE_ARRAY(relocInfo, locs_capacity);
duke@435 365 _locs_start = locs_start;
duke@435 366 _locs_end = locs_start;
duke@435 367 _locs_limit = locs_start + locs_capacity;
duke@435 368 _locs_own = true;
duke@435 369 }
duke@435 370
duke@435 371 void CodeSection::initialize_shared_locs(relocInfo* buf, int length) {
duke@435 372 assert(_locs_start == NULL, "do this before locs are allocated");
duke@435 373 // Internal invariant: locs buf must be fully aligned.
duke@435 374 // See copy_relocations_to() below.
duke@435 375 while ((uintptr_t)buf % HeapWordSize != 0 && length > 0) {
duke@435 376 ++buf; --length;
duke@435 377 }
duke@435 378 if (length > 0) {
duke@435 379 _locs_start = buf;
duke@435 380 _locs_end = buf;
duke@435 381 _locs_limit = buf + length;
duke@435 382 _locs_own = false;
duke@435 383 }
duke@435 384 }
duke@435 385
duke@435 386 void CodeSection::initialize_locs_from(const CodeSection* source_cs) {
duke@435 387 int lcount = source_cs->locs_count();
duke@435 388 if (lcount != 0) {
duke@435 389 initialize_shared_locs(source_cs->locs_start(), lcount);
duke@435 390 _locs_end = _locs_limit = _locs_start + lcount;
duke@435 391 assert(is_allocated(), "must have copied code already");
duke@435 392 set_locs_point(start() + source_cs->locs_point_off());
duke@435 393 }
duke@435 394 assert(this->locs_count() == source_cs->locs_count(), "sanity");
duke@435 395 }
duke@435 396
duke@435 397 void CodeSection::expand_locs(int new_capacity) {
duke@435 398 if (_locs_start == NULL) {
duke@435 399 initialize_locs(new_capacity);
duke@435 400 return;
duke@435 401 } else {
duke@435 402 int old_count = locs_count();
duke@435 403 int old_capacity = locs_capacity();
duke@435 404 if (new_capacity < old_capacity * 2)
duke@435 405 new_capacity = old_capacity * 2;
duke@435 406 relocInfo* locs_start;
duke@435 407 if (_locs_own) {
duke@435 408 locs_start = REALLOC_RESOURCE_ARRAY(relocInfo, _locs_start, old_capacity, new_capacity);
duke@435 409 } else {
duke@435 410 locs_start = NEW_RESOURCE_ARRAY(relocInfo, new_capacity);
kvn@1958 411 Copy::conjoint_jbytes(_locs_start, locs_start, old_capacity * sizeof(relocInfo));
duke@435 412 _locs_own = true;
duke@435 413 }
duke@435 414 _locs_start = locs_start;
duke@435 415 _locs_end = locs_start + old_count;
duke@435 416 _locs_limit = locs_start + new_capacity;
duke@435 417 }
duke@435 418 }
duke@435 419
duke@435 420
duke@435 421 /// Support for emitting the code to its final location.
duke@435 422 /// The pattern is the same for all functions.
duke@435 423 /// We iterate over all the sections, padding each to alignment.
duke@435 424
duke@435 425 csize_t CodeBuffer::total_code_size() const {
duke@435 426 csize_t code_size_so_far = 0;
duke@435 427 for (int n = 0; n < (int)SECT_LIMIT; n++) {
duke@435 428 const CodeSection* cs = code_section(n);
duke@435 429 if (cs->is_empty()) continue; // skip trivial section
duke@435 430 code_size_so_far = cs->align_at_start(code_size_so_far);
duke@435 431 code_size_so_far += cs->size();
duke@435 432 }
duke@435 433 return code_size_so_far;
duke@435 434 }
duke@435 435
duke@435 436 void CodeBuffer::compute_final_layout(CodeBuffer* dest) const {
duke@435 437 address buf = dest->_total_start;
duke@435 438 csize_t buf_offset = 0;
duke@435 439 assert(dest->_total_size >= total_code_size(), "must be big enough");
duke@435 440
duke@435 441 {
duke@435 442 // not sure why this is here, but why not...
duke@435 443 int alignSize = MAX2((intx) sizeof(jdouble), CodeEntryAlignment);
duke@435 444 assert( (dest->_total_start - _insts.start()) % alignSize == 0, "copy must preserve alignment");
duke@435 445 }
duke@435 446
duke@435 447 const CodeSection* prev_cs = NULL;
duke@435 448 CodeSection* prev_dest_cs = NULL;
duke@435 449 for (int n = 0; n < (int)SECT_LIMIT; n++) {
duke@435 450 // figure compact layout of each section
duke@435 451 const CodeSection* cs = code_section(n);
duke@435 452 address cstart = cs->start();
duke@435 453 address cend = cs->end();
duke@435 454 csize_t csize = cend - cstart;
duke@435 455
duke@435 456 CodeSection* dest_cs = dest->code_section(n);
duke@435 457 if (!cs->is_empty()) {
duke@435 458 // Compute initial padding; assign it to the previous non-empty guy.
duke@435 459 // Cf. figure_expanded_capacities.
duke@435 460 csize_t padding = cs->align_at_start(buf_offset) - buf_offset;
duke@435 461 if (padding != 0) {
duke@435 462 buf_offset += padding;
duke@435 463 assert(prev_dest_cs != NULL, "sanity");
duke@435 464 prev_dest_cs->_limit += padding;
duke@435 465 }
duke@435 466 #ifdef ASSERT
duke@435 467 if (prev_cs != NULL && prev_cs->is_frozen() && n < SECT_CONSTS) {
duke@435 468 // Make sure the ends still match up.
duke@435 469 // This is important because a branch in a frozen section
duke@435 470 // might target code in a following section, via a Label,
duke@435 471 // and without a relocation record. See Label::patch_instructions.
duke@435 472 address dest_start = buf+buf_offset;
duke@435 473 csize_t start2start = cs->start() - prev_cs->start();
duke@435 474 csize_t dest_start2start = dest_start - prev_dest_cs->start();
duke@435 475 assert(start2start == dest_start2start, "cannot stretch frozen sect");
duke@435 476 }
duke@435 477 #endif //ASSERT
duke@435 478 prev_dest_cs = dest_cs;
duke@435 479 prev_cs = cs;
duke@435 480 }
duke@435 481
duke@435 482 debug_only(dest_cs->_start = NULL); // defeat double-initialization assert
duke@435 483 dest_cs->initialize(buf+buf_offset, csize);
duke@435 484 dest_cs->set_end(buf+buf_offset+csize);
duke@435 485 assert(dest_cs->is_allocated(), "must always be allocated");
duke@435 486 assert(cs->is_empty() == dest_cs->is_empty(), "sanity");
duke@435 487
duke@435 488 buf_offset += csize;
duke@435 489 }
duke@435 490
duke@435 491 // Done calculating sections; did it come out to the right end?
duke@435 492 assert(buf_offset == total_code_size(), "sanity");
duke@435 493 assert(dest->verify_section_allocation(), "final configuration works");
duke@435 494 }
duke@435 495
duke@435 496 csize_t CodeBuffer::total_offset_of(address addr) const {
duke@435 497 csize_t code_size_so_far = 0;
duke@435 498 for (int n = 0; n < (int)SECT_LIMIT; n++) {
duke@435 499 const CodeSection* cs = code_section(n);
duke@435 500 if (!cs->is_empty()) {
duke@435 501 code_size_so_far = cs->align_at_start(code_size_so_far);
duke@435 502 }
duke@435 503 if (cs->contains2(addr)) {
duke@435 504 return code_size_so_far + (addr - cs->start());
duke@435 505 }
duke@435 506 code_size_so_far += cs->size();
duke@435 507 }
duke@435 508 #ifndef PRODUCT
duke@435 509 tty->print_cr("Dangling address " PTR_FORMAT " in:", addr);
duke@435 510 ((CodeBuffer*)this)->print();
duke@435 511 #endif
duke@435 512 ShouldNotReachHere();
duke@435 513 return -1;
duke@435 514 }
duke@435 515
duke@435 516 csize_t CodeBuffer::total_relocation_size() const {
duke@435 517 csize_t lsize = copy_relocations_to(NULL); // dry run only
duke@435 518 csize_t csize = total_code_size();
duke@435 519 csize_t total = RelocIterator::locs_and_index_size(csize, lsize);
duke@435 520 return (csize_t) align_size_up(total, HeapWordSize);
duke@435 521 }
duke@435 522
duke@435 523 csize_t CodeBuffer::copy_relocations_to(CodeBlob* dest) const {
duke@435 524 address buf = NULL;
duke@435 525 csize_t buf_offset = 0;
duke@435 526 csize_t buf_limit = 0;
duke@435 527 if (dest != NULL) {
duke@435 528 buf = (address)dest->relocation_begin();
duke@435 529 buf_limit = (address)dest->relocation_end() - buf;
duke@435 530 assert((uintptr_t)buf % HeapWordSize == 0, "buf must be fully aligned");
duke@435 531 assert(buf_limit % HeapWordSize == 0, "buf must be evenly sized");
duke@435 532 }
duke@435 533 // if dest == NULL, this is just the sizing pass
duke@435 534
duke@435 535 csize_t code_end_so_far = 0;
duke@435 536 csize_t code_point_so_far = 0;
duke@435 537 for (int n = 0; n < (int)SECT_LIMIT; n++) {
duke@435 538 // pull relocs out of each section
duke@435 539 const CodeSection* cs = code_section(n);
duke@435 540 assert(!(cs->is_empty() && cs->locs_count() > 0), "sanity");
duke@435 541 if (cs->is_empty()) continue; // skip trivial section
duke@435 542 relocInfo* lstart = cs->locs_start();
duke@435 543 relocInfo* lend = cs->locs_end();
duke@435 544 csize_t lsize = (csize_t)( (address)lend - (address)lstart );
duke@435 545 csize_t csize = cs->size();
duke@435 546 code_end_so_far = cs->align_at_start(code_end_so_far);
duke@435 547
duke@435 548 if (lsize > 0) {
duke@435 549 // Figure out how to advance the combined relocation point
duke@435 550 // first to the beginning of this section.
duke@435 551 // We'll insert one or more filler relocs to span that gap.
duke@435 552 // (Don't bother to improve this by editing the first reloc's offset.)
duke@435 553 csize_t new_code_point = code_end_so_far;
duke@435 554 for (csize_t jump;
duke@435 555 code_point_so_far < new_code_point;
duke@435 556 code_point_so_far += jump) {
duke@435 557 jump = new_code_point - code_point_so_far;
duke@435 558 relocInfo filler = filler_relocInfo();
duke@435 559 if (jump >= filler.addr_offset()) {
duke@435 560 jump = filler.addr_offset();
duke@435 561 } else { // else shrink the filler to fit
duke@435 562 filler = relocInfo(relocInfo::none, jump);
duke@435 563 }
duke@435 564 if (buf != NULL) {
duke@435 565 assert(buf_offset + (csize_t)sizeof(filler) <= buf_limit, "filler in bounds");
duke@435 566 *(relocInfo*)(buf+buf_offset) = filler;
duke@435 567 }
duke@435 568 buf_offset += sizeof(filler);
duke@435 569 }
duke@435 570
duke@435 571 // Update code point and end to skip past this section:
duke@435 572 csize_t last_code_point = code_end_so_far + cs->locs_point_off();
duke@435 573 assert(code_point_so_far <= last_code_point, "sanity");
duke@435 574 code_point_so_far = last_code_point; // advance past this guy's relocs
duke@435 575 }
duke@435 576 code_end_so_far += csize; // advance past this guy's instructions too
duke@435 577
duke@435 578 // Done with filler; emit the real relocations:
duke@435 579 if (buf != NULL && lsize != 0) {
duke@435 580 assert(buf_offset + lsize <= buf_limit, "target in bounds");
duke@435 581 assert((uintptr_t)lstart % HeapWordSize == 0, "sane start");
duke@435 582 if (buf_offset % HeapWordSize == 0) {
duke@435 583 // Use wordwise copies if possible:
duke@435 584 Copy::disjoint_words((HeapWord*)lstart,
duke@435 585 (HeapWord*)(buf+buf_offset),
duke@435 586 (lsize + HeapWordSize-1) / HeapWordSize);
duke@435 587 } else {
kvn@1958 588 Copy::conjoint_jbytes(lstart, buf+buf_offset, lsize);
duke@435 589 }
duke@435 590 }
duke@435 591 buf_offset += lsize;
duke@435 592 }
duke@435 593
duke@435 594 // Align end of relocation info in target.
duke@435 595 while (buf_offset % HeapWordSize != 0) {
duke@435 596 if (buf != NULL) {
duke@435 597 relocInfo padding = relocInfo(relocInfo::none, 0);
duke@435 598 assert(buf_offset + (csize_t)sizeof(padding) <= buf_limit, "padding in bounds");
duke@435 599 *(relocInfo*)(buf+buf_offset) = padding;
duke@435 600 }
duke@435 601 buf_offset += sizeof(relocInfo);
duke@435 602 }
duke@435 603
duke@435 604 assert(code_end_so_far == total_code_size(), "sanity");
duke@435 605
duke@435 606 // Account for index:
duke@435 607 if (buf != NULL) {
duke@435 608 RelocIterator::create_index(dest->relocation_begin(),
duke@435 609 buf_offset / sizeof(relocInfo),
duke@435 610 dest->relocation_end());
duke@435 611 }
duke@435 612
duke@435 613 return buf_offset;
duke@435 614 }
duke@435 615
duke@435 616 void CodeBuffer::copy_code_to(CodeBlob* dest_blob) {
duke@435 617 #ifndef PRODUCT
duke@435 618 if (PrintNMethods && (WizardMode || Verbose)) {
duke@435 619 tty->print("done with CodeBuffer:");
duke@435 620 ((CodeBuffer*)this)->print();
duke@435 621 }
duke@435 622 #endif //PRODUCT
duke@435 623
duke@435 624 CodeBuffer dest(dest_blob->instructions_begin(),
duke@435 625 dest_blob->instructions_size());
duke@435 626 assert(dest_blob->instructions_size() >= total_code_size(), "good sizing");
duke@435 627 this->compute_final_layout(&dest);
duke@435 628 relocate_code_to(&dest);
duke@435 629
duke@435 630 // transfer comments from buffer to blob
duke@435 631 dest_blob->set_comments(_comments);
duke@435 632
duke@435 633 // Done moving code bytes; were they the right size?
duke@435 634 assert(round_to(dest.total_code_size(), oopSize) == dest_blob->instructions_size(), "sanity");
duke@435 635
duke@435 636 // Flush generated code
duke@435 637 ICache::invalidate_range(dest_blob->instructions_begin(),
duke@435 638 dest_blob->instructions_size());
duke@435 639 }
duke@435 640
duke@435 641 // Move all my code into another code buffer.
duke@435 642 // Consult applicable relocs to repair embedded addresses.
duke@435 643 void CodeBuffer::relocate_code_to(CodeBuffer* dest) const {
duke@435 644 DEBUG_ONLY(address dest_end = dest->_total_start + dest->_total_size);
duke@435 645 for (int n = 0; n < (int)SECT_LIMIT; n++) {
duke@435 646 // pull code out of each section
duke@435 647 const CodeSection* cs = code_section(n);
duke@435 648 if (cs->is_empty()) continue; // skip trivial section
duke@435 649 CodeSection* dest_cs = dest->code_section(n);
duke@435 650 assert(cs->size() == dest_cs->size(), "sanity");
duke@435 651 csize_t usize = dest_cs->size();
duke@435 652 csize_t wsize = align_size_up(usize, HeapWordSize);
duke@435 653 assert(dest_cs->start() + wsize <= dest_end, "no overflow");
duke@435 654 // Copy the code as aligned machine words.
duke@435 655 // This may also include an uninitialized partial word at the end.
duke@435 656 Copy::disjoint_words((HeapWord*)cs->start(),
duke@435 657 (HeapWord*)dest_cs->start(),
duke@435 658 wsize / HeapWordSize);
duke@435 659
duke@435 660 if (dest->blob() == NULL) {
duke@435 661 // Destination is a final resting place, not just another buffer.
duke@435 662 // Normalize uninitialized bytes in the final padding.
duke@435 663 Copy::fill_to_bytes(dest_cs->end(), dest_cs->remaining(),
duke@435 664 Assembler::code_fill_byte());
duke@435 665 }
duke@435 666
duke@435 667 assert(cs->locs_start() != (relocInfo*)badAddress,
duke@435 668 "this section carries no reloc storage, but reloc was attempted");
duke@435 669
duke@435 670 // Make the new code copy use the old copy's relocations:
duke@435 671 dest_cs->initialize_locs_from(cs);
duke@435 672
duke@435 673 { // Repair the pc relative information in the code after the move
duke@435 674 RelocIterator iter(dest_cs);
duke@435 675 while (iter.next()) {
duke@435 676 iter.reloc()->fix_relocation_after_move(this, dest);
duke@435 677 }
duke@435 678 }
duke@435 679 }
duke@435 680 }
duke@435 681
duke@435 682 csize_t CodeBuffer::figure_expanded_capacities(CodeSection* which_cs,
duke@435 683 csize_t amount,
duke@435 684 csize_t* new_capacity) {
duke@435 685 csize_t new_total_cap = 0;
duke@435 686
duke@435 687 int prev_n = -1;
duke@435 688 for (int n = 0; n < (int)SECT_LIMIT; n++) {
duke@435 689 const CodeSection* sect = code_section(n);
duke@435 690
duke@435 691 if (!sect->is_empty()) {
duke@435 692 // Compute initial padding; assign it to the previous non-empty guy.
duke@435 693 // Cf. compute_final_layout.
duke@435 694 csize_t padding = sect->align_at_start(new_total_cap) - new_total_cap;
duke@435 695 if (padding != 0) {
duke@435 696 new_total_cap += padding;
duke@435 697 assert(prev_n >= 0, "sanity");
duke@435 698 new_capacity[prev_n] += padding;
duke@435 699 }
duke@435 700 prev_n = n;
duke@435 701 }
duke@435 702
duke@435 703 csize_t exp = sect->size(); // 100% increase
duke@435 704 if ((uint)exp < 4*K) exp = 4*K; // minimum initial increase
duke@435 705 if (sect == which_cs) {
duke@435 706 if (exp < amount) exp = amount;
duke@435 707 if (StressCodeBuffers) exp = amount; // expand only slightly
duke@435 708 } else if (n == SECT_INSTS) {
duke@435 709 // scale down inst increases to a more modest 25%
duke@435 710 exp = 4*K + ((exp - 4*K) >> 2);
duke@435 711 if (StressCodeBuffers) exp = amount / 2; // expand only slightly
duke@435 712 } else if (sect->is_empty()) {
duke@435 713 // do not grow an empty secondary section
duke@435 714 exp = 0;
duke@435 715 }
duke@435 716 // Allow for inter-section slop:
duke@435 717 exp += CodeSection::end_slop();
duke@435 718 csize_t new_cap = sect->size() + exp;
duke@435 719 if (new_cap < sect->capacity()) {
duke@435 720 // No need to expand after all.
duke@435 721 new_cap = sect->capacity();
duke@435 722 }
duke@435 723 new_capacity[n] = new_cap;
duke@435 724 new_total_cap += new_cap;
duke@435 725 }
duke@435 726
duke@435 727 return new_total_cap;
duke@435 728 }
duke@435 729
duke@435 730 void CodeBuffer::expand(CodeSection* which_cs, csize_t amount) {
duke@435 731 #ifndef PRODUCT
duke@435 732 if (PrintNMethods && (WizardMode || Verbose)) {
duke@435 733 tty->print("expanding CodeBuffer:");
duke@435 734 this->print();
duke@435 735 }
duke@435 736
duke@435 737 if (StressCodeBuffers && blob() != NULL) {
duke@435 738 static int expand_count = 0;
duke@435 739 if (expand_count >= 0) expand_count += 1;
duke@435 740 if (expand_count > 100 && is_power_of_2(expand_count)) {
duke@435 741 tty->print_cr("StressCodeBuffers: have expanded %d times", expand_count);
duke@435 742 // simulate an occasional allocation failure:
duke@435 743 free_blob();
duke@435 744 }
duke@435 745 }
duke@435 746 #endif //PRODUCT
duke@435 747
duke@435 748 // Resizing must be allowed
duke@435 749 {
duke@435 750 if (blob() == NULL) return; // caller must check for blob == NULL
duke@435 751 for (int n = 0; n < (int)SECT_LIMIT; n++) {
duke@435 752 guarantee(!code_section(n)->is_frozen(), "resizing not allowed when frozen");
duke@435 753 }
duke@435 754 }
duke@435 755
duke@435 756 // Figure new capacity for each section.
duke@435 757 csize_t new_capacity[SECT_LIMIT];
duke@435 758 csize_t new_total_cap
duke@435 759 = figure_expanded_capacities(which_cs, amount, new_capacity);
duke@435 760
duke@435 761 // Create a new (temporary) code buffer to hold all the new data
duke@435 762 CodeBuffer cb(name(), new_total_cap, 0);
duke@435 763 if (cb.blob() == NULL) {
duke@435 764 // Failed to allocate in code cache.
duke@435 765 free_blob();
duke@435 766 return;
duke@435 767 }
duke@435 768
duke@435 769 // Create an old code buffer to remember which addresses used to go where.
duke@435 770 // This will be useful when we do final assembly into the code cache,
duke@435 771 // because we will need to know how to warp any internal address that
duke@435 772 // has been created at any time in this CodeBuffer's past.
duke@435 773 CodeBuffer* bxp = new CodeBuffer(_total_start, _total_size);
duke@435 774 bxp->take_over_code_from(this); // remember the old undersized blob
duke@435 775 DEBUG_ONLY(this->_blob = NULL); // silence a later assert
duke@435 776 bxp->_before_expand = this->_before_expand;
duke@435 777 this->_before_expand = bxp;
duke@435 778
duke@435 779 // Give each section its required (expanded) capacity.
duke@435 780 for (int n = (int)SECT_LIMIT-1; n >= SECT_INSTS; n--) {
duke@435 781 CodeSection* cb_sect = cb.code_section(n);
duke@435 782 CodeSection* this_sect = code_section(n);
duke@435 783 if (new_capacity[n] == 0) continue; // already nulled out
duke@435 784 if (n > SECT_INSTS) {
duke@435 785 cb.initialize_section_size(cb_sect, new_capacity[n]);
duke@435 786 }
duke@435 787 assert(cb_sect->capacity() >= new_capacity[n], "big enough");
duke@435 788 address cb_start = cb_sect->start();
duke@435 789 cb_sect->set_end(cb_start + this_sect->size());
duke@435 790 if (this_sect->mark() == NULL) {
duke@435 791 cb_sect->clear_mark();
duke@435 792 } else {
duke@435 793 cb_sect->set_mark(cb_start + this_sect->mark_off());
duke@435 794 }
duke@435 795 }
duke@435 796
duke@435 797 // Move all the code and relocations to the new blob:
duke@435 798 relocate_code_to(&cb);
duke@435 799
duke@435 800 // Copy the temporary code buffer into the current code buffer.
duke@435 801 // Basically, do {*this = cb}, except for some control information.
duke@435 802 this->take_over_code_from(&cb);
duke@435 803 cb.set_blob(NULL);
duke@435 804
duke@435 805 // Zap the old code buffer contents, to avoid mistakenly using them.
duke@435 806 debug_only(Copy::fill_to_bytes(bxp->_total_start, bxp->_total_size,
duke@435 807 badCodeHeapFreeVal));
duke@435 808
duke@435 809 _decode_begin = NULL; // sanity
duke@435 810
duke@435 811 // Make certain that the new sections are all snugly inside the new blob.
duke@435 812 assert(verify_section_allocation(), "expanded allocation is ship-shape");
duke@435 813
duke@435 814 #ifndef PRODUCT
duke@435 815 if (PrintNMethods && (WizardMode || Verbose)) {
duke@435 816 tty->print("expanded CodeBuffer:");
duke@435 817 this->print();
duke@435 818 }
duke@435 819 #endif //PRODUCT
duke@435 820 }
duke@435 821
duke@435 822 void CodeBuffer::take_over_code_from(CodeBuffer* cb) {
duke@435 823 // Must already have disposed of the old blob somehow.
duke@435 824 assert(blob() == NULL, "must be empty");
duke@435 825 #ifdef ASSERT
duke@435 826
duke@435 827 #endif
duke@435 828 // Take the new blob away from cb.
duke@435 829 set_blob(cb->blob());
duke@435 830 // Take over all the section pointers.
duke@435 831 for (int n = 0; n < (int)SECT_LIMIT; n++) {
duke@435 832 CodeSection* cb_sect = cb->code_section(n);
duke@435 833 CodeSection* this_sect = code_section(n);
duke@435 834 this_sect->take_over_code_from(cb_sect);
duke@435 835 }
duke@435 836 _overflow_arena = cb->_overflow_arena;
duke@435 837 // Make sure the old cb won't try to use it or free it.
duke@435 838 DEBUG_ONLY(cb->_blob = (BufferBlob*)badAddress);
duke@435 839 }
duke@435 840
duke@435 841 #ifdef ASSERT
duke@435 842 bool CodeBuffer::verify_section_allocation() {
duke@435 843 address tstart = _total_start;
duke@435 844 if (tstart == badAddress) return true; // smashed by set_blob(NULL)
duke@435 845 address tend = tstart + _total_size;
duke@435 846 if (_blob != NULL) {
duke@435 847 assert(tstart >= _blob->instructions_begin(), "sanity");
duke@435 848 assert(tend <= _blob->instructions_end(), "sanity");
duke@435 849 }
duke@435 850 address tcheck = tstart; // advancing pointer to verify disjointness
duke@435 851 for (int n = 0; n < (int)SECT_LIMIT; n++) {
duke@435 852 CodeSection* sect = code_section(n);
duke@435 853 if (!sect->is_allocated()) continue;
duke@435 854 assert(sect->start() >= tcheck, "sanity");
duke@435 855 tcheck = sect->start();
duke@435 856 assert((intptr_t)tcheck % sect->alignment() == 0
duke@435 857 || sect->is_empty() || _blob == NULL,
duke@435 858 "start is aligned");
duke@435 859 assert(sect->end() >= tcheck, "sanity");
duke@435 860 assert(sect->end() <= tend, "sanity");
duke@435 861 }
duke@435 862 return true;
duke@435 863 }
duke@435 864 #endif //ASSERT
duke@435 865
duke@435 866 #ifndef PRODUCT
duke@435 867
duke@435 868 void CodeSection::dump() {
duke@435 869 address ptr = start();
duke@435 870 for (csize_t step; ptr < end(); ptr += step) {
duke@435 871 step = end() - ptr;
duke@435 872 if (step > jintSize * 4) step = jintSize * 4;
duke@435 873 tty->print(PTR_FORMAT ": ", ptr);
duke@435 874 while (step > 0) {
duke@435 875 tty->print(" " PTR32_FORMAT, *(jint*)ptr);
duke@435 876 ptr += jintSize;
duke@435 877 }
duke@435 878 tty->cr();
duke@435 879 }
duke@435 880 }
duke@435 881
duke@435 882
duke@435 883 void CodeSection::decode() {
duke@435 884 Disassembler::decode(start(), end());
duke@435 885 }
duke@435 886
duke@435 887
duke@435 888 void CodeBuffer::block_comment(intptr_t offset, const char * comment) {
duke@435 889 _comments.add_comment(offset, comment);
duke@435 890 }
duke@435 891
duke@435 892
duke@435 893 class CodeComment: public CHeapObj {
duke@435 894 private:
duke@435 895 friend class CodeComments;
duke@435 896 intptr_t _offset;
duke@435 897 const char * _comment;
duke@435 898 CodeComment* _next;
duke@435 899
duke@435 900 ~CodeComment() {
duke@435 901 assert(_next == NULL, "wrong interface for freeing list");
duke@435 902 os::free((void*)_comment);
duke@435 903 }
duke@435 904
duke@435 905 public:
duke@435 906 CodeComment(intptr_t offset, const char * comment) {
duke@435 907 _offset = offset;
duke@435 908 _comment = os::strdup(comment);
duke@435 909 _next = NULL;
duke@435 910 }
duke@435 911
duke@435 912 intptr_t offset() const { return _offset; }
duke@435 913 const char * comment() const { return _comment; }
duke@435 914 CodeComment* next() { return _next; }
duke@435 915
duke@435 916 void set_next(CodeComment* next) { _next = next; }
duke@435 917
duke@435 918 CodeComment* find(intptr_t offset) {
duke@435 919 CodeComment* a = this;
duke@435 920 while (a != NULL && a->_offset != offset) {
duke@435 921 a = a->_next;
duke@435 922 }
duke@435 923 return a;
duke@435 924 }
duke@435 925 };
duke@435 926
duke@435 927
duke@435 928 void CodeComments::add_comment(intptr_t offset, const char * comment) {
duke@435 929 CodeComment* c = new CodeComment(offset, comment);
duke@435 930 CodeComment* insert = NULL;
duke@435 931 if (_comments != NULL) {
duke@435 932 CodeComment* c = _comments->find(offset);
duke@435 933 insert = c;
duke@435 934 while (c && c->offset() == offset) {
duke@435 935 insert = c;
duke@435 936 c = c->next();
duke@435 937 }
duke@435 938 }
duke@435 939 if (insert) {
duke@435 940 // insert after comments with same offset
duke@435 941 c->set_next(insert->next());
duke@435 942 insert->set_next(c);
duke@435 943 } else {
duke@435 944 c->set_next(_comments);
duke@435 945 _comments = c;
duke@435 946 }
duke@435 947 }
duke@435 948
duke@435 949
duke@435 950 void CodeComments::assign(CodeComments& other) {
duke@435 951 assert(_comments == NULL, "don't overwrite old value");
duke@435 952 _comments = other._comments;
duke@435 953 }
duke@435 954
duke@435 955
duke@435 956 void CodeComments::print_block_comment(outputStream* stream, intptr_t offset) {
duke@435 957 if (_comments != NULL) {
duke@435 958 CodeComment* c = _comments->find(offset);
duke@435 959 while (c && c->offset() == offset) {
jrose@535 960 stream->bol();
duke@435 961 stream->print(" ;; ");
duke@435 962 stream->print_cr(c->comment());
duke@435 963 c = c->next();
duke@435 964 }
duke@435 965 }
duke@435 966 }
duke@435 967
duke@435 968
duke@435 969 void CodeComments::free() {
duke@435 970 CodeComment* n = _comments;
duke@435 971 while (n) {
duke@435 972 // unlink the node from the list saving a pointer to the next
duke@435 973 CodeComment* p = n->_next;
duke@435 974 n->_next = NULL;
duke@435 975 delete n;
duke@435 976 n = p;
duke@435 977 }
duke@435 978 _comments = NULL;
duke@435 979 }
duke@435 980
duke@435 981
duke@435 982
duke@435 983 void CodeBuffer::decode() {
duke@435 984 Disassembler::decode(decode_begin(), code_end());
duke@435 985 _decode_begin = code_end();
duke@435 986 }
duke@435 987
duke@435 988
duke@435 989 void CodeBuffer::skip_decode() {
duke@435 990 _decode_begin = code_end();
duke@435 991 }
duke@435 992
duke@435 993
duke@435 994 void CodeBuffer::decode_all() {
duke@435 995 for (int n = 0; n < (int)SECT_LIMIT; n++) {
duke@435 996 // dump contents of each section
duke@435 997 CodeSection* cs = code_section(n);
duke@435 998 tty->print_cr("! %s:", code_section_name(n));
duke@435 999 if (cs != consts())
duke@435 1000 cs->decode();
duke@435 1001 else
duke@435 1002 cs->dump();
duke@435 1003 }
duke@435 1004 }
duke@435 1005
duke@435 1006
duke@435 1007 void CodeSection::print(const char* name) {
duke@435 1008 csize_t locs_size = locs_end() - locs_start();
duke@435 1009 tty->print_cr(" %7s.code = " PTR_FORMAT " : " PTR_FORMAT " : " PTR_FORMAT " (%d of %d)%s",
duke@435 1010 name, start(), end(), limit(), size(), capacity(),
duke@435 1011 is_frozen()? " [frozen]": "");
duke@435 1012 tty->print_cr(" %7s.locs = " PTR_FORMAT " : " PTR_FORMAT " : " PTR_FORMAT " (%d of %d) point=%d",
duke@435 1013 name, locs_start(), locs_end(), locs_limit(), locs_size, locs_capacity(), locs_point_off());
duke@435 1014 if (PrintRelocations) {
duke@435 1015 RelocIterator iter(this);
duke@435 1016 iter.print();
duke@435 1017 }
duke@435 1018 }
duke@435 1019
duke@435 1020 void CodeBuffer::print() {
duke@435 1021 if (this == NULL) {
duke@435 1022 tty->print_cr("NULL CodeBuffer pointer");
duke@435 1023 return;
duke@435 1024 }
duke@435 1025
duke@435 1026 tty->print_cr("CodeBuffer:");
duke@435 1027 for (int n = 0; n < (int)SECT_LIMIT; n++) {
duke@435 1028 // print each section
duke@435 1029 CodeSection* cs = code_section(n);
duke@435 1030 cs->print(code_section_name(n));
duke@435 1031 }
duke@435 1032 }
duke@435 1033
duke@435 1034 #endif // PRODUCT

mercurial