diff options
Diffstat (limited to 'libjava/classpath/java/lang')
-rw-r--r-- | libjava/classpath/java/lang/Character.java | 11 | ||||
-rw-r--r-- | libjava/classpath/java/lang/Class.java | 8 | ||||
-rw-r--r-- | libjava/classpath/java/lang/Double.java | 75 | ||||
-rw-r--r-- | libjava/classpath/java/lang/Float.java | 77 | ||||
-rw-r--r-- | libjava/classpath/java/lang/InheritableThreadLocal.java | 13 | ||||
-rw-r--r-- | libjava/classpath/java/lang/SecurityManager.java | 15 | ||||
-rw-r--r-- | libjava/classpath/java/lang/StackTraceElement.java | 22 | ||||
-rw-r--r-- | libjava/classpath/java/lang/String.java | 16 | ||||
-rw-r--r-- | libjava/classpath/java/lang/Thread.java | 6 | ||||
-rw-r--r-- | libjava/classpath/java/lang/ThreadLocal.java | 23 |
10 files changed, 215 insertions, 51 deletions
diff --git a/libjava/classpath/java/lang/Character.java b/libjava/classpath/java/lang/Character.java index 78db41ef216..3c88ff805c7 100644 --- a/libjava/classpath/java/lang/Character.java +++ b/libjava/classpath/java/lang/Character.java @@ -2410,11 +2410,11 @@ public final class Character implements Serializable, Comparable { // Write second char first to cause IndexOutOfBoundsException // immediately. - dst[dstIndex + 1] = (char) ((codePoint & 0x3ff) - + (int) MIN_LOW_SURROGATE ); - dst[dstIndex] = (char) ((codePoint >> 10) + (int) MIN_HIGH_SURROGATE); + final int cp2 = codePoint - 0x10000; + dst[dstIndex + 1] = (char) ((cp2 % 0x400) + (int) MIN_LOW_SURROGATE); + dst[dstIndex] = (char) ((cp2 / 0x400) + (int) MIN_HIGH_SURROGATE); result = 2; - } + } else { dst[dstIndex] = (char) codePoint; @@ -2523,7 +2523,8 @@ public final class Character implements Serializable, Comparable */ public static int toCodePoint(char high, char low) { - return ((high - MIN_HIGH_SURROGATE) << 10) + (low - MIN_LOW_SURROGATE); + return ((high - MIN_HIGH_SURROGATE) * 0x400) + + (low - MIN_LOW_SURROGATE) + 0x10000; } /** diff --git a/libjava/classpath/java/lang/Class.java b/libjava/classpath/java/lang/Class.java index 726c794a413..c4235e6808c 100644 --- a/libjava/classpath/java/lang/Class.java +++ b/libjava/classpath/java/lang/Class.java @@ -583,8 +583,7 @@ public final class Class implements Serializable /** * Returns the <code>Package</code> in which this class is defined * Returns null when this information is not available from the - * classloader of this class or when the classloader of this class - * is null. + * classloader of this class. * * @return the package for this class, if it is available * @since 1.2 @@ -837,7 +836,10 @@ public final class Class implements Serializable */ public int getModifiers() { - return VMClass.getModifiers (this, false); + int mod = VMClass.getModifiers (this, false); + return (mod & (Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE | + Modifier.FINAL | Modifier.STATIC | Modifier.ABSTRACT | + Modifier.INTERFACE)); } /** diff --git a/libjava/classpath/java/lang/Double.java b/libjava/classpath/java/lang/Double.java index 26b398bb695..03c56068921 100644 --- a/libjava/classpath/java/lang/Double.java +++ b/libjava/classpath/java/lang/Double.java @@ -173,6 +173,81 @@ public final class Double extends Number implements Comparable } /** + * Convert a double value to a hexadecimal string. This converts as + * follows: + * <ul> + * <li> A NaN value is converted to the string "NaN". + * <li> Positive infinity is converted to the string "Infinity". + * <li> Negative infinity is converted to the string "-Infinity". + * <li> For all other values, the first character of the result is '-' + * if the value is negative. This is followed by '0x1.' if the + * value is normal, and '0x0.' if the value is denormal. This is + * then followed by a (lower-case) hexadecimal representation of the + * mantissa, with leading zeros as required for denormal values. + * The next character is a 'p', and this is followed by a decimal + * representation of the unbiased exponent. + * </ul> + * @param d the double value + * @return the hexadecimal string representation + * @since 1.5 + */ + public static String toHexString(double d) + { + if (isNaN(d)) + return "NaN"; + if (isInfinite(d)) + return d < 0 ? "-Infinity" : "Infinity"; + + long bits = doubleToLongBits(d); + StringBuilder result = new StringBuilder(); + + if (bits < 0) + result.append('-'); + result.append("0x"); + + final int mantissaBits = 52; + final int exponentBits = 11; + long mantMask = (1L << mantissaBits) - 1; + long mantissa = bits & mantMask; + long expMask = (1L << exponentBits) - 1; + long exponent = (bits >>> mantissaBits) & expMask; + + result.append(exponent == 0 ? '0' : '1'); + result.append('.'); + result.append(Long.toHexString(mantissa)); + if (exponent == 0 && mantissa != 0) + { + // Treat denormal specially by inserting '0's to make + // the length come out right. The constants here are + // to account for things like the '0x'. + int offset = 4 + ((bits < 0) ? 1 : 0); + // The silly +3 is here to keep the code the same between + // the Float and Double cases. In Float the value is + // not a multiple of 4. + int desiredLength = offset + (mantissaBits + 3) / 4; + while (result.length() < desiredLength) + result.insert(offset, '0'); + } + result.append('p'); + if (exponent == 0 && mantissa == 0) + { + // Zero, so do nothing special. + } + else + { + // Apply bias. + boolean denormal = exponent == 0; + exponent -= (1 << (exponentBits - 1)) - 1; + // Handle denormal. + if (denormal) + ++exponent; + } + + result.append(Long.toString(exponent)); + return result.toString(); + } + + /** * Returns a <code>Double</code> object wrapping the value. * In contrast to the <code>Double</code> constructor, this method * may cache some values. It is used by boxing conversion. diff --git a/libjava/classpath/java/lang/Float.java b/libjava/classpath/java/lang/Float.java index eef34a0abeb..dcd5b221197 100644 --- a/libjava/classpath/java/lang/Float.java +++ b/libjava/classpath/java/lang/Float.java @@ -183,6 +183,83 @@ public final class Float extends Number implements Comparable } /** + * Convert a float value to a hexadecimal string. This converts as + * follows: + * <ul> + * <li> A NaN value is converted to the string "NaN". + * <li> Positive infinity is converted to the string "Infinity". + * <li> Negative infinity is converted to the string "-Infinity". + * <li> For all other values, the first character of the result is '-' + * if the value is negative. This is followed by '0x1.' if the + * value is normal, and '0x0.' if the value is denormal. This is + * then followed by a (lower-case) hexadecimal representation of the + * mantissa, with leading zeros as required for denormal values. + * The next character is a 'p', and this is followed by a decimal + * representation of the unbiased exponent. + * </ul> + * @param f the float value + * @return the hexadecimal string representation + * @since 1.5 + */ + public static String toHexString(float f) + { + if (isNaN(f)) + return "NaN"; + if (isInfinite(f)) + return f < 0 ? "-Infinity" : "Infinity"; + + int bits = floatToIntBits(f); + StringBuilder result = new StringBuilder(); + + if (bits < 0) + result.append('-'); + result.append("0x"); + + final int mantissaBits = 23; + final int exponentBits = 8; + int mantMask = (1 << mantissaBits) - 1; + int mantissa = bits & mantMask; + int expMask = (1 << exponentBits) - 1; + int exponent = (bits >>> mantissaBits) & expMask; + + result.append(exponent == 0 ? '0' : '1'); + result.append('.'); + // For Float only, we have to adjust the mantissa. + mantissa <<= 1; + result.append(Integer.toHexString(mantissa)); + if (exponent == 0 && mantissa != 0) + { + // Treat denormal specially by inserting '0's to make + // the length come out right. The constants here are + // to account for things like the '0x'. + int offset = 4 + ((bits < 0) ? 1 : 0); + // The silly +3 is here to keep the code the same between + // the Float and Double cases. In Float the value is + // not a multiple of 4. + int desiredLength = offset + (mantissaBits + 3) / 4; + while (result.length() < desiredLength) + result.insert(offset, '0'); + } + result.append('p'); + if (exponent == 0 && mantissa == 0) + { + // Zero, so do nothing special. + } + else + { + // Apply bias. + boolean denormal = exponent == 0; + exponent -= (1 << (exponentBits - 1)) - 1; + // Handle denormal. + if (denormal) + ++exponent; + } + + result.append(Integer.toString(exponent)); + return result.toString(); + } + + /** * Creates a new <code>Float</code> object using the <code>String</code>. * * @param s the <code>String</code> to convert diff --git a/libjava/classpath/java/lang/InheritableThreadLocal.java b/libjava/classpath/java/lang/InheritableThreadLocal.java index 69ff6138dc6..b9c7624ef44 100644 --- a/libjava/classpath/java/lang/InheritableThreadLocal.java +++ b/libjava/classpath/java/lang/InheritableThreadLocal.java @@ -1,5 +1,5 @@ /* InheritableThreadLocal -- a ThreadLocal which inherits values across threads - Copyright (C) 2000, 2001, 2002, 2003, 2005 Free Software Foundation, Inc. + Copyright (C) 2000, 2001, 2002, 2003, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -37,8 +37,9 @@ exception statement from your version. */ package java.lang; +import gnu.java.util.WeakIdentityHashMap; + import java.util.Iterator; -import java.util.WeakHashMap; /** * A ThreadLocal whose value is inherited by child Threads. The value of the @@ -98,15 +99,15 @@ public class InheritableThreadLocal extends ThreadLocal Iterator keys = parentThread.locals.keySet().iterator(); while (keys.hasNext()) { - Key key = (Key)keys.next(); - if (key.get() instanceof InheritableThreadLocal) + Object key = keys.next(); + if (key instanceof InheritableThreadLocal) { - InheritableThreadLocal local = (InheritableThreadLocal)key.get(); + InheritableThreadLocal local = (InheritableThreadLocal)key; Object parentValue = parentThread.locals.get(key); Object childValue = local.childValue(parentValue == NULL ? null : parentValue); if (childThread.locals == null) - childThread.locals = new WeakHashMap(); + childThread.locals = new WeakIdentityHashMap(); childThread.locals.put(key, (childValue == null ? NULL : childValue)); } diff --git a/libjava/classpath/java/lang/SecurityManager.java b/libjava/classpath/java/lang/SecurityManager.java index 26d56a64bf3..30ee1be086f 100644 --- a/libjava/classpath/java/lang/SecurityManager.java +++ b/libjava/classpath/java/lang/SecurityManager.java @@ -41,9 +41,6 @@ package java.lang; import gnu.classpath.VMStackWalker; import java.awt.AWTPermission; -import java.awt.Frame; -import java.awt.Toolkit; -import java.awt.Window; import java.io.File; import java.io.FileDescriptor; import java.io.FileInputStream; @@ -424,7 +421,7 @@ public class SecurityManager public void checkAccess(Thread thread) { if (thread.getThreadGroup() != null - && thread.getThreadGroup().getParent() != null) + && thread.getThreadGroup().getParent() == null) checkPermission(new RuntimePermission("modifyThread")); } @@ -457,7 +454,7 @@ public class SecurityManager */ public void checkAccess(ThreadGroup g) { - if (g.getParent() != null) + if (g.getParent() == null) checkPermission(new RuntimePermission("modifyThreadGroup")); } @@ -837,7 +834,7 @@ public class SecurityManager * @param window the window to create * @return true if there is permission to show the window without warning * @throws NullPointerException if window is null - * @see Window#Window(Frame) + * @see java.awt.Window#Window(java.awt.Frame) */ public boolean checkTopLevelWindow(Object window) { @@ -862,7 +859,7 @@ public class SecurityManager * an exception. * * @throws SecurityException if permission is denied - * @see Toolkit#getPrintJob(Frame, String, Properties) + * @see java.awt.Toolkit#getPrintJob(java.awt.Frame, String, Properties) * @since 1.1 */ public void checkPrintJobAccess() @@ -878,7 +875,7 @@ public class SecurityManager * rather than throwing an exception. * * @throws SecurityException if permission is denied - * @see Toolkit#getSystemClipboard() + * @see java.awt.Toolkit#getSystemClipboard() * @since 1.1 */ public void checkSystemClipboardAccess() @@ -894,7 +891,7 @@ public class SecurityManager * rather than throwing an exception. * * @throws SecurityException if permission is denied - * @see Toolkit#getSystemEventQueue() + * @see java.awt.Toolkit#getSystemEventQueue() * @since 1.1 */ public void checkAwtEventQueueAccess() diff --git a/libjava/classpath/java/lang/StackTraceElement.java b/libjava/classpath/java/lang/StackTraceElement.java index 6dd4d8532e8..cf4d1c76f4d 100644 --- a/libjava/classpath/java/lang/StackTraceElement.java +++ b/libjava/classpath/java/lang/StackTraceElement.java @@ -49,7 +49,7 @@ import java.io.Serializable; * @author Mark Wielaard (mark@klomp.org) * @author Eric Blake (ebb9@email.byu.edu) * @since 1.4 - * @status updated to 1.4 + * @status updated to 1.5 */ public final class StackTraceElement implements Serializable { @@ -112,6 +112,26 @@ public final class StackTraceElement implements Serializable } /** + * Create a new StackTraceElement representing a given source location. + * + * @param className the fully qualified name of the class + * @param methodName the name of the method + * @param fileName the name of the file, null if unknown + * @param lineNumber the line in the file, negative if unknown, or -2 + * if this method is native + * + * @since 1.5 + */ + public StackTraceElement(String className, String methodName, String fileName, + int lineNumber) + { + this(fileName, lineNumber, className, methodName, lineNumber == -2); + // The public constructor doesn't allow certain values to be null. + if (className == null || methodName == null) + throw new NullPointerException("invalid argument to constructor"); + } + + /** * Returns the name of the file, or null if unknown. This is usually * obtained from the <code>SourceFile</code> attribute of the class file * format, if present. diff --git a/libjava/classpath/java/lang/String.java b/libjava/classpath/java/lang/String.java index 369d8085a02..231afc77b92 100644 --- a/libjava/classpath/java/lang/String.java +++ b/libjava/classpath/java/lang/String.java @@ -273,7 +273,8 @@ public final class String implements Serializable, Comparable, CharSequence throw new StringIndexOutOfBoundsException("offset: " + offset); if (count < 0) throw new StringIndexOutOfBoundsException("count: " + count); - if (offset + count < 0 || offset + count > ascii.length) + // equivalent to: offset + count < 0 || offset + count > ascii.length + if (ascii.length - offset < count) throw new StringIndexOutOfBoundsException("offset + count: " + (offset + count)); value = new char[count]; @@ -338,7 +339,8 @@ public final class String implements Serializable, Comparable, CharSequence throw new StringIndexOutOfBoundsException("offset: " + offset); if (count < 0) throw new StringIndexOutOfBoundsException("count: " + count); - if (offset + count < 0 || offset + count > data.length) + // equivalent to: offset + count < 0 || offset + count > data.length + if (data.length - offset < count) throw new StringIndexOutOfBoundsException("offset + count: " + (offset + count)); try @@ -418,7 +420,8 @@ public final class String implements Serializable, Comparable, CharSequence throw new StringIndexOutOfBoundsException("offset: " + offset); if (count < 0) throw new StringIndexOutOfBoundsException("count: " + count); - if (offset + count < 0 || offset + count > data.length) + // equivalent to: offset + count < 0 || offset + count > data.length + if (data.length - offset < count) throw new StringIndexOutOfBoundsException("offset + count: " + (offset + count)); int o, c; @@ -533,7 +536,8 @@ public final class String implements Serializable, Comparable, CharSequence throw new StringIndexOutOfBoundsException("offset: " + offset); if (count < 0) throw new StringIndexOutOfBoundsException("count: " + count); - if (offset + count < 0 || offset + count > data.length) + // equivalent to: offset + count < 0 || offset + count > data.length + if (data.length - offset < count) throw new StringIndexOutOfBoundsException("offset + count: " + (offset + count)); if (dont_copy) @@ -1761,7 +1765,7 @@ public final class String implements Serializable, Comparable, CharSequence /** * Return the number of code points between two indices in the - * <code>StringBuffer</code>. An unpaired surrogate counts as a + * <code>String</code>. An unpaired surrogate counts as a * code point for this purpose. Characters outside the indicated * range are not examined, even if the range ends in the middle of a * surrogate pair. @@ -1879,6 +1883,8 @@ public final class String implements Serializable, Comparable, CharSequence * described in s. * @param s the CharSequence * @return true iff this String contains s + * + * @since 1.5 */ public boolean contains (CharSequence s) { diff --git a/libjava/classpath/java/lang/Thread.java b/libjava/classpath/java/lang/Thread.java index 763228c16ef..9afde5bfd03 100644 --- a/libjava/classpath/java/lang/Thread.java +++ b/libjava/classpath/java/lang/Thread.java @@ -38,9 +38,9 @@ exception statement from your version. */ package java.lang; +import gnu.java.util.WeakIdentityHashMap; import java.security.Permission; import java.util.Map; -import java.util.WeakHashMap; /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 * "The Java Language Specification", ISBN 0-201-63451-1 @@ -137,7 +137,7 @@ public class Thread implements Runnable /** Thread local storage. Package accessible for use by * InheritableThreadLocal. */ - WeakHashMap locals; + WeakIdentityHashMap locals; /** * Allocates a new <code>Thread</code> object. This constructor has @@ -996,7 +996,7 @@ public class Thread implements Runnable Map locals = thread.locals; if (locals == null) { - locals = thread.locals = new WeakHashMap(); + locals = thread.locals = new WeakIdentityHashMap(); } return locals; } diff --git a/libjava/classpath/java/lang/ThreadLocal.java b/libjava/classpath/java/lang/ThreadLocal.java index bc839044574..aceb2557a54 100644 --- a/libjava/classpath/java/lang/ThreadLocal.java +++ b/libjava/classpath/java/lang/ThreadLocal.java @@ -1,5 +1,5 @@ /* ThreadLocal -- a variable with a unique value per thread - Copyright (C) 2000, 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 2000, 2002, 2003, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -96,21 +96,6 @@ public class ThreadLocal static final Object NULL = new Object(); /** - * Serves as a key for the Thread.locals WeakHashMap. - * We can't use "this", because a subclass may override equals/hashCode - * and we need to use object identity for the map. - */ - final Key key = new Key(); - - class Key - { - ThreadLocal get() - { - return ThreadLocal.this; - } - } - - /** * Creates a ThreadLocal object without associating any value to it yet. */ public ThreadLocal() @@ -143,11 +128,11 @@ public class ThreadLocal Map map = Thread.getThreadLocals(); // Note that we don't have to synchronize, as only this thread will // ever modify the map. - Object value = map.get(key); + Object value = map.get(this); if (value == null) { value = initialValue(); - map.put(key, value == null ? NULL : value); + map.put(this, value == null ? NULL : value); } return value == NULL ? null : value; } @@ -165,6 +150,6 @@ public class ThreadLocal Map map = Thread.getThreadLocals(); // Note that we don't have to synchronize, as only this thread will // ever modify the map. - map.put(key, value == null ? NULL : value); + map.put(this, value == null ? NULL : value); } } |