简体   繁体   English

lambda表达式的Java堆转储分析

[英]Java heap dump analysis for lambda expressions

My Java application heap dump shows that a specific lambda used in my class has locked up some amount of memory and its not being released during GC. 我的Java应用程序堆转储显示我的类中使用的特定lambda锁定了一些内存,并且在GC期间没有释放它。

Heap shows the specific anonymous lambda class as ParentClass$$Lambda$ID and in current case, the ID is 79(image attached). Heap将特定的匿名lambda类显示为ParentClass $$ Lambda $ ID ,在当前情况下,ID为79(附加图像)。 This ID does not seem to have any relation with the number of lambdas that exist in the class and hence we cannot conclude on which lambda is represented. 这个ID似乎与类中存在的lambda的数量没有任何关系,因此我们不能断定表示哪个lambda。 I'm interested to point at the exact lambda expression as it helps in analyzing, fixing and testing the scenarios related. 我有兴趣指出确切的lambda表达式,因为它有助于分析,修复和测试相关的场景。

Decompiling the class file with DJ did not help as it recreates the lambda expressions to a readable code. 使用DJ反编译类文件没有帮助,因为它将lambda表达式重新创建为可读代码。 Let me know if any ideas on this. 如果有任何想法,请告诉我。

在此输入图像描述

Try defining the system property 尝试定义系统属性

jdk.internal.lambda.dumpProxyClasses=/path/to/dir

when invoking the JVM. 在调用JVM时。 This will cause the runtime to write the dynamically generated lambda classes to disk, where you can inspect them with javap . 这将导致运行时将动态生成的lambda类写入磁盘,您可以使用javap检查它们。 This will enable you to see what fields (captured variables) they hold, and what lambda body method the lambda corresponds to. 这将使您能够查看它们保存的字段(捕获的变量)以及lambda对应的lambda body方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM