Skip to content
This repository has been archived by the owner on Mar 11, 2023. It is now read-only.

JVM Notes 1

spencercjh edited this page Jan 8, 2020 · 2 revisions

深入理解Java虚拟机 2nd Notes 1

第 2 章 Java内存区域与内存溢出异常

运行时数据区

这图是JDK 8之前的结构

model.png

对比一下:

old.png

new.png

这图是JDK 8之后的结构

model.png

P57 字符串 常量池 和早已不在的永久代

看书还没看明白要写点代码才能彻底搞懂:

还搁这 JDK 6 VS JDK 7呢,我给你看个JDK 13:

image.png

public class Test{
    public static void main(String[] args) {
        final String str1 = new StringBuilder("计算机").append("软件").toString();
        // true
        System.out.println(str1.intern() == str1);

        System.out.println(Tests.class.getName());

        final String str2 = new StringBuilder("com.").append("test.").append("Tests").toString();
        // false
        System.out.println(str2.intern() == str2);
        final String str3 = Tests.class.getName();
        // false
        System.out.println(str2 == str3);
        // true
        System.out.println(str2.intern() == str3);

        System.out.println("end");
    }
}