# HG changeset patch # User Roland Schatz # Date 1389969990 -3600 # Node ID f308146421225566b131383034c813788aa26eab # Parent a87e5c330cbd892fec3279e76c5619ad2313c916 Tightly pack data references that are smaller than 8 bytes. diff -r a87e5c330cbd -r f30814642122 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java Fri Jan 17 15:40:50 2014 +0100 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java Fri Jan 17 15:46:30 2014 +0100 @@ -142,15 +142,19 @@ */ public abstract static class Data { - public final int size; - public final int alignment; + private final int alignment; - public abstract void emit(ByteBuffer buffer); - - protected Data(int size, int alignment) { - this.size = size; + protected Data(int alignment) { this.alignment = alignment; } + + public int getAlignment() { + return alignment; + } + + public abstract int getSize(Architecture arch); + + public abstract void emit(Architecture arch, ByteBuffer buffer); } public static final class ConstantData extends Data { @@ -158,17 +162,56 @@ public final Constant constant; public ConstantData(Constant constant, int alignment) { - super(8, alignment); + super(alignment); this.constant = constant; } @Override - public void emit(ByteBuffer buffer) { - if (constant.getKind().isPrimitive()) { - buffer.putLong(constant.getPrimitive()); - } else { - // emit placeholder for oop value - buffer.putLong(0); + public int getSize(Architecture arch) { + return arch.getSizeInBytes(constant.getPlatformKind()); + } + + @Override + public void emit(Architecture arch, ByteBuffer buffer) { + switch (constant.getKind()) { + case Boolean: + assert getSize(arch) == 1; + buffer.put(constant.asBoolean() ? (byte) 1 : (byte) 0); + break; + case Byte: + assert getSize(arch) == 1; + buffer.put((byte) constant.asInt()); + break; + case Char: + assert getSize(arch) == 2; + buffer.putChar((char) constant.asInt()); + break; + case Short: + assert getSize(arch) == 2; + buffer.putShort((short) constant.asInt()); + break; + case Int: + assert getSize(arch) == 4; + buffer.putInt(constant.asInt()); + break; + case Long: + assert getSize(arch) == 8; + buffer.putLong(constant.asLong()); + break; + case Float: + assert getSize(arch) == 4; + buffer.putFloat(constant.asFloat()); + break; + case Double: + assert getSize(arch) == 8; + buffer.putDouble(constant.asDouble()); + break; + case Object: + // placeholder for oop value + for (int i = 0; i < getSize(arch); i++) { + buffer.put((byte) 0); + } + break; } } @@ -183,12 +226,17 @@ public final byte[] data; public RawData(byte[] data, int alignment) { - super(data.length, alignment); + super(alignment); this.data = data; } @Override - public void emit(ByteBuffer buffer) { + public int getSize(Architecture arch) { + return data.length; + } + + @Override + public void emit(Architecture arch, ByteBuffer buffer) { buffer.put(data); } diff -r a87e5c330cbd -r f30814642122 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotCryptoSubstitutionTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotCryptoSubstitutionTest.java Fri Jan 17 15:40:50 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotCryptoSubstitutionTest.java Fri Jan 17 15:46:30 2014 +0100 @@ -49,7 +49,7 @@ protected InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult) { HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) method; HotSpotNmethod installedCode = new HotSpotNmethod(hsMethod, compResult.getName(), true); - HotSpotCompiledNmethod compiledNmethod = new HotSpotCompiledNmethod(hsMethod, compResult); + HotSpotCompiledNmethod compiledNmethod = new HotSpotCompiledNmethod(runtime().getTarget().arch, hsMethod, compResult); CodeInstallResult result = runtime().getCompilerToVM().installCode(compiledNmethod, installedCode, null); Assert.assertEquals("Error installing method " + method + ": " + result, result, CodeInstallResult.OK); diff -r a87e5c330cbd -r f30814642122 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledCode.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledCode.java Fri Jan 17 15:40:50 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledCode.java Fri Jan 17 15:46:30 2014 +0100 @@ -71,12 +71,17 @@ public Constant constant; public HotSpotData(int offset) { - super(0, 0); + super(0); this.offset = offset; } @Override - public void emit(ByteBuffer buffer) { + public int getSize(Architecture arch) { + return 0; + } + + @Override + public void emit(Architecture arch, ByteBuffer buffer) { } } @@ -100,7 +105,7 @@ */ public final HotSpotData[] patches; - public DataSection(Site[] sites) { + public DataSection(Architecture arch, Site[] sites) { int size = 0; int patchCount = 0; List externalDataList = new ArrayList<>(); @@ -111,8 +116,8 @@ DataPatch dataPatch = (DataPatch) site; if (dataPatch.externalData != null) { Data d = dataPatch.externalData; - size = NumUtil.roundUp(size, d.alignment); - size += d.size; + size = NumUtil.roundUp(size, d.getAlignment()); + size += d.getSize(arch); externalDataList.add(dataPatch); if (dataPatch.getConstant() != null && dataPatch.getConstant().getKind() == Kind.Object) { patchCount++; @@ -132,8 +137,8 @@ for (DataPatch dataPatch : externalDataList) { Data d = dataPatch.externalData; - alignment = Math.max(alignment, d.alignment); - index = NumUtil.roundUp(index, d.alignment); + alignment = Math.max(alignment, d.getAlignment()); + index = NumUtil.roundUp(index, d.getAlignment()); buffer.position(index); HotSpotData hsData = new HotSpotData(index); @@ -144,8 +149,8 @@ } dataPatch.externalData = hsData; - index += d.size; - d.emit(buffer); + index += d.getSize(arch); + d.emit(arch, buffer); } this.sectionAlignment = alignment; @@ -163,10 +168,10 @@ } } - public HotSpotCompiledCode(CompilationResult compResult) { + public HotSpotCompiledCode(Architecture arch, CompilationResult compResult) { this.comp = compResult; sites = getSortedSites(compResult); - dataSection = new DataSection(sites); + dataSection = new DataSection(arch, sites); if (compResult.getExceptionHandlers().isEmpty()) { exceptionHandlers = null; } else { diff -r a87e5c330cbd -r f30814642122 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledNmethod.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledNmethod.java Fri Jan 17 15:40:50 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledNmethod.java Fri Jan 17 15:46:30 2014 +0100 @@ -35,8 +35,8 @@ public final int entryBCI; public final int id; - public HotSpotCompiledNmethod(HotSpotResolvedJavaMethod method, CompilationResult compResult) { - super(compResult); + public HotSpotCompiledNmethod(Architecture arch, HotSpotResolvedJavaMethod method, CompilationResult compResult) { + super(arch, compResult); this.method = method; this.entryBCI = compResult.getEntryBCI(); this.id = compResult.getId(); diff -r a87e5c330cbd -r f30814642122 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledRuntimeStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledRuntimeStub.java Fri Jan 17 15:40:50 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledRuntimeStub.java Fri Jan 17 15:46:30 2014 +0100 @@ -38,8 +38,8 @@ public final String stubName; - public HotSpotCompiledRuntimeStub(Stub stub, CompilationResult compResult) { - super(compResult); + public HotSpotCompiledRuntimeStub(Architecture arch, Stub stub, CompilationResult compResult) { + super(arch, compResult); assert checkStubInvariants(compResult); this.stubName = stub.toString(); } diff -r a87e5c330cbd -r f30814642122 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeCacheProvider.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeCacheProvider.java Fri Jan 17 15:40:50 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeCacheProvider.java Fri Jan 17 15:46:30 2014 +0100 @@ -169,7 +169,7 @@ public HotSpotInstalledCode installMethod(HotSpotResolvedJavaMethod method, CompilationResult compResult) { HotSpotInstalledCode installedCode = new HotSpotNmethod(method, compResult.getName(), true); - runtime.getCompilerToVM().installCode(new HotSpotCompiledNmethod(method, compResult), installedCode, method.getSpeculationLog()); + runtime.getCompilerToVM().installCode(new HotSpotCompiledNmethod(target.arch, method, compResult), installedCode, method.getSpeculationLog()); return logOrDump(installedCode, compResult); } @@ -177,7 +177,7 @@ public InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult, SpeculationLog log) { HotSpotResolvedJavaMethod hotspotMethod = (HotSpotResolvedJavaMethod) method; HotSpotInstalledCode code = new HotSpotNmethod(hotspotMethod, compResult.getName(), false); - CodeInstallResult result = runtime.getCompilerToVM().installCode(new HotSpotCompiledNmethod(hotspotMethod, compResult), code, log); + CodeInstallResult result = runtime.getCompilerToVM().installCode(new HotSpotCompiledNmethod(target.arch, hotspotMethod, compResult), code, log); if (result != CodeInstallResult.OK) { return null; } @@ -193,7 +193,7 @@ public InstalledCode addExternalMethod(ResolvedJavaMethod method, CompilationResult compResult) { HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) method; HotSpotInstalledCode icode = new HotSpotNmethod(javaMethod, compResult.getName(), false, true); - HotSpotCompiledNmethod compiled = new HotSpotCompiledNmethod(javaMethod, compResult); + HotSpotCompiledNmethod compiled = new HotSpotCompiledNmethod(target.arch, javaMethod, compResult); CompilerToVM vm = runtime.getCompilerToVM(); CodeInstallResult result = vm.installCode(compiled, icode, null); if (result != CodeInstallResult.OK) { diff -r a87e5c330cbd -r f30814642122 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/Stub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/Stub.java Fri Jan 17 15:40:50 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/Stub.java Fri Jan 17 15:46:30 2014 +0100 @@ -153,7 +153,7 @@ try (Scope s = Debug.scope("CodeInstall")) { Stub stub = Stub.this; HotSpotRuntimeStub installedCode = new HotSpotRuntimeStub(stub); - HotSpotCompiledCode hsCompResult = new HotSpotCompiledRuntimeStub(stub, compResult); + HotSpotCompiledCode hsCompResult = new HotSpotCompiledRuntimeStub(backend.getTarget().arch, stub, compResult); CodeInstallResult result = runtime().getCompilerToVM().installCode(hsCompResult, installedCode, null); if (result != CodeInstallResult.OK) {