Java-machine executable (class file)(cla.rfh):
Class: Executable and Object, Status: Almost Complete, Last change: 19.05.2023 13:40:44

set byteorder rev
type
  u1 num +(1)
  u2 num +(2)
  u4 num +(4)

data
0 u4 magic

assert magic=0xCAFEBABE;

descr ('CLASS file (Java VM executable).',NL,
  'Info Source: The JavaTM Virtual Machine Specification',NL,
  '  by Tim Lindholm and Frank Yellin',NL,
  '  at http://java.sun.com',NL,
  '  Java Virtual Machine Specification. The class File Format',NL,
  '  at https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html',NL,
  '  Java SE > Java SE Specifications > Java Virtual Machine Specification',NL,
  '    Chapter 4. The class File Format',NL,
  '  https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-4.html',NL)

type
  TCPInfoTag enum u1 of (
    C_Class = 7,
    C_Fieldref = 9,
    C_Methodref = 10,
    C_InterfaceMethodref = 11,
    C_String = 8,
    C_Integer = 3,
    C_Float = 4,
    C_Long = 5,
    C_Double = 6,
    C_NameAndType = 12,
    C_MethodHandle = 15,
    C_MethodType = 16,
    C_Dynamic = 17,
    C_InvokeDynamic = 18,
    C_Utf8 = 1,
    C_Module = 19,
    C_Package = 20
  )

//  TConstNDX1 u1()
//  TConstNDX u2()
  TUtf8NDX u2()
  TClassNDX u2()
  TNameTypeNDX u2()
  TFldRefNdx u2()
  TMethRefNdx u2()
  TIMethRefNdx u2()
  TDMethRefNdx u2()
  TBootstrapMethodRefNdx u2()


  TRefInfo struc
    TClassNDX class_index
    TNameTypeNDX NameTypeNdx
  ends

  TLongInfo struc
    u4 high_bytes
    u4 low_bytes
  ends

  TNameTypeInfo struc
    TUtf8NDX nameNdx %Utf8
    TUtf8NDX descrNdx %Utf8
  ends

  TUtf8Str struc
    u2 len
    array[@.len] of Char val %in fact Utf-8 encoding
  ends

  TMethodRefKind enum u1 of (
    REF_getField=1, //getfield C.f:T
    REF_getStatic=2, //getstatic C.f:T
    REF_putField=3, //putfield C.f:T
    REF_putStatic=4, //putstatic C.f:T
    REF_invokeVirtual=5, //invokevirtual C.m:(A*)T
    REF_invokeStatic=6, //invokestatic C.m:(A*)T
    REF_invokeSpecial=7, //invokespecial C.m:(A*)T
    REF_newInvokeSpecial=8, //new C; dup; invokespecial C.<init>:(A*)void
    REF_invokeInterface=9 //invokeinterface C.m:(A*)T
  )

  TMethodHandleInfo struc
    TMethodRefKind ref_kind
    case @.ref_kind of
     REF_getField,REF_getStatic,REF_putField,REF_putStatic: TFldRefNdx
     REF_invokeVirtual,REF_invokeStatic,REF_invokeSpecial,REF_newInvokeSpecial: TMethRefNdx
     REF_invokeInterface: TIMethRefNdx
    else
      u2 //Just in case
    endc ref_index
  ends

  TDynamicInfo struc
    TBootstrapMethodRefNdx bootstrap_method_attr_index //index into the bootstrap_methods array of the bootstrap method table
    TNameTypeNDX name_and_type_index
  ends

  TInvokeDynamicInfo struc
    TBootstrapMethodRefNdx bootstrap_method_attr_index //index into the bootstrap_methods array of the bootstrap method table
    TNameTypeNDX name_and_type_index
  ends
  
  cp_info struc
    TCPInfoTag Tag
    case @.Tag of
      C_Class: TUtf8NDX %name_index,Utf8
      C_Fieldref,
      C_Methodref,
      C_InterfaceMethodref: TRefInfo
      C_String: TUtf8NDX %string_index,Utf8
      C_Integer: u4 %Bytes
      C_Float: u4 %Bytes,IEEE 754
      C_Long: TLongInfo
      C_Double: TLongInfo
      C_NameAndType: TNameTypeInfo
      C_Utf8: TUtf8Str
     //new:
      C_MethodHandle: TMethodHandleInfo
      C_MethodType: TUtf8NDX //descriptor_index
      C_Dynamic: TDynamicInfo
      C_InvokeDynamic: TInvokeDynamicInfo
      C_Module: TUtf8NDX
      C_Package: TUtf8NDX
    endc info
  ends

  attribute_info forward
/*
  attribute_info struc
    TConstNDX name_index,Ult8
    u4 len
    array[@.len]of u1 info
  ends
*/
  TFieldAccessFlags set 16 of (
  //Flag Name    Value   Meaning                        Used By
    ACC_PUBLIC =    0, //Is public; may be accessed
                       //from outside its package.      Any field
    ACC_PRIVATE =   1, //Is private; usable only within
                       //the defining class.            Class field
    ACC_PROTECTED = 2, //Is protected; may be accessed
                       //within subclasses.             Class field
    ACC_STATIC =    3, //Is static.                     Any field
    ACC_FINAL =     4, //Is final; no further
                       //overriding or assignment after
                       //initialization.                Any field
    ACC_VOLATILE =  6, //Is volatile; cannot be cached. Class field
    ACC_TRANSIENT = 7,  //Is transient; not written or
                       //read by a persistent object
                       //manager.                       Class field
    ACC_SYNTHETIC = 12,	//Declared synthetic; not present in the source code
    ACC_ENUM = 14 	//Declared as an element of an enum class
  )

  field_info struc
    TFieldAccessFlags access_flags
    TUtf8NDX nameNdx
    TUtf8NDX descrNdx
    u2 attr_count
    array[@.attr_count]of attribute_info attributes
  ends

  TMethodAccessFlags set 16 of (
  //Flag Name    Value   Meaning                        Used By
    ACC_PUBLIC =    0, //Is public; may be accessed
                       //from outside its package.      Any method
    ACC_PRIVATE =   1, //Is private; usable only within
                       //the defining class.            Class/instance
    ACC_PROTECTED = 2, //Is protected; may be accessed
                       //within subclasses.             Class/instance
    ACC_STATIC =    3, //Is static.                     Class/instance
    ACC_FINAL =     4, //Is final; no overriding
                       //allowed.                       Class
    ACC_SYNCHRONIZED=5,//Is synchronized; wrap use in
                       //monitor lock.                  Class/instance
    ACC_BRIDGE = 6,    //A bridge method, generated by the compiler.
    ACC_VARARGS = 7,   //Declared with variable number of arguments.
    ACC_NATIVE=     8, //Is native; implemented in a
                       //language other than Java.      Class/instance
    ACC_ABSTRACT = 10,  //Is abstract; no implementation
                       //is provided.                   Any method
    ACC_STRICT = 11,   //In a class file whose major version number is at least 46 and at most 60: Declared strictfp.
    ACC_SYNTHETIC = 12//Declared synthetic; not present in the source code
  )

  method_info struc
    TMethodAccessFlags access_flags
    TUtf8NDX nameNdx
    TUtf8NDX descrNdx
    u2 attr_count
    array[@.attr_count]of attribute_info attributes
  ends

  TClassAccessFlags set 16 of (
  //Flag Name    Value   Meaning                        Used By
    ACC_PUBLIC =    0, //Is public; may be accessed     Class,
                       //from outside its package.      interface
    ACC_FINAL =     4, //Is final; no subclasses
                       //allowed.                       Class
    ACC_SUPER =     5, //Treat superclass methods       Class,
                       //specially in invokespecial.    interface
    ACC_INTERFACE = 9, //Is an interface.               Interface
    ACC_ABSTRACT = 10, //Is abstract; may not be        Class,
                       //instantiated.                  interface
   //newer spec:
    ACC_SYNTHETIC = 12,	//Declared synthetic; not present in the source code
    ACC_ANNOTATION = 13,//Declared as an annotation type.
    ACC_ENUM = 14, 	//Declared as an enum type.
    ACC_MODULE = 15     //Is a module, not a class or interface.
  )

  TClassFile struc
    u2 minor_version
    u2 major_version
    u2 C_pool_count
    array[@.C_pool_count-1]of cp_info TAKES 2 when(
      (@.Tag=TCPInfoTag.C_Long)or(@.Tag=TCPInfoTag.C_Double)); C_pool
    TClassAccessFlags access_flags
    TClassNDX this_class
    TClassNDX super_class
    u2 interfaces_count
    array[@.interfaces_count]of TClassNDX interfaces
    u2 fields_count
    array[@.fields_count] of field_info fields
    u2 methods_count
    array[@.methods_count]of method_info methods
    u2 attr_count
    array[@.attr_count]of attribute_info attributes
  ends

data
0004 TClassFile Hdr

type
  TUtf8NDX:displ=('''',Hdr.C_pool[@-1].info.C_Utf8.val,'''{str:',INT(@),'}')
  TClassNDX:displ=(Hdr.C_pool[@-1].info.C_Class,'{class:',INT(@),'}')
  TNameTypeNDX:displ=(Hdr.C_pool[@-1].info.C_NameAndType.nameNdx,'{name:',INT(@),'}')
  //TNameTypeNDX enum TNameTypeNDX Hdr.C_pool[@-1].info.C_NameAndType.nameNdx;
  //TRefNDX u2():displ=(Hdr.C_pool[@-1].info.C_Fieldref.NameTypeNdx,'{',@,'}')
  /*TRefNDX enum u2 Hdr.C_pool[@-1].info.C_Fieldref.NameTypeNdx;
  TFldRefNdx TRefNDX
  TMethRefNdx TRefNDX
  TIMethRefNdx TRefNDX*/
  TFldRefNdx:displ=(Hdr.C_pool[@-1].info.C_Fieldref.NameTypeNdx,'{field:',INT(@),'}')
  TMethRefNdx:displ=(Hdr.C_pool[@-1].info.C_Fieldref.NameTypeNdx,'{method:',INT(@),'}')
  TIMethRefNdx:displ=(Hdr.C_pool[@-1].info.C_Fieldref.NameTypeNdx,'{imethod:',INT(@),'}')
  TDMethRefNdx:displ=(Hdr.C_pool[@-1].info.C_InvokeDynamic,'{dynsite:',INT(@),'}')

//  TConstNDX1 enum TConstNDX1 = Hdr.C_pool[@-1]
//  TConstNDX enum TConstNDX = Hdr.C_pool[@-1]
  TConstNDX1 num+(1):displ=(Hdr.C_pool[@-1],'{',INT(@),'}')
  TConstNDX num+(2):displ=(Hdr.C_pool[@-1],'{',INT(@),'}')
  
  TMethodHandleNdx num+(2):displ=(Hdr.C_pool[@-1].info.C_MethodHandle,'{hmethod:',INT(@),'}')

  
include java_cod.rfi

type
  TAttrData raw[]

  TCodeExcRec struc
    u2 start_pc
    u2 end_pc
    u2 handler_pc
    TClassNDX catch_type
  ends

  TCodeAttr struc
    u2 max_stack
    u2 max_locals
    u4 CodeLen
    TOpSeries(@.CodeLen) code
  %  raw[@.CodeLen] code
    u2 ExcTblLen
    array[@.ExcTblLen]of TCodeExcRec exc_tbl
    u2 AttrCnt
    array[@.AttrCnt]of attribute_info attributes
  ends//:[@.code:Size=@.CodeLen]

  TExcAttr struc
    u2 NumExc
    array[@.NumExc]of TClassNDX ExcNdxTbl
  ends

  TLinNumRec struc
    u2 pc
    u2 l
  ends

  TLinNumAttr struc
    u2 Len
    array[@.Len]of TLinNumRec LinNumTbl
  ends

  TLocVarRec struc
    u2 start_pc
    u2 len
    TUtf8NDX name_index
    TUtf8NDX descr_index
    u2 index
  ends

  TLocVarTblAttr struc
    u2 Len
    array[@.Len]of TLocVarRec LocVarTbl
  ends
  
  TLocVarTypeRec struc
    u2 start_pc
    u2 len
    TUtf8NDX name_index
    TUtf8NDX sign_index
    u2 index
  ends

  TLocVarTypeTblAttr struc
    u2 Len
    array[@.Len]of TLocVarTypeRec LocVarTbl
  ends
  
  TInnerClassAccessFlags set 16 of (
    ACC_PUBLIC ^ 0x0001, //Marked or implicitly public in source.
    ACC_PRIVATE ^ 0x0002, //Marked private in source.
    ACC_PROTECTED ^ 0x0004, //Marked protected in source.
    ACC_STATIC ^ 0x0008, //Marked or implicitly static in source.
    ACC_FINAL ^ 0x0010, //Marked or implicitly final in source.
    ACC_INTERFACE ^ 0x0200, //Was an interface in source.
    ACC_ABSTRACT ^ 0x0400, //Marked or implicitly abstract in source.
    ACC_SYNTHETIC ^ 0x1000, //Declared synthetic; not present in the source code.
    ACC_ANNOTATION ^ 0x2000, //Declared as an annotation interface.
    ACC_ENUM ^ 0x4000 //Declared as an enum class.
  )

  TInnerClassRec struc
    TClassNDX inner_class_info_index
    TClassNDX outer_class_info_index
    TUtf8NDX inner_name_index
    TInnerClassAccessFlags inner_class_access_flags
  ends
  
  TInnerClassesAttr struc
    u2 number_of_classes
    array[@.number_of_classes]of TInnerClassRec classes
  ends

  TBootstrapMethodRec struc
    TMethodHandleNdx bootstrap_method_ref
    u2 n_args
    array[@.n_args]of TConstNDX args
  ends
  
  TBootstrapMethodsAttr struc
    u2 num_bootstrap_methods
    array[@.num_bootstrap_methods]of TBootstrapMethodRec bootstrap_methods
  ends
  
  TElementValueTag enum Char (
    //Type=tag Item	//value Item	Constant Type
    v_byte='B', 	//const_value_index	CONSTANT_Integer
    v_char='C', 	//const_value_index	CONSTANT_Integer
    v_double='D',	//const_value_index	CONSTANT_Double
    v_float='F',	//const_value_index	CONSTANT_Float
    v_int='I',  	//const_value_index	CONSTANT_Integer
    v_long='J', 	//const_value_index	CONSTANT_Long
    v_short='S',	//const_value_index	CONSTANT_Integer
    v_boolean='Z',	//const_value_index	CONSTANT_Integer
    v_String='s',	//const_value_index	CONSTANT_Utf8
    v_Enum='e',		//enum_const_value	Not applicable
    v_Class='c',	//class_info_index	Not applicable
    v_Annotation='@',	//annotation_value	Not applicable
    v_Array='['		//array_value	Not applicable
  )
  
  TAnnotation forward
  
  TElementValue struc
    TElementValueTag tag
    case @.tag of
     v_byte,v_char,v_double,v_float,v_int,v_long,v_short,v_boolean: TConstNDX
     v_string: TUtf8NDX
     v_Enum: struc
       TUtf8NDX type_name_index
       TUtf8NDX const_name_index
      ends
     v_Class: TUtf8NDX //return descriptor
     v_Annotation: TAnnotation
     v_Array: struc
       u2 n_vals
       array[@.n_vals]of TElementValue vals
      ends
    endc value
  ends
  
  TAnnotationElementValuePair struc
    TUtf8NDX el_name
    TElementValue value
  ends
  
  TAnnotation struc
    TUtf8NDX type_index
    u2 n_pairs
    array[@.n_pairs]of TAnnotationElementValuePair pairs
  ends
  
  TRuntimeAnnotationsAttr struc
    u2 num_annotations
    array[@.num_annotations]of TAnnotation annotations
  ends
  
  TVerificationTypeTag enum u1 of (
    I_Top = 0,
    I_Integer = 1,
    I_Float = 2,
    I_Double = 3,
    I_Long = 4,
    I_Null = 5,
    I_UninitializedThis = 6,
    I_Object = 7,
    I_Uninitialized = 8
  )
  
  TVerificationTypeInfo struc
    TVerificationTypeTag tag
    case @.tag of
     I_Object: TClassNDX //cpool_index
     I_Uninitialized: u2 //offset of the corresponding new instruction
    endc D
  ends
  
  TStackMapFrameType enum u1 of (
    SAME_STACK1_EXT=247,
    CHOP_3=248,
    CHOP_2=249,
    CHOP_1=250,
    SAME_EXT=251,
    APPEND_1=252,
    APPEND_2=253,
    APPEND_3=254,
    FULL=255
  ):displ = (case @ of
      0..63: ('SAME_',INT(@)) //SAME
      64..127: ('SAME_STACK_',INT(@-64)) //SAME_LOCALS_1_STACK_ITEM
      else (@)
  endc)
  TStackMapFrame struc
    TStackMapFrameType cod
    case @.cod of
      0..63: struc
       ends //SAME
      64..127: struc
         TVerificationTypeInfo stack0
       ends //SAME_LOCALS_1_STACK_ITEM
      //128..246: reserved
      247: struc
        u2 offset_delta
        TVerificationTypeInfo stack0 
       ends //SAME_LOCALS_1_STACK_ITEM_EXTENDED 
      248..250: struc
        u2 offset_delta 
       ends //CHOP, k=251-@@@.cod
      251: struc
        u2 offset_delta
       ends //SAME_FRAME_EXTENDED
      252..254: struc
        u2 offset_delta
        array[@@@.cod-251]of TVerificationTypeInfo locals 
       ends //APPEND
      255: struc
        u2 offset_delta
        u2 n_locals
        array[@.n_locals]of TVerificationTypeInfo locals
        u2 n_stack
        array[@.n_stack]of TVerificationTypeInfo stack
       ends //FULL_FRAME
    endc D
  ends
  
  TStackMapTableAttr struc
    u2 n_entries
    array[@.n_entries]of TStackMapFrame entries
  ends
  
  attribute_info struc
    TUtf8NDX name_index
    u4 len
    case Hdr.C_pool[@.name_index-1].
         info.C_Utf8.val of
      'SourceFile': TUtf8NDX
      'ConstantValue': TConstNDX
      'Code': TCodeAttr
      'Exceptions': TExcAttr
      'LineNumberTable': TLinNumAttr
      'LocalVariableTable': TLocVarTblAttr
      'LocalVariableTypeTable': TLocVarTypeTblAttr 
      'InnerClasses': TInnerClassesAttr
      'BootstrapMethods': TBootstrapMethodsAttr
      'RuntimeVisibleAnnotations','RuntimeInvisibleAnnotations': TRuntimeAnnotationsAttr
      'Signature': TUtf8NDX
      'StackMapTable': TStackMapTableAttr
    else
      TAttrData
    endc info
  ends:[@.info:Size=@.len]

  TBootstrapMethodRefNdx:displ=(Hdr.attributes[?Hdr.C_pool[@.name_index-1].
         info.C_Utf8.val='BootstrapMethods'].info.'BootstrapMethods'.bootstrap_methods[@].bootstrap_method_ref,'{bootstrap:',INT(@),'}')



Other specifications.


FlexT home page, Author`s home page.