/** * Equivalent to <code>setLocal (0).setType (Object.class)</code>; the * <code>this</code> ptr is always passed in local variable 0. * * @return this instruction, for method chaining */ public LoadInstruction setThis() { return (LoadInstruction) setLocal(0).setType(Object.class); }
/** * Add the {@link Instruction}s to load the instance to modify onto the * stack, and return it. If <code>forStatic</code> is set, then * <code>code</code> is in an accessor method or another static method; * otherwise, it is in one of the PC-specified methods. * * @return the first instruction added to <code>code</code>. */ private Instruction loadManagedInstance(Code code, boolean forStatic) { if (_meta.getAccessType() == ClassMetaData.ACCESS_FIELD && forStatic) return code.aload().setParam(0); return code.aload().setThis(); }
/** * Load an int local variable onto the stack. This instruction will * result in a <code>nop</code> until its local index is set. */ public LoadInstruction iload() { return (LoadInstruction) addInstruction(new LoadInstruction(this). setType(int.class)); }
void calculateOpcode() { // taken care of when setting type setType(getTypeName()); }
throws NoSuchMethodException { code.aload().setThis(); code.constant().setValue(fmd.getIndex()); Class type = fmd.getDeclaredType(); code.xload().setLocal(val).setType(type); if (param == -1) { loadManagedInstance(code, false); addGetManagedValueCode(code, fmd); } else { code.xload().setParam(param).setType(type);
Code code = method.getCode(true); code.aload().setParam(0); TableSwitchInstruction tabins = code.tableswitch(); tabins.setLow(0); tabins.addTarget(code.aload().setThis()); if (typeCode >= JavaTypes.OBJECT) { code.aload().setThis(); code.getfield().setField("objects", Object[].class); JumpInstruction ifins = code.ifnonnull(); code.aload().setThis(); code.constant().setValue(totalObjects); code.anewarray().setType(Object.class); ifins.setTarget(code.aload().setThis()); code.getfield().setField("objects", Object[].class); code.constant().setValue(objectCount); code.aload().setParam(1); code.aastore(); objectCount++; load.setType(type); load.setParam(1); code.putfield().setField("field" + i, type);
/** * Copy bean properties. Called with the copy object on the stack. Must * return with the copy object on the stack. */ private void copyProperties(Class type, Code code) { int copy = code.getNextLocalsIndex(); code.astore().setLocal(copy); Method[] meths = type.getMethods(); Method getter; int mods; for (int i = 0; i < meths.length; i++) { mods = meths[i].getModifiers(); if (!Modifier.isPublic(mods) || Modifier.isStatic(mods)) continue; if (!startsWith(meths[i].getName(), "set") || meths[i].getParameterTypes().length != 1) continue; getter = findGetter(type, meths[i]); if (getter == null) continue; // copy.setXXX(orig.getXXX()); code.aload().setLocal(copy); code.aload().setParam(0); code.checkcast().setType(type); code.invokevirtual().setMethod(getter); code.invokevirtual().setMethod(meths[i]); } code.aload().setLocal(copy); }
public TypedInstruction setType(String type) { type = mapType(type, _mappings, true); int local = getLocal(); int len = getLength(); setOpcode(Constants.NOP); } else { switch (type.charAt(0)) { case 'i': setOpcode((local > 3) ? Constants.ILOAD : (Constants.ILOAD0 + local)); break; case 'l': setOpcode((local > 3) ? Constants.LLOAD : (Constants.LLOAD0 + local)); break; case 'f': setOpcode((local > 3) ? Constants.FLOAD : (Constants.FLOAD0 + local)); break; case 'd': setOpcode((local > 3) ? Constants.DLOAD : (Constants.DLOAD0 + local)); break; default: setOpcode((local > 3) ? Constants.ALOAD : (Constants.ALOAD0 + local)); if (len != getLength())
private void addNotifyAccess(Code code, FieldMetaData fmd) { // PCHelper.accessingField(this, <absolute-index>); code.aload().setThis(); code.constant().setValue(fmd.getIndex()); code.invokestatic().setMethod(RedefinitionHelper.class, "accessingField", void.class, new Class[] { Object.class, int.class }); }
void calculateLocal() { switch (getOpcode()) { case Constants.ILOAD0: case Constants.LLOAD0: case Constants.DLOAD0: case Constants.ALOAD0: setLocal(0); break; case Constants.ILOAD1: case Constants.DLOAD1: case Constants.ALOAD1: setLocal(1); break; case Constants.ILOAD2: case Constants.DLOAD2: case Constants.ALOAD2: setLocal(2); break; case Constants.ILOAD3: case Constants.DLOAD3: case Constants.ALOAD3: setLocal(3); break;
public void enterLoadInstruction(LoadInstruction obj) { _out.print("<" + obj.getLocal() + ">"); }
private void replaceNewEmbeddedPCData(BCClass bc) { BCMethod meth = bc.declareMethod("newEmbeddedPCData", AbstractPCData.class, new Class[]{ OpenJPAStateManager.class }); Code code = meth.getCode(true); // return new DataCachePCDataImpl(sm.getObjectId(), sm.getMetaData()); code.anew().setType(DataCachePCDataImpl.class); code.dup(); code.aload().setParam(0); code.invokeinterface().setMethod(OpenJPAStateManager.class, "getId", Object.class, null); code.aload().setParam(0); code.invokeinterface().setMethod(OpenJPAStateManager.class, "getMetaData", ClassMetaData.class, null); code.invokespecial().setMethod(DataCachePCDataImpl.class, "<init>", void.class, new Class[] { Object.class, ClassMetaData.class }); code.areturn(); code.calculateMaxLocals(); code.calculateMaxStack(); }
/** * Load a local variable onto the stack. This instruction will result * in a <code>nop</code> until its type and local index are set. */ public LoadInstruction xload() { return (LoadInstruction) addInstruction(new LoadInstruction(this)); }
throws NoSuchMethodException { code.aload().setThis(); code.constant().setValue(fmd.getIndex()); Class type = fmd.getDeclaredType(); code.xload().setLocal(val).setType(type); if (param == -1) { loadManagedInstance(code, false); addGetManagedValueCode(code, fmd); } else { code.xload().setParam(param).setType(type);
Code code = method.getCode(true); code.aload().setParam(0); TableSwitchInstruction tabins = code.tableswitch(); tabins.setLow(0); tabins.addTarget(code.aload().setThis()); if (typeCode >= JavaTypes.OBJECT) { code.aload().setThis(); code.getfield().setField("objects", Object[].class); JumpInstruction ifins = code.ifnonnull(); code.aload().setThis(); code.constant().setValue(totalObjects); code.anewarray().setType(Object.class); ifins.setTarget(code.aload().setThis()); code.getfield().setField("objects", Object[].class); code.constant().setValue(objectCount); code.aload().setParam(1); code.aastore(); objectCount++; load.setType(type); load.setParam(1); code.putfield().setField("field" + i, type);
/** * Copy bean properties. Called with the copy object on the stack. Must * return with the copy object on the stack. */ private void copyProperties(Class type, Code code) { int copy = code.getNextLocalsIndex(); code.astore().setLocal(copy); Method[] meths = type.getMethods(); Method getter; int mods; for (int i = 0; i < meths.length; i++) { mods = meths[i].getModifiers(); if (!Modifier.isPublic(mods) || Modifier.isStatic(mods)) continue; if (!startsWith(meths[i].getName(), "set") || meths[i].getParameterTypes().length != 1) continue; getter = findGetter(type, meths[i]); if (getter == null) continue; // copy.setXXX(orig.getXXX()); code.aload().setLocal(copy); code.aload().setParam(0); code.checkcast().setType(type); code.invokevirtual().setMethod(getter); code.invokevirtual().setMethod(meths[i]); } code.aload().setLocal(copy); }