# HG changeset patch # User Christian Wimmer # Date 1390616018 28800 # Node ID a12017c18d5d16df0713afedb6a6388a8b3a7ee8 # Parent eed1aafead0d938d1dbd5544c85a4128c1dce21a Truffle API cleanup: Reduce the visibility of classes and constructors that are not intended to be instantiated by guest language implementations; provide abstract class RootCallTarget as a CallTarget to a RootNode diff -r eed1aafead0d -r a12017c18d5d graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java Fri Jan 24 18:34:18 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java Fri Jan 24 18:13:38 2014 -0800 @@ -48,7 +48,6 @@ import com.oracle.graal.runtime.*; import com.oracle.truffle.api.*; import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.api.impl.*; import com.oracle.truffle.api.nodes.*; /** @@ -73,9 +72,9 @@ return "Graal Truffle Runtime"; } - public CallTarget createCallTarget(RootNode rootNode) { + public RootCallTarget createCallTarget(RootNode rootNode) { if (!acceptForCompilation(rootNode)) { - return new DefaultCallTarget(rootNode); + return new UnoptimizedCallTarget(rootNode); } if (truffleCompiler == null) { truffleCompiler = new TruffleCompilerImpl(); diff -r eed1aafead0d -r a12017c18d5d graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java Fri Jan 24 18:34:18 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java Fri Jan 24 18:13:38 2014 -0800 @@ -55,7 +55,7 @@ super(rootNode); this.compiler = compiler; this.compilationProfile = new CompilationProfile(compilationThreshold, invokeCounter, rootNode.toString()); - this.rootNode.setCallTarget(this); + this.getRootNode().setCallTarget(this); if (TruffleUseTimeForCompilationDecision.getValue()) { compilationPolicy = new TimedCompilationPolicy(); @@ -117,7 +117,7 @@ installedCode = null; compilationProfile.reportInvalidated(); if (TraceTruffleCompilation.getValue()) { - OUT.printf("[truffle] invalidated %-48s |Inv# %d |Replace# %d\n", rootNode, compilationProfile.getInvalidationCount(), + OUT.printf("[truffle] invalidated %-48s |Inv# %d |Replace# %d\n", getRootNode(), compilationProfile.getInvalidationCount(), compilationProfile.getNodeReplaceCount()); } } @@ -183,7 +183,7 @@ return installedCodeTask.get(); } catch (InterruptedException | ExecutionException e) { compilationEnabled = false; - OUT.printf("[truffle] opt failed %-48s %s\n", rootNode, e.getMessage()); + OUT.printf("[truffle] opt failed %-48s %s\n", getRootNode(), e.getMessage()); if (e.getCause() instanceof BailoutException) { // Bailout => move on. } else { @@ -212,8 +212,8 @@ } public Object executeHelper(PackedFrame caller, Arguments args) { - VirtualFrame frame = createFrame(rootNode.getFrameDescriptor(), caller, args); - return rootNode.execute(frame); + VirtualFrame frame = createFrame(getRootNode().getFrameDescriptor(), caller, args); + return getRootNode().execute(frame); } protected static FrameWithoutBoxing createFrame(FrameDescriptor descriptor, PackedFrame caller, Arguments args) { @@ -260,8 +260,8 @@ } int notInlinedCallSiteCount = TruffleInliningImpl.getInlinableCallSites(callTarget).size(); - int nodeCount = NodeUtil.countNodes(callTarget.rootNode); - int inlinedCallSiteCount = NodeUtil.countNodes(callTarget.rootNode, InlinedCallSite.class); + int nodeCount = NodeUtil.countNodes(callTarget.getRootNode()); + int inlinedCallSiteCount = NodeUtil.countNodes(callTarget.getRootNode(), InlinedCallSite.class); String comment = callTarget.installedCode == null ? " int" : ""; comment += callTarget.compilationEnabled ? "" : " fail"; OUT.printf("%-50s | %10d | %15d | %15d | %10d | %3d%s\n", callTarget.getRootNode(), callTarget.callCount, inlinedCallSiteCount, notInlinedCallSiteCount, nodeCount, diff -r eed1aafead0d -r a12017c18d5d graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleDebugJavaMethod.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleDebugJavaMethod.java Fri Jan 24 18:34:18 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleDebugJavaMethod.java Fri Jan 24 18:13:38 2014 -0800 @@ -26,14 +26,14 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.debug.*; -import com.oracle.truffle.api.impl.*; +import com.oracle.truffle.api.*; /** * Enables a Truffle compilable to masquerade as a {@link JavaMethod} for use as a context value in * {@linkplain Debug#scope(String, Object...) debug scopes}. */ public class TruffleDebugJavaMethod implements JavaMethod { - private final DefaultCallTarget compilable; + private final RootCallTarget compilable; private static final JavaType declaringClass = new JavaType() { @@ -95,7 +95,7 @@ } }; - public TruffleDebugJavaMethod(DefaultCallTarget compilable) { + public TruffleDebugJavaMethod(RootCallTarget compilable) { this.compilable = compilable; } diff -r eed1aafead0d -r a12017c18d5d graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInliningImpl.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInliningImpl.java Fri Jan 24 18:34:18 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInliningImpl.java Fri Jan 24 18:13:38 2014 -0800 @@ -28,7 +28,7 @@ import java.util.*; import com.oracle.graal.debug.*; -import com.oracle.truffle.api.impl.*; +import com.oracle.truffle.api.*; import com.oracle.truffle.api.nodes.*; class TruffleInliningImpl implements TruffleInlining { @@ -200,7 +200,7 @@ } } - static List getInlinableCallSites(final DefaultCallTarget target) { + static List getInlinableCallSites(final RootCallTarget target) { final ArrayList inlinableCallSites = new ArrayList<>(); target.getRootNode().accept(new NodeVisitor() { diff -r eed1aafead0d -r a12017c18d5d graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleTreeDumpHandler.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleTreeDumpHandler.java Fri Jan 24 18:34:18 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleTreeDumpHandler.java Fri Jan 24 18:13:38 2014 -0800 @@ -23,15 +23,15 @@ package com.oracle.graal.truffle; import com.oracle.graal.debug.*; -import com.oracle.truffle.api.impl.*; +import com.oracle.truffle.api.*; import com.oracle.truffle.api.nodes.*; public class TruffleTreeDumpHandler implements DebugDumpHandler { @Override public void dump(Object object, final String message) { - if (object instanceof DefaultCallTarget) { - DefaultCallTarget callTarget = (DefaultCallTarget) object; + if (object instanceof RootCallTarget) { + RootCallTarget callTarget = (RootCallTarget) object; if (callTarget.getRootNode() != null) { new GraphPrintVisitor().beginGroup(callTarget.toString()).beginGraph(message).visit(callTarget.getRootNode()).printToNetwork(); } diff -r eed1aafead0d -r a12017c18d5d graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/UnoptimizedCallTarget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/UnoptimizedCallTarget.java Fri Jan 24 18:13:38 2014 -0800 @@ -0,0 +1,36 @@ +/* + * 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.truffle; + +import com.oracle.truffle.api.impl.*; +import com.oracle.truffle.api.nodes.*; + +/** + * Call target that is not optimized by Graal upon surpassing a specific invocation threshold. + */ +public final class UnoptimizedCallTarget extends DefaultCallTarget { + + protected UnoptimizedCallTarget(RootNode rootNode) { + super(rootNode); + } +} diff -r eed1aafead0d -r a12017c18d5d graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CallTarget.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CallTarget.java Fri Jan 24 18:34:18 2014 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CallTarget.java Fri Jan 24 18:13:38 2014 -0800 @@ -27,8 +27,7 @@ import com.oracle.truffle.api.frame.*; /** - * Represents the target of a call. Instances of this interface can be created using the - * {@link TruffleRuntime#createCallTarget(com.oracle.truffle.api.nodes.RootNode)} method. + * Represents the target of a call. */ public abstract class CallTarget { diff -r eed1aafead0d -r a12017c18d5d graal/com.oracle.truffle.api/src/com/oracle/truffle/api/RootCallTarget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/RootCallTarget.java Fri Jan 24 18:13:38 2014 -0800 @@ -0,0 +1,50 @@ +/* + * 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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.truffle.api; + +import com.oracle.truffle.api.nodes.*; + +/** + * Represents the target of a call to a {@link RootNode}, i.e., to another tree of nodes. Instances + * of this class can be created using {@link TruffleRuntime#createCallTarget(RootNode)}. + */ +public abstract class RootCallTarget extends CallTarget { + + private final RootNode rootNode; + + public RootCallTarget(RootNode function) { + this.rootNode = function; + this.rootNode.setCallTarget(this); + } + + @Override + public String toString() { + return rootNode.toString(); + } + + public RootNode getRootNode() { + return rootNode; + } +} diff -r eed1aafead0d -r a12017c18d5d graal/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleRuntime.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleRuntime.java Fri Jan 24 18:34:18 2014 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleRuntime.java Fri Jan 24 18:13:38 2014 -0800 @@ -48,7 +48,7 @@ * represents the entry point * @return the new call target object */ - CallTarget createCallTarget(RootNode rootNode); + RootCallTarget createCallTarget(RootNode rootNode); /** * Creates a new assumption object that can be checked and invalidated. diff -r eed1aafead0d -r a12017c18d5d graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultAssumption.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultAssumption.java Fri Jan 24 18:34:18 2014 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultAssumption.java Fri Jan 24 18:13:38 2014 -0800 @@ -24,11 +24,16 @@ */ package com.oracle.truffle.api.impl; +import com.oracle.truffle.api.*; import com.oracle.truffle.api.nodes.*; -public final class DefaultAssumption extends AbstractAssumption { +/** + * This is an implementation-specific class. Do not use or instantiate it. Instead, use + * {@link TruffleRuntime#createAssumption()} to create an {@link Assumption}. + */ +final class DefaultAssumption extends AbstractAssumption { - public DefaultAssumption(String name) { + DefaultAssumption(String name) { super(name); } diff -r eed1aafead0d -r a12017c18d5d graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultCallTarget.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultCallTarget.java Fri Jan 24 18:34:18 2014 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultCallTarget.java Fri Jan 24 18:13:38 2014 -0800 @@ -28,27 +28,19 @@ import com.oracle.truffle.api.frame.*; import com.oracle.truffle.api.nodes.*; -public class DefaultCallTarget extends CallTarget { - - protected final RootNode rootNode; +/** + * This is an implementation-specific class. Do not use or instantiate it. Instead, use + * {@link TruffleRuntime#createCallTarget(RootNode)} to create a {@link RootCallTarget}. + */ +public class DefaultCallTarget extends RootCallTarget { - public DefaultCallTarget(RootNode function) { - this.rootNode = function; - this.rootNode.setCallTarget(this); - } - - @Override - public String toString() { - return rootNode.toString(); + protected DefaultCallTarget(RootNode function) { + super(function); } @Override public Object call(PackedFrame caller, Arguments args) { - VirtualFrame frame = new DefaultVirtualFrame(rootNode.getFrameDescriptor(), caller, args); - return rootNode.execute(frame); - } - - public RootNode getRootNode() { - return rootNode; + VirtualFrame frame = new DefaultVirtualFrame(getRootNode().getFrameDescriptor(), caller, args); + return getRootNode().execute(frame); } } diff -r eed1aafead0d -r a12017c18d5d graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultMaterializedFrame.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultMaterializedFrame.java Fri Jan 24 18:34:18 2014 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultMaterializedFrame.java Fri Jan 24 18:13:38 2014 -0800 @@ -27,11 +27,16 @@ import com.oracle.truffle.api.*; import com.oracle.truffle.api.frame.*; +/** + * This is an implementation-specific class. Do not use or instantiate it. Instead, use + * {@link TruffleRuntime#createMaterializedFrame(Arguments)} or {@link Frame#materialize()} to + * create a {@link MaterializedFrame}. + */ final class DefaultMaterializedFrame implements MaterializedFrame, PackedFrame { private final DefaultVirtualFrame wrapped; - protected DefaultMaterializedFrame(DefaultVirtualFrame wrapped) { + DefaultMaterializedFrame(DefaultVirtualFrame wrapped) { this.wrapped = wrapped; } diff -r eed1aafead0d -r a12017c18d5d graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultPackedFrame.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultPackedFrame.java Fri Jan 24 18:34:18 2014 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultPackedFrame.java Fri Jan 24 18:13:38 2014 -0800 @@ -26,11 +26,15 @@ import com.oracle.truffle.api.frame.*; +/** + * This is an implementation-specific class. Do not use or instantiate it. Instead, use + * {@link Frame#pack()} to create a {@link PackedFrame}. + */ final class DefaultPackedFrame implements PackedFrame { private final DefaultVirtualFrame wrapped; - protected DefaultPackedFrame(DefaultVirtualFrame wrapped) { + DefaultPackedFrame(DefaultVirtualFrame wrapped) { this.wrapped = wrapped; } diff -r eed1aafead0d -r a12017c18d5d graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultTruffleRuntime.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultTruffleRuntime.java Fri Jan 24 18:34:18 2014 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultTruffleRuntime.java Fri Jan 24 18:13:38 2014 -0800 @@ -31,16 +31,25 @@ /** * Default implementation of the Truffle runtime if the virtual machine does not provide a better * performing alternative. + *

+ * This is an implementation-specific class. Do not use or instantiate it. Instead, use + * {@link Truffle#getRuntime()} to retrieve the current {@link TruffleRuntime}. */ public final class DefaultTruffleRuntime implements TruffleRuntime { + public DefaultTruffleRuntime() { + if (Truffle.getRuntime() != null) { + throw new IllegalArgumentException("Cannot instantiate DefaultTruffleRuntime. Use Truffle.getRuntime() instead."); + } + } + @Override public String getName() { return "Default Truffle Runtime"; } @Override - public CallTarget createCallTarget(RootNode rootNode) { + public RootCallTarget createCallTarget(RootNode rootNode) { return new DefaultCallTarget(rootNode); } diff -r eed1aafead0d -r a12017c18d5d graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java Fri Jan 24 18:34:18 2014 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java Fri Jan 24 18:13:38 2014 -0800 @@ -29,7 +29,12 @@ import com.oracle.truffle.api.*; import com.oracle.truffle.api.frame.*; -public final class DefaultVirtualFrame implements VirtualFrame { +/** + * This is an implementation-specific class. Do not use or instantiate it. Instead, use + * {@link TruffleRuntime#createVirtualFrame(PackedFrame, Arguments, FrameDescriptor)} to create a + * {@link VirtualFrame}. + */ +final class DefaultVirtualFrame implements VirtualFrame { private final FrameDescriptor descriptor; private final PackedFrame caller; @@ -37,7 +42,7 @@ private Object[] locals; private byte[] tags; - public DefaultVirtualFrame(FrameDescriptor descriptor, PackedFrame caller, Arguments arguments) { + DefaultVirtualFrame(FrameDescriptor descriptor, PackedFrame caller, Arguments arguments) { this.descriptor = descriptor; this.caller = caller; this.arguments = arguments;