< prev index next >

src/cpu/ppc/vm/nativeInst_ppc.cpp

Print this page




 204   }
 205 }
 206 
 207 address NativeMovConstReg::set_data_plain(intptr_t data, CodeBlob *cb) {
 208   address addr         = instruction_address();
 209   address next_address = NULL;
 210   if (!cb) cb = CodeCache::find_blob(addr);
 211 
 212   if (cb != NULL && MacroAssembler::is_load_const_from_method_toc_at(addr)) {
 213     // A load from the method's TOC (ctable).
 214     assert(cb->is_nmethod(), "must be nmethod");
 215     const address ctable = cb->content_begin();
 216     const int toc_offset = MacroAssembler::get_offset_of_load_const_from_method_toc_at(addr);
 217     *(intptr_t *)(ctable + toc_offset) = data;
 218     next_address = addr + BytesPerInstWord;
 219   } else if (cb != NULL &&
 220              MacroAssembler::is_calculate_address_from_global_toc_at(addr, cb->content_begin())) {
 221     // A calculation relative to the global TOC.
 222     if (MacroAssembler::get_address_of_calculate_address_from_global_toc_at(addr, cb->content_begin()) !=
 223         (address)data) {
 224       const int invalidated_range =
 225         MacroAssembler::patch_calculate_address_from_global_toc_at(addr, cb->content_begin(),
 226                                                                    (address)data);
 227       const address start = invalidated_range < 0 ? addr + invalidated_range : addr;
 228       // FIXME:
 229       const int range = invalidated_range < 0 ? 4 - invalidated_range : 8;
 230       ICache::ppc64_flush_icache_bytes(start, range);
 231     }
 232     next_address = addr + 1 * BytesPerInstWord;
 233   } else if (MacroAssembler::is_load_const_at(addr)) {
 234     // A normal 5 instruction load_const code sequence.
 235     if (MacroAssembler::get_const(addr) != (long)data) {
 236       // This is not mt safe, ok in methods like CodeBuffer::copy_code().
 237       MacroAssembler::patch_const(addr, (long)data);
 238       ICache::ppc64_flush_icache_bytes(addr, load_const_instruction_size);
 239     }
 240     next_address = addr + 5 * BytesPerInstWord;
 241   } else if (MacroAssembler::is_bl(* (int*) addr)) {
 242     // A single branch-and-link instruction.
 243     ResourceMark rm;
 244     const int code_size = 1 * BytesPerInstWord;
 245     CodeBuffer cb(addr, code_size + 1);
 246     MacroAssembler* a = new MacroAssembler(&cb);
 247     a->bl((address) data);
 248     ICache::ppc64_flush_icache_bytes(addr, code_size);
 249     next_address = addr + code_size;


 274           assert(oop_addr == r->oop_addr(), "must be only one set-oop here");
 275         }
 276       }
 277       if (iter.type() == relocInfo::metadata_type) {
 278         metadata_Relocation *r = iter.metadata_reloc();
 279         if (metadata_addr == NULL) {
 280           metadata_addr = r->metadata_addr();
 281           *metadata_addr = (Metadata*)data;
 282         } else {
 283           assert(metadata_addr == r->metadata_addr(), "must be only one set-metadata here");
 284         }
 285       }
 286     }
 287   }
 288 }
 289 
 290 void NativeMovConstReg::set_narrow_oop(narrowOop data, CodeBlob *code /* = NULL */) {
 291   address   addr = addr_at(0);
 292   CodeBlob* cb = (code) ? code : CodeCache::find_blob(instruction_address());
 293   if (MacroAssembler::get_narrow_oop(addr, cb->content_begin()) == (long)data) return;
 294   const int invalidated_range =
 295     MacroAssembler::patch_set_narrow_oop(addr, cb->content_begin(), (long)data);
 296   const address start = invalidated_range < 0 ? addr + invalidated_range : addr;
 297   // FIXME:
 298   const int range = invalidated_range < 0 ? 4 - invalidated_range : 8;
 299   ICache::ppc64_flush_icache_bytes(start, range);
 300 }
 301 
 302 // Do not use an assertion here. Let clients decide whether they only
 303 // want this when assertions are enabled.
 304 #ifdef ASSERT
 305 void NativeMovConstReg::verify() {
 306   address   addr = addr_at(0);
 307   if (! MacroAssembler::is_load_const_at(addr) &&
 308       ! MacroAssembler::is_load_const_from_method_toc_at(addr)) {
 309     CodeBlob* cb = CodeCache::find_blob_unsafe(addr);   // find_nmethod() asserts if nmethod is zombie.
 310     if (! (cb != NULL && MacroAssembler::is_calculate_address_from_global_toc_at(addr, cb->content_begin())) &&
 311         ! (cb != NULL && MacroAssembler::is_set_narrow_oop(addr, cb->content_begin())) &&
 312         ! MacroAssembler::is_bl(*((int*) addr))) {
 313       tty->print_cr("not a NativeMovConstReg at " PTR_FORMAT, p2i(addr));
 314       // TODO: PPC port: Disassembler::decode(addr, 20, 20, tty);
 315       fatal("not a NativeMovConstReg at " PTR_FORMAT, p2i(addr));
 316     }
 317   }
 318 }




 204   }
 205 }
 206 
 207 address NativeMovConstReg::set_data_plain(intptr_t data, CodeBlob *cb) {
 208   address addr         = instruction_address();
 209   address next_address = NULL;
 210   if (!cb) cb = CodeCache::find_blob(addr);
 211 
 212   if (cb != NULL && MacroAssembler::is_load_const_from_method_toc_at(addr)) {
 213     // A load from the method's TOC (ctable).
 214     assert(cb->is_nmethod(), "must be nmethod");
 215     const address ctable = cb->content_begin();
 216     const int toc_offset = MacroAssembler::get_offset_of_load_const_from_method_toc_at(addr);
 217     *(intptr_t *)(ctable + toc_offset) = data;
 218     next_address = addr + BytesPerInstWord;
 219   } else if (cb != NULL &&
 220              MacroAssembler::is_calculate_address_from_global_toc_at(addr, cb->content_begin())) {
 221     // A calculation relative to the global TOC.
 222     if (MacroAssembler::get_address_of_calculate_address_from_global_toc_at(addr, cb->content_begin()) !=
 223         (address)data) {
 224       const int first_insn_offset =
 225         MacroAssembler::patch_calculate_address_from_global_toc_at(addr, cb->content_begin(),
 226                                                                    (address)data);
 227       assert(first_insn_offset > 0, "first instruction must be found");
 228       const address start = addr - first_insn_offset;
 229       const int range = BytesPerInstWord + first_insn_offset;
 230       ICache::ppc64_flush_icache_bytes(start, range);
 231     }
 232     next_address = addr + 1 * BytesPerInstWord;
 233   } else if (MacroAssembler::is_load_const_at(addr)) {
 234     // A normal 5 instruction load_const code sequence.
 235     if (MacroAssembler::get_const(addr) != (long)data) {
 236       // This is not mt safe, ok in methods like CodeBuffer::copy_code().
 237       MacroAssembler::patch_const(addr, (long)data);
 238       ICache::ppc64_flush_icache_bytes(addr, load_const_instruction_size);
 239     }
 240     next_address = addr + 5 * BytesPerInstWord;
 241   } else if (MacroAssembler::is_bl(* (int*) addr)) {
 242     // A single branch-and-link instruction.
 243     ResourceMark rm;
 244     const int code_size = 1 * BytesPerInstWord;
 245     CodeBuffer cb(addr, code_size + 1);
 246     MacroAssembler* a = new MacroAssembler(&cb);
 247     a->bl((address) data);
 248     ICache::ppc64_flush_icache_bytes(addr, code_size);
 249     next_address = addr + code_size;


 274           assert(oop_addr == r->oop_addr(), "must be only one set-oop here");
 275         }
 276       }
 277       if (iter.type() == relocInfo::metadata_type) {
 278         metadata_Relocation *r = iter.metadata_reloc();
 279         if (metadata_addr == NULL) {
 280           metadata_addr = r->metadata_addr();
 281           *metadata_addr = (Metadata*)data;
 282         } else {
 283           assert(metadata_addr == r->metadata_addr(), "must be only one set-metadata here");
 284         }
 285       }
 286     }
 287   }
 288 }
 289 
 290 void NativeMovConstReg::set_narrow_oop(narrowOop data, CodeBlob *code /* = NULL */) {
 291   address   addr = addr_at(0);
 292   CodeBlob* cb = (code) ? code : CodeCache::find_blob(instruction_address());
 293   if (MacroAssembler::get_narrow_oop(addr, cb->content_begin()) == (long)data) return;
 294   const int first_insn_offset =
 295     MacroAssembler::patch_set_narrow_oop(addr, cb->content_begin(), (long)data);
 296   assert(first_insn_offset > 0, "first instruction must be found");
 297   const address start = addr - first_insn_offset;
 298   const int range = BytesPerInstWord + first_insn_offset;
 299   ICache::ppc64_flush_icache_bytes(start, range);
 300 }
 301 
 302 // Do not use an assertion here. Let clients decide whether they only
 303 // want this when assertions are enabled.
 304 #ifdef ASSERT
 305 void NativeMovConstReg::verify() {
 306   address   addr = addr_at(0);
 307   if (! MacroAssembler::is_load_const_at(addr) &&
 308       ! MacroAssembler::is_load_const_from_method_toc_at(addr)) {
 309     CodeBlob* cb = CodeCache::find_blob_unsafe(addr);   // find_nmethod() asserts if nmethod is zombie.
 310     if (! (cb != NULL && MacroAssembler::is_calculate_address_from_global_toc_at(addr, cb->content_begin())) &&
 311         ! (cb != NULL && MacroAssembler::is_set_narrow_oop(addr, cb->content_begin())) &&
 312         ! MacroAssembler::is_bl(*((int*) addr))) {
 313       tty->print_cr("not a NativeMovConstReg at " PTR_FORMAT, p2i(addr));
 314       // TODO: PPC port: Disassembler::decode(addr, 20, 20, tty);
 315       fatal("not a NativeMovConstReg at " PTR_FORMAT, p2i(addr));
 316     }
 317   }
 318 }


< prev index next >