예제 #1
0
 private ClassDependency createClassDependency(String className) {
   ClassReader cls = classSource.get(className);
   ClassDependency dependency = new ClassDependency(this, className, cls);
   if (!dependency.isMissing()) {
     if (cls.getParent() != null && !cls.getParent().equals(className)) {
       linkClass(cls.getParent(), null);
     }
     for (String ifaceName : cls.getInterfaces()) {
       linkClass(ifaceName, null);
     }
   }
   return dependency;
 }
예제 #2
0
 private boolean addClassAccess(
     DefaultCallGraphNode node, String className, InstructionLocation loc) {
   if (!node.addClassAccess(className, loc)) {
     return false;
   }
   ClassReader cls = classSource.get(className);
   if (cls != null) {
     if (cls.getParent() != null && !cls.getParent().equals(cls.getName())) {
       addClassAccess(node, cls.getParent(), loc);
     }
     for (String iface : cls.getInterfaces()) {
       addClassAccess(node, iface, loc);
     }
   }
   return true;
 }
예제 #3
0
  public void submitMethod(MethodReference methodRef, Program program) {
    if (!completing) {
      ClassHolder cls = classSource.get(methodRef.getClassName());

      if (cls == null) {
        throw new IllegalArgumentException("Class not found: " + methodRef.getClassName());
      }
      if (cls.getMethod(methodRef.getDescriptor()) != null) {
        throw new IllegalArgumentException("Method already exists: " + methodRef.getClassName());
      }
      MethodHolder method = new MethodHolder(methodRef.getDescriptor());
      method.getModifiers().add(ElementModifier.STATIC);
      method.setProgram(ProgramUtils.copy(program));
      new UnreachableBasicBlockEliminator().optimize(program);
      cls.addMethod(method);
    } else {
      MethodDependency dep = getMethod(methodRef);
      if (dep == null) {
        throw new IllegalArgumentException("Method was not reached: " + methodRef);
      }
      MethodHolder method = dep.method;

      if (!method.hasModifier(ElementModifier.NATIVE)) {
        throw new IllegalArgumentException("Method is not native: " + methodRef);
      }
      if (!dep.used) {
        return;
      }
      method.getModifiers().remove(ElementModifier.NATIVE);
      method.setProgram(ProgramUtils.copy(program));
      new UnreachableBasicBlockEliminator().optimize(method.getProgram());

      dep.used = false;
      lock(dep, false);
      tasks.add(
          () -> {
            DependencyGraphBuilder graphBuilder =
                new DependencyGraphBuilder(DependencyChecker.this);
            graphBuilder.buildGraph(dep);
            dep.used = true;
          });

      processQueue();
    }
  }
예제 #4
0
 public void addClassTransformer(ClassHolderTransformer transformer) {
   classSource.addTransformer(transformer);
 }
예제 #5
0
 public void submitClass(ClassHolder cls) {
   if (completing) {
     throw new IllegalStateException("Can't submit class during completion phase");
   }
   classSource.submit(ModelUtils.copyClass(cls));
 }