Package nginx.clojure.wave.MethodDatabase

Examples of nginx.clojure.wave.MethodDatabase.ClassEntry


    }
    return ce;
  }
 
  public static ClassEntry buildClassEntryFamily(MethodDatabase db, String name) {
    ClassEntry ce = db.getClasses().get(name);
    if (ce == null) {
      CheckInstrumentationVisitor civ = db.checkClass(name);
      if (civ == null) {
        return null;
      }
View Full Code Here


    static byte[] instrumentClass(MethodDatabase db, byte[] data, boolean check) {
        ClassReader r = new ClassReader(data);
        ClassWriter cw = new DBClassWriter(db, r);
        ClassVisitor cv = check ? new CheckClassAdapter(cw) : cw;
        ClassEntry ce = MethodDatabaseUtil.buildClassEntryFamily(db, r);
        if(db.shouldIgnore(r.getClassName())) {
            return null;
        }
        db.trace("TRANSFORM: %s", r.getClassName());
        InstrumentClass ic = new InstrumentClass(r.getClassName(), ce, cv, db, false);
View Full Code Here

          protected String getCommonSuperClass(String type1, String type2) {
            return db.getCommonSuperClass(type1, type2);
          }
        };
       
        ClassEntry ce = MethodDatabaseUtil.buildClassEntryFamily(db, cr);
//        if (className.startsWith("sun/launcher/")
//            || className.startsWith("clojure/asm")
//            || className.startsWith("org/objectweb/asm/")
//            || className.startsWith("clojure/asm")
//            || className.startsWith("org/junit")
View Full Code Here

        throw new IOException("can not load resource [" + resource + "] from classpath");
      }
      BufferedReader r = new BufferedReader(new InputStreamReader(in, MethodDatabase.UTF_8));
      db.getUserDefinedWaveConfigFiles().add(resource);
      String l = null;
      ClassEntry ce = null;
      LazyClassEntry lce = null;
      FuzzyLazyClassEntry flce = null;
      int lc = 0;
      String clz = null;
      while ((l = r.readLine()) != null) {
        lc++;
        l = l.trim();
        if (l.startsWith("class:")) {
          lce = null;
          flce = null;
          clz = l.substring("class:".length());
          ce = db.getClasses().get(clz);
          if (ce == null) {
            ce = buildClassEntryFamily(db, clz);
            if (ce == null) {
              db.warn("file %s line %d : not found class: %s", resource , lc,  clz);
              ce = null;
              continue;
            }
          }
        }else if (l.startsWith("lazyclass:")) {
          clz = l.substring("lazyclass:".length());
          ce = null;
          flce = null;
          lce = db.getLazyClasses().get(clz);
          if (lce == null) {
            db.getLazyClasses().put(clz, lce = new LazyClassEntry(resource));
          }
        }else if (l.startsWith("fuzzyclass:")) {
          clz = l.substring("fuzzyclass:".length());
          ce = null;
          lce = null;
          flce = new FuzzyLazyClassEntry(Pattern.compile(clz), resource);
          db.getFuzzlyLazyClasses().add(flce);
        }else if (l.startsWith("retransform:")) {
          db.getRetransformedClasses().add(l.substring("retransform:".length()).trim());
          ce = null;
          lce = null;
          flce = null;
        }else if (l.startsWith("filter:")) {
          db.getFilters().add(l.substring("filter:".length()).trim());
          ce = null;
          lce = null;
          flce = null;
        }else if (l.length() == 0 || (ce == null && lce == null && flce == null) || l.charAt(0) == '#'){
          continue;
        }else {
          String[] ma = l.split(":");
          String m = ma[0];
          Integer st = MethodDatabase.SUSPEND_NORMAL;
          if (ma.length > 1) {
            if (MethodDatabase.SUSPEND_NORMAL_STR.equals(ma[1])) {
              st = MethodDatabase.SUSPEND_NORMAL;
            }else if (MethodDatabase.SUSPEND_NONE_STR.equals(ma[1])) {
              st = MethodDatabase.SUSPEND_NONE;
            }else if (MethodDatabase.SUSPEND_JUST_MARK_STR.equals(ma[1])) {
              st = MethodDatabase.SUSPEND_JUST_MARK;
            }else if (MethodDatabase.SUSPEND_BLOCKING_STR.equals(ma[1])) {
              st = MethodDatabase.SUSPEND_BLOCKING;
            }else if (MethodDatabase.SUSPEND_FAMILY_STR.equals(ma[1])) {
              st = MethodDatabase.SUSPEND_FAMILY;
            }else if (MethodDatabase.SUSPEND_SKIP_STR.equals(ma[1])) {
              st = MethodDatabase.SUSPEND_SKIP;
            }else {
              db.warn("file %s line %d : unknown suspend type: %s , we just set to 'normal'", resource , lc, ma[1]);
              st = MethodDatabase.SUSPEND_NORMAL;
            }
          }
          if (lce != null) {
            Map<String, Integer> methods = lce.getMethods();
            Integer ost = methods.get(m);
            if (ost == null || st.intValue() > ost.intValue()) {
              methods.put(m, st);
            }else {
              st = ost;
            }
            if (db.meetTraceTargetClassMethod(clz, m)) {
              db.info("meet traced method %s.%s, suspend type = %s", clz, m, MethodDatabase.SUSPEND_TYPE_STRS[st]);
            }
            continue;
          }else if (flce != null) {
            Map<String, Integer> methods = flce.getMethods();
            Integer ost = methods.get(m);
            if (ost == null || st.intValue() > ost.intValue()) {
              methods.put(m, st);
            }else {
              st = ost;
            }
            if (db.meetTraceTargetClassMethod(clz, m)) {
              db.info("meet traced method %s.%s, suspend type = %s", clz, m, MethodDatabase.SUSPEND_TYPE_STRS[st]);
            }
            continue;
          }
          if (m.charAt(0) == '/') { // regex pattern
            Pattern p = Pattern.compile(m.substring(1));
            boolean matched = false;
            for (Entry<String, Integer> me : ce.getMethods().entrySet()) {
              if (p.matcher(me.getKey()).find()) {
                me.setValue(st);
                matched = true;
              }
            }
            if (!matched) {
              db.warn("file %s line %d : none of methods matched regex: %s ,ignored", resource , lc, m);
            }
          }else if (ce.getMethods().get(m) == null) {
            db.warn("file %s line %d : unknown method: %s ,ignored", resource , lc, m);
            continue;
          }else {
            Integer ost = ce.getMethods().get(m);
            if (ost == null || st.intValue() > ost.intValue()) {
              ce.set(m, st);
            }else {
              st = ost;
            }
            if (db.meetTraceTargetClassMethod(clz, m)) {
              db.info("meet traced method %s.%s, suspend type = %s", clz, m, MethodDatabase.SUSPEND_TYPE_STRS[st]);
View Full Code Here

    }
    return rt.toString();
  }
 
  public static ClassEntry buildClassEntryFamily(MethodDatabase db, ClassReader r) {
    ClassEntry ce = db.getClasses().get(r.getClassName());
    if (ce == null) {
      CheckInstrumentationVisitor civ = db.checkClass(r);
      return buildClassEntryFamily(db, civ);
    }
    return ce;
View Full Code Here

      }
    }
  }
 
  public static ClassEntry buildClassEntryFamily(MethodDatabase db, CheckInstrumentationVisitor civ) {
    ClassEntry ce = civ.getClassEntry();
    String clz = civ.getName();
    LazyClassEntry lce = db.getLazyClasses().get(clz);
   
    if (lce != null) {
      db.debug("rebuild wave info for lazy class %s", clz);
      for (Entry<String, Integer> lme : lce.getMethods().entrySet()) {
        String m = lme.getKey();
        Integer st = lme.getValue();
        if (m.charAt(0) == '/') { // regex pattern
          Pattern p = Pattern.compile(m.substring(1));
          boolean matched = false;
          for (Entry<String, Integer> me : ce.getMethods().entrySet()) {
            if (p.matcher(me.getKey()).find()) {
              me.setValue(st);
              matched = true;
            }
          }
          if (!matched) {
            db.warn("file %s lazy class %s: none of methods matched regex: %s ,ignored", lce.getResource() , clz, m);
          }
        }else if (ce.getMethods().get(m) == null) {
          db.warn("file %s lazy class %s:  : unknown method: %s ,ignored", lce.getResource() , clz, m);
          continue;
        }else {
          Integer ost = ce.getMethods().get(m);
          if (ost == null || st.intValue() > ost.intValue()) {
            ce.set(m, st);
          }
        }
      }
    }
   
    if (FUZZY_CLASS_PATTERN.matcher(clz).find()) {
      for (FuzzyLazyClassEntry flce : db.getFuzzlyLazyClasses()) {
        if (flce.getPattern().matcher(clz).find()) {
          db.debug("rebuild wave info for fuzzylazy class %s, pattern %s", clz, flce.getPattern().toString());
          for (Entry<String, Integer> lme : flce.getMethods().entrySet()) {
            String m = lme.getKey();
            Integer st = lme.getValue();
            if (m.charAt(0) == '/') { // regex pattern
              Pattern p = Pattern.compile(m.substring(1));
              boolean matched = false;
              for (Entry<String, Integer> me : ce.getMethods().entrySet()) {
                if (p.matcher(me.getKey()).find()) {
                  me.setValue(st);
                  matched = true;
                }
              }
              if (!matched) {
                db.warn("file %s fuzzylazy class %s: none of methods matched regex: %s ,ignored", flce.getResource() , clz, m);
              }
            }else if (ce.getMethods().get(m) == null) {
              db.warn("file %s fuzzylazy class %s:  : unknown method: %s ,ignored", flce.getResource() , clz, m);
              continue;
            }else {
              Integer ost = ce.getMethods().get(m);
              if (ost == null || st.intValue() > ost.intValue()) {
                ce.set(m, st);
              }
            }
          }
        }
      }
    }
   
    String superName = ce.getSuperName();
    db.recordSuspendableMethods(clz, ce);
   
    if (superName != null) {
      ClassEntry sce = db.getClasses().get(superName);
      if (sce == null) {
        CheckInstrumentationVisitor sciv = db.checkClass(superName);
        if (sciv == null) {
          db.error("super class %s can not visited", superName);
        }else {
          sce = buildClassEntryFamily(db, sciv);
          db.recordSuspendableMethods(superName, sce);
        }
      }
     
      mergeMethodsSuspendTypeFromSuper(ce, sce);
    }
   
    String[] interfaces = ce.getInterfaces();
    if (interfaces != null) {
      for (String itf : interfaces) {
        ClassEntry sce = db.getClasses().get(itf);
        if (sce == null) {
          CheckInstrumentationVisitor sciv = db.checkClass(itf);
          if (sciv == null) {
            return null;
          }
View Full Code Here

  @Test
  public void testLoad() throws IOException {
    MethodDatabase db = new MethodDatabase(Thread.currentThread().getContextClassLoader());
    MethodDatabaseUtil.load(db, "nginx/clojure/wave/test-coroutine-method-db.txt");
    ClassEntry ce = db.getClasses().get("java/lang/Thread");
    assertEquals(MethodDatabase.SUSPEND_BLOCKING, ce.check("sleep", "(J)V"));
    assertEquals(MethodDatabase.SUSPEND_BLOCKING, ce.check("sleep", "(JI)V"));
    assertEquals(MethodDatabase.SUSPEND_BLOCKING, ce.check("join", "()V"));
   
   
    ce = db.getClasses().get("java/lang/Object");
    assertEquals(MethodDatabase.SUSPEND_BLOCKING, ce.check("wait", "(J)V"));
    assertEquals(MethodDatabase.SUSPEND_BLOCKING, ce.check("wait", "()V"));
    assertEquals(MethodDatabase.SUSPEND_BLOCKING, ce.check("wait", "(JI)V"));
    assertNull(ce.check("test-unknown-method", "()V"));
   
    ce = db.getClasses().get("clojure/lang/IFn");
    assertEquals(MethodDatabase.SUSPEND_FAMILY, ce.check("invoke", "()Ljava/lang/Object;"));
   
    ClassEntry mce = MethodDatabaseUtil.buildClassEntryFamily(db, Type.getInternalName(MyAF.class));
    assertEquals(MethodDatabase.SUSPEND_FAMILY, db.checkMethodSuspendType(Type.getInternalName(MyAF.class), "invoke()Ljava/lang/Object;", true));
   
  }
View Full Code Here

    }
   
    @Override
    public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
        this.className = name;
        this.classEntry = new ClassEntry(superName, interfaces, (access & Opcodes.ACC_INTERFACE) != 0);
    }
View Full Code Here

        MethodInfo mi = stack.get(i);
        if (mi.suspendType != -1 || ("nginx/clojure/Coroutine".equals(mi.owner) && "resume()V".equals(mi.method))) {
          break;
        }
       
        ClassEntry ce = db.getClasses().get(mi.owner);
       
        if (ce == null) {
          vi.exception = true;
          db.error(new RuntimeException(String.format("#%d onYield: can not found ClassEntry for %s", vi.vid, mi.owner)));
          return;
        }
       
        if (!ce.isAlreadyInstrumented()) {
          vi.exception = true;
          db.error(new RuntimeException(String.format("#%d onYield: %s is not AlreadyInstrumented!", vi.vid, mi.owner)));
          return;
        }
       
View Full Code Here

      quiteFlags.set(false);
    }
  }
 
  public static void markSuper(String clz, Set<String> methods, Map<String, TreeMap<String, String>> upperMarks) {
    ClassEntry ce = db.getClasses().get(clz);
    if (ce == null) {
      db.warn("can not found class %s in db, maybe its' suspend info defined in orginal configuration file");
      return;
    }
    String[] itfs = ce.getInterfaces();
    if (itfs != null) {
      for (String itf : ce.getInterfaces()) {
        markSuper(itf, clz, methods, upperMarks);
      }
      String sclz = ce.getSuperName();
      if (sclz != null) {
        markSuper(sclz, clz, methods, upperMarks);
      }
    }
  }
View Full Code Here

TOP

Related Classes of nginx.clojure.wave.MethodDatabase.ClassEntry

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.