112 bool add_relocation, bool emit_dummy_addr) { 113 int offset = -1; 114 if (emit_dummy_addr) { 115 offset = -128; // dummy address 116 } else if (addr != (address)(intptr_t)-1) { 117 offset = MacroAssembler::offset_to_global_toc(addr); 118 } 119 120 if (hi16) { 121 addis(dst, R29_TOC, MacroAssembler::largeoffset_si16_si16_hi(offset)); 122 } 123 if (lo16) { 124 if (add_relocation) { 125 // Relocate at the addi to avoid confusion with a load from the method's TOC. 126 relocate(internal_word_Relocation::spec(addr)); 127 } 128 addi(dst, dst, MacroAssembler::largeoffset_si16_si16_lo(offset)); 129 } 130 } 131 132 int MacroAssembler::patch_calculate_address_from_global_toc_at(address a, address bound, address addr) { 133 const int offset = MacroAssembler::offset_to_global_toc(addr); 134 135 const address inst2_addr = a; 136 const int inst2 = *(int *)inst2_addr; 137 138 // The relocation points to the second instruction, the addi, 139 // and the addi reads and writes the same register dst. 140 const int dst = inv_rt_field(inst2); 141 assert(is_addi(inst2) && inv_ra_field(inst2) == dst, "must be addi reading and writing dst"); 142 143 // Now, find the preceding addis which writes to dst. 144 int inst1 = 0; 145 address inst1_addr = inst2_addr - BytesPerInstWord; 146 while (inst1_addr >= bound) { 147 inst1 = *(int *) inst1_addr; 148 if (is_addis(inst1) && inv_rt_field(inst1) == dst) { 149 // Stop, found the addis which writes dst. 150 break; 151 } 152 inst1_addr -= BytesPerInstWord; 153 } 154 155 assert(is_addis(inst1) && inv_ra_field(inst1) == 29 /* R29 */, "source must be global TOC"); 156 set_imm((int *)inst1_addr, MacroAssembler::largeoffset_si16_si16_hi(offset)); 157 set_imm((int *)inst2_addr, MacroAssembler::largeoffset_si16_si16_lo(offset)); 158 return (int)((intptr_t)addr - (intptr_t)inst1_addr); 159 } 160 161 address MacroAssembler::get_address_of_calculate_address_from_global_toc_at(address a, address bound) { 162 const address inst2_addr = a; 163 const int inst2 = *(int *)inst2_addr; 164 165 // The relocation points to the second instruction, the addi, 166 // and the addi reads and writes the same register dst. 167 const int dst = inv_rt_field(inst2); 168 assert(is_addi(inst2) && inv_ra_field(inst2) == dst, "must be addi reading and writing dst"); 169 170 // Now, find the preceding addis which writes to dst. 171 int inst1 = 0; 172 address inst1_addr = inst2_addr - BytesPerInstWord; 173 while (inst1_addr >= bound) { 174 inst1 = *(int *) inst1_addr; 175 if (is_addis(inst1) && inv_rt_field(inst1) == dst) { 176 // stop, found the addis which writes dst 177 break; 178 } 184 int offset = (get_imm(inst1_addr, 0) << 16) + get_imm(inst2_addr, 0); 185 // -1 is a special case 186 if (offset == -1) { 187 return (address)(intptr_t)-1; 188 } else { 189 return global_toc() + offset; 190 } 191 } 192 193 #ifdef _LP64 194 // Patch compressed oops or klass constants. 195 // Assembler sequence is 196 // 1) compressed oops: 197 // lis rx = const.hi 198 // ori rx = rx | const.lo 199 // 2) compressed klass: 200 // lis rx = const.hi 201 // clrldi rx = rx & 0xFFFFffff // clearMS32b, optional 202 // ori rx = rx | const.lo 203 // Clrldi will be passed by. 204 int MacroAssembler::patch_set_narrow_oop(address a, address bound, narrowOop data) { 205 assert(UseCompressedOops, "Should only patch compressed oops"); 206 207 const address inst2_addr = a; 208 const int inst2 = *(int *)inst2_addr; 209 210 // The relocation points to the second instruction, the ori, 211 // and the ori reads and writes the same register dst. 212 const int dst = inv_rta_field(inst2); 213 assert(is_ori(inst2) && inv_rs_field(inst2) == dst, "must be ori reading and writing dst"); 214 // Now, find the preceding addis which writes to dst. 215 int inst1 = 0; 216 address inst1_addr = inst2_addr - BytesPerInstWord; 217 bool inst1_found = false; 218 while (inst1_addr >= bound) { 219 inst1 = *(int *)inst1_addr; 220 if (is_lis(inst1) && inv_rs_field(inst1) == dst) { inst1_found = true; break; } 221 inst1_addr -= BytesPerInstWord; 222 } 223 assert(inst1_found, "inst is not lis"); 224 225 int xc = (data >> 16) & 0xffff; 226 int xd = (data >> 0) & 0xffff; 227 228 set_imm((int *)inst1_addr, (short)(xc)); // see enc_load_con_narrow_hi/_lo 229 set_imm((int *)inst2_addr, (xd)); // unsigned int 230 return (int)((intptr_t)inst2_addr - (intptr_t)inst1_addr); 231 } 232 233 // Get compressed oop or klass constant. 234 narrowOop MacroAssembler::get_narrow_oop(address a, address bound) { 235 assert(UseCompressedOops, "Should only patch compressed oops"); 236 237 const address inst2_addr = a; 238 const int inst2 = *(int *)inst2_addr; 239 240 // The relocation points to the second instruction, the ori, 241 // and the ori reads and writes the same register dst. 242 const int dst = inv_rta_field(inst2); 243 assert(is_ori(inst2) && inv_rs_field(inst2) == dst, "must be ori reading and writing dst"); 244 // Now, find the preceding lis which writes to dst. 245 int inst1 = 0; 246 address inst1_addr = inst2_addr - BytesPerInstWord; 247 bool inst1_found = false; 248 249 while (inst1_addr >= bound) { 250 inst1 = *(int *) inst1_addr; | 112 bool add_relocation, bool emit_dummy_addr) { 113 int offset = -1; 114 if (emit_dummy_addr) { 115 offset = -128; // dummy address 116 } else if (addr != (address)(intptr_t)-1) { 117 offset = MacroAssembler::offset_to_global_toc(addr); 118 } 119 120 if (hi16) { 121 addis(dst, R29_TOC, MacroAssembler::largeoffset_si16_si16_hi(offset)); 122 } 123 if (lo16) { 124 if (add_relocation) { 125 // Relocate at the addi to avoid confusion with a load from the method's TOC. 126 relocate(internal_word_Relocation::spec(addr)); 127 } 128 addi(dst, dst, MacroAssembler::largeoffset_si16_si16_lo(offset)); 129 } 130 } 131 132 address MacroAssembler::patch_calculate_address_from_global_toc_at(address a, address bound, address addr) { 133 const int offset = MacroAssembler::offset_to_global_toc(addr); 134 135 const address inst2_addr = a; 136 const int inst2 = *(int *)inst2_addr; 137 138 // The relocation points to the second instruction, the addi, 139 // and the addi reads and writes the same register dst. 140 const int dst = inv_rt_field(inst2); 141 assert(is_addi(inst2) && inv_ra_field(inst2) == dst, "must be addi reading and writing dst"); 142 143 // Now, find the preceding addis which writes to dst. 144 int inst1 = 0; 145 address inst1_addr = inst2_addr - BytesPerInstWord; 146 while (inst1_addr >= bound) { 147 inst1 = *(int *) inst1_addr; 148 if (is_addis(inst1) && inv_rt_field(inst1) == dst) { 149 // Stop, found the addis which writes dst. 150 break; 151 } 152 inst1_addr -= BytesPerInstWord; 153 } 154 155 assert(is_addis(inst1) && inv_ra_field(inst1) == 29 /* R29 */, "source must be global TOC"); 156 set_imm((int *)inst1_addr, MacroAssembler::largeoffset_si16_si16_hi(offset)); 157 set_imm((int *)inst2_addr, MacroAssembler::largeoffset_si16_si16_lo(offset)); 158 return inst1_addr; 159 } 160 161 address MacroAssembler::get_address_of_calculate_address_from_global_toc_at(address a, address bound) { 162 const address inst2_addr = a; 163 const int inst2 = *(int *)inst2_addr; 164 165 // The relocation points to the second instruction, the addi, 166 // and the addi reads and writes the same register dst. 167 const int dst = inv_rt_field(inst2); 168 assert(is_addi(inst2) && inv_ra_field(inst2) == dst, "must be addi reading and writing dst"); 169 170 // Now, find the preceding addis which writes to dst. 171 int inst1 = 0; 172 address inst1_addr = inst2_addr - BytesPerInstWord; 173 while (inst1_addr >= bound) { 174 inst1 = *(int *) inst1_addr; 175 if (is_addis(inst1) && inv_rt_field(inst1) == dst) { 176 // stop, found the addis which writes dst 177 break; 178 } 184 int offset = (get_imm(inst1_addr, 0) << 16) + get_imm(inst2_addr, 0); 185 // -1 is a special case 186 if (offset == -1) { 187 return (address)(intptr_t)-1; 188 } else { 189 return global_toc() + offset; 190 } 191 } 192 193 #ifdef _LP64 194 // Patch compressed oops or klass constants. 195 // Assembler sequence is 196 // 1) compressed oops: 197 // lis rx = const.hi 198 // ori rx = rx | const.lo 199 // 2) compressed klass: 200 // lis rx = const.hi 201 // clrldi rx = rx & 0xFFFFffff // clearMS32b, optional 202 // ori rx = rx | const.lo 203 // Clrldi will be passed by. 204 address MacroAssembler::patch_set_narrow_oop(address a, address bound, narrowOop data) { 205 assert(UseCompressedOops, "Should only patch compressed oops"); 206 207 const address inst2_addr = a; 208 const int inst2 = *(int *)inst2_addr; 209 210 // The relocation points to the second instruction, the ori, 211 // and the ori reads and writes the same register dst. 212 const int dst = inv_rta_field(inst2); 213 assert(is_ori(inst2) && inv_rs_field(inst2) == dst, "must be ori reading and writing dst"); 214 // Now, find the preceding addis which writes to dst. 215 int inst1 = 0; 216 address inst1_addr = inst2_addr - BytesPerInstWord; 217 bool inst1_found = false; 218 while (inst1_addr >= bound) { 219 inst1 = *(int *)inst1_addr; 220 if (is_lis(inst1) && inv_rs_field(inst1) == dst) { inst1_found = true; break; } 221 inst1_addr -= BytesPerInstWord; 222 } 223 assert(inst1_found, "inst is not lis"); 224 225 int xc = (data >> 16) & 0xffff; 226 int xd = (data >> 0) & 0xffff; 227 228 set_imm((int *)inst1_addr, (short)(xc)); // see enc_load_con_narrow_hi/_lo 229 set_imm((int *)inst2_addr, (xd)); // unsigned int 230 return inst1_addr; 231 } 232 233 // Get compressed oop or klass constant. 234 narrowOop MacroAssembler::get_narrow_oop(address a, address bound) { 235 assert(UseCompressedOops, "Should only patch compressed oops"); 236 237 const address inst2_addr = a; 238 const int inst2 = *(int *)inst2_addr; 239 240 // The relocation points to the second instruction, the ori, 241 // and the ori reads and writes the same register dst. 242 const int dst = inv_rta_field(inst2); 243 assert(is_ori(inst2) && inv_rs_field(inst2) == dst, "must be ori reading and writing dst"); 244 // Now, find the preceding lis which writes to dst. 245 int inst1 = 0; 246 address inst1_addr = inst2_addr - BytesPerInstWord; 247 bool inst1_found = false; 248 249 while (inst1_addr >= bound) { 250 inst1 = *(int *) inst1_addr; |