Skip to content
This repository was archived by the owner on Feb 23, 2018. It is now read-only.

Commit e5c39e5

Browse files
authored
Merge pull request #11 from varming/varming/5.1
Varming/5.1
2 parents e7851a4 + 450a410 commit e5c39e5

23 files changed

+862
-136
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ This makes it easy to see how our fork differs from the official release.
1919

2020
## Current Version
2121

22-
The current sources are based on the following version of ASM ([browse tags here](http://websvn.ow2.org/listing.php?repname=asm&path=%2Ftags%2F&peg=1748)):
22+
The current sources are based on the following version of ASM ([browse tags here](http://websvn.ow2.org/listing.php?repname=asm&path=%2Ftags%2F)):
2323

2424
```
25-
Version 5.0.4, SVN r1779, tags/ASM_5_0_4
25+
Version 5.1, SVN r1798, tags/ASM_5_1
2626
```
2727

2828
Previous ASM Upgrade PR: https://github.com/scala/scala-asm/pull/5

src/main/java/scala/tools/asm/ClassReader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2496,11 +2496,12 @@ public Object readConst(final int item, final char[] buf) {
24962496
int tag = readByte(index);
24972497
int[] items = this.items;
24982498
int cpIndex = items[readUnsignedShort(index + 1)];
2499+
boolean itf = b[cpIndex - 1] == ClassWriter.IMETH;
24992500
String owner = readClass(cpIndex, buf);
25002501
cpIndex = items[readUnsignedShort(cpIndex + 2)];
25012502
String name = readUTF8(cpIndex, buf);
25022503
String desc = readUTF8(cpIndex + 2, buf);
2503-
return new Handle(tag, owner, name, desc);
2504+
return new Handle(tag, owner, name, desc, itf);
25042505
}
25052506
}
25062507
}

src/main/java/scala/tools/asm/ClassWriter.java

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ Item newConstItem(final Object cst) {
10521052
}
10531053
} else if (cst instanceof Handle) {
10541054
Handle h = (Handle) cst;
1055-
return newHandleItem(h.tag, h.owner, h.name, h.desc);
1055+
return newHandleItem(h.tag, h.owner, h.name, h.desc, h.itf);
10561056
} else {
10571057
throw new IllegalArgumentException("value " + cst);
10581058
}
@@ -1187,10 +1187,12 @@ public int newMethodType(final String methodDesc) {
11871187
* the name of the field or method.
11881188
* @param desc
11891189
* the descriptor of the field or method.
1190+
* @param itf
1191+
* true if the owner is an interface.
11901192
* @return a new or an already existing method type reference item.
11911193
*/
11921194
Item newHandleItem(final int tag, final String owner, final String name,
1193-
final String desc) {
1195+
final String desc, final boolean itf) {
11941196
key4.set(HANDLE_BASE + tag, owner, name, desc);
11951197
Item result = get(key4);
11961198
if (result == null) {
@@ -1199,8 +1201,7 @@ Item newHandleItem(final int tag, final String owner, final String name,
11991201
} else {
12001202
put112(HANDLE,
12011203
tag,
1202-
newMethod(owner, name, desc,
1203-
tag == Opcodes.H_INVOKEINTERFACE));
1204+
newMethod(owner, name, desc, itf));
12041205
}
12051206
result = new Item(index++, key4);
12061207
put(result);
@@ -1230,10 +1231,44 @@ Item newHandleItem(final int tag, final String owner, final String name,
12301231
* the descriptor of the field or method.
12311232
* @return the index of a new or already existing method type reference
12321233
* item.
1234+
*
1235+
* @deprecated this method is superseded by
1236+
* {@link #newHandle(int, String, String, String, boolean)}.
12331237
*/
1238+
@Deprecated
12341239
public int newHandle(final int tag, final String owner, final String name,
12351240
final String desc) {
1236-
return newHandleItem(tag, owner, name, desc).index;
1241+
return newHandle(tag, owner, name, desc, tag == Opcodes.H_INVOKEINTERFACE);
1242+
}
1243+
1244+
/**
1245+
* Adds a handle to the constant pool of the class being build. Does nothing
1246+
* if the constant pool already contains a similar item. <i>This method is
1247+
* intended for {@link Attribute} sub classes, and is normally not needed by
1248+
* class generators or adapters.</i>
1249+
*
1250+
* @param tag
1251+
* the kind of this handle. Must be {@link Opcodes#H_GETFIELD},
1252+
* {@link Opcodes#H_GETSTATIC}, {@link Opcodes#H_PUTFIELD},
1253+
* {@link Opcodes#H_PUTSTATIC}, {@link Opcodes#H_INVOKEVIRTUAL},
1254+
* {@link Opcodes#H_INVOKESTATIC},
1255+
* {@link Opcodes#H_INVOKESPECIAL},
1256+
* {@link Opcodes#H_NEWINVOKESPECIAL} or
1257+
* {@link Opcodes#H_INVOKEINTERFACE}.
1258+
* @param owner
1259+
* the internal name of the field or method owner class.
1260+
* @param name
1261+
* the name of the field or method.
1262+
* @param desc
1263+
* the descriptor of the field or method.
1264+
* @param itf
1265+
* true if the owner is an interface.
1266+
* @return the index of a new or already existing method type reference
1267+
* item.
1268+
*/
1269+
public int newHandle(final int tag, final String owner, final String name,
1270+
final String desc, final boolean itf) {
1271+
return newHandleItem(tag, owner, name, desc, itf).index;
12371272
}
12381273

12391274
/**
@@ -1265,7 +1300,7 @@ Item newInvokeDynamicItem(final String name, final String desc,
12651300

12661301
int hashCode = bsm.hashCode();
12671302
bootstrapMethods.putShort(newHandle(bsm.tag, bsm.owner, bsm.name,
1268-
bsm.desc));
1303+
bsm.desc, bsm.isInterface()));
12691304

12701305
int argsLength = bsmArgs.length;
12711306
bootstrapMethods.putShort(argsLength);

src/main/java/scala/tools/asm/Context.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,4 @@ class Context {
142142
* The stack values of the latest stack map frame that has been parsed.
143143
*/
144144
Object[] stack;
145-
}
145+
}

src/main/java/scala/tools/asm/Handle.java

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ public final class Handle {
6464
*/
6565
final String desc;
6666

67+
68+
/**
69+
* Indicate if the owner is an interface or not.
70+
*/
71+
final boolean itf;
72+
6773
/**
6874
* Constructs a new field or method handle.
6975
*
@@ -84,12 +90,44 @@ public final class Handle {
8490
* @param desc
8591
* the descriptor of the field or method designated by this
8692
* handle.
93+
*
94+
* @deprecated this constructor has been superseded
95+
* by {@link #Handle(int, String, String, String, boolean)}.
8796
*/
97+
@Deprecated
8898
public Handle(int tag, String owner, String name, String desc) {
99+
this(tag, owner, name, desc, tag == Opcodes.H_INVOKEINTERFACE);
100+
}
101+
102+
/**
103+
* Constructs a new field or method handle.
104+
*
105+
* @param tag
106+
* the kind of field or method designated by this Handle. Must be
107+
* {@link Opcodes#H_GETFIELD}, {@link Opcodes#H_GETSTATIC},
108+
* {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC},
109+
* {@link Opcodes#H_INVOKEVIRTUAL},
110+
* {@link Opcodes#H_INVOKESTATIC},
111+
* {@link Opcodes#H_INVOKESPECIAL},
112+
* {@link Opcodes#H_NEWINVOKESPECIAL} or
113+
* {@link Opcodes#H_INVOKEINTERFACE}.
114+
* @param owner
115+
* the internal name of the class that owns the field or method
116+
* designated by this handle.
117+
* @param name
118+
* the name of the field or method designated by this handle.
119+
* @param desc
120+
* the descriptor of the field or method designated by this
121+
* handle.
122+
* @param itf
123+
* true if the owner is an interface.
124+
*/
125+
public Handle(int tag, String owner, String name, String desc, boolean itf) {
89126
this.tag = tag;
90127
this.owner = owner;
91128
this.name = name;
92129
this.desc = desc;
130+
this.itf = itf;
93131
}
94132

95133
/**
@@ -135,6 +173,17 @@ public String getDesc() {
135173
return desc;
136174
}
137175

176+
/**
177+
* Returns true if the owner of the field or method designated
178+
* by this handle is an interface.
179+
*
180+
* @return true if the owner of the field or method designated
181+
* by this handle is an interface.
182+
*/
183+
public boolean isInterface() {
184+
return itf;
185+
}
186+
138187
@Override
139188
public boolean equals(Object obj) {
140189
if (obj == this) {
@@ -144,27 +193,30 @@ public boolean equals(Object obj) {
144193
return false;
145194
}
146195
Handle h = (Handle) obj;
147-
return tag == h.tag && owner.equals(h.owner) && name.equals(h.name)
148-
&& desc.equals(h.desc);
196+
return tag == h.tag && itf == h.itf && owner.equals(h.owner)
197+
&& name.equals(h.name) && desc.equals(h.desc);
149198
}
150199

151200
@Override
152201
public int hashCode() {
153-
return tag + owner.hashCode() * name.hashCode() * desc.hashCode();
202+
return tag + (itf? 64: 0) + owner.hashCode() * name.hashCode() * desc.hashCode();
154203
}
155204

156205
/**
157206
* Returns the textual representation of this handle. The textual
158207
* representation is:
159208
*
160209
* <pre>
210+
* for a reference to a class:
161211
* owner '.' name desc ' ' '(' tag ')'
212+
* for a reference to an interface:
213+
* owner '.' name desc ' ' '(' tag ' ' itf ')'
162214
* </pre>
163215
*
164216
* . As this format is unambiguous, it can be parsed if necessary.
165217
*/
166218
@Override
167219
public String toString() {
168-
return owner + '.' + name + desc + " (" + tag + ')';
220+
return owner + '.' + name + desc + " (" + tag + (itf? " itf": "") + ')';
169221
}
170222
}

src/main/java/scala/tools/asm/MethodWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2040,7 +2040,7 @@ final int getSize() {
20402040
}
20412041
int size = 8;
20422042
if (code.length > 0) {
2043-
if (code.length > 65536) {
2043+
if (code.length > 65535) {
20442044
String nameString = "";
20452045
Item nameItem = cw.findItemByIndex(name);
20462046
if (nameItem != null) nameString = nameItem.strVal1 +"'s ";

src/main/java/scala/tools/asm/Type.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ public int getArgumentsAndReturnSizes() {
625625
* @return the descriptor corresponding to this Java type.
626626
*/
627627
public String getDescriptor() {
628-
StringBuffer buf = new StringBuffer();
628+
StringBuilder buf = new StringBuilder();
629629
getDescriptor(buf);
630630
return buf.toString();
631631
}
@@ -643,7 +643,7 @@ public String getDescriptor() {
643643
*/
644644
public static String getMethodDescriptor(final Type returnType,
645645
final Type... argumentTypes) {
646-
StringBuffer buf = new StringBuffer();
646+
StringBuilder buf = new StringBuilder();
647647
buf.append('(');
648648
for (int i = 0; i < argumentTypes.length; ++i) {
649649
argumentTypes[i].getDescriptor(buf);
@@ -660,7 +660,7 @@ public static String getMethodDescriptor(final Type returnType,
660660
* @param buf
661661
* the string buffer to which the descriptor must be appended.
662662
*/
663-
private void getDescriptor(final StringBuffer buf) {
663+
private void getDescriptor(final StringBuilder buf) {
664664
if (this.buf == null) {
665665
// descriptor is in byte 3 of 'off' for primitive types (buf ==
666666
// null)
@@ -700,7 +700,7 @@ public static String getInternalName(final Class<?> c) {
700700
* @return the descriptor corresponding to the given class.
701701
*/
702702
public static String getDescriptor(final Class<?> c) {
703-
StringBuffer buf = new StringBuffer();
703+
StringBuilder buf = new StringBuilder();
704704
getDescriptor(buf, c);
705705
return buf.toString();
706706
}
@@ -714,7 +714,7 @@ public static String getDescriptor(final Class<?> c) {
714714
*/
715715
public static String getConstructorDescriptor(final Constructor<?> c) {
716716
Class<?>[] parameters = c.getParameterTypes();
717-
StringBuffer buf = new StringBuffer();
717+
StringBuilder buf = new StringBuilder();
718718
buf.append('(');
719719
for (int i = 0; i < parameters.length; ++i) {
720720
getDescriptor(buf, parameters[i]);
@@ -731,7 +731,7 @@ public static String getConstructorDescriptor(final Constructor<?> c) {
731731
*/
732732
public static String getMethodDescriptor(final Method m) {
733733
Class<?>[] parameters = m.getParameterTypes();
734-
StringBuffer buf = new StringBuffer();
734+
StringBuilder buf = new StringBuilder();
735735
buf.append('(');
736736
for (int i = 0; i < parameters.length; ++i) {
737737
getDescriptor(buf, parameters[i]);
@@ -749,7 +749,7 @@ public static String getMethodDescriptor(final Method m) {
749749
* @param c
750750
* the class whose descriptor must be computed.
751751
*/
752-
private static void getDescriptor(final StringBuffer buf, final Class<?> c) {
752+
private static void getDescriptor(final StringBuilder buf, final Class<?> c) {
753753
Class<?> d = c;
754754
while (true) {
755755
if (d.isPrimitive()) {

src/main/java/scala/tools/asm/signature/SignatureWriter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
public class SignatureWriter extends SignatureVisitor {
4141

4242
/**
43-
* Buffer used to construct the signature.
43+
* Builder used to construct the signature.
4444
*/
45-
private final StringBuffer buf = new StringBuffer();
45+
private final StringBuilder buf = new StringBuilder();
4646

4747
/**
4848
* Indicates if the signature contains formal type parameters.
@@ -224,4 +224,4 @@ private void endArguments() {
224224
}
225225
argumentStack /= 2;
226226
}
227-
}
227+
}

src/main/java/scala/tools/asm/tree/IincInsnNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ public void accept(final MethodVisitor mv) {
8080
public AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels) {
8181
return new IincInsnNode(var, incr).cloneAnnotations(this);
8282
}
83-
}
83+
}

src/main/java/scala/tools/asm/tree/InsnList.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ public ListIterator<AbstractInsnNode> iterator() {
176176
/**
177177
* Returns an iterator over the instructions in this list.
178178
*
179+
* @param index
180+
* index of instruction for the iterator to start at
181+
*
179182
* @return an iterator over the instructions in this list.
180183
*/
181184
@SuppressWarnings("unchecked")
@@ -610,14 +613,28 @@ public int previousIndex() {
610613
}
611614

612615
public void add(Object o) {
613-
InsnList.this.insertBefore(next, (AbstractInsnNode) o);
616+
if (next != null) {
617+
InsnList.this.insertBefore(next, (AbstractInsnNode) o);
618+
} else if (prev != null) {
619+
InsnList.this.insert(prev, (AbstractInsnNode) o);
620+
} else {
621+
InsnList.this.add((AbstractInsnNode) o);
622+
}
614623
prev = (AbstractInsnNode) o;
615624
remove = null;
616625
}
617626

618627
public void set(Object o) {
619-
InsnList.this.set(next.prev, (AbstractInsnNode) o);
620-
prev = (AbstractInsnNode) o;
628+
if (remove != null) {
629+
InsnList.this.set(remove, (AbstractInsnNode) o);
630+
if (remove == prev) {
631+
prev = (AbstractInsnNode) o;
632+
} else {
633+
next = (AbstractInsnNode) o;
634+
}
635+
} else {
636+
throw new IllegalStateException();
637+
}
621638
}
622639
}
623640
}

src/main/java/scala/tools/asm/tree/InvokeDynamicInsnNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,4 @@ public AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels) {
9999
return new InvokeDynamicInsnNode(name, desc, bsm, bsmArgs)
100100
.cloneAnnotations(this);
101101
}
102-
}
102+
}

src/main/java/scala/tools/asm/tree/LabelNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,4 @@ public AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels) {
7575
public void resetLabel() {
7676
label = null;
7777
}
78-
}
78+
}

src/main/java/scala/tools/asm/tree/LdcInsnNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ public void accept(final MethodVisitor mv) {
7676
public AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels) {
7777
return new LdcInsnNode(cst).cloneAnnotations(this);
7878
}
79-
}
79+
}

0 commit comments

Comments
 (0)