Arthas 学习使用1:排查NoSuchMethodError

利用Arthas排查NoSuchMethodError

curl -O --insecure https://alibaba.github.io/arthas/arthas-boot.jar
java -jar arthas-boot.jar

https://github.com/hengyunabc/spring-boot-inside/tree/master/demo-NoSuchMethodError的基础上,将 org.springframework.spring.2.5.6.SEC03 注释之后,再重新运行,得到结果

[arthas@19153]$ sc -d org.springframework.core.annotation.AnnotationAwareOrderComparator
 class-info        org.springframework.core.annotation.AnnotationAwareOrderComparator
 code-source       file:/Users/yangxiaohuan/Downloads/temp_2019_09_19/spring-boot-inside/demo-NoSuchMethodError/target/demo-NoSuchMethodError-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/sp
                   ring-core-4.3.19.RELEASE.jar!/
 name              org.springframework.core.annotation.AnnotationAwareOrderComparator
 isInterface       false
 isAnnotation      false
 isEnum            false
 isAnonymousClass  false
 isArray           false
 isLocalClass      false
 isMemberClass     false
 isPrimitive       false
 isSynthetic       false
 simple-name       AnnotationAwareOrderComparator
 modifier          public
 annotation
 interfaces
 super-class       +-org.springframework.core.OrderComparator
                     +-java.lang.Object
 class-loader      +-org.springframework.boot.loader.LaunchedURLClassLoader@38af3868
                     +-sun.misc.Launcher$AppClassLoader@42a57993
                       +-sun.misc.Launcher$ExtClassLoader@1b3f3783
 classLoaderHash   38af3868

Affect(row-cnt:1) cost in 29 ms.

可以看到AnnotationAwareOrderComparator是来自于 spring-core-4.3.19.RELEASE.jar

[arthas@19153]$ jad org.springframework.core.annotation.AnnotationAwareOrderComparator

ClassLoader:
+-org.springframework.boot.loader.LaunchedURLClassLoader@38af3868
  +-sun.misc.Launcher$AppClassLoader@42a57993
    +-sun.misc.Launcher$ExtClassLoader@1b3f3783

Location:
file:/Users/yangxiaohuan/Downloads/temp_2019_09_19/spring-boot-inside/demo-NoSuchMethodError/target/demo-NoSuchMethodError-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/spring-core-4.3.19.REL
EASE.jar!/

/*
 * Decompiled with CFR.
 *
 * Could not load the following classes:
 *  org.springframework.core.DecoratingProxy
 *  org.springframework.core.OrderComparator
 *  org.springframework.core.annotation.AnnotationUtils
 *  org.springframework.core.annotation.Order
 *  org.springframework.core.annotation.OrderUtils
 */
package org.springframework.core.annotation;

import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.springframework.core.DecoratingProxy;
import org.springframework.core.OrderComparator;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.annotation.Order;
import org.springframework.core.annotation.OrderUtils;

public class AnnotationAwareOrderComparator
extends OrderComparator {
    public static final AnnotationAwareOrderComparator INSTANCE = new AnnotationAwareOrderComparator();

    public Integer getPriority(Object obj) {
        Integer priority = null;
        if (obj instanceof Class) {
            priority = OrderUtils.getPriority((Class)((Class)obj));
        } else if (obj != null && (priority = OrderUtils.getPriority(obj.getClass())) == null && obj instanceof DecoratingProxy) {
            priority = OrderUtils.getPriority((Class)((DecoratingProxy)obj).getDecoratedClass());
        }
        return priority;
    }

    public static void sort(List<?> list) {
        if (list.size() > 1) {
            Collections.sort(list, INSTANCE);
        }
    }

    public static void sort(Object[] array) {
        if (array.length > 1) {
            Arrays.sort(array, INSTANCE);
        }
    }

    protected Integer findOrder(Object obj) {
        Integer order = super.findOrder(obj);
        if (order != null) {
            return order;
        }
        if (obj instanceof Class) {
            return OrderUtils.getOrder((Class)((Class)obj));
        }
        if (obj instanceof Method) {
            Order ann = (Order)AnnotationUtils.findAnnotation((Method)((Method)obj), Order.class);
            if (ann != null) {
                return ann.value();
            }
        } else if (obj instanceof AnnotatedElement) {
            Order ann = (Order)AnnotationUtils.getAnnotation((AnnotatedElement)((AnnotatedElement)obj), Order.class);
            if (ann != null) {
                return ann.value();
            }
        } else if (obj != null && (order = OrderUtils.getOrder(obj.getClass())) == null && obj instanceof DecoratingProxy) {
            order = OrderUtils.getOrder((Class)((DecoratingProxy)obj).getDecoratedClass());
        }
        return order;
    }

    public static void sortIfNecessary(Object value) {
        if (value instanceof Object[]) {
            AnnotationAwareOrderComparator.sort((Object[])value);
        } else if (value instanceof List) {
            AnnotationAwareOrderComparator.sort((List)value);
        }
    }
}

Affect(row-cnt:1) cost in 889 ms.

无论是 Arthas 还是 BTrace ,都是用来排查单机服务问题的,也就是应用内部的代码、性能问题,如果要排查不同服务之间的调用问题,那就是另一个维度上的事儿了。就需要 APM 的帮助了。

参考文档:

  1. https://www.jianshu.com/p/9151293c0a1e
  2. https://www.ppkanshu.com/index.php/post/4578.html

猜你喜欢

转载自blog.csdn.net/yangyangrenren/article/details/101147639