]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
* java/lang/Class.h (Class::desiredAssertionStatus): Declare.
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 11 Jun 2002 17:33:22 +0000 (17:33 +0000)
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 11 Jun 2002 17:33:22 +0000 (17:33 +0000)
(Class::getPackagePortion): Likewise.
* java/lang/Class.java (desiredAssertionStatus): New method from
Classpath.
(getPackagePortion): Likewise.
* java/lang/VMClassLoader.java (defaultAssertionStatus,
packageAssertionStatus, classAssertionStatus): New methods from
Classpath.
* java/lang/ClassLoader.java (defaultAssertionStatus,
systemPackageAssertionStatus, packageAssertionStatus,
systemClassAssertionStatus, classAssertionStatus): New fields from
Classpath.
(setDefaultAssertionStatus, setPackageAssertionStatus,
setClassAssertionStatus, clearAssertionStatus): New methods from
Classpath.
* Makefile.in: Rebuilt.
* Makefile.am (core_java_source_files): Added AssertionError.java.
* java/lang/AssertionError.java: New from Classpath.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@54517 138bc75d-0d04-0410-961f-82ee72b054a4

libjava/ChangeLog
libjava/Makefile.am
libjava/Makefile.in
libjava/gcj/Makefile.in
libjava/include/Makefile.in
libjava/java/lang/AssertionError.java [new file with mode: 0644]
libjava/java/lang/Class.h
libjava/java/lang/Class.java
libjava/java/lang/ClassLoader.java
libjava/java/lang/VMClassLoader.java

index 118270ae40fa3edf032cb9d263ec35c244af8057..072c7b56945a784f15b1ecc411528131a109713a 100644 (file)
@@ -1,3 +1,24 @@
+2002-06-10  Tom Tromey  <tromey@redhat.com>
+
+       * java/lang/Class.h (Class::desiredAssertionStatus): Declare.
+       (Class::getPackagePortion): Likewise.
+       * java/lang/Class.java (desiredAssertionStatus): New method from
+       Classpath.
+       (getPackagePortion): Likewise.
+       * java/lang/VMClassLoader.java (defaultAssertionStatus,
+       packageAssertionStatus, classAssertionStatus): New methods from
+       Classpath.
+       * java/lang/ClassLoader.java (defaultAssertionStatus,
+       systemPackageAssertionStatus, packageAssertionStatus,
+       systemClassAssertionStatus, classAssertionStatus): New fields from
+       Classpath.
+       (setDefaultAssertionStatus, setPackageAssertionStatus,
+       setClassAssertionStatus, clearAssertionStatus): New methods from
+       Classpath.
+       * Makefile.in: Rebuilt.
+       * Makefile.am (core_java_source_files): Added AssertionError.java.
+       * java/lang/AssertionError.java: New from Classpath.
+
 2002-06-10  Bryce McKinlay  <bryce@waitaki.otago.ac.nz>
 
        * configure.host: Disable hash synchronization and slow_pthread_self
index a959fdbba5e61ec0fe51ecaac6ee375dcfe9b042..29ba7290a5f949102657c373356f1984a13f3993 100644 (file)
@@ -1029,6 +1029,7 @@ java/lang/AbstractMethodError.java \
 java/lang/ArithmeticException.java \
 java/lang/ArrayIndexOutOfBoundsException.java \
 java/lang/ArrayStoreException.java \
+java/lang/AssertionError.java \
 java/lang/Boolean.java \
 java/lang/Byte.java \
 java/lang/Character.java \
index 6c4a9001a8476025e202ee1e2288703af3da0f6c..72b3dafd5d3b27d10385b6f47bcbc0560cfbd63e 100644 (file)
@@ -796,6 +796,7 @@ java/lang/AbstractMethodError.java \
 java/lang/ArithmeticException.java \
 java/lang/ArrayIndexOutOfBoundsException.java \
 java/lang/ArrayStoreException.java \
+java/lang/AssertionError.java \
 java/lang/Boolean.java \
 java/lang/Byte.java \
 java/lang/Character.java \
@@ -2235,7 +2236,8 @@ DEP_FILES =  .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \
 .deps/java/lang/AbstractMethodError.P \
 .deps/java/lang/ArithmeticException.P \
 .deps/java/lang/ArrayIndexOutOfBoundsException.P \
-.deps/java/lang/ArrayStoreException.P .deps/java/lang/Boolean.P \
+.deps/java/lang/ArrayStoreException.P .deps/java/lang/AssertionError.P \
+.deps/java/lang/Boolean.P \
 .deps/java/lang/Byte.P .deps/java/lang/CharSequence.P \
 .deps/java/lang/Character.P .deps/java/lang/Class.P \
 .deps/java/lang/ClassCastException.P \
index 9260947c7a81cfe528c8ce3deed3fd60ee766e98..697d7ff909c94a22d09de4af9fb8b9f4e145d23f 100644 (file)
@@ -1,4 +1,4 @@
-# Makefile.in generated automatically by automake 1.4 from Makefile.am
+# Makefile.in generated automatically by automake 1.4-p4 from Makefile.am
 
 # Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
@@ -258,7 +258,7 @@ distdir: $(DISTFILES)
        @for file in $(DISTFILES); do \
          d=$(srcdir); \
          if test -d $$d/$$file; then \
-           cp -pr $$/$$file $(distdir)/$$file; \
+           cp -pr $$d/$$file $(distdir)/$$file; \
          else \
            test -f $(distdir)/$$file \
            || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
index 1d38fcdb4d3971b532267d1f49acbffe8cb25ddd..0dbe4528b3f5a129a0142db0073cdc8d017b3f55 100644 (file)
@@ -1,4 +1,4 @@
-# Makefile.in generated automatically by automake 1.4 from Makefile.am
+# Makefile.in generated automatically by automake 1.4-p4 from Makefile.am
 
 # Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
@@ -239,7 +239,7 @@ distdir: $(DISTFILES)
        @for file in $(DISTFILES); do \
          d=$(srcdir); \
          if test -d $$d/$$file; then \
-           cp -pr $$/$$file $(distdir)/$$file; \
+           cp -pr $$d/$$file $(distdir)/$$file; \
          else \
            test -f $(distdir)/$$file \
            || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
diff --git a/libjava/java/lang/AssertionError.java b/libjava/java/lang/AssertionError.java
new file mode 100644 (file)
index 0000000..1ce00ae
--- /dev/null
@@ -0,0 +1,148 @@
+/* AssertionError.java -- indication of a failed assertion
+   Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.lang;
+
+/**
+ * An assertion error normally occurs as a result of the <code>assert</code>
+ * statement added in JDK 1.4, to indicate that an assertion failed. There
+ * are enough constructors to ensure that
+ * <code>new AssertionError(<em>expression</em)</code> will work for all
+ * espressions, regardless of type, as if the error message were given by
+ * the string <code>"" + <em>expression</em></code>. This extends Error,
+ * because you usually do not want to inadvertently trap an assertion failure.
+ *
+ * @author Eric Blake <ebb9@email.byu.edu>
+ * @since 1.4
+ * @status updated to 1.4
+ */
+public class AssertionError extends Error
+{
+  /**
+   * Compatible with JDK 1.4+.
+   */
+  private static final long serialVersionUID = -5013299493970297370L;
+
+  /**
+   * Construct an AssertionError with no detail message.
+   */
+  public AssertionError()
+  {
+  }
+
+  /**
+   * Construct an AssertionError with the string conversion of the given
+   * object as its error message. If the object is a Throwable, it is also
+   * set as the cause of this error.
+   *
+   * @param msg the source of the error message
+   * @see Throwable#getCause()
+   */
+  public AssertionError(Object msg)
+  {
+    super("" + msg);
+    if (msg instanceof Throwable)
+      initCause((Throwable) msg);
+  }
+
+  /**
+   * Construct an AssertionError with the string conversion of the given
+   * boolean as its error message.
+   *
+   * @param msg the source of the error message
+   */
+  public AssertionError(boolean msg)
+  {
+    super(msg ? "true" : "false");
+  }
+
+  /**
+   * Construct an AssertionError with the string conversion of the given
+   * char as its error message.
+   *
+   * @param msg the source of the error message
+   */
+  public AssertionError(char msg)
+  {
+    super(String.valueOf(msg));
+  }
+
+  /**
+   * Construct an AssertionError with the string conversion of the given
+   * int as its error message.
+   *
+   * @param msg the source of the error message
+   */
+  public AssertionError(int msg)
+  {
+    super(Integer.toString(msg, 10));
+  }
+
+  /**
+   * Construct an AssertionError with the string conversion of the given
+   * long as its error message.
+   *
+   * @param msg the source of the error message
+   */
+  public AssertionError(long msg)
+  {
+    super(Long.toString(msg));
+  }
+
+  /**
+   * Construct an AssertionError with the string conversion of the given
+   * float as its error message.
+   *
+   * @param msg the source of the error message
+   */
+  public AssertionError(float msg)
+  {
+    super(Float.toString(msg));
+  }
+
+  /**
+   * Construct an AssertionError with the string conversion of the given
+   * double as its error message.
+   *
+   * @param msg the source of the error message
+   */
+  public AssertionError(double msg)
+  {
+    super(Double.toString(msg));
+  }
+}
index 0f36f25eacf2640b1296381ed0bc32eeecabc571..91a430a548b8cf492a05a339cb4c27ac03a4b37c 100644 (file)
@@ -1,6 +1,6 @@
 // Class.h - Header file for java.lang.Class.  -*- c++ -*-
 
-/* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -210,6 +210,7 @@ public:
 
   jobject newInstance (void);
   jstring toString (void);
+  jboolean desiredAssertionStatus (void);
 
   // FIXME: this probably shouldn't be public.
   jint size (void)
@@ -232,6 +233,8 @@ private:
 
   void initializeClass (void);
 
+  static jstring getPackagePortion (jstring);
+
   // Friend functions implemented in natClass.cc.
   friend _Jv_Method *_Jv_GetMethodLocal (jclass klass, _Jv_Utf8Const *name,
                                         _Jv_Utf8Const *signature);
index 549eaec9cf2172740df55d0db9ed393186104c9b..7bd38dee01f85e69733e18f262914ee7d7fee860 100644 (file)
@@ -1,6 +1,6 @@
 // Class.java - Representation of a Java class.
 
-/* Copyright (C) 1998, 1999, 2000  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2002  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -217,6 +217,75 @@ public final class Class implements Serializable
     return (isInterface () ? "interface " : "class ") + getName ();
   }
 
+  /**
+   * Returns the desired assertion status of this class, if it were to be
+   * initialized at this moment. The class assertion status, if set, is
+   * returned; the backup is the default package status; then if there is
+   * a class loader, that default is returned; and finally the system default
+   * is returned. This method seldom needs calling in user code, but exists
+   * for compilers to implement the assert statement. Note that there is no
+   * guarantee that the result of this method matches the class's actual
+   * assertion status.
+   *
+   * @return the desired assertion status
+   * @see ClassLoader#setClassAssertionStatus(String, boolean)
+   * @see ClassLoader#setPackageAssertionStatus(String, boolean)
+   * @see ClassLoader#setDefaultAssertionStatus(boolean)
+   * @since 1.4
+   */
+  public boolean desiredAssertionStatus()
+  {
+    ClassLoader c = getClassLoader();
+    Object status;
+    if (c == null)
+      return VMClassLoader.defaultAssertionStatus();
+    if (c.classAssertionStatus != null)
+      synchronized (c)
+        {
+          status = c.classAssertionStatus.get(getName());
+          if (status != null)
+            return status.equals(Boolean.TRUE);
+        }
+    else
+      {
+        status = ClassLoader.systemClassAssertionStatus.get(getName());
+        if (status != null)
+          return status.equals(Boolean.TRUE);
+      }
+    if (c.packageAssertionStatus != null)
+      synchronized (c)
+        {
+          String name = getPackagePortion(getName());
+          if ("".equals(name))
+            status = c.packageAssertionStatus.get(null);
+          else
+            do
+              {
+                status = c.packageAssertionStatus.get(name);
+                name = getPackagePortion(name);
+              }
+            while (! "".equals(name) && status == null);
+          if (status != null)
+            return status.equals(Boolean.TRUE);
+        }
+    else
+      {
+        String name = getPackagePortion(getName());
+        if ("".equals(name))
+          status = ClassLoader.systemPackageAssertionStatus.get(null);
+        else
+          do
+            {
+              status = ClassLoader.systemPackageAssertionStatus.get(name);
+              name = getPackagePortion(name);
+            }
+          while (! "".equals(name) && status == null);
+        if (status != null)
+          return status.equals(Boolean.TRUE);
+      }
+    return c.defaultAssertionStatus;
+  }
+
   // Don't allow new classes to be made.
   private Class ()
   {
@@ -235,4 +304,18 @@ public final class Class implements Serializable
 
   // finalization
   protected native void finalize ();
+
+  /**
+   * Strip the last portion of the name (after the last dot).
+   *
+   * @param name the name to get package of
+   * @return the package name, or "" if no package
+   */
+  private static String getPackagePortion(String name)
+  {
+    int lastInd = name.lastIndexOf('.');
+    if (lastInd == -1)
+      return "";
+    return name.substring(0, lastInd);
+  }
 }
index 32351d84040a251b5ed697d3a81f886d0dce179d..7925fe73d871149fd9e29ff809ff8d9d0835ebac 100644 (file)
@@ -1,6 +1,6 @@
 // ClassLoader.java - Define policies for loading Java classes.
 
-/* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -20,9 +20,7 @@ import java.security.Permission;
 import java.security.Permissions;
 import java.security.Policy;
 import java.security.ProtectionDomain;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Stack;
+import java.util.*;
 
 /**
  * The class <code>ClassLoader</code> is intended to be subclassed by
@@ -34,6 +32,47 @@ import java.util.Stack;
 
 public abstract class ClassLoader
 {
+  /**
+   * The desired assertion status of classes loaded by this loader, if not
+   * overridden by package or class instructions.
+   */
+  // Package visible for use by Class.
+  boolean defaultAssertionStatus = VMClassLoader.defaultAssertionStatus();
+
+  /**
+   * The command-line state of the package assertion status overrides. This
+   * map is never modified, so it does not need to be synchronized.
+   */
+  // Package visible for use by Class.
+  static final Map systemPackageAssertionStatus
+    = VMClassLoader.packageAssertionStatus();
+
+  /**
+   * The map of package assertion status overrides, or null if no package
+   * overrides have been specified yet. The values of the map should be
+   * Boolean.TRUE or Boolean.FALSE, and the unnamed package is represented
+   * by the null key. This map must be synchronized on this instance.
+   */
+  // Package visible for use by Class.
+  Map packageAssertionStatus;
+
+  /**
+   * The command-line state of the class assertion status overrides. This
+   * map is never modified, so it does not need to be synchronized.
+   */
+  // Package visible for use by Class.
+  static final Map systemClassAssertionStatus
+    = VMClassLoader.classAssertionStatus();
+
+  /**
+   * The map of class assertion status overrides, or null if no class
+   * overrides have been specified yet. The values of the map should be
+   * Boolean.TRUE or Boolean.FALSE. This map must be synchronized on this
+   * instance.
+   */
+  // Package visible for use by Class.
+  Map classAssertionStatus;
+
   private ClassLoader parent;
   private HashMap definedPackages = new HashMap();
 
@@ -577,4 +616,78 @@ public abstract class ClassLoader
     // Default to returning null.  Derived classes implement this.
     return null;
   }
+
+  /**
+   * Set the default assertion status for classes loaded by this classloader,
+   * used unless overridden by a package or class request.
+   *
+   * @param enabled true to set the default to enabled
+   * @see #setClassAssertionStatus(String, boolean)
+   * @see #setPackageAssertionStatus(String, boolean)
+   * @see #clearAssertionStatus()
+   * @since 1.4
+   */
+  public void setDefaultAssertionStatus(boolean enabled)
+  {
+    defaultAssertionStatus = enabled;
+  }
+
+  /**
+   * Set the default assertion status for packages, used unless overridden
+   * by a class request. This default also covers subpackages, unless they
+   * are also specified. The unnamed package should use null for the name.
+   *
+   * @param name the package (and subpackages) to affect
+   * @param enabled true to set the default to enabled
+   * @see #setDefaultAssertionStatus(String, boolean)
+   * @see #setClassAssertionStatus(String, boolean)
+   * @see #clearAssertionStatus()
+   * @since 1.4
+   */
+  public synchronized void setPackageAssertionStatus(String name,
+                                                     boolean enabled)
+  {
+    if (packageAssertionStatus == null)
+      packageAssertionStatus
+        = new HashMap(systemPackageAssertionStatus);
+    packageAssertionStatus.put(name, Boolean.valueOf(enabled));
+  }
+  
+  /**
+   * Set the default assertion status for a class. This only affects the
+   * status of top-level classes, any other string is harmless.
+   *
+   * @param name the class to affect
+   * @param enabled true to set the default to enabled
+   * @throws NullPointerException if name is null
+   * @see #setDefaultAssertionStatus(String, boolean)
+   * @see #setPackageAssertionStatus(String, boolean)
+   * @see #clearAssertionStatus()
+   * @since 1.4
+   */
+  public synchronized void setClassAssertionStatus(String name,
+                                                   boolean enabled)
+  {
+    if (classAssertionStatus == null)
+      classAssertionStatus = new HashMap(systemClassAssertionStatus);
+    // The toString() hack catches null, as required.
+    classAssertionStatus.put(name.toString(), Boolean.valueOf(enabled));
+  }
+  
+  /**
+   * Resets the default assertion status of this classloader, its packages
+   * and classes, all to false. This allows overriding defaults inherited
+   * from the command line.
+   *
+   * @see #setDefaultAssertionStatus(boolean)
+   * @see #setClassAssertionStatus(String, boolean)
+   * @see #setPackageAssertionStatus(String, boolean)
+   * @since 1.4
+   */
+  public synchronized void clearAssertionStatus()
+  {
+    defaultAssertionStatus = false;
+    packageAssertionStatus = new HashMap();
+    classAssertionStatus = new HashMap();
+  }
 }
index 5ff7ae86b211904fe61f9d15dc225d19cbd1f0fa..445272b1bbacf86c76b1e68ac2d535d574ac3e66 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * java.lang.ClassLoader: part of the Java Class Libraries project.
- * Copyright (C) 1998, 2001 Free Software Foundation
+ * Copyright (C) 1998, 2001, 2002 Free Software Foundation
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -20,6 +20,8 @@
 
 package java.lang;
 
+import java.util.*;
+
 /**
  * java.lang.VMClassLoader is a package-private helper for VMs to implement
  * on behalf of java.lang.ClassLoader.
@@ -59,4 +61,47 @@ class VMClassLoader {
      * @param type code for the primitive type.
      */
   static native Class getPrimitiveClass(char type);
+
+  /**
+   * The system default for assertion status. This is used for all system
+   * classes (those with a null ClassLoader), as well as the initial value for
+   * every ClassLoader's default assertion status.
+   *
+   * XXX - Not implemented yet; this requires native help.
+   *
+   * @return the system-wide default assertion status
+   */
+  static final boolean defaultAssertionStatus()
+  {
+    return true;
+  }
+
+  /**
+   * The system default for package assertion status. This is used for all
+   * ClassLoader's packageAssertionStatus defaults. It must be a map of
+   * package names to Boolean.TRUE or Boolean.FALSE, with the unnamed package
+   * represented as a null key.
+   *
+   * XXX - Not implemented yet; this requires native help.
+   *
+   * @return a (read-only) map for the default packageAssertionStatus
+   */
+  static final Map packageAssertionStatus()
+  {
+    return new HashMap();
+  }
+
+  /**
+   * The system default for class assertion status. This is used for all
+   * ClassLoader's classAssertionStatus defaults. It must be a map of
+   * class names to Boolean.TRUE or Boolean.FALSE
+   *
+   * XXX - Not implemented yet; this requires native help.
+   *
+   * @return a (read-only) map for the default classAssertionStatus
+   */
+  static final Map classAssertionStatus()
+  {
+    return new HashMap();
+  }
 }