This commit is contained in:
Joel Dice 2007-08-20 18:24:54 -06:00
parent e2f3e80bdf
commit 27c8511c5e
6 changed files with 56 additions and 34 deletions

View File

@ -97,6 +97,13 @@ doWrite(JNIEnv* e, jint fd, const jbyte* data, jint length)
} // namespace } // namespace
extern "C" JNIEXPORT jstring JNICALL
Java_java_io_File_toCanonicalPath(JNIEnv* /*e*/, jclass, jstring path)
{
// todo
return path;
}
extern "C" JNIEXPORT jstring JNICALL extern "C" JNIEXPORT jstring JNICALL
Java_java_io_File_toAbsolutePath(JNIEnv* /*e*/, jclass, jstring path) Java_java_io_File_toAbsolutePath(JNIEnv* /*e*/, jclass, jstring path)
{ {

View File

@ -1,7 +1,7 @@
package java.lang; package java.lang;
public class StackTraceElement { public class StackTraceElement {
private static int NativeLine = -2; private static int NativeLine = -1;
private String class_; private String class_;
private String method; private String method;

View File

@ -1,24 +1,30 @@
package java.util; package java.util;
public class ArrayList<T> implements List<T> { public class ArrayList<T> implements List<T> {
private static final int MinimumCapacity = 16;
private Object[] array; private Object[] array;
private int size; private int size;
public ArrayList(int capacity) { public ArrayList(int capacity) {
if (capacity != 0) { resize(capacity);
array = new Object[capacity];
}
} }
public ArrayList() { public ArrayList() {
this(0); this(0);
} }
private void grow() {
if (array == null || size >= array.length) {
resize(array == null ? MinimumCapacity : array.length * 2);
}
}
private void resize() { private void shrink() {
if (array == null || size >= array.length - 1) { if (array.length / 2 >= MinimumCapacity && size <= array.length / 3) {
resize(array == null ? 16 : array.length * 2);
} else if (size <= array.length / 3) {
resize(array.length / 2); resize(array.length / 2);
} else if (size == 0) {
resize(0);
} }
} }
@ -55,8 +61,9 @@ public class ArrayList<T> implements List<T> {
} }
public boolean add(T element) { public boolean add(T element) {
resize(); ++ size;
array[size++] = element; grow();
array[size - 1] = element;
return true; return true;
} }
@ -78,7 +85,7 @@ public class ArrayList<T> implements List<T> {
} }
-- size; -- size;
resize(); shrink();
return v; return v;
} }

View File

@ -1,6 +1,8 @@
package java.util; package java.util;
public class HashMap<K, V> implements Map<K, V> { public class HashMap<K, V> implements Map<K, V> {
private static final int MinimumCapacity = 16;
private int size; private int size;
private Cell[] array; private Cell[] array;
private final Helper helper; private final Helper helper;
@ -46,11 +48,17 @@ public class HashMap<K, V> implements Map<K, V> {
return size; return size;
} }
private void resize() { private void grow() {
if (array == null || size >= array.length * 2) { if (array == null || size >= array.length * 2) {
resize(array == null ? 16 : array.length * 2); resize(array == null ? MinimumCapacity : array.length * 2);
} else if (size <= array.length / 3) { }
}
private void shrink() {
if (array.length / 2 >= MinimumCapacity && size <= array.length / 3) {
resize(array.length / 2); resize(array.length / 2);
} else if (size == 0) {
resize(0);
} }
} }
@ -94,7 +102,7 @@ public class HashMap<K, V> implements Map<K, V> {
private void insert(Cell<K, V> cell) { private void insert(Cell<K, V> cell) {
++ size; ++ size;
resize(); grow();
int index = cell.hashCode() & (array.length - 1); int index = cell.hashCode() & (array.length - 1);
cell.setNext(array[index]); cell.setNext(array[index]);
@ -116,7 +124,7 @@ public class HashMap<K, V> implements Map<K, V> {
} }
} }
resize(); shrink();
} }
private Cell<K, V> putCell(K key, V value) { private Cell<K, V> putCell(K key, V value) {
@ -161,7 +169,7 @@ public class HashMap<K, V> implements Map<K, V> {
} }
} }
resize(); shrink();
} }
return old; return old;
} }

View File

@ -1,4 +1,4 @@
#MAKEFLAGS = -s MAKEFLAGS = -s
arch = $(shell uname -m) arch = $(shell uname -m)
ifeq ($(arch),i586) ifeq ($(arch),i586)

View File

@ -616,7 +616,7 @@ run(Thread* t)
{ {
pushObject(t, objectArrayBody(t, array, index)); pushObject(t, objectArrayBody(t, array, index));
} else { } else {
object message = makeString(t, "%d not in [0,%d]", index, object message = makeString(t, "%d not in [0,%d)", index,
objectArrayLength(t, array)); objectArrayLength(t, array));
exception = makeArrayIndexOutOfBoundsException(t, message); exception = makeArrayIndexOutOfBoundsException(t, message);
goto throw_; goto throw_;
@ -638,7 +638,7 @@ run(Thread* t)
{ {
set(t, objectArrayBody(t, array, index), value); set(t, objectArrayBody(t, array, index), value);
} else { } else {
object message = makeString(t, "%d not in [0,%d]", index, object message = makeString(t, "%d not in [0,%d)", index,
objectArrayLength(t, array)); objectArrayLength(t, array));
exception = makeArrayIndexOutOfBoundsException(t, message); exception = makeArrayIndexOutOfBoundsException(t, message);
goto throw_; goto throw_;
@ -748,7 +748,7 @@ run(Thread* t)
{ {
pushInt(t, byteArrayBody(t, array, index)); pushInt(t, byteArrayBody(t, array, index));
} else { } else {
object message = makeString(t, "%d not in [0,%d]", index, object message = makeString(t, "%d not in [0,%d)", index,
byteArrayLength(t, array)); byteArrayLength(t, array));
exception = makeArrayIndexOutOfBoundsException(t, message); exception = makeArrayIndexOutOfBoundsException(t, message);
goto throw_; goto throw_;
@ -770,7 +770,7 @@ run(Thread* t)
{ {
byteArrayBody(t, array, index) = value; byteArrayBody(t, array, index) = value;
} else { } else {
object message = makeString(t, "%d not in [0,%d]", index, object message = makeString(t, "%d not in [0,%d)", index,
byteArrayLength(t, array)); byteArrayLength(t, array));
exception = makeArrayIndexOutOfBoundsException(t, message); exception = makeArrayIndexOutOfBoundsException(t, message);
goto throw_; goto throw_;
@ -795,7 +795,7 @@ run(Thread* t)
{ {
pushInt(t, charArrayBody(t, array, index)); pushInt(t, charArrayBody(t, array, index));
} else { } else {
object message = makeString(t, "%d not in [0,%d]", index, object message = makeString(t, "%d not in [0,%d)", index,
charArrayLength(t, array)); charArrayLength(t, array));
exception = makeArrayIndexOutOfBoundsException(t, message); exception = makeArrayIndexOutOfBoundsException(t, message);
goto throw_; goto throw_;
@ -817,7 +817,7 @@ run(Thread* t)
{ {
charArrayBody(t, array, index) = value; charArrayBody(t, array, index) = value;
} else { } else {
object message = makeString(t, "%d not in [0,%d]", index, object message = makeString(t, "%d not in [0,%d)", index,
charArrayLength(t, array)); charArrayLength(t, array));
exception = makeArrayIndexOutOfBoundsException(t, message); exception = makeArrayIndexOutOfBoundsException(t, message);
goto throw_; goto throw_;
@ -878,7 +878,7 @@ run(Thread* t)
memcpy(&d, &doubleArrayBody(t, array, index), sizeof(double)); memcpy(&d, &doubleArrayBody(t, array, index), sizeof(double));
pushDouble(t, d); pushDouble(t, d);
} else { } else {
object message = makeString(t, "%d not in [0,%d]", index, object message = makeString(t, "%d not in [0,%d)", index,
doubleArrayLength(t, array)); doubleArrayLength(t, array));
exception = makeArrayIndexOutOfBoundsException(t, message); exception = makeArrayIndexOutOfBoundsException(t, message);
goto throw_; goto throw_;
@ -900,7 +900,7 @@ run(Thread* t)
{ {
memcpy(&doubleArrayBody(t, array, index), &value, sizeof(uint64_t)); memcpy(&doubleArrayBody(t, array, index), &value, sizeof(uint64_t));
} else { } else {
object message = makeString(t, "%d not in [0,%d]", index, object message = makeString(t, "%d not in [0,%d)", index,
doubleArrayLength(t, array)); doubleArrayLength(t, array));
exception = makeArrayIndexOutOfBoundsException(t, message); exception = makeArrayIndexOutOfBoundsException(t, message);
goto throw_; goto throw_;
@ -1063,7 +1063,7 @@ run(Thread* t)
float f; memcpy(&f, &floatArrayBody(t, array, index), sizeof(float)); float f; memcpy(&f, &floatArrayBody(t, array, index), sizeof(float));
pushFloat(t, f); pushFloat(t, f);
} else { } else {
object message = makeString(t, "%d not in [0,%d]", index, object message = makeString(t, "%d not in [0,%d)", index,
floatArrayLength(t, array)); floatArrayLength(t, array));
exception = makeArrayIndexOutOfBoundsException(t, message); exception = makeArrayIndexOutOfBoundsException(t, message);
goto throw_; goto throw_;
@ -1085,7 +1085,7 @@ run(Thread* t)
{ {
memcpy(&floatArrayBody(t, array, index), &value, sizeof(uint32_t)); memcpy(&floatArrayBody(t, array, index), &value, sizeof(uint32_t));
} else { } else {
object message = makeString(t, "%d not in [0,%d]", index, object message = makeString(t, "%d not in [0,%d)", index,
floatArrayLength(t, array)); floatArrayLength(t, array));
exception = makeArrayIndexOutOfBoundsException(t, message); exception = makeArrayIndexOutOfBoundsException(t, message);
goto throw_; goto throw_;
@ -1276,7 +1276,7 @@ run(Thread* t)
{ {
pushInt(t, intArrayBody(t, array, index)); pushInt(t, intArrayBody(t, array, index));
} else { } else {
object message = makeString(t, "%d not in [0,%d]", index, object message = makeString(t, "%d not in [0,%d)", index,
intArrayLength(t, array)); intArrayLength(t, array));
exception = makeArrayIndexOutOfBoundsException(t, message); exception = makeArrayIndexOutOfBoundsException(t, message);
goto throw_; goto throw_;
@ -1305,7 +1305,7 @@ run(Thread* t)
{ {
intArrayBody(t, array, index) = value; intArrayBody(t, array, index) = value;
} else { } else {
object message = makeString(t, "%d not in [0,%d]", index, object message = makeString(t, "%d not in [0,%d)", index,
intArrayLength(t, array)); intArrayLength(t, array));
exception = makeArrayIndexOutOfBoundsException(t, message); exception = makeArrayIndexOutOfBoundsException(t, message);
goto throw_; goto throw_;
@ -1803,7 +1803,7 @@ run(Thread* t)
{ {
pushLong(t, longArrayBody(t, array, index)); pushLong(t, longArrayBody(t, array, index));
} else { } else {
object message = makeString(t, "%d not in [0,%d]", index, object message = makeString(t, "%d not in [0,%d)", index,
longArrayLength(t, array)); longArrayLength(t, array));
exception = makeArrayIndexOutOfBoundsException(t, message); exception = makeArrayIndexOutOfBoundsException(t, message);
goto throw_; goto throw_;
@ -1832,7 +1832,7 @@ run(Thread* t)
{ {
longArrayBody(t, array, index) = value; longArrayBody(t, array, index) = value;
} else { } else {
object message = makeString(t, "%d not in [0,%d]", index, object message = makeString(t, "%d not in [0,%d)", index,
longArrayLength(t, array)); longArrayLength(t, array));
exception = makeArrayIndexOutOfBoundsException(t, message); exception = makeArrayIndexOutOfBoundsException(t, message);
goto throw_; goto throw_;
@ -2287,7 +2287,7 @@ run(Thread* t)
{ {
pushInt(t, shortArrayBody(t, array, index)); pushInt(t, shortArrayBody(t, array, index));
} else { } else {
object message = makeString(t, "%d not in [0,%d]", index, object message = makeString(t, "%d not in [0,%d)", index,
shortArrayLength(t, array)); shortArrayLength(t, array));
exception = makeArrayIndexOutOfBoundsException(t, message); exception = makeArrayIndexOutOfBoundsException(t, message);
goto throw_; goto throw_;
@ -2309,7 +2309,7 @@ run(Thread* t)
{ {
shortArrayBody(t, array, index) = value; shortArrayBody(t, array, index) = value;
} else { } else {
object message = makeString(t, "%d not in [0,%d]", index, object message = makeString(t, "%d not in [0,%d)", index,
shortArrayLength(t, array)); shortArrayLength(t, array));
exception = makeArrayIndexOutOfBoundsException(t, message); exception = makeArrayIndexOutOfBoundsException(t, message);
goto throw_; goto throw_;