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

Commit 097ab07

Browse files
committed
Upgrade ASM to 5.0.3
This commit is a squashed version of all commits in PR #4382. For the next upgrade, consult the src/asm/README and check the commits in https://github.com/scala/scala/pull/4382/commits.
1 parent d60ca79 commit 097ab07

File tree

7 files changed

+270
-32
lines changed

7 files changed

+270
-32
lines changed

README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Version 5.0.2, SVN r1741, tags/ASM_5_0_2
1+
Version 5.0.3, SVN r1748, tags/ASM_5_0_3
22

33
Git SVN repo: https://github.com/lrytz/asm
44
- git svn howto: https://github.com/lrytz/asm/issues/1

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ boolean inSameSubroutine(final Label block) {
473473
void addToSubroutine(final long id, final int nbSubroutines) {
474474
if ((status & VISITED) == 0) {
475475
status |= VISITED;
476-
srcAndRefPositions = new int[(nbSubroutines - 1) / 32 + 1];
476+
srcAndRefPositions = new int[nbSubroutines / 32 + 1];
477477
}
478478
srcAndRefPositions[(int) (id >>> 32)] |= (int) id;
479479
}

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,43 +1974,43 @@ private void writeFrameTypes(final int start, final int end) {
19741974
stackMap.putByte(v);
19751975
}
19761976
} else {
1977-
StringBuffer buf = new StringBuffer();
1977+
StringBuilder sb = new StringBuilder();
19781978
d >>= 28;
19791979
while (d-- > 0) {
1980-
buf.append('[');
1980+
sb.append('[');
19811981
}
19821982
if ((t & Frame.BASE_KIND) == Frame.OBJECT) {
1983-
buf.append('L');
1984-
buf.append(cw.typeTable[t & Frame.BASE_VALUE].strVal1);
1985-
buf.append(';');
1983+
sb.append('L');
1984+
sb.append(cw.typeTable[t & Frame.BASE_VALUE].strVal1);
1985+
sb.append(';');
19861986
} else {
19871987
switch (t & 0xF) {
19881988
case 1:
1989-
buf.append('I');
1989+
sb.append('I');
19901990
break;
19911991
case 2:
1992-
buf.append('F');
1992+
sb.append('F');
19931993
break;
19941994
case 3:
1995-
buf.append('D');
1995+
sb.append('D');
19961996
break;
19971997
case 9:
1998-
buf.append('Z');
1998+
sb.append('Z');
19991999
break;
20002000
case 10:
2001-
buf.append('B');
2001+
sb.append('B');
20022002
break;
20032003
case 11:
2004-
buf.append('C');
2004+
sb.append('C');
20052005
break;
20062006
case 12:
2007-
buf.append('S');
2007+
sb.append('S');
20082008
break;
20092009
default:
2010-
buf.append('J');
2010+
sb.append('J');
20112011
}
20122012
}
2013-
stackMap.putByte(7).putShort(cw.newClass(buf.toString()));
2013+
stackMap.putByte(7).putShort(cw.newClass(sb.toString()));
20142014
}
20152015
}
20162016
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,11 @@ public String getClassName() {
556556
case DOUBLE:
557557
return "double";
558558
case ARRAY:
559-
StringBuffer b = new StringBuffer(getElementType().getClassName());
559+
StringBuilder sb = new StringBuilder(getElementType().getClassName());
560560
for (int i = getDimensions(); i > 0; --i) {
561-
b.append("[]");
561+
sb.append("[]");
562562
}
563-
return b.toString();
563+
return sb.toString();
564564
case OBJECT:
565565
return new String(buf, off, len).replace('/', '.');
566566
default:
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
/***
2+
* ASM: a very small and fast Java bytecode manipulation framework
3+
* Copyright (c) 2000-2011 INRIA, France Telecom
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions
8+
* are met:
9+
* 1. Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* 2. Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
* 3. Neither the name of the copyright holders nor the names of its
15+
* contributors may be used to endorse or promote products derived from
16+
* this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28+
* THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
package scala.tools.asm.commons;
31+
32+
import scala.tools.asm.Handle;
33+
import scala.tools.asm.Label;
34+
import scala.tools.asm.MethodVisitor;
35+
import scala.tools.asm.Opcodes;
36+
37+
/**
38+
* A {@link MethodVisitor} that can be used to approximate method size.
39+
*
40+
* @author Eugene Kuleshov
41+
*/
42+
public class CodeSizeEvaluator extends MethodVisitor implements Opcodes {
43+
44+
private int minSize;
45+
46+
private int maxSize;
47+
48+
public CodeSizeEvaluator(final MethodVisitor mv) {
49+
this(Opcodes.ASM5, mv);
50+
}
51+
52+
protected CodeSizeEvaluator(final int api, final MethodVisitor mv) {
53+
super(api, mv);
54+
}
55+
56+
public int getMinSize() {
57+
return this.minSize;
58+
}
59+
60+
public int getMaxSize() {
61+
return this.maxSize;
62+
}
63+
64+
@Override
65+
public void visitInsn(final int opcode) {
66+
minSize += 1;
67+
maxSize += 1;
68+
if (mv != null) {
69+
mv.visitInsn(opcode);
70+
}
71+
}
72+
73+
@Override
74+
public void visitIntInsn(final int opcode, final int operand) {
75+
if (opcode == SIPUSH) {
76+
minSize += 3;
77+
maxSize += 3;
78+
} else {
79+
minSize += 2;
80+
maxSize += 2;
81+
}
82+
if (mv != null) {
83+
mv.visitIntInsn(opcode, operand);
84+
}
85+
}
86+
87+
@Override
88+
public void visitVarInsn(final int opcode, final int var) {
89+
if (var < 4 && opcode != RET) {
90+
minSize += 1;
91+
maxSize += 1;
92+
} else if (var >= 256) {
93+
minSize += 4;
94+
maxSize += 4;
95+
} else {
96+
minSize += 2;
97+
maxSize += 2;
98+
}
99+
if (mv != null) {
100+
mv.visitVarInsn(opcode, var);
101+
}
102+
}
103+
104+
@Override
105+
public void visitTypeInsn(final int opcode, final String type) {
106+
minSize += 3;
107+
maxSize += 3;
108+
if (mv != null) {
109+
mv.visitTypeInsn(opcode, type);
110+
}
111+
}
112+
113+
@Override
114+
public void visitFieldInsn(final int opcode, final String owner,
115+
final String name, final String desc) {
116+
minSize += 3;
117+
maxSize += 3;
118+
if (mv != null) {
119+
mv.visitFieldInsn(opcode, owner, name, desc);
120+
}
121+
}
122+
123+
@Deprecated
124+
@Override
125+
public void visitMethodInsn(final int opcode, final String owner,
126+
final String name, final String desc) {
127+
if (api >= Opcodes.ASM5) {
128+
super.visitMethodInsn(opcode, owner, name, desc);
129+
return;
130+
}
131+
doVisitMethodInsn(opcode, owner, name, desc,
132+
opcode == Opcodes.INVOKEINTERFACE);
133+
}
134+
135+
@Override
136+
public void visitMethodInsn(final int opcode, final String owner,
137+
final String name, final String desc, final boolean itf) {
138+
if (api < Opcodes.ASM5) {
139+
super.visitMethodInsn(opcode, owner, name, desc, itf);
140+
return;
141+
}
142+
doVisitMethodInsn(opcode, owner, name, desc, itf);
143+
}
144+
145+
private void doVisitMethodInsn(int opcode, final String owner,
146+
final String name, final String desc, final boolean itf) {
147+
if (opcode == INVOKEINTERFACE) {
148+
minSize += 5;
149+
maxSize += 5;
150+
} else {
151+
minSize += 3;
152+
maxSize += 3;
153+
}
154+
if (mv != null) {
155+
mv.visitMethodInsn(opcode, owner, name, desc, itf);
156+
}
157+
}
158+
159+
@Override
160+
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
161+
Object... bsmArgs) {
162+
minSize += 5;
163+
maxSize += 5;
164+
if (mv != null) {
165+
mv.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
166+
}
167+
}
168+
169+
@Override
170+
public void visitJumpInsn(final int opcode, final Label label) {
171+
minSize += 3;
172+
if (opcode == GOTO || opcode == JSR) {
173+
maxSize += 5;
174+
} else {
175+
maxSize += 8;
176+
}
177+
if (mv != null) {
178+
mv.visitJumpInsn(opcode, label);
179+
}
180+
}
181+
182+
@Override
183+
public void visitLdcInsn(final Object cst) {
184+
if (cst instanceof Long || cst instanceof Double) {
185+
minSize += 3;
186+
maxSize += 3;
187+
} else {
188+
minSize += 2;
189+
maxSize += 3;
190+
}
191+
if (mv != null) {
192+
mv.visitLdcInsn(cst);
193+
}
194+
}
195+
196+
@Override
197+
public void visitIincInsn(final int var, final int increment) {
198+
if (var > 255 || increment > 127 || increment < -128) {
199+
minSize += 6;
200+
maxSize += 6;
201+
} else {
202+
minSize += 3;
203+
maxSize += 3;
204+
}
205+
if (mv != null) {
206+
mv.visitIincInsn(var, increment);
207+
}
208+
}
209+
210+
@Override
211+
public void visitTableSwitchInsn(final int min, final int max,
212+
final Label dflt, final Label... labels) {
213+
minSize += 13 + labels.length * 4;
214+
maxSize += 16 + labels.length * 4;
215+
if (mv != null) {
216+
mv.visitTableSwitchInsn(min, max, dflt, labels);
217+
}
218+
}
219+
220+
@Override
221+
public void visitLookupSwitchInsn(final Label dflt, final int[] keys,
222+
final Label[] labels) {
223+
minSize += 9 + keys.length * 8;
224+
maxSize += 12 + keys.length * 8;
225+
if (mv != null) {
226+
mv.visitLookupSwitchInsn(dflt, keys, labels);
227+
}
228+
}
229+
230+
@Override
231+
public void visitMultiANewArrayInsn(final String desc, final int dims) {
232+
minSize += 4;
233+
maxSize += 4;
234+
if (mv != null) {
235+
mv.visitMultiANewArrayInsn(desc, dims);
236+
}
237+
}
238+
}

src/main/java/scala/tools/asm/tree/analysis/Frame.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -725,14 +725,14 @@ public boolean merge(final Frame<? extends V> frame, final boolean[] access) {
725725
*/
726726
@Override
727727
public String toString() {
728-
StringBuffer b = new StringBuffer();
728+
StringBuilder sb = new StringBuilder();
729729
for (int i = 0; i < getLocals(); ++i) {
730-
b.append(getLocal(i));
730+
sb.append(getLocal(i));
731731
}
732-
b.append(' ');
732+
sb.append(' ');
733733
for (int i = 0; i < getStackSize(); ++i) {
734-
b.append(getStack(i).toString());
734+
sb.append(getStack(i).toString());
735735
}
736-
return b.toString();
736+
return sb.toString();
737737
}
738738
}

src/main/java/scala/tools/asm/util/CheckClassAdapter.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,26 +269,26 @@ static void printAnalyzerResult(MethodNode method, Analyzer<BasicValue> a,
269269
for (int j = 0; j < method.instructions.size(); ++j) {
270270
method.instructions.get(j).accept(mv);
271271

272-
StringBuffer s = new StringBuffer();
272+
StringBuilder sb = new StringBuilder();
273273
Frame<BasicValue> f = frames[j];
274274
if (f == null) {
275-
s.append('?');
275+
sb.append('?');
276276
} else {
277277
for (int k = 0; k < f.getLocals(); ++k) {
278-
s.append(getShortName(f.getLocal(k).toString()))
278+
sb.append(getShortName(f.getLocal(k).toString()))
279279
.append(' ');
280280
}
281-
s.append(" : ");
281+
sb.append(" : ");
282282
for (int k = 0; k < f.getStackSize(); ++k) {
283-
s.append(getShortName(f.getStack(k).toString()))
283+
sb.append(getShortName(f.getStack(k).toString()))
284284
.append(' ');
285285
}
286286
}
287-
while (s.length() < method.maxStack + method.maxLocals + 1) {
288-
s.append(' ');
287+
while (sb.length() < method.maxStack + method.maxLocals + 1) {
288+
sb.append(' ');
289289
}
290290
pw.print(Integer.toString(j + 100000).substring(1));
291-
pw.print(" " + s + " : " + t.text.get(t.text.size() - 1));
291+
pw.print(" " + sb + " : " + t.text.get(t.text.size() - 1));
292292
}
293293
for (int j = 0; j < method.tryCatchBlocks.size(); ++j) {
294294
method.tryCatchBlocks.get(j).accept(mv);

0 commit comments

Comments
 (0)