aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2006-10-29 23:33:15 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2006-10-29 23:33:15 +0000
commit31d13951317303d8066f6cf75a84de96db9274d8 (patch)
tree436e21a69d264812b51ac9dd94f9eef65a05ae3b /src
parent9a5e5219c1812a2e254021fc0f7fc9264814d532 (diff)
downloadjavassist-31d13951317303d8066f6cf75a84de96db9274d8.tar.gz
javassist-31d13951317303d8066f6cf75a84de96db9274d8.zip
StackMapTable support (not complete)
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@325 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src')
-rw-r--r--src/main/javassist/bytecode/AttributeInfo.java7
-rw-r--r--src/main/javassist/bytecode/StackMapTable.java315
-rw-r--r--src/main/javassist/util/proxy/ProxyFactory.java10
3 files changed, 326 insertions, 6 deletions
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().
/**
* <code>attribute_info</code> 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;
+
+/**
+ * <code>stack_map</code> attribute.
+ *
+ * <p>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 <code>"StackMapTable"</code>.
+ */
+ public static final String tag = "StackMapTable";
+
+ private StackMapFrame[] entries; // may be null
+
+ /**
+ * Constructs a <code>stack_map</code> 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
+ }
+
+ /**
+ * <code>union stack_map_frame</code>
+ */
+ public static class StackMapFrame {}
+
+ /*
+ * verification_type_info is represented by a pair of
+ * 2 int variables (tag and cpool_index/offset).
+ */
+
+ /**
+ * <code>Top_variable_info.tag</code>.
+ */
+ public static final int TOP = 0;
+
+ /**
+ * <code>Float_variable_info.tag</code>.
+ */
+ public static final int INTEGER = 1;
+
+ /**
+ * <code>Integer_variable_info.tag</code>.
+ */
+ public static final int FLOAT = 2;
+
+ /**
+ * <code>Double_variable_info.tag</code>.
+ */
+ public static final int DOUBLE = 3;
+
+ /**
+ * <code>Long_variable_info.tag</code>.
+ */
+ public static final int LONG = 4;
+
+ /**
+ * <code>Null_variable_info.tag</code>.
+ */
+ public static final int NULL = 5;
+
+ /**
+ * <code>UninitializedThis_variable_info.tag</code>.
+ */
+ public static final int THIS = 6;
+
+ /**
+ * <code>Object_variable_info.tag</code>.
+ */
+ public static final int OBJECT = 7;
+
+ /**
+ * <code>Uninitialized_variable_info.tag</code>.
+ */
+ public static final int UNINIT = 8;
+
+ /**
+ * <code>same_frame</code>.
+ * The frame has exactly the same locals as the previous
+ * stack map frame.
+ */
+ public static class SameFrame extends StackMapFrame {
+ /**
+ * The maximum value of <code>SAME</code>.
+ */
+ public static final int FRAME_TYPE_MAX = 63;
+
+ /**
+ * <code>u1 frame_type</code>.
+ */
+ public int frameType;
+ }
+
+ /**
+ * <code>same_locals_1_stack_item_frame</code> or
+ * <code>same_locals_1_stack_item_frame_extended</code>.
+ */
+ public static class SameLocals extends StackMapFrame {
+ /**
+ * The minimum value of <code>SAME_LOCALS_1_STACK_ITEM</code>.
+ */
+ public static final int FRAME_TYPE = 64;
+
+ /**
+ * The maximum value of <code>SAME_LOCALS_1_STACK_ITEM</code>.
+ */
+ public static final int FRAME_TYPE_MAX = 127;
+
+ /**
+ * <code>SAME_LOCALS_1_STACK_ITEM_EXTENDED</code>.
+ */
+ public static final int FRAME_TYPE_EXTENDED = 247;
+
+ /*
+ * <code>frame_type</code> is computed by offsetDelta.
+ */
+
+ /**
+ * <code>u2 offset_delta</code>.
+ */
+ public int offsetDelta;
+
+ /**
+ * <code>stack[0].tag</code>.
+ */
+ public int typeTag;
+
+ /**
+ * <code>stack[0].cpool_index</code> or <code>stack[0].offset</code>.
+ */
+ public int typeValue;
+ }
+
+ /**
+ * <code>chop_frame</code>.
+ */
+ public static class ChopFrame extends StackMapFrame {
+ /**
+ * The minimum value of <code>CHOP</code>.
+ */
+ public static final int FRAME_TYPE = 248;
+
+ /**
+ * The maximum value of <code>CHOP</code>.
+ */
+ public static final int FRAME_TYPE_MAX = 250;
+
+ /**
+ * <code>u1 frame_type</code>.
+ */
+ public int frameType;
+
+ /**
+ * <code>u2 offset_delta</code>.
+ */
+ public int offsetDelta;
+ }
+
+ /**
+ * <code>same_frame_extended</code>.
+ */
+ public static class SameFrameExtended extends StackMapFrame {
+ /**
+ * <code>SAME_FRAME_EXTENDED</code>.
+ */
+ public static final int FRAME_TYPE = 251;
+
+ /**
+ * <code>u2 offset_delta</code>.
+ */
+ public int offsetDelta;
+ }
+
+ /**
+ * <code>append_frame</code>.
+ */
+ public static class AppendFrame extends StackMapFrame {
+ /**
+ * The minimum value of <code>APPEND</code>.
+ */
+ public static final int FRAME_TYPE = 252;
+
+ /**
+ * The maximum value of <code>APPEND</code>.
+ */
+ public static final int FRAME_TYPE_MAX = 254;
+
+ /**
+ * <code>u1 frame_type</code>.
+ */
+ public int frameType;
+
+ /**
+ * <code>u2 offset_delta</code>.
+ */
+ public int offsetDelta;
+
+ /**
+ * <code>locals[?].tag</code>.
+ */
+ public int[] typeTags;
+
+ /**
+ * <code>locals[?].cpool_index</code> or <code>locals[?].offset</code>.
+ */
+ public int[] typeValues;
+ }
+
+ /**
+ * <code>ful_frame</code>.
+ */
+ public static class FullFrame extends StackMapFrame {
+ /**
+ * <code>FULL_FRAME</code>.
+ */
+ public static final int FRAME_TYPE = 255;
+
+ /**
+ * <code>u2 offset_delta</code>.
+ */
+ public int offsetDelta;
+
+ /**
+ * <code>u2 number_of_locals</code>.
+ */
+ public int numOfLocals;
+
+ /**
+ * <code>locals[?].tag</code>.
+ */
+ public int[] typeTags;
+
+ /**
+ * <code>locals[?].cpool_index</code> or <code>locals[?].offset</code>.
+ */
+ public int[] typeValues;
+
+ /**
+ * <code>u2 number_of_stack_items</code>.
+ */
+ public int numOfStackItems;
+
+ /**
+ * <code>stack[?].tag</code>.
+ */
+ public int[] stackTypeTags;
+
+ /**
+ * <code>stack[?].cpool_index</code> or <code>locals[?].offset</code>.
+ */
+ 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 <code>createClass()</code> for obtaining
* a class loader.
- * <code>get()</code> on this <code>ClassLoaderGetter</code> object
+ * <code>get()</code> on this <code>ClassLoaderProvider</code> object
* is called to obtain a class loader.
*
* <p>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;