Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Constant.java @ 14563:82e4fe6fa525
Remove all references to NarrowOop from VM independent code.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Mon, 17 Mar 2014 13:08:32 +0100 |
parents | 958c99d0790c |
children | db4254246f9a |
rev | line source |
---|---|
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
4182
de7b3e7ae528
Simplify CiValue
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents:
4169
diff
changeset
|
2 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
4 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
8 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
14 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
18 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
21 * questions. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
22 */ |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5506
diff
changeset
|
23 package com.oracle.graal.api.meta; |
5502
13aee5aba8cc
Moved RiConstant to cri.ri package.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5501
diff
changeset
|
24 |
13627
a2aac8373610
more robust handling of errors in Constant.toString()
Doug Simon <doug.simon@oracle.com>
parents:
13588
diff
changeset
|
25 import static com.oracle.graal.api.meta.MetaUtil.*; |
a2aac8373610
more robust handling of errors in Constant.toString()
Doug Simon <doug.simon@oracle.com>
parents:
13588
diff
changeset
|
26 |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
27 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
28 * Represents a constant (boxed) value, such as an integer, floating point number, or object |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
29 * reference, within the compiler and across the compiler/runtime interface. Exports a set of |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
30 * {@code Constant} instances that represent frequently used constant values, such as |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
31 * {@link #NULL_OBJECT}. |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
32 */ |
5539
bc647d8b0080
Renaming RiValue => Value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5538
diff
changeset
|
33 public final class Constant extends Value { |
6539
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6329
diff
changeset
|
34 |
4182
de7b3e7ae528
Simplify CiValue
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents:
4169
diff
changeset
|
35 private static final long serialVersionUID = -6355452536852663986L; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
36 |
5538
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5507
diff
changeset
|
37 private static final Constant[] INT_CONSTANT_CACHE = new Constant[100]; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
38 static { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
39 for (int i = 0; i < INT_CONSTANT_CACHE.length; ++i) { |
7105
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
40 INT_CONSTANT_CACHE[i] = new Constant(Kind.Int, null, i); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
41 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
43 |
7105
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
44 public static final Constant NULL_OBJECT = new Constant(Kind.Object, null, 0); |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
45 public static final Constant INT_MINUS_1 = new Constant(Kind.Int, null, -1); |
5538
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5507
diff
changeset
|
46 public static final Constant INT_0 = forInt(0); |
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5507
diff
changeset
|
47 public static final Constant INT_1 = forInt(1); |
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5507
diff
changeset
|
48 public static final Constant INT_2 = forInt(2); |
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5507
diff
changeset
|
49 public static final Constant INT_3 = forInt(3); |
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5507
diff
changeset
|
50 public static final Constant INT_4 = forInt(4); |
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5507
diff
changeset
|
51 public static final Constant INT_5 = forInt(5); |
7105
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
52 public static final Constant LONG_0 = new Constant(Kind.Long, null, 0L); |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
53 public static final Constant LONG_1 = new Constant(Kind.Long, null, 1L); |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
54 public static final Constant FLOAT_0 = new Constant(Kind.Float, null, Float.floatToRawIntBits(0.0F)); |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
55 public static final Constant FLOAT_1 = new Constant(Kind.Float, null, Float.floatToRawIntBits(1.0F)); |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
56 public static final Constant FLOAT_2 = new Constant(Kind.Float, null, Float.floatToRawIntBits(2.0F)); |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
57 public static final Constant DOUBLE_0 = new Constant(Kind.Double, null, Double.doubleToRawLongBits(0.0D)); |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
58 public static final Constant DOUBLE_1 = new Constant(Kind.Double, null, Double.doubleToRawLongBits(1.0D)); |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
59 public static final Constant TRUE = new Constant(Kind.Boolean, null, 1L); |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
60 public static final Constant FALSE = new Constant(Kind.Boolean, null, 0L); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
61 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
62 static { |
5543
25d561cfdcfa
Clean up in api classes. Removed CiGenericCallback. Simplified Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5540
diff
changeset
|
63 assert FLOAT_0 != forFloat(-0.0F) : "Constant for 0.0f must be different from -0.0f"; |
25d561cfdcfa
Clean up in api classes. Removed CiGenericCallback. Simplified Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5540
diff
changeset
|
64 assert DOUBLE_0 != forDouble(-0.0d) : "Constant for 0.0d must be different from -0.0d"; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
65 assert NULL_OBJECT.isNull(); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
66 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
67 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
68 /** |
6996
eec373d34caf
added support for annotated Constants and used it to track Klass* values in Graal and register them in the metadata section of a nmethod during code installation
Doug Simon <doug.simon@oracle.com>
parents:
6994
diff
changeset
|
69 * The boxed object value if {@code !kind.isObject()} otherwise the (possibly null) |
eec373d34caf
added support for annotated Constants and used it to track Klass* values in Graal and register them in the metadata section of a nmethod during code installation
Doug Simon <doug.simon@oracle.com>
parents:
6994
diff
changeset
|
70 * {@link #getPrimitiveAnnotation() annotation} for a primitive value. |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
71 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
72 private final Object object; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
73 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
74 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
75 * The boxed primitive value as a {@code long}. This is ignored iff {@code kind.isObject()}. For |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
76 * {@code float} and {@code double} values, this value is the result of |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
77 * {@link Float#floatToRawIntBits(float)} and {@link Double#doubleToRawLongBits(double)} |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
78 * respectively. |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
79 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
80 private final long primitive; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
81 |
7105
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
82 private Constant(Kind kind, Object object, long primitive) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
83 super(kind); |
7105
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
84 this.object = object; |
6996
eec373d34caf
added support for annotated Constants and used it to track Klass* values in Graal and register them in the metadata section of a nmethod during code installation
Doug Simon <doug.simon@oracle.com>
parents:
6994
diff
changeset
|
85 this.primitive = primitive; |
eec373d34caf
added support for annotated Constants and used it to track Klass* values in Graal and register them in the metadata section of a nmethod during code installation
Doug Simon <doug.simon@oracle.com>
parents:
6994
diff
changeset
|
86 } |
eec373d34caf
added support for annotated Constants and used it to track Klass* values in Graal and register them in the metadata section of a nmethod during code installation
Doug Simon <doug.simon@oracle.com>
parents:
6994
diff
changeset
|
87 |
eec373d34caf
added support for annotated Constants and used it to track Klass* values in Graal and register them in the metadata section of a nmethod during code installation
Doug Simon <doug.simon@oracle.com>
parents:
6994
diff
changeset
|
88 /** |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
89 * Checks whether this constant is non-null. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
90 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
91 * @return {@code true} if this constant is a primitive, or an object constant that is not null |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
92 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
93 public boolean isNonNull() { |
7098
e23980f4a890
Cleanup of Kind class: remove isXxx methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6996
diff
changeset
|
94 return getKind() != Kind.Object || object != null; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
95 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
96 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
97 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
98 * Checks whether this constant is null. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
99 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
100 * @return {@code true} if this constant is the null constant |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
101 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
102 public boolean isNull() { |
7098
e23980f4a890
Cleanup of Kind class: remove isXxx methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6996
diff
changeset
|
103 return getKind() == Kind.Object && object == null; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
104 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
105 |
6708
a5156d39b622
add isDefaultForKind to Constant
Lukas Stadler <lukas.stadler@jku.at>
parents:
6539
diff
changeset
|
106 /** |
a5156d39b622
add isDefaultForKind to Constant
Lukas Stadler <lukas.stadler@jku.at>
parents:
6539
diff
changeset
|
107 * Checks whether this constant is the default value for its kind (null, 0, 0.0, false). |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
108 * |
6708
a5156d39b622
add isDefaultForKind to Constant
Lukas Stadler <lukas.stadler@jku.at>
parents:
6539
diff
changeset
|
109 * @return {@code true} if this constant is the default value for its kind |
a5156d39b622
add isDefaultForKind to Constant
Lukas Stadler <lukas.stadler@jku.at>
parents:
6539
diff
changeset
|
110 */ |
a5156d39b622
add isDefaultForKind to Constant
Lukas Stadler <lukas.stadler@jku.at>
parents:
6539
diff
changeset
|
111 public boolean isDefaultForKind() { |
a5156d39b622
add isDefaultForKind to Constant
Lukas Stadler <lukas.stadler@jku.at>
parents:
6539
diff
changeset
|
112 return object == null && primitive == 0; |
a5156d39b622
add isDefaultForKind to Constant
Lukas Stadler <lukas.stadler@jku.at>
parents:
6539
diff
changeset
|
113 } |
a5156d39b622
add isDefaultForKind to Constant
Lukas Stadler <lukas.stadler@jku.at>
parents:
6539
diff
changeset
|
114 |
13588
8aee7169dbe4
Improve documentation of data section building code.
Roland Schatz <roland.schatz@oracle.com>
parents:
13576
diff
changeset
|
115 public long getPrimitive() { |
8aee7169dbe4
Improve documentation of data section building code.
Roland Schatz <roland.schatz@oracle.com>
parents:
13576
diff
changeset
|
116 assert getKind().isPrimitive(); |
8aee7169dbe4
Improve documentation of data section building code.
Roland Schatz <roland.schatz@oracle.com>
parents:
13576
diff
changeset
|
117 return primitive; |
13576
4e679d50ba9a
Move data section building code to Java.
Roland Schatz <roland.schatz@oracle.com>
parents:
13140
diff
changeset
|
118 } |
4e679d50ba9a
Move data section building code to Java.
Roland Schatz <roland.schatz@oracle.com>
parents:
13140
diff
changeset
|
119 |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
120 @Override |
4169
f5328dda9714
Initial commit of SSA-based spill-all register assignment
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents:
4142
diff
changeset
|
121 public String toString() { |
12617
bca33c3135de
PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents:
11477
diff
changeset
|
122 if (getKind() == Kind.Illegal) { |
bca33c3135de
PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents:
11477
diff
changeset
|
123 return "illegal"; |
bca33c3135de
PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents:
11477
diff
changeset
|
124 } else { |
bca33c3135de
PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents:
11477
diff
changeset
|
125 String annotationSuffix = ""; |
13627
a2aac8373610
more robust handling of errors in Constant.toString()
Doug Simon <doug.simon@oracle.com>
parents:
13588
diff
changeset
|
126 Object primitiveAnnotation = getPrimitiveAnnotation(); |
a2aac8373610
more robust handling of errors in Constant.toString()
Doug Simon <doug.simon@oracle.com>
parents:
13588
diff
changeset
|
127 if (getKind() != Kind.Object && primitiveAnnotation != null) { |
a2aac8373610
more robust handling of errors in Constant.toString()
Doug Simon <doug.simon@oracle.com>
parents:
13588
diff
changeset
|
128 try { |
a2aac8373610
more robust handling of errors in Constant.toString()
Doug Simon <doug.simon@oracle.com>
parents:
13588
diff
changeset
|
129 annotationSuffix = "{" + primitiveAnnotation + "}"; |
a2aac8373610
more robust handling of errors in Constant.toString()
Doug Simon <doug.simon@oracle.com>
parents:
13588
diff
changeset
|
130 } catch (Throwable t) { |
a2aac8373610
more robust handling of errors in Constant.toString()
Doug Simon <doug.simon@oracle.com>
parents:
13588
diff
changeset
|
131 annotationSuffix = "{" + getSimpleName(primitiveAnnotation.getClass(), true) + "@" + System.identityHashCode(primitiveAnnotation) + "}"; |
a2aac8373610
more robust handling of errors in Constant.toString()
Doug Simon <doug.simon@oracle.com>
parents:
13588
diff
changeset
|
132 } |
12617
bca33c3135de
PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents:
11477
diff
changeset
|
133 } |
bca33c3135de
PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents:
11477
diff
changeset
|
134 return getKind().getJavaName() + "[" + getKind().format(asBoxedValue()) + (getKind() != Kind.Object ? "|0x" + Long.toHexString(primitive) : "") + "]" + annotationSuffix; |
6996
eec373d34caf
added support for annotated Constants and used it to track Klass* values in Graal and register them in the metadata section of a nmethod during code installation
Doug Simon <doug.simon@oracle.com>
parents:
6994
diff
changeset
|
135 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
136 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
137 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
138 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
139 * Returns the value of this constant as a boxed Java value. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
140 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
141 * @return the value of this constant |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
142 */ |
6539
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6329
diff
changeset
|
143 public Object asBoxedValue() { |
6329
92bc58dc5b5e
More clean up and documentation in api.code and api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
6328
diff
changeset
|
144 switch (getKind()) { |
6539
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6329
diff
changeset
|
145 case Byte: |
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6329
diff
changeset
|
146 return (byte) asInt(); |
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6329
diff
changeset
|
147 case Boolean: |
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6329
diff
changeset
|
148 return asInt() == 0 ? Boolean.FALSE : Boolean.TRUE; |
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6329
diff
changeset
|
149 case Short: |
6996
eec373d34caf
added support for annotated Constants and used it to track Klass* values in Graal and register them in the metadata section of a nmethod during code installation
Doug Simon <doug.simon@oracle.com>
parents:
6994
diff
changeset
|
150 return (short) primitive; |
6539
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6329
diff
changeset
|
151 case Char: |
6996
eec373d34caf
added support for annotated Constants and used it to track Klass* values in Graal and register them in the metadata section of a nmethod during code installation
Doug Simon <doug.simon@oracle.com>
parents:
6994
diff
changeset
|
152 return (char) primitive; |
6539
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6329
diff
changeset
|
153 case Int: |
6996
eec373d34caf
added support for annotated Constants and used it to track Klass* values in Graal and register them in the metadata section of a nmethod during code installation
Doug Simon <doug.simon@oracle.com>
parents:
6994
diff
changeset
|
154 return (int) primitive; |
6539
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6329
diff
changeset
|
155 case Long: |
6996
eec373d34caf
added support for annotated Constants and used it to track Klass* values in Graal and register them in the metadata section of a nmethod during code installation
Doug Simon <doug.simon@oracle.com>
parents:
6994
diff
changeset
|
156 return primitive; |
6539
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6329
diff
changeset
|
157 case Float: |
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6329
diff
changeset
|
158 return asFloat(); |
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6329
diff
changeset
|
159 case Double: |
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6329
diff
changeset
|
160 return asDouble(); |
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6329
diff
changeset
|
161 case Object: |
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6329
diff
changeset
|
162 return object; |
12617
bca33c3135de
PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents:
11477
diff
changeset
|
163 case Illegal: |
bca33c3135de
PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents:
11477
diff
changeset
|
164 return this; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
165 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
166 throw new IllegalArgumentException(); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
167 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
168 |
5538
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5507
diff
changeset
|
169 private boolean valueEqual(Constant other, boolean ignoreKind) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
170 // must have equivalent kinds to be equal |
6329
92bc58dc5b5e
More clean up and documentation in api.code and api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
6328
diff
changeset
|
171 if (!ignoreKind && getKind() != other.getKind()) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
172 return false; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
173 } |
14563
82e4fe6fa525
Remove all references to NarrowOop from VM independent code.
Roland Schatz <roland.schatz@oracle.com>
parents:
14000
diff
changeset
|
174 if (getKind() == Kind.Object) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
175 return object == other.object; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
176 } |
6996
eec373d34caf
added support for annotated Constants and used it to track Klass* values in Graal and register them in the metadata section of a nmethod during code installation
Doug Simon <doug.simon@oracle.com>
parents:
6994
diff
changeset
|
177 return primitive == other.primitive && getPrimitiveAnnotation() == other.getPrimitiveAnnotation(); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
178 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
179 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
180 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
181 * Returns the primitive int value this constant represents. The constant must have a |
7816
4e1278443941
Remove Kind.Jsr.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
182 * {@link Kind#getStackKind()} of {@link Kind#Int}. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
183 * |
7103
0c59b76e6689
Eliminate bogus conversion that Constant.asLong() performed; simplify asXxx methods so that they do not have control flow.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
184 * @return the constant value |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
185 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
186 public int asInt() { |
7816
4e1278443941
Remove Kind.Jsr.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
187 assert getKind().getStackKind() == Kind.Int; |
7103
0c59b76e6689
Eliminate bogus conversion that Constant.asLong() performed; simplify asXxx methods so that they do not have control flow.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
188 return (int) primitive; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
189 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
190 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
191 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
192 * Returns the primitive boolean value this constant represents. The constant must have kind |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
193 * {@link Kind#Boolean}. |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
194 * |
7103
0c59b76e6689
Eliminate bogus conversion that Constant.asLong() performed; simplify asXxx methods so that they do not have control flow.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
195 * @return the constant value |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
196 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
197 public boolean asBoolean() { |
7103
0c59b76e6689
Eliminate bogus conversion that Constant.asLong() performed; simplify asXxx methods so that they do not have control flow.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
198 assert getKind() == Kind.Boolean; |
0c59b76e6689
Eliminate bogus conversion that Constant.asLong() performed; simplify asXxx methods so that they do not have control flow.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
199 return primitive != 0L; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
200 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
201 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
202 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
203 * Returns the primitive long value this constant represents. The constant must have kind |
7816
4e1278443941
Remove Kind.Jsr.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
204 * {@link Kind#Long}, a {@link Kind#getStackKind()} of {@link Kind#Int}. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
205 * |
7103
0c59b76e6689
Eliminate bogus conversion that Constant.asLong() performed; simplify asXxx methods so that they do not have control flow.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
206 * @return the constant value |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
207 */ |
7103
0c59b76e6689
Eliminate bogus conversion that Constant.asLong() performed; simplify asXxx methods so that they do not have control flow.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
208 public long asLong() { |
12695
4aec62c32a82
Helper functions for identifying numeric kinds.
Roland Schatz <roland.schatz@oracle.com>
parents:
12617
diff
changeset
|
209 assert getKind().isNumericInteger(); |
7103
0c59b76e6689
Eliminate bogus conversion that Constant.asLong() performed; simplify asXxx methods so that they do not have control flow.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
210 return primitive; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
211 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
212 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
213 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
214 * Returns the primitive float value this constant represents. The constant must have kind |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
215 * {@link Kind#Float}. |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
216 * |
7103
0c59b76e6689
Eliminate bogus conversion that Constant.asLong() performed; simplify asXxx methods so that they do not have control flow.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
217 * @return the constant value |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
218 */ |
7103
0c59b76e6689
Eliminate bogus conversion that Constant.asLong() performed; simplify asXxx methods so that they do not have control flow.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
219 public float asFloat() { |
0c59b76e6689
Eliminate bogus conversion that Constant.asLong() performed; simplify asXxx methods so that they do not have control flow.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
220 assert getKind() == Kind.Float; |
0c59b76e6689
Eliminate bogus conversion that Constant.asLong() performed; simplify asXxx methods so that they do not have control flow.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
221 return Float.intBitsToFloat((int) primitive); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
222 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
223 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
224 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
225 * Returns the primitive double value this constant represents. The constant must have kind |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
226 * {@link Kind#Double}. |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
227 * |
7103
0c59b76e6689
Eliminate bogus conversion that Constant.asLong() performed; simplify asXxx methods so that they do not have control flow.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
228 * @return the constant value |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
229 */ |
7103
0c59b76e6689
Eliminate bogus conversion that Constant.asLong() performed; simplify asXxx methods so that they do not have control flow.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
230 public double asDouble() { |
0c59b76e6689
Eliminate bogus conversion that Constant.asLong() performed; simplify asXxx methods so that they do not have control flow.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
231 assert getKind() == Kind.Double; |
0c59b76e6689
Eliminate bogus conversion that Constant.asLong() performed; simplify asXxx methods so that they do not have control flow.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
232 return Double.longBitsToDouble(primitive); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
233 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
234 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
235 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
236 * Returns the object reference this constant represents. The constant must have kind |
14563
82e4fe6fa525
Remove all references to NarrowOop from VM independent code.
Roland Schatz <roland.schatz@oracle.com>
parents:
14000
diff
changeset
|
237 * {@link Kind#Object}. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
238 * |
7103
0c59b76e6689
Eliminate bogus conversion that Constant.asLong() performed; simplify asXxx methods so that they do not have control flow.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
239 * @return the constant value |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
240 */ |
7103
0c59b76e6689
Eliminate bogus conversion that Constant.asLong() performed; simplify asXxx methods so that they do not have control flow.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
241 public Object asObject() { |
14563
82e4fe6fa525
Remove all references to NarrowOop from VM independent code.
Roland Schatz <roland.schatz@oracle.com>
parents:
14000
diff
changeset
|
242 assert getKind() == Kind.Object; |
7103
0c59b76e6689
Eliminate bogus conversion that Constant.asLong() performed; simplify asXxx methods so that they do not have control flow.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
243 return object; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
244 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
245 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
246 /** |
6996
eec373d34caf
added support for annotated Constants and used it to track Klass* values in Graal and register them in the metadata section of a nmethod during code installation
Doug Simon <doug.simon@oracle.com>
parents:
6994
diff
changeset
|
247 * Gets the annotation (if any) associated with this constant. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
248 * |
6996
eec373d34caf
added support for annotated Constants and used it to track Klass* values in Graal and register them in the metadata section of a nmethod during code installation
Doug Simon <doug.simon@oracle.com>
parents:
6994
diff
changeset
|
249 * @return null if this constant is not primitive or has no annotation |
eec373d34caf
added support for annotated Constants and used it to track Klass* values in Graal and register them in the metadata section of a nmethod during code installation
Doug Simon <doug.simon@oracle.com>
parents:
6994
diff
changeset
|
250 */ |
eec373d34caf
added support for annotated Constants and used it to track Klass* values in Graal and register them in the metadata section of a nmethod during code installation
Doug Simon <doug.simon@oracle.com>
parents:
6994
diff
changeset
|
251 public Object getPrimitiveAnnotation() { |
14563
82e4fe6fa525
Remove all references to NarrowOop from VM independent code.
Roland Schatz <roland.schatz@oracle.com>
parents:
14000
diff
changeset
|
252 return getKind() == Kind.Object ? null : object; |
6996
eec373d34caf
added support for annotated Constants and used it to track Klass* values in Graal and register them in the metadata section of a nmethod during code installation
Doug Simon <doug.simon@oracle.com>
parents:
6994
diff
changeset
|
253 } |
eec373d34caf
added support for annotated Constants and used it to track Klass* values in Graal and register them in the metadata section of a nmethod during code installation
Doug Simon <doug.simon@oracle.com>
parents:
6994
diff
changeset
|
254 |
eec373d34caf
added support for annotated Constants and used it to track Klass* values in Graal and register them in the metadata section of a nmethod during code installation
Doug Simon <doug.simon@oracle.com>
parents:
6994
diff
changeset
|
255 /** |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
256 * Computes the hashcode of this constant. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
257 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
258 * @return a suitable hashcode for this constant |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
259 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
260 @Override |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
261 public int hashCode() { |
14563
82e4fe6fa525
Remove all references to NarrowOop from VM independent code.
Roland Schatz <roland.schatz@oracle.com>
parents:
14000
diff
changeset
|
262 if (getKind() == Kind.Object) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
263 return System.identityHashCode(object); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
264 } |
13140
3f1c70baa3bd
use separate data structure for canonicalizing ConstantNodes (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents:
12695
diff
changeset
|
265 return (int) primitive * getKind().ordinal(); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
266 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
267 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
268 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
269 * Checks whether this constant equals another object. This is only true if the other object is |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
270 * a constant that has the same {@linkplain #getKind() kind}, value and |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
271 * {@link #getPrimitiveAnnotation() annotation}. |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
272 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
273 * @param o the object to compare equality |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
274 * @return {@code true} if this constant is equivalent to the specified object |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
275 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
276 @Override |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
277 public boolean equals(Object o) { |
5538
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5507
diff
changeset
|
278 return o == this || o instanceof Constant && valueEqual((Constant) o, false); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
279 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
280 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
281 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
282 * Creates a boxed double constant. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
283 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
284 * @param d the double value to box |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
285 * @return a boxed copy of {@code value} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
286 */ |
5538
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5507
diff
changeset
|
287 public static Constant forDouble(double d) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
288 if (Double.compare(0.0D, d) == 0) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
289 return DOUBLE_0; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
290 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
291 if (Double.compare(d, 1.0D) == 0) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
292 return DOUBLE_1; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
293 } |
7105
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
294 return new Constant(Kind.Double, null, Double.doubleToRawLongBits(d)); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
295 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
296 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
297 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
298 * Creates a boxed float constant. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
299 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
300 * @param f the float value to box |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
301 * @return a boxed copy of {@code value} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
302 */ |
5538
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5507
diff
changeset
|
303 public static Constant forFloat(float f) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
304 if (Float.compare(f, 0.0F) == 0) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
305 return FLOAT_0; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
306 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
307 if (Float.compare(f, 1.0F) == 0) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
308 return FLOAT_1; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
309 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
310 if (Float.compare(f, 2.0F) == 0) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
311 return FLOAT_2; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
312 } |
7105
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
313 return new Constant(Kind.Float, null, Float.floatToRawIntBits(f)); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
314 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
315 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
316 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
317 * Creates a boxed long constant. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
318 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
319 * @param i the long value to box |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
320 * @return a boxed copy of {@code value} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
321 */ |
5538
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5507
diff
changeset
|
322 public static Constant forLong(long i) { |
7105
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
323 return i == 0 ? LONG_0 : i == 1 ? LONG_1 : new Constant(Kind.Long, null, i); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
324 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
325 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
326 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
327 * Creates a boxed integer constant. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
328 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
329 * @param i the integer value to box |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
330 * @return a boxed copy of {@code value} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
331 */ |
5538
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5507
diff
changeset
|
332 public static Constant forInt(int i) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
333 if (i == -1) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
334 return INT_MINUS_1; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
335 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
336 if (i >= 0 && i < INT_CONSTANT_CACHE.length) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
337 return INT_CONSTANT_CACHE[i]; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
338 } |
7105
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
339 return new Constant(Kind.Int, null, i); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
340 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
341 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
342 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
343 * Creates a boxed byte constant. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
344 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
345 * @param i the byte value to box |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
346 * @return a boxed copy of {@code value} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
347 */ |
5538
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5507
diff
changeset
|
348 public static Constant forByte(byte i) { |
7105
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
349 return new Constant(Kind.Byte, null, i); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
350 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
351 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
352 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
353 * Creates a boxed boolean constant. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
354 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
355 * @param i the boolean value to box |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
356 * @return a boxed copy of {@code value} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
357 */ |
5538
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5507
diff
changeset
|
358 public static Constant forBoolean(boolean i) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
359 return i ? TRUE : FALSE; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
360 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
361 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
362 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
363 * Creates a boxed char constant. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
364 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
365 * @param i the char value to box |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
366 * @return a boxed copy of {@code value} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
367 */ |
5538
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5507
diff
changeset
|
368 public static Constant forChar(char i) { |
7105
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
369 return new Constant(Kind.Char, null, i); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
370 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
371 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
372 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
373 * Creates a boxed short constant. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
374 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
375 * @param i the short value to box |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
376 * @return a boxed copy of {@code value} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
377 */ |
5538
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5507
diff
changeset
|
378 public static Constant forShort(short i) { |
7105
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
379 return new Constant(Kind.Short, null, i); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
380 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
381 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
382 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
383 * Creates a boxed object constant. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
384 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
385 * @param o the object value to box |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
386 * @return a boxed copy of {@code value} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
387 */ |
5538
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5507
diff
changeset
|
388 public static Constant forObject(Object o) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
389 if (o == null) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
390 return NULL_OBJECT; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
391 } |
7105
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
392 return new Constant(Kind.Object, o, 0L); |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
393 } |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
394 |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
395 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
396 * Creates an annotated int or long constant. An annotation enables a client to associate some |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
397 * extra semantic or debugging information with a primitive. An annotated primitive constant is |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
398 * never {@linkplain #equals(Object) equal} to a non-annotated constant. |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
399 * |
7105
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
400 * @param kind the type of this constant |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
401 * @param i the value of this constant |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
402 * @param annotation an arbitrary non-null object |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
403 */ |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
404 public static Constant forIntegerKind(Kind kind, long i, Object annotation) { |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
405 switch (kind) { |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
406 case Int: |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
407 return new Constant(kind, annotation, (int) i); |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
408 case Long: |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
409 return new Constant(kind, annotation, i); |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
410 default: |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
411 throw new IllegalArgumentException("not an integer kind: " + kind); |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
412 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
413 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
414 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
415 /** |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13726
diff
changeset
|
416 * Creates a {@link Constant} from a primitive integer of a certain width. |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13726
diff
changeset
|
417 */ |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13726
diff
changeset
|
418 public static Constant forPrimitiveInt(int bits, long i) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13726
diff
changeset
|
419 assert bits <= 64; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13726
diff
changeset
|
420 if (bits > 32) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13726
diff
changeset
|
421 return new Constant(Kind.Long, null, i); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13726
diff
changeset
|
422 } else { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13726
diff
changeset
|
423 return new Constant(Kind.Int, null, (int) i); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13726
diff
changeset
|
424 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13726
diff
changeset
|
425 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13726
diff
changeset
|
426 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13726
diff
changeset
|
427 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
428 * Creates a boxed constant for the given kind from an Object. The object needs to be of the |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
429 * Java boxed type corresponding to the kind. |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
430 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
431 * @param kind the kind of the constant to create |
5774
a1db0ea58b53
Removed left over Ci* prefixed identifiers
Doug Simon <doug.simon@oracle.com>
parents:
5711
diff
changeset
|
432 * @param value the Java boxed value: a {@link Byte} instance for {@link Kind#Byte}, etc. |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
433 * @return the boxed copy of {@code value} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
434 */ |
5540
a891c53a295b
Renaming RiKind => Kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5539
diff
changeset
|
435 public static Constant forBoxed(Kind kind, Object value) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
436 switch (kind) { |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
4199
diff
changeset
|
437 case Boolean: |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
4199
diff
changeset
|
438 return forBoolean((Boolean) value); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
439 case Byte: |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
440 return forByte((Byte) value); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
441 case Char: |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
442 return forChar((Character) value); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
443 case Short: |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
444 return forShort((Short) value); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
445 case Int: |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
446 return forInt((Integer) value); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
447 case Long: |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
448 return forLong((Long) value); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
449 case Float: |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
450 return forFloat((Float) value); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
451 case Double: |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
452 return forDouble((Double) value); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
453 case Object: |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
454 return forObject(value); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
455 default: |
5572
8f9c9d372e31
small renaming and doc fixes
Lukas Stadler <lukas.stadler@jku.at>
parents:
5543
diff
changeset
|
456 throw new RuntimeException("cannot create Constant for boxed " + kind + " value"); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
457 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
458 } |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
459 |
12617
bca33c3135de
PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents:
11477
diff
changeset
|
460 public static Constant forIllegal() { |
bca33c3135de
PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents:
11477
diff
changeset
|
461 return new Constant(Kind.Illegal, null, 0); |
bca33c3135de
PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents:
11477
diff
changeset
|
462 } |
bca33c3135de
PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents:
11477
diff
changeset
|
463 |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
464 /** |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
465 * Returns a constant with the default value for the given kind. |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
466 */ |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
467 public static Constant defaultForKind(Kind kind) { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
468 switch (kind) { |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
469 case Boolean: |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
470 return FALSE; |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
471 case Byte: |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
472 return forByte((byte) 0); |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
473 case Char: |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
474 return forChar((char) 0); |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
475 case Short: |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
476 return forShort((short) 0); |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
477 case Int: |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
478 return INT_0; |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
479 case Double: |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
480 return DOUBLE_0; |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
481 case Float: |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
482 return FLOAT_0; |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
483 case Long: |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
484 return LONG_0; |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
485 case Object: |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
486 return NULL_OBJECT; |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
487 default: |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
488 throw new IllegalArgumentException(kind.toString()); |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
489 } |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
490 } |
11477
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
491 |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
492 /** |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
493 * Returns the zero value for a given numeric kind. |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
494 */ |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
495 public static Constant zero(Kind kind) { |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
496 switch (kind) { |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
497 case Byte: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
498 return forByte((byte) 0); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
499 case Char: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
500 return forChar((char) 0); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
501 case Double: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
502 return DOUBLE_0; |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
503 case Float: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
504 return FLOAT_0; |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
505 case Int: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
506 return INT_0; |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
507 case Long: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
508 return LONG_0; |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
509 case Short: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
510 return forShort((short) 0); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
511 default: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
512 throw new IllegalArgumentException(kind.toString()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
513 } |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
514 } |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
515 |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
516 /** |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
517 * Returns the one value for a given numeric kind. |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
518 */ |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
519 public static Constant one(Kind kind) { |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
520 switch (kind) { |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
521 case Byte: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
522 return forByte((byte) 1); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
523 case Char: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
524 return forChar((char) 1); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
525 case Double: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
526 return DOUBLE_1; |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
527 case Float: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
528 return FLOAT_1; |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
529 case Int: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
530 return INT_1; |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
531 case Long: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
532 return LONG_1; |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
533 case Short: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
534 return forShort((short) 1); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
535 default: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
536 throw new IllegalArgumentException(kind.toString()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
537 } |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
538 } |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
539 |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
540 /** |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
541 * Adds two numeric constants. |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
542 */ |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
543 public static Constant add(Constant x, Constant y) { |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
544 assert x.getKind() == y.getKind(); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
545 switch (x.getKind()) { |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
546 case Byte: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
547 return forByte((byte) (x.asInt() + y.asInt())); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
548 case Char: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
549 return forChar((char) (x.asInt() + y.asInt())); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
550 case Double: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
551 return forDouble(x.asDouble() + y.asDouble()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
552 case Float: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
553 return forFloat(x.asFloat() + y.asFloat()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
554 case Int: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
555 return forInt(x.asInt() + y.asInt()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
556 case Long: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
557 return forLong(x.asLong() + y.asLong()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
558 case Short: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
559 return forShort((short) (x.asInt() + y.asInt())); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
560 default: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
561 throw new IllegalArgumentException(x.getKind().toString()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
562 } |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
563 } |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
564 |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
565 /** |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
566 * Multiplies two numeric constants. |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
567 */ |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
568 public static Constant mul(Constant x, Constant y) { |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
569 assert x.getKind() == y.getKind(); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
570 switch (x.getKind()) { |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
571 case Byte: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
572 return forByte((byte) (x.asInt() * y.asInt())); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
573 case Char: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
574 return forChar((char) (x.asInt() * y.asInt())); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
575 case Double: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
576 return forDouble(x.asDouble() * y.asDouble()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
577 case Float: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
578 return forFloat(x.asFloat() * y.asFloat()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
579 case Int: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
580 return forInt(x.asInt() * y.asInt()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
581 case Long: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
582 return forLong(x.asLong() * y.asLong()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
583 case Short: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
584 return forShort((short) (x.asInt() * y.asInt())); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
585 default: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
586 throw new IllegalArgumentException(x.getKind().toString()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
587 } |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
588 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
589 } |