annotate src/share/vm/asm/codeBuffer.hpp @ 3602:da91efe96a93

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