annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/graphbuilderconf/InvocationPlugins.java @ 23389:69a9c45e2143

Add constructor to create InvocationPlugins from map of already resolved methods
author Christian Wimmer <christian.wimmer@oracle.com>
date Thu, 04 Feb 2016 17:18:03 -0800
parents 2160e7da7fb0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 */
23076
fb4379f87d4d Merge com.oracle.graal.graphbuilderconf into com.oracle.graal.nodes project.
Roland Schatz <roland.schatz@oracle.com>
parents: 22994
diff changeset
23 package com.oracle.graal.nodes.graphbuilderconf;
19050
75da87c96605 initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
22646
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22457
diff changeset
25 import static java.lang.String.format;
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: 19066
diff changeset
26
22646
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22457
diff changeset
27 import java.lang.reflect.Executable;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22457
diff changeset
28 import java.lang.reflect.Method;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22457
diff changeset
29 import java.lang.reflect.Modifier;
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
30 import java.lang.reflect.Type;
22646
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22457
diff changeset
31 import java.util.ArrayList;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22457
diff changeset
32 import java.util.Arrays;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22457
diff changeset
33 import java.util.Collections;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22457
diff changeset
34 import java.util.HashMap;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22457
diff changeset
35 import java.util.List;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22457
diff changeset
36 import java.util.Map;
19050
75da87c96605 initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
37
22790
615f3bbbb174 Update jvmci and truffle import: Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22685
diff changeset
38 import jdk.vm.ci.common.JVMCIError;
615f3bbbb174 Update jvmci and truffle import: Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22685
diff changeset
39 import jdk.vm.ci.meta.MetaAccessProvider;
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
40 import jdk.vm.ci.meta.MetaUtil;
22790
615f3bbbb174 Update jvmci and truffle import: Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22685
diff changeset
41 import jdk.vm.ci.meta.ResolvedJavaMethod;
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
42 import sun.misc.Launcher;
22054
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents: 22010
diff changeset
43
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
44 import com.oracle.graal.graph.Node;
22646
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22457
diff changeset
45 import com.oracle.graal.graph.iterators.NodeIterable;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22457
diff changeset
46 import com.oracle.graal.nodes.ValueNode;
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 /**
19390
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
49 * Manages a set of {@link InvocationPlugin}s.
19050
75da87c96605 initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
50 */
19390
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
51 public class InvocationPlugins {
19817
3cc8aa066ed3 made resolution of method with InvocationPlugins lazy
Doug Simon <doug.simon@oracle.com>
parents: 19775
diff changeset
52
21548
f4b3a6dadb44 moved Receiver inner class from MethodIdMap to InvocationPlugin (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21376
diff changeset
53 public static class InvocationPluginReceiver implements InvocationPlugin.Receiver {
20827
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
54 private final GraphBuilderContext parser;
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
55 private ValueNode[] args;
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
56 private ValueNode value;
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
57
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
58 public InvocationPluginReceiver(GraphBuilderContext parser) {
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
59 this.parser = parser;
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
60 }
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
61
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
62 @Override
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
63 public ValueNode get() {
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
64 assert args != null : "Cannot get the receiver of a static method";
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
65 if (value == null) {
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
66 value = parser.nullCheckedValue(args[0]);
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
67 if (value != args[0]) {
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
68 args[0] = value;
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
69 }
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
70 }
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
71 return value;
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
72 }
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
73
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
74 @Override
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
75 public boolean isConstant() {
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
76 return args[0].isConstant();
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
77 }
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
78
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
79 public InvocationPluginReceiver init(ResolvedJavaMethod targetMethod, ValueNode[] newArgs) {
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
80 if (!targetMethod.isStatic()) {
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
81 this.args = newArgs;
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
82 this.value = null;
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
83 return this;
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
84 }
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
85 return null;
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
86 }
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
87 }
5bf195ce816a New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20162
diff changeset
88
19817
3cc8aa066ed3 made resolution of method with InvocationPlugins lazy
Doug Simon <doug.simon@oracle.com>
parents: 19775
diff changeset
89 /**
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
90 * A symbol that is lazily {@linkplain OptionalLazySymbol#resolve() resolved} to a {@link Type}.
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
91 */
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
92 static class OptionalLazySymbol implements Type {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
93 private static final Class<?> MASK_NULL = OptionalLazySymbol.class;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
94 private final String name;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
95 private Class<?> resolved;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
96
23323
2160e7da7fb0 remove redundant modifiers.
Manuel Rigger <rigger.manuel@gmail.com>
parents: 23160
diff changeset
97 OptionalLazySymbol(String name) {
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
98 this.name = name;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
99 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
100
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
101 public String getTypeName() {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
102 return name;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
103 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
104
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
105 /**
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
106 * Gets the resolved {@link Class} corresponding to this symbol or {@code null} if
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
107 * resolution fails.
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
108 */
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
109 public Class<?> resolve() {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
110 if (resolved == null) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
111 Class<?> resolvedOrNull = resolveClass(name, true);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
112 resolved = resolvedOrNull == null ? MASK_NULL : resolvedOrNull;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
113 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
114 return resolved == MASK_NULL ? null : resolved;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
115 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
116
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
117 @Override
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
118 public String toString() {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
119 return name;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
120 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
121 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
122
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
123 /**
19817
3cc8aa066ed3 made resolution of method with InvocationPlugins lazy
Doug Simon <doug.simon@oracle.com>
parents: 19775
diff changeset
124 * Utility for
3cc8aa066ed3 made resolution of method with InvocationPlugins lazy
Doug Simon <doug.simon@oracle.com>
parents: 19775
diff changeset
125 * {@linkplain InvocationPlugins#register(InvocationPlugin, Class, String, Class...)
19390
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
126 * registration} of invocation 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: 19066
diff changeset
127 */
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19066
diff changeset
128 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: 19066
diff changeset
129
19390
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
130 private final InvocationPlugins plugins;
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
131 private final Type declaringType;
22678
f3ebbebef617 Allow overwriting of invocation plugins
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22457
diff changeset
132 private boolean allowOverwrite;
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: 19066
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: 19066
diff changeset
134 /**
19390
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
135 * Creates an object for registering {@link InvocationPlugin}s for methods declared by a
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
136 * given 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: 19066
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: 19066
diff changeset
138 * @param plugins where to register the plugins
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
139 * @param declaringType the class declaring the methods for which plugins will be registered
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
140 * via this object
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: 19066
diff changeset
141 */
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
142 public Registration(InvocationPlugins plugins, Type declaringType) {
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: 19066
diff changeset
143 this.plugins = plugins;
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
144 this.declaringType = declaringType;
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: 19066
diff changeset
145 }
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19066
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: 19066
diff changeset
147 /**
22680
d79fcf097df7 Allow invocation plugin registry to be created with class name instead of java.lang.Class
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22679
diff changeset
148 * Creates an object for registering {@link InvocationPlugin}s for methods declared by a
d79fcf097df7 Allow invocation plugin registry to be created with class name instead of java.lang.Class
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22679
diff changeset
149 * given class.
d79fcf097df7 Allow invocation plugin registry to be created with class name instead of java.lang.Class
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22679
diff changeset
150 *
d79fcf097df7 Allow invocation plugin registry to be created with class name instead of java.lang.Class
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22679
diff changeset
151 * @param plugins where to register the plugins
d79fcf097df7 Allow invocation plugin registry to be created with class name instead of java.lang.Class
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22679
diff changeset
152 * @param declaringClassName the name of the class class declaring the methods for which
d79fcf097df7 Allow invocation plugin registry to be created with class name instead of java.lang.Class
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22679
diff changeset
153 * plugins will be registered via this object
d79fcf097df7 Allow invocation plugin registry to be created with class name instead of java.lang.Class
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22679
diff changeset
154 */
d79fcf097df7 Allow invocation plugin registry to be created with class name instead of java.lang.Class
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22679
diff changeset
155 public Registration(InvocationPlugins plugins, String declaringClassName) {
d79fcf097df7 Allow invocation plugin registry to be created with class name instead of java.lang.Class
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22679
diff changeset
156 this.plugins = plugins;
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
157 this.declaringType = new OptionalLazySymbol(declaringClassName);
22680
d79fcf097df7 Allow invocation plugin registry to be created with class name instead of java.lang.Class
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22679
diff changeset
158 }
d79fcf097df7 Allow invocation plugin registry to be created with class name instead of java.lang.Class
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22679
diff changeset
159
d79fcf097df7 Allow invocation plugin registry to be created with class name instead of java.lang.Class
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22679
diff changeset
160 /**
22678
f3ebbebef617 Allow overwriting of invocation plugins
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22457
diff changeset
161 * Configures this registration to allow or disallow overwriting of invocation plugins.
f3ebbebef617 Allow overwriting of invocation plugins
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22457
diff changeset
162 */
f3ebbebef617 Allow overwriting of invocation plugins
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22457
diff changeset
163 public Registration setAllowOverwrite(boolean allowOverwrite) {
f3ebbebef617 Allow overwriting of invocation plugins
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22457
diff changeset
164 this.allowOverwrite = allowOverwrite;
f3ebbebef617 Allow overwriting of invocation plugins
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22457
diff changeset
165 return this;
f3ebbebef617 Allow overwriting of invocation plugins
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22457
diff changeset
166 }
f3ebbebef617 Allow overwriting of invocation plugins
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22457
diff changeset
167
f3ebbebef617 Allow overwriting of invocation plugins
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22457
diff changeset
168 /**
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: 19066
diff changeset
169 * 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: 19066
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: 19066
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: 19066
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: 19066
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: 19066
diff changeset
174 public void register0(String name, InvocationPlugin plugin) {
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
175 plugins.register(plugin, false, allowOverwrite, declaringType, name);
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: 19066
diff changeset
176 }
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19066
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: 19066
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: 19066
diff changeset
179 * 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: 19066
diff changeset
180 *
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19066
diff changeset
181 * @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: 19066
diff changeset
182 * @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: 19066
diff changeset
183 */
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
184 public void register1(String name, Type arg, InvocationPlugin plugin) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
185 plugins.register(plugin, false, allowOverwrite, declaringType, name, arg);
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: 19066
diff changeset
186 }
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19066
diff changeset
187
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19066
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: 19066
diff changeset
189 * 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: 19066
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: 19066
diff changeset
191 * @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: 19066
diff changeset
192 * @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: 19066
diff changeset
193 */
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
194 public void register2(String name, Type arg1, Type arg2, InvocationPlugin plugin) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
195 plugins.register(plugin, false, allowOverwrite, declaringType, name, arg1, arg2);
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: 19066
diff changeset
196 }
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19066
diff changeset
197
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19066
diff changeset
198 /**
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19066
diff changeset
199 * 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: 19066
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: 19066
diff changeset
201 * @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: 19066
diff changeset
202 * @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: 19066
diff changeset
203 */
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
204 public void register3(String name, Type arg1, Type arg2, Type arg3, InvocationPlugin plugin) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
205 plugins.register(plugin, false, allowOverwrite, declaringType, name, arg1, arg2, arg3);
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: 19066
diff changeset
206 }
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19066
diff changeset
207
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19066
diff changeset
208 /**
19178
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
209 * Registers a plugin for a method with 4 arguments.
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
210 *
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
211 * @param name the name of the method
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
212 * @param plugin the plugin to be registered
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
213 */
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
214 public void register4(String name, Type arg1, Type arg2, Type arg3, Type arg4, InvocationPlugin plugin) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
215 plugins.register(plugin, false, allowOverwrite, declaringType, name, arg1, arg2, arg3, arg4);
19775
14e703edb2ab use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents: 19493
diff changeset
216 }
14e703edb2ab use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents: 19493
diff changeset
217
14e703edb2ab use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents: 19493
diff changeset
218 /**
14e703edb2ab use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents: 19493
diff changeset
219 * Registers a plugin for a method with 5 arguments.
14e703edb2ab use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents: 19493
diff changeset
220 *
14e703edb2ab use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents: 19493
diff changeset
221 * @param name the name of the method
14e703edb2ab use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents: 19493
diff changeset
222 * @param plugin the plugin to be registered
14e703edb2ab use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents: 19493
diff changeset
223 */
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
224 public void register5(String name, Type arg1, Type arg2, Type arg3, Type arg4, Type arg5, InvocationPlugin plugin) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
225 plugins.register(plugin, false, allowOverwrite, declaringType, name, arg1, arg2, arg3, arg4, arg5);
19817
3cc8aa066ed3 made resolution of method with InvocationPlugins lazy
Doug Simon <doug.simon@oracle.com>
parents: 19775
diff changeset
226 }
20835
a2cd0e7072e2 added MethodSubstitutionPlugin as (eventual) replacement for @MethodSubstitution mechanism
Doug Simon <doug.simon@oracle.com>
parents: 20827
diff changeset
227
a2cd0e7072e2 added MethodSubstitutionPlugin as (eventual) replacement for @MethodSubstitution mechanism
Doug Simon <doug.simon@oracle.com>
parents: 20827
diff changeset
228 /**
22679
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
229 * Registers a plugin for an optional method with no arguments.
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
230 *
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
231 * @param name the name of the method
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
232 * @param plugin the plugin to be registered
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
233 */
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
234 public void registerOptional0(String name, InvocationPlugin plugin) {
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
235 plugins.register(plugin, true, allowOverwrite, declaringType, name);
22679
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
236 }
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
237
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
238 /**
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
239 * Registers a plugin for an optional method with 1 argument.
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
240 *
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
241 * @param name the name of the method
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
242 * @param plugin the plugin to be registered
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
243 */
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
244 public void registerOptional1(String name, Type arg, InvocationPlugin plugin) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
245 plugins.register(plugin, true, allowOverwrite, declaringType, name, arg);
22679
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
246 }
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
247
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
248 /**
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
249 * Registers a plugin for an optional method with 2 arguments.
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
250 *
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
251 * @param name the name of the method
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
252 * @param plugin the plugin to be registered
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
253 */
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
254 public void registerOptional2(String name, Type arg1, Type arg2, InvocationPlugin plugin) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
255 plugins.register(plugin, true, allowOverwrite, declaringType, name, arg1, arg2);
22679
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
256 }
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
257
152f2a7c46d8 Add missing registerOptional* methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22678
diff changeset
258 /**
22111
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
259 * Registers a plugin for an optional method with 3 arguments.
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
260 *
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
261 * @param name the name of the method
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
262 * @param plugin the plugin to be registered
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
263 */
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
264 public void registerOptional3(String name, Type arg1, Type arg2, Type arg3, InvocationPlugin plugin) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
265 plugins.register(plugin, true, allowOverwrite, declaringType, name, arg1, arg2, arg3);
22111
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
266 }
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
267
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
268 /**
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
269 * Registers a plugin for an optional method with 4 arguments.
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
270 *
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
271 * @param name the name of the method
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
272 * @param plugin the plugin to be registered
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
273 */
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
274 public void registerOptional4(String name, Type arg1, Type arg2, Type arg3, Type arg4, InvocationPlugin plugin) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
275 plugins.register(plugin, true, allowOverwrite, declaringType, name, arg1, arg2, arg3, arg4);
22111
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
276 }
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
277
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
278 /**
20835
a2cd0e7072e2 added MethodSubstitutionPlugin as (eventual) replacement for @MethodSubstitution mechanism
Doug Simon <doug.simon@oracle.com>
parents: 20827
diff changeset
279 * Registers a plugin that implements a method based on the bytecode of a substitute method.
a2cd0e7072e2 added MethodSubstitutionPlugin as (eventual) replacement for @MethodSubstitution mechanism
Doug Simon <doug.simon@oracle.com>
parents: 20827
diff changeset
280 *
a2cd0e7072e2 added MethodSubstitutionPlugin as (eventual) replacement for @MethodSubstitution mechanism
Doug Simon <doug.simon@oracle.com>
parents: 20827
diff changeset
281 * @param substituteDeclaringClass the class declaring the substitute method
a2cd0e7072e2 added MethodSubstitutionPlugin as (eventual) replacement for @MethodSubstitution mechanism
Doug Simon <doug.simon@oracle.com>
parents: 20827
diff changeset
282 * @param name the name of both the original and substitute method
21548
f4b3a6dadb44 moved Receiver inner class from MethodIdMap to InvocationPlugin (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21376
diff changeset
283 * @param argumentTypes the argument types of the method. Element 0 of this array must be
21549
0627ebc2a3ea moved MethodId* classes from c.o.g.graphbuilderconf to c.o.g.api.meta (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21548
diff changeset
284 * the {@link Class} value for {@link InvocationPlugin.Receiver} iff the method
0627ebc2a3ea moved MethodId* classes from c.o.g.graphbuilderconf to c.o.g.api.meta (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21548
diff changeset
285 * is non-static. Upon returning, element 0 will have been rewritten to
0627ebc2a3ea moved MethodId* classes from c.o.g.graphbuilderconf to c.o.g.api.meta (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21548
diff changeset
286 * {@code declaringClass}
20835
a2cd0e7072e2 added MethodSubstitutionPlugin as (eventual) replacement for @MethodSubstitution mechanism
Doug Simon <doug.simon@oracle.com>
parents: 20827
diff changeset
287 */
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
288 public void registerMethodSubstitution(Class<?> substituteDeclaringClass, String name, Type... argumentTypes) {
22994
7a9ffb0f17d9 AES decrypt stubs require an extra argument on SPARC
Doug Simon <doug.simon@oracle.com>
parents: 22790
diff changeset
289 registerMethodSubstitution(substituteDeclaringClass, name, name, argumentTypes);
7a9ffb0f17d9 AES decrypt stubs require an extra argument on SPARC
Doug Simon <doug.simon@oracle.com>
parents: 22790
diff changeset
290 }
7a9ffb0f17d9 AES decrypt stubs require an extra argument on SPARC
Doug Simon <doug.simon@oracle.com>
parents: 22790
diff changeset
291
7a9ffb0f17d9 AES decrypt stubs require an extra argument on SPARC
Doug Simon <doug.simon@oracle.com>
parents: 22790
diff changeset
292 /**
7a9ffb0f17d9 AES decrypt stubs require an extra argument on SPARC
Doug Simon <doug.simon@oracle.com>
parents: 22790
diff changeset
293 * Registers a plugin that implements a method based on the bytecode of a substitute method.
7a9ffb0f17d9 AES decrypt stubs require an extra argument on SPARC
Doug Simon <doug.simon@oracle.com>
parents: 22790
diff changeset
294 *
7a9ffb0f17d9 AES decrypt stubs require an extra argument on SPARC
Doug Simon <doug.simon@oracle.com>
parents: 22790
diff changeset
295 * @param substituteDeclaringClass the class declaring the substitute method
7a9ffb0f17d9 AES decrypt stubs require an extra argument on SPARC
Doug Simon <doug.simon@oracle.com>
parents: 22790
diff changeset
296 * @param name the name of both the original method
7a9ffb0f17d9 AES decrypt stubs require an extra argument on SPARC
Doug Simon <doug.simon@oracle.com>
parents: 22790
diff changeset
297 * @param substituteName the name of the substitute method
7a9ffb0f17d9 AES decrypt stubs require an extra argument on SPARC
Doug Simon <doug.simon@oracle.com>
parents: 22790
diff changeset
298 * @param argumentTypes the argument types of the method. Element 0 of this array must be
7a9ffb0f17d9 AES decrypt stubs require an extra argument on SPARC
Doug Simon <doug.simon@oracle.com>
parents: 22790
diff changeset
299 * the {@link Class} value for {@link InvocationPlugin.Receiver} iff the method
7a9ffb0f17d9 AES decrypt stubs require an extra argument on SPARC
Doug Simon <doug.simon@oracle.com>
parents: 22790
diff changeset
300 * is non-static. Upon returning, element 0 will have been rewritten to
7a9ffb0f17d9 AES decrypt stubs require an extra argument on SPARC
Doug Simon <doug.simon@oracle.com>
parents: 22790
diff changeset
301 * {@code declaringClass}
7a9ffb0f17d9 AES decrypt stubs require an extra argument on SPARC
Doug Simon <doug.simon@oracle.com>
parents: 22790
diff changeset
302 */
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
303 public void registerMethodSubstitution(Class<?> substituteDeclaringClass, String name, String substituteName, Type... argumentTypes) {
22994
7a9ffb0f17d9 AES decrypt stubs require an extra argument on SPARC
Doug Simon <doug.simon@oracle.com>
parents: 22790
diff changeset
304 MethodSubstitutionPlugin plugin = new MethodSubstitutionPlugin(substituteDeclaringClass, substituteName, argumentTypes);
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
305 plugins.register(plugin, false, allowOverwrite, declaringType, name, argumentTypes);
20835
a2cd0e7072e2 added MethodSubstitutionPlugin as (eventual) replacement for @MethodSubstitution mechanism
Doug Simon <doug.simon@oracle.com>
parents: 20827
diff changeset
306 }
19817
3cc8aa066ed3 made resolution of method with InvocationPlugins lazy
Doug Simon <doug.simon@oracle.com>
parents: 19775
diff changeset
307 }
3cc8aa066ed3 made resolution of method with InvocationPlugins lazy
Doug Simon <doug.simon@oracle.com>
parents: 19775
diff changeset
308
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
309 /**
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
310 * Key for a method.
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
311 */
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
312 static class MethodKey {
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
313 final boolean isStatic;
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
314
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
315 /**
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
316 * This method is optional. This is used for new API methods not present in previous JDK
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
317 * versions.
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
318 */
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
319 final boolean isOptional;
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
320
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
321 final String name;
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
322 final Type[] argumentTypes;
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
323 final InvocationPlugin value;
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
324
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
325 /**
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
326 * Used to lazily initialize {@link #resolved}.
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
327 */
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
328 private final MetaAccessProvider metaAccess;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
329
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
330 private volatile ResolvedJavaMethod resolved;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
331
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
332 MethodKey(MetaAccessProvider metaAccess, InvocationPlugin data, boolean isStatic, boolean isOptional, String name, Type... argumentTypes) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
333 this.metaAccess = metaAccess;
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
334 this.value = data;
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
335 this.isStatic = isStatic;
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
336 this.isOptional = isOptional;
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
337 this.name = name;
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
338 this.argumentTypes = argumentTypes;
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
339 }
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
340
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
341 @Override
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
342 public boolean equals(Object obj) {
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
343 if (obj instanceof MethodKey) {
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
344 MethodKey that = (MethodKey) obj;
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
345 boolean res = this.name.equals(that.name) && areEqual(this.argumentTypes, that.argumentTypes);
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
346 assert !res || this.isStatic == that.isStatic;
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
347 return res;
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
348 }
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
349 return false;
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
350 }
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
351
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
352 private static boolean areEqual(Type[] args1, Type[] args2) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
353 if (args1.length == args2.length) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
354 for (int i = 0; i < args1.length; i++) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
355 if (!args1[i].getTypeName().equals(args2[i].getTypeName())) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
356 return false;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
357 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
358 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
359 return true;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
360 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
361 return false;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
362 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
363
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
364 public int getDeclaredParameterCount() {
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
365 return isStatic ? argumentTypes.length : argumentTypes.length - 1;
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
366 }
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
367
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
368 @Override
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
369 public int hashCode() {
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
370 return name.hashCode();
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
371 }
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
372
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
373 private ResolvedJavaMethod resolve(Class<?> declaringClass) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
374 if (resolved == null) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
375 Executable method = resolveJava(declaringClass);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
376 if (method == null) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
377 return null;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
378 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
379 resolved = metaAccess.lookupJavaMethod(method);
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
380 }
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
381 return resolved;
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
382 }
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
383
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
384 private Executable resolveJava(Class<?> declaringClass) {
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
385 try {
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
386 Executable res;
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
387 Class<?>[] parameterTypes = resolveTypes(argumentTypes, isStatic ? 0 : 1, argumentTypes.length);
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
388 if (name.equals("<init>")) {
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
389 res = declaringClass.getDeclaredConstructor(parameterTypes);
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
390 } else {
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
391 res = declaringClass.getDeclaredMethod(name, parameterTypes);
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
392 }
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
393 assert Modifier.isStatic(res.getModifiers()) == isStatic;
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
394 return res;
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
395 } catch (NoSuchMethodException | SecurityException e) {
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
396 if (isOptional) {
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
397 return null;
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
398 }
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
399 throw new InternalError(e);
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
400 }
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
401 }
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
402
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
403 @Override
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
404 public String toString() {
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
405 StringBuilder sb = new StringBuilder(name).append('(');
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
406 for (Type p : argumentTypes) {
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
407 if (sb.charAt(sb.length() - 1) != '(') {
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
408 sb.append(", ");
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
409 }
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
410 sb.append(p.getTypeName());
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
411 }
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
412 return sb.append(')').toString();
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
413 }
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
414 }
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
415
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
416 private final MetaAccessProvider metaAccess;
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
417
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
418 private final Map<String, ClassPlugins> registrations = new HashMap<>();
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
419
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
420 /**
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
421 * Deferred registrations as well as guard for initialization. The guard uses double-checked
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
422 * locking which is why this field is {@code volatile}.
23144
043cb31c85cd defer InvocationPlugin registration until first plugin lookup or plugins are closed
Doug Simon <doug.simon@oracle.com>
parents: 23078
diff changeset
423 */
043cb31c85cd defer InvocationPlugin registration until first plugin lookup or plugins are closed
Doug Simon <doug.simon@oracle.com>
parents: 23078
diff changeset
424 private volatile List<Runnable> deferredRegistrations = new ArrayList<>();
043cb31c85cd defer InvocationPlugin registration until first plugin lookup or plugins are closed
Doug Simon <doug.simon@oracle.com>
parents: 23078
diff changeset
425
043cb31c85cd defer InvocationPlugin registration until first plugin lookup or plugins are closed
Doug Simon <doug.simon@oracle.com>
parents: 23078
diff changeset
426 /**
043cb31c85cd defer InvocationPlugin registration until first plugin lookup or plugins are closed
Doug Simon <doug.simon@oracle.com>
parents: 23078
diff changeset
427 * Adds a {@link Runnable} for doing registration deferred until the first time
043cb31c85cd defer InvocationPlugin registration until first plugin lookup or plugins are closed
Doug Simon <doug.simon@oracle.com>
parents: 23078
diff changeset
428 * {@link #get(ResolvedJavaMethod)} or {@link #closeRegistration()} is called on this object.
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
429 */
23144
043cb31c85cd defer InvocationPlugin registration until first plugin lookup or plugins are closed
Doug Simon <doug.simon@oracle.com>
parents: 23078
diff changeset
430 public void defer(Runnable deferrable) {
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
431 assert deferredRegistrations != null : "registration is closed";
23144
043cb31c85cd defer InvocationPlugin registration until first plugin lookup or plugins are closed
Doug Simon <doug.simon@oracle.com>
parents: 23078
diff changeset
432 deferredRegistrations.add(deferrable);
043cb31c85cd defer InvocationPlugin registration until first plugin lookup or plugins are closed
Doug Simon <doug.simon@oracle.com>
parents: 23078
diff changeset
433 }
043cb31c85cd defer InvocationPlugin registration until first plugin lookup or plugins are closed
Doug Simon <doug.simon@oracle.com>
parents: 23078
diff changeset
434
043cb31c85cd defer InvocationPlugin registration until first plugin lookup or plugins are closed
Doug Simon <doug.simon@oracle.com>
parents: 23078
diff changeset
435 /**
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
436 * Per-class invocation plugins.
23144
043cb31c85cd defer InvocationPlugin registration until first plugin lookup or plugins are closed
Doug Simon <doug.simon@oracle.com>
parents: 23078
diff changeset
437 */
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
438 protected static class ClassPlugins {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
439 private final Type declaringType;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
440
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
441 private final List<MethodKey> registrations = new ArrayList<>();
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
442
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
443 public ClassPlugins(Type declaringClass) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
444 this.declaringType = declaringClass;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
445 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
446
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
447 /**
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
448 * Entry map that is initialized upon first call to {@link #get(ResolvedJavaMethod)}.
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
449 *
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
450 * Note: this must be volatile as threads may race to initialize it.
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
451 */
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
452 private volatile Map<ResolvedJavaMethod, InvocationPlugin> entries;
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
453
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
454 void initializeMap() {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
455 if (entries == null) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
456 if (registrations.isEmpty()) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
457 entries = Collections.emptyMap();
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
458 } else {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
459 Class<?> declaringClass = resolveType(declaringType, true);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
460 if (declaringClass == null) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
461 // An optional type that could not be resolved
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
462 entries = Collections.emptyMap();
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
463 } else {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
464 Map<ResolvedJavaMethod, InvocationPlugin> newEntries = new HashMap<>();
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
465 for (MethodKey methodKey : registrations) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
466 ResolvedJavaMethod m = methodKey.resolve(declaringClass);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
467 newEntries.put(m, methodKey.value);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
468 if (entries != null) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
469 // Another thread finished initializing entries first
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
470 return;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
471 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
472 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
473 entries = newEntries;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
474 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
475 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
476 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
477 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
478
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
479 public InvocationPlugin get(ResolvedJavaMethod method) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
480 if (entries == null) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
481 initializeMap();
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
482 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
483 return entries.get(method);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
484 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
485
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
486 public void register(MethodKey methodKey, boolean allowOverwrite) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
487 assert entries == null : "registration is closed";
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
488 if (allowOverwrite) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
489 int index = registrations.indexOf(methodKey);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
490 if (index >= 0) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
491 registrations.set(index, methodKey);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
492 return;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
493 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
494 } else {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
495 assert !registrations.contains(methodKey) : "a value is already registered for " + declaringType + "." + methodKey;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
496 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
497 registrations.add(methodKey);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
498 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
499 }
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
500
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
501 /**
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
502 * Adds an entry to this map for a specified method.
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
503 *
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
504 * @param value value to be associated with the specified method
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
505 * @param isStatic specifies if the method is static
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
506 * @param isOptional specifies if the method is optional
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
507 * @param declaringClass the class declaring the method
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
508 * @param name the name of the method
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
509 * @param argumentTypes the argument types of the method. Element 0 of this array must be
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
510 * {@code declaringClass} iff the method is non-static.
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
511 * @return an object representing the method
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
512 */
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
513 MethodKey put(InvocationPlugin value, boolean isStatic, boolean isOptional, boolean allowOverwrite, Type declaringClass, String name, Type... argumentTypes) {
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
514 assert isStatic || argumentTypes[0] == declaringClass;
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
515
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
516 String internalName = MetaUtil.toInternalName(declaringClass.getTypeName());
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
517 ClassPlugins classPlugins = registrations.get(internalName);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
518 if (classPlugins == null) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
519 classPlugins = new ClassPlugins(declaringClass);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
520 registrations.put(internalName, classPlugins);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
521 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
522 assert isStatic || argumentTypes[0] == declaringClass;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
523 MethodKey methodKey = new MethodKey(metaAccess, value, isStatic, isOptional, name, argumentTypes);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
524 classPlugins.register(methodKey, allowOverwrite);
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
525 return methodKey;
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
526 }
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
527
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
528 /**
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
529 * Determines if a method denoted by a given {@link MethodKey} is in this map.
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
530 */
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
531 boolean containsKey(Type declaringType, MethodKey key) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
532 String internalName = MetaUtil.toInternalName(declaringType.getTypeName());
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
533 ClassPlugins classPlugins = registrations.get(internalName);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
534 return classPlugins != null && classPlugins.registrations.contains(key);
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
535 }
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
536
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
537 InvocationPlugin get(ResolvedJavaMethod method) {
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
538 flushDeferrables();
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
539 String internalName = method.getDeclaringClass().getName();
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
540 ClassPlugins classPlugins = registrations.get(internalName);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
541 if (classPlugins != null) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
542 return classPlugins.get(method);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
543 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
544 return null;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
545 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
546
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
547 private void flushDeferrables() {
23144
043cb31c85cd defer InvocationPlugin registration until first plugin lookup or plugins are closed
Doug Simon <doug.simon@oracle.com>
parents: 23078
diff changeset
548 if (deferredRegistrations != null) {
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
549 synchronized (this) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
550 if (deferredRegistrations != null) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
551 for (Runnable deferrable : deferredRegistrations) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
552 deferrable.run();
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
553 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
554 deferredRegistrations = null;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
555 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
556 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
557 for (Map.Entry<String, ClassPlugins> e : registrations.entrySet()) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
558 e.getValue().initializeMap();
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
559 }
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
560 }
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
561 }
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
562
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
563 /**
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
564 * Disallows new registrations of new plugins, and creates the internal tables for method
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
565 * lookup.
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
566 */
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
567 public void closeRegistration() {
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
568 flushDeferrables();
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
569 for (Map.Entry<String, ClassPlugins> e : registrations.entrySet()) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
570 e.getValue().initializeMap();
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
571 }
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
572 }
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
573
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
574 public int size() {
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
575 return registrations.size();
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
576 }
19390
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
577
19819
0c29075aeafe graph builder plugins are created before GraphBuilderConfigurations and the process for deriving plugins from an existing configuration is simplified
Doug Simon <doug.simon@oracle.com>
parents: 19817
diff changeset
578 /**
19822
b950967f74c7 replaced HashMap with a side-table (i.e., an array) for looking up InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19821
diff changeset
579 * The plugins {@linkplain #lookupInvocation(ResolvedJavaMethod) searched} before searching in
b950967f74c7 replaced HashMap with a side-table (i.e., an array) for looking up InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19821
diff changeset
580 * this object.
19819
0c29075aeafe graph builder plugins are created before GraphBuilderConfigurations and the process for deriving plugins from an existing configuration is simplified
Doug Simon <doug.simon@oracle.com>
parents: 19817
diff changeset
581 */
20887
dc58f4ca21c9 generalized map in InvocationPlugins to MethodIdMap
Doug Simon <doug.simon@oracle.com>
parents: 20886
diff changeset
582 protected final InvocationPlugins parent;
19822
b950967f74c7 replaced HashMap with a side-table (i.e., an array) for looking up InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19821
diff changeset
583
19951
b94503d3840c removed logic for estimating invocation plugin count
Doug Simon <doug.simon@oracle.com>
parents: 19822
diff changeset
584 private InvocationPlugins(InvocationPlugins parent, MetaAccessProvider metaAccess) {
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
585 this.metaAccess = metaAccess;
19822
b950967f74c7 replaced HashMap with a side-table (i.e., an array) for looking up InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19821
diff changeset
586 InvocationPlugins p = parent;
b950967f74c7 replaced HashMap with a side-table (i.e., an array) for looking up InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19821
diff changeset
587 this.parent = p;
b950967f74c7 replaced HashMap with a side-table (i.e., an array) for looking up InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19821
diff changeset
588 }
b950967f74c7 replaced HashMap with a side-table (i.e., an array) for looking up InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19821
diff changeset
589
b950967f74c7 replaced HashMap with a side-table (i.e., an array) for looking up InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19821
diff changeset
590 /**
b950967f74c7 replaced HashMap with a side-table (i.e., an array) for looking up InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19821
diff changeset
591 * Creates a set of invocation plugins with a non-null {@linkplain #getParent() parent}.
b950967f74c7 replaced HashMap with a side-table (i.e., an array) for looking up InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19821
diff changeset
592 */
b950967f74c7 replaced HashMap with a side-table (i.e., an array) for looking up InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19821
diff changeset
593 public InvocationPlugins(InvocationPlugins parent) {
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
594 this(parent, parent.getMetaAccess());
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
595 }
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
596
23389
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
597 public InvocationPlugins(Map<ResolvedJavaMethod, InvocationPlugin> plugins, InvocationPlugins parent, MetaAccessProvider metaAccess) {
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
598 this.metaAccess = metaAccess;
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
599 this.parent = parent;
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
600
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
601 this.deferredRegistrations = null;
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
602
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
603 for (Map.Entry<ResolvedJavaMethod, InvocationPlugin> entry : plugins.entrySet()) {
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
604 ResolvedJavaMethod method = entry.getKey();
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
605 InvocationPlugin plugin = entry.getValue();
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
606
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
607 String internalName = method.getDeclaringClass().getName();
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
608 ClassPlugins classPlugins = registrations.get(internalName);
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
609 if (classPlugins == null) {
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
610 classPlugins = new ClassPlugins(null);
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
611 registrations.put(internalName, classPlugins);
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
612 classPlugins.entries = new HashMap<>();
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
613 }
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
614
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
615 classPlugins.entries.put(method, plugin);
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
616 }
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
617 }
69a9c45e2143 Add constructor to create InvocationPlugins from map of already resolved methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 23323
diff changeset
618
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
619 public MetaAccessProvider getMetaAccess() {
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
620 return metaAccess;
19819
0c29075aeafe graph builder plugins are created before GraphBuilderConfigurations and the process for deriving plugins from an existing configuration is simplified
Doug Simon <doug.simon@oracle.com>
parents: 19817
diff changeset
621 }
0c29075aeafe graph builder plugins are created before GraphBuilderConfigurations and the process for deriving plugins from an existing configuration is simplified
Doug Simon <doug.simon@oracle.com>
parents: 19817
diff changeset
622
19817
3cc8aa066ed3 made resolution of method with InvocationPlugins lazy
Doug Simon <doug.simon@oracle.com>
parents: 19775
diff changeset
623 public InvocationPlugins(MetaAccessProvider metaAccess) {
19951
b94503d3840c removed logic for estimating invocation plugin count
Doug Simon <doug.simon@oracle.com>
parents: 19822
diff changeset
624 this(null, metaAccess);
19817
3cc8aa066ed3 made resolution of method with InvocationPlugins lazy
Doug Simon <doug.simon@oracle.com>
parents: 19775
diff changeset
625 }
3cc8aa066ed3 made resolution of method with InvocationPlugins lazy
Doug Simon <doug.simon@oracle.com>
parents: 19775
diff changeset
626
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
627 private void register(InvocationPlugin plugin, boolean isOptional, boolean allowOverwrite, Type declaringClass, String name, Type... argumentTypes) {
22111
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
628 boolean isStatic = argumentTypes.length == 0 || argumentTypes[0] != InvocationPlugin.Receiver.class;
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
629 if (!isStatic) {
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
630 argumentTypes[0] = declaringClass;
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
631 }
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
632 MethodKey methodKey = put(plugin, isStatic, isOptional, allowOverwrite, declaringClass, name, argumentTypes);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
633 assert Checker.check(this, declaringClass, methodKey, plugin);
22111
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
634 }
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
635
19390
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
636 /**
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
637 * Registers an invocation plugin for a given method. There must be no plugin currently
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
638 * registered for {@code method}.
21548
f4b3a6dadb44 moved Receiver inner class from MethodIdMap to InvocationPlugin (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21376
diff changeset
639 *
f4b3a6dadb44 moved Receiver inner class from MethodIdMap to InvocationPlugin (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21376
diff changeset
640 * @param argumentTypes the argument types of the method. Element 0 of this array must be the
21549
0627ebc2a3ea moved MethodId* classes from c.o.g.graphbuilderconf to c.o.g.api.meta (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21548
diff changeset
641 * {@link Class} value for {@link InvocationPlugin.Receiver} iff the method is
0627ebc2a3ea moved MethodId* classes from c.o.g.graphbuilderconf to c.o.g.api.meta (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21548
diff changeset
642 * non-static. Upon returning, element 0 will have been rewritten to
0627ebc2a3ea moved MethodId* classes from c.o.g.graphbuilderconf to c.o.g.api.meta (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21548
diff changeset
643 * {@code declaringClass}
19390
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
644 */
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
645 public void register(InvocationPlugin plugin, Type declaringClass, String name, Type... argumentTypes) {
22678
f3ebbebef617 Allow overwriting of invocation plugins
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22457
diff changeset
646 register(plugin, false, false, declaringClass, name, argumentTypes);
22111
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
647 }
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
648
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
649 public void register(InvocationPlugin plugin, String declaringClass, String name, Type... argumentTypes) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
650 register(plugin, false, false, new OptionalLazySymbol(declaringClass), name, argumentTypes);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
651 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
652
22111
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
653 /**
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
654 * Registers an invocation plugin for a given, optional method. There must be no plugin
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
655 * currently registered for {@code method}.
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
656 *
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
657 * @param argumentTypes the argument types of the method. Element 0 of this array must be the
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
658 * {@link Class} value for {@link InvocationPlugin.Receiver} iff the method is
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
659 * non-static. Upon returning, element 0 will have been rewritten to
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
660 * {@code declaringClass}
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
661 */
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
662 public void registerOptional(InvocationPlugin plugin, Type declaringClass, String name, Type... argumentTypes) {
22678
f3ebbebef617 Allow overwriting of invocation plugins
Christian Wimmer <christian.wimmer@oracle.com>
parents: 22457
diff changeset
663 register(plugin, true, false, declaringClass, name, argumentTypes);
19390
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
664 }
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
665
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
666 /**
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
667 * Gets the plugin for a given method.
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
668 *
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
669 * @param method the method to lookup
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
670 * @return the plugin associated with {@code method} or {@code null} if none exists
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
671 */
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
672 public InvocationPlugin lookupInvocation(ResolvedJavaMethod method) {
19822
b950967f74c7 replaced HashMap with a side-table (i.e., an array) for looking up InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19821
diff changeset
673 if (parent != null) {
b950967f74c7 replaced HashMap with a side-table (i.e., an array) for looking up InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19821
diff changeset
674 InvocationPlugin plugin = parent.lookupInvocation(method);
b950967f74c7 replaced HashMap with a side-table (i.e., an array) for looking up InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19821
diff changeset
675 if (plugin != null) {
b950967f74c7 replaced HashMap with a side-table (i.e., an array) for looking up InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19821
diff changeset
676 return plugin;
b950967f74c7 replaced HashMap with a side-table (i.e., an array) for looking up InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19821
diff changeset
677 }
b950967f74c7 replaced HashMap with a side-table (i.e., an array) for looking up InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19821
diff changeset
678 }
22457
dfa24d13486e Drop use of MethodIdMap in InvocationPlugins
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22247
diff changeset
679 return get(method);
21376
739d9d9bd2fc Allow closing of invocation plugin registry to prevent future modifications
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20887
diff changeset
680 }
739d9d9bd2fc Allow closing of invocation plugin registry to prevent future modifications
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20887
diff changeset
681
739d9d9bd2fc Allow closing of invocation plugin registry to prevent future modifications
Christian Wimmer <christian.wimmer@oracle.com>
parents: 20887
diff changeset
682 /**
19822
b950967f74c7 replaced HashMap with a side-table (i.e., an array) for looking up InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19821
diff changeset
683 * Gets the invocation plugins {@linkplain #lookupInvocation(ResolvedJavaMethod) searched}
b950967f74c7 replaced HashMap with a side-table (i.e., an array) for looking up InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19821
diff changeset
684 * before searching in this object.
19390
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
685 */
19822
b950967f74c7 replaced HashMap with a side-table (i.e., an array) for looking up InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19821
diff changeset
686 public InvocationPlugins getParent() {
b950967f74c7 replaced HashMap with a side-table (i.e., an array) for looking up InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents: 19821
diff changeset
687 return parent;
19394
07f2edacfd3f copy all plugins when copying a GraphBuilderConfiguration
Doug Simon <doug.simon@oracle.com>
parents: 19390
diff changeset
688 }
07f2edacfd3f copy all plugins when copying a GraphBuilderConfiguration
Doug Simon <doug.simon@oracle.com>
parents: 19390
diff changeset
689
19390
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
690 @Override
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
691 public String toString() {
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
692 StringBuilder buf = new StringBuilder();
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
693 registrations.forEach((name, cp) -> buf.append(name).append('.').append(cp).append(", "));
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
694 String s = buf.toString();
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
695 if (buf.length() != 0) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
696 s = s.substring(buf.length() - ", ".length());
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
697 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
698 return s + " / parent: " + this.parent;
19390
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
699 }
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
700
7f4201b633e7 renamed GraphBuilderPlugins to InvocationPlugins and consolidated it into GraphBuilderConfiguration; moved declaration of GraphBuilderPlugin sub-interfaces into GraphBuilderPlugin
Doug Simon <doug.simon@oracle.com>
parents: 19375
diff changeset
701 private static class Checker {
19775
14e703edb2ab use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents: 19493
diff changeset
702 private static final int MAX_ARITY = 5;
19178
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
703 /**
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
704 * The set of all {@link InvocationPlugin#apply} method signatures.
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
705 */
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
706 static final Class<?>[][] SIGS;
22111
3f83cc877a0e Add support so methods for invocation plugins can be optional; add support for new unaligned Unsafe methods in JDK 9.
twisti
parents: 22054
diff changeset
707
19178
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
708 static {
19775
14e703edb2ab use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents: 19493
diff changeset
709 ArrayList<Class<?>[]> sigs = new ArrayList<>(MAX_ARITY);
19178
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
710 for (Method method : InvocationPlugin.class.getDeclaredMethods()) {
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
711 if (!Modifier.isStatic(method.getModifiers()) && method.getName().equals("apply")) {
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
712 Class<?>[] sig = method.getParameterTypes();
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
713 assert sig[0] == GraphBuilderContext.class;
19775
14e703edb2ab use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents: 19493
diff changeset
714 assert sig[1] == ResolvedJavaMethod.class;
21548
f4b3a6dadb44 moved Receiver inner class from MethodIdMap to InvocationPlugin (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21376
diff changeset
715 assert sig[2] == InvocationPlugin.Receiver.class;
22247
653e85bc19a0 Don't unconditionally copy an array that's only used in an assertion.
Roland Schatz <roland.schatz@oracle.com>
parents: 22111
diff changeset
716 assert Arrays.asList(sig).subList(3, sig.length).stream().allMatch(c -> c == ValueNode.class);
19962
9b669776bf8a added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents: 19959
diff changeset
717 while (sigs.size() < sig.length - 2) {
19178
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
718 sigs.add(null);
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
719 }
19962
9b669776bf8a added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents: 19959
diff changeset
720 sigs.set(sig.length - 3, sig);
19178
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
721 }
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
722 }
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
723 assert sigs.indexOf(null) == -1 : format("need to add an apply() method to %s that takes %d %s arguments ", InvocationPlugin.class.getName(), sigs.indexOf(null),
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
724 ValueNode.class.getSimpleName());
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
725 SIGS = sigs.toArray(new Class<?>[sigs.size()][]);
c8091ec0fdc0 added graph builder plugins for FrameWithoutBoxing
Doug Simon <doug.simon@oracle.com>
parents: 19155
diff changeset
726 }
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: 19066
diff changeset
727
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
728 public static boolean check(InvocationPlugins plugins, Type declaringType, MethodKey method, InvocationPlugin plugin) {
20887
dc58f4ca21c9 generalized map in InvocationPlugins to MethodIdMap
Doug Simon <doug.simon@oracle.com>
parents: 20886
diff changeset
729 InvocationPlugins p = plugins.parent;
20851
ce38ee1b67ab fix check for registering multiple InvocationPlugins for one method
Doug Simon <doug.simon@oracle.com>
parents: 20847
diff changeset
730 while (p != null) {
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
731 assert !p.containsKey(declaringType, method) : "a plugin is already registered for " + method;
20851
ce38ee1b67ab fix check for registering multiple InvocationPlugins for one method
Doug Simon <doug.simon@oracle.com>
parents: 20847
diff changeset
732 p = p.parent;
ce38ee1b67ab fix check for registering multiple InvocationPlugins for one method
Doug Simon <doug.simon@oracle.com>
parents: 20847
diff changeset
733 }
23078
b00ef2b9cd00 Generate graph builder plugins for @NodeIntrinsic and @Fold methods.
Roland Schatz <roland.schatz@oracle.com>
parents: 23076
diff changeset
734 if (plugin instanceof ForeignCallPlugin || plugin instanceof GeneratedInvocationPlugin) {
20847
74f8a2ec0844 generalized MathRuntimeCallPlugin to ForeignCallPlugin
Doug Simon <doug.simon@oracle.com>
parents: 20838
diff changeset
735 return true;
74f8a2ec0844 generalized MathRuntimeCallPlugin to ForeignCallPlugin
Doug Simon <doug.simon@oracle.com>
parents: 20838
diff changeset
736 }
20835
a2cd0e7072e2 added MethodSubstitutionPlugin as (eventual) replacement for @MethodSubstitution mechanism
Doug Simon <doug.simon@oracle.com>
parents: 20827
diff changeset
737 if (plugin instanceof MethodSubstitutionPlugin) {
a2cd0e7072e2 added MethodSubstitutionPlugin as (eventual) replacement for @MethodSubstitution mechanism
Doug Simon <doug.simon@oracle.com>
parents: 20827
diff changeset
738 MethodSubstitutionPlugin msplugin = (MethodSubstitutionPlugin) plugin;
a2cd0e7072e2 added MethodSubstitutionPlugin as (eventual) replacement for @MethodSubstitution mechanism
Doug Simon <doug.simon@oracle.com>
parents: 20827
diff changeset
739 msplugin.getJavaSubstitute();
a2cd0e7072e2 added MethodSubstitutionPlugin as (eventual) replacement for @MethodSubstitution mechanism
Doug Simon <doug.simon@oracle.com>
parents: 20827
diff changeset
740 return true;
a2cd0e7072e2 added MethodSubstitutionPlugin as (eventual) replacement for @MethodSubstitution mechanism
Doug Simon <doug.simon@oracle.com>
parents: 20827
diff changeset
741 }
21549
0627ebc2a3ea moved MethodId* classes from c.o.g.graphbuilderconf to c.o.g.api.meta (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21548
diff changeset
742 int arguments = method.getDeclaredParameterCount();
19817
3cc8aa066ed3 made resolution of method with InvocationPlugins lazy
Doug Simon <doug.simon@oracle.com>
parents: 19775
diff changeset
743 assert arguments < SIGS.length : format("need to extend %s to support method with %d arguments: %s", InvocationPlugin.class.getSimpleName(), arguments, method);
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: 19066
diff changeset
744 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: 19066
diff changeset
745 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: 19066
diff changeset
746 Class<?>[] parameterTypes = m.getParameterTypes();
19493
c4173ea6c8c7 allow an InvocationPlugin concrete class to implement more than one apply method
Doug Simon <doug.simon@oracle.com>
parents: 19444
diff changeset
747 if (Arrays.equals(SIGS[arguments], parameterTypes)) {
c4173ea6c8c7 allow an InvocationPlugin concrete class to implement more than one apply method
Doug Simon <doug.simon@oracle.com>
parents: 19444
diff changeset
748 return true;
c4173ea6c8c7 allow an InvocationPlugin concrete class to implement more than one apply method
Doug Simon <doug.simon@oracle.com>
parents: 19444
diff changeset
749 }
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: 19066
diff changeset
750 }
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19066
diff changeset
751 }
19817
3cc8aa066ed3 made resolution of method with InvocationPlugins lazy
Doug Simon <doug.simon@oracle.com>
parents: 19775
diff changeset
752 throw new AssertionError(format("graph builder plugin for %s not found", method));
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: 19066
diff changeset
753 }
81be933b83eb use anonymous classes for GraphBuilderPlugins instead of enums to common out registration logic and add better static checking
Doug Simon <doug.simon@oracle.com>
parents: 19066
diff changeset
754 }
19817
3cc8aa066ed3 made resolution of method with InvocationPlugins lazy
Doug Simon <doug.simon@oracle.com>
parents: 19775
diff changeset
755
19929
3a1ce0aeb829 added support for checking nodes added to the graph by an Invocation plugin and used this to check that only legal constants are added under ImmutableCode
Doug Simon <doug.simon@oracle.com>
parents: 19822
diff changeset
756 /**
3a1ce0aeb829 added support for checking nodes added to the graph by an Invocation plugin and used this to check that only legal constants are added under ImmutableCode
Doug Simon <doug.simon@oracle.com>
parents: 19822
diff changeset
757 * Checks a set of nodes added to the graph by an {@link InvocationPlugin}.
3a1ce0aeb829 added support for checking nodes added to the graph by an Invocation plugin and used this to check that only legal constants are added under ImmutableCode
Doug Simon <doug.simon@oracle.com>
parents: 19822
diff changeset
758 *
3a1ce0aeb829 added support for checking nodes added to the graph by an Invocation plugin and used this to check that only legal constants are added under ImmutableCode
Doug Simon <doug.simon@oracle.com>
parents: 19822
diff changeset
759 * @param b the graph builder that applied the plugin
3a1ce0aeb829 added support for checking nodes added to the graph by an Invocation plugin and used this to check that only legal constants are added under ImmutableCode
Doug Simon <doug.simon@oracle.com>
parents: 19822
diff changeset
760 * @param plugin a plugin that was just applied
3a1ce0aeb829 added support for checking nodes added to the graph by an Invocation plugin and used this to check that only legal constants are added under ImmutableCode
Doug Simon <doug.simon@oracle.com>
parents: 19822
diff changeset
761 * @param newNodes the nodes added to the graph by {@code plugin}
3a1ce0aeb829 added support for checking nodes added to the graph by an Invocation plugin and used this to check that only legal constants are added under ImmutableCode
Doug Simon <doug.simon@oracle.com>
parents: 19822
diff changeset
762 * @throws AssertionError if any check fail
3a1ce0aeb829 added support for checking nodes added to the graph by an Invocation plugin and used this to check that only legal constants are added under ImmutableCode
Doug Simon <doug.simon@oracle.com>
parents: 19822
diff changeset
763 */
3a1ce0aeb829 added support for checking nodes added to the graph by an Invocation plugin and used this to check that only legal constants are added under ImmutableCode
Doug Simon <doug.simon@oracle.com>
parents: 19822
diff changeset
764 public void checkNewNodes(GraphBuilderContext b, InvocationPlugin plugin, NodeIterable<Node> newNodes) {
3a1ce0aeb829 added support for checking nodes added to the graph by an Invocation plugin and used this to check that only legal constants are added under ImmutableCode
Doug Simon <doug.simon@oracle.com>
parents: 19822
diff changeset
765 if (parent != null) {
3a1ce0aeb829 added support for checking nodes added to the graph by an Invocation plugin and used this to check that only legal constants are added under ImmutableCode
Doug Simon <doug.simon@oracle.com>
parents: 19822
diff changeset
766 parent.checkNewNodes(b, plugin, newNodes);
3a1ce0aeb829 added support for checking nodes added to the graph by an Invocation plugin and used this to check that only legal constants are added under ImmutableCode
Doug Simon <doug.simon@oracle.com>
parents: 19822
diff changeset
767 }
3a1ce0aeb829 added support for checking nodes added to the graph by an Invocation plugin and used this to check that only legal constants are added under ImmutableCode
Doug Simon <doug.simon@oracle.com>
parents: 19822
diff changeset
768 }
23160
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
769
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
770 /**
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
771 * Resolves a name to a class.
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
772 *
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
773 * @param className the name of the class to resolve
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
774 * @param optional if true, resolution failure returns null
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
775 * @return the resolved class or null if resolution fails and {@code optional} is true
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
776 */
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
777 public static Class<?> resolveClass(String className, boolean optional) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
778 try {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
779 // Need to use launcher class path to handle classes
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
780 // that are not on the boot class path
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
781 ClassLoader cl = Launcher.getLauncher().getClassLoader();
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
782 return Class.forName(className, false, cl);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
783 } catch (ClassNotFoundException e) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
784 if (optional) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
785 return null;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
786 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
787 throw new JVMCIError("Could not resolve type " + className);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
788 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
789 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
790
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
791 /**
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
792 * Resolves a {@link Type} to a {@link Class}.
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
793 *
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
794 * @param type the type to resolve
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
795 * @param optional if true, resolution failure returns null
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
796 * @return the resolved class or null if resolution fails and {@code optional} is true
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
797 */
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
798 public static Class<?> resolveType(Type type, boolean optional) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
799 if (type instanceof Class) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
800 return (Class<?>) type;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
801 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
802 if (optional && type instanceof OptionalLazySymbol) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
803 return ((OptionalLazySymbol) type).resolve();
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
804 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
805 return resolveClass(type.getTypeName(), optional);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
806 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
807
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
808 private static final Class<?>[] NO_CLASSES = {};
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
809
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
810 /**
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
811 * Resolves an array of {@link Type}s to an array of {@link Class}es.
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
812 *
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
813 * @param types the types to resolve
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
814 * @param from the initial index of the range to be resolved, inclusive
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
815 * @param to the final index of the range to be resolved, exclusive
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
816 * @return the resolved class or null if resolution fails and {@code optional} is true
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
817 */
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
818 public static Class<?>[] resolveTypes(Type[] types, int from, int to) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
819 int length = to - from;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
820 if (length <= 0) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
821 return NO_CLASSES;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
822 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
823 Class<?>[] classes = new Class<?>[length];
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
824 for (int i = 0; i < length; i++) {
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
825 classes[i] = resolveType(types[i + from], false);
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
826 }
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
827 return classes;
c01c5942b880 lazily initialize invocation plugins per class the first time an invocation to a method for which a plugin exists is compiled
Doug Simon <doug.simon@oracle.com>
parents: 23144
diff changeset
828 }
19050
75da87c96605 initial commit of GraphBuilderPhase plugins
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
829 }