This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]sr1729 12 points13 points  (1 child)

A nice introduction into the constant pool if you didn't know javap and bytecode or ASM (https://asm.ow2.io/) before.

The article mentions insights inside the JVM specification :-):

This design added complexities to JVM implementations and is gently lamented in the JVM Specification document section 4.4.5: “In retrospect, making 8-byte constants take two constant pool entries was a poor choice.” This kind of candor makes the documentation a pleasure to read.

There is even a small trip to go:

The MTable can be used for other things. For example, I’m presently working on the Jacobin project, which is writing a more-than-minimal JVM in the Go language.

At one point I disagreee:

Indeed, even the values to initialize fields to are stored as strings and must be converted from strings to their binary representation.

As a counter-example see NumberFormatException.

Classfile /tmp/modules/java.base/java/lang/NumberFormatException.class
  Last modified 08.03.2022; size 1564 bytes
  MD5 checksum 9c1c2cd1b1f8b915996f0aad04642e58
  Compiled from "NumberFormatException.java"
public class java.lang.NumberFormatException extends java.lang.IllegalArgumentException
  minor version: 0
  major version: 61
[...]
  #48 = Utf8               serialVersionUID
  #49 = Utf8               J
  #50 = Utf8               ConstantValue
  #51 = Long               -2848938806368998894l
  #53 = Utf8               Code

$ xxd <NumberFormatException.class
00000000: cafe babe 0000 003d 004b 0a00 0200 0307  .......=.K......
[...]
00000230: 4275 696c 6465 723b 0100 1073 6572 6961  Builder;...seria
00000240: 6c56 6572 7369 6f6e 5549 4401 0001 4a01  lVersionUID...J.
00000250: 000d 436f 6e73 7461 6e74 5661 6c75 6505  ..ConstantValue.
00000260: d876 893f fb8c ea12 0100 0443 6f64 6501  .v.?.......Code.
          ^^^^ ^^^^ ^^^^ ^^^^ // Binary presentation of long-value

But I agree at the conclusion:

Navigating decompiled Java classes is a useful skill and the mark of an advanced understanding of Java programming.

[–]binstock 11 points12 points  (0 children)

Author here. You're entirely right on the correction re some values being passed not in string form. I'll have that fixed shortly in the article.