日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

使用Javap分析Java代码里的static final的工作原理

發布時間:2023/12/19 java 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用Javap分析Java代码里的static final的工作原理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Created by Jerry Wang, last modified on Oct 05, 2016

I have written the following test code:

I would like to test the difference with “static int” and “static final int”.
Use javap to decompile .class file:

The result is listed below:

According to JVM instruction list explanation in wiki: https://en.wikipedia.org/wiki/Java_bytecode_instruction_listings
sipush 545: push int value 545 to stack
putstatic #16: put the stack value 545 to static class field number3

aload_0: load a reference onto the stack from local variable 0
invokespecial: invoke instance method on object objectref and puts the result on the stack (might be void); the method is identified by method reference index in constant pool
ldc: push a constant #index from a constant pool (String, int or float) onto the stack
Here we can know the fact that the value of result 512 * 623 has already been calculated during compilation and stored in constant pool index #29.
istore_1: store int value into variable 1
getstatic: get a static field value of a class, where the field is identified by field reference in the constant pool index
imul: multiply two integers
new: create new object of type identified by class reference in constant pool index
dup: duplicate the value on top of the stack

You might wonder how we can know each # represents. In order to get the table you can use javap -v instead:


We can also know that the "Value: " + product1 + " , " + product2 is coverted automatically by JVM to create a new StringBuilder instance and call append method to achieve string concatenation.

要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":

總結

以上是生活随笔為你收集整理的使用Javap分析Java代码里的static final的工作原理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。