comparison src/cpu/x86/vm/assembler_x86.cpp @ 7198:6ab62ad83507

8003195: AbstractAssembler should not store code pointers but use the CodeSection directly Reviewed-by: twisti, kvn Contributed-by: Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
author twisti
date Fri, 30 Nov 2012 11:44:05 -0800
parents a3ecd773a7b9
children cd3d6a6b95d9
comparison
equal deleted inserted replaced
7197:1acccb7c0b01 7198:6ab62ad83507
1152 1152
1153 void Assembler::call_literal(address entry, RelocationHolder const& rspec) { 1153 void Assembler::call_literal(address entry, RelocationHolder const& rspec) {
1154 assert(entry != NULL, "call most probably wrong"); 1154 assert(entry != NULL, "call most probably wrong");
1155 InstructionMark im(this); 1155 InstructionMark im(this);
1156 emit_byte(0xE8); 1156 emit_byte(0xE8);
1157 intptr_t disp = entry - (_code_pos + sizeof(int32_t)); 1157 intptr_t disp = entry - (pc() + sizeof(int32_t));
1158 assert(is_simm32(disp), "must be 32bit offset (call2)"); 1158 assert(is_simm32(disp), "must be 32bit offset (call2)");
1159 // Technically, should use call32_operand, but this format is 1159 // Technically, should use call32_operand, but this format is
1160 // implied by the fact that we're emitting a call instruction. 1160 // implied by the fact that we're emitting a call instruction.
1161 1161
1162 int operand = LP64_ONLY(disp32_operand) NOT_LP64(call32_operand); 1162 int operand = LP64_ONLY(disp32_operand) NOT_LP64(call32_operand);
1415 address dst = target(L); 1415 address dst = target(L);
1416 assert(dst != NULL, "jcc most probably wrong"); 1416 assert(dst != NULL, "jcc most probably wrong");
1417 1417
1418 const int short_size = 2; 1418 const int short_size = 2;
1419 const int long_size = 6; 1419 const int long_size = 6;
1420 intptr_t offs = (intptr_t)dst - (intptr_t)_code_pos; 1420 intptr_t offs = (intptr_t)dst - (intptr_t)pc();
1421 if (maybe_short && is8bit(offs - short_size)) { 1421 if (maybe_short && is8bit(offs - short_size)) {
1422 // 0111 tttn #8-bit disp 1422 // 0111 tttn #8-bit disp
1423 emit_byte(0x70 | cc); 1423 emit_byte(0x70 | cc);
1424 emit_byte((offs - short_size) & 0xFF); 1424 emit_byte((offs - short_size) & 0xFF);
1425 } else { 1425 } else {
1445 void Assembler::jccb(Condition cc, Label& L) { 1445 void Assembler::jccb(Condition cc, Label& L) {
1446 if (L.is_bound()) { 1446 if (L.is_bound()) {
1447 const int short_size = 2; 1447 const int short_size = 2;
1448 address entry = target(L); 1448 address entry = target(L);
1449 #ifdef ASSERT 1449 #ifdef ASSERT
1450 intptr_t dist = (intptr_t)entry - ((intptr_t)_code_pos + short_size); 1450 intptr_t dist = (intptr_t)entry - ((intptr_t)pc() + short_size);
1451 intptr_t delta = short_branch_delta(); 1451 intptr_t delta = short_branch_delta();
1452 if (delta != 0) { 1452 if (delta != 0) {
1453 dist += (dist < 0 ? (-delta) :delta); 1453 dist += (dist < 0 ? (-delta) :delta);
1454 } 1454 }
1455 assert(is8bit(dist), "Dispacement too large for a short jmp"); 1455 assert(is8bit(dist), "Dispacement too large for a short jmp");
1456 #endif 1456 #endif
1457 intptr_t offs = (intptr_t)entry - (intptr_t)_code_pos; 1457 intptr_t offs = (intptr_t)entry - (intptr_t)pc();
1458 // 0111 tttn #8-bit disp 1458 // 0111 tttn #8-bit disp
1459 emit_byte(0x70 | cc); 1459 emit_byte(0x70 | cc);
1460 emit_byte((offs - short_size) & 0xFF); 1460 emit_byte((offs - short_size) & 0xFF);
1461 } else { 1461 } else {
1462 InstructionMark im(this); 1462 InstructionMark im(this);
1478 address entry = target(L); 1478 address entry = target(L);
1479 assert(entry != NULL, "jmp most probably wrong"); 1479 assert(entry != NULL, "jmp most probably wrong");
1480 InstructionMark im(this); 1480 InstructionMark im(this);
1481 const int short_size = 2; 1481 const int short_size = 2;
1482 const int long_size = 5; 1482 const int long_size = 5;
1483 intptr_t offs = entry - _code_pos; 1483 intptr_t offs = entry - pc();
1484 if (maybe_short && is8bit(offs - short_size)) { 1484 if (maybe_short && is8bit(offs - short_size)) {
1485 emit_byte(0xEB); 1485 emit_byte(0xEB);
1486 emit_byte((offs - short_size) & 0xFF); 1486 emit_byte((offs - short_size) & 0xFF);
1487 } else { 1487 } else {
1488 emit_byte(0xE9); 1488 emit_byte(0xE9);
1508 1508
1509 void Assembler::jmp_literal(address dest, RelocationHolder const& rspec) { 1509 void Assembler::jmp_literal(address dest, RelocationHolder const& rspec) {
1510 InstructionMark im(this); 1510 InstructionMark im(this);
1511 emit_byte(0xE9); 1511 emit_byte(0xE9);
1512 assert(dest != NULL, "must have a target"); 1512 assert(dest != NULL, "must have a target");
1513 intptr_t disp = dest - (_code_pos + sizeof(int32_t)); 1513 intptr_t disp = dest - (pc() + sizeof(int32_t));
1514 assert(is_simm32(disp), "must be 32bit offset (jmp)"); 1514 assert(is_simm32(disp), "must be 32bit offset (jmp)");
1515 emit_data(disp, rspec.reloc(), call32_operand); 1515 emit_data(disp, rspec.reloc(), call32_operand);
1516 } 1516 }
1517 1517
1518 void Assembler::jmpb(Label& L) { 1518 void Assembler::jmpb(Label& L) {
1519 if (L.is_bound()) { 1519 if (L.is_bound()) {
1520 const int short_size = 2; 1520 const int short_size = 2;
1521 address entry = target(L); 1521 address entry = target(L);
1522 assert(entry != NULL, "jmp most probably wrong"); 1522 assert(entry != NULL, "jmp most probably wrong");
1523 #ifdef ASSERT 1523 #ifdef ASSERT
1524 intptr_t dist = (intptr_t)entry - ((intptr_t)_code_pos + short_size); 1524 intptr_t dist = (intptr_t)entry - ((intptr_t)pc() + short_size);
1525 intptr_t delta = short_branch_delta(); 1525 intptr_t delta = short_branch_delta();
1526 if (delta != 0) { 1526 if (delta != 0) {
1527 dist += (dist < 0 ? (-delta) :delta); 1527 dist += (dist < 0 ? (-delta) :delta);
1528 } 1528 }
1529 assert(is8bit(dist), "Dispacement too large for a short jmp"); 1529 assert(is8bit(dist), "Dispacement too large for a short jmp");
1530 #endif 1530 #endif
1531 intptr_t offs = entry - _code_pos; 1531 intptr_t offs = entry - pc();
1532 emit_byte(0xEB); 1532 emit_byte(0xEB);
1533 emit_byte((offs - short_size) & 0xFF); 1533 emit_byte((offs - short_size) & 0xFF);
1534 } else { 1534 } else {
1535 InstructionMark im(this); 1535 InstructionMark im(this);
1536 L.add_patch_at(code(), locator()); 1536 L.add_patch_at(code(), locator());
4359 disp = (int64_t)adr._target - ((int64_t)CodeCache::low_bound() + sizeof(int)); 4359 disp = (int64_t)adr._target - ((int64_t)CodeCache::low_bound() + sizeof(int));
4360 if (!is_simm32(disp)) return false; 4360 if (!is_simm32(disp)) return false;
4361 disp = (int64_t)adr._target - ((int64_t)CodeCache::high_bound() + sizeof(int)); 4361 disp = (int64_t)adr._target - ((int64_t)CodeCache::high_bound() + sizeof(int));
4362 if (!is_simm32(disp)) return false; 4362 if (!is_simm32(disp)) return false;
4363 4363
4364 disp = (int64_t)adr._target - ((int64_t)_code_pos + sizeof(int)); 4364 disp = (int64_t)adr._target - ((int64_t)pc() + sizeof(int));
4365 4365
4366 // Because rip relative is a disp + address_of_next_instruction and we 4366 // Because rip relative is a disp + address_of_next_instruction and we
4367 // don't know the value of address_of_next_instruction we apply a fudge factor 4367 // don't know the value of address_of_next_instruction we apply a fudge factor
4368 // to make sure we will be ok no matter the size of the instruction we get placed into. 4368 // to make sure we will be ok no matter the size of the instruction we get placed into.
4369 // We don't have to fudge the checks above here because they are already worst case. 4369 // We don't have to fudge the checks above here because they are already worst case.
4390 4390
4391 void Assembler::emit_data64(jlong data, 4391 void Assembler::emit_data64(jlong data,
4392 relocInfo::relocType rtype, 4392 relocInfo::relocType rtype,
4393 int format) { 4393 int format) {
4394 if (rtype == relocInfo::none) { 4394 if (rtype == relocInfo::none) {
4395 emit_long64(data); 4395 emit_int64(data);
4396 } else { 4396 } else {
4397 emit_data64(data, Relocation::spec_simple(rtype), format); 4397 emit_data64(data, Relocation::spec_simple(rtype), format);
4398 } 4398 }
4399 } 4399 }
4400 4400
4408 // embedded words. Instead, relocate to the enclosing instruction. 4408 // embedded words. Instead, relocate to the enclosing instruction.
4409 code_section()->relocate(inst_mark(), rspec, format); 4409 code_section()->relocate(inst_mark(), rspec, format);
4410 #ifdef ASSERT 4410 #ifdef ASSERT
4411 check_relocation(rspec, format); 4411 check_relocation(rspec, format);
4412 #endif 4412 #endif
4413 emit_long64(data); 4413 emit_int64(data);
4414 } 4414 }
4415 4415
4416 int Assembler::prefix_and_encode(int reg_enc, bool byteinst) { 4416 int Assembler::prefix_and_encode(int reg_enc, bool byteinst) {
4417 if (reg_enc >= 8) { 4417 if (reg_enc >= 8) {
4418 prefix(REX_B); 4418 prefix(REX_B);
4941 4941
4942 void Assembler::mov64(Register dst, int64_t imm64) { 4942 void Assembler::mov64(Register dst, int64_t imm64) {
4943 InstructionMark im(this); 4943 InstructionMark im(this);
4944 int encode = prefixq_and_encode(dst->encoding()); 4944 int encode = prefixq_and_encode(dst->encoding());
4945 emit_byte(0xB8 | encode); 4945 emit_byte(0xB8 | encode);
4946 emit_long64(imm64); 4946 emit_int64(imm64);
4947 } 4947 }
4948 4948
4949 void Assembler::mov_literal64(Register dst, intptr_t imm64, RelocationHolder const& rspec) { 4949 void Assembler::mov_literal64(Register dst, intptr_t imm64, RelocationHolder const& rspec) {
4950 InstructionMark im(this); 4950 InstructionMark im(this);
4951 int encode = prefixq_and_encode(dst->encoding()); 4951 int encode = prefixq_and_encode(dst->encoding());
7889 if (reachable(dst)) { 7889 if (reachable(dst)) {
7890 InstructionMark im(this); 7890 InstructionMark im(this);
7891 relocate(dst.reloc()); 7891 relocate(dst.reloc());
7892 const int short_size = 2; 7892 const int short_size = 2;
7893 const int long_size = 6; 7893 const int long_size = 6;
7894 int offs = (intptr_t)dst.target() - ((intptr_t)_code_pos); 7894 int offs = (intptr_t)dst.target() - ((intptr_t)pc());
7895 if (dst.reloc() == relocInfo::none && is8bit(offs - short_size)) { 7895 if (dst.reloc() == relocInfo::none && is8bit(offs - short_size)) {
7896 // 0111 tttn #8-bit disp 7896 // 0111 tttn #8-bit disp
7897 emit_byte(0x70 | cc); 7897 emit_byte(0x70 | cc);
7898 emit_byte((offs - short_size) & 0xFF); 7898 emit_byte((offs - short_size) & 0xFF);
7899 } else { 7899 } else {