mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-15 08:34:30 +02:00
8147599: [JVMCI] simplify code installation interface
Reviewed-by: twisti
This commit is contained in:
parent
f3dca540d8
commit
5456fcf370
35 changed files with 1229 additions and 2165 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -27,12 +27,12 @@ import java.lang.reflect.Method;
|
|||
import jdk.vm.ci.amd64.AMD64;
|
||||
import jdk.vm.ci.code.Architecture;
|
||||
import jdk.vm.ci.code.CodeCacheProvider;
|
||||
import jdk.vm.ci.code.CompilationResult;
|
||||
import jdk.vm.ci.code.InstalledCode;
|
||||
import jdk.vm.ci.code.TargetDescription;
|
||||
import jdk.vm.ci.hotspot.HotSpotCompiledCode;
|
||||
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
|
||||
import jdk.vm.ci.meta.ConstantReflectionProvider;
|
||||
import jdk.vm.ci.meta.MetaAccessProvider;
|
||||
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
||||
import jdk.vm.ci.runtime.JVMCI;
|
||||
import jdk.vm.ci.runtime.JVMCIBackend;
|
||||
import jdk.vm.ci.sparc.SPARC;
|
||||
|
@ -65,12 +65,12 @@ public class CodeInstallationTest {
|
|||
void compile(TestAssembler asm);
|
||||
}
|
||||
|
||||
private TestAssembler createAssembler(CompilationResult result) {
|
||||
private TestAssembler createAssembler() {
|
||||
Architecture arch = codeCache.getTarget().arch;
|
||||
if (arch instanceof AMD64) {
|
||||
return new AMD64TestAssembler(result, codeCache);
|
||||
return new AMD64TestAssembler(codeCache);
|
||||
} else if (arch instanceof SPARC) {
|
||||
return new SPARCTestAssembler(result, codeCache);
|
||||
return new SPARCTestAssembler(codeCache);
|
||||
} else {
|
||||
Assert.fail("unsupported architecture");
|
||||
return null;
|
||||
|
@ -87,17 +87,14 @@ public class CodeInstallationTest {
|
|||
}
|
||||
|
||||
protected void test(TestCompiler compiler, Method method, Object... args) {
|
||||
CompilationResult result = new CompilationResult(method.getName());
|
||||
TestAssembler asm = createAssembler(result);
|
||||
HotSpotResolvedJavaMethod resolvedMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaMethod(method);
|
||||
TestAssembler asm = createAssembler();
|
||||
|
||||
asm.emitPrologue();
|
||||
compiler.compile(asm);
|
||||
asm.finish();
|
||||
|
||||
result.close();
|
||||
|
||||
ResolvedJavaMethod resolvedMethod = metaAccess.lookupJavaMethod(method);
|
||||
InstalledCode installed = codeCache.addCode(resolvedMethod, result, null, null);
|
||||
HotSpotCompiledCode code = asm.finish(resolvedMethod);
|
||||
InstalledCode installed = codeCache.addCode(resolvedMethod, code, null, null);
|
||||
|
||||
try {
|
||||
Object expected = method.invoke(null, args);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -30,9 +30,8 @@
|
|||
|
||||
package compiler.jvmci.code;
|
||||
|
||||
import jdk.vm.ci.code.CompilationResult.DataSectionReference;
|
||||
import jdk.vm.ci.code.DataSection.Data;
|
||||
import jdk.vm.ci.code.Register;
|
||||
import jdk.vm.ci.code.site.DataSectionReference;
|
||||
import jdk.vm.ci.hotspot.HotSpotConstant;
|
||||
import jdk.vm.ci.hotspot.HotSpotVMConfig;
|
||||
import jdk.vm.ci.meta.ResolvedJavaType;
|
||||
|
@ -53,7 +52,6 @@ public class DataPatchTest extends CodeInstallationTest {
|
|||
test(compiler, getMethod("getConstClass"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testInlineObject() {
|
||||
test(asm -> {
|
||||
|
@ -81,8 +79,7 @@ public class DataPatchTest extends CodeInstallationTest {
|
|||
test(asm -> {
|
||||
ResolvedJavaType type = metaAccess.lookupJavaType(getConstClass());
|
||||
HotSpotConstant c = (HotSpotConstant) type.getJavaClass();
|
||||
Data data = codeCache.createDataItem(c);
|
||||
DataSectionReference ref = asm.result.getDataSection().insertData(data);
|
||||
DataSectionReference ref = asm.emitDataItem(c);
|
||||
Register ret = asm.emitLoadPointer(ref);
|
||||
asm.emitPointerRet(ret);
|
||||
});
|
||||
|
@ -95,8 +92,7 @@ public class DataPatchTest extends CodeInstallationTest {
|
|||
ResolvedJavaType type = metaAccess.lookupJavaType(getConstClass());
|
||||
HotSpotConstant c = (HotSpotConstant) type.getJavaClass();
|
||||
HotSpotConstant cCompressed = (HotSpotConstant) c.compress();
|
||||
Data data = codeCache.createDataItem(cCompressed);
|
||||
DataSectionReference ref = asm.result.getDataSection().insertData(data);
|
||||
DataSectionReference ref = asm.emitDataItem(cCompressed);
|
||||
Register compressed = asm.emitLoadNarrowPointer(ref);
|
||||
Register ret = asm.emitUncompressPointer(compressed, HotSpotVMConfig.config().narrowOopBase, HotSpotVMConfig.config().narrowOopShift);
|
||||
asm.emitPointerRet(ret);
|
||||
|
@ -131,8 +127,7 @@ public class DataPatchTest extends CodeInstallationTest {
|
|||
test(asm -> {
|
||||
ResolvedJavaType type = metaAccess.lookupJavaType(getConstClass());
|
||||
HotSpotConstant hub = (HotSpotConstant) type.getObjectHub();
|
||||
Data data = codeCache.createDataItem(hub);
|
||||
DataSectionReference ref = asm.result.getDataSection().insertData(data);
|
||||
DataSectionReference ref = asm.emitDataItem(hub);
|
||||
Register klass = asm.emitLoadPointer(ref);
|
||||
Register ret = asm.emitLoadPointer(klass, HotSpotVMConfig.config().classMirrorOffset);
|
||||
asm.emitPointerRet(ret);
|
||||
|
@ -146,8 +141,7 @@ public class DataPatchTest extends CodeInstallationTest {
|
|||
ResolvedJavaType type = metaAccess.lookupJavaType(getConstClass());
|
||||
HotSpotConstant hub = (HotSpotConstant) type.getObjectHub();
|
||||
HotSpotConstant narrowHub = (HotSpotConstant) hub.compress();
|
||||
Data data = codeCache.createDataItem(narrowHub);
|
||||
DataSectionReference ref = asm.result.getDataSection().insertData(data);
|
||||
DataSectionReference ref = asm.emitDataItem(narrowHub);
|
||||
Register narrowKlass = asm.emitLoadNarrowPointer(ref);
|
||||
Register klass = asm.emitUncompressPointer(narrowKlass, HotSpotVMConfig.config().narrowKlassBase, HotSpotVMConfig.config().narrowKlassShift);
|
||||
Register ret = asm.emitLoadPointer(klass, HotSpotVMConfig.config().classMirrorOffset);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -25,17 +25,30 @@ package compiler.jvmci.code;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import jdk.vm.ci.code.CodeCacheProvider;
|
||||
import jdk.vm.ci.code.CompilationResult;
|
||||
import jdk.vm.ci.code.CompilationResult.DataSectionReference;
|
||||
import jdk.vm.ci.code.DebugInfo;
|
||||
import jdk.vm.ci.code.Register;
|
||||
import jdk.vm.ci.code.StackSlot;
|
||||
import jdk.vm.ci.code.site.ConstantReference;
|
||||
import jdk.vm.ci.code.site.DataPatch;
|
||||
import jdk.vm.ci.code.site.DataSectionReference;
|
||||
import jdk.vm.ci.code.site.Infopoint;
|
||||
import jdk.vm.ci.code.site.InfopointReason;
|
||||
import jdk.vm.ci.code.site.Reference;
|
||||
import jdk.vm.ci.code.site.Site;
|
||||
import jdk.vm.ci.hotspot.HotSpotCompiledCode;
|
||||
import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment;
|
||||
import jdk.vm.ci.hotspot.HotSpotCompiledNmethod;
|
||||
import jdk.vm.ci.hotspot.HotSpotConstant;
|
||||
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
|
||||
import jdk.vm.ci.meta.Assumptions.Assumption;
|
||||
import jdk.vm.ci.meta.LIRKind;
|
||||
import jdk.vm.ci.meta.PlatformKind;
|
||||
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
||||
import jdk.vm.ci.meta.VMConstant;
|
||||
|
||||
/**
|
||||
* Simple assembler used by the code installation tests.
|
||||
|
@ -49,6 +62,7 @@ public abstract class TestAssembler {
|
|||
|
||||
/**
|
||||
* Emit code to grow the stack frame.
|
||||
*
|
||||
* @param size the size in bytes that the stack should grow
|
||||
*/
|
||||
public abstract void emitGrowStack(int size);
|
||||
|
@ -84,18 +98,20 @@ public abstract class TestAssembler {
|
|||
public abstract Register emitLoadFloat(float value);
|
||||
|
||||
/**
|
||||
* Emit code to load a constant oop or metaspace pointer to a register.
|
||||
* The pointer may be wide or narrow, depending on {@link HotSpotConstant#isCompressed() c.isCompressed()}.
|
||||
* Emit code to load a constant oop or metaspace pointer to a register. The pointer may be wide
|
||||
* or narrow, depending on {@link HotSpotConstant#isCompressed() c.isCompressed()}.
|
||||
*/
|
||||
public abstract Register emitLoadPointer(HotSpotConstant c);
|
||||
|
||||
/**
|
||||
* Emit code to load a wide pointer from the {@link DataSection} to a register.
|
||||
* Emit code to load a wide pointer from the {@link HotSpotCompiledCode#dataSection} to a
|
||||
* register.
|
||||
*/
|
||||
public abstract Register emitLoadPointer(DataSectionReference ref);
|
||||
|
||||
/**
|
||||
* Emit code to load a narrow pointer from the {@link DataSection} to a register.
|
||||
* Emit code to load a narrow pointer from the {@link HotSpotCompiledCode#dataSection} to a
|
||||
* register.
|
||||
*/
|
||||
public abstract Register emitLoadNarrowPointer(DataSectionReference ref);
|
||||
|
||||
|
@ -149,14 +165,13 @@ public abstract class TestAssembler {
|
|||
*/
|
||||
public abstract void emitTrap(DebugInfo info);
|
||||
|
||||
protected int position() {
|
||||
return data.position();
|
||||
}
|
||||
|
||||
public final CompilationResult result;
|
||||
public final LIRKind narrowOopKind;
|
||||
|
||||
private ByteBuffer data;
|
||||
protected final Buffer code;
|
||||
protected final Buffer data;
|
||||
private final ArrayList<Site> sites;
|
||||
private final ArrayList<DataPatch> dataPatches;
|
||||
|
||||
protected final CodeCacheProvider codeCache;
|
||||
|
||||
private final Register[] registers;
|
||||
|
@ -166,11 +181,14 @@ public abstract class TestAssembler {
|
|||
private int stackAlignment;
|
||||
private int curStackSlot;
|
||||
|
||||
protected TestAssembler(CompilationResult result, CodeCacheProvider codeCache, int initialFrameSize, int stackAlignment, PlatformKind narrowOopKind, Register... registers) {
|
||||
this.result = result;
|
||||
protected TestAssembler(CodeCacheProvider codeCache, int initialFrameSize, int stackAlignment, PlatformKind narrowOopKind, Register... registers) {
|
||||
this.narrowOopKind = LIRKind.reference(narrowOopKind);
|
||||
|
||||
this.data = ByteBuffer.allocate(32).order(ByteOrder.nativeOrder());
|
||||
this.code = new Buffer();
|
||||
this.data = new Buffer();
|
||||
this.sites = new ArrayList<>();
|
||||
this.dataPatches = new ArrayList<>();
|
||||
|
||||
this.codeCache = codeCache;
|
||||
|
||||
this.registers = registers;
|
||||
|
@ -198,38 +216,87 @@ public abstract class TestAssembler {
|
|||
return StackSlot.get(kind, -curStackSlot, true);
|
||||
}
|
||||
|
||||
public void finish() {
|
||||
result.setTotalFrameSize(frameSize);
|
||||
result.setTargetCode(data.array(), data.position());
|
||||
protected void recordImplicitException(DebugInfo info) {
|
||||
sites.add(new Infopoint(code.position(), info, InfopointReason.IMPLICIT_EXCEPTION));
|
||||
}
|
||||
|
||||
private void ensureSize(int length) {
|
||||
if (length >= data.limit()) {
|
||||
byte[] newBuf = Arrays.copyOf(data.array(), length * 4);
|
||||
ByteBuffer newData = ByteBuffer.wrap(newBuf);
|
||||
newData.order(data.order());
|
||||
newData.position(data.position());
|
||||
data = newData;
|
||||
protected void recordDataPatchInCode(Reference ref) {
|
||||
sites.add(new DataPatch(code.position(), ref));
|
||||
}
|
||||
|
||||
protected void recordDataPatchInData(Reference ref) {
|
||||
dataPatches.add(new DataPatch(data.position(), ref));
|
||||
}
|
||||
|
||||
public DataSectionReference emitDataItem(HotSpotConstant c) {
|
||||
DataSectionReference ref = new DataSectionReference();
|
||||
ref.setOffset(data.position());
|
||||
|
||||
recordDataPatchInData(new ConstantReference((VMConstant) c));
|
||||
if (c.isCompressed()) {
|
||||
data.emitInt(0xDEADDEAD);
|
||||
} else {
|
||||
data.emitLong(0xDEADDEADDEADDEADL);
|
||||
}
|
||||
|
||||
return ref;
|
||||
}
|
||||
|
||||
public HotSpotCompiledCode finish(HotSpotResolvedJavaMethod method) {
|
||||
int id = method.allocateCompileId(0);
|
||||
byte[] finishedCode = code.finish();
|
||||
Site[] finishedSites = sites.toArray(new Site[0]);
|
||||
byte[] finishedData = data.finish();
|
||||
DataPatch[] finishedDataPatches = dataPatches.toArray(new DataPatch[0]);
|
||||
return new HotSpotCompiledNmethod(method.getName(), finishedCode, finishedCode.length, finishedSites, new Assumption[0], new ResolvedJavaMethod[]{method}, new Comment[0], finishedData, 16,
|
||||
finishedDataPatches, false, frameSize, 0, method, 0, id, 0L, false);
|
||||
}
|
||||
|
||||
protected static class Buffer {
|
||||
|
||||
private ByteBuffer data = ByteBuffer.allocate(32).order(ByteOrder.nativeOrder());
|
||||
|
||||
private void ensureSize(int length) {
|
||||
if (length >= data.limit()) {
|
||||
byte[] newBuf = Arrays.copyOf(data.array(), length * 4);
|
||||
ByteBuffer newData = ByteBuffer.wrap(newBuf);
|
||||
newData.order(data.order());
|
||||
newData.position(data.position());
|
||||
data = newData;
|
||||
}
|
||||
}
|
||||
|
||||
public int position() {
|
||||
return data.position();
|
||||
}
|
||||
|
||||
public void emitByte(int b) {
|
||||
ensureSize(data.position() + 1);
|
||||
data.put((byte) (b & 0xFF));
|
||||
}
|
||||
|
||||
public void emitShort(int b) {
|
||||
ensureSize(data.position() + 2);
|
||||
data.putShort((short) b);
|
||||
}
|
||||
|
||||
public void emitInt(int b) {
|
||||
ensureSize(data.position() + 4);
|
||||
data.putInt(b);
|
||||
}
|
||||
|
||||
public void emitLong(long b) {
|
||||
ensureSize(data.position() + 8);
|
||||
data.putLong(b);
|
||||
}
|
||||
|
||||
public void emitFloat(float f) {
|
||||
ensureSize(data.position() + 4);
|
||||
data.putFloat(f);
|
||||
}
|
||||
|
||||
private byte[] finish() {
|
||||
return Arrays.copyOf(data.array(), data.position());
|
||||
}
|
||||
}
|
||||
|
||||
protected void emitByte(int b) {
|
||||
ensureSize(data.position() + 1);
|
||||
data.put((byte) (b & 0xFF));
|
||||
}
|
||||
|
||||
protected void emitShort(int b) {
|
||||
ensureSize(data.position() + 2);
|
||||
data.putShort((short) b);
|
||||
}
|
||||
|
||||
protected void emitInt(int b) {
|
||||
ensureSize(data.position() + 4);
|
||||
data.putInt(b);
|
||||
}
|
||||
|
||||
protected void emitLong(long b) {
|
||||
ensureSize(data.position() + 8);
|
||||
data.putLong(b);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -25,18 +25,14 @@ package compiler.jvmci.code.amd64;
|
|||
|
||||
import jdk.vm.ci.amd64.AMD64;
|
||||
import jdk.vm.ci.amd64.AMD64Kind;
|
||||
import jdk.vm.ci.code.CallingConvention.Type;
|
||||
import jdk.vm.ci.code.CodeCacheProvider;
|
||||
import jdk.vm.ci.code.CompilationResult;
|
||||
import jdk.vm.ci.code.CompilationResult.ConstantReference;
|
||||
import jdk.vm.ci.code.CompilationResult.DataSectionReference;
|
||||
import jdk.vm.ci.code.DataSection.Data;
|
||||
import jdk.vm.ci.code.DebugInfo;
|
||||
import jdk.vm.ci.code.InfopointReason;
|
||||
import jdk.vm.ci.code.Register;
|
||||
import jdk.vm.ci.code.StackSlot;
|
||||
import jdk.vm.ci.code.CallingConvention.Type;
|
||||
import jdk.vm.ci.code.site.ConstantReference;
|
||||
import jdk.vm.ci.code.site.DataSectionReference;
|
||||
import jdk.vm.ci.hotspot.HotSpotConstant;
|
||||
import jdk.vm.ci.meta.JavaConstant;
|
||||
import jdk.vm.ci.meta.JavaKind;
|
||||
import jdk.vm.ci.meta.LIRKind;
|
||||
import jdk.vm.ci.meta.VMConstant;
|
||||
|
@ -45,27 +41,31 @@ import compiler.jvmci.code.TestAssembler;
|
|||
|
||||
public class AMD64TestAssembler extends TestAssembler {
|
||||
|
||||
public AMD64TestAssembler(CompilationResult result, CodeCacheProvider codeCache) {
|
||||
super(result, codeCache, 16, 16, AMD64Kind.DWORD, AMD64.rax, AMD64.rcx, AMD64.rdi, AMD64.r8, AMD64.r9, AMD64.r10);
|
||||
public AMD64TestAssembler(CodeCacheProvider codeCache) {
|
||||
super(codeCache, 16, 16, AMD64Kind.DWORD, AMD64.rax, AMD64.rcx, AMD64.rdi, AMD64.r8, AMD64.r9, AMD64.r10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitPrologue() {
|
||||
emitByte(0x50 | AMD64.rbp.encoding); // PUSH rbp
|
||||
emitMove(true, AMD64.rbp, AMD64.rsp); // MOV rbp, rsp
|
||||
code.emitByte(0x50 | AMD64.rbp.encoding); // PUSH rbp
|
||||
emitMove(true, AMD64.rbp, AMD64.rsp); // MOV rbp, rsp
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitGrowStack(int size) {
|
||||
// SUB rsp, size
|
||||
emitByte(0x48);
|
||||
emitByte(0x81);
|
||||
emitByte(0xEC);
|
||||
emitInt(size);
|
||||
code.emitByte(0x48);
|
||||
code.emitByte(0x81);
|
||||
code.emitByte(0xEC);
|
||||
code.emitInt(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitIntArg0() {
|
||||
return codeCache.getRegisterConfig().getCallingConventionRegisters(Type.JavaCall, JavaKind.Int)[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitIntArg1() {
|
||||
return codeCache.getRegisterConfig().getCallingConventionRegisters(Type.JavaCall, JavaKind.Int)[1];
|
||||
}
|
||||
|
@ -73,60 +73,66 @@ public class AMD64TestAssembler extends TestAssembler {
|
|||
private void emitREX(boolean w, int r, int x, int b) {
|
||||
int wrxb = (w ? 0x08 : 0) | ((r >> 3) << 2) | ((x >> 3) << 1) | (b >> 3);
|
||||
if (wrxb != 0) {
|
||||
emitByte(0x40 | wrxb);
|
||||
code.emitByte(0x40 | wrxb);
|
||||
}
|
||||
}
|
||||
|
||||
private void emitModRMReg(boolean w, int opcode, int r, int m) {
|
||||
emitREX(w, r, 0, m);
|
||||
emitByte((byte) opcode);
|
||||
emitByte((byte) 0xC0 | ((r & 0x7) << 3) | (m & 0x7));
|
||||
code.emitByte((byte) opcode);
|
||||
code.emitByte((byte) 0xC0 | ((r & 0x7) << 3) | (m & 0x7));
|
||||
}
|
||||
|
||||
private void emitModRMMemory(boolean w, int opcode, int r, int b, int offset) {
|
||||
emitREX(w, r, 0, b);
|
||||
emitByte((byte) opcode);
|
||||
emitByte((byte) 0x80 | ((r & 0x7) << 3) | (b & 0x7));
|
||||
emitInt(offset);
|
||||
code.emitByte((byte) opcode);
|
||||
code.emitByte((byte) 0x80 | ((r & 0x7) << 3) | (b & 0x7));
|
||||
code.emitInt(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitLoadInt(int c) {
|
||||
Register ret = newRegister();
|
||||
emitREX(false, 0, 0, ret.encoding);
|
||||
emitByte(0xB8 | (ret.encoding & 0x7)); // MOV r32, imm32
|
||||
emitInt(c);
|
||||
code.emitByte(0xB8 | (ret.encoding & 0x7)); // MOV r32, imm32
|
||||
code.emitInt(c);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitLoadLong(long c) {
|
||||
Register ret = newRegister();
|
||||
emitREX(true, 0, 0, ret.encoding);
|
||||
emitByte(0xB8 | (ret.encoding & 0x7)); // MOV r64, imm64
|
||||
emitLong(c);
|
||||
code.emitByte(0xB8 | (ret.encoding & 0x7)); // MOV r64, imm64
|
||||
code.emitLong(c);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitLoadFloat(float c) {
|
||||
Data data = codeCache.createDataItem(JavaConstant.forFloat(c));
|
||||
DataSectionReference ref = result.getDataSection().insertData(data);
|
||||
result.recordDataPatch(position(), ref);
|
||||
DataSectionReference ref = new DataSectionReference();
|
||||
ref.setOffset(data.position());
|
||||
data.emitFloat(c);
|
||||
|
||||
recordDataPatchInCode(ref);
|
||||
Register ret = AMD64.xmm0;
|
||||
emitREX(false, ret.encoding, 0, 0);
|
||||
emitByte(0xF3);
|
||||
emitByte(0x0F);
|
||||
emitByte(0x10); // MOVSS xmm1, xmm2/m32
|
||||
emitByte(0x05 | ((ret.encoding & 0x7) << 3)); // xmm, [rip+offset]
|
||||
emitInt(0xDEADDEAD);
|
||||
code.emitByte(0xF3);
|
||||
code.emitByte(0x0F);
|
||||
code.emitByte(0x10); // MOVSS xmm1, xmm2/m32
|
||||
code.emitByte(0x05 | ((ret.encoding & 0x7) << 3)); // xmm, [rip+offset]
|
||||
code.emitInt(0xDEADDEAD);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitLoadPointer(HotSpotConstant c) {
|
||||
result.recordDataPatch(position(), new ConstantReference((VMConstant) c));
|
||||
recordDataPatchInCode(new ConstantReference((VMConstant) c));
|
||||
if (c.isCompressed()) {
|
||||
Register ret = newRegister();
|
||||
emitREX(false, 0, 0, ret.encoding);
|
||||
emitByte(0xB8 | (ret.encoding & 0x7)); // MOV r32, imm32
|
||||
emitInt(0xDEADDEAD);
|
||||
code.emitByte(0xB8 | (ret.encoding & 0x7)); // MOV r32, imm32
|
||||
code.emitInt(0xDEADDEAD);
|
||||
return ret;
|
||||
} else {
|
||||
return emitLoadLong(0xDEADDEADDEADDEADl);
|
||||
|
@ -134,68 +140,77 @@ public class AMD64TestAssembler extends TestAssembler {
|
|||
}
|
||||
|
||||
private Register emitLoadPointer(DataSectionReference ref, boolean narrow) {
|
||||
result.recordDataPatch(position(), ref);
|
||||
recordDataPatchInCode(ref);
|
||||
Register ret = newRegister();
|
||||
emitREX(!narrow, ret.encoding, 0, 0);
|
||||
emitByte(0x8B); // MOV r64,r/m64
|
||||
emitByte(0x05 | ((ret.encoding & 0x7) << 3)); // r64, [rip+offset]
|
||||
emitInt(0xDEADDEAD);
|
||||
code.emitByte(0x8B); // MOV r64,r/m64
|
||||
code.emitByte(0x05 | ((ret.encoding & 0x7) << 3)); // r64, [rip+offset]
|
||||
code.emitInt(0xDEADDEAD);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitLoadPointer(DataSectionReference ref) {
|
||||
return emitLoadPointer(ref, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitLoadNarrowPointer(DataSectionReference ref) {
|
||||
return emitLoadPointer(ref, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitLoadPointer(Register b, int offset) {
|
||||
Register ret = newRegister();
|
||||
emitModRMMemory(true, 0x8B, ret.encoding, b.encoding, offset); // MOV r64,r/m64
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackSlot emitIntToStack(Register a) {
|
||||
StackSlot ret = newStackSlot(LIRKind.value(AMD64Kind.DWORD));
|
||||
emitModRMMemory(false, 0x89, a.encoding, AMD64.rbp.encoding, ret.getRawOffset() + 16); // MOV r/m32,r32
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackSlot emitLongToStack(Register a) {
|
||||
StackSlot ret = newStackSlot(LIRKind.value(AMD64Kind.QWORD));
|
||||
emitModRMMemory(true, 0x89, a.encoding, AMD64.rbp.encoding, ret.getRawOffset() + 16); // MOV r/m64,r64
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackSlot emitFloatToStack(Register a) {
|
||||
StackSlot ret = newStackSlot(LIRKind.value(AMD64Kind.SINGLE));
|
||||
emitREX(false, a.encoding, 0, 0);
|
||||
emitByte(0xF3);
|
||||
emitByte(0x0F);
|
||||
emitByte(0x11); // MOVSS xmm2/m32, xmm1
|
||||
emitByte(0x85 | ((a.encoding & 0x7) << 3)); // [rbp+offset]
|
||||
emitInt(ret.getRawOffset() + 16);
|
||||
code.emitByte(0xF3);
|
||||
code.emitByte(0x0F);
|
||||
code.emitByte(0x11); // MOVSS xmm2/m32, xmm1
|
||||
code.emitByte(0x85 | ((a.encoding & 0x7) << 3)); // [rbp+offset]
|
||||
code.emitInt(ret.getRawOffset() + 16);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackSlot emitPointerToStack(Register a) {
|
||||
StackSlot ret = newStackSlot(LIRKind.reference(AMD64Kind.QWORD));
|
||||
emitModRMMemory(true, 0x89, a.encoding, AMD64.rbp.encoding, ret.getRawOffset() + 16); // MOV r/m64,r64
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackSlot emitNarrowPointerToStack(Register a) {
|
||||
StackSlot ret = newStackSlot(LIRKind.reference(AMD64Kind.DWORD));
|
||||
emitModRMMemory(false, 0x89, a.encoding, AMD64.rbp.encoding, ret.getRawOffset() + 16); // MOV r/m32,r32
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitUncompressPointer(Register compressed, long base, int shift) {
|
||||
if (shift > 0) {
|
||||
emitModRMReg(true, 0xC1, 4, compressed.encoding);
|
||||
emitByte(shift);
|
||||
code.emitByte(shift);
|
||||
}
|
||||
if (base == 0) {
|
||||
return compressed;
|
||||
|
@ -206,6 +221,7 @@ public class AMD64TestAssembler extends TestAssembler {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitIntAdd(Register a, Register b) {
|
||||
emitModRMReg(false, 0x03, a.encoding, b.encoding);
|
||||
return a;
|
||||
|
@ -217,26 +233,29 @@ public class AMD64TestAssembler extends TestAssembler {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitIntRet(Register a) {
|
||||
emitMove(false, AMD64.rax, a); // MOV eax, ...
|
||||
emitMove(true, AMD64.rsp, AMD64.rbp); // MOV rsp, rbp
|
||||
emitByte(0x58 | AMD64.rbp.encoding); // POP rbp
|
||||
emitByte(0xC3); // RET
|
||||
emitMove(false, AMD64.rax, a); // MOV eax, ...
|
||||
emitMove(true, AMD64.rsp, AMD64.rbp); // MOV rsp, rbp
|
||||
code.emitByte(0x58 | AMD64.rbp.encoding); // POP rbp
|
||||
code.emitByte(0xC3); // RET
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitPointerRet(Register a) {
|
||||
emitMove(true, AMD64.rax, a); // MOV rax, ...
|
||||
emitMove(true, AMD64.rsp, AMD64.rbp); // MOV rsp, rbp
|
||||
emitByte(0x58 | AMD64.rbp.encoding); // POP rbp
|
||||
emitByte(0xC3); // RET
|
||||
emitMove(true, AMD64.rax, a); // MOV rax, ...
|
||||
emitMove(true, AMD64.rsp, AMD64.rbp); // MOV rsp, rbp
|
||||
code.emitByte(0x58 | AMD64.rbp.encoding); // POP rbp
|
||||
code.emitByte(0xC3); // RET
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitTrap(DebugInfo info) {
|
||||
result.recordInfopoint(position(), info, InfopointReason.IMPLICIT_EXCEPTION);
|
||||
recordImplicitException(info);
|
||||
// MOV rax, [0]
|
||||
emitByte(0x8B);
|
||||
emitByte(0x04);
|
||||
emitByte(0x25);
|
||||
emitInt(0);
|
||||
code.emitByte(0x8B);
|
||||
code.emitByte(0x04);
|
||||
code.emitByte(0x25);
|
||||
code.emitInt(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -23,18 +23,16 @@
|
|||
|
||||
package compiler.jvmci.code.sparc;
|
||||
|
||||
import jdk.vm.ci.code.CallingConvention.Type;
|
||||
import jdk.vm.ci.code.CodeCacheProvider;
|
||||
import jdk.vm.ci.code.CompilationResult;
|
||||
import jdk.vm.ci.code.CompilationResult.ConstantReference;
|
||||
import jdk.vm.ci.code.CompilationResult.DataSectionReference;
|
||||
import jdk.vm.ci.code.DataSection.Data;
|
||||
import jdk.vm.ci.code.DebugInfo;
|
||||
import jdk.vm.ci.code.InfopointReason;
|
||||
import jdk.vm.ci.code.Register;
|
||||
import jdk.vm.ci.code.StackSlot;
|
||||
import jdk.vm.ci.code.CallingConvention.Type;
|
||||
import jdk.vm.ci.code.site.ConstantReference;
|
||||
import jdk.vm.ci.code.site.DataSectionReference;
|
||||
import jdk.vm.ci.hotspot.HotSpotCompiledCode;
|
||||
import jdk.vm.ci.hotspot.HotSpotConstant;
|
||||
import jdk.vm.ci.meta.JavaConstant;
|
||||
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
|
||||
import jdk.vm.ci.meta.JavaKind;
|
||||
import jdk.vm.ci.meta.LIRKind;
|
||||
import jdk.vm.ci.meta.VMConstant;
|
||||
|
@ -47,48 +45,53 @@ public class SPARCTestAssembler extends TestAssembler {
|
|||
|
||||
private static final int MASK13 = (1 << 13) - 1;
|
||||
|
||||
public SPARCTestAssembler(CompilationResult result, CodeCacheProvider codeCache) {
|
||||
super(result, codeCache, 0, 16, SPARCKind.WORD, SPARC.l0, SPARC.l1, SPARC.l2, SPARC.l3, SPARC.l4, SPARC.l5, SPARC.l6, SPARC.l7);
|
||||
public SPARCTestAssembler(CodeCacheProvider codeCache) {
|
||||
super(codeCache, 0, 16, SPARCKind.WORD, SPARC.l0, SPARC.l1, SPARC.l2, SPARC.l3, SPARC.l4, SPARC.l5, SPARC.l6, SPARC.l7);
|
||||
}
|
||||
|
||||
private void emitOp2(Register rd, int op2, int imm22) {
|
||||
emitInt((0b00 << 30) | (rd.encoding << 25) | (op2 << 22) | imm22);
|
||||
code.emitInt((0b00 << 30) | (rd.encoding << 25) | (op2 << 22) | imm22);
|
||||
}
|
||||
|
||||
private void emitOp3(int op, Register rd, int op3, Register rs1, Register rs2) {
|
||||
emitInt((op << 30) | (rd.encoding << 25) | (op3 << 19) | (rs1.encoding << 14) | rs2.encoding);
|
||||
code.emitInt((op << 30) | (rd.encoding << 25) | (op3 << 19) | (rs1.encoding << 14) | rs2.encoding);
|
||||
}
|
||||
|
||||
private void emitOp3(int op, Register rd, int op3, Register rs1, int simm13) {
|
||||
emitInt((op << 30) | (rd.encoding << 25) | (op3 << 19) | (rs1.encoding << 14) | (1 << 13) | (simm13 & MASK13));
|
||||
code.emitInt((op << 30) | (rd.encoding << 25) | (op3 << 19) | (rs1.encoding << 14) | (1 << 13) | (simm13 & MASK13));
|
||||
}
|
||||
|
||||
private void emitNop() {
|
||||
emitInt(1 << 24);
|
||||
code.emitInt(1 << 24);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitPrologue() {
|
||||
emitOp3(0b10, SPARC.sp, 0b111100, SPARC.sp, -SPARC.REGISTER_SAFE_AREA_SIZE); // SAVE sp, -128, sp
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
public HotSpotCompiledCode finish(HotSpotResolvedJavaMethod method) {
|
||||
frameSize += SPARC.REGISTER_SAFE_AREA_SIZE;
|
||||
super.finish();
|
||||
return super.finish(method);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitGrowStack(int size) {
|
||||
emitOp3(0b10, SPARC.sp, 0b000100, SPARC.sp, size); // SUB sp, size, sp
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitIntArg0() {
|
||||
return codeCache.getRegisterConfig().getCallingConventionRegisters(Type.JavaCallee, JavaKind.Int)[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitIntArg1() {
|
||||
return codeCache.getRegisterConfig().getCallingConventionRegisters(Type.JavaCallee, JavaKind.Int)[1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitLoadInt(int c) {
|
||||
Register ret = newRegister();
|
||||
int hi = c >>> 10;
|
||||
|
@ -104,41 +107,46 @@ public class SPARCTestAssembler extends TestAssembler {
|
|||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitLoadLong(long c) {
|
||||
if ((c & 0xFFFFFFFF) == c) {
|
||||
return emitLoadInt((int) c);
|
||||
} else {
|
||||
Data data = codeCache.createDataItem(JavaConstant.forLong(c));
|
||||
DataSectionReference ref = result.getDataSection().insertData(data);
|
||||
DataSectionReference ref = new DataSectionReference();
|
||||
ref.setOffset(data.position());
|
||||
data.emitLong(c);
|
||||
return emitLoadPointer(ref);
|
||||
}
|
||||
}
|
||||
|
||||
private void emitPatchableSethi(Register ret, boolean wide) {
|
||||
int startPos = position();
|
||||
int startPos = code.position();
|
||||
emitOp2(ret, 0b100, 0); // SETHI 0, ret
|
||||
if (wide) {
|
||||
// pad for later patching
|
||||
while (position() < (startPos + 28)) {
|
||||
while (code.position() < (startPos + 28)) {
|
||||
emitNop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitLoadFloat(float c) {
|
||||
Data data = codeCache.createDataItem(JavaConstant.forFloat(c));
|
||||
DataSectionReference ref = result.getDataSection().insertData(data);
|
||||
DataSectionReference ref = new DataSectionReference();
|
||||
ref.setOffset(data.position());
|
||||
data.emitFloat(c);
|
||||
|
||||
Register ptr = newRegister();
|
||||
result.recordDataPatch(position(), ref);
|
||||
recordDataPatchInCode(ref);
|
||||
emitPatchableSethi(ptr, true);
|
||||
emitOp3(0b11, SPARC.f0, 0b100000, ptr, 0); // LDF [ptr+0], f0
|
||||
return SPARC.f0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitLoadPointer(HotSpotConstant c) {
|
||||
Register ret = newRegister();
|
||||
result.recordDataPatch(position(), new ConstantReference((VMConstant) c));
|
||||
recordDataPatchInCode(new ConstantReference((VMConstant) c));
|
||||
|
||||
emitPatchableSethi(ret, !c.isCompressed());
|
||||
emitOp3(0b10, ret, 0b000010, ret, 0); // OR ret, 0, ret
|
||||
|
@ -146,58 +154,67 @@ public class SPARCTestAssembler extends TestAssembler {
|
|||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitLoadPointer(DataSectionReference ref) {
|
||||
Register ret = newRegister();
|
||||
result.recordDataPatch(position(), ref);
|
||||
recordDataPatchInCode(ref);
|
||||
emitPatchableSethi(ret, true);
|
||||
emitOp3(0b11, ret, 0b001011, ret, 0); // LDX [ret+0], ret
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitLoadNarrowPointer(DataSectionReference ref) {
|
||||
Register ret = newRegister();
|
||||
result.recordDataPatch(position(), ref);
|
||||
recordDataPatchInCode(ref);
|
||||
emitPatchableSethi(ret, true);
|
||||
emitOp3(0b11, ret, 0b000000, ret, 0); // LDUW [ret+0], ret
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitLoadPointer(Register b, int offset) {
|
||||
Register ret = newRegister();
|
||||
emitOp3(0b11, ret, 0b001011, b, offset); // LDX [b+offset], ret
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackSlot emitIntToStack(Register a) {
|
||||
StackSlot ret = newStackSlot(LIRKind.value(SPARCKind.WORD));
|
||||
emitOp3(0b11, a, 0b000100, SPARC.fp, ret.getRawOffset() + SPARC.STACK_BIAS); // STW a, [fp+offset]
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackSlot emitLongToStack(Register a) {
|
||||
StackSlot ret = newStackSlot(LIRKind.value(SPARCKind.XWORD));
|
||||
emitOp3(0b11, a, 0b001110, SPARC.fp, ret.getRawOffset() + SPARC.STACK_BIAS); // STX a, [fp+offset]
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackSlot emitFloatToStack(Register a) {
|
||||
StackSlot ret = newStackSlot(LIRKind.value(SPARCKind.SINGLE));
|
||||
emitOp3(0b11, a, 0b100100, SPARC.fp, ret.getRawOffset() + SPARC.STACK_BIAS); // STF a, [fp+offset]
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackSlot emitPointerToStack(Register a) {
|
||||
StackSlot ret = newStackSlot(LIRKind.reference(SPARCKind.XWORD));
|
||||
emitOp3(0b11, a, 0b001110, SPARC.fp, ret.getRawOffset() + SPARC.STACK_BIAS); // STX a, [fp+offset]
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackSlot emitNarrowPointerToStack(Register a) {
|
||||
StackSlot ret = newStackSlot(LIRKind.reference(SPARCKind.WORD));
|
||||
emitOp3(0b11, a, 0b000100, SPARC.fp, ret.getRawOffset() + SPARC.STACK_BIAS); // STW a, [fp+offset]
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitUncompressPointer(Register compressed, long base, int shift) {
|
||||
Register ret;
|
||||
if (shift > 0) {
|
||||
|
@ -215,6 +232,7 @@ public class SPARCTestAssembler extends TestAssembler {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Register emitIntAdd(Register a, Register b) {
|
||||
Register ret = newRegister();
|
||||
emitOp3(0b10, ret, 0b00000, a, b); // ADD a, b, ret
|
||||
|
@ -227,18 +245,21 @@ public class SPARCTestAssembler extends TestAssembler {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitIntRet(Register a) {
|
||||
emitPointerRet(a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitPointerRet(Register a) {
|
||||
emitMove(SPARC.i0, a);
|
||||
emitOp3(0b10, SPARC.g0, 0b111000, SPARC.i7, 8); // JMPL [i7+8], g0
|
||||
emitOp3(0b10, SPARC.g0, 0b111101, SPARC.g0, SPARC.g0); // RESTORE g0, g0, g0
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitTrap(DebugInfo info) {
|
||||
result.recordInfopoint(position(), info, InfopointReason.IMPLICIT_EXCEPTION);
|
||||
recordImplicitException(info);
|
||||
emitOp3(0b11, SPARC.g0, 0b001011, SPARC.g0, 0); // LDX [g0+0], g0
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue