如何解决 Java9 中与分段代码缓存相关的内存问题?

How to resolve segmented code cache related memory issues in Java 9?

Segmented code cache是​​Java9中引入的新特性,将code cache分割成段,在相当程度上提高了性能。但是由于每个代码堆的大小固定,可能会有一些内存浪费,在小代码缓存的情况下,一个代码堆已满而另一个代码堆中仍有 space。

那么克服这些内存问题的可能解决方法是什么?

Segmented Code Cache JEP 的风险和假设 以更简洁的方式陈述了相同的内容:-

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.

引入了以下命令行开关来控制代码堆的大小:

  • -XX:NonProfiledCodeHeapSize:设置包含非剖析方法的代码堆的大小(以字节为单位)。

  • -XX:ProfiledCodeHeapSize:设置包含分析方法的代码堆的大小(以字节为单位)。

  • -XX:NonMethodCodeHeapSize:设置包含非方法代码的代码堆的字节大小。