annotate graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/BoxingSnippets.java @ 19290:bf166845c7d8

Truffle-DSL: new test examples package to show and explain Truffle-DSL features.
author Christian Humer <christian.humer@gmail.com>
date Wed, 11 Feb 2015 12:13:44 +0100
parents 07f2a49f0bfb
children 14e703edb2ab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
1 /*
18935
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18680
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
4 *
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
8 *
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
13 * accompanied this code).
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
14 *
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
18 *
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
21 * questions.
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
22 */
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.replacements;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
24
15259
d90e5c22ba55 Move GraalOptions to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents: 15018
diff changeset
25 import static com.oracle.graal.compiler.common.GraalOptions.*;
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
26 import static com.oracle.graal.replacements.SnippetTemplate.*;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
27
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
28 import java.util.*;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
29
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
30 import com.oracle.graal.api.code.*;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
31 import com.oracle.graal.api.meta.*;
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13505
diff changeset
32 import com.oracle.graal.api.replacements.*;
15261
882f4cb7cfcf Move Stamps to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents: 15259
diff changeset
33 import com.oracle.graal.compiler.common.type.*;
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
34 import com.oracle.graal.debug.*;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
35 import com.oracle.graal.graph.Node.NodeIntrinsic;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
36 import com.oracle.graal.nodes.*;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
37 import com.oracle.graal.nodes.calc.*;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
38 import com.oracle.graal.nodes.extended.*;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
39 import com.oracle.graal.nodes.spi.*;
10569
6b9ebfcf5fc5 make BoxNode and UnboxNode floating
Lukas Stadler <lukas.stadler@jku.at>
parents: 10074
diff changeset
40 import com.oracle.graal.nodes.util.*;
12054
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
41 import com.oracle.graal.phases.util.*;
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
42 import com.oracle.graal.replacements.Snippet.SnippetInliningPolicy;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
43 import com.oracle.graal.replacements.SnippetTemplate.AbstractTemplates;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
44 import com.oracle.graal.replacements.SnippetTemplate.Arguments;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
45 import com.oracle.graal.replacements.SnippetTemplate.SnippetInfo;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
46 import com.oracle.graal.word.*;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
47
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
48 public class BoxingSnippets implements Snippets {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
49
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
50 /**
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
51 * This snippet inlining policy differs from the default one in that it does normal inlining of
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
52 * boxing methods like {@link Integer#valueOf(int)} (as opposed to method substitution).
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
53 */
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
54 public static class BoxingSnippetInliningPolicy implements SnippetInliningPolicy {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
55
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
56 @Override
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
57 public boolean shouldInline(ResolvedJavaMethod method, ResolvedJavaMethod caller) {
15311
820c6d353358 added ModifiersProvider as superinterface for ResolvedJava[Method|Field|Type] and implemented all checks against modifiers as default methods
Doug Simon <doug.simon@oracle.com>
parents: 15261
diff changeset
58 if (method.isNative()) {
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
59 return false;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
60 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
61 if (method.getAnnotation(Fold.class) != null) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
62 return false;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
63 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
64 if (method.getAnnotation(NodeIntrinsic.class) != null) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
65 return false;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
66 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
67 if (method.getAnnotation(Word.Operation.class) != null) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
68 return false;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
69 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
70 return true;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
71 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
72
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
73 @Override
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
74 public boolean shouldUseReplacement(ResolvedJavaMethod callee, ResolvedJavaMethod methodToParse) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
75 return false;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
76 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
77 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
78
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
79 @Snippet(inlining = BoxingSnippetInliningPolicy.class)
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
80 public static Boolean booleanValueOf(boolean value) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
81 valueOfCounter.inc();
11752
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11732
diff changeset
82 return PiNode.piCast(Boolean.valueOf(value), StampFactory.forNodeIntrinsic());
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
83 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
84
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
85 @Snippet(inlining = BoxingSnippetInliningPolicy.class)
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
86 public static Byte byteValueOf(byte value) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
87 valueOfCounter.inc();
11752
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11732
diff changeset
88 return PiNode.piCast(Byte.valueOf(value), StampFactory.forNodeIntrinsic());
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
89 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
90
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
91 @Snippet(inlining = BoxingSnippetInliningPolicy.class)
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
92 public static Character charValueOf(char value) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
93 valueOfCounter.inc();
11752
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11732
diff changeset
94 return PiNode.piCast(Character.valueOf(value), StampFactory.forNodeIntrinsic());
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
95 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
96
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
97 @Snippet(inlining = BoxingSnippetInliningPolicy.class)
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
98 public static Double doubleValueOf(double value) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
99 valueOfCounter.inc();
11752
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11732
diff changeset
100 return PiNode.piCast(Double.valueOf(value), StampFactory.forNodeIntrinsic());
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
101 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
102
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
103 @Snippet(inlining = BoxingSnippetInliningPolicy.class)
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
104 public static Float floatValueOf(float value) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
105 valueOfCounter.inc();
11752
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11732
diff changeset
106 return PiNode.piCast(Float.valueOf(value), StampFactory.forNodeIntrinsic());
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
107 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
108
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
109 @Snippet(inlining = BoxingSnippetInliningPolicy.class)
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
110 public static Integer intValueOf(int value) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
111 valueOfCounter.inc();
11752
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11732
diff changeset
112 return PiNode.piCast(Integer.valueOf(value), StampFactory.forNodeIntrinsic());
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
113 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
114
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
115 @Snippet(inlining = BoxingSnippetInliningPolicy.class)
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
116 public static Long longValueOf(long value) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
117 valueOfCounter.inc();
11752
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11732
diff changeset
118 return PiNode.piCast(Long.valueOf(value), StampFactory.forNodeIntrinsic());
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
119 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
120
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
121 @Snippet(inlining = BoxingSnippetInliningPolicy.class)
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
122 public static Short shortValueOf(short value) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
123 valueOfCounter.inc();
11752
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11732
diff changeset
124 return PiNode.piCast(Short.valueOf(value), StampFactory.forNodeIntrinsic());
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
125 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
126
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
127 @Snippet(inlining = BoxingSnippetInliningPolicy.class)
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
128 public static boolean booleanValue(Boolean value) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
129 valueOfCounter.inc();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
130 return value.booleanValue();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
131 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
132
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
133 @Snippet(inlining = BoxingSnippetInliningPolicy.class)
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
134 public static byte byteValue(Byte value) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
135 valueOfCounter.inc();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
136 return value.byteValue();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
137 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
138
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
139 @Snippet(inlining = BoxingSnippetInliningPolicy.class)
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
140 public static char charValue(Character value) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
141 valueOfCounter.inc();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
142 return value.charValue();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
143 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
144
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
145 @Snippet(inlining = BoxingSnippetInliningPolicy.class)
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
146 public static double doubleValue(Double value) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
147 valueOfCounter.inc();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
148 return value.doubleValue();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
149 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
150
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
151 @Snippet(inlining = BoxingSnippetInliningPolicy.class)
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
152 public static float floatValue(Float value) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
153 valueOfCounter.inc();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
154 return value.floatValue();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
155 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
156
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
157 @Snippet(inlining = BoxingSnippetInliningPolicy.class)
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
158 public static int intValue(Integer value) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
159 valueOfCounter.inc();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
160 return value.intValue();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
161 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
162
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
163 @Snippet(inlining = BoxingSnippetInliningPolicy.class)
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
164 public static long longValue(Long value) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
165 valueOfCounter.inc();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
166 return value.longValue();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
167 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
168
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
169 @Snippet(inlining = BoxingSnippetInliningPolicy.class)
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
170 public static short shortValue(Short value) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
171 valueOfCounter.inc();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
172 return value.shortValue();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
173 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
174
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13505
diff changeset
175 public static FloatingNode canonicalizeBoxing(BoxNode box, MetaAccessProvider metaAccess, ConstantReflectionProvider constantReflection) {
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
176 ValueNode value = box.getValue();
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
177 if (value.isConstant()) {
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
178 JavaConstant sourceConstant = value.asJavaConstant();
18935
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18680
diff changeset
179 if (sourceConstant.getKind() != box.getBoxingKind() && sourceConstant.getKind().isNumericInteger()) {
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18680
diff changeset
180 switch (box.getBoxingKind()) {
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18680
diff changeset
181 case Boolean:
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18680
diff changeset
182 sourceConstant = JavaConstant.forBoolean(sourceConstant.asLong() != 0L);
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18680
diff changeset
183 break;
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18680
diff changeset
184 case Byte:
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18680
diff changeset
185 sourceConstant = JavaConstant.forByte((byte) sourceConstant.asLong());
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18680
diff changeset
186 break;
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18680
diff changeset
187 case Char:
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18680
diff changeset
188 sourceConstant = JavaConstant.forChar((char) sourceConstant.asLong());
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18680
diff changeset
189 break;
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18680
diff changeset
190 case Short:
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18680
diff changeset
191 sourceConstant = JavaConstant.forShort((short) sourceConstant.asLong());
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18680
diff changeset
192 break;
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18680
diff changeset
193 }
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 18680
diff changeset
194 }
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 15311
diff changeset
195 JavaConstant boxedConstant = constantReflection.boxPrimitive(sourceConstant);
18680
6707a08faa9b fix bug that prevented constants from being boxed
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18370
diff changeset
196 if (boxedConstant != null && sourceConstant.getKind() == box.getBoxingKind()) {
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13505
diff changeset
197 return ConstantNode.forConstant(boxedConstant, metaAccess, box.graph());
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
198 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
199 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
200 return null;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
201 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
202
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
203 public static class Templates extends AbstractTemplates {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
204
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
205 private final EnumMap<Kind, SnippetInfo> boxSnippets = new EnumMap<>(Kind.class);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
206 private final EnumMap<Kind, SnippetInfo> unboxSnippets = new EnumMap<>(Kind.class);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
207
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13505
diff changeset
208 public Templates(Providers providers, SnippetReflectionProvider snippetReflection, TargetDescription target) {
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13505
diff changeset
209 super(providers, snippetReflection, target);
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
210 for (Kind kind : new Kind[]{Kind.Boolean, Kind.Byte, Kind.Char, Kind.Double, Kind.Float, Kind.Int, Kind.Long, Kind.Short}) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
211 boxSnippets.put(kind, snippet(BoxingSnippets.class, kind.getJavaName() + "ValueOf"));
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
212 unboxSnippets.put(kind, snippet(BoxingSnippets.class, kind.getJavaName() + "Value"));
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
213 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
214 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
215
10569
6b9ebfcf5fc5 make BoxNode and UnboxNode floating
Lukas Stadler <lukas.stadler@jku.at>
parents: 10074
diff changeset
216 public void lower(BoxNode box, LoweringTool tool) {
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13505
diff changeset
217 FloatingNode canonical = canonicalizeBoxing(box, providers.getMetaAccess(), providers.getConstantReflection());
10074
e8fbc5fd3440 aot: add/fix some javadoc
Bernhard Urban <bernhard.urban@jku.at>
parents: 10064
diff changeset
218 // if in AOT mode, we don't want to embed boxed constants.
13378
16d99e9d77ad Options: rename flag (AOTCompilation -> ImmutableCode)
Bernhard Urban <bernhard.urban@jku.at>
parents: 12054
diff changeset
219 if (canonical != null && !ImmutableCode.getValue()) {
10569
6b9ebfcf5fc5 make BoxNode and UnboxNode floating
Lukas Stadler <lukas.stadler@jku.at>
parents: 10074
diff changeset
220 box.graph().replaceFloating(box, canonical);
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
221 } else {
13505
75a67ebd50e8 Introduce a LoweringStage so that lowerings can be conditional on one of the three times that lowering is performed by default
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13378
diff changeset
222 Arguments args = new Arguments(boxSnippets.get(box.getBoxingKind()), box.graph().getGuardsStage(), tool.getLoweringStage());
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
223 args.add("value", box.getValue());
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
224
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
225 SnippetTemplate template = template(args);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
226 Debug.log("Lowering integerValueOf in %s: node=%s, template=%s, arguments=%s", box.graph(), box, template, args);
12054
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
227 template.instantiate(providers.getMetaAccess(), box, DEFAULT_REPLACER, tool, args);
10569
6b9ebfcf5fc5 make BoxNode and UnboxNode floating
Lukas Stadler <lukas.stadler@jku.at>
parents: 10074
diff changeset
228 GraphUtil.killWithUnusedFloatingInputs(box);
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
229 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
230 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
231
10569
6b9ebfcf5fc5 make BoxNode and UnboxNode floating
Lukas Stadler <lukas.stadler@jku.at>
parents: 10074
diff changeset
232 public void lower(UnboxNode unbox, LoweringTool tool) {
13505
75a67ebd50e8 Introduce a LoweringStage so that lowerings can be conditional on one of the three times that lowering is performed by default
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13378
diff changeset
233 Arguments args = new Arguments(unboxSnippets.get(unbox.getBoxingKind()), unbox.graph().getGuardsStage(), tool.getLoweringStage());
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
234 args.add("value", unbox.getValue());
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
235
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
236 SnippetTemplate template = template(args);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
237 Debug.log("Lowering integerValueOf in %s: node=%s, template=%s, arguments=%s", unbox.graph(), unbox, template, args);
12054
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
238 template.instantiate(providers.getMetaAccess(), unbox, DEFAULT_REPLACER, tool, args);
10569
6b9ebfcf5fc5 make BoxNode and UnboxNode floating
Lukas Stadler <lukas.stadler@jku.at>
parents: 10074
diff changeset
239 GraphUtil.killWithUnusedFloatingInputs(unbox);
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
240 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
241 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
242
9864
063a712fe8d8 converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 9602
diff changeset
243 private static final SnippetCounter.Group integerCounters = SnippetCounters.getValue() ? new SnippetCounter.Group("Integer intrinsifications") : null;
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
244 private static final SnippetCounter valueOfCounter = new SnippetCounter(integerCounters, "valueOf", "valueOf intrinsification");
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
245
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
246 }