# HG changeset patch # User Doug Simon # Date 1423818065 -3600 # Node ID 2b392a92e27b3f83ed56f0fa24cb65ab60f6aa19 # Parent 0d85421cb5d67f8d0b295ace44a7f4b521c40dfa made it explicit that a StructuredGraph only records method dependencies for inlined methods - the root method is not recorded as it is already available in the 'method' field diff -r 0d85421cb5d6 -r 2b392a92e27b graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java Thu Feb 12 17:25:50 2015 -0800 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java Fri Feb 13 10:01:05 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 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 getMethods() { - return methods == null ? Collections.emptyList() : Arrays.asList(methods); + return methods == null ? null : Arrays.asList(methods); } public DataSection getDataSection() { diff -r 0d85421cb5d6 -r 2b392a92e27b graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Thu Feb 12 17:25:50 2015 -0800 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Fri Feb 13 10:01:05 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 methods, LIRGenerationResult lirGenRes, CompilationResult compilationResult, - ResolvedJavaMethod installedCodeOwner, CompilationResultBuilderFactory factory) { + public static void emitCode(Backend backend, Assumptions assumptions, ResolvedJavaMethod rootMethod, Set 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()) { diff -r 0d85421cb5d6 -r 2b392a92e27b 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 Thu Feb 12 17:25:50 2015 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Fri Feb 13 10:01:05 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 diff -r 0d85421cb5d6 -r 2b392a92e27b graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledRuntimeStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledRuntimeStub.java Thu Feb 12 17:25:50 2015 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledRuntimeStub.java Fri Feb 13 10:01:05 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) { diff -r 0d85421cb5d6 -r 2b392a92e27b graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/ForeignCallStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/ForeignCallStub.java Thu Feb 12 17:25:50 2015 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/ForeignCallStub.java Fri Feb 13 10:01:05 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); diff -r 0d85421cb5d6 -r 2b392a92e27b 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 Thu Feb 12 17:25:50 2015 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/Stub.java Fri Feb 13 10:01:05 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)); diff -r 0d85421cb5d6 -r 2b392a92e27b graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Thu Feb 12 17:25:50 2015 -0800 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Fri Feb 13 10:01:05 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); } } diff -r 0d85421cb5d6 -r 2b392a92e27b graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StructuredGraph.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StructuredGraph.java Thu Feb 12 17:25:50 2015 -0800 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StructuredGraph.java Fri Feb 13 10:01:05 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 methods = new HashSet<>(); + private Set 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 getMethods() { - return methods; + public Set getInlinedMethods() { + return inlinedMethods; } } diff -r 0d85421cb5d6 -r 2b392a92e27b graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningUtil.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningUtil.java Thu Feb 12 17:25:50 2015 -0800 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningUtil.java Fri Feb 13 10:01:05 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; diff -r 0d85421cb5d6 -r 2b392a92e27b graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/AbstractInlineInfo.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/AbstractInlineInfo.java Thu Feb 12 17:25:50 2015 -0800 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/AbstractInlineInfo.java Fri Feb 13 10:01:05 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; } diff -r 0d85421cb5d6 -r 2b392a92e27b graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/elem/InlineableGraph.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/elem/InlineableGraph.java Thu Feb 12 17:25:50 2015 -0800 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/elem/InlineableGraph.java Fri Feb 13 10:01:05 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); diff -r 0d85421cb5d6 -r 2b392a92e27b graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java Thu Feb 12 17:25:50 2015 -0800 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java Fri Feb 13 10:01:05 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(); diff -r 0d85421cb5d6 -r 2b392a92e27b graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java Thu Feb 12 17:25:50 2015 -0800 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java Fri Feb 13 10:01:05 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 nodeReplacements = Node.newIdentityMap(); diff -r 0d85421cb5d6 -r 2b392a92e27b graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java Thu Feb 12 17:25:50 2015 -0800 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java Fri Feb 13 10:01:05 2015 +0100 @@ -166,9 +166,8 @@ compilationNotify.notifyCompilationGraalTierFinished((OptimizedCallTarget) predefinedInstalledCode, graph); - if (graph.isMethodRecordingEnabled()) { - Set 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; }