transmittable-thread-local
transmittable-thread-local copied to clipboard
fix:add synchronized to weakHashMap,avoid endless loop while updating…
在更新ExtensionTransformlets时使用到了WeakHashMap,在并发时,WeakHashMap在扩容的时候有一定概率形成环形链表,导致死循环,CPU飙升。
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
dingmingcheng seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.
在更新ExtensionTransformlets时使用到了WeakHashMap, 在并发时,WeakHashMap在扩容的时候有一定概率形成环形链表,导致死循环,CPU飙升。
@dingmingcheng 你有实际出现/复现『在并发时,WeakHashMap死循环CPU飙升』风险的情况吗?
类加载过程(即java.lang.instrument.ClassFileTransformer#transform调用) 应该是 『等效单线程』不并发的。
上面这点需要通过JVM官方文档来确认的。
可以帮忙一起确认吗? ♥️ @dingmingcheng
如果 类加载过程 是 『等效单线程』的,则不需要 上面的Collections.synchronizedMap的处理逻辑。
# 也规避了实现逻辑可以不必要的复杂性。
@oldratlee 有出现过。但只有当时dump下来的线程栈信息,有两个线程都卡在了下面的代码。Java版本是1.8.0_192。
"http-nio-127.0.0.1-8300-exec-97" #195 daemon prio=5 os_prio=0 tid=0x00007f03513a6000 nid=0x4e6 runnable [0x00007f02eab59000]
java.lang.Thread.State: RUNNABLE
at java.util.WeakHashMap.getEntry(WeakHashMap.java:431)
at java.util.WeakHashMap.containsKey(WeakHashMap.java:417)
at com.alibaba.ttl.threadpool.agent.TtlExtensionTransformletManager.collectExtensionTransformlet(TtlExtensionTransformletManager.java:67)
at com.alibaba.ttl.threadpool.agent.TtlTransformer.transform(TtlTransformer.java:68)
at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
at sun.misc.Unsafe.defineClass(Native Method)
at sun.reflect.ClassDefiner.defineClass(ClassDefiner.java:63)
at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:399)
at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:394)
at java.security.AccessController.doPrivileged(Native Method)
at sun.reflect.MethodAccessorGenerator.generate(MethodAccessorGenerator.java:393)
at sun.reflect.MethodAccessorGenerator.generateMethod(MethodAccessorGenerator.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:53)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:689)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:755)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178)
@dingmingcheng 收到,感谢提供的信息 ♥️
这个PR我先理解&Review一下,然后合并
fixed by 0ec1ea1b187e4531866f466e0d99cfede3650dee