From: chiba Date: Sat, 6 Oct 2012 14:47:31 +0000 (+0000) Subject: fixed JASSIST-160 X-Git-Tag: rel_3_17_1_ga~17 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3ab8b841312f792dc64016800193cb1b0368a9f9;p=javassist.git fixed JASSIST-160 git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@672 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- diff --git a/Readme.html b/Readme.html index 353cb4b2..72933367 100644 --- a/Readme.html +++ b/Readme.html @@ -7,7 +7,7 @@

Javassist version 3

-

Copyright (C) 1999-2011 by Shigeru Chiba, All rights reserved.

+

Copyright (C) 1999-2012 by Shigeru Chiba, All rights reserved.


diff --git a/javassist.jar b/javassist.jar index 719a322e..ec0b29a9 100644 Binary files a/javassist.jar and b/javassist.jar differ diff --git a/src/main/javassist/bytecode/CodeIterator.java b/src/main/javassist/bytecode/CodeIterator.java index 0c5db6ff..a1d882e0 100644 --- a/src/main/javassist/bytecode/CodeIterator.java +++ b/src/main/javassist/bytecode/CodeIterator.java @@ -27,10 +27,14 @@ import java.util.ArrayList; * the following code substitutes the NOP instruction for the first * instruction of the method: * - *
CodeAttribute ca = method.getMethodInfo().getCodeAttribute();
+ * 
+ * CodeAttribute ca = method.getMethodInfo().getCodeAttribute();
  * CodeIterator ci = ca.iterator();
  * ci.writeByte(Opcode.NOP, 0);
* + *

To visit every instruction, call {@link #next()} on a CodeIterator. + * It returns the index of the first byte of the next instruction. + * *

If there are multiple CodeIterators referring to the * same Code_attribute, then inserting a gap by one * CodeIterator will break the other diff --git a/src/main/javassist/bytecode/stackmap/Tracer.java b/src/main/javassist/bytecode/stackmap/Tracer.java index 1bacd09c..e5216165 100644 --- a/src/main/javassist/bytecode/stackmap/Tracer.java +++ b/src/main/javassist/bytecode/stackmap/Tracer.java @@ -803,7 +803,9 @@ public abstract class Tracer implements TypeTag { String className = cpool.getMethodrefClassName(i); TypeData target = stackTypes[--stackTop]; if (target instanceof TypeData.UninitTypeVar && target.isUninit()) - constructorCalled((TypeData.UninitTypeVar)target); + constructorCalled(target, ((TypeData.UninitTypeVar)target).offset()); + else if (target instanceof TypeData.UninitData) + constructorCalled(target, ((TypeData.UninitData)target).offset()); target.setType(className, classPool); } @@ -814,9 +816,10 @@ public abstract class Tracer implements TypeTag { /* This is a constructor call on an uninitialized object. * Sets flags of other references to that object. + * + * @param offset the offset where the object has been created. */ - private void constructorCalled(TypeData.UninitTypeVar target) { - int offset = target.offset(); + private void constructorCalled(TypeData target, int offset) { target.constructorCalled(offset); for (int i = 0; i < stackTop; i++) stackTypes[i].constructorCalled(offset); diff --git a/src/main/javassist/bytecode/stackmap/TypeData.java b/src/main/javassist/bytecode/stackmap/TypeData.java index d77f6a55..6428335d 100644 --- a/src/main/javassist/bytecode/stackmap/TypeData.java +++ b/src/main/javassist/bytecode/stackmap/TypeData.java @@ -745,11 +745,13 @@ public abstract class TypeData { public void setType(String typeName, ClassPool cp) throws BadBytecode { super.setType(typeName, cp); - initialized = true; + // initialized = true; } public String toString() { return "uninit:" + getName() + "@" + offset; } + public int offset() { return offset; } + public void constructorCalled(int offset) { if (offset == this.offset) initialized = true; diff --git a/src/test/javassist/bytecode/StackMapTest.java b/src/test/javassist/bytecode/StackMapTest.java index 4b9339d7..4714f7aa 100644 --- a/src/test/javassist/bytecode/StackMapTest.java +++ b/src/test/javassist/bytecode/StackMapTest.java @@ -529,6 +529,7 @@ public class StackMapTest extends TestCase { public static class T8dd { java.util.List foo(String s) { return new java.util.ArrayList(); } } + public static class T8d { static T8dd helper() { return new T8dd(); } int integer() { return 9; } @@ -588,6 +589,39 @@ public class StackMapTest extends TestCase { } } + public void testInnerClass() throws Exception { + CtClass cc = loader.get("javassist.bytecode.StackMapTest$T9"); + CtClass par = loader.get("javassist.bytecode.StackMapTest$T9$Parent"); + CtClass in = loader.get("javassist.bytecode.StackMapTest$T9$In"); + rebuildStackMaps2(cc); + rebuildStackMaps2(par); + rebuildStackMaps2(in); + cc.writeFile(); + in.writeFile(); + par.writeFile(); + Object t1 = make(cc.getName()); + assertEquals(19, invoke(t1, "test")); + } + + public static class T9 { + class Parent { + int f; + Parent(int i) { f = i; } + } + class In extends Parent { + int value; + public In(int i) { + super(i > 0 ? 10 : 20); + value = i; + } + } + + public int test() { + In in = new In(9); + return in.value + in.f; + } + } + public void tstCtClassType() throws Exception { ClassPool cp = ClassPool.getDefault(); CtClass cc = cp.get("javassist.CtClassType"); diff --git a/src/test/test4/InvokeDyn.java b/src/test/test4/InvokeDyn.java index 5e5f0c01..fbcba64d 100644 --- a/src/test/test4/InvokeDyn.java +++ b/src/test/test4/InvokeDyn.java @@ -4,11 +4,23 @@ import java.lang.invoke.*; public class InvokeDyn { public static int test9(int i, String s) { return 9; } + public int test8(int i, String s) { return 8; } - public static CallSite boot(MethodHandles.Lookup caller, String name, MethodType type) throws NoSuchMethodException, IllegalAccessException { + public static CallSite boot(MethodHandles.Lookup caller, String name, MethodType type) + throws NoSuchMethodException, IllegalAccessException + { MethodHandles.Lookup lookup = MethodHandles.lookup(); Class thisClass = lookup.lookupClass(); MethodHandle method = lookup.findStatic(thisClass, "test9", MethodType.methodType(int.class, int.class, String.class)); return new ConstantCallSite(method); } + + public CallSite boot2(MethodHandles.Lookup caller, String name, MethodType type) + throws NoSuchMethodException, IllegalAccessException + { + MethodHandles.Lookup lookup = MethodHandles.lookup(); + Class thisClass = lookup.lookupClass(); + MethodHandle method = lookup.findVirtual(thisClass, "test8", MethodType.methodType(int.class, int.class, String.class)); + return new ConstantCallSite(method.asType(MethodType.methodType(int.class, Object.class, int.class, String.class))); + } }