Mercurial > hg > graal-compiler
changeset 14172:cd22c8dbda4f
Made graph caching compilation local
line wrap: on
line diff
--- a/CHANGELOG.md Thu Mar 13 14:48:01 2014 +0100 +++ b/CHANGELOG.md Thu Mar 13 15:36:30 2014 +0100 @@ -3,7 +3,8 @@ ## `tip` ### Graal * New methods for querying memory usage of individual objects and object graphs in Graal API (MetaAccessProvider#getMemorySize, MetaUtil#getMemorySizeRecursive). -* ... +* New (tested) invariant that equality comparisons for JavaType/JavaMethod/JavaField values use .equals() instead of '=='. +* Made graph caching compilation-local. ### Truffle * ...
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java Thu Mar 13 14:48:01 2014 +0100 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java Thu Mar 13 15:36:30 2014 +0100 @@ -464,13 +464,6 @@ private Assumptions assumptions; - /** - * The leafGraphIds will contain the StructuredGraph.graphId()s of the graphs that were - * incorporated into this compilation. These ids are later on used by the runtime system to - * evict graphs from the graph cache when deoptimizations occur. - */ - private long[] leafGraphIds; - public CompilationResult() { this(null); } @@ -515,14 +508,6 @@ return assumptions; } - public void setLeafGraphIds(long[] leafGraphIds) { - this.leafGraphIds = leafGraphIds; - } - - public long[] getLeafGraphIds() { - return leafGraphIds; - } - /** * Sets the frame size in bytes. Does not include the return address pushed onto the stack, if * any.
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Thu Mar 13 14:48:01 2014 +0100 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Thu Mar 13 15:36:30 2014 +0100 @@ -30,9 +30,9 @@ import com.oracle.graal.alloc.*; import com.oracle.graal.api.code.*; -import com.oracle.graal.api.code.CompilationResult.*; +import com.oracle.graal.api.code.CompilationResult.DataPatch; import com.oracle.graal.api.meta.*; -import com.oracle.graal.api.meta.ProfilingInfo.*; +import com.oracle.graal.api.meta.ProfilingInfo.TriState; import com.oracle.graal.compiler.alloc.*; import com.oracle.graal.compiler.gen.*; import com.oracle.graal.compiler.target.*; @@ -43,7 +43,6 @@ import com.oracle.graal.lir.asm.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.cfg.*; -import com.oracle.graal.nodes.spi.*; import com.oracle.graal.nodes.util.*; import com.oracle.graal.options.*; import com.oracle.graal.phases.*; @@ -134,8 +133,8 @@ * @return the result of the compilation */ public static <T extends CompilationResult> T compileGraph(StructuredGraph graph, Object stub, CallingConvention cc, ResolvedJavaMethod installedCodeOwner, Providers providers, Backend backend, - TargetDescription target, GraphCache cache, PhaseSuite<HighTierContext> graphBuilderSuite, OptimisticOptimizations optimisticOpts, ProfilingInfo profilingInfo, - SpeculationLog speculationLog, Suites suites, T compilationResult, CompilationResultBuilderFactory factory) { + TargetDescription target, Map<ResolvedJavaMethod, StructuredGraph> cache, PhaseSuite<HighTierContext> graphBuilderSuite, OptimisticOptimizations optimisticOpts, + ProfilingInfo profilingInfo, SpeculationLog speculationLog, Suites suites, T compilationResult, CompilationResultBuilderFactory factory) { assert !graph.isFrozen(); try (Scope s0 = Debug.scope("GraalCompiler", graph, providers.getCodeCache())) { Assumptions assumptions = new Assumptions(OptAssumptions.getValue()); @@ -149,7 +148,7 @@ LIRGenerator lirGen = null; lirGen = emitLIR(backend, target, schedule, graph, stub, cc); try (Scope s = Debug.scope("CodeGen", lirGen)) { - emitCode(backend, getLeafGraphIdArray(graph), assumptions, lirGen, compilationResult, installedCodeOwner, factory); + emitCode(backend, assumptions, lirGen, compilationResult, installedCodeOwner, factory); } catch (Throwable e) { throw Debug.handle(e); } @@ -170,21 +169,11 @@ } } - private static long[] getLeafGraphIdArray(StructuredGraph graph) { - long[] leafGraphIdArray = new long[graph.getLeafGraphIds().size() + 1]; - int i = 0; - leafGraphIdArray[i++] = graph.graphId(); - for (long id : graph.getLeafGraphIds()) { - leafGraphIdArray[i++] = id; - } - return leafGraphIdArray; - } - /** * Builds the graph, optimizes it. */ - public static SchedulePhase emitHIR(Providers providers, TargetDescription target, StructuredGraph graph, Assumptions assumptions, GraphCache cache, PhaseSuite<HighTierContext> graphBuilderSuite, - OptimisticOptimizations optimisticOpts, ProfilingInfo profilingInfo, SpeculationLog speculationLog, Suites suites) { + public static SchedulePhase emitHIR(Providers providers, TargetDescription target, StructuredGraph graph, Assumptions assumptions, Map<ResolvedJavaMethod, StructuredGraph> cache, + PhaseSuite<HighTierContext> graphBuilderSuite, OptimisticOptimizations optimisticOpts, ProfilingInfo profilingInfo, SpeculationLog speculationLog, Suites suites) { if (speculationLog != null) { speculationLog.collectFailedSpeculations(); @@ -294,7 +283,7 @@ } } - public static void emitCode(Backend backend, long[] leafGraphIds, Assumptions assumptions, LIRGenerator lirGen, CompilationResult compilationResult, ResolvedJavaMethod installedCodeOwner, + public static void emitCode(Backend backend, Assumptions assumptions, LIRGenerator lirGen, CompilationResult compilationResult, ResolvedJavaMethod installedCodeOwner, CompilationResultBuilderFactory factory) { CompilationResultBuilder crb = backend.newCompilationResultBuilder(lirGen, compilationResult, factory); backend.emitCode(crb, lirGen.lir, installedCodeOwner); @@ -302,7 +291,6 @@ if (!assumptions.isEmpty()) { compilationResult.setAssumptions(assumptions); } - compilationResult.setLeafGraphIds(leafGraphIds); if (Debug.isMeterEnabled()) { List<DataPatch> ldp = compilationResult.getDataReferences();
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Thu Mar 13 14:48:01 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Thu Mar 13 15:36:30 2014 +0100 @@ -32,6 +32,7 @@ import java.io.*; import java.lang.reflect.*; +import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; @@ -234,9 +235,9 @@ TTY.Filter filter = new TTY.Filter(PrintFilter.getValue(), method); long start = System.currentTimeMillis(); try (Scope s = Debug.scope("Compiling", new DebugDumpScope(String.valueOf(id), true))) { - GraphCache graphCache = backend.getRuntime().getGraphCache(); - if (graphCache != null) { - graphCache.removeStaleGraphs(); + Map<ResolvedJavaMethod, StructuredGraph> graphCache = null; + if (GraalOptions.CacheGraphs.getValue()) { + graphCache = new HashMap<>(); } HotSpotProviders providers = backend.getProviders();
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Thu Mar 13 14:48:01 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Thu Mar 13 15:36:30 2014 +0100 @@ -41,7 +41,6 @@ import com.oracle.graal.hotspot.logging.*; import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.options.*; -import com.oracle.graal.phases.*; import com.oracle.graal.runtime.*; //JaCoCo Exclude @@ -196,8 +195,6 @@ protected/* final */CompilerToVM compilerToVm; protected/* final */VMToCompiler vmToCompiler; - private volatile HotSpotGraphCache cache; - protected final HotSpotVMConfig config; private final HotSpotBackend hostBackend; @@ -254,10 +251,6 @@ } registerBackend(factory.createBackend(this, hostBackend)); } - - if (GraalOptions.CacheGraphs.getValue()) { - cache = new HotSpotGraphCache(compilerToVm); - } } private HotSpotBackend registerBackend(HotSpotBackend backend) { @@ -314,10 +307,6 @@ return hostBackend.getTarget(); } - public HotSpotGraphCache getGraphCache() { - return cache; - } - public CompilerToVM getCompilerToVM() { return compilerToVm; }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Thu Mar 13 14:48:01 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Thu Mar 13 15:36:30 2014 +0100 @@ -275,8 +275,6 @@ Object executeCompiledMethodVarargs(Object[] args, HotSpotInstalledCode hotspotInstalledCode) throws InvalidInstalledCodeException; - long[] getDeoptedLeafGraphIds(); - long[] getLineNumberTable(long metaspaceMethod); long getLocalVariableTableStart(long metaspaceMethod);
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Thu Mar 13 14:48:01 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Thu Mar 13 15:36:30 2014 +0100 @@ -125,9 +125,6 @@ public native Object executeCompiledMethodVarargs(Object[] args, HotSpotInstalledCode hotspotInstalledCode); @Override - public native long[] getDeoptedLeafGraphIds(); - - @Override public native long[] getLineNumberTable(long metaspaceMethod); @Override
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Thu Mar 13 14:48:01 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Thu Mar 13 15:36:30 2014 +0100 @@ -330,9 +330,6 @@ TTY.println(" in %d ms (compiled %d methods)", System.currentTimeMillis() - startTime, compileQueue.getCompletedTaskCount()); } - if (runtime.getGraphCache() != null) { - runtime.getGraphCache().clear(); - } System.gc(); phaseTransition("bootstrap2"); }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphCache.java Thu Mar 13 14:48:01 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,194 +0,0 @@ -/* - * 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. - * - * 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.hotspot.meta; - -import static com.oracle.graal.phases.GraalOptions.*; - -import java.io.*; -import java.lang.ref.*; -import java.util.*; -import java.util.Map.Entry; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.hotspot.bridge.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.spi.*; - -/** - * This class implements the graph caching system for the HotSpot platform. - * - * This implementation does not use a map to store the actual cached graphs. The problem is that - * such maps keep the graph, and therefore the {@link ResolvedJavaMethod} referenced from the graph, - * alive. For some applications and benchmarks this is a problem, e.g., the DaCapoScala "scalatest" - * benchmark will quickly run out of perm gen because of this. - * - * This cannot be solved with a {@code WeakHashMap<ResolvedJavaMethod, Graph>}, since the values - * within the map will keep the keys alive. In order for this to work we would require a weak map in - * which the "strongness" of the value references depends upon the reachability of the keys. - * - * Therefore the graph cache is implemented in such a way that it stores its cache entries within - * the {@link ResolvedJavaMethod}. It uses the {@link ResolvedJavaMethod#getCompilerStorage()} map - * with the HotSpotGraphCache instance as key. The cached graph will be kept alive as long as the - * {@link ResolvedJavaMethod} is alive, but does not prevent the method, and therefore the class, - * from being unloaded. - * - * The {@link #cachedGraphIds} map is used to find the graphs that should be removed because of - * deoptimization, and to enforce the graph cache size restriction. - */ -public class HotSpotGraphCache implements GraphCache { - - private static final PrintStream out = System.out; - - private volatile long hitCounter; - private volatile long missCounter; - private volatile long removeHitCounter; - private volatile long removeCounter; - private volatile long putCounter; - - /** - * An ordered hash map for looking up the methods corresponding to a specific graph id. It - * enforces the maximum graph cache size by removing the oldest (in insertion-order) element if - * the cache gets too big. - */ - private final class LRUCache extends LinkedHashMap<Long, WeakReference<ResolvedJavaMethod>> { - - private static final long serialVersionUID = -3973307040793397840L; - - public LRUCache() { - super(GraphCacheSize.getValue() * 2, 0.75f, false); - } - - @Override - protected boolean removeEldestEntry(Entry<Long, WeakReference<ResolvedJavaMethod>> eldest) { - if (size() > GraphCacheSize.getValue()) { - ResolvedJavaMethod method = eldest.getValue().get(); - if (method != null) { - StructuredGraph cachedGraph = (StructuredGraph) method.getCompilerStorage().get(HotSpotGraphCache.this); - if (cachedGraph != null && cachedGraph.graphId() == eldest.getKey()) { - method.getCompilerStorage().remove(HotSpotGraphCache.this); - } - } - return true; - } else { - return false; - } - } - } - - private final Map<Long, WeakReference<ResolvedJavaMethod>> cachedGraphIds = Collections.synchronizedMap(new LRUCache()); - - public HotSpotGraphCache(CompilerToVM compilerToVM) { - this.compilerToVM = compilerToVM; - if (PrintGraphCache.getValue()) { - Runtime.getRuntime().addShutdownHook(new Thread() { - - @Override - public void run() { - out.println("put: " + putCounter); - out.println("get hit: " + hitCounter); - out.println("get miss: " + missCounter); - out.println("remove hit: " + removeHitCounter); - out.println("remove miss: " + (removeCounter - removeHitCounter)); - } - }); - } - } - - @Override - public StructuredGraph get(ResolvedJavaMethod method) { - StructuredGraph result = (StructuredGraph) method.getCompilerStorage().get(this); - - if (PrintGraphCache.getValue()) { - if (result == null) { - missCounter++; - } else { - hitCounter++; - } - } - return result; - } - - @Override - public boolean put(StructuredGraph graph, boolean hasMatureProfilingInfo) { - assert graph.method() != null; - if (hasMatureProfilingInfo) { - cachedGraphIds.put(graph.graphId(), new WeakReference<>(graph.method())); - graph.method().getCompilerStorage().put(this, graph); - - if (PrintGraphCache.getValue()) { - putCounter++; - } - return true; - } - return false; - } - - public void clear() { - synchronized (cachedGraphIds) { - for (WeakReference<ResolvedJavaMethod> ref : cachedGraphIds.values()) { - ResolvedJavaMethod method = ref.get(); - if (method != null) { - method.getCompilerStorage().remove(this); - } - } - cachedGraphIds.clear(); - hitCounter = 0; - missCounter = 0; - removeHitCounter = 0; - removeCounter = 0; - putCounter = 0; - } - } - - public void removeGraphs(long[] deoptedGraphs) { - for (long graphId : deoptedGraphs) { - WeakReference<ResolvedJavaMethod> ref = cachedGraphIds.get(graphId); - ResolvedJavaMethod method = ref == null ? null : ref.get(); - if (method != null) { - StructuredGraph cachedGraph = (StructuredGraph) method.getCompilerStorage().get(this); - if (cachedGraph != null && cachedGraph.graphId() == graphId) { - method.getCompilerStorage().remove(this); - if (PrintGraphCache.getValue()) { - removeHitCounter++; - } - } - } - if (PrintGraphCache.getValue()) { - removeCounter++; - } - } - } - - private final CompilerToVM compilerToVM; - - public void removeStaleGraphs() { - long[] deoptedGraphs = compilerToVM.getDeoptedLeafGraphIds(); - if (deoptedGraphs != null) { - if (deoptedGraphs.length == 0) { - clear(); - } else { - removeGraphs(deoptedGraphs); - } - } - } -}
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StructuredGraph.java Thu Mar 13 14:48:01 2014 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StructuredGraph.java Thu Mar 13 15:36:30 2014 +0100 @@ -71,8 +71,6 @@ private static final AtomicLong uniqueGraphIds = new AtomicLong(); - private final Set<Long> leafGraphIds = new HashSet<>(4); - private StartNode start; private final ResolvedJavaMethod method; private final long graphId; @@ -162,14 +160,6 @@ this.start = start; } - /** - * @return the {@link Set} that contains the {@link #graphId()} of all graphs that were - * incorporated into this one (e.g. by inlining). - */ - public Set<Long> getLeafGraphIds() { - return leafGraphIds; - } - @Override public StructuredGraph copy() { return copy(name);
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/GraphCache.java Thu Mar 13 14:48:01 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * 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. - * - * 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.nodes.spi; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.nodes.*; - -/** - * A cache for graphs associated with {@linkplain StructuredGraph#method() methods}. - */ -public interface GraphCache { - - /** - * Requests that a graph be added to this cache. - * - * @param hasMatureProfilingInfo indicates that the caller has - * {@linkplain ProfilingInfo#isMature() mature} profiling info for the method - * associated with the graph - * @return true if {@code graph} was added to this cache, false otherwise - */ - boolean put(StructuredGraph graph, boolean hasMatureProfilingInfo); - - /** - * Gets the graph from this cache associated with a given method. - * - * @param method a method for which a cached graph is requested - * @return the graph cached for {@code method} or null if it does not exist - */ - StructuredGraph get(ResolvedJavaMethod method); - - /** - * The cache will remove graphs it considers stale. For example, graphs associated with - * installed code that has subsequently be deoptimized might be considered stale. - */ - void removeStaleGraphs(); -}
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningPhase.java Thu Mar 13 14:48:01 2014 +0100 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningPhase.java Thu Mar 13 15:36:30 2014 +0100 @@ -281,7 +281,7 @@ } private static StructuredGraph getCachedGraph(ResolvedJavaMethod method, HighTierContext context) { - if (CacheGraphs.getValue() && context.getGraphCache() != null) { + if (context.getGraphCache() != null) { StructuredGraph cachedGraph = context.getGraphCache().get(method); if (cachedGraph != null) { return cachedGraph; @@ -304,8 +304,8 @@ canonicalizer.apply(newGraph, context); } - if (CacheGraphs.getValue() && context.getGraphCache() != null) { - context.getGraphCache().put(newGraph.copy(), hasMatureProfilingInfo); + if (hasMatureProfilingInfo && context.getGraphCache() != null) { + context.getGraphCache().put(newGraph.method(), newGraph.copy()); } return newGraph; }
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java Thu Mar 13 14:48:01 2014 +0100 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java Thu Mar 13 15:36:30 2014 +0100 @@ -318,14 +318,9 @@ } protected static void inline(Invoke invoke, ResolvedJavaMethod concrete, Inlineable inlineable, Assumptions assumptions, boolean receiverNullCheck) { - StructuredGraph graph = invoke.asNode().graph(); if (inlineable instanceof InlineableGraph) { StructuredGraph calleeGraph = ((InlineableGraph) inlineable).getGraph(); InliningUtil.inline(invoke, calleeGraph, receiverNullCheck); - - graph.getLeafGraphIds().add(calleeGraph.graphId()); - // we might at some point cache already-inlined graphs, so add recursively: - graph.getLeafGraphIds().addAll(calleeGraph.getLeafGraphIds()); } else { assert inlineable instanceof InlineableMacroNode;
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java Thu Mar 13 14:48:01 2014 +0100 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java Thu Mar 13 15:36:30 2014 +0100 @@ -92,10 +92,6 @@ // graph caching @Option(help = "") public static final OptionValue<Boolean> CacheGraphs = new OptionValue<>(true); - @Option(help = "") - public static final OptionValue<Integer> GraphCacheSize = new OptionValue<>(1000); - @Option(help = "") - public static final OptionValue<Boolean> PrintGraphCache = new OptionValue<>(false); //loop transform settings TODO (gd) tune @Option(help = "")
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/tiers/HighTierContext.java Thu Mar 13 14:48:01 2014 +0100 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/tiers/HighTierContext.java Thu Mar 13 15:36:30 2014 +0100 @@ -22,8 +22,11 @@ */ package com.oracle.graal.phases.tiers; +import java.util.*; + import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; +import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.phases.*; import com.oracle.graal.phases.util.*; @@ -32,18 +35,19 @@ private final PhaseSuite<HighTierContext> graphBuilderSuite; - private final GraphCache cache; + private final Map<ResolvedJavaMethod, StructuredGraph> cache; private final OptimisticOptimizations optimisticOpts; public HighTierContext(MetaAccessProvider metaAccess, ConstantReflectionProvider constantReflection, LoweringProvider lowerer, Replacements replacements, Assumptions assumptions, - GraphCache cache, PhaseSuite<HighTierContext> graphBuilderSuite, OptimisticOptimizations optimisticOpts) { + Map<ResolvedJavaMethod, StructuredGraph> cache, PhaseSuite<HighTierContext> graphBuilderSuite, OptimisticOptimizations optimisticOpts) { super(metaAccess, constantReflection, lowerer, replacements, assumptions); this.cache = cache; this.graphBuilderSuite = graphBuilderSuite; this.optimisticOpts = optimisticOpts; } - public HighTierContext(Providers providers, Assumptions assumptions, GraphCache cache, PhaseSuite<HighTierContext> graphBuilderSuite, OptimisticOptimizations optimisticOpts) { + public HighTierContext(Providers providers, Assumptions assumptions, Map<ResolvedJavaMethod, StructuredGraph> cache, PhaseSuite<HighTierContext> graphBuilderSuite, + OptimisticOptimizations optimisticOpts) { this(providers.getMetaAccess(), providers.getConstantReflection(), providers.getLowerer(), providers.getReplacements(), assumptions, cache, graphBuilderSuite, optimisticOpts); } @@ -51,7 +55,7 @@ return graphBuilderSuite; } - public GraphCache getGraphCache() { + public Map<ResolvedJavaMethod, StructuredGraph> getGraphCache() { return cache; }
--- a/graal/com.oracle.graal.runtime/src/com/oracle/graal/runtime/RuntimeProvider.java Thu Mar 13 14:48:01 2014 +0100 +++ b/graal/com.oracle.graal.runtime/src/com/oracle/graal/runtime/RuntimeProvider.java Thu Mar 13 15:36:30 2014 +0100 @@ -24,11 +24,9 @@ import com.oracle.graal.api.code.*; import com.oracle.graal.compiler.target.*; -import com.oracle.graal.nodes.spi.*; /** - * A runtime supporting a host backend as well, zero or more additional backends and an optional - * {@linkplain GraphCache graph cache}. + * A runtime supporting a host backend as well, zero or more additional backends. */ public interface RuntimeProvider { @@ -43,9 +41,4 @@ * @param arch a specific architecture class */ <T extends Architecture> Backend getBackend(Class<T> arch); - - /** - * Gets the graph cache (if any) maintained by this runtime. - */ - GraphCache getGraphCache(); }
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java Thu Mar 13 14:48:01 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java Thu Mar 13 15:36:30 2014 +0100 @@ -51,7 +51,6 @@ import com.oracle.graal.phases.common.CanonicalizerPhase.CustomCanonicalizer; import com.oracle.graal.phases.tiers.*; import com.oracle.graal.phases.util.*; -import com.oracle.graal.runtime.*; import com.oracle.graal.truffle.nodes.asserts.*; import com.oracle.graal.truffle.nodes.frame.*; import com.oracle.graal.truffle.nodes.frame.NewFrameNode.VirtualOnlyInstanceNode; @@ -71,16 +70,14 @@ private final CanonicalizerPhase canonicalizer; private final GraphBuilderConfiguration config; private Set<Constant> constantReceivers; - private final GraphCache cache; private final TruffleCache truffleCache; private final ResolvedJavaType frameType; - public PartialEvaluator(RuntimeProvider runtime, Providers providers, TruffleCache truffleCache, GraphBuilderConfiguration config) { + public PartialEvaluator(Providers providers, TruffleCache truffleCache, GraphBuilderConfiguration config) { this.providers = providers; CustomCanonicalizer customCanonicalizer = new PartialEvaluatorCanonicalizer(providers.getMetaAccess(), providers.getConstantReflection()); this.canonicalizer = new CanonicalizerPhase(!ImmutableCode.getValue(), customCanonicalizer); this.config = config; - this.cache = runtime.getGraphCache(); this.truffleCache = truffleCache; this.frameType = providers.getMetaAccess().lookupJavaType(FrameWithoutBoxing.class); try { @@ -142,7 +139,11 @@ } canonicalizer.apply(graph, baseContext); - HighTierContext tierContext = new HighTierContext(providers, assumptions, cache, new PhaseSuite<HighTierContext>(), OptimisticOptimizations.NONE); + Map<ResolvedJavaMethod, StructuredGraph> graphCache = null; + if (CacheGraphs.getValue()) { + graphCache = new HashMap<>(); + } + HighTierContext tierContext = new HighTierContext(providers, assumptions, graphCache, new PhaseSuite<HighTierContext>(), OptimisticOptimizations.NONE); for (NeverPartOfCompilationNode neverPartOfCompilationNode : graph.getNodes(NeverPartOfCompilationNode.class)) { Throwable exception = new VerificationError(neverPartOfCompilationNode.getMessage());
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java Thu Mar 13 14:48:01 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java Thu Mar 13 15:36:30 2014 +0100 @@ -102,7 +102,7 @@ this.config = GraphBuilderConfiguration.getDefault(); this.config.setSkippedExceptionTypes(skippedExceptionTypes); - this.partialEvaluator = new PartialEvaluator(runtime, providers, truffleCache, config); + this.partialEvaluator = new PartialEvaluator(providers, truffleCache, config); if (Debug.isEnabled()) { DebugEnvironment.initialize(System.out); @@ -136,10 +136,6 @@ private InstalledCode compileMethodImpl(final OptimizedCallTarget compilable) { final StructuredGraph graph; - GraphCache graphCache = runtime.getGraphCache(); - if (graphCache != null) { - graphCache.removeStaleGraphs(); - } if (TraceTruffleCompilation.getValue()) { OptimizedCallTarget.logOptimizingStart(compilable);
--- a/src/share/vm/code/nmethod.cpp Thu Mar 13 14:48:01 2014 +0100 +++ b/src/share/vm/code/nmethod.cpp Thu Mar 13 15:36:30 2014 +0100 @@ -623,8 +623,7 @@ ExceptionHandlerTable* handler_table, ImplicitExceptionTable* nul_chk_table, AbstractCompiler* compiler, - int comp_level, - GrowableArray<jlong>* leaf_graph_ids + int comp_level #ifdef GRAAL , Handle installed_code, Handle speculationLog @@ -633,7 +632,6 @@ { assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR"); code_buffer->finalize_oop_references(method); - int leaf_graph_ids_size = leaf_graph_ids == NULL ? 0 : round_to(sizeof(jlong) * leaf_graph_ids->length(), oopSize); // create nmethod nmethod* nm = NULL; { MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); @@ -643,8 +641,7 @@ + round_to(dependencies->size_in_bytes() , oopSize) + round_to(handler_table->size_in_bytes(), oopSize) + round_to(nul_chk_table->size_in_bytes(), oopSize) - + round_to(debug_info->data_size() , oopSize) - + leaf_graph_ids_size; + + round_to(debug_info->data_size() , oopSize); nm = new (nmethod_size) nmethod(method(), nmethod_size, compile_id, entry_bci, offsets, orig_pc_offset, debug_info, dependencies, code_buffer, frame_size, @@ -652,8 +649,7 @@ handler_table, nul_chk_table, compiler, - comp_level, - leaf_graph_ids + comp_level #ifdef GRAAL , installed_code, speculationLog @@ -733,8 +729,7 @@ _dependencies_offset = _scopes_pcs_offset; _handler_table_offset = _dependencies_offset; _nul_chk_table_offset = _handler_table_offset; - _leaf_graph_ids_offset = _nul_chk_table_offset; - _nmethod_end_offset = _leaf_graph_ids_offset; + _nmethod_end_offset = _nul_chk_table_offset; _compile_id = compile_id; _comp_level = CompLevel_none; _entry_point = code_begin() + offsets->value(CodeOffsets::Entry); @@ -881,8 +876,7 @@ ExceptionHandlerTable* handler_table, ImplicitExceptionTable* nul_chk_table, AbstractCompiler* compiler, - int comp_level, - GrowableArray<jlong>* leaf_graph_ids + int comp_level #ifdef GRAAL , Handle installed_code, Handle speculation_log @@ -951,8 +945,6 @@ _unwind_handler_offset = -1; } - int leaf_graph_ids_size = leaf_graph_ids == NULL ? 0 : round_to(sizeof(jlong) * leaf_graph_ids->length(), oopSize); - _oops_offset = data_offset(); _metadata_offset = _oops_offset + round_to(code_buffer->total_oop_size(), oopSize); _scopes_data_offset = _metadata_offset + round_to(code_buffer->total_metadata_size(), wordSize); @@ -961,8 +953,7 @@ _dependencies_offset = _scopes_pcs_offset + adjust_pcs_size(debug_info->pcs_size()); _handler_table_offset = _dependencies_offset + round_to(dependencies->size_in_bytes (), oopSize); _nul_chk_table_offset = _handler_table_offset + round_to(handler_table->size_in_bytes(), oopSize); - _leaf_graph_ids_offset = _nul_chk_table_offset + round_to(nul_chk_table->size_in_bytes(), oopSize); - _nmethod_end_offset = _leaf_graph_ids_offset + leaf_graph_ids_size; + _nmethod_end_offset = _nul_chk_table_offset + round_to(nul_chk_table->size_in_bytes(), oopSize); _entry_point = code_begin() + offsets->value(CodeOffsets::Entry); _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry); @@ -986,10 +977,6 @@ handler_table->copy_to(this); nul_chk_table->copy_to(this); - if (leaf_graph_ids != NULL && leaf_graph_ids_size > 0) { - memcpy(leaf_graph_ids_begin(), leaf_graph_ids->adr_at(0), leaf_graph_ids_size); - } - // we use the information of entry points to find out if a method is // static or non static assert(compiler->is_c2() || compiler->is_graal() ||
--- a/src/share/vm/code/nmethod.hpp Thu Mar 13 14:48:01 2014 +0100 +++ b/src/share/vm/code/nmethod.hpp Thu Mar 13 15:36:30 2014 +0100 @@ -159,7 +159,6 @@ int _dependencies_offset; int _handler_table_offset; int _nul_chk_table_offset; - int _leaf_graph_ids_offset; int _nmethod_end_offset; // location in frame (offset for sp) that deopt can store the original @@ -276,8 +275,7 @@ ExceptionHandlerTable* handler_table, ImplicitExceptionTable* nul_chk_table, AbstractCompiler* compiler, - int comp_level, - GrowableArray<jlong>* leaf_graph_ids + int comp_level #ifdef GRAAL , Handle installed_code, Handle speculation_log @@ -318,8 +316,7 @@ ExceptionHandlerTable* handler_table, ImplicitExceptionTable* nul_chk_table, AbstractCompiler* compiler, - int comp_level, - GrowableArray<jlong>* leaf_graph_ids = NULL + int comp_level #ifdef GRAAL , Handle installed_code = Handle(), Handle speculation_log = Handle() @@ -393,9 +390,7 @@ address handler_table_begin () const { return header_begin() + _handler_table_offset ; } address handler_table_end () const { return header_begin() + _nul_chk_table_offset ; } address nul_chk_table_begin () const { return header_begin() + _nul_chk_table_offset ; } - address nul_chk_table_end () const { return header_begin() + _leaf_graph_ids_offset; } - jlong* leaf_graph_ids_begin () const { return (jlong*)(header_begin() + _leaf_graph_ids_offset); } - jlong* leaf_graph_ids_end () const { return (jlong*)(header_begin() + _nmethod_end_offset) ; } + address nul_chk_table_end () const { return header_begin() + _nmethod_end_offset; } // Sizes int consts_size () const { return consts_end () - consts_begin (); }
--- a/src/share/vm/graal/graalCodeInstaller.cpp Thu Mar 13 14:48:01 2014 +0100 +++ b/src/share/vm/graal/graalCodeInstaller.cpp Thu Mar 13 15:36:30 2014 +0100 @@ -364,24 +364,6 @@ } } -GrowableArray<jlong>* get_leaf_graph_ids(Handle& compiled_code) { - arrayOop leafGraphArray = (arrayOop) CompilationResult::leafGraphIds(HotSpotCompiledCode::comp(compiled_code)); - - jint length; - if (leafGraphArray == NULL) { - length = 0; - } else { - length = leafGraphArray->length(); - } - - GrowableArray<jlong>* result = new GrowableArray<jlong>(length); - for (int i = 0; i < length; i++) { - result->append(((jlong*) leafGraphArray->base(T_LONG))[i]); - } - - return result; -} - // constructor used to create a method GraalEnv::CodeInstallResult CodeInstaller::install(Handle& compiled_code, CodeBlob*& cb, Handle installed_code, Handle speculation_log) { BufferBlob* buffer_blob = GraalCompiler::initialize_buffer_blob(); @@ -407,7 +389,6 @@ } int stack_slots = _total_frame_size / HeapWordSize; // conversion to words - GrowableArray<jlong>* leaf_graph_ids = get_leaf_graph_ids(compiled_code); GraalEnv::CodeInstallResult result; if (compiled_code->is_a(HotSpotCompiledRuntimeStub::klass())) { @@ -430,7 +411,7 @@ id = CompileBroker::assign_compile_id_unlocked(Thread::current(), method, entry_bci); } result = GraalEnv::register_method(method, nm, entry_bci, &_offsets, _custom_stack_area_offset, &buffer, stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table, - GraalCompiler::instance(), _debug_recorder, _dependencies, NULL, id, false, leaf_graph_ids, installed_code, speculation_log); + GraalCompiler::instance(), _debug_recorder, _dependencies, NULL, id, false, installed_code, speculation_log); cb = nm; }
--- a/src/share/vm/graal/graalCompiler.cpp Thu Mar 13 14:48:01 2014 +0100 +++ b/src/share/vm/graal/graalCompiler.cpp Thu Mar 13 15:36:30 2014 +0100 @@ -53,8 +53,6 @@ AMD64_ONLY(guarantee(heap_end < allocation_end, "heap end too close to end of address space (might lead to erroneous TLAB allocations)")); NOT_LP64(error("check TLAB allocation code for address space conflicts")); - _deopted_leaf_graph_count = 0; - BufferBlob* buffer_blob = initialize_buffer_blob(); if (buffer_blob == NULL) { // If we are called from JNI_CreateJavaVM we cannot use set_state yet because it takes a lock. @@ -128,47 +126,6 @@ } } -void GraalCompiler::deopt_leaf_graph(jlong leaf_graph_id) { - assert(leaf_graph_id != -1, "unexpected leaf graph id"); - - if (_deopted_leaf_graph_count < LEAF_GRAPH_ARRAY_SIZE) { - MutexLockerEx y(GraalDeoptLeafGraphIds_lock, Mutex::_no_safepoint_check_flag); - if (_deopted_leaf_graph_count < LEAF_GRAPH_ARRAY_SIZE) { - _deopted_leaf_graphs[_deopted_leaf_graph_count++] = leaf_graph_id; - } - } -} - -oop GraalCompiler::dump_deopted_leaf_graphs(TRAPS) { - if (_deopted_leaf_graph_count == 0) { - return NULL; - } - jlong* elements; - int length; - { - MutexLockerEx y(GraalDeoptLeafGraphIds_lock, Mutex::_no_safepoint_check_flag); - if (_deopted_leaf_graph_count == 0) { - return NULL; - } - if (_deopted_leaf_graph_count == LEAF_GRAPH_ARRAY_SIZE) { - length = 0; - } else { - length = _deopted_leaf_graph_count; - } - elements = NEW_C_HEAP_ARRAY(jlong, length, mtCompiler); - for (int i = 0; i < length; i++) { - elements[i] = _deopted_leaf_graphs[i]; - } - _deopted_leaf_graph_count = 0; - } - typeArrayOop array = oopFactory::new_longArray(length, CHECK_NULL); - for (int i = 0; i < length; i++) { - array->long_at_put(i, elements[i]); - } - FREE_C_HEAP_ARRAY(jlong, elements, mtCompiler); - return array; -} - BufferBlob* GraalCompiler::initialize_buffer_blob() { JavaThread* THREAD = JavaThread::current(); BufferBlob* buffer_blob = THREAD->get_buffer_blob();
--- a/src/share/vm/graal/graalCompiler.hpp Thu Mar 13 14:48:01 2014 +0100 +++ b/src/share/vm/graal/graalCompiler.hpp Thu Mar 13 15:36:30 2014 +0100 @@ -36,9 +36,6 @@ static GraalCompiler* _instance; - jlong _deopted_leaf_graphs[LEAF_GRAPH_ARRAY_SIZE]; - int _deopted_leaf_graph_count; - public: GraalCompiler(); @@ -65,9 +62,6 @@ void compile_method(methodHandle target, int entry_bci, jboolean blocking); - void deopt_leaf_graph(jlong leaf_graph_id); - oop dump_deopted_leaf_graphs(TRAPS); - // Print compilation timers and statistics virtual void print_timers();
--- a/src/share/vm/graal/graalCompilerToVM.cpp Thu Mar 13 14:48:01 2014 +0100 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Thu Mar 13 15:36:30 2014 +0100 @@ -679,17 +679,6 @@ } C2V_END -C2V_VMENTRY(jobject, getDeoptedLeafGraphIds, (JNIEnv *, jobject)) - - // the contract for this method is as follows: - // returning null: no deopted leaf graphs - // returning array (size > 0): the ids of the deopted leaf graphs - // returning array (size == 0): there was an overflow, the compiler needs to clear its cache completely - - oop array = GraalCompiler::instance()->dump_deopted_leaf_graphs(CHECK_NULL); - return JNIHandles::make_local(array); -C2V_END - C2V_ENTRY(jlongArray, getLineNumberTable, (JNIEnv *env, jobject, jlong metaspace_method)) Method* method = (Method*) metaspace_method; if (!method->has_linenumber_table()) { @@ -869,7 +858,6 @@ {CC"resetCompilationStatistics", CC"()V", FN_PTR(resetCompilationStatistics)}, {CC"disassembleCodeBlob", CC"(J)"STRING, FN_PTR(disassembleCodeBlob)}, {CC"executeCompiledMethodVarargs", CC"(["OBJECT HS_INSTALLED_CODE")"OBJECT, FN_PTR(executeCompiledMethodVarargs)}, - {CC"getDeoptedLeafGraphIds", CC"()[J", FN_PTR(getDeoptedLeafGraphIds)}, {CC"getLineNumberTable", CC"("METASPACE_METHOD")[J", FN_PTR(getLineNumberTable)}, {CC"getLocalVariableTableStart", CC"("METASPACE_METHOD")J", FN_PTR(getLocalVariableTableStart)}, {CC"getLocalVariableTableLength", CC"("METASPACE_METHOD")I", FN_PTR(getLocalVariableTableLength)},
--- a/src/share/vm/graal/graalEnv.cpp Thu Mar 13 14:48:01 2014 +0100 +++ b/src/share/vm/graal/graalEnv.cpp Thu Mar 13 15:36:30 2014 +0100 @@ -450,7 +450,6 @@ CompileTask* task, int compile_id, bool has_unsafe_access, - GrowableArray<jlong>* leaf_graph_ids, Handle installed_code, Handle speculation_log) { GRAAL_EXCEPTION_CONTEXT; @@ -497,7 +496,7 @@ debug_info, dependencies, code_buffer, frame_words, oop_map_set, handler_table, &implicit_tbl, - compiler, comp_level, leaf_graph_ids, installed_code, speculation_log); + compiler, comp_level, installed_code, speculation_log); // Free codeBlobs //code_buffer->free_blob();
--- a/src/share/vm/graal/graalEnv.hpp Thu Mar 13 14:48:01 2014 +0100 +++ b/src/share/vm/graal/graalEnv.hpp Thu Mar 13 15:36:30 2014 +0100 @@ -144,7 +144,6 @@ CompileTask* task, int compile_id, bool has_unsafe_access, - GrowableArray<jlong>* leaf_graph_ids, Handle installed_code, Handle speculation_log);
--- a/src/share/vm/graal/graalJavaAccess.hpp Thu Mar 13 14:48:01 2014 +0100 +++ b/src/share/vm/graal/graalJavaAccess.hpp Thu Mar 13 15:36:30 2014 +0100 @@ -111,7 +111,6 @@ start_class(CompilationResult) \ int_field(CompilationResult, frameSize) \ int_field(CompilationResult, customStackAreaOffset) \ - oop_field(CompilationResult, leafGraphIds, "[J") \ oop_field(CompilationResult, targetCode, "[B") \ oop_field(CompilationResult, assumptions, "Lcom/oracle/graal/api/code/Assumptions;") \ int_field(CompilationResult, targetCodeSize) \
--- a/src/share/vm/runtime/deoptimization.cpp Thu Mar 13 14:48:01 2014 +0100 +++ b/src/share/vm/runtime/deoptimization.cpp Thu Mar 13 15:36:30 2014 +0100 @@ -209,21 +209,6 @@ // Java frame. This storage is allocated with the usual system arena. assert(deoptee.is_compiled_frame(), "Wrong frame type"); -#ifdef GRAAL - nmethod* nm = (nmethod*) deoptee.cb(); - GraalCompiler* compiler = (GraalCompiler*) nm->compiler(); - for (jlong* p = nm->leaf_graph_ids_begin(); p != nm->leaf_graph_ids_end(); p++) { - compiler->deopt_leaf_graph(*p); - } - if (PrintDeoptimizationDetails) { - tty->print("leaf graph ids: "); - for (jlong* p = nm->leaf_graph_ids_begin(); p != nm->leaf_graph_ids_end(); p++) { - tty->print("%d ", *p); - } - tty->cr(); - } -#endif - GrowableArray<compiledVFrame*>* chunk = new GrowableArray<compiledVFrame*>(10); vframe* vf = vframe::new_vframe(&deoptee, &map, thread); while (!vf->is_top()) {