[jboss-cvs] javassist SVN: r686 - in trunk: src/main/javassist and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Nov 15 10:06:33 EST 2012
Author: chiba
Date: 2012-11-15 10:06:33 -0500 (Thu, 15 Nov 2012)
New Revision: 686
Modified:
trunk/Readme.html
trunk/javassist.jar
trunk/src/main/javassist/CtClass.java
trunk/src/main/javassist/bytecode/stackmap/BasicBlock.java
trunk/src/main/javassist/bytecode/stackmap/MapMaker.java
trunk/src/main/javassist/compiler/MemberCodeGen.java
trunk/src/test/javassist/bytecode/StackMapTest.java
Log:
fixed JASSIST-177
Modified: trunk/Readme.html
===================================================================
--- trunk/Readme.html 2012-11-08 15:37:05 UTC (rev 685)
+++ trunk/Readme.html 2012-11-15 15:06:33 UTC (rev 686)
@@ -281,6 +281,12 @@
<h2>Changes</h2>
+<p>-version 3.17.1
+<ul>
+ <li>JIRA JASSIST-177
+</ul>
+
+
<p>-version 3.17 on November 8, 2012
<ul>
<li>OSGi bundle info is now included in the jar file.
Modified: trunk/javassist.jar
===================================================================
(Binary files differ)
Modified: trunk/src/main/javassist/CtClass.java
===================================================================
--- trunk/src/main/javassist/CtClass.java 2012-11-08 15:37:05 UTC (rev 685)
+++ trunk/src/main/javassist/CtClass.java 2012-11-15 15:06:33 UTC (rev 686)
@@ -69,7 +69,7 @@
/**
* The version number of this release.
*/
- public static final String version = "3.17.0-GA";
+ public static final String version = "3.17.1-snapshot";
/**
* Prints the version number and the copyright notice.
Modified: trunk/src/main/javassist/bytecode/stackmap/BasicBlock.java
===================================================================
--- trunk/src/main/javassist/bytecode/stackmap/BasicBlock.java 2012-11-08 15:37:05 UTC (rev 685)
+++ trunk/src/main/javassist/bytecode/stackmap/BasicBlock.java 2012-11-15 15:06:33 UTC (rev 686)
@@ -23,10 +23,14 @@
/**
* A basic block is a sequence of bytecode that does not contain jump/branch
* instructions except at the last bytecode.
- * Since Java6 or later does not allow JSR, this class deals with JSR as a
- * non-branch instruction.
+ * Since Java7 or later does not allow JSR, this class throws an exception when
+ * it finds JSR.
*/
public class BasicBlock {
+ static class JsrBytecode extends BadBytecode {
+ JsrBytecode() { super("JSR"); }
+ }
+
protected int position, length;
protected int incoming; // the number of incoming branches.
protected BasicBlock[] exit; // null if the block is a leaf.
@@ -294,16 +298,18 @@
makeMark(marks, pos, jumps, size, true);
}
- /**
- * We ignore JSR since Java 6 or later does not allow it.
+ /*
+ * We could ignore JSR since Java 7 or later does not allow it.
+ * See The JVM Spec. Sec. 4.10.2.5.
*/
- protected void makeJsr(HashMap marks, int pos, int target, int size) {
- /*
+ protected void makeJsr(HashMap marks, int pos, int target, int size) throws BadBytecode {
+ /*
Mark to = makeMark(marks, target);
Mark next = makeMark(marks, pos + size);
BasicBlock[] jumps = makeArray(to.block, next.block);
makeMark(marks, pos, jumps, size, false);
- */
+ */
+ throw new JsrBytecode();
}
private BasicBlock[] makeBlocks(HashMap markTable) {
Modified: trunk/src/main/javassist/bytecode/stackmap/MapMaker.java
===================================================================
--- trunk/src/main/javassist/bytecode/stackmap/MapMaker.java 2012-11-08 15:37:05 UTC (rev 685)
+++ trunk/src/main/javassist/bytecode/stackmap/MapMaker.java 2012-11-15 15:06:33 UTC (rev 686)
@@ -82,7 +82,7 @@
/**
* Computes the stack map table of the given method and returns it.
* It returns null if the given method does not have to have a
- * stack map table.
+ * stack map table or it includes JSR.
*/
public static StackMapTable make(ClassPool classes, MethodInfo minfo)
throws BadBytecode
@@ -91,7 +91,14 @@
if (ca == null)
return null;
- TypedBlock[] blocks = TypedBlock.makeBlocks(minfo, ca, true);
+ TypedBlock[] blocks;
+ try {
+ blocks = TypedBlock.makeBlocks(minfo, ca, true);
+ }
+ catch (BasicBlock.JsrBytecode e) {
+ return null;
+ }
+
if (blocks == null)
return null;
@@ -109,7 +116,7 @@
/**
* Computes the stack map table for J2ME.
* It returns null if the given method does not have to have a
- * stack map table.
+ * stack map table or it includes JSR.
*/
public static StackMap make2(ClassPool classes, MethodInfo minfo)
throws BadBytecode
@@ -118,7 +125,14 @@
if (ca == null)
return null;
- TypedBlock[] blocks = TypedBlock.makeBlocks(minfo, ca, true);
+ TypedBlock[] blocks;
+ try {
+ blocks = TypedBlock.makeBlocks(minfo, ca, true);
+ }
+ catch (BasicBlock.JsrBytecode e) {
+ return null;
+ }
+
if (blocks == null)
return null;
Modified: trunk/src/main/javassist/compiler/MemberCodeGen.java
===================================================================
--- trunk/src/main/javassist/compiler/MemberCodeGen.java 2012-11-08 15:37:05 UTC (rev 685)
+++ trunk/src/main/javassist/compiler/MemberCodeGen.java 2012-11-15 15:06:33 UTC (rev 686)
@@ -590,7 +590,7 @@
if (mname.equals(MethodInfo.nameInit)) {
isSpecial = true;
if (declClass != targetClass)
- throw new CompileError("no such constructor");
+ throw new CompileError("no such constructor: " + targetClass.getName());
if (declClass != thisClass && AccessFlag.isPrivate(acc)) {
desc = getAccessibleConstructor(desc, declClass, minfo);
Modified: trunk/src/test/javassist/bytecode/StackMapTest.java
===================================================================
--- trunk/src/test/javassist/bytecode/StackMapTest.java 2012-11-08 15:37:05 UTC (rev 685)
+++ trunk/src/test/javassist/bytecode/StackMapTest.java 2012-11-15 15:06:33 UTC (rev 686)
@@ -13,6 +13,7 @@
import javassist.CodeConverter;
import javassist.CtClass;
import javassist.CtMethod;
+import javassist.CtNewConstructor;
import javassist.CtNewMethod;
import javassist.JvstTest;
import javassist.Loader;
@@ -779,6 +780,36 @@
assertTrue(two.subtypeOf(objarray));
}
+ public void testJsr() throws Exception {
+ CtClass cc = loader.makeClass("javassist.bytecode.StackMapTestJsrTest");
+ ClassFile cf = cc.getClassFile();
+ cf.setMajorVersion(ClassFile.JAVA_6);
+ ConstPool cp = cf.getConstPool();
+ MethodInfo mi = new MethodInfo(cp, "test", "()I");
+ mi.setAccessFlags(AccessFlag.PUBLIC);
+ Bytecode code = new Bytecode(cp, 1, 3);
+ code.addIconst(3);
+ code.addIstore(1);
+ code.add(Opcode.JSR);
+ code.addIndex(5);
+ code.addIload(1);
+ code.add(Opcode.IRETURN);
+ code.addAstore(2);
+ code.addRet(2);
+ CodeAttribute ca = code.toCodeAttribute();
+ mi.addAttribute(ca);
+ mi.rebuildStackMap(loader);
+ cf.addMethod(mi);
+ cc.addConstructor(CtNewConstructor.make("public StackMapTestJsrTest() {}", cc));
+ cc.addMethod(CtMethod.make("public static void main(String[] args) {"
+ + "new javassist.bytecode.StackMapTestJsrTest().test();"
+ + "}",
+ cc));
+ cc.writeFile();
+ // Object t1 = make(cc.getName());
+ // assertEquals(3, invoke(t1, "test"));
+ }
+
public void tstCtClassType() throws Exception {
ClassPool cp = ClassPool.getDefault();
CtClass cc = cp.get("javassist.CtClassType");
More information about the jboss-cvs-commits
mailing list