muarine opened a new issue, #13676:
URL: https://github.com/apache/skywalking/issues/13676

   ### Search before asking
   
   - [x] I had searched in the 
[issues](https://github.com/apache/skywalking/issues?q=is%3Aissue) and found no 
similar issues.
   
   
   ### Apache SkyWalking Component
   
   Java Agent (apache/skywalking-java)
   
   ### What happened
   
   Environment 
   - SkyWalking Agent: 9.4(你实际版本)
   - JVM: JDK 17
   - Application type: Spring Boot 3.4.2
   - Message middleware: RocketMQ
   - OS: Linux
   
   Problem Description
   Heap dump analysis shows that ~97% of heap memory is retained by
   
   org.apache.skywalking.apm.dependencies.net.bytebuddy.agent.builder.
   SWDescriptionStrategy$SWTypeDescriptionWrapper
   
   via CLASS_LOADER_TYPE_CACHE (ConcurrentHashMap).
   
   The cache holds ~5.8 million TypeDescription entries and is
   strongly referenced without size limit.
   
   
   MAT Dominator Tree shows:
   - CLASS_LOADER_TYPE_CACHE retained heap: ~3.8GB
   - Entry count: ~5.8 million
   - Other components (Spring, RocketMQ, MyBatis) are negligible
   
   
   ### What you expected to happen
   
   Is it expected for CLASS_LOADER_TYPE_CACHE to be unbounded?
   
   Would it be possible to:
   - introduce weak references, or
   - add a size limit / eviction strategy, or
   - provide an agent configuration to disable or limit such caching?
   
   We would like to confirm whether this behavior is by design
   or could be improved to avoid memory risk in dynamic-class-heavy workloads.
   
   ### How to reproduce
   
   1. Prepare a Spring Boot application with SkyWalking Java agent enabled.
   
   2. Use JDK 11+ (JDK 17 recommended).
   
   3. Initialize a large number of MessageConsumers (or similar components)
      using anonymous classes or lambda expressions.
   
      For example, repeatedly create RocketMQ consumers like:
   
      RocketMqBaseConsumer.builder()
          .nameServer(...)
          .topic(...)
          .groupId(...)
          .build()
          .init(new MessageListenerConcurrently() {
              @Override
              public ConsumeConcurrentlyStatus consumeMessage(
                      List<MessageExt> msgs,
                      ConsumeConcurrentlyContext context) {
                  return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
              }
          });
   
      (Each init call creates a new anonymous MessageListener class.)
   
   4. Ensure that:
      - Consumers are initialized dynamically (e.g. on startup or configuration 
reload)
      - A large number of such listeners are created over time (tens of 
thousands or more)
   
   5. Run the application under normal workload for several hours.
   
   6. Observe heap memory usage continuously increasing and not being released.
   
   7. Take a heap dump and analyze with MAT:
      - Dominator Tree shows
        org.apache.skywalking.apm.dependencies.net.bytebuddy.agent.builder
        .SWDescriptionStrategy$SWTypeDescriptionWrapper
        retaining most of the heap.
      - The retention path goes through
        SWDescriptionStrategy.CLASS_LOADER_TYPE_CACHE (ConcurrentHashMap).
      - Entry count grows monotonically with runtime-generated classes.
   
   
   Replacing anonymous classes with a single reusable concrete listener
   class prevents the cache growth, confirming the correlation with
   runtime-generated classes.
   
   
   ### Anything else
   
   _No response_
   
   ### Are you willing to submit a pull request to fix on your own?
   
   - [ ] Yes I am willing to submit a pull request on my own!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: 
[email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to