From 31d13951317303d8066f6cf75a84de96db9274d8 Mon Sep 17 00:00:00 2001 From: chiba Date: Sun, 29 Oct 2006 23:33:15 +0000 Subject: StackMapTable support (not complete) git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@325 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- src/main/javassist/bytecode/AttributeInfo.java | 7 +- src/main/javassist/bytecode/StackMapTable.java | 315 ++++++++++++++++++++++++ src/main/javassist/util/proxy/ProxyFactory.java | 10 +- 3 files changed, 326 insertions(+), 6 deletions(-) create mode 100644 src/main/javassist/bytecode/StackMapTable.java (limited to 'src') diff --git a/src/main/javassist/bytecode/AttributeInfo.java b/src/main/javassist/bytecode/AttributeInfo.java index 69152a7a..174ad00d 100644 --- a/src/main/javassist/bytecode/AttributeInfo.java +++ b/src/main/javassist/bytecode/AttributeInfo.java @@ -23,7 +23,7 @@ import java.util.LinkedList; import java.util.ListIterator; // Note: if you define a new subclass of AttributeInfo, then -// update AttributeInfo.read(). +// update AttributeInfo.read(), .copy(), and (maybe) write(). /** * attribute_info structure. @@ -107,6 +107,8 @@ public class AttributeInfo { return new SourceFileAttribute(cp, name, in); else if (nameStr.equals(SyntheticAttribute.tag)) return new SyntheticAttribute(cp, name, in); + else if (nameStr.equals(StackMapTable.tag)) + return new StackMapTable(cp, name, in); } return new AttributeInfo(cp, name, in); @@ -161,9 +163,10 @@ public class AttributeInfo { */ public AttributeInfo copy(ConstPool newCp, Map classnames) { int s = info.length; + byte[] srcInfo = info; byte[] newInfo = new byte[s]; for (int i = 0; i < s; ++i) - newInfo[i] = info[i]; + newInfo[i] = srcInfo[i]; return new AttributeInfo(newCp, getName(), newInfo); } diff --git a/src/main/javassist/bytecode/StackMapTable.java b/src/main/javassist/bytecode/StackMapTable.java new file mode 100644 index 00000000..6318104f --- /dev/null +++ b/src/main/javassist/bytecode/StackMapTable.java @@ -0,0 +1,315 @@ +/* + * Javassist, a Java-bytecode translator toolkit. + * Copyright (C) 1999-2006 Shigeru Chiba. All Rights Reserved. + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. Alternatively, the contents of this file may be used under + * the terms of the GNU Lesser General Public License Version 2.1 or later. + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + */ + +package javassist.bytecode; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.Map; + +/** + * stack_map attribute. + * + *

This is an entry in the attributes table of a Code attribute. + * It was introduced by J2SE 6 for the process of verification by + * typechecking. + */ +public class StackMapTable extends AttributeInfo { + /** + * The name of this attribute "StackMapTable". + */ + public static final String tag = "StackMapTable"; + + private StackMapFrame[] entries; // may be null + + /** + * Constructs a stack_map attribute. + */ + public StackMapTable(ConstPool cp) { + this(cp, (byte[])null); + } + + private StackMapTable(ConstPool cp, byte[] newInfo) { + super(cp, tag, newInfo); + entries = null; + } + + StackMapTable(ConstPool cp, int name_id, DataInputStream in) + throws IOException + { + super(cp, name_id, in); + entries = null; + } + + /** + * Makes a copy. + */ + public AttributeInfo copy(ConstPool newCp, Map classnames) { + toByteArray(false); + int s = info.length; + byte[] newInfo = new byte[s]; + System.arraycopy(info, 0, newInfo, 0, s); + return new StackMapTable(newCp, newInfo); + } + + void write(DataOutputStream out) throws IOException { + toByteArray(true); + super.write(out); + } + + private void parseMap() { + byte[] data = info; + int n = ByteArray.readU16bit(data, 0); + entries = new StackMapFrame[n]; + } + + private void toByteArray(boolean clear) { + if (entries != null) + ; // unparse + } + + /** + * union stack_map_frame + */ + public static class StackMapFrame {} + + /* + * verification_type_info is represented by a pair of + * 2 int variables (tag and cpool_index/offset). + */ + + /** + * Top_variable_info.tag. + */ + public static final int TOP = 0; + + /** + * Float_variable_info.tag. + */ + public static final int INTEGER = 1; + + /** + * Integer_variable_info.tag. + */ + public static final int FLOAT = 2; + + /** + * Double_variable_info.tag. + */ + public static final int DOUBLE = 3; + + /** + * Long_variable_info.tag. + */ + public static final int LONG = 4; + + /** + * Null_variable_info.tag. + */ + public static final int NULL = 5; + + /** + * UninitializedThis_variable_info.tag. + */ + public static final int THIS = 6; + + /** + * Object_variable_info.tag. + */ + public static final int OBJECT = 7; + + /** + * Uninitialized_variable_info.tag. + */ + public static final int UNINIT = 8; + + /** + * same_frame. + * The frame has exactly the same locals as the previous + * stack map frame. + */ + 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. + */ + public static class SameLocals extends StackMapFrame { + /** + * The minimum value of SAME_LOCALS_1_STACK_ITEM. + */ + public static final int FRAME_TYPE = 64; + + /** + * The maximum value of SAME_LOCALS_1_STACK_ITEM. + */ + public static final int FRAME_TYPE_MAX = 127; + + /** + * SAME_LOCALS_1_STACK_ITEM_EXTENDED. + */ + public static final int FRAME_TYPE_EXTENDED = 247; + + /* + * frame_type is computed by offsetDelta. + */ + + /** + * u2 offset_delta. + */ + public int offsetDelta; + + /** + * stack[0].tag. + */ + public int typeTag; + + /** + * stack[0].cpool_index or stack[0].offset. + */ + public int typeValue; + } + + /** + * chop_frame. + */ + public static class ChopFrame extends StackMapFrame { + /** + * The minimum value of CHOP. + */ + public static final int FRAME_TYPE = 248; + + /** + * The maximum value of CHOP. + */ + public static final int FRAME_TYPE_MAX = 250; + + /** + * u1 frame_type. + */ + public int frameType; + + /** + * u2 offset_delta. + */ + public int offsetDelta; + } + + /** + * same_frame_extended. + */ + public static class SameFrameExtended extends StackMapFrame { + /** + * SAME_FRAME_EXTENDED. + */ + public static final int FRAME_TYPE = 251; + + /** + * u2 offset_delta. + */ + public int offsetDelta; + } + + /** + * append_frame. + */ + public static class AppendFrame extends StackMapFrame { + /** + * The minimum value of APPEND. + */ + public static final int FRAME_TYPE = 252; + + /** + * The maximum value of APPEND. + */ + public static final int FRAME_TYPE_MAX = 254; + + /** + * u1 frame_type. + */ + public int frameType; + + /** + * u2 offset_delta. + */ + public int offsetDelta; + + /** + * locals[?].tag. + */ + public int[] typeTags; + + /** + * locals[?].cpool_index or locals[?].offset. + */ + public int[] typeValues; + } + + /** + * ful_frame. + */ + public static class FullFrame extends StackMapFrame { + /** + * FULL_FRAME. + */ + public static final int FRAME_TYPE = 255; + + /** + * u2 offset_delta. + */ + public int offsetDelta; + + /** + * u2 number_of_locals. + */ + public int numOfLocals; + + /** + * locals[?].tag. + */ + public int[] typeTags; + + /** + * locals[?].cpool_index or locals[?].offset. + */ + public int[] typeValues; + + /** + * u2 number_of_stack_items. + */ + public int numOfStackItems; + + /** + * stack[?].tag. + */ + public int[] stackTypeTags; + + /** + * stack[?].cpool_index or locals[?].offset. + */ + public int[] stackTypeValues; + } +} diff --git a/src/main/javassist/util/proxy/ProxyFactory.java b/src/main/javassist/util/proxy/ProxyFactory.java index e3d6b65e..fe1ce0f8 100644 --- a/src/main/javassist/util/proxy/ProxyFactory.java +++ b/src/main/javassist/util/proxy/ProxyFactory.java @@ -209,7 +209,7 @@ public class ProxyFactory { /** * A provider used by createClass() for obtaining * a class loader. - * get() on this ClassLoaderGetter object + * get() on this ClassLoaderProvider object * is called to obtain a class loader. * *

The value of this field can be updated for changing the default @@ -238,7 +238,6 @@ public class ProxyFactory { } protected ClassLoader getClassLoader0() { - // return Thread.currentThread().getContextClassLoader(); ClassLoader loader = null; if (superClass != null && !superClass.getName().equals("java.lang.Object")) loader = superClass.getClassLoader(); @@ -248,8 +247,11 @@ public class ProxyFactory { if (loader == null) { loader = getClass().getClassLoader(); // In case javassist is in the endorsed dir - if (loader == null) - loader = ClassLoader.getSystemClassLoader(); + if (loader == null) { + loader = Thread.currentThread().getContextClassLoader(); + if (loader == null) + loader = ClassLoader.getSystemClassLoader(); + } } return loader; -- cgit v1.2.3