????????????Java??string.intern()????????????????????????в??????????????????????????????????????????????д???????????????????
?????????????????????????С??HashMap??????????????1009?? ??Java7u40???????????????60013????Java6???У?????????????????Perm???????Java7????????????????????Heap??????棬?????????????????????????????????Java6??Java7????????汾???μ????????????
???????????
public class StringPoolTest {
public void testStringPoolWithLongString(){
long i=0;
while(true){
String longString = "This is a very long string?? very very long string to test the gc behavior of the string constant pool"+i;
longString.intern();
i++;
}
}
public static void main(String[] args){
StringPoolTest stringPoolTest = new StringPoolTest();
stringPoolTest.testStringPoolWithLongString();
}
}
???????????????????????????????????????????i?????????????????main???????????
????Java 6
??????????e汾Jdk1.6.0_29????ó?????Java VisualVM?????????????Perm?????????GC?????????????????????????????Perm???????Perm????????????JVM??????????????е????????????????

????Java 7
???????棬?????л???Jdk1.7.0_67????ó??????????Perm????????????????????г??????????????

????????Heap????μ???????????????????GC

????????
????????Perm????С?????????????м??MB????????????Java6?1????String.intern()?????????string-intern-in-java-6-7-8????????????????Java6???′??????intern()????????????????????????п??????OOM????????Java7??????????????????????Heap???Heap?????С???????????????????С????????Java7?????String.intern()?????Ч????????String???????????á?