Patch: FYI: Logger -vs- stack trace

Tom Tromey tromey@redhat.com
Mon Feb 21 17:44:00 GMT 2005


I'm checking this in on behalf of Andrew, who is doing other things
today.

This changes java.util.logging.Logger to use a native method to get
caller stack frame information.  This is more efficient.

With this patch in place, I can start up a gcj-compiled jonas in a
reasonable amount of time with no libgcj hacks.  (Some minor jonas
hacks are still required, eg making sure jacorb is available.)

Tom

Index: ChangeLog
from  Andrew Haley  <aph@redhat.com>

	* Makefile.in: Rebuilt.
	* Makefile.am (nat_source_files): Added natLogger.cc.
	* java/util/logging/natLogger.cc: New file.
	* java/util/logging/Logger.java (getCallerStackFrame): Now
	native.

Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.451
diff -u -r1.451 Makefile.am
--- Makefile.am 19 Feb 2005 18:47:10 -0000 1.451
+++ Makefile.am 21 Feb 2005 17:30:05 -0000
@@ -3720,6 +3720,7 @@
 java/text/natCollator.cc \
 java/util/natResourceBundle.cc \
 java/util/natVMTimeZone.cc \
+java/util/logging/natLogger.cc \
 java/util/zip/natDeflater.cc \
 java/util/zip/natInflater.cc
 
Index: java/util/logging/Logger.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/util/logging/Logger.java,v
retrieving revision 1.4
diff -u -r1.4 Logger.java
--- java/util/logging/Logger.java 20 Oct 2004 07:53:27 -0000 1.4
+++ java/util/logging/Logger.java 21 Feb 2005 17:30:05 -0000
@@ -1,5 +1,5 @@
 /* Logger.java -- a class for logging messages
-   Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -1169,17 +1169,5 @@
    * That should be the initial caller of a logging method.
    * @return caller of the initial looging method
    */
-  private StackTraceElement getCallerStackFrame()
-  {
-    Throwable t = new Throwable();
-    StackTraceElement[] stackTrace = t.getStackTrace();
-    int index = 0;
-    // skip to stackentries until this class
-    while(!stackTrace[index].getClassName().equals(getClass().getName())){index++;}
-    // skip the stackentries of this class
-    while(stackTrace[index].getClassName().equals(getClass().getName())){index++;}
-
-    return stackTrace[index];
-  }
-  
+  private native StackTraceElement getCallerStackFrame();
 }
Index: java/util/logging/natLogger.cc
===================================================================
RCS file: java/util/logging/natLogger.cc
diff -N java/util/logging/natLogger.cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ java/util/logging/natLogger.cc 21 Feb 2005 17:30:05 -0000
@@ -0,0 +1,55 @@
+// natLogger.cc - Native part of Logger class.
+
+/* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
+
+   This Logger is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License.  Please consult the Logger "LIBGCJ_LICENSE" for
+details.  */
+
+#include <config.h>
+#include <platform.h>
+
+#include <string.h>
+
+#pragma implementation "Logger.h"
+
+#include <gcj/cni.h>
+#include <jvm.h>
+
+
+#include <java/lang/Object.h>
+#include <java/lang/Class.h>
+#include <java/util/logging/Logger.h>
+#include <java/lang/StackTraceElement.h>
+#include <java/lang/ArrayIndexOutOfBoundsException.h>
+
+java::lang::StackTraceElement* 
+java::util::logging::Logger::getCallerStackFrame ()
+{
+  gnu::gcj::runtime::StackTrace *t 
+    = new gnu::gcj::runtime::StackTrace(4);
+  java::lang::Class *klass = NULL;
+  int i = 2;
+  try
+    {
+      // skip until this class
+      while ((klass = t->classAt (i)) != getClass())
+	i++;
+      // skip the stackentries of this class
+      while ((klass = t->classAt (i)) == getClass() || klass == NULL)
+	i++;
+    }
+  catch (::java::lang::ArrayIndexOutOfBoundsException *e)
+    {
+      // FIXME: RuntimeError
+    }
+
+  java::lang::StackTraceElement *e 
+    = new java::lang::StackTraceElement
+    (JvNewStringUTF (""), 0, 
+     klass->getName(), t->methodAt(i), false);
+
+  return e;
+}



More information about the Java-patches mailing list