Speed up JSP compilations in GlassFish with JSR 199 Java Compiler Interface

A frequent complaint about web application development is the speed (or lack of) of compiling JSP pages, and a major portion of JSP compilation time is spent in compiling the generated Java files.

In GlassFish, Java compilations are handled with ant, and for reasons I won't get into now, with fork option as the default. This really slow down the compilation.

The reason for using ant to invoke javac is that there is no standard API for invoking it. Well, not until now, that is. JSR 199, Java Compiler API, is now part of Mustang, and starting with b11, GlassFish now supports it for JSP compilations!

To turn on JSR 199 support, take the following steps.

  1. Use Java SE 6 (code name Mustang) in GlassFish. To do that, the file asenv.conf in ${GF_HOME}/config/asenv.conf needs to be edited to set AS_JAVA to point to Mustang, before starting the appserver.
  2. Download jasper-jsr199.jar and drop it into ${GF_HOME}/lib. This jar provides the code in jasper that invokes Mustang for java compilations.

The performance gain for using JSR1 199 API is amazing! Preliminary measurement shows an order of magnitude improvement in raw Javac compilation speed, and a 3.5X improvement in overall execution when running JSP TCK tests!

With JSR 199 support in Jasper, the generated Java files and the generated class files are both kept in memory, avoiding unnecessary disk I/Os. The fact that the class files are actual byte arrays makes bytecodes processing (such as SMAP generation and bytecode preprocessing) and class loading much more efficient, as they can all be done in memory.

One other performance work that I haven't done yet is to cache the system jars used in java compilations. Doing this would effectively create a compiler server for the web container. Since this may also have scalability and usability issues, I'll need to experiment to see if this effort is worthwile.

Comments:

Kin-Man, how does Jasper-199 assemble its compilation classpath? Does it need to know the structure of the container's class repositories? Does Glassfish expose them in any way? Or did you find a way to work around http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6297388 ? I played with the compiler support recently and the problem still seems to be there. Thanks Matthias

Posted by Matthias Ernst on July 31, 2006 at 04:33 PM PDT #

Matthias, Jasper assembles its compilation classpath from its classLoader, which is assumed to be an URLClassLoader. So we luck out here. The fact that JSR 199 cannot take a classloader is a problem still, because I kept the bytecodes in memory, and I don't have a easy way to include them when compiling another file, without writing the class files to disk. Fortunately I found a way by overriding the list method in JavaFileManager, but it is still awkward.

Posted by Kin-man Chung on August 01, 2006 at 09:34 AM PDT #

Post a Comment:
Comments are closed for this entry.
About

kchung

Search

Top Tags
Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
Bookmarks