I'm in charge of maintaining a JSP based application, running on IBM WebSphere 6.1 (IBM J9 JVM). All JSP pages have a static include reference and in this include file there is some static Java methods declared. They are included in all JSP pages to offer an "easy access" to those utility static methods. I know that this is a very bad way to work, and I'm working to change this. But, just for curiosity, and to support my effort in changing this, I'm wondering how these "duplicated" static methods are optimized by the JVM JIT compiler.
Each JSP page is compiled to a unique class, and so the included code will also be compiled into distinct classes. The JIT will not consolidate the various copies of the code into one.
To avoid this, you can put the imported code into a real Java class, and import that in the JSP. Then there will be no duplicates, since you are reusing the same class.
@mdma's answer is correct for current JVMs, but needs to be qualified in a couple of respects.
The JITs in future JVMs could possibly support aggressive optimizations for reducing the memory footprint of the native code.
The flipside is that unless you have thousands of distinct JSPs, the chances are that the overheads of a few static methods per JSP class won't make a lot of difference to your webapp's memory footprint.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With