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

Varming/5.1 #11

Merged
merged 17 commits into from
Jul 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ This makes it easy to see how our fork differs from the official release.

## Current Version

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)):
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)):

```
Version 5.0.4, SVN r1779, tags/ASM_5_0_4
Version 5.1, SVN r1798, tags/ASM_5_1
```

Previous ASM Upgrade PR: https://github.com/scala/scala-asm/pull/5
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/scala/tools/asm/ClassReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2496,11 +2496,12 @@ public Object readConst(final int item, final char[] buf) {
int tag = readByte(index);
int[] items = this.items;
int cpIndex = items[readUnsignedShort(index + 1)];
boolean itf = b[cpIndex - 1] == ClassWriter.IMETH;
String owner = readClass(cpIndex, buf);
cpIndex = items[readUnsignedShort(cpIndex + 2)];
String name = readUTF8(cpIndex, buf);
String desc = readUTF8(cpIndex + 2, buf);
return new Handle(tag, owner, name, desc);
return new Handle(tag, owner, name, desc, itf);
}
}
}
47 changes: 41 additions & 6 deletions src/main/java/scala/tools/asm/ClassWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ Item newConstItem(final Object cst) {
}
} else if (cst instanceof Handle) {
Handle h = (Handle) cst;
return newHandleItem(h.tag, h.owner, h.name, h.desc);
return newHandleItem(h.tag, h.owner, h.name, h.desc, h.itf);
} else {
throw new IllegalArgumentException("value " + cst);
}
Expand Down Expand Up @@ -1187,10 +1187,12 @@ public int newMethodType(final String methodDesc) {
* the name of the field or method.
* @param desc
* the descriptor of the field or method.
* @param itf
* true if the owner is an interface.
* @return a new or an already existing method type reference item.
*/
Item newHandleItem(final int tag, final String owner, final String name,
final String desc) {
final String desc, final boolean itf) {
key4.set(HANDLE_BASE + tag, owner, name, desc);
Item result = get(key4);
if (result == null) {
Expand All @@ -1199,8 +1201,7 @@ Item newHandleItem(final int tag, final String owner, final String name,
} else {
put112(HANDLE,
tag,
newMethod(owner, name, desc,
tag == Opcodes.H_INVOKEINTERFACE));
newMethod(owner, name, desc, itf));
}
result = new Item(index++, key4);
put(result);
Expand Down Expand Up @@ -1230,10 +1231,44 @@ Item newHandleItem(final int tag, final String owner, final String name,
* the descriptor of the field or method.
* @return the index of a new or already existing method type reference
* item.
*
* @deprecated this method is superseded by
* {@link #newHandle(int, String, String, String, boolean)}.
*/
@Deprecated
public int newHandle(final int tag, final String owner, final String name,
final String desc) {
return newHandleItem(tag, owner, name, desc).index;
return newHandle(tag, owner, name, desc, tag == Opcodes.H_INVOKEINTERFACE);
}

/**
* Adds a handle to the constant pool of the class being build. Does nothing
* if the constant pool already contains a similar item. <i>This method is
* intended for {@link Attribute} sub classes, and is normally not needed by
* class generators or adapters.</i>
*
* @param tag
* the kind of this handle. Must be {@link Opcodes#H_GETFIELD},
* {@link Opcodes#H_GETSTATIC}, {@link Opcodes#H_PUTFIELD},
* {@link Opcodes#H_PUTSTATIC}, {@link Opcodes#H_INVOKEVIRTUAL},
* {@link Opcodes#H_INVOKESTATIC},
* {@link Opcodes#H_INVOKESPECIAL},
* {@link Opcodes#H_NEWINVOKESPECIAL} or
* {@link Opcodes#H_INVOKEINTERFACE}.
* @param owner
* the internal name of the field or method owner class.
* @param name
* the name of the field or method.
* @param desc
* the descriptor of the field or method.
* @param itf
* true if the owner is an interface.
* @return the index of a new or already existing method type reference
* item.
*/
public int newHandle(final int tag, final String owner, final String name,
final String desc, final boolean itf) {
return newHandleItem(tag, owner, name, desc, itf).index;
}

/**
Expand Down Expand Up @@ -1265,7 +1300,7 @@ Item newInvokeDynamicItem(final String name, final String desc,

int hashCode = bsm.hashCode();
bootstrapMethods.putShort(newHandle(bsm.tag, bsm.owner, bsm.name,
bsm.desc));
bsm.desc, bsm.isInterface()));

int argsLength = bsmArgs.length;
bootstrapMethods.putShort(argsLength);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/scala/tools/asm/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,4 @@ class Context {
* The stack values of the latest stack map frame that has been parsed.
*/
Object[] stack;
}
}
60 changes: 56 additions & 4 deletions src/main/java/scala/tools/asm/Handle.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public final class Handle {
*/
final String desc;


/**
* Indicate if the owner is an interface or not.
*/
final boolean itf;

/**
* Constructs a new field or method handle.
*
Expand All @@ -84,12 +90,44 @@ public final class Handle {
* @param desc
* the descriptor of the field or method designated by this
* handle.
*
* @deprecated this constructor has been superseded
* by {@link #Handle(int, String, String, String, boolean)}.
*/
@Deprecated
public Handle(int tag, String owner, String name, String desc) {
this(tag, owner, name, desc, tag == Opcodes.H_INVOKEINTERFACE);
}

/**
* Constructs a new field or method handle.
*
* @param tag
* the kind of field or method designated by this Handle. Must be
* {@link Opcodes#H_GETFIELD}, {@link Opcodes#H_GETSTATIC},
* {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC},
* {@link Opcodes#H_INVOKEVIRTUAL},
* {@link Opcodes#H_INVOKESTATIC},
* {@link Opcodes#H_INVOKESPECIAL},
* {@link Opcodes#H_NEWINVOKESPECIAL} or
* {@link Opcodes#H_INVOKEINTERFACE}.
* @param owner
* the internal name of the class that owns the field or method
* designated by this handle.
* @param name
* the name of the field or method designated by this handle.
* @param desc
* the descriptor of the field or method designated by this
* handle.
* @param itf
* true if the owner is an interface.
*/
public Handle(int tag, String owner, String name, String desc, boolean itf) {
this.tag = tag;
this.owner = owner;
this.name = name;
this.desc = desc;
this.itf = itf;
}

/**
Expand Down Expand Up @@ -135,6 +173,17 @@ public String getDesc() {
return desc;
}

/**
* Returns true if the owner of the field or method designated
* by this handle is an interface.
*
* @return true if the owner of the field or method designated
* by this handle is an interface.
*/
public boolean isInterface() {
return itf;
}

@Override
public boolean equals(Object obj) {
if (obj == this) {
Expand All @@ -144,27 +193,30 @@ public boolean equals(Object obj) {
return false;
}
Handle h = (Handle) obj;
return tag == h.tag && owner.equals(h.owner) && name.equals(h.name)
&& desc.equals(h.desc);
return tag == h.tag && itf == h.itf && owner.equals(h.owner)
&& name.equals(h.name) && desc.equals(h.desc);
}

@Override
public int hashCode() {
return tag + owner.hashCode() * name.hashCode() * desc.hashCode();
return tag + (itf? 64: 0) + owner.hashCode() * name.hashCode() * desc.hashCode();
}

/**
* Returns the textual representation of this handle. The textual
* representation is:
*
* <pre>
* for a reference to a class:
* owner '.' name desc ' ' '(' tag ')'
* for a reference to an interface:
* owner '.' name desc ' ' '(' tag ' ' itf ')'
* </pre>
*
* . As this format is unambiguous, it can be parsed if necessary.
*/
@Override
public String toString() {
return owner + '.' + name + desc + " (" + tag + ')';
return owner + '.' + name + desc + " (" + tag + (itf? " itf": "") + ')';
}
}
2 changes: 1 addition & 1 deletion src/main/java/scala/tools/asm/MethodWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2040,7 +2040,7 @@ final int getSize() {
}
int size = 8;
if (code.length > 0) {
if (code.length > 65536) {
if (code.length > 65535) {
String nameString = "";
Item nameItem = cw.findItemByIndex(name);
if (nameItem != null) nameString = nameItem.strVal1 +"'s ";
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/scala/tools/asm/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ public int getArgumentsAndReturnSizes() {
* @return the descriptor corresponding to this Java type.
*/
public String getDescriptor() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
getDescriptor(buf);
return buf.toString();
}
Expand All @@ -643,7 +643,7 @@ public String getDescriptor() {
*/
public static String getMethodDescriptor(final Type returnType,
final Type... argumentTypes) {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append('(');
for (int i = 0; i < argumentTypes.length; ++i) {
argumentTypes[i].getDescriptor(buf);
Expand All @@ -660,7 +660,7 @@ public static String getMethodDescriptor(final Type returnType,
* @param buf
* the string buffer to which the descriptor must be appended.
*/
private void getDescriptor(final StringBuffer buf) {
private void getDescriptor(final StringBuilder buf) {
if (this.buf == null) {
// descriptor is in byte 3 of 'off' for primitive types (buf ==
// null)
Expand Down Expand Up @@ -700,7 +700,7 @@ public static String getInternalName(final Class<?> c) {
* @return the descriptor corresponding to the given class.
*/
public static String getDescriptor(final Class<?> c) {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
getDescriptor(buf, c);
return buf.toString();
}
Expand All @@ -714,7 +714,7 @@ public static String getDescriptor(final Class<?> c) {
*/
public static String getConstructorDescriptor(final Constructor<?> c) {
Class<?>[] parameters = c.getParameterTypes();
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append('(');
for (int i = 0; i < parameters.length; ++i) {
getDescriptor(buf, parameters[i]);
Expand All @@ -731,7 +731,7 @@ public static String getConstructorDescriptor(final Constructor<?> c) {
*/
public static String getMethodDescriptor(final Method m) {
Class<?>[] parameters = m.getParameterTypes();
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append('(');
for (int i = 0; i < parameters.length; ++i) {
getDescriptor(buf, parameters[i]);
Expand All @@ -749,7 +749,7 @@ public static String getMethodDescriptor(final Method m) {
* @param c
* the class whose descriptor must be computed.
*/
private static void getDescriptor(final StringBuffer buf, final Class<?> c) {
private static void getDescriptor(final StringBuilder buf, final Class<?> c) {
Class<?> d = c;
while (true) {
if (d.isPrimitive()) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/scala/tools/asm/signature/SignatureWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
public class SignatureWriter extends SignatureVisitor {

/**
* Buffer used to construct the signature.
* Builder used to construct the signature.
*/
private final StringBuffer buf = new StringBuffer();
private final StringBuilder buf = new StringBuilder();

/**
* Indicates if the signature contains formal type parameters.
Expand Down Expand Up @@ -224,4 +224,4 @@ private void endArguments() {
}
argumentStack /= 2;
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/scala/tools/asm/tree/IincInsnNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ public void accept(final MethodVisitor mv) {
public AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels) {
return new IincInsnNode(var, incr).cloneAnnotations(this);
}
}
}
23 changes: 20 additions & 3 deletions src/main/java/scala/tools/asm/tree/InsnList.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ public ListIterator<AbstractInsnNode> iterator() {
/**
* Returns an iterator over the instructions in this list.
*
* @param index
* index of instruction for the iterator to start at
*
* @return an iterator over the instructions in this list.
*/
@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -610,14 +613,28 @@ public int previousIndex() {
}

public void add(Object o) {
InsnList.this.insertBefore(next, (AbstractInsnNode) o);
if (next != null) {
InsnList.this.insertBefore(next, (AbstractInsnNode) o);
} else if (prev != null) {
InsnList.this.insert(prev, (AbstractInsnNode) o);
} else {
InsnList.this.add((AbstractInsnNode) o);
}
prev = (AbstractInsnNode) o;
remove = null;
}

public void set(Object o) {
InsnList.this.set(next.prev, (AbstractInsnNode) o);
prev = (AbstractInsnNode) o;
if (remove != null) {
InsnList.this.set(remove, (AbstractInsnNode) o);
if (remove == prev) {
prev = (AbstractInsnNode) o;
} else {
next = (AbstractInsnNode) o;
}
} else {
throw new IllegalStateException();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ public AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels) {
return new InvokeDynamicInsnNode(name, desc, bsm, bsmArgs)
.cloneAnnotations(this);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/scala/tools/asm/tree/LabelNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ public AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels) {
public void resetLabel() {
label = null;
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/scala/tools/asm/tree/LdcInsnNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ public void accept(final MethodVisitor mv) {
public AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels) {
return new LdcInsnNode(cst).cloneAnnotations(this);
}
}
}
Loading