< prev index next >

src/hotspot/share/asm/codeBuffer.hpp

Print this page

 72   CodeOffsets() {
 73     _values[Entry         ] = 0;
 74     _values[Verified_Entry] = 0;
 75     _values[Frame_Complete] = frame_never_safe;
 76     _values[OSR_Entry     ] = 0;
 77     _values[Exceptions    ] = -1;
 78     _values[Deopt         ] = -1;
 79     _values[DeoptMH       ] = -1;
 80     _values[UnwindHandler ] = -1;
 81   }
 82 
 83   int value(Entries e) { return _values[e]; }
 84   void set_value(Entries e, int val) { _values[e] = val; }
 85 };
 86 
 87 // This class represents a stream of code and associated relocations.
 88 // There are a few in each CodeBuffer.
 89 // They are filled concurrently, and concatenated at the end.
 90 class CodeSection {
 91   friend class CodeBuffer;

 92  public:
 93   typedef int csize_t;  // code size type; would be size_t except for history
 94 
 95  private:
 96   address     _start;           // first byte of contents (instructions)
 97   address     _mark;            // user mark, usually an instruction beginning
 98   address     _end;             // current end address
 99   address     _limit;           // last possible (allocated) end address
100   relocInfo*  _locs_start;      // first byte of relocation information
101   relocInfo*  _locs_end;        // first byte after relocation information
102   relocInfo*  _locs_limit;      // first byte after relocation information buf
103   address     _locs_point;      // last relocated position (grows upward)
104   bool        _locs_own;        // did I allocate the locs myself?
105   bool        _scratch_emit;    // Buffer is used for scratch emit, don't relocate.
106   int         _skipped_instructions_size;
107   int8_t      _index;           // my section number (SECT_INST, etc.)
108   CodeBuffer* _outer;           // enclosing CodeBuffer
109 
110   // (Note:  _locs_point used to be called _last_reloc_offset.)
111 

266 
267   // Emit a relocation.
268   void relocate(address at, RelocationHolder const& rspec, int format = 0);
269   void relocate(address at,    relocInfo::relocType rtype, int format = 0, jint method_index = 0);
270 
271   int alignment() const;
272 
273   // Slop between sections, used only when allocating temporary BufferBlob buffers.
274   static csize_t end_slop()         { return MAX2((int)sizeof(jdouble), (int)CodeEntryAlignment); }
275 
276   csize_t align_at_start(csize_t off) const {
277     return (csize_t) align_up(off, alignment());
278   }
279 
280   // Ensure there's enough space left in the current section.
281   // Return true if there was an expansion.
282   bool maybe_expand_to_ensure_remaining(csize_t amount);
283 
284 #ifndef PRODUCT
285   void decode();
286   void print(const char* name);
287 #endif //PRODUCT
288 };
289 
290 
291 #ifndef PRODUCT
292 
293 class AsmRemarkCollection;
294 class DbgStringCollection;
295 
296 // The assumption made here is that most code remarks (or comments) added to
297 // the generated assembly code are unique, i.e. there is very little gain in
298 // trying to share the strings between the different offsets tracked in a
299 // buffer (or blob).
300 
301 class AsmRemarks {
302  public:
303   AsmRemarks();
304  ~AsmRemarks();
305 
306   const char* insert(uint offset, const char* remstr);

369 // (1) A CodeBuffer referring to an already allocated piece of memory:
370 //     This is used to direct 'static' code generation (e.g. for interpreter
371 //     or stubroutine generation, etc.).  This code comes with NO relocation
372 //     information.
373 //
374 // (2) A CodeBuffer referring to a piece of memory allocated when the
375 //     CodeBuffer is allocated.  This is used for nmethod generation.
376 //
377 // The memory can be divided up into several parts called sections.
378 // Each section independently accumulates code (or data) an relocations.
379 // Sections can grow (at the expense of a reallocation of the BufferBlob
380 // and recopying of all active sections).  When the buffered code is finally
381 // written to an nmethod (or other CodeBlob), the contents (code, data,
382 // and relocations) of the sections are padded to an alignment and concatenated.
383 // Instructions and data in one section can contain relocatable references to
384 // addresses in a sibling section.
385 
386 class CodeBuffer: public StackObj DEBUG_ONLY(COMMA private Scrubber) {
387   friend class CodeSection;
388   friend class StubCodeGenerator;

389 
390  private:
391   // CodeBuffers must be allocated on the stack except for a single
392   // special case during expansion which is handled internally.  This
393   // is done to guarantee proper cleanup of resources.
394   void* operator new(size_t size) throw() { return resource_allocate_bytes(size); }
395   void  operator delete(void* p)          { ShouldNotCallThis(); }
396 
397  public:
398   typedef int csize_t;  // code size type; would be size_t except for history
399   enum : int8_t {
400     // Here is the list of all possible sections.  The order reflects
401     // the final layout.
402     SECT_FIRST = 0,
403     SECT_CONSTS = SECT_FIRST, // Non-instruction data:  Floats, jump tables, etc.
404     SECT_INSTS,               // Executable instructions.
405     SECT_STUBS,               // Outbound trampolines for supporting call sites.
406     SECT_LIMIT, SECT_NONE = -1
407   };
408 

723   const char* code_string(const char* str) PRODUCT_RETURN_(return nullptr;);
724 
725   // Log a little info about section usage in the CodeBuffer
726   void log_section_sizes(const char* name);
727 
728   // Make a set of stubs final. It can create/optimize stubs.
729   bool finalize_stubs();
730 
731   // Request for a shared stub to the interpreter
732   void shared_stub_to_interp_for(ciMethod* callee, csize_t call_offset);
733 
734   void set_const_section_alignment(int align) {
735     _const_section_alignment = align_up(align, HeapWordSize);
736   }
737 
738 #ifndef PRODUCT
739  public:
740   // Printing / Decoding
741   // decodes from decode_begin() to code_end() and sets decode_begin to end
742   void    decode();
743   void    print();
744 #endif
745   // Directly disassemble code buffer.
746   void    decode(address start, address end);
747 
748   // The following header contains architecture-specific implementations
749 #include CPU_HEADER(codeBuffer)
750 
751 };
752 
753 // A Java method can have calls of Java methods which can be statically bound.
754 // Calls of Java methods need stubs to the interpreter. Calls sharing the same Java method
755 // can share a stub to the interpreter.
756 // A SharedStubToInterpRequest is a request for a shared stub to the interpreter.
757 class SharedStubToInterpRequest : public ResourceObj {
758  private:
759   ciMethod* _shared_method;
760   CodeBuffer::csize_t _call_offset; // The offset of the call in CodeBuffer
761 
762  public:
763   SharedStubToInterpRequest(ciMethod* method = nullptr, CodeBuffer::csize_t call_offset = -1) : _shared_method(method),

 72   CodeOffsets() {
 73     _values[Entry         ] = 0;
 74     _values[Verified_Entry] = 0;
 75     _values[Frame_Complete] = frame_never_safe;
 76     _values[OSR_Entry     ] = 0;
 77     _values[Exceptions    ] = -1;
 78     _values[Deopt         ] = -1;
 79     _values[DeoptMH       ] = -1;
 80     _values[UnwindHandler ] = -1;
 81   }
 82 
 83   int value(Entries e) { return _values[e]; }
 84   void set_value(Entries e, int val) { _values[e] = val; }
 85 };
 86 
 87 // This class represents a stream of code and associated relocations.
 88 // There are a few in each CodeBuffer.
 89 // They are filled concurrently, and concatenated at the end.
 90 class CodeSection {
 91   friend class CodeBuffer;
 92   friend class SCCReader;
 93  public:
 94   typedef int csize_t;  // code size type; would be size_t except for history
 95 
 96  private:
 97   address     _start;           // first byte of contents (instructions)
 98   address     _mark;            // user mark, usually an instruction beginning
 99   address     _end;             // current end address
100   address     _limit;           // last possible (allocated) end address
101   relocInfo*  _locs_start;      // first byte of relocation information
102   relocInfo*  _locs_end;        // first byte after relocation information
103   relocInfo*  _locs_limit;      // first byte after relocation information buf
104   address     _locs_point;      // last relocated position (grows upward)
105   bool        _locs_own;        // did I allocate the locs myself?
106   bool        _scratch_emit;    // Buffer is used for scratch emit, don't relocate.
107   int         _skipped_instructions_size;
108   int8_t      _index;           // my section number (SECT_INST, etc.)
109   CodeBuffer* _outer;           // enclosing CodeBuffer
110 
111   // (Note:  _locs_point used to be called _last_reloc_offset.)
112 

267 
268   // Emit a relocation.
269   void relocate(address at, RelocationHolder const& rspec, int format = 0);
270   void relocate(address at,    relocInfo::relocType rtype, int format = 0, jint method_index = 0);
271 
272   int alignment() const;
273 
274   // Slop between sections, used only when allocating temporary BufferBlob buffers.
275   static csize_t end_slop()         { return MAX2((int)sizeof(jdouble), (int)CodeEntryAlignment); }
276 
277   csize_t align_at_start(csize_t off) const {
278     return (csize_t) align_up(off, alignment());
279   }
280 
281   // Ensure there's enough space left in the current section.
282   // Return true if there was an expansion.
283   bool maybe_expand_to_ensure_remaining(csize_t amount);
284 
285 #ifndef PRODUCT
286   void decode();
287   void print_on(outputStream* st, const char* name);
288 #endif //PRODUCT
289 };
290 
291 
292 #ifndef PRODUCT
293 
294 class AsmRemarkCollection;
295 class DbgStringCollection;
296 
297 // The assumption made here is that most code remarks (or comments) added to
298 // the generated assembly code are unique, i.e. there is very little gain in
299 // trying to share the strings between the different offsets tracked in a
300 // buffer (or blob).
301 
302 class AsmRemarks {
303  public:
304   AsmRemarks();
305  ~AsmRemarks();
306 
307   const char* insert(uint offset, const char* remstr);

370 // (1) A CodeBuffer referring to an already allocated piece of memory:
371 //     This is used to direct 'static' code generation (e.g. for interpreter
372 //     or stubroutine generation, etc.).  This code comes with NO relocation
373 //     information.
374 //
375 // (2) A CodeBuffer referring to a piece of memory allocated when the
376 //     CodeBuffer is allocated.  This is used for nmethod generation.
377 //
378 // The memory can be divided up into several parts called sections.
379 // Each section independently accumulates code (or data) an relocations.
380 // Sections can grow (at the expense of a reallocation of the BufferBlob
381 // and recopying of all active sections).  When the buffered code is finally
382 // written to an nmethod (or other CodeBlob), the contents (code, data,
383 // and relocations) of the sections are padded to an alignment and concatenated.
384 // Instructions and data in one section can contain relocatable references to
385 // addresses in a sibling section.
386 
387 class CodeBuffer: public StackObj DEBUG_ONLY(COMMA private Scrubber) {
388   friend class CodeSection;
389   friend class StubCodeGenerator;
390   friend class SCCReader;
391 
392  private:
393   // CodeBuffers must be allocated on the stack except for a single
394   // special case during expansion which is handled internally.  This
395   // is done to guarantee proper cleanup of resources.
396   void* operator new(size_t size) throw() { return resource_allocate_bytes(size); }
397   void  operator delete(void* p)          { ShouldNotCallThis(); }
398 
399  public:
400   typedef int csize_t;  // code size type; would be size_t except for history
401   enum : int8_t {
402     // Here is the list of all possible sections.  The order reflects
403     // the final layout.
404     SECT_FIRST = 0,
405     SECT_CONSTS = SECT_FIRST, // Non-instruction data:  Floats, jump tables, etc.
406     SECT_INSTS,               // Executable instructions.
407     SECT_STUBS,               // Outbound trampolines for supporting call sites.
408     SECT_LIMIT, SECT_NONE = -1
409   };
410 

725   const char* code_string(const char* str) PRODUCT_RETURN_(return nullptr;);
726 
727   // Log a little info about section usage in the CodeBuffer
728   void log_section_sizes(const char* name);
729 
730   // Make a set of stubs final. It can create/optimize stubs.
731   bool finalize_stubs();
732 
733   // Request for a shared stub to the interpreter
734   void shared_stub_to_interp_for(ciMethod* callee, csize_t call_offset);
735 
736   void set_const_section_alignment(int align) {
737     _const_section_alignment = align_up(align, HeapWordSize);
738   }
739 
740 #ifndef PRODUCT
741  public:
742   // Printing / Decoding
743   // decodes from decode_begin() to code_end() and sets decode_begin to end
744   void    decode();
745   void    print_on(outputStream* st);
746 #endif
747   // Directly disassemble code buffer.
748   void    decode(address start, address end);
749 
750   // The following header contains architecture-specific implementations
751 #include CPU_HEADER(codeBuffer)
752 
753 };
754 
755 // A Java method can have calls of Java methods which can be statically bound.
756 // Calls of Java methods need stubs to the interpreter. Calls sharing the same Java method
757 // can share a stub to the interpreter.
758 // A SharedStubToInterpRequest is a request for a shared stub to the interpreter.
759 class SharedStubToInterpRequest : public ResourceObj {
760  private:
761   ciMethod* _shared_method;
762   CodeBuffer::csize_t _call_offset; // The offset of the call in CodeBuffer
763 
764  public:
765   SharedStubToInterpRequest(ciMethod* method = nullptr, CodeBuffer::csize_t call_offset = -1) : _shared_method(method),
< prev index next >