Mercurial > hg > graal-jvmci-8
annotate jvmci/jdk.vm.ci.meta/src/jdk/vm/ci/meta/PrimitiveConstant.java @ 24111:8abcd8e1285d
missing checks in HotSpotMemoryAccessProviderImpl can cause VM assertions to fail (JDK-8177673)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 30 Mar 2017 21:18:43 +0200 |
parents | 1bbd4a7c274b |
children |
rev | line source |
---|---|
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
1 /* |
18793
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
2 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
4 * |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
8 * |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
14 * |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
18 * |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
21 * questions. |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
22 */ |
22672
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22569
diff
changeset
|
23 package jdk.vm.ci.meta; |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
24 |
22569
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22536
diff
changeset
|
25 import java.nio.ByteBuffer; |
18793
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
26 |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
27 /** |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
28 * Represents a primitive constant value, such as an integer or floating point number, within the |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
29 * compiler and across the compiler/runtime interface. |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
30 */ |
22489
24b4e5e1431c
Remove JavaConstant from Value hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
31 public class PrimitiveConstant implements JavaConstant, SerializableConstant { |
24b4e5e1431c
Remove JavaConstant from Value hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
32 |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22489
diff
changeset
|
33 private final JavaKind kind; |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
34 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
35 /** |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
36 * The boxed primitive value as a {@code long}. For {@code float} and {@code double} values, |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
37 * this value is the result of {@link Float#floatToRawIntBits(float)} and |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
38 * {@link Double#doubleToRawLongBits(double)} respectively. |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
39 */ |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
40 private final long primitive; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
41 |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22489
diff
changeset
|
42 protected PrimitiveConstant(JavaKind kind, long primitive) { |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
43 this.primitive = primitive; |
22489
24b4e5e1431c
Remove JavaConstant from Value hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
44 this.kind = kind; |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
45 |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22489
diff
changeset
|
46 assert kind.isPrimitive() || kind == JavaKind.Illegal; |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
47 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
48 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
49 @Override |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22489
diff
changeset
|
50 public JavaKind getJavaKind() { |
22489
24b4e5e1431c
Remove JavaConstant from Value hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
51 return kind; |
24b4e5e1431c
Remove JavaConstant from Value hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
52 } |
24b4e5e1431c
Remove JavaConstant from Value hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
53 |
24b4e5e1431c
Remove JavaConstant from Value hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
54 @Override |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
55 public boolean isNull() { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
56 return false; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
57 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
58 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
59 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
60 public boolean isDefaultForKind() { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
61 return primitive == 0; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
62 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
63 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
64 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
65 public boolean asBoolean() { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22489
diff
changeset
|
66 assert getJavaKind() == JavaKind.Boolean; |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
67 return primitive != 0L; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
68 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
69 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
70 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
71 public int asInt() { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22489
diff
changeset
|
72 assert getJavaKind().getStackKind() == JavaKind.Int : getJavaKind().getStackKind(); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
73 return (int) primitive; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
74 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
75 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
76 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
77 public long asLong() { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22489
diff
changeset
|
78 assert getJavaKind().isNumericInteger(); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
79 return primitive; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
80 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
81 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
82 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
83 public float asFloat() { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22489
diff
changeset
|
84 assert getJavaKind() == JavaKind.Float; |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
85 return Float.intBitsToFloat((int) primitive); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
86 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
87 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
88 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
89 public double asDouble() { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22489
diff
changeset
|
90 assert getJavaKind() == JavaKind.Double; |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
91 return Double.longBitsToDouble(primitive); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
92 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
93 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
94 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
95 public Object asBoxedPrimitive() { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22489
diff
changeset
|
96 switch (getJavaKind()) { |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
97 case Byte: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
98 return Byte.valueOf((byte) primitive); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
99 case Boolean: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
100 return Boolean.valueOf(asBoolean()); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
101 case Short: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
102 return Short.valueOf((short) primitive); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
103 case Char: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
104 return Character.valueOf((char) primitive); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
105 case Int: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
106 return Integer.valueOf(asInt()); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
107 case Long: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
108 return Long.valueOf(asLong()); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
109 case Float: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
110 return Float.valueOf(asFloat()); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
111 case Double: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
112 return Double.valueOf(asDouble()); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
113 default: |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22489
diff
changeset
|
114 throw new IllegalArgumentException("unexpected kind " + getJavaKind()); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
115 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
116 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
117 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
118 @Override |
18793
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
119 public int getSerializedSize() { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22489
diff
changeset
|
120 return getJavaKind().getByteCount(); |
18793
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
121 } |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
122 |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
123 @Override |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
124 public void serialize(ByteBuffer buffer) { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22489
diff
changeset
|
125 switch (getJavaKind()) { |
18793
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
126 case Byte: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
127 case Boolean: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
128 buffer.put((byte) primitive); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
129 break; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
130 case Short: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
131 buffer.putShort((short) primitive); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
132 break; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
133 case Char: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
134 buffer.putChar((char) primitive); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
135 break; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
136 case Int: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
137 buffer.putInt(asInt()); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
138 break; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
139 case Long: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
140 buffer.putLong(asLong()); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
141 break; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
142 case Float: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
143 buffer.putFloat(asFloat()); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
144 break; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
145 case Double: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
146 buffer.putDouble(asDouble()); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
147 break; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
148 default: |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22489
diff
changeset
|
149 throw new IllegalArgumentException("unexpected kind " + getJavaKind()); |
18793
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
150 } |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
151 } |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
152 |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
153 @Override |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
154 public int hashCode() { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22489
diff
changeset
|
155 return (int) (primitive ^ (primitive >>> 32)) * (getJavaKind().ordinal() + 31); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
156 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
157 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
158 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
159 public boolean equals(Object o) { |
22489
24b4e5e1431c
Remove JavaConstant from Value hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
160 if (o == this) { |
24b4e5e1431c
Remove JavaConstant from Value hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
161 return true; |
24b4e5e1431c
Remove JavaConstant from Value hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
162 } |
24b4e5e1431c
Remove JavaConstant from Value hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
163 if (!(o instanceof PrimitiveConstant)) { |
24b4e5e1431c
Remove JavaConstant from Value hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
164 return false; |
24b4e5e1431c
Remove JavaConstant from Value hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
165 } |
24b4e5e1431c
Remove JavaConstant from Value hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
166 PrimitiveConstant other = (PrimitiveConstant) o; |
24b4e5e1431c
Remove JavaConstant from Value hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
167 return this.kind.equals(other.kind) && this.primitive == other.primitive; |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
168 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
169 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
170 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
171 public String toString() { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22489
diff
changeset
|
172 if (getJavaKind() == JavaKind.Illegal) { |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
173 return "illegal"; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
174 } else { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22489
diff
changeset
|
175 return getJavaKind().getJavaName() + "[" + asBoxedPrimitive() + "|0x" + Long.toHexString(primitive) + "]"; |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
176 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
177 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
178 } |