a Class Salutationís constant pool 分析
来源:互联网 发布:淘宝口碑店铺 编辑:程序博客网 时间:2024/06/05 03:04
首先:1、建立一张像书一样的目录索引表1,2,3........
2、具体的值再根据 Value 去查。
一、jvm找类常量字符串(CONSTANT_String_info):static final 类常量 3个。
1--30 CONSTANT_Utf8_info "Greetings, planet!"
2--31 CONSTANT_Utf8_info "Hello, world!"
3--39 CONSTANT_Utf8_info "Salutations, orb!"
二、jvm找类相关信息(CONSTANT_Class_info ):5个
1、类名 Salutation :4--37 CONSTANT_Utf8_info "Salutation"
2、System.out用到两个类:1>PrintStream 5--44 CONSTANT_Utf8_info "java/io/PrintStream"
2>System 8--47 CONSTANT_Utf8_info "java/lang/System"
3、choice 变量用到的类 java/lang/Math:6--45 CONSTANT_Utf8_info "java/lang/Math"
4、默认的父类 java/lang/Object :7--46 CONSTANT_Utf8_info "java/lang/Object"
1、查找类变量需要的类和方法:CONSTANT_Methodref_info方法连接信息(类,方法),7开始查找相应类,16开始查找相应的方法。
2、存放类成员的名字(choice),类型(int),
1》属于哪个类:CONSTANT_Fieldref_info 3个
2》成员变量out本类没有:是System类里面的 public final static PrintStream out = null;
四、jvm 查找类用的方法:out.print(s),Math.random() 两个。CONSTANT_Methodref_info
1、输出时用的方法
如print(s):类,方法名,参数类型。
2、给类变量赋值用的方法。
五、编译时常量值保存:14 CONSTANT_Double_info 2.99
package Linking.ex5;
public class Salutation {
//** 这些都是类成员
private static final String hello="Hello,world!";
private static final String greeting="Greetings,planet!";
private static final String saulutation="Saulutations,orb!";
private static int choice=(int)(Math.random()*2.99);
public static void main(String[] args) {
// TODO Auto-generated method stub
String s=hello;//建立新的字符串对象。
s.intern();
System.out.print("choice:"+choice);
if (choice==1)
s=greeting;
else if (choice==2)
s=saulutation;
System.out.print(s);
}
}
Table 8-1. Class Salutationís constant pool
Index Type Value
1 CONSTANT_String_info 30
2 CONSTANT_String_info 31
3 CONSTANT_String_info 39
4 CONSTANT_Class_info 37
5 CONSTANT_Class_info 44
6 CONSTANT_Class_info 45
7 CONSTANT_Class_info 46
8 CONSTANT_Class_info 47
9 CONSTANT_Methodref_info 7, 16
10 CONSTANT_Fieldref_info 4, 17
11 CONSTANT_Fieldref_info 8, 18
12 CONSTANT_Methodref_info 5, 19
13 CONSTANT_Methodref_info 6, 20
14 CONSTANT_Double_info 2.99
16 CONSTANT_NameAndType_info 26, 22
17 CONSTANT_NameAndType_info 41, 32
18 CONSTANT_NameAndType_info 49, 34
19 CONSTANT_NameAndType_info 50, 23
20 CONSTANT_NameAndType_info 51, 21
21 CONSTANT_Utf8_info "()D"
22 CONSTANT_Utf8_info "()V"
23 CONSTANT_Utf8_info "(Ljava/lang/String;)V"
24 CONSTANT_Utf8_info "([Ljava/lang/String;)V"
25 CONSTANT_Utf8_info "<clinit"
26 CONSTANT_Utf8_info "<init"
27 CONSTANT_Utf8_info "Code"
28 CONSTANT_Utf8_info "ConstantValue"
29 CONSTANT_Utf8_info "Exceptions"
30 CONSTANT_Utf8_info "Greetings, planet!"
31 CONSTANT_Utf8_info "Hello, world!"
32 CONSTANT_Utf8_info "I"
33 CONSTANT_Utf8_info "LineNumberTable"
34 CONSTANT_Utf8_info "Ljava/io/PrintStream;"
35 CONSTANT_Utf8_info "Ljava/lang/String;"
36 CONSTANT_Utf8_info "LocalVariables"
37 CONSTANT_Utf8_info "Salutation"
38 CONSTANT_Utf8_info "Salutation.java"
39 CONSTANT_Utf8_info "Salutations, orb!"
40 CONSTANT_Utf8_info "SourceFile"
41 CONSTANT_Utf8_info "choice"
42 CONSTANT_Utf8_info "greeting"
43 CONSTANT_Utf8_info "hello"
44 CONSTANT_Utf8_info "java/io/PrintStream"
45 CONSTANT_Utf8_info "java/lang/Math"
46 CONSTANT_Utf8_info "java/lang/Object"
47 CONSTANT_Utf8_info "java/lang/System"
48 CONSTANT_Utf8_info "main"
49 CONSTANT_Utf8_info "out"
50 CONSTANT_Utf8_info "println"
51 CONSTANT_Utf8_info "random"
52 CONSTANT_Utf8_info "salutation"
使用 javap -c -verbose Salutation.class 可以查看常量池
文章来源:Inside the Java Virtual Machine.pdf p353
参考:http://www.cnblogs.com/lrh-xl/p/5334755.html
- a Class Salutationís constant pool 分析
- Constant Pool
- error--------Illegal UTF8 string in constant pool in class file
- method area constant pool
- The String Constant Pool
- a class's lifetime
- java.lang.ClassFormatError: Illegal UTF8 string in constant pool in class file Server/Request
- java String深入constant pool
- Java Card CAP 文件组件分析 05—— Constant Pool Component
- Undefined class constant 'MYSQL_ATTR_INIT_COMMAND'
- Undefined class constant 'MYSQL_ATTR_INIT_COMMAND'
- ClassFormatException: Invalid byte tag in constant pool
- Constant Pool常量池的概念
- Java String with Constant pool, heap&stack
- ClassFormatException Invalid byte tag in constant pool
- Invalid byte tag in constant pool: 15
- Invalid byte tag in constant pool 15
- Could not get a resource from the pool 错误分析
- spring cloud eureka 参数配置
- String s=null和String s=""和String s 的区别
- ios各种生成opencv.framwork
- tomcat+log4j控制台日志乱码问题解决
- Linux下的实时流媒体编程(RTP,RTCP,RTSP)
- a Class Salutationís constant pool 分析
- Qt5 基于TCP传输的发送/接收文件服务器(支持多客户端)
- 安装python pip,再安装request模块,执行python代码
- JAVA之IO类
- sublimeREPL 快捷键配置
- IPv6协议族的其它协议
- Unity3D A* 寻路算法
- Qt多线程编程中的对象线程与函数执行线程
- 勒索病毒防护