Search in sources :

Example 11 with MatcherOperand

use of com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand 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 12 with MatcherOperand

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

the class TransformerMatcherExecutionPlanner method traversal.

// find indexed operands.
private boolean traversal(final MatcherOperand operand, final List<MatcherOperand> index) {
    if (!operand.isOperator()) {
        if (operand.isIndex()) {
            index.add(operand);
            return true;
        }
        return false;
    }
    if (operand instanceof NotMatcherOperator) {
        // skip NOT operator.
        return false;
    }
    MatcherOperator operator = (MatcherOperator) operand;
    final MatcherOperand leftOperand = operator.getLeftOperand();
    if (leftOperand == null) {
        throw new IllegalArgumentException("invalid left operand - left operand must not be null. operator=" + operator);
    }
    final MatcherOperand rightOperand = operator.getRightOperand();
    if (rightOperand == null) {
        throw new IllegalArgumentException("invalid right operand - right operand must not be null. operator=" + operator);
    }
    if (operand instanceof AndMatcherOperator) {
        // if find any.
        final boolean indexed = traversal(leftOperand, index);
        if (indexed) {
            return true;
        }
        return traversal(rightOperand, index);
    } else if (operand instanceof OrMatcherOperator) {
        // find all.
        final boolean indexed = traversal(leftOperand, index);
        return traversal(rightOperand, index) || indexed;
    } else {
        throw new IllegalArgumentException("unknown operator. operator=" + operand);
    }
}
Also used : MatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand) AndMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.AndMatcherOperator) OrMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.OrMatcherOperator) AndMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.AndMatcherOperator) MatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.MatcherOperator) NotMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.NotMatcherOperator) OrMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.OrMatcherOperator) NotMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.NotMatcherOperator)

Example 13 with MatcherOperand

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

the class DefaultTransformerMatcher method traversal.

boolean traversal(ClassLoader classLoader, MatcherOperand operand, InternalClassMetadata classMetadata) {
    if (operand instanceof NotMatcherOperator) {
        NotMatcherOperator operator = (NotMatcherOperator) operand;
        if (operator.getRightOperand() == null) {
            throw new IllegalArgumentException("invalid operator - not found right operand. operator=" + operator);
        }
        final MatcherOperand rightOperand = operator.getRightOperand();
        // NOT
        return match(classLoader, rightOperand, classMetadata) == false;
    }
    MatcherOperator operator = (MatcherOperator) operand;
    // for binary operator.
    if (operator.getLeftOperand() == null) {
        throw new IllegalArgumentException("invalid operator - not found left operand. operator=" + operator);
    }
    final MatcherOperand leftOperand = operator.getLeftOperand();
    if (operator.getRightOperand() == null) {
        throw new IllegalArgumentException("invalid operator - not found right operand. operator=" + operator);
    }
    final MatcherOperand rightOperand = operator.getRightOperand();
    MatcherOperand firstOperand = leftOperand;
    MatcherOperand secondOperand = rightOperand;
    if (leftOperand.getExecutionCost() > rightOperand.getExecutionCost()) {
        // cost-based execution plan.
        firstOperand = rightOperand;
        secondOperand = leftOperand;
    }
    if (operand instanceof OrMatcherOperator) {
        // OR
        if (match(classLoader, firstOperand, classMetadata)) {
            return true;
        }
        return match(classLoader, secondOperand, classMetadata);
    } else if (operand instanceof AndMatcherOperator) {
        // AND
        if (match(classLoader, firstOperand, classMetadata)) {
            return match(classLoader, secondOperand, classMetadata);
        }
        return false;
    } else {
        throw new IllegalArgumentException("unknown operator. operator=" + operator);
    }
}
Also used : 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) AndMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.AndMatcherOperator) OrMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.OrMatcherOperator) NotMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.NotMatcherOperator) OrMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.OrMatcherOperator) AndMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.AndMatcherOperator) MatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.MatcherOperator) NotMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.NotMatcherOperator)

Example 14 with MatcherOperand

use of com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand 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)

Example 15 with MatcherOperand

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

the class DefaultPackageBasedMatcherTest method getMatcherOperandWithPackageNameAndAdditionalIsNull.

@Test
public void getMatcherOperandWithPackageNameAndAdditionalIsNull() {
    // check unusual pattern.
    PackageBasedMatcher classMatcher = new DefaultPackageBasedMatcher("java.lang", null);
    MatcherOperand operand = classMatcher.getMatcherOperand();
    assertTrue(operand instanceof PackageInternalNameMatcherOperand);
    PackageInternalNameMatcherOperand annotationInternalNameMatcherOperand = (PackageInternalNameMatcherOperand) operand;
    assertEquals("java/lang", annotationInternalNameMatcherOperand.getPackageInternalName());
}
Also used : MatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand) PackageInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.PackageInternalNameMatcherOperand) InterfaceInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.InterfaceInternalNameMatcherOperand) PackageInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.PackageInternalNameMatcherOperand) Test(org.junit.Test)

Aggregations

MatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand)17 ClassInternalNameMatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand)11 InterfaceInternalNameMatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.InterfaceInternalNameMatcherOperand)10 PackageInternalNameMatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.PackageInternalNameMatcherOperand)10 Test (org.junit.Test)10 AndMatcherOperator (com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.AndMatcherOperator)5 OrMatcherOperator (com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.OrMatcherOperator)5 AnnotationInternalNameMatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.AnnotationInternalNameMatcherOperand)3 SuperClassInternalNameMatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.SuperClassInternalNameMatcherOperand)3 MatcherOperator (com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.MatcherOperator)2 NotMatcherOperator (com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.NotMatcherOperator)2 BasedMatcher (com.navercorp.pinpoint.bootstrap.instrument.matcher.BasedMatcher)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