On Thu, 25 Jul 2024 22:41:08 GMT, Chen Liang <li...@openjdk.org> wrote:

> As discussed in offline meeting, the max stack and locals information are 
> part of the code attribute and not meaningful for buffered code elements. 
> Computation would be costly and these see no real usage during 
> transformations. Thus, the proposed solution is to move these APIs to be 
> CodeAttribute specific, as this is already how all these APIs' users are 
> using.
> 
> Also removed useless `Writable` on buffered models, and fixed 
> `BufferedMethodBuilder::code` implementation.

src/java.base/share/classes/jdk/internal/classfile/impl/BufferedCodeBuilder.java
 line 67:

> 65:         this.maxLocals = Util.maxLocals(methodInfo.methodFlags(), 
> methodInfo.methodTypeSymbol());
> 66:         if (original != null)
> 67:             this.maxLocals = Math.max(this.maxLocals, 
> original.maxLocals());

`original::maxLocals`set the counter for `CodeBuilder::allocateLocal`
By restricting calculation of maxLocals to "origin instanceof CodeAttribute" 
may cause invalid locals allocations for chained code builders. The number 
might not be exposed in the API, however we need to know it internally.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/20338#discussion_r1692669453

Reply via email to