1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/asm/codeBuffer.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,608 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_ASM_CODEBUFFER_HPP 1.29 +#define SHARE_VM_ASM_CODEBUFFER_HPP 1.30 + 1.31 +#include "code/oopRecorder.hpp" 1.32 +#include "code/relocInfo.hpp" 1.33 + 1.34 +class CodeStrings; 1.35 +class PhaseCFG; 1.36 +class Compile; 1.37 +class BufferBlob; 1.38 +class CodeBuffer; 1.39 +class Label; 1.40 + 1.41 +class CodeOffsets: public StackObj { 1.42 +public: 1.43 + enum Entries { Entry, 1.44 + Verified_Entry, 1.45 + Frame_Complete, // Offset in the code where the frame setup is (for forte stackwalks) is complete 1.46 + OSR_Entry, 1.47 + Dtrace_trap = OSR_Entry, // dtrace probes can never have an OSR entry so reuse it 1.48 + Exceptions, // Offset where exception handler lives 1.49 + Deopt, // Offset where deopt handler lives 1.50 + DeoptMH, // Offset where MethodHandle deopt handler lives 1.51 + UnwindHandler, // Offset to default unwind handler 1.52 + max_Entries }; 1.53 + 1.54 + // special value to note codeBlobs where profile (forte) stack walking is 1.55 + // always dangerous and suspect. 1.56 + 1.57 + enum { frame_never_safe = -1 }; 1.58 + 1.59 +private: 1.60 + int _values[max_Entries]; 1.61 + 1.62 +public: 1.63 + CodeOffsets() { 1.64 + _values[Entry ] = 0; 1.65 + _values[Verified_Entry] = 0; 1.66 + _values[Frame_Complete] = frame_never_safe; 1.67 + _values[OSR_Entry ] = 0; 1.68 + _values[Exceptions ] = -1; 1.69 + _values[Deopt ] = -1; 1.70 + _values[DeoptMH ] = -1; 1.71 + _values[UnwindHandler ] = -1; 1.72 + } 1.73 + 1.74 + int value(Entries e) { return _values[e]; } 1.75 + void set_value(Entries e, int val) { _values[e] = val; } 1.76 +}; 1.77 + 1.78 +// This class represents a stream of code and associated relocations. 1.79 +// There are a few in each CodeBuffer. 1.80 +// They are filled concurrently, and concatenated at the end. 1.81 +class CodeSection VALUE_OBJ_CLASS_SPEC { 1.82 + friend class CodeBuffer; 1.83 + public: 1.84 + typedef int csize_t; // code size type; would be size_t except for history 1.85 + 1.86 + private: 1.87 + address _start; // first byte of contents (instructions) 1.88 + address _mark; // user mark, usually an instruction beginning 1.89 + address _end; // current end address 1.90 + address _limit; // last possible (allocated) end address 1.91 + relocInfo* _locs_start; // first byte of relocation information 1.92 + relocInfo* _locs_end; // first byte after relocation information 1.93 + relocInfo* _locs_limit; // first byte after relocation information buf 1.94 + address _locs_point; // last relocated position (grows upward) 1.95 + bool _locs_own; // did I allocate the locs myself? 1.96 + bool _frozen; // no more expansion of this section 1.97 + char _index; // my section number (SECT_INST, etc.) 1.98 + CodeBuffer* _outer; // enclosing CodeBuffer 1.99 + 1.100 + // (Note: _locs_point used to be called _last_reloc_offset.) 1.101 + 1.102 + CodeSection() { 1.103 + _start = NULL; 1.104 + _mark = NULL; 1.105 + _end = NULL; 1.106 + _limit = NULL; 1.107 + _locs_start = NULL; 1.108 + _locs_end = NULL; 1.109 + _locs_limit = NULL; 1.110 + _locs_point = NULL; 1.111 + _locs_own = false; 1.112 + _frozen = false; 1.113 + debug_only(_index = (char)-1); 1.114 + debug_only(_outer = (CodeBuffer*)badAddress); 1.115 + } 1.116 + 1.117 + void initialize_outer(CodeBuffer* outer, int index) { 1.118 + _outer = outer; 1.119 + _index = index; 1.120 + } 1.121 + 1.122 + void initialize(address start, csize_t size = 0) { 1.123 + assert(_start == NULL, "only one init step, please"); 1.124 + _start = start; 1.125 + _mark = NULL; 1.126 + _end = start; 1.127 + 1.128 + _limit = start + size; 1.129 + _locs_point = start; 1.130 + } 1.131 + 1.132 + void initialize_locs(int locs_capacity); 1.133 + void expand_locs(int new_capacity); 1.134 + void initialize_locs_from(const CodeSection* source_cs); 1.135 + 1.136 + // helper for CodeBuffer::expand() 1.137 + void take_over_code_from(CodeSection* cs) { 1.138 + _start = cs->_start; 1.139 + _mark = cs->_mark; 1.140 + _end = cs->_end; 1.141 + _limit = cs->_limit; 1.142 + _locs_point = cs->_locs_point; 1.143 + } 1.144 + 1.145 + public: 1.146 + address start() const { return _start; } 1.147 + address mark() const { return _mark; } 1.148 + address end() const { return _end; } 1.149 + address limit() const { return _limit; } 1.150 + csize_t size() const { return (csize_t)(_end - _start); } 1.151 + csize_t mark_off() const { assert(_mark != NULL, "not an offset"); 1.152 + return (csize_t)(_mark - _start); } 1.153 + csize_t capacity() const { return (csize_t)(_limit - _start); } 1.154 + csize_t remaining() const { return (csize_t)(_limit - _end); } 1.155 + 1.156 + relocInfo* locs_start() const { return _locs_start; } 1.157 + relocInfo* locs_end() const { return _locs_end; } 1.158 + int locs_count() const { return (int)(_locs_end - _locs_start); } 1.159 + relocInfo* locs_limit() const { return _locs_limit; } 1.160 + address locs_point() const { return _locs_point; } 1.161 + csize_t locs_point_off() const{ return (csize_t)(_locs_point - _start); } 1.162 + csize_t locs_capacity() const { return (csize_t)(_locs_limit - _locs_start); } 1.163 + csize_t locs_remaining()const { return (csize_t)(_locs_limit - _locs_end); } 1.164 + 1.165 + int index() const { return _index; } 1.166 + bool is_allocated() const { return _start != NULL; } 1.167 + bool is_empty() const { return _start == _end; } 1.168 + bool is_frozen() const { return _frozen; } 1.169 + bool has_locs() const { return _locs_end != NULL; } 1.170 + 1.171 + CodeBuffer* outer() const { return _outer; } 1.172 + 1.173 + // is a given address in this section? (2nd version is end-inclusive) 1.174 + bool contains(address pc) const { return pc >= _start && pc < _end; } 1.175 + bool contains2(address pc) const { return pc >= _start && pc <= _end; } 1.176 + bool allocates(address pc) const { return pc >= _start && pc < _limit; } 1.177 + bool allocates2(address pc) const { return pc >= _start && pc <= _limit; } 1.178 + 1.179 + void set_end(address pc) { assert(allocates2(pc), err_msg("not in CodeBuffer memory: " PTR_FORMAT " <= " PTR_FORMAT " <= " INTPTR_FORMAT, p2i(_start), p2i(pc), p2i(_limit))); _end = pc; } 1.180 + void set_mark(address pc) { assert(contains2(pc), "not in codeBuffer"); 1.181 + _mark = pc; } 1.182 + void set_mark_off(int offset) { assert(contains2(offset+_start),"not in codeBuffer"); 1.183 + _mark = offset + _start; } 1.184 + void set_mark() { _mark = _end; } 1.185 + void clear_mark() { _mark = NULL; } 1.186 + 1.187 + void set_locs_end(relocInfo* p) { 1.188 + assert(p <= locs_limit(), "locs data fits in allocated buffer"); 1.189 + _locs_end = p; 1.190 + } 1.191 + void set_locs_point(address pc) { 1.192 + assert(pc >= locs_point(), "relocation addr may not decrease"); 1.193 + assert(allocates2(pc), "relocation addr must be in this section"); 1.194 + _locs_point = pc; 1.195 + } 1.196 + 1.197 + // Code emission 1.198 + void emit_int8 ( int8_t x) { *((int8_t*) end()) = x; set_end(end() + sizeof(int8_t)); } 1.199 + void emit_int16( int16_t x) { *((int16_t*) end()) = x; set_end(end() + sizeof(int16_t)); } 1.200 + void emit_int32( int32_t x) { *((int32_t*) end()) = x; set_end(end() + sizeof(int32_t)); } 1.201 + void emit_int64( int64_t x) { *((int64_t*) end()) = x; set_end(end() + sizeof(int64_t)); } 1.202 + 1.203 + void emit_float( jfloat x) { *((jfloat*) end()) = x; set_end(end() + sizeof(jfloat)); } 1.204 + void emit_double(jdouble x) { *((jdouble*) end()) = x; set_end(end() + sizeof(jdouble)); } 1.205 + void emit_address(address x) { *((address*) end()) = x; set_end(end() + sizeof(address)); } 1.206 + 1.207 + // Share a scratch buffer for relocinfo. (Hacky; saves a resource allocation.) 1.208 + void initialize_shared_locs(relocInfo* buf, int length); 1.209 + 1.210 + // Manage labels and their addresses. 1.211 + address target(Label& L, address branch_pc); 1.212 + 1.213 + // Emit a relocation. 1.214 + void relocate(address at, RelocationHolder const& rspec, int format = 0); 1.215 + void relocate(address at, relocInfo::relocType rtype, int format = 0) { 1.216 + if (rtype != relocInfo::none) 1.217 + relocate(at, Relocation::spec_simple(rtype), format); 1.218 + } 1.219 + 1.220 + // alignment requirement for starting offset 1.221 + // Requirements are that the instruction area and the 1.222 + // stubs area must start on CodeEntryAlignment, and 1.223 + // the ctable on sizeof(jdouble) 1.224 + int alignment() const { return MAX2((int)sizeof(jdouble), (int)CodeEntryAlignment); } 1.225 + 1.226 + // Slop between sections, used only when allocating temporary BufferBlob buffers. 1.227 + static csize_t end_slop() { return MAX2((int)sizeof(jdouble), (int)CodeEntryAlignment); } 1.228 + 1.229 + csize_t align_at_start(csize_t off) const { return (csize_t) align_size_up(off, alignment()); } 1.230 + 1.231 + // Mark a section frozen. Assign its remaining space to 1.232 + // the following section. It will never expand after this point. 1.233 + inline void freeze(); // { _outer->freeze_section(this); } 1.234 + 1.235 + // Ensure there's enough space left in the current section. 1.236 + // Return true if there was an expansion. 1.237 + bool maybe_expand_to_ensure_remaining(csize_t amount); 1.238 + 1.239 +#ifndef PRODUCT 1.240 + void decode(); 1.241 + void dump(); 1.242 + void print(const char* name); 1.243 +#endif //PRODUCT 1.244 +}; 1.245 + 1.246 +class CodeString; 1.247 +class CodeStrings VALUE_OBJ_CLASS_SPEC { 1.248 +private: 1.249 +#ifndef PRODUCT 1.250 + CodeString* _strings; 1.251 +#endif 1.252 + 1.253 + CodeString* find(intptr_t offset) const; 1.254 + CodeString* find_last(intptr_t offset) const; 1.255 + 1.256 +public: 1.257 + CodeStrings() { 1.258 +#ifndef PRODUCT 1.259 + _strings = NULL; 1.260 +#endif 1.261 + } 1.262 + 1.263 + const char* add_string(const char * string) PRODUCT_RETURN_(return NULL;); 1.264 + 1.265 + void add_comment(intptr_t offset, const char * comment) PRODUCT_RETURN; 1.266 + void print_block_comment(outputStream* stream, intptr_t offset) const PRODUCT_RETURN; 1.267 + void assign(CodeStrings& other) PRODUCT_RETURN; 1.268 + void free() PRODUCT_RETURN; 1.269 +}; 1.270 + 1.271 +// A CodeBuffer describes a memory space into which assembly 1.272 +// code is generated. This memory space usually occupies the 1.273 +// interior of a single BufferBlob, but in some cases it may be 1.274 +// an arbitrary span of memory, even outside the code cache. 1.275 +// 1.276 +// A code buffer comes in two variants: 1.277 +// 1.278 +// (1) A CodeBuffer referring to an already allocated piece of memory: 1.279 +// This is used to direct 'static' code generation (e.g. for interpreter 1.280 +// or stubroutine generation, etc.). This code comes with NO relocation 1.281 +// information. 1.282 +// 1.283 +// (2) A CodeBuffer referring to a piece of memory allocated when the 1.284 +// CodeBuffer is allocated. This is used for nmethod generation. 1.285 +// 1.286 +// The memory can be divided up into several parts called sections. 1.287 +// Each section independently accumulates code (or data) an relocations. 1.288 +// Sections can grow (at the expense of a reallocation of the BufferBlob 1.289 +// and recopying of all active sections). When the buffered code is finally 1.290 +// written to an nmethod (or other CodeBlob), the contents (code, data, 1.291 +// and relocations) of the sections are padded to an alignment and concatenated. 1.292 +// Instructions and data in one section can contain relocatable references to 1.293 +// addresses in a sibling section. 1.294 + 1.295 +class CodeBuffer: public StackObj { 1.296 + friend class CodeSection; 1.297 + 1.298 + private: 1.299 + // CodeBuffers must be allocated on the stack except for a single 1.300 + // special case during expansion which is handled internally. This 1.301 + // is done to guarantee proper cleanup of resources. 1.302 + void* operator new(size_t size) throw() { return ResourceObj::operator new(size); } 1.303 + void operator delete(void* p) { ShouldNotCallThis(); } 1.304 + 1.305 + public: 1.306 + typedef int csize_t; // code size type; would be size_t except for history 1.307 + enum { 1.308 + // Here is the list of all possible sections. The order reflects 1.309 + // the final layout. 1.310 + SECT_FIRST = 0, 1.311 + SECT_CONSTS = SECT_FIRST, // Non-instruction data: Floats, jump tables, etc. 1.312 + SECT_INSTS, // Executable instructions. 1.313 + SECT_STUBS, // Outbound trampolines for supporting call sites. 1.314 + SECT_LIMIT, SECT_NONE = -1 1.315 + }; 1.316 + 1.317 + private: 1.318 + enum { 1.319 + sect_bits = 2, // assert (SECT_LIMIT <= (1<<sect_bits)) 1.320 + sect_mask = (1<<sect_bits)-1 1.321 + }; 1.322 + 1.323 + const char* _name; 1.324 + 1.325 + CodeSection _consts; // constants, jump tables 1.326 + CodeSection _insts; // instructions (the main section) 1.327 + CodeSection _stubs; // stubs (call site support), deopt, exception handling 1.328 + 1.329 + CodeBuffer* _before_expand; // dead buffer, from before the last expansion 1.330 + 1.331 + BufferBlob* _blob; // optional buffer in CodeCache for generated code 1.332 + address _total_start; // first address of combined memory buffer 1.333 + csize_t _total_size; // size in bytes of combined memory buffer 1.334 + 1.335 + OopRecorder* _oop_recorder; 1.336 + CodeStrings _strings; 1.337 + OopRecorder _default_oop_recorder; // override with initialize_oop_recorder 1.338 + Arena* _overflow_arena; 1.339 + 1.340 + address _decode_begin; // start address for decode 1.341 + address decode_begin(); 1.342 + 1.343 + void initialize_misc(const char * name) { 1.344 + // all pointers other than code_start/end and those inside the sections 1.345 + assert(name != NULL, "must have a name"); 1.346 + _name = name; 1.347 + _before_expand = NULL; 1.348 + _blob = NULL; 1.349 + _oop_recorder = NULL; 1.350 + _decode_begin = NULL; 1.351 + _overflow_arena = NULL; 1.352 + } 1.353 + 1.354 + void initialize(address code_start, csize_t code_size) { 1.355 + _consts.initialize_outer(this, SECT_CONSTS); 1.356 + _insts.initialize_outer(this, SECT_INSTS); 1.357 + _stubs.initialize_outer(this, SECT_STUBS); 1.358 + _total_start = code_start; 1.359 + _total_size = code_size; 1.360 + // Initialize the main section: 1.361 + _insts.initialize(code_start, code_size); 1.362 + assert(!_stubs.is_allocated(), "no garbage here"); 1.363 + assert(!_consts.is_allocated(), "no garbage here"); 1.364 + _oop_recorder = &_default_oop_recorder; 1.365 + } 1.366 + 1.367 + void initialize_section_size(CodeSection* cs, csize_t size); 1.368 + 1.369 + void freeze_section(CodeSection* cs); 1.370 + 1.371 + // helper for CodeBuffer::expand() 1.372 + void take_over_code_from(CodeBuffer* cs); 1.373 + 1.374 + // ensure sections are disjoint, ordered, and contained in the blob 1.375 + void verify_section_allocation(); 1.376 + 1.377 + // copies combined relocations to the blob, returns bytes copied 1.378 + // (if target is null, it is a dry run only, just for sizing) 1.379 + csize_t copy_relocations_to(CodeBlob* blob) const; 1.380 + 1.381 + // copies combined code to the blob (assumes relocs are already in there) 1.382 + void copy_code_to(CodeBlob* blob); 1.383 + 1.384 + // moves code sections to new buffer (assumes relocs are already in there) 1.385 + void relocate_code_to(CodeBuffer* cb) const; 1.386 + 1.387 + // set up a model of the final layout of my contents 1.388 + void compute_final_layout(CodeBuffer* dest) const; 1.389 + 1.390 + // Expand the given section so at least 'amount' is remaining. 1.391 + // Creates a new, larger BufferBlob, and rewrites the code & relocs. 1.392 + void expand(CodeSection* which_cs, csize_t amount); 1.393 + 1.394 + // Helper for expand. 1.395 + csize_t figure_expanded_capacities(CodeSection* which_cs, csize_t amount, csize_t* new_capacity); 1.396 + 1.397 + public: 1.398 + // (1) code buffer referring to pre-allocated instruction memory 1.399 + CodeBuffer(address code_start, csize_t code_size) { 1.400 + assert(code_start != NULL, "sanity"); 1.401 + initialize_misc("static buffer"); 1.402 + initialize(code_start, code_size); 1.403 + verify_section_allocation(); 1.404 + } 1.405 + 1.406 + // (2) CodeBuffer referring to pre-allocated CodeBlob. 1.407 + CodeBuffer(CodeBlob* blob); 1.408 + 1.409 + // (3) code buffer allocating codeBlob memory for code & relocation 1.410 + // info but with lazy initialization. The name must be something 1.411 + // informative. 1.412 + CodeBuffer(const char* name) { 1.413 + initialize_misc(name); 1.414 + } 1.415 + 1.416 + 1.417 + // (4) code buffer allocating codeBlob memory for code & relocation 1.418 + // info. The name must be something informative and code_size must 1.419 + // include both code and stubs sizes. 1.420 + CodeBuffer(const char* name, csize_t code_size, csize_t locs_size) { 1.421 + initialize_misc(name); 1.422 + initialize(code_size, locs_size); 1.423 + } 1.424 + 1.425 + ~CodeBuffer(); 1.426 + 1.427 + // Initialize a CodeBuffer constructed using constructor 3. Using 1.428 + // constructor 4 is equivalent to calling constructor 3 and then 1.429 + // calling this method. It's been factored out for convenience of 1.430 + // construction. 1.431 + void initialize(csize_t code_size, csize_t locs_size); 1.432 + 1.433 + CodeSection* consts() { return &_consts; } 1.434 + CodeSection* insts() { return &_insts; } 1.435 + CodeSection* stubs() { return &_stubs; } 1.436 + 1.437 + // present sections in order; return NULL at end; consts is #0, etc. 1.438 + CodeSection* code_section(int n) { 1.439 + // This makes the slightly questionable but portable assumption 1.440 + // that the various members (_consts, _insts, _stubs, etc.) are 1.441 + // adjacent in the layout of CodeBuffer. 1.442 + CodeSection* cs = &_consts + n; 1.443 + assert(cs->index() == n || !cs->is_allocated(), "sanity"); 1.444 + return cs; 1.445 + } 1.446 + const CodeSection* code_section(int n) const { // yucky const stuff 1.447 + return ((CodeBuffer*)this)->code_section(n); 1.448 + } 1.449 + static const char* code_section_name(int n); 1.450 + int section_index_of(address addr) const; 1.451 + bool contains(address addr) const { 1.452 + // handy for debugging 1.453 + return section_index_of(addr) > SECT_NONE; 1.454 + } 1.455 + 1.456 + // A stable mapping between 'locators' (small ints) and addresses. 1.457 + static int locator_pos(int locator) { return locator >> sect_bits; } 1.458 + static int locator_sect(int locator) { return locator & sect_mask; } 1.459 + static int locator(int pos, int sect) { return (pos << sect_bits) | sect; } 1.460 + int locator(address addr) const; 1.461 + address locator_address(int locator) const; 1.462 + 1.463 + // Heuristic for pre-packing the taken/not-taken bit of a predicted branch. 1.464 + bool is_backward_branch(Label& L); 1.465 + 1.466 + // Properties 1.467 + const char* name() const { return _name; } 1.468 + CodeBuffer* before_expand() const { return _before_expand; } 1.469 + BufferBlob* blob() const { return _blob; } 1.470 + void set_blob(BufferBlob* blob); 1.471 + void free_blob(); // Free the blob, if we own one. 1.472 + 1.473 + // Properties relative to the insts section: 1.474 + address insts_begin() const { return _insts.start(); } 1.475 + address insts_end() const { return _insts.end(); } 1.476 + void set_insts_end(address end) { _insts.set_end(end); } 1.477 + address insts_limit() const { return _insts.limit(); } 1.478 + address insts_mark() const { return _insts.mark(); } 1.479 + void set_insts_mark() { _insts.set_mark(); } 1.480 + void clear_insts_mark() { _insts.clear_mark(); } 1.481 + 1.482 + // is there anything in the buffer other than the current section? 1.483 + bool is_pure() const { return insts_size() == total_content_size(); } 1.484 + 1.485 + // size in bytes of output so far in the insts sections 1.486 + csize_t insts_size() const { return _insts.size(); } 1.487 + 1.488 + // same as insts_size(), except that it asserts there is no non-code here 1.489 + csize_t pure_insts_size() const { assert(is_pure(), "no non-code"); 1.490 + return insts_size(); } 1.491 + // capacity in bytes of the insts sections 1.492 + csize_t insts_capacity() const { return _insts.capacity(); } 1.493 + 1.494 + // number of bytes remaining in the insts section 1.495 + csize_t insts_remaining() const { return _insts.remaining(); } 1.496 + 1.497 + // is a given address in the insts section? (2nd version is end-inclusive) 1.498 + bool insts_contains(address pc) const { return _insts.contains(pc); } 1.499 + bool insts_contains2(address pc) const { return _insts.contains2(pc); } 1.500 + 1.501 + // Record any extra oops required to keep embedded metadata alive 1.502 + void finalize_oop_references(methodHandle method); 1.503 + 1.504 + // Allocated size in all sections, when aligned and concatenated 1.505 + // (this is the eventual state of the content in its final 1.506 + // CodeBlob). 1.507 + csize_t total_content_size() const; 1.508 + 1.509 + // Combined offset (relative to start of first section) of given 1.510 + // section, as eventually found in the final CodeBlob. 1.511 + csize_t total_offset_of(CodeSection* cs) const; 1.512 + 1.513 + // allocated size of all relocation data, including index, rounded up 1.514 + csize_t total_relocation_size() const; 1.515 + 1.516 + // allocated size of any and all recorded oops 1.517 + csize_t total_oop_size() const { 1.518 + OopRecorder* recorder = oop_recorder(); 1.519 + return (recorder == NULL)? 0: recorder->oop_size(); 1.520 + } 1.521 + 1.522 + // allocated size of any and all recorded metadata 1.523 + csize_t total_metadata_size() const { 1.524 + OopRecorder* recorder = oop_recorder(); 1.525 + return (recorder == NULL)? 0: recorder->metadata_size(); 1.526 + } 1.527 + 1.528 + // Configuration functions, called immediately after the CB is constructed. 1.529 + // The section sizes are subtracted from the original insts section. 1.530 + // Note: Call them in reverse section order, because each steals from insts. 1.531 + void initialize_consts_size(csize_t size) { initialize_section_size(&_consts, size); } 1.532 + void initialize_stubs_size(csize_t size) { initialize_section_size(&_stubs, size); } 1.533 + // Override default oop recorder. 1.534 + void initialize_oop_recorder(OopRecorder* r); 1.535 + 1.536 + OopRecorder* oop_recorder() const { return _oop_recorder; } 1.537 + CodeStrings& strings() { return _strings; } 1.538 + 1.539 + // Code generation 1.540 + void relocate(address at, RelocationHolder const& rspec, int format = 0) { 1.541 + _insts.relocate(at, rspec, format); 1.542 + } 1.543 + void relocate(address at, relocInfo::relocType rtype, int format = 0) { 1.544 + _insts.relocate(at, rtype, format); 1.545 + } 1.546 + 1.547 + // Management of overflow storage for binding of Labels. 1.548 + GrowableArray<int>* create_patch_overflow(); 1.549 + 1.550 + // NMethod generation 1.551 + void copy_code_and_locs_to(CodeBlob* blob) { 1.552 + assert(blob != NULL, "sane"); 1.553 + copy_relocations_to(blob); 1.554 + copy_code_to(blob); 1.555 + } 1.556 + void copy_values_to(nmethod* nm) { 1.557 + if (!oop_recorder()->is_unused()) { 1.558 + oop_recorder()->copy_values_to(nm); 1.559 + } 1.560 + } 1.561 + 1.562 + // Transform an address from the code in this code buffer to a specified code buffer 1.563 + address transform_address(const CodeBuffer &cb, address addr) const; 1.564 + 1.565 + void block_comment(intptr_t offset, const char * comment) PRODUCT_RETURN; 1.566 + const char* code_string(const char* str) PRODUCT_RETURN_(return NULL;); 1.567 + 1.568 + // Log a little info about section usage in the CodeBuffer 1.569 + void log_section_sizes(const char* name); 1.570 + 1.571 +#ifndef PRODUCT 1.572 + public: 1.573 + // Printing / Decoding 1.574 + // decodes from decode_begin() to code_end() and sets decode_begin to end 1.575 + void decode(); 1.576 + void decode_all(); // decodes all the code 1.577 + void skip_decode(); // sets decode_begin to code_end(); 1.578 + void print(); 1.579 +#endif 1.580 + 1.581 + 1.582 + // The following header contains architecture-specific implementations 1.583 +#ifdef TARGET_ARCH_x86 1.584 +# include "codeBuffer_x86.hpp" 1.585 +#endif 1.586 +#ifdef TARGET_ARCH_sparc 1.587 +# include "codeBuffer_sparc.hpp" 1.588 +#endif 1.589 +#ifdef TARGET_ARCH_zero 1.590 +# include "codeBuffer_zero.hpp" 1.591 +#endif 1.592 +#ifdef TARGET_ARCH_arm 1.593 +# include "codeBuffer_arm.hpp" 1.594 +#endif 1.595 +#ifdef TARGET_ARCH_ppc 1.596 +# include "codeBuffer_ppc.hpp" 1.597 +#endif 1.598 + 1.599 +}; 1.600 + 1.601 + 1.602 +inline void CodeSection::freeze() { 1.603 + _outer->freeze_section(this); 1.604 +} 1.605 + 1.606 +inline bool CodeSection::maybe_expand_to_ensure_remaining(csize_t amount) { 1.607 + if (remaining() < amount) { _outer->expand(this, amount); return true; } 1.608 + return false; 1.609 +} 1.610 + 1.611 +#endif // SHARE_VM_ASM_CODEBUFFER_HPP