author | vromero |
Fri, 17 May 2019 13:16:07 -0400 | |
changeset 54929 | 657f6e484bc6 |
parent 52914 | 4fa75d8ad418 |
permissions | -rw-r--r-- |
52914 | 1 |
/* |
54929
657f6e484bc6
8223803: j.l.c.MethodTypeDesc::insertParameterTypes doesn't control type of parameters
vromero
parents:
52914
diff
changeset
|
2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
52914 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
package java.lang.constant; |
|
26 |
||
27 |
import java.lang.Enum.EnumDesc; |
|
28 |
import java.lang.invoke.MethodHandle; |
|
29 |
import java.lang.invoke.MethodHandles; |
|
30 |
import java.lang.invoke.MethodType; |
|
31 |
import java.lang.invoke.VarHandle.VarHandleDesc; |
|
32 |
||
33 |
/** |
|
34 |
* A <a href="package-summary.html#nominal">nominal descriptor</a> for a loadable |
|
35 |
* constant value, as defined in JVMS 4.4. Such a descriptor can be resolved via |
|
36 |
* {@link ConstantDesc#resolveConstantDesc(MethodHandles.Lookup)} to yield the |
|
37 |
* constant value itself. |
|
38 |
* |
|
39 |
* <p>Class names in a nominal descriptor, like class names in the constant pool |
|
40 |
* of a classfile, must be interpreted with respect to a particular class |
|
41 |
* loader, which is not part of the nominal descriptor. |
|
42 |
* |
|
43 |
* <p>Static constants that are expressible natively in the constant pool ({@link String}, |
|
44 |
* {@link Integer}, {@link Long}, {@link Float}, and {@link Double}) implement |
|
45 |
* {@link ConstantDesc}, and serve as nominal descriptors for themselves. |
|
46 |
* Native linkable constants ({@link Class}, {@link MethodType}, and |
|
47 |
* {@link MethodHandle}) have counterpart {@linkplain ConstantDesc} types: |
|
48 |
* {@link ClassDesc}, {@link MethodTypeDesc}, and {@link MethodHandleDesc}. |
|
49 |
* Other constants are represented by subtypes of {@link DynamicConstantDesc}. |
|
50 |
* |
|
51 |
* <p>APIs that perform generation or parsing of bytecode are encouraged to use |
|
52 |
* {@linkplain ConstantDesc} to describe the operand of an {@code ldc} instruction |
|
53 |
* (including dynamic constants), the static bootstrap arguments of |
|
54 |
* dynamic constants and {@code invokedynamic} instructions, and other |
|
55 |
* bytecodes or classfile structures that make use of the constant pool. |
|
56 |
* |
|
57 |
* <p>Constants describing various common constants (such as {@link ClassDesc} |
|
58 |
* instances for platform types) can be found in {@link ConstantDescs}. |
|
59 |
* |
|
60 |
* <p>Implementations of {@linkplain ConstantDesc} must be |
|
61 |
* <a href="../doc-files/ValueBased.html">value-based</a> classes. |
|
62 |
* |
|
63 |
* <p>Non-platform classes should not implement {@linkplain ConstantDesc} directly. |
|
64 |
* Instead, they should extend {@link DynamicConstantDesc} (as {@link EnumDesc} |
|
65 |
* and {@link VarHandleDesc} do.) |
|
66 |
* |
|
67 |
* <p>Nominal descriptors should be compared using the |
|
68 |
* {@link Object#equals(Object)} method. There is no guarantee that any |
|
69 |
* particular entity will always be represented by the same descriptor instance. |
|
70 |
* |
|
71 |
* @apiNote In the future, if the Java language permits, {@linkplain ConstantDesc} |
|
72 |
* may become a {@code sealed} interface, which would prohibit subclassing except by |
|
73 |
* explicitly permitted types. Clients can assume that the following |
|
74 |
* set of subtypes is exhaustive: {@link String}, {@link Integer}, |
|
75 |
* {@link Long}, {@link Float}, {@link Double}, {@link ClassDesc}, |
|
76 |
* {@link MethodTypeDesc}, {@link MethodHandleDesc}, and |
|
77 |
* {@link DynamicConstantDesc}; this list may be extended to reflect future |
|
78 |
* changes to the constant pool format as defined in JVMS 4.4. |
|
79 |
* |
|
80 |
* @see Constable |
|
81 |
* @see ConstantDescs |
|
82 |
* |
|
83 |
* @jvms 4.4 The Constant Pool |
|
84 |
* |
|
85 |
* @since 12 |
|
86 |
*/ |
|
87 |
public interface ConstantDesc { |
|
88 |
/** |
|
89 |
* Resolves this descriptor reflectively, emulating the resolution behavior |
|
90 |
* of JVMS 5.4.3 and the access control behavior of JVMS 5.4.4. The resolution |
|
91 |
* and access control context is provided by the {@link MethodHandles.Lookup} |
|
92 |
* parameter. No caching of the resulting value is performed. |
|
93 |
* |
|
94 |
* @param lookup The {@link MethodHandles.Lookup} to provide name resolution |
|
95 |
* and access control context |
|
96 |
* @return the resolved constant value |
|
97 |
* @throws ReflectiveOperationException if a class, method, or field |
|
98 |
* could not be reflectively resolved in the course of resolution |
|
99 |
* @throws LinkageError if a linkage error occurs |
|
54929
657f6e484bc6
8223803: j.l.c.MethodTypeDesc::insertParameterTypes doesn't control type of parameters
vromero
parents:
52914
diff
changeset
|
100 |
* |
657f6e484bc6
8223803: j.l.c.MethodTypeDesc::insertParameterTypes doesn't control type of parameters
vromero
parents:
52914
diff
changeset
|
101 |
* @apiNote {@linkplain MethodTypeDesc} can represent method type descriptors |
657f6e484bc6
8223803: j.l.c.MethodTypeDesc::insertParameterTypes doesn't control type of parameters
vromero
parents:
52914
diff
changeset
|
102 |
* that are not representable by {@linkplain MethodType}, such as methods with |
657f6e484bc6
8223803: j.l.c.MethodTypeDesc::insertParameterTypes doesn't control type of parameters
vromero
parents:
52914
diff
changeset
|
103 |
* more than 255 parameter slots, so attempts to resolve these may result in errors. |
657f6e484bc6
8223803: j.l.c.MethodTypeDesc::insertParameterTypes doesn't control type of parameters
vromero
parents:
52914
diff
changeset
|
104 |
* |
52914 | 105 |
* @jvms 5.4.3 Resolution |
106 |
* @jvms 5.4.4 Access Control |
|
107 |
*/ |
|
108 |
Object resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException; |
|
109 |
} |