annotate graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/NamedLocationIdentity.java @ 19997:58f2aad37d0e

Further improvements to IGV. Make displayed names of nodes shorter.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Mon, 23 Mar 2015 00:26:37 +0100
parents 88e8fe50ccac
children f9024b74dd9e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9792
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 *
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 *
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 * accompanied this code).
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 *
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 *
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 * questions.
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
22 */
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.api.meta;
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
25 import java.util.*;
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
26
18537
ee1b8eb230f7 made NamedLocationIdentity implement FormatWithToString
Doug Simon <doug.simon@oracle.com>
parents: 18317
diff changeset
27 import com.oracle.graal.api.meta.Kind.FormatWithToString;
ee1b8eb230f7 made NamedLocationIdentity implement FormatWithToString
Doug Simon <doug.simon@oracle.com>
parents: 18317
diff changeset
28
9792
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
29 /**
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
30 * A {@link LocationIdentity} with a name.
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
31 */
19844
426461951938 Convert LocationIdentity from an interface into an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18537
diff changeset
32 public final class NamedLocationIdentity extends LocationIdentity implements FormatWithToString {
18259
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
33
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
34 /**
18317
c83efc00f6cc made LocationIdentity values support .equals() instead of identity (i.e. '==') for equality comparisons (and as hash map keys)
Doug Simon <doug.simon@oracle.com>
parents: 18307
diff changeset
35 * Map for asserting all {@link NamedLocationIdentity} instances have a unique name.
18259
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
36 */
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
37 static class DB {
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
38 private static final HashMap<String, NamedLocationIdentity> map = new HashMap<>();
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
39
18317
c83efc00f6cc made LocationIdentity values support .equals() instead of identity (i.e. '==') for equality comparisons (and as hash map keys)
Doug Simon <doug.simon@oracle.com>
parents: 18307
diff changeset
40 static boolean checkUnique(NamedLocationIdentity identity) {
18259
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
41 NamedLocationIdentity oldValue = map.put(identity.name, identity);
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
42 if (oldValue != null) {
18317
c83efc00f6cc made LocationIdentity values support .equals() instead of identity (i.e. '==') for equality comparisons (and as hash map keys)
Doug Simon <doug.simon@oracle.com>
parents: 18307
diff changeset
43 throw new AssertionError("identity " + identity + " already exists");
18259
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
44 }
18317
c83efc00f6cc made LocationIdentity values support .equals() instead of identity (i.e. '==') for equality comparisons (and as hash map keys)
Doug Simon <doug.simon@oracle.com>
parents: 18307
diff changeset
45 return true;
18259
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
46 }
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
47 }
9792
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
48
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
49 protected final String name;
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
50
18259
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
51 private NamedLocationIdentity(String name, boolean immutable) {
19845
3d0116ec99c5 Create utilities LocationIdentity#isAny, LocationIdentity#isSingle, LocationIdentity#any, LocationIdentity#overlaps.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19844
diff changeset
52 super(immutable);
9792
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
53 this.name = name;
18231
70df63b02309 Use LocationIdentity.isImmutable instead of testing against FINAL_LOCATION
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 9792
diff changeset
54 }
70df63b02309 Use LocationIdentity.isImmutable instead of testing against FINAL_LOCATION
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 9792
diff changeset
55
70df63b02309 Use LocationIdentity.isImmutable instead of testing against FINAL_LOCATION
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 9792
diff changeset
56 /**
18307
85f5227a7a37 add mutable/immutable factory methods to NamedLocationIdentity
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18259
diff changeset
57 * Creates a named unique location identity for read and write operations against mutable
85f5227a7a37 add mutable/immutable factory methods to NamedLocationIdentity
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18259
diff changeset
58 * memory.
18231
70df63b02309 Use LocationIdentity.isImmutable instead of testing against FINAL_LOCATION
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 9792
diff changeset
59 *
70df63b02309 Use LocationIdentity.isImmutable instead of testing against FINAL_LOCATION
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 9792
diff changeset
60 * @param name the name of the new location identity
70df63b02309 Use LocationIdentity.isImmutable instead of testing against FINAL_LOCATION
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 9792
diff changeset
61 */
18307
85f5227a7a37 add mutable/immutable factory methods to NamedLocationIdentity
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18259
diff changeset
62 public static NamedLocationIdentity mutable(String name) {
18259
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
63 return create(name, false);
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
64 }
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
65
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
66 /**
18307
85f5227a7a37 add mutable/immutable factory methods to NamedLocationIdentity
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18259
diff changeset
67 * Creates a named unique location identity for read operations against immutable memory.
85f5227a7a37 add mutable/immutable factory methods to NamedLocationIdentity
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18259
diff changeset
68 * Immutable memory will never have a visible write in the graph, which is more restictive than
85f5227a7a37 add mutable/immutable factory methods to NamedLocationIdentity
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18259
diff changeset
69 * Java final.
85f5227a7a37 add mutable/immutable factory methods to NamedLocationIdentity
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18259
diff changeset
70 *
85f5227a7a37 add mutable/immutable factory methods to NamedLocationIdentity
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18259
diff changeset
71 * @param name the name of the new location identity
85f5227a7a37 add mutable/immutable factory methods to NamedLocationIdentity
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18259
diff changeset
72 */
85f5227a7a37 add mutable/immutable factory methods to NamedLocationIdentity
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18259
diff changeset
73 public static NamedLocationIdentity immutable(String name) {
85f5227a7a37 add mutable/immutable factory methods to NamedLocationIdentity
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18259
diff changeset
74 return create(name, true);
85f5227a7a37 add mutable/immutable factory methods to NamedLocationIdentity
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18259
diff changeset
75 }
85f5227a7a37 add mutable/immutable factory methods to NamedLocationIdentity
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18259
diff changeset
76
85f5227a7a37 add mutable/immutable factory methods to NamedLocationIdentity
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18259
diff changeset
77 /**
18259
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
78 * Creates a named unique location identity for read and write operations.
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
79 *
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
80 * @param name the name of the new location identity
18307
85f5227a7a37 add mutable/immutable factory methods to NamedLocationIdentity
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18259
diff changeset
81 * @param immutable true if the location is immutable
18259
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
82 */
18307
85f5227a7a37 add mutable/immutable factory methods to NamedLocationIdentity
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18259
diff changeset
83 private static NamedLocationIdentity create(String name, boolean immutable) {
18317
c83efc00f6cc made LocationIdentity values support .equals() instead of identity (i.e. '==') for equality comparisons (and as hash map keys)
Doug Simon <doug.simon@oracle.com>
parents: 18307
diff changeset
84 NamedLocationIdentity id = new NamedLocationIdentity(name, immutable);
c83efc00f6cc made LocationIdentity values support .equals() instead of identity (i.e. '==') for equality comparisons (and as hash map keys)
Doug Simon <doug.simon@oracle.com>
parents: 18307
diff changeset
85 assert DB.checkUnique(id);
c83efc00f6cc made LocationIdentity values support .equals() instead of identity (i.e. '==') for equality comparisons (and as hash map keys)
Doug Simon <doug.simon@oracle.com>
parents: 18307
diff changeset
86 return id;
18259
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
87 }
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
88
e1b2489393f4 added global map to ensure each NamedLocationIdentity object has a unique name which can be used for implementing .equals() and .hashCode()
Doug Simon <doug.simon@oracle.com>
parents: 18231
diff changeset
89 @Override
9792
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
90 public String toString() {
19997
58f2aad37d0e Further improvements to IGV. Make displayed names of nodes shorter.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19851
diff changeset
91 return name + (isImmutable() ? ":final" : "");
18231
70df63b02309 Use LocationIdentity.isImmutable instead of testing against FINAL_LOCATION
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 9792
diff changeset
92 }
70df63b02309 Use LocationIdentity.isImmutable instead of testing against FINAL_LOCATION
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 9792
diff changeset
93
9792
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
94 /**
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
95 * Returns the named location identity for an array of the given element kind. Array accesses of
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
96 * the same kind must have the same location identity unless an alias analysis guarantees that
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
97 * two distinct arrays are accessed.
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
98 */
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
99 public static LocationIdentity getArrayLocation(Kind elementKind) {
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
100 return ARRAY_LOCATIONS.get(elementKind);
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
101 }
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
102
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
103 private static final EnumMap<Kind, LocationIdentity> ARRAY_LOCATIONS = initArrayLocations();
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
104
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
105 private static EnumMap<Kind, LocationIdentity> initArrayLocations() {
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
106 EnumMap<Kind, LocationIdentity> result = new EnumMap<>(Kind.class);
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
107 for (Kind kind : Kind.values()) {
18307
85f5227a7a37 add mutable/immutable factory methods to NamedLocationIdentity
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18259
diff changeset
108 result.put(kind, NamedLocationIdentity.mutable("Array: " + kind.getJavaName()));
9792
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
109 }
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
110 return result;
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
111 }
06dc2d2324d6 pulled LocationIdentity into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
112 }