Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to parse JVM bytecode instructions

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

How to parse JVM bytecode instructions, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

In the usual demo, depending on the bytecode order, parsing the program execution flow, the real execution order is the bytecode execution order, and the bytecode order under single thread is consistent with the program writing order. In the multi-threaded environment, the assignment reading order of shared variables can not grasp the timing.

JVM:Java Virtual Machine

Ps: this is the cleanest JVM memory diagram I've ever collected.

The process of MinorGC (copy-> clear-> swap)

1Rich EdenMart SurvivorFrom to SurvivorTo, age + 1

First of all, when the Eden area is full, the first GC will be triggered, and the living objects will be copied to the SurvivorFrom area. When the Eden area starts GC again, it will scan the Eden area and the form area for garbage collection. If the area is still alive after this collection, it will be copied to the To area with the object age + 1.

2: clear Eden area, SurvivorFrom

Then clear the objects in the Eden area and the SurvivorFrom area, who is empty and who is to.

3:SurvivorTo and SurvivorFrom interchange

After the swap, the SurvivorTo becomes the From area of the next GC. When the object reaches the age of 15, eventually, if it survives, it is saved into the old age.

GC algorithm

Label removal algorithm: first mark the recycled object, and then uniformly reclaim it.

Mark compression, after the mark is cleared, compress the discontiguous space

Replication algorithm

Divide the space into two pieces and GC only one of them at a time. When this piece of memory is used up, the surviving objects are copied to another piece.

Reference counting: circular references are not recyclable and are not recommended

GCRoot: reachability Analysis algorithm

Search down from the root set object, and if an object is not linked by any chain, the object is not available.

Which can be used as objects of GC root

Reference objects in the virtual machine stack

Objects referenced by static properties of a class in the method area

Method to go to the object referenced by the constant

Objects referenced in the local method stack

How to determine rubbish?

Space that is no longer used by memory

JVM parameter

JVM system default value Xms Xmx is adjusted to be consistent to avoid frequent GC collection ups and downs

XX type: boolean type, KV setting type, jinfo type

+-indicates whether it is turned on

-XX:+PrintGCDetails

-XX:+UseSerialGC

Heap PSYoungGen total 38400K, used 4366K [0x00000000d5a00000, 0x00000000d8480000, 0x0000000100000000) eden space 33280K, 10% used [0x000000d5a00000) ParOldGen total 87552K, used 16K [0x0000000080e00000, 0x0000000086380000, 0x00000000d5a00000) object space 87552K, 14% used [0x000000d7f80000tem0x000000d803a020moment 0x0000000000d8480000) to space 5120K, 0% used [0x000000d7a800000000000x0000d7a800000000d7f80000) ParOldGen total 87552K, used 16K [0x0000000080e00000, 0x0000000086380000, 0x00000000d5a00000) object space 87552K, used [0x00000000e0000000000e0000000400000000000000000000000000000000000000000000000000d7f80000) str= kkget Metaspace used 335K capacity 56641068K committed

Class space used 355K, capacity 392K, committed 512K, reserved 1048576

-Xms: the initial memory size defaults to 1x64 of physical memory

-Xmx: maximum memory size. Default is 1x4 of physical memory.

-Xss: the size of a single thread, usually 512k-1024k

-Xmn: sets the size of the younger generation

-XX:MetespaceSize: sets the meta-space size, which uses local memory

Garbage collector: parallel serial concurrent marking G1 ZGC

1. Serial garbage collector (Serial) single-threaded environment is designed to be recycled with only one thread

two。 Parallel garbage collector (Parellel) multiple collection threads work in parallel

3. Concurrent garbage collector (CMS) user thread and garbage collection thread colleague execution

4.G1 garbage collector uses a large amount of heap memory, split area collection, java8

How do I view the server default garbage collector?

-XX:+PrintFlagsFinal | |-XX:+PrintCommandLineFlags

Bool UseSerialGC: = true {product}-XX:InitialHeapSize=133236224-XX:MaxHeapSize=2131779584-XX:+PrintCommandLineFlags-XX:+PrintFlagsFinal-XX:+PrintGCDetails-XX:+UseCompressedClassPointers-XX:+UseCompressedOops-XX:-UseLargePagesIndividualAllocation-XX:+UseSerialGC

G1 does not produce memory fragmentation, but can precisely control the pause

Bytecode instruction parsing

Take Price problem as an example

Package com.kk

Import org.junit.Assert;import org.junit.Before;import org.junit.Test;import org.junit.jupiter.api.AfterEach;import org.junit.jupiter.api.BeforeEach

Import java.util.ArrayList

Public class Price {

Public static final Price INSTANCE = new Price (12)

Private static volatile int staticPrice = 5

Public int todayPrice = 20

Public Price (int price) {todayPrice = price-staticPrice

}

Public static void main (String [] args) {System.out.println (Price.INSTANCE.todayPrice);}

@ BeforeEach public void init () {ArrayList list = new ArrayList (); System.out.println ("Set up for" + list.get (1)); for (int I = 0; I < 3; iTunes +) {list.add (Integer.toString (I))

} @ AfterEach public void clean () {System.out.println ("Clean...")

}

@ Test public void replace () {System.out.println ("Runing testReplace ()")

}

}

Load and store instructions

Load and store instructions are used for data transfer back and forth between the local variable table and the Operand stack in the stack frame.

Load a local variable into the Operand stack: iload, iload_, lload, lload_, fload, fload_, dload, dload, aload, aload.

The instruction to extend the local variable table to access the index: wide.

Object creation and access instruction

JVM uses different instructions to deal with the creation of ordinary objects and arrays.

Instructions for creating a normal object: new

Instructions to create an array: newarray, anewarray, multianewarray

Instructions to access class variables (static type) and instance variables (non-static type): getstatic, putstatic, getfield, putfield

Instructions to load an array into the Operand stack: baload, caload, saload, iaload, laload, faload, daload, aaload

Instructions that store the value of an Operand stack in an array element: bastore, castore, sastore, iastore, fastore, dastore, aastore

Instruction to take the length of the array: arraylength

Check instructions for normal object types: instanceof, checkcast

After reading the above, have you mastered how to parse the JVM bytecode instruction? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report