# HG changeset patch # User Doug Simon # Date 1363627572 -3600 # Node ID 8d6ea1915d420a2ce0fa6313246b8e3e80b8c386 # Parent 79f0ff46290b458ebd4cb81c51916b009857e6ba merged CodeInfo into InstalledCode (GRAAL-156) diff -r 79f0ff46290b -r 8d6ea1915d42 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 18:03:16 2013 +0100 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeCacheProvider.java Mon Mar 18 18:26:12 2013 +0100 @@ -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 79f0ff46290b -r 8d6ea1915d42 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 18:03:16 2013 +0100 +++ /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 79f0ff46290b -r 8d6ea1915d42 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 18:03:16 2013 +0100 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/InstalledCode.java Mon Mar 18 18:26:12 2013 +0100 @@ -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 79f0ff46290b -r 8d6ea1915d42 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 18:03:16 2013 +0100 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/package-info.java Mon Mar 18 18:26:12 2013 +0100 @@ -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 79f0ff46290b -r 8d6ea1915d42 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 18:03:16 2013 +0100 +++ b/graal/com.oracle.graal.asm.test/src/com/oracle/graal/asm/test/AssemblerTest.java Mon Mar 18 18:26:12 2013 +0100 @@ -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 79f0ff46290b -r 8d6ea1915d42 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 18:03:16 2013 +0100 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Mon Mar 18 18:26:12 2013 +0100 @@ -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 79f0ff46290b -r 8d6ea1915d42 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 18:03:16 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Mon Mar 18 18:26:12 2013 +0100 @@ -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 79f0ff46290b -r 8d6ea1915d42 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 18:03:16 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Mon Mar 18 18:26:12 2013 +0100 @@ -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); @@ -192,6 +190,13 @@ 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); Object executeCompiledMethod(long metaspaceMethod, long nmethod, Object arg1, Object arg2, Object arg3); diff -r 79f0ff46290b -r 8d6ea1915d42 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 18:03:16 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Mon Mar 18 18:26:12 2013 +0100 @@ -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 @@ -127,6 +127,9 @@ public native String disassembleNMethod(long nmethod); @Override + public native byte[] getCode(long nmethod); + + @Override public native StackTraceElement getStackTraceElement(long metaspaceMethod, int bci); @Override diff -r 79f0ff46290b -r 8d6ea1915d42 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 18:03:16 2013 +0100 +++ /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 79f0ff46290b -r 8d6ea1915d42 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 18:03:16 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotInstalledCode.java Mon Mar 18 18:26:12 2013 +0100 @@ -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 79f0ff46290b -r 8d6ea1915d42 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 18:03:16 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java Mon Mar 18 18:26:12 2013 +0100 @@ -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)); } } @@ -806,27 +807,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 79f0ff46290b -r 8d6ea1915d42 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 18:03:16 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/Stub.java Mon Mar 18 18:26:12 2013 +0100 @@ -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 79f0ff46290b -r 8d6ea1915d42 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 18:03:16 2013 +0100 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java Mon Mar 18 18:26:12 2013 +0100 @@ -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 79f0ff46290b -r 8d6ea1915d42 src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Mon Mar 18 18:03:16 2013 +0100 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Mon Mar 18 18:26:12 2013 +0100 @@ -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,23 +808,31 @@ 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, getCode, (JNIEnv *jniEnv, jobject, jlong metaspace_nmethod)) + ResourceMark rm; + HandleMark hm; + + 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)) ResourceMark rm; HandleMark hm; @@ -1028,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" @@ -1064,7 +1071,8 @@ {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"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)}, diff -r 79f0ff46290b -r 8d6ea1915d42 src/share/vm/graal/graalJavaAccess.hpp --- a/src/share/vm/graal/graalJavaAccess.hpp Mon Mar 18 18:03:16 2013 +0100 +++ b/src/share/vm/graal/graalJavaAccess.hpp Mon Mar 18 18:26:12 2013 +0100 @@ -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;") \