Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JVM -XX:+StringCache argument?

Tags:

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 allocated strings.

Now I was always under the impression that Java kept a pool of interned (correct word?) Strings and when doing something like String concatenation with literals it was not creating new objects, but pulling them from this pool. Has anyone ever used this argument, or can explain why it would be needed?

EDIT: I attempted to run a benchmark, to see if this argument had any effect and was unable to get the Sun JVM to recognize it. This was with:

java version "1.6.0_11"  
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode,
sharing)

So I'm not sure if this argument works at all.

like image 615
Gandalf Avatar asked Jun 26 '09 16:06

Gandalf


People also ask

How do I change the default JVM argument?

Yes, right click the project. Click Run as then Run Configurations . You can change the parameters passed to the JVM in the Arguments tab in the VM Arguments box. That configuration can then be used as the default when running the project.

How do I pass a VM argument in IntelliJ?

Configure JVM optionsFrom the main menu, select Help | Edit Custom VM Options. If you do not have any project open, on the Welcome screen, click Configure and then Edit Custom VM Options. If you cannot start IntelliJ IDEA, manually copy the default file with JVM options to the IntelliJ IDEA configuration directory.


1 Answers

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.

like image 121
Tom Hawtin - tackline Avatar answered Sep 17 '22 13:09

Tom Hawtin - tackline