# HG changeset patch # User Christian Wirth # Date 1405589156 -7200 # Node ID 1e8b758800fbfa6782b4a0e4f541ba3777e493f0 # Parent eb3209d37c506a14cee27c319931249483936a9a extract methods in TruffleCacheImpl diff -r eb3209d37c50 -r 1e8b758800fb graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCacheImpl.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCacheImpl.java Thu Jul 17 11:21:36 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCacheImpl.java Thu Jul 17 11:25:56 2014 +0200 @@ -29,6 +29,7 @@ import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; +import com.oracle.graal.compiler.common.*; import com.oracle.graal.debug.*; import com.oracle.graal.debug.Debug.Scope; import com.oracle.graal.graph.Graph.Mark; @@ -97,7 +98,6 @@ return graph; } - @SuppressWarnings("unused") public StructuredGraph lookup(final ResolvedJavaMethod method, final NodeInputList arguments, final Assumptions assumptions, final CanonicalizerPhase finalCanonicalizer, boolean ignoreSlowPath) { @@ -124,24 +124,7 @@ } if (lastUsed.values().size() >= TruffleCompilerOptions.TruffleMaxCompilationCacheSize.getValue()) { - List lastUsedList = new ArrayList<>(); - for (long l : lastUsed.values()) { - lastUsedList.add(l); - } - Collections.sort(lastUsedList); - long mid = lastUsedList.get(lastUsedList.size() / 2); - - List> toRemoveList = new ArrayList<>(); - for (Entry, Long> entry : lastUsed.entrySet()) { - if (entry.getValue() < mid) { - toRemoveList.add(entry.getKey()); - } - } - - for (List entry : toRemoveList) { - cache.remove(entry); - lastUsed.remove(entry); - } + lookupExceedsMaxSize(); } lastUsed.put(key, counter++); @@ -183,42 +166,11 @@ boolean inliningProgress = false; for (MethodCallTargetNode methodCallTarget : graph.getNodes(MethodCallTargetNode.class)) { if (!graph.getMark().equals(mark)) { - // Make sure macro substitutions such as - // CompilerDirectives.transferToInterpreter get processed first. - for (Node newNode : graph.getNewNodes(mark)) { - if (newNode instanceof MethodCallTargetNode) { - MethodCallTargetNode methodCallTargetNode = (MethodCallTargetNode) newNode; - Class macroSubstitution = providers.getReplacements().getMacroSubstitution(methodCallTargetNode.targetMethod()); - if (macroSubstitution != null) { - InliningUtil.inlineMacroNode(methodCallTargetNode.invoke(), methodCallTargetNode.targetMethod(), macroSubstitution); - } else { - tryCutOffRuntimeExceptionsAndErrors(methodCallTargetNode); - } - } - } - mark = graph.getMark(); + mark = lookupProcessMacroSubstitutions(graph, mark); } if (methodCallTarget.isAlive() && methodCallTarget.invoke() != null && shouldInline(methodCallTarget)) { inliningProgress = true; - List canonicalizerUsages = new ArrayList(); - for (Node n : methodCallTarget.invoke().asNode().usages()) { - if (n instanceof Canonicalizable) { - canonicalizerUsages.add(n); - } - } - List argumentSnapshot = methodCallTarget.arguments().snapshot(); - Mark beforeInvokeMark = graph.getMark(); - expandInvoke(methodCallTarget); - for (Node arg : argumentSnapshot) { - if (arg != null && arg.recordsUsages()) { - for (Node argUsage : arg.usages()) { - if (graph.isNew(beforeInvokeMark, argUsage) && argUsage instanceof Canonicalizable) { - canonicalizerUsages.add(argUsage); - } - } - } - } - canonicalizerPhase.applyIncremental(graph, phaseContext, canonicalizerUsages); + lookupDoInline(graph, phaseContext, canonicalizerPhase, methodCallTarget); } } @@ -240,7 +192,66 @@ } catch (Throwable e) { throw Debug.handle(e); } + } + private void lookupExceedsMaxSize() { + List lastUsedList = new ArrayList<>(); + for (long l : lastUsed.values()) { + lastUsedList.add(l); + } + Collections.sort(lastUsedList); + long mid = lastUsedList.get(lastUsedList.size() / 2); + + List> toRemoveList = new ArrayList<>(); + for (Entry, Long> entry : lastUsed.entrySet()) { + if (entry.getValue() < mid) { + toRemoveList.add(entry.getKey()); + } + } + + for (List entry : toRemoveList) { + cache.remove(entry); + lastUsed.remove(entry); + } + } + + private Mark lookupProcessMacroSubstitutions(final StructuredGraph graph, Mark mark) throws GraalInternalError { + // Make sure macro substitutions such as + // CompilerDirectives.transferToInterpreter get processed first. + for (Node newNode : graph.getNewNodes(mark)) { + if (newNode instanceof MethodCallTargetNode) { + MethodCallTargetNode methodCallTargetNode = (MethodCallTargetNode) newNode; + Class macroSubstitution = providers.getReplacements().getMacroSubstitution(methodCallTargetNode.targetMethod()); + if (macroSubstitution != null) { + InliningUtil.inlineMacroNode(methodCallTargetNode.invoke(), methodCallTargetNode.targetMethod(), macroSubstitution); + } else { + tryCutOffRuntimeExceptionsAndErrors(methodCallTargetNode); + } + } + } + return graph.getMark(); + } + + private void lookupDoInline(final StructuredGraph graph, final PhaseContext phaseContext, CanonicalizerPhase canonicalizerPhase, MethodCallTargetNode methodCallTarget) { + List canonicalizerUsages = new ArrayList<>(); + for (Node n : methodCallTarget.invoke().asNode().usages()) { + if (n instanceof Canonicalizable) { + canonicalizerUsages.add(n); + } + } + List argumentSnapshot = methodCallTarget.arguments().snapshot(); + Mark beforeInvokeMark = graph.getMark(); + expandInvoke(methodCallTarget); + for (Node arg : argumentSnapshot) { + if (arg != null && arg.recordsUsages()) { + for (Node argUsage : arg.usages()) { + if (graph.isNew(beforeInvokeMark, argUsage) && argUsage instanceof Canonicalizable) { + canonicalizerUsages.add(argUsage); + } + } + } + } + canonicalizerPhase.applyIncremental(graph, phaseContext, canonicalizerUsages); } private void expandInvoke(MethodCallTargetNode methodCallTargetNode) {