当前位置:网站首页>What are the symbolic and direct references of the JVM
What are the symbolic and direct references of the JVM
2022-06-26 10:12:00 【ZZ learn java well】
Analysis 1 :
A symbolic reference is a class ( Not just classes, of course , It also includes other parts of the class , Such as method , Field etc. ), Other classes are introduced , But JVM I don't know where the other classes introduced are , So we use the unique symbol instead of , Wait until the classloader resolves , Just find the address of the reference class by referring to the symbol , This address is a direct reference .
Analysis 2 :
1. Symbol reference (Symbolic References):
A symbolic reference describes the referenced target with a set of symbols , A symbol can be any form of literal quantity , As long as it can be used to locate the target without ambiguity . for example , stay Class In the document it uses CONSTANT_Class_info、CONSTANT_Fieldref_info、CONSTANT_Methodref_info Constant of the same type appears . Symbol references are independent of the memory layout of the virtual machine , Referenced targets are not necessarily loaded into memory . stay Java in , One java Class will compile into a class file . At compile time ,java Class does not know the actual address of the referenced class , So we can only use symbolic references instead of . such as org.simple.People Class references org.simple.Language class , At compile time People Class does not know Language Class's actual memory address , So only symbols can be used org.simple.Language( Suppose it's this , Of course, in practice, it is similar to CONSTANT_Class_info Is represented by a constant of ) To express Language Class address . The memory layout of various virtual machine implementations may be different , But the symbolic references they can accept are consistent , Because the literal form of symbolic reference is clearly defined in Java Virtual machine specification Class In file format .
2. Direct reference :
A direct quote can be
(1) Pointer directly to the target ( such as , Point to “ type ”【Class object 】、 Class variables 、 A direct reference to a class method may be a pointer to a method area )
(2) Relative offset ( such as , Point to instance variable 、 Direct references to instance methods are offsets )
(3) A handle that can be indirectly located to the target
Direct references are related to the layout of the virtual machine , The direct references translated from the same symbolic reference on different virtual machine instances will not be the same . If there is a direct quote , The target of the reference must have been loaded into memory .
Analysis three :
Symbolic references are used immediately **( In the form of string symbols )** To denote a reference , In fact, the quoted class 、 Methods or variables have not yet been loaded into memory . A direct reference is a pointer with a specific reference address , The referenced class 、 Methods or variables have been loaded into memory . Take variables for example :
Symbol references need to be converted to direct references to be valid , It also shows that direct reference is more efficient than symbol reference . Then why do we use symbolic references ? This is because before the class loads ,javac Will compile the source code into .class file , This is the time javac I don't know the class referenced in the compiled class 、 Methods or variables where their reference address is , So we can only use symbolic references to express , Of course , The symbolic reference is to follow java Virtual machine specification . There is also a situation where symbols are used to refer to , For example, the example of symbolic reference of variables mentioned above , For clarity of logic and readability of code .
javac Compiling a A Class time , If A Class applied B class , that javac Go to the classpath to find B class , If you find it , Just put A Class to A.class file , At this time A.class There's one in the file B Symbol reference of class ( String form ), You can write two for yourself A Classes and B class ,A Class reference B class , compile A After the class , Use JDK Built in decompiler , Decompile the code to see
We all know , Class loading process is divided into loading —> verification —> Get ready —> analysis —> Initialize this 5 Stages , The conversion of symbolic references to direct references occurs during the parsing phase , The parsing phase may occur before initialization , Or after initialization .
边栏推荐
- Detailed explanation of the network security competition questions (2) of the 2021 national vocational college skills competition (secondary vocational group)
- Various errors encountered by tensorflow
- install ompl. sh
- 118. 杨辉三角
- 全渠道、多场景、跨平台,App如何借助数据分析渠道流量
- Teach you to use shell script to check whether the server program is running
- 【无标题】
- Dialog centered
- c语言语法基础之——函数 小程序 求阶乘
- Today's headline adaptation scheme code
猜你喜欢

首批12家企业入驻!广州首个集中展销老字号产品专柜开张

瑞萨电子面向物联网应用推出完整的智能传感器解决方案

#云原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service

Solution to network request crash in retrofit2.8.1

Redis novice introduction

方法区里面有什么——class文件、class文件常量池、运行时常量池

thymeleaf中抽取公共片段

Configuration internationale

Day 3 array, pre post, character space, keyword and address pointer

Go learning notes (83) - code specification and common development skills
随机推荐
Extracting public fragments from thymeleaf
字符串常量池、class常量池和运行时常量池
A concise tutorial for getting started with go generics
国际化配置
定制拦截器
SSM项目小例子,SSM整合图文详细教程
thymeleaf中抽取公共片段
The basis of C language grammar -- pointer (multidimensional array, function, summary) learning
A list of common methods for customizing paint and canvas of view
install ompl. sh
Redis notes (13) - scan and keys search for specific prefix key fields (command format, usage examples, locating large keys)
WGCLOUD的web ssh服务端口是多少
2. 合并两个有序数组
Standard implementation of streaming layout: a guide to flexboxlayout
Crawler related articles collection: pyppeter, burpsuite
The basis of C language grammar -- function nesting, Fibonacci sum of recursive applet and factorial
【LeetCode】59. Spiral matrix II
mysql学习总结
Custom interceptor
创建对象的时候堆内存的分配