# HG changeset patch # User Tom Rodriguez # Date 1422853076 28800 # Node ID a8bcda325946d54c3bfb14da56e0b4d9b5aff524 # Parent c370e6f3957528e89454dc4db63b455cbef8d3f7# Parent 9544b5f6762615ef1c262a0af247da501d9bdd7f Merge diff -r 9544b5f67626 -r a8bcda325946 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/GraphChangeMonitoringPhase.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/GraphChangeMonitoringPhase.java Sun Feb 01 02:21:32 2015 +0100 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/GraphChangeMonitoringPhase.java Sun Feb 01 20:57:56 2015 -0800 @@ -22,12 +22,11 @@ */ package com.oracle.graal.compiler.phases; -import static com.oracle.graal.graph.Graph.NodeEvent.*; - import java.util.stream.*; import com.oracle.graal.debug.*; import com.oracle.graal.debug.Debug.Scope; +import com.oracle.graal.graph.Graph.NodeEvent; import com.oracle.graal.graph.Graph.NodeEventScope; import com.oracle.graal.nodes.*; import com.oracle.graal.phases.*; @@ -60,9 +59,13 @@ @Override protected void run(StructuredGraph graph, C context) { - HashSetNodeEventListener listener = new HashSetNodeEventListener().exclude(INPUT_CHANGED); - try (NodeEventScope s = graph.trackNodeEvents(listener)) { - StructuredGraph graphCopy = graph.copy(); + /* + * Phase may add nodes but not end up using them so ignore additions. Nodes going dead and + * having their inputs change are the main interesting differences. + */ + HashSetNodeEventListener listener = new HashSetNodeEventListener().exclude(NodeEvent.NODE_ADDED); + StructuredGraph graphCopy = graph.copy(); + try (NodeEventScope s = graphCopy.trackNodeEvents(listener)) { try (Scope s2 = Debug.sandbox("WithoutMonitoring", null)) { super.run(graphCopy, context); } catch (Throwable t) { @@ -70,10 +73,10 @@ } } if (!listener.getNodes().isEmpty()) { - // rerun it on the real graph in a new Debug scope so Dump and Log can find it. - listener = new HashSetNodeEventListener().exclude(INPUT_CHANGED); + /* rerun it on the real graph in a new Debug scope so Dump and Log can find it. */ + listener = new HashSetNodeEventListener(); try (NodeEventScope s = graph.trackNodeEvents(listener)) { - try (Scope s2 = Debug.scope("GraphChangeMonitoring." + getName() + "-" + message)) { + try (Scope s2 = Debug.scope("WithGraphChangeMonitoring." + getName() + "-" + message)) { if (Debug.isDumpEnabled(BasePhase.PHASE_DUMP_LEVEL)) { Debug.dump(BasePhase.PHASE_DUMP_LEVEL, graph, "*** Before phase %s", getName()); } @@ -81,8 +84,8 @@ if (Debug.isDumpEnabled(BasePhase.PHASE_DUMP_LEVEL)) { Debug.dump(BasePhase.PHASE_DUMP_LEVEL, graph, "*** After phase %s", getName()); } + Debug.log("*** %s %s %s\n", message, graph, listener.getNodes().stream().filter(e -> !e.isAlive()).collect(Collectors.toSet())); } - Debug.log("*** %s %s %s\n", message, graph, listener.getNodes().stream().filter(e -> !e.isAlive()).collect(Collectors.toSet())); } } else { // Go ahead and run it normally even though it should have no effect diff -r 9544b5f67626 -r a8bcda325946 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeMap.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeMap.java Sun Feb 01 02:21:32 2015 +0100 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeMap.java Sun Feb 01 20:57:56 2015 -0800 @@ -98,6 +98,14 @@ values[getNodeId(node)] = value; } + /** + * @param i + * @return Return the key for the entry at index {@code i} + */ + protected Node getKey(int i) { + return graph.getNode(i); + } + public int size() { return values.length; } @@ -135,7 +143,7 @@ @Override public Entry next() { final int pos = i; - Node key = NodeMap.this.graph.getNode(pos); + Node key = NodeMap.this.getKey(pos); T value = (T) NodeMap.this.values[pos]; i++; forward(); @@ -158,7 +166,7 @@ } private void forward() { - while (i < NodeMap.this.values.length && (NodeMap.this.graph.getNode(i) == null || NodeMap.this.values[i] == null)) { + while (i < NodeMap.this.values.length && (NodeMap.this.getKey(i) == null || NodeMap.this.values[i] == null)) { i++; } } diff -r 9544b5f67626 -r a8bcda325946 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeNodeMap.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeNodeMap.java Sun Feb 01 02:21:32 2015 +0100 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeNodeMap.java Sun Feb 01 20:57:56 2015 -0800 @@ -56,10 +56,21 @@ public Set keySet() { HashSet entries = new HashSet<>(); - for (Map.Entry entry : entries()) { - entries.add(entry.getKey()); + for (int i = 0; i < values.length; ++i) { + Object v = values[i]; + if (v != null) { + Node key = getKey(i); + if (key != null) { + entries.add(key); + } + } } - return entries; + /* + * The normal contract for entrySet is that modifications of the set are reflected in the + * underlying data structure. For simplicity don't allow that but complain if someone tries + * to use it that way. + */ + return Collections.unmodifiableSet(entries); } public Collection values() { @@ -78,6 +89,11 @@ for (Map.Entry entry : entries()) { entries.add(entry); } - return entries; + /* + * The normal contract for entrySet is that modifications of the set are reflected in the + * underlying data structure. For simplicity don't allow that but complain if someone tries + * to use it that way. + */ + return Collections.unmodifiableSet(entries); } } diff -r 9544b5f67626 -r a8bcda325946 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Sun Feb 01 02:21:32 2015 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Sun Feb 01 20:57:56 2015 -0800 @@ -91,6 +91,7 @@ * Do deferred initialization. */ public void completeInitialization() { + TTY.initialize(Options.LogFile.getStream(compilerToVm)); // Proxies for the VM/Compiler interfaces cannot be initialized // in the constructor as proxy creation causes static @@ -109,8 +110,6 @@ this.compilerToVm = toVM; - TTY.initialize(Options.LogFile.getStream(compilerToVm)); - if (Log.getValue() == null && Meter.getValue() == null && Time.getValue() == null && Dump.getValue() == null && Verify.getValue() == null) { if (MethodFilter.getValue() != null) { TTY.println("WARNING: Ignoring MethodFilter option since Log, Meter, Time, Dump and Verify options are all null"); diff -r 9544b5f67626 -r a8bcda325946 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/logging/CountingProxy.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/logging/CountingProxy.java Sun Feb 01 02:21:32 2015 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/logging/CountingProxy.java Sun Feb 01 20:57:56 2015 -0800 @@ -22,7 +22,6 @@ */ package com.oracle.graal.hotspot.logging; -import java.io.*; import java.lang.reflect.*; import java.util.*; import java.util.concurrent.*; @@ -97,13 +96,12 @@ protected void print() { long sum = 0; - PrintStream out = System.out; for (Map.Entry entry : calls.entrySet()) { Method method = entry.getKey(); long count = entry.getValue().get(); sum += count; - out.println(delegate.getClass().getSimpleName() + "." + method.getName() + ": " + count); + TTY.println(delegate.getClass().getSimpleName() + "." + method.getName() + ": " + count); } - out.println(delegate.getClass().getSimpleName() + " calls: " + sum); + TTY.println(delegate.getClass().getSimpleName() + " calls: " + sum); } } diff -r 9544b5f67626 -r a8bcda325946 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ClassSubstitutions.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ClassSubstitutions.java Sun Feb 01 02:21:32 2015 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ClassSubstitutions.java Sun Feb 01 20:57:56 2015 -0800 @@ -105,7 +105,7 @@ if (superKlass.equal(0)) { return null; } else { - return piCastExactNonNull(superKlass.readObject(classMirrorOffset(), CLASS_MIRROR_LOCATION), Class.class); + return readJavaMirror(superKlass); } } } @@ -113,6 +113,10 @@ return null; } + public static Class readJavaMirror(Word klass) { + return piCastExactNonNull(klass.readObject(classMirrorOffset(), CLASS_MIRROR_LOCATION), Class.class); + } + @MacroSubstitution(macro = ClassGetComponentTypeNode.class, isStatic = false) @MethodSubstitution(isStatic = false) public static Class getComponentType(final Class thisObj) { diff -r 9544b5f67626 -r a8bcda325946 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CompilerToVMImplSubstitutions.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CompilerToVMImplSubstitutions.java Sun Feb 01 20:57:56 2015 -0800 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2015, 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.replacements; + +import com.oracle.graal.api.replacements.*; +import com.oracle.graal.hotspot.bridge.*; +import com.oracle.graal.word.*; + +/** + * Substitutions for {@link CompilerToVMImpl} methods. + */ +@ClassSubstitution(com.oracle.graal.hotspot.bridge.CompilerToVMImpl.class) +public class CompilerToVMImplSubstitutions { + + @MethodSubstitution(isStatic = false) + public static Class getJavaMirror(@SuppressWarnings("unused") CompilerToVMImpl impl, long metaspaceklass) { + return ClassSubstitutions.readJavaMirror(Word.unsigned(metaspaceklass)); + } +} diff -r 9544b5f67626 -r a8bcda325946 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotSubstitutions.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotSubstitutions.java Sun Feb 01 02:21:32 2015 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotSubstitutions.java Sun Feb 01 20:57:56 2015 -0800 @@ -33,6 +33,7 @@ import com.oracle.graal.api.replacements.*; import com.oracle.graal.api.runtime.*; import com.oracle.graal.graph.*; +import com.oracle.graal.hotspot.bridge.*; import com.oracle.graal.lir.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.replacements.*; @@ -65,6 +66,7 @@ replacements.registerSubstitutions(NodeClass.class, HotSpotNodeClassSubstitutions.class); replacements.registerSubstitutions(Node.class, HotSpotNodeSubstitutions.class); replacements.registerSubstitutions(CompositeValueClass.class, CompositeValueClassSubstitutions.class); + replacements.registerSubstitutions(CompilerToVMImpl.class, CompilerToVMImplSubstitutions.class); replacements.registerSubstitutions(new NamedType("com.sun.crypto.provider.AESCrypt"), AESCryptSubstitutions.class); replacements.registerSubstitutions(new NamedType("com.sun.crypto.provider.CipherBlockChaining"), CipherBlockChainingSubstitutions.class); } diff -r 9544b5f67626 -r a8bcda325946 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 Sun Feb 01 02:21:32 2015 +0100 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java Sun Feb 01 20:57:56 2015 -0800 @@ -113,11 +113,13 @@ } String originalName = originalName(substituteMethod, methodSubstitution.value()); JavaSignature originalSignature = originalSignature(substituteMethod, methodSubstitution.signature(), methodSubstitution.isStatic()); - Executable originalMethod = originalMethod(classSubstitution, methodSubstitution.optional(), originalName, originalSignature); - if (originalMethod != null && (guard == null || guard.execute())) { - ResolvedJavaMethod original = registerMethodSubstitution(this, originalMethod, substituteMethod); - if (original != null && methodSubstitution.forced() && shouldIntrinsify(original)) { - forcedSubstitutions.add(original); + Executable[] originalMethods = originalMethods(classSubstitution, methodSubstitution.optional(), originalName, originalSignature); + for (Executable originalMethod : originalMethods) { + if (originalMethod != null && (guard == null || guard.execute())) { + ResolvedJavaMethod original = registerMethodSubstitution(this, originalMethod, substituteMethod); + if (original != null && methodSubstitution.forced() && shouldIntrinsify(original)) { + forcedSubstitutions.add(original); + } } } } @@ -126,11 +128,13 @@ if (macroSubstitution != null && (defaultGuard == null || defaultGuard.execute())) { String originalName = originalName(substituteMethod, macroSubstitution.value()); JavaSignature originalSignature = originalSignature(substituteMethod, macroSubstitution.signature(), macroSubstitution.isStatic()); - Executable originalMethod = originalMethod(classSubstitution, macroSubstitution.optional(), originalName, originalSignature); - if (originalMethod != null) { - ResolvedJavaMethod original = registerMacroSubstitution(this, originalMethod, macroSubstitution.macro()); - if (original != null && macroSubstitution.forced() && shouldIntrinsify(original)) { - forcedSubstitutions.add(original); + Executable[] originalMethods = originalMethods(classSubstitution, macroSubstitution.optional(), originalName, originalSignature); + for (Executable originalMethod : originalMethods) { + if (originalMethod != null) { + ResolvedJavaMethod original = registerMacroSubstitution(this, originalMethod, macroSubstitution.macro()); + if (original != null && macroSubstitution.forced() && shouldIntrinsify(original)) { + forcedSubstitutions.add(original); + } } } } @@ -159,20 +163,30 @@ return new JavaSignature(returnType, parameters); } - private Executable originalMethod(ClassSubstitution classSubstitution, boolean optional, String name, JavaSignature signature) { + private Executable[] originalMethods(ClassSubstitution classSubstitution, boolean optional, String name, JavaSignature signature) { Class originalClass = classSubstitution.value(); if (originalClass == ClassSubstitution.class) { + ArrayList result = new ArrayList<>(); for (String className : classSubstitution.className()) { originalClass = resolveClass(className, classSubstitution.optional()); if (originalClass != null) { - break; + result.add(lookupOriginalMethod(originalClass, name, signature, optional)); } } - if (originalClass == null) { + if (result.size() == 0) { // optional class was not found return null; } + return result.toArray(new Executable[result.size()]); } + Executable original = lookupOriginalMethod(originalClass, name, signature, optional); + if (original != null) { + return new Executable[]{original}; + } + return null; + } + + private Executable lookupOriginalMethod(Class originalClass, String name, JavaSignature signature, boolean optional) throws GraalInternalError { try { if (name.equals("")) { assert signature.returnType.equals(void.class) : signature;