Search in sources :

Example 1 with PinpointException

use of com.navercorp.pinpoint.exception.PinpointException in project pinpoint by naver.

the class TargetAnnotatedInterceptorInjector method createMethodEditor.

private ClassRecipe createMethodEditor(ClassLoader classLoader, Class<?> interceptorType, InstrumentClass targetClass, AnnotatedInterceptorInjector injector) {
    List<MethodTransformer> editors = new ArrayList<MethodTransformer>();
    TargetMethods targetMethods = interceptorType.getAnnotation(TargetMethods.class);
    if (targetMethods != null) {
        for (TargetMethod m : targetMethods.value()) {
            editors.add(createDedicatedMethodEditor(m, injector));
        }
    }
    TargetConstructors targetConstructors = interceptorType.getAnnotation(TargetConstructors.class);
    if (targetConstructors != null) {
        for (TargetConstructor c : targetConstructors.value()) {
            editors.add(createConstructorEditor(c, injector));
        }
    }
    TargetMethod targetMethod = interceptorType.getAnnotation(TargetMethod.class);
    if (targetMethod != null) {
        editors.add(createDedicatedMethodEditor(targetMethod, injector));
    }
    TargetConstructor targetConstructor = interceptorType.getAnnotation(TargetConstructor.class);
    if (targetConstructor != null) {
        editors.add(createConstructorEditor(targetConstructor, injector));
    }
    TargetFilter targetFilter = interceptorType.getAnnotation(TargetFilter.class);
    if (targetFilter != null) {
        editors.add(createFilteredMethodEditor(targetFilter, targetClass, injector, classLoader));
    }
    if (editors.isEmpty()) {
        throw new PinpointException("No target is specified. At least one of @Targets, @TargetMethod, @TargetConstructor, @TargetFilter must present. interceptor: " + interceptorClassName);
    }
    return editors.size() == 1 ? editors.get(0) : new ClassCookBook(editors);
}
Also used : TargetConstructors(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetConstructors) MethodTransformer(com.navercorp.pinpoint.profiler.plugin.xml.transformer.MethodTransformer) DedicatedMethodTransformer(com.navercorp.pinpoint.profiler.plugin.xml.transformer.DedicatedMethodTransformer) FilteringMethodTransformer(com.navercorp.pinpoint.profiler.plugin.xml.transformer.FilteringMethodTransformer) TargetMethod(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetMethod) ClassCookBook(com.navercorp.pinpoint.profiler.plugin.xml.transformer.ClassCookBook) TargetMethods(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetMethods) PinpointException(com.navercorp.pinpoint.exception.PinpointException) ArrayList(java.util.ArrayList) TargetConstructor(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetConstructor) TargetFilter(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetFilter)

Example 2 with PinpointException

use of com.navercorp.pinpoint.exception.PinpointException in project pinpoint by naver.

the class DedicatedClassFileTransformer method transform.

@Override
public byte[] transform(ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
    try {
        InstrumentClass target = context.getInstrumentClass(classLoader, className, classfileBuffer);
        recipe.edit(classLoader, target);
        return target.toBytecode();
    } catch (PinpointException e) {
        throw e;
    } catch (Throwable e) {
        String msg = "Fail to invoke plugin class recipe: " + toString();
        throw new PinpointException(msg, e);
    }
}
Also used : PinpointException(com.navercorp.pinpoint.exception.PinpointException) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)

Example 3 with PinpointException

use of com.navercorp.pinpoint.exception.PinpointException in project pinpoint by naver.

the class ASMClass method addInterceptor0.

private int addInterceptor0(String interceptorClassName, Object[] constructorArgs, InterceptorScope scope, ExecutionPolicy executionPolicy) throws InstrumentException {
    int interceptorId = -1;
    final Class<?> interceptorType = this.pluginContext.injectClass(this.classLoader, interceptorClassName);
    final TargetMethods targetMethods = interceptorType.getAnnotation(TargetMethods.class);
    if (targetMethods != null) {
        for (TargetMethod m : targetMethods.value()) {
            interceptorId = addInterceptor0(m, interceptorClassName, constructorArgs, scope, executionPolicy);
        }
    }
    final TargetMethod targetMethod = interceptorType.getAnnotation(TargetMethod.class);
    if (targetMethod != null) {
        interceptorId = addInterceptor0(targetMethod, interceptorClassName, constructorArgs, scope, executionPolicy);
    }
    final TargetConstructors targetConstructors = interceptorType.getAnnotation(TargetConstructors.class);
    if (targetConstructors != null) {
        for (TargetConstructor c : targetConstructors.value()) {
            interceptorId = addInterceptor0(c, interceptorClassName, scope, executionPolicy, constructorArgs);
        }
    }
    final TargetConstructor targetConstructor = interceptorType.getAnnotation(TargetConstructor.class);
    if (targetConstructor != null) {
        interceptorId = addInterceptor0(targetConstructor, interceptorClassName, scope, executionPolicy, constructorArgs);
    }
    final TargetFilter targetFilter = interceptorType.getAnnotation(TargetFilter.class);
    if (targetFilter != null) {
        interceptorId = addInterceptor0(targetFilter, interceptorClassName, scope, executionPolicy, constructorArgs);
    }
    if (interceptorId == -1) {
        throw new PinpointException("No target is specified. At least one of @Targets, @TargetMethod, @TargetConstructor, @TargetFilter must present. interceptor: " + interceptorClassName);
    }
    return interceptorId;
}
Also used : TargetConstructors(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetConstructors) TargetMethod(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetMethod) TargetMethods(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetMethods) PinpointException(com.navercorp.pinpoint.exception.PinpointException) TargetConstructor(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetConstructor) TargetFilter(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetFilter)

Example 4 with PinpointException

use of com.navercorp.pinpoint.exception.PinpointException in project pinpoint by naver.

the class PlainClassLoaderHandler method define0.

private void define0(final ClassLoader classLoader, ClassLoaderAttachment attachment, SimpleClassMetadata currentClass, Map<String, SimpleClassMetadata> classMetaMap, ClassLoadingChecker classLoadingChecker) {
    if ("java.lang.Object".equals(currentClass.getClassName())) {
        return;
    }
    if (attachment.containsClass(currentClass.getClassName())) {
        return;
    }
    final String superName = currentClass.getSuperClassName();
    if (isDebug) {
        logger.debug("className:{} super:{}", currentClass.getClassName(), superName);
    }
    if (!"java.lang.Object".equals(superName)) {
        if (!isSkipClass(superName, classLoadingChecker)) {
            SimpleClassMetadata superClassBinary = classMetaMap.get(superName);
            if (isDebug) {
                logger.debug("superClass dependency define super:{} ori:{}", superClassBinary.getClassName(), currentClass.getClassName());
            }
            define0(classLoader, attachment, superClassBinary, classMetaMap, classLoadingChecker);
        }
    }
    final List<String> interfaceList = currentClass.getInterfaceNames();
    for (String interfaceName : interfaceList) {
        if (!isSkipClass(interfaceName, classLoadingChecker)) {
            SimpleClassMetadata interfaceClassBinary = classMetaMap.get(interfaceName);
            if (interfaceClassBinary == null) {
                throw new PinpointException(interfaceName + " not found");
            }
            if (isDebug) {
                logger.debug("interface dependency define interface:{} ori:{}", interfaceClassBinary.getClassName(), interfaceClassBinary.getClassName());
            }
            define0(classLoader, attachment, interfaceClassBinary, classMetaMap, classLoadingChecker);
        }
    }
    final Class<?> clazz = defineClass(classLoader, currentClass);
    attachment.putClass(currentClass.getClassName(), clazz);
}
Also used : SimpleClassMetadata(com.navercorp.pinpoint.profiler.instrument.classreading.SimpleClassMetadata) PinpointException(com.navercorp.pinpoint.exception.PinpointException)

Example 5 with PinpointException

use of com.navercorp.pinpoint.exception.PinpointException in project pinpoint by naver.

the class DefaultModuleFactoryResolver method resolve.

@Override
public ModuleFactory resolve() {
    logger.info("{} ModuleFactory lookup", moduleFactoryClazzName);
    if (isDefaultModuleFactory(moduleFactoryClazzName)) {
        return new ApplicationContextModuleFactory();
    }
    ClassLoader classLoader = getClassLoader(DefaultModuleFactoryResolver.class.getClassLoader());
    try {
        final Class<? extends ModuleFactory> moduleFactoryClass = (Class<? extends ModuleFactory>) Class.forName(moduleFactoryClazzName, true, classLoader);
        Constructor<? extends ModuleFactory> constructor = moduleFactoryClass.getConstructor();
        return constructor.newInstance();
    } catch (Exception ex) {
        logger.warn("{} ModuleFactory initialize fail", moduleFactoryClazzName, ex);
        throw new PinpointException(moduleFactoryClazzName + " ModuleFactory initialize fail", ex);
    }
}
Also used : PinpointException(com.navercorp.pinpoint.exception.PinpointException) PinpointException(com.navercorp.pinpoint.exception.PinpointException)

Aggregations

PinpointException (com.navercorp.pinpoint.exception.PinpointException)25 TargetConstructor (com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetConstructor)4 TargetConstructors (com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetConstructors)4 TargetFilter (com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetFilter)4 TargetMethod (com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetMethod)4 TargetMethods (com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetMethods)4 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)2 InstrumentContext (com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext)2 InstrumentException (com.navercorp.pinpoint.bootstrap.instrument.InstrumentException)2 TransformCallback (com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback)2 GuardInstrumentor (com.navercorp.pinpoint.profiler.instrument.GuardInstrumentor)2 FilteringMethodTransformer (com.navercorp.pinpoint.profiler.plugin.xml.transformer.FilteringMethodTransformer)2 InstrumentClass (com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)1 MethodFilter (com.navercorp.pinpoint.bootstrap.instrument.MethodFilter)1 ByStaticFactoryMethod (com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory.ByStaticFactoryMethod)1 SimpleClassMetadata (com.navercorp.pinpoint.profiler.instrument.classreading.SimpleClassMetadata)1 AutoBindingObjectFactory (com.navercorp.pinpoint.profiler.objectfactory.AutoBindingObjectFactory)1 InterceptorArgumentProvider (com.navercorp.pinpoint.profiler.objectfactory.InterceptorArgumentProvider)1 ClassCookBook (com.navercorp.pinpoint.profiler.plugin.xml.transformer.ClassCookBook)1 DedicatedMethodTransformer (com.navercorp.pinpoint.profiler.plugin.xml.transformer.DedicatedMethodTransformer)1