Java Reference
In-Depth Information
Not Entrant Code
There are two things that cause code to be made not entrant. One is due to the way classes
and interfaces work, and one is an implementation detail of tiered compilation.
Let's look at the first case. Recall that the stock application has an interface StockPriceHis-
tory . In the sample code, this interface has two implementations: a basic one ( Stock-
PriceHistoryImpl ) and one that adds logging ( StockPriceHistoryLogger ) to each opera-
tion. In the servlet code, the implementation used is based on the log parameter of the URL:
StockPriceHistory sph ;
String log = request . getParameter ( "log" );
iif ( log != null
null && log . equals ( "true" )) {
sph = new
new StockPriceHistoryLogger (...);
else {
sph = new
new StockPriceHistoryImpl (...);
// Then the JSP makes calls to:
sph . getHighPrice ();
sph . getStdDev ();
// and so on
If a bunch of calls are made to http://localhost:8080/StockServlet (that is, without the log
parameter), the compiler will see that the actual type of the sph object is StockPriceHis-
toryImpl . It will then inline code and perform other optimizations based on that knowledge.
Later, say a call is made to http://localhost:8080/StockServlet?log=true . Now the assumption
the compiler made regarding the type of the sph object is false; the previous optimizations
are no longer valid. This generates a deoptimization trap, and the previous optimizations are
discarded. If a lot of additional calls are made with logging enabled, the JVM will quickly
end up compiling that code and making new optimizations.
The compilation log for that scenario will include lines such as the following:
841113 25 % net.sdo.StockPriceHistoryImpl::<init> @ -2 (156 bytes)
made not entrant
841113 937 s net.sdo.StockPriceHistoryImpl::process (248 bytes)
made not entrant
1322722 25 % net.sdo.StockPriceHistoryImpl::<init> @ -2 (156 bytes)
made zombie
Search WWH ::

Custom Search