This is the mail archive of the java-patches@sources.redhat.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Turn off fillOutStackTrace while initializing default exception objects


Filling out a stack trace while creating the exception objects in
main_init is redundant, because fillOutStackTrace() will be called on
them again when they are actually thrown. This patch adds a flag so we
can disable the stack trace fill out during startup.

This serves two purposes:

1. Makes bootstrapping the runtime a little more efficient, by
eliminating a few system calls and allocations.

2. Prevents one potential problem in the out of memory sitation, where
printStackTrace() would try to allocate when dumping the stack of the
OutOfMemoryException (which wouldn't be the correct stack anyway).

regards

  [ bryce ]


2000-12-22  Bryce McKinlay  <bryce@albatross.co.nz>

	* java/lang/Throwable.java (trace_enabled): New static field.
	* java/lang/natThrowable.cc (fillInStackTrace): Do nothing if
	trace_enabled not set.
	* prims.cc (main_init): Turn off trace_enabled while creating
	default exception objects.

Index: prims.cc
===================================================================
RCS file: /cvs/gcc/egcs/libjava/prims.cc,v
retrieving revision 1.42
diff -u -r1.42 prims.cc
--- prims.cc	2000/11/27 04:05:23	1.42
+++ prims.cc	2000/12/22 06:01:44
@@ -687,6 +687,10 @@
 static void
 main_init ()
 {
+  // Turn stack trace generation off while creating exception objects.
+  _Jv_InitClass (&java::lang::Throwable::class$);
+  java::lang::Throwable::trace_enabled = 0;
+  
   INIT_SEGV;
 #ifdef HANDLE_FPE
   INIT_FPE;
@@ -696,6 +700,8 @@
 #endif
 
   no_memory = new java::lang::OutOfMemoryError;
+
+  java::lang::Throwable::trace_enabled = 1;
 
 #ifdef USE_LTDL
   LTDL_SET_PRELOADED_SYMBOLS ();
Index: java/lang/Throwable.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/lang/Throwable.java,v
retrieving revision 1.8
diff -u -r1.8 Throwable.java
--- Throwable.java	2000/07/27 23:57:06	1.8
+++ Throwable.java	2000/12/22 06:01:46
@@ -164,6 +164,8 @@
   // Name of this field comes from serialization spec.
   private String detailMessage;
 
+  // Setting this flag to false prevents fillInStackTrace() from running.
+  static boolean trace_enabled = true;
   private transient byte stackTrace[];
   private static final long serialVersionUID = -3042686055658047285L;
 }
Index: java/lang/natThrowable.cc
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/lang/natThrowable.cc,v
retrieving revision 1.7
diff -u -r1.7 natThrowable.cc
--- natThrowable.cc	2000/07/19 14:37:56	1.7
+++ natThrowable.cc	2000/12/22 06:01:46
@@ -50,6 +50,8 @@
 java::lang::Throwable *
 java::lang::Throwable::fillInStackTrace (void)
 {
+  if (! trace_enabled)
+    return this;
 #if defined (HAVE_BACKTRACE) || defined (__ia64__)
   void *p[128];
   

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]