2.4 Fields<strong>The</strong> information for each field immediately follows the field_count field in the class file. Each field is describedby a variable length field_info structure. <strong>The</strong> format of this structure is as follows:field_info (u2 access_ flags;u2 name_index;u2 signature_index;u2 attributes_count;attribute_info attributes(attribute_countl;access_ lag•This is a set of sixteen flags used by classes, methods, and fields to describe various propertiesand how they many be accessed by methods in other classes. See the table "Access Flags" onpage 12 which indicates the meaning of the bits in this field.<strong>The</strong> possible fields that can be set for a field are ACC_PUBLIC, ACC_PRIVATE,ACC _PROTECTED, ACC_STAT I C, ACC_F I NAL, ACC_VOLATI LE, and ACC_TRANS I ENT .At most one of ACC_ PUBL I C, ACC_PROTECTED, and ACC_PRIVATE can be set for anymethodname_indexcon stant_pool (name_index) is a CONSTANT_Ut f 8 string which is the name of thefield.• ignature_indexconstant_pool ( s ignature_index I is a CONSTANT_Ut f string which is the signatureof the field. See the section "Signatures" for more information on signatures.attributes_countThis value indicates the number of additional attributes about this field.attributesA field can have any number of optional attributes associated with it. Currently, the only fieldattribute recognized is the "Constant Value" attribute, which indicates that this field is a staticnumeric constant, and indicates the constant value of that field.Any other attributes are skipped.2.5 Methods<strong>The</strong> information for each method immediately follows the met hod_count field in the class file. Each methodis described by is variable length method_ i nfo structure. <strong>The</strong> structure has the following format:method_infou2 access_flags;u2 name_index;u2 signature_index;u2 attributes_count;attribute_info attribuceslactribute_countl;access_flagsThis is a set of sixteen flags used by classes, methods, and fields to describe various propertiesand how they many be accessed by methods in other classes. See the table "'Access Flags - onpage 12 which gives the various bits in this field.<strong>The</strong> possible fields that can be set for a method are ACC_PUBLIC, ACC_PRIVATE,ACC_ PROTECTED, ACC_STATIC, ACC_F I NAL, ACC_S YNCHRON I 2 ED, ACC _NAT I V E, aridACC_ABSTFtACT.Al most one of ACC_PUBLIC, ACC_PROTECTED, and ACC__PR I VATE can be set for anymethod.name_ indexconstant._pool (name_index) is a CONSTANT_Ut f 0 string giving the name of themethod.signature_indexconstant_pool ( s ignature_i ndex) is a CONSTANT_Ut f 8 string giving the signature ofthe field. See the section "Signatures" for more information on signatures.attributes_countThis value indicates the number of additional attributes about this field.attribute.A field can have any number of optional attributes associated with it. Each attribute has aname, and other additional information. Currently, the only field attributes recognized are the"Code" and "Exceptions" attributes, which describe the bytecodes that are executed toperform this method, and the Java Exceptions which are declared to result from the executionof the method, respectively.Any other attributes are skipped.2.6 AttributesAttributes are used at several different places in the class format. All attributes have the following format.GenericAttribute_infou2 attribute_name;u4 attribute_length;ul infolattribute_length);<strong>The</strong> attr ibute_name is a 16•bit index into the class's constant pool; the value ofconstant_pool ( at t r bute_name I is a CONSTANT_Ut f8 string giving the name of the attribute. thefield attribute_length indicates the length of the subsequent information in bytes. This length does notinclude the six bytes of the attribute_name and at tri bo t e_l ength.In the following text, whenever we allow attributes, we give the name of the attributes that are currentlyunderstood. In the future, more attributes will be added. Class file readers are expected to skip over and ignorethe information in any attribute they do not understand.Augurs 22, 1995 JAVA Vlrtunt Machine SpetIlICA11011 19 20 JAVA VIMIAIMAthille Spe
2.6.1 SourceFile<strong>The</strong> "SourceFile" attribute has the following format:SourceFile_attribute (u2 attribute_name_index;u4 attribute_length;u2 sourcefile_index:at t ribute_name_indexcons tant_pool (at tr i bute_name_i ndex ) is the CONSTANT_Ut f 8 string- SourceFiattribute_lengthCode_attribute (u2 attribute_name_index;u4 attribute_length;u2 max_stack;u2 max_locals;u4 code_length;ul code(code_lengthl;u2 exception_table_length;( u2 start_pc;u2 end_pc;u2 handler_pc;u2 catch_type;) exception_table(exception_table_length);u2 attributes_count;attribute_info at.tributes(attribute_count);<strong>The</strong> length of a Sourceile_attribute must be 2 .source f ile_indexconstant_pool ( source ffrom which this class file was compiled.2.6.2 ConstantValue<strong>The</strong> "Constant Value" attribute has the following format:ConstantValue_attributeu2 attribute_name_index;u4 attribute_length;u2 constantvalue_index;attribute_name_indexis a CONSTANT_Ut f 8 string giving the source fileconstant_pool tat t r bute_name_i ndex is the CONSTANT_Ut f 8 string'ConstantValue" .attribute_length<strong>The</strong> length of a Constant Value_attribute must be 2.co<strong>net</strong>•ntvalue_indexcons tan t_pool (constant value_index I gives the constant value for this field.<strong>The</strong> constant pool entry must be of a type appropriate to the field, as shown by the followingtable:attribute_name_indexconstant_pool ( att r i bute_name_ ndex I is the CONSTANT_Ut f 8 siring -Code - .attribute_lengthThis field indicates the total length of the "Code" attribute, excluding the initial six bytesmax_stackMaximum number of entries on the operand stack that will be used during execution of thismethod. See the other chapters in this spec for more information on the operand stack.mex_loca laNumber of local variable slots used by this method. See the other chapters in this spec formore information on the local variables.code_ lengthcode<strong>The</strong> number of bytes in the virtual machine code for this method.<strong>The</strong>se are the actual bytes of the virtual machine code that implement the method. When readinto memory, if the first byte of code is aligned onto a multiple•of•four boundary the thetableswitch and tablelookup opcodc entries will be aligned; see their description formore information on alignment requirements.except ion_table_length<strong>The</strong> number of entries in the following exception table.longfloatdoubleint, short, char, byte, boolean2.6.3 Code<strong>The</strong> "Code" attribute has the following format:CONSTANT_LongCONSTANT_FloatCONSTANT_DoubleCONSTANT_Integerexception_tebleEach entry in the exception table describes one exception handler in the codestart_pc, end_pc<strong>The</strong> two fields start_pc and end_pc indicate the ranges in the code at which the exceptionhandler is active. <strong>The</strong> values of both fields arc offsets from the start of the code. start_pc isinclusive. end_pc is exclusive.handler_pcThis field indicates the starting address of the exception handler. <strong>The</strong> value of the field is anoffset from the start of the code.August 22, 1915 JAvA VutuAl MAchlne SpecIlIcAlion 21 22 tas• Viirual MAchonc Specificmion A.K.021995