src/share/vm/asm/codeBuffer.cpp

Mon, 01 Feb 2010 19:29:46 +0100

author
twisti
date
Mon, 01 Feb 2010 19:29:46 +0100
changeset 1639
18a389214829
parent 1014
0fbdb4381b99
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6921352: JSR 292 needs its own deopt handler
Summary: We need to introduce a new MH deopt handler so we can easily determine if the deopt happened at a MH call site or not.
Reviewed-by: never, jrose

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

mercurial