1/* 2 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24package com.sun.hotspot.igv.graal.filters; 25 26import com.sun.hotspot.igv.data.Properties; 27import com.sun.hotspot.igv.filter.AbstractFilter; 28import com.sun.hotspot.igv.graph.Connection; 29import com.sun.hotspot.igv.graph.Diagram; 30import com.sun.hotspot.igv.graph.Figure; 31import com.sun.hotspot.igv.graph.InputSlot; 32import com.sun.hotspot.igv.graph.OutputSlot; 33import java.util.HashSet; 34import java.util.Set; 35 36public class GraalCFGFilter extends AbstractFilter { 37 38 @Override 39 public String getName() { 40 return "Graal CFG Filter"; 41 } 42 43 @Override 44 public void apply(Diagram d) { 45 Set<Connection> connectionsToRemove = new HashSet<>(); 46 47 for (Figure f : d.getFigures()) { 48 Properties p = f.getProperties(); 49 int predCount; 50 String predCountString = p.get("predecessorCount"); 51 if (predCountString != null) { 52 predCount = Integer.parseInt(predCountString); 53 } else if (Boolean.parseBoolean(p.get("hasPredecessor"))) { 54 predCount = 1; 55 } else { 56 predCount = 0; 57 } 58 for (InputSlot is : f.getInputSlots()) { 59 if (is.getPosition() >= predCount && !"EndNode".equals(is.getProperties().get("class"))) { 60 for (Connection c : is.getConnections()) { 61 if (!"EndNode".equals(c.getOutputSlot().getFigure().getProperties().get("class"))) { 62 connectionsToRemove.add(c); 63 } 64 } 65 } 66 } 67 } 68 69 for (Connection c : connectionsToRemove) { 70 c.remove(); 71 } 72 73 Set<Figure> figuresToRemove = new HashSet<>(); 74 next: for (Figure f : d.getFigures()) { 75 for (InputSlot is : f.getInputSlots()) { 76 if (!is.getConnections().isEmpty()) { 77 continue next; 78 } 79 } 80 for (OutputSlot os : f.getOutputSlots()) { 81 if (!os.getConnections().isEmpty()) { 82 continue next; 83 } 84 } 85 figuresToRemove.add(f); 86 } 87 d.removeAllFigures(figuresToRemove); 88 } 89} 90