There has been some discussion as to where to find the later updates to the class file format specification.
Two have been offered, as noted in the original e-mails below: (A) UpdatedClassFileFormat.pdf being downloaded from http://java.sun.com/docs/books/vmspec/2nd-edition/UpdatedClassFileFormat.pdf and (B) ClassFileFormat-final-draft.pdf being downloaded from http://java.sun.com/docs/books/vmspec/2nd-edition/ClassFileFormat-final-draf t.pdf I have compared these documents, which, on the face, look almost _completely_ identical. However, a simple 'diff A B' command showed where the difference were. It is my opinion that (B) is the latest, due to the extended description and clarification of the annotation attributes. Per Nick's quotation of objectweb.org, file (B) is probably the later of the two. But is it the _latest_? Can comeone confirm whether or not (B) is the latest class file spec? I would suggest that it might be. We are going to need proper verification of this speculation of mine if we are going to correctly implement the lated class files in a JVM. I have enclosed a text file 'ClassDocDiffs.txt' which shows the differences between (A) and (B) in a readable form. I have also enclosed 'diffs.txt' which is the raw data from which the differences were located. Could somebody please confirm which of either (A) or (B) or (C--neither) is the latest and most accurate version of the class file format specification? Is there yet a more recent one out there? Thanks for your help, Dan Lydick > [Original Message] > From: Nick Lothian <[EMAIL PROTECTED]> > To: <harmony-dev@incubator.apache.org> > Date: 6/5/05 6:37:01 PM > Subject: RE: [arch] How much of java.* and friends does Harmony need to write. Was: VM/Classlibrary interface > > There is also > http://java.sun.com/docs/books/vmspec/2nd-edition/ClassFileFormat-final-draf t.pdf . > > According to http://asm.objectweb.org/doc/tutorial-annotations.html it > included "modifications for J2SE 5.0 to support changes mandated by > JSR-14, JSR-175, and JSR-201, as well as minor corrections and > adjustments." > > > Nick > > > -----Original Message----- > > From: Ulrich Kunitz [mailto:[EMAIL PROTECTED] > > Sent: Monday, 6 June 2005 8:01 AM > > To: harmony-dev@incubator.apache.org > > Subject: Re: [arch] How much of java.* and friends does=20 > > Harmony need to write. Was: VM/Classlibrary interface > > =20 > > On Sun, 5 Jun 2005, Geir Magnusson Jr. wrote: > >=20 > > > > Also from time to time the VM interface has to be=20 > > extended for new=20 > > > > VMs, which have different needs. This is one reason that the=20 > > > > interface isn't yet stable, even for 1.4. > > >=20 > > > It would be interesting to know why and how it was extended=20 > > - there's=20 > > > something to learn there. I'm also interested in getting=20 > > some input=20 > > > from the commercial VM developers. > >=20 > > The new features in 1.5 varargs, enums, annotations, and=20 > > generics required additions to the class file format. More=20 > > changes appear to be introduced to improve debugging (type=20 > > infos about local variables). > >=20 > > Tom Tromey has already found a link to an updated class file > > description: > >=20 > > http://java.sun.com/docs/books/vmspec/2nd-edition/UpdatedClassFileFormat.pdf > >=20 > > Here is a short and probably incomplete overview over the changes: > >=20 > > varargs: ACC_VARARGS, ACC_BRIDGE (?) > > enums: ACC_ENUM > > annotations: ACC_ANNOTATION > >=20 > > New attributes: EnclosingMethod, Signature (for generics), > > LocalVariableTypeTable, > > RuntimeVisibleAnnotations, > > RuntimeInvisibleAnnotations, > > RumtimeVisibleParameterAnnotations, > > RumtimeInvisibleParameterAnnotations,
(A) UpdatedClassFileFormat.pdf downloaded from http://java.sun.com/docs/books/vmspec/2nd-edition/UpdatedClassFileFormat.pdf (B) ClassFileFormat-final-draft.pdf downloaded from http://java.sun.com/docs/books/vmspec/2nd-edition/ClassFileFormat-final-draft.pdf (A) page 97 "The ACC_ENUM bit indicates that this class is declared as an enumerated type." (B) page 97 "The ACC_ENUM bit indicates that this class or its superclass is declared as an enumerated type." (A) page 108 (missing) (B) page 108 "A Java compiler must generate generic signature information for any class, interface, constructor, or member whose generic signature would include references to type variables or parameterized types. If the 'throws' clause of a method or constructor does not involve type variables, the 'ThrowsSignature' may be elided from the 'MethodTypeSignature'. (A) page 117. "First, the null byte (byte)0 is encoded using the 2-byte format rather than the 1-byte format, so that Java virtual machine UTF-8 strings never have embedded nulls. (B) page 117. "First, the null character (char)0 is encoded using the 2-byte format rather rather than the 1-byte format, so that modified UTF-8 strings never have embedded nulls." (A) page 146 struct annotation { u2 type_index; u1 num_components; { u2 component_name_index; annotation_component_value component_value; } component[num_components] } (B) page 146 annotation { u2 type_index; u2 num_element_value_pairs; { u2 element_name_index; element_value value; } element_Value_pairs[num_element_value_pairs] } (A) page 147 representing the attribute interface describing the attribute corresponding to the annotation represented by this 'annotation' structure. 'num_components' The value of the 'num_components' item gives the number of components of the annotation represented by this 'annotation' structure. Note that a maximum of 255 components may be contained in a single 'annotation'. 'components' Each value of the components table represents a single component in the annotation represented by this 'annotation' structure. Each 'components' entry contains the following two items: 'component_name_index' The value of the 'component_name_index' item must be a valid index into the (B) page 147 representing a field descriptor representing the annotation type corresponding to the annotation represented by this 'annotation' structure. 'num_element_value_pairs' The value of the 'num_element_value_pairs' item gives the number of element-value pairs of the annotation represented by this 'annotation' structure. Note that a maximum of 65535 element-value pairs may be contained in a single annotation. 'element_value_pairs' Each value of the 'element_value_pairs' table represents a single element-value pair in the annotation represented by this 'annotation' structure. Each 'element_value_pairs' entry contains the following two items: 'element_name_index' The value of the 'element_name_index' item must be a valid index into the (A) page 147 'component_value' The value of the 'component_value' item represents the value of the annotation component represented by this 'components' entry. The 'annotation_component_value' structure The 'annotation_component_value' structure is a discriminated union representing the value of an 'annotation' component. It is used to represent annotation value s in all attributes that describe annotations... The 'annotation_component_value' structure has the following format: (B) page 147 'value' The value of the 'value' item represents the value of the element-value pair represented by this 'element_value_pairs' entry. 4.8.14.1 The 'element_value' structure The 'element_value' structure is a discriminated union representing the value of an 'element-value' pair. It is used to represent element values in all attributes that describe annotations... The 'element_value' structure has the following format: *** IMPORTANT *** Notice a significant difference in the definition of the enumeration constant. (B) seems to have a definition corresponding more with JDK 5. (A) page 148 struct annotation_component_value { u1 tag; union { u2 const_value_index; u2 enum_const_index; <--- *** u2 class_info_index; annotation attr_value; struct { u2 num_values; annotation_component_value values[num_values]; } array_value; } value; } (B) page 148 element_value { u1 tag; union { u2 const_value_index; { u2 type_name_index; u2 const_name_index; } enum_const_value; <--- *** u2 class_info_index; annotation annotation_value; { u2 num_values; element_value values[num_values]; } array_value; } value; } (A) page 148 The items of the 'annotation_component_value' structure are as follows: The tag item indicates the type of this annotation 'component'.... ...Annotation Component Type ...attribute type (B) page 148 The items of the 'element_value' structure are as follows: The tag item indicates the type of this annotation 'element-value' pair.... ...Element Type ...annotation type *** IMPORTANT *** I think this item indicates that a correction was made to (A) in order to make it reference the correct table as in (B). Table 4.6 is way back on page 128 in the section on the ConstantValue attribute. (A) page 149 type for the field type designated by the tag item, as specified in table 4.6. (B) page 149 type for the field type designated by the tag item, as specified in Table 4.8. *** IMPORTANT *** These two definitions for the enumeration constant are consistent with the structure element pseudocode differences above: (A) page 149 'enum_const_index' The 'enum_const_index' item is used if the tag item is 'e'. The 'enum_const_index' item must be a valid index into the 'constant_pool' table. The 'constant_pool' entry at that index must be a 'CONSTANT_Fieldref_info' structure representing the enum constant represented by this 'annotation_component_value' structure. (B) page 149 'enum_const_value' The 'enum_const_value' item is used if the tag item is 'e'. The 'enum_const_value' item consists of the following two items: 'type_name_index' The value of the 'type_name_index' item must be a valid index into the 'constant_pool' table. The 'constant_pool' entry at that index must be a 'CONSTANT_Utf8_info' structure representing the binary name (JLS 13.1) of the type of the enum constant represented by this 'element_value' structure. 'const_name_index' The value of the 'const_name_index' item must be a valid index into the 'constant_pool' table. The 'constant_pool' entry at that index must be a 'CONSTANT_Utf8_info' structure representing the simple name of the enum constant represented by this 'element_value' structure. (A) page 149 (under 'class_info_index') The 'class_info_index' item must be a 'CONSTANT_Class_info' structure representing the class represented by this 'annotation_component_value' structure. 'attr_value' The 'attr_value' item is used if the tag item is '@'. The 'annotation_component_value' structure represents a "nested" annotation. (B) page 149 (under 'class_info_index') The 'class_info_index' item must be a 'CONSTANT_Utf8_info' structure representing the return descriptor (paragraph 4.4.3) of the type that is reified by the class represented by this element_value structure (e.g., 'V' for Void.class, 'Ljava/lang/Object;' for Object, etc.) 'annotation_value' The annotation_value item is used if the tag item is '@'. The element_value structure represents a "nested" annotation. (A) page 154 (missing) <--- *** It looks like (B) has a section that (A) does not (B) page 154 4.8.18 The AnnotationDefault attribute The 'AnnotationDefault' attribute is a variable length attribute in the attributes table of certain 'method_info' structures, namely those representing elements of annotation types. The 'AnnotationDefault' attribute records the default value for the element represented by the 'method_info' structure. Each 'method_info' structures representing an element of an annotation types may contain at most one 'AnnotationDefault' attribute. The JVM must make this default value available so it can be applied by appropriate reflective APIs. The 'AnnotationDefault' attribute has the following format: AnnotationDefault_attribute { u2 attribute_name_index; u4 attribute_length; element_value default_value; } The items of the 'AnnotationDefault' structure are as follows: 'attribute_name_index' The value of the 'attribute_name_index' item must be a valid index into the 'constant_pool' table. The 'constant_pool' entry at that index must be a 'CONSTANT_Utf8_info' structure representing the string "AnnotationDefault". 'attribute_length' The value of the 'attribute_length' item indicates the length of the attribute, excluding the initial six bytes. The value of the 'attribute_length' item is thus dependent on the default value. 'default_value' The 'default_value' item represents the default value of the annotation type element whose default value is represented by this 'AnnotationDefault' attribute.
72c72 < Mi.0 = v = Mj.m. Only Sun can specify what range of versions a --- > Mi.0 £ v £ Mj.m. Only Sun can specify what range of versions a 92c92 < 45.65535 inclusive. For k 2 = implementations of version 1.k of the Java 2 --- > 45.65535 inclusive. For k = 2 implementations of version 1.k of the Java 2 114,115c114,115 < The ACC_ENUM bit is indicates that this class is declared as < an enumerated type. --- > The ACC_ENUM bit is indicates that this class or its > superclass is declared as an enumerated type. 193c193 < interfaces[i], where 0 = i < interfaces_count, must be a --- > interfaces[i], where 0 £ i < interfaces_count, must be a 481a482,486 > A Java compiler must output generic signature information for any class, > interface, consructor or member whose generic signature would include > references to type variables or parameterized types. If the throws clause of > a > method or constructor does not involve type variables, the ThowsSignature may > be elided from the MethodTypeSignature. 664c669 < . s m 2 · · e – 150 --- > . s m 2 . . e – 150 722c727 < mathematical expression s m 2 – · · e 1075 . --- > mathematical expression s m 2 . . e – 1075 . 761c766 < bits 5-0 bits 11-6 x: 1 1 1 0 bits 15-12 y: 1 0 z: 1 0 --- > bits 5-0 x: 1 1 1 0 bits 15-12 y: 1 0 bits 11-6 z: 1 0 777,780c782,785 < format. First, the null byte (byte)0 is encoded using the 2-byte format rather < than the 1-byte format, so that Java virtual machine UTF-8 strings never < have embedded nulls. Second, only the 1-byte, 2-byte, and 3-byte formats < of standard UTF-8 are used. The Java VM does not recognize the four-byte --- > format. First, the null character (char)0 is encoded using the 2-byte format > rather than the 1-byte format, so that modified UTF-8 strings never have > embedded nulls. Second, only the 1-byte, 2-byte, and 3-byte formats of > standard UTF-8 are used. The Java VM does not recognize the four-byte 1771c1776 < struct annotation { --- > annotation { 1773,1776c1778,1781 < u1 num_components; < { u2 component_name_index; < annotation_component_value component_value; < } components[num_components] --- > u2 num_element_value_pairs; > { u2 element_name_index; > element_value value; > } element_value_pairs[num_element_value_pairs] 1782,1794c1787,1799 < The constant_pool entry at that index must be a CONSTANT_Class_info structure representing < the attribute interface describing the attribute corresponding to the annotation < represented by this annotation structure. < num_components < The value of the num_components item gives the number of components of the < annotation represented by this annotation structure. Note that a maximum of 255 < components may be contained in a single annotation. < components < Each value of the components table represents a single component in the annotation < represented by this annotation structure. Each components entry contains the following < two items: < component_name_index < The value of the component_name_index item must be a valid index into the --- > The constant_pool entry at that index must be a CONSTANT_Utf8_info structure > representing > a field descriptor representing the annotation type corresponding to the > annotation represented by this annotation structure. > num_element_value_pairs > The value of the num_element_value_pairs item gives the number of > element-value > pairs of the annotation represented by this annotation structure. Note that a > maximum > of 65535 element-value pairs may be contained in a single annotation. > element_value_pairs > Each value of the element_value_pairs table represents a single element-value > pair in > the annotation represented by this annotation structure. Each > element_value_pairs entry > contains the following two items: > element_name_index > The value of the element_name_index item must be a valid index into the 1796,1806c1801,1811 < CONSTANT_Utf8_info structure representing the name of the annotation component < represented by this components entry. < component_value < The value of the component_value item represents the value of the annotation < component represented by this components entry. < The annotation_component_value structure < The annotation_component_value structure is a discriminated union representing < the value of an annotation component. It is used to represent annotation values in all < attributes that describe annotations ( RuntimeVisibleAnnotations, RuntimeInvisibleAnnotations, < RuntimeVisibleParameterAnnotations, and RuntimeInvisibleParameterAnnotations). < The annotation_component_value structure has the following format: --- > CONSTANT_Utf8_info structure representing the name of the annotation type > element > represented by this element_value_pairs entry. > value > The value of the value item represents the value of the element-value pair > represented > by this element_value_pairs entry. > 4.8.14.1 The element_value structure > The element_value structure is a discriminated union representing the value > of an > element-value pair. It is used to represent element values in all attributes > that > describe annotations ( RuntimeVisibleAnnotations, > RuntimeInvisibleAnnotations, Runtime- > VisibleParameterAnnotations, and RuntimeInvisibleParameterAnnotations). > The element_value structure has the following format: 1808c1813 < struct annotation_component_value { --- > element_value { 1812c1817,1820 < u2 enum_const_index; --- > { > u2 type_name_index; > u2 const_name_index; > } enum_const_value; 1814,1815c1822,1823 < annotation attr_value; < struct { --- > annotation annotation_value; > { 1817c1825 < annotation_component_value values[num_values]; --- > element_value values[num_values]; 1821c1829 < The items of the annotation_component_value structure are as follows: --- > The items of the element_value structure are as follows: 1823,1826c1831,1834 < The tag item indicates the type of this annotation component. The letters 'B', 'C', < 'D', 'F', 'I', 'J', 'S', and 'Z' indicate a primitive type. These letters are interpreted as < BaseType characters (§Table 4.2). The other legal values for tag are listed with their < interpretations in this table: --- > The tag item indicates the type of this annotation element-value pair. The > letters > 'B', 'C', 'D', 'F', 'I', 'J', 'S', and 'Z' indicate a primitive type. These > letters are interpreted > as BaseType characters (§Table 4.2). The other legal values for tag are > listed > with their interpretations in this table: 1833c1841 < Annotation Component Type --- > Element Type 1837c1845 < attribute type --- > annotation type 1842d1849 < const_value_index 1844a1852 > const_value_index 1848,1853c1856,1869 < type for the field type designated by the tag item, as specified in table 4.6. < enum_const_index < The enum_const_index item is used if the tag item is 'e'. The enum_const_index item < must be a valid index into the constant_pool table. The constant_pool entry at that index < must be a CONSTANT_Fieldref_info structure representing the enum constant represented < by this annotation_component_value structure. --- > type for the field type designated by the tag item, as specified in Table > 4.8. > enum_const_value > The enum_const_value item is used if the tag item is 'e'. The > enum_const_value item > consists of the following two items: > type_name_index > The value of the type_name_index item must be a valid index into the > constant_pool > table. The constant_pool entry at that index must be a CONSTANT_Utf8_info > structure > representing the binary name (JLS 13.1) of the type of the enum constant > represented > by this element_value structure. > const_name_index > The value of the const_name_index item must be a valid index into the > constant_pool > table. The constant_pool entry at that index must be a CONSTANT_Utf8_info > structure > representing the simple name of the enum constant represented by this > element_value > structure. 1857,1861c1873,1878 < be a CONSTANT_Class_info structure representing the class represented by this < annotation_component_value structure. < attr_value < The attr_value item is used if the tag item is '@'. The annotation_component_value < structure represents a "nested" annotation. --- > be a CONSTANT_Utf8_info structure representing the return descriptor (§4.4.3) > of the > type that is reified by the class represented by this element_value structure > (e.g., ‘V’ > for Void.class, ‘Ljava/lang/Object;’ for Object, etc.) > annotation_value > The annotation_value item is used if the tag item is '@'. The element_value > structure > represents a "nested" annotation. 1867,1870c1884,1887 < annotation component value represented by this annotation_component_value < structure. Note that a maximum of 65535 elements are permitted in an array-typed < annotation component value. < values --- > value represented by this element_value structure. Note that a maximum of > 65535 elements are permitted in an array-typed element value. > values > THE CLASS FILE FORMAT 150 1872c1889 < annotation component value represented by this annotation_component_value structure. --- > value represented by this element_value structure. 1877,1879c1894,1895 < JVM has been instructed to retain these annotations via some implementation-spe- < THE CLASS FILE FORMAT 150 < cific mechanism such as a command line flag. In the absence of such instructions, --- > JVM has been instructed to retain these annotations via some > implementation-specific > mechanism such as a command line flag. In the absence of such instructions, 1902c1918,1919 < the initial six bytes. The value of the attribute_length item is thus dependent on the --- > the initial six bytes. The value of the attribute_length item is thus > dependent on the > VERIFICATION OF CLASS FILES 151 1911c1928 < on a program element. VERIFICATION OF CLASS FILES 151 --- > on a program element. 1932c1949,1950 < attribute_name_index --- > attribute_name_index > THE CLASS FILE FORMAT 152 1941,1942c1959 < num_parameters < THE CLASS FILE FORMAT 152 --- > num_parameters 1965c1982,1983 < absence of such instructions, the JVM ignores this attribute. --- > absence of such instructions, the JVM ignores this attribute. > ATTRIBUTES 153 1973,1974c1991 < The RuntimeInvisibleParameterAnnotations attribute has the following format: < ATTRIBUTES 153 --- > The RuntimeInvisibleParameterAnnotations attribute has the following format: 1998c2015 < parameter_annotations --- > parameter_annotations 2007c2024 < annotations --- > annotations 2010a2028,2054 > 4.8.18 The AnnotationDefault attribute > The AnnotationDefault attribute is a variable length attribute in the > attributes table of > certain method_info structures, namely those representing elements of > annotation > types. The AnnotationDefault attribute records the default value for the > element represented > by the method_info structure. Each method_info structures representing an > element > of an annotation types may contain at most one AnnotationDefault attribute. > The > JVM must make this default value available so it can be applied by > appropriate > reflective APIs. > The AnnotationDefault attribute has the following format: > AnnotationDefault_attribute { > u2 attribute_name_index; > u4 attribute_length; > element_value default_value; > } > The items of the AnnotationDefault structure are as follows: > attribute_name_index > The value of the attribute_name_index item must be a valid index into the > constant_pool table. The constant_pool entry at that index must be a > CONSTANT_Utf8_info structure representing the string "AnnotationDefault". > attribute_length > FORMAT CHECKING 155 > The value of the attribute_length item indicates the length of the attribute, > excluding > the initial six bytes. The value of the attribute_length item is thus > dependent on the > default value. > default_value > The default_value item represents the default value of the annotation type > element > whose default value is represented by this AnnotationDefault attribute. 2032c2076 < CONSTRAINTS ON JAVA VIRTUAL MACHINE CODE 155 --- > THE CLASS FILE FORMAT 156 2061c2105 < have a number of entries in its jump table that is consistent with the value of its THE CLASS FILE FORMAT 156 --- > have a number of entries in its jump table that is consistent with the value > of its CONSTRAINTS ON JAVA VIRTUAL MACHINE CODE 157 2095c2139 < class or interface initialization method specially named <clinit> is never called CONSTRAINTS ON JAVA VIRTUAL MACHINE CODE 157 --- > class or interface initialization method specially named <clinit> is never > called THE CLASS FILE FORMAT 158 2130c2174 < THE CLASS FILE FORMAT 158 --- > CONSTRAINTS ON JAVA VIRTUAL MACHINE CODE 159 2161c2205 < CONSTRAINTS ON JAVA VIRTUAL MACHINE CODE 159 --- > THE CLASS FILE FORMAT 160 2197c2241 < THE CLASS FILE FORMAT 160 --- > CONSTRAINTS ON JAVA VIRTUAL MACHINE CODE 161 2229,2230c2273,2274 < information on Java virtual machine subroutines, see §4.11.2.6.) < VERIFICATION OF class FILES 161 --- > information on Java virtual machine subroutines, see §4.11.1.6.) > THE CLASS FILE FORMAT 162 2263c2307 < THE CLASS FILE FORMAT 162 --- > VERIFICATION OF class FILES 163 2290c2334 < VERIFICATION OF class FILES 163 --- > THE CLASS FILE FORMAT 164 2322c2366 < THE CLASS FILE FORMAT 164 --- > VERIFICATION OF class FILES 165 2357c2401 < VERIFICATION OF class FILES 165 --- > THE CLASS FILE FORMAT 166 2389c2433 < stack and local variable values calculated in steps 2 and 3 into the THE CLASS FILE FORMAT 166 --- > stack and local variable values calculated in steps 2 and 3 into the > VERIFICATION OF class FILES 167 2426c2470 < and long as atomic (indivisible). For example, the verifier reports a failure if the top value VERIFICATION OF class FILES 167 --- > and long as atomic (indivisible). For example, the verifier reports a failure > if the top value THE CLASS FILE FORMAT 168 2468c2512 < as the result of the Java virtual machine instruction new. The special type indicates the THE CLASS FILE FORMAT 168 --- > as the result of the Java virtual machine instruction new. The special type > indicates the VERIFICATION OF class FILES 169 2501c2545 < LIMITATIONS OF THE JAVA VIRTUAL MACHINE 169 --- > THE CLASS FILE FORMAT 170 2521d2564 < • The number of direct superinterfaces of a class or interface is limited to 65535 2522a2566 > • The number of direct superinterfaces of a class or interface is limited to > 65535 2533c2577 < THE CLASS FILE FORMAT 170 --- > LIMITATIONS OF THE JAVA VIRTUAL MACHINE 171 2545a2590 > THE CLASS FILE FORMAT 172