37 // - relocation 38 // - instruction space 39 // - data space 40 class DeoptimizationBlob; 41 42 class CodeBlob VALUE_OBJ_CLASS_SPEC { 43 44 friend class VMStructs; 45 46 private: 47 const char* _name; 48 int _size; // total size of CodeBlob in bytes 49 int _header_size; // size of header (depends on subclass) 50 int _relocation_size; // size of relocation 51 int _instructions_offset; // offset to where instructions region begins 52 int _frame_complete_offset; // instruction offsets in [0.._frame_complete_offset) have 53 // not finished setting up their frame. Beware of pc's in 54 // that range. There is a similar range(s) on returns 55 // which we don't detect. 56 int _data_offset; // offset to where data region begins 57 int _oops_offset; // offset to where embedded oop table begins (inside data) 58 int _oops_length; // number of embedded oops 59 int _frame_size; // size of stack frame 60 OopMapSet* _oop_maps; // OopMap for this CodeBlob 61 CodeComments _comments; 62 63 friend class OopRecorder; 64 65 void fix_oop_relocations(address begin, address end, bool initialize_immediates); 66 inline void initialize_immediate_oop(oop* dest, jobject handle); 67 68 public: 69 // Returns the space needed for CodeBlob 70 static unsigned int allocation_size(CodeBuffer* cb, int header_size); 71 72 // Creation 73 // a) simple CodeBlob 74 // frame_complete is the offset from the beginning of the instructions 75 // to where the frame setup (from stackwalk viewpoint) is complete. 76 CodeBlob(const char* name, int header_size, int size, int frame_complete, int locs_size); 77 78 // b) full CodeBlob 79 CodeBlob( 80 const char* name, 81 CodeBuffer* cb, 82 int header_size, 83 int size, 84 int frame_complete, 85 int frame_size, 86 OopMapSet* oop_maps 87 ); 98 virtual bool is_exception_stub() const { return false; } 99 virtual bool is_safepoint_stub() const { return false; } 100 virtual bool is_adapter_blob() const { return false; } 101 virtual bool is_method_handles_adapter_blob() const { return false; } 102 103 virtual bool is_compiled_by_c2() const { return false; } 104 virtual bool is_compiled_by_c1() const { return false; } 105 106 // Casting 107 nmethod* as_nmethod_or_null() { return is_nmethod() ? (nmethod*) this : NULL; } 108 109 // Boundaries 110 address header_begin() const { return (address) this; } 111 address header_end() const { return ((address) this) + _header_size; }; 112 relocInfo* relocation_begin() const { return (relocInfo*) header_end(); }; 113 relocInfo* relocation_end() const { return (relocInfo*)(header_end() + _relocation_size); } 114 address instructions_begin() const { return (address) header_begin() + _instructions_offset; } 115 address instructions_end() const { return (address) header_begin() + _data_offset; } 116 address data_begin() const { return (address) header_begin() + _data_offset; } 117 address data_end() const { return (address) header_begin() + _size; } 118 oop* oops_begin() const { return (oop*) (header_begin() + _oops_offset); } 119 oop* oops_end() const { return oops_begin() + _oops_length; } 120 121 // Offsets 122 int relocation_offset() const { return _header_size; } 123 int instructions_offset() const { return _instructions_offset; } 124 int data_offset() const { return _data_offset; } 125 int oops_offset() const { return _oops_offset; } 126 127 // Sizes 128 int size() const { return _size; } 129 int header_size() const { return _header_size; } 130 int relocation_size() const { return (address) relocation_end() - (address) relocation_begin(); } 131 int instructions_size() const { return instructions_end() - instructions_begin(); } 132 int data_size() const { return data_end() - data_begin(); } 133 int oops_size() const { return (address) oops_end() - (address) oops_begin(); } 134 135 // Containment 136 bool blob_contains(address addr) const { return header_begin() <= addr && addr < data_end(); } 137 bool relocation_contains(relocInfo* addr) const{ return relocation_begin() <= addr && addr < relocation_end(); } 138 bool instructions_contains(address addr) const { return instructions_begin() <= addr && addr < instructions_end(); } 139 bool data_contains(address addr) const { return data_begin() <= addr && addr < data_end(); } 140 bool oops_contains(oop* addr) const { return oops_begin() <= addr && addr < oops_end(); } 141 bool contains(address addr) const { return instructions_contains(addr); } 142 bool is_frame_complete_at(address addr) const { return instructions_contains(addr) && 143 addr >= instructions_begin() + _frame_complete_offset; } 144 145 // Relocation support 146 void fix_oop_relocations(address begin, address end) { 147 fix_oop_relocations(begin, end, false); 148 } 149 void fix_oop_relocations() { 150 fix_oop_relocations(NULL, NULL, false); 151 } 152 relocInfo::relocType reloc_type_for_address(address pc); 153 bool is_at_poll_return(address pc); 154 bool is_at_poll_or_poll_return(address pc); 155 156 // Support for oops in scopes and relocs: 157 // Note: index 0 is reserved for null. 158 oop oop_at(int index) const { return index == 0? (oop)NULL: *oop_addr_at(index); } 159 oop* oop_addr_at(int index) const{ // for GC 160 // relocation indexes are biased by 1 (because 0 is reserved) 161 assert(index > 0 && index <= _oops_length, "must be a valid non-zero index"); 162 return &oops_begin()[index-1]; 163 } 164 165 void copy_oops(GrowableArray<jobject>* oops); 166 167 // CodeCache support: really only used by the nmethods, but in order to get 168 // asserts and certain bookkeeping to work in the CodeCache they are defined 169 // virtual here. 170 virtual bool is_zombie() const { return false; } 171 virtual bool is_locked_by_vm() const { return false; } 172 173 virtual bool is_unloaded() const { return false; } 174 virtual bool is_not_entrant() const { return false; } 175 176 // GC support 177 virtual bool is_alive() const = 0; 178 virtual void do_unloading(BoolObjectClosure* is_alive, 179 OopClosure* keep_alive, 180 bool unloading_occurred); 181 virtual void oops_do(OopClosure* f) = 0; 182 // (All CodeBlob subtypes other than NMethod currently have 183 // an empty oops_do() method. 184 185 // OopMap for frame 186 OopMapSet* oop_maps() const { return _oop_maps; } 187 void set_oop_maps(OopMapSet* p); 188 OopMap* oop_map_for_return_address(address return_address); 189 virtual void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { ShouldNotReachHere(); } 190 191 // Frame support 192 int frame_size() const { return _frame_size; } 193 void set_frame_size(int size) { _frame_size = size; } 194 195 // Returns true, if the next frame is responsible for GC'ing oops passed as arguments 196 virtual bool caller_must_gc_arguments(JavaThread* thread) const { return false; } 197 198 // Naming 199 const char* name() const { return _name; } 200 void set_name(const char* name) { _name = name; } 201 202 // Debugging 203 virtual void verify(); | 37 // - relocation 38 // - instruction space 39 // - data space 40 class DeoptimizationBlob; 41 42 class CodeBlob VALUE_OBJ_CLASS_SPEC { 43 44 friend class VMStructs; 45 46 private: 47 const char* _name; 48 int _size; // total size of CodeBlob in bytes 49 int _header_size; // size of header (depends on subclass) 50 int _relocation_size; // size of relocation 51 int _instructions_offset; // offset to where instructions region begins 52 int _frame_complete_offset; // instruction offsets in [0.._frame_complete_offset) have 53 // not finished setting up their frame. Beware of pc's in 54 // that range. There is a similar range(s) on returns 55 // which we don't detect. 56 int _data_offset; // offset to where data region begins 57 int _frame_size; // size of stack frame 58 OopMapSet* _oop_maps; // OopMap for this CodeBlob 59 CodeComments _comments; 60 61 friend class OopRecorder; 62 63 public: 64 // Returns the space needed for CodeBlob 65 static unsigned int allocation_size(CodeBuffer* cb, int header_size); 66 67 // Creation 68 // a) simple CodeBlob 69 // frame_complete is the offset from the beginning of the instructions 70 // to where the frame setup (from stackwalk viewpoint) is complete. 71 CodeBlob(const char* name, int header_size, int size, int frame_complete, int locs_size); 72 73 // b) full CodeBlob 74 CodeBlob( 75 const char* name, 76 CodeBuffer* cb, 77 int header_size, 78 int size, 79 int frame_complete, 80 int frame_size, 81 OopMapSet* oop_maps 82 ); 93 virtual bool is_exception_stub() const { return false; } 94 virtual bool is_safepoint_stub() const { return false; } 95 virtual bool is_adapter_blob() const { return false; } 96 virtual bool is_method_handles_adapter_blob() const { return false; } 97 98 virtual bool is_compiled_by_c2() const { return false; } 99 virtual bool is_compiled_by_c1() const { return false; } 100 101 // Casting 102 nmethod* as_nmethod_or_null() { return is_nmethod() ? (nmethod*) this : NULL; } 103 104 // Boundaries 105 address header_begin() const { return (address) this; } 106 address header_end() const { return ((address) this) + _header_size; }; 107 relocInfo* relocation_begin() const { return (relocInfo*) header_end(); }; 108 relocInfo* relocation_end() const { return (relocInfo*)(header_end() + _relocation_size); } 109 address instructions_begin() const { return (address) header_begin() + _instructions_offset; } 110 address instructions_end() const { return (address) header_begin() + _data_offset; } 111 address data_begin() const { return (address) header_begin() + _data_offset; } 112 address data_end() const { return (address) header_begin() + _size; } 113 114 // Offsets 115 int relocation_offset() const { return _header_size; } 116 int instructions_offset() const { return _instructions_offset; } 117 int data_offset() const { return _data_offset; } 118 119 // Sizes 120 int size() const { return _size; } 121 int header_size() const { return _header_size; } 122 int relocation_size() const { return (address) relocation_end() - (address) relocation_begin(); } 123 int instructions_size() const { return instructions_end() - instructions_begin(); } 124 int data_size() const { return data_end() - data_begin(); } 125 126 // Containment 127 bool blob_contains(address addr) const { return header_begin() <= addr && addr < data_end(); } 128 bool relocation_contains(relocInfo* addr) const{ return relocation_begin() <= addr && addr < relocation_end(); } 129 bool instructions_contains(address addr) const { return instructions_begin() <= addr && addr < instructions_end(); } 130 bool data_contains(address addr) const { return data_begin() <= addr && addr < data_end(); } 131 bool contains(address addr) const { return instructions_contains(addr); } 132 bool is_frame_complete_at(address addr) const { return instructions_contains(addr) && 133 addr >= instructions_begin() + _frame_complete_offset; } 134 135 // CodeCache support: really only used by the nmethods, but in order to get 136 // asserts and certain bookkeeping to work in the CodeCache they are defined 137 // virtual here. 138 virtual bool is_zombie() const { return false; } 139 virtual bool is_locked_by_vm() const { return false; } 140 141 virtual bool is_unloaded() const { return false; } 142 virtual bool is_not_entrant() const { return false; } 143 144 // GC support 145 virtual bool is_alive() const = 0; 146 virtual void do_unloading(BoolObjectClosure* is_alive, 147 OopClosure* keep_alive, 148 bool unloading_occurred); 149 150 // OopMap for frame 151 OopMapSet* oop_maps() const { return _oop_maps; } 152 void set_oop_maps(OopMapSet* p); 153 OopMap* oop_map_for_return_address(address return_address); 154 virtual void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { ShouldNotReachHere(); } 155 156 // Frame support 157 int frame_size() const { return _frame_size; } 158 void set_frame_size(int size) { _frame_size = size; } 159 160 // Returns true, if the next frame is responsible for GC'ing oops passed as arguments 161 virtual bool caller_must_gc_arguments(JavaThread* thread) const { return false; } 162 163 // Naming 164 const char* name() const { return _name; } 165 void set_name(const char* name) { _name = name; } 166 167 // Debugging 168 virtual void verify(); |