Bug 60126 - The code of method invoke0(JspWriter) is exceeding the 65535 bytes limit
Summary: The code of method invoke0(JspWriter) is exceeding the 65535 bytes limit
Status: RESOLVED INVALID
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Jasper (show other bugs)
Version: 8.0.37
Hardware: All All
: P2 major with 5 votes (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-13 13:51 UTC by Björn Mahler
Modified: 2018-01-09 09:40 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Björn Mahler 2016-09-13 13:51:01 UTC
We currently get an error with some of our JSPs with the following message:
An error occurred at line: [20.607] in the generated java file: [/home/xxx/.IntelliJIdea2016.1/system/tomcat/xxx/work/Catalina/localhost/xxx/org/apache/jsp/pages/gwf/form_005flayout_jsp.java]
The code of method invoke0(JspWriter) is exceeding the 65535 bytes limit


The jsp form_layout.jsp uses a lot of dynamic including of other jsps but other tomcat versions before did the job (including 8.0.36). The last time I saw this error message was with tomcat 6 I think (weird regression? ;-)). 

TIA
Björn
Comment 1 Mark Thomas 2016-09-13 14:15:17 UTC
I'm pretty sure this is invalid. Feel free to re-open if my explanation below proves not to be correct.

The changelog for 8.0.37 mentions a number of changes in Jasper around error handling that will have increased the volume of the auto-generated code Jasper creates. If the JSPs were close to the limit in 8.0.36 it is possible this extra error handling code will have tipped them over in 8.0.37.

The way to check this is to look at the generated .java code for 8.0.36 and compare it to the .java code generated for 8.0.37. If you see something other than error handling (e.g. additional try/finally blocks) then please re-open and attach the JSP source, the .java for 8.0.36 and the .java for 8.0.37
Comment 2 Björn Mahler 2016-09-13 15:12:24 UTC
Okay - so how do we know that we are close to the limit - what kind of limits in our JSP do we have to consider and how can we avoid that?

But I'll check what you suggested... thanks for the quick answer.
Comment 3 Mark Thomas 2016-09-13 15:33:25 UTC
What actaully matters is the size of the .class file. That has to conform to the JVM specification. There are various limits there although the method size one is the one folks tend to hit first.

It should be possible to analyse you generated clss files to see how big they are. There is probably a utility for that somewhere. If not, it should be trivial to write with BCEL or similar.
Comment 4 Christopher Schultz 2016-09-14 22:19:42 UTC
(In reply to Mark Thomas from comment #3)
> It should be possible to analyse you generated clss files to see how big
> they are.

In this case, the compiler is failing, so no .class file is generated. Only the auto-generated Java source can be reviewed.

The only way to prevent this from happening is to somewhat arbitrarily divide the generated code for a JSP into sections that are unlikely to result in a method-size overflow.

That path is fraught with difficulty. An automated approach may not be practical.

Björn, I recommend that you look into using Tomcat's precompiler to either actually precompile your JSPs, or just as a sanity-check during your development process to determine if you are going to have any issues with JSP sizes.
Comment 5 Ralf Hauser 2017-01-16 10:20:27 UTC
see also bug 60578#c3
Comment 6 Ralf Hauser 2017-01-17 15:46:43 UTC
we got that problem when upgrading from tc8.0.14 to 8.5.9 for several jsp pages that before didn't have it (and not change to the jsp).

1) the jsp generation got less efficient!

before 8.0.14: wc outboxmessage_005fen_jsp.java
  20511   97184 1708876 outboxmessage_005fen_jsp.java

now 8.5.9: wc outboxmessage_005fen_jsp.java
  20874   98766 1651642 outboxmessage_005fen_jsp.java

(although interestingly bytes do not behave the same as words)

2) rights and date have changed, before it was the correct date, now we see sometimes 

  $ sudo ls -lart 
  -rw-r----- 1 root root 1651642 Jan  1  1970 /var/cache/tomcat8...
Comment 7 Christopher Schultz 2017-01-17 18:16:37 UTC
(In reply to Ralf Hauser from comment #5)
> see also bug 60578#c3

I'm not sure these bugs are related in any way.

I'm surprised to see a file owned by root. That should not be possible unless your process permissions are for admin (which is a terrible idea). I don't believe Tomcat attempts to adjust permissions or file timestamps.

I you are having the "bytes exceeded" problem, your only recourse is to re-work the JSP to be shorter or more modular.
Comment 8 Ralf Hauser 2017-01-18 08:33:45 UTC
Finally got it to compile again.

Just for the record (in my case the exact error message was "The code of method _jspService(HttpServletRequest, HttpServletResponse) is exceeding the 65535 bytes limit"):

1) tc8.0.14 no error: wc jspService.txt 
 10284  44600 856690 jspService8.0.14.txt

2a) tc8.5.9. minor optimization, WITH error: wc jspService8.5.9.minorOpt.txt 
 10026  44545 826378 jspService8.5.9.minorOpt.txt

2b) tc8.5.9. optimized no more error: wc jspService8.5.9.optimized.txt 
  7731  32414 588382 jspService.txt

I still don't get it why 2a) caused the "exceeding the 65535 bytes limit" while 1) and 2b) don't.

---------
How jspService*.txt was created:
i) open the _jsp.java in an IDE like eclipse
ii) go to the method
iii) hilite and copy anything between its outer "{
... }" into clipboard
iv) past the clipboard into an editor with the empty jspService*.txt
Comment 9 Christopher Schultz 2017-01-18 22:23:59 UTC
Please take this conversation to the users list. If you do so, please provide examples of the .java files that will not compile successfully.
Comment 10 Ralf Hauser 2017-01-25 13:43:10 UTC
(In reply to Christopher Schultz from comment #9)
> Please take this conversation to the users list. If you do so, please
> provide examples of the .java files that will not compile successfully.
cannot upload it to a public repository but the .java should be in your mail as of
19.01.2017 08:10 GMT
Comment 11 Günter Paul 2018-01-09 09:40:29 UTC
Have the same problem, tomcat 8.5 and tomcat 9 too.
We have hundred of older jsp-files with struts 1.1 and no easy solution for the problem. 
We are using tomcat 8.0.3 without problems. Can't find the difference.