7

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.

  • They are optimized separately even having the exact same signature?
  • Does the JVM JIT compiler "sees" that these methods are all identical an provides an "unified" JIT'ed code?
3
  • Could you refresh my mind and tell me what's the syntax for static include? Commented Jun 17, 2010 at 23:12
  • 1
    It is a include using a JSP directive (<%@ page include="includeFile.inc" %>). The content of "includeFile.inc" is statically included in the JSP code at compile time. A dynamic include can be done using a JSP tag (<jsp:include>) where you can reference a URL and the content is included at runtime. Using the tag you can also choose to do a static include. Commented Jun 17, 2010 at 23:26
  • +1 for support. I've been exactly where you are now. The only difference, in the project that I've inherited was that these static methods were cut-and-paste into every JSP page. Commented Jun 17, 2010 at 23:33

3 Answers 3

11

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.

Sign up to request clarification or add additional context in comments.

Comments

3

@mdma's answer is correct for current JVMs, but needs to be qualified in a couple of respects.

  1. The JITs in future JVMs could possibly support aggressive optimizations for reducing the memory footprint of the native code.

  2. 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.

Comments

0

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

Then you no longer have all that duplication. And other than the import you would not need to touch aything else.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.