use of jdk.vm.ci.code.site.Call in project graal by oracle.
the class Stub method checkStubInvariants.
/**
* Checks the conditions a compilation must satisfy to be installed as a RuntimeStub.
*/
private boolean checkStubInvariants(CompilationResult compResult) {
assert compResult.getExceptionHandlers().isEmpty() : this;
// assumptions and there is no point in recording evol_method dependencies
assert compResult.getAssumptions() == null : "stubs should not use assumptions: " + this;
for (DataPatch data : compResult.getDataPatches()) {
if (data.reference instanceof ConstantReference) {
ConstantReference ref = (ConstantReference) data.reference;
if (ref.getConstant() instanceof HotSpotMetaspaceConstant) {
HotSpotMetaspaceConstant c = (HotSpotMetaspaceConstant) ref.getConstant();
if (c.asResolvedJavaType() != null && c.asResolvedJavaType().getName().equals("[I")) {
// embedding the type '[I' is safe, since it is never unloaded
continue;
}
}
}
assert !(data.reference instanceof ConstantReference) : this + " cannot have embedded object or metadata constant: " + data.reference;
}
for (Infopoint infopoint : compResult.getInfopoints()) {
assert infopoint instanceof Call : this + " cannot have non-call infopoint: " + infopoint;
Call call = (Call) infopoint;
assert call.target instanceof HotSpotForeignCallLinkage : this + " cannot have non runtime call: " + call.target;
HotSpotForeignCallLinkage callLinkage = (HotSpotForeignCallLinkage) call.target;
assert !callLinkage.isCompiledStub() || callLinkage.getDescriptor().equals(UNCOMMON_TRAP_HANDLER) : this + " cannot call compiled stub " + callLinkage;
}
return true;
}
use of jdk.vm.ci.code.site.Call in project graal by oracle.
the class InstalledCodeBuilder method patchCalls.
private int patchCalls(AMD64InstructionPatcher patcher) {
/*
* Patch the direct call instructions. TODO: This is highly x64 specific. Should be
* rewritten to generic backends.
*/
Map<Long, Integer> directTargets = new HashMap<>();
int currentPos = codeSize;
for (Infopoint infopoint : compilation.getInfopoints()) {
if (infopoint instanceof Call && ((Call) infopoint).direct) {
Call call = (Call) infopoint;
long targetAddress = getTargetCodeAddress(call);
long pcDisplacement = targetAddress - (code.rawValue() + call.pcOffset);
if (pcDisplacement != (int) pcDisplacement || testTrampolineJumps) {
/*
* In case a trampoline jump is need we just "call" the trampoline jump at the
* end of the code.
*/
Long destAddr = Long.valueOf(targetAddress);
Integer trampolineOffset = directTargets.get(destAddr);
if (trampolineOffset == null) {
trampolineOffset = currentPos;
directTargets.put(destAddr, trampolineOffset);
currentPos += TRAMPOLINE_JUMP_SIZE;
}
pcDisplacement = trampolineOffset - call.pcOffset;
}
assert pcDisplacement == (int) pcDisplacement;
// Patch a PC-relative call.
patcher.findPatchData(call.pcOffset, (int) pcDisplacement).apply(compiledBytes);
}
}
if (directTargets.size() > 0) {
/*
* Insert trampoline jumps. Note that this is only a fail-safe, because usually the code
* should be within a 32-bit address range.
*/
currentPos = ObjectLayout.roundUp(currentPos, 8);
ByteBuffer codeBuffer = ByteBuffer.wrap(compiledBytes).order(ConfigurationValues.getTarget().arch.getByteOrder());
for (Entry<Long, Integer> entry : directTargets.entrySet()) {
long targetAddress = entry.getKey();
int trampolineOffset = entry.getValue();
// Write the "jmp [rip+offset]" instruction
codeBuffer.put(trampolineOffset + 0, (byte) 0xff);
codeBuffer.put(trampolineOffset + 1, (byte) 0x25);
codeBuffer.putInt(trampolineOffset + 2, currentPos - (trampolineOffset + TRAMPOLINE_JUMP_SIZE));
// Write the target address
codeBuffer.putLong(currentPos, targetAddress);
currentPos += 8;
}
}
return currentPos;
}
use of jdk.vm.ci.code.site.Call in project graal by oracle.
the class InstanceOfTest method test10.
@Test
public void test10() {
Call callAt63 = new Call(null, 63, 5, true, null);
Mark markAt63 = new Mark(63, "1");
test("compareSites", callAt63, callAt63);
test("compareSites", callAt63, markAt63);
test("compareSites", markAt63, callAt63);
test("compareSites", markAt63, markAt63);
}
use of jdk.vm.ci.code.site.Call in project graal by oracle.
the class HotSpotMonitorValueTest method addMethod.
@Override
protected InstalledCode addMethod(DebugContext debug, ResolvedJavaMethod method, CompilationResult compResult) {
for (Infopoint i : compResult.getInfopoints()) {
if (i instanceof Call) {
Call call = (Call) i;
if (call.target instanceof ResolvedJavaMethod) {
ResolvedJavaMethod target = (ResolvedJavaMethod) call.target;
if (target.equals(lookupObjectWait())) {
BytecodeFrame frame = call.debugInfo.frame();
BytecodeFrame caller = frame.caller();
assertNotNull(caller);
assertNull(caller.caller());
assertDeepEquals(2, frame.numLocks);
assertDeepEquals(2, caller.numLocks);
StackLockValue lock1 = (StackLockValue) frame.getLockValue(0);
StackLockValue lock2 = (StackLockValue) frame.getLockValue(1);
StackLockValue lock3 = (StackLockValue) caller.getLockValue(0);
StackLockValue lock4 = (StackLockValue) caller.getLockValue(1);
List<StackLockValue> locks = Arrays.asList(lock1, lock2, lock3, lock4);
for (StackLockValue lock : locks) {
for (StackLockValue other : locks) {
if (other != lock) {
// Every lock must have a different stack slot
assertThat(lock.getSlot(), not(other.getSlot()));
}
}
}
assertDeepEquals(lock3.getOwner(), lock4.getOwner());
assertThat(lock1.getOwner(), not(lock2.getOwner()));
return super.addMethod(debug, method, compResult);
}
}
}
}
throw new AssertionError("Could not find debug info for call to Object.wait(long)");
}
use of jdk.vm.ci.code.site.Call in project graal by oracle.
the class CompilationResult method recordCall.
/**
* Records a call in the code array.
*
* @param codePos the position of the call in the code array
* @param size the size of the call instruction
* @param target the being called
* @param debugInfo the debug info for the call
* @param direct specifies if this is a {@linkplain Call#direct direct} call
*/
public void recordCall(int codePos, int size, InvokeTarget target, DebugInfo debugInfo, boolean direct) {
checkOpen();
final Call call = new Call(target, codePos, size, direct, debugInfo);
addInfopoint(call);
}
Aggregations