git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@672 30ef5769-5b8d-40dd-aea6-55b5d6557bb3tags/rel_3_17_1_ga
@@ -7,7 +7,7 @@ | |||
<h1>Javassist version 3</h1> | |||
<h3>Copyright (C) 1999-2011 by Shigeru Chiba, All rights reserved.</h3> | |||
<h3>Copyright (C) 1999-2012 by Shigeru Chiba, All rights reserved.</h3> | |||
<p><br></p> | |||
@@ -27,10 +27,14 @@ import java.util.ArrayList; | |||
* the following code substitutes the <code>NOP</code> instruction for the first | |||
* instruction of the method: | |||
* | |||
* <pre>CodeAttribute ca = method.getMethodInfo().getCodeAttribute(); | |||
* <pre> | |||
* CodeAttribute ca = method.getMethodInfo().getCodeAttribute(); | |||
* CodeIterator ci = ca.iterator(); | |||
* ci.writeByte(Opcode.NOP, 0);</pre> | |||
* | |||
* <p>To visit every instruction, call {@link #next()} on a <code>CodeIterator</code>. | |||
* It returns the index of the first byte of the next instruction. | |||
* | |||
* <p>If there are multiple <code>CodeIterator</code>s referring to the | |||
* same <code>Code_attribute</code>, then inserting a gap by one | |||
* <code>CodeIterator</code> will break the other |
@@ -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); |
@@ -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; |
@@ -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"); |
@@ -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))); | |||
} | |||
} |