Mercurial > hg > truffle
diff graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LocationIdentity.java @ 21556:48c1ebd24120
renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 27 May 2015 00:36:16 +0200 |
parents | graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/LocationIdentity.java@f9024b74dd9e |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/LocationIdentity.java Wed May 27 00:36:16 2015 +0200 @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.jvmci.meta; + +import java.util.*; + +// JaCoCo Exclude + +/** + * Marker interface for location identities. Apart from the special values {@link #ANY_LOCATION} and + * {@link #FINAL_LOCATION}, a different location identity of two memory accesses guarantees that the + * two accesses do not interfere. + * + * Clients of {@link LocationIdentity} must use {@link #equals(Object)}, not {@code ==}, when + * comparing two {@link LocationIdentity} values for equality. Likewise, they must not use + * {@link IdentityHashMap}s with {@link LocationIdentity} values as keys. + */ +public abstract class LocationIdentity { + + /** + * Denotes any location. A write to such a location kills all values in a memory map during an + * analysis of memory accesses. A read from this location cannot be moved or coalesced with + * other reads because its interaction with other reads is not known. + */ + private static final LocationIdentity ANY_LOCATION = NamedLocationIdentity.mutable("ANY_LOCATION"); + + /** + * Denotes the location of a value that is guaranteed to be unchanging. + */ + public static final LocationIdentity FINAL_LOCATION = NamedLocationIdentity.immutable("FINAL_LOCATION"); + + /** + * Denotes the location of the length field of a Java array. + */ + public static final LocationIdentity ARRAY_LENGTH_LOCATION = NamedLocationIdentity.immutable("[].length"); + + public static LocationIdentity any() { + return ANY_LOCATION; + } + + /** + * Denotes a location is unchanging in all cases. Not that this is different than the Java + * notion of final which only requires definite assignment. + */ + public abstract boolean isImmutable(); + + public final boolean isMutable() { + return !isImmutable(); + } + + public final boolean isAny() { + return this == ANY_LOCATION; + } + + public final boolean isSingle() { + return this != ANY_LOCATION; + } + + public final boolean overlaps(LocationIdentity other) { + return isAny() || other.isAny() || this.equals(other); + } +}