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