Review of Classfile API JEP

Paul Sandoz paul.sandoz at oracle.com
Tue Jun 28 20:19:01 UTC 2022


I made some minor edits, mostly updating the code examples, replacing the guarded pattern with a when clause on the pattern label.

Paul.


Non-goals

- Not a goal to provide a view of a classfile at runtime by abstracting over reflective APIs and broadening reflection to give access to the byte codes of a method body.
[In response to list discussion on this topic]

- Not a goal to provide code analysis functionality 
[i.e. we are not gonna provide an equivalent to all that ASM supports, since in part the JDK does not use all of ASM].
 
- Not a goal to support the generation of incorrect classifies, for the purposes of testing consumers.
[Although it may be possible in some cases e.g. unverifiable classifies]

?


“
**JVM evolution.**  The JVM, and class file format, are evolving much faster now
than in the early years of Java. While some evolutions are simple
(such as adding new attributes such as `NestMembers`), others are more complex;
Project Valhalla will bring new bytecodes, new field descriptors, and new
verification rules. At some point, it may be prohibitively expensive or complex
to evolve existing libraries to support these new features.
“

Plus it makes it harder for us to prototype new features.

Plus plus writing bytecode tests using ASM is also hard, and we do have quite a few tests that do that.

As a case in point we successfully wrote condy tests using a very early prototype of the API (that is committed in the test area). We can update those tests to use this API, and remove the prototype type.


“
If we want to process a class file and keep everything unchanged except for
removing methods whose names start with "debug", we would get a `ClassModel`,
create a `ClassBuilder`, iterate the elements of the original `ClassModel`, and
pass through all of them to the builder, except the methods we want to drop:
“

Mention about information may be retained in the constant pool for the removed method’s code elements referring to constant pool entries, but the pool can be compacted if need be?






More information about the classfile-api-dev mailing list