codeBuffer.hpp revision 1378
2120N/A * Copyright 1997-2010 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1472N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1472N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A Frame_Complete,
// Offset in the code where the frame setup is (for forte stackwalks) is complete 0N/A Deopt,
// Offset where deopt handler lives 0N/A // special value to note codeBlobs where profile (forte) stack walking is 0N/A // always dangerous and suspect. 0N/A// This class represents a stream of code and associated relocations. 0N/A// There are a few in each CodeBuffer. 0N/A// They are filled concurrently, and concatenated at the end. 2312N/A typedef int csize_t;
// code size type; would be size_t except for history 0N/A bool _frozen;
// no more expansion of this section 0N/A char _index;
// my section number (SECT_INST, etc.) 0N/A // (Note: _locs_point used to be called _last_reloc_offset.) 0N/A // helper for CodeBuffer::expand() 0N/A // is a given address in this section? (2nd version is end-inclusive) 0N/A // Share a scratch buffer for relocinfo. (Hacky; saves a resource allocation.) 0N/A // Manage labels and their addresses. 0N/A // Emit a relocation. 2312N/A // alignment requirement for starting offset 2312N/A // Requirements are that the instruction area and the 2312N/A // stubs area must start on CodeEntryAlignment, and 2312N/A // the ctable on sizeof(jdouble) 0N/A // Slop between sections, used only when allocating temporary BufferBlob buffers. 0N/A // Mark a section frozen. Assign its remaining space to 0N/A // the following section. It will never expand after this point. 2312N/A inline void freeze();
// { _outer->freeze_section(this); } 2312N/A // Ensure there's enough space left in the current section. 2312N/A // Return true if there was an expansion. 0N/A// A CodeBuffer describes a memory space into which assembly 0N/A// code is generated. This memory space usually occupies the 0N/A// interior of a single BufferBlob, but in some cases it may be 0N/A// an arbitrary span of memory, even outside the code cache. 0N/A// A code buffer comes in two variants: 0N/A// (1) A CodeBuffer referring to an already allocated piece of memory: 0N/A// This is used to direct 'static' code generation (e.g. for interpreter 0N/A// or stubroutine generation, etc.). This code comes with NO relocation 0N/A// (2) A CodeBuffer referring to a piece of memory allocated when the 0N/A// CodeBuffer is allocated. This is used for nmethod generation. 0N/A// The memory can be divided up into several parts called sections. 0N/A// Each section independently accumulates code (or data) an relocations. 4321N/A// Sections can grow (at the expense of a reallocation of the BufferBlob 4321N/A// and recopying of all active sections). When the buffered code is finally 4321N/A// written to an nmethod (or other CodeBlob), the contents (code, data, 4321N/A// and relocations) of the sections are padded to an alignment and concatenated. 4321N/A// Instructions and data in one section can contain relocatable references to 4321N/A// addresses in a sibling section. 4321N/A // CodeBuffers must be allocated on the stack except for a single 0N/A // special case during expansion which is handled internally. This 0N/A // is done to guarantee proper cleanup of resources. 0N/A typedef int csize_t;
// code size type; would be size_t except for history 0N/A // Here is the list of all possible sections, in order of ascending address. 0N/A // Initialize the main section: 0N/A // helper for CodeBuffer::expand() 0N/A // ensure sections are disjoint, ordered, and contained in the blob 0N/A // copies combined relocations to the blob, returns bytes copied 3986N/A // (if target is null, it is a dry run only, just for sizing) 0N/A // copies combined code to the blob (assumes relocs are already in there) 0N/A // moves code sections to new buffer (assumes relocs are already in there) 0N/A // set up a model of the final layout of my contents 0N/A // Expand the given section so at least 'amount' is remaining. 0N/A // Creates a new, larger BufferBlob, and rewrites the code & relocs. 0N/A // Helper for expand. 0N/A // (1) code buffer referring to pre-allocated instruction memory 0N/A // (2) code buffer allocating codeBlob memory for code & relocation 0N/A // info but with lazy initialization. The name must be something 1172N/A // (3) code buffer allocating codeBlob memory for code & relocation 401N/A // info. The name must be something informative and code_size must 401N/A // include both code and stubs sizes. 0N/A // Initialize a CodeBuffer constructed using constructor 2. Using 0N/A // constructor 3 is equivalent to calling constructor 2 and then 0N/A // calling this method. It's been factored out for convenience of 0N/A // present sections in order; return NULL at end; insts is #0, etc. 0N/A // This makes the slightly questionable but portable assumption that 0N/A // the various members (_insts, _stubs, etc.) are adjacent in the 0N/A // layout of CodeBuffer. 0N/A // handy for debugging 0N/A // A stable mapping between 'locators' (small ints) and addresses. 0N/A // Properties relative to the insts section: 0N/A // is there anything in the buffer other than the current section? 0N/A // size in bytes of output so far in the insts sections 0N/A // same as code_size(), except that it asserts there is no non-code here 0N/A // capacity in bytes of the insts sections 1172N/A // number of bytes remaining in the insts section 2312N/A // is a given address in the insts section? (2nd version is end-inclusive) 0N/A // allocated size of code in all sections, when aligned and concatenated 0N/A // (this is the eventual state of the code in its final CodeBlob) 0N/A // combined offset (relative to start of insts) of given address, 0N/A // as eventually found in the final CodeBlob 0N/A // allocated size of all relocation data, including index, rounded up 0N/A // allocated size of any and all recorded oops 0N/A // Configuration functions, called immediately after the CB is constructed. 0N/A // The section sizes are subtracted from the original insts section. 0N/A // Note: Call them in reverse section order, because each steals from insts. 0N/A // Override default oop recorder. 0N/A // Management of overflow storage for binding of Labels. 0N/A // NMethod generation 0N/A // Transform an address from the code in this code buffer to a specified code buffer 0N/A // Printing / Decoding 0N/A // decodes from decode_begin() to code_end() and sets decode_begin to end 0N/A // The following header contains architecture-specific implementations