Mercurial > hg > truffle
annotate graal/com.oracle.graal.java/src/com/oracle/graal/java/StandardGraphBuilderPluginsProvider.java @ 19104:81be933b83eb
use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 03 Feb 2015 21:22:33 +0100 |
parents | graal/com.oracle.graal.java/src/com/oracle/graal/java/DefaultGraphBuilderPluginsProvider.java@69f2926cd2ab |
children | 04a07ceab00d |
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 |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
25 import com.oracle.graal.api.meta.*; |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
26 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:
19070
diff
changeset
|
27 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:
19070
diff
changeset
|
28 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:
19070
diff
changeset
|
29 import com.oracle.graal.java.GraphBuilderPlugins.Registration.Receiver; |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.graal.nodes.*; |
19070
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
31 import com.oracle.graal.nodes.extended.*; |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
32 import com.oracle.graal.nodes.java.*; |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
33 |
19067 | 34 /** |
35 * Provider of non-runtime specific {@link GraphBuilderPlugin}s. | |
36 */ | |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
37 @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:
19070
diff
changeset
|
38 public class StandardGraphBuilderPluginsProvider implements GraphBuilderPluginsProvider { |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
39 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:
19070
diff
changeset
|
40 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:
19070
diff
changeset
|
41 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:
19070
diff
changeset
|
42 public boolean apply(GraphBuilderContext builder, ValueNode object) { |
19069
0499dbe2da01
factored out common code
Doug Simon <doug.simon@oracle.com>
parents:
19067
diff
changeset
|
43 if (RegisterFinalizerNode.mayHaveFinalizer(object, builder.getAssumptions())) { |
0499dbe2da01
factored out common code
Doug Simon <doug.simon@oracle.com>
parents:
19067
diff
changeset
|
44 builder.append(new RegisterFinalizerNode(object)); |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
45 } |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
46 return true; |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 } |
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:
19070
diff
changeset
|
48 }); |
19050
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:
19070
diff
changeset
|
50 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:
19070
diff
changeset
|
51 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:
19070
diff
changeset
|
52 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:
19070
diff
changeset
|
53 new UnboxPlugin(kind).register(metaAccess, plugins); |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
54 } |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
55 } |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
56 } |
19070
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
57 |
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:
19070
diff
changeset
|
58 static class BoxPlugin implements InvocationPlugin { |
19070
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
59 |
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:
19070
diff
changeset
|
60 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:
19070
diff
changeset
|
61 |
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:
19070
diff
changeset
|
62 BoxPlugin(Kind kind) { |
19070
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
63 this.kind = kind; |
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
64 } |
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
65 |
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:
19070
diff
changeset
|
66 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:
19070
diff
changeset
|
67 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:
19070
diff
changeset
|
68 builder.push(Kind.Object, builder.append(new BoxNode(value, resultType, kind))); |
19070
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
69 return true; |
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
70 } |
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
71 |
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:
19070
diff
changeset
|
72 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:
19070
diff
changeset
|
73 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:
19070
diff
changeset
|
74 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:
19070
diff
changeset
|
75 } |
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:
19070
diff
changeset
|
76 } |
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:
19070
diff
changeset
|
77 |
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:
19070
diff
changeset
|
78 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:
19070
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:
19070
diff
changeset
|
80 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:
19070
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:
19070
diff
changeset
|
82 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:
19070
diff
changeset
|
83 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:
19070
diff
changeset
|
84 } |
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:
19070
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:
19070
diff
changeset
|
86 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:
19070
diff
changeset
|
87 builder.push(kind, builder.append(new UnboxNode(value, 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:
19070
diff
changeset
|
88 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:
19070
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:
19070
diff
changeset
|
90 |
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:
19070
diff
changeset
|
91 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:
19070
diff
changeset
|
92 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:
19070
diff
changeset
|
93 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:
19070
diff
changeset
|
94 plugins.register(method, this); |
19070
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
95 } |
69f2926cd2ab
added GraphBuilderPlugins for standard boxing/unboxing methods
Doug Simon <doug.simon@oracle.com>
parents:
19069
diff
changeset
|
96 } |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
97 } |