* <code>stack_map</code> attribute.
*
* <p>This is an entry in the attributes table of a Code attribute.
- * It was introduced by J2SE 6 for the process of verification by
+ * It was introduced by J2SE 6 for the verification by
* typechecking.
*
* @see StackMap
int data = 0;
if (tag == OBJECT || tag == UNINIT) {
data = ByteArray.readU16bit(info, pos + 2);
+ objectOrUninitialized(tag, data, pos + 2);
pos += 2;
}
tags[i] = tag;
if (tag == OBJECT || tag == UNINIT) {
data[i] = ByteArray.readU16bit(info, p + 1);
+ objectOrUninitialized(tag, data[i], p + 1);
p += 3;
}
else {
tags[i] = tag;
if (tag == OBJECT || tag == UNINIT) {
data[i] = ByteArray.readU16bit(info, pos);
+ objectOrUninitialized(tag, data[i], pos);
pos += 2;
}
}
return pos;
}
+
+ /**
+ * Invoked if <code>Object_variable_info</code>
+ * or <code>Uninitialized_variable_info</code> is visited.
+ *
+ * @param tag <code>OBJECT</code> or <code>UNINIT</code>.
+ * @param data the value of <code>cpool_index</code> or <code>offset</code>.
+ * @param pos the position of <code>cpool_index</code> or <code>offset</code>.
+ */
+ public void objectOrUninitialized(int tag, int data, int pos) {}
}
static class SimpleCopy extends Walker {
void shiftPc(int where, int gapSize, boolean exclusive)
throws BadBytecode
{
+ new OffsetShifter(this, where, gapSize).parse();
new Shifter(this, where, gapSize, exclusive).doit();
}
+ static class OffsetShifter extends Walker {
+ int where, gap;
+
+ public OffsetShifter(StackMapTable smt, int where, int gap) {
+ super(smt);
+ this.where = where;
+ this.gap = gap;
+ }
+
+ public void objectOrUninitialized(int tag, int data, int pos) {
+ if (tag == UNINIT)
+ if (where <= data)
+ ByteArray.write16bit(data + gap, info, pos);
+ }
+ }
+
static class Shifter extends Walker {
private StackMapTable stackMap;
int where, gap;
}
}
+ public void testConstructor3() throws Exception {
+ CtClass cc = loader.get("javassist.bytecode.StackMapTest$C4");
+ MethodInfo mi = cc.getDeclaredMethod("foo").getMethodInfo();
+ mi.rebuildStackMapForME(loader);
+ CodeIterator ci = mi.getCodeAttribute().iterator();
+ ci.insertGap(0, 7);
+ cc.writeFile();
+ Object t1 = make(cc.getName());
+ assertEquals(6, invoke(t1, "test"));
+ }
+
+ public static class C4 {
+ public int test() { return foo(3); }
+ public int foo(int i) {
+ String s = new String(i > 0 ? "pos" : "negative");
+ System.out.println("2nd stage");
+ int len = 0;
+ if (i > 0) {
+ String t = new String(i > 0 ? "pos" : "negative");
+ len = t.length();
+ }
+ return s.length() + len;
+ }
+ }
+
public void tstCtClassType() throws Exception {
ClassPool cp = ClassPool.getDefault();
CtClass cc = cp.get("javassist.CtClassType");