Mercurial > hg > graal-compiler
annotate graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/PrimitiveConstant.java @ 21643:2081f8f294fe
Fixed some javadoc
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Mon, 01 Jun 2015 11:49:57 -0700 |
parents | 48c1ebd24120 |
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 */ |
21556
48c1ebd24120
renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21411
diff
changeset
|
23 package com.oracle.jvmci.meta; |
15018
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 /** |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
34 * 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
|
35 * 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
|
36 * {@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
|
37 */ |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
38 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
|
39 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
40 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
|
41 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
|
42 this.primitive = primitive; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
43 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
44 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
|
45 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
46 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
47 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
48 public boolean isNull() { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
49 return false; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
50 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
51 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
52 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
53 public boolean isDefaultForKind() { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
54 return primitive == 0; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
55 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
56 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
57 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
58 public boolean asBoolean() { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
59 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
|
60 return primitive != 0L; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
61 } |
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 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
64 public int asInt() { |
21023
3ceda1f37dcc
[SPARC] Remove redundant compare type (kind) for CMOVE
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
18793
diff
changeset
|
65 assert getKind().getStackKind() == Kind.Int : getKind().getStackKind(); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
66 return (int) primitive; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
67 } |
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 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
70 public long asLong() { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
71 assert getKind().isNumericInteger(); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
72 return primitive; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
73 } |
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 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
76 public float asFloat() { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
77 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
|
78 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
|
79 } |
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 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
82 public double asDouble() { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
83 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
|
84 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
|
85 } |
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 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
88 public Object asBoxedPrimitive() { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
89 switch (getKind()) { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
90 case Byte: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
91 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
|
92 case Boolean: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
93 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
|
94 case Short: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
95 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
|
96 case Char: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
97 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
|
98 case Int: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
99 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
|
100 case Long: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
101 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
|
102 case Float: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
103 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
|
104 case Double: |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
105 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
|
106 default: |
15183
b862cf4381ef
don't throw exception for Constant.toValueString with Kind.Illegal
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15018
diff
changeset
|
107 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
|
108 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
109 } |
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 @Override |
18793
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
112 public int getSerializedSize() { |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
113 return getKind().getByteCount(); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
114 } |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
115 |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
116 @Override |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
117 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
|
118 switch (getKind()) { |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
119 case Byte: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
120 case Boolean: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
121 buffer.put((byte) primitive); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
122 break; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
123 case Short: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
124 buffer.putShort((short) primitive); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
125 break; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
126 case Char: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
127 buffer.putChar((char) primitive); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
128 break; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
129 case Int: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
130 buffer.putInt(asInt()); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
131 break; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
132 case Long: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
133 buffer.putLong(asLong()); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
134 break; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
135 case Float: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
136 buffer.putFloat(asFloat()); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
137 break; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
138 case Double: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
139 buffer.putDouble(asDouble()); |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
140 break; |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
141 default: |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
142 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
|
143 } |
ef51dadd50f7
Generalize ReinterpretNode to deal with arbitrary non-pointer types.
Roland Schatz <roland.schatz@oracle.com>
parents:
18320
diff
changeset
|
144 } |
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 @Override |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
147 public int hashCode() { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
148 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
|
149 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
150 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
151 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
152 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
|
153 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
|
154 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
155 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
156 @Override |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
157 public String toString() { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
158 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
|
159 return "illegal"; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
160 } else { |
17124
7b3ece800806
Using getKind().format is unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16094
diff
changeset
|
161 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
|
162 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
163 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
164 } |