1 /* 2 * Copyright (c) 2011, 2016, 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 package org.graalvm.compiler.core.common; 24 25 // JaCoCo Exclude 26 27 /** 28 * Marker interface for location identities. A different location identity of two memory accesses 29 * guarantees that the two accesses do not interfere. 30 * 31 * Clients of {@link LocationIdentity} must use {@link #equals(Object)}, not {@code ==}, when 32 * comparing two {@link LocationIdentity} values for equality. Likewise, they must not use 33 * {@link java.util.IdentityHashMap}s with {@link LocationIdentity} values as keys. 34 */ 35 public abstract class LocationIdentity { 36 37 private static final class AnyLocationIdentity extends LocationIdentity { 38 @Override 39 public boolean isImmutable() { 40 return false; 41 } 42 43 @Override 44 public String toString() { 45 return "ANY_LOCATION"; 46 } 47 } 48 49 private static final class InitLocationIdentity extends LocationIdentity { 50 @Override 51 public boolean isImmutable() { 52 return true; 53 } 54 55 @Override 56 public String toString() { 57 return "INIT_LOCATION"; 58 } 59 } 60 61 public static final LocationIdentity ANY_LOCATION = new AnyLocationIdentity(); 62 public static final LocationIdentity INIT_LOCATION = new InitLocationIdentity(); 63 64 /** 65 * Indicates that the given location is the union of all possible mutable locations. A write to 66 * such a location kill all reads from mutable locations and a read from this location is killed 67 * by any write (except for initialization writes). 68 */ 69 public static LocationIdentity any() { 70 return ANY_LOCATION; 71 } 72 73 /** 74 * Location only allowed to be used for writes. Indicates that a completely new memory location 75 * is written. Kills no read. The previous value at the given location must be either 76 * uninitialized or null. Writes to this location do not need a GC pre-barrier. 77 */ 78 public static LocationIdentity init() { 79 return INIT_LOCATION; 80 } 81 82 /** 83 * Denotes a location is unchanging in all cases. Not that this is different than the Java 84 * notion of final which only requires definite assignment. 85 */ 86 public abstract boolean isImmutable(); 87 88 public final boolean isMutable() { 89 return !isImmutable(); 90 } 91 92 public final boolean isAny() { 93 return this == ANY_LOCATION; 94 } 95 96 public final boolean isInit() { 97 return this == INIT_LOCATION; 98 } 99 100 public final boolean isSingle() { 101 return this != ANY_LOCATION; 102 } 103 104 public final boolean overlaps(LocationIdentity other) { 105 return isAny() || other.isAny() || this.equals(other); 106 } 107 }