Steven Erat's Blog
 
 
Viewing By Entry
 
 

TalkingTree  Understanding HotSpot in Plain English

 

Not having a degree in Computer Science means that my view of web technology begins at a granular level and necessarily seeps from the top down into the foundations of how software works. For ColdFusion this course traverses the basics of HTTP and CSS, expands into the full range of CFML tags, functions, and architecture, then arcs into databases and SQL, and continues well into the depths of Java and J2EE technology and all that's contained therein. One low level topic that has often piqued my interest has been the question of what exactly is the Sun HotSpot technology for Java Virtual Machines? Sure many ColdFusion pundits share recommendations for JVM tuning parameters, but if you're like me you find it rather superficial and want to know more about this HotSpot black box.

Many resources will point to the Sun whitepaper on Java HotSpot Technology, but I've not been fully satisfied with the high level view and marketing speak there. Recently I've discovered several helpful explanations, and today I've read one of the more comprehensive articles that's written in plain english about what HotSpot and JIT really are, including a great sidebar that could be an article all by itself which explains exactly what a compiler, language interpreter, and bytecode interpreter are and how they work. The article was written back in 1998, preceding the formal release of Sun HotSpot, but the content definitely hit the spot for me. I think you'll find it very helpful in the context of ColdFusion MX applications.

HotSpot: A new breed of virtual machine
Sun's HotSpot technology promises to deliver interpreted bytecodes that run faster than a compiled program! Is such a thing possible? Apparently. HotSpot combines a Java virtual machine (JVM) and a compiler in a unique new way that up until now has existed only in universities. The result is a powerful new technology that threatens to blow the doors off language performance as we know it. Find out about the inner workings of Sun's dynamic compiler, and learn which kinds of applications are -- and are not -- more effective with HotSpot than with the fastest JIT. Plus: Primers compare HotSpot technology to its predecessors -- standard VMs, compilers, and just-in-time compilers. (4,000 words)
By Eric Armstrong

Watch your HotSpot compiler go
Together we have seen that a given piece of Java code will execute at very different speeds during an application's lifetime. Initially, it might execute in interpreted mode; if it executes enough times, it becomes a candidate for compilation to native code.

For a Java program with high uptime, such as an application server, most methods will translate into native code sooner or later. At this state of the JVM, profiling gives a realistic picture of the application's performance. Profiling data taken early in the application's lifetime should either be discarded or not collected at all (unless you are specifically profiling your application's startup behavior). Unfortunately, I suspect that most programmers do not take this into proper consideration. Sun Microsystems' server HotSpot JVM has a larger default method invocation threshold than the client JVM (10,000 instead of 1,500 (see Resources)), and it might take minutes, if not hours, to properly warm up the JVM.
By Vladimir Roubtsov

HotSpot on Wikipedia
Its name derives from the fact that as it runs Java byte-code, it continually analyzes the program's performance for "hot spots" which are frequently or repeatedly executed. These are then targeted for optimization, leading to high performance execution with a minimum of overhead for less performance-critical code. HotSpot is widely acclaimed as providing the best performance in its class of JVM. In theory, though rarely in practice, it is possible for adaptive optimization of a JVM to exceed hand coded C++ or assembly language.

These articles help me better understand how the JVM behaves underneath a ColdFusion MX server and application, although they don't teach the art of JVM tuning through modulation of HotSpot VM Options. That is the next step.

From these I've learned that since ColdFusion MX ships with the -server switch enabled, performance observed during load tests may not be completely accurate until the application has been exercised for hours because the HotSpot threshold for compiling bytecode to native code is quite high in that configuration. During initial testing periods after startup, the JVM is largely operating in interpreted mode only.

This would also help explain why JVM crashes leaving behind HotSpot crash logs happen after hours or days of uptime... The demand on the application has risen to the level where HotSpot begins to do its thing, finally exacerbating any HotSpot flaws or weaknesses. One example that comes to mind is these errors which have been reported infrequently in ColdFusion apps but their impact is that the JVM crashes:

Exception in thread "CompilerThread0" java.lang.OutOfMemoryError: requested 141380 bytes for Chunk::new. Out of swap space?

Exception java.lang.OutOfMemoryError: requested 1024000 bytes for GrET* in D:/BUILD_AREA2/jdk1.4.2/hotspot\src\share\vm\utilities\growableArray.cpp. Out of swap space?

While these errors are found among various Sun bug reports, the only easy solution is an indirect one, to disable the HotSpot compiler entirely with the -Xint optional argument which forces it to only run in interpreted mode. The errors might be caused when HotSpot begins to optimized certain frequently run methods or tight blocks of code. When this happens the compiler will convert the interpreted bytecode to native code and tuck it away in a little piece of memory. The compiler probably needs a little chunk of contiguous memory to store the optimized native code and the OS was unable to provide it. Notice the errors usually indicate that attempts to allocate 1-2MB of memory failed, even though its often noted that neither the JVM heap nor the OS memory usage has maxed out at the time of crash.

A more careful approach to resolve the crashes would be to determine the method which crashed, sometimes identified in the hs_err_pidNNNNN.log files, and add them to a list of methods to exclude from optimization. To do this create a file called .hotspot_compiler (note the ' . ' there) in the cf_root/runtime/bin (or jrun_root/bin) directory and add to it individual lines for methods to exclude. Say the crash log identified coldfusion.runtime.CFPage::Duplicate, put this on one line in the .hotspot_compiler file:

exclude coldfusion/runtime/CFPage Duplicate

This approach may require a great deal of trial and error and could require a lot of time to get right. Disabling the HotSpot compiler with -Xint should be used as a good first pass since it may be possible that the applications run on the ColdFusion server don't normally take much advantage of the HotSpot compiler and so you might find that there is no clearly observable decline in performance. Its often said that forcing HotSpot to run in interpreted mode will always decrease performance, but I know first hand of several who have found it very satisfactory.

As a rule of thumb, the more homogenous the code, the more computationally intensive the application, then the more the application will benefit from HotSpot and is more likely to show a decline in performance when disabled. For a codebase that is built around a lot of I/O like file system operations or network/database calls, then HotSpot will be less utilized and you're more likely to not show a drop if HotSpot were disabled. This should be true for applications that are heterogeneous as well, such as on an ISP, where the code is diverse without much repetition in the codebase.

 


Comments

No that's a nice post! A lot of info. So far I've not run across these errors but I have very low usage applications so far... but my next app is a different story. I'm gonna tuck this one away for a rainy day


Thank you very much for this post, I got a quite a bit of useful information from this.


Steven, you are a f&@#*&g hero! Thanks for this.


 

 

Calendar

 
Sun Mon Tue Wed Thu Fri Sat
  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        

Search This Site

 
This is an exact search only

About This Site

 
I live west of Boston and work for Adobe with ColdFusion and Flex, and specialize in Linux. I'm also interested in travel and science, and I'm studyng photography at CDIA. Curious about my banner image?

More about me

Recent Entries

 
Hollywood East comes to Bosto..

Recent Comments

 
Posted By Jennifer:
First of all thank you for this great article it was very helpful for my situation. I have used the omit="yes" to omit the optional items that se ...

Posted By Mark Lynch:
Thanks for the tips. I found another issue relating to MYSQL autoconfiguration which I've documented here: [link] Thanks, Mark ...

Posted By Quinn:
even when a cert is imported to the keystore, it looks like coldfusion does not support the "Subject Alternative Name" extension of the cert. i've ...

recently played

 
Episode 18 - StackOverflow
by Jeff Atwood and Joel Spolsky
on IT Conversations
IT Conversations, Jeff Atwood and Joel Spolsky

now playing, a plug-in for itunes

Categories

 
RSS Adobe (29)
RSS Bicycling (9)
RSS Blogging (37)
RSS Books (13)
RSS Breeze (12)
RSS CFMX Podcasts (10)
RSS ColdFusion (417)
RSS Computer Technology (49)
RSS Events (25)
RSS Flash (3)
RSS Flex (17)
RSS Gadgets (10)
RSS HiTech Industry (16)
RSS Java (25)
RSS Learning (54)
RSS Linux (70)
RSS Mac OS X (21)
RSS Macromedia (28)
RSS Meetup (34)
RSS New England (60)
RSS Odds & Ends (25)
RSS Outdoors (32)
RSS Personal (26)
RSS Photography (105)
RSS Photoshop (28)
RSS Podcasts (18)
RSS Rants (19)
RSS Restaurants (8)
RSS Science (34)
RSS Spain (16)
RSS Travel (42)
RSS Video (20)
RSS Webcam (3)
RSS Writing (10)

Blogs I Read

 
Scrum Sucks
Ben Forta
Ray Camden
Kinky Solutions
Gary Gilbert
Red Hat Blogs
O'Reilly Digital Media
O'Reilly Radar
John Nack
The Strobist
Scott Kelby
Matt Kloskowski
Joe McNally
Digital Photography School
Engadget
Science Blog

RSS

 


Add to Google
Add to My Yahoo!

Aggregated By

 


Consumed By Feed-Squirrel.com
Aggregated by ColdFusionBlogger.org

Credits and Stuff

 
BlogCFC - Free ColdFusion Powered Blog Software
CJM Group - ColdFusion Website Hosting


 
 
blog | photos | flickr | referers | webcam | stats | about | contact
 
Copyright © 2008 Steven Erat. All rights reserved.
This is a personal weblog. The opinions expressed here represent my own and not those of my employer