# HG changeset patch # User Christian Wimmer # Date 1363660765 25200 # Node ID a69eb5f539d903efac7b1d1f69f3a6fab890cb4a # Parent 5fbb2df2b47fddc158ecbc0e6f8f53464482d30b# Parent 65ba93f118d41bcece3cb9c23d00d9d813f2764a Merge diff -r 5fbb2df2b47f -r a69eb5f539d9 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeCacheProvider.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeCacheProvider.java Mon Mar 18 19:38:46 2013 -0700 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeCacheProvider.java Mon Mar 18 19:39:25 2013 -0700 @@ -37,12 +37,10 @@ * * @param method a method to which the executable code is begin added * @param compResult the compilation result to be added - * @param info the object into which details of the installed code will be written. Ignored if - * null, otherwise the info is written to index 0 of this array. * @return a reference to the compiled and ready-to-run code or null if the code installation * failed */ - InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult, CodeInfo[] info); + InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult); /** * Returns the size in bytes for locking information on the stack. @@ -50,13 +48,16 @@ int getSizeOfLockData(); /** - * Returns a disassembly of the given installed code. + * Returns a disassembly of some compiled code. * - * @param code the code that should be disassembled + * @param compResult some compiled code + * @param installedCode the result of installing the code in {@code compResult} or null if the + * code has not yet been installed + * * @return a disassembly. This will be of length 0 if the runtime does not support * disassembling. */ - String disassemble(CodeInfo code, CompilationResult tm); + String disassemble(CompilationResult compResult, InstalledCode installedCode); /** * Gets the register configuration to use when compiling a given method. diff -r 5fbb2df2b47f -r a69eb5f539d9 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeInfo.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeInfo.java Mon Mar 18 19:38:46 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2012, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.api.code; - -import com.oracle.graal.api.meta.*; - -/** - * Represents some code installed in the code cache of the runtime. This encapsulated details are - * only for informational purposes. At any time, the runtime may invalidate the underlying code - * (e.g. due to deopt etc). - */ -public interface CodeInfo { - - /** - * Returns the start address of this installed code. - */ - long getStart(); - - /** - * Returns a copy of this installed code. - */ - byte[] getCode(); - - /** - * Returns the method (if any) from which this installed code was compiled. - */ - ResolvedJavaMethod getMethod(); -} diff -r 5fbb2df2b47f -r a69eb5f539d9 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/InstalledCode.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/InstalledCode.java Mon Mar 18 19:38:46 2013 -0700 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/InstalledCode.java Mon Mar 18 19:39:25 2013 -0700 @@ -39,11 +39,22 @@ } /** - * Returns the method to which the compiled code belongs. + * Returns the method (if any) to which the installed code belongs. */ ResolvedJavaMethod getMethod(); /** + * Returns the start address of this installed code if it is {@linkplain #isValid() valid}, 0 + * otherwise. + */ + long getStart(); + + /** + * Returns a copy of this installed code if it is {@linkplain #isValid() valid}, null otherwise. + */ + byte[] getCode(); + + /** * @return true if the code represented by this object is still valid, false otherwise (may * happen due to deopt, etc.) */ diff -r 5fbb2df2b47f -r a69eb5f539d9 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/package-info.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/package-info.java Mon Mar 18 19:38:46 2013 -0700 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/package-info.java Mon Mar 18 19:39:25 2013 -0700 @@ -23,7 +23,7 @@ /** * Package that defines the interface between a Java application that wants to install code and the runtime. * The runtime provides in implementation of the {@link com.oracle.graal.api.code.CodeCacheProvider} interface. - * The method {@link com.oracle.graal.api.code.CodeCacheProvider#addMethod(com.oracle.graal.api.meta.ResolvedJavaMethod, CompilationResult, CodeInfo[])} + * The method {@link com.oracle.graal.api.code.CodeCacheProvider#addMethod(com.oracle.graal.api.meta.ResolvedJavaMethod, CompilationResult)} * can be used to install code for a given method. */ package com.oracle.graal.api.code; diff -r 5fbb2df2b47f -r a69eb5f539d9 graal/com.oracle.graal.asm.test/src/com/oracle/graal/asm/test/AssemblerTest.java --- a/graal/com.oracle.graal.asm.test/src/com/oracle/graal/asm/test/AssemblerTest.java Mon Mar 18 19:38:46 2013 -0700 +++ b/graal/com.oracle.graal.asm.test/src/com/oracle/graal/asm/test/AssemblerTest.java Mon Mar 18 19:39:25 2013 -0700 @@ -54,7 +54,7 @@ Buffer codeBuffer = test.generateCode(compResult, codeCache.getTarget(), registerConfig, cc); compResult.setTargetCode(codeBuffer.close(true), codeBuffer.position()); - InstalledCode code = codeCache.addMethod(method, compResult, null); + InstalledCode code = codeCache.addMethod(method, compResult); DisassemblerProvider dis = Graal.getRuntime().getCapability(DisassemblerProvider.class); if (dis != null) { diff -r 5fbb2df2b47f -r a69eb5f539d9 graal/com.oracle.graal.compiler.amd64.test/src/com/oracle/graal/compiler/amd64/test/AMD64FrameOmissionTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.amd64.test/src/com/oracle/graal/compiler/amd64/test/AMD64FrameOmissionTest.java Mon Mar 18 19:39:25 2013 -0700 @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2013, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.compiler.amd64.test; + +import static com.oracle.graal.amd64.AMD64.*; + +import java.lang.reflect.*; + +import org.junit.*; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.api.meta.*; +import com.oracle.graal.api.runtime.*; +import com.oracle.graal.asm.amd64.*; +import com.oracle.graal.compiler.test.*; +import com.oracle.graal.phases.*; + +/** + * Ensures that frame omission works in cases where it is expected to. + */ +public class AMD64FrameOmissionTest extends GraalCompilerTest { + + interface CodeGenerator { + + void generateCode(AMD64Assembler asm); + } + + public static void test1snippet() { + return; + } + + @Test + public void test1() { + testHelper("test1snippet", new CodeGenerator() { + + @Override + public void generateCode(AMD64Assembler asm) { + asm.ret(0); + } + }); + } + + public static int test2snippet(int x) { + return x + 5; + } + + @Test + public void test2() { + testHelper("test2snippet", new CodeGenerator() { + + @Override + public void generateCode(AMD64Assembler asm) { + asm.addl(rsi, 5); + asm.movl(rax, rsi); + asm.ret(0); + } + }); + } + + public static double test3snippet(double x) { + return 42.0D / x; + } + + @Test + public void test3() { + testHelper("test3snippet", new CodeGenerator() { + + @Override + public void generateCode(AMD64Assembler asm) { + asm.movsd(xmm1, new AMD64Address(rip, -40)); + asm.divsd(xmm1, xmm0); + asm.movapd(xmm0, xmm1); + asm.ret(0); + } + }); + } + + private static boolean DEBUG = false; + + private void testHelper(String name, CodeGenerator gen) { + Method method = getMethod(name); + ResolvedJavaMethod javaMethod = runtime.lookupJavaMethod(method); + InstalledCode installedCode = getCode(javaMethod, parse(method)); + + CodeCacheProvider codeCache = Graal.getRequiredCapability(CodeCacheProvider.class); + TargetDescription target = codeCache.getTarget(); + RegisterConfig registerConfig = codeCache.lookupRegisterConfig(); + AMD64Assembler asm = new AMD64Assembler(target, registerConfig); + + gen.generateCode(asm); + for (int i = 0; i < GraalOptions.MethodEndBreakpointGuards; ++i) { + asm.int3(); + } + while ((asm.codeBuffer.position() % 8) != 0) { + asm.hlt(); + } + + byte[] expectedCode = asm.codeBuffer.close(true); + byte[] actualCode = installedCode.getCode(); + + if (DEBUG) { + System.out.println(Graal.getRequiredCapability(DisassemblerProvider.class).disassemble(installedCode)); + } + + Assert.assertArrayEquals(expectedCode, actualCode); + } +} diff -r 5fbb2df2b47f -r a69eb5f539d9 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Mon Mar 18 19:38:46 2013 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Mon Mar 18 19:39:25 2013 -0700 @@ -413,12 +413,12 @@ @Override public InstalledCode call() throws Exception { - final CodeInfo[] info = Debug.isDumpEnabled() ? new CodeInfo[1] : null; - InstalledCode installedMethod = runtime.addMethod(method, compResult, info); - if (info != null) { - Debug.dump(new Object[]{compResult, info[0]}, "After code installation"); + InstalledCode installedCode = runtime.addMethod(method, compResult); + if (Debug.isDumpEnabled()) { + Debug.dump(new Object[]{compResult, installedCode}, "After code installation"); } - return installedMethod; + + return installedCode; } }); } diff -r 5fbb2df2b47f -r a69eb5f539d9 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Mon Mar 18 19:38:46 2013 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Mon Mar 18 19:39:25 2013 -0700 @@ -177,15 +177,14 @@ stats.finish(method); } - private void installMethod(final CompilationResult tm) { + private void installMethod(final CompilationResult compResult) { Debug.scope("CodeInstall", new Object[]{new DebugDumpScope(String.valueOf(id), true), graalRuntime.getRuntime(), method}, new Runnable() { @Override public void run() { - final CodeInfo[] info = Debug.isDumpEnabled() ? new CodeInfo[1] : null; - graalRuntime.getRuntime().installMethod(method, entryBCI, tm, info); - if (info != null) { - Debug.dump(new Object[]{tm, info[0]}, "After code installation"); + HotSpotInstalledCode installedCode = graalRuntime.getRuntime().installMethod(method, entryBCI, compResult); + if (Debug.isDumpEnabled()) { + Debug.dump(new Object[]{compResult, installedCode}, "After code installation"); } } diff -r 5fbb2df2b47f -r a69eb5f539d9 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Mon Mar 18 19:38:46 2013 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Mon Mar 18 19:39:25 2013 -0700 @@ -149,11 +149,9 @@ * @param compResult the result of a compilation * @param code if not null, then the code is installed as the non-default compiled code for the * associated method and the details of the installation are written to this object - * @param info additional information about the installation are written to this object if it is - * not null * @return the outcome of the installation as a {@link CodeInstallResult}. */ - CodeInstallResult installCode(HotSpotCompilationResult compResult, HotSpotInstalledCode code, HotSpotCodeInfo info, SpeculationLog cache); + CodeInstallResult installCode(HotSpotCompilationResult compResult, HotSpotInstalledCode code, SpeculationLog cache); void initializeConfiguration(HotSpotVMConfig config); @@ -190,9 +188,14 @@ long getMaxCallTargetOffset(long stub); - String disassembleNative(byte[] code, long address); + String disassembleNMethod(long nmethod); - String disassembleNMethod(long nmethod); + /** + * Gets a copy of the machine code for an nmethod. + * + * @return the machine code for {@code nmethod} if it is valid, null otherwise + */ + byte[] getCode(long nmethod); StackTraceElement getStackTraceElement(long metaspaceMethod, int bci); @@ -204,8 +207,6 @@ long[] getDeoptedLeafGraphIds(); - String decodePC(long pc); - long[] getLineNumberTable(HotSpotResolvedJavaMethod method); Local[] getLocalVariableTable(HotSpotResolvedJavaMethod method); diff -r 5fbb2df2b47f -r a69eb5f539d9 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Mon Mar 18 19:38:46 2013 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Mon Mar 18 19:39:25 2013 -0700 @@ -35,11 +35,11 @@ */ public class CompilerToVMImpl implements CompilerToVM { - private native int installCode0(HotSpotCompilationResult comp, HotSpotInstalledCode code, HotSpotCodeInfo info, boolean[] triggeredDeoptimizations); + private native int installCode0(HotSpotCompilationResult comp, HotSpotInstalledCode code, boolean[] triggeredDeoptimizations); @Override - public CodeInstallResult installCode(HotSpotCompilationResult comp, HotSpotInstalledCode code, HotSpotCodeInfo info, SpeculationLog speculationLog) { - return CodeInstallResult.values()[installCode0(comp, code, info, (speculationLog == null) ? null : speculationLog.getRawMap())]; + public CodeInstallResult installCode(HotSpotCompilationResult comp, HotSpotInstalledCode code, SpeculationLog speculationLog) { + return CodeInstallResult.values()[installCode0(comp, code, (speculationLog == null) ? null : speculationLog.getRawMap())]; } @Override @@ -124,10 +124,10 @@ public native long getMaxCallTargetOffset(long stub); @Override - public native String disassembleNative(byte[] code, long address); + public native String disassembleNMethod(long nmethod); @Override - public native String disassembleNMethod(long nmethod); + public native byte[] getCode(long nmethod); @Override public native StackTraceElement getStackTraceElement(long metaspaceMethod, int bci); @@ -145,9 +145,6 @@ public native long[] getDeoptedLeafGraphIds(); @Override - public native String decodePC(long pc); - - @Override public native long[] getLineNumberTable(HotSpotResolvedJavaMethod method); @Override diff -r 5fbb2df2b47f -r a69eb5f539d9 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeInfo.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeInfo.java Mon Mar 18 19:38:46 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2011, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.meta; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.hotspot.*; - -/** - * Implementation of {@link CodeInfo} for HotSpot. - */ -public class HotSpotCodeInfo extends CompilerObject implements CodeInfo { - - private static final long serialVersionUID = -6766490427732498354L; - - private long start; - private byte[] code; - public final CompilationResult targetMethod; - private HotSpotResolvedJavaMethod method; - - public HotSpotCodeInfo(CompilationResult targetMethod, HotSpotResolvedJavaMethod method) { - assert targetMethod != null; - this.method = method; - this.targetMethod = targetMethod; - } - - @Override - public long getStart() { - return start; - } - - @Override - public byte[] getCode() { - return code; - } - - @Override - public String toString() { - int size = code == null ? 0 : code.length; - return "installed code @[" + Long.toHexString(start) + "-" + Long.toHexString(start + size) + "]"; - - } - - @Override - public ResolvedJavaMethod getMethod() { - return method; - } -} diff -r 5fbb2df2b47f -r a69eb5f539d9 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotInstalledCode.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotInstalledCode.java Mon Mar 18 19:38:46 2013 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotInstalledCode.java Mon Mar 18 19:39:25 2013 -0700 @@ -40,6 +40,7 @@ private final HotSpotResolvedJavaMethod method; private final boolean isDefault; long nmethod; + long start; public HotSpotInstalledCode(HotSpotResolvedJavaMethod method, boolean isDefault) { this.method = method; @@ -93,4 +94,14 @@ assert checkArgs(args); return HotSpotGraalRuntime.getInstance().getCompilerToVM().executeCompiledMethodVarargs(method.metaspaceMethod, nmethod, args); } + + @Override + public long getStart() { + return isValid() ? start : 0; + } + + @Override + public byte[] getCode() { + return HotSpotGraalRuntime.getInstance().getCompilerToVM().getCode(nmethod); + } } diff -r 5fbb2df2b47f -r a69eb5f539d9 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java Mon Mar 18 19:38:46 2013 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java Mon Mar 18 19:39:25 2013 -0700 @@ -380,16 +380,17 @@ public abstract Register stackPointerRegister(); @Override - public String disassemble(CodeInfo info, CompilationResult tm) { - byte[] code = info.getCode(); + public String disassemble(CompilationResult compResult, InstalledCode installedCode) { + byte[] code = installedCode == null ? Arrays.copyOf(compResult.getTargetCode(), compResult.getTargetCodeSize()) : installedCode.getCode(); + long start = installedCode == null ? 0L : installedCode.getStart(); TargetDescription target = graalRuntime.getTarget(); - HexCodeFile hcf = new HexCodeFile(code, info.getStart(), target.arch.getName(), target.wordSize * 8); - if (tm != null) { - HexCodeFile.addAnnotations(hcf, tm.getAnnotations()); - addExceptionHandlersComment(tm, hcf); + HexCodeFile hcf = new HexCodeFile(code, start, target.arch.getName(), target.wordSize * 8); + if (compResult != null) { + HexCodeFile.addAnnotations(hcf, compResult.getAnnotations()); + addExceptionHandlersComment(compResult, hcf); Register fp = regConfig.getFrameRegister(); RefMapFormatter slotFormatter = new RefMapFormatter(target.arch, target.wordSize, fp, 0); - for (Safepoint safepoint : tm.getSafepoints()) { + for (Safepoint safepoint : compResult.getSafepoints()) { if (safepoint instanceof Call) { Call call = (Call) safepoint; if (call.debugInfo != null) { @@ -403,10 +404,10 @@ addOperandComment(hcf, safepoint.pcOffset, "{safepoint}"); } } - for (DataPatch site : tm.getDataReferences()) { + for (DataPatch site : compResult.getDataReferences()) { hcf.addOperandComment(site.pcOffset, "{" + site.constant + "}"); } - for (Mark mark : tm.getMarks()) { + for (Mark mark : compResult.getMarks()) { hcf.addComment(mark.pcOffset, getMarkName(mark)); } } @@ -808,27 +809,17 @@ return graalRuntime.getCompilerToVM().getJavaField(reflectionField); } - private static HotSpotCodeInfo makeInfo(ResolvedJavaMethod method, CompilationResult compResult, CodeInfo[] info) { - HotSpotCodeInfo hsInfo = null; - if (info != null && info.length > 0) { - hsInfo = new HotSpotCodeInfo(compResult, (HotSpotResolvedJavaMethod) method); - info[0] = hsInfo; - } - return hsInfo; - } - - public void installMethod(HotSpotResolvedJavaMethod method, int entryBCI, CompilationResult compResult, CodeInfo[] info) { - HotSpotCodeInfo hsInfo = makeInfo(method, compResult, info); - HotSpotInstalledCode code = new HotSpotInstalledCode(method, true); - graalRuntime.getCompilerToVM().installCode(new HotSpotCompilationResult(method, entryBCI, compResult), code, hsInfo, method.getSpeculationLog()); + public HotSpotInstalledCode installMethod(HotSpotResolvedJavaMethod method, int entryBCI, CompilationResult compResult) { + HotSpotInstalledCode installedCode = new HotSpotInstalledCode(method, true); + graalRuntime.getCompilerToVM().installCode(new HotSpotCompilationResult(method, entryBCI, compResult), installedCode, method.getSpeculationLog()); + return installedCode; } @Override - public InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult, CodeInfo[] info) { - HotSpotCodeInfo hsInfo = makeInfo(method, compResult, info); + public InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult) { HotSpotResolvedJavaMethod hotspotMethod = (HotSpotResolvedJavaMethod) method; HotSpotInstalledCode code = new HotSpotInstalledCode(hotspotMethod, false); - CodeInstallResult result = graalRuntime.getCompilerToVM().installCode(new HotSpotCompilationResult(hotspotMethod, -1, compResult), code, hsInfo, null); + CodeInstallResult result = graalRuntime.getCompilerToVM().installCode(new HotSpotCompilationResult(hotspotMethod, -1, compResult), code, null); if (result != CodeInstallResult.OK) { return null; } diff -r 5fbb2df2b47f -r a69eb5f539d9 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 Mon Mar 18 19:38:46 2013 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/Stub.java Mon Mar 18 19:39:25 2013 -0700 @@ -121,22 +121,21 @@ final CompilationResult compResult = GraalCompiler.compileMethod(runtime(), backend, runtime().getTarget(), stubMethod, graph, null, phasePlan, OptimisticOptimizations.ALL, new SpeculationLog()); - final CodeInfo[] info = new CodeInfo[1]; stubCode = Debug.scope("CodeInstall", new Object[]{runtime(), stubMethod}, new Callable() { @Override public InstalledCode call() { - InstalledCode installedCode = runtime().addMethod(stubMethod, compResult, info); + InstalledCode installedCode = runtime().addMethod(stubMethod, compResult); assert installedCode != null : "error installing stub " + stubMethod; if (Debug.isDumpEnabled()) { - Debug.dump(new Object[]{compResult, info[0]}, "After code installation"); + Debug.dump(new Object[]{compResult, installedCode}, "After code installation"); } return installedCode; } }); assert stubCode != null : "error installing stub " + stubMethod; - linkage.setAddress(info[0].getStart()); + linkage.setAddress(stubCode.getStart()); } /** diff -r 5fbb2df2b47f -r a69eb5f539d9 graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java Mon Mar 18 19:38:46 2013 -0700 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java Mon Mar 18 19:39:25 2013 -0700 @@ -151,32 +151,11 @@ cfgPrinter.printCFG(message, Arrays.asList(cfgPrinter.cfg.getBlocks())); } else if (object instanceof CompilationResult) { - final CompilationResult tm = (CompilationResult) object; - final byte[] code = Arrays.copyOf(tm.getTargetCode(), tm.getTargetCodeSize()); - CodeInfo info = new CodeInfo() { - - public ResolvedJavaMethod getMethod() { - return curMethod; - } - - public long getStart() { - return 0L; - } - - public byte[] getCode() { - return code; - } - - @Override - public String toString() { - int size = code == null ? 0 : code.length; - return getMethod() + " installed code; length = " + size; - } - }; - cfgPrinter.printMachineCode(runtime.disassemble(info, tm), message); - } else if (isCompilationResultAndCodeInfo(object)) { + final CompilationResult compResult = (CompilationResult) object; + cfgPrinter.printMachineCode(runtime.disassemble(compResult, null), message); + } else if (isCompilationResultAndInstalledCode(object)) { Object[] tuple = (Object[]) object; - cfgPrinter.printMachineCode(runtime.disassemble((CodeInfo) tuple[1], (CompilationResult) tuple[0]), message); + cfgPrinter.printMachineCode(runtime.disassemble((CompilationResult) tuple[0], (InstalledCode) tuple[1]), message); } else if (object instanceof Interval[]) { cfgPrinter.printIntervals(message, (Interval[]) object); @@ -189,10 +168,10 @@ cfgPrinter.flush(); } - private static boolean isCompilationResultAndCodeInfo(Object object) { + private static boolean isCompilationResultAndInstalledCode(Object object) { if (object instanceof Object[]) { Object[] tuple = (Object[]) object; - if (tuple.length == 2 && tuple[0] instanceof CompilationResult && tuple[1] instanceof CodeInfo) { + if (tuple.length == 2 && tuple[0] instanceof CompilationResult && tuple[1] instanceof InstalledCode) { return true; } } diff -r 5fbb2df2b47f -r a69eb5f539d9 mx/projects --- a/mx/projects Mon Mar 18 19:38:46 2013 -0700 +++ b/mx/projects Mon Mar 18 19:39:25 2013 -0700 @@ -248,7 +248,7 @@ # graal.compiler.amd64.test project@com.oracle.graal.compiler.amd64.test@subDir=graal project@com.oracle.graal.compiler.amd64.test@sourceDirs=src -project@com.oracle.graal.compiler.amd64.test@dependencies=com.oracle.graal.compiler.test +project@com.oracle.graal.compiler.amd64.test@dependencies=com.oracle.graal.compiler.test,com.oracle.graal.asm.amd64 project@com.oracle.graal.compiler.amd64.test@checkstyle=com.oracle.graal.graph project@com.oracle.graal.compiler.amd64.test@javaCompliance=1.7 diff -r 5fbb2df2b47f -r a69eb5f539d9 src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Mon Mar 18 19:38:46 2013 -0700 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Mon Mar 18 19:39:25 2013 -0700 @@ -794,7 +794,7 @@ C2V_END -C2V_VMENTRY(jint, installCode0, (JNIEnv *jniEnv, jobject, jobject compResult, jobject installed_code, jobject info, jobject triggered_deoptimizations)) +C2V_VMENTRY(jint, installCode0, (JNIEnv *jniEnv, jobject, jobject compResult, jobject installed_code, jobject triggered_deoptimizations)) ResourceMark rm; HandleMark hm; Handle compResultHandle = JNIHandles::resolve(compResult); @@ -808,36 +808,29 @@ if (result != GraalEnv::ok) { assert(nm == NULL, "should be"); } else { - if (info != NULL) { - arrayOop codeCopy = oopFactory::new_byteArray(nm->code_size(), CHECK_0); - memcpy(codeCopy->base(T_BYTE), nm->code_begin(), nm->code_size()); - HotSpotCodeInfo::set_code(info, codeCopy); - HotSpotCodeInfo::set_start(info, (jlong) nm->code_begin()); - } - if (!installed_code_handle.is_null()) { assert(installed_code_handle->is_a(HotSpotInstalledCode::klass()), "wrong type"); HotSpotInstalledCode::set_nmethod(installed_code_handle, (jlong) nm); HotSpotInstalledCode::set_method(installed_code_handle, HotSpotCompilationResult::method(compResult)); + HotSpotInstalledCode::set_start(installed_code_handle, (jlong) nm->code_begin()); assert(nm == NULL || !installed_code_handle->is_scavengable() || nm->on_scavenge_root_list(), "nm should be scavengable if installed_code is scavengable"); } } return result; C2V_END -C2V_VMENTRY(jobject, disassembleNative, (JNIEnv *jniEnv, jobject, jbyteArray code, jlong start_address)) +C2V_VMENTRY(jobject, getCode, (JNIEnv *jniEnv, jobject, jlong metaspace_nmethod)) ResourceMark rm; HandleMark hm; - stringStream(st); - arrayOop code_oop = (arrayOop) JNIHandles::resolve(code); - int len = code_oop->length(); - address begin = (address) code_oop->base(T_BYTE); - address end = begin + len; - Disassembler::decode(begin, end, &st); - - Handle result = java_lang_String::create_from_platform_dependent_str(st.as_string(), CHECK_NULL); - return JNIHandles::make_local(result()); + nmethod* nm = (nmethod*) (address) metaspace_nmethod; + if (nm == NULL || !nm->is_alive()) { + return NULL; + } + int length = nm->code_size(); + arrayOop codeCopy = oopFactory::new_byteArray(length, CHECK_0); + memcpy(codeCopy->base(T_BYTE), nm->code_begin(), length); + return JNIHandles::make_local(codeCopy); C2V_END C2V_VMENTRY(jobject, disassembleNMethod, (JNIEnv *jniEnv, jobject, jlong metaspace_nmethod)) @@ -942,28 +935,7 @@ return JNIHandles::make_local(array); C2V_END -C2V_VMENTRY(jobject, decodePC, (JNIEnv *, jobject, jlong pc)) - stringStream(st); - CodeBlob* blob = CodeCache::find_blob_unsafe((void*) pc); - if (blob == NULL) { - st.print("[unidentified pc]"); - } else { - st.print(blob->name()); - - nmethod* nm = blob->as_nmethod_or_null(); - if (nm != NULL && nm->method() != NULL) { - st.print(" %s.", nm->method()->method_holder()->external_name()); - nm->method()->name()->print_symbol_on(&st); - st.print(" @ %d", pc - (jlong) nm->entry_point()); - } - } - Handle result = java_lang_String::create_from_platform_dependent_str(st.as_string(), CHECK_NULL); - return JNIHandles::make_local(result()); -C2V_END - C2V_ENTRY(jlongArray, getLineNumberTable, (JNIEnv *env, jobject, jobject hotspot_method)) -// XXX: Attention: it seEms that the line number table of a method just contains lines that are important, means that -// empty lines are left out or lines that can't have a breakpoint on it; eg int a; or try { Method* method = getMethodFromHotSpotMethod(JNIHandles::resolve(hotspot_method)); if (!method->has_linenumber_table()) { return NULL; @@ -1064,7 +1036,6 @@ #define HS_CONFIG "Lcom/oracle/graal/hotspot/HotSpotVMConfig;" #define HS_METHOD "Lcom/oracle/graal/hotspot/meta/HotSpotMethod;" #define HS_INSTALLED_CODE "Lcom/oracle/graal/hotspot/meta/HotSpotInstalledCode;" -#define HS_CODE_INFO "Lcom/oracle/graal/hotspot/meta/HotSpotCodeInfo;" #define METHOD_DATA "Lcom/oracle/graal/hotspot/meta/HotSpotMethodData;" #define METASPACE_METHOD "J" #define METASPACE_METHOD_DATA "J" @@ -1100,13 +1071,12 @@ {CC"getMetaspaceConstructor", CC"("REFLECT_CONSTRUCTOR"["HS_RESOLVED_TYPE")"METASPACE_METHOD, FN_PTR(getMetaspaceConstructor)}, {CC"getJavaField", CC"("REFLECT_FIELD")"HS_RESOLVED_FIELD, FN_PTR(getJavaField)}, {CC"initializeConfiguration", CC"("HS_CONFIG")V", FN_PTR(initializeConfiguration)}, - {CC"installCode0", CC"("HS_COMP_RESULT HS_INSTALLED_CODE HS_CODE_INFO"[Z)I", FN_PTR(installCode0)}, - {CC"disassembleNative", CC"([BJ)"STRING, FN_PTR(disassembleNative)}, + {CC"installCode0", CC"("HS_COMP_RESULT HS_INSTALLED_CODE"[Z)I", FN_PTR(installCode0)}, + {CC"getCode", CC"(J)[B", FN_PTR(getCode)}, {CC"disassembleNMethod", CC"(J)"STRING, FN_PTR(disassembleNMethod)}, {CC"executeCompiledMethod", CC"("METASPACE_METHOD NMETHOD OBJECT OBJECT OBJECT")"OBJECT, FN_PTR(executeCompiledMethod)}, {CC"executeCompiledMethodVarargs", CC"("METASPACE_METHOD NMETHOD "["OBJECT")"OBJECT, FN_PTR(executeCompiledMethodVarargs)}, {CC"getDeoptedLeafGraphIds", CC"()[J", FN_PTR(getDeoptedLeafGraphIds)}, - {CC"decodePC", CC"(J)"STRING, FN_PTR(decodePC)}, {CC"getLineNumberTable", CC"("HS_RESOLVED_METHOD")[J", FN_PTR(getLineNumberTable)}, {CC"getLocalVariableTable", CC"("HS_RESOLVED_METHOD")["LOCAL, FN_PTR(getLocalVariableTable)}, {CC"getFileName", CC"("HS_RESOLVED_JAVA_TYPE")"STRING, FN_PTR(getFileName)}, diff -r 5fbb2df2b47f -r a69eb5f539d9 src/share/vm/graal/graalJavaAccess.hpp --- a/src/share/vm/graal/graalJavaAccess.hpp Mon Mar 18 19:38:46 2013 -0700 +++ b/src/share/vm/graal/graalJavaAccess.hpp Mon Mar 18 19:39:25 2013 -0700 @@ -75,12 +75,9 @@ start_class(HotSpotInstalledCode) \ long_field(HotSpotInstalledCode, nmethod) \ oop_field(HotSpotInstalledCode, method, "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod;") \ + long_field(HotSpotInstalledCode, start) \ boolean_field(HotSpotInstalledCode, isDefault) \ end_class \ - start_class(HotSpotCodeInfo) \ - long_field(HotSpotCodeInfo, start) \ - oop_field(HotSpotCodeInfo, code, "[B") \ - end_class \ start_class(HotSpotCompilationResult) \ oop_field(HotSpotCompilationResult, comp, "Lcom/oracle/graal/api/code/CompilationResult;") \ oop_field(HotSpotCompilationResult, method, "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod;") \