How is "duplicated" Java code optimized by the JVM JIT compiler?

I am responsible for supporting the JSP-based application running on IBM WebSphere 6.1 (IBM J9 JVM). All JSP pages have a static include link, and in this include file there are some static Java methods declared. They are included in all JSP pages to offer "easy access" to these static utility methods. I know this is a very bad way to work, and I am working on it. But, just for the sake of curiosity, and to support my efforts to change this, I wonder how these "duplicated" static methods are optimized by the JVM JIT compiler.

  • Are they optimized separately, even with the same signature?
  • Does the JVM JIT compiler “see” that all these methods are the same and provide a “unified” JIT code?
+7
java jsp compilation websphere jit
source share
3 answers

Each JSP page is compiled into a unique class, so the included code will also be compiled into different classes. JIT will not consolidate various copies of the code into one.

To avoid this, you can put the imported code into a real Java class and import it into the JSP. Then there will be no duplicates, since you are reusing the same class.

+11
source share

@mdma's answer is correct for current JVMs, but needs to be qualified in several ways.

  • JITs in future JVMs may support aggressive optimization to reduce the memory size of their own code.

  • Flipside is that if you do not have thousands of JSP systems, the likelihood that the overhead of several static methods per JSP class will not make much difference to your web server memory.

+3
source share

You can use static import from one class: <% @page import = "static foo. *"%>.

Then you have no more duplication. And besides import, you will not need to touch anything else.

0
source share

All Articles