184 assert(pc >= locs_point(), "relocation addr may not decrease"); |
184 assert(pc >= locs_point(), "relocation addr may not decrease"); |
185 assert(allocates2(pc), "relocation addr must be in this section"); |
185 assert(allocates2(pc), "relocation addr must be in this section"); |
186 _locs_point = pc; |
186 _locs_point = pc; |
187 } |
187 } |
188 |
188 |
|
189 // Code emission |
|
190 void emit_int8 (int8_t x) { *((int8_t*) end()) = x; set_end(end() + 1); } |
|
191 void emit_int16(int16_t x) { *((int16_t*) end()) = x; set_end(end() + 2); } |
|
192 void emit_int32(int32_t x) { *((int32_t*) end()) = x; set_end(end() + 4); } |
|
193 void emit_int64(int64_t x) { *((int64_t*) end()) = x; set_end(end() + 8); } |
|
194 |
189 // Share a scratch buffer for relocinfo. (Hacky; saves a resource allocation.) |
195 // Share a scratch buffer for relocinfo. (Hacky; saves a resource allocation.) |
190 void initialize_shared_locs(relocInfo* buf, int length); |
196 void initialize_shared_locs(relocInfo* buf, int length); |
191 |
197 |
192 // Manage labels and their addresses. |
198 // Manage labels and their addresses. |
193 address target(Label& L, address branch_pc); |
199 address target(Label& L, address branch_pc); |
372 // Helper for expand. |
378 // Helper for expand. |
373 csize_t figure_expanded_capacities(CodeSection* which_cs, csize_t amount, csize_t* new_capacity); |
379 csize_t figure_expanded_capacities(CodeSection* which_cs, csize_t amount, csize_t* new_capacity); |
374 |
380 |
375 public: |
381 public: |
376 // (1) code buffer referring to pre-allocated instruction memory |
382 // (1) code buffer referring to pre-allocated instruction memory |
377 CodeBuffer(address code_start, csize_t code_size); |
383 CodeBuffer(address code_start, csize_t code_size) { |
378 |
384 assert(code_start != NULL, "sanity"); |
379 // (2) code buffer allocating codeBlob memory for code & relocation |
385 initialize_misc("static buffer"); |
|
386 initialize(code_start, code_size); |
|
387 assert(verify_section_allocation(), "initial use of buffer OK"); |
|
388 } |
|
389 |
|
390 // (2) CodeBuffer referring to pre-allocated CodeBlob. |
|
391 CodeBuffer(CodeBlob* blob); |
|
392 |
|
393 // (3) code buffer allocating codeBlob memory for code & relocation |
380 // info but with lazy initialization. The name must be something |
394 // info but with lazy initialization. The name must be something |
381 // informative. |
395 // informative. |
382 CodeBuffer(const char* name) { |
396 CodeBuffer(const char* name) { |
383 initialize_misc(name); |
397 initialize_misc(name); |
384 } |
398 } |
385 |
399 |
386 |
400 |
387 // (3) code buffer allocating codeBlob memory for code & relocation |
401 // (4) code buffer allocating codeBlob memory for code & relocation |
388 // info. The name must be something informative and code_size must |
402 // info. The name must be something informative and code_size must |
389 // include both code and stubs sizes. |
403 // include both code and stubs sizes. |
390 CodeBuffer(const char* name, csize_t code_size, csize_t locs_size) { |
404 CodeBuffer(const char* name, csize_t code_size, csize_t locs_size) { |
391 initialize_misc(name); |
405 initialize_misc(name); |
392 initialize(code_size, locs_size); |
406 initialize(code_size, locs_size); |
393 } |
407 } |
394 |
408 |
395 ~CodeBuffer(); |
409 ~CodeBuffer(); |
396 |
410 |
397 // Initialize a CodeBuffer constructed using constructor 2. Using |
411 // Initialize a CodeBuffer constructed using constructor 3. Using |
398 // constructor 3 is equivalent to calling constructor 2 and then |
412 // constructor 4 is equivalent to calling constructor 3 and then |
399 // calling this method. It's been factored out for convenience of |
413 // calling this method. It's been factored out for convenience of |
400 // construction. |
414 // construction. |
401 void initialize(csize_t code_size, csize_t locs_size); |
415 void initialize(csize_t code_size, csize_t locs_size); |
402 |
416 |
403 CodeSection* insts() { return &_insts; } |
417 CodeSection* insts() { return &_insts; } |
436 BufferBlob* blob() const { return _blob; } |
450 BufferBlob* blob() const { return _blob; } |
437 void set_blob(BufferBlob* blob); |
451 void set_blob(BufferBlob* blob); |
438 void free_blob(); // Free the blob, if we own one. |
452 void free_blob(); // Free the blob, if we own one. |
439 |
453 |
440 // Properties relative to the insts section: |
454 // Properties relative to the insts section: |
441 address code_begin() const { return _insts.start(); } |
455 address insts_begin() const { return _insts.start(); } |
442 address code_end() const { return _insts.end(); } |
456 address insts_end() const { return _insts.end(); } |
443 void set_code_end(address end) { _insts.set_end(end); } |
457 void set_insts_end(address end) { _insts.set_end(end); } |
444 address code_limit() const { return _insts.limit(); } |
458 address insts_limit() const { return _insts.limit(); } |
445 address inst_mark() const { return _insts.mark(); } |
459 address insts_mark() const { return _insts.mark(); } |
446 void set_inst_mark() { _insts.set_mark(); } |
460 void set_insts_mark() { _insts.set_mark(); } |
447 void clear_inst_mark() { _insts.clear_mark(); } |
461 void clear_insts_mark() { _insts.clear_mark(); } |
448 |
462 |
449 // is there anything in the buffer other than the current section? |
463 // is there anything in the buffer other than the current section? |
450 bool is_pure() const { return code_size() == total_code_size(); } |
464 bool is_pure() const { return insts_size() == total_content_size(); } |
451 |
465 |
452 // size in bytes of output so far in the insts sections |
466 // size in bytes of output so far in the insts sections |
453 csize_t code_size() const { return _insts.size(); } |
467 csize_t insts_size() const { return _insts.size(); } |
454 |
468 |
455 // same as code_size(), except that it asserts there is no non-code here |
469 // same as insts_size(), except that it asserts there is no non-code here |
456 csize_t pure_code_size() const { assert(is_pure(), "no non-code"); |
470 csize_t pure_insts_size() const { assert(is_pure(), "no non-code"); |
457 return code_size(); } |
471 return insts_size(); } |
458 // capacity in bytes of the insts sections |
472 // capacity in bytes of the insts sections |
459 csize_t code_capacity() const { return _insts.capacity(); } |
473 csize_t insts_capacity() const { return _insts.capacity(); } |
460 |
474 |
461 // number of bytes remaining in the insts section |
475 // number of bytes remaining in the insts section |
462 csize_t code_remaining() const { return _insts.remaining(); } |
476 csize_t insts_remaining() const { return _insts.remaining(); } |
463 |
477 |
464 // is a given address in the insts section? (2nd version is end-inclusive) |
478 // is a given address in the insts section? (2nd version is end-inclusive) |
465 bool code_contains(address pc) const { return _insts.contains(pc); } |
479 bool insts_contains(address pc) const { return _insts.contains(pc); } |
466 bool code_contains2(address pc) const { return _insts.contains2(pc); } |
480 bool insts_contains2(address pc) const { return _insts.contains2(pc); } |
467 |
481 |
468 // allocated size of code in all sections, when aligned and concatenated |
482 // Allocated size in all sections, when aligned and concatenated |
469 // (this is the eventual state of the code in its final CodeBlob) |
483 // (this is the eventual state of the content in its final |
470 csize_t total_code_size() const; |
484 // CodeBlob). |
|
485 csize_t total_content_size() const; |
471 |
486 |
472 // combined offset (relative to start of insts) of given address, |
487 // combined offset (relative to start of insts) of given address, |
473 // as eventually found in the final CodeBlob |
488 // as eventually found in the final CodeBlob |
474 csize_t total_offset_of(address addr) const; |
489 csize_t total_offset_of(address addr) const; |
475 |
490 |