-
Bug
-
Resolution: Fixed
-
P3
-
23
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8336135 | 23.0.1 | Chen Liang | P3 | Resolved | Fixed | b03 |
JDK-8335863 | 23 | Chen Liang | P3 | Closed | Fixed | b31 |
There is a mini test case:
jshell> import java.lang.classfile.*;
...> import java.lang.constant.ClassDesc;
...> import static java.lang.classfile.ClassFile.*;
...> import static java.lang.constant.ConstantDescs.MTD_void;
jshell> ClassModel cm = ClassFile.of().parse(
...> ClassFile.of().build(
...> ClassDesc.of("test"),
...> clb-> clb.withMethodBody( "clsEmpty", MTD_void, ACC_PRIVATE | ACC_STATIC,
...> cb->cb.return_()).
...> withMethodBody( "instEmpty", MTD_void, ACC_PRIVATE,
...> cb->cb.return_()
...> )
...> ));
...> for (MethodModel mm : cm.methods()) {
...> System.out.println("%s:\tmax_locals = %d".formatted(mm.methodName().stringValue(), mm.code().get().maxLocals()));
...> }
cm ==> ClassModel[thisClass=test, flags=1]
clsEmpty: max_locals = 1
instEmpty: max_locals = 1
The expected values:
clsEmpty: max_locals = 0
instEmpty: max_locals = 1
as a result of javac for the method:
private static void clsEmpty() {
}
=>
private static void clsEmpty();
descriptor: ()V
flags: (0x000a) ACC_PRIVATE, ACC_STATIC
Code:
stack=0, locals=0, args_size=0
0: return
jshell> import java.lang.classfile.*;
...> import java.lang.constant.ClassDesc;
...> import static java.lang.classfile.ClassFile.*;
...> import static java.lang.constant.ConstantDescs.MTD_void;
jshell> ClassModel cm = ClassFile.of().parse(
...> ClassFile.of().build(
...> ClassDesc.of("test"),
...> clb-> clb.withMethodBody( "clsEmpty", MTD_void, ACC_PRIVATE | ACC_STATIC,
...> cb->cb.return_()).
...> withMethodBody( "instEmpty", MTD_void, ACC_PRIVATE,
...> cb->cb.return_()
...> )
...> ));
...> for (MethodModel mm : cm.methods()) {
...> System.out.println("%s:\tmax_locals = %d".formatted(mm.methodName().stringValue(), mm.code().get().maxLocals()));
...> }
cm ==> ClassModel[thisClass=test, flags=1]
clsEmpty: max_locals = 1
instEmpty: max_locals = 1
The expected values:
clsEmpty: max_locals = 0
instEmpty: max_locals = 1
as a result of javac for the method:
private static void clsEmpty() {
}
=>
private static void clsEmpty();
descriptor: ()V
flags: (0x000a) ACC_PRIVATE, ACC_STATIC
Code:
stack=0, locals=0, args_size=0
0: return
- backported by
-
JDK-8336135 ClassBuilder incorrectly calculates max_locals in some cases
- Resolved
-
JDK-8335863 ClassBuilder incorrectly calculates max_locals in some cases
- Closed
- links to
-
Commit openjdk/jdk/1ef34c18
-
Commit openjdk/jdk/2f60d368
-
Review openjdk/jdk/19993
-
Review(master) openjdk/jdk/19981
(1 links to)