001/* 002 * Copyright (c) 2011, 2012, 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.virtual.phases.ea; 024 025import java.util.*; 026 027public abstract class EffectsBlockState<T extends EffectsBlockState<T>> { 028 029 /* 030 * This flag specifies whether this path that leads to this block is unreachable. 031 */ 032 private boolean dead; 033 034 public EffectsBlockState() { 035 // emtpy 036 } 037 038 public EffectsBlockState(EffectsBlockState<T> other) { 039 this.dead = other.dead; 040 } 041 042 @Override 043 public String toString() { 044 return ""; 045 } 046 047 protected abstract boolean equivalentTo(T other); 048 049 public boolean isDead() { 050 return dead; 051 } 052 053 public void markAsDead() { 054 this.dead = true; 055 } 056 057 protected static <K, V> boolean compareMaps(Map<K, V> left, Map<K, V> right) { 058 if (left.size() != right.size()) { 059 return false; 060 } 061 return compareMapsNoSize(left, right); 062 } 063 064 protected static <K, V> boolean compareMapsNoSize(Map<K, V> left, Map<K, V> right) { 065 if (left == right) { 066 return true; 067 } 068 for (Map.Entry<K, V> entry : right.entrySet()) { 069 K key = entry.getKey(); 070 V value = entry.getValue(); 071 assert value != null; 072 V otherValue = left.get(key); 073 if (otherValue != value && !value.equals(otherValue)) { 074 return false; 075 } 076 } 077 return true; 078 } 079 080 protected static <U, V> void meetMaps(Map<U, V> target, Map<U, V> source) { 081 Iterator<Map.Entry<U, V>> iter = target.entrySet().iterator(); 082 while (iter.hasNext()) { 083 Map.Entry<U, V> entry = iter.next(); 084 if (source.containsKey(entry.getKey())) { 085 assert source.get(entry.getKey()) == entry.getValue(); 086 } else { 087 iter.remove(); 088 } 089 } 090 } 091 092}