49 CodeBlob::CodeBlob(const char* name, int header_size, int size, int frame_complete, int locs_size) { 50 assert(size == round_to(size, oopSize), "unaligned size"); 51 assert(locs_size == round_to(locs_size, oopSize), "unaligned size"); 52 assert(header_size == round_to(header_size, oopSize), "unaligned size"); 53 assert(!UseRelocIndex, "no space allocated for reloc index yet"); 54 55 // Note: If UseRelocIndex is enabled, there needs to be (at least) one 56 // extra word for the relocation information, containing the reloc 57 // index table length. Unfortunately, the reloc index table imple- 58 // mentation is not easily understandable and thus it is not clear 59 // what exactly the format is supposed to be. For now, we just turn 60 // off the use of this table (gri 7/6/2000). 61 62 _name = name; 63 _size = size; 64 _frame_complete_offset = frame_complete; 65 _header_size = header_size; 66 _relocation_size = locs_size; 67 _instructions_offset = align_code_offset(header_size + locs_size); 68 _data_offset = size; 69 _oops_offset = size; 70 _oops_length = 0; 71 _frame_size = 0; 72 set_oop_maps(NULL); 73 } 74 75 76 // Creates a CodeBlob from a CodeBuffer. Sets up the size of the different regions, 77 // and copy code and relocation info. 78 CodeBlob::CodeBlob( 79 const char* name, 80 CodeBuffer* cb, 81 int header_size, 82 int size, 83 int frame_complete, 84 int frame_size, 85 OopMapSet* oop_maps 86 ) { 87 assert(size == round_to(size, oopSize), "unaligned size"); 88 assert(header_size == round_to(header_size, oopSize), "unaligned size"); 89 90 _name = name; 91 _size = size; 92 _frame_complete_offset = frame_complete; 93 _header_size = header_size; 94 _relocation_size = round_to(cb->total_relocation_size(), oopSize); 95 _instructions_offset = align_code_offset(header_size + _relocation_size); 96 _data_offset = _instructions_offset + round_to(cb->total_code_size(), oopSize); 97 _oops_offset = _size - round_to(cb->total_oop_size(), oopSize); 98 _oops_length = 0; // temporary, until the copy_oops handshake 99 assert(_oops_offset >= _data_offset, "codeBlob is too small"); 100 assert(_data_offset <= size, "codeBlob is too small"); 101 102 cb->copy_code_and_locs_to(this); 103 set_oop_maps(oop_maps); 104 _frame_size = frame_size; 105 #ifdef COMPILER1 106 // probably wrong for tiered 107 assert(_frame_size >= -1, "must use frame size or -1 for runtime stubs"); 108 #endif // COMPILER1 109 } 110 111 112 void CodeBlob::set_oop_maps(OopMapSet* p) { 113 // Danger Will Robinson! This method allocates a big 114 // chunk of memory, its your job to free it. 115 if (p != NULL) { 116 // We need to allocate a chunk big enough to hold the OopMapSet and all of its OopMaps 117 _oop_maps = (OopMapSet* )NEW_C_HEAP_ARRAY(unsigned char, p->heap_size()); 118 p->copy_to((address)_oop_maps); 119 } else { 120 _oop_maps = NULL; 121 } 122 } 123 124 125 void CodeBlob::flush() { 126 if (_oop_maps) { 127 FREE_C_HEAP_ARRAY(unsigned char, _oop_maps); 128 _oop_maps = NULL; 129 } 130 _comments.free(); 131 } 132 133 134 // Promote one word from an assembly-time handle to a live embedded oop. 135 inline void CodeBlob::initialize_immediate_oop(oop* dest, jobject handle) { 136 if (handle == NULL || 137 // As a special case, IC oops are initialized to 1 or -1. 138 handle == (jobject) Universe::non_oop_word()) { 139 (*dest) = (oop)handle; 140 } else { 141 (*dest) = JNIHandles::resolve_non_null(handle); 142 } 143 } 144 145 146 void CodeBlob::copy_oops(GrowableArray<jobject>* array) { 147 assert(_oops_length == 0, "do this handshake just once, please"); 148 int length = array->length(); 149 assert((address)(oops_begin() + length) <= data_end(), "oops big enough"); 150 oop* dest = oops_begin(); 151 for (int index = 0 ; index < length; index++) { 152 initialize_immediate_oop(&dest[index], array->at(index)); 153 } 154 _oops_length = length; 155 156 // Now we can fix up all the oops in the code. 157 // We need to do this in the code because 158 // the assembler uses jobjects as placeholders. 159 // The code and relocations have already been 160 // initialized by the CodeBlob constructor, 161 // so it is valid even at this early point to 162 // iterate over relocations and patch the code. 163 fix_oop_relocations(NULL, NULL, /*initialize_immediates=*/ true); 164 } 165 166 167 relocInfo::relocType CodeBlob::reloc_type_for_address(address pc) { 168 RelocIterator iter(this, pc, pc+1); 169 while (iter.next()) { 170 return (relocInfo::relocType) iter.type(); 171 } 172 // No relocation info found for pc 173 ShouldNotReachHere(); 174 return relocInfo::none; // dummy return value 175 } 176 177 178 bool CodeBlob::is_at_poll_return(address pc) { 179 RelocIterator iter(this, pc, pc+1); 180 while (iter.next()) { 181 if (iter.type() == relocInfo::poll_return_type) 182 return true; 183 } 184 return false; 185 } 186 187 188 bool CodeBlob::is_at_poll_or_poll_return(address pc) { 189 RelocIterator iter(this, pc, pc+1); 190 while (iter.next()) { 191 relocInfo::relocType t = iter.type(); 192 if (t == relocInfo::poll_return_type || t == relocInfo::poll_type) 193 return true; 194 } 195 return false; 196 } 197 198 199 void CodeBlob::fix_oop_relocations(address begin, address end, 200 bool initialize_immediates) { 201 // re-patch all oop-bearing instructions, just in case some oops moved 202 RelocIterator iter(this, begin, end); 203 while (iter.next()) { 204 if (iter.type() == relocInfo::oop_type) { 205 oop_Relocation* reloc = iter.oop_reloc(); 206 if (initialize_immediates && reloc->oop_is_immediate()) { 207 oop* dest = reloc->oop_addr(); 208 initialize_immediate_oop(dest, (jobject) *dest); 209 } 210 // Refresh the oop-related bits of this instruction. 211 reloc->fix_oop_relocation(); 212 } 213 214 // There must not be any interfering patches or breakpoints. 215 assert(!(iter.type() == relocInfo::breakpoint_type 216 && iter.breakpoint_reloc()->active()), 217 "no active breakpoint"); 218 } 219 } 220 221 void CodeBlob::do_unloading(BoolObjectClosure* is_alive, 222 OopClosure* keep_alive, 223 bool unloading_occurred) { 224 ShouldNotReachHere(); 225 } 226 227 OopMap* CodeBlob::oop_map_for_return_address(address return_address) { 228 address pc = return_address ; 229 assert (oop_maps() != NULL, "nope"); 230 return oop_maps()->find_map_at_offset ((intptr_t) pc - (intptr_t) instructions_begin()); 231 } 232 233 234 //---------------------------------------------------------------------------------------------------- 235 // Implementation of BufferBlob 236 237 238 BufferBlob::BufferBlob(const char* name, int size) 239 : CodeBlob(name, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, /*locs_size:*/ 0) 240 {} 241 242 BufferBlob* BufferBlob::create(const char* name, int buffer_size) { 243 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock 244 245 BufferBlob* blob = NULL; 246 unsigned int size = sizeof(BufferBlob); | 49 CodeBlob::CodeBlob(const char* name, int header_size, int size, int frame_complete, int locs_size) { 50 assert(size == round_to(size, oopSize), "unaligned size"); 51 assert(locs_size == round_to(locs_size, oopSize), "unaligned size"); 52 assert(header_size == round_to(header_size, oopSize), "unaligned size"); 53 assert(!UseRelocIndex, "no space allocated for reloc index yet"); 54 55 // Note: If UseRelocIndex is enabled, there needs to be (at least) one 56 // extra word for the relocation information, containing the reloc 57 // index table length. Unfortunately, the reloc index table imple- 58 // mentation is not easily understandable and thus it is not clear 59 // what exactly the format is supposed to be. For now, we just turn 60 // off the use of this table (gri 7/6/2000). 61 62 _name = name; 63 _size = size; 64 _frame_complete_offset = frame_complete; 65 _header_size = header_size; 66 _relocation_size = locs_size; 67 _instructions_offset = align_code_offset(header_size + locs_size); 68 _data_offset = size; 69 _frame_size = 0; 70 set_oop_maps(NULL); 71 } 72 73 74 // Creates a CodeBlob from a CodeBuffer. Sets up the size of the different regions, 75 // and copy code and relocation info. 76 CodeBlob::CodeBlob( 77 const char* name, 78 CodeBuffer* cb, 79 int header_size, 80 int size, 81 int frame_complete, 82 int frame_size, 83 OopMapSet* oop_maps 84 ) { 85 assert(size == round_to(size, oopSize), "unaligned size"); 86 assert(header_size == round_to(header_size, oopSize), "unaligned size"); 87 88 _name = name; 89 _size = size; 90 _frame_complete_offset = frame_complete; 91 _header_size = header_size; 92 _relocation_size = round_to(cb->total_relocation_size(), oopSize); 93 _instructions_offset = align_code_offset(header_size + _relocation_size); 94 _data_offset = _instructions_offset + round_to(cb->total_code_size(), oopSize); 95 assert(_data_offset <= size, "codeBlob is too small"); 96 97 cb->copy_code_and_locs_to(this); 98 set_oop_maps(oop_maps); 99 _frame_size = frame_size; 100 #ifdef COMPILER1 101 // probably wrong for tiered 102 assert(_frame_size >= -1, "must use frame size or -1 for runtime stubs"); 103 #endif // COMPILER1 104 } 105 106 107 void CodeBlob::set_oop_maps(OopMapSet* p) { 108 // Danger Will Robinson! This method allocates a big 109 // chunk of memory, its your job to free it. 110 if (p != NULL) { 111 // We need to allocate a chunk big enough to hold the OopMapSet and all of its OopMaps 112 _oop_maps = (OopMapSet* )NEW_C_HEAP_ARRAY(unsigned char, p->heap_size()); 113 p->copy_to((address)_oop_maps); 114 } else { 115 _oop_maps = NULL; 116 } 117 } 118 119 120 void CodeBlob::flush() { 121 if (_oop_maps) { 122 FREE_C_HEAP_ARRAY(unsigned char, _oop_maps); 123 _oop_maps = NULL; 124 } 125 _comments.free(); 126 } 127 128 129 OopMap* CodeBlob::oop_map_for_return_address(address return_address) { 130 address pc = return_address ; 131 assert (oop_maps() != NULL, "nope"); 132 return oop_maps()->find_map_at_offset ((intptr_t) pc - (intptr_t) instructions_begin()); 133 } 134 135 136 //---------------------------------------------------------------------------------------------------- 137 // Implementation of BufferBlob 138 139 140 BufferBlob::BufferBlob(const char* name, int size) 141 : CodeBlob(name, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, /*locs_size:*/ 0) 142 {} 143 144 BufferBlob* BufferBlob::create(const char* name, int buffer_size) { 145 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock 146 147 BufferBlob* blob = NULL; 148 unsigned int size = sizeof(BufferBlob); |