Package org.aspectj.apache.bcel.generic

Examples of org.aspectj.apache.bcel.generic.ConstantPoolGen$Index


    // Pass 3a ran before, so it's safe to assume the JavaClass object is
    // in the BCEL repository.
    JavaClass jc = Repository.lookupClass(myOwner.getClassName());

    ConstantPoolGen constantPoolGen = new ConstantPoolGen(jc.getConstantPool());
    // Init Visitors
    InstConstraintVisitor icv = new InstConstraintVisitor();
    icv.setConstantPoolGen(constantPoolGen);
   
    ExecutionVisitor ev = new ExecutionVisitor();
View Full Code Here


  }



  private void deleteNewAndDup() {
    final ConstantPoolGen cpg = getEnclosingClass().getConstantPoolGen();
    int depth = 1;
    InstructionHandle ih = range.getStart();

    while (true) {
      Instruction inst = ih.getInstruction();
View Full Code Here

            // so we don't inline it.
            // Note: for code style, this is done at Aspect compilation time.
            boolean canSeeProceedPassedToOther = false;
            InstructionHandle curr = adviceMethod.getBody().getStart();
            InstructionHandle end = adviceMethod.getBody().getEnd();
            ConstantPoolGen cpg = adviceMethod.getEnclosingClass().getConstantPoolGen();
            while (curr != end) {
                InstructionHandle next = curr.getNext();
                Instruction inst = curr.getInstruction();
                if ((inst instanceof InvokeInstruction)
                    && ((InvokeInstruction)inst).getSignature(cpg).indexOf("Lorg/aspectj/lang/ProceedingJoinPoint;") > 0) {
                    // we may want to refine to exclude stuff returning jp ?
                    // does code style skip inline if i write dump(thisJoinPoint) ?
                    canSeeProceedPassedToOther = true;// we see one pjp passed around - dangerous
                    break;
                }
                curr = next;
            }
            if (canSeeProceedPassedToOther) {
                // remember this decision to avoid re-analysis
                adviceMethod.setCanInline(false);
                weaveAroundClosure(munger, hasDynamicTest);
                return;
            }
        }



    // We can't inline around methods if they have around advice on them, this
    // is because the weaving will extract the body and hence the proceed call.
    //??? should consider optimizations to recognize simple cases that don't require body extraction
    enclosingMethod.setCanInline(false);
   
    // start by exposing various useful things into the frame
    final InstructionFactory fact = getFactory();
   
    // now generate the aroundBody method
        LazyMethodGen extractedMethod =
          extractMethod(
            NameMangler.aroundCallbackMethodName(
              getSignature(),
              getEnclosingClass()),
        Modifier.PRIVATE,
        munger
            );
             
             
        // now extract the advice into its own method
        String adviceMethodName =
      NameMangler.aroundCallbackMethodName(
              getSignature(),
              getEnclosingClass()) + "$advice";
       
    List argVarList = new ArrayList();
    List proceedVarList = new ArrayList();
    int extraParamOffset = 0;
   
    // Create the extra parameters that are needed for passing to proceed
    // This code is very similar to that found in makeCallToCallback and should
    // be rationalized in the future
    if (thisVar != null) {
      argVarList.add(thisVar);
      proceedVarList.add(new BcelVar(thisVar.getType(), extraParamOffset));
      extraParamOffset += thisVar.getType().getSize();
    }
   
    if (targetVar != null && targetVar != thisVar) {
      argVarList.add(targetVar);
      proceedVarList.add(new BcelVar(targetVar.getType(), extraParamOffset));
      extraParamOffset += targetVar.getType().getSize();
    }
    for (int i = 0, len = getArgCount(); i < len; i++) {
      argVarList.add(argVars[i]);
      proceedVarList.add(new BcelVar(argVars[i].getType(), extraParamOffset));
      extraParamOffset += argVars[i].getType().getSize();
    }
    if (thisJoinPointVar != null) {
      argVarList.add(thisJoinPointVar);
      proceedVarList.add(new BcelVar(thisJoinPointVar.getType(), extraParamOffset));
      extraParamOffset += thisJoinPointVar.getType().getSize();
    }
       
        Type[] adviceParameterTypes = adviceMethod.getArgumentTypes();
        Type[] extractedMethodParameterTypes = extractedMethod.getArgumentTypes();
    Type[] parameterTypes =
      new Type[extractedMethodParameterTypes.length
        + adviceParameterTypes.length
        + 1];
    int parameterIndex = 0;
    System.arraycopy(
      extractedMethodParameterTypes,
      0,
      parameterTypes,
      parameterIndex,
      extractedMethodParameterTypes.length);
    parameterIndex += extractedMethodParameterTypes.length;

    parameterTypes[parameterIndex++] =
      BcelWorld.makeBcelType(adviceMethod.getEnclosingClass().getType());
    System.arraycopy(
      adviceParameterTypes,
      0,
      parameterTypes,
      parameterIndex,
      adviceParameterTypes.length);

        LazyMethodGen localAdviceMethod =
          new LazyMethodGen(
            Modifier.PRIVATE | Modifier.FINAL | Modifier.STATIC,
            BcelWorld.makeBcelType(mungerSig.getReturnType()),
            adviceMethodName,
            parameterTypes,
            new String[0],
            getEnclosingClass());
    String donorFileName = adviceMethod.getEnclosingClass().getInternalFileName();
    String recipientFileName = getEnclosingClass().getInternalFileName();
//    System.err.println("donor " + donorFileName);
//    System.err.println("recip " + recipientFileName);
    if (! donorFileName.equals(recipientFileName)) {
      localAdviceMethod.fromFilename = donorFileName;
      getEnclosingClass().addInlinedSourceFileInfo(
        donorFileName,
        adviceMethod.highestLineNumber);
    }
   
    getEnclosingClass().addMethodGen(localAdviceMethod);
   
    // create a map that will move all slots in advice method forward by extraParamOffset
    // in order to make room for the new proceed-required arguments that are added at
    // the beginning of the parameter list
    int nVars = adviceMethod.getMaxLocals() + extraParamOffset;
    IntMap varMap = IntMap.idMap(nVars);
    for (int i=extraParamOffset; i < nVars; i++) {
      varMap.put(i-extraParamOffset, i);
    }

    localAdviceMethod.getBody().insert(
      BcelClassWeaver.genInlineInstructions(adviceMethod,
          localAdviceMethod, varMap, fact, true));


         
    localAdviceMethod.setMaxLocals(nVars);
         
    //System.err.println(localAdviceMethod);
   
   
      // the shadow is now empty.  First, create a correct call
      // to the around advice.  This includes both the call (which may involve
      // value conversion of the advice arguments) and the return
      // (which may involve value conversion of the return value).  Right now
      // we push a null for the unused closure.  It's sad, but there it is.
           
      InstructionList advice = new InstructionList();
        // InstructionHandle adviceMethodInvocation;
        {
      for (Iterator i = argVarList.iterator(); i.hasNext(); ) {
        BcelVar var = (BcelVar)i.next();
        var.appendLoad(advice, fact);
      }        
          // ??? we don't actually need to push NULL for the closure if we take care
      advice.append(
        munger.getAdviceArgSetup(
          this,
          null,
                    (munger.getConcreteAspect().isAnnotationStyleAspect())?
                        this.loadThisJoinPoint():
              new InstructionList(InstructionConstants.ACONST_NULL)));
        // adviceMethodInvocation =
            advice.append(
              Utility.createInvoke(fact, localAdviceMethod)); //(fact, getWorld(), munger.getSignature()));
      advice.append(
            Utility.createConversion(
                getFactory(),
                BcelWorld.makeBcelType(mungerSig.getReturnType()),
                extractedMethod.getReturnType(),world.isInJava5Mode()));
        if (! isFallsThrough()) {
            advice.append(InstructionFactory.createReturn(extractedMethod.getReturnType()));
        }
        }
       
    // now, situate the call inside the possible dynamic tests,
    // and actually add the whole mess to the shadow
        if (! hasDynamicTest) {
            range.append(advice);
        } else {
          InstructionList afterThingie = new InstructionList(InstructionConstants.NOP);
            InstructionList callback = makeCallToCallback(extractedMethod);
      if (terminatesWithReturn()) {
        callback.append(
          InstructionFactory.createReturn(extractedMethod.getReturnType()));
      } else {
        //InstructionHandle endNop = range.insert(fact.NOP, Range.InsideAfter);
        advice.append(
          InstructionFactory.createBranchInstruction(
            Constants.GOTO,
            afterThingie.getStart()));
      }
      range.append(
        munger.getTestInstructions(
          this,
          advice.getStart(),
          callback.getStart(),
          advice.getStart()));
            range.append(advice);
            range.append(callback);
            range.append(afterThingie);         
        }       


        // now search through the advice, looking for a call to PROCEED. 
        // Then we replace the call to proceed with some argument setup, and a
        // call to the extracted method.

        // inlining support for code style aspects
        if (!munger.getConcreteAspect().isAnnotationStyleAspect()) {
            String proceedName =
                NameMangler.proceedMethodName(munger.getSignature().getName());

            InstructionHandle curr = localAdviceMethod.getBody().getStart();
            InstructionHandle end = localAdviceMethod.getBody().getEnd();
            ConstantPoolGen cpg = localAdviceMethod.getEnclosingClass().getConstantPoolGen();
            while (curr != end) {
                InstructionHandle next = curr.getNext();
                Instruction inst = curr.getInstruction();
                if ((inst instanceof INVOKESTATIC)
                    && proceedName.equals(((INVOKESTATIC) inst).getMethodName(cpg))) {

                    localAdviceMethod.getBody().append(
                        curr,
                        getRedoneProceedCall(
                            fact,
                            extractedMethod,
                            munger,
                            localAdviceMethod,
                            proceedVarList));
                    Utility.deleteInstruction(curr, localAdviceMethod);
                }
                curr = next;
            }
            // and that's it.
        } else {
            //ATAJ inlining support for @AJ aspects
            // [TODO document @AJ code rule: don't manipulate 2 jps proceed at the same time.. in an advice body]
            InstructionHandle curr = localAdviceMethod.getBody().getStart();
            InstructionHandle end = localAdviceMethod.getBody().getEnd();
            ConstantPoolGen cpg = localAdviceMethod.getEnclosingClass().getConstantPoolGen();
            while (curr != end) {
                InstructionHandle next = curr.getNext();
                Instruction inst = curr.getInstruction();
                if ((inst instanceof INVOKEINTERFACE)
                    && "proceed".equals(((INVOKEINTERFACE) inst).getMethodName(cpg))) {
View Full Code Here

     * @param aroundAdvice
     */
    private void openAroundAdvice(LazyMethodGen aroundAdvice) {
        InstructionHandle curr = aroundAdvice.getBody().getStart();
        InstructionHandle end = aroundAdvice.getBody().getEnd();
        ConstantPoolGen cpg = aroundAdvice.getEnclosingClass().getConstantPoolGen();
        InstructionFactory factory = aroundAdvice.getEnclosingClass().getFactory();

        boolean realizedCannotInline = false;
        while (curr != end) {
            if (realizedCannotInline) {
View Full Code Here

            gen.addAnnotation(new AnnotationGen(a,gen.getConstantPool(),true));
          }
        }
       
        if (isSynthetic) {
      ConstantPoolGen cpg = gen.getConstantPool();
      int index = cpg.addUtf8("Synthetic");
      gen.addAttribute(new Synthetic(index, 0, new byte[0], cpg.getConstantPool()));
        }
       
        if (hasBody()) {
            packBody(gen);
            gen.setMaxLocals();
View Full Code Here

    int ni = shape[0];
    int nj = shape[1];
    int nk = shape[2];

    array = new ArrayDouble.D3(ni, nj, nk);
    Index index = array.getIndex();

    for (int i = 0; i < ni; i++) {
      for (int j = 0; j < nj; j++) {
        for (int k = 0; k < nk; k++) {
          index.set(i, j, k);
          double d = pertArray.getDouble(index)
              + baseArray.getDouble(index);
          if (isZStag) {
            d = d / 9.81//convert geopotential to height
          }
View Full Code Here

      IndexChunker.printl(" dataStrides=", dataStrides);
      IndexChunker.printa(" wantStride=", resultStrides);
      System.out.println(" indexChunks=" + Index.computeSize(shape));
    }
    dataIndex = new IndexLong(shape, dataStrides);
    resultIndex = new Index(shape, resultStrides);

    if (debugDetail) {
      System.out.println(" dataIndex="+ dataIndex.toString());
      System.out.println(" resultIndex="+ resultIndex.toStringDebug());
    }
View Full Code Here

    Array data = v.read();
    int[] shape = data.getShape();
    assert shape[0] == 1000;
    assert shape[1] == 20;

    Index ima = data.getIndex();
    for (int i = 0; i < 1000; i++)
      for (int j = 0; j < 20; j++) {
        int val = data.getInt(ima.set(i, j));
        assert val == i + j : val + " != " + (i + j);
      }

  }
View Full Code Here

        Array dataArray =
            Array.factory(v2.getDataType().getPrimitiveClassType(),
                          section.getShape());

        Index dataIndex = dataArray.getIndex();

        if (varname.equals("latitude") || varname.equals("longitude")) {
            double[][] pixel = new double[2][1];
            double[][] latLon;
            double[][][] latLonValues =
                new double[geoXRange.length()][geoYRange.length()][2];

            // Use Range object, which calculates requested i, j
            // values and incorporates stride
            for (int i = 0; i < geoXRange.length(); i++) {
                for (int j = 0; j < geoYRange.length(); j++) {
                    pixel[0][0] = (double) geoXRange.element(i);
                    pixel[1][0] = (double) geoYRange.element(j);
                    latLon      = nav.toLatLon(pixel);

                    if (varname.equals("lat")) {
                        dataArray.setFloat(dataIndex.set(j, i),
                                           (float) (latLon[0][0]));
                    } else {
                        dataArray.setFloat(dataIndex.set(j, i),
                                           (float) (latLon[1][0]));
                    }
                }
            }
        }

        if (varname.equals("image")) {
            try {
                int[][] pixelData = new int[1][1];
                if (bandRange != null) {
                    for (int k = 0; k < bandRange.length(); k++) {
                        int bandIndex = bandRange.element(k) + 1// band numbers in McIDAS are 1 based
                        for (int j = 0; j < geoYRange.length(); j++) {
                            for (int i = 0; i < geoXRange.length(); i++) {
                                pixelData = af.getData(geoYRange.element(j),
                                        geoXRange.element(i), 1, 1,
                                        bandIndex);
                                dataArray.setInt(dataIndex.set(0, k, j, i),
                                        (pixelData[0][0]));
                            }
                        }
                    }

                } else {
                    for (int j = 0; j < geoYRange.length(); j++) {
                        for (int i = 0; i < geoXRange.length(); i++) {
                            pixelData = af.getData(geoYRange.element(j),
                                    geoXRange.element(i), 1, 1);
                            dataArray.setInt(dataIndex.set(0, j, i),
                                             (pixelData[0][0]));
                        }
                    }

                }
View Full Code Here

                    var=varList.get(ix);
                    if ((var.getShortName()).equals("numGates")) { numGates=var; break}
                }
            }
            ArrayInt.D1 gatesArr=(ArrayInt.D1) Array.factory(DataType.INT, numGates.getShape());
            Index gatesIndex=gatesArr.getIndex();
           
            for (int i=0; i<number_sweeps; i++) {
                List rlist = sgp[i];
                for (int jj=0; jj<num_rays; jj++) { rtemp[jj]=(Ray)rlist.get(jj); } //ray[i][jj]; }
                ngates=rtemp[0].getBins();
                gatesArr.setInt(gatesIndex.set(i), ngates);
            }

            for (int i=0; i<number_sweeps; i++) {
                distanceR[i].setCachedData(distArr[i], false);
                time[i].setCachedData(timeArr[i], false);
View Full Code Here

TOP

Related Classes of org.aspectj.apache.bcel.generic.ConstantPoolGen$Index

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.