Java 类org.apache.bcel.generic.DUP 实例源码

项目:eclectic    文件:RequiredQueueJVMGen.java   
@Override
public void generateInitField(InstructionList il, InstructionFactory ifact, GenScope scope) {
    RequiredQueueJVMGen jvmQ = this;
    ClassGen cg = scope.getClassGen();

    il.append(ifact.createNew(jvmQ.getType().getClassName()));
    il.append(new DUP());       

    il.append(ifact.createConstant(jvmQ.getName()));
    // il.append(InstructionConstants.THIS); 
    /*
    il.append(ifact.createInvoke(jvmQ.getClassName(), "<init>",
                Type.VOID, new Type[] { Type.STRING, DefaultTypes.QoolTransformation }, Constants.INVOKESPECIAL));              
    */
    // required queues do not take a qool transformation, but just delegates in one
    il.append(ifact.createInvoke(jvmQ.getClassName(), "<init>",
            Type.VOID, new Type[] { Type.STRING }, Constants.INVOKESPECIAL));               

    // Set the field
    il.append(InstructionConstants.THIS); 
    il.append(InstructionConstants.SWAP); 

    il.append( ifact.createPutField(cg.getClassName(), jvmQ.getFieldName(), jvmQ.getType()) );      
}
项目:eclectic    文件:QoolTransformationJVMGen.java   
private void createObserverCreatorMethod(ClassGen cg, ObserverDescription observer, String observerClassName) {
    final String methodName = "create" + observer.getName();
    InstructionList il = new InstructionList();
    InstructionFactory ifact = new InstructionFactory(cg);
    MethodGen mg = new MethodGen(Constants.ACC_PUBLIC, new ObjectType(observerClassName), new Type[] { } , null, methodName,
               cg.getClassName(), il, cg.getConstantPool());

    il.append(ifact.createNew(observerClassName));
    il.append(InstructionConstants.DUP);
    il.append(InstructionConstants.THIS);
    il.append(ifact.createInvoke(observerClassName, "<init>",
            Type.VOID, new Type[] { DefaultTypes.QoolTransformation }, Constants.INVOKESPECIAL));

    il.append(InstructionFactory.ARETURN);  

    mg.setMaxLocals();
    mg.setMaxStack();

    cg.addMethod(mg.getMethod());       
}
项目:eclectic    文件:LocalQueueJVMGen.java   
@Override
public void generateInitField(InstructionList il, InstructionFactory ifact, GenScope scope) {
    LocalQueueJVMGen jvmQ = this;
    ClassGen cg = scope.getClassGen();

    il.append(ifact.createNew(jvmQ.getType().getClassName()));
    il.append(new DUP());       

    il.append(ifact.createConstant(jvmQ.getName()));
    il.append(InstructionConstants.THIS); 
    il.append(ifact.createInvoke(jvmQ.getClassName(), "<init>",
                Type.VOID, new Type[] { Type.STRING, DefaultTypes.QoolTransformation }, Constants.INVOKESPECIAL));              

    // Stack: queue
    il.append(InstructionConstants.THIS); 
    il.append(InstructionConstants.SWAP); 

    il.append( ifact.createPutField(cg.getClassName(), jvmQ.getFieldName(), jvmQ.getType()) );      
}
项目:eclectic    文件:LocalQueueJVMGen.java   
@Override
public void generateConfigureOptimizations(InstructionList il, InstructionFactory ifact, GenScope scope) {
    if ( getOptimizations().size() > 1 ) throw new UnsupportedOperationException("Only one optimization at a time supported by now");
    if ( getOptimizations().size() == 1 ) {
        AccessByFeatureOptimization opt = (AccessByFeatureOptimization) getOptimizations().get(0);

        il.append(new DUP());       
        il.append(ifact.createConstant(opt.getFeatureName()));
        il.append(ifact.createInvoke(this.getClassName(), "configureAccessByFeatureOptimization",
                Type.VOID, new Type[] { Type.STRING }, Constants.INVOKEVIRTUAL));               

        // TODO: Configure if the access is speculative...
    }


    // Sets the model of the queue statically
    // It is compulsory to have a type for the queue to enable optimizations
    if ( getOptimizations().size() > 0 ) {
        il.append(new DUP());   
        scope.generateGetModel(this.getType_().getModel().getName());
        il.append(ifact.createInvoke(this.getClassName(), "setModel",
                Type.VOID, new Type[] { DefaultTypes.IModel }, Constants.INVOKEVIRTUAL));               
    }
}
项目:cashmere    文件:Cashmerec.java   
InstructionHandle insertThrowAbort(MethodGen m, InstructionList il,
    InstructionHandle pos) {
    InstructionHandle retval;

    retval = il.insert(pos, ins_f
        .createNew("ibis.cashmere.impl.aborts.AbortException"));
    il.insert(pos, new DUP());
    il.insert(pos, ins_f.createInvoke(
        "ibis.cashmere.impl.aborts.AbortException", "<init>", Type.VOID,
        Type.NO_ARGS, Constants.INVOKESPECIAL));
    il.insert(pos, new ATHROW());

    return retval;
}
项目:cashmere    文件:MethodGen.java   
private boolean containsDUP(ArrayList<InstructionHandle> instructionHandles) {
for (InstructionHandle ih : instructionHandles) {
    if (ih.getInstruction() instanceof DUP) {
    return true;
    }
}
return false;
   }
项目:cashmere    文件:MethodGen.java   
private InstructionHandle getDUP(ArrayList<InstructionHandle> instructionHandles) {
if (instructionHandles.size() == 1 && 
    instructionHandles.get(0).getInstruction() instanceof DUP) {
    return instructionHandles.get(0);
}
throw new Error("Very strange situation, not handled yet, controlflow in DUP's????\n");
   }
项目:eclectic    文件:ParallelTransformationJVMGen.java   
private void createConstructor(GenScope scope, ClassGen cg) {
    InstructionList il = new InstructionList();
    InstructionFactory ifact = new InstructionFactory(cg);

    // Call super
       il.append(InstructionConstants.THIS); 
       il.append(new INVOKESPECIAL(cg.getConstantPool().addMethodref(cg.getSuperclassName(), "<init>", "()V")));

       // Instantiate and register each transformation to be executed 
    for (TransformationExecution exec : getExecutions()) {
        // TODO: Ensure the name obtained with "getTransformationName" is the one of the generated transformation (weak link now!)
        String transformationClassName = exec.getTransformationName();
        // TODO: Find out the class package name!!
        transformationClassName = "eclectic." + transformationClassName;

        il.append(ifact.createNew(transformationClassName)); 
        il.append(new DUP());       
        il.append(ifact.createInvoke(transformationClassName, "<init>",
                Type.VOID, new Type[] { }, Constants.INVOKESPECIAL));

        il.append(InstructionConstants.THIS); 
        il.append(InstructionConstants.SWAP); 
        il.append(ifact.createInvoke(cg.getClassName(), "register",
                    Type.VOID, new Type[] { DefaultTypes.IdcTransformation }, Constants.INVOKEVIRTUAL));                
    }

       il.append(InstructionConstants.RETURN);

       MethodGen mg = new MethodGen(Constants.ACC_PUBLIC, Type.VOID, new Type[] { } , null, "<init>",
               cg.getClassName(), il, cg.getConstantPool());
       mg.setMaxStack();
       cg.addMethod(mg.getMethod());        
}
项目:eclectic    文件:ReadMetaJVMGen.java   
/**
 * A new IdcMetaclass object is created to wrap de 
 * real metaclass providing additional functionality.
 * 
 * <pre>
 *      NEW IdcMetaclass 
 *      DUP
 *      LDC <<model_name>>
 *      LDC <<class_name>>
 *      INVOKESPECIAL IdcMetaclass.<init>
 *      ASTORE !!#variable!!
 * </pre>
 */
@Override
public void generate(GenScope scope) {
    InstructionList il       = scope.getInstructionList();
    InstructionFactory ifact = scope.getInstructionFactory();
    ConstantPoolGen cpg      = scope.getConstantPool();

    LocalVariableGen lvg = null;

    if ( getKind() == ReadMetaKind.METACLASS) {     
        lvg = scope.newLocalVariable(this, DefaultTypes.IdcMetaclass);

        lvg.setStart(il.append(ifact.createNew(DefaultTypes.IdcMetaclass)));
        il.append(new DUP());

        // il.append(new LDC(cpg.addString(getModel().getName())));
        scope.generateGetTransformation();
        scope.generateGetModel(getModel().getName());
        // CommonGen.generateGetModel(getModel().getName(), il, ifact, scope);

        il.append(new LDC(cpg.addString(getClassName())));
        il.append(ifact.createInvoke(DefaultTypes.IdcMetaclass.getClassName(), "<init>",
            Type.VOID, new Type[] { DefaultTypes.IdcTransformation, DefaultTypes.IModel, Type.STRING },
            Constants.INVOKESPECIAL));
    } else if ( getKind() == ReadMetaKind.THIS_TRANSFORMATION_OBJECT ||
                getKind() == ReadMetaKind.THIS_TRANSFORMATION_METHOD_HANDLER ) {
        lvg = scope.newLocalVariable(this, DefaultTypes.IdcTransformation);         
        lvg.setStart(il.append(InstructionConstants.NOP));

        scope.generateGetTransformation();
    } else if ( getKind() == ReadMetaKind.MODEL ){
        lvg = scope.newLocalVariable(this, DefaultTypes.IModel);            
        lvg.setStart(il.append(InstructionConstants.NOP));
        scope.generateGetModel(getModel().getName());   
    } else {
        throw new IllegalArgumentException();
    }

    il.append(new ASTORE(lvg.getIndex()));
}
项目:eclectic    文件:ClosureDefJVMGen.java   
@Override
public void generate(GenScope scope) {
    InstructionList il       = scope.getInstructionList();
    InstructionFactory ifact = scope.getInstructionFactory();       

    NewScopeResult closureClassScope = createClosureClass(scope);
    ClassGen     closureClass = closureClassScope.cg;
    ClosureScope closureScope = (ClosureScope) closureClassScope.scope;

    scope.getTransformationContext().addExtraClass(closureClass.getJavaClass());

    LocalVariableGen lvg  = scope.newLocalVariable(this, Type.OBJECT);

    // Create the closure instance 
    il.append(ifact.createNew(closureClass.getClassName()));        
    il.append(new DUP());       

    scope.generateGetTransformation();
    scope.generateGetModelManager();        
    il.append(ifact.createInvoke(closureClass.getClassName(), "<init>",
            Type.VOID, new Type[] { DefaultTypes.IdcTransformation, DefaultTypes.ModelManager }, Constants.INVOKESPECIAL));
            //Type.VOID, new Type[] { DefaultTypes.ModelManager }, Constants.INVOKESPECIAL));

    // This is a bit hard-wired because the OuterVariableSet 
    // is computed as a result of creating the closureClass...
    OuterVariableSet outers = closureScope.getOuterVariables();
    Set<Variable> o = outers.get();
    for (Variable variable : o) {
        il.append(new DUP());
        scope.loadVariable(variable, il);
        il.append(scope.getInstructionFactory().createPutField(closureClass.getClassName(), variable.getName(), Type.OBJECT));  
    }       

    il.append(new ASTORE(lvg.getIndex()));
}
项目:cashmere    文件:Cashmerec.java   
void generateMain(ClassGen clg, Method origMain) {

        InstructionList il = new InstructionList();

        MethodGen new_main = new MethodGen(Constants.ACC_STATIC
            | Constants.ACC_PUBLIC, Type.VOID, new Type[] { new ArrayType(
            Type.STRING, 1) }, new String[] { "argv" }, "main", clg
            .getClassName(), il, clg.getConstantPool());

        il.append(ins_f.createNew(cashmereType));
        il.append(new DUP());
        il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "<init>",
            Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
        il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "isMaster",
            Type.BOOLEAN, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
        BranchHandle ifcmp = il.append(new IFEQ(null));

        InstructionHandle origMain_handle = il.append(new ALOAD(0));

        InstructionHandle try_start = il.append(ins_f.createInvoke(clg
            .getClassName(), origMain.getName(), Type.VOID,
            new Type[] { new ArrayType(Type.STRING, 1) },
            Constants.INVOKESTATIC));

        BranchHandle try_end = il.append(new GOTO(null));

        InstructionHandle e_handler = il.append(getCashmere(ins_f));
        il.append(new SWAP());
        il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "exit",
                Type.VOID, new Type[] { new ObjectType("java.lang.Throwable")},
                Constants.INVOKEVIRTUAL));

        BranchHandle gto2 = il.append(new GOTO(null));

        InstructionHandle ifeq_target = il.append(getCashmere(ins_f));
        ifcmp.setTarget(ifeq_target);
        il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "client",
            Type.VOID, Type.NO_ARGS, Constants.INVOKEVIRTUAL));

        il.append(getCashmere(ins_f));
        il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "isMaster",
            Type.BOOLEAN, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
        il.append(new IFNE(origMain_handle));

        InstructionHandle gto_target = il.append(getCashmere(ins_f));
        try_end.setTarget(gto_target);

        il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "exit",
            Type.VOID, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
        InstructionHandle gto2_target = il.append(new RETURN());
        gto2.setTarget(gto2_target);

        new_main.addExceptionHandler(try_start, try_end, e_handler,
            new ObjectType("java.lang.Throwable"));
        new_main.setMaxStack();
        new_main.setMaxLocals();

        new_main.addLocalVariable("argv", new ArrayType(Type.STRING, 1), 0,
            origMain_handle, null);

        removeLocalTypeTables(new_main);

        Method main = new_main.getMethod();
        gen_c.addMethod(main);
    }
项目:cn1    文件:JavaByteCodeOutputProcess.java   
@SuppressWarnings("unused")
// Called using reflection
private Instruction createInstructionDup(Element inst) {
    return new DUP();
}
项目:eclectic    文件:GetJVMGen.java   
/**
 * <<GET_IMODEL(THIS)>> 
     * ALOAD !!#receptor_variable!!
    * LDC <<featureName>>
 * INVOKEINTERFACE getFeature
 */  
@Override
public void generate(GenScope scope) {
    InstructionList il       = scope.getInstructionList();
    InstructionFactory ifact = scope.getInstructionFactory();
    ConstantPoolGen cpg      = scope.getConstantPool();

    Variable realReceptor = scope.getRealVariable(this.receptor);

    LocalVariableGen lvg = scope.newLocalVariable(this, Type.OBJECT);

    // generate model access
    scope.generateGetModel(realReceptor);
    il.append(new DUP()); // for later calls of get/method calls (problem if I put the generateGetModel directly, not using the dup optimize, why?)


    // push receptor
    // push featureName
    scope.loadVariable(realReceptor, il);
    lvg.setStart(il.append(new LDC(cpg.addString(featureName))));

    if ( kind == GetKind.PLAIN_GET ) {
        appendGetFeature(il, ifact);
        il.append(InstructionFactory.SWAP);
        il.append(InstructionFactory.POP);
        // I should swap, and then pop...
        // il.append(new POP());
    } else {
        BranchInstruction branchToCall = InstructionFactory
                .createBranchInstruction(Constants.IFEQ, null);
        BranchInstruction branchToEnd = InstructionFactory
                .createBranchInstruction(Constants.GOTO, null);

        // hasFeature(f)
        // ifeq (jump if value == 0)
        appendHasFeature(il, ifact);
        lvg.setStart(il.append(branchToCall));

        // push receptor
        // push featureName
        // get & jump to the end
        /*
        scope.loadVariable(realReceptor, il);
        lvg.setStart(il.append(new LDC(cpg.addString(featureName))));
        */
        if ( isStreamingMode(scope) ) {
            appendContinuableGetFeature(scope, realReceptor, il, ifact, cpg);
        } else {
            scope.loadVariable(realReceptor, il);
            il.append(new LDC(cpg.addString(featureName)));
            appendGetFeature(il, ifact);
            // branchToEnd.setTarget(appendGetFeature(il, ifact));
        }
        il.append(branchToEnd);

        // push receptor
        // push featureName
        // methodCall
        branchToCall.setTarget( il.append(InstructionConstants.NOP) ); // label for this part
        //scope.loadVariable(realReceptor, il);
        // lvg.setStart(il.append(new LDC(cpg.addString(featureName))));            
        lvg.setStart(il.append(InstructionConstants.POP)); // remove IModel
        appendMethodCall(scope, il, ifact);

        // NOP-end
        branchToEnd.setTarget( il.append(InstructionConstants.NOP) );
    }

    // store result
    il.append(new ASTORE( lvg.getIndex() ));
}
项目:eclectic    文件:ModelElementQueueJVMGen.java   
@Override
public void generateInitField(InstructionList il, InstructionFactory ifact, GenScope scope) {
    ModelElementQueueJVMGen jvmQ = this;
    ClassGen cg = scope.getClassGen();

    il.append(ifact.createNew(jvmQ.getType().getClassName()));
    il.append(new DUP());       

    il.append(ifact.createConstant( jvmQ.getName()));
    il.append(ifact.createConstant( ((ModelElementQueue) jvmQ).getType_().getModel().getName() ) );
    il.append(ifact.createConstant( ((ModelElementQueue) jvmQ).getType_().getClassifierName() ) );
    il.append(InstructionConstants.THIS); 
    il.append(ifact.createInvoke(jvmQ.getClassName(), "<init>",
            Type.VOID, new Type[] { Type.STRING, Type.STRING, Type.STRING, DefaultTypes.QoolTransformation }, Constants.INVOKESPECIAL));

    // Set if the type is strict (no subclasses)
    il.append(InstructionConstants.DUP);
    il.append(ifact.createConstant( this.getType_().isStrictType() ));
    il.append(ifact.createInvoke(jvmQ.getClassName(), "setStrictType",
            Type.VOID, new Type[] { Type.BOOLEAN }, Constants.INVOKEVIRTUAL));          


    for(TypeInfo info : getAdditionals()) {
        il.append(InstructionConstants.DUP);
        il.append(ifact.createConstant( info.getModel().getName() ));
        il.append(ifact.createConstant( info.getClassifierName() ));
        il.append(ifact.createConstant( info.isStrictType() ));
        il.append(ifact.createInvoke(jvmQ.getClassName(), "addAdditionalType",
                Type.VOID, new Type[] { Type.STRING,Type.STRING, Type.BOOLEAN }, 
                Constants.INVOKEVIRTUAL));          
    }

    // Dealing with potency
    if ( this.extension != null && this.extension instanceof PotencyExtension ) {
        il.append(InstructionConstants.DUP);
        il.append(ifact.createConstant( ((PotencyExtension) extension).getPotency() ));
        il.append(ifact.createInvoke(jvmQ.getClassName(), "setPotency",
                Type.VOID, new Type[] { Type.INT }, Constants.INVOKEVIRTUAL));          
    }

    il.append(InstructionConstants.THIS); 
    il.append(InstructionConstants.SWAP); 

    il.append( ifact.createPutField(cg.getClassName(), jvmQ.getFieldName(), jvmQ.getType()) );

}