author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 42827 | langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Pool.java@36468b5fa7f4 |
child 49577 | faf02d65df7d |
permissions | -rw-r--r-- |
10 | 1 |
/* |
15564
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
14949
diff
changeset
|
2 |
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 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 |
* |
|
5520 | 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. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.jvm; |
|
27 |
||
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
28 |
import com.sun.tools.javac.code.Symbol; |
10 | 29 |
import com.sun.tools.javac.code.Symbol.*; |
24605
265027386d51
8015927: Class reference duplicates in constant pool
pgovereau
parents:
24396
diff
changeset
|
30 |
import com.sun.tools.javac.code.TypeTag; |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
31 |
import com.sun.tools.javac.code.Type; |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
32 |
import com.sun.tools.javac.code.Types; |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
33 |
import com.sun.tools.javac.code.Types.UniqueType; |
14052 | 34 |
|
14053 | 35 |
import com.sun.tools.javac.util.ArrayUtils; |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
36 |
import com.sun.tools.javac.util.Assert; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
37 |
import com.sun.tools.javac.util.Filter; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
38 |
import com.sun.tools.javac.util.Name; |
10 | 39 |
|
14052 | 40 |
import java.util.*; |
41 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
42 |
import com.sun.tools.javac.util.DefinedBy; |
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
43 |
import com.sun.tools.javac.util.DefinedBy.Api; |
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
44 |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26266
diff
changeset
|
45 |
import static com.sun.tools.javac.code.Kinds.*; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26266
diff
changeset
|
46 |
import static com.sun.tools.javac.code.Kinds.Kind.*; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26266
diff
changeset
|
47 |
|
10 | 48 |
/** An internal structure that corresponds to the constant pool of a classfile. |
49 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
50 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
51 |
* If you write code that depends on this, you do so at your own risk. |
10 | 52 |
* This code and its internal interfaces are subject to change or |
53 |
* deletion without notice.</b> |
|
54 |
*/ |
|
55 |
public class Pool { |
|
56 |
||
57 |
public static final int MAX_ENTRIES = 0xFFFF; |
|
58 |
public static final int MAX_STRING_LENGTH = 0xFFFF; |
|
59 |
||
60 |
/** Index of next constant to be entered. |
|
61 |
*/ |
|
62 |
int pp; |
|
63 |
||
64 |
/** The initial pool buffer. |
|
65 |
*/ |
|
66 |
Object[] pool; |
|
67 |
||
68 |
/** A hashtable containing all constants in the pool. |
|
69 |
*/ |
|
70 |
Map<Object,Integer> indices; |
|
71 |
||
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
72 |
Types types; |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
73 |
|
10 | 74 |
/** Construct a pool with given number of elements and element array. |
75 |
*/ |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
76 |
public Pool(int pp, Object[] pool, Types types) { |
10 | 77 |
this.pp = pp; |
78 |
this.pool = pool; |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
79 |
this.types = types; |
22163 | 80 |
this.indices = new HashMap<>(pool.length); |
10 | 81 |
for (int i = 1; i < pp; i++) { |
82 |
if (pool[i] != null) indices.put(pool[i], i); |
|
83 |
} |
|
84 |
} |
|
85 |
||
86 |
/** Construct an empty pool. |
|
87 |
*/ |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
88 |
public Pool(Types types) { |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
89 |
this(1, new Object[64], types); |
10 | 90 |
} |
91 |
||
92 |
/** Return the number of entries in the constant pool. |
|
93 |
*/ |
|
94 |
public int numEntries() { |
|
95 |
return pp; |
|
96 |
} |
|
97 |
||
98 |
/** Remove everything from this pool. |
|
99 |
*/ |
|
100 |
public void reset() { |
|
101 |
pp = 1; |
|
102 |
indices.clear(); |
|
103 |
} |
|
104 |
||
105 |
/** Place an object in the pool, unless it is already there. |
|
106 |
* If object is a symbol also enter its owner unless the owner is a |
|
107 |
* package. Return the object's index in the pool. |
|
108 |
*/ |
|
109 |
public int put(Object value) { |
|
14547 | 110 |
value = makePoolValue(value); |
24396 | 111 |
Assert.check(!(value instanceof Type.TypeVar)); |
112 |
Assert.check(!(value instanceof Types.UniqueType && |
|
113 |
((UniqueType) value).type instanceof Type.TypeVar)); |
|
10 | 114 |
Integer index = indices.get(value); |
115 |
if (index == null) { |
|
116 |
index = pp; |
|
117 |
indices.put(value, index); |
|
14049
3207422a0f9b
7193657: provide internal ArrayUtils class to simplify common usage of arrays in javac
jjg
parents:
14046
diff
changeset
|
118 |
pool = ArrayUtils.ensureCapacity(pool, pp); |
10 | 119 |
pool[pp++] = value; |
120 |
if (value instanceof Long || value instanceof Double) { |
|
14049
3207422a0f9b
7193657: provide internal ArrayUtils class to simplify common usage of arrays in javac
jjg
parents:
14046
diff
changeset
|
121 |
pool = ArrayUtils.ensureCapacity(pool, pp); |
10 | 122 |
pool[pp++] = null; |
123 |
} |
|
124 |
} |
|
125 |
return index.intValue(); |
|
126 |
} |
|
127 |
||
14547 | 128 |
Object makePoolValue(Object o) { |
129 |
if (o instanceof DynamicMethodSymbol) { |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
130 |
return new DynamicMethod((DynamicMethodSymbol)o, types); |
14547 | 131 |
} else if (o instanceof MethodSymbol) { |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
132 |
return new Method((MethodSymbol)o, types); |
14547 | 133 |
} else if (o instanceof VarSymbol) { |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
134 |
return new Variable((VarSymbol)o, types); |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
135 |
} else if (o instanceof Type) { |
24605
265027386d51
8015927: Class reference duplicates in constant pool
pgovereau
parents:
24396
diff
changeset
|
136 |
Type t = (Type)o; |
265027386d51
8015927: Class reference duplicates in constant pool
pgovereau
parents:
24396
diff
changeset
|
137 |
// ClassRefs can come from ClassSymbols or from Types. |
265027386d51
8015927: Class reference duplicates in constant pool
pgovereau
parents:
24396
diff
changeset
|
138 |
// Return the symbol for these types to avoid duplicates |
265027386d51
8015927: Class reference duplicates in constant pool
pgovereau
parents:
24396
diff
changeset
|
139 |
// in the constant pool |
265027386d51
8015927: Class reference duplicates in constant pool
pgovereau
parents:
24396
diff
changeset
|
140 |
if (t.hasTag(TypeTag.CLASS)) |
265027386d51
8015927: Class reference duplicates in constant pool
pgovereau
parents:
24396
diff
changeset
|
141 |
return t.tsym; |
265027386d51
8015927: Class reference duplicates in constant pool
pgovereau
parents:
24396
diff
changeset
|
142 |
else |
265027386d51
8015927: Class reference duplicates in constant pool
pgovereau
parents:
24396
diff
changeset
|
143 |
return new UniqueType(t, types); |
14547 | 144 |
} else { |
145 |
return o; |
|
146 |
} |
|
147 |
} |
|
148 |
||
10 | 149 |
/** Return the given object's index in the pool, |
150 |
* or -1 if object is not in there. |
|
151 |
*/ |
|
152 |
public int get(Object o) { |
|
153 |
Integer n = indices.get(o); |
|
154 |
return n == null ? -1 : n.intValue(); |
|
155 |
} |
|
156 |
||
15564
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
14949
diff
changeset
|
157 |
static class Method extends DelegatedSymbol<MethodSymbol> { |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
158 |
UniqueType uniqueType; |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
159 |
Method(MethodSymbol m, Types types) { |
10 | 160 |
super(m); |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
161 |
this.uniqueType = new UniqueType(m.type, types); |
10 | 162 |
} |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
163 |
@DefinedBy(Api.LANGUAGE_MODEL) |
15564
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
14949
diff
changeset
|
164 |
public boolean equals(Object any) { |
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
14949
diff
changeset
|
165 |
if (!(any instanceof Method)) return false; |
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
14949
diff
changeset
|
166 |
MethodSymbol o = ((Method)any).other; |
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
14949
diff
changeset
|
167 |
MethodSymbol m = this.other; |
10 | 168 |
return |
169 |
o.name == m.name && |
|
170 |
o.owner == m.owner && |
|
15564
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
14949
diff
changeset
|
171 |
((Method)any).uniqueType.equals(uniqueType); |
10 | 172 |
} |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
173 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 174 |
public int hashCode() { |
15564
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
14949
diff
changeset
|
175 |
MethodSymbol m = this.other; |
10 | 176 |
return |
177 |
m.name.hashCode() * 33 + |
|
178 |
m.owner.hashCode() * 9 + |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
179 |
uniqueType.hashCode(); |
10 | 180 |
} |
181 |
} |
|
182 |
||
14547 | 183 |
static class DynamicMethod extends Method { |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
184 |
public Object[] uniqueStaticArgs; |
14547 | 185 |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
186 |
DynamicMethod(DynamicMethodSymbol m, Types types) { |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
187 |
super(m, types); |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
188 |
uniqueStaticArgs = getUniqueTypeArray(m.staticArgs, types); |
14547 | 189 |
} |
190 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
191 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
15564
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
14949
diff
changeset
|
192 |
public boolean equals(Object any) { |
32334
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
193 |
return equalsImpl(any, true); |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
194 |
} |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
195 |
|
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
196 |
protected boolean equalsImpl(Object any, boolean includeDynamicArgs) { |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
197 |
if (includeDynamicArgs && !super.equals(any)) return false; |
15564
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
14949
diff
changeset
|
198 |
if (!(any instanceof DynamicMethod)) return false; |
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
14949
diff
changeset
|
199 |
DynamicMethodSymbol dm1 = (DynamicMethodSymbol)other; |
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
14949
diff
changeset
|
200 |
DynamicMethodSymbol dm2 = (DynamicMethodSymbol)((DynamicMethod)any).other; |
14547 | 201 |
return dm1.bsm == dm2.bsm && |
202 |
dm1.bsmKind == dm2.bsmKind && |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
203 |
Arrays.equals(uniqueStaticArgs, |
15564
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
14949
diff
changeset
|
204 |
((DynamicMethod)any).uniqueStaticArgs); |
14547 | 205 |
} |
206 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
207 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
14547 | 208 |
public int hashCode() { |
32334
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
209 |
return hashCodeImpl(true); |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
210 |
} |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
211 |
|
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
212 |
protected int hashCodeImpl(boolean includeDynamicArgs) { |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
213 |
int hash = includeDynamicArgs ? super.hashCode() : 0; |
15564
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
14949
diff
changeset
|
214 |
DynamicMethodSymbol dm = (DynamicMethodSymbol)other; |
14547 | 215 |
hash += dm.bsmKind * 7 + |
216 |
dm.bsm.hashCode() * 11; |
|
217 |
for (int i = 0; i < dm.staticArgs.length; i++) { |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
218 |
hash += (uniqueStaticArgs[i].hashCode() * 23); |
14547 | 219 |
} |
220 |
return hash; |
|
221 |
} |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
222 |
|
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
223 |
private Object[] getUniqueTypeArray(Object[] objects, Types types) { |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
224 |
Object[] result = new Object[objects.length]; |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
225 |
for (int i = 0; i < objects.length; i++) { |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
226 |
if (objects[i] instanceof Type) { |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
227 |
result[i] = new UniqueType((Type)objects[i], types); |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
228 |
} else { |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
229 |
result[i] = objects[i]; |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
230 |
} |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
231 |
} |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
232 |
return result; |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
233 |
} |
32334
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
234 |
|
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
235 |
static class BootstrapMethodsKey extends DynamicMethod { |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
236 |
BootstrapMethodsKey(DynamicMethodSymbol m, Types types) { |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
237 |
super(m, types); |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
238 |
} |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
239 |
|
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
240 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
241 |
public boolean equals(Object any) { |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
242 |
return equalsImpl(any, false); |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
243 |
} |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
244 |
|
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
245 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
246 |
public int hashCode() { |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
247 |
return hashCodeImpl(false); |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
248 |
} |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
249 |
|
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
250 |
Object[] getUniqueArgs() { |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
251 |
return uniqueStaticArgs; |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
252 |
} |
fd65e32e16b3
8129547: Excess entries in BootstrapMethods with the same (bsm, bsmKind, bsmStaticArgs), but different dynamicArgs
mcimadamore
parents:
27224
diff
changeset
|
253 |
} |
32336
9e9acf7f26a4
8134329: TeeOpTest.java fails across platforms after fix for JDK-8129547
mcimadamore
parents:
32334
diff
changeset
|
254 |
|
9e9acf7f26a4
8134329: TeeOpTest.java fails across platforms after fix for JDK-8129547
mcimadamore
parents:
32334
diff
changeset
|
255 |
static class BootstrapMethodsValue { |
9e9acf7f26a4
8134329: TeeOpTest.java fails across platforms after fix for JDK-8129547
mcimadamore
parents:
32334
diff
changeset
|
256 |
final MethodHandle mh; |
9e9acf7f26a4
8134329: TeeOpTest.java fails across platforms after fix for JDK-8129547
mcimadamore
parents:
32334
diff
changeset
|
257 |
final int index; |
9e9acf7f26a4
8134329: TeeOpTest.java fails across platforms after fix for JDK-8129547
mcimadamore
parents:
32334
diff
changeset
|
258 |
|
9e9acf7f26a4
8134329: TeeOpTest.java fails across platforms after fix for JDK-8129547
mcimadamore
parents:
32334
diff
changeset
|
259 |
public BootstrapMethodsValue(MethodHandle mh, int index) { |
9e9acf7f26a4
8134329: TeeOpTest.java fails across platforms after fix for JDK-8129547
mcimadamore
parents:
32334
diff
changeset
|
260 |
this.mh = mh; |
9e9acf7f26a4
8134329: TeeOpTest.java fails across platforms after fix for JDK-8129547
mcimadamore
parents:
32334
diff
changeset
|
261 |
this.index = index; |
9e9acf7f26a4
8134329: TeeOpTest.java fails across platforms after fix for JDK-8129547
mcimadamore
parents:
32334
diff
changeset
|
262 |
} |
9e9acf7f26a4
8134329: TeeOpTest.java fails across platforms after fix for JDK-8129547
mcimadamore
parents:
32334
diff
changeset
|
263 |
} |
14547 | 264 |
} |
265 |
||
15564
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
14949
diff
changeset
|
266 |
static class Variable extends DelegatedSymbol<VarSymbol> { |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
267 |
UniqueType uniqueType; |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
268 |
Variable(VarSymbol v, Types types) { |
10 | 269 |
super(v); |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
270 |
this.uniqueType = new UniqueType(v.type, types); |
10 | 271 |
} |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
272 |
@DefinedBy(Api.LANGUAGE_MODEL) |
15564
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
14949
diff
changeset
|
273 |
public boolean equals(Object any) { |
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
14949
diff
changeset
|
274 |
if (!(any instanceof Variable)) return false; |
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
14949
diff
changeset
|
275 |
VarSymbol o = ((Variable)any).other; |
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
14949
diff
changeset
|
276 |
VarSymbol v = other; |
10 | 277 |
return |
278 |
o.name == v.name && |
|
279 |
o.owner == v.owner && |
|
15564
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
14949
diff
changeset
|
280 |
((Variable)any).uniqueType.equals(uniqueType); |
10 | 281 |
} |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
282 |
@DefinedBy(Api.LANGUAGE_MODEL) |
10 | 283 |
public int hashCode() { |
15564
6d8db91563a7
8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents:
14949
diff
changeset
|
284 |
VarSymbol v = other; |
10 | 285 |
return |
286 |
v.name.hashCode() * 33 + |
|
287 |
v.owner.hashCode() * 9 + |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
288 |
uniqueType.hashCode(); |
10 | 289 |
} |
290 |
} |
|
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
291 |
|
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
292 |
public static class MethodHandle { |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
293 |
|
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
294 |
/** Reference kind - see ClassFile */ |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
295 |
int refKind; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
296 |
|
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
297 |
/** Reference symbol */ |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
298 |
Symbol refSym; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
299 |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
300 |
UniqueType uniqueType; |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
301 |
|
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
302 |
public MethodHandle(int refKind, Symbol refSym, Types types) { |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
303 |
this.refKind = refKind; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
304 |
this.refSym = refSym; |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
305 |
this.uniqueType = new UniqueType(this.refSym.type, types); |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
306 |
checkConsistent(); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
307 |
} |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
308 |
public boolean equals(Object other) { |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
309 |
if (!(other instanceof MethodHandle)) return false; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
310 |
MethodHandle mr = (MethodHandle) other; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
311 |
if (mr.refKind != refKind) return false; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
312 |
Symbol o = mr.refSym; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
313 |
return |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
314 |
o.name == refSym.name && |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
315 |
o.owner == refSym.owner && |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
316 |
((MethodHandle)other).uniqueType.equals(uniqueType); |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
317 |
} |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
318 |
public int hashCode() { |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
319 |
return |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
320 |
refKind * 65 + |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
321 |
refSym.name.hashCode() * 33 + |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
322 |
refSym.owner.hashCode() * 9 + |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
323 |
uniqueType.hashCode(); |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
324 |
} |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
325 |
|
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
326 |
/** |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
327 |
* Check consistency of reference kind and symbol (see JVMS 4.4.8) |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
328 |
*/ |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
329 |
@SuppressWarnings("fallthrough") |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
330 |
private void checkConsistent() { |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
331 |
boolean staticOk = false; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26266
diff
changeset
|
332 |
Kind expectedKind = null; |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
333 |
Filter<Name> nameFilter = nonInitFilter; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
334 |
boolean interfaceOwner = false; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
335 |
switch (refKind) { |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
336 |
case ClassFile.REF_getStatic: |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
337 |
case ClassFile.REF_putStatic: |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
338 |
staticOk = true; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
339 |
case ClassFile.REF_getField: |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
340 |
case ClassFile.REF_putField: |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26266
diff
changeset
|
341 |
expectedKind = VAR; |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
342 |
break; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
343 |
case ClassFile.REF_newInvokeSpecial: |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
344 |
nameFilter = initFilter; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26266
diff
changeset
|
345 |
expectedKind = MTH; |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
346 |
break; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
347 |
case ClassFile.REF_invokeInterface: |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
348 |
interfaceOwner = true; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26266
diff
changeset
|
349 |
expectedKind = MTH; |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
350 |
break; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
351 |
case ClassFile.REF_invokeStatic: |
16330
66e277848a69
8009299: Javac crashes when compiling method reference to static interface method
mcimadamore
parents:
15564
diff
changeset
|
352 |
interfaceOwner = true; |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
353 |
staticOk = true; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
354 |
case ClassFile.REF_invokeVirtual: |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26266
diff
changeset
|
355 |
expectedKind = MTH; |
21014
57913337d634
8012557: Implement lambda methods on interfaces as private
rfield
parents:
16330
diff
changeset
|
356 |
break; |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
357 |
case ClassFile.REF_invokeSpecial: |
21014
57913337d634
8012557: Implement lambda methods on interfaces as private
rfield
parents:
16330
diff
changeset
|
358 |
interfaceOwner = true; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26266
diff
changeset
|
359 |
expectedKind = MTH; |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
360 |
break; |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
361 |
} |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
362 |
Assert.check(!refSym.isStatic() || staticOk); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
363 |
Assert.check(refSym.kind == expectedKind); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
364 |
Assert.check(nameFilter.accepts(refSym.name)); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
365 |
Assert.check(!refSym.owner.isInterface() || interfaceOwner); |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
366 |
} |
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
367 |
//where |
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
32336
diff
changeset
|
368 |
Filter<Name> nonInitFilter = n -> (n != n.table.names.init && n != n.table.names.clinit); |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
369 |
|
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
32336
diff
changeset
|
370 |
Filter<Name> initFilter = n -> n == n.table.names.init; |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
5847
diff
changeset
|
371 |
} |
10 | 372 |
} |