This is GC diagram from visualvm for a simple application that listens for some incoming stream of data trough websocket... At start it creates a lot of garbage, but as you can see it gets better over time... Is this JIT figuring out somehow how to avoid creating objects?
-
It's a curve. What does the application do? And, what does the request pattern look like? – Elliott Frisch Jan 01 '16 at 20:36
-
it opens a websocket client, subscribes for a channel, and starts getting messages, 90% of them are heartbeat (so they are identical)... – vach Jan 01 '16 at 20:40
-
2JIT does not optimize the heap memory. The GC however has some dynamic options, so more likely the GC is responding to the number of dirty objects and cleaning them a bit more efficient after a while. – Norbert Jan 01 '16 at 20:42
-
Somewhat related -- JIT does do escape analysis as [demonstrated by](https://plus.google.com/u/0/+AttilaMihalyBalazs/posts/MKkeNrK3vCB?cfem=1) the awesome JITWatch. – Kedar Mhaswade Oct 21 '16 at 16:25
1 Answers
There are some very specific cases, where the JIT can remove allocations and therefore reduce the pressure on the GC. Mainly with escape analysis. Basically if the object lives only withing one method and never leaves it, it can be allocated on the stack instead of the heap, reducing work of the garbage collector.
If you want to know for sure: You can disable escape analysis: Use the command line argument -XX:-DoEscapeAnalysis
and see if the graph changes.
However there many other self tuning mechanisms present. Like the runtime system notices that you don't need as much memory, and therefore start to reduce the heap size. Your graph would match that. As most of the memory can always be freed, the memory system reduces the heap size: With more frequent but smaller GC's.

- 12,978
- 7
- 43
- 70
-
Yup. In this case, heap down-sizing is the more likely explanation, IMO. – Stephen C Jan 02 '16 at 06:53
-
I knew about stack confinement however JIT is most active in the beginning of the application after application is warmed up, JIT activity goes nearly to 0... what surprized me is that this optimization were going on for quite some time... like an hour and it got better and better... hence i tought there might be some other magic i dont know about... – vach Jan 02 '16 at 12:37