From 27c8511c5e9b4b966a4b27e9dde644577f10277a Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 20 Aug 2007 18:24:54 -0600 Subject: [PATCH] bugfixes --- classpath/java-io.cpp | 7 +++++ classpath/java/lang/StackTraceElement.java | 2 +- classpath/java/util/ArrayList.java | 27 +++++++++++------- classpath/java/util/HashMap.java | 20 ++++++++++---- makefile | 2 +- src/run.cpp | 32 +++++++++++----------- 6 files changed, 56 insertions(+), 34 deletions(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index 3110c068c2..f945f44bc8 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -97,6 +97,13 @@ doWrite(JNIEnv* e, jint fd, const jbyte* data, jint length) } // namespace +extern "C" JNIEXPORT jstring JNICALL +Java_java_io_File_toCanonicalPath(JNIEnv* /*e*/, jclass, jstring path) +{ + // todo + return path; +} + extern "C" JNIEXPORT jstring JNICALL Java_java_io_File_toAbsolutePath(JNIEnv* /*e*/, jclass, jstring path) { diff --git a/classpath/java/lang/StackTraceElement.java b/classpath/java/lang/StackTraceElement.java index acf1986dc8..269a686a1b 100644 --- a/classpath/java/lang/StackTraceElement.java +++ b/classpath/java/lang/StackTraceElement.java @@ -1,7 +1,7 @@ package java.lang; public class StackTraceElement { - private static int NativeLine = -2; + private static int NativeLine = -1; private String class_; private String method; diff --git a/classpath/java/util/ArrayList.java b/classpath/java/util/ArrayList.java index d1da10da40..f440f06794 100644 --- a/classpath/java/util/ArrayList.java +++ b/classpath/java/util/ArrayList.java @@ -1,24 +1,30 @@ package java.util; public class ArrayList implements List { + private static final int MinimumCapacity = 16; + private Object[] array; private int size; public ArrayList(int capacity) { - if (capacity != 0) { - array = new Object[capacity]; - } + resize(capacity); } public ArrayList() { this(0); } + + private void grow() { + if (array == null || size >= array.length) { + resize(array == null ? MinimumCapacity : array.length * 2); + } + } - private void resize() { - if (array == null || size >= array.length - 1) { - resize(array == null ? 16 : 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); + } else if (size == 0) { + resize(0); } } @@ -55,8 +61,9 @@ public class ArrayList implements List { } public boolean add(T element) { - resize(); - array[size++] = element; + ++ size; + grow(); + array[size - 1] = element; return true; } @@ -78,7 +85,7 @@ public class ArrayList implements List { } -- size; - resize(); + shrink(); return v; } diff --git a/classpath/java/util/HashMap.java b/classpath/java/util/HashMap.java index bbfb51cb49..e3bede0d3e 100644 --- a/classpath/java/util/HashMap.java +++ b/classpath/java/util/HashMap.java @@ -1,6 +1,8 @@ package java.util; public class HashMap implements Map { + private static final int MinimumCapacity = 16; + private int size; private Cell[] array; private final Helper helper; @@ -46,11 +48,17 @@ public class HashMap implements Map { return size; } - private void resize() { + private void grow() { if (array == null || size >= array.length * 2) { - resize(array == null ? 16 : array.length * 2); - } else if (size <= array.length / 3) { + resize(array == null ? MinimumCapacity : array.length * 2); + } + } + + private void shrink() { + if (array.length / 2 >= MinimumCapacity && size <= array.length / 3) { resize(array.length / 2); + } else if (size == 0) { + resize(0); } } @@ -94,7 +102,7 @@ public class HashMap implements Map { private void insert(Cell cell) { ++ size; - resize(); + grow(); int index = cell.hashCode() & (array.length - 1); cell.setNext(array[index]); @@ -116,7 +124,7 @@ public class HashMap implements Map { } } - resize(); + shrink(); } private Cell putCell(K key, V value) { @@ -161,7 +169,7 @@ public class HashMap implements Map { } } - resize(); + shrink(); } return old; } diff --git a/makefile b/makefile index 3ad44f87ef..ff0ad44095 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -#MAKEFLAGS = -s +MAKEFLAGS = -s arch = $(shell uname -m) ifeq ($(arch),i586) diff --git a/src/run.cpp b/src/run.cpp index f70e538512..0509a92ef3 100644 --- a/src/run.cpp +++ b/src/run.cpp @@ -616,7 +616,7 @@ run(Thread* t) { pushObject(t, objectArrayBody(t, array, index)); } else { - object message = makeString(t, "%d not in [0,%d]", index, + object message = makeString(t, "%d not in [0,%d)", index, objectArrayLength(t, array)); exception = makeArrayIndexOutOfBoundsException(t, message); goto throw_; @@ -638,7 +638,7 @@ run(Thread* t) { set(t, objectArrayBody(t, array, index), value); } else { - object message = makeString(t, "%d not in [0,%d]", index, + object message = makeString(t, "%d not in [0,%d)", index, objectArrayLength(t, array)); exception = makeArrayIndexOutOfBoundsException(t, message); goto throw_; @@ -748,7 +748,7 @@ run(Thread* t) { pushInt(t, byteArrayBody(t, array, index)); } else { - object message = makeString(t, "%d not in [0,%d]", index, + object message = makeString(t, "%d not in [0,%d)", index, byteArrayLength(t, array)); exception = makeArrayIndexOutOfBoundsException(t, message); goto throw_; @@ -770,7 +770,7 @@ run(Thread* t) { byteArrayBody(t, array, index) = value; } else { - object message = makeString(t, "%d not in [0,%d]", index, + object message = makeString(t, "%d not in [0,%d)", index, byteArrayLength(t, array)); exception = makeArrayIndexOutOfBoundsException(t, message); goto throw_; @@ -795,7 +795,7 @@ run(Thread* t) { pushInt(t, charArrayBody(t, array, index)); } else { - object message = makeString(t, "%d not in [0,%d]", index, + object message = makeString(t, "%d not in [0,%d)", index, charArrayLength(t, array)); exception = makeArrayIndexOutOfBoundsException(t, message); goto throw_; @@ -817,7 +817,7 @@ run(Thread* t) { charArrayBody(t, array, index) = value; } else { - object message = makeString(t, "%d not in [0,%d]", index, + object message = makeString(t, "%d not in [0,%d)", index, charArrayLength(t, array)); exception = makeArrayIndexOutOfBoundsException(t, message); goto throw_; @@ -878,7 +878,7 @@ run(Thread* t) memcpy(&d, &doubleArrayBody(t, array, index), sizeof(double)); pushDouble(t, d); } else { - object message = makeString(t, "%d not in [0,%d]", index, + object message = makeString(t, "%d not in [0,%d)", index, doubleArrayLength(t, array)); exception = makeArrayIndexOutOfBoundsException(t, message); goto throw_; @@ -900,7 +900,7 @@ run(Thread* t) { memcpy(&doubleArrayBody(t, array, index), &value, sizeof(uint64_t)); } else { - object message = makeString(t, "%d not in [0,%d]", index, + object message = makeString(t, "%d not in [0,%d)", index, doubleArrayLength(t, array)); exception = makeArrayIndexOutOfBoundsException(t, message); goto throw_; @@ -1063,7 +1063,7 @@ run(Thread* t) float f; memcpy(&f, &floatArrayBody(t, array, index), sizeof(float)); pushFloat(t, f); } else { - object message = makeString(t, "%d not in [0,%d]", index, + object message = makeString(t, "%d not in [0,%d)", index, floatArrayLength(t, array)); exception = makeArrayIndexOutOfBoundsException(t, message); goto throw_; @@ -1085,7 +1085,7 @@ run(Thread* t) { memcpy(&floatArrayBody(t, array, index), &value, sizeof(uint32_t)); } else { - object message = makeString(t, "%d not in [0,%d]", index, + object message = makeString(t, "%d not in [0,%d)", index, floatArrayLength(t, array)); exception = makeArrayIndexOutOfBoundsException(t, message); goto throw_; @@ -1276,7 +1276,7 @@ run(Thread* t) { pushInt(t, intArrayBody(t, array, index)); } else { - object message = makeString(t, "%d not in [0,%d]", index, + object message = makeString(t, "%d not in [0,%d)", index, intArrayLength(t, array)); exception = makeArrayIndexOutOfBoundsException(t, message); goto throw_; @@ -1305,7 +1305,7 @@ run(Thread* t) { intArrayBody(t, array, index) = value; } else { - object message = makeString(t, "%d not in [0,%d]", index, + object message = makeString(t, "%d not in [0,%d)", index, intArrayLength(t, array)); exception = makeArrayIndexOutOfBoundsException(t, message); goto throw_; @@ -1803,7 +1803,7 @@ run(Thread* t) { pushLong(t, longArrayBody(t, array, index)); } else { - object message = makeString(t, "%d not in [0,%d]", index, + object message = makeString(t, "%d not in [0,%d)", index, longArrayLength(t, array)); exception = makeArrayIndexOutOfBoundsException(t, message); goto throw_; @@ -1832,7 +1832,7 @@ run(Thread* t) { longArrayBody(t, array, index) = value; } else { - object message = makeString(t, "%d not in [0,%d]", index, + object message = makeString(t, "%d not in [0,%d)", index, longArrayLength(t, array)); exception = makeArrayIndexOutOfBoundsException(t, message); goto throw_; @@ -2287,7 +2287,7 @@ run(Thread* t) { pushInt(t, shortArrayBody(t, array, index)); } else { - object message = makeString(t, "%d not in [0,%d]", index, + object message = makeString(t, "%d not in [0,%d)", index, shortArrayLength(t, array)); exception = makeArrayIndexOutOfBoundsException(t, message); goto throw_; @@ -2309,7 +2309,7 @@ run(Thread* t) { shortArrayBody(t, array, index) = value; } else { - object message = makeString(t, "%d not in [0,%d]", index, + object message = makeString(t, "%d not in [0,%d)", index, shortArrayLength(t, array)); exception = makeArrayIndexOutOfBoundsException(t, message); goto throw_;