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

Spring web war 包 classloader -t 命令打印输出不符合预期 #2926

Open
1 task
RaymondLam1 opened this issue Oct 18, 2024 · 2 comments
Open
1 task

Comments

@RaymondLam1
Copy link
Collaborator

  • 我已经在 issues 里搜索,没有重复的issue。

环境信息

arthas 4.0.0

重现问题的步骤

在 tomcat 运行 spring boot war 应用

https://github.com/RaymondLam1/spring-boot-war

期望的结果

正常输出 classloer tree

实际运行的结果

[arthas@39492]$ classloader -t
+-BootstrapClassLoader
+-sun.misc.Launcher$ExtClassLoader@604ed9f0
  +-com.taobao.arthas.agent.ArthasClassloader@43f89e
  | 84
  +-sun.misc.Launcher$AppClassLoader@70dea4e
    +-java.net.URLClassLoader@e9e54c2
                  bappClassLoader
          context: spring-boot-deployment-0.0.1-SNAP


            ------> Parent Classloader:
            .net.URLClassLoader@e9e54c2


[arthas@39492]$ classloader
 name
 BootstrapClassLoader
 org.apache.catalina.loader.ParallelWebappClassLoader
 com.taobao.arthas.agent.ArthasClassloader
 java.net.URLClassLoader
 sun.reflect.DelegatingClassLoader
 sun.misc.Launcher$ExtClassLoader
 sun.misc.Launcher$AppClassLoader

classloader -t 的树型输出可能有问题,缺少了 ParallelWebappClassLoader

@hengyunabc
Copy link
Collaborator

这个应该是 tomcat 的 classloader#toString() 输出有多行,可能被截断了。试下把窗口变大点。

@RaymondLam1
Copy link
Collaborator Author

RaymondLam1 commented Oct 21, 2024

研究发现,Arthas 对 classloader -t 的处理符合预期:

+-BootstrapClassLoader                                                                                                                                                                                                                                                   
+-sun.misc.Launcher$ExtClassLoader@91161c7                                                                                                                                                                                                                               
  +-com.taobao.arthas.agent.ArthasClassloader@67690ffd                                                                                                                                                                                                                   
  +-sun.misc.Launcher$AppClassLoader@18b4aac2                                                                                                                                                                                                                            
    +-java.net.URLClassLoader@53d8d10a                                                                                                                                                                                                                                   
      +-ParallelWebappClassLoader
                                                                                                                                                                                                                                       
          context: spring-boot-deployment-0.0.1-SNAPSHOT
                                                                                                                                                                                                                
          delegate: false
                                                                                                                                                                                                                                               
        ----------> Parent Classloader:
                                                                                                                                                                                                                                 
        java.net.URLClassLoader@53d8d10a
                                                                                                                                                                                                                               

但是在 TermHandler.java 对于 \r的处理是有问题的:

    @Override
    public String apply(String data) {
        term.write(data);
        return data;
    }

ParallelWebappClassLoader 刚好有 \r

    @Override
    public String toString() {

        StringBuilder sb = new StringBuilder(this.getClass().getSimpleName());
        sb.append("\r\n  context: ");
        sb.append(getContextName());
        sb.append("\r\n  delegate: ");
        sb.append(delegate);
        sb.append("\r\n");
        if (this.parent != null) {
            sb.append("----------> Parent Classloader:\r\n");
            sb.append(this.parent.toString());
            sb.append("\r\n");
        }
        if (this.transformers.size() > 0) {
            sb.append("----------> Class file transformers:\r\n");
            for (ClassFileTransformer transformer : this.transformers) {
                sb.append(transformer).append("\r\n");
            }
        }
        return sb.toString();
    }

现在考虑两种解决方式:1. classloader.toString() 的结果去除 \r;2. 研究 term 对 \r 的支持。个人倾向于第一种。

RaymondLam1 pushed a commit to RaymondLam1/arthas that referenced this issue Oct 28, 2024
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