<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>
* 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
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);
}
/* 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);
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;
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; }
}
}
+ 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");
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)));
+ }
}