Mercurial > hg > graal-jvmci-8
diff graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotInstalledCode.java @ 9668:fe9a18fbb15e
added subclasses for HotSpotInstalledCode: HotSpotNmethod and HotSpotRuntimeStub
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 13 May 2013 18:19:43 +0200 |
parents | 18632807db02 |
children | 001c41b01d13 |
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotInstalledCode.java Mon May 13 16:09:49 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotInstalledCode.java Mon May 13 18:19:43 2013 +0200 @@ -24,123 +24,30 @@ import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; -import java.lang.reflect.*; - import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.graph.*; import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.stubs.*; /** - * Implementation of {@link InstalledCode} for HotSpot. If the code is installed as an nmethod (as - * opposed to some other subclass of CodeBlob such as RuntimeStub), then the nmethod stores a weak - * reference to an instance of this class. This is necessary to keep the nmethod from being unloaded - * while the associated {@link HotSpotInstalledCode} instance is alive. - * <p> - * Note that there is no (current) way for the reference from an nmethod to a - * {@link HotSpotInstalledCode} instance to be anything but weak. This is due to the fact that - * HotSpot does not treat nmethods as strong GC roots. + * Implementation of {@link InstalledCode} for HotSpot. */ -public class HotSpotInstalledCode extends CompilerObject implements InstalledCode { +public abstract class HotSpotInstalledCode extends CompilerObject implements InstalledCode { private static final long serialVersionUID = 156632908220561612L; - private final HotSpotResolvedJavaMethod method; - private final Stub stub; - private final boolean isDefault; - private final Graph graph; long codeBlob; long start; - public HotSpotInstalledCode(HotSpotResolvedJavaMethod method, Graph graph, boolean isDefault) { - this.method = method; - this.stub = null; - this.graph = graph; - this.isDefault = isDefault; - } - - public HotSpotInstalledCode(Stub stub) { - this.method = null; - this.stub = stub; - this.graph = null; - this.isDefault = false; - } - - public boolean isDefault() { - return isDefault; - } - public long getCodeBlob() { return codeBlob; } - public Graph getGraph() { - return graph; - } - @Override - public ResolvedJavaMethod getMethod() { - return method; - } - - @Override - public boolean isValid() { - return stub != null || graalRuntime().getCompilerToVM().isInstalledCodeValid(codeBlob); - } + public abstract String toString(); - @Override - public void invalidate() { - if (stub == null) { - graalRuntime().getCompilerToVM().invalidateInstalledCode(codeBlob); - } - } - - @Override - public String toString() { - if (stub != null) { - return String.format("InstalledCode[stub=%s, codeBlob=0x%x]", stub, codeBlob); - } - return String.format("InstalledCode[method=%s, codeBlob=0x%x, isDefault=%b]", method, codeBlob, isDefault); + public long getStart() { + return start; } - @Override - public Object execute(Object arg1, Object arg2, Object arg3) throws InvalidInstalledCodeException { - assert stub == null; - assert method.getSignature().getParameterCount(!Modifier.isStatic(method.getModifiers())) == 3; - assert method.getSignature().getParameterKind(0) == Kind.Object; - assert method.getSignature().getParameterKind(1) == Kind.Object; - assert !Modifier.isStatic(method.getModifiers()) || method.getSignature().getParameterKind(2) == Kind.Object; - return graalRuntime().getCompilerToVM().executeCompiledMethod(arg1, arg2, arg3, codeBlob); - } - - private boolean checkArgs(Object... args) { - JavaType[] sig = MetaUtil.signatureToTypes(method); - assert args.length == sig.length : MetaUtil.format("%H.%n(%p): expected ", method) + sig.length + " args, got " + args.length; - for (int i = 0; i < sig.length; i++) { - Object arg = args[i]; - if (arg == null) { - assert sig[i].getKind() == Kind.Object : MetaUtil.format("%H.%n(%p): expected arg ", method) + i + " to be Object, not " + sig[i]; - } else if (sig[i].getKind() != Kind.Object) { - assert sig[i].getKind().toBoxedJavaClass() == arg.getClass() : MetaUtil.format("%H.%n(%p): expected arg ", method) + i + " to be " + sig[i] + ", not " + arg.getClass(); - } - } - return true; - } - - @Override - public Object executeVarargs(Object... args) throws InvalidInstalledCodeException { - assert stub == null; - assert checkArgs(args); - return graalRuntime().getCompilerToVM().executeCompiledMethodVarargs(args, codeBlob); - } - - @Override - public long getStart() { - return isValid() ? start : 0; - } - - @Override public byte[] getCode() { return graalRuntime().getCompilerToVM().getCode(codeBlob); }