blogss's People
blogss's Issues
类相关指令
接下里的指令设计到jvm的类加载机制,如果你对类加载机制不熟悉,请务必观看我之前的文章
算法
一个类会有 cinit 方法,和init方法,类初始化的时候会执行cinit方法,对象初始化的时候会执行init方法。
public class Monkey {
public static int count = 1024;
int age = 100;
public static void main(String[] args) {
Monkey monkey = new Monkey();
monkey.age = 22;
}
}
编译后的字节码是这样的
``` bash
$ javac Monkey.java
$ javap -v Monkey.class
Classfile /Users/apple/Downloads/x1hnd1rk/TemplateJava/src/Monkey.class
Last modified Jul 6, 2019; size 404 bytes
MD5 checksum 5126d2b933fff12a7a23312c26d22d7e
Compiled from "Monkey.java"
public class Monkey
minor version: 0
major version: 54
flags: (0x0021) ACC_PUBLIC, ACC_SUPER
this_class: #3 // Monkey
super_class: #6 // java/lang/Object
interfaces: 0, fields: 2, methods: 3, attributes: 1
Constant pool:
#1 = Methodref #6.#19 // java/lang/Object."<init>":()V
#2 = Fieldref #3.#20 // Monkey.age:I
#3 = Class #21 // Monkey
#4 = Methodref #3.#19 // Monkey."<init>":()V
#5 = Fieldref #3.#22 // Monkey.count:I
#6 = Class #23 // java/lang/Object
#7 = Utf8 count
#8 = Utf8 I
#9 = Utf8 age
#10 = Utf8 <init>
#11 = Utf8 ()V
#12 = Utf8 Code
#13 = Utf8 LineNumberTable
#14 = Utf8 main
#15 = Utf8 ([Ljava/lang/String;)V
#16 = Utf8 <clinit>
#17 = Utf8 SourceFile
#18 = Utf8 Monkey.java
#19 = NameAndType #10:#11 // "<init>":()V
#20 = NameAndType #9:#8 // age:I
#21 = Utf8 Monkey
#22 = NameAndType #7:#8 // count:I
#23 = Utf8 java/lang/Object
{
public static int count;
descriptor: I
flags: (0x0009) ACC_PUBLIC, ACC_STATIC
int age;
descriptor: I
flags: (0x0000)
public Monkey();
descriptor: ()V
flags: (0x0001) ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: aload_0
5: bipush 100
7: putfield #2 // Field age:I
10: return
LineNumberTable:
line 1: 0
line 4: 4
public static void main(java.lang.String[]);
descriptor: ([Ljava/lang/String;)V
flags: (0x0009) ACC_PUBLIC, ACC_STATIC
Code:
stack=2, locals=2, args_size=1
0: new #3 // class Monkey
3: dup
4: invokespecial #4 // Method "<init>":()V
7: astore_1
8: aload_1
9: bipush 22
11: putfield #2 // Field age:I
14: return
LineNumberTable:
line 7: 0
line 8: 8
line 9: 14
static {};
descriptor: ()V
flags: (0x0008) ACC_STATIC
Code:
stack=1, locals=0, args_size=0
0: sipush 1024
3: putstatic #5 // Field count:I
6: return
LineNumberTable:
line 2: 0
}
SourceFile: "Monkey.java"
通过字节码来理解Java
链表相关的算法
破解jvm软件
指令的执行流程
Class File Format
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.