1 简介
Class文件是一组以字节为基础单位的二进制流。
JVM的数据入口就是我们平时代码编译后的Class文件,那么要搞懂JVM的原理之前,就要了解Class文件里边都是什么,才能更好的理解JVM原理。
内容比较多,希望看到的小伙伴也能自己动手,边看边解析一个自己的Class文件,光看不操作其实等于白看,因为过两天你就忘了。
2 准备工作
一个Class文件 、NotePad++文本文件查看
Class文件,用文本工具打开,是一堆乱码,因为它本身是二进制流的。
用NotePad++的插件有个HEX插件,就是以16进制的方式显示。
javap -verbose .class 反编译看看Class文件信息
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 kuku@DESKTOP-KQS9B3J MINGW64 ~/Desktop 2 $ javap -verbose BscDictService.class 3 Classfile /C:/Users/kuku/Desktop/BscDictService.class 4 Last modified 2022-6-9; size 1727 bytes 5 MD5 checksum 87ad0a7a75e3755bdbb266ee5e77a998 6 Compiled from "BscDictService.java" 7 public interface com.goldjet.appservice.customs.application.bsc.BscDictService extends com.bitsun.core.framwork.application.IApplicationService 8 minor version: 0 9 major version: 52 10 flags: ACC_PUBLIC, ACC_INTERFACE, ACC_ABSTRACT 11 Constant pool: 12 #1 = Class #31 // com/goldjet/appservice/customs/application/bsc/BscDictService 13 #2 = Class #32 // java/lang/Object 14 #3 = Class #33 // com/bitsun/core/framwork/application/IApplicationService 15 #4 = Utf8 save 16 #5 = Utf8 (Lcom/goldjet/appservice/customs/dto/req/bcs/BscDictReqDto;)Lcom/goldjet/appservice/customs/dto/res/bcs/BscDictResDto; 17 #6 = Utf8 MethodParameters 18 #7 = Utf8 reqDto 19 #8 = Utf8 deleteByIds 20 #9 = Utf8 (Ljava/lang/String;)Ljava/lang/Void; 21 #10 = Utf8 ids 22 #11 = Utf8 doPager 23 #12 = Utf8 (Ljava/util/Map;)Lcom/bitsun/core/common/persistence/Pager; 24 #13 = Utf8 params 25 #14 = Utf8 Signature 26 #15 = Utf8 (Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;)Lcom/bitsun/core/common/persistence/Pager<Lcom/goldjet/appservice/customs/dto/res/bcs/BscDictResDto;>; 27 #16 = Utf8 selectOne 28 #17 = Utf8 (Ljava/lang/Long;)Lcom/goldjet/appservice/customs/dto/res/bcs/BscDictResDto; 29 #18 = Utf8 id 30 #19 = Utf8 (Ljava/util/Map;)Lcom/goldjet/appservice/customs/dto/res/bcs/BscDictResDto; 31 #20 = Utf8 (Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;)Lcom/goldjet/appservice/customs/dto/res/bcs/BscDictResDto; 32 #21 = Utf8 updateProps 33 #22 = Utf8 (Ljava/lang/Long;Ljava/util/Map;)Lcom/goldjet/appservice/customs/dto/res/bcs/BscDictResDto; 34 #23 = Utf8 (Ljava/lang/Long;Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;)Lcom/goldjet/appservice/customs/dto/res/bcs/BscDictResDto; 35 #24 = Utf8 (Ljava/lang/Long;Lcom/goldjet/appservice/customs/dto/req/bcs/BscDictReqDto;)Lcom/goldjet/appservice/customs/dto/res/bcs/BscDictResDto; 36 #25 = Utf8 selectDictItemByDictCode 37 #26 = Utf8 (Ljava/lang/String;)Ljava/util/List; 38 #27 = Utf8 dictCode 39 #28 = Utf8 (Ljava/lang/String;)Ljava/util/List<Lcom/goldjet/appservice/customs/dto/res/bcs/BscDictItemResDto;>; 40 #29 = Utf8 SourceFile 41 #30 = Utf8 BscDictService.java 42 #31 = Utf8 com/goldjet/appservice/customs/application/bsc/BscDictService 43 #32 = Utf8 java/lang/Object 44 #33 = Utf8 com/bitsun/core/framwork/application/IApplicationService 45 { 46 public abstract com.goldjet.appservice.customs.dto.res.bcs.BscDictResDto save(com.goldjet.appservice.customs.dto.req.bcs.BscDictReqDto); 47 descriptor: (Lcom/goldjet/appservice/customs/dto/req/bcs/BscDictReqDto;)Lcom/goldjet/appservice/customs/dto/res/bcs/BscDictResDto; 48 flags: ACC_PUBLIC, ACC_ABSTRACT 49 MethodParameters: 50 Name Flags 51 reqDto 52 53 public abstract java.lang.Void deleteByIds(java.lang.String); 54 descriptor: (Ljava/lang/String;)Ljava/lang/Void; 55 flags: ACC_PUBLIC, ACC_ABSTRACT 56 MethodParameters: 57 Name Flags 58 ids 59 60 public abstract com.bitsun.core.common.persistence.Pager<com.goldjet.appservice.customs.dto.res.bcs.BscDictResDto> doPager(java.util.Map<java.lang.String, java.lang.Object>); 61 descriptor: (Ljava/util/Map;)Lcom/bitsun/core/common/persistence/Pager; 62 flags: ACC_PUBLIC, ACC_ABSTRACT 63 MethodParameters: 64 Name Flags 65 params 66 Signature: #15 // (Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;)Lcom/bitsun/core/common/persistence/Pager<Lcom/goldjet/appservice/customs/dto/res/bcs/BscDictResDto;>; 67 68 public abstract com.goldjet.appservice.customs.dto.res.bcs.BscDictResDto selectOne(java.lang.Long); 69 descriptor: (Ljava/lang/Long;)Lcom/goldjet/appservice/customs/dto/res/bcs/BscDictResDto; 70 flags: ACC_PUBLIC, ACC_ABSTRACT 71 MethodParameters: 72 Name Flags 73 id 74 75 public abstract com.goldjet.appservice.customs.dto.res.bcs.BscDictResDto selectOne(java.util.Map<java.lang.String, java.lang.Object>); 76 descriptor: (Ljava/util/Map;)Lcom/goldjet/appservice/customs/dto/res/bcs/BscDictResDto; 77 flags: ACC_PUBLIC, ACC_ABSTRACT 78 MethodParameters: 79 Name Flags 80 params 81 Signature: #20 // (Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;)Lcom/goldjet/appservice/customs/dto/res/bcs/BscDictResDto; 82 83 public abstract com.goldjet.appservice.customs.dto.res.bcs.BscDictResDto updateProps(java.lang.Long, java.util.Map<java.lang.String, java.lang.Object>); 84 descriptor: (Ljava/lang/Long;Ljava/util/Map;)Lcom/goldjet/appservice/customs/dto/res/bcs/BscDictResDto; 85 flags: ACC_PUBLIC, ACC_ABSTRACT 86 MethodParameters: 87 Name Flags 88 id 89 params 90 Signature: #23 // (Ljava/lang/Long;Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;)Lcom/goldjet/appservice/customs/dto/res/bcs/BscDictResDto; 91 92 public abstract com.goldjet.appservice.customs.dto.res.bcs.BscDictResDto updateProps(java.lang.Long, com.goldjet.appservice.customs.dto.req.bcs.BscDictReqDto); 93 descriptor: (Ljava/lang/Long;Lcom/goldjet/appservice/customs/dto/req/bcs/BscDictReqDto;)Lcom/goldjet/appservice/customs/dto/res/bcs/BscDictResDto; 94 flags: ACC_PUBLIC, ACC_ABSTRACT 95 MethodParameters: 96 Name Flags 97 id 98 reqDto 99 100 public abstract java.util.List<com.goldjet.appservice.customs.dto.res.bcs.BscDictItemResDto> selectDictItemByDictCode(java.lang.String); 101 descriptor: (Ljava/lang/String;)Ljava/util/List; 102 flags: ACC_PUBLIC, ACC_ABSTRACT 103 MethodParameters: 104 Name Flags 105 dictCode 106 Signature: #28 // (Ljava/lang/String;)Ljava/util/List<Lcom/goldjet/appservice/customs/dto/res/bcs/BscDictItemResDto;>; 107 } 108 SourceFile: "BscDictService.java"View Code
3 文件结构
Class文件是一组以8位字节为基础单位的二进制流,内容是以《Java虚拟机规范》规定的一种固定的格式存储数据。存储数据用到了两个数据类型:“无符号数”和“表”。
无符号数:无符号数是基本数据类型,以u1、u2、u4、u8来分别代表1个字节、2个字节、4个字节和8个字节的无符号数,无符号数可以用来描述数字、索引引用、数量表或者按照UTF-8编码构成字符串值。
表:由多个无符号数或者其他表作为数据项构成的复合数据类型,以“_info”结尾,用户描述有层次关系的复合结构的数据。
下图是《Java虚拟机规范》规定的Class文件的固定格式,所有Class文件均按照一下格式存储内容。(注意:每个class文件内容都是按照以下列表按列表中从上到下顺序组成,如果某些类型不涉及可以为空)
4 文件结构分析
4.1 魔数
标签:appservice,Ljava,dto,Utf8,customs,goldjet,详解,JVM,Class From: https://www.cnblogs.com/kukuxjx/p/17107692.html