Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.graal.api.replacements/src/com/oracle/graal/api/replacements/SnippetReflectionProvider.java @ 18845:f57d86eb036f
removed Node factory methods
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 12 Jan 2015 20:39:04 +0100 |
parents | 25a21e1794ec |
children | 48c1ebd24120 |
rev | line source |
---|---|
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
1 /* |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved. |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
4 * |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
8 * |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
14 * |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
18 * |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
21 * questions. |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
22 */ |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.api.replacements; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
24 |
18533
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
25 import java.lang.reflect.*; |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
26 import java.util.*; |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
27 |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
28 import com.oracle.graal.api.meta.*; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
29 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
30 /** |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
15018
diff
changeset
|
31 * Reflection operations on values represented as {@linkplain JavaConstant constants} for the |
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
15018
diff
changeset
|
32 * processing of snippets. Snippets need a direct access to the value of object constants, which is |
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
15018
diff
changeset
|
33 * not allowed in other parts of Graal to enforce compiler-VM separation. |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
34 * <p> |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
35 * This interface must not be used in Graal code that is not related to snippet processing. |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
36 */ |
18530
2906b3cc3e2f
moved application of Remote marker interface to implementation classes only
Doug Simon <doug.simon@oracle.com>
parents:
18515
diff
changeset
|
37 public interface SnippetReflectionProvider { |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
38 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
39 /** |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
40 * Creates a boxed {@link Kind#Object object} constant. |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
41 * |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
42 * @param object the object value to box |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
43 * @return a constant containing {@code object} |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
44 */ |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
15018
diff
changeset
|
45 JavaConstant forObject(Object object); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
46 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
47 /** |
18533
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
48 * Gets the object reference a given constant represents if it is of a given type. The constant |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
49 * must have kind {@link Kind#Object}. |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
50 * |
18533
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
51 * @param type the expected type of the object represented by {@code constant}. If the object is |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
52 * required to be of this type, then wrap the call to this method in |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
53 * {@link Objects#requireNonNull(Object)}. |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
54 * @param constant an object constant |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
55 * @return the object value represented by {@code constant} cast to {@code type} if it is an |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
56 * {@link Class#isInstance(Object) instance of} {@code type} otherwise {@code null} |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
57 */ |
18533
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
58 <T> T asObject(Class<T> type, JavaConstant constant); |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
59 |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
60 /** |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
61 * Gets the object reference a given constant represents if it is of a given type. The constant |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
62 * must have kind {@link Kind#Object}. |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
63 * |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
64 * @param type the expected type of the object represented by {@code constant}. If the object is |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
65 * required to be of this type, then wrap the call to this method in |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
66 * {@link Objects#requireNonNull(Object)}. |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
67 * @param constant an object constant |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
68 * @return the object value represented by {@code constant} if it is an |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
69 * {@link ResolvedJavaType#isInstance(JavaConstant) instance of} {@code type} otherwise |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
70 * {@code null} |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
71 */ |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
72 Object asObject(ResolvedJavaType type, JavaConstant constant); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
73 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
74 /** |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
75 * Creates a boxed constant for the given kind from an Object. The object needs to be of the |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
76 * Java boxed type corresponding to the kind. |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
77 * |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
78 * @param kind the kind of the constant to create |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
79 * @param value the Java boxed value: a {@link Byte} instance for {@link Kind#Byte}, etc. |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
80 * @return the boxed copy of {@code value} |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
81 */ |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
15018
diff
changeset
|
82 JavaConstant forBoxed(Kind kind, Object value); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
83 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
84 /** |
18533
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
85 * Resolves a parameter or return type involved in snippet code to a {@link Class}. |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
86 */ |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
87 static Class<?> resolveClassForSnippet(JavaType type) throws ClassNotFoundException { |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
88 try { |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
89 return Class.forName(type.toClassName()); |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
90 } catch (ClassNotFoundException e) { |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
91 // Support for -XX:-UseGraalClassLoader |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
92 return Class.forName(type.toClassName(), false, ClassLoader.getSystemClassLoader()); |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
93 } |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
94 } |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
95 |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
96 /** |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
97 * Invokes a given method via {@link Method#invoke(Object, Object...)}. |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
98 */ |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
99 default Object invoke(ResolvedJavaMethod method, Object receiver, Object... args) { |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
100 try { |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
101 JavaType[] parameterTypes = method.toParameterTypes(); |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
102 Class<?>[] parameterClasses = new Class<?>[parameterTypes.length]; |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
103 for (int i = 0; i < parameterClasses.length; ++i) { |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
104 JavaType type = parameterTypes[i]; |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
105 if (type.getKind() != Kind.Object) { |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
106 parameterClasses[i] = type.getKind().toJavaClass(); |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
107 } else { |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
108 parameterClasses[i] = resolveClassForSnippet(parameterTypes[i]); |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
109 } |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
110 } |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
111 |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
112 Class<?> c = resolveClassForSnippet(method.getDeclaringClass()); |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18533
diff
changeset
|
113 if (method.isConstructor()) { |
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18533
diff
changeset
|
114 Constructor<?> javaConstructor = c.getDeclaredConstructor(parameterClasses); |
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18533
diff
changeset
|
115 javaConstructor.setAccessible(true); |
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18533
diff
changeset
|
116 return javaConstructor.newInstance(args); |
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18533
diff
changeset
|
117 } else { |
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18533
diff
changeset
|
118 Method javaMethod = c.getDeclaredMethod(method.getName(), parameterClasses); |
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18533
diff
changeset
|
119 javaMethod.setAccessible(true); |
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18533
diff
changeset
|
120 return javaMethod.invoke(receiver, args); |
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18533
diff
changeset
|
121 } |
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18533
diff
changeset
|
122 } catch (IllegalAccessException | InstantiationException | InvocationTargetException | ClassNotFoundException | NoSuchMethodException ex) { |
18533
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
123 throw new IllegalArgumentException(ex); |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
124 } |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
125 } |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
126 |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
127 /** |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
128 * Gets the constant value of this field. Note that a {@code static final} field may not be |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
129 * considered constant if its declaring class is not yet initialized or if it is a well known |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
130 * field that can be updated via other means (e.g., {@link System#setOut(java.io.PrintStream)}). |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
131 * |
18533
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
132 * @param receiver object from which this field's value is to be read. This value is ignored if |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
133 * this field is static. |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
134 * @return the constant value of this field or {@code null} if this field is not considered |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
135 * constant by the runtime |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
136 */ |
18533
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
137 default Object readConstantFieldValue(JavaField field, Object receiver) { |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
138 try { |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
139 Class<?> c = resolveClassForSnippet(field.getDeclaringClass()); |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
140 Field javaField = c.getDeclaredField(field.getName()); |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
141 javaField.setAccessible(true); |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
142 return javaField.get(receiver); |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
143 } catch (IllegalAccessException | ClassNotFoundException | NoSuchFieldException ex) { |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
144 throw new IllegalArgumentException(ex); |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
145 } |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
146 } |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
147 |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
148 /** |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
149 * Creates a new array with a given type as the component type and the specified length. This |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
150 * method is similar to {@link Array#newInstance(Class, int)}. |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
151 */ |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
152 default Object newArray(ResolvedJavaType componentType, int length) { |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
153 try { |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
154 return Array.newInstance(resolveClassForSnippet(componentType), length); |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
155 } catch (ClassNotFoundException e) { |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
156 throw new IllegalArgumentException(e); |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
157 } |
25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
158 } |
18512
7a3bba33f2b7
added support for binding arguments of arbitrary types to parameters of a SubstitutionGuard constructor
Doug Simon <doug.simon@oracle.com>
parents:
18267
diff
changeset
|
159 |
7a3bba33f2b7
added support for binding arguments of arbitrary types to parameters of a SubstitutionGuard constructor
Doug Simon <doug.simon@oracle.com>
parents:
18267
diff
changeset
|
160 /** |
7a3bba33f2b7
added support for binding arguments of arbitrary types to parameters of a SubstitutionGuard constructor
Doug Simon <doug.simon@oracle.com>
parents:
18267
diff
changeset
|
161 * Gets the value to bind to a parameter in a {@link SubstitutionGuard} constructor. |
7a3bba33f2b7
added support for binding arguments of arbitrary types to parameters of a SubstitutionGuard constructor
Doug Simon <doug.simon@oracle.com>
parents:
18267
diff
changeset
|
162 * |
7a3bba33f2b7
added support for binding arguments of arbitrary types to parameters of a SubstitutionGuard constructor
Doug Simon <doug.simon@oracle.com>
parents:
18267
diff
changeset
|
163 * @param type the type of a parameter in a {@link SubstitutionGuard} constructor |
7a3bba33f2b7
added support for binding arguments of arbitrary types to parameters of a SubstitutionGuard constructor
Doug Simon <doug.simon@oracle.com>
parents:
18267
diff
changeset
|
164 * @return the value that should be bound to the parameter when invoking the constructor or null |
7a3bba33f2b7
added support for binding arguments of arbitrary types to parameters of a SubstitutionGuard constructor
Doug Simon <doug.simon@oracle.com>
parents:
18267
diff
changeset
|
165 * if this provider cannot provide a value of the requested type |
7a3bba33f2b7
added support for binding arguments of arbitrary types to parameters of a SubstitutionGuard constructor
Doug Simon <doug.simon@oracle.com>
parents:
18267
diff
changeset
|
166 */ |
7a3bba33f2b7
added support for binding arguments of arbitrary types to parameters of a SubstitutionGuard constructor
Doug Simon <doug.simon@oracle.com>
parents:
18267
diff
changeset
|
167 Object getSubstitutionGuardParameter(Class<?> type); |
18515
e846c9e2f0e5
added support for binding arguments of arbitrary types to parameters of a node intrinsic constructor (or factory method)
Doug Simon <doug.simon@oracle.com>
parents:
18512
diff
changeset
|
168 |
e846c9e2f0e5
added support for binding arguments of arbitrary types to parameters of a node intrinsic constructor (or factory method)
Doug Simon <doug.simon@oracle.com>
parents:
18512
diff
changeset
|
169 /** |
e846c9e2f0e5
added support for binding arguments of arbitrary types to parameters of a node intrinsic constructor (or factory method)
Doug Simon <doug.simon@oracle.com>
parents:
18512
diff
changeset
|
170 * Gets the value to bind to an injected parameter in a node intrinsic. |
e846c9e2f0e5
added support for binding arguments of arbitrary types to parameters of a node intrinsic constructor (or factory method)
Doug Simon <doug.simon@oracle.com>
parents:
18512
diff
changeset
|
171 * |
e846c9e2f0e5
added support for binding arguments of arbitrary types to parameters of a node intrinsic constructor (or factory method)
Doug Simon <doug.simon@oracle.com>
parents:
18512
diff
changeset
|
172 * @param type the type of a parameter in a node intrinsic constructor |
e846c9e2f0e5
added support for binding arguments of arbitrary types to parameters of a node intrinsic constructor (or factory method)
Doug Simon <doug.simon@oracle.com>
parents:
18512
diff
changeset
|
173 * @return the value that should be bound to the parameter when invoking the constructor or null |
e846c9e2f0e5
added support for binding arguments of arbitrary types to parameters of a node intrinsic constructor (or factory method)
Doug Simon <doug.simon@oracle.com>
parents:
18512
diff
changeset
|
174 * if this provider cannot provide a value of the requested type |
e846c9e2f0e5
added support for binding arguments of arbitrary types to parameters of a node intrinsic constructor (or factory method)
Doug Simon <doug.simon@oracle.com>
parents:
18512
diff
changeset
|
175 */ |
e846c9e2f0e5
added support for binding arguments of arbitrary types to parameters of a node intrinsic constructor (or factory method)
Doug Simon <doug.simon@oracle.com>
parents:
18512
diff
changeset
|
176 Object getInjectedNodeIntrinsicParameter(ResolvedJavaType type); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
177 } |