Mercurial > hg > truffle
annotate graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPlugins.java @ 19147:609480dfa0d8
Create ExplodeLoop plugin prototype. Special sort for blocks from bci block map builder for explode loop methods. Graph builder plugin for customizing static field accesses. New Truffle option TruffleExcludeAssertions default true that excludes assertion code from being partial evaluated in the new partial evaluator.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Thu, 05 Feb 2015 03:25:21 +0100 |
parents | 18caaceabfdb |
children | ac9ad302e12f |
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 |
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:
19067
diff
changeset
|
25 import static java.lang.String.*; |
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:
19067
diff
changeset
|
26 |
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:
19067
diff
changeset
|
27 import java.lang.reflect.*; |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
28 import java.util.*; |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
29 |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.graal.api.meta.*; |
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:
19067
diff
changeset
|
31 import com.oracle.graal.compiler.common.*; |
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:
19067
diff
changeset
|
32 import com.oracle.graal.nodes.*; |
19112
c2019f6e821b
Draft for ParameterPlugin.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19111
diff
changeset
|
33 import com.oracle.graal.nodes.calc.*; |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
34 |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
35 /** |
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:
19067
diff
changeset
|
36 * Interface for managing a set of graph builder {@link GraphBuilderPlugin}s. |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
37 */ |
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:
19067
diff
changeset
|
38 public interface GraphBuilderPlugins { |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
39 |
19111
0b15114268c8
Draft for LoadFieldPlugin.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19104
diff
changeset
|
40 public interface LoadFieldPlugin extends GraphBuilderPlugin { |
19147
609480dfa0d8
Create ExplodeLoop plugin prototype. Special sort for blocks from bci block map builder for explode loop methods. Graph builder plugin for customizing static field accesses. New Truffle option TruffleExcludeAssertions default true that excludes assertion code from being partial evaluated in the new partial evaluator.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19145
diff
changeset
|
41 @SuppressWarnings("unused") |
609480dfa0d8
Create ExplodeLoop plugin prototype. Special sort for blocks from bci block map builder for explode loop methods. Graph builder plugin for customizing static field accesses. New Truffle option TruffleExcludeAssertions default true that excludes assertion code from being partial evaluated in the new partial evaluator.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19145
diff
changeset
|
42 default boolean apply(GraphBuilderContext builder, ValueNode receiver, ResolvedJavaField field) { |
609480dfa0d8
Create ExplodeLoop plugin prototype. Special sort for blocks from bci block map builder for explode loop methods. Graph builder plugin for customizing static field accesses. New Truffle option TruffleExcludeAssertions default true that excludes assertion code from being partial evaluated in the new partial evaluator.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19145
diff
changeset
|
43 return false; |
609480dfa0d8
Create ExplodeLoop plugin prototype. Special sort for blocks from bci block map builder for explode loop methods. Graph builder plugin for customizing static field accesses. New Truffle option TruffleExcludeAssertions default true that excludes assertion code from being partial evaluated in the new partial evaluator.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19145
diff
changeset
|
44 } |
609480dfa0d8
Create ExplodeLoop plugin prototype. Special sort for blocks from bci block map builder for explode loop methods. Graph builder plugin for customizing static field accesses. New Truffle option TruffleExcludeAssertions default true that excludes assertion code from being partial evaluated in the new partial evaluator.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19145
diff
changeset
|
45 |
609480dfa0d8
Create ExplodeLoop plugin prototype. Special sort for blocks from bci block map builder for explode loop methods. Graph builder plugin for customizing static field accesses. New Truffle option TruffleExcludeAssertions default true that excludes assertion code from being partial evaluated in the new partial evaluator.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19145
diff
changeset
|
46 @SuppressWarnings("unused") |
609480dfa0d8
Create ExplodeLoop plugin prototype. Special sort for blocks from bci block map builder for explode loop methods. Graph builder plugin for customizing static field accesses. New Truffle option TruffleExcludeAssertions default true that excludes assertion code from being partial evaluated in the new partial evaluator.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19145
diff
changeset
|
47 default boolean apply(GraphBuilderContext graphBuilderContext, ResolvedJavaField staticField) { |
609480dfa0d8
Create ExplodeLoop plugin prototype. Special sort for blocks from bci block map builder for explode loop methods. Graph builder plugin for customizing static field accesses. New Truffle option TruffleExcludeAssertions default true that excludes assertion code from being partial evaluated in the new partial evaluator.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19145
diff
changeset
|
48 return false; |
609480dfa0d8
Create ExplodeLoop plugin prototype. Special sort for blocks from bci block map builder for explode loop methods. Graph builder plugin for customizing static field accesses. New Truffle option TruffleExcludeAssertions default true that excludes assertion code from being partial evaluated in the new partial evaluator.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19145
diff
changeset
|
49 } |
19111
0b15114268c8
Draft for LoadFieldPlugin.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19104
diff
changeset
|
50 } |
0b15114268c8
Draft for LoadFieldPlugin.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19104
diff
changeset
|
51 |
19112
c2019f6e821b
Draft for ParameterPlugin.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19111
diff
changeset
|
52 public interface ParameterPlugin extends GraphBuilderPlugin { |
c2019f6e821b
Draft for ParameterPlugin.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19111
diff
changeset
|
53 FloatingNode interceptParameter(int index); |
c2019f6e821b
Draft for ParameterPlugin.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19111
diff
changeset
|
54 } |
c2019f6e821b
Draft for ParameterPlugin.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19111
diff
changeset
|
55 |
19132
8fe322db4b6d
Prototype for configuring inlining during parsing via a closure in the GraphBuilderConfiguration object.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19118
diff
changeset
|
56 public interface InlineInvokePlugin extends GraphBuilderPlugin { |
8fe322db4b6d
Prototype for configuring inlining during parsing via a closure in the GraphBuilderConfiguration object.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19118
diff
changeset
|
57 boolean shouldInlineInvoke(ResolvedJavaMethod method, int depth); |
8fe322db4b6d
Prototype for configuring inlining during parsing via a closure in the GraphBuilderConfiguration object.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19118
diff
changeset
|
58 } |
8fe322db4b6d
Prototype for configuring inlining during parsing via a closure in the GraphBuilderConfiguration object.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19118
diff
changeset
|
59 |
19145
18caaceabfdb
Create prototype for new graph builder plugin for loop explosion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19132
diff
changeset
|
60 public interface LoopExplosionPlugin extends GraphBuilderPlugin { |
18caaceabfdb
Create prototype for new graph builder plugin for loop explosion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19132
diff
changeset
|
61 boolean shouldExplodeLoops(ResolvedJavaMethod method); |
18caaceabfdb
Create prototype for new graph builder plugin for loop explosion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19132
diff
changeset
|
62 } |
18caaceabfdb
Create prototype for new graph builder plugin for loop explosion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19132
diff
changeset
|
63 |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
64 /** |
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:
19067
diff
changeset
|
65 * Plugin for handling a method invocation. |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
66 */ |
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:
19067
diff
changeset
|
67 public interface InvocationPlugin extends GraphBuilderPlugin { |
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:
19067
diff
changeset
|
68 /** |
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:
19067
diff
changeset
|
69 * Tries to handle an invocation to a method with no arguments. |
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:
19067
diff
changeset
|
70 * |
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:
19067
diff
changeset
|
71 * @return {@code true} this plugin handled the invocation |
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:
19067
diff
changeset
|
72 */ |
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:
19067
diff
changeset
|
73 default boolean apply(GraphBuilderContext builder) { |
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:
19067
diff
changeset
|
74 throw invalidHandler(builder); |
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:
19067
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:
19067
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:
19067
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:
19067
diff
changeset
|
78 * Tries to handle an invocation to a method with one argument. |
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:
19067
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:
19067
diff
changeset
|
80 * @return {@code true} this plugin handled the invocation |
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:
19067
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:
19067
diff
changeset
|
82 default boolean apply(GraphBuilderContext builder, ValueNode arg) { |
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:
19067
diff
changeset
|
83 throw invalidHandler(builder, arg); |
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:
19067
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:
19067
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:
19067
diff
changeset
|
86 /** |
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:
19067
diff
changeset
|
87 * Tries to handle an invocation to a method with two arguments. |
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:
19067
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:
19067
diff
changeset
|
89 * @return {@code true} this plugin handled the invocation |
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:
19067
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:
19067
diff
changeset
|
91 default boolean apply(GraphBuilderContext builder, ValueNode arg1, ValueNode arg2) { |
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:
19067
diff
changeset
|
92 throw invalidHandler(builder, arg1, arg2); |
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:
19067
diff
changeset
|
93 } |
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:
19067
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:
19067
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:
19067
diff
changeset
|
96 * Tries to handle an invocation to a method with three arguments. |
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:
19067
diff
changeset
|
97 * |
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:
19067
diff
changeset
|
98 * @return {@code true} this plugin handled the invocation |
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:
19067
diff
changeset
|
99 */ |
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:
19067
diff
changeset
|
100 default boolean apply(GraphBuilderContext builder, ValueNode arg1, ValueNode arg2, ValueNode arg3) { |
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:
19067
diff
changeset
|
101 throw invalidHandler(builder, arg1, arg2, arg3); |
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:
19067
diff
changeset
|
102 } |
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:
19067
diff
changeset
|
103 |
19106
02bfa2747729
moved dispatch for plugin to be within InvocationPlugin
Doug Simon <doug.simon@oracle.com>
parents:
19104
diff
changeset
|
104 default boolean apply(GraphBuilderContext builder, ValueNode[] args) { |
02bfa2747729
moved dispatch for plugin to be within InvocationPlugin
Doug Simon <doug.simon@oracle.com>
parents:
19104
diff
changeset
|
105 if (args.length == 0) { |
02bfa2747729
moved dispatch for plugin to be within InvocationPlugin
Doug Simon <doug.simon@oracle.com>
parents:
19104
diff
changeset
|
106 return apply(builder); |
02bfa2747729
moved dispatch for plugin to be within InvocationPlugin
Doug Simon <doug.simon@oracle.com>
parents:
19104
diff
changeset
|
107 } else if (args.length == 1) { |
02bfa2747729
moved dispatch for plugin to be within InvocationPlugin
Doug Simon <doug.simon@oracle.com>
parents:
19104
diff
changeset
|
108 return apply(builder, args[0]); |
02bfa2747729
moved dispatch for plugin to be within InvocationPlugin
Doug Simon <doug.simon@oracle.com>
parents:
19104
diff
changeset
|
109 } else if (args.length == 2) { |
02bfa2747729
moved dispatch for plugin to be within InvocationPlugin
Doug Simon <doug.simon@oracle.com>
parents:
19104
diff
changeset
|
110 return apply(builder, args[0], args[1]); |
02bfa2747729
moved dispatch for plugin to be within InvocationPlugin
Doug Simon <doug.simon@oracle.com>
parents:
19104
diff
changeset
|
111 } else if (args.length == 3) { |
02bfa2747729
moved dispatch for plugin to be within InvocationPlugin
Doug Simon <doug.simon@oracle.com>
parents:
19104
diff
changeset
|
112 return apply(builder, args[0], args[1], args[2]); |
02bfa2747729
moved dispatch for plugin to be within InvocationPlugin
Doug Simon <doug.simon@oracle.com>
parents:
19104
diff
changeset
|
113 } else { |
02bfa2747729
moved dispatch for plugin to be within InvocationPlugin
Doug Simon <doug.simon@oracle.com>
parents:
19104
diff
changeset
|
114 throw invalidHandler(builder, args); |
02bfa2747729
moved dispatch for plugin to be within InvocationPlugin
Doug Simon <doug.simon@oracle.com>
parents:
19104
diff
changeset
|
115 } |
02bfa2747729
moved dispatch for plugin to be within InvocationPlugin
Doug Simon <doug.simon@oracle.com>
parents:
19104
diff
changeset
|
116 } |
02bfa2747729
moved dispatch for plugin to be within InvocationPlugin
Doug Simon <doug.simon@oracle.com>
parents:
19104
diff
changeset
|
117 |
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:
19067
diff
changeset
|
118 default Error invalidHandler(@SuppressWarnings("unused") GraphBuilderContext builder, ValueNode... args) { |
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:
19067
diff
changeset
|
119 return new GraalInternalError("Invocation plugin %s does not handle invocations with %d arguments", getClass().getSimpleName(), args.length); |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
120 } |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
121 } |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
122 |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
123 /** |
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:
19067
diff
changeset
|
124 * Utility for {@linkplain GraphBuilderPlugins#register(ResolvedJavaMethod, 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:
19067
diff
changeset
|
125 * registration} of 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:
19067
diff
changeset
|
126 */ |
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:
19067
diff
changeset
|
127 public static class 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:
19067
diff
changeset
|
128 |
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:
19067
diff
changeset
|
129 /** |
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:
19067
diff
changeset
|
130 * Sentinel class for use with {@link Registration#register1}, |
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:
19067
diff
changeset
|
131 * {@link Registration#register2} or {@link Registration#register3} to denote the receiver |
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:
19067
diff
changeset
|
132 * argument for a non-static method. |
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:
19067
diff
changeset
|
133 */ |
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:
19067
diff
changeset
|
134 public static final class Receiver { |
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:
19067
diff
changeset
|
135 private Receiver() { |
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:
19067
diff
changeset
|
136 throw GraalInternalError.shouldNotReachHere(); |
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:
19067
diff
changeset
|
137 } |
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:
19067
diff
changeset
|
138 } |
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:
19067
diff
changeset
|
139 |
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:
19067
diff
changeset
|
140 private final 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:
19067
diff
changeset
|
141 private final MetaAccessProvider metaAccess; |
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:
19067
diff
changeset
|
142 private final Class<?> declaringClass; |
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:
19067
diff
changeset
|
143 |
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:
19067
diff
changeset
|
144 /** |
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:
19067
diff
changeset
|
145 * Creates an object for registering plugins for methods declared by a given 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:
19067
diff
changeset
|
146 * |
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:
19067
diff
changeset
|
147 * @param plugins where to register the 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:
19067
diff
changeset
|
148 * @param metaAccess used to resolve classes and methods |
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:
19067
diff
changeset
|
149 * @param declaringClass the class declaring the methods for which plugins will be |
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:
19067
diff
changeset
|
150 * registered via this object |
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:
19067
diff
changeset
|
151 */ |
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:
19067
diff
changeset
|
152 public Registration(GraphBuilderPlugins plugins, MetaAccessProvider metaAccess, Class<?> declaringClass) { |
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:
19067
diff
changeset
|
153 this.plugins = 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:
19067
diff
changeset
|
154 this.metaAccess = metaAccess; |
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:
19067
diff
changeset
|
155 this.declaringClass = declaringClass; |
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:
19067
diff
changeset
|
156 } |
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:
19067
diff
changeset
|
157 |
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:
19067
diff
changeset
|
158 /** |
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:
19067
diff
changeset
|
159 * Registers a plugin for a method with no arguments. |
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:
19067
diff
changeset
|
160 * |
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:
19067
diff
changeset
|
161 * @param name the name of the method |
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:
19067
diff
changeset
|
162 * @param plugin the plugin to be registered |
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:
19067
diff
changeset
|
163 */ |
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:
19067
diff
changeset
|
164 public void register0(String name, InvocationPlugin plugin) { |
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:
19067
diff
changeset
|
165 plugins.register(resolve(metaAccess, declaringClass, name), plugin); |
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:
19067
diff
changeset
|
166 } |
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:
19067
diff
changeset
|
167 |
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:
19067
diff
changeset
|
168 /** |
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:
19067
diff
changeset
|
169 * Registers a plugin for a method with 1 argument. |
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:
19067
diff
changeset
|
170 * |
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:
19067
diff
changeset
|
171 * @param name the name of the method |
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:
19067
diff
changeset
|
172 * @param plugin the plugin to be registered |
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:
19067
diff
changeset
|
173 */ |
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:
19067
diff
changeset
|
174 public void register1(String name, Class<?> arg, InvocationPlugin plugin) { |
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:
19067
diff
changeset
|
175 ResolvedJavaMethod method = arg == Receiver.class ? resolve(metaAccess, declaringClass, name) : resolve(metaAccess, declaringClass, name, arg); |
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:
19067
diff
changeset
|
176 plugins.register(method, plugin); |
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:
19067
diff
changeset
|
177 } |
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:
19067
diff
changeset
|
178 |
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:
19067
diff
changeset
|
179 /** |
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:
19067
diff
changeset
|
180 * Registers a plugin for a method with 2 arguments. |
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:
19067
diff
changeset
|
181 * |
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:
19067
diff
changeset
|
182 * @param name the name of the method |
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:
19067
diff
changeset
|
183 * @param plugin the plugin to be registered |
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:
19067
diff
changeset
|
184 */ |
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:
19067
diff
changeset
|
185 public void register2(String name, Class<?> arg1, Class<?> arg2, InvocationPlugin plugin) { |
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:
19067
diff
changeset
|
186 ResolvedJavaMethod method = arg1 == Receiver.class ? resolve(metaAccess, declaringClass, name, arg2) : resolve(metaAccess, declaringClass, name, arg1, arg2); |
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:
19067
diff
changeset
|
187 plugins.register(method, plugin); |
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:
19067
diff
changeset
|
188 } |
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:
19067
diff
changeset
|
189 |
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:
19067
diff
changeset
|
190 /** |
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:
19067
diff
changeset
|
191 * Registers a plugin for a method with 3 arguments. |
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:
19067
diff
changeset
|
192 * |
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:
19067
diff
changeset
|
193 * @param name the name of the method |
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:
19067
diff
changeset
|
194 * @param plugin the plugin to be registered |
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:
19067
diff
changeset
|
195 */ |
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:
19067
diff
changeset
|
196 public void register3(String name, Class<?> arg1, Class<?> arg2, Class<?> arg3, InvocationPlugin plugin) { |
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:
19067
diff
changeset
|
197 ResolvedJavaMethod method = arg1 == Receiver.class ? resolve(metaAccess, declaringClass, name, arg2, arg3) : resolve(metaAccess, declaringClass, name, arg1, arg2, arg3); |
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:
19067
diff
changeset
|
198 plugins.register(method, plugin); |
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:
19067
diff
changeset
|
199 } |
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:
19067
diff
changeset
|
200 |
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:
19067
diff
changeset
|
201 /** |
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:
19067
diff
changeset
|
202 * Resolves a method given a declaring class, name and parameter types. |
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:
19067
diff
changeset
|
203 */ |
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:
19067
diff
changeset
|
204 public static ResolvedJavaMethod resolve(MetaAccessProvider metaAccess, Class<?> declaringClass, String name, Class<?>... parameterTypes) { |
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:
19067
diff
changeset
|
205 try { |
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:
19067
diff
changeset
|
206 return metaAccess.lookupJavaMethod(name.equals("<init>") ? declaringClass.getDeclaredConstructor(parameterTypes) : declaringClass.getDeclaredMethod(name, parameterTypes)); |
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:
19067
diff
changeset
|
207 } catch (NoSuchMethodException | SecurityException e) { |
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:
19067
diff
changeset
|
208 throw new GraalInternalError(e); |
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:
19067
diff
changeset
|
209 } |
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:
19067
diff
changeset
|
210 } |
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:
19067
diff
changeset
|
211 } |
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:
19067
diff
changeset
|
212 |
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:
19067
diff
changeset
|
213 public static class InvocationPluginChecker { |
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:
19067
diff
changeset
|
214 static final Class<?>[] APPLY0 = {GraphBuilderContext.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:
19067
diff
changeset
|
215 static final Class<?>[] APPLY1 = {GraphBuilderContext.class, ValueNode.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:
19067
diff
changeset
|
216 static final Class<?>[] APPLY2 = {GraphBuilderContext.class, ValueNode.class, ValueNode.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:
19067
diff
changeset
|
217 static final Class<?>[] APPLY3 = {GraphBuilderContext.class, ValueNode.class, ValueNode.class, ValueNode.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:
19067
diff
changeset
|
218 static final Class<?>[][] SIGS = {APPLY0, APPLY1, APPLY2, APPLY3}; |
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:
19067
diff
changeset
|
219 |
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:
19067
diff
changeset
|
220 public static boolean check(ResolvedJavaMethod method, InvocationPlugin plugin) { |
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:
19067
diff
changeset
|
221 int arguments = method.getSignature().getParameterCount(!method.isStatic()); |
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:
19067
diff
changeset
|
222 assert arguments < SIGS.length : format("need to extend %s to support method with %d arguments: %s", InvocationPlugin.class.getSimpleName(), arguments, method.format("%H.%n(%p)")); |
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:
19067
diff
changeset
|
223 Method expected = null; |
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:
19067
diff
changeset
|
224 for (Method m : plugin.getClass().getDeclaredMethods()) { |
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:
19067
diff
changeset
|
225 if (m.getName().equals("apply")) { |
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:
19067
diff
changeset
|
226 Class<?>[] parameterTypes = m.getParameterTypes(); |
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:
19067
diff
changeset
|
227 assert Arrays.equals(SIGS[arguments], parameterTypes) : format("graph builder plugin for %s has wrong signature%nexpected: (%s)%n actual: (%s)", method.format("%H.%n(%p)"), |
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:
19067
diff
changeset
|
228 sigString(SIGS[arguments]), sigString(m.getParameterTypes())); |
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:
19067
diff
changeset
|
229 expected = m; |
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:
19067
diff
changeset
|
230 } |
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:
19067
diff
changeset
|
231 } |
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:
19067
diff
changeset
|
232 assert expected != null : format("graph builder plugin %s must define exactly one \"apply\" method, none found", plugin); |
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:
19067
diff
changeset
|
233 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:
19067
diff
changeset
|
234 } |
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:
19067
diff
changeset
|
235 |
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:
19067
diff
changeset
|
236 protected static String sigString(Class<?>... sig) { |
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:
19067
diff
changeset
|
237 StringBuilder sb = new StringBuilder(); |
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:
19067
diff
changeset
|
238 for (Class<?> t : sig) { |
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:
19067
diff
changeset
|
239 if (sb.length() != 0) { |
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:
19067
diff
changeset
|
240 sb.append(", "); |
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:
19067
diff
changeset
|
241 } |
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:
19067
diff
changeset
|
242 sb.append(t.getSimpleName()); |
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:
19067
diff
changeset
|
243 } |
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:
19067
diff
changeset
|
244 return sb.toString(); |
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:
19067
diff
changeset
|
245 } |
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:
19067
diff
changeset
|
246 |
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:
19067
diff
changeset
|
247 } |
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:
19067
diff
changeset
|
248 |
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:
19067
diff
changeset
|
249 /** |
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:
19067
diff
changeset
|
250 * Registers an {@link InvocationPlugin} for a given method. There must be no plugin currently |
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:
19067
diff
changeset
|
251 * registered for {@code method}. |
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:
19067
diff
changeset
|
252 */ |
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:
19067
diff
changeset
|
253 void register(ResolvedJavaMethod method, InvocationPlugin plugin); |
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:
19067
diff
changeset
|
254 |
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:
19067
diff
changeset
|
255 /** |
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:
19067
diff
changeset
|
256 * Gets the {@link InvocationPlugin} for a given method. |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
257 * |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
258 * @param method the method to lookup |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
259 * @return the plugin associated with {@code method} or {@code null} if none exists |
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
260 */ |
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:
19067
diff
changeset
|
261 InvocationPlugin lookupInvocation(ResolvedJavaMethod method); |
19050
75da87c96605
initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
262 } |