src/share/vm/asm/codeBuffer.hpp

Fri, 29 Apr 2016 00:06:10 +0800

author
aoqi
date
Fri, 29 Apr 2016 00:06:10 +0800
changeset 1
2d8a650513c2
parent 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Added MIPS 64-bit port.

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@1 25 /*
aoqi@1 26 * This file has been modified by Loongson Technology in 2015. These
aoqi@1 27 * modifications are Copyright (c) 2015 Loongson Technology, and are made
aoqi@1 28 * available on the same license terms set forth above.
aoqi@1 29 */
aoqi@1 30
aoqi@0 31 #ifndef SHARE_VM_ASM_CODEBUFFER_HPP
aoqi@0 32 #define SHARE_VM_ASM_CODEBUFFER_HPP
aoqi@0 33
aoqi@0 34 #include "code/oopRecorder.hpp"
aoqi@0 35 #include "code/relocInfo.hpp"
aoqi@0 36
aoqi@0 37 class CodeStrings;
aoqi@0 38 class PhaseCFG;
aoqi@0 39 class Compile;
aoqi@0 40 class BufferBlob;
aoqi@0 41 class CodeBuffer;
aoqi@0 42 class Label;
aoqi@0 43
aoqi@0 44 class CodeOffsets: public StackObj {
aoqi@0 45 public:
aoqi@0 46 enum Entries { Entry,
aoqi@0 47 Verified_Entry,
aoqi@0 48 Frame_Complete, // Offset in the code where the frame setup is (for forte stackwalks) is complete
aoqi@0 49 OSR_Entry,
aoqi@0 50 Dtrace_trap = OSR_Entry, // dtrace probes can never have an OSR entry so reuse it
aoqi@0 51 Exceptions, // Offset where exception handler lives
aoqi@0 52 Deopt, // Offset where deopt handler lives
aoqi@0 53 DeoptMH, // Offset where MethodHandle deopt handler lives
aoqi@0 54 UnwindHandler, // Offset to default unwind handler
aoqi@0 55 max_Entries };
aoqi@0 56
aoqi@0 57 // special value to note codeBlobs where profile (forte) stack walking is
aoqi@0 58 // always dangerous and suspect.
aoqi@0 59
aoqi@0 60 enum { frame_never_safe = -1 };
aoqi@0 61
aoqi@0 62 private:
aoqi@0 63 int _values[max_Entries];
aoqi@0 64
aoqi@0 65 public:
aoqi@0 66 CodeOffsets() {
aoqi@0 67 _values[Entry ] = 0;
aoqi@0 68 _values[Verified_Entry] = 0;
aoqi@0 69 _values[Frame_Complete] = frame_never_safe;
aoqi@0 70 _values[OSR_Entry ] = 0;
aoqi@0 71 _values[Exceptions ] = -1;
aoqi@0 72 _values[Deopt ] = -1;
aoqi@0 73 _values[DeoptMH ] = -1;
aoqi@0 74 _values[UnwindHandler ] = -1;
aoqi@0 75 }
aoqi@0 76
aoqi@0 77 int value(Entries e) { return _values[e]; }
aoqi@0 78 void set_value(Entries e, int val) { _values[e] = val; }
aoqi@0 79 };
aoqi@0 80
aoqi@0 81 // This class represents a stream of code and associated relocations.
aoqi@0 82 // There are a few in each CodeBuffer.
aoqi@0 83 // They are filled concurrently, and concatenated at the end.
aoqi@0 84 class CodeSection VALUE_OBJ_CLASS_SPEC {
aoqi@0 85 friend class CodeBuffer;
aoqi@0 86 public:
aoqi@0 87 typedef int csize_t; // code size type; would be size_t except for history
aoqi@0 88
aoqi@0 89 private:
aoqi@0 90 address _start; // first byte of contents (instructions)
aoqi@0 91 address _mark; // user mark, usually an instruction beginning
aoqi@0 92 address _end; // current end address
aoqi@0 93 address _limit; // last possible (allocated) end address
aoqi@0 94 relocInfo* _locs_start; // first byte of relocation information
aoqi@0 95 relocInfo* _locs_end; // first byte after relocation information
aoqi@0 96 relocInfo* _locs_limit; // first byte after relocation information buf
aoqi@0 97 address _locs_point; // last relocated position (grows upward)
aoqi@0 98 bool _locs_own; // did I allocate the locs myself?
aoqi@0 99 bool _frozen; // no more expansion of this section
aoqi@0 100 char _index; // my section number (SECT_INST, etc.)
aoqi@0 101 CodeBuffer* _outer; // enclosing CodeBuffer
aoqi@0 102
aoqi@0 103 // (Note: _locs_point used to be called _last_reloc_offset.)
aoqi@0 104
aoqi@0 105 CodeSection() {
aoqi@0 106 _start = NULL;
aoqi@0 107 _mark = NULL;
aoqi@0 108 _end = NULL;
aoqi@0 109 _limit = NULL;
aoqi@0 110 _locs_start = NULL;
aoqi@0 111 _locs_end = NULL;
aoqi@0 112 _locs_limit = NULL;
aoqi@0 113 _locs_point = NULL;
aoqi@0 114 _locs_own = false;
aoqi@0 115 _frozen = false;
aoqi@0 116 debug_only(_index = (char)-1);
aoqi@0 117 debug_only(_outer = (CodeBuffer*)badAddress);
aoqi@0 118 }
aoqi@0 119
aoqi@0 120 void initialize_outer(CodeBuffer* outer, int index) {
aoqi@0 121 _outer = outer;
aoqi@0 122 _index = index;
aoqi@0 123 }
aoqi@0 124
aoqi@0 125 void initialize(address start, csize_t size = 0) {
aoqi@0 126 assert(_start == NULL, "only one init step, please");
aoqi@0 127 _start = start;
aoqi@0 128 _mark = NULL;
aoqi@0 129 _end = start;
aoqi@0 130
aoqi@0 131 _limit = start + size;
aoqi@0 132 _locs_point = start;
aoqi@0 133 }
aoqi@0 134
aoqi@0 135 void initialize_locs(int locs_capacity);
aoqi@0 136 void expand_locs(int new_capacity);
aoqi@0 137 void initialize_locs_from(const CodeSection* source_cs);
aoqi@0 138
aoqi@0 139 // helper for CodeBuffer::expand()
aoqi@0 140 void take_over_code_from(CodeSection* cs) {
aoqi@0 141 _start = cs->_start;
aoqi@0 142 _mark = cs->_mark;
aoqi@0 143 _end = cs->_end;
aoqi@0 144 _limit = cs->_limit;
aoqi@0 145 _locs_point = cs->_locs_point;
aoqi@0 146 }
aoqi@0 147
aoqi@0 148 public:
aoqi@0 149 address start() const { return _start; }
aoqi@0 150 address mark() const { return _mark; }
aoqi@0 151 address end() const { return _end; }
aoqi@0 152 address limit() const { return _limit; }
aoqi@0 153 csize_t size() const { return (csize_t)(_end - _start); }
aoqi@0 154 csize_t mark_off() const { assert(_mark != NULL, "not an offset");
aoqi@0 155 return (csize_t)(_mark - _start); }
aoqi@0 156 csize_t capacity() const { return (csize_t)(_limit - _start); }
aoqi@0 157 csize_t remaining() const { return (csize_t)(_limit - _end); }
aoqi@0 158
aoqi@0 159 relocInfo* locs_start() const { return _locs_start; }
aoqi@0 160 relocInfo* locs_end() const { return _locs_end; }
aoqi@0 161 int locs_count() const { return (int)(_locs_end - _locs_start); }
aoqi@0 162 relocInfo* locs_limit() const { return _locs_limit; }
aoqi@0 163 address locs_point() const { return _locs_point; }
aoqi@0 164 csize_t locs_point_off() const{ return (csize_t)(_locs_point - _start); }
aoqi@0 165 csize_t locs_capacity() const { return (csize_t)(_locs_limit - _locs_start); }
aoqi@0 166 csize_t locs_remaining()const { return (csize_t)(_locs_limit - _locs_end); }
aoqi@0 167
aoqi@0 168 int index() const { return _index; }
aoqi@0 169 bool is_allocated() const { return _start != NULL; }
aoqi@0 170 bool is_empty() const { return _start == _end; }
aoqi@0 171 bool is_frozen() const { return _frozen; }
aoqi@0 172 bool has_locs() const { return _locs_end != NULL; }
aoqi@0 173
aoqi@0 174 CodeBuffer* outer() const { return _outer; }
aoqi@0 175
aoqi@0 176 // is a given address in this section? (2nd version is end-inclusive)
aoqi@0 177 bool contains(address pc) const { return pc >= _start && pc < _end; }
aoqi@0 178 bool contains2(address pc) const { return pc >= _start && pc <= _end; }
aoqi@0 179 bool allocates(address pc) const { return pc >= _start && pc < _limit; }
aoqi@0 180 bool allocates2(address pc) const { return pc >= _start && pc <= _limit; }
aoqi@0 181
aoqi@0 182 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; }
aoqi@0 183 void set_mark(address pc) { assert(contains2(pc), "not in codeBuffer");
aoqi@0 184 _mark = pc; }
aoqi@0 185 void set_mark_off(int offset) { assert(contains2(offset+_start),"not in codeBuffer");
aoqi@0 186 _mark = offset + _start; }
aoqi@0 187 void set_mark() { _mark = _end; }
aoqi@0 188 void clear_mark() { _mark = NULL; }
aoqi@0 189
aoqi@0 190 void set_locs_end(relocInfo* p) {
aoqi@0 191 assert(p <= locs_limit(), "locs data fits in allocated buffer");
aoqi@0 192 _locs_end = p;
aoqi@0 193 }
aoqi@0 194 void set_locs_point(address pc) {
aoqi@0 195 assert(pc >= locs_point(), "relocation addr may not decrease");
aoqi@0 196 assert(allocates2(pc), "relocation addr must be in this section");
aoqi@0 197 _locs_point = pc;
aoqi@0 198 }
aoqi@0 199
aoqi@0 200 // Code emission
aoqi@0 201 void emit_int8 ( int8_t x) { *((int8_t*) end()) = x; set_end(end() + sizeof(int8_t)); }
aoqi@0 202 void emit_int16( int16_t x) { *((int16_t*) end()) = x; set_end(end() + sizeof(int16_t)); }
aoqi@0 203 void emit_int32( int32_t x) { *((int32_t*) end()) = x; set_end(end() + sizeof(int32_t)); }
aoqi@0 204 void emit_int64( int64_t x) { *((int64_t*) end()) = x; set_end(end() + sizeof(int64_t)); }
aoqi@0 205
aoqi@0 206 void emit_float( jfloat x) { *((jfloat*) end()) = x; set_end(end() + sizeof(jfloat)); }
aoqi@0 207 void emit_double(jdouble x) { *((jdouble*) end()) = x; set_end(end() + sizeof(jdouble)); }
aoqi@0 208 void emit_address(address x) { *((address*) end()) = x; set_end(end() + sizeof(address)); }
aoqi@0 209
aoqi@0 210 // Share a scratch buffer for relocinfo. (Hacky; saves a resource allocation.)
aoqi@0 211 void initialize_shared_locs(relocInfo* buf, int length);
aoqi@0 212
aoqi@0 213 // Manage labels and their addresses.
aoqi@0 214 address target(Label& L, address branch_pc);
aoqi@0 215
aoqi@0 216 // Emit a relocation.
aoqi@0 217 void relocate(address at, RelocationHolder const& rspec, int format = 0);
aoqi@0 218 void relocate(address at, relocInfo::relocType rtype, int format = 0) {
aoqi@0 219 if (rtype != relocInfo::none)
aoqi@0 220 relocate(at, Relocation::spec_simple(rtype), format);
aoqi@0 221 }
aoqi@0 222
aoqi@0 223 // alignment requirement for starting offset
aoqi@0 224 // Requirements are that the instruction area and the
aoqi@0 225 // stubs area must start on CodeEntryAlignment, and
aoqi@0 226 // the ctable on sizeof(jdouble)
aoqi@0 227 int alignment() const { return MAX2((int)sizeof(jdouble), (int)CodeEntryAlignment); }
aoqi@0 228
aoqi@0 229 // Slop between sections, used only when allocating temporary BufferBlob buffers.
aoqi@0 230 static csize_t end_slop() { return MAX2((int)sizeof(jdouble), (int)CodeEntryAlignment); }
aoqi@0 231
aoqi@0 232 csize_t align_at_start(csize_t off) const { return (csize_t) align_size_up(off, alignment()); }
aoqi@0 233
aoqi@0 234 // Mark a section frozen. Assign its remaining space to
aoqi@0 235 // the following section. It will never expand after this point.
aoqi@0 236 inline void freeze(); // { _outer->freeze_section(this); }
aoqi@0 237
aoqi@0 238 // Ensure there's enough space left in the current section.
aoqi@0 239 // Return true if there was an expansion.
aoqi@0 240 bool maybe_expand_to_ensure_remaining(csize_t amount);
aoqi@0 241
aoqi@0 242 #ifndef PRODUCT
aoqi@0 243 void decode();
aoqi@0 244 void dump();
aoqi@0 245 void print(const char* name);
aoqi@0 246 #endif //PRODUCT
aoqi@0 247 };
aoqi@0 248
aoqi@0 249 class CodeString;
aoqi@0 250 class CodeStrings VALUE_OBJ_CLASS_SPEC {
aoqi@0 251 private:
aoqi@0 252 #ifndef PRODUCT
aoqi@0 253 CodeString* _strings;
aoqi@0 254 #endif
aoqi@0 255
aoqi@0 256 CodeString* find(intptr_t offset) const;
aoqi@0 257 CodeString* find_last(intptr_t offset) const;
aoqi@0 258
aoqi@0 259 public:
aoqi@0 260 CodeStrings() {
aoqi@0 261 #ifndef PRODUCT
aoqi@0 262 _strings = NULL;
aoqi@0 263 #endif
aoqi@0 264 }
aoqi@0 265
aoqi@0 266 const char* add_string(const char * string) PRODUCT_RETURN_(return NULL;);
aoqi@0 267
aoqi@0 268 void add_comment(intptr_t offset, const char * comment) PRODUCT_RETURN;
aoqi@0 269 void print_block_comment(outputStream* stream, intptr_t offset) const PRODUCT_RETURN;
aoqi@0 270 void assign(CodeStrings& other) PRODUCT_RETURN;
aoqi@0 271 void free() PRODUCT_RETURN;
aoqi@0 272 };
aoqi@0 273
aoqi@0 274 // A CodeBuffer describes a memory space into which assembly
aoqi@0 275 // code is generated. This memory space usually occupies the
aoqi@0 276 // interior of a single BufferBlob, but in some cases it may be
aoqi@0 277 // an arbitrary span of memory, even outside the code cache.
aoqi@0 278 //
aoqi@0 279 // A code buffer comes in two variants:
aoqi@0 280 //
aoqi@0 281 // (1) A CodeBuffer referring to an already allocated piece of memory:
aoqi@0 282 // This is used to direct 'static' code generation (e.g. for interpreter
aoqi@0 283 // or stubroutine generation, etc.). This code comes with NO relocation
aoqi@0 284 // information.
aoqi@0 285 //
aoqi@0 286 // (2) A CodeBuffer referring to a piece of memory allocated when the
aoqi@0 287 // CodeBuffer is allocated. This is used for nmethod generation.
aoqi@0 288 //
aoqi@0 289 // The memory can be divided up into several parts called sections.
aoqi@0 290 // Each section independently accumulates code (or data) an relocations.
aoqi@0 291 // Sections can grow (at the expense of a reallocation of the BufferBlob
aoqi@0 292 // and recopying of all active sections). When the buffered code is finally
aoqi@0 293 // written to an nmethod (or other CodeBlob), the contents (code, data,
aoqi@0 294 // and relocations) of the sections are padded to an alignment and concatenated.
aoqi@0 295 // Instructions and data in one section can contain relocatable references to
aoqi@0 296 // addresses in a sibling section.
aoqi@0 297
aoqi@0 298 class CodeBuffer: public StackObj {
aoqi@0 299 friend class CodeSection;
aoqi@0 300
aoqi@0 301 private:
aoqi@0 302 // CodeBuffers must be allocated on the stack except for a single
aoqi@0 303 // special case during expansion which is handled internally. This
aoqi@0 304 // is done to guarantee proper cleanup of resources.
aoqi@0 305 void* operator new(size_t size) throw() { return ResourceObj::operator new(size); }
aoqi@0 306 void operator delete(void* p) { ShouldNotCallThis(); }
aoqi@0 307
aoqi@0 308 public:
aoqi@0 309 typedef int csize_t; // code size type; would be size_t except for history
aoqi@0 310 enum {
aoqi@0 311 // Here is the list of all possible sections. The order reflects
aoqi@0 312 // the final layout.
aoqi@0 313 SECT_FIRST = 0,
aoqi@0 314 SECT_CONSTS = SECT_FIRST, // Non-instruction data: Floats, jump tables, etc.
aoqi@0 315 SECT_INSTS, // Executable instructions.
aoqi@0 316 SECT_STUBS, // Outbound trampolines for supporting call sites.
aoqi@0 317 SECT_LIMIT, SECT_NONE = -1
aoqi@0 318 };
aoqi@0 319
aoqi@0 320 private:
aoqi@0 321 enum {
aoqi@0 322 sect_bits = 2, // assert (SECT_LIMIT <= (1<<sect_bits))
aoqi@0 323 sect_mask = (1<<sect_bits)-1
aoqi@0 324 };
aoqi@0 325
aoqi@0 326 const char* _name;
aoqi@0 327
aoqi@0 328 CodeSection _consts; // constants, jump tables
aoqi@0 329 CodeSection _insts; // instructions (the main section)
aoqi@0 330 CodeSection _stubs; // stubs (call site support), deopt, exception handling
aoqi@0 331
aoqi@0 332 CodeBuffer* _before_expand; // dead buffer, from before the last expansion
aoqi@0 333
aoqi@0 334 BufferBlob* _blob; // optional buffer in CodeCache for generated code
aoqi@0 335 address _total_start; // first address of combined memory buffer
aoqi@0 336 csize_t _total_size; // size in bytes of combined memory buffer
aoqi@0 337
aoqi@0 338 OopRecorder* _oop_recorder;
aoqi@0 339 CodeStrings _strings;
aoqi@0 340 OopRecorder _default_oop_recorder; // override with initialize_oop_recorder
aoqi@0 341 Arena* _overflow_arena;
aoqi@0 342
aoqi@0 343 address _decode_begin; // start address for decode
aoqi@0 344 address decode_begin();
aoqi@0 345
aoqi@0 346 void initialize_misc(const char * name) {
aoqi@0 347 // all pointers other than code_start/end and those inside the sections
aoqi@0 348 assert(name != NULL, "must have a name");
aoqi@0 349 _name = name;
aoqi@0 350 _before_expand = NULL;
aoqi@0 351 _blob = NULL;
aoqi@0 352 _oop_recorder = NULL;
aoqi@0 353 _decode_begin = NULL;
aoqi@0 354 _overflow_arena = NULL;
aoqi@0 355 }
aoqi@0 356
aoqi@0 357 void initialize(address code_start, csize_t code_size) {
aoqi@0 358 _consts.initialize_outer(this, SECT_CONSTS);
aoqi@0 359 _insts.initialize_outer(this, SECT_INSTS);
aoqi@0 360 _stubs.initialize_outer(this, SECT_STUBS);
aoqi@0 361 _total_start = code_start;
aoqi@0 362 _total_size = code_size;
aoqi@0 363 // Initialize the main section:
aoqi@0 364 _insts.initialize(code_start, code_size);
aoqi@0 365 assert(!_stubs.is_allocated(), "no garbage here");
aoqi@0 366 assert(!_consts.is_allocated(), "no garbage here");
aoqi@0 367 _oop_recorder = &_default_oop_recorder;
aoqi@0 368 }
aoqi@0 369
aoqi@0 370 void initialize_section_size(CodeSection* cs, csize_t size);
aoqi@0 371
aoqi@0 372 void freeze_section(CodeSection* cs);
aoqi@0 373
aoqi@0 374 // helper for CodeBuffer::expand()
aoqi@0 375 void take_over_code_from(CodeBuffer* cs);
aoqi@0 376
aoqi@0 377 // ensure sections are disjoint, ordered, and contained in the blob
aoqi@0 378 void verify_section_allocation();
aoqi@0 379
aoqi@0 380 // copies combined relocations to the blob, returns bytes copied
aoqi@0 381 // (if target is null, it is a dry run only, just for sizing)
aoqi@0 382 csize_t copy_relocations_to(CodeBlob* blob) const;
aoqi@0 383
aoqi@0 384 // copies combined code to the blob (assumes relocs are already in there)
aoqi@0 385 void copy_code_to(CodeBlob* blob);
aoqi@0 386
aoqi@0 387 // moves code sections to new buffer (assumes relocs are already in there)
aoqi@0 388 void relocate_code_to(CodeBuffer* cb) const;
aoqi@0 389
aoqi@0 390 // set up a model of the final layout of my contents
aoqi@0 391 void compute_final_layout(CodeBuffer* dest) const;
aoqi@0 392
aoqi@0 393 // Expand the given section so at least 'amount' is remaining.
aoqi@0 394 // Creates a new, larger BufferBlob, and rewrites the code & relocs.
aoqi@0 395 void expand(CodeSection* which_cs, csize_t amount);
aoqi@0 396
aoqi@0 397 // Helper for expand.
aoqi@0 398 csize_t figure_expanded_capacities(CodeSection* which_cs, csize_t amount, csize_t* new_capacity);
aoqi@0 399
aoqi@0 400 public:
aoqi@0 401 // (1) code buffer referring to pre-allocated instruction memory
aoqi@0 402 CodeBuffer(address code_start, csize_t code_size) {
aoqi@0 403 assert(code_start != NULL, "sanity");
aoqi@0 404 initialize_misc("static buffer");
aoqi@0 405 initialize(code_start, code_size);
aoqi@0 406 verify_section_allocation();
aoqi@0 407 }
aoqi@0 408
aoqi@0 409 // (2) CodeBuffer referring to pre-allocated CodeBlob.
aoqi@0 410 CodeBuffer(CodeBlob* blob);
aoqi@0 411
aoqi@0 412 // (3) code buffer allocating codeBlob memory for code & relocation
aoqi@0 413 // info but with lazy initialization. The name must be something
aoqi@0 414 // informative.
aoqi@0 415 CodeBuffer(const char* name) {
aoqi@0 416 initialize_misc(name);
aoqi@0 417 }
aoqi@0 418
aoqi@0 419
aoqi@0 420 // (4) code buffer allocating codeBlob memory for code & relocation
aoqi@0 421 // info. The name must be something informative and code_size must
aoqi@0 422 // include both code and stubs sizes.
aoqi@0 423 CodeBuffer(const char* name, csize_t code_size, csize_t locs_size) {
aoqi@0 424 initialize_misc(name);
aoqi@0 425 initialize(code_size, locs_size);
aoqi@0 426 }
aoqi@0 427
aoqi@0 428 ~CodeBuffer();
aoqi@0 429
aoqi@0 430 // Initialize a CodeBuffer constructed using constructor 3. Using
aoqi@0 431 // constructor 4 is equivalent to calling constructor 3 and then
aoqi@0 432 // calling this method. It's been factored out for convenience of
aoqi@0 433 // construction.
aoqi@0 434 void initialize(csize_t code_size, csize_t locs_size);
aoqi@0 435
aoqi@0 436 CodeSection* consts() { return &_consts; }
aoqi@0 437 CodeSection* insts() { return &_insts; }
aoqi@0 438 CodeSection* stubs() { return &_stubs; }
aoqi@0 439
aoqi@0 440 // present sections in order; return NULL at end; consts is #0, etc.
aoqi@0 441 CodeSection* code_section(int n) {
aoqi@0 442 // This makes the slightly questionable but portable assumption
aoqi@0 443 // that the various members (_consts, _insts, _stubs, etc.) are
aoqi@0 444 // adjacent in the layout of CodeBuffer.
aoqi@0 445 CodeSection* cs = &_consts + n;
aoqi@0 446 assert(cs->index() == n || !cs->is_allocated(), "sanity");
aoqi@0 447 return cs;
aoqi@0 448 }
aoqi@0 449 const CodeSection* code_section(int n) const { // yucky const stuff
aoqi@0 450 return ((CodeBuffer*)this)->code_section(n);
aoqi@0 451 }
aoqi@0 452 static const char* code_section_name(int n);
aoqi@0 453 int section_index_of(address addr) const;
aoqi@0 454 bool contains(address addr) const {
aoqi@0 455 // handy for debugging
aoqi@0 456 return section_index_of(addr) > SECT_NONE;
aoqi@0 457 }
aoqi@0 458
aoqi@0 459 // A stable mapping between 'locators' (small ints) and addresses.
aoqi@0 460 static int locator_pos(int locator) { return locator >> sect_bits; }
aoqi@0 461 static int locator_sect(int locator) { return locator & sect_mask; }
aoqi@0 462 static int locator(int pos, int sect) { return (pos << sect_bits) | sect; }
aoqi@0 463 int locator(address addr) const;
aoqi@0 464 address locator_address(int locator) const;
aoqi@0 465
aoqi@0 466 // Heuristic for pre-packing the taken/not-taken bit of a predicted branch.
aoqi@0 467 bool is_backward_branch(Label& L);
aoqi@0 468
aoqi@0 469 // Properties
aoqi@0 470 const char* name() const { return _name; }
aoqi@0 471 CodeBuffer* before_expand() const { return _before_expand; }
aoqi@0 472 BufferBlob* blob() const { return _blob; }
aoqi@0 473 void set_blob(BufferBlob* blob);
aoqi@0 474 void free_blob(); // Free the blob, if we own one.
aoqi@0 475
aoqi@0 476 // Properties relative to the insts section:
aoqi@0 477 address insts_begin() const { return _insts.start(); }
aoqi@0 478 address insts_end() const { return _insts.end(); }
aoqi@0 479 void set_insts_end(address end) { _insts.set_end(end); }
aoqi@0 480 address insts_limit() const { return _insts.limit(); }
aoqi@0 481 address insts_mark() const { return _insts.mark(); }
aoqi@0 482 void set_insts_mark() { _insts.set_mark(); }
aoqi@0 483 void clear_insts_mark() { _insts.clear_mark(); }
aoqi@0 484
aoqi@0 485 // is there anything in the buffer other than the current section?
aoqi@0 486 bool is_pure() const { return insts_size() == total_content_size(); }
aoqi@0 487
aoqi@0 488 // size in bytes of output so far in the insts sections
aoqi@0 489 csize_t insts_size() const { return _insts.size(); }
aoqi@0 490
aoqi@0 491 // same as insts_size(), except that it asserts there is no non-code here
aoqi@0 492 csize_t pure_insts_size() const { assert(is_pure(), "no non-code");
aoqi@0 493 return insts_size(); }
aoqi@0 494 // capacity in bytes of the insts sections
aoqi@0 495 csize_t insts_capacity() const { return _insts.capacity(); }
aoqi@0 496
aoqi@0 497 // number of bytes remaining in the insts section
aoqi@0 498 csize_t insts_remaining() const { return _insts.remaining(); }
aoqi@0 499
aoqi@0 500 // is a given address in the insts section? (2nd version is end-inclusive)
aoqi@0 501 bool insts_contains(address pc) const { return _insts.contains(pc); }
aoqi@0 502 bool insts_contains2(address pc) const { return _insts.contains2(pc); }
aoqi@0 503
aoqi@0 504 // Record any extra oops required to keep embedded metadata alive
aoqi@0 505 void finalize_oop_references(methodHandle method);
aoqi@0 506
aoqi@0 507 // Allocated size in all sections, when aligned and concatenated
aoqi@0 508 // (this is the eventual state of the content in its final
aoqi@0 509 // CodeBlob).
aoqi@0 510 csize_t total_content_size() const;
aoqi@0 511
aoqi@0 512 // Combined offset (relative to start of first section) of given
aoqi@0 513 // section, as eventually found in the final CodeBlob.
aoqi@0 514 csize_t total_offset_of(CodeSection* cs) const;
aoqi@0 515
aoqi@0 516 // allocated size of all relocation data, including index, rounded up
aoqi@0 517 csize_t total_relocation_size() const;
aoqi@0 518
aoqi@0 519 // allocated size of any and all recorded oops
aoqi@0 520 csize_t total_oop_size() const {
aoqi@0 521 OopRecorder* recorder = oop_recorder();
aoqi@0 522 return (recorder == NULL)? 0: recorder->oop_size();
aoqi@0 523 }
aoqi@0 524
aoqi@0 525 // allocated size of any and all recorded metadata
aoqi@0 526 csize_t total_metadata_size() const {
aoqi@0 527 OopRecorder* recorder = oop_recorder();
aoqi@0 528 return (recorder == NULL)? 0: recorder->metadata_size();
aoqi@0 529 }
aoqi@0 530
aoqi@0 531 // Configuration functions, called immediately after the CB is constructed.
aoqi@0 532 // The section sizes are subtracted from the original insts section.
aoqi@0 533 // Note: Call them in reverse section order, because each steals from insts.
aoqi@0 534 void initialize_consts_size(csize_t size) { initialize_section_size(&_consts, size); }
aoqi@0 535 void initialize_stubs_size(csize_t size) { initialize_section_size(&_stubs, size); }
aoqi@0 536 // Override default oop recorder.
aoqi@0 537 void initialize_oop_recorder(OopRecorder* r);
aoqi@0 538
aoqi@0 539 OopRecorder* oop_recorder() const { return _oop_recorder; }
aoqi@0 540 CodeStrings& strings() { return _strings; }
aoqi@0 541
aoqi@0 542 // Code generation
aoqi@0 543 void relocate(address at, RelocationHolder const& rspec, int format = 0) {
aoqi@0 544 _insts.relocate(at, rspec, format);
aoqi@0 545 }
aoqi@0 546 void relocate(address at, relocInfo::relocType rtype, int format = 0) {
aoqi@0 547 _insts.relocate(at, rtype, format);
aoqi@0 548 }
aoqi@0 549
aoqi@0 550 // Management of overflow storage for binding of Labels.
aoqi@0 551 GrowableArray<int>* create_patch_overflow();
aoqi@0 552
aoqi@0 553 // NMethod generation
aoqi@0 554 void copy_code_and_locs_to(CodeBlob* blob) {
aoqi@0 555 assert(blob != NULL, "sane");
aoqi@0 556 copy_relocations_to(blob);
aoqi@0 557 copy_code_to(blob);
aoqi@0 558 }
aoqi@0 559 void copy_values_to(nmethod* nm) {
aoqi@0 560 if (!oop_recorder()->is_unused()) {
aoqi@0 561 oop_recorder()->copy_values_to(nm);
aoqi@0 562 }
aoqi@0 563 }
aoqi@0 564
aoqi@0 565 // Transform an address from the code in this code buffer to a specified code buffer
aoqi@0 566 address transform_address(const CodeBuffer &cb, address addr) const;
aoqi@0 567
aoqi@0 568 void block_comment(intptr_t offset, const char * comment) PRODUCT_RETURN;
aoqi@0 569 const char* code_string(const char* str) PRODUCT_RETURN_(return NULL;);
aoqi@0 570
aoqi@0 571 // Log a little info about section usage in the CodeBuffer
aoqi@0 572 void log_section_sizes(const char* name);
aoqi@0 573
aoqi@0 574 #ifndef PRODUCT
aoqi@0 575 public:
aoqi@0 576 // Printing / Decoding
aoqi@0 577 // decodes from decode_begin() to code_end() and sets decode_begin to end
aoqi@0 578 void decode();
aoqi@0 579 void decode_all(); // decodes all the code
aoqi@0 580 void skip_decode(); // sets decode_begin to code_end();
aoqi@0 581 void print();
aoqi@0 582 #endif
aoqi@0 583
aoqi@0 584
aoqi@0 585 // The following header contains architecture-specific implementations
aoqi@0 586 #ifdef TARGET_ARCH_x86
aoqi@0 587 # include "codeBuffer_x86.hpp"
aoqi@0 588 #endif
aoqi@0 589 #ifdef TARGET_ARCH_sparc
aoqi@0 590 # include "codeBuffer_sparc.hpp"
aoqi@0 591 #endif
aoqi@0 592 #ifdef TARGET_ARCH_zero
aoqi@0 593 # include "codeBuffer_zero.hpp"
aoqi@0 594 #endif
aoqi@0 595 #ifdef TARGET_ARCH_arm
aoqi@0 596 # include "codeBuffer_arm.hpp"
aoqi@0 597 #endif
aoqi@0 598 #ifdef TARGET_ARCH_ppc
aoqi@0 599 # include "codeBuffer_ppc.hpp"
aoqi@0 600 #endif
aoqi@1 601 #ifdef TARGET_ARCH_mips
aoqi@1 602 # include "codeBuffer_mips.hpp"
aoqi@1 603 #endif
aoqi@0 604
aoqi@0 605 };
aoqi@0 606
aoqi@0 607
aoqi@0 608 inline void CodeSection::freeze() {
aoqi@0 609 _outer->freeze_section(this);
aoqi@0 610 }
aoqi@0 611
aoqi@0 612 inline bool CodeSection::maybe_expand_to_ensure_remaining(csize_t amount) {
aoqi@0 613 if (remaining() < amount) { _outer->expand(this, amount); return true; }
aoqi@0 614 return false;
aoqi@0 615 }
aoqi@0 616
aoqi@0 617 #endif // SHARE_VM_ASM_CODEBUFFER_HPP

mercurial