Batch of classes necessary to implement invoke dynamic interfaces. Taken from JDK8 build 132
2 * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
26 package sun.invoke.anon;
29 * A visitor called by {@link ConstantPoolParser#parse(ConstantPoolVisitor)}
30 * when a constant pool entry is parsed.
32 * A visit* method is called when a constant pool entry is parsed.
33 * The first argument is always the constant pool index.
34 * The second argument is always the constant pool tag,
35 * even for methods like {@link #visitUTF8(int, byte, String)} which only apply to one tag.
36 * String arguments refer to Utf8 or NameAndType entries declared elsewhere,
37 * and are always accompanied by the indexes of those entries.
39 * The order of the calls to the visit* methods is not necessarily related
40 * to the order of the entries in the constant pool.
41 * If one entry has a reference to another entry, the latter (lower-level)
42 * entry will be visited first.
44 * The following table shows the relation between constant pool entry
45 * types and the corresponding visit* methods:
47 * <table border=1 cellpadding=5 summary="constant pool visitor methods">
48 * <tr><th>Tag(s)</th><th>Method</th></tr>
50 * <td>{@link #CONSTANT_Utf8}</td>
51 * <td>{@link #visitUTF8(int, byte, String)}</td>
53 * <td>{@link #CONSTANT_Integer}, {@link #CONSTANT_Float},
54 * {@link #CONSTANT_Long}, {@link #CONSTANT_Double}</td>
55 * <td>{@link #visitConstantValue(int, byte, Object)}</td>
57 * <td>{@link #CONSTANT_String}, {@link #CONSTANT_Class}</td>
58 * <td>{@link #visitConstantString(int, byte, String, int)}</td>
60 * <td>{@link #CONSTANT_NameAndType}</td>
61 * <td>{@link #visitDescriptor(int, byte, String, String, int, int)}</td>
63 * <td>{@link #CONSTANT_Fieldref},
64 * {@link #CONSTANT_Methodref},
65 * {@link #CONSTANT_InterfaceMethodref}</td>
66 * <td>{@link #visitMemberRef(int, byte, String, String, String, int, int)}</td>
70 * @see ConstantPoolPatch
74 public class ConstantPoolVisitor {
75 /** Called each time an UTF8 constant pool entry is found.
76 * @param index the constant pool index
77 * @param tag always {@link #CONSTANT_Utf8}
78 * @param utf8 string encoded in modified UTF-8 format passed as a {@code String}
80 * @see ConstantPoolPatch#putUTF8(int, String)
82 public void visitUTF8(int index, byte tag, String utf8) {
86 /** Called for each constant pool entry that encodes an integer,
87 * a float, a long, or a double.
88 * Constant strings and classes are not managed by this method but
89 * by {@link #visitConstantString(int, byte, String, int)}.
91 * @param index the constant pool index
92 * @param tag one of {@link #CONSTANT_Integer},
93 * {@link #CONSTANT_Float},
94 * {@link #CONSTANT_Long},
95 * or {@link #CONSTANT_Double}
96 * @param value encoded value
98 * @see ConstantPoolPatch#putConstantValue(int, Object)
100 public void visitConstantValue(int index, byte tag, Object value) {
104 /** Called for each constant pool entry that encodes a string or a class.
105 * @param index the constant pool index
106 * @param tag one of {@link #CONSTANT_String},
107 * {@link #CONSTANT_Class},
108 * @param name string body or class name (using dot separator)
109 * @param nameIndex the index of the Utf8 string for the name
111 * @see ConstantPoolPatch#putConstantValue(int, byte, Object)
113 public void visitConstantString(int index, byte tag,
114 String name, int nameIndex) {
118 /** Called for each constant pool entry that encodes a name and type.
119 * @param index the constant pool index
120 * @param tag always {@link #CONSTANT_NameAndType}
121 * @param memberName a field or method name
122 * @param signature the member signature
123 * @param memberNameIndex index of the Utf8 string for the member name
124 * @param signatureIndex index of the Utf8 string for the signature
126 * @see ConstantPoolPatch#putDescriptor(int, String, String)
128 public void visitDescriptor(int index, byte tag,
129 String memberName, String signature,
130 int memberNameIndex, int signatureIndex) {
134 /** Called for each constant pool entry that encodes a field or method.
135 * @param index the constant pool index
136 * @param tag one of {@link #CONSTANT_Fieldref},
137 * or {@link #CONSTANT_Methodref},
138 * or {@link #CONSTANT_InterfaceMethodref}
139 * @param className the class name (using dot separator)
140 * @param memberName name of the field or method
141 * @param signature the field or method signature
142 * @param classNameIndex index of the Utf8 string for the class name
143 * @param descriptorIndex index of the NameAndType descriptor constant
145 * @see ConstantPoolPatch#putMemberRef(int, byte, String, String, String)
147 public void visitMemberRef(int index, byte tag,
148 String className, String memberName, String signature,
149 int classNameIndex, int descriptorIndex) {
153 public static final byte
156 //CONSTANT_Unicode = 2, /* unused */
157 CONSTANT_Integer = 3,
163 CONSTANT_Fieldref = 9,
164 CONSTANT_Methodref = 10,
165 CONSTANT_InterfaceMethodref = 11,
166 CONSTANT_NameAndType = 12;
168 private static String[] TAG_NAMES = {
180 "InterfaceMethodref",
184 public static String tagName(byte tag) {
186 if ((tag & 0xFF) < TAG_NAMES.length)
187 name = TAG_NAMES[tag];
189 name = "Unknown#"+(tag&0xFF);