zoukankan      html  css  js  c++  java
  • Java字节码

    package com.my;
    
    public interface IMy01 {
        int say01();
    }
    package com.my;
    
    public interface IMy02 {
        String say02();
    }
    package com.my;
    
    /**
     * Hello world!
     */
    public class App04 implements IMy01, IMy02 {
        private int id;
        private int age;
    
        public void func() {
        }
    
        public void func2() {
        }
    
        @Override
        public int say01() {
            return 0;
        }
    
        @Override
        public String say02() {
            return "say02";
        }
    }

    两个插件

    最终生成的字节码

    CA FE BA BE 00 00 00 34 00 1E 0A 00 04 00 19 08 
    00 15 07 00 1A 07 00 1B 07 00 1C 07 00 1D 01 00 
    02 69 64 01 00 01 49 01 00 03 61 67 65 01 00 06 
    3C 69 6E 69 74 3E 01 00 03 28 29 56 01 00 04 43 
    6F 64 65 01 00 0F 4C 69 6E 65 4E 75 6D 62 65 72 
    54 61 62 6C 65 01 00 12 4C 6F 63 61 6C 56 61 72 
    69 61 62 6C 65 54 61 62 6C 65 01 00 04 74 68 69 
    73 01 00 0E 4C 63 6F 6D 2F 6D 79 2F 41 70 70 30 
    34 3B 01 00 04 66 75 6E 63 01 00 05 66 75 6E 63 
    32 01 00 05 73 61 79 30 31 01 00 03 28 29 49 01 
    00 05 73 61 79 30 32 01 00 14 28 29 4C 6A 61 76 
    61 2F 6C 61 6E 67 2F 53 74 72 69 6E 67 3B 01 00 
    0A 53 6F 75 72 63 65 46 69 6C 65 01 00 0A 41 70 
    70 30 34 2E 6A 61 76 61 0C 00 0A 00 0B 01 00 0C 
    63 6F 6D 2F 6D 79 2F 41 70 70 30 34 01 00 10 6A 
    61 76 61 2F 6C 61 6E 67 2F 4F 62 6A 65 63 74 01 
    00 0C 63 6F 6D 2F 6D 79 2F 49 4D 79 30 31 01 00 
    0C 63 6F 6D 2F 6D 79 2F 49 4D 79 30 32 00 21 00 
    03 00 04 00 02 00 05 00 06 00 02 00 02 00 07 00 
    08 00 00 00 02 00 09 00 08 00 00 00 05 00 01 00 
    0A 00 0B 00 01 00 0C 00 00 00 2F 00 01 00 01 00 
    00 00 05 2A B7 00 01 B1 00 00 00 02 00 0D 00 00 
    00 06 00 01 00 00 00 06 00 0E 00 00 00 0C 00 01 
    00 00 00 05 00 0F 00 10 00 00 00 01 00 11 00 0B 
    00 01 00 0C 00 00 00 2B 00 00 00 01 00 00 00 01 
    B1 00 00 00 02 00 0D 00 00 00 06 00 01 00 00 00 
    0B 00 0E 00 00 00 0C 00 01 00 00 00 01 00 0F 00 
    10 00 00 00 01 00 12 00 0B 00 01 00 0C 00 00 00 
    2B 00 00 00 01 00 00 00 01 B1 00 00 00 02 00 0D 
    00 00 00 06 00 01 00 00 00 0E 00 0E 00 00 00 0C 
    00 01 00 00 00 01 00 0F 00 10 00 00 00 01 00 13 
    00 14 00 01 00 0C 00 00 00 2C 00 01 00 01 00 00 
    00 02 03 AC 00 00 00 02 00 0D 00 00 00 06 00 01 
    00 00 00 12 00 0E 00 00 00 0C 00 01 00 00 00 02 
    00 0F 00 10 00 00 00 01 00 15 00 16 00 01 00 0C 
    00 00 00 2D 00 01 00 01 00 00 00 03 12 02 B0 00 
    00 00 02 00 0D 00 00 00 06 00 01 00 00 00 17 00 
    0E 00 00 00 0C 00 01 00 00 00 03 00 0F 00 10 00 
    00 00 01 00 17 00 00 00 02 00 18

    字节码解读

    字节码存储数据的顺序

    magic 魔术 4u
    minor_version 小版本 2u
    major_version 大版本 2u
    constant_pool_count 常量池数量 2u
    constant_pool 常量池  不确定,通过计算获得
    AccessFlags 2u
    this_Class 2u
    super_calss 2u
    interfaces_count 2u
    interfaces 不确定,通过计算获得
    fields_count 2u
    fields 不确定,通过计算获得
    methods_count 2u
    method_info 不确定,通过计算获得
    attribute_count 2u
    attribute

    字节码常量池的数据类型的结构表

     上面的表中描述了11中数据类型的结构,其实在jdk1.7之后又增加了3种(CONSTANT_MethodHandle_info,CONSTANT_MethodType_info以及CONSTANT_InvokeDynamic_info)。这样算起来一共是14种。

  • 相关阅读:
    性能测试-地铁模型分析
    如何测试网页登录页面
    软件测试修炼之道(转载)
    每当在测试之路迷茫的时候来看看这篇文章
    软件测试博客较好的网址(供参考)
    Spring扩展:替换IOC容器中的Bean组件 -- @Replace注解
    拯救老旧工程,记桥接SpringMVC与Stripes框架
    Netty实现WebSocket,URI参数问题
    高性能内存队列Disruptor--原理分析
    Idea中Smart Tomcat插件启动报NullPointerException问题
  • 原文地址:https://www.cnblogs.com/Tony100/p/13519009.html
Copyright © 2011-2022 走看看