summaryrefslogtreecommitdiff
path: root/java/lang
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2006-01-10 15:59:36 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2006-01-10 15:59:36 +0000
commite2880df85352a4f46c1fc8b28c4cd08540a2daed (patch)
treeaee81230bdbf73bd817662e0ce7a4665939ab41d /java/lang
parent05f169147352fa3eeb9726f3d57597a83eb7d64d (diff)
downloadclasspath-e2880df85352a4f46c1fc8b28c4cd08540a2daed.tar.gz
2006-01-10 Andrew John Hughes <gnu_andrew@member.fsf.org>
Merge of HEAD --> generics branch for the period 2005/11/27 to 2006/01/09.
Diffstat (limited to 'java/lang')
-rw-r--r--java/lang/Character.java11
-rw-r--r--java/lang/Class.java8
-rw-r--r--java/lang/Double.java75
-rw-r--r--java/lang/Float.java77
-rw-r--r--java/lang/InheritableThreadLocal.java14
-rw-r--r--java/lang/String.java16
-rw-r--r--java/lang/Thread.java6
-rw-r--r--java/lang/ThreadLocal.java35
8 files changed, 190 insertions, 52 deletions
diff --git a/java/lang/Character.java b/java/lang/Character.java
index e33c15585..b0535e8b6 100644
--- a/java/lang/Character.java
+++ b/java/lang/Character.java
@@ -3054,11 +3054,11 @@ public final class Character implements Serializable, Comparable<Character>
{
// 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;
@@ -3167,7 +3167,8 @@ public final class Character implements Serializable, Comparable<Character>
*/
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/java/lang/Class.java b/java/lang/Class.java
index 82d47819b..af5f3c723 100644
--- a/java/lang/Class.java
+++ b/java/lang/Class.java
@@ -590,8 +590,7 @@ public final class Class<T>
/**
* 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
@@ -843,7 +842,10 @@ public final class Class<T>
*/
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/java/lang/Double.java b/java/lang/Double.java
index f79432a99..c71620314 100644
--- a/java/lang/Double.java
+++ b/java/lang/Double.java
@@ -175,6 +175,81 @@ public final class Double extends Number implements Comparable<Double>
}
/**
+ * 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/java/lang/Float.java b/java/lang/Float.java
index 56cc8e136..1e85922be 100644
--- a/java/lang/Float.java
+++ b/java/lang/Float.java
@@ -185,6 +185,83 @@ public final class Float extends Number implements Comparable<Float>
}
/**
+ * 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/java/lang/InheritableThreadLocal.java b/java/lang/InheritableThreadLocal.java
index 9d02e921d..bbcbc0c2f 100644
--- a/java/lang/InheritableThreadLocal.java
+++ b/java/lang/InheritableThreadLocal.java
@@ -1,5 +1,5 @@
/* InheritableThreadLocal -- a ThreadLocal which inherits values across threads
- Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001, 2002, 2003, 2004, 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
@@ -101,16 +102,15 @@ public class InheritableThreadLocal<T> extends ThreadLocal<T>
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/java/lang/String.java b/java/lang/String.java
index fdec7f929..c3c92a178 100644
--- a/java/lang/String.java
+++ b/java/lang/String.java
@@ -277,7 +277,8 @@ public final class String
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];
@@ -342,7 +343,8 @@ public final class String
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
@@ -422,7 +424,8 @@ public final class String
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;
@@ -537,7 +540,8 @@ public final class String
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)
@@ -1763,7 +1767,7 @@ public final class String
/**
* 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.
@@ -1881,6 +1885,8 @@ public final class String
* 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/java/lang/Thread.java b/java/lang/Thread.java
index 5430facf5..e64402610 100644
--- a/java/lang/Thread.java
+++ b/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
@@ -141,7 +141,7 @@ public class Thread implements Runnable
/** Thread local storage. Package accessible for use by
* InheritableThreadLocal.
*/
- WeakHashMap locals;
+ WeakIdentityHashMap locals;
/** The uncaught exception handler. */
UncaughtExceptionHandler exceptionHandler;
@@ -1015,7 +1015,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/java/lang/ThreadLocal.java b/java/lang/ThreadLocal.java
index 670c13a03..f599cfb44 100644
--- a/java/lang/ThreadLocal.java
+++ b/java/lang/ThreadLocal.java
@@ -1,5 +1,5 @@
/* ThreadLocal -- a variable with a unique value per thread
- Copyright (C) 2000, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -96,29 +96,6 @@ public class ThreadLocal<T>
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(this);
-
- static class Key
- {
- private ThreadLocal outer;
-
- Key(ThreadLocal outer)
- {
- this.outer = outer;
- }
-
- ThreadLocal get()
- {
- return outer;
- }
- }
-
-
- /**
* Creates a ThreadLocal object without associating any value to it yet.
*/
public ThreadLocal()
@@ -148,14 +125,14 @@ public class ThreadLocal<T>
*/
public T get()
{
- Map<Key,T> map = (Map<Key,T>) Thread.getThreadLocals();
+ Map<ThreadLocal<T>,T> map = (Map<ThreadLocal<T>,T>) Thread.getThreadLocals();
// Note that we don't have to synchronize, as only this thread will
// ever modify the map.
- T value = map.get(key);
+ T value = map.get(this);
if (value == null)
{
value = initialValue();
- map.put(key, value == null ? (T) NULL : value);
+ map.put(this, (T) (value == null ? NULL : value));
}
return value == (T) NULL ? null : value;
}
@@ -173,7 +150,7 @@ public class ThreadLocal<T>
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);
}
/**
@@ -184,6 +161,6 @@ public class ThreadLocal<T>
public void remove()
{
Map map = Thread.getThreadLocals();
- map.remove(key);
+ map.remove(this);
}
}