Xinglong Wang created FLINK-37289:
-------------------------------------
Summary: Resolve JVM bytecode size limit exceeded in <init> method
due to excessive field initializations in SQL job
Key: FLINK-37289
URL: https://issues.apache.org/jira/browse/FLINK-37289
Project: Flink
Issue Type: Bug
Affects Versions: 1.16.1
Reporter: Xinglong Wang
h3. Problem Description
The SQL job encounters issues due to having too many fields in the DML
operations, such as a job which has over 2,000 fields. This results in the code
generation process creating an initialization block that needs to initialize
these fields and some auxiliary intermediate variables, totaling over 20,000
members. Consequently, the bytecode for the {{<init>}} method exceeds the JVM's
single method limit of 64KB, resulting in the following error:
{code:java}
Caused by: org.codehaus.janino.InternalCompilerException: Compiling
"StreamExecCalc$127849": Code of method
"<init>([Ljava/lang/Object;Lorg/apache/flink/streaming/runtime/tasks/StreamTask;Lorg/apache/flink/streaming/api/graph/StreamConfig;Lorg/apache/flink/streaming/api/operators/Output;Lorg/apache/flink/streaming/runtime/tasks/ProcessingTimeService;)V"
of class "StreamExecCalc$127849" grows beyond 64 KB
at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:382)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:237)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.codehaus.janino.SimpleCompiler.compileToClassLoader(SimpleCompiler.java:465)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:216)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:207)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:80)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:75)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.apache.flink.table.runtime.generated.CompileUtils.doCompile(CompileUtils.java:104)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.apache.flink.table.runtime.generated.CompileUtils.lambda$compile$0(CompileUtils.java:92)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.apache.flink.shaded.guava30.com.google.common.cache.LocalCache$LocalManualCache$1.load(LocalCache.java:4864)
~[flink-dist-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.apache.flink.shaded.guava30.com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3529)
~[flink-dist-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.apache.flink.shaded.guava30.com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2278)
~[flink-dist-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.apache.flink.shaded.guava30.com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2155)
~[flink-dist-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.apache.flink.shaded.guava30.com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2045)
~[flink-dist-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.apache.flink.shaded.guava30.com.google.common.cache.LocalCache.get(LocalCache.java:3962)
~[flink-dist-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.apache.flink.shaded.guava30.com.google.common.cache.LocalCache$LocalManualCache.get(LocalCache.java:4859)
~[flink-dist-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.apache.flink.table.runtime.generated.CompileUtils.compile(CompileUtils.java:92)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
... 32 more
Caused by: org.codehaus.janino.InternalCompilerException: Code of method
"<init>([Ljava/lang/Object;Lorg/apache/flink/streaming/runtime/tasks/StreamTask;Lorg/apache/flink/streaming/api/graph/StreamConfig;Lorg/apache/flink/streaming/api/operators/Output;Lorg/apache/flink/streaming/runtime/tasks/ProcessingTimeService;)V"
of class "StreamExecCalc$127849" grows beyond 64 KB
at org.codehaus.janino.CodeContext.makeSpace(CodeContext.java:1048)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.CodeContext.write(CodeContext.java:925)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.writeOpcode(UnitCompiler.java:12291)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.getfield(UnitCompiler.java:11974)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:4470)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.access$7700(UnitCompiler.java:215)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.codehaus.janino.UnitCompiler$16$1.visitFieldAccess(UnitCompiler.java:4405)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.codehaus.janino.UnitCompiler$16$1.visitFieldAccess(UnitCompiler.java:4400)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.Java$FieldAccess.accept(Java.java:4310)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler$16.visitLvalue(UnitCompiler.java:4400)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler$16.visitLvalue(UnitCompiler.java:4396)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.Java$Lvalue.accept(Java.java:4148)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:4396)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:4461)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.access$7500(UnitCompiler.java:215)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.codehaus.janino.UnitCompiler$16$1.visitAmbiguousName(UnitCompiler.java:4403)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.codehaus.janino.UnitCompiler$16$1.visitAmbiguousName(UnitCompiler.java:4400)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.Java$AmbiguousName.accept(Java.java:4224)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler$16.visitLvalue(UnitCompiler.java:4400)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler$16.visitLvalue(UnitCompiler.java:4396)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.Java$Lvalue.accept(Java.java:4148)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:4396)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:5662)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.compileContext2(UnitCompiler.java:4351)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.access$6800(UnitCompiler.java:215)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.codehaus.janino.UnitCompiler$15$1.visitArrayAccessExpression(UnitCompiler.java:4272)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.codehaus.janino.UnitCompiler$15$1.visitArrayAccessExpression(UnitCompiler.java:4268)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.Java$ArrayAccessExpression.accept(Java.java:4605)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler$15.visitLvalue(UnitCompiler.java:4268)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler$15.visitLvalue(UnitCompiler.java:4264)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.Java$Lvalue.accept(Java.java:4148)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.compileContext(UnitCompiler.java:4264)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:3789)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.access$6100(UnitCompiler.java:215)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.codehaus.janino.UnitCompiler$13.visitAssignment(UnitCompiler.java:3754)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.codehaus.janino.UnitCompiler$13.visitAssignment(UnitCompiler.java:3734)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.Java$Assignment.accept(Java.java:4477)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:3734)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:2360)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.access$1800(UnitCompiler.java:215)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.codehaus.janino.UnitCompiler$6.visitExpressionStatement(UnitCompiler.java:1494)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.codehaus.janino.UnitCompiler$6.visitExpressionStatement(UnitCompiler.java:1487)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.Java$ExpressionStatement.accept(Java.java:2874)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1487)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.codehaus.janino.UnitCompiler.compileStatements(UnitCompiler.java:1567)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:1553)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.access$1700(UnitCompiler.java:215)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler$6.visitBlock(UnitCompiler.java:1493)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler$6.visitBlock(UnitCompiler.java:1487)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.Java$Block.accept(Java.java:2779)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1487)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:1546)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.access$1400(UnitCompiler.java:215)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.codehaus.janino.UnitCompiler$6.visitInitializer(UnitCompiler.java:1490)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.codehaus.janino.UnitCompiler$6.visitInitializer(UnitCompiler.java:1487)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.Java$Initializer.accept(Java.java:2048)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1487)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.codehaus.janino.UnitCompiler.initializeInstanceVariablesAndInvokeInstanceInitializers(UnitCompiler.java:7580)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:3378)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:834)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:432)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.access$400(UnitCompiler.java:215)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:411)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:406)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:1414)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:406)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:378)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:237)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.codehaus.janino.SimpleCompiler.compileToClassLoader(SimpleCompiler.java:465)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:216)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:207)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:80)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:75)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.apache.flink.table.runtime.generated.CompileUtils.doCompile(CompileUtils.java:104)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.apache.flink.table.runtime.generated.CompileUtils.lambda$compile$0(CompileUtils.java:92)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.apache.flink.shaded.guava30.com.google.common.cache.LocalCache$LocalManualCache$1.load(LocalCache.java:4864)
~[flink-dist-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.apache.flink.shaded.guava30.com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3529)
~[flink-dist-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.apache.flink.shaded.guava30.com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2278)
~[flink-dist-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.apache.flink.shaded.guava30.com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2155)
~[flink-dist-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.apache.flink.shaded.guava30.com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2045)
~[flink-dist-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.apache.flink.shaded.guava30.com.google.common.cache.LocalCache.get(LocalCache.java:3962)
~[flink-dist-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.apache.flink.shaded.guava30.com.google.common.cache.LocalCache$LocalManualCache.get(LocalCache.java:4859)
~[flink-dist-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
at
org.apache.flink.table.runtime.generated.CompileUtils.compile(CompileUtils.java:92)
~[flink-table-runtime-1.16.1-mt001-SNAPSHOT.jar:1.16.1-mt001-SNAPSHOT]
... 32 more {code}
{{}}
h3. Explanation of the {{<init>}} Method
* {*}{{<init>}} Method{*}: In Java bytecode, each constructor is represented
as a special method named {{{}<init>{}}}.
* {*}Order of Instance Initialization{*}: The Java compiler weaves the
initialization logic into the {{<init>}} method in the following order:
** a. Calls the superclass constructor (calls the default no-argument
constructor if none is explicitly called).
** b. Initializes instance variables.
** c. Executes instance initialization blocks.
** d. Executes the actual code of the constructor.
* {*}Bytecode Generation{*}: The compiler inserts all this initialization
logic (instance variable initialization and instance initialization blocks)
into the beginning of the {{<init>}} method, after the call to the superclass
constructor but before the constructor's own code.
* {*}Impact on {{<init>}} Method Size{*}: Therefore, even if the constructor
itself has little code, having a large number of instance variable
initializations or complex instance initialization blocks will increase the
bytecode size of the {{<init>}} method.
h3. Fix
The initial logic in the initialization block, when translated into bytecode,
is executed via {{putfield}} instructions. The solution is to segment the
numerous {{putfield}} instructions into smaller blocks. For example, group
every 1,000 initialization statements into a private method, then call these
private methods within the initialization block. This transforms the
initialization block into a series of {{invokespecial}} instructions, which are
fewer in number.
For a detailed explanation, refer to the demonstration at
[https://godbolt.org/z/q9d1ncTrE].
--
This message was sent by Atlassian Jira
(v8.20.10#820010)