git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@686 30ef5769-5b8d-40dd-aea6-55b5d6557bb3tags/rel_3_17_1_ga
@@ -281,6 +281,12 @@ see javassist.Dump. | |||
<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. |
@@ -69,7 +69,7 @@ public abstract class CtClass { | |||
/** | |||
* 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. |
@@ -23,10 +23,14 @@ import java.util.ArrayList; | |||
/** | |||
* 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 @@ public class BasicBlock { | |||
makeMark(marks, pos, jumps, size, true); | |||
} | |||
/** | |||
* We ignore JSR since Java 6 or later does not allow it. | |||
*/ | |||
protected void makeJsr(HashMap marks, int pos, int target, int size) { | |||
/* | |||
* 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) 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) { |
@@ -82,7 +82,7 @@ public class MapMaker extends Tracer { | |||
/** | |||
* 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 @@ public class MapMaker extends Tracer { | |||
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 @@ public class MapMaker extends Tracer { | |||
/** | |||
* 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 @@ public class MapMaker extends Tracer { | |||
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; | |||
@@ -590,7 +590,7 @@ public class MemberCodeGen extends CodeGen { | |||
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); |
@@ -13,6 +13,7 @@ import javassist.ClassPool; | |||
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 @@ public class StackMapTest extends TestCase { | |||
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"); |