--- old/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/phases/aot/ReplaceConstantNodesPhase.java 2017-06-26 15:43:51.000000000 -0700 +++ new/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/phases/aot/ReplaceConstantNodesPhase.java 2017-06-26 15:43:51.000000000 -0700 @@ -136,7 +136,7 @@ throw new GraalError("Type with bad fingerprint: " + type); } assert !metaspaceConstant.isCompressed() : "No support for replacing compressed metaspace constants"; - replaceWithInitialization(graph, node); + tryToReplaceWithExisting(graph, node); if (anyUsagesNeedReplacement(node)) { replaceWithResolution(graph, node); } @@ -172,45 +172,45 @@ } /** - * Try to find dominating {@link InitializeKlassNode} that can be reused. + * Try to find dominating node doing the resolution that can be reused. * * @param graph * @param node {@link ConstantNode} containing a {@link HotSpotResolvedJavaType} that needs * resolution. */ - private static void replaceWithInitialization(StructuredGraph graph, ConstantNode node) { + private static void tryToReplaceWithExisting(StructuredGraph graph, ConstantNode node) { ScheduleResult schedule = graph.getLastSchedule(); NodeMap nodeToBlock = schedule.getNodeToBlockMap(); BlockMap> blockToNodes = schedule.getBlockToNodesMap(); - EconomicMap blockToInit = EconomicMap.create(); - for (Node n : node.usages().filter(InitializeKlassNode.class)) { - blockToInit.put(nodeToBlock.get(n), n); + EconomicMap blockToExisting = EconomicMap.create(); + for (Node n : node.usages().filter(n -> isReplacementNode(n))) { + blockToExisting.put(nodeToBlock.get(n), n); } for (Node use : node.usages().filter(n -> !isReplacementNode(n)).snapshot()) { boolean replaced = false; Block b = nodeToBlock.get(use); - InitializeKlassNode i = (InitializeKlassNode) blockToInit.get(b); - if (i != null) { - // There is an initialization in the same block as the use, look if the use is - // scheduled after it. + Node e = blockToExisting.get(b); + if (e != null) { + // There is an initialization or resolution in the same block as the use, look if + // the use is scheduled after it. for (Node n : blockToNodes.get(b)) { if (n.equals(use)) { // Usage is before initialization, can't use it break; } - if (n.equals(i)) { - use.replaceFirstInput(node, i); + if (n.equals(e)) { + use.replaceFirstInput(node, e); replaced = true; break; } } } if (!replaced) { - // Look for dominating blocks that have initializations - for (Block d : blockToInit.getKeys()) { + // Look for dominating blocks that have existing nodes + for (Block d : blockToExisting.getKeys()) { if (strictlyDominates(d, b)) { - use.replaceFirstInput(node, blockToInit.get(d)); + use.replaceFirstInput(node, blockToExisting.get(d)); break; } }