字符串池存在于年轻一代和老一代? [英] String Pool exists in both young and old generation?

查看:207
本文介绍了字符串池存在于年轻一代和老一代?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Java 7开始,实际上字符串不再存储在permgen区域。相反,它们存储在正常的堆空间中,这意味着它们必须经历一半的GC和完整的GC。现在,在半个GC之后,那些生存下来的实习生必须从年轻一代转移到老一代。

From Java 7 interned Strings are no longer stored in permgen area. Rather they are stored in normal heap space which means they must undergo half GC and full GC. Now after half GC those interned String that survive must be transfered from young to old generation.


  • 这是否意味着年轻一代和老一代都有此字符串投票?

接下来让我们说实习生中的一个字符串。我们定义了一个具有相同内容的字符串文字,然后在这种情况下,它必须指向池中相同的字符串内容。

Next lets say a string in interned. They I define an string literal with same content then in that case it has to point to same string innstance in the pool.


  • 因此JVM必须在年轻和年老的
    中搜索String并返回对approriate字符串实例的引用。我的
    是否正确?

推荐答案

你混淆了逻辑布局实习生表在内存中的物理安排。实习表只是一个链接冲突的哈希表,逻辑上(虽然不是物理上)类似于HashMap。当一个字符串实际运行时,JVM会对其进行哈希处理,然后查找相应的存储桶并返回它找到的字符串或将新字符串添加到存储桶中。

You're confusing the logical layout of the intern table with its physical arrangement in memory. The intern table is just a hash table with chaining on collisions, logically (though not physically) similar to a HashMap. When interning a string, the JVM hashes it, then looks in the appropriate bucket and either returns the string it finds or adds the new string to the bucket.

这是正交的垃圾收集者对几代人的管理。事实上,一些收藏家有两代以上,并且 G1 (发音为垃圾优先)收集器可以为新旧对象使用多个区域。查找字符串时,JVM只是执行哈希表查找并遵循一些引用/指针,而不是像你建议的那样在每个代/区域中单独搜索。

This is orthogonal to the garbage collector's management of generations. Indeed, some collectors have more than two generations, and the G1 (pronounced "garbage first") collector can use multiple regions for new or old objects. When looking up a string, the JVM simply does a hash table lookup and follows some references/pointers, not a separate search in each generation/region as you suggest.

这篇关于字符串池存在于年轻一代和老一代?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆