support default method. #1105

This commit is contained in:
hengyunabc
2020-04-10 16:59:16 +08:00
parent bec5cf5a6e
commit f409082b22
7 changed files with 22 additions and 3 deletions
@@ -1,5 +1,7 @@
package com.taobao.arthas.core;
import com.taobao.arthas.common.JavaVersionUtils;
/**
* 全局开关
* Created by vlinux on 15/6/4.
@@ -67,6 +69,18 @@ public class GlobalOptions {
)
public static volatile boolean isDisableSubClass = false;
/**
* 是否在interface类里搜索函数
* https://github.com/alibaba/arthas/issues/1105
*/
@Option(
level = 1,
name = "support-default-method",
summary = "Option to control include default method in interface when class matching",
description = "This option disable to include default method in interface when matching class."
)
public static volatile boolean isSupportDefaultMethod = true && JavaVersionUtils.isGreaterThanJava7();
/**
* 是否在asm中输出
*/
@@ -253,9 +253,8 @@ public class Enhancer implements ClassFileTransformer {
* 是否过滤目前暂不支持的类
*/
private static boolean isUnsupportedClass(Class<?> clazz) {
return clazz.isArray()
|| clazz.isInterface()
|| (clazz.isInterface() && !GlobalOptions.isSupportDefaultMethod)
|| clazz.isEnum()
|| clazz.equals(Class.class) || clazz.equals(Integer.class) || clazz.equals(Method.class);
}
@@ -15,7 +15,6 @@ import org.objectweb.asm.ClassReader;
import com.alibaba.arthas.deps.org.slf4j.Logger;
import com.alibaba.arthas.deps.org.slf4j.LoggerFactory;
import com.taobao.arthas.core.command.Constants;
import com.taobao.arthas.core.command.logger.LoggerCommand;
import com.taobao.arthas.core.shell.cli.Completion;
import com.taobao.arthas.core.shell.cli.CompletionUtils;
import com.taobao.arthas.core.shell.command.AnnotatedCommand;
@@ -115,6 +115,7 @@ public abstract class EnhancerCommand extends AnnotatedCommand {
if (effect.cCnt() == 0 || effect.mCnt() == 0) {
// no class effected
// might be method code too large
process.write("Matched class-cnt: " + effect.cCnt() + ", method-cnt: " + effect.mCnt() + "\n");
process.write("No class or method is affected, try:\n"
+ "1. sm CLASS_NAME METHOD_NAME to make sure the method you are tracing actually exists (it might be in your parent class).\n"
+ "2. reset CLASS_NAME and try again, your method body might be too large.\n"