codeBuffer.hpp revision 1605
3516N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. 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 2362N/A * published by the Free Software Foundation. 2362N/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. 0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3516N/A Frame_Complete,
// Offset in the code where the frame setup is (for forte stackwalks) is complete 0N/A // special value to note codeBlobs where profile (forte) stack walking is 3516N/A // always dangerous and suspect. // This class represents a stream of code and associated relocations. // There are a few in each CodeBuffer. // They are filled concurrently, and concatenated at the end. typedef int csize_t;
// code size type; would be size_t except for history address _mark;
// user mark, usually an instruction beginning bool _locs_own;
// did I allocate the locs myself? bool _frozen;
// no more expansion of this section char _index;
// my section number (SECT_INST, etc.) // (Note: _locs_point used to be called _last_reloc_offset.) // helper for CodeBuffer::expand() // is a given address in this section? (2nd version is end-inclusive) // Share a scratch buffer for relocinfo. (Hacky; saves a resource allocation.) // Manage labels and their addresses. // alignment requirement for starting offset // Requirements are that the instruction area and the // stubs area must start on CodeEntryAlignment, and // the ctable on sizeof(jdouble) // Slop between sections, used only when allocating temporary BufferBlob buffers. // Mark a section frozen. Assign its remaining space to // the following section. It will never expand after this point. inline void freeze();
// { _outer->freeze_section(this); } // Ensure there's enough space left in the current section. // Return true if there was an expansion. // A CodeBuffer describes a memory space into which assembly // code is generated. This memory space usually occupies the // interior of a single BufferBlob, but in some cases it may be // an arbitrary span of memory, even outside the code cache. // A code buffer comes in two variants: // (1) A CodeBuffer referring to an already allocated piece of memory: // This is used to direct 'static' code generation (e.g. for interpreter // or stubroutine generation, etc.). This code comes with NO relocation // (2) A CodeBuffer referring to a piece of memory allocated when the // CodeBuffer is allocated. This is used for nmethod generation. // The memory can be divided up into several parts called sections. // Each section independently accumulates code (or data) an relocations. // Sections can grow (at the expense of a reallocation of the BufferBlob // and recopying of all active sections). When the buffered code is finally // written to an nmethod (or other CodeBlob), the contents (code, data, // and relocations) of the sections are padded to an alignment and concatenated. // Instructions and data in one section can contain relocatable references to // addresses in a sibling section. // CodeBuffers must be allocated on the stack except for a single // special case during expansion which is handled internally. This // is done to guarantee proper cleanup of resources. typedef int csize_t;
// code size type; would be size_t except for history // Here is the list of all possible sections, in order of ascending address. SECT_STUBS,
// Outbound trampolines for supporting call sites. SECT_CONSTS,
// Non-instruction data: Floats, jump tables, etc. sect_bits =
2,
// assert (SECT_LIMIT <= (1<<sect_bits)) // all pointers other than code_start/end and those inside the sections // Initialize the main section: // helper for CodeBuffer::expand() // ensure sections are disjoint, ordered, and contained in the blob // copies combined relocations to the blob, returns bytes copied // (if target is null, it is a dry run only, just for sizing) // copies combined code to the blob (assumes relocs are already in there) // moves code sections to new buffer (assumes relocs are already in there) // set up a model of the final layout of my contents // Expand the given section so at least 'amount' is remaining. // Creates a new, larger BufferBlob, and rewrites the code & relocs. // (1) code buffer referring to pre-allocated instruction memory // (2) code buffer allocating codeBlob memory for code & relocation // info but with lazy initialization. The name must be something // (3) code buffer allocating codeBlob memory for code & relocation // info. The name must be something informative and code_size must // include both code and stubs sizes. // Initialize a CodeBuffer constructed using constructor 2. Using // constructor 3 is equivalent to calling constructor 2 and then // calling this method. It's been factored out for convenience of // present sections in order; return NULL at end; insts is #0, etc. // This makes the slightly questionable but portable assumption that // the various members (_insts, _stubs, etc.) are adjacent in the // A stable mapping between 'locators' (small ints) and addresses. void free_blob();
// Free the blob, if we own one. // Properties relative to the insts section: // is there anything in the buffer other than the current section? // size in bytes of output so far in the insts sections // same as code_size(), except that it asserts there is no non-code here // capacity in bytes of the insts sections // number of bytes remaining in the insts section // is a given address in the insts section? (2nd version is end-inclusive) // allocated size of code in all sections, when aligned and concatenated // (this is the eventual state of the code in its final CodeBlob) // combined offset (relative to start of insts) of given address, // as eventually found in the final CodeBlob // allocated size of all relocation data, including index, rounded up // allocated size of any and all recorded oops // Configuration functions, called immediately after the CB is constructed. // The section sizes are subtracted from the original insts section. // Note: Call them in reverse section order, because each steals from insts. // Override default oop recorder. // Management of overflow storage for binding of Labels. // Transform an address from the code in this code buffer to a specified code buffer // decodes from decode_begin() to code_end() and sets decode_begin to end void skip_decode();
// sets decode_begin to code_end(); // The following header contains architecture-specific implementations