annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnboxNode.java @ 17328:c9bb0da795d4

Backed out of changeset 17322:655f3e6b467b
author Doug Simon <doug.simon@oracle.com>
date Fri, 03 Oct 2014 14:19:58 +0200
parents 655f3e6b467b
children 45b45f902bed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
14085
af84c0b2e74f Don't remove UnboxNode if the incoming type is wrong.
Roland Schatz <roland.schatz@oracle.com>
parents: 12045
diff changeset
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
23 package com.oracle.graal.nodes.extended;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
5507
dc71b06d09f8 Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5504
diff changeset
25 import com.oracle.graal.api.meta.*;
15261
882f4cb7cfcf Move Stamps to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents: 15018
diff changeset
26 import com.oracle.graal.compiler.common.type.*;
11881
da9db8331658 moved Canonicalizable and Simplifiable to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents: 11880
diff changeset
27 import com.oracle.graal.graph.spi.*;
16841
cbd42807a31f moved NodeInfo and friends into separate com.oracle.graal.nodeinfo project so that annotation processor can be applied to the base Node class
Doug Simon <doug.simon@oracle.com>
parents: 16822
diff changeset
28 import com.oracle.graal.nodeinfo.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
29 import com.oracle.graal.nodes.*;
10569
6b9ebfcf5fc5 make BoxNode and UnboxNode floating
Lukas Stadler <lukas.stadler@jku.at>
parents: 9528
diff changeset
30 import com.oracle.graal.nodes.calc.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
31 import com.oracle.graal.nodes.spi.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32
16822
5d468add216f added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents: 16216
diff changeset
33 @NodeInfo
16216
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
34 public class UnboxNode extends UnaryNode implements Virtualizable, Lowerable {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35
17328
c9bb0da795d4 Backed out of changeset 17322:655f3e6b467b
Doug Simon <doug.simon@oracle.com>
parents: 17327
diff changeset
36 protected final Kind boxingKind;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37
16895
06c15e88d383 added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents: 16841
diff changeset
38 public static UnboxNode create(ValueNode value, Kind boxingKind) {
16919
0fe4732e5181 made use of generated Node classes predicated on value of graal.useGeneratedNodes system property (default is false)
Doug Simon <doug.simon@oracle.com>
parents: 16895
diff changeset
39 return USE_GENERATED_NODES ? new UnboxNodeGen(value, boxingKind) : new UnboxNode(value, boxingKind);
16895
06c15e88d383 added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents: 16841
diff changeset
40 }
06c15e88d383 added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents: 16841
diff changeset
41
17309
845e881ce054 constructors in a Node class must be protected
Doug Simon <doug.simon@oracle.com>
parents: 17276
diff changeset
42 protected UnboxNode(ValueNode value, Kind boxingKind) {
16156
0993768dfc8e new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
43 super(StampFactory.forKind(boxingKind.getStackKind()), value);
8913
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
44 this.boxingKind = boxingKind;
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
45 }
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
46
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
47 public Kind getBoxingKind() {
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
48 return boxingKind;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50
8913
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
51 @Override
11579
ae619d70bf4b Rename LoweringType to GuardsPhase and make it an attribute of StructuredGraphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10569
diff changeset
52 public void lower(LoweringTool tool) {
12045
0fc653a9e019 made GraalCodeCacheProvider independent of CodeCacheProvider and renamed the former to LoweringProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11959
diff changeset
53 tool.getLowerer().lower(this, tool);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55
8913
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
56 @Override
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
57 public void virtualize(VirtualizerTool tool) {
16156
0993768dfc8e new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
58 State state = tool.getObjectState(getValue());
8913
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
59 if (state != null && state.getState() == EscapeState.Virtual) {
14085
af84c0b2e74f Don't remove UnboxNode if the incoming type is wrong.
Roland Schatz <roland.schatz@oracle.com>
parents: 12045
diff changeset
60 ResolvedJavaType objectType = state.getVirtualObject().type();
af84c0b2e74f Don't remove UnboxNode if the incoming type is wrong.
Roland Schatz <roland.schatz@oracle.com>
parents: 12045
diff changeset
61 ResolvedJavaType expectedType = tool.getMetaAccessProvider().lookupJavaType(boxingKind.toBoxedJavaClass());
14160
fd7fcd2d2072 replaced == with .equals() for comparisons between JavaMethod/JavaField/JavaType values
Doug Simon <doug.simon@oracle.com>
parents: 14085
diff changeset
62 if (objectType.equals(expectedType)) {
14085
af84c0b2e74f Don't remove UnboxNode if the incoming type is wrong.
Roland Schatz <roland.schatz@oracle.com>
parents: 12045
diff changeset
63 tool.replaceWithValue(state.getEntry(0));
af84c0b2e74f Don't remove UnboxNode if the incoming type is wrong.
Roland Schatz <roland.schatz@oracle.com>
parents: 12045
diff changeset
64 }
8913
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
65 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
66 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
67
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68 @Override
16216
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
69 public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) {
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
70 if (forValue.isConstant()) {
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
71 Constant constant = forValue.asConstant();
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14160
diff changeset
72 Constant unboxed = tool.getConstantReflection().unboxPrimitive(constant);
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14160
diff changeset
73 if (unboxed != null && unboxed.getKind() == boxingKind) {
16216
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
74 return ConstantNode.forConstant(unboxed, tool.getMetaAccess());
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
75 }
16216
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
76 } else if (forValue instanceof BoxNode) {
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
77 BoxNode box = (BoxNode) forValue;
14085
af84c0b2e74f Don't remove UnboxNode if the incoming type is wrong.
Roland Schatz <roland.schatz@oracle.com>
parents: 12045
diff changeset
78 if (boxingKind == box.getBoxingKind()) {
af84c0b2e74f Don't remove UnboxNode if the incoming type is wrong.
Roland Schatz <roland.schatz@oracle.com>
parents: 12045
diff changeset
79 return box.getValue();
af84c0b2e74f Don't remove UnboxNode if the incoming type is wrong.
Roland Schatz <roland.schatz@oracle.com>
parents: 12045
diff changeset
80 }
8913
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
81 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
82 return this;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
83 }
8913
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
84
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
85 @NodeIntrinsic
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
86 public static native boolean unbox(Boolean value, @ConstantNodeParameter Kind kind);
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
87
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
88 @NodeIntrinsic
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
89 public static native byte unbox(Byte value, @ConstantNodeParameter Kind kind);
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
90
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
91 @NodeIntrinsic
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
92 public static native char unbox(Character value, @ConstantNodeParameter Kind kind);
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
93
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
94 @NodeIntrinsic
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
95 public static native double unbox(Double value, @ConstantNodeParameter Kind kind);
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
96
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
97 @NodeIntrinsic
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
98 public static native float unbox(Float value, @ConstantNodeParameter Kind kind);
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
99
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
100 @NodeIntrinsic
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
101 public static native int unbox(Integer value, @ConstantNodeParameter Kind kind);
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
102
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
103 @NodeIntrinsic
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
104 public static native long unbox(Long value, @ConstantNodeParameter Kind kind);
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
105
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
106 @NodeIntrinsic
653110156f8a refactored boxing identification and lowering, removed BoxingMethodPool and explicit boxing phases
Lukas Stadler <lukas.stadler@jku.at>
parents: 7660
diff changeset
107 public static native short unbox(Short value, @ConstantNodeParameter Kind kind);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
108 }