Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/PrimitiveConstant.java @ 18793:ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Wed, 07 Jan 2015 14:05:14 +0100 |
parents | 0093dcea7092 |
children | 3ceda1f37dcc |
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 */ |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.api.meta; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
24 |
18793
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
25 import java.nio.*; |
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 */ |
18793
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
31 public class PrimitiveConstant extends AbstractValue implements JavaConstant, SerializableConstant { |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
32 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
33 private static final long serialVersionUID = 8787949721295655376L; |
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 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
42 protected PrimitiveConstant(Kind kind, long primitive) { |
16094
c0b8d395368b
Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents:
15183
diff
changeset
|
43 super(LIRKind.value(kind)); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
44 this.primitive = primitive; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
45 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
46 assert kind.isPrimitive() || kind == Kind.Illegal; |
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 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
50 public boolean isNull() { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
51 return false; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
52 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
53 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
54 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
55 public boolean isDefaultForKind() { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
56 return primitive == 0; |
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 asBoolean() { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
61 assert getKind() == Kind.Boolean; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
62 return primitive != 0L; |
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 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
65 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
66 public int asInt() { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
67 assert getKind().getStackKind() == Kind.Int; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
68 return (int) primitive; |
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 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
71 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
72 public long asLong() { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
73 assert getKind().isNumericInteger(); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
74 return primitive; |
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 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
77 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
78 public float asFloat() { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
79 assert getKind() == Kind.Float; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
80 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
|
81 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
82 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
83 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
84 public double asDouble() { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
85 assert getKind() == Kind.Double; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
86 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
|
87 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
88 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
89 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
90 public Object asBoxedPrimitive() { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
91 switch (getKind()) { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
92 case Byte: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
93 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
|
94 case Boolean: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
95 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
|
96 case Short: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
97 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
|
98 case Char: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
99 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
|
100 case Int: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
101 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
|
102 case Long: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
103 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
|
104 case Float: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
105 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
|
106 case Double: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
107 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
|
108 default: |
15183
b862cf4381ef
don't throw exception for Constant.toValueString with Kind.Illegal
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15018
diff
changeset
|
109 throw new IllegalArgumentException("unexpected kind " + getKind()); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
110 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
111 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
112 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
113 @Override |
18793
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
114 public int getSerializedSize() { |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
115 return getKind().getByteCount(); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
116 } |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
117 |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
118 @Override |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
119 public void serialize(ByteBuffer buffer) { |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
120 switch (getKind()) { |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
121 case Byte: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
122 case Boolean: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
123 buffer.put((byte) primitive); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
124 break; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
125 case Short: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
126 buffer.putShort((short) primitive); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
127 break; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
128 case Char: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
129 buffer.putChar((char) primitive); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
130 break; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
131 case Int: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
132 buffer.putInt(asInt()); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
133 break; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
134 case Long: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
135 buffer.putLong(asLong()); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
136 break; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
137 case Float: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
138 buffer.putFloat(asFloat()); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
139 break; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
140 case Double: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
141 buffer.putDouble(asDouble()); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
142 break; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
143 default: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
144 throw new IllegalArgumentException("unexpected kind " + getKind()); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
145 } |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
146 } |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
147 |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
148 @Override |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
149 public int hashCode() { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
150 return (int) (primitive ^ (primitive >>> 32)) * (getKind().ordinal() + 31); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
151 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
152 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
153 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
154 public boolean equals(Object o) { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
155 return o == this || (o instanceof PrimitiveConstant && super.equals(o) && primitive == ((PrimitiveConstant) o).primitive); |
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 String toString() { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
160 if (getKind() == Kind.Illegal) { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
161 return "illegal"; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
162 } else { |
17124
7b3ece800806
Using getKind().format is unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16094
diff
changeset
|
163 return getKind().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
|
164 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
165 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
166 } |