store = bc.declareMethod("store", void.class,
new Class[]{ OpenJPAStateManager.class, BitSet.class });
else
store = bc.declareMethod("store", void.class,
new Class[]{ OpenJPAStateManager.class });
Code code = store.getCode(true);
// initialize();
code.aload().setThis();
code.invokevirtual().setMethod("initialize", void.class, null);
// storeVersion(sm);
code.aload().setThis();
code.aload().setParam(0);
code.invokevirtual().setMethod("storeVersion", void.class,
new Class[]{ OpenJPAStateManager.class });
// storeImplData(sm);
code.aload().setThis();
code.aload().setParam(0);
code.invokevirtual().setMethod("storeImplData", void.class,
new Class[]{ OpenJPAStateManager.class });
FieldMetaData[] fmds = meta.getFields();
Collection jumps = new LinkedList();
int objectCount = 0;
for (int i = 0; i < fmds.length; i++) {
if (fields) {
// if (fields != null && fields.get(index))
setTarget(code.aload().setParam(1), jumps);
jumps.add(code.ifnull());
code.aload().setParam(1);
code.constant().setValue(i);
code.invokevirtual().setMethod(BitSet.class, "get",
boolean.class, new Class[]{ int.class });
jumps.add(code.ifeq());
} else {
// if (sm.getLoaded().get(index)))
setTarget(code.aload().setParam(0), jumps);
code.invokeinterface().setMethod(OpenJPAStateManager.class,
"getLoaded", BitSet.class, null);
code.constant().setValue(i);
code.invokevirtual().setMethod(BitSet.class, "get",
boolean.class, new Class[]{ int.class });
jumps.add(code.ifeq());
}
addStore(bc, code, fmds[i], objectCount);
if (usesIntermediate(fmds[i])) {
JumpInstruction elseIns = code.go2();
// else if (!loaded.get(index))
setTarget(code.aload().setThis(), jumps);
jumps.add(elseIns);
code.getfield().setField("loaded", BitSet.class);
code.constant().setValue(i);
code.invokevirtual().setMethod(BitSet.class, "get",
boolean.class, new Class[]{ int.class });
jumps.add(code.ifne());
// Object val = sm.getIntermediate(index);
// if (val != null)
// objects[objectCount] = val;
code.aload().setParam(0);
code.constant().setValue(i);
code.invokeinterface().setMethod(OpenJPAStateManager.class,
"getIntermediate", Object.class, new Class[]{ int.class });
int local = code.getNextLocalsIndex();
code.astore().setLocal(local);
code.aload().setLocal(local);
jumps.add(code.ifnull());
code.aload().setThis();
code.getfield().setField("objects", Object[].class);
code.constant().setValue(objectCount);
code.aload().setLocal(local);
code.aastore();
}
if (replaceType(fmds[i]) >= JavaTypes.OBJECT)
objectCount++;
}
setTarget(code.vreturn(), jumps);
code.calculateMaxLocals();
code.calculateMaxStack();
}