From 455010067508fe0c38f6620daec32dfd0cebebed Mon Sep 17 00:00:00 2001 From: "Eric J. Bowersox" Date: Sun, 2 May 2004 23:42:18 +0000 Subject: [PATCH] added some code for debugging memory issue --- etc/logging-config.xml | 17 ++++++++--- .../venice/ui/servlet/BaseServlet.java | 29 ++++++++++++++++--- .../venice/ui/servlet/RequestImpl.java | 13 +++++++++ 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/etc/logging-config.xml b/etc/logging-config.xml index b70cc21..c050441 100644 --- a/etc/logging-config.xml +++ b/etc/logging-config.xml @@ -30,6 +30,14 @@ + + + + + + + + @@ -38,6 +46,11 @@ + + + + + @@ -45,7 +58,3 @@ - - - - diff --git a/src/com/silverwrist/venice/ui/servlet/BaseServlet.java b/src/com/silverwrist/venice/ui/servlet/BaseServlet.java index 606a082..8eaf16b 100644 --- a/src/com/silverwrist/venice/ui/servlet/BaseServlet.java +++ b/src/com/silverwrist/venice/ui/servlet/BaseServlet.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-04 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -79,7 +79,8 @@ public abstract class BaseServlet extends HttpServlet private static final String ENGINE_INIT_PARAM = "venice.config"; private static final String UICONFIG_INIT_PARAM = "ui.config"; - private static Category logger = Category.getInstance(BaseServlet.class); + private static Logger logger = Logger.getLogger(BaseServlet.class); + private static Logger memlog = Logger.getLogger("MEMLOG"); private static VeniceUISessionFactory factory = new HttpSessionFactory(); @@ -127,6 +128,7 @@ public abstract class BaseServlet extends HttpServlet } // end catch + String str_request = the_request.toString(); String default_location = the_request.getLocation(); // log the username with all log messages, if the user is logged in @@ -173,12 +175,19 @@ public abstract class BaseServlet extends HttpServlet { // filter out RuntimeExceptions and rethrow them logger.error("BaseServlet caught runtime exception" + e.getClass().getName() + " in commonProcess",e); - throw (RuntimeException)e; + throw new ServletException(e); } // end if my_output = translateException(the_request,e); + } // end catch + catch (VirtualMachineError e) + { // OutOfMemoryError and similar come here... + System.gc(); // garbage collect so we have enough space to handle the error + logger.error("Virtual machine failure " + e.getClass().getName() + " in commonProcess",e); + throw new ServletException(e); + } // end catch if (logger.isDebugEnabled()) @@ -198,6 +207,13 @@ public abstract class BaseServlet extends HttpServlet the_request.outputRaw(my_output.toString()); } // end try + catch (VirtualMachineError e) + { // OutOfMemoryError and similar come here... + System.gc(); // garbage collect so we have enough space to handle the error + logger.error("Virtual machine failure " + e.getClass().getName() + " in commonProcess(2)",e); + throw new ServletException(e); + + } // end catch finally { // end the request the_request.end(); @@ -206,7 +222,12 @@ public abstract class BaseServlet extends HttpServlet } // end try finally - { // make sure and pop the diagnostic context, if it was pushed + { // log memory usage + Runtime r = Runtime.getRuntime(); + memlog.info("After: " + str_request + " Cur: " + r.totalMemory() + " Max: " + r.maxMemory() + " Free: " + + r.freeMemory()); + + // make sure and pop the diagnostic context, if it was pushed if (record_user) NDC.pop(); diff --git a/src/com/silverwrist/venice/ui/servlet/RequestImpl.java b/src/com/silverwrist/venice/ui/servlet/RequestImpl.java index 58aa830..6cddb16 100644 --- a/src/com/silverwrist/venice/ui/servlet/RequestImpl.java +++ b/src/com/silverwrist/venice/ui/servlet/RequestImpl.java @@ -756,6 +756,19 @@ public class RequestImpl implements RequestInput } // end expandServletPath + /*-------------------------------------------------------------------------------- + * Overrides from class Object + *-------------------------------------------------------------------------------- + */ + + public String toString() + { + StringBuffer buf = new StringBuffer("{RequestImpl from ["); + buf.append(request.getRemoteAddr()).append("] for ").append(request.getServletPath()).append("}"); + return buf.toString(); + + } // end toString + /*-------------------------------------------------------------------------------- * Implementations from interface ServiceProvider *--------------------------------------------------------------------------------