Class文件解读
https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html
java file source content
package tests;
import java.io.Serializable;
public class DemoClass implements Serializable, Cloneable {
int num;
private double privateDoubleField;
long defaultLongField;
protected char chValue;
public static final String STATIC_FINAL_STRING = "I'm a final static string in DemoClass";
public static String staticString = "I'm a static string in DemoClass";
public int add() {
num = num + 2;
return num;
}
public void check(int inum, double dnum, long lnum, char chnum) {
System.out.println(">" + inum + dnum + lnum + chnum);
}
}
compile java file by
javac -g DemoClass.java
class content
CA FE BA BE 00 00 00 34 00 56 0A 00 11 00 33 09
00 10 00 34 09 00 35 00 36 07 00 37 0A 00 04 00
33 08 00 38 0A 00 04 00 39 0A 00 04 00 3A 0A 00
04 00 3B 0A 00 04 00 3C 0A 00 04 00 3D 0A 00 04
00 3E 0A 00 3F 00 40 08 00 41 09 00 10 00 42 07
00 43 07 00 44 07 00 45 07 00 46 01 00 03 6E 75
6D 01 00 01 49 01 00 12 70 72 69 76 61 74 65 44
6F 75 62 6C 65 46 69 65 6C 64 01 00 01 44 01 00
10 64 65 66 61 75 6C 74 4C 6F 6E 67 46 69 65 6C
64 01 00 01 4A 01 00 07 63 68 56 61 6C 75 65 01
00 01 43 01 00 13 53 54 41 54 49 43 5F 46 49 4E
41 4C 5F 53 54 52 49 4E 47 01 00 12 4C 6A 61 76
61 2F 6C 61 6E 67 2F 53 74 72 69 6E 67 3B 01 00
0D 43 6F 6E 73 74 61 6E 74 56 61 6C 75 65 08 00
47 01 00 0C 73 74 61 74 69 63 53 74 72 69 6E 67
01 00 06 3C 69 6E 69 74 3E 01 00 03 28 29 56 01
00 04 43 6F 64 65 01 00 0F 4C 69 6E 65 4E 75 6D
62 65 72 54 61 62 6C 65 01 00 12 4C 6F 63 61 6C
56 61 72 69 61 62 6C 65 54 61 62 6C 65 01 00 04
74 68 69 73 01 00 11 4C 74 65 73 74 73 2F 44 65
6D 6F 43 6C 61 73 73 3B 01 00 03 61 64 64 01 00
03 28 29 49 01 00 05 63 68 65 63 6B 01 00 07 28
49 44 4A 43 29 56 01 00 04 69 6E 75 6D 01 00 04
64 6E 75 6D 01 00 04 6C 6E 75 6D 01 00 05 63 68
6E 75 6D 01 00 08 3C 63 6C 69 6E 69 74 3E 01 00
0A 53 6F 75 72 63 65 46 69 6C 65 01 00 0E 44 65
6D 6F 43 6C 61 73 73 2E 6A 61 76 61 0C 00 21 00
22 0C 00 14 00 15 07 00 48 0C 00 49 00 4A 01 00
17 6A 61 76 61 2F 6C 61 6E 67 2F 53 74 72 69 6E
67 42 75 69 6C 64 65 72 01 00 01 3E 0C 00 4B 00
4C 0C 00 4B 00 4D 0C 00 4B 00 4E 0C 00 4B 00 4F
0C 00 4B 00 50 0C 00 51 00 52 07 00 53 0C 00 54
00 55 01 00 20 49 27 6D 20 61 20 73 74 61 74 69
63 20 73 74 72 69 6E 67 20 69 6E 20 44 65 6D 6F
43 6C 61 73 73 0C 00 20 00 1D 01 00 0F 74 65 73
74 73 2F 44 65 6D 6F 43 6C 61 73 73 01 00 10 6A
61 76 61 2F 6C 61 6E 67 2F 4F 62 6A 65 63 74 01
00 14 6A 61 76 61 2F 69 6F 2F 53 65 72 69 61 6C
69 7A 61 62 6C 65 01 00 13 6A 61 76 61 2F 6C 61
6E 67 2F 43 6C 6F 6E 65 61 62 6C 65 01 00 26 49
27 6D 20 61 20 66 69 6E 61 6C 20 73 74 61 74 69
63 20 73 74 72 69 6E 67 20 69 6E 20 44 65 6D 6F
43 6C 61 73 73 01 00 10 6A 61 76 61 2F 6C 61 6E
67 2F 53 79 73 74 65 6D 01 00 03 6F 75 74 01 00
15 4C 6A 61 76 61 2F 69 6F 2F 50 72 69 6E 74 53
74 72 65 61 6D 3B 01 00 06 61 70 70 65 6E 64 01
00 2D 28 4C 6A 61 76 61 2F 6C 61 6E 67 2F 53 74
72 69 6E 67 3B 29 4C 6A 61 76 61 2F 6C 61 6E 67
2F 53 74 72 69 6E 67 42 75 69 6C 64 65 72 3B 01
00 1C 28 49 29 4C 6A 61 76 61 2F 6C 61 6E 67 2F
53 74 72 69 6E 67 42 75 69 6C 64 65 72 3B 01 00
1C 28 44 29 4C 6A 61 76 61 2F 6C 61 6E 67 2F 53
74 72 69 6E 67 42 75 69 6C 64 65 72 3B 01 00 1C
28 4A 29 4C 6A 61 76 61 2F 6C 61 6E 67 2F 53 74
72 69 6E 67 42 75 69 6C 64 65 72 3B 01 00 1C 28
43 29 4C 6A 61 76 61 2F 6C 61 6E 67 2F 53 74 72
69 6E 67 42 75 69 6C 64 65 72 3B 01 00 08 74 6F
53 74 72 69 6E 67 01 00 14 28 29 4C 6A 61 76 61
2F 6C 61 6E 67 2F 53 74 72 69 6E 67 3B 01 00 13
6A 61 76 61 2F 69 6F 2F 50 72 69 6E 74 53 74 72
65 61 6D 01 00 07 70 72 69 6E 74 6C 6E 01 00 15
28 4C 6A 61 76 61 2F 6C 61 6E 67 2F 53 74 72 69
6E 67 3B 29 56 00 21 00 10 00 11 00 02 00 12 00
13 00 06 00 00 00 14 00 15 00 00 00 02 00 16 00
17 00 00 00 00 00 18 00 19 00 00 00 04 00 1A 00
1B 00 00 00 19 00 1C 00 1D 00 01 00 1E 00 00 00
02 00 1F 00 09 00 20 00 1D 00 00 00 04 00 01 00
21 00 22 00 01 00 23 00 00 00 2F 00 01 00 01 00
00 00 05 2A B7 00 01 B1 00 00 00 02 00 24 00 00
00 06 00 01 00 00 00 05 00 25 00 00 00 0C 00 01
00 00 00 05 00 26 00 27 00 00 00 01 00 28 00 29
00 01 00 23 00 00 00 3D 00 03 00 01 00 00 00 0F
2A 2A B4 00 02 05 60 B5 00 02 2A B4 00 02 AC 00
00 00 02 00 24 00 00 00 0A 00 02 00 00 00 0E 00
0A 00 0F 00 25 00 00 00 0C 00 01 00 00 00 0F 00
26 00 27 00 00 00 01 00 2A 00 2B 00 01 00 23 00
00 00 7E 00 04 00 07 00 00 00 28 B2 00 03 BB 00
04 59 B7 00 05 12 06 B6 00 07 1B B6 00 08 28 B6
00 09 16 04 B6 00 0A 15 06 B6 00 0B B6 00 0C B6
00 0D B1 00 00 00 02 00 24 00 00 00 0A 00 02 00
00 00 13 00 27 00 14 00 25 00 00 00 34 00 05 00
00 00 28 00 26 00 27 00 00 00 00 00 28 00 2C 00
15 00 01 00 00 00 28 00 2D 00 17 00 02 00 00 00
28 00 2E 00 19 00 04 00 00 00 28 00 2F 00 1B 00
06 00 08 00 30 00 22 00 01 00 23 00 00 00 1E 00
01 00 00 00 00 00 06 12 0E B3 00 0F B1 00 00 00
01 00 24 00 00 00 06 00 01 00 00 00 0B 00 01 00
31 00 00 00 02 00 32
explain
CA FE BA BE magic
00 00 minor_version
00 34 major_version
00 56 constant_pool_count
0A 00 11 00 33 CONSTANT_Methodref
09 00 10 00 34 CONSTANT_Fieldref
09 00 35 00 36 CONSTANT_Fieldref
07 00 37 CONSTANT_Class
0A 00 04 00 33 CONSTANT_Methodref
08 00 38 CONSTANT_String
0A 00 04 00 39 CONSTANT_Methodref
0A 00 04 00 3A CONSTANT_Methodref
0A 00 04 00 3B CONSTANT_Methodref
0A 00 04 00 3C CONSTANT_Methodref
0A 00 04 00 3D CONSTANT_Methodref
0A 00 04 00 3E CONSTANT_Methodref
0A 00 3F 00 40 CONSTANT_Methodref
08 00 41 CONSTANT_String
09 00 10 00 42 CONSTANT_Fieldref
07 00 43 CONSTANT_Class
07 00 44 CONSTANT_Class
07 00 45 CONSTANT_Class
07 00 46 CONSTANT_Class
01 00 03 6E 75 6D CONSTANT_Utf8
01 00 01 49 CONSTANT_Utf8
01 00 12 70 72 69 76 61 74 65 44 6F 75 62 6C 65 46 69 65 6C 64 CONSTANT_Utf8
01 00 01 44 CONSTANT_Utf8
01 00 10 64 65 66 61 75 6C 74 4C 6F 6E 67 46 69 65 6C 64 CONSTANT_Utf8
01 00 01 4A CONSTANT_Utf8
01 00 07 63 68 56 61 6C 75 65 CONSTANT_Utf8
01 00 01 43 CONSTANT_Utf8
01 00 13 53 54 41 54 49 43 5F 46 49 4E 41 4C 5F 53 54 52 49 4E 47 CONSTANT_Utf8
01 00 12 4C 6A 61 76 61 2F 6C 61 6E 67 2F 53 74 72 69 6E 67 3B CONSTANT_Utf8
01 00 0D 43 6F 6E 73 74 61 6E 74 56 61 6C 75 65 CONSTANT_Utf8
08 00 47 CONSTANT_String
01 00 0C 73 74 61 74 69 63 53 74 72 69 6E 67 CONSTANT_Utf8
01 00 06 3C 69 6E 69 74 3E CONSTANT_Utf8
01 00 03 28 29 56 CONSTANT_Utf8
01 00 04 43 6F 64 65 CONSTANT_Utf8
01 00 0F 4C 69 6E 65 4E 75 6D 62 65 72 54 61 62 6C 65 CONSTANT_Utf8
01 00 12 4C 6F 63 61 6C 56 61 72 69 61 62 6C 65 54 61 62 6C 65 CONSTANT_Utf8
01 00 04 74 68 69 73 CONSTANT_Utf8
01 00 11 4C 74 65 73 74 73 2F 44 65 6D 6F 43 6C 61 73 73 3B CONSTANT_Utf8
01 00 03 61 64 64 CONSTANT_Utf8
01 00 03 28 29 49 CONSTANT_Utf8
01 00 05 63 68 65 63 6B CONSTANT_Utf8
01 00 07 28 49 44 4A 43 29 56 CONSTANT_Utf8
01 00 04 69 6E 75 6D CONSTANT_Utf8
01 00 04 64 6E 75 6D CONSTANT_Utf8
01 00 04 6C 6E 75 6D CONSTANT_Utf8
01 00 05 63 68 6E 75 6D CONSTANT_Utf8
01 00 08 3C 63 6C 69 6E 69 74 3E CONSTANT_Utf8
01 00 0A 53 6F 75 72 63 65 46 69 6C 65 CONSTANT_Utf8
01 00 0E 44 65 6D 6F 43 6C 61 73 73 2E 6A 61 76 61 CONSTANT_Utf8
0C 00 21 00 22 CONSTANT_NameAndType
0C 00 14 00 15 CONSTANT_NameAndType
07 00 48 CONSTANT_Class
0C 00 49 00 4A CONSTANT_NameAndType
01 00 17 6A 61 76 61 2F 6C 61 6E 67 2F 53 74 72 69 6E 67 42 75 69 6C 64 65 72 CONSTANT_Utf8
01 00 01 3E CONSTANT_Utf8
0C 00 4B 00 4C CONSTANT_NameAndType
0C 00 4B 00 4D CONSTANT_NameAndType
0C 00 4B 00 4E CONSTANT_NameAndType
0C 00 4B 00 4F CONSTANT_NameAndType
0C 00 4B 00 50 CONSTANT_NameAndType
0C 00 51 00 52 CONSTANT_NameAndType
07 00 53 CONSTANT_Class
0C 00 54 00 55 CONSTANT_NameAndType
01 00 20 49 27 6D 20 61 20 73 74 61 74 69 63 20 73 74 72 69 6E 67 20 69 6E 20 44 65 6D 6F 43 6C 61 73 73 CONSTANT_Utf8
0C 00 20 00 1D CONSTANT_NameAndType
01 00 0F 74 65 73 74 73 2F 44 65 6D 6F 43 6C 61 73 73 CONSTANT_Utf8
01 00 10 6A 61 76 61 2F 6C 61 6E 67 2F 4F 62 6A 65 63 74 CONSTANT_Utf8
01 00 14 6A 61 76 61 2F 69 6F 2F 53 65 72 69 61 6C 69 7A 61 62 6C 65 CONSTANT_Utf8
01 00 13 6A 61 76 61 2F 6C 61 6E 67 2F 43 6C 6F 6E 65 61 62 6C 65 CONSTANT_Utf8
01 00 26 49 27 6D 20 61 20 66 69 6E 61 6C 20 73 74 61 74 69 63 20 73 74 72 69 6E 67 20 69 6E 20 44 65 6D 6F 43 6C 61 73 73 CONSTANT_Utf8
01 00 10 6A 61 76 61 2F 6C 61 6E 67 2F 53 79 73 74 65 6D CONSTANT_Utf8
01 00 03 6F 75 74 CONSTANT_Utf8
01 00 15 4C 6A 61 76 61 2F 69 6F 2F 50 72 69 6E 74 53 74 72 65 61 6D 3B CONSTANT_Utf8
01 00 06 61 70 70 65 6E 64 CONSTANT_Utf8
01 00 2D 28 4C 6A 61 76 61 2F 6C 61 6E 67 2F 53 74 72 69 6E 67 3B 29 4C 6A 61 76 61 2F 6C 61 6E 67 2F 53 74 72 69 6E 67 42 75 69 6C 64 65 72 3B CONSTANT_Utf8
01 00 1C 28 49 29 4C 6A 61 76 61 2F 6C 61 6E 67 2F 53 74 72 69 6E 67 42 75 69 6C 64 65 72 3B CONSTANT_Utf8
01 00 1C 28 44 29 4C 6A 61 76 61 2F 6C 61 6E 67 2F 53 74 72 69 6E 67 42 75 69 6C 64 65 72 3B CONSTANT_Utf8
01 00 1C 28 4A 29 4C 6A 61 76 61 2F 6C 61 6E 67 2F 53 74 72 69 6E 67 42 75 69 6C 64 65 72 3B CONSTANT_Utf8
01 00 1C 28 43 29 4C 6A 61 76 61 2F 6C 61 6E 67 2F 53 74 72 69 6E 67 42 75 69 6C 64 65 72 3B CONSTANT_Utf8
01 00 08 74 6F 53 74 72 69 6E 67 CONSTANT_Utf8
01 00 14 28 29 4C 6A 61 76 61 2F 6C 61 6E 67 2F 53 74 72 69 6E 67 3B CONSTANT_Utf8
01 00 13 6A 61 76 61 2F 69 6F 2F 50 72 69 6E 74 53 74 72 65 61 6D CONSTANT_Utf8
01 00 07 70 72 69 6E 74 6C 6E CONSTANT_Utf8
01 00 15 28 4C 6A 61 76 61 2F 6C 61 6E 67 2F 53 74 72 69 6E 67 3B 29 56 CONSTANT_Utf8
00 21 access_flags
00 10 this_class
00 11 super_class
00 02 interfaces_count
00 12 interfaces[0]
00 13 interfaces[1]
00 06 fields_count
00 00 fields[0].access_flags
00 14 fields[0].name_index
00 15 fields[0].descriptor_index
00 00 fields[0].attributes_count
00 02 fields[1].access_flags
00 16 fields[1].name_index
00 17 fields[1].descriptor_index
00 00 fields[1].attributes_count
00 00 fields[2].access_flags
00 18 fields[2].name_index
00 19 fields[2].descriptor_index
00 00 fields[2].attributes_count
00 04 fields[3].access_flags
00 1A fields[3].name_index
00 1B fields[3].descriptor_index
00 00 fields[3].attributes_count
00 19 fields[4].access_flags
00 1C fields[4].name_index
00 1D fields[4].descriptor_index
00 01 fields[4].attributes_count
00 1E fields[4].attributes[0].attribute_name_index
00 00 00 02 fields[4].attributes[0].attribute_length
00 1F fields[4].attributes[0].info[]
00 09 fields[5].access_flags
00 20 fields[5].name_index
00 1D fields[5].descriptor_index
00 00 fields[5].attributes_count
00 04 methods_count
00 01 methods[0].access_flags
00 21 methods[0].name_index
00 22 methods[0].descriptor_index
00 01 methods[0].attributes_count
00 23 methods[0].attributes[0].attribute_name_index
00 00 00 2F methods[0].attributes[0].attribute_length
00 01 00 01 00 00 00 05 2A B7 00 01 B1 00 00 00 02 00 24 00 00 00 06 00 01 00 00 00 05 00 25 00 00 00 0C 00 01 00 00 00 05 00 26 00 27 00 00 methods[0].attributes[0].info[]
00 01 methods[1].access_flags
00 28 methods[1].name_index
00 29 methods[1].descriptor_index
00 01 methods[1].attributes_count
00 23 methods[1].attributes[0].attribute_name_index
00 00 00 3D methods[1].attributes[0].attribute_length
00 03 00 01 00 00 00 0F 2A 2A B4 00 02 05 60 B5 00 02 2A B4 00 02 AC 00 00 00 02 00 24 00 00 00 0A 00 02 00 00 00 0E 00 0A 00 0F 00 25 00 00 00 0C 00 01 00 00 00 0F 00 26 00 27 00 00 methods[1].attributes[0].info[]
00 01 methods[2].access_flags
00 2A methods[2].name_index
00 2B methods[2].descriptor_index
00 01 methods[2].attributes_count
00 23 methods[2].attributes[0].attribute_name_index
00 00 00 7E methods[2].attributes[0].attribute_length
00 04 00 07 00 00 00 28 B2 00 03 BB 00 04 59 B7 00 05 12 06 B6 00 07 1B B6 00 08 28 B6 00 09 16 04 B6 00 0A 15 06 B6 00 0B B6 00 0C B6 00 0D B1 00 00 00 02 00 24 00 00 00 0A 00 02 00 00 00 13 00 27 00 14 00 25 00 00 00 34 00 05 00 00 00 28 00 26 00 27 00 00 00 00 00 28 00 2C 00 15 00 01 00 00 00 28 00 2D 00 17 00 02 00 00 00 28 00 2E 00 19 00 04 00 00 00 28 00 2F 00 1B 00 06 methods[2].attributes[0].info[]
00 08 methods[3].access_flags
00 30 methods[3].name_index
00 22 methods[3].descriptor_index
00 01 methods[3].attributes_count
00 23 methods[3].attributes[0].attribute_name_index
00 00 00 1E methods[3].attributes[0].attribute_length
00 01 00 00 00 00 00 06 12 0E B3 00 0F B1 00 00 00 01 00 24 00 00 00 06 00 01 00 00 00 0B methods[3].attributes[0].info[]
00 01 attributes_count
00 31 attributes[0].attribute_name_index
00 00 00 02 attributes[0].attribute_length
00 32 attributes[0].info[]
constant_pool
| Constant Type | Value | structure | | ----------------------------- | ----- | ------------------------------------------------------------ | | CONSTANT_Class | 7 | CONSTANT_Class_info { u1 tag; u2 name_index; } | | CONSTANT_Fieldref | 9 | CONSTANT_Fieldref_info { u1 tag; u2 class_index; u2 name_and_type_index; } | | CONSTANT_Methodref | 10 (0a) | CONSTANT_Methodref_info { u1 tag; u2 class_index; u2 name_and_type_index; } | | CONSTANT_InterfaceMethodref | 11(0b) | | | CONSTANT_String | 8 | CONSTANT_String_info { u1 tag; u2 string_index; } | | CONSTANT_Integer | 3 | | | CONSTANT_Float | 4 | | | CONSTANT_Long | 5 | | | CONSTANT_Double | 6 | | | CONSTANT_NameAndType | 12 (0c) | CONSTANT_NameAndType_info { u1 tag; u2 name_index; u2 descriptor_index; } | | CONSTANT_Utf8 | 1 | CONSTANT_Utf8_info { u1 tag; u2 length; u1 bytes[length]; } | | CONSTANT_MethodHandle | 15 (0f) | | | CONSTANT_MethodType | 16 (10) | | | CONSTANT_InvokeDynamic | 18 (12) | |
Class access and property modifiers
| Flag Name | Value | Interpretation |
| ---------------- | ------ | ------------------------------------------------------------ |
| ACC_PUBLIC
| 0x0001 | Declared public
; may be accessed from outside its package. |
| ACC_FINAL
| 0x0010 | Declared final
; no subclasses allowed. |
| ACC_SUPER
| 0x0020 | Treat superclass methods specially when invoked by the invokespecial instruction. |
| ACC_INTERFACE
| 0x0200 | Is an interface, not a class. |
| ACC_ABSTRACT
| 0x0400 | Declared abstract
; must not be instantiated. |
| ACC_SYNTHETIC
| 0x1000 | Declared synthetic; not present in the source code. |
| ACC_ANNOTATION
| 0x2000 | Declared as an annotation type. |
| ACC_ENUM
| 0x4000 | Declared as an enum
type. |
CONSTANT_Class_info {
u1 tag;
u2 name_index;
}
CONSTANT_Integer_info {
u1 tag;
u4 bytes;
}
CONSTANT_Float_info {
u1 tag;
u4 bytes;
}
CONSTANT_Long_info {
u1 tag;
u4 high_bytes;
u4 low_bytes;
}
CONSTANT_Double_info {
u1 tag;
u4 high_bytes;
u4 low_bytes;
}
CONSTANT_NameAndType_info {
u1 tag;
u2 name_index;
u2 descriptor_index;
}
CONSTANT_Utf8_info {
u1 tag;
u2 length;
u1 bytes[length];
}
CONSTANT_MethodHandle_info {
u1 tag;
u1 reference_kind;
u2 reference_index;
}
CONSTANT_MethodType_info {
u1 tag;
u2 descriptor_index;
}
CONSTANT_InvokeDynamic_info {
u1 tag;
u2 bootstrap_method_attr_index;
u2 name_and_type_index;
}
field_info
field_info {
u2 access_flags;
u2 name_index;
u2 descriptor_index;
u2 attributes_count;
attribute_info attributes[attributes_count];
}
field_info#descriptor_index: A field descriptor represents the type of a class, instance, or local variable.
Interpretation of field descriptors
| FieldType term | Type | Interpretation |
| ------------------- | ----------- | ------------------------------------------------------------ |
| B
| byte
| signed byte |
| C
| char
| Unicode character code point in the Basic Multilingual Plane, encoded with UTF-16 |
| D
| double
| double-precision floating-point value |
| F
| float
| single-precision floating-point value |
| I
| int
| integer |
| J
| long
| long integer |
| L
ClassName ;
| reference
| an instance of class ClassName |
| S
| short
| signed short |
| Z
| boolean
| true
or false
|
| [
| reference
| one array dimension |
method_info
method_info {
u2 access_flags;
u2 name_index;
u2 descriptor_index;
u2 attributes_count;
attribute_info attributes[attributes_count];
}
Object m(int i, double d, Thread t) {...}
is
(IDLjava/lang/Thread;)Ljava/lang/Object;
attribute_info
attribute_info {
u2 attribute_name_index;
u4 attribute_length;
u1 info[attribute_length];
}
The predefined attributes are categorized into three groups according to their purpose:
- Five attributes are critical to correct interpretation of the
class
file by the Java Virtual Machine:ConstantValue
Code
StackMapTable
Exceptions
BootstrapMethods
- Twelve attributes are critical to correct interpretation of the
class
file by the class libraries of the Java SE platform:InnerClasses
EnclosingMethod
Synthetic
Signature
RuntimeVisibleAnnotations
RuntimeInvisibleAnnotations
RuntimeVisibleParameterAnnotations
RuntimeInvisibleParameterAnnotations
RuntimeVisibleTypeAnnotations
RuntimeInvisibleTypeAnnotations
AnnotationDefault
MethodParameters
- Six attributes are not critical to correct interpretation of the
class
file by either the Java Virtual Machine or the class libraries of the Java SE platform, but are useful for tools:SourceFile
SourceDebugExtension
LineNumberTable
LocalVariableTable
LocalVariableTypeTable
Deprecated
Limitations of the Java Virtual Machine
The following limitations of the Java Virtual Machine are implicit in the class
file format:
-
The per-class or per-interface constant pool is limited to 65535 entries by the 16-bit
constant_pool_count
field of theClassFile
structure (§4.1). This acts as an internal limit on the total complexity of a single class or interface. -
The number of fields that may be declared by a class or interface is limited to 65535 by the size of the
fields_count
item of theClassFile
structure (§4.1).Note that the value of the
fields_count
item of theClassFile
structure does not include fields that are inherited from superclasses or superinterfaces. -
The number of methods that may be declared by a class or interface is limited to 65535 by the size of the
methods_count
item of theClassFile
structure (§4.1).Note that the value of the
methods_count
item of theClassFile
structure does not include methods that are inherited from superclasses or superinterfaces. -
The number of direct superinterfaces of a class or interface is limited to 65535 by the size of the
interfaces_count
item of theClassFile
structure (§4.1). -
The greatest number of local variables in the local variables array of a frame created upon invocation of a method (§2.6) is limited to 65535 by the size of the
max_locals
item of theCode
attribute (§4.7.3) giving the code of the method, and by the 16-bit local variable indexing of the Java Virtual Machine instruction set.Note that values of type
long
anddouble
are each considered to reserve two local variables and contribute two units toward themax_locals
value, so use of local variables of those types further reduces this limit. -
The size of an operand stack in a frame (§2.6) is limited to 65535 values by the
max_stack
field of theCode
attribute (§4.7.3).Note that values of type
long
anddouble
are each considered to contribute two units toward themax_stack
value, so use of values of these types on the operand stack further reduces this limit. -
The number of method parameters is limited to 255 by the definition of a method descriptor (§4.3.3), where the limit includes one unit for
this
in the case of instance or interface method invocations.Note that a method descriptor is defined in terms of a notion of method parameter length in which a parameter of type
long
ordouble
contributes two units to the length, so parameters of these types further reduce the limit. -
The length of field and method names, field and method descriptors, and other constant string values (including those referenced by
ConstantValue
(§4.7.2) attributes) is limited to 65535 characters by the 16-bit unsignedlength
item of theCONSTANT_Utf8_info
structure (§4.4.7).Note that the limit is on the number of bytes in the encoding and not on the number of encoded characters. UTF-8 encodes some characters using two or three bytes. Thus, strings incorporating multibyte characters are further constrained.
-
The number of dimensions in an array is limited to 255 by the size of the dimensions opcode of the multianewarray instruction and by the constraints imposed on the multianewarray, anewarray, and newarray instructions (§4.9.1, §4.9.2).