Example usage for org.objectweb.asm.tree InsnList add

List of usage examples for org.objectweb.asm.tree InsnList add

Introduction

In this page you can find the example usage for org.objectweb.asm.tree InsnList add.

Prototype

public void add(final InsnList insnList) 

Source Link

Document

Adds the given instructions to the end of this list.

Usage

From source file:gemlite.core.internal.asm.serialize.dataserialize.DataSFieldProcessor.java

License:Apache License

/***
 * @param owner//ww w .jav  a  2s  .  co  m
 * @param fn
 * @param inst
 */
private void initToMethodStack(String owner, FieldNode fn, InsnList inst) {
    inst.add(new VarInsnNode(ALOAD, 0));
    inst.add(new FieldInsnNode(GETFIELD, owner, fn.name, fn.desc));
    inst.add(new VarInsnNode(ALOAD, 1));
}

From source file:gemlite.core.internal.asm.serialize.dataserialize.DataSFieldProcessor.java

License:Apache License

/***
 * mv.visitMethodInsn(INVOKESTATIC, "com/gemstone/gemfire/DataSerializer",
 * "writeLong", "(Ljava/lang/Long;Ljava/io/DataOutput;)V", false);
 * /*from   w w w  .ja v  a2  s.  c o m*/
 * @param fn
 * @param inst
 * @param dsi
 */
private void writeValue(FieldNode fn, InsnList inst, DataSItem dsi) {
    inst.add(AsmHelper.newMethodInsnNode(INVOKESTATIC, "com/gemstone/gemfire/DataSerializer", dsi.toMethod,
            "(" + fn.desc + "Ljava/io/DataOutput;)V", false));
}

From source file:gemlite.core.internal.asm.serialize.dataserialize.DataSFieldProcessor.java

License:Apache License

/***
 * /*from  w  w w . j  ava 2  s  . co  m*/
 * @param inst
 * @param dsi
 */
private void fieldValueIsNull(FieldNode fn, InsnList inst) {
    if ("Ljava/lang/Integer;".equals(fn.desc)) {
        inst.add(new InsnNode(ICONST_0));
        inst.add(AsmHelper.newMethodInsnNode(INVOKESTATIC, "java/lang/Integer", "valueOf",
                "(J)Ljava/lang/Integer;", false));
    } else if ("Ljava/lang/Long;".equals(fn.desc)) {
        inst.add(new InsnNode(LCONST_0));
        inst.add(AsmHelper.newMethodInsnNode(INVOKESTATIC, "java/lang/Lang", "valueOf", "(J)Ljava/lang/Long;",
                false));
    } else if ("Ljava/lang/Double;".equals(fn.desc)) {
        inst.add(new InsnNode(DCONST_0));
        inst.add(AsmHelper.newMethodInsnNode(INVOKESTATIC, "java/lang/Double", "valueOf",
                "(J)Ljava/lang/Double;", false));
    } else if ("Ljava/lang/Short;".equals(fn.desc)) {
        inst.add(new InsnNode(DCONST_0));
        inst.add(AsmHelper.newMethodInsnNode(INVOKESTATIC, "java/lang/Short", "valueOf", "(J)Ljava/lang/Short;",
                false));
    }
}

From source file:gemlite.core.internal.asm.serialize.dataserialize.DataSFieldProcessor.java

License:Apache License

public void toMethod(String owner, FieldNode fn, InsnList inst) {
    initToMethodStack(owner, fn, inst);//from w ww .  j av a2  s  .co  m

    DataSItem dsi = DataSRegistry.getDataSItem(fn.desc);
    if (!dsi.hasNullMethod) {
        writeValue(fn, inst, dsi);
    } else {
        LabelNode elseLabel = new LabelNode();
        LabelNode endLabel = new LabelNode();

        // if 
        inst.add(new VarInsnNode(ALOAD, 0));
        inst.add(new FieldInsnNode(GETFIELD, owner, fn.name, fn.desc));
        inst.add(new JumpInsnNode(IFNULL, elseLabel));
        // ?
        initToMethodStack(owner, fn, inst);
        writeValue(fn, inst, dsi);
        // ???
        inst.add(new JumpInsnNode(GOTO, endLabel));
        // ?
        inst.add(elseLabel);
        fieldValueIsNull(fn, inst);
        inst.add(new VarInsnNode(ALOAD, 1));
        writeValue(fn, inst, dsi);
    }
}

From source file:gemlite.core.internal.asm.serialize.dataserialize.DataSFieldProcessor.java

License:Apache License

/***
 * mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1);
 * mv.visitMethodInsn(INVOKESTATIC, "com/gemstone/gemfire/DataSerializer",
 * dsi.fromMethod, "(Ljava/io/DataInput;)" + dsi.fieldDesc, false);
 * mv.visitFieldInsn(PUTFIELD, internalClassName, pd.getName(),
 * dsi.fieldDesc);/*from   w  ww .j  a v a 2s  .  c  o  m*/
 * 
 * @param owner
 * @param fn
 * @param inst
 */
public void fromMethod(String owner, FieldNode fn, InsnList inst) {

    inst.add(new VarInsnNode(ALOAD, 0));
    inst.add(new VarInsnNode(ALOAD, 1));

    DataSItem dsi = DataSRegistry.getDataSItem(fn.desc);
    inst.add(AsmHelper.newMethodInsnNode(INVOKESTATIC, "com/gemstone/gemfire/DataSerializer", dsi.fromMethod,
            "(Ljava/io/DataInput;)" + fn.desc, false));
    inst.add(new FieldInsnNode(PUTFIELD, owner, fn.name, fn.desc));
}

From source file:gemlite.core.internal.asm.serialize.DataSerializeHelper.java

License:Apache License

private void implementInterface(ClassNode cn) {
    MethodNode toMethod = new MethodNode(ACC_PUBLIC, "toData", "(Ljava/io/DataOutput;)V", null,
            new String[] { "java/io/IOException" });
    InsnList instToMethod = toMethod.instructions;

    MethodNode fromMethod = new MethodNode(ACC_PUBLIC, "fromData", "(Ljava/io/DataInput;)V", null,
            new String[] { "java/io/IOException", "java/lang/ClassNotFoundException" });
    InsnList instFromMethod = fromMethod.instructions;
    for (int i = 0; i < cn.fields.size(); i++) {
        FieldNode fn = (FieldNode) cn.fields.get(i);

        fp.toMethod(cn.name, fn, instToMethod);
        fp.fromMethod(cn.name, fn, instFromMethod);
    }/*from ww  w  .  j  a v  a 2s .  c o  m*/
    instToMethod.add(new InsnNode(RETURN));
    cn.methods.add(toMethod);

    instFromMethod.add(new InsnNode(RETURN));
    cn.methods.add(fromMethod);

    //    if (DomainMojoHelper.log().isDebugEnabled())
    //      DomainMojoHelper.log().debug(cn.name + " add toData and fromData method.");
}

From source file:gemlite.core.internal.asm.serialize.pdxserialize.PdxSFieldProcessor.java

License:Apache License

/***
 * /* w w  w . j  a  v  a2  s . c  o  m*/
 * 
 * @param fn
 * @param inst
 * @param dsi
 */
private void writeValue(String owner, FieldNode fn, InsnList inst, PdxSItem dsi) {
    String desc = new StringBuffer("(Ljava/lang/String;").append(fn.desc)
            .append(")Lcom/gemstone/gemfire/pdx/PdxWriter;").toString();

    inst.add(new VarInsnNode(ALOAD, 1));
    inst.add(new LdcInsnNode(fn.name));
    inst.add(new VarInsnNode(ALOAD, 0));
    inst.add(new FieldInsnNode(GETFIELD, owner, fn.name, fn.desc));

    // add INVOKEVIRTUAL method
    if (PdxConstants.TYPE_BYTECODE_BYTE_B.equals(fn.desc)) // data type ->byte
        inst.add(AsmHelper.newMethodInsnNode(INVOKEVIRTUAL, PdxConstants.TYPE_BYTECODE_BYTE, "byteValue",
                fn.desc, false));
    else if (PdxConstants.TYPE_BYTECODE_BOOL_Z.equals(fn.desc)) // data type ->
                                                                // boolean
        inst.add(AsmHelper.newMethodInsnNode(INVOKEVIRTUAL, PdxConstants.TYPE_BYTECODE_BOOL, "booleanValue",
                fn.desc, false));

    inst.add(AsmHelper.newMethodInsnNode(INVOKEINTERFACE, PdxConstants.PDX_WRITER_VALUE, dsi.toMethod, desc,
            true));
    inst.add(new InsnNode(POP));
}

From source file:gemlite.core.internal.asm.serialize.pdxserialize.PdxSFieldProcessor.java

License:Apache License

/***
 * /*from   w w w  .  j av a2s . co  m*/
 * 
 * @param owner
 * @param fn
 * @param inst
 */
public void fromMethod(String owner, FieldNode fn, InsnList inst) {
    PdxSItem dsi = PdxSRegistry.getDataSItem(fn.desc);
    if (dsi == null) {
        LogUtil.getAppLog().error("Can't get dataSItem {}.", fn.desc);
        return;
    }

    String desc = "(Ljava/lang/String;)" + fn.desc;

    inst.add(new VarInsnNode(ALOAD, 0));
    inst.add(new VarInsnNode(ALOAD, 1));
    inst.add(new LdcInsnNode(fn.name));

    inst.add(AsmHelper.newMethodInsnNode(INVOKEINTERFACE, PdxConstants.PDX_READER_VALUE, dsi.fromMethod, desc,
            true));

    // add INVOKEVIRTUAL method
    if (PdxConstants.TYPE_BYTECODE_BYTE_B.equals(fn.desc)) // data type ->byte
        inst.add(AsmHelper.newMethodInsnNode(INVOKESTATIC, PdxConstants.TYPE_BYTECODE_BYTE,
                PdxConstants.VALUE_OF, "(" + fn.desc + ")Ljava/lang/Byte;", false));
    else if (PdxConstants.TYPE_BYTECODE_BOOL_Z.equals(fn.desc)) // data type ->
                                                                // boolean
        inst.add(AsmHelper.newMethodInsnNode(INVOKESTATIC, PdxConstants.TYPE_BYTECODE_BOOL,
                PdxConstants.VALUE_OF, "(" + fn.desc + ")Ljava/lang/Boolean;", false));

    inst.add(new FieldInsnNode(PUTFIELD, owner, fn.name, fn.desc));
}

From source file:gemlite.core.internal.asm.serialize.pdxserialize.PdxSFieldProcessor.java

License:Apache License

/**
 * aload_1//from   ww w .  j a v  a  2 s  .  co m
 * ldc "product_id"
 * invokeinterface
 * com/gemstone/gemfire/pdx/PdxWriter/markIdentityField(Ljava/lang
 * /String;)Lcom/gemstone/gemfire/pdx/PdxWriter;
 * pop
 * 
 * 
 * @param cn
 * @param inst
 */
public void markIdentityFields(ClassNode cn, InsnList inst) {
    List<FieldNode> fieldNodeList = null;
    try {
        fieldNodeList = findKeyNodeListByKeyClass(cn);
    } catch (IOException e) {
        if (LogUtil.getCoreLog() != null)
            LogUtil.getCoreLog().error("Domain " + cn.name + " find keyclass failed.", e);
    }

    if (fieldNodeList == null || fieldNodeList.size() == 0) {
        fieldNodeList = findKeyNodeListByDomain(cn);
    }

    if (fieldNodeList == null || fieldNodeList.size() == 0) {
        if (LogUtil.getCoreLog() != null)
            LogUtil.getCoreLog().info("Domain " + cn.name + " can't find key field.");
        return;
    }

    for (FieldNode fn : fieldNodeList) {
        inst.add(new VarInsnNode(ALOAD, 1));
        inst.add(new LdcInsnNode(fn.name));
        inst.add(AsmHelper.newMethodInsnNode(INVOKEINTERFACE, PdxConstants.PDX_WRITER_VALUE,
                "markIdentityField", "(Ljava/lang/String;)Lcom/gemstone/gemfire/pdx/PdxWriter;", true));
        inst.add(new InsnNode(POP));
    }
}

From source file:gemlite.core.internal.asm.serialize.PdxSerializeHelper.java

License:Apache License

private void implementInterface(ClassNode cn) {
    MethodNode toMethod = new MethodNode(ACC_PUBLIC, PdxConstants.PDX_TODATA, PdxConstants.PDX_WRITER_PARAM,
            null, new String[] {});
    InsnList instToMethod = toMethod.instructions;

    MethodNode fromMethod = new MethodNode(ACC_PUBLIC, PdxConstants.PDX_FROMDATA, PdxConstants.PDX_READER_PARAM,
            null, new String[] {});
    InsnList instFromMethod = fromMethod.instructions;
    for (int i = 0; i < cn.fields.size(); i++) {
        FieldNode fn = (FieldNode) cn.fields.get(i);

        fp.toMethod(cn.name, fn, instToMethod);
        fp.fromMethod(cn.name, fn, instFromMethod);
    }//from w  ww  .j  a v a2s . c  o  m

    //markIdentityFields
    fp.markIdentityFields(cn, instToMethod);

    instToMethod.add(new InsnNode(RETURN));
    cn.methods.add(toMethod);

    instFromMethod.add(new InsnNode(RETURN));
    cn.methods.add(fromMethod);

    //    if (DomainMojoHelper.log().isDebugEnabled())
    //      DomainMojoHelper.log().debug(cn.name + " add toData and fromData method.");
}