Write Java, but do not understand the java series of loading and storage

shysh 2021-01-24 12:52:44
write java understand java series


quite a lot Java Engineer's grammar is very , But really let him say Java How it works , I'm sure he'll be confused !!!

1.jpeg

I hope students at this stage can read it carefully Class Document series The article , It covers Class The vast majority of the document , When you read and understand , I believe you are no longer confused .

I don't know if I still remember Code attribute , If you don't remember, I suggest you review it ,Code Attribute stores the bytecode instructions we're going to talk about today .

Let's talk about bytecode instructions today ( Load and store instructions ). The bytecode instruction is JVM What you need to do at run time , Bytecode instructions are roughly divided into the following types :

  • Load and store instructions
  • Operation instruction
  • Type conversion instructions
  • Object creation and access instructions
  • Operand stack management instructions
  • Control transfer instructions
  • Method calls and return instructions
  • Exception handling instructions
  • Synchronization instructions

For most bytecode instructions , They all contain the data types corresponding to their operations ,i Corresponding Integer type ,l representative Long type ,f representative Float type ,d representative Double type ,a representative Reference type ,b representative byte type ,s representative short type ,c representative char type .

Load and store instructions

The load and store instructions are used to transfer data in the local variable table and the operands stack of the stack frame .

Local variables are loaded into the stack of operands

iload,iload_<n>,lload, lload_<n>, fload, fload_<n>, dload, dload_<n>, aload, aload_<n>

<n> It's just a mnemonic , such as iload_1 It means to put the local variables into the table slot The index for 1 Of int Type elements are pushed into the top of the stack of operands ,iload_1 Exactly equivalent to iload(1).

WX20210120-220932@2x.png

The stack of operands is loaded into the local variables table

istore,istore_<n>、lstore, lstore_<n>, fstore, fstore_<n>, dstore, dstore_<n>, astore, astore_<n>.

istore_1 The function is to save the top element of the stack of operands to the local variable table index as 1 Location .

Push constants into the stack of operands

bipush,sipush,ldc,ldc_w,ldc2_w,aconst_null,iconst_m1,iconst_<n>,lconst_<l>,fconst_<f>,dconst_<d>.

So let's talk about that ldc、ldc_w、ldc2_w, Let's take a look first Java8 The virtual machine specification defines it , Here's the picture :

WX20210120-224650@2x.png

The meaning of the figure is to push certain types of constants in the constant pool to the top of the stack of operands , These types include int,float,String, Class,java.lang.invoke.MethodType, java.lang.invoke.MethodHandle.

ldc Equate to ldc_w, ldc2_w Equate to ldc Of a particular type long and double.

public class ClassTest {
public void test() {
Class<Long> c = Long.class;
String s = "test";
int r = Integer.MAX_VALUE;
float f = Float.MAX_VALUE;
long l = Long.MAX_VALUE;
double d = Double.MAX_VALUE;
}
}

WX20210124-111646@2x.png

Pay attention to the part in the red box ,ldc #2, The second term in the constant pool is Class type , Description that conforms to the virtual machine specification ; Looking at ldc #3, The third term in the constant pool is String type , Description that conforms to the virtual machine specification ;ldc2_w #8、ldc2_w #11, In the second part of the constant pool 8 And the 11 The items are Long and Double type , Conform to the virtual machine specification .

WX20210124-112210@2x.png

JVM It supports trestle instruction sets , In the course of our code running , We need to load and store instructions to complete the transfer of variables between the local variable table and the stack of operands .

The load and store instructions in this issue cover this , See you next time !!!

I am a shysh95, I hope I can work with you on the road of focusing on technology , Do something different from most people , A little further from mediocrity , Scan code concerns WeChat official account , More wonderful articles !!!

qrcode_for_gh_1706f00849c9_344.jpg

版权声明
本文为[shysh]所创,转载请带上原文链接,感谢
https://javamana.com/2021/01/20210124125207272b.html

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云