Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the Java class file format missing constant pool tag 2?

The JVM specification for Java 1.0.2 lists the following constant pool entry types:

+-----------------------------+-------+
|        Constant Type        | Value |
+-----------------------------+-------+
| CONSTANT_Class              |     7 |
| CONSTANT_Fieldref           |     9 |
| CONSTANT_Methodref          |    10 |
| CONSTANT_InterfaceMethodref |    11 |
| CONSTANT_String             |     8 |
| CONSTANT_Integer            |     3 |
| CONSTANT_Float              |     4 |
| CONSTANT_Long               |     5 |
| CONSTANT_Double             |     6 |
| CONSTANT_NameAndType        |    12 |
| CONSTANT_Utf8               |     1 |
+-----------------------------+-------+

Subsequent JVM specs have added more constant pool entry types but haven't ever filled the "2" spot. Why is there a gap there?

like image 675
0xbe5077ed Avatar asked Aug 06 '26 14:08

0xbe5077ed


1 Answers

I did some research and found some clue, for the constant pool tag 2, it seems to be held open under the Constant_Unicode but has never been used, because UTF-8 is already there, and UTF-8 is widely adopted, so if there is constant written in unicode, UTF-8 can handle it, and UTF-8 has a number of advantages than other encoding scheme, so I guess this historical fact might explain why 2 is missing, I guess it can be reused for other purposes if necessary.

Some statements from here: https://bugs.openjdk.java.net/browse/JDK-8161256

For 13, 14, it should have different specific reasons why it was opened but never got used.

like image 139
Jakim Avatar answered Aug 08 '26 09:08

Jakim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!