Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.java/src/com/oracle/graal/java/StandardGraphBuilderPluginsProvider.java @ 19241:30c8d110b281
More Truffle graph builder plugins and parse time canonicalizations.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Tue, 10 Feb 2015 20:43:48 +0100 |
parents | ce23018b970a |
children |
rev | line source |
---|---|
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.java; |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 |
19155
ac9ad302e12f
added utility to GraphBuilderContext for generating a receiver null check from within an InvocationPlugin for a non-static method
Doug Simon <doug.simon@oracle.com>
parents:
19138
diff
changeset
|
25 import static com.oracle.graal.java.GraphBuilderContext.*; |
19138
149427a9a397
Add null check in Unbox graph builder plugin.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19133
diff
changeset
|
26 |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
27 import com.oracle.graal.api.meta.*; |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
28 import com.oracle.graal.api.runtime.*; |
19104
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
29 import com.oracle.graal.java.GraphBuilderPlugins.InvocationPlugin; |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
30 import com.oracle.graal.java.GraphBuilderPlugins.Registration; |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
31 import com.oracle.graal.java.GraphBuilderPlugins.Registration.Receiver; |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
32 import com.oracle.graal.nodes.*; |
19069
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19068
diff
changeset
|
33 import com.oracle.graal.nodes.extended.*; |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
34 import com.oracle.graal.nodes.java.*; |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
35 |
19066 | 36 /** |
37 * Provider of non-runtime specific {@link GraphBuilderPlugin}s. | |
38 */ | |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
39 @ServiceProvider(GraphBuilderPluginsProvider.class) |
19104
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
40 public class StandardGraphBuilderPluginsProvider implements GraphBuilderPluginsProvider { |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
41 public void registerPlugins(MetaAccessProvider metaAccess, GraphBuilderPlugins plugins) { |
19104
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
42 Registration r = new Registration(plugins, metaAccess, Object.class); |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
43 r.register1("<init>", Receiver.class, new InvocationPlugin() { |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
44 public boolean apply(GraphBuilderContext builder, ValueNode object) { |
19068
0499dbe2da01
factored out common code
Doug Simon <doug.simon@oracle.com>
parents:
19066
diff
changeset
|
45 if (RegisterFinalizerNode.mayHaveFinalizer(object, builder.getAssumptions())) { |
0499dbe2da01
factored out common code
Doug Simon <doug.simon@oracle.com>
parents:
19066
diff
changeset
|
46 builder.append(new RegisterFinalizerNode(object)); |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 } |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
48 return true; |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
49 } |
19104
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
50 }); |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
51 |
19104
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
52 for (Kind kind : Kind.values()) { |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
53 if (kind.isPrimitive() && kind != Kind.Void) { |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
54 new BoxPlugin(kind).register(metaAccess, plugins); |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
55 new UnboxPlugin(kind).register(metaAccess, plugins); |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
56 } |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
57 } |
19128
04a07ceab00d
GraphBuilderPlugins for GraalDirectives.
Roland Schatz <roland.schatz@oracle.com>
parents:
19104
diff
changeset
|
58 |
04a07ceab00d
GraphBuilderPlugins for GraalDirectives.
Roland Schatz <roland.schatz@oracle.com>
parents:
19104
diff
changeset
|
59 GraalDirectivePlugins.registerPlugins(metaAccess, plugins); |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
60 } |
19069
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19068
diff
changeset
|
61 |
19104
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
62 static class BoxPlugin implements InvocationPlugin { |
19069
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19068
diff
changeset
|
63 |
19104
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
64 private final Kind kind; |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
65 |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
66 BoxPlugin(Kind kind) { |
19069
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19068
diff
changeset
|
67 this.kind = kind; |
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19068
diff
changeset
|
68 } |
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19068
diff
changeset
|
69 |
19104
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
70 public boolean apply(GraphBuilderContext builder, ValueNode value) { |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
71 ResolvedJavaType resultType = builder.getMetaAccess().lookupJavaType(kind.toBoxedJavaClass()); |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
72 builder.push(Kind.Object, builder.append(new BoxNode(value, resultType, kind))); |
19069
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19068
diff
changeset
|
73 return true; |
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19068
diff
changeset
|
74 } |
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19068
diff
changeset
|
75 |
19104
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
76 void register(MetaAccessProvider metaAccess, GraphBuilderPlugins plugins) { |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
77 ResolvedJavaMethod method = Registration.resolve(metaAccess, kind.toBoxedJavaClass(), "valueOf", kind.toJavaClass()); |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
78 plugins.register(method, this); |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
79 } |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
80 } |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
81 |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
82 static class UnboxPlugin implements InvocationPlugin { |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
83 |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
84 private final Kind kind; |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
85 |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
86 UnboxPlugin(Kind kind) { |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
87 this.kind = kind; |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
88 } |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
89 |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
90 public boolean apply(GraphBuilderContext builder, ValueNode value) { |
19241
30c8d110b281
More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19161
diff
changeset
|
91 ValueNode valueNode = UnboxNode.create(builder.getMetaAccess(), builder.getConstantReflection(), nullCheckedValue(builder, value), kind); |
30c8d110b281
More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19161
diff
changeset
|
92 builder.push(kind.getStackKind(), builder.append(valueNode)); |
19104
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
93 return true; |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
94 } |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
95 |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
96 void register(MetaAccessProvider metaAccess, GraphBuilderPlugins plugins) { |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
97 String name = kind.toJavaClass().getSimpleName() + "Value"; |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
98 ResolvedJavaMethod method = Registration.resolve(metaAccess, kind.toBoxedJavaClass(), name); |
81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
99 plugins.register(method, this); |
19069
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19068
diff
changeset
|
100 } |
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19068
diff
changeset
|
101 } |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
102 } |