"For further proof you can add the -XX:+PrintCompilation HotSpot option (see Resources) to your JVM command line and watch the HotSpot engine tell you when it compiles various methods:"
"HotSpot is a simple, object-oriented drawing program. A drawing program allows a user to create a picture from a palette of simple geometric shapes. Once a shape has been placed on the drawing surface, the user can reselect it and adjust its size, shape, and position. In this respect, a drawing program differs from a paint program, in which a shape, once placed on the drawing surface, becomes nothing more than a colored collection of pixels."
"Most applications spend the vast majority of their time executing a small minority of their code. The Java HotSpot performance engine analyzes an application as it runs, identifying the areas that are most critical to performance?where the greatest time is being spent executing bytecode. Rather than compiling an entire program when it first starts, or compiling each method as it is called (as does the JIT compiler), the performance engine initially runs the program using an interpreter, and then analyzes it as it runs, looking for performance "hot spots." It then compiles and optimizes only those performance-critical areas of code. This monitoring process continues dynamically throughout the life of the program, with the performance engine adapting on-the-fly to the ongoing performance needs of the application."
"The inner loop could be anything. "sum += index" is just one operation that someone might try to measure. The method begins interpreting, but on every backward branch (corresponding to the closing brace of the loop), a counter associated with the method is incremented. When it goes past a threshold (currently 10,000 in Java HotSpot version 1.0) then the method is compiled."
"References: Application modeling and Performance tuning from Garbage Collection Perspective The Java HotSpot Virtual Machine Java HotSpot VM Options Tuning Garbage Collection with the 1.3.1 Java Virtual Machine Java and Solaris Threading Generational Mostly-concurrent Garbage Collector New Parallel Collector The SIPCenter.com Ubiquity's Application Services Broker (A Telco SIP server) The JAIN API Sun ONE Sun ONE Application Server 7 JSR 174 JSR 163 Sun Docs The Java HotSpot Virtual Machine, v1.4.1"
"In the past, programmers often inserted the "final" keyword for exactly this reason. Or to better facilitate inlining and increase execution speed, they would combine many smaller methods into one larger method. But in many ways, such techniques defeat the entire facility of modularization and reusability built into the programming language."
"The Hotspot VM is a collection of techniques, the most significant of which is called "adaptive optimization." In fact, this technique gives Hotspot its name."
"Last month, we looked at the classic garbage collection techniques of reference counting, copying, mark-sweep, and mark-compact. Each of these approaches has advantages and disadvantages in certain situations. For example, copying does well when a large proportion of objects are garbage, but does poorly with many long-lived objects (copying them repeatedly). Conversely, mark-compact does quite well with long-lived objects (copying them only once), but not so well with many short-lived objects. The technique used by the 1.2 and later JVMs, called generational garbage collection, combines these two techniques to get the best of both worlds, and as a bonus provides very low object allocation overhead."
"The first step in the process was to determine the cause of the sudden application slowdowns. First on our list of suspects was garbage collection. As we demonstrated in last month's column, the easiest way to determine if garbage collection and memory utilization issues are having a negative effect on your applications performance is to set the -verbose:gc JVM option and examine the log output. So we restarted the application with verbose garbage collection logging turned in, and patiently waited for the application's performance to fall off. Our patience paid off in the form of a very revealing gc log file."