Browse Source

Latest patches from ASM trunk

pull/493/merge
Juergen Hoeller 12 years ago
parent
commit
cfc720db25
  1. 5
      spring-core/src/main/java/org/springframework/asm/Item.java
  2. 2
      spring-core/src/main/java/org/springframework/asm/Label.java
  3. 28
      spring-core/src/main/java/org/springframework/asm/MethodWriter.java
  4. 83
      spring-core/src/main/java/org/springframework/asm/Type.java

5
spring-core/src/main/java/org/springframework/asm/Item.java

@ -208,9 +208,12 @@ final class Item {
this.strVal2 = strVal2; this.strVal2 = strVal2;
this.strVal3 = strVal3; this.strVal3 = strVal3;
switch (type) { switch (type) {
case ClassWriter.CLASS:
this.intVal = 0; // intVal of a class must be zero, see visitInnerClass
hashCode = 0x7FFFFFFF & (type + strVal1.hashCode());
return;
case ClassWriter.UTF8: case ClassWriter.UTF8:
case ClassWriter.STR: case ClassWriter.STR:
case ClassWriter.CLASS:
case ClassWriter.MTYPE: case ClassWriter.MTYPE:
case ClassWriter.TYPE_NORMAL: case ClassWriter.TYPE_NORMAL:
hashCode = 0x7FFFFFFF & (type + strVal1.hashCode()); hashCode = 0x7FFFFFFF & (type + strVal1.hashCode());

2
spring-core/src/main/java/org/springframework/asm/Label.java

@ -473,7 +473,7 @@ public class Label {
void addToSubroutine(final long id, final int nbSubroutines) { void addToSubroutine(final long id, final int nbSubroutines) {
if ((status & VISITED) == 0) { if ((status & VISITED) == 0) {
status |= VISITED; status |= VISITED;
srcAndRefPositions = new int[(nbSubroutines - 1) / 32 + 1]; srcAndRefPositions = new int[nbSubroutines / 32 + 1];
} }
srcAndRefPositions[(int) (id >>> 32)] |= (int) id; srcAndRefPositions[(int) (id >>> 32)] |= (int) id;
} }

28
spring-core/src/main/java/org/springframework/asm/MethodWriter.java

@ -1966,43 +1966,43 @@ class MethodWriter extends MethodVisitor {
stackMap.putByte(v); stackMap.putByte(v);
} }
} else { } else {
StringBuffer buf = new StringBuffer(); StringBuilder sb = new StringBuilder();
d >>= 28; d >>= 28;
while (d-- > 0) { while (d-- > 0) {
buf.append('['); sb.append('[');
} }
if ((t & Frame.BASE_KIND) == Frame.OBJECT) { if ((t & Frame.BASE_KIND) == Frame.OBJECT) {
buf.append('L'); sb.append('L');
buf.append(cw.typeTable[t & Frame.BASE_VALUE].strVal1); sb.append(cw.typeTable[t & Frame.BASE_VALUE].strVal1);
buf.append(';'); sb.append(';');
} else { } else {
switch (t & 0xF) { switch (t & 0xF) {
case 1: case 1:
buf.append('I'); sb.append('I');
break; break;
case 2: case 2:
buf.append('F'); sb.append('F');
break; break;
case 3: case 3:
buf.append('D'); sb.append('D');
break; break;
case 9: case 9:
buf.append('Z'); sb.append('Z');
break; break;
case 10: case 10:
buf.append('B'); sb.append('B');
break; break;
case 11: case 11:
buf.append('C'); sb.append('C');
break; break;
case 12: case 12:
buf.append('S'); sb.append('S');
break; break;
default: default:
buf.append('J'); sb.append('J');
} }
} }
stackMap.putByte(7).putShort(cw.newClass(buf.toString())); stackMap.putByte(7).putShort(cw.newClass(sb.toString()));
} }
} }
} }

83
spring-core/src/main/java/org/springframework/asm/Type.java

@ -401,8 +401,8 @@ public class Type {
* @return the size of the arguments of the method (plus one for the * @return the size of the arguments of the method (plus one for the
* implicit this argument), argSize, and the size of its return * implicit this argument), argSize, and the size of its return
* value, retSize, packed into a single int i = * value, retSize, packed into a single int i =
* <tt>(argSize << 2) | retSize</tt> (argSize is therefore equal to * <tt>(argSize &lt;&lt; 2) | retSize</tt> (argSize is therefore equal to
* <tt>i >> 2</tt>, and retSize to <tt>i & 0x03</tt>). * <tt>i &gt;&gt; 2</tt>, and retSize to <tt>i &amp; 0x03</tt>).
*/ */
public static int getArgumentsAndReturnSizes(final String desc) { public static int getArgumentsAndReturnSizes(final String desc) {
int n = 1; int n = 1;
@ -556,11 +556,11 @@ public class Type {
case DOUBLE: case DOUBLE:
return "double"; return "double";
case ARRAY: case ARRAY:
StringBuffer b = new StringBuffer(getElementType().getClassName()); StringBuilder sb = new StringBuilder(getElementType().getClassName());
for (int i = getDimensions(); i > 0; --i) { for (int i = getDimensions(); i > 0; --i) {
b.append("[]"); sb.append("[]");
} }
return b.toString(); return sb.toString();
case OBJECT: case OBJECT:
return new String(buf, off, len).replace('/', '.'); return new String(buf, off, len).replace('/', '.');
default: default:
@ -606,9 +606,10 @@ public class Type {
* *
* @return the size of the arguments (plus one for the implicit this * @return the size of the arguments (plus one for the implicit this
* argument), argSize, and the size of the return value, retSize, * argument), argSize, and the size of the return value, retSize,
* packed into a single int i = <tt>(argSize << 2) | retSize</tt> * packed into a single
* (argSize is therefore equal to <tt>i >> 2</tt>, and retSize to * int i = <tt>(argSize &lt;&lt; 2) | retSize</tt>
* <tt>i & 0x03</tt>). * (argSize is therefore equal to <tt>i &gt;&gt; 2</tt>,
* and retSize to <tt>i &amp; 0x03</tt>).
*/ */
public int getArgumentsAndReturnSizes() { public int getArgumentsAndReturnSizes() {
return getArgumentsAndReturnSizes(getDescriptor()); return getArgumentsAndReturnSizes(getDescriptor());
@ -624,9 +625,9 @@ public class Type {
* @return the descriptor corresponding to this Java type. * @return the descriptor corresponding to this Java type.
*/ */
public String getDescriptor() { public String getDescriptor() {
StringBuffer buf = new StringBuffer(); StringBuilder sb = new StringBuilder();
getDescriptor(buf); getDescriptor(sb);
return buf.toString(); return sb.toString();
} }
/** /**
@ -642,24 +643,24 @@ public class Type {
*/ */
public static String getMethodDescriptor(final Type returnType, public static String getMethodDescriptor(final Type returnType,
final Type... argumentTypes) { final Type... argumentTypes) {
StringBuffer buf = new StringBuffer(); StringBuilder sb = new StringBuilder();
buf.append('('); sb.append('(');
for (int i = 0; i < argumentTypes.length; ++i) { for (int i = 0; i < argumentTypes.length; ++i) {
argumentTypes[i].getDescriptor(buf); argumentTypes[i].getDescriptor(sb);
} }
buf.append(')'); sb.append(')');
returnType.getDescriptor(buf); returnType.getDescriptor(sb);
return buf.toString(); return sb.toString();
} }
/** /**
* Appends the descriptor corresponding to this Java type to the given * Appends the descriptor corresponding to this Java type to the given
* string buffer. * string builder.
* *
* @param buf * @param buf
* the string buffer to which the descriptor must be appended. * the string builder to which the descriptor must be appended.
*/ */
private void getDescriptor(final StringBuffer buf) { private void getDescriptor(final StringBuilder buf) {
if (this.buf == null) { if (this.buf == null) {
// descriptor is in byte 3 of 'off' for primitive types (buf == // descriptor is in byte 3 of 'off' for primitive types (buf ==
// null) // null)
@ -699,9 +700,9 @@ public class Type {
* @return the descriptor corresponding to the given class. * @return the descriptor corresponding to the given class.
*/ */
public static String getDescriptor(final Class<?> c) { public static String getDescriptor(final Class<?> c) {
StringBuffer buf = new StringBuffer(); StringBuilder sb = new StringBuilder();
getDescriptor(buf, c); getDescriptor(sb, c);
return buf.toString(); return sb.toString();
} }
/** /**
@ -713,12 +714,12 @@ public class Type {
*/ */
public static String getConstructorDescriptor(final Constructor<?> c) { public static String getConstructorDescriptor(final Constructor<?> c) {
Class<?>[] parameters = c.getParameterTypes(); Class<?>[] parameters = c.getParameterTypes();
StringBuffer buf = new StringBuffer(); StringBuilder sb = new StringBuilder();
buf.append('('); sb.append('(');
for (int i = 0; i < parameters.length; ++i) { for (int i = 0; i < parameters.length; ++i) {
getDescriptor(buf, parameters[i]); getDescriptor(sb, parameters[i]);
} }
return buf.append(")V").toString(); return sb.append(")V").toString();
} }
/** /**
@ -730,25 +731,25 @@ public class Type {
*/ */
public static String getMethodDescriptor(final Method m) { public static String getMethodDescriptor(final Method m) {
Class<?>[] parameters = m.getParameterTypes(); Class<?>[] parameters = m.getParameterTypes();
StringBuffer buf = new StringBuffer(); StringBuilder sb = new StringBuilder();
buf.append('('); sb.append('(');
for (int i = 0; i < parameters.length; ++i) { for (int i = 0; i < parameters.length; ++i) {
getDescriptor(buf, parameters[i]); getDescriptor(sb, parameters[i]);
} }
buf.append(')'); sb.append(')');
getDescriptor(buf, m.getReturnType()); getDescriptor(sb, m.getReturnType());
return buf.toString(); return sb.toString();
} }
/** /**
* Appends the descriptor of the given class to the given string buffer. * Appends the descriptor of the given class to the given string builder.
* *
* @param buf * @param sb
* the string buffer to which the descriptor must be appended. * the string buffer to which the descriptor must be appended.
* @param c * @param c
* the class whose descriptor must be computed. * the class whose descriptor must be computed.
*/ */
private static void getDescriptor(final StringBuffer buf, final Class<?> c) { private static void getDescriptor(final StringBuilder sb, final Class<?> c) {
Class<?> d = c; Class<?> d = c;
while (true) { while (true) {
if (d.isPrimitive()) { if (d.isPrimitive()) {
@ -772,20 +773,20 @@ public class Type {
} else /* if (d == Long.TYPE) */{ } else /* if (d == Long.TYPE) */{
car = 'J'; car = 'J';
} }
buf.append(car); sb.append(car);
return; return;
} else if (d.isArray()) { } else if (d.isArray()) {
buf.append('['); sb.append('[');
d = d.getComponentType(); d = d.getComponentType();
} else { } else {
buf.append('L'); sb.append('L');
String name = d.getName(); String name = d.getName();
int len = name.length(); int len = name.length();
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
char car = name.charAt(i); char car = name.charAt(i);
buf.append(car == '.' ? '/' : car); sb.append(car == '.' ? '/' : car);
} }
buf.append(';'); sb.append(';');
return; return;
} }
} }

Loading…
Cancel
Save