Dear all:
     Can you help me analyze the following simplified synchronization
code in tomcat (the servlet function of JspServletWrapper class), I
think it involves an atomicity violation, the detailed explanation is as
follows:

service(Request request, Response response...) 
{ 
            if (development_mode) {// the jsp file 
            // may be updated on the fly 
                synchronized (this) {... 
                    ctxt.compile(); ... 
                } 
            } 
           synchronized(this) { getServlet();} 
           if (mt_mode) {  // sync  to guarantee the 
            //freshness right before servicing 
               synchronized (this) { 
                   theServlet.service(request, response); 
                } 
            } 
}
 
The service function of JspServletWrapper class processes the  incoming
request from a JSP file. In particular, it creates a class
(servletClass) to  represent the JSP file, and instantiates an instance
(theServlet)  of the class, and then uses the instance to serve the
request.


The class (servletClass) is created at runtime for a JSP file, and
should be updated on the fly once the JSP file changes at runtime.  In
the code  The (compile) invocation checks the freshness of
servletClass, updates and stores it if necessary. The  (getServlet)
invocation retrieves the stored  servletClass class and uses it to
create an instance theServlet. The (service) invocation uses the
(theServlet) instance to serve  the request. The expected semantic is
that the (service) invocation should  use  the instance of the most
up-to-date  (servletClass). However, the semantic is not preserved by
the original atomic regions due to atomicity violations: the retrieved
(servletClass) by the (getServlet) invocation may be stale as the
(servletClass) may be updated by the other thread since last (compile)
invocation. Even if there is no buggy interleaving  between the first
two invocations,  there may be an interleaving write to (theServlet)
between the second and third invocation, which makes (theServlet) used
by  the  third invocation stale. Note that, however,  the implementation
of (getServlet) method protects servletClass and theServlet in an atomic
region to avoid the interleaving update of (servletClass} before
instantiating  (theServlet). 


Thank you sincerely for your help.

Regards
Peng



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to