Java基础-字节码

本文详细介绍了Java字节码的各个方面,包括字节码的Big-Endian字节序、字节码文件的结构,如魔数、版本号、常量池等。还探讨了字段表、方法表及其访问标识,并解析了字节码命令和字节码文件的实际例子,旨在帮助读者深入理解JVM的工作原理。
摘要由CSDN通过智能技术生成
概述
  • 字节码采用Big-Endian,是Spark、PowerPC等处理器的默认字节序;x86则是用Little-Endian

jvm-001.jpg

  • 字节码文件采用一种类似于C语言结构体的伪结构来存储数据,只有两种数据类型:无符号数和表
    • 无符号数
      • 基本数据类型,以u1,u2,u4,u8分别代表1,2,4,8字节的无符号数
      • 可用来描述数字、索引引用、数量值或者按UTF-8编码构成字符串值
      • 由多个无符号数或者其他表作为数据项构成的复合数据类型
      • 习惯性地以“_info”结尾
      • 整个Class文件本质上也就是一张表
文件结构

ClassFile {
    u4             magic; # 0xCAFEBABE
    u2             minor_version;
    u2             major_version;
    u2             constant_pool_count;
    cp_info        contant_pool[constant_pool_count – 1]; # 之所以-1,是因为#0被做他用了
    u2             access_flags;
    u2             this_class;
    u2             super_class;
    u2             interfaces_count;
    u2             interfaces[interfaces_count];
    u2             fields_count;
    field_info     fields[fields_count];
    u2             methods_count;
    method_info    methods[methods_count];
    u2             attributes_count;
    attribute_info attributes[attributes_count];
}
magic, minor_version, major_version
    specifies information about the version of the class,  and the version of the JDK this class was compiled for
constant_pool
    similar to a symbol table although it contains more data this is described in more detail below
access_flags
    provides the list of modifiers for this class
this_class
    index into the constant_pool providing the fully qualified name of this class i.e. org/jamesdbloom/foo/Bar
sup
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Eddy咸鱼

感谢大佬加鸡蛋~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值