private void emit_div() { b.math(Opcode.DDIV); }
private void emit_plus() { b.math(Opcode.DADD); }
private void emit_minus() { b.math(Opcode.DSUB); }
private void emit_mult() { b.math(Opcode.DMUL); }
public void integerIncrement(LocalVariable local, int amount) { if (local == null) { throw new IllegalArgumentException("No local variable specified"); } if (-32768 <= amount && amount <= 32767) { mInstructions.new ShortIncrementInstruction(local, (short)amount); } else { // Amount can't possibly fit in a 16-bit value, so use regular // instructions instead. loadLocal(local); loadConstant(amount); math(Opcode.IADD); storeLocal(local); } }
builder.math(Opcode.FCMPG); Label label = builder.createLabel(); builder.ifZeroComparisonBranch(label, ">="); builder.loadLocal(a); builder.loadLocal(b); builder.math(Opcode.FCMPL); label = builder.createLabel(); builder.ifZeroComparisonBranch(label, "<="); builder.invoke(floatToIntBits); builder.convert(TypeDesc.INT, TypeDesc.LONG); builder.math(Opcode.LCMP); builder.loadLocal(b); done = builder.createLabel(); builder.math(Opcode.DCMPG); Label label = builder.createLabel(); builder.ifZeroComparisonBranch(label, ">="); builder.loadLocal(a); builder.loadLocal(b); builder.math(Opcode.DCMPL); label = builder.createLabel(); builder.ifZeroComparisonBranch(label, "<="); builder.loadLocal(b); builder.invoke(doubleToLongBits); builder.math(Opcode.LCMP);
public void integerIncrement(LocalVariable local, int amount) { if (local == null) { throw new IllegalArgumentException("No local variable specified"); } if (-32768 <= amount && amount <= 32767) { mInstructions.new ShortIncrementInstruction(local, (short)amount); } else { // Amount can't possibly fit in a 16-bit value, so use regular // instructions instead. loadLocal(local); loadConstant(amount); math(Opcode.IADD); storeLocal(local); } }
/** * Generates code to branch if a property is dirty. * * @param propNumber property number from all properties map * @param target branch target * @param when true, branch if dirty; when false, branch when not dirty */ private void branchIfDirty(CodeBuilder b, int propNumber, Label target, boolean branchIfDirty) { String stateFieldName = StorableGenerator.PROPERTY_STATE_FIELD_NAME + (propNumber >> 4); b.loadThis(); b.loadField(stateFieldName, TypeDesc.INT); int shift = (propNumber & 0xf) * 2; b.loadConstant(StorableGenerator.PROPERTY_STATE_MASK << shift); b.math(Opcode.IAND); b.loadConstant(StorableGenerator.PROPERTY_STATE_DIRTY << shift); b.ifComparisonBranch(target, branchIfDirty ? "==" : "!="); }
/** * Generates code to branch if a property is dirty. * * @param propNumber property number from all properties map * @param target branch target * @param when true, branch if dirty; when false, branch when not dirty */ private void branchIfDirty(CodeBuilder b, int propNumber, Label target, boolean branchIfDirty) { String stateFieldName = StorableGenerator.PROPERTY_STATE_FIELD_NAME + (propNumber >> 4); b.loadThis(); b.loadField(stateFieldName, TypeDesc.INT); int shift = (propNumber & 0xf) * 2; b.loadConstant(StorableGenerator.PROPERTY_STATE_MASK << shift); b.math(Opcode.IAND); b.loadConstant(StorableGenerator.PROPERTY_STATE_DIRTY << shift); b.ifComparisonBranch(target, branchIfDirty ? "==" : "!="); }
void successIfZeroComparisonElseFail(CodeBuilder b, RelOp relOp) { if (mSuccessLocation != null) { b.ifZeroComparisonBranch(mSuccessLocation, relOpToChoice(relOp)); fail(b); } else if (mFailLocation != null) { b.ifZeroComparisonBranch(mFailLocation, relOpToChoice(relOp.reverse())); success(b); } else { if (relOp == RelOp.NE) { b.returnValue(BOOLEAN); } else if (relOp == RelOp.EQ) { b.loadConstant(1); b.math(Opcode.IAND); b.loadConstant(1); b.math(Opcode.IXOR); b.returnValue(BOOLEAN); } else { Label success = b.createLabel(); b.ifZeroComparisonBranch(success, relOpToChoice(relOp)); b.loadConstant(false); b.returnValue(BOOLEAN); success.setLocation(); b.loadConstant(true); b.returnValue(BOOLEAN); } } }
private void defineExtractAllMethod(Map<JDBCStorableProperty<S>, Class<?>> lobLoaderMap) throws SupportException { MethodInfo mi = mClassFile.addMethod (Modifiers.PRIVATE, EXTRACT_ALL_METHOD_NAME, null, new TypeDesc[] {TypeDesc.forClass(ResultSet.class), TypeDesc.INT}); CodeBuilder b = new CodeBuilder(mi); defineExtract(b, b.getParameter(0), b.getParameter(1), null, mInfo.getPrimaryKeyProperties().values(), lobLoaderMap); // Invoke extract data method to do the rest. b.loadThis(); // Load the ResultSet var. b.loadLocal(b.getParameter(0)); // The offset variable has already been incremented by code generated // by defineExtract, except for the last property. b.loadLocal(b.getParameter(1)); b.loadConstant(1); b.math(Opcode.IADD); b.loadNull(); // No Lobs to update b.invokePrivate(EXTRACT_DATA_METHOD_NAME, null, new TypeDesc[] {TypeDesc.forClass(ResultSet.class), TypeDesc.INT, TypeDesc.forClass(Lob.class).toArrayType()}); b.returnVoid(); }
private void defineExtractAllMethod(Map<JDBCStorableProperty<S>, Class<?>> lobLoaderMap) throws SupportException { MethodInfo mi = mClassFile.addMethod (Modifiers.PRIVATE, EXTRACT_ALL_METHOD_NAME, null, new TypeDesc[] {TypeDesc.forClass(ResultSet.class), TypeDesc.INT}); CodeBuilder b = new CodeBuilder(mi); defineExtract(b, b.getParameter(0), b.getParameter(1), null, mInfo.getPrimaryKeyProperties().values(), lobLoaderMap); // Invoke extract data method to do the rest. b.loadThis(); // Load the ResultSet var. b.loadLocal(b.getParameter(0)); // The offset variable has already been incremented by code generated // by defineExtract, except for the last property. b.loadLocal(b.getParameter(1)); b.loadConstant(1); b.math(Opcode.IADD); b.loadNull(); // No Lobs to update b.invokePrivate(EXTRACT_DATA_METHOD_NAME, null, new TypeDesc[] {TypeDesc.forClass(ResultSet.class), TypeDesc.INT, TypeDesc.forClass(Lob.class).toArrayType()}); b.returnVoid(); }
/** * Sets the version property to its initial uninitialized state. */ private void unsetVersionProperty(CodeBuilder b) throws SupportException { StorableProperty<?> property = mInfo.getVersionProperty(); // Set the property state to uninitialized. { String stateFieldName = StorableGenerator.PROPERTY_STATE_FIELD_NAME + (property.getNumber() >> 4); b.loadThis(); b.loadThis(); b.loadField(stateFieldName, TypeDesc.INT); int shift = (property.getNumber() & 0xf) * 2; b.loadConstant(~(StorableGenerator.PROPERTY_STATE_MASK << shift)); b.math(Opcode.IAND); b.storeField(stateFieldName, TypeDesc.INT); } // Zero the property value. TypeDesc type = TypeDesc.forClass(property.getType()); b.loadThis(); CodeBuilderUtil.blankValue(b, type); b.storeField(property.getName(), type); }
/** * Sets the version property to its initial uninitialized state. */ private void unsetVersionProperty(CodeBuilder b) throws SupportException { StorableProperty<?> property = mInfo.getVersionProperty(); // Set the property state to uninitialized. { String stateFieldName = StorableGenerator.PROPERTY_STATE_FIELD_NAME + (property.getNumber() >> 4); b.loadThis(); b.loadThis(); b.loadField(stateFieldName, TypeDesc.INT); int shift = (property.getNumber() & 0xf) * 2; b.loadConstant(~(StorableGenerator.PROPERTY_STATE_MASK << shift)); b.math(Opcode.IAND); b.storeField(stateFieldName, TypeDesc.INT); } // Zero the property value. TypeDesc type = TypeDesc.forClass(property.getType()); b.loadThis(); CodeBuilderUtil.blankValue(b, type); b.storeField(property.getName(), type); }
private void addPropertyAppendCall(CodeBuilder b, StorableProperty property, LocalVariable commaCountVar) { Label skipPrint = b.createLabel(); // Check if independent property is supported, and skip if not. if (property.isIndependent()) { addSkipIndependent(b, null, property, skipPrint); } int ordinal = property.getNumber(); // Check if property is initialized, and skip if not. b.loadThis(); b.loadField(PROPERTY_STATE_FIELD_NAME + (ordinal >> 4), TypeDesc.INT); b.loadConstant(PROPERTY_STATE_MASK << ((ordinal & 0xf) * 2)); b.math(Opcode.IAND); b.ifZeroComparisonBranch(skipPrint, "=="); b.integerIncrement(commaCountVar, 1); b.loadLocal(commaCountVar); Label noComma = b.createLabel(); b.ifZeroComparisonBranch(noComma, "=="); b.loadConstant(", "); invokeAppend(b, TypeDesc.STRING); noComma.setLocation(); addPropertyAppendCall(b, property); skipPrint.setLocation(); }
private void addPropertyAppendCall(CodeBuilder b, StorableProperty property, LocalVariable commaCountVar) { Label skipPrint = b.createLabel(); // Check if independent property is supported, and skip if not. if (property.isIndependent()) { addSkipIndependent(b, null, property, skipPrint); } int ordinal = property.getNumber(); // Check if property is initialized, and skip if not. b.loadThis(); b.loadField(PROPERTY_STATE_FIELD_NAME + (ordinal >> 4), TypeDesc.INT); b.loadConstant(PROPERTY_STATE_MASK << ((ordinal & 0xf) * 2)); b.math(Opcode.IAND); b.ifZeroComparisonBranch(skipPrint, "=="); b.integerIncrement(commaCountVar, 1); b.loadLocal(commaCountVar); Label noComma = b.createLabel(); b.ifZeroComparisonBranch(noComma, "=="); b.loadConstant(", "); invokeAppend(b, TypeDesc.STRING); noComma.setLocation(); addPropertyAppendCall(b, property); skipPrint.setLocation(); }