duke@435: /* coleenp@4037: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "asm/codeBuffer.hpp" stefank@2314: #include "compiler/disassembler.hpp" coleenp@4037: #include "memory/gcLocker.hpp" coleenp@4037: #include "oops/methodData.hpp" coleenp@4037: #include "oops/oop.inline.hpp" stefank@2314: #include "utilities/copy.hpp" never@3255: #include "utilities/xmlstream.hpp" duke@435: duke@435: // The structure of a CodeSection: duke@435: // duke@435: // _start -> +----------------+ duke@435: // | machine code...| duke@435: // _end -> |----------------| duke@435: // | | duke@435: // | (empty) | duke@435: // | | duke@435: // | | duke@435: // +----------------+ duke@435: // _limit -> | | duke@435: // duke@435: // _locs_start -> +----------------+ duke@435: // |reloc records...| duke@435: // |----------------| duke@435: // _locs_end -> | | duke@435: // | | duke@435: // | (empty) | duke@435: // | | duke@435: // | | duke@435: // +----------------+ duke@435: // _locs_limit -> | | duke@435: // The _end (resp. _limit) pointer refers to the first duke@435: // unused (resp. unallocated) byte. duke@435: duke@435: // The structure of the CodeBuffer while code is being accumulated: duke@435: // duke@435: // _total_start -> \ duke@435: // _insts._start -> +----------------+ duke@435: // | | duke@435: // | Code | duke@435: // | | duke@435: // _stubs._start -> |----------------| duke@435: // | | duke@435: // | Stubs | (also handlers for deopt/exception) duke@435: // | | duke@435: // _consts._start -> |----------------| duke@435: // | | duke@435: // | Constants | duke@435: // | | duke@435: // +----------------+ duke@435: // + _total_size -> | | duke@435: // duke@435: // When the code and relocations are copied to the code cache, duke@435: // the empty parts of each section are removed, and everything duke@435: // is copied into contiguous locations. duke@435: duke@435: typedef CodeBuffer::csize_t csize_t; // file-local definition duke@435: twisti@2103: // External buffer, in a predefined CodeBlob. duke@435: // Important: The code_start must be taken exactly, and not realigned. twisti@2103: CodeBuffer::CodeBuffer(CodeBlob* blob) { duke@435: initialize_misc("static buffer"); twisti@2103: initialize(blob->content_begin(), blob->content_size()); never@3255: verify_section_allocation(); duke@435: } duke@435: duke@435: void CodeBuffer::initialize(csize_t code_size, csize_t locs_size) { duke@435: // Compute maximal alignment. duke@435: int align = _insts.alignment(); duke@435: // Always allow for empty slop around each section. duke@435: int slop = (int) CodeSection::end_slop(); duke@435: duke@435: assert(blob() == NULL, "only once"); duke@435: set_blob(BufferBlob::create(_name, code_size + (align+slop) * (SECT_LIMIT+1))); duke@435: if (blob() == NULL) { duke@435: // The assembler constructor will throw a fatal on an empty CodeBuffer. duke@435: return; // caller must test this duke@435: } duke@435: duke@435: // Set up various pointers into the blob. duke@435: initialize(_total_start, _total_size); duke@435: twisti@2103: assert((uintptr_t)insts_begin() % CodeEntryAlignment == 0, "instruction start not code entry aligned"); duke@435: duke@435: pd_initialize(); duke@435: duke@435: if (locs_size != 0) { duke@435: _insts.initialize_locs(locs_size / sizeof(relocInfo)); duke@435: } duke@435: never@3255: verify_section_allocation(); duke@435: } duke@435: duke@435: duke@435: CodeBuffer::~CodeBuffer() { never@3255: verify_section_allocation(); never@3255: duke@435: // If we allocate our code buffer from the CodeCache duke@435: // via a BufferBlob, and it's not permanent, then duke@435: // free the BufferBlob. duke@435: // The rest of the memory will be freed when the ResourceObj duke@435: // is released. duke@435: for (CodeBuffer* cb = this; cb != NULL; cb = cb->before_expand()) { duke@435: // Previous incarnations of this buffer are held live, so that internal duke@435: // addresses constructed before expansions will not be confused. duke@435: cb->free_blob(); duke@435: } never@996: never@996: // free any overflow storage never@996: delete _overflow_arena; never@996: duke@435: #ifdef ASSERT kvn@2040: // Save allocation type to execute assert in ~ResourceObj() kvn@2040: // which is called after this destructor. kvn@2357: assert(_default_oop_recorder.allocated_on_stack(), "should be embedded object"); kvn@2040: ResourceObj::allocation_type at = _default_oop_recorder.get_allocation_type(); duke@435: Copy::fill_to_bytes(this, sizeof(*this), badResourceValue); kvn@2040: ResourceObj::set_allocation_type((address)(&_default_oop_recorder), at); duke@435: #endif duke@435: } duke@435: duke@435: void CodeBuffer::initialize_oop_recorder(OopRecorder* r) { duke@435: assert(_oop_recorder == &_default_oop_recorder && _default_oop_recorder.is_unused(), "do this once"); coleenp@4037: DEBUG_ONLY(_default_oop_recorder.freeze()); // force unused OR to be frozen duke@435: _oop_recorder = r; duke@435: } duke@435: duke@435: void CodeBuffer::initialize_section_size(CodeSection* cs, csize_t size) { duke@435: assert(cs != &_insts, "insts is the memory provider, not the consumer"); duke@435: csize_t slop = CodeSection::end_slop(); // margin between sections duke@435: int align = cs->alignment(); duke@435: assert(is_power_of_2(align), "sanity"); duke@435: address start = _insts._start; duke@435: address limit = _insts._limit; duke@435: address middle = limit - size; duke@435: middle -= (intptr_t)middle & (align-1); // align the division point downward duke@435: guarantee(middle - slop > start, "need enough space to divide up"); duke@435: _insts._limit = middle - slop; // subtract desired space, plus slop duke@435: cs->initialize(middle, limit - middle); duke@435: assert(cs->start() == middle, "sanity"); duke@435: assert(cs->limit() == limit, "sanity"); duke@435: // give it some relocations to start with, if the main section has them duke@435: if (_insts.has_locs()) cs->initialize_locs(1); duke@435: } duke@435: duke@435: void CodeBuffer::freeze_section(CodeSection* cs) { duke@435: CodeSection* next_cs = (cs == consts())? NULL: code_section(cs->index()+1); duke@435: csize_t frozen_size = cs->size(); duke@435: if (next_cs != NULL) { duke@435: frozen_size = next_cs->align_at_start(frozen_size); duke@435: } duke@435: address old_limit = cs->limit(); duke@435: address new_limit = cs->start() + frozen_size; duke@435: relocInfo* old_locs_limit = cs->locs_limit(); duke@435: relocInfo* new_locs_limit = cs->locs_end(); duke@435: // Patch the limits. duke@435: cs->_limit = new_limit; duke@435: cs->_locs_limit = new_locs_limit; duke@435: cs->_frozen = true; duke@435: if (!next_cs->is_allocated() && !next_cs->is_frozen()) { duke@435: // Give remaining buffer space to the following section. duke@435: next_cs->initialize(new_limit, old_limit - new_limit); duke@435: next_cs->initialize_shared_locs(new_locs_limit, duke@435: old_locs_limit - new_locs_limit); duke@435: } duke@435: } duke@435: duke@435: void CodeBuffer::set_blob(BufferBlob* blob) { duke@435: _blob = blob; duke@435: if (blob != NULL) { twisti@2103: address start = blob->content_begin(); twisti@2103: address end = blob->content_end(); duke@435: // Round up the starting address. duke@435: int align = _insts.alignment(); duke@435: start += (-(intptr_t)start) & (align-1); duke@435: _total_start = start; duke@435: _total_size = end - start; duke@435: } else { twisti@2117: #ifdef ASSERT duke@435: // Clean out dangling pointers. duke@435: _total_start = badAddress; twisti@2117: _consts._start = _consts._end = badAddress; duke@435: _insts._start = _insts._end = badAddress; duke@435: _stubs._start = _stubs._end = badAddress; twisti@2117: #endif //ASSERT duke@435: } duke@435: } duke@435: duke@435: void CodeBuffer::free_blob() { duke@435: if (_blob != NULL) { duke@435: BufferBlob::free(_blob); duke@435: set_blob(NULL); duke@435: } duke@435: } duke@435: duke@435: const char* CodeBuffer::code_section_name(int n) { duke@435: #ifdef PRODUCT duke@435: return NULL; duke@435: #else //PRODUCT duke@435: switch (n) { twisti@2117: case SECT_CONSTS: return "consts"; duke@435: case SECT_INSTS: return "insts"; duke@435: case SECT_STUBS: return "stubs"; duke@435: default: return NULL; duke@435: } duke@435: #endif //PRODUCT duke@435: } duke@435: duke@435: int CodeBuffer::section_index_of(address addr) const { duke@435: for (int n = 0; n < (int)SECT_LIMIT; n++) { duke@435: const CodeSection* cs = code_section(n); duke@435: if (cs->allocates(addr)) return n; duke@435: } duke@435: return SECT_NONE; duke@435: } duke@435: duke@435: int CodeBuffer::locator(address addr) const { duke@435: for (int n = 0; n < (int)SECT_LIMIT; n++) { duke@435: const CodeSection* cs = code_section(n); duke@435: if (cs->allocates(addr)) { duke@435: return locator(addr - cs->start(), n); duke@435: } duke@435: } duke@435: return -1; duke@435: } duke@435: duke@435: address CodeBuffer::locator_address(int locator) const { duke@435: if (locator < 0) return NULL; duke@435: address start = code_section(locator_sect(locator))->start(); duke@435: return start + locator_pos(locator); duke@435: } duke@435: twisti@4318: bool CodeBuffer::is_backward_branch(Label& L) { twisti@4318: return L.is_bound() && insts_end() <= locator_address(L.loc()); twisti@4318: } twisti@4318: duke@435: address CodeBuffer::decode_begin() { duke@435: address begin = _insts.start(); duke@435: if (_decode_begin != NULL && _decode_begin > begin) duke@435: begin = _decode_begin; duke@435: return begin; duke@435: } duke@435: duke@435: duke@435: GrowableArray* CodeBuffer::create_patch_overflow() { duke@435: if (_overflow_arena == NULL) { zgu@3900: _overflow_arena = new (mtCode) Arena(); duke@435: } duke@435: return new (_overflow_arena) GrowableArray(_overflow_arena, 8, 0, 0); duke@435: } duke@435: duke@435: duke@435: // Helper function for managing labels and their target addresses. duke@435: // Returns a sensible address, and if it is not the label's final duke@435: // address, notes the dependency (at 'branch_pc') on the label. duke@435: address CodeSection::target(Label& L, address branch_pc) { duke@435: if (L.is_bound()) { duke@435: int loc = L.loc(); duke@435: if (index() == CodeBuffer::locator_sect(loc)) { duke@435: return start() + CodeBuffer::locator_pos(loc); duke@435: } else { duke@435: return outer()->locator_address(loc); duke@435: } duke@435: } else { duke@435: assert(allocates2(branch_pc), "sanity"); duke@435: address base = start(); duke@435: int patch_loc = CodeBuffer::locator(branch_pc - base, index()); duke@435: L.add_patch_at(outer(), patch_loc); duke@435: duke@435: // Need to return a pc, doesn't matter what it is since it will be duke@435: // replaced during resolution later. coleenp@548: // Don't return NULL or badAddress, since branches shouldn't overflow. coleenp@548: // Don't return base either because that could overflow displacements coleenp@548: // for shorter branches. It will get checked when bound. coleenp@548: return branch_pc; duke@435: } duke@435: } duke@435: duke@435: void CodeSection::relocate(address at, RelocationHolder const& spec, int format) { duke@435: Relocation* reloc = spec.reloc(); duke@435: relocInfo::relocType rtype = (relocInfo::relocType) reloc->type(); duke@435: if (rtype == relocInfo::none) return; duke@435: duke@435: // The assertion below has been adjusted, to also work for duke@435: // relocation for fixup. Sometimes we want to put relocation duke@435: // information for the next instruction, since it will be patched duke@435: // with a call. duke@435: assert(start() <= at && at <= end()+1, duke@435: "cannot relocate data outside code boundaries"); duke@435: duke@435: if (!has_locs()) { duke@435: // no space for relocation information provided => code cannot be duke@435: // relocated. Make sure that relocate is only called with rtypes duke@435: // that can be ignored for this kind of code. duke@435: assert(rtype == relocInfo::none || duke@435: rtype == relocInfo::runtime_call_type || duke@435: rtype == relocInfo::internal_word_type|| duke@435: rtype == relocInfo::section_word_type || duke@435: rtype == relocInfo::external_word_type, duke@435: "code needs relocation information"); duke@435: // leave behind an indication that we attempted a relocation duke@435: DEBUG_ONLY(_locs_start = _locs_limit = (relocInfo*)badAddress); duke@435: return; duke@435: } duke@435: duke@435: // Advance the point, noting the offset we'll have to record. duke@435: csize_t offset = at - locs_point(); duke@435: set_locs_point(at); duke@435: duke@435: // Test for a couple of overflow conditions; maybe expand the buffer. duke@435: relocInfo* end = locs_end(); duke@435: relocInfo* req = end + relocInfo::length_limit; duke@435: // Check for (potential) overflow duke@435: if (req >= locs_limit() || offset >= relocInfo::offset_limit()) { duke@435: req += (uint)offset / (uint)relocInfo::offset_limit(); duke@435: if (req >= locs_limit()) { duke@435: // Allocate or reallocate. duke@435: expand_locs(locs_count() + (req - end)); duke@435: // reload pointer duke@435: end = locs_end(); duke@435: } duke@435: } duke@435: duke@435: // If the offset is giant, emit filler relocs, of type 'none', but duke@435: // each carrying the largest possible offset, to advance the locs_point. duke@435: while (offset >= relocInfo::offset_limit()) { duke@435: assert(end < locs_limit(), "adjust previous paragraph of code"); duke@435: *end++ = filler_relocInfo(); duke@435: offset -= filler_relocInfo().addr_offset(); duke@435: } duke@435: duke@435: // If it's a simple reloc with no data, we'll just write (rtype | offset). duke@435: (*end) = relocInfo(rtype, offset, format); duke@435: duke@435: // If it has data, insert the prefix, as (data_prefix_tag | data1), data2. duke@435: end->initialize(this, reloc); duke@435: } duke@435: duke@435: void CodeSection::initialize_locs(int locs_capacity) { duke@435: assert(_locs_start == NULL, "only one locs init step, please"); duke@435: // Apply a priori lower limits to relocation size: duke@435: csize_t min_locs = MAX2(size() / 16, (csize_t)4); duke@435: if (locs_capacity < min_locs) locs_capacity = min_locs; duke@435: relocInfo* locs_start = NEW_RESOURCE_ARRAY(relocInfo, locs_capacity); duke@435: _locs_start = locs_start; duke@435: _locs_end = locs_start; duke@435: _locs_limit = locs_start + locs_capacity; duke@435: _locs_own = true; duke@435: } duke@435: duke@435: void CodeSection::initialize_shared_locs(relocInfo* buf, int length) { duke@435: assert(_locs_start == NULL, "do this before locs are allocated"); duke@435: // Internal invariant: locs buf must be fully aligned. duke@435: // See copy_relocations_to() below. duke@435: while ((uintptr_t)buf % HeapWordSize != 0 && length > 0) { duke@435: ++buf; --length; duke@435: } duke@435: if (length > 0) { duke@435: _locs_start = buf; duke@435: _locs_end = buf; duke@435: _locs_limit = buf + length; duke@435: _locs_own = false; duke@435: } duke@435: } duke@435: duke@435: void CodeSection::initialize_locs_from(const CodeSection* source_cs) { duke@435: int lcount = source_cs->locs_count(); duke@435: if (lcount != 0) { duke@435: initialize_shared_locs(source_cs->locs_start(), lcount); duke@435: _locs_end = _locs_limit = _locs_start + lcount; duke@435: assert(is_allocated(), "must have copied code already"); duke@435: set_locs_point(start() + source_cs->locs_point_off()); duke@435: } duke@435: assert(this->locs_count() == source_cs->locs_count(), "sanity"); duke@435: } duke@435: duke@435: void CodeSection::expand_locs(int new_capacity) { duke@435: if (_locs_start == NULL) { duke@435: initialize_locs(new_capacity); duke@435: return; duke@435: } else { duke@435: int old_count = locs_count(); duke@435: int old_capacity = locs_capacity(); duke@435: if (new_capacity < old_capacity * 2) duke@435: new_capacity = old_capacity * 2; duke@435: relocInfo* locs_start; duke@435: if (_locs_own) { duke@435: locs_start = REALLOC_RESOURCE_ARRAY(relocInfo, _locs_start, old_capacity, new_capacity); duke@435: } else { duke@435: locs_start = NEW_RESOURCE_ARRAY(relocInfo, new_capacity); kvn@1958: Copy::conjoint_jbytes(_locs_start, locs_start, old_capacity * sizeof(relocInfo)); duke@435: _locs_own = true; duke@435: } duke@435: _locs_start = locs_start; duke@435: _locs_end = locs_start + old_count; duke@435: _locs_limit = locs_start + new_capacity; duke@435: } duke@435: } duke@435: duke@435: duke@435: /// Support for emitting the code to its final location. duke@435: /// The pattern is the same for all functions. duke@435: /// We iterate over all the sections, padding each to alignment. duke@435: twisti@2103: csize_t CodeBuffer::total_content_size() const { twisti@2103: csize_t size_so_far = 0; duke@435: for (int n = 0; n < (int)SECT_LIMIT; n++) { duke@435: const CodeSection* cs = code_section(n); duke@435: if (cs->is_empty()) continue; // skip trivial section twisti@2103: size_so_far = cs->align_at_start(size_so_far); twisti@2103: size_so_far += cs->size(); duke@435: } twisti@2103: return size_so_far; duke@435: } duke@435: duke@435: void CodeBuffer::compute_final_layout(CodeBuffer* dest) const { duke@435: address buf = dest->_total_start; duke@435: csize_t buf_offset = 0; twisti@2103: assert(dest->_total_size >= total_content_size(), "must be big enough"); duke@435: duke@435: { duke@435: // not sure why this is here, but why not... duke@435: int alignSize = MAX2((intx) sizeof(jdouble), CodeEntryAlignment); duke@435: assert( (dest->_total_start - _insts.start()) % alignSize == 0, "copy must preserve alignment"); duke@435: } duke@435: duke@435: const CodeSection* prev_cs = NULL; duke@435: CodeSection* prev_dest_cs = NULL; twisti@2117: twisti@2117: for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { duke@435: // figure compact layout of each section duke@435: const CodeSection* cs = code_section(n); twisti@2117: csize_t csize = cs->size(); duke@435: duke@435: CodeSection* dest_cs = dest->code_section(n); duke@435: if (!cs->is_empty()) { duke@435: // Compute initial padding; assign it to the previous non-empty guy. duke@435: // Cf. figure_expanded_capacities. duke@435: csize_t padding = cs->align_at_start(buf_offset) - buf_offset; duke@435: if (padding != 0) { duke@435: buf_offset += padding; duke@435: assert(prev_dest_cs != NULL, "sanity"); duke@435: prev_dest_cs->_limit += padding; duke@435: } duke@435: #ifdef ASSERT twisti@2117: if (prev_cs != NULL && prev_cs->is_frozen() && n < (SECT_LIMIT - 1)) { duke@435: // Make sure the ends still match up. duke@435: // This is important because a branch in a frozen section duke@435: // might target code in a following section, via a Label, duke@435: // and without a relocation record. See Label::patch_instructions. duke@435: address dest_start = buf+buf_offset; duke@435: csize_t start2start = cs->start() - prev_cs->start(); duke@435: csize_t dest_start2start = dest_start - prev_dest_cs->start(); duke@435: assert(start2start == dest_start2start, "cannot stretch frozen sect"); duke@435: } duke@435: #endif //ASSERT duke@435: prev_dest_cs = dest_cs; duke@435: prev_cs = cs; duke@435: } duke@435: duke@435: debug_only(dest_cs->_start = NULL); // defeat double-initialization assert duke@435: dest_cs->initialize(buf+buf_offset, csize); duke@435: dest_cs->set_end(buf+buf_offset+csize); duke@435: assert(dest_cs->is_allocated(), "must always be allocated"); duke@435: assert(cs->is_empty() == dest_cs->is_empty(), "sanity"); duke@435: duke@435: buf_offset += csize; duke@435: } duke@435: duke@435: // Done calculating sections; did it come out to the right end? twisti@2103: assert(buf_offset == total_content_size(), "sanity"); never@3255: dest->verify_section_allocation(); duke@435: } duke@435: coleenp@4345: // Append an oop reference that keeps the class alive. coleenp@4304: static void append_oop_references(GrowableArray* oops, Klass* k) { coleenp@4345: oop cl = k->klass_holder(); coleenp@4304: if (cl != NULL && !oops->contains(cl)) { coleenp@4304: oops->append(cl); coleenp@4304: } coleenp@4304: } coleenp@4304: coleenp@4037: void CodeBuffer::finalize_oop_references(methodHandle mh) { coleenp@4037: No_Safepoint_Verifier nsv; coleenp@4037: coleenp@4037: GrowableArray oops; coleenp@4037: coleenp@4037: // Make sure that immediate metadata records something in the OopRecorder coleenp@4037: for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { coleenp@4037: // pull code out of each section coleenp@4037: CodeSection* cs = code_section(n); coleenp@4037: if (cs->is_empty()) continue; // skip trivial section coleenp@4037: RelocIterator iter(cs); coleenp@4037: while (iter.next()) { coleenp@4037: if (iter.type() == relocInfo::metadata_type) { coleenp@4037: metadata_Relocation* md = iter.metadata_reloc(); coleenp@4037: if (md->metadata_is_immediate()) { coleenp@4037: Metadata* m = md->metadata_value(); coleenp@4037: if (oop_recorder()->is_real(m)) { coleenp@4037: if (m->is_methodData()) { coleenp@4037: m = ((MethodData*)m)->method(); coleenp@4037: } coleenp@4037: if (m->is_method()) { coleenp@4037: m = ((Method*)m)->method_holder(); coleenp@4037: } coleenp@4037: if (m->is_klass()) { coleenp@4304: append_oop_references(&oops, (Klass*)m); coleenp@4037: } else { coleenp@4037: // XXX This will currently occur for MDO which don't coleenp@4037: // have a backpointer. This has to be fixed later. coleenp@4037: m->print(); coleenp@4037: ShouldNotReachHere(); coleenp@4037: } coleenp@4037: } coleenp@4037: } coleenp@4037: } coleenp@4037: } coleenp@4037: } coleenp@4037: coleenp@4037: if (!oop_recorder()->is_unused()) { coleenp@4037: for (int i = 0; i < oop_recorder()->metadata_count(); i++) { coleenp@4037: Metadata* m = oop_recorder()->metadata_at(i); coleenp@4037: if (oop_recorder()->is_real(m)) { coleenp@4037: if (m->is_methodData()) { coleenp@4037: m = ((MethodData*)m)->method(); coleenp@4037: } coleenp@4037: if (m->is_method()) { coleenp@4037: m = ((Method*)m)->method_holder(); coleenp@4037: } coleenp@4037: if (m->is_klass()) { coleenp@4304: append_oop_references(&oops, (Klass*)m); coleenp@4037: } else { coleenp@4037: m->print(); coleenp@4037: ShouldNotReachHere(); coleenp@4037: } coleenp@4037: } coleenp@4037: } coleenp@4037: coleenp@4037: } coleenp@4037: coleenp@4037: // Add the class loader of Method* for the nmethod itself coleenp@4304: append_oop_references(&oops, mh->method_holder()); coleenp@4037: coleenp@4037: // Add any oops that we've found coleenp@4037: Thread* thread = Thread::current(); coleenp@4037: for (int i = 0; i < oops.length(); i++) { coleenp@4037: oop_recorder()->find_index((jobject)thread->handle_area()->allocate_handle(oops.at(i))); coleenp@4037: } coleenp@4037: } coleenp@4037: coleenp@4037: coleenp@4037: twisti@2117: csize_t CodeBuffer::total_offset_of(CodeSection* cs) const { twisti@2117: csize_t size_so_far = 0; twisti@2117: for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { twisti@2117: const CodeSection* cur_cs = code_section(n); twisti@2117: if (!cur_cs->is_empty()) { twisti@2117: size_so_far = cur_cs->align_at_start(size_so_far); duke@435: } twisti@2117: if (cur_cs->index() == cs->index()) { twisti@2117: return size_so_far; duke@435: } twisti@2117: size_so_far += cur_cs->size(); duke@435: } duke@435: ShouldNotReachHere(); duke@435: return -1; duke@435: } duke@435: duke@435: csize_t CodeBuffer::total_relocation_size() const { duke@435: csize_t lsize = copy_relocations_to(NULL); // dry run only twisti@2103: csize_t csize = total_content_size(); duke@435: csize_t total = RelocIterator::locs_and_index_size(csize, lsize); duke@435: return (csize_t) align_size_up(total, HeapWordSize); duke@435: } duke@435: duke@435: csize_t CodeBuffer::copy_relocations_to(CodeBlob* dest) const { duke@435: address buf = NULL; duke@435: csize_t buf_offset = 0; duke@435: csize_t buf_limit = 0; duke@435: if (dest != NULL) { duke@435: buf = (address)dest->relocation_begin(); duke@435: buf_limit = (address)dest->relocation_end() - buf; duke@435: assert((uintptr_t)buf % HeapWordSize == 0, "buf must be fully aligned"); duke@435: assert(buf_limit % HeapWordSize == 0, "buf must be evenly sized"); duke@435: } duke@435: // if dest == NULL, this is just the sizing pass duke@435: duke@435: csize_t code_end_so_far = 0; duke@435: csize_t code_point_so_far = 0; twisti@2117: for (int n = (int) SECT_FIRST; n < (int)SECT_LIMIT; n++) { duke@435: // pull relocs out of each section duke@435: const CodeSection* cs = code_section(n); duke@435: assert(!(cs->is_empty() && cs->locs_count() > 0), "sanity"); duke@435: if (cs->is_empty()) continue; // skip trivial section duke@435: relocInfo* lstart = cs->locs_start(); duke@435: relocInfo* lend = cs->locs_end(); duke@435: csize_t lsize = (csize_t)( (address)lend - (address)lstart ); duke@435: csize_t csize = cs->size(); duke@435: code_end_so_far = cs->align_at_start(code_end_so_far); duke@435: duke@435: if (lsize > 0) { duke@435: // Figure out how to advance the combined relocation point duke@435: // first to the beginning of this section. duke@435: // We'll insert one or more filler relocs to span that gap. duke@435: // (Don't bother to improve this by editing the first reloc's offset.) duke@435: csize_t new_code_point = code_end_so_far; duke@435: for (csize_t jump; duke@435: code_point_so_far < new_code_point; duke@435: code_point_so_far += jump) { duke@435: jump = new_code_point - code_point_so_far; duke@435: relocInfo filler = filler_relocInfo(); duke@435: if (jump >= filler.addr_offset()) { duke@435: jump = filler.addr_offset(); duke@435: } else { // else shrink the filler to fit duke@435: filler = relocInfo(relocInfo::none, jump); duke@435: } duke@435: if (buf != NULL) { duke@435: assert(buf_offset + (csize_t)sizeof(filler) <= buf_limit, "filler in bounds"); duke@435: *(relocInfo*)(buf+buf_offset) = filler; duke@435: } duke@435: buf_offset += sizeof(filler); duke@435: } duke@435: duke@435: // Update code point and end to skip past this section: duke@435: csize_t last_code_point = code_end_so_far + cs->locs_point_off(); duke@435: assert(code_point_so_far <= last_code_point, "sanity"); duke@435: code_point_so_far = last_code_point; // advance past this guy's relocs duke@435: } duke@435: code_end_so_far += csize; // advance past this guy's instructions too duke@435: duke@435: // Done with filler; emit the real relocations: duke@435: if (buf != NULL && lsize != 0) { duke@435: assert(buf_offset + lsize <= buf_limit, "target in bounds"); duke@435: assert((uintptr_t)lstart % HeapWordSize == 0, "sane start"); duke@435: if (buf_offset % HeapWordSize == 0) { duke@435: // Use wordwise copies if possible: duke@435: Copy::disjoint_words((HeapWord*)lstart, duke@435: (HeapWord*)(buf+buf_offset), duke@435: (lsize + HeapWordSize-1) / HeapWordSize); duke@435: } else { kvn@1958: Copy::conjoint_jbytes(lstart, buf+buf_offset, lsize); duke@435: } duke@435: } duke@435: buf_offset += lsize; duke@435: } duke@435: duke@435: // Align end of relocation info in target. duke@435: while (buf_offset % HeapWordSize != 0) { duke@435: if (buf != NULL) { duke@435: relocInfo padding = relocInfo(relocInfo::none, 0); duke@435: assert(buf_offset + (csize_t)sizeof(padding) <= buf_limit, "padding in bounds"); duke@435: *(relocInfo*)(buf+buf_offset) = padding; duke@435: } duke@435: buf_offset += sizeof(relocInfo); duke@435: } duke@435: twisti@2103: assert(code_end_so_far == total_content_size(), "sanity"); duke@435: duke@435: // Account for index: duke@435: if (buf != NULL) { duke@435: RelocIterator::create_index(dest->relocation_begin(), duke@435: buf_offset / sizeof(relocInfo), duke@435: dest->relocation_end()); duke@435: } duke@435: duke@435: return buf_offset; duke@435: } duke@435: duke@435: void CodeBuffer::copy_code_to(CodeBlob* dest_blob) { duke@435: #ifndef PRODUCT duke@435: if (PrintNMethods && (WizardMode || Verbose)) { duke@435: tty->print("done with CodeBuffer:"); duke@435: ((CodeBuffer*)this)->print(); duke@435: } duke@435: #endif //PRODUCT duke@435: twisti@2103: CodeBuffer dest(dest_blob); twisti@2103: assert(dest_blob->content_size() >= total_content_size(), "good sizing"); duke@435: this->compute_final_layout(&dest); duke@435: relocate_code_to(&dest); duke@435: roland@4767: // transfer strings and comments from buffer to blob roland@4767: dest_blob->set_strings(_strings); duke@435: duke@435: // Done moving code bytes; were they the right size? twisti@2103: assert(round_to(dest.total_content_size(), oopSize) == dest_blob->content_size(), "sanity"); duke@435: duke@435: // Flush generated code twisti@2103: ICache::invalidate_range(dest_blob->code_begin(), dest_blob->code_size()); duke@435: } duke@435: twisti@2117: // Move all my code into another code buffer. Consult applicable twisti@2117: // relocs to repair embedded addresses. The layout in the destination twisti@2117: // CodeBuffer is different to the source CodeBuffer: the destination twisti@2117: // CodeBuffer gets the final layout (consts, insts, stubs in order of twisti@2117: // ascending address). duke@435: void CodeBuffer::relocate_code_to(CodeBuffer* dest) const { never@3236: address dest_end = dest->_total_start + dest->_total_size; never@3236: address dest_filled = NULL; twisti@2117: for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { duke@435: // pull code out of each section duke@435: const CodeSection* cs = code_section(n); duke@435: if (cs->is_empty()) continue; // skip trivial section duke@435: CodeSection* dest_cs = dest->code_section(n); duke@435: assert(cs->size() == dest_cs->size(), "sanity"); duke@435: csize_t usize = dest_cs->size(); duke@435: csize_t wsize = align_size_up(usize, HeapWordSize); duke@435: assert(dest_cs->start() + wsize <= dest_end, "no overflow"); duke@435: // Copy the code as aligned machine words. duke@435: // This may also include an uninitialized partial word at the end. duke@435: Copy::disjoint_words((HeapWord*)cs->start(), duke@435: (HeapWord*)dest_cs->start(), duke@435: wsize / HeapWordSize); duke@435: duke@435: if (dest->blob() == NULL) { duke@435: // Destination is a final resting place, not just another buffer. duke@435: // Normalize uninitialized bytes in the final padding. duke@435: Copy::fill_to_bytes(dest_cs->end(), dest_cs->remaining(), duke@435: Assembler::code_fill_byte()); duke@435: } never@3236: // Keep track of the highest filled address never@3236: dest_filled = MAX2(dest_filled, dest_cs->end() + dest_cs->remaining()); duke@435: duke@435: assert(cs->locs_start() != (relocInfo*)badAddress, duke@435: "this section carries no reloc storage, but reloc was attempted"); duke@435: duke@435: // Make the new code copy use the old copy's relocations: duke@435: dest_cs->initialize_locs_from(cs); kvn@4316: } duke@435: kvn@4316: // Do relocation after all sections are copied. kvn@4316: // This is necessary if the code uses constants in stubs, which are kvn@4316: // relocated when the corresponding instruction in the code (e.g., a kvn@4316: // call) is relocated. Stubs are placed behind the main code kvn@4316: // section, so that section has to be copied before relocating. kvn@4316: for (int n = (int) SECT_FIRST; n < (int)SECT_LIMIT; n++) { kvn@4316: // pull code out of each section kvn@4316: const CodeSection* cs = code_section(n); kvn@4316: if (cs->is_empty()) continue; // skip trivial section kvn@4316: CodeSection* dest_cs = dest->code_section(n); duke@435: { // Repair the pc relative information in the code after the move duke@435: RelocIterator iter(dest_cs); duke@435: while (iter.next()) { duke@435: iter.reloc()->fix_relocation_after_move(this, dest); duke@435: } duke@435: } duke@435: } never@3236: twisti@4237: if (dest->blob() == NULL && dest_filled != NULL) { never@3236: // Destination is a final resting place, not just another buffer. never@3236: // Normalize uninitialized bytes in the final padding. never@3236: Copy::fill_to_bytes(dest_filled, dest_end - dest_filled, never@3236: Assembler::code_fill_byte()); never@3236: never@3236: } duke@435: } duke@435: duke@435: csize_t CodeBuffer::figure_expanded_capacities(CodeSection* which_cs, duke@435: csize_t amount, duke@435: csize_t* new_capacity) { duke@435: csize_t new_total_cap = 0; duke@435: twisti@2117: for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { duke@435: const CodeSection* sect = code_section(n); duke@435: duke@435: if (!sect->is_empty()) { twisti@2117: // Compute initial padding; assign it to the previous section, twisti@2117: // even if it's empty (e.g. consts section can be empty). twisti@2117: // Cf. compute_final_layout duke@435: csize_t padding = sect->align_at_start(new_total_cap) - new_total_cap; duke@435: if (padding != 0) { duke@435: new_total_cap += padding; twisti@2117: assert(n - 1 >= SECT_FIRST, "sanity"); twisti@2117: new_capacity[n - 1] += padding; duke@435: } duke@435: } duke@435: duke@435: csize_t exp = sect->size(); // 100% increase duke@435: if ((uint)exp < 4*K) exp = 4*K; // minimum initial increase duke@435: if (sect == which_cs) { duke@435: if (exp < amount) exp = amount; duke@435: if (StressCodeBuffers) exp = amount; // expand only slightly duke@435: } else if (n == SECT_INSTS) { duke@435: // scale down inst increases to a more modest 25% duke@435: exp = 4*K + ((exp - 4*K) >> 2); duke@435: if (StressCodeBuffers) exp = amount / 2; // expand only slightly duke@435: } else if (sect->is_empty()) { duke@435: // do not grow an empty secondary section duke@435: exp = 0; duke@435: } duke@435: // Allow for inter-section slop: duke@435: exp += CodeSection::end_slop(); duke@435: csize_t new_cap = sect->size() + exp; duke@435: if (new_cap < sect->capacity()) { duke@435: // No need to expand after all. duke@435: new_cap = sect->capacity(); duke@435: } duke@435: new_capacity[n] = new_cap; duke@435: new_total_cap += new_cap; duke@435: } duke@435: duke@435: return new_total_cap; duke@435: } duke@435: duke@435: void CodeBuffer::expand(CodeSection* which_cs, csize_t amount) { duke@435: #ifndef PRODUCT duke@435: if (PrintNMethods && (WizardMode || Verbose)) { duke@435: tty->print("expanding CodeBuffer:"); duke@435: this->print(); duke@435: } duke@435: duke@435: if (StressCodeBuffers && blob() != NULL) { duke@435: static int expand_count = 0; duke@435: if (expand_count >= 0) expand_count += 1; duke@435: if (expand_count > 100 && is_power_of_2(expand_count)) { duke@435: tty->print_cr("StressCodeBuffers: have expanded %d times", expand_count); duke@435: // simulate an occasional allocation failure: duke@435: free_blob(); duke@435: } duke@435: } duke@435: #endif //PRODUCT duke@435: duke@435: // Resizing must be allowed duke@435: { duke@435: if (blob() == NULL) return; // caller must check for blob == NULL duke@435: for (int n = 0; n < (int)SECT_LIMIT; n++) { duke@435: guarantee(!code_section(n)->is_frozen(), "resizing not allowed when frozen"); duke@435: } duke@435: } duke@435: duke@435: // Figure new capacity for each section. duke@435: csize_t new_capacity[SECT_LIMIT]; duke@435: csize_t new_total_cap duke@435: = figure_expanded_capacities(which_cs, amount, new_capacity); duke@435: duke@435: // Create a new (temporary) code buffer to hold all the new data duke@435: CodeBuffer cb(name(), new_total_cap, 0); duke@435: if (cb.blob() == NULL) { duke@435: // Failed to allocate in code cache. duke@435: free_blob(); duke@435: return; duke@435: } duke@435: duke@435: // Create an old code buffer to remember which addresses used to go where. duke@435: // This will be useful when we do final assembly into the code cache, duke@435: // because we will need to know how to warp any internal address that duke@435: // has been created at any time in this CodeBuffer's past. duke@435: CodeBuffer* bxp = new CodeBuffer(_total_start, _total_size); duke@435: bxp->take_over_code_from(this); // remember the old undersized blob duke@435: DEBUG_ONLY(this->_blob = NULL); // silence a later assert duke@435: bxp->_before_expand = this->_before_expand; duke@435: this->_before_expand = bxp; duke@435: duke@435: // Give each section its required (expanded) capacity. twisti@2117: for (int n = (int)SECT_LIMIT-1; n >= SECT_FIRST; n--) { duke@435: CodeSection* cb_sect = cb.code_section(n); duke@435: CodeSection* this_sect = code_section(n); duke@435: if (new_capacity[n] == 0) continue; // already nulled out twisti@2117: if (n != SECT_INSTS) { duke@435: cb.initialize_section_size(cb_sect, new_capacity[n]); duke@435: } duke@435: assert(cb_sect->capacity() >= new_capacity[n], "big enough"); duke@435: address cb_start = cb_sect->start(); duke@435: cb_sect->set_end(cb_start + this_sect->size()); duke@435: if (this_sect->mark() == NULL) { duke@435: cb_sect->clear_mark(); duke@435: } else { duke@435: cb_sect->set_mark(cb_start + this_sect->mark_off()); duke@435: } duke@435: } duke@435: duke@435: // Move all the code and relocations to the new blob: duke@435: relocate_code_to(&cb); duke@435: duke@435: // Copy the temporary code buffer into the current code buffer. duke@435: // Basically, do {*this = cb}, except for some control information. duke@435: this->take_over_code_from(&cb); duke@435: cb.set_blob(NULL); duke@435: duke@435: // Zap the old code buffer contents, to avoid mistakenly using them. duke@435: debug_only(Copy::fill_to_bytes(bxp->_total_start, bxp->_total_size, duke@435: badCodeHeapFreeVal)); duke@435: duke@435: _decode_begin = NULL; // sanity duke@435: duke@435: // Make certain that the new sections are all snugly inside the new blob. never@3255: verify_section_allocation(); duke@435: duke@435: #ifndef PRODUCT duke@435: if (PrintNMethods && (WizardMode || Verbose)) { duke@435: tty->print("expanded CodeBuffer:"); duke@435: this->print(); duke@435: } duke@435: #endif //PRODUCT duke@435: } duke@435: duke@435: void CodeBuffer::take_over_code_from(CodeBuffer* cb) { duke@435: // Must already have disposed of the old blob somehow. duke@435: assert(blob() == NULL, "must be empty"); duke@435: #ifdef ASSERT duke@435: duke@435: #endif duke@435: // Take the new blob away from cb. duke@435: set_blob(cb->blob()); duke@435: // Take over all the section pointers. duke@435: for (int n = 0; n < (int)SECT_LIMIT; n++) { duke@435: CodeSection* cb_sect = cb->code_section(n); duke@435: CodeSection* this_sect = code_section(n); duke@435: this_sect->take_over_code_from(cb_sect); duke@435: } duke@435: _overflow_arena = cb->_overflow_arena; duke@435: // Make sure the old cb won't try to use it or free it. duke@435: DEBUG_ONLY(cb->_blob = (BufferBlob*)badAddress); duke@435: } duke@435: never@3255: void CodeBuffer::verify_section_allocation() { duke@435: address tstart = _total_start; never@3255: if (tstart == badAddress) return; // smashed by set_blob(NULL) duke@435: address tend = tstart + _total_size; duke@435: if (_blob != NULL) { never@3255: never@3255: guarantee(tstart >= _blob->content_begin(), "sanity"); never@3255: guarantee(tend <= _blob->content_end(), "sanity"); duke@435: } twisti@2117: // Verify disjointness. twisti@2117: for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { duke@435: CodeSection* sect = code_section(n); twisti@2117: if (!sect->is_allocated() || sect->is_empty()) continue; never@3255: guarantee((intptr_t)sect->start() % sect->alignment() == 0 duke@435: || sect->is_empty() || _blob == NULL, duke@435: "start is aligned"); twisti@2117: for (int m = (int) SECT_FIRST; m < (int) SECT_LIMIT; m++) { twisti@2117: CodeSection* other = code_section(m); twisti@2117: if (!other->is_allocated() || other == sect) continue; never@3255: guarantee(!other->contains(sect->start() ), "sanity"); twisti@2117: // limit is an exclusive address and can be the start of another twisti@2117: // section. never@3255: guarantee(!other->contains(sect->limit() - 1), "sanity"); twisti@2117: } never@3255: guarantee(sect->end() <= tend, "sanity"); never@3255: guarantee(sect->end() <= sect->limit(), "sanity"); duke@435: } duke@435: } never@3255: never@3255: void CodeBuffer::log_section_sizes(const char* name) { never@3255: if (xtty != NULL) { never@3255: // log info about buffer usage never@3255: xtty->print_cr("", name, _total_size); never@3255: for (int n = (int) CodeBuffer::SECT_FIRST; n < (int) CodeBuffer::SECT_LIMIT; n++) { never@3255: CodeSection* sect = code_section(n); never@3255: if (!sect->is_allocated() || sect->is_empty()) continue; never@3255: xtty->print_cr("", never@3255: n, sect->limit() - sect->start(), sect->limit() - sect->end()); never@3255: } never@3255: xtty->print_cr(""); never@3255: } never@3255: } duke@435: duke@435: #ifndef PRODUCT duke@435: duke@435: void CodeSection::dump() { duke@435: address ptr = start(); duke@435: for (csize_t step; ptr < end(); ptr += step) { duke@435: step = end() - ptr; duke@435: if (step > jintSize * 4) step = jintSize * 4; duke@435: tty->print(PTR_FORMAT ": ", ptr); duke@435: while (step > 0) { duke@435: tty->print(" " PTR32_FORMAT, *(jint*)ptr); duke@435: ptr += jintSize; duke@435: } duke@435: tty->cr(); duke@435: } duke@435: } duke@435: duke@435: duke@435: void CodeSection::decode() { duke@435: Disassembler::decode(start(), end()); duke@435: } duke@435: duke@435: duke@435: void CodeBuffer::block_comment(intptr_t offset, const char * comment) { roland@4767: _strings.add_comment(offset, comment); duke@435: } duke@435: roland@4767: const char* CodeBuffer::code_string(const char* str) { roland@4767: return _strings.add_string(str); roland@4767: } roland@4767: roland@4767: class CodeString: public CHeapObj { duke@435: private: roland@4767: friend class CodeStrings; roland@4767: const char * _string; roland@4767: CodeString* _next; duke@435: intptr_t _offset; duke@435: roland@4767: ~CodeString() { duke@435: assert(_next == NULL, "wrong interface for freeing list"); roland@4767: os::free((void*)_string, mtCode); duke@435: } duke@435: roland@4767: bool is_comment() const { return _offset >= 0; } roland@4767: duke@435: public: roland@4767: CodeString(const char * string, intptr_t offset = -1) roland@4767: : _next(NULL), _offset(offset) { roland@4767: _string = os::strdup(string, mtCode); duke@435: } duke@435: roland@4767: const char * string() const { return _string; } roland@4767: intptr_t offset() const { assert(_offset >= 0, "offset for non comment?"); return _offset; } roland@4767: CodeString* next() const { return _next; } duke@435: roland@4767: void set_next(CodeString* next) { _next = next; } duke@435: roland@4767: CodeString* first_comment() { roland@4767: if (is_comment()) { roland@4767: return this; roland@4767: } else { roland@4767: return next_comment(); duke@435: } duke@435: } roland@4767: CodeString* next_comment() const { roland@4767: CodeString* s = _next; roland@4767: while (s != NULL && !s->is_comment()) { roland@4767: s = s->_next; kvn@4107: } roland@4767: return s; kvn@4107: } duke@435: }; duke@435: roland@4767: CodeString* CodeStrings::find(intptr_t offset) const { roland@4767: CodeString* a = _strings->first_comment(); roland@4767: while (a != NULL && a->offset() != offset) { roland@4767: a = a->next_comment(); roland@4767: } roland@4767: return a; roland@4767: } duke@435: roland@4767: // Convenience for add_comment. roland@4767: CodeString* CodeStrings::find_last(intptr_t offset) const { roland@4767: CodeString* a = find(offset); roland@4767: if (a != NULL) { roland@4767: CodeString* c = NULL; roland@4767: while (((c = a->next_comment()) != NULL) && (c->offset() == offset)) { roland@4767: a = c; roland@4767: } roland@4767: } roland@4767: return a; roland@4767: } roland@4767: roland@4767: void CodeStrings::add_comment(intptr_t offset, const char * comment) { roland@4767: CodeString* c = new CodeString(comment, offset); roland@4767: CodeString* inspos = (_strings == NULL) ? NULL : find_last(offset); kvn@4107: kvn@4107: if (inspos) { kvn@4107: // insert after already existing comments with same offset kvn@4107: c->set_next(inspos->next()); kvn@4107: inspos->set_next(c); duke@435: } else { kvn@4107: // no comments with such offset, yet. Insert before anything else. roland@4767: c->set_next(_strings); roland@4767: _strings = c; duke@435: } duke@435: } duke@435: roland@4767: void CodeStrings::assign(CodeStrings& other) { roland@4767: _strings = other._strings; duke@435: } duke@435: roland@4767: void CodeStrings::print_block_comment(outputStream* stream, intptr_t offset) const { roland@4767: if (_strings != NULL) { roland@4767: CodeString* c = find(offset); duke@435: while (c && c->offset() == offset) { jrose@535: stream->bol(); duke@435: stream->print(" ;; "); roland@4767: stream->print_cr(c->string()); roland@4767: c = c->next_comment(); duke@435: } duke@435: } duke@435: } duke@435: duke@435: roland@4767: void CodeStrings::free() { roland@4767: CodeString* n = _strings; duke@435: while (n) { duke@435: // unlink the node from the list saving a pointer to the next roland@4767: CodeString* p = n->next(); roland@4767: n->set_next(NULL); duke@435: delete n; duke@435: n = p; duke@435: } roland@4767: _strings = NULL; duke@435: } duke@435: roland@4767: const char* CodeStrings::add_string(const char * string) { roland@4767: CodeString* s = new CodeString(string); roland@4767: s->set_next(_strings); roland@4767: _strings = s; roland@4767: assert(s->string() != NULL, "should have a string"); roland@4767: return s->string(); roland@4767: } duke@435: duke@435: void CodeBuffer::decode() { kvn@4107: ttyLocker ttyl; twisti@2103: Disassembler::decode(decode_begin(), insts_end()); twisti@2103: _decode_begin = insts_end(); duke@435: } duke@435: duke@435: duke@435: void CodeBuffer::skip_decode() { twisti@2103: _decode_begin = insts_end(); duke@435: } duke@435: duke@435: duke@435: void CodeBuffer::decode_all() { kvn@4107: ttyLocker ttyl; duke@435: for (int n = 0; n < (int)SECT_LIMIT; n++) { duke@435: // dump contents of each section duke@435: CodeSection* cs = code_section(n); duke@435: tty->print_cr("! %s:", code_section_name(n)); duke@435: if (cs != consts()) duke@435: cs->decode(); duke@435: else duke@435: cs->dump(); duke@435: } duke@435: } duke@435: duke@435: duke@435: void CodeSection::print(const char* name) { duke@435: csize_t locs_size = locs_end() - locs_start(); duke@435: tty->print_cr(" %7s.code = " PTR_FORMAT " : " PTR_FORMAT " : " PTR_FORMAT " (%d of %d)%s", duke@435: name, start(), end(), limit(), size(), capacity(), duke@435: is_frozen()? " [frozen]": ""); duke@435: tty->print_cr(" %7s.locs = " PTR_FORMAT " : " PTR_FORMAT " : " PTR_FORMAT " (%d of %d) point=%d", duke@435: name, locs_start(), locs_end(), locs_limit(), locs_size, locs_capacity(), locs_point_off()); duke@435: if (PrintRelocations) { duke@435: RelocIterator iter(this); duke@435: iter.print(); duke@435: } duke@435: } duke@435: duke@435: void CodeBuffer::print() { duke@435: if (this == NULL) { duke@435: tty->print_cr("NULL CodeBuffer pointer"); duke@435: return; duke@435: } duke@435: duke@435: tty->print_cr("CodeBuffer:"); duke@435: for (int n = 0; n < (int)SECT_LIMIT; n++) { duke@435: // print each section duke@435: CodeSection* cs = code_section(n); duke@435: cs->print(code_section_name(n)); duke@435: } duke@435: } duke@435: duke@435: #endif // PRODUCT