Method code too large in Groovy & Grails?
Asked Answered
A

2

9
2014-06-17 11:22:18,622 [Thread-11] ERROR compiler.GrailsProjectWatcher  - Compilation Error: startup failed:
General error during class generation: Method code too large!

What is the solution? Only 4-5 line code hide and restart then fully run in successfully, the bootStrap file size is 149k. When I comment or delete 4-5 line code, it will be run without no error!

Ani answered 17/6, 2014 at 5:28 Comment(1)
Can you provide further information? Grails version, the code causing the problem...Ishmael
W
13

The Java Virtual Machine has a limitation that methods cannot be larger than 64k (65536 bytes). This post describes this limitation in details.
The best way to overcome this issue is simply splitting your large method into smaller ones, which is generally a good practice.

Also notice that the JVM JIT compiler will not compile methods larger than 8K. You can however change this behavior using the -XX:-DontCompileHugeMethods option.

Wootan answered 17/6, 2014 at 6:15 Comment(1)
any solution how I can get which class is having this issueMargretmargreta
H
2

The problem: Just got in Jenkins pipeline the following exception error: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: General error during class generation: Method code too large! java.lang.RuntimeException: Method code too large!

Explanation : The root cause related to 64kB limit of byte code of a single method. Java Virtual Machine has implicit limitations on class that there are mandatory to be followed and restricted according to performance and the language limitiation - such as: size of an operand stack in frame, length of fields and method names, number of methods may be declared in class etc... you can follow this "check list" on Oracle JVM documentation. You got the method size limitation on this scenario.

Solution: In order to solve this issue, just separate the class methods into shared-lib library or sub internal / external class (such as Utils.Groovy for example) and import that library in your main class. In general a code should be readable , lean and high level. if it's too long export the functionality use object oriented architecture and you would earn readable and maintainable code as well.

Hyacinthhyacintha answered 24/5, 2020 at 11:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.