GC stress fixes and other bugfixes; classpath progress

This commit is contained in:
Joel Dice
2007-07-29 17:32:23 -06:00
parent d5a00c4556
commit a2bd7d0668
27 changed files with 463 additions and 75 deletions

View File

@ -3,12 +3,31 @@ package java.lang;
public final class Boolean {
public static final Class TYPE = Class.forCanonicalName("Z");
public static final Boolean FALSE = new Boolean(false);
public static final Boolean TRUE = new Boolean(true);
private final boolean value;
public Boolean(boolean value) {
this.value = value;
}
public boolean equals(Object o) {
return o instanceof Boolean && ((Boolean) o).value == value;
}
public int hashCode() {
return (value ? 1 : 0);
}
public String toString() {
return toString(value);
}
public static String toString(boolean v) {
return (v ? "true" : "false");
}
public boolean booleanValue() {
return value;
}

View File

@ -9,6 +9,26 @@ public final class Byte extends Number {
this.value = value;
}
public boolean equals(Object o) {
return o instanceof Byte && ((Byte) o).value == value;
}
public int hashCode() {
return value;
}
public String toString() {
return toString(value);
}
public static String toString(byte v, int radix) {
return Long.toString(v, radix);
}
public static String toString(byte v) {
return toString(v, 10);
}
public byte byteValue() {
return value;
}

View File

@ -9,6 +9,22 @@ public final class Character {
this.value = value;
}
public boolean equals(Object o) {
return o instanceof Character && ((Character) o).value == value;
}
public int hashCode() {
return (int) value;
}
public String toString() {
return toString(value);
}
public static String toString(char v) {
return new String(new char[] { v });
}
public char charValue() {
return value;
}

View File

@ -38,7 +38,7 @@ public final class Class <T> {
} else if (name.startsWith("L")) {
return forName(name.substring(1, name.length() - 1));
} else {
if (name.length() == 0) {
if (name.length() == 1) {
return primitiveClass(name.charAt(0));
} else {
throw new ClassNotFoundException(name);

View File

@ -0,0 +1,3 @@
package java.lang;
public interface Cloneable { }

View File

@ -1,14 +1,35 @@
package java.lang;
public final class Double {
public final class Double extends Number {
public static final Class TYPE = Class.forCanonicalName("D");
private final double value;
public Double(String value) {
this.value = parseDouble(value);
}
public Double(double value) {
this.value = value;
}
public boolean equals(Object o) {
return o instanceof Double && ((Double) o).value == value;
}
public int hashCode() {
long v = doubleToRawLongBits(value);
return (int) ((v >> 32) ^ (v & 0xFF));
}
public String toString() {
return toString(value);
}
public static String toString(double v) {
return "todo";
}
public byte byteValue() {
return (byte) value;
}
@ -32,4 +53,14 @@ public final class Double {
public double doubleValue() {
return value;
}
public static double parseDouble(String s) {
// todo
return 0.0;
}
public static long doubleToRawLongBits(double value) {
// todo
return 0;
}
}

View File

@ -9,6 +9,22 @@ public final class Float extends Number {
this.value = value;
}
public boolean equals(Object o) {
return o instanceof Float && ((Float) o).value == value;
}
public int hashCode() {
return floatToRawIntBits(value);
}
public String toString() {
return toString(value);
}
public static String toString(float v) {
return "todo";
}
public byte byteValue() {
return (byte) value;
}
@ -32,4 +48,9 @@ public final class Float extends Number {
public double doubleValue() {
return (double) value;
}
public static int floatToRawIntBits(float value) {
// todo
return 0;
}
}

View File

@ -3,12 +3,35 @@ package java.lang;
public final class Integer extends Number {
public static final Class TYPE = Class.forCanonicalName("I");
public static final int MIN_VALUE = 0x80000000;
public static final int MAX_VALUE = 0x7FFFFFFF;
private final int value;
public Integer(int value) {
this.value = value;
}
public boolean equals(Object o) {
return o instanceof Integer && ((Integer) o).value == value;
}
public int hashCode() {
return value;
}
public String toString() {
return toString(value);
}
public static String toString(int v, int radix) {
return Long.toString(v, radix);
}
public static String toString(int v) {
return toString(v, 10);
}
public byte byteValue() {
return (byte) value;
}

View File

@ -9,6 +9,54 @@ public final class Long extends Number {
this.value = value;
}
public boolean equals(Object o) {
return o instanceof Long && ((Long) o).value == value;
}
public int hashCode() {
return (int) ((value >> 32) ^ (value & 0xFF));
}
public String toString() {
return String.valueOf(value);
}
public static String toString(long v, int radix) {
if (radix < 1 || radix > 36) {
throw new IllegalArgumentException("radix " + radix + " not in [1,36]");
}
if (v == 0) {
return "0";
}
int size = (v < 0 ? 1 : 0);
for (long n = v; n > 0; n /= radix) ++size;
char[] array = new char[size];
int i = array.length - 1;
for (long n = v; n > 0; n /= radix) {
long digit = n % radix;
if (digit >= 0 && digit <= 9) {
array[i] = (char) ('0' + digit);
} else {
array[i] = (char) ('a' + (digit - 10));
}
--i;
}
if (v < 0) {
array[i] = '-';
}
return new String(array);
}
public static String toString(long v) {
return toString(v, 10);
}
public byte byteValue() {
return (byte) value;
}
@ -49,7 +97,7 @@ public final class Long extends Number {
long digit = ((c >= '0' && c <= '9') ? (c - '0') : (c - 'a' + 10));
number += digit * pow(radix, (s.length() - i - 1));
} else {
throw new NumberFormatException("Invalid character " + c + " code " +
throw new NumberFormatException("invalid character " + c + " code " +
(int) c);
}
}

View File

@ -0,0 +1,77 @@
package java.lang;
public final class Math {
private Math() { }
public static int abs(int v) {
return (v < 0 ? -v : v);
}
public static long round(double v) {
return (long) (v + 0.5);
}
public static int round(float v) {
return (int) (v + 0.5);
}
public static double floor(double v) {
// todo
return 0;
}
public static double ceil(double v) {
// todo
return 0;
}
public static double exp(double v) {
// todo
return 0;
}
public static double log(double v) {
// todo
return 0;
}
public static double cos(double v) {
// todo
return 0;
}
public static double sin(double v) {
// todo
return 0;
}
public static double tan(double v) {
// todo
return 0;
}
public static double acos(double v) {
// todo
return 0;
}
public static double asin(double v) {
// todo
return 0;
}
public static double atan(double v) {
// todo
return 0;
}
public static double sqrt(double v) {
// todo
return 0;
}
public static double pow(double v, double e) {
// todo
return 0;
}
}

View File

@ -9,6 +9,26 @@ public final class Short extends Number {
this.value = value;
}
public boolean equals(Object o) {
return o instanceof Short && ((Short) o).value == value;
}
public int hashCode() {
return value;
}
public String toString() {
return toString(value);
}
public static String toString(short v, int radix) {
return Long.toString(v, radix);
}
public static String toString(short v) {
return toString(v, 10);
}
public byte byteValue() {
return (byte) value;
}

View File

@ -14,6 +14,10 @@ public final class String implements Comparable<String> {
this(data, offset, length, true);
}
public String(char[] data) {
this(data, 0, data.length);
}
public String(byte[] data, int offset, int length, boolean copy) {
this((Object) data, offset, length, copy);
}
@ -22,6 +26,10 @@ public final class String implements Comparable<String> {
this(data, offset, length, true);
}
public String(byte[] data) {
this(data, 0, data.length);
}
private String(Object data, int offset, int length, boolean copy) {
if (copy) {
Object c;
@ -41,6 +49,10 @@ public final class String implements Comparable<String> {
}
}
public String toString() {
return this;
}
public int length() {
return length;
}
@ -91,6 +103,26 @@ public final class String implements Comparable<String> {
}
}
public int indexOf(char c) {
for (int i = 0; i < length - 1; ++i) {
if (charAt(i) == c) {
return i;
}
}
return -1;
}
public int lastIndexOf(char c) {
for (int i = length - 1; i >= 0; --i) {
if (charAt(i) == c) {
return i;
}
}
return -1;
}
public int indexOf(String s) {
if (s.length == 0) return 0;
@ -232,29 +264,35 @@ public final class String implements Comparable<String> {
public native String intern();
public static String valueOf(boolean v) {
return Boolean.toString(v);
}
public static String valueOf(byte v) {
return Byte.toString(v);
}
public static String valueOf(short v) {
return Short.toString(v);
}
public static String valueOf(char v) {
return Character.toString(v);
}
public static String valueOf(int v) {
return valueOf((long) v);
return Integer.toString(v);
}
public static String valueOf(long v) {
if (v == 0) {
return valueOf('0');
} else {
final int Max = 21;
char[] array = new char[Max];
int index = Max;
long x = (v >= 0 ? v : -v);
return Long.toString(v);
}
while (x != 0) {
array[--index] = (char) ('0' + (x % 10));
x /= 10;
}
public static String valueOf(float v) {
return Float.toString(v);
}
if (v < 0) {
array[--index] = '-';
}
return new String(array, index, Max - index, false);
}
public static String valueOf(double v) {
return Double.toString(v);
}
}

View File

@ -1,7 +1,15 @@
package java.lang;
public class StringBuffer {
private final StringBuilder sb = new StringBuilder();
private final StringBuilder sb;
public StringBuffer(int capacity) {
sb = new StringBuilder(capacity);
}
public StringBuffer() {
this(0);
}
public synchronized StringBuffer append(String s) {
sb.append(s);

View File

@ -4,6 +4,12 @@ public class StringBuilder {
private Cell chain;
private int length;
public StringBuilder(int capacity) { }
public StringBuilder() {
this(0);
}
public StringBuilder append(String s) {
if (s.length() > 0) {
chain = new Cell(s, chain);