Package org.aspectj.weaver

Examples of org.aspectj.weaver.WeaverStateInfo$Entry


    // System.out.println("type: " + type + " for " + aspectName);
    if (type.isAspect()) {

      // Bug 119657 ensure we use the unwoven aspect
      WeaverStateInfo wsi = type.getWeaverState();
      if (wsi != null && wsi.isReweavable()) {
        BcelObjectType classType = getClassType(type.getName());
        JavaClass wovenJavaClass = classType.getJavaClass();
        byte[] bytes = wsi.getUnwovenClassFileData(wovenJavaClass.getBytes());
        JavaClass unwovenJavaClass = Utility.makeJavaClass(wovenJavaClass.getFileName(), bytes);
        world.storeClass(unwovenJavaClass);
        classType.setJavaClass(unwovenJavaClass, true);
        // classType.setJavaClass(Utility.makeJavaClass(classType.
        // getJavaClass().getFileName(),
View Full Code Here


  }

  public void processReweavableStateIfPresent(String className, BcelObjectType classType) {
    // If the class is marked reweavable, check any aspects around when it
    // was built are in this world
    WeaverStateInfo wsi = classType.getWeaverState();
    // System.out.println(">> processReweavableStateIfPresent " + className + " wsi=" + wsi);
    if (wsi != null && wsi.isReweavable()) { // Check all necessary types
      // are around!
      world.showMessage(IMessage.INFO, WeaverMessages.format(WeaverMessages.PROCESSING_REWEAVABLE, className, classType
          .getSourceLocation().getSourceFile()), null, null);
      Set<String> aspectsPreviouslyInWorld = wsi.getAspectsAffectingType();
      // keep track of them just to ensure unique missing aspect error
      // reporting
      Set<String> alreadyConfirmedReweavableState = new HashSet<String>();
      for (String requiredTypeSignature : aspectsPreviouslyInWorld) {
        // for (Iterator iter = aspectsPreviouslyInWorld.iterator(); iter.hasNext();) {
        // String requiredTypeName = (String) iter.next();
        if (!alreadyConfirmedReweavableState.contains(requiredTypeSignature)) {
          ResolvedType rtx = world.resolve(UnresolvedType.forSignature(requiredTypeSignature), true);
          boolean exists = !rtx.isMissing();
          if (!exists) {
            world.getLint().missingAspectForReweaving.signal(new String[] { rtx.getName(), className },
                classType.getSourceLocation(), null);
            // world.showMessage(IMessage.ERROR, WeaverMessages.format(WeaverMessages.MISSING_REWEAVABLE_TYPE,
            // requiredTypeName, className), classType.getSourceLocation(), null);
          } else {
            if (world.isOverWeaving()) {
              // System.out.println(">> Removing " + requiredTypeName + " from weaving process: "
              // + xcutSet.deleteAspect(rtx));
            } else {
              // weaved in aspect that are not declared in aop.xml
              // trigger an error for now
              // may cause headhache for LTW and packaged lib
              // without aop.xml in
              // see #104218
              if (!xcutSet.containsAspect(rtx)) {
                world.showMessage(IMessage.ERROR, WeaverMessages.format(
                    WeaverMessages.REWEAVABLE_ASPECT_NOT_REGISTERED, rtx.getName(), className), null, null);
              } else if (!world.getMessageHandler().isIgnoring(IMessage.INFO)) {
                world.showMessage(IMessage.INFO, WeaverMessages.format(WeaverMessages.VERIFIED_REWEAVABLE_TYPE,
                    rtx.getName(), rtx.getSourceLocation().getSourceFile()), null, null);
              }
            }
            alreadyConfirmedReweavableState.add(requiredTypeSignature);
          }
        }
      }
      // old:
      // classType.setJavaClass(Utility.makeJavaClass(classType.getJavaClass
      // ().getFileName(), wsi.getUnwovenClassFileData()));
      // new: reweavable default with clever diff
      if (!world.isOverWeaving()) {
        byte[] bytes = wsi.getUnwovenClassFileData(classType.getJavaClass().getBytes());
        WeaverVersionInfo wvi = classType.getWeaverVersionAttribute();
        JavaClass newJavaClass = Utility.makeJavaClass(classType.getJavaClass().getFileName(), bytes);
        classType.setJavaClass(newJavaClass, true);
        classType.getResolvedTypeX().ensureConsistent();
      }
View Full Code Here

  private List<ShadowMunger> fastMatch(List<ShadowMunger> list, ResolvedType type) {
    if (list == null) {
      return Collections.emptyList();
    }
    boolean isOverweaving = world.isOverWeaving();
    WeaverStateInfo typeWeaverState = (isOverweaving ? type.getWeaverState() : null);

    // here we do the coarsest grained fast match with no kind constraints
    // this will remove all obvious non-matches and see if we need to do any
    // weaving
    FastMatchInfo info = new FastMatchInfo(type, null, world);

    List<ShadowMunger> result = new ArrayList<ShadowMunger>();

    if (world.areInfoMessagesEnabled() && world.isTimingEnabled()) {
      for (ShadowMunger munger : list) {
        if (typeWeaverState != null) { // will only be null if overweaving is ON and there is weaverstate
          ResolvedType declaringAspect = munger.getDeclaringType();
          if (typeWeaverState.isAspectAlreadyApplied(declaringAspect)) {
            continue;
          }
        }
        Pointcut pointcut = munger.getPointcut();
        long starttime = System.nanoTime();
        FuzzyBoolean fb = pointcut.fastMatch(info);
        long endtime = System.nanoTime();
        world.recordFastMatch(pointcut, endtime - starttime);
        if (fb.maybeTrue()) {
          result.add(munger);
        }
      }
    } else {
      for (ShadowMunger munger : list) {
        if (typeWeaverState != null) { // will only be null if overweaving is ON and there is weaverstate
          ResolvedType declaringAspect = munger.getConcreteAspect();// getDeclaringType();
          if (typeWeaverState.isAspectAlreadyApplied(declaringAspect)) {
            continue;
          }
        }
        Pointcut pointcut = munger.getPointcut();
        FuzzyBoolean fb = pointcut.fastMatch(info);
View Full Code Here

    if (((myGen.getMajor() == Constants.MAJOR_1_6 && world.shouldGenerateStackMaps()) || myGen.getMajor() > Constants.MAJOR_1_6)
        && AsmDetector.isAsmAround) {
      wovenClassFileData = StackMapAdder.addStackMaps(world, wovenClassFileData);
    }

    WeaverStateInfo wsi = myType.getWeaverState();// getOrCreateWeaverStateInfo();
    if (wsi != null && wsi.isReweavable()) { // && !reweavableDataInserted
      // reweavableDataInserted = true;
      return wsi.replaceKeyWithDiff(wovenClassFileData);
    } else {
      return wovenClassFileData;
    }
  }
View Full Code Here

    }
    return myType.getWeaverState().getAspectsAffectingType();
  }

  public WeaverStateInfo getOrCreateWeaverStateInfo(boolean inReweavableMode) {
    WeaverStateInfo ret = myType.getWeaverState();
    if (ret != null) {
      return ret;
    }
    ret = new WeaverStateInfo(inReweavableMode);
    myType.setWeaverState(ret);
    return ret;
  }
View Full Code Here

    // we want to "touch" all aspects
    if (clazz.getType().isAspect()) {
      isChanged = true;
    }

    WeaverStateInfo typeWeaverState = (world.isOverWeaving() ? getLazyClassGen().getType().getWeaverState() : null);
    // start by munging all typeMungers
    for (ConcreteTypeMunger o : typeMungers) {
      if (!(o instanceof BcelTypeMunger)) {
        // ???System.err.println("surprising: " + o);
        continue;
      }
      BcelTypeMunger munger = (BcelTypeMunger) o;

      if (typeWeaverState != null && typeWeaverState.isAspectAlreadyApplied(munger.getAspectType())) {
        continue;
      }
      boolean typeMungerAffectedType = munger.munge(this);
      if (typeMungerAffectedType) {
        isChanged = true;
        if (inReweavableMode || clazz.getType().isAspect()) {
          aspectsAffectingType.add(munger.getAspectType().getSignature());
        }
      }
    }

    // Weave special half type/half shadow mungers...
    isChanged = weaveDeclareAtMethodCtor(clazz) || isChanged;
    isChanged = weaveDeclareAtField(clazz) || isChanged;

    // XXX do major sort of stuff
    // sort according to: Major: type hierarchy
    // within each list: dominates
    // don't forget to sort addedThisInitialiers according to dominates
    addedSuperInitializersAsList = new ArrayList<IfaceInitList>(addedSuperInitializers.values());
    addedSuperInitializersAsList = PartialOrder.sort(addedSuperInitializersAsList);
    if (addedSuperInitializersAsList == null) {
      throw new BCException("circularity in inter-types");
    }

    // this will create a static initializer if there isn't one
    // this is in just as bad taste as NOPs
    LazyMethodGen staticInit = clazz.getStaticInitializer();
    staticInit.getBody().insert(genInitInstructions(addedClassInitializers, true));

    // now go through each method, and match against each method. This
    // sets up each method's {@link LazyMethodGen#matchedShadows} field,
    // and it also possibly adds to {@link #initializationShadows}.
    List<LazyMethodGen> methodGens = new ArrayList<LazyMethodGen>(clazz.getMethodGens());
    for (LazyMethodGen member : methodGens) {
      if (!member.hasBody()) {
        continue;
      }
      if (world.isJoinpointSynchronizationEnabled() && world.areSynchronizationPointcutsInUse()
          && member.getMethod().isSynchronized()) {
        transformSynchronizedMethod(member);
      }
      boolean shadowMungerMatched = match(member);
      if (shadowMungerMatched) {
        // For matching mungers, add their declaring aspects to the list
        // that affected this type
        if (inReweavableMode || clazz.getType().isAspect()) {
          aspectsAffectingType.addAll(findAspectsForMungers(member));
        }
        isChanged = true;
      }
    }

    // now we weave all but the initialization shadows
    for (LazyMethodGen methodGen : methodGens) {
      if (!methodGen.hasBody()) {
        continue;
      }
      implement(methodGen);
    }

    // if we matched any initialization shadows, we inline and weave
    if (!initializationShadows.isEmpty()) {
      // Repeat next step until nothing left to inline...cant go on
      // infinetly as compiler will have detected and reported
      // "Recursive constructor invocation"
      List<LazyMethodGen> recursiveCtors = new ArrayList<LazyMethodGen>();
      while (inlineSelfConstructors(methodGens, recursiveCtors)) {
      }
      positionAndImplement(initializationShadows);
    }

    // now proceed with late type mungers
    if (lateTypeMungers != null) {
      for (Iterator<ConcreteTypeMunger> i = lateTypeMungers.iterator(); i.hasNext();) {
        BcelTypeMunger munger = (BcelTypeMunger) i.next();
        if (munger.matches(clazz.getType())) {
          boolean typeMungerAffectedType = munger.munge(this);
          if (typeMungerAffectedType) {
            isChanged = true;
            if (inReweavableMode || clazz.getType().isAspect()) {
              aspectsAffectingType.add(munger.getAspectType().getSignature());
            }
          }
        }
      }
    }

    // FIXME AV - see #75442, for now this is not enough to fix the bug,
    // comment that out until we really fix it
    // // flush to save some memory
    // PerObjectInterfaceTypeMunger.unregisterFromAsAdvisedBy(clazz.getType()
    // );

    // finally, if we changed, we add in the introduced methods.
    if (isChanged) {
      clazz.getOrCreateWeaverStateInfo(inReweavableMode);
      weaveInAddedMethods(); // FIXME asc are these potentially affected
      // by declare annotation?
    }

    if (inReweavableMode) {
      WeaverStateInfo wsi = clazz.getOrCreateWeaverStateInfo(true);
      wsi.addAspectsAffectingType(aspectsAffectingType);
      wsi.setUnwovenClassFileData(ty.getJavaClass().getBytes());
      wsi.setReweavable(true);
    } else {
      clazz.getOrCreateWeaverStateInfo(false).setReweavable(false);
    }

    // tidyup, reduce ongoing memory usage of BcelMethods that hang around
View Full Code Here

    ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.MUNGING_WITH, this);
    boolean changed = false;
    boolean worthReporting = true;

    if (weaver.getWorld().isOverWeaving()) {
      WeaverStateInfo typeWeaverState = weaver.getLazyClassGen().getType().getWeaverState();
      if (typeWeaverState != null && typeWeaverState.isAspectAlreadyApplied(getAspectType())) {
        return false;
      }
    }

    if (munger.getKind() == ResolvedTypeMunger.Field) {
      changed = mungeNewField(weaver, (NewFieldTypeMunger) munger);
    } else if (munger.getKind() == ResolvedTypeMunger.Method) {
      changed = mungeNewMethod(weaver, (NewMethodTypeMunger) munger);
    } else if (munger.getKind() == ResolvedTypeMunger.InnerClass) {
      changed = mungeNewMemberType(weaver, (NewMemberClassTypeMunger) munger);
    } else if (munger.getKind() == ResolvedTypeMunger.MethodDelegate2) {
      changed = mungeMethodDelegate(weaver, (MethodDelegateTypeMunger) munger);
    } else if (munger.getKind() == ResolvedTypeMunger.FieldHost) {
      changed = mungeFieldHost(weaver, (MethodDelegateTypeMunger.FieldHostTypeMunger) munger);
    } else if (munger.getKind() == ResolvedTypeMunger.PerObjectInterface) {
      changed = mungePerObjectInterface(weaver, (PerObjectInterfaceTypeMunger) munger);
      worthReporting = false;
    } else if (munger.getKind() == ResolvedTypeMunger.PerTypeWithinInterface) {
      // PTWIMPL Transform the target type (add the aspect instance field)
      changed = mungePerTypeWithinTransformer(weaver);
      worthReporting = false;
    } else if (munger.getKind() == ResolvedTypeMunger.PrivilegedAccess) {
      changed = mungePrivilegedAccess(weaver, (PrivilegedAccessMunger) munger);
      worthReporting = false;
    } else if (munger.getKind() == ResolvedTypeMunger.Constructor) {
      changed = mungeNewConstructor(weaver, (NewConstructorTypeMunger) munger);
    } else if (munger.getKind() == ResolvedTypeMunger.Parent) {
      changed = mungeNewParent(weaver, (NewParentTypeMunger) munger);
    } else if (munger.getKind() == ResolvedTypeMunger.AnnotationOnType) {
      changed = mungeNewAnnotationOnType(weaver, (AnnotationOnTypeMunger) munger);
      worthReporting = false;
    } else {
      throw new RuntimeException("unimplemented");
    }

    if (changed && munger.changesPublicSignature()) {
      WeaverStateInfo info = weaver.getLazyClassGen().getOrCreateWeaverStateInfo(weaver.getReweavableMode());
      info.addConcreteMunger(this);
    }

    if (changed && worthReporting) {
      ResolvedType declaringAspect = null;
      AsmManager model = ((BcelWorld) getWorld()).getModelAsAsmManager();
View Full Code Here

    // System.out.println("type: " + type + " for " + aspectName);
    if (type.isAspect()) {

      // Bug 119657 ensure we use the unwoven aspect
      WeaverStateInfo wsi = type.getWeaverState();
      if (wsi != null && wsi.isReweavable()) {
        BcelObjectType classType = getClassType(type.getName());
        JavaClass wovenJavaClass = classType.getJavaClass();
        byte[] bytes = wsi.getUnwovenClassFileData(wovenJavaClass.getBytes());
        JavaClass unwovenJavaClass = Utility.makeJavaClass(wovenJavaClass.getFileName(), bytes);
        world.storeClass(unwovenJavaClass);
        classType.setJavaClass(unwovenJavaClass, true);
        // classType.setJavaClass(Utility.makeJavaClass(classType.
        // getJavaClass().getFileName(),
View Full Code Here

  }

  public void processReweavableStateIfPresent(String className, BcelObjectType classType) {
    // If the class is marked reweavable, check any aspects around when it
    // was built are in this world
    WeaverStateInfo wsi = classType.getWeaverState();
    // System.out.println(">> processReweavableStateIfPresent " + className + " wsi=" + wsi);
    if (wsi != null && wsi.isReweavable()) { // Check all necessary types
      // are around!
      world.showMessage(IMessage.INFO, WeaverMessages.format(WeaverMessages.PROCESSING_REWEAVABLE, className, classType
          .getSourceLocation().getSourceFile()), null, null);
      Set<String> aspectsPreviouslyInWorld = wsi.getAspectsAffectingType();
      // keep track of them just to ensure unique missing aspect error
      // reporting
      Set<String> alreadyConfirmedReweavableState = new HashSet<String>();
      for (String requiredTypeSignature : aspectsPreviouslyInWorld) {
        // for (Iterator iter = aspectsPreviouslyInWorld.iterator(); iter.hasNext();) {
        // String requiredTypeName = (String) iter.next();
        if (!alreadyConfirmedReweavableState.contains(requiredTypeSignature)) {
          ResolvedType rtx = world.resolve(UnresolvedType.forSignature(requiredTypeSignature), true);
          boolean exists = !rtx.isMissing();
          if (!exists) {
            world.getLint().missingAspectForReweaving.signal(new String[] { rtx.getName(), className },
                classType.getSourceLocation(), null);
            // world.showMessage(IMessage.ERROR, WeaverMessages.format(WeaverMessages.MISSING_REWEAVABLE_TYPE,
            // requiredTypeName, className), classType.getSourceLocation(), null);
          } else {
            if (world.isOverWeaving()) {
              // System.out.println(">> Removing " + requiredTypeName + " from weaving process: "
              // + xcutSet.deleteAspect(rtx));
            } else {
              // weaved in aspect that are not declared in aop.xml
              // trigger an error for now
              // may cause headhache for LTW and packaged lib
              // without aop.xml in
              // see #104218
              if (!xcutSet.containsAspect(rtx)) {
                world.showMessage(IMessage.ERROR, WeaverMessages.format(
                    WeaverMessages.REWEAVABLE_ASPECT_NOT_REGISTERED, rtx.getName(), className), null, null);
              } else if (!world.getMessageHandler().isIgnoring(IMessage.INFO)) {
                world.showMessage(IMessage.INFO, WeaverMessages.format(WeaverMessages.VERIFIED_REWEAVABLE_TYPE,
                    rtx.getName(), rtx.getSourceLocation().getSourceFile()), null, null);
              }
            }
            alreadyConfirmedReweavableState.add(requiredTypeSignature);
          }
        }
      }
      // old:
      // classType.setJavaClass(Utility.makeJavaClass(classType.getJavaClass
      // ().getFileName(), wsi.getUnwovenClassFileData()));
      // new: reweavable default with clever diff
      if (!world.isOverWeaving()) {
        byte[] bytes = wsi.getUnwovenClassFileData(classType.getJavaClass().getBytes());
        WeaverVersionInfo wvi = classType.getWeaverVersionAttribute();
        JavaClass newJavaClass = Utility.makeJavaClass(classType.getJavaClass().getFileName(), bytes);
        classType.setJavaClass(newJavaClass, true);
        classType.getResolvedTypeX().ensureConsistent();
      }
View Full Code Here

  private List<ShadowMunger> fastMatch(List<ShadowMunger> list, ResolvedType type) {
    if (list == null) {
      return Collections.emptyList();
    }
    boolean isOverweaving = world.isOverWeaving();
    WeaverStateInfo typeWeaverState = (isOverweaving ? type.getWeaverState() : null);

    // here we do the coarsest grained fast match with no kind constraints
    // this will remove all obvious non-matches and see if we need to do any
    // weaving
    FastMatchInfo info = new FastMatchInfo(type, null, world);

    List<ShadowMunger> result = new ArrayList<ShadowMunger>();

    if (world.areInfoMessagesEnabled() && world.isTimingEnabled()) {
      for (ShadowMunger munger : list) {
        if (typeWeaverState != null) { // will only be null if overweaving is ON and there is weaverstate
          ResolvedType declaringAspect = munger.getDeclaringType();
          if (typeWeaverState.isAspectAlreadyApplied(declaringAspect)) {
            continue;
          }
        }
        Pointcut pointcut = munger.getPointcut();
        long starttime = System.nanoTime();
        FuzzyBoolean fb = pointcut.fastMatch(info);
        long endtime = System.nanoTime();
        world.recordFastMatch(pointcut, endtime - starttime);
        if (fb.maybeTrue()) {
          result.add(munger);
        }
      }
    } else {
      for (ShadowMunger munger : list) {
        if (typeWeaverState != null) { // will only be null if overweaving is ON and there is weaverstate
          ResolvedType declaringAspect = munger.getConcreteAspect();// getDeclaringType();
          if (typeWeaverState.isAspectAlreadyApplied(declaringAspect)) {
            continue;
          }
        }
        Pointcut pointcut = munger.getPointcut();
        FuzzyBoolean fb = pointcut.fastMatch(info);
View Full Code Here

TOP

Related Classes of org.aspectj.weaver.WeaverStateInfo$Entry

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.