Search in sources :

Example 1 with ClassInternalNameMatcherOperand

use of com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand in project pinpoint by naver.

the class DefaultTransformerMatcherTest method matchClass.

@Test
public void matchClass() throws Exception {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    InstrumentMatcherCacheConfig config = new DefaultInstrumentMatcherCacheConfig();
    TransformerMatcher matcher = new DefaultTransformerMatcher(config);
    InternalClassMetadata stringClassMetadata = readClassMetadata(classLoader, String.class.getName());
    InternalClassMetadata threadClassMetadata = readClassMetadata(classLoader, Thread.class.getName());
    InternalClassMetadata inputStreamClassMetadata = readClassMetadata(classLoader, InputStream.class.getName());
    MatcherOperand operand = null;
    // single operand.
    operand = new ClassInternalNameMatcherOperand("java/lang/String");
    boolean result = matcher.match(classLoader, operand, stringClassMetadata);
    assertTrue(result);
    // not matched.
    operand = new ClassInternalNameMatcherOperand("java/io/InputStream");
    result = matcher.match(classLoader, operand, stringClassMetadata);
    assertFalse(result);
    // and operator
    // package AND interface
    operand = new PackageInternalNameMatcherOperand("java/lang").and(new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false));
    // java.lang.Thread
    result = matcher.match(classLoader, operand, threadClassMetadata);
    assertTrue(result);
    // java.lang.String
    result = matcher.match(classLoader, operand, stringClassMetadata);
    assertFalse(result);
    // or operator
    // package OR interface
    operand = new PackageInternalNameMatcherOperand("java/lang").or(new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false));
    // java.lang.Thread
    result = matcher.match(classLoader, operand, threadClassMetadata);
    assertTrue(result);
    // java.lang.String
    result = matcher.match(classLoader, operand, stringClassMetadata);
    assertTrue(result);
    // not operator
    // NOT interface.
    operand = new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false);
    operand = operand.not();
    // java.lang.Thread
    result = matcher.match(classLoader, operand, threadClassMetadata);
    assertFalse(result);
    // java.lang.String
    result = matcher.match(classLoader, operand, stringClassMetadata);
    assertTrue(result);
    // complex operator
    // (class or interface) AND (class or interface) ==> class, interface
    operand = new ClassInternalNameMatcherOperand("java/lang/String").or(new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false));
    operand = operand.and(new ClassInternalNameMatcherOperand("java/lang/Thread").or(new InterfaceInternalNameMatcherOperand("java/lang/Comparable", false)));
    result = matcher.match(classLoader, operand, stringClassMetadata);
    assertTrue(result);
    result = matcher.match(classLoader, operand, threadClassMetadata);
    assertTrue(result);
    // (class AND interface) OR (class AND interface) ==> class, class
    operand = new ClassInternalNameMatcherOperand("java/lang/String").and(new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false));
    operand = operand.or(new ClassInternalNameMatcherOperand("java/lang/Thread").and(new InterfaceInternalNameMatcherOperand("java/lang/Comparable", false)));
    result = matcher.match(classLoader, operand, stringClassMetadata);
    assertFalse(result);
    result = matcher.match(classLoader, operand, threadClassMetadata);
    assertFalse(result);
    // package AND (interface OR annotation) ==> package
    operand = new PackageInternalNameMatcherOperand("java/lang");
    operand = operand.and(new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false).or(new AnnotationInternalNameMatcherOperand("java/lang/Override", false)));
    result = matcher.match(classLoader, operand, stringClassMetadata);
    assertFalse(result);
    result = matcher.match(classLoader, operand, threadClassMetadata);
    assertTrue(result);
    // class OR (interface AND NOT annotation)
    operand = new ClassInternalNameMatcherOperand("java/lang/String");
    operand = operand.or(new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false).and(new AnnotationInternalNameMatcherOperand("java/lang/Override", false).not()));
    result = matcher.match(classLoader, operand, stringClassMetadata);
    assertTrue(result);
    result = matcher.match(classLoader, operand, threadClassMetadata);
    assertTrue(result);
}
Also used : InterfaceInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.InterfaceInternalNameMatcherOperand) SuperClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.SuperClassInternalNameMatcherOperand) ClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand) InterfaceInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.InterfaceInternalNameMatcherOperand) MatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand) AnnotationInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.AnnotationInternalNameMatcherOperand) PackageInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.PackageInternalNameMatcherOperand) InputStream(java.io.InputStream) PackageInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.PackageInternalNameMatcherOperand) DefaultInstrumentMatcherCacheConfig(com.navercorp.pinpoint.profiler.instrument.config.DefaultInstrumentMatcherCacheConfig) InstrumentMatcherCacheConfig(com.navercorp.pinpoint.profiler.instrument.config.InstrumentMatcherCacheConfig) DefaultInstrumentMatcherCacheConfig(com.navercorp.pinpoint.profiler.instrument.config.DefaultInstrumentMatcherCacheConfig) InternalClassMetadata(com.navercorp.pinpoint.profiler.instrument.classreading.InternalClassMetadata) AnnotationInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.AnnotationInternalNameMatcherOperand) SuperClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.SuperClassInternalNameMatcherOperand) ClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand) Test(org.junit.Test)

Example 2 with ClassInternalNameMatcherOperand

use of com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand in project pinpoint by naver.

the class DefaultMultiClassBasedMatcher method joinOr.

private MatcherOperand joinOr(List<String> baseClassNames) {
    MatcherOperand operand = null;
    for (String baseClassName : baseClassNames) {
        if (operand == null) {
            operand = new ClassInternalNameMatcherOperand(baseClassName);
        } else {
            // class OR ...
            final MatcherOperand classMatcherOperand = new ClassInternalNameMatcherOperand(baseClassName);
            operand = operand.or(classMatcherOperand);
        }
    }
    return operand;
}
Also used : MatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand) ClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand) ClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand)

Example 3 with ClassInternalNameMatcherOperand

use of com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand in project pinpoint by naver.

the class TransformerMatcherExecutionPlannerTest method findIndex.

@Test
public void findIndex() {
    TransformerMatcherExecutionPlanner executionPlanner = new TransformerMatcherExecutionPlanner();
    // and
    MatcherOperand operand = new ClassInternalNameMatcherOperand("java/lang/String");
    operand = operand.and(new InterfaceInternalNameMatcherOperand("java/lang/Comparable", false));
    operand = operand.and(new AnnotationInternalNameMatcherOperand("java/lang/Override", false));
    operand = operand.and(new PackageInternalNameMatcherOperand("java/lang"));
    List<MatcherOperand> result = executionPlanner.findIndex(operand);
    assertEquals(1, result.size());
    // or
    operand = new ClassInternalNameMatcherOperand("java/lang/String");
    operand = operand.or(new InterfaceInternalNameMatcherOperand("java/lang/Comparable", false));
    operand = operand.or(new AnnotationInternalNameMatcherOperand("java/lang/Override", false));
    operand = operand.or(new PackageInternalNameMatcherOperand("java/lang"));
    result = executionPlanner.findIndex(operand);
    assertEquals(2, result.size());
    // not
    operand = new InterfaceInternalNameMatcherOperand("java/lang/Comparable", false);
    operand = operand.or(new AnnotationInternalNameMatcherOperand("java/lang/Override", false));
    operand = operand.and(new PackageInternalNameMatcherOperand("javax").not());
    result = executionPlanner.findIndex(operand);
    assertEquals(0, result.size());
    // none
    operand = new InterfaceInternalNameMatcherOperand("java/lang/Comparable", false);
    operand = operand.or(new AnnotationInternalNameMatcherOperand("java/lang/Override", false));
    operand = operand.and(new SuperClassInternalNameMatcherOperand("java/lang/Object", true));
    result = executionPlanner.findIndex(operand);
    assertEquals(0, result.size());
}
Also used : InterfaceInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.InterfaceInternalNameMatcherOperand) MatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand) AnnotationInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.AnnotationInternalNameMatcherOperand) SuperClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.SuperClassInternalNameMatcherOperand) PackageInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.PackageInternalNameMatcherOperand) ClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand) InterfaceInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.InterfaceInternalNameMatcherOperand) AnnotationInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.AnnotationInternalNameMatcherOperand) PackageInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.PackageInternalNameMatcherOperand) SuperClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.SuperClassInternalNameMatcherOperand) SuperClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.SuperClassInternalNameMatcherOperand) ClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand) Test(org.junit.Test)

Example 4 with ClassInternalNameMatcherOperand

use of com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand in project pinpoint by naver.

the class MatchableTransformerRegistry method addIndex.

private void addIndex(final MatcherOperand condition, final ClassFileTransformer transformer) {
    // find class or package matcher operand.
    final List<MatcherOperand> indexedMatcherOperands = executionPlanner.findIndex(condition);
    if (indexedMatcherOperands.isEmpty()) {
        throw new IllegalArgumentException("invalid matcher - not found index operand. condition=" + condition);
    }
    boolean indexed;
    final IndexValue indexValue = new IndexValue(condition, transformer);
    for (MatcherOperand operand : indexedMatcherOperands) {
        if (operand instanceof ClassInternalNameMatcherOperand) {
            ClassInternalNameMatcherOperand classInternalNameMatcherOperand = (ClassInternalNameMatcherOperand) operand;
            final IndexValue prev = classNameBasedIndex.put(classInternalNameMatcherOperand.getClassInternalName(), indexValue);
            if (prev != null) {
                throw new IllegalStateException("Transformer already exist. class=" + classInternalNameMatcherOperand.getClassInternalName() + ", new=" + indexValue + ", prev=" + prev);
            }
            indexed = true;
        } else if (operand instanceof PackageInternalNameMatcherOperand) {
            PackageInternalNameMatcherOperand packageInternalNameMatcherOperand = (PackageInternalNameMatcherOperand) operand;
            addIndexData(packageInternalNameMatcherOperand.getPackageInternalName(), indexValue, this.packageNameBasedIndex);
            indexed = true;
        } else {
            throw new IllegalArgumentException("invalid matcher or execution planner - unknown operand. condition=" + condition + ", unknown operand=" + operand);
        }
        if (!indexed) {
            throw new IllegalArgumentException("invalid matcher or execution planner - no such indexed operand. operand=" + condition);
        }
    }
}
Also used : ClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand) MatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand) PackageInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.PackageInternalNameMatcherOperand) PackageInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.PackageInternalNameMatcherOperand) ClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand)

Example 5 with ClassInternalNameMatcherOperand

use of com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand in project pinpoint by naver.

the class DefaultMultiClassBasedMatcherTest method getMatcherOperandWithMultiClassName.

@Test
public void getMatcherOperandWithMultiClassName() {
    // (class OR class)
    DefaultMultiClassBasedMatcher matcher = new DefaultMultiClassBasedMatcher(Arrays.asList("java.lang.String", "java.lang.Thread"));
    assertTrue(matcher.getBaseClassNames().contains("java.lang.String"));
    assertTrue(matcher.getBaseClassNames().contains("java.lang.Thread"));
    MatcherOperand operand = matcher.getMatcherOperand();
    assertTrue(operand instanceof OrMatcherOperator);
    OrMatcherOperator operator = (OrMatcherOperator) operand;
    assertTrue(operator.getLeftOperand() instanceof ClassInternalNameMatcherOperand);
    ClassInternalNameMatcherOperand leftOperand = (ClassInternalNameMatcherOperand) operator.getLeftOperand();
    assertEquals("java/lang/String", leftOperand.getClassInternalName());
    assertTrue(operator.getRightOperand() instanceof ClassInternalNameMatcherOperand);
    ClassInternalNameMatcherOperand rightOperand = (ClassInternalNameMatcherOperand) operator.getRightOperand();
    assertEquals("java/lang/Thread", rightOperand.getClassInternalName());
}
Also used : MatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand) ClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand) InterfaceInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.InterfaceInternalNameMatcherOperand) OrMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.OrMatcherOperator) ClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand) Test(org.junit.Test)

Aggregations

ClassInternalNameMatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand)9 InterfaceInternalNameMatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.InterfaceInternalNameMatcherOperand)7 MatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand)7 Test (org.junit.Test)7 PackageInternalNameMatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.PackageInternalNameMatcherOperand)3 AnnotationInternalNameMatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.AnnotationInternalNameMatcherOperand)2 SuperClassInternalNameMatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.SuperClassInternalNameMatcherOperand)2 AndMatcherOperator (com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.AndMatcherOperator)1 OrMatcherOperator (com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.OrMatcherOperator)1 InternalClassMetadata (com.navercorp.pinpoint.profiler.instrument.classreading.InternalClassMetadata)1 DefaultInstrumentMatcherCacheConfig (com.navercorp.pinpoint.profiler.instrument.config.DefaultInstrumentMatcherCacheConfig)1 InstrumentMatcherCacheConfig (com.navercorp.pinpoint.profiler.instrument.config.InstrumentMatcherCacheConfig)1 InputStream (java.io.InputStream)1