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

Upgrade to ASM 5.0.4 #5

Merged
merged 13 commits into from
May 20, 2015
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
37 changes: 18 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ This makes it easy to see how our fork differs from the official release.
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)):

```
Version 5.0.3, SVN r1748, tags/ASM_5_0_3
Version 5.0.4, SVN r1779, tags/ASM_5_0_4
```

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

## Upgrading ASM

Start by deleting all source files and copy the ones from the latest ASM release.

The original ASM sources are in an SVN repository, which is mirrored here: https://github.com/lrytz/asm.
The original ASM sources are in an [SVN repository](http://forge.ow2.org/plugins/scmsvn/index.php?group_id=23), which is mirrored here: https://github.com/lrytz/asm.
You can use this mirror, your own git-svn mirror, or the original SVN repository to grab the sources of a new ASM version.
A description how to work with the git-svn clone is here: https://github.com/lrytz/asm/issues/1.

Expand All @@ -39,27 +41,24 @@ Excluded Files (don't copy):
* `org/objectweb/asm/optimizer`
* `org/objectweb/asm/xml`

*The below will change once a first is done in the new `scala/scala-asm` repository.*
*In the new repository, it probably makes sense to only squash the "Re-packaging and cosmetic changes".*
*The "actual changes" can then stay in the commit history.*

Check the commit history of `src/asm`: https://github.com/scala/scala/commits/2.11.x/src/asm.
Find the previous commit that upgraded ASM and take a look at its commit message.
It should be a squashed version of a pull request that shows the precise procedure how the last upgrade was made.
Take a look at the previous PR that upgraded ASM [(see above)](#current-version).
Follow the upgrade procedure in the same way.

Re-packaging and cosmetic changes:
The re-packaging and cleanup commits can be applied using the following commands:
* convert line endings (there are some `CRLF`)
`find src/asm/scala/tools/asm -name '*.java' | xargs dos2unix`
`find src -name '*.java' | xargs dos2unix`
* change package clauses
`find src/asm/scala/tools/asm -name '*.java' | xargs sed -i '' -e 's/package org\.objectweb\.asm/package scala.tools.asm/'`
`find src -name '*.java' | xargs sed -i '' -e 's/package org\.objectweb\.asm/package scala.tools.asm/'`
* update imports
`find src/asm/scala/tools/asm -name '*.java' | xargs sed -i '' -e 's/import org\.objectweb\.asm/import scala.tools.asm/'`
`find src -name '*.java' | xargs sed -i '' -e 's/import org\.objectweb\.asm/import scala.tools.asm/'`
* update `@links`, `@associates`
`find src/asm/scala/tools/asm -name '*.java' | xargs sed -i '' -e 's/@link org\.objectweb\.asm/@link scala.tools.asm/'`
`find src/asm/scala/tools/asm -name '*.java' | xargs sed -i '' -e 's/@associates org\.objectweb\.asm/@associates scala.tools.asm/'`
`find src -name '*.java' | xargs sed -i '' -e 's/@link org\.objectweb\.asm/@link scala.tools.asm/'`
`find src -name '*.java' | xargs sed -i '' -e 's/@associates org\.objectweb\.asm/@associates scala.tools.asm/'`
* remove trailing whitespace
`find src/asm/scala/tools/asm -name '*.java' | xargs sed -i '' -e 's/[ ]*$//'`
`find src -name '*.java' | xargs sed -i '' -e 's/[ ]*$//'`

Cherry-pick the actual changes that we have in our fork:
* Include the commits labelled `[asm-cherry-pick]` in the previous upgrade PR
* Include the changes to `src` that were added since the last upgrade, and label them `[asm-cherry-pick]`

Include the actual changes that we have in our repostiory
* Include the commits labelled `[asm-cherry-pick]` in the non-squashed PR of the previous upgrade
* Include the changes that were added to src/asm since the last upgrade and label them `[asm-cherry-pick]`
Update the ["Current Version"](#current-version) section of this README.
32 changes: 21 additions & 11 deletions src/main/java/scala/tools/asm/ClassReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,14 @@ private void readCode(final MethodVisitor mv, final Context context, int u) {
if (labels[label] == null) {
readLabel(label, labels).status |= Label.DEBUG;
}
labels[label].line = readUnsignedShort(v + 12);
Label l = labels[label];
while (l.line > 0) {
if (l.next == null) {
l.next = new Label();
}
l = l.next;
}
l.line = readUnsignedShort(v + 12);
v += 4;
}
}
Expand Down Expand Up @@ -1285,9 +1292,15 @@ private void readCode(final MethodVisitor mv, final Context context, int u) {
// visits the label and line number for this offset, if any
Label l = labels[offset];
if (l != null) {
Label next = l.next;
l.next = null;
mv.visitLabel(l);
if ((context.flags & SKIP_DEBUG) == 0 && l.line > 0) {
mv.visitLineNumber(l.line, l);
while (next != null) {
mv.visitLineNumber(next.line, l);
next = next.next;
}
}
}

Expand Down Expand Up @@ -1828,8 +1841,7 @@ private int readAnnotationValue(int v, final char[] buf, final String name,
v += 2;
break;
case 'B': // pointer to CONSTANT_Byte
av.visit(name,
new Byte((byte) readInt(items[readUnsignedShort(v)])));
av.visit(name, (byte) readInt(items[readUnsignedShort(v)]));
v += 2;
break;
case 'Z': // pointer to CONSTANT_Boolean
Expand All @@ -1839,13 +1851,11 @@ private int readAnnotationValue(int v, final char[] buf, final String name,
v += 2;
break;
case 'S': // pointer to CONSTANT_Short
av.visit(name, new Short(
(short) readInt(items[readUnsignedShort(v)])));
av.visit(name, (short) readInt(items[readUnsignedShort(v)]));
v += 2;
break;
case 'C': // pointer to CONSTANT_Char
av.visit(name, new Character(
(char) readInt(items[readUnsignedShort(v)])));
av.visit(name, (char) readInt(items[readUnsignedShort(v)]));
v += 2;
break;
case 's': // pointer to CONSTANT_Utf8
Expand Down Expand Up @@ -2469,13 +2479,13 @@ public Object readConst(final int item, final char[] buf) {
int index = items[item];
switch (b[index - 1]) {
case ClassWriter.INT:
return new Integer(readInt(index));
return readInt(index);
case ClassWriter.FLOAT:
return new Float(Float.intBitsToFloat(readInt(index)));
return Float.intBitsToFloat(readInt(index));
case ClassWriter.LONG:
return new Long(readLong(index));
return readLong(index);
case ClassWriter.DOUBLE:
return new Double(Double.longBitsToDouble(readLong(index)));
return Double.longBitsToDouble(readLong(index));
case ClassWriter.CLASS:
return Type.getObjectType(readUTF8(index, buf));
case ClassWriter.STR:
Expand Down
1 change: 1 addition & 0 deletions src/main/java/scala/tools/asm/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ void set(final double doubleVal) {
* @param strVal3
* third part of the value of this item.
*/
@SuppressWarnings("fallthrough")
void set(final int type, final String strVal1, final String strVal2,
final String strVal3) {
this.type = type;
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/scala/tools/asm/Label.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ public class Label {
int status;

/**
* The line number corresponding to this label, if known.
* The line number corresponding to this label, if known. If there are
* several lines, each line is stored in a separate label, all linked via
* their next field (these links are created in ClassReader and removed just
* before visitLabel is called, so that this does not impact the rest of the
* code).
*/
int line;

Expand Down Expand Up @@ -239,7 +243,8 @@ public class Label {
* The next basic block in the basic block stack. This stack is used in the
* main loop of the fix point algorithm used in the second step of the
* control flow analysis algorithms. It is also used in
* {@link #visitSubroutine} to avoid using a recursive method.
* {@link #visitSubroutine} to avoid using a recursive method, and in
* ClassReader to temporarily store multiple source lines for a label.
*
* @see MethodWriter#visitMaxs
*/
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/scala/tools/asm/MethodVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@
* A visitor to visit a Java method. The methods of this class must be called in
* the following order: ( <tt>visitParameter</tt> )* [
* <tt>visitAnnotationDefault</tt> ] ( <tt>visitAnnotation</tt> |
* <tt>visitTypeAnnotation</tt> | <tt>visitAttribute</tt> )* [
* <tt>visitCode</tt> ( <tt>visitFrame</tt> | <tt>visit<i>X</i>Insn</tt> |
* <tt>visitLabel</tt> | <tt>visitInsnAnnotation</tt> |
* <tt>visitTryCatchBlock</tt> | <tt>visitTryCatchBlockAnnotation</tt> |
* <tt>visitLocalVariable</tt> | <tt>visitLocalVariableAnnotation</tt> |
* <tt>visitLineNumber</tt> )* <tt>visitMaxs</tt> ] <tt>visitEnd</tt>. In
* addition, the <tt>visit<i>X</i>Insn</tt> and <tt>visitLabel</tt> methods must
* be called in the sequential order of the bytecode instructions of the visited
* code, <tt>visitInsnAnnotation</tt> must be called <i>after</i> the annotated
* <tt>visitParameterAnnotation</tt> <tt>visitTypeAnnotation</tt> |
* <tt>visitAttribute</tt> )* [ <tt>visitCode</tt> ( <tt>visitFrame</tt> |
* <tt>visit<i>X</i>Insn</tt> | <tt>visitLabel</tt> |
* <tt>visitInsnAnnotation</tt> | <tt>visitTryCatchBlock</tt> |
* <tt>visitTryCatchAnnotation</tt> | <tt>visitLocalVariable</tt> |
* <tt>visitLocalVariableAnnotation</tt> | <tt>visitLineNumber</tt> )*
* <tt>visitMaxs</tt> ] <tt>visitEnd</tt>. In addition, the
* <tt>visit<i>X</i>Insn</tt> and <tt>visitLabel</tt> methods must be called in
* the sequential order of the bytecode instructions of the visited code,
* <tt>visitInsnAnnotation</tt> must be called <i>after</i> the annotated
* instruction, <tt>visitTryCatchBlock</tt> must be called <i>before</i> the
* labels passed as arguments have been visited,
* <tt>visitTryCatchBlockAnnotation</tt> must be called <i>after</i> the
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/scala/tools/asm/MethodWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2717,11 +2717,13 @@ private void resizeInstructions() {
l = l.successor;
}
// Update the offsets in the uninitialized types
for (i = 0; i < cw.typeTable.length; ++i) {
Item item = cw.typeTable[i];
if (item != null && item.type == ClassWriter.TYPE_UNINIT) {
item.intVal = getNewOffset(allIndexes, allSizes, 0,
item.intVal);
if (cw.typeTable != null) {
for (i = 0; i < cw.typeTable.length; ++i) {
Item item = cw.typeTable[i];
if (item != null && item.type == ClassWriter.TYPE_UNINIT) {
item.intVal = getNewOffset(allIndexes, allSizes, 0,
item.intVal);
}
}
}
// The stack map frames are not serialized yet, so we don't need
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/scala/tools/asm/TypePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ public static TypePath fromString(final String typePath) {
typeArg = typeArg * 10 + c - '0';
i += 1;
}
if (i < n && typePath.charAt(i) == ';') {
i += 1;
}
out.put11(TYPE_ARGUMENT, typeArg);
}
}
Expand All @@ -164,7 +167,7 @@ public static TypePath fromString(final String typePath) {
* ARRAY_ELEMENT} steps are represented with '[', {@link #INNER_TYPE
* INNER_TYPE} steps with '.', {@link #WILDCARD_BOUND WILDCARD_BOUND} steps
* with '*' and {@link #TYPE_ARGUMENT TYPE_ARGUMENT} steps with their type
* argument index in decimal form.
* argument index in decimal form followed by ';'.
*/
@Override
public String toString() {
Expand All @@ -182,7 +185,7 @@ public String toString() {
result.append('*');
break;
case TYPE_ARGUMENT:
result.append(getStepArgument(i));
result.append(getStepArgument(i)).append(';');
break;
default:
result.append('_');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* <ul>
* <li><i>ClassSignature</i> = ( <tt>visitFormalTypeParameter</tt>
* <tt>visitClassBound</tt>? <tt>visitInterfaceBound</tt>* )* (
* <tt>visitSuperClass</tt> <tt>visitInterface</tt>* )</li>
* <tt>visitSuperclass</tt> <tt>visitInterface</tt>* )</li>
* <li><i>MethodSignature</i> = ( <tt>visitFormalTypeParameter</tt>
* <tt>visitClassBound</tt>? <tt>visitInterfaceBound</tt>* )* (
* <tt>visitParameterType</tt>* <tt>visitReturnType</tt>
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/scala/tools/asm/tree/AnnotationNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,13 @@ static void accept(final AnnotationVisitor av, final String name,
an.accept(av.visitAnnotation(name, an.desc));
} else if (value instanceof List) {
AnnotationVisitor v = av.visitArray(name);
List<?> array = (List<?>) value;
for (int j = 0; j < array.size(); ++j) {
accept(v, null, array.get(j));
if (v != null) {
List<?> array = (List<?>) value;
for (int j = 0; j < array.size(); ++j) {
accept(v, null, array.get(j));
}
v.visitEnd();
}
v.visitEnd();
} else {
av.visit(name, value);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/scala/tools/asm/tree/InsnList.java
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ public void resetLabels() {
}

// this class is not generified because it will create bridges
@SuppressWarnings("rawtypes")
private final class InsnListIterator implements ListIterator {

AbstractInsnNode next;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public LookupSwitchInsnNode(final LabelNode dflt, final int[] keys,
: labels.length);
if (keys != null) {
for (int i = 0; i < keys.length; ++i) {
this.keys.add(new Integer(keys[i]));
this.keys.add(keys[i]);
}
}
if (labels != null) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/scala/tools/asm/tree/MethodInsnNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public int getType() {
@Override
public void accept(final MethodVisitor mv) {
mv.visitMethodInsn(opcode, owner, name, desc, itf);
acceptAnnotations(mv);
}

@Override
Expand Down
1 change: 1 addition & 0 deletions src/main/java/scala/tools/asm/tree/MethodNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ public AnnotationVisitor visitTypeAnnotation(int typeRef,
}

@Override
@SuppressWarnings("unchecked")
public AnnotationVisitor visitParameterAnnotation(final int parameter,
final String desc, final boolean visible) {
AnnotationNode an = new AnnotationNode(desc);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/scala/tools/asm/tree/analysis/Analyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public Analyzer(final Interpreter<V> interpreter) {
* @throws AnalyzerException
* if a problem occurs during the analysis.
*/
@SuppressWarnings("unchecked")
public Frame<V>[] analyze(final String owner, final MethodNode m)
throws AnalyzerException {
if ((m.access & (ACC_ABSTRACT | ACC_NATIVE)) != 0) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/scala/tools/asm/tree/analysis/Frame.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public class Frame<V extends Value> {
* @param nStack
* the maximum stack size of the frame.
*/
@SuppressWarnings("unchecked")
public Frame(final int nLocals, final int nStack) {
this.values = (V[]) new Value[nLocals + nStack];
this.locals = nLocals;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/scala/tools/asm/util/CheckMethodAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ public void visitLabel(final Label label) {
if (labels.get(label) != null) {
throw new IllegalArgumentException("Already visited label");
}
labels.put(label, new Integer(insnCount));
labels.put(label, insnCount);
super.visitLabel(label);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/scala/tools/asm/util/Textifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ public Textifier visitParameterAnnotation(final int parameter,
Textifier t = createTextifier();
text.add(t.getText());
text.add(visible ? ") // parameter " : ") // invisible, parameter ");
text.add(new Integer(parameter));
text.add(parameter);
text.add("\n");
return t;
}
Expand Down