JVM -XX:+StringCache 参数?

发布于 2024-07-25 09:05:29 字数 615 浏览 6 评论 0原文

我最近阅读了 JRE 6 中可用的所有 JVM 参数 [Java VM 选项] 看到了这个:

-XX:+StringCache :启用常用分配字符串的缓存。

现在我一直有这样的印象:Java 保留了一个实习(正确的词?)字符串池,当执行字符串与文字的连接之类的操作时,它不是创建新对象,而是从该池中提取它们。 有没有人曾经使用过这个论点,或者可以解释为什么需要它?

编辑:我尝试运行基准测试,看看这个参数是否有任何影响,但无法让 Sun JVM 识别它。 这是:

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)

所以我不确定这个论点是否有效。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

雨落□心尘 2024-08-01 09:05:49

我还没有找到一个 JVM 能够接受这个假设的论点——所以我想没有什么可说的了。

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.

断爱 2024-08-01 09:05:45

从 JDK 8.0 开始,此选项已被删除。 我不清楚什么(如果有的话)可以用作替代品。

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

<前><代码> -XX:+UseStringCache

启用常用分配字符串的缓存。 该选项已从 JDK 8 中删除
没有替代品。

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.
甜味拾荒者 2024-08-01 09:05:43

我也未能找到一个遵循此设置的 JVM; 正如所评论的那样,有关 JVM 参数的文档的质量和实用性很糟糕,但出于某种原因,JVM 供应商似乎看到了竞争差异化的空间 - 尽管公平地说,Oracle/Sun 是迄今为止最差的。

无论如何,如果您发现您的应用程序在某些特定区域重复使用少量字符串值,那么使用实习绝对是明智的 - 通过使用 String.intern() 方法返回实习池值。 请注意,您必须使用返回值,这不是对原始值的副作用。

与所有分析/性能调整一样,这需要通过指标和测试仔细完成。 它可能很重要(对我来说),但如果值池不小,它会降低性能,并且您需要注意字符串值池保存在 Perm Gen 中,因此使用它会影响内存使用、GC ETC。

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.

甲如呢乙后呢 2024-08-01 09:05:42

我也无法使上述工作正常,但最新的 JBB @spec.org 显示了它的用途:-XX:-UseStringCache。 我将不得不重新运行基准测试,看看它是否会产生影响(一个 XML 密集型应用程序)。

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).

岁月静好 2024-08-01 09:05:39

-XX:-UseStringCache 对我有用,奇怪的是。

我的jdk版本应该是1.6.0_22

-XX:-UseStringCache works for me, strangely.

my jdk version should be 1.6.0_22

笑饮青盏花 2024-08-01 09:05:35

我相信,当与 -XX:+AggressiveOpts 一起使用时,它可以在使用相同文本创建 String 时返回相同的 String 对象(尽管当然不是通过new String)。 有一个配置文件阶段,其中建立缓存,并且在某个点之后缓存切换为只读。 它在某些基准测试中获得更高的分数。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文