RFR: 7885: Graphical rendering of dependency view fails due to heap memory drain [v3]

Marcus Hirt hirt at openjdk.org
Tue Sep 19 10:12:54 UTC 2023


On Thu, 31 Aug 2023 05:14:37 GMT, Virag Purnam <vpurnam at openjdk.org> wrote:

>> When multiple views are enabled in JMC mainly Dependency View and Heatmap View. (Issue was with Flame graph as well but it got fixed as the implementation is now based on swing component)
>> 
>> For the Dependency View and Heatmap View still the implementation is based on javascript and for one particular scenario JMC gives "**java.lang.OutOfMemoryError: Java heap space**". 
>> 
>> **Scenario:**
>> For each selection in a table, views get rendered. For each click on table, 4 threads call method "**toJsonString(IItemCollection items)**" present in "**IItemCollectionJsonSerializer**" class. Within method it appends the items to a StringBuilder and then it writes it to a StringWriter. When we have multiple JFR files open in editor, or we select the table contents very fast, multiple threads call the method at the same time and all try to append and write at the same time. This results in the "**java.lang.OutOfMemoryError: Java heap space**". 
>> 
>> ![image](https://github.com/openjdk/jmc/assets/97600378/ae24614c-c640-4dc0-9c4c-7f70ee2f164f)
>> 
>> ![image](https://github.com/openjdk/jmc/assets/97600378/a41434d7-7bb1-47a0-bb7f-6a8b8e17af30)
>> 
>> 
>> **Possible solution:** Making method  "**toJsonString(IItemCollection items)**" synchronized. I have done the changes and created a PR. 
>> 
>> Could you please review and provide your comments on this? If there are better way to solve this issue, could you please suggest me the same?
>
> Virag Purnam has updated the pull request incrementally with one additional commit since the last revision:
> 
>   7885: Graphical rendering of dependency view fails due to heap memory drain

Marked as reviewed by hirt (Lead).

application/org.openjdk.jmc.flightrecorder.heatmap/src/main/java/org/openjdk/jmc/flightrecorder/heatmap/views/HeatmapView.java line 107:

> 105: 			LOGGER.info("starting to create model");
> 106: 			try {
> 107: 				view.modelState = ModelState.STARTED;

Not really necessary to move into the try block. I'd try to keep the block as small as possible.

application/org.openjdk.jmc.flightrecorder.heatmap/src/main/java/org/openjdk/jmc/flightrecorder/heatmap/views/HeatmapView.java line 108:

> 106: 			try {
> 107: 				view.modelState = ModelState.STARTED;
> 108: 				if (isInvalid) {

This code smells a bit, but since that is already how we do it, it's fine.

-------------

PR Review: https://git.openjdk.org/jmc/pull/511#pullrequestreview-1625011873
PR Review Comment: https://git.openjdk.org/jmc/pull/511#discussion_r1324801732
PR Review Comment: https://git.openjdk.org/jmc/pull/511#discussion_r1324813624


More information about the jmc-dev mailing list