From f685aa708c5f598a34f36896d3c4bcaa22e94e7d Mon Sep 17 00:00:00 2001 From: chiba Date: Wed, 1 Nov 2006 02:45:05 +0000 Subject: [PATCH] fixed JIRA JASSIST-28? git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@326 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- src/main/javassist/ClassPool.java | 18 +++- .../javassist/bytecode/AttributeInfo.java | 4 +- .../javassist/bytecode/StackMapTable.java | 91 ++++++++----------- .../javassist/util/proxy/FactoryHelper.java | 18 +++- .../javassist/util/proxy/ProxyFactory.java | 7 +- 5 files changed, 74 insertions(+), 64 deletions(-) diff --git a/src/main/javassist/ClassPool.java b/src/main/javassist/ClassPool.java index 5db629f4..1a487cd3 100644 --- a/src/main/javassist/ClassPool.java +++ b/src/main/javassist/ClassPool.java @@ -20,6 +20,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.lang.reflect.Method; import java.net.URL; import java.security.AccessController; import java.security.PrivilegedActionException; @@ -893,11 +894,8 @@ public class ClassPool { args = new Object[] { ct.getName(), b, new Integer(0), new Integer(b.length), domain}; } - - method.setAccessible(true); - Class clazz = (Class)method.invoke(loader, args); - method.setAccessible(false); - return clazz; + + return toClass2(method, loader, args); } catch (RuntimeException e) { throw e; @@ -909,4 +907,14 @@ public class ClassPool { throw new CannotCompileException(e); } } + + private static synchronized Class toClass2(Method method, + ClassLoader loader, Object[] args) + throws Exception + { + method.setAccessible(true); + Class clazz = (Class)method.invoke(loader, args); + method.setAccessible(false); + return clazz; + } } diff --git a/src/main/javassist/bytecode/AttributeInfo.java b/src/main/javassist/bytecode/AttributeInfo.java index 174ad00d..3393be16 100644 --- a/src/main/javassist/bytecode/AttributeInfo.java +++ b/src/main/javassist/bytecode/AttributeInfo.java @@ -96,8 +96,10 @@ public class AttributeInfo { || nameStr.equals(LocalVariableAttribute.typeTag)) return new LocalVariableAttribute(cp, name, in); else if (nameStr.equals(AnnotationsAttribute.visibleTag) - || nameStr.equals(AnnotationsAttribute.invisibleTag)) + || nameStr.equals(AnnotationsAttribute.invisibleTag)) { + // RuntimeVisibleAnnotations or RuntimeInvisibleAnnotations return new AnnotationsAttribute(cp, name, in); + } else if (nameStr.equals(ParameterAnnotationsAttribute.visibleTag) || nameStr.equals(ParameterAnnotationsAttribute.invisibleTag)) return new ParameterAnnotationsAttribute(cp, name, in); diff --git a/src/main/javassist/bytecode/StackMapTable.java b/src/main/javassist/bytecode/StackMapTable.java index 6318104f..7a56c633 100644 --- a/src/main/javassist/bytecode/StackMapTable.java +++ b/src/main/javassist/bytecode/StackMapTable.java @@ -19,6 +19,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.Map; +import java.util.ArrayList; /** * stack_map attribute. @@ -33,7 +34,7 @@ public class StackMapTable extends AttributeInfo { */ public static final String tag = "StackMapTable"; - private StackMapFrame[] entries; // may be null + private ArrayList entries; // ArrayList. may be null. /** * Constructs a stack_map attribute. @@ -73,7 +74,12 @@ public class StackMapTable extends AttributeInfo { private void parseMap() { byte[] data = info; int n = ByteArray.readU16bit(data, 0); - entries = new StackMapFrame[n]; + entries = new ArrayList(n); + int offset = 2; + while (n-- > 0) { + int frameType; + } + } private void toByteArray(boolean clear) { @@ -82,9 +88,21 @@ public class StackMapTable extends AttributeInfo { } /** - * union stack_map_frame + * union stack_map_frame. + *

verification_type_info is represented + * by a pair of two int values. No class + * for represening verification_type_ */ - public static class StackMapFrame {} + public static class StackMapFrame { + /** + * u2 offset_delta. + * If offset_delta is not included + * (i.e. same_frame), the value of + * this field is computed from other members such + * as frame_type. + */ + public int offsetDelta; + } /* * verification_type_info is represented by a pair of @@ -138,24 +156,22 @@ public class StackMapTable extends AttributeInfo { /** * same_frame. - * The frame has exactly the same locals as the previous - * stack map frame. + * frame_type is not included. + * It is computed by offsetDelta. */ public static class SameFrame extends StackMapFrame { /** * The maximum value of SAME. */ public static final int FRAME_TYPE_MAX = 63; - - /** - * u1 frame_type. - */ - public int frameType; } /** * same_locals_1_stack_item_frame or - * same_locals_1_stack_item_frame_extended. + * same_locals_1_stack_item_frame_extended. + * + *

frame_type is not included. + * It is computed by offsetDelta. */ public static class SameLocals extends StackMapFrame { /** @@ -173,15 +189,6 @@ public class StackMapTable extends AttributeInfo { */ public static final int FRAME_TYPE_EXTENDED = 247; - /* - * frame_type is computed by offsetDelta. - */ - - /** - * u2 offset_delta. - */ - public int offsetDelta; - /** * stack[0].tag. */ @@ -211,11 +218,6 @@ public class StackMapTable extends AttributeInfo { * u1 frame_type. */ public int frameType; - - /** - * u2 offset_delta. - */ - public int offsetDelta; } /** @@ -226,11 +228,6 @@ public class StackMapTable extends AttributeInfo { * SAME_FRAME_EXTENDED. */ public static final int FRAME_TYPE = 251; - - /** - * u2 offset_delta. - */ - public int offsetDelta; } /** @@ -252,18 +249,17 @@ public class StackMapTable extends AttributeInfo { */ public int frameType; - /** - * u2 offset_delta. - */ - public int offsetDelta; - /** * locals[?].tag. + * typeTags.length and typeValues.length + * are equal to number_of_locals. */ public int[] typeTags; /** * locals[?].cpool_index or locals[?].offset. + * typeTags.length and typeValues.length + * are equal to number_of_locals. */ public int[] typeValues; } @@ -277,38 +273,31 @@ public class StackMapTable extends AttributeInfo { */ public static final int FRAME_TYPE = 255; - /** - * u2 offset_delta. - */ - public int offsetDelta; - - /** - * u2 number_of_locals. - */ - public int numOfLocals; - /** * locals[?].tag. + * typeTags.length and typeValues.length + * are equal to number_of_locals. */ public int[] typeTags; /** * locals[?].cpool_index or locals[?].offset. + * typeTags.length and typeValues.length + * are equal to number_of_locals. */ public int[] typeValues; - /** - * u2 number_of_stack_items. - */ - public int numOfStackItems; - /** * stack[?].tag. + * stackTypeTags.length and stackTypeValues.length + * are equal to number_of_stack_items. */ public int[] stackTypeTags; /** * stack[?].cpool_index or locals[?].offset. + * stackTypeTags.length and stackTypeValues.length + * are equal to number_of_stack_items. */ public int[] stackTypeValues; } diff --git a/src/main/javassist/util/proxy/FactoryHelper.java b/src/main/javassist/util/proxy/FactoryHelper.java index 4579f04e..aea9d88f 100644 --- a/src/main/javassist/util/proxy/FactoryHelper.java +++ b/src/main/javassist/util/proxy/FactoryHelper.java @@ -15,6 +15,7 @@ package javassist.util.proxy; +import java.lang.reflect.Method; import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; @@ -142,7 +143,7 @@ public class FactoryHelper { { try { byte[] b = toBytecode(cf); - java.lang.reflect.Method method; + Method method; Object[] args; if (domain == null) { method = defineClass1; @@ -155,10 +156,7 @@ public class FactoryHelper { new Integer(b.length), domain }; } - method.setAccessible(true); - Class clazz = (Class)method.invoke(loader, args); - method.setAccessible(false); - return clazz; + return toClass2(method, loader, args); } catch (RuntimeException e) { throw e; @@ -171,6 +169,16 @@ public class FactoryHelper { } } + private static synchronized Class toClass2(Method method, + ClassLoader loader, Object[] args) + throws Exception + { + method.setAccessible(true); + Class clazz = (Class)method.invoke(loader, args); + method.setAccessible(false); + return clazz; + } + private static byte[] toBytecode(ClassFile cf) throws IOException { ByteArrayOutputStream barray = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(barray); diff --git a/src/main/javassist/util/proxy/ProxyFactory.java b/src/main/javassist/util/proxy/ProxyFactory.java index fe1ce0f8..566b809d 100644 --- a/src/main/javassist/util/proxy/ProxyFactory.java +++ b/src/main/javassist/util/proxy/ProxyFactory.java @@ -309,6 +309,10 @@ public class ProxyFactory { private static int counter = 0; + private static synchronized String makeProxyName(String classname) { + return classname + "_$$_javassist_" + counter++; + } + private ClassFile make() throws CannotCompileException { String superName, classname; if (interfaces == null) @@ -328,8 +332,7 @@ public class ProxyFactory { if (Modifier.isFinal(superClass.getModifiers())) throw new CannotCompileException(superName + " is final"); - // generate a proxy name. - classname = classname + "_$$_javassist_" + counter++; + classname = makeProxyName(classname); if (classname.startsWith("java.")) classname = "org.javassist.tmp." + classname; -- 2.39.5