Mercurial > hg > truffle
annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/ClassCastNode.java @ 15018:db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Mon, 07 Apr 2014 16:09:17 -0700 |
parents | 2606d64dc08b |
children | 288c23143d47 |
rev | line source |
---|---|
11712
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
4 * |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
8 * |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
14 * |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
18 * |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
21 * questions. |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
22 */ |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.hotspot.nodes; |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
24 |
11880
9a747d8e0d0f
broadened types in Canonicalizable interface so that it can be moved to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents:
11712
diff
changeset
|
25 import com.oracle.graal.graph.*; |
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
|
26 import com.oracle.graal.graph.spi.*; |
11712
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
27 import com.oracle.graal.hotspot.meta.*; |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
28 import com.oracle.graal.hotspot.replacements.*; |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
29 import com.oracle.graal.nodes.*; |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.graal.nodes.java.*; |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
31 import com.oracle.graal.replacements.nodes.*; |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
32 |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
33 /** |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
34 * {@link MacroNode Macro node} for {@link Class#cast(Object)}. |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
35 * |
14071 | 36 * @see ClassSubstitutions#cast(Class, Object) |
11712
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
37 */ |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
38 public class ClassCastNode extends MacroNode implements Canonicalizable { |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
39 |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
40 public ClassCastNode(Invoke invoke) { |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
41 super(invoke); |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 } |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
43 |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
44 private ValueNode getJavaClass() { |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
45 return arguments.get(0); |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
46 } |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
47 |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
48 private ValueNode getObject() { |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
49 return arguments.get(1); |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
50 } |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
51 |
11882
51059863da73
replace instanceof type tests for Canonicalizable and Simplifiable with extra boolean properties in NodeClass (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents:
11881
diff
changeset
|
52 @Override |
11880
9a747d8e0d0f
broadened types in Canonicalizable interface so that it can be moved to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents:
11712
diff
changeset
|
53 public Node canonical(CanonicalizerTool tool) { |
11712
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
54 ValueNode javaClass = getJavaClass(); |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
55 if (javaClass.isConstant()) { |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
56 ValueNode object = getObject(); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14071
diff
changeset
|
57 Class c = (Class) HotSpotObjectConstant.asObject(javaClass.asConstant()); |
11712
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
58 if (c != null && !c.isPrimitive()) { |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
59 HotSpotResolvedObjectType type = (HotSpotResolvedObjectType) HotSpotResolvedObjectType.fromClass(c); |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
60 CheckCastNode checkcast = graph().add(new CheckCastNode(type, object, null, false)); |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
61 return checkcast; |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
62 } |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
63 } |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
64 return this; |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
65 } |
0d16339188ef
Improvements to the Truffle cache.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
66 } |