001/* 002 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. 008 * 009 * This code is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 012 * version 2 for more details (a copy is included in the LICENSE file that 013 * accompanied this code). 014 * 015 * You should have received a copy of the GNU General Public License version 016 * 2 along with this work; if not, write to the Free Software Foundation, 017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 018 * 019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 020 * or visit www.oracle.com if you need additional information or have any 021 * questions. 022 */ 023package com.oracle.graal.compiler.test.ea; 024 025import com.oracle.graal.debug.*; 026import com.oracle.graal.debug.Debug.*; 027 028import org.junit.*; 029 030import com.oracle.graal.compiler.test.*; 031import com.oracle.graal.graph.*; 032import com.oracle.graal.nodes.*; 033import com.oracle.graal.nodes.StructuredGraph.AllowAssumptions; 034import com.oracle.graal.nodes.java.*; 035import com.oracle.graal.nodes.spi.*; 036import com.oracle.graal.phases.common.*; 037import com.oracle.graal.phases.common.inlining.*; 038import com.oracle.graal.phases.tiers.*; 039 040/** 041 * Tests {@link AbstractNewObjectNode#simplify(com.oracle.graal.graph.spi.SimplifierTool)}. 042 * 043 */ 044public class PoorMansEATest extends GraalCompilerTest { 045 public static class A { 046 public A obj; 047 } 048 049 public static A test1Snippet() { 050 A a = new A(); 051 a.obj = a; 052 return null; 053 } 054 055 @Test 056 public void test1() { 057 test("test1Snippet"); 058 } 059 060 private void test(final String snippet) { 061 try (Scope s = Debug.scope("PoorMansEATest", new DebugDumpScope(snippet))) { 062 StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO); 063 HighTierContext highTierContext = getDefaultHighTierContext(); 064 new InliningPhase(new CanonicalizerPhase()).apply(graph, highTierContext); 065 PhaseContext context = new PhaseContext(getProviders()); 066 new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context); 067 068 // remove framestates in order to trigger the simplification. 069 cleanup: for (FrameState fs : graph.getNodes(FrameState.TYPE).snapshot()) { 070 for (Node input : fs.inputs()) { 071 if (input instanceof NewInstanceNode) { 072 fs.replaceAtUsages(null); 073 fs.safeDelete(); 074 continue cleanup; 075 } 076 } 077 } 078 new CanonicalizerPhase().apply(graph, context); 079 } catch (Throwable e) { 080 throw Debug.handle(e); 081 } 082 } 083}