src/share/vm/asm/codeBuffer.cpp

Sun, 13 Apr 2008 17:43:42 -0400

author
coleenp
date
Sun, 13 Apr 2008 17:43:42 -0400
changeset 548
ba764ed4b6f2
parent 535
c7c777385a15
child 631
d1605aabd0a1
permissions
-rw-r--r--

6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
Summary: Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv
Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold

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

mercurial