comparison jvmci/jdk.vm.ci.meta/src/jdk/vm/ci/meta/Value.java @ 22672:1bbd4a7c274b

Rename jdk.internal.jvmci to jdk.vm.ci
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Thu, 08 Oct 2015 17:28:41 -0700
parents jvmci/jdk.internal.jvmci.meta/src/jdk/internal/jvmci/meta/Value.java@df053711614b
children 9ed5b586018b
comparison
equal deleted inserted replaced
22671:97f30e4d0e95 22672:1bbd4a7c274b
1 /*
2 * Copyright (c) 2009, 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 package jdk.vm.ci.meta;
24
25 /**
26 * Abstract base class for values.
27 */
28 public abstract class Value {
29
30 public static final Value[] NO_VALUES = new Value[0];
31
32 public static final AllocatableValue ILLEGAL = new IllegalValue();
33
34 private static final class IllegalValue extends AllocatableValue {
35 private IllegalValue() {
36 super(LIRKind.Illegal);
37 }
38
39 @Override
40 public String toString() {
41 return "-";
42 }
43
44 @Override
45 public boolean equals(Object other) {
46 // Due to de-serialization this object may exist multiple times. So we compare classes
47 // instead of the individual objects. (This anonymous class has always the same meaning)
48 return other instanceof IllegalValue;
49 }
50 }
51
52 private final LIRKind lirKind;
53
54 /**
55 * Initializes a new value of the specified kind.
56 *
57 * @param lirKind the kind
58 */
59 protected Value(LIRKind lirKind) {
60 this.lirKind = lirKind;
61 }
62
63 /**
64 * Returns a String representation of the kind, which should be the end of all
65 * {@link #toString()} implementation of subclasses.
66 */
67 protected final String getKindSuffix() {
68 return "|" + getPlatformKind().getTypeChar();
69 }
70
71 public final LIRKind getLIRKind() {
72 return lirKind;
73 }
74
75 /**
76 * Returns the platform specific kind used to store this value.
77 */
78 public final PlatformKind getPlatformKind() {
79 return lirKind.getPlatformKind();
80 }
81
82 @Override
83 public int hashCode() {
84 return 41 + lirKind.hashCode();
85 }
86
87 @Override
88 public boolean equals(Object obj) {
89 if (obj instanceof Value) {
90 Value that = (Value) obj;
91 return lirKind.equals(that.lirKind);
92 }
93 return false;
94 }
95
96 /**
97 * Checks if this value is identical to {@code other}.
98 *
99 * Warning: Use with caution! Usually equivalence {@link #equals(Object)} is sufficient and
100 * should be used.
101 */
102 public final boolean identityEquals(Value other) {
103 return this == other;
104 }
105 }