changeset 19352:dd7d436a7e19

Merge
author Paul Woegerer <paul.woegerer@oracle.com>
date Fri, 13 Feb 2015 12:00:26 +0100
parents ef292a5bb79d (diff) 78510d27786b (current diff)
children 343e0e71031b
files
diffstat 18 files changed, 125 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java	Fri Feb 13 11:54:02 2015 +0100
+++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java	Fri Feb 13 12:00:26 2015 +0100
@@ -532,7 +532,9 @@
     private Assumption[] assumptions;
 
     /**
-     * The list of the methods whose bytecodes were used as input to the compilation.
+     * The list of the methods whose bytecodes were used as input to the compilation. If
+     * {@code null}, then the compilation did not record method dependencies. Otherwise, the first
+     * element of this array is the root method of the compilation.
      */
     private ResolvedJavaMethod[] methods;
 
@@ -552,6 +554,9 @@
 
     @Override
     public String toString() {
+        if (methods != null) {
+            return getClass().getName() + "[" + methods[0].format("%H.%n(%p)%r") + "]";
+        }
         return identityHashCodeString(this);
     }
 
@@ -629,17 +634,45 @@
 
     /**
      * Sets the methods whose bytecodes were used as input to the compilation.
+     *
+     * @param rootMethod the root method of the compilation
+     * @param inlinedMethods the methods inlined during compilation
      */
-    public void setMethods(ResolvedJavaMethod[] methods) {
-        this.methods = methods;
+    public void setMethods(ResolvedJavaMethod rootMethod, Collection<ResolvedJavaMethod> inlinedMethods) {
+        assert rootMethod != null;
+        assert inlinedMethods != null;
+        if (inlinedMethods.contains(rootMethod)) {
+            methods = inlinedMethods.toArray(new ResolvedJavaMethod[inlinedMethods.size()]);
+            for (int i = 0; i < methods.length; i++) {
+                if (methods[i].equals(rootMethod)) {
+                    if (i != 0) {
+                        ResolvedJavaMethod tmp = methods[0];
+                        methods[0] = methods[i];
+                        methods[i] = tmp;
+                    }
+                    break;
+                }
+            }
+        } else {
+            methods = new ResolvedJavaMethod[1 + inlinedMethods.size()];
+            methods[0] = rootMethod;
+            int i = 1;
+            for (ResolvedJavaMethod m : inlinedMethods) {
+                methods[i++] = m;
+            }
+        }
     }
 
     /**
      * Gets a fixed-size {@linkplain Arrays#asList(Object...) view} of the methods whose bytecodes
      * were used as input to the compilation.
+     *
+     * @return {@code null} if the compilation did not record method dependencies otherwise the
+     *         methods whose bytecodes were used as input to the compilation with the first element
+     *         being the root method of the compilation
      */
     public Collection<ResolvedJavaMethod> getMethods() {
-        return methods == null ? Collections.emptyList() : Arrays.asList(methods);
+        return methods == null ? null : Arrays.asList(methods);
     }
 
     public DataSection getDataSection() {
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java	Fri Feb 13 11:54:02 2015 +0100
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java	Fri Feb 13 12:00:26 2015 +0100
@@ -280,7 +280,7 @@
             LIRGenerationResult lirGen = null;
             lirGen = emitLIR(backend, target, schedule, graph, stub, cc, registerConfig, lirSuites);
             try (Scope s = Debug.scope("CodeGen", lirGen, lirGen.getLIR())) {
-                emitCode(backend, graph.getAssumptions(), graph.getMethods(), lirGen, compilationResult, installedCodeOwner, factory);
+                emitCode(backend, graph.getAssumptions(), graph.method(), graph.getInlinedMethods(), lirGen, compilationResult, installedCodeOwner, factory);
             } catch (Throwable e) {
                 throw Debug.handle(e);
             }
@@ -364,8 +364,8 @@
         return lirGenRes;
     }
 
-    public static void emitCode(Backend backend, Assumptions assumptions, Set<ResolvedJavaMethod> methods, LIRGenerationResult lirGenRes, CompilationResult compilationResult,
-                    ResolvedJavaMethod installedCodeOwner, CompilationResultBuilderFactory factory) {
+    public static void emitCode(Backend backend, Assumptions assumptions, ResolvedJavaMethod rootMethod, Set<ResolvedJavaMethod> inlinedMethods, LIRGenerationResult lirGenRes,
+                    CompilationResult compilationResult, ResolvedJavaMethod installedCodeOwner, CompilationResultBuilderFactory factory) {
         FrameMap frameMap = lirGenRes.getFrameMap();
         CompilationResultBuilder crb = backend.newCompilationResultBuilder(lirGenRes, frameMap, compilationResult, factory);
         backend.emitCode(crb, lirGenRes.getLIR(), installedCodeOwner);
@@ -373,8 +373,8 @@
         if (assumptions != null && !assumptions.isEmpty()) {
             compilationResult.setAssumptions(assumptions.toArray());
         }
-        if (methods != null) {
-            compilationResult.setMethods(methods.toArray(new ResolvedJavaMethod[methods.size()]));
+        if (inlinedMethods != null) {
+            compilationResult.setMethods(rootMethod, inlinedMethods);
         }
 
         if (Debug.isMeterEnabled()) {
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java	Fri Feb 13 11:54:02 2015 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java	Fri Feb 13 12:00:26 2015 +0100
@@ -208,7 +208,7 @@
                 if (graph == null || entryBCI != INVOCATION_ENTRY_BCI) {
                     graph = new StructuredGraph(method, entryBCI, AllowAssumptions.from(OptAssumptions.getValue()));
                     if (!recordEvolMethodDeps) {
-                        graph.disableMethodRecording();
+                        graph.disableInlinedMethodRecording();
                     }
                 } else {
                     // Compiling method substitution - must clone the graph
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledRuntimeStub.java	Fri Feb 13 11:54:02 2015 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledRuntimeStub.java	Fri Feb 13 12:00:26 2015 +0100
@@ -56,7 +56,7 @@
         // Stubs cannot be recompiled so they cannot be compiled with
         // assumptions and there is no point in recording evol_method dependencies
         assert compResult.getAssumptions().isEmpty() : "stubs should not use assumptions: " + this;
-        assert compResult.getMethods().isEmpty() : "stubs should not record evol_method dependencies: " + this;
+        assert compResult.getMethods() == null : "stubs should not record evol_method dependencies: " + this;
 
         for (DataPatch data : compResult.getDataPatches()) {
             if (data.reference instanceof ConstantReference) {
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/ForeignCallStub.java	Fri Feb 13 11:54:02 2015 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/ForeignCallStub.java	Fri Feb 13 12:00:26 2015 +0100
@@ -192,7 +192,7 @@
         boolean isObjectResult = linkage.getOutgoingCallingConvention().getReturn().getKind() == Kind.Object;
 
         StructuredGraph graph = new StructuredGraph(toString(), null, AllowAssumptions.NO);
-        graph.disableMethodRecording();
+        graph.disableInlinedMethodRecording();
 
         GraphKit kit = new HotSpotGraphKit(graph, providers);
         ParameterNode[] params = createParameters(kit, args);
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/Stub.java	Fri Feb 13 11:54:02 2015 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/Stub.java	Fri Feb 13 12:00:26 2015 +0100
@@ -161,7 +161,7 @@
                 // Stubs cannot be recompiled so they cannot be compiled with
                 // assumptions and there is no point in recording evol_method dependencies
                 assert graph.getAssumptions() == null;
-                assert !graph.isMethodRecordingEnabled() : graph;
+                assert !graph.isInlinedMethodRecordingEnabled() : graph;
 
                 if (!(graph.start() instanceof StubStartNode)) {
                     StubStartNode newStart = graph.add(new StubStartNode(Stub.this));
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Fri Feb 13 11:54:02 2015 +0100
+++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Fri Feb 13 12:00:26 2015 +0100
@@ -971,9 +971,9 @@
                     calleeBeforeUnwindNode.setNext(handleException(calleeUnwindValue, bci()));
                 }
 
-                // Record method dependency in the graph
-                if (currentGraph.isMethodRecordingEnabled()) {
-                    currentGraph.getMethods().add(targetMethod);
+                // Record inlined method dependency in the graph
+                if (currentGraph.isInlinedMethodRecordingEnabled()) {
+                    currentGraph.getInlinedMethods().add(targetMethod);
                 }
             }
 
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StructuredGraph.java	Fri Feb 13 11:54:02 2015 +0100
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StructuredGraph.java	Fri Feb 13 12:00:26 2015 +0100
@@ -112,9 +112,9 @@
     private final Assumptions assumptions;
 
     /**
-     * The methods whose bytecodes are used while constructing this graph.
+     * The methods that were inlined while constructing this graph.
      */
-    private Set<ResolvedJavaMethod> methods = new HashSet<>();
+    private Set<ResolvedJavaMethod> inlinedMethods = new HashSet<>();
 
     /**
      * Creates a new Graph containing a single {@link AbstractBeginNode} as the {@link #start()
@@ -220,16 +220,16 @@
     }
 
     public StructuredGraph copy(String newName, ResolvedJavaMethod newMethod) {
-        return copy(newName, newMethod, AllowAssumptions.from(assumptions != null), isMethodRecordingEnabled());
+        return copy(newName, newMethod, AllowAssumptions.from(assumptions != null), isInlinedMethodRecordingEnabled());
     }
 
-    public StructuredGraph copy(String newName, ResolvedJavaMethod newMethod, AllowAssumptions allowAssumptions, boolean enableMethodRecording) {
+    public StructuredGraph copy(String newName, ResolvedJavaMethod newMethod, AllowAssumptions allowAssumptions, boolean enableInlinedMethodRecording) {
         StructuredGraph copy = new StructuredGraph(newName, newMethod, graphId, entryBCI, allowAssumptions);
         if (allowAssumptions == AllowAssumptions.YES && assumptions != null) {
             copy.assumptions.record(assumptions);
         }
-        if (!enableMethodRecording) {
-            copy.disableMethodRecording();
+        if (!enableInlinedMethodRecording) {
+            copy.disableInlinedMethodRecording();
         }
         copy.setGuardsStage(getGuardsStage());
         copy.isAfterFloatingReadPhase = isAfterFloatingReadPhase;
@@ -512,26 +512,26 @@
     }
 
     /**
-     * Disables recording of method used while constructing this graph. This can be done at most
-     * once and must be done before any methods are recorded.
+     * Disables recording of methods inlined while constructing this graph. This can be done at most
+     * once and must be done before any inlined methods are recorded.
      */
-    public void disableMethodRecording() {
-        assert methods != null : "cannot disable method recording more than once";
-        assert methods.isEmpty() : "cannot disable method recording once methods have been recorded";
-        methods = null;
+    public void disableInlinedMethodRecording() {
+        assert inlinedMethods != null : "cannot disable inlined method recording more than once";
+        assert inlinedMethods.isEmpty() : "cannot disable inlined method recording once methods have been recorded";
+        inlinedMethods = null;
     }
 
-    public boolean isMethodRecordingEnabled() {
-        return methods != null;
+    public boolean isInlinedMethodRecordingEnabled() {
+        return inlinedMethods != null;
     }
 
     /**
-     * Gets the methods whose bytecodes are used while constructing this graph.
+     * Gets the methods that were inlined while constructing this graph.
      *
-     * @return {@code null} if method recording has been {@linkplain #disableMethodRecording()
-     *         disabled}
+     * @return {@code null} if inlined method recording has been
+     *         {@linkplain #disableInlinedMethodRecording() disabled}
      */
-    public Set<ResolvedJavaMethod> getMethods() {
-        return methods;
+    public Set<ResolvedJavaMethod> getInlinedMethods() {
+        return inlinedMethods;
     }
 }
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningUtil.java	Fri Feb 13 11:54:02 2015 +0100
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningUtil.java	Fri Feb 13 12:00:26 2015 +0100
@@ -373,9 +373,9 @@
             assert inlineGraph.getAssumptions() == null : "cannot inline graph which makes assumptions into a graph that doesn't: " + inlineGraph + " -> " + graph;
         }
 
-        // Copy method dependencies from inlinee to caller
-        if (inlineGraph.isMethodRecordingEnabled() && graph.isMethodRecordingEnabled()) {
-            graph.getMethods().addAll(inlineGraph.getMethods());
+        // Copy inlined methods from inlinee to caller
+        if (inlineGraph.isInlinedMethodRecordingEnabled() && graph.isInlinedMethodRecordingEnabled()) {
+            graph.getInlinedMethods().addAll(inlineGraph.getInlinedMethods());
         }
 
         return duplicates;
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/AbstractInlineInfo.java	Fri Feb 13 11:54:02 2015 +0100
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/AbstractInlineInfo.java	Fri Feb 13 12:00:26 2015 +0100
@@ -66,8 +66,8 @@
 
         InliningUtil.InlinedBytecodes.add(concrete.getCodeSize());
         StructuredGraph graph = invoke.asNode().graph();
-        if (graph.isMethodRecordingEnabled()) {
-            graph.getMethods().add(concrete);
+        if (graph.isInlinedMethodRecordingEnabled()) {
+            graph.getInlinedMethods().add(concrete);
         }
         return canonicalizeNodes;
     }
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/elem/InlineableGraph.java	Fri Feb 13 11:54:02 2015 +0100
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/elem/InlineableGraph.java	Fri Feb 13 12:00:26 2015 +0100
@@ -201,12 +201,12 @@
     private static StructuredGraph parseBytecodes(ResolvedJavaMethod method, HighTierContext context, CanonicalizerPhase canonicalizer, StructuredGraph caller) {
         StructuredGraph newGraph = new StructuredGraph(method, AllowAssumptions.from(caller.getAssumptions() != null));
         try (Debug.Scope s = Debug.scope("InlineGraph", newGraph)) {
-            if (!caller.isMethodRecordingEnabled()) {
-                // Don't record method dependencies in the inlinee if
+            if (!caller.isInlinedMethodRecordingEnabled()) {
+                // Don't record inlined methods in the callee if
                 // the caller doesn't want them. This decision is
                 // preserved in the graph cache (if used) which is
                 // ok since the graph cache is compilation local.
-                newGraph.disableMethodRecording();
+                newGraph.disableInlinedMethodRecording();
             }
             if (context.getGraphBuilderSuite() != null) {
                 context.getGraphBuilderSuite().apply(newGraph, context);
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java	Fri Feb 13 11:54:02 2015 +0100
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java	Fri Feb 13 12:00:26 2015 +0100
@@ -612,7 +612,7 @@
             final StructuredGraph graph = new StructuredGraph(methodToParse, AllowAssumptions.NO);
 
             // They will also never be never be evolved or have breakpoints set in them
-            graph.disableMethodRecording();
+            graph.disableInlinedMethodRecording();
 
             try (Scope s = Debug.scope("buildInitialGraph", graph)) {
                 MetaAccessProvider metaAccess = replacements.providers.getMetaAccess();
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java	Fri Feb 13 11:54:02 2015 +0100
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java	Fri Feb 13 12:00:26 2015 +0100
@@ -566,8 +566,8 @@
 
         // Copy snippet graph, replacing constant parameters with given arguments
         final StructuredGraph snippetCopy = new StructuredGraph(snippetGraph.name, snippetGraph.method(), AllowAssumptions.NO);
-        if (!snippetGraph.isMethodRecordingEnabled()) {
-            snippetCopy.disableMethodRecording();
+        if (!snippetGraph.isInlinedMethodRecordingEnabled()) {
+            snippetCopy.disableInlinedMethodRecording();
         }
 
         Map<Node, Node> nodeReplacements = Node.newIdentityMap();
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java	Fri Feb 13 11:54:02 2015 +0100
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java	Fri Feb 13 12:00:26 2015 +0100
@@ -166,9 +166,8 @@
 
         compilationNotify.notifyCompilationGraalTierFinished((OptimizedCallTarget) predefinedInstalledCode, graph);
 
-        if (graph.isMethodRecordingEnabled()) {
-            Set<ResolvedJavaMethod> methods = graph.getMethods();
-            result.setMethods(methods.toArray(new ResolvedJavaMethod[methods.size()]));
+        if (graph.isInlinedMethodRecordingEnabled()) {
+            result.setMethods(graph.method(), graph.getInlinedMethods());
         } else {
             assert result.getMethods() == null;
         }
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/expression/DSLExpression.java	Fri Feb 13 11:54:02 2015 +0100
+++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/expression/DSLExpression.java	Fri Feb 13 12:00:26 2015 +0100
@@ -23,6 +23,7 @@
 package com.oracle.truffle.dsl.processor.expression;
 
 import java.util.*;
+import java.util.concurrent.atomic.*;
 
 import javax.lang.model.element.*;
 import javax.lang.model.type.*;
@@ -68,6 +69,19 @@
         return variables;
     }
 
+    public boolean containsComparisons() {
+        final AtomicBoolean found = new AtomicBoolean();
+        this.accept(new AbstractDSLExpressionVisitor() {
+            @Override
+            public void visitBinary(Binary binary) {
+                if (binary.isComparison()) {
+                    found.set(true);
+                }
+            }
+        });
+        return found.get();
+    }
+
     public void setResolvedTargetType(TypeMirror resolvedTargetType) {
         this.resolvedTargetType = resolvedTargetType;
     }
@@ -131,6 +145,10 @@
             this.right = right;
         }
 
+        public boolean isComparison() {
+            return DSLExpressionResolver.COMPARABLE_OPERATORS.contains(operator) || DSLExpressionResolver.IDENTITY_OPERATORS.contains(operator);
+        }
+
         @Override
         public boolean equals(Object obj) {
             if (obj instanceof Binary) {
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/expression/DSLExpressionResolver.java	Fri Feb 13 11:54:02 2015 +0100
+++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/expression/DSLExpressionResolver.java	Fri Feb 13 12:00:26 2015 +0100
@@ -41,8 +41,8 @@
 public class DSLExpressionResolver implements DSLExpressionVisitor {
 
     private static final List<String> LOGIC_OPERATORS = Arrays.asList("||");
-    private static final List<String> COMPARABLE_OPERATORS = Arrays.asList("<", "<=", ">", ">=");
-    private static final List<String> IDENTITY_OPERATORS = Arrays.asList("==", "!=");
+    public static final List<String> COMPARABLE_OPERATORS = Arrays.asList("<", "<=", ">", ">=");
+    public static final List<String> IDENTITY_OPERATORS = Arrays.asList("==", "!=");
     private static final String CONSTRUCTOR_KEYWORD = "new";
 
     private final List<VariableElement> variables = new ArrayList<>();
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeGenFactory.java	Fri Feb 13 11:54:02 2015 +0100
+++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeGenFactory.java	Fri Feb 13 12:00:26 2015 +0100
@@ -213,6 +213,8 @@
         }
         clazz.add(createGetCostMethod());
 
+        avoidFindbugsProblems(clazz);
+
         if (singleSpecializable) {
             if (node.needsRewrites(context)) {
                 clazz.add(createUnsupportedMethod());
@@ -236,6 +238,28 @@
         return clazz;
     }
 
+    private void avoidFindbugsProblems(CodeTypeElement clazz) {
+        TypeElement type = context.getEnvironment().getElementUtils().getTypeElement("edu.umd.cs.findbugs.annotations.SuppressFBWarnings");
+        if (type == null) {
+            return;
+        }
+        boolean foundComparison = false;
+        outer: for (SpecializationData specialization : node.getSpecializations()) {
+            for (GuardExpression guard : specialization.getGuards()) {
+                if (guard.getExpression().containsComparisons()) {
+                    foundComparison = true;
+                    break outer;
+                }
+            }
+        }
+
+        if (foundComparison) {
+            CodeAnnotationMirror annotation = new CodeAnnotationMirror((DeclaredType) type.asType());
+            annotation.setElementValue(annotation.findExecutableElement("value"), new CodeAnnotationValue("SA_LOCAL_SELF_COMPARISON"));
+            clazz.addAnnotationMirror(annotation);
+        }
+    }
+
     private Element createUnsupportedMethod() {
         LocalContext locals = LocalContext.load(this);
         CodeExecutableElement method = locals.createMethod(modifiers(PROTECTED), getType(UnsupportedSpecializationException.class), "unsupported");
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/NodeParser.java	Fri Feb 13 11:54:02 2015 +0100
+++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/NodeParser.java	Fri Feb 13 12:00:26 2015 +0100
@@ -1126,10 +1126,6 @@
     }
 
     private void initializeGeneric(final NodeData node) {
-        if (!node.needsRewrites(context)) {
-            return;
-        }
-
         List<SpecializationData> generics = new ArrayList<>();
         for (SpecializationData spec : node.getSpecializations()) {
             if (spec.isFallback()) {