JVM -XX:+StringCache argument?

后端 未结 6 1460
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-15 20:19

I was recently reading about all the JVM arguments available in JRE 6 [Java VM Options] and saw this :

-XX:+StringCache : Enables caching of commonly

相关标签:
6条回答
  • 2020-12-15 20:21

    I have not been able to find a single JVM that even accepts this supposed argument - so I guess there's not much else to say.

    0 讨论(0)
  • 2020-12-15 20:39

    I also have not been able to find a JVM which respects this setting; as commented the quality and thus usefulness of the documentation around JVM parameters is terrible, and yet for some reason seems to be an area where JVM vendors see room for competitive differentiation - although to be fair Oracle/Sun is by far the worst.

    Anyhow if you find that your app in some particular area uses a small number of string values repeatedly then it is definitely sensible to use interning - by using the String.intern() method to return an intern-pool value. Note that you have to use the return value, this is not a side-effect on the original value.

    As with all profiling/performance tweaks this needs to be done carefully with metrics and testing. It can be significant (has been for me) but if the pool of values is not small it degrades performance and you need to be aware that the pool of String values is held in the Perm Gen and so using it will affect memory usage, GC etc.

    0 讨论(0)
  • 2020-12-15 20:40

    I too couldn't get the above to work, but the latest JBB @ spec.org shows it's use: -XX:-UseStringCache. I'll have to re-run benchmarks to see if it makes a difference (an XML heavy app).

    0 讨论(0)
  • 2020-12-15 20:41

    -XX:-UseStringCache works for me, strangely.

    my jdk version should be 1.6.0_22

    0 讨论(0)
  • 2020-12-15 20:43

    I believe when used with -XX:+AggressiveOpts it enables the same String objects to be returned when creating the String with the same text (though not through new String, of course). There is a profile phase where a cache is build up, and after a point the cache is switched to read only. It gets higher scores in certain benchmarks.

    0 讨论(0)
  • 2020-12-15 20:46

    As of JDK 8.0, this option has been removed. It is unclear to me what, if anything, can be used as a replacement.

    http://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html

     -XX:+UseStringCache
    
        Enables caching of commonly allocated strings. This option was removed from JDK 8 
        with no replacement.
    
    0 讨论(0)
提交回复
热议问题