Java类文件结构及javac的ClassReader类解读

首先来看一下ClassFile,类注释如下:

   A JVM class file.

Generic Java classfiles have one additional attribute for classes,
methods and fields:

"Signature" (u4 attr-length, u2 signature-index)


A signature gives the full Java type of a method or field. When
used as a class attribute, it indicates type parameters, followed
by supertype, followed by all interfaces.

methodOrFieldSignature ::= type
classSignature ::= [ typeparams ] supertype { interfacetype }

The type syntax in signatures is extended as follows:

type ::= ... | classtype | methodtype | typevar
classtype ::= classsig { '.' classsig }
classig ::= 'L' name [typeargs] ';'
methodtype ::= [ typeparams ] '(' { type } ')' type
typevar ::= 'T' name ';'
typeargs ::= '<' type { type } '>'
typeparams ::= '<' typeparam { typeparam } '>'
typeparam ::= name ':' type

This class defines constants used in class files as well
as routines to convert between internal ``.'' and external ``/''
separators in class names.

一些常量定义(由虚拟机严格规定)如下:

 

public final static int JAVA_MAGIC = 0xCAFEBABE;  // 魔数

    // 常量池中14种常量项
    public final static int CONSTANT_Utf8 = 1;
    public final static int CONSTANT_Unicode = 2;
    public final static int CONSTANT_Integer = 3;
    public final static int CONSTANT_Float = 4;
    public final static int CONSTANT_Long = 5;
    public final static int CONSTANT_Double = 6;
    public final static int CONSTANT_Class = 7;
    public final static int CONSTANT_String = 8;
    public final static int CONSTANT_Fieldref = 9;
    public final static int CONSTANT_Methodref = 10;
    public final static int CONSTANT_InterfaceMethodref = 11;
    public final static int CONSTANT_NameandType = 12;
    public final static int CONSTANT_MethodHandle = 15;
    public final static int CONSTANT_MethodType = 16;
    public final static int CONSTANT_InvokeDynamic = 18;

    public final static int MAX_PARAMETERS = 0xff; // max_parameters
    public final static int MAX_DIMENSIONS = 0xff; // max_dimensions
    public final static int MAX_CODE = 0xffff; // max_code
    public final static int MAX_LOCALS = 0xffff; // max_locals
    public final static int MAX_STACK = 0xffff; // max_stack

 

ClassReader类的注释如下:

 This class provides operations to read a classfile into an internal
representation. The internal representation is anchored in (立足于) a
ClassSymbol which contains in its scope symbol representations
for all other definitions in the classfile.

Top-level Classes themselves appear as members of the scopes of PackageSymbols.

Error Diagnoses
Buffer Access
Constant Pool Access
Reading Types
Reading Attributes
Reading Java-language annotations
Reading Symbols
Adjusting flags
Loading Classes
Loading Packages
 

 

 

参考文章:

http://blog.csdn.net/column/details/jvm-principle.html

转载于:https://www.cnblogs.com/extjs4/p/7040883.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值