|
Java example source code file (codeBuffer.hpp)
The codeBuffer.hpp Java example source code/* * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ #ifndef SHARE_VM_ASM_CODEBUFFER_HPP #define SHARE_VM_ASM_CODEBUFFER_HPP #include "code/oopRecorder.hpp" #include "code/relocInfo.hpp" class CodeStrings; class PhaseCFG; class Compile; class BufferBlob; class CodeBuffer; class Label; class CodeOffsets: public StackObj { public: enum Entries { Entry, Verified_Entry, Frame_Complete, // Offset in the code where the frame setup is (for forte stackwalks) is complete OSR_Entry, Dtrace_trap = OSR_Entry, // dtrace probes can never have an OSR entry so reuse it Exceptions, // Offset where exception handler lives Deopt, // Offset where deopt handler lives DeoptMH, // Offset where MethodHandle deopt handler lives UnwindHandler, // Offset to default unwind handler max_Entries }; // special value to note codeBlobs where profile (forte) stack walking is // always dangerous and suspect. enum { frame_never_safe = -1 }; private: int _values[max_Entries]; public: CodeOffsets() { _values[Entry ] = 0; _values[Verified_Entry] = 0; _values[Frame_Complete] = frame_never_safe; _values[OSR_Entry ] = 0; _values[Exceptions ] = -1; _values[Deopt ] = -1; _values[DeoptMH ] = -1; _values[UnwindHandler ] = -1; } int value(Entries e) { return _values[e]; } void set_value(Entries e, int val) { _values[e] = val; } }; // 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. class CodeSection VALUE_OBJ_CLASS_SPEC { friend class CodeBuffer; public: typedef int csize_t; // code size type; would be size_t except for history private: address _start; // first byte of contents (instructions) address _mark; // user mark, usually an instruction beginning address _end; // current end address address _limit; // last possible (allocated) end address relocInfo* _locs_start; // first byte of relocation information relocInfo* _locs_end; // first byte after relocation information relocInfo* _locs_limit; // first byte after relocation information buf address _locs_point; // last relocated position (grows upward) 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.) CodeBuffer* _outer; // enclosing CodeBuffer // (Note: _locs_point used to be called _last_reloc_offset.) CodeSection() { _start = NULL; _mark = NULL; _end = NULL; _limit = NULL; _locs_start = NULL; _locs_end = NULL; _locs_limit = NULL; _locs_point = NULL; _locs_own = false; _frozen = false; debug_only(_index = (char)-1); debug_only(_outer = (CodeBuffer*)badAddress); } void initialize_outer(CodeBuffer* outer, int index) { _outer = outer; _index = index; } void initialize(address start, csize_t size = 0) { assert(_start == NULL, "only one init step, please"); _start = start; _mark = NULL; _end = start; _limit = start + size; _locs_point = start; } void initialize_locs(int locs_capacity); void expand_locs(int new_capacity); void initialize_locs_from(const CodeSection* source_cs); // helper for CodeBuffer::expand() void take_over_code_from(CodeSection* cs) { _start = cs->_start; _mark = cs->_mark; _end = cs->_end; _limit = cs->_limit; _locs_point = cs->_locs_point; } public: address start() const { return _start; } address mark() const { return _mark; } address end() const { return _end; } address limit() const { return _limit; } csize_t size() const { return (csize_t)(_end - _start); } csize_t mark_off() const { assert(_mark != NULL, "not an offset"); return (csize_t)(_mark - _start); } csize_t capacity() const { return (csize_t)(_limit - _start); } csize_t remaining() const { return (csize_t)(_limit - _end); } relocInfo* locs_start() const { return _locs_start; } relocInfo* locs_end() const { return _locs_end; } int locs_count() const { return (int)(_locs_end - _locs_start); } relocInfo* locs_limit() const { return _locs_limit; } address locs_point() const { return _locs_point; } csize_t locs_point_off() const{ return (csize_t)(_locs_point - _start); } csize_t locs_capacity() const { return (csize_t)(_locs_limit - _locs_start); } csize_t locs_remaining()const { return (csize_t)(_locs_limit - _locs_end); } int index() const { return _index; } bool is_allocated() const { return _start != NULL; } bool is_empty() const { return _start == _end; } bool is_frozen() const { return _frozen; } bool has_locs() const { return _locs_end != NULL; } CodeBuffer* outer() const { return _outer; } // is a given address in this section? (2nd version is end-inclusive) bool contains(address pc) const { return pc >= _start && pc < _end; } bool contains2(address pc) const { return pc >= _start && pc <= _end; } bool allocates(address pc) const { return pc >= _start && pc < _limit; } bool allocates2(address pc) const { return pc >= _start && pc <= _limit; } void set_end(address pc) { assert(allocates2(pc), err_msg("not in CodeBuffer memory: " PTR_FORMAT " <= " PTR_FORMAT " <= " PTR_FORMAT, _start, pc, _limit)); _end = pc; } void set_mark(address pc) { assert(contains2(pc), "not in codeBuffer"); _mark = pc; } void set_mark_off(int offset) { assert(contains2(offset+_start),"not in codeBuffer"); _mark = offset + _start; } void set_mark() { _mark = _end; } void clear_mark() { _mark = NULL; } void set_locs_end(relocInfo* p) { assert(p <= locs_limit(), "locs data fits in allocated buffer"); _locs_end = p; } void set_locs_point(address pc) { assert(pc >= locs_point(), "relocation addr may not decrease"); assert(allocates2(pc), "relocation addr must be in this section"); _locs_point = pc; } // Code emission void emit_int8 ( int8_t x) { *((int8_t*) end()) = x; set_end(end() + sizeof(int8_t)); } void emit_int16( int16_t x) { *((int16_t*) end()) = x; set_end(end() + sizeof(int16_t)); } void emit_int32( int32_t x) { *((int32_t*) end()) = x; set_end(end() + sizeof(int32_t)); } void emit_int64( int64_t x) { *((int64_t*) end()) = x; set_end(end() + sizeof(int64_t)); } void emit_float( jfloat x) { *((jfloat*) end()) = x; set_end(end() + sizeof(jfloat)); } void emit_double(jdouble x) { *((jdouble*) end()) = x; set_end(end() + sizeof(jdouble)); } void emit_address(address x) { *((address*) end()) = x; set_end(end() + sizeof(address)); } // Share a scratch buffer for relocinfo. (Hacky; saves a resource allocation.) void initialize_shared_locs(relocInfo* buf, int length); // Manage labels and their addresses. address target(Label& L, address branch_pc); // Emit a relocation. void relocate(address at, RelocationHolder const& rspec, int format = 0); void relocate(address at, relocInfo::relocType rtype, int format = 0) { if (rtype != relocInfo::none) relocate(at, Relocation::spec_simple(rtype), format); } // 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) int alignment() const { return MAX2((int)sizeof(jdouble), (int)CodeEntryAlignment); } // Slop between sections, used only when allocating temporary BufferBlob buffers. static csize_t end_slop() { return MAX2((int)sizeof(jdouble), (int)CodeEntryAlignment); } csize_t align_at_start(csize_t off) const { return (csize_t) align_size_up(off, alignment()); } // 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. bool maybe_expand_to_ensure_remaining(csize_t amount); #ifndef PRODUCT void decode(); void dump(); void print(const char* name); #endif //PRODUCT }; class CodeString; class CodeStrings VALUE_OBJ_CLASS_SPEC { private: #ifndef PRODUCT CodeString* _strings; #endif CodeString* find(intptr_t offset) const; CodeString* find_last(intptr_t offset) const; public: CodeStrings() { #ifndef PRODUCT _strings = NULL; #endif } const char* add_string(const char * string) PRODUCT_RETURN_(return NULL;); void add_comment(intptr_t offset, const char * comment) PRODUCT_RETURN; void print_block_comment(outputStream* stream, intptr_t offset) const PRODUCT_RETURN; void assign(CodeStrings& other) PRODUCT_RETURN; void free() PRODUCT_RETURN; }; // 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 // information. // // (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. class CodeBuffer: public StackObj { friend class CodeSection; private: // 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. void* operator new(size_t size) throw() { return ResourceObj::operator new(size); } void operator delete(void* p) { ShouldNotCallThis(); } public: typedef int csize_t; // code size type; would be size_t except for history enum { // Here is the list of all possible sections. The order reflects // the final layout. SECT_FIRST = 0, SECT_CONSTS = SECT_FIRST, // Non-instruction data: Floats, jump tables, etc. SECT_INSTS, // Executable instructions. SECT_STUBS, // Outbound trampolines for supporting call sites. SECT_LIMIT, SECT_NONE = -1 }; private: enum { sect_bits = 2, // assert (SECT_LIMIT <= (1< Other Java examples (source code examples)Here is a short list of links related to this Java codeBuffer.hpp source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.