commit-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Removing remaining static initializers from basic classes


From: Grzegorz B. Prokopski
Subject: Removing remaining static initializers from basic classes
Date: Fri, 26 Mar 2004 23:26:11 -0500

After recent discusions some of the static initializers of basic classes
have been removed or worked around by using inner classes. The attached
patch removes two other such cases and works around another one.

                                Grzegorz B. Prokopski

Index: java/lang/Object.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/Object.java,v
retrieving revision 1.14
diff -u -r1.14 Object.java
--- java/lang/Object.java       26 Mar 2002 06:19:38 -0000      1.14
+++ java/lang/Object.java       27 Mar 2004 04:16:09 -0000
@@ -63,18 +63,8 @@
 {
   // WARNING: Object is a CORE class in the bootstrap cycle. See the comments
   // in vm/reference/java/lang/Runtime for implications of this fact.
-
-  /**
-   * Load in all native methods in the java.lang package. Note that this
-   * call is actually a no-op, since it triggers the class initialization
-   * of System, which loads the same library; but it is necessary to start
-   * the System class initialization for the bootstrap sequence to work.
-   */
-  static
-  {
-    if (Configuration.INIT_LOAD_LIBRARY)
-      System.loadLibrary("javalang");
-  }
+  // Many JVMs do not allow for static initializers in this class,
+  // hence we do not use them in the default implementation.
 
   // Some VM's rely on the order that these methods appear when laying
   // out their internal structure.  Therefore, do not haphazardly
Index: java/lang/Throwable.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/Throwable.java,v
retrieving revision 1.18
diff -u -r1.18 Throwable.java
--- java/lang/Throwable.java    4 Oct 2002 15:26:25 -0000       1.18
+++ java/lang/Throwable.java    27 Mar 2004 04:16:09 -0000
@@ -400,7 +400,18 @@
     pw.print(stackTraceString());
   }
 
-  private static final String nl = System.getProperty("line.separator");
+  /*
+   * We use inner class to avoid a static initializer in this basic class
+   */
+  private static class StaticData {
+
+    private final static String nl;
+
+    static {
+      nl = System.getProperty("line.separator");
+    }
+  }
+
   // Create whole stack trace in a stringbuffer so we don't have to print
   // it line by line. This prevents printing multiple stack traces from
   // different threads to get mixed up when written to the same PrintWriter.
@@ -453,6 +464,7 @@
   private static void stackTraceStringBuffer(StringBuffer sb, String name,
                                        StackTraceElement[] stack, int equal)
   {
+    String nl = StaticData.nl;
     // (finish) first line
     sb.append(name);
     sb.append(nl);
Index: java/lang/reflect/Array.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/reflect/Array.java,v
retrieving revision 1.10
diff -u -r1.10 Array.java
--- java/lang/reflect/Array.java        7 Jan 2004 09:18:46 -0000       1.10
+++ java/lang/reflect/Array.java        27 Mar 2004 04:16:10 -0000
@@ -78,13 +78,6 @@
  */
 public final class Array
 {
-  static
-  {
-    if (Configuration.INIT_LOAD_LIBRARY)
-      {
-        System.loadLibrary("javalangreflect");
-      }
-  }
 
   /**
    * This class is uninstantiable.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]