src/share/vm/asm/codeBuffer.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 1
2d8a650513c2
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial