In-depth understanding of the JVM (XIV) – one – object distribution map

example

/ * * *@Description: Explore the citation distribution *@Author: jianweil
 * @date: 2021/8/30 9:17
 */
public class Test {
    // constant - method field
    final static int constantPrice = 1;
    final static String constantName = "Constant 1";

    / / string
    String stringName1 = "String 1";
    String stringName2 = new String("String 2");

    // Static constant pool
    static int staticPrice = 100;
    static Item item1 = new Item("Item 1", staticPrice);

    // Instance variable - heap
    int instancePrice = 200;
    Item item2 = new Item("Item 2", instancePrice);

    public static void main(String[] args) throws InterruptedException {
        Test test1 = new Test();
        int mainA = 300;
        String intern = test1.stringName2.intern();
        Item mainItem = new Item("Main item", mainA); }}class Item {
    / / name
    private String name;
    / / price
    public int number;

    public Item(String name, int number) {
        this.name = name;
        this.number = number; }}Copy the code

Distribution of