changeset 9783:5402504894fe

Merge.
author Christian Humer <christian.humer@gmail.com>
date Tue, 21 May 2013 19:51:00 +0200
parents ba02d19dd3cc (diff) 05b719a4ae09 (current diff)
children 747b2517feae 06dc2d2324d6 d6d5e3dc2713
files graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/RuntimeCallTarget.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotRuntimeCallTarget.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/CRuntimeCall.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/MonitorEnterStubCall.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/ThreadIsInterruptedStubCall.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/VerifyOopStubCall.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/CRuntimeStub.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/LogObjectStub.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/LogPrimitiveStub.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/LogPrintfStub.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewMultiArrayStub.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/OSRMigrationEndStub.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/RuntimeCallStub.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/ThreadIsInterruptedStub.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/VMErrorStub.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/RuntimeCallNode.java
diffstat 11 files changed, 125 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java	Tue May 21 12:39:40 2013 +0200
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java	Tue May 21 19:51:00 2013 +0200
@@ -149,6 +149,7 @@
             // Pass on the source section to the new node.
             newNode.assignSourceSection(sourceSection);
         }
+        onReplace(newNode, reason);
         return (T) this.getParent().replaceChild(this, newNode);
     }
 
@@ -170,6 +171,16 @@
     }
 
     /**
+     * Intended to be implemented by subclasses of {@link Node} to receive a notification when the
+     * node is rewritten. This method is invoked before the actual replace has happened.
+     * 
+     * @param newNode the replacement node
+     * @param reason the reason the replace supplied
+     */
+    protected void onReplace(Node newNode, String reason) {
+    }
+
+    /**
      * Invokes the {@link NodeVisitor#visit(Node)} method for this node and recursively also for all
      * child nodes.
      * 
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeInfo.java	Tue May 21 12:39:40 2013 +0200
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeInfo.java	Tue May 21 19:51:00 2013 +0200
@@ -37,4 +37,11 @@
      * @return the short name
      */
     String shortName() default "";
+
+    Kind kind() default Kind.SPECIALIZED;
+
+    public enum Kind {
+        UNINITIALIZED, SPECIALIZED, GENERIC
+    }
+
 }
--- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/TruffleTypes.java	Tue May 21 12:39:40 2013 +0200
+++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/TruffleTypes.java	Tue May 21 19:51:00 2013 +0200
@@ -26,7 +26,7 @@
 
 import javax.lang.model.element.*;
 import javax.lang.model.type.*;
-import javax.tools.Diagnostic.*;
+import javax.tools.Diagnostic.Kind;
 
 import com.oracle.truffle.api.*;
 import com.oracle.truffle.api.frame.*;
@@ -47,6 +47,8 @@
     private final TypeMirror invalidAssumption;
     private final DeclaredType childAnnotation;
     private final DeclaredType childrenAnnotation;
+    private final DeclaredType nodeInfoAnnotation;
+    private final DeclaredType nodeInfoKind;
     private final TypeMirror compilerDirectives;
     private final TypeMirror compilerAsserts;
 
@@ -63,6 +65,12 @@
         compilerAsserts = getRequired(context, CompilerAsserts.class);
         assumption = getRequired(context, Assumption.class);
         invalidAssumption = getRequired(context, InvalidAssumptionException.class);
+        nodeInfoAnnotation = getRequired(context, NodeInfo.class);
+        nodeInfoKind = getRequired(context, NodeInfo.Kind.class);
+    }
+
+    public DeclaredType getNodeInfoAnnotation() {
+        return nodeInfoAnnotation;
     }
 
     public boolean verify(ProcessorContext context, Element element, AnnotationMirror mirror) {
@@ -77,6 +85,10 @@
         return false;
     }
 
+    public DeclaredType getNodeInfoKind() {
+        return nodeInfoKind;
+    }
+
     private DeclaredType getRequired(ProcessorContext context, Class clazz) {
         TypeMirror type = context.getType(clazz);
         if (type == null) {
--- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/Utils.java	Tue May 21 12:39:40 2013 +0200
+++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/Utils.java	Tue May 21 19:51:00 2013 +0200
@@ -40,6 +40,26 @@
  */
 public class Utils {
 
+    public static ExecutableElement findExecutableElement(DeclaredType type, String name) {
+        List<? extends ExecutableElement> elements = ElementFilter.methodsIn(type.asElement().getEnclosedElements());
+        for (ExecutableElement executableElement : elements) {
+            if (executableElement.getSimpleName().toString().equals(name)) {
+                return executableElement;
+            }
+        }
+        return null;
+    }
+
+    public static VariableElement findVariableElement(DeclaredType type, String name) {
+        List<? extends VariableElement> elements = ElementFilter.fieldsIn(type.asElement().getEnclosedElements());
+        for (VariableElement variableElement : elements) {
+            if (variableElement.getSimpleName().toString().equals(name)) {
+                return variableElement;
+            }
+        }
+        return null;
+    }
+
     public static String getMethodBody(ProcessingEnvironment env, ExecutableElement method) {
         if (method instanceof CodeExecutableElement) {
             return ((CodeExecutableElement) method).getBody();
--- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/ast/CodeAnnotationMirror.java	Tue May 21 12:39:40 2013 +0200
+++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/ast/CodeAnnotationMirror.java	Tue May 21 19:51:00 2013 +0200
@@ -26,8 +26,8 @@
 
 import javax.lang.model.element.*;
 import javax.lang.model.type.*;
-import javax.lang.model.util.*;
 
+import com.oracle.truffle.codegen.processor.*;
 import com.oracle.truffle.codegen.processor.api.element.*;
 
 public class CodeAnnotationMirror implements WritableAnnotationMirror {
@@ -60,13 +60,7 @@
     }
 
     public ExecutableElement findExecutableElement(String name) {
-        List<? extends ExecutableElement> elements = ElementFilter.methodsIn(annotationType.asElement().getEnclosedElements());
-        for (ExecutableElement executableElement : elements) {
-            if (executableElement.getSimpleName().toString().equals(name)) {
-                return executableElement;
-            }
-        }
-        return null;
+        return Utils.findExecutableElement(annotationType, name);
     }
 
     public static CodeAnnotationMirror clone(AnnotationMirror mirror) {
--- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/ExecutableTypeData.java	Tue May 21 12:39:40 2013 +0200
+++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/ExecutableTypeData.java	Tue May 21 19:51:00 2013 +0200
@@ -75,23 +75,6 @@
         return count;
     }
 
-    public boolean startsWithSignature(TemplateMethod method) {
-        for (ActualParameter param : getParameters()) {
-            if (!param.getSpecification().isSignature()) {
-                continue;
-            }
-            ActualParameter foundParam = method.findParameter(param.getLocalName());
-            if (foundParam != null) {
-                TypeData actualType = param.getTypeSystemType();
-                TypeData foundType = foundParam.getTypeSystemType();
-                if (actualType == null || foundType == null || !actualType.equalsType(foundType)) {
-                    return false;
-                }
-            }
-        }
-        return true;
-    }
-
     public boolean hasGenericSignature() {
         List<TypeData> types = getSignature();
         for (TypeData typeData : types) {
--- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/ExecutableTypeMethodParser.java	Tue May 21 12:39:40 2013 +0200
+++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/ExecutableTypeMethodParser.java	Tue May 21 19:51:00 2013 +0200
@@ -44,8 +44,15 @@
     @Override
     public MethodSpec createSpecification(ExecutableElement method, AnnotationMirror mirror) {
         MethodSpec spec = createDefaultMethodSpec(method, mirror, false, null);
+        List<ParameterSpec> requiredSpecs = new ArrayList<>(spec.getRequired());
+        spec.getRequired().clear();
+
+        for (ParameterSpec originalSpec : requiredSpecs) {
+            spec.addRequired(new ParameterSpec(originalSpec, Arrays.asList(getNode().getTypeSystem().getGenericType())));
+        }
+
         spec.setVariableRequiredArguments(true);
-        ParameterSpec other = new ParameterSpec("other", nodeTypeMirrors(getNode()));
+        ParameterSpec other = new ParameterSpec("other", Arrays.asList(getNode().getTypeSystem().getGenericType()));
         other.setCardinality(Cardinality.MANY);
         other.setSignature(true);
         other.setIndexed(true);
--- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.java	Tue May 21 12:39:40 2013 +0200
+++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.java	Tue May 21 19:51:00 2013 +0200
@@ -1336,6 +1336,27 @@
                 baseType = nodeGen.asType();
             }
             CodeTypeElement clazz = createClass(node, modifiers(PRIVATE, STATIC, FINAL), nodeSpecializationClassName(specialization), baseType, false);
+
+            String shortName = specialization.getNode().getShortName();
+            CodeAnnotationMirror nodeInfoMirror = new CodeAnnotationMirror(getContext().getTruffleTypes().getNodeInfoAnnotation());
+            if (shortName != null) {
+                nodeInfoMirror.setElementValue(nodeInfoMirror.findExecutableElement("shortName"), new CodeAnnotationValue(shortName));
+            }
+
+            DeclaredType nodeinfoKind = getContext().getTruffleTypes().getNodeInfoKind();
+            VariableElement kind;
+            if (specialization.isGeneric()) {
+                kind = Utils.findVariableElement(nodeinfoKind, "GENERIC");
+            } else if (specialization.isUninitialized()) {
+                kind = Utils.findVariableElement(nodeinfoKind, "UNINITIALIZED");
+            } else {
+                kind = Utils.findVariableElement(nodeinfoKind, "SPECIALIZED");
+            }
+
+            nodeInfoMirror.setElementValue(nodeInfoMirror.findExecutableElement("kind"), new CodeAnnotationValue(kind));
+
+            clazz.getAnnotationMirrors().add(nodeInfoMirror);
+
             return clazz;
         }
 
@@ -1373,12 +1394,13 @@
 
             CodeTreeBuilder builder = new CodeTreeBuilder(parent);
 
-            ExecutableTypeData foundEvaluatedPrimaryType = findFunctionalExecutableType(specialization, execType.getEvaluatedCount());
+            List<ExecutableTypeData> primaryExecutes = findFunctionalExecutableType(specialization, execType.getEvaluatedCount());
 
-            if (execType == foundEvaluatedPrimaryType || foundEvaluatedPrimaryType == null) {
+            if (primaryExecutes.contains(execType) || primaryExecutes.isEmpty()) {
                 builder.tree(createFunctionalExecute(builder, specialization, execType));
             } else if (needsCastingExecuteMethod(execType, primaryType)) {
-                builder.tree(createCastingExecute(builder, specialization, execType, foundEvaluatedPrimaryType));
+                assert !primaryExecutes.isEmpty();
+                builder.tree(createCastingExecute(builder, specialization, execType, primaryExecutes.get(0)));
             } else {
                 return null;
             }
@@ -1420,7 +1442,7 @@
             return false;
         }
 
-        private ExecutableTypeData findFunctionalExecutableType(SpecializationData specialization, int evaluatedCount) {
+        private List<ExecutableTypeData> findFunctionalExecutableType(SpecializationData specialization, int evaluatedCount) {
             TypeData primaryType = specialization.getReturnType().getTypeSystemType();
             List<ExecutableTypeData> otherTypes = specialization.getNode().getExecutableTypes(evaluatedCount);
 
@@ -1432,19 +1454,24 @@
                 filteredTypes.add(compareType);
             }
 
-            for (ExecutableTypeData compareType : filteredTypes) {
-                if (compareType.startsWithSignature(specialization)) {
-                    return compareType;
+            // no direct matches found use generic where the type is Object
+            if (filteredTypes.isEmpty()) {
+                for (ExecutableTypeData compareType : otherTypes) {
+                    if (compareType.getType().isGeneric() && !compareType.hasUnexpectedValue(getContext())) {
+                        filteredTypes.add(compareType);
+                    }
                 }
             }
 
-            for (ExecutableTypeData compareType : otherTypes) {
-                if (compareType.startsWithSignature(specialization)) {
-                    return compareType;
+            if (filteredTypes.isEmpty()) {
+                for (ExecutableTypeData compareType : otherTypes) {
+                    if (compareType.getType().isGeneric()) {
+                        filteredTypes.add(compareType);
+                    }
                 }
             }
 
-            return null;
+            return filteredTypes;
         }
 
         private CodeTree createCastingExecute(CodeTreeBuilder parent, SpecializationData specialization, ExecutableTypeData executable, ExecutableTypeData castExecutable) {
--- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeData.java	Tue May 21 12:39:40 2013 +0200
+++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeData.java	Tue May 21 19:51:00 2013 +0200
@@ -51,6 +51,8 @@
     private List<ShortCircuitData> shortCircuits;
     private List<String> assumptions;
 
+    private String shortName;
+
     public NodeData(TypeElement type, String id) {
         super(type, null, null);
         this.nodeId = id;
@@ -72,6 +74,14 @@
         this.assumptions = splitSource.assumptions;
     }
 
+    void setShortName(String shortName) {
+        this.shortName = shortName;
+    }
+
+    public String getShortName() {
+        return shortName;
+    }
+
     public boolean isSplitByMethodName() {
         return splitByMethodName;
     }
--- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeParser.java	Tue May 21 12:39:40 2013 +0200
+++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeParser.java	Tue May 21 19:51:00 2013 +0200
@@ -32,6 +32,7 @@
 
 import com.oracle.truffle.api.codegen.*;
 import com.oracle.truffle.api.codegen.NodeClass.InheritNode;
+import com.oracle.truffle.api.nodes.*;
 import com.oracle.truffle.codegen.processor.*;
 import com.oracle.truffle.codegen.processor.node.NodeChildData.Cardinality;
 import com.oracle.truffle.codegen.processor.node.NodeChildData.ExecutionKind;
@@ -577,6 +578,11 @@
                 }
             }
         }
+        AnnotationMirror nodeInfoMirror = findFirstAnnotation(lookupTypes, NodeInfo.class);
+        if (nodeInfoMirror != null) {
+            nodeData.setShortName(Utils.getAnnotationValue(String.class, nodeInfoMirror, "shortName"));
+        }
+
         nodeData.setAssumptions(new ArrayList<>(assumptionsList));
         nodeData.setNodeType(nodeType);
         nodeData.setSplitByMethodName(splitByMethodName);
--- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/template/ParameterSpec.java	Tue May 21 12:39:40 2013 +0200
+++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/template/ParameterSpec.java	Tue May 21 19:51:00 2013 +0200
@@ -55,6 +55,16 @@
         this.allowedTypes = allowedTypes;
     }
 
+    public ParameterSpec(ParameterSpec o, List<TypeMirror> allowedTypes) {
+        this.name = o.name;
+        this.cardinality = o.cardinality;
+        this.signature = o.signature;
+        this.indexed = o.indexed;
+        this.local = o.local;
+        this.typeDefinition = o.typeDefinition;
+        this.allowedTypes = allowedTypes;
+    }
+
     void setTypeDefinition(TypeDef typeDefinition) {
         this.typeDefinition = typeDefinition;
     }