Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SearchUtils replace '/' to '.' , can not match classes created by lambda method #302

Closed
hengyunabc opened this issue Nov 14, 2018 · 4 comments
Milestone

Comments

@hengyunabc
Copy link
Collaborator

// com.taobao.arthas.core.util.SearchUtils.classNameMatcher(String, boolean)
    public static Matcher<String> classNameMatcher(String classPattern, boolean isRegEx) {
        if (StringUtils.isEmpty(classPattern)) {
            classPattern = isRegEx ? ".*" : "*";
        }
        classPattern = StringUtils.replace(classPattern, "/", ".");
        return isRegEx ? new RegexMatcher(classPattern) : new WildcardMatcher(classPattern);
    }

Before: Test$$Lambda$1/1876631416

After: Test$$Lambda$1.1876631416

@hengyunabc hengyunabc added this to the 3.0.5 milestone Nov 14, 2018
@hengyunabc
Copy link
Collaborator Author

$ sc Test*
Test
Test$$Lambda$1/531885035
Affect(row-cnt:2) cost in 16 ms.
$ sc Test$$Lambda$1/531885035
Affect(row-cnt:0) cost in 4 ms.

@hengyunabc
Copy link
Collaborator Author

据java规范,Test$$Lambda$1/531885035 不是一个合法的 Identifier 。。

https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.8

@hengyunabc hengyunabc changed the title SearchUtils replace '/' to '.' , causes do not match lambda method SearchUtils replace '/' to '.' , can not match classes created by lambda method Nov 15, 2018
@hengyunabc
Copy link
Collaborator Author

  • java.lang.invoke.InnerClassLambdaMetafactory.spinInnerClass() 生成的类的名字是 Test$$Lambda$1
  • 但是 return UNSAFE.defineAnonymousClass(targetClass, classBytes, null); 执行之后,实际jvm里加载的类名字是 Test$$Lambda$1/531885035 。 这个可能是jvm内部处理过的。
Thread [main] (Suspended (breakpoint at line 326 in InnerClassLambdaMetafactory))	
	InnerClassLambdaMetafactory.spinInnerClass() line: 326	
	InnerClassLambdaMetafactory.buildCallSite() line: 194	
	LambdaMetafactory.metafactory(MethodHandles$Lookup, String, MethodType, MethodType, MethodHandle, MethodType) line: 304	
	529116035.invokeStatic_L6_L(Object, Object, Object, Object, Object, Object, Object) line: not available	
	1359044626.reinvoke(Object, Object, Object, Object, Object, Object, Object) line: not available	
	705265961.invoke_MT(Object, Object, Object, Object, Object, Object, Object, Object) line: not available	
	CallSite.makeSite(MethodHandle, String, MethodType, Object, Class<?>) line: 302	
	MethodHandleNatives.linkCallSiteImpl(Class<?>, MethodHandle, String, MethodType, Object, Object[]) line: 307	
	MethodHandleNatives.linkCallSite(Object, Object, Object, Object, Object, Object[]) line: 297	
	Test.main(String[]) line: 9	

可以做一个简单的判断,当字符串里有$$Lambda时,不做 '/' 替换为 '.' 的处理。

@anpbszzz
Copy link

mark

lzc-alioo pushed a commit to lzc-alioo/arthas that referenced this issue May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants