3

Segmented code cache is a new feature introduced in Java 9 that divides the code cache into segments, this improves performance to a considerable extent. But there can be some memory wastage due to fixed size per code heap, in case of small code cache, one code heap is full and there is still space in another code heap.

So what are possible workarounds to overcome these memory issues?

Mohit Tyagi
  • 2,788
  • 4
  • 17
  • 29
  • 5
    ...You've been told that this feature incurs a tradeoff. Either you accept some memory cost in exchange for performance, or you don't. What more do you want? If it could be done without any cost, it would be on for everyone anyway. – Louis Wasserman Sep 29 '17 at 18:19
  • @LouisWasserman what about dynamic resizing of code cache? – Mohit Tyagi Sep 29 '17 at 18:26
  • If you have a specific workaround, post some code using it and ask a specific question about it. – tgdavies Sep 22 '21 at 01:13

1 Answers1

3

The Risks and Assumptions of the Segmented Code Cache JEP states the same in a cleaner way:-

Having a fixed size per code heap leads to a potential waste of memory in case one code heap is full and there is still space in another code heap. Especially for very small code cache sizes, it may happen that the compilers are shut off even if there is still space available. To solve this problem an option will be added to turn off the segmentation for small code-cache sizes.

The following command-line switches are introduced to control the sizes of the code heaps:

  • -XX:NonProfiledCodeHeapSize: Sets the size in bytes of the code heap containing non-profiled methods.

  • -XX:ProfiledCodeHeapSize: Sets the size in bytes of the code heap containing profiled methods.

  • -XX:NonMethodCodeHeapSize: Sets the size in bytes of the code heap containing non-method code.

Naman
  • 27,789
  • 26
  • 218
  • 353
  • 1
    they changed the last one to `NonNMethodCodeHeapSize`. Also a little follow up [here](https://stackoverflow.com/questions/69262935/minor-question-about-segmented-code-cache-http-openjdk-java-net-jeps-197) – Eugene Sep 21 '21 at 03:11