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

View File

@ -47,6 +47,10 @@ public class JavaVersionUtils {
return JAVA_VERSION < 9.0f;
}
public static boolean isGreaterThanJava7() {
return JAVA_VERSION > 1.7f;
}
public static boolean isGreaterThanJava8() {
return JAVA_VERSION > 1.8f;
}

View File

@ -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中输出
*/

View File

@ -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);
}

View File

@ -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;

View File

@ -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"

View File

@ -10,6 +10,7 @@ options
| batch-re-transform | true | whether to re-transform matched classes in batch|
| json-format | false | whether to output in JSON format|
| disable-sub-class | false | whether to enable matching child classes. The default value is `true`. If exact match is desire, turn off this flag|
| support-default-method | true | whether to enable matching default method in interface. The default value is `true`. Refer to [#1105](https://github.com/alibaba/arthas/issues/1105) |
| debug-for-asm | false | whether to enable ASM debugging log|
| save-result | false | whether to save execution result. All execution results will be saved to `~/logs/arthas-cache/result.log` when it's turned on|
| job-timeout | 1d | default timeout for background jobs. Background job will be terminated once it's timed out (i.e. 1d, 2h, 3m, 25s)| print-parent-fields | true | This option enables print files in parent class, default value true.|

View File

@ -10,6 +10,7 @@ options
| batch-re-transform | true | 是否支持批量对匹配到的类执行retransform操作 |
| json-format | false | 是否支持json化的输出 |
| disable-sub-class | false | 是否禁用子类匹配,默认在匹配目标类的时候会默认匹配到其子类,如果想精确匹配,可以关闭此开关 |
| support-default-method | true | 是否支持匹配到default method默认会查找interface匹配里面的default method。参考 [#1105](https://github.com/alibaba/arthas/issues/1105) |
| debug-for-asm | false | 打印ASM相关的调试信息 |
| save-result | false | 是否打开执行结果存日志功能,打开之后所有命令的运行结果都将保存到`~/logs/arthas-cache/result.log`中 |
| job-timeout | 1d | 异步后台任务的默认超时时间,超过这个时间,任务自动停止;比如设置 1d, 2h, 3m, 25s分别代表天、小时、分、秒 |