add logging for different JspServletWrapper instances
diff --git a/src/main/java/org/apache/sling/scripting/jsp/jasper/JspCompilationContext.java b/src/main/java/org/apache/sling/scripting/jsp/jasper/JspCompilationContext.java
index 90f55ea..d6dc90b 100644
--- a/src/main/java/org/apache/sling/scripting/jsp/jasper/JspCompilationContext.java
+++ b/src/main/java/org/apache/sling/scripting/jsp/jasper/JspCompilationContext.java
@@ -30,12 +30,15 @@
 import javax.servlet.ServletContext;
 import javax.servlet.jsp.tagext.TagInfo;
 
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
 import org.apache.sling.commons.compiler.source.JavaEscapeHelper;
 import org.apache.sling.scripting.jsp.jasper.compiler.Compiler;
 import org.apache.sling.scripting.jsp.jasper.compiler.JDTCompiler;
 import org.apache.sling.scripting.jsp.jasper.compiler.JspRuntimeContext;
 import org.apache.sling.scripting.jsp.jasper.compiler.Localizer;
 import org.apache.sling.scripting.jsp.jasper.compiler.ServletWriter;
+import org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper;
 
 /**
  * A place holder for various things that are used through out the JSP
@@ -53,11 +56,11 @@
  */
 public class JspCompilationContext {
 
-    private final org.apache.juli.logging.Log LOG =
-            org.apache.juli.logging.LogFactory.getLog(Compiler.class);
+    private final Log LOG = LogFactory.getLog(Compiler.class);
 
     private final Map<String, URL> tagFileJarUrls;
 
+    private final JspServletWrapper jspServletWrapper;
     private volatile String className;
     private final String jspUri;
     private volatile boolean isErrPage;
@@ -82,23 +85,23 @@
     private volatile TagInfo tagInfo;
     private volatile URL tagFileJarUrl;
 
-    public JspCompilationContext(String jspUri,
+    public JspCompilationContext(JspServletWrapper jspServletWrapper,
                                  boolean isErrPage,
                                  Options options,
                                  ServletContext context,
                                  JspRuntimeContext rctxt) {
-        this(jspUri, isErrPage, options, context, rctxt, Constants.JSP_PACKAGE_NAME);
+        this(jspServletWrapper, isErrPage, options, context, rctxt, Constants.JSP_PACKAGE_NAME);
     }
 
     // jspURI _must_ be relative to the context
-    public JspCompilationContext(String jspUri,
-                                 boolean isErrPage,
-                                 Options options,
-                                 ServletContext context,
-                                 JspRuntimeContext rctxt,
-                                 String basePckName) {
-
-        this.jspUri = canonicalURI(jspUri);
+    public JspCompilationContext(JspServletWrapper jspServletWrapper,
+                                  boolean isErrPage,
+                                  Options options,
+                                  ServletContext context,
+                                  JspRuntimeContext rctxt,
+                                  String basePckName) {
+        this.jspServletWrapper = jspServletWrapper;
+        this.jspUri = canonicalURI(jspServletWrapper.getJspUri());
         this.isErrPage = isErrPage;
         this.options = options;
         this.context = context;
@@ -121,13 +124,13 @@
         this.basePackageName = basePckName;
     }
 
-    public JspCompilationContext(String tagfile,
+    public JspCompilationContext(JspServletWrapper jspServletWrapper,
                                  TagInfo tagInfo,
                                  Options options,
                                  ServletContext context,
                                  JspRuntimeContext rctxt,
                                  URL tagFileJarUrl) {
-        this(tagfile, false, options, context, rctxt);
+        this(jspServletWrapper, false, options, context, rctxt);
         this.isTagFile = true;
         this.tagInfo = tagInfo;
         this.tagFileJarUrl = tagFileJarUrl;
@@ -246,7 +249,7 @@
      * @return a null if the resource cannot be found or represented
      *         as an InputStream.
      */
-    public java.io.InputStream getResourceAsStream(String res) {
+    public InputStream getResourceAsStream(String res) {
         return context.getResourceAsStream(canonicalURI(res));
     }
 
@@ -649,5 +652,8 @@
        return result.toString();
     }
 
+    public JspServletWrapper getJspServletWrapper() {
+        return jspServletWrapper;
+    }
 }
 
diff --git a/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/SmapUtil.java b/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/SmapUtil.java
index 4b010eb..9fe0b0c 100644
--- a/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/SmapUtil.java
+++ b/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/SmapUtil.java
@@ -33,6 +33,7 @@
 
 import org.apache.sling.scripting.jsp.jasper.JasperException;
 import org.apache.sling.scripting.jsp.jasper.JspCompilationContext;
+import org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper;
 
 /**
  * Contains static utilities for generating SMAP data based on the
@@ -245,6 +246,20 @@
         private static final ConcurrentHashMap<String, Exception> DIAGNOSTICS = new ConcurrentHashMap<>();
 
         static void install(JspCompilationContext ctxt, String classFile, byte[] smap) throws IOException {
+            JspServletWrapper activeWrapper = ctxt.getJspServletWrapper();
+            JspServletWrapper currentWrapper = ctxt.getRuntimeContext().getWrapper(ctxt.getJspFile());
+            if (activeWrapper != currentWrapper) {
+                String originalHex = Integer.toHexString(activeWrapper.hashCode());
+                String currentHex = Integer.toHexString(currentWrapper.hashCode());
+                log.warn("SmapUtil#install() called for " + activeWrapper.getJspUri() +
+                        " with JspServletWrapper@" + originalHex +
+                        ", which is different from the current JspServletWrapper@" + currentHex + ".");
+            } else {
+                String originalHex = Integer.toHexString(activeWrapper.hashCode());
+                log.info("SmapUtil#install() called for " + activeWrapper.getJspUri() +
+                        " with the current JspServletWrapper@" + originalHex);
+            }
+
             Exception ourTrace = new Exception("diagnostic stack trace from thread " + Thread.currentThread().getName());
             Exception otherTrace = DIAGNOSTICS.put(classFile, ourTrace);
             try {
diff --git a/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java b/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java
index 24db180..509e21d 100644
--- a/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java
+++ b/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java
@@ -106,7 +106,7 @@
         this.config = config;
         this.options = options;
         this.jspUri = jspUri;
-        this.ctxt = new JspCompilationContext(jspUri, isErrorPage, options,
+        this.ctxt = new JspCompilationContext(this, isErrorPage, options,
 					 config.getServletContext(),
 					 rctxt);
         if ( log.isDebugEnabled() ) {
@@ -127,7 +127,7 @@
         this.config = config;
         this.options = options;
         this.jspUri = jspUri;
-        this.ctxt = new JspCompilationContext(jspUri, isErrorPage, options,
+        this.ctxt = new JspCompilationContext(this, isErrorPage, options,
                              config.getServletContext(),
                              rctxt, null);
         this.theServlet = servlet;
@@ -150,7 +150,7 @@
         this.config = null;	// not used
         this.options = options;
         this.jspUri = tagFilePath;
-        this.ctxt = new JspCompilationContext(jspUri, tagInfo, options,
+        this.ctxt = new JspCompilationContext(this, tagInfo, options,
 					 servletContext, rctxt, tagFileJarUrl);
         if ( log.isDebugEnabled() ) {
             log.debug("Creating new wrapper for tagfile " + jspUri);
@@ -418,7 +418,7 @@
                     continue;
                 }
                 final long includeLastModified = ctxt.getRuntimeContext().getIOProvider().lastModified(include);
-                log.info("Last modified date for include " + include + " is " + Instant.ofEpochMilli(includeLastModified));
+                log.info("Last modified date for include " + include + " (of " + targetFile + ") is " + Instant.ofEpochMilli(includeLastModified));
 
                 if (includeLastModified > targetLastModified) {
                     if (log.isDebugEnabled()) {
@@ -464,7 +464,7 @@
      * @throws SlingPageException JSP page exception handler exceptions
      * @throws SlingException for any non runtime exception
      * @throws RuntimeException for runtime exceptions
-     * 
+     *
      */
     public void service(final SlingBindings bindings) {
         try {
@@ -611,7 +611,7 @@
             return (RuntimeException) e;
         }
         // wrap in ScriptEvaluationException
-        return new ScriptEvaluationException(this.ctxt.getJspFile(), 
+        return new ScriptEvaluationException(this.ctxt.getJspFile(),
             e.getMessage() == null ? e.toString() : e.getMessage(), e);
     }
 
@@ -652,7 +652,7 @@
                         null,
                         javaLineNumber,
                         ctxt);
-    
+
                 // If the line number is less than one we couldn't find out
                 // where in the JSP things went wrong
                 final int jspLineNumber = detail.getJspBeginLineNumber();
@@ -662,13 +662,13 @@
                     if (options.getDisplaySourceFragment() && detail.getJspExtract() != null ) {
                         message = Localizer.getMessage("jsp.exception", detail.getJspFileName(), String.valueOf(jspLineNumber))
                                 .concat(" : ").concat(origMsg).concat("\n\n").concat(detail.getJspExtract()).concat("\n");
-        
+
                     } else {
                         message = Localizer.getMessage("jsp.exception", detail.getJspFileName(), String.valueOf(jspLineNumber))
                                 .concat(" : ").concat(origMsg);
-                    }    
-                    result = new SlingException(message, ex);    
-                }    
+                    }
+                    result = new SlingException(message, ex);
+                }
             }
         } catch (final Exception je) {
             // If anything goes wrong, just revert to the original behaviour