< prev index next >

src/hotspot/share/code/codeBlob.hpp

Print this page

 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_CODE_CODEBLOB_HPP
 26 #define SHARE_CODE_CODEBLOB_HPP
 27 
 28 #include "asm/codeBuffer.hpp"
 29 #include "compiler/compilerDefinitions.hpp"

 30 #include "runtime/javaFrameAnchor.hpp"
 31 #include "runtime/frame.hpp"
 32 #include "runtime/handles.hpp"
 33 #include "utilities/align.hpp"
 34 #include "utilities/macros.hpp"
 35 
 36 class ImmutableOopMap;
 37 class ImmutableOopMapSet;
 38 class JNIHandleBlock;
 39 class OopMapSet;
 40 
 41 // CodeBlob Types
 42 // Used in the CodeCache to assign CodeBlobs to different CodeHeaps
 43 struct CodeBlobType {
 44   enum {
 45     MethodNonProfiled   = 0,    // Execution level 1 and 4 (non-profiled) nmethods (including native nmethods)
 46     MethodProfiled      = 1,    // Execution level 2 and 3 (profiled) nmethods
 47     NonNMethod          = 2,    // Non-nmethods like Buffers, Adapters and Runtime Stubs
 48     All                 = 3,    // All types (No code cache segmentation)
 49     NumTypes            = 4     // Number of CodeBlobTypes

 89 protected:
 90 
 91   const CompilerType _type;                      // CompilerType
 92   int        _size;                              // total size of CodeBlob in bytes
 93   int        _header_size;                       // size of header (depends on subclass)
 94   int        _frame_complete_offset;             // instruction offsets in [0.._frame_complete_offset) have
 95                                                  // not finished setting up their frame. Beware of pc's in
 96                                                  // that range. There is a similar range(s) on returns
 97                                                  // which we don't detect.
 98   int        _data_offset;                       // offset to where data region begins
 99   int        _frame_size;                        // size of stack frame
100 
101   address    _code_begin;
102   address    _code_end;
103   address    _content_begin;                     // address to where content region begins (this includes consts, insts, stubs)
104                                                  // address    _content_end - not required, for all CodeBlobs _code_end == _content_end for now
105   address    _data_end;
106   address    _relocation_begin;
107   address    _relocation_end;
108 


109   ImmutableOopMapSet* _oop_maps;                 // OopMap for this CodeBlob
110   bool                _caller_must_gc_arguments;
111 
112   const char*         _name;
113   S390_ONLY(int       _ctable_offset;)
114 
115 #ifndef PRODUCT
116   AsmRemarks _asm_remarks;
117   DbgStrings _dbg_strings;
118 
119  ~CodeBlob() {
120     _asm_remarks.clear();
121     _dbg_strings.clear();
122   }
123 #endif // not PRODUCT
124 
125   CodeBlob(const char* name, CompilerType type, const CodeBlobLayout& layout, int frame_complete_offset, int frame_size, ImmutableOopMapSet* oop_maps, bool caller_must_gc_arguments);
126   CodeBlob(const char* name, CompilerType type, const CodeBlobLayout& layout, CodeBuffer* cb, int frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments);
127 
128 public:
129   // Only used by unit test.
130   CodeBlob() : _type(compiler_none) {}
131 
132   // Returns the space needed for CodeBlob
133   static unsigned int allocation_size(CodeBuffer* cb, int header_size);
134   static unsigned int align_code_offset(int offset);
135 
136   // Deletion
137   virtual void flush();
138 
139   // Typing
140   virtual bool is_buffer_blob() const                 { return false; }
141   virtual bool is_nmethod() const                     { return false; }
142   virtual bool is_runtime_stub() const                { return false; }
143   virtual bool is_deoptimization_stub() const         { return false; }
144   virtual bool is_uncommon_trap_stub() const          { return false; }
145   virtual bool is_exception_stub() const              { return false; }
146   virtual bool is_safepoint_stub() const              { return false; }
147   virtual bool is_adapter_blob() const                { return false; }
148   virtual bool is_vtable_blob() const                 { return false; }
149   virtual bool is_method_handles_adapter_blob() const { return false; }
150   virtual bool is_compiled() const                    { return false; }

151   virtual bool is_optimized_entry_blob() const                  { return false; }
152 
153   inline bool is_compiled_by_c1() const    { return _type == compiler_c1; };
154   inline bool is_compiled_by_c2() const    { return _type == compiler_c2; };
155   inline bool is_compiled_by_jvmci() const { return _type == compiler_jvmci; };
156   const char* compiler_name() const;
157   CompilerType compiler_type() const { return _type; }
158 
159   // Casting
160   nmethod* as_nmethod_or_null()                { return is_nmethod() ? (nmethod*) this : NULL; }
161   nmethod* as_nmethod()                        { assert(is_nmethod(), "must be nmethod"); return (nmethod*) this; }
162   CompiledMethod* as_compiled_method_or_null() { return is_compiled() ? (CompiledMethod*) this : NULL; }
163   CompiledMethod* as_compiled_method()         { assert(is_compiled(), "must be compiled"); return (CompiledMethod*) this; }
164   CodeBlob* as_codeblob_or_null() const        { return (CodeBlob*) this; }
165   OptimizedEntryBlob* as_optimized_entry_blob() const             { assert(is_optimized_entry_blob(), "must be entry blob"); return (OptimizedEntryBlob*) this; }
166 
167   // Boundaries
168   address header_begin() const        { return (address) this; }
169   relocInfo* relocation_begin() const { return (relocInfo*) _relocation_begin; };
170   relocInfo* relocation_end() const   { return (relocInfo*) _relocation_end; }

200   bool contains(address addr) const              { return content_begin()      <= addr && addr < content_end();    }
201   bool is_frame_complete_at(address addr) const  { return _frame_complete_offset != CodeOffsets::frame_never_safe &&
202                                                           code_contains(addr) && addr >= code_begin() + _frame_complete_offset; }
203   int frame_complete_offset() const              { return _frame_complete_offset; }
204 
205   // CodeCache support: really only used by the nmethods, but in order to get
206   // asserts and certain bookkeeping to work in the CodeCache they are defined
207   // virtual here.
208   virtual bool is_zombie() const                 { return false; }
209   virtual bool is_locked_by_vm() const           { return false; }
210 
211   virtual bool is_unloaded() const               { return false; }
212   virtual bool is_not_entrant() const            { return false; }
213 
214   // GC support
215   virtual bool is_alive() const                  = 0;
216 
217   // OopMap for frame
218   ImmutableOopMapSet* oop_maps() const           { return _oop_maps; }
219   void set_oop_maps(OopMapSet* p);
220   const ImmutableOopMap* oop_map_for_return_address(address return_address);







221   virtual void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) = 0;
222 
223   // Frame support. Sizes are in word units.
224   int  frame_size() const                        { return _frame_size; }
225   void set_frame_size(int size)                  { _frame_size = size; }
226 
227   // Returns true, if the next frame is responsible for GC'ing oops passed as arguments
228   bool caller_must_gc_arguments(JavaThread* thread) const { return _caller_must_gc_arguments; }
229 
230   // Naming
231   const char* name() const                       { return _name; }
232   void set_name(const char* name)                { _name = name; }
233 
234   // Debugging
235   virtual void verify() = 0;
236   virtual void print() const;
237   virtual void print_on(outputStream* st) const;
238   virtual void print_value_on(outputStream* st) const;
239   void dump_for_addr(address addr, outputStream* st, bool verbose) const;
240   void print_code();

 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_CODE_CODEBLOB_HPP
 26 #define SHARE_CODE_CODEBLOB_HPP
 27 
 28 #include "asm/codeBuffer.hpp"
 29 #include "compiler/compilerDefinitions.hpp"
 30 #include "compiler/oopMap.inline.hpp"
 31 #include "runtime/javaFrameAnchor.hpp"
 32 #include "runtime/frame.hpp"
 33 #include "runtime/handles.hpp"
 34 #include "utilities/align.hpp"
 35 #include "utilities/macros.hpp"
 36 
 37 class ImmutableOopMap;
 38 class ImmutableOopMapSet;
 39 class JNIHandleBlock;
 40 class OopMapSet;
 41 
 42 // CodeBlob Types
 43 // Used in the CodeCache to assign CodeBlobs to different CodeHeaps
 44 struct CodeBlobType {
 45   enum {
 46     MethodNonProfiled   = 0,    // Execution level 1 and 4 (non-profiled) nmethods (including native nmethods)
 47     MethodProfiled      = 1,    // Execution level 2 and 3 (profiled) nmethods
 48     NonNMethod          = 2,    // Non-nmethods like Buffers, Adapters and Runtime Stubs
 49     All                 = 3,    // All types (No code cache segmentation)
 50     NumTypes            = 4     // Number of CodeBlobTypes

 90 protected:
 91 
 92   const CompilerType _type;                      // CompilerType
 93   int        _size;                              // total size of CodeBlob in bytes
 94   int        _header_size;                       // size of header (depends on subclass)
 95   int        _frame_complete_offset;             // instruction offsets in [0.._frame_complete_offset) have
 96                                                  // not finished setting up their frame. Beware of pc's in
 97                                                  // that range. There is a similar range(s) on returns
 98                                                  // which we don't detect.
 99   int        _data_offset;                       // offset to where data region begins
100   int        _frame_size;                        // size of stack frame
101 
102   address    _code_begin;
103   address    _code_end;
104   address    _content_begin;                     // address to where content region begins (this includes consts, insts, stubs)
105                                                  // address    _content_end - not required, for all CodeBlobs _code_end == _content_end for now
106   address    _data_end;
107   address    _relocation_begin;
108   address    _relocation_end;
109 
110   bool       _is_compiled;
111 
112   ImmutableOopMapSet* _oop_maps;                 // OopMap for this CodeBlob
113   bool                _caller_must_gc_arguments;
114 
115   const char*         _name;
116   S390_ONLY(int       _ctable_offset;)
117 
118 #ifndef PRODUCT
119   AsmRemarks _asm_remarks;
120   DbgStrings _dbg_strings;
121 
122  ~CodeBlob() {
123     _asm_remarks.clear();
124     _dbg_strings.clear();
125   }
126 #endif // not PRODUCT
127 
128   CodeBlob(const char* name, CompilerType type, const CodeBlobLayout& layout, int frame_complete_offset, int frame_size, ImmutableOopMapSet* oop_maps, bool caller_must_gc_arguments, bool compiled = false);
129   CodeBlob(const char* name, CompilerType type, const CodeBlobLayout& layout, CodeBuffer* cb, int frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments, bool compiled = false);

130 public:
131   // Only used by unit test.
132   CodeBlob() : _type(compiler_none) {}
133 
134   // Returns the space needed for CodeBlob
135   static unsigned int allocation_size(CodeBuffer* cb, int header_size);
136   static unsigned int align_code_offset(int offset);
137 
138   // Deletion
139   virtual void flush();
140 
141   // Typing
142   virtual bool is_buffer_blob() const                 { return false; }
143   virtual bool is_nmethod() const                     { return false; }
144   virtual bool is_runtime_stub() const                { return false; }
145   virtual bool is_deoptimization_stub() const         { return false; }
146   virtual bool is_uncommon_trap_stub() const          { return false; }
147   virtual bool is_exception_stub() const              { return false; }
148   virtual bool is_safepoint_stub() const              { return false; }
149   virtual bool is_adapter_blob() const                { return false; }
150   virtual bool is_vtable_blob() const                 { return false; }
151   virtual bool is_method_handles_adapter_blob() const { return false; }
152   bool is_compiled() const                            { return _is_compiled; }
153   const bool* is_compiled_addr() const                { return &_is_compiled; }
154   virtual bool is_optimized_entry_blob() const                  { return false; }
155 
156   inline bool is_compiled_by_c1() const    { return _type == compiler_c1; };
157   inline bool is_compiled_by_c2() const    { return _type == compiler_c2; };
158   inline bool is_compiled_by_jvmci() const { return _type == compiler_jvmci; };
159   const char* compiler_name() const;
160   CompilerType compiler_type() const { return _type; }
161 
162   // Casting
163   nmethod* as_nmethod_or_null()                { return is_nmethod() ? (nmethod*) this : NULL; }
164   nmethod* as_nmethod()                        { assert(is_nmethod(), "must be nmethod"); return (nmethod*) this; }
165   CompiledMethod* as_compiled_method_or_null() { return is_compiled() ? (CompiledMethod*) this : NULL; }
166   CompiledMethod* as_compiled_method()         { assert(is_compiled(), "must be compiled"); return (CompiledMethod*) this; }
167   CodeBlob* as_codeblob_or_null() const        { return (CodeBlob*) this; }
168   OptimizedEntryBlob* as_optimized_entry_blob() const             { assert(is_optimized_entry_blob(), "must be entry blob"); return (OptimizedEntryBlob*) this; }
169 
170   // Boundaries
171   address header_begin() const        { return (address) this; }
172   relocInfo* relocation_begin() const { return (relocInfo*) _relocation_begin; };
173   relocInfo* relocation_end() const   { return (relocInfo*) _relocation_end; }

203   bool contains(address addr) const              { return content_begin()      <= addr && addr < content_end();    }
204   bool is_frame_complete_at(address addr) const  { return _frame_complete_offset != CodeOffsets::frame_never_safe &&
205                                                           code_contains(addr) && addr >= code_begin() + _frame_complete_offset; }
206   int frame_complete_offset() const              { return _frame_complete_offset; }
207 
208   // CodeCache support: really only used by the nmethods, but in order to get
209   // asserts and certain bookkeeping to work in the CodeCache they are defined
210   // virtual here.
211   virtual bool is_zombie() const                 { return false; }
212   virtual bool is_locked_by_vm() const           { return false; }
213 
214   virtual bool is_unloaded() const               { return false; }
215   virtual bool is_not_entrant() const            { return false; }
216 
217   // GC support
218   virtual bool is_alive() const                  = 0;
219 
220   // OopMap for frame
221   ImmutableOopMapSet* oop_maps() const           { return _oop_maps; }
222   void set_oop_maps(OopMapSet* p);
223 
224   const ImmutableOopMap* oop_map_for_slot(int slot, address return_address) const {
225     assert(_oop_maps != NULL, "nope");
226     return _oop_maps->find_map_at_slot(slot, (intptr_t) return_address - (intptr_t) code_begin());
227   }
228 
229   //const ImmutableOopMap* oop_map_for_slot(int slot, address return_address) const;
230   const ImmutableOopMap* oop_map_for_return_address(address return_address) const;
231   virtual void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) = 0;
232 
233   // Frame support. Sizes are in word units.
234   int  frame_size() const                        { return _frame_size; }
235   void set_frame_size(int size)                  { _frame_size = size; }
236 
237   // Returns true, if the next frame is responsible for GC'ing oops passed as arguments
238   bool caller_must_gc_arguments(JavaThread* thread) const { return _caller_must_gc_arguments; }
239 
240   // Naming
241   const char* name() const                       { return _name; }
242   void set_name(const char* name)                { _name = name; }
243 
244   // Debugging
245   virtual void verify() = 0;
246   virtual void print() const;
247   virtual void print_on(outputStream* st) const;
248   virtual void print_value_on(outputStream* st) const;
249   void dump_for_addr(address addr, outputStream* st, bool verbose) const;
250   void print_code();
< prev index next >