From 4694d75553b10ed615d2464b594083a5312a2902 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 16 Jun 2008 10:08:51 -0600 Subject: [PATCH 1/7] implement Date.toString, which just defers to ctime for now --- classpath/java-util.cpp | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 classpath/java-util.cpp diff --git a/classpath/java-util.cpp b/classpath/java-util.cpp new file mode 100644 index 0000000000..17dac0e960 --- /dev/null +++ b/classpath/java-util.cpp @@ -0,0 +1,48 @@ +/* Copyright (c) 2008, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +#include "time.h" +#include "jni.h" +#include "jni-util.h" + +namespace { + +void +removeNewline(char* s) +{ + for (; s; ++s) { + if (*s == '\n') { + *s = 0; + break; + } + } +} + +} // namespace + +extern "C" JNIEXPORT jstring JNICALL +Java_java_util_Date_toString(JNIEnv* e, jclass c UNUSED, jlong when) +{ + time_t time = when / 1000; + +#ifdef WIN32 + e->MonitorEnter(c); + char* s = ctime(&time); + removeNewline(s); + jstring r = e->NewStringUTF(s); + e->MonitorExit(c); + return r; +#else + char buffer[27]; + ctime_r(&time, buffer); + removeNewline(buffer); + return e->NewStringUTF(buffer); +#endif +} From 2bfe6f0d1363f87b9d2216b510615539d32c14d3 Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Mon, 16 Jun 2008 10:55:29 -0600 Subject: [PATCH 2/7] Ensure we align the stack before any time we might enter a C function from generated code --- src/compile.cpp | 54 ++++++++++++++++++++++++------------------------- src/machine.cpp | 2 +- src/machine.h | 2 +- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/compile.cpp b/src/compile.cpp index ec3c1d9235..364046dd84 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -28,7 +28,7 @@ vmCall(); namespace { const bool Verbose = false; -const bool DebugNatives = false; +const bool DebugNatives = true; const bool DebugCallTable = false; const bool DebugMethodTree = false; const bool DebugFrameMaps = false; @@ -1212,7 +1212,7 @@ findInterfaceMethodFromInstance(MyThread* t, object method, object instance) } } -intptr_t +intptr_t FORCE_ALIGN compareDoublesG(uint64_t bi, uint64_t ai) { double a = bitsToDouble(ai); @@ -1229,7 +1229,7 @@ compareDoublesG(uint64_t bi, uint64_t ai) } } -intptr_t +intptr_t FORCE_ALIGN compareDoublesL(uint64_t bi, uint64_t ai) { double a = bitsToDouble(ai); @@ -1246,7 +1246,7 @@ compareDoublesL(uint64_t bi, uint64_t ai) } } -intptr_t +intptr_t FORCE_ALIGN compareFloatsG(uint32_t bi, uint32_t ai) { float a = bitsToFloat(ai); @@ -1263,7 +1263,7 @@ compareFloatsG(uint32_t bi, uint32_t ai) } } -intptr_t +intptr_t FORCE_ALIGN compareFloatsL(uint32_t bi, uint32_t ai) { float a = bitsToFloat(ai); @@ -1280,79 +1280,79 @@ compareFloatsL(uint32_t bi, uint32_t ai) } } -uint64_t +uint64_t FORCE_ALIGN addDouble(uint64_t b, uint64_t a) { return doubleToBits(bitsToDouble(a) + bitsToDouble(b)); } -uint64_t +uint64_t FORCE_ALIGN subtractDouble(uint64_t b, uint64_t a) { return doubleToBits(bitsToDouble(a) - bitsToDouble(b)); } -uint64_t +uint64_t FORCE_ALIGN multiplyDouble(uint64_t b, uint64_t a) { return doubleToBits(bitsToDouble(a) * bitsToDouble(b)); } -uint64_t +uint64_t FORCE_ALIGN divideDouble(uint64_t b, uint64_t a) { return doubleToBits(bitsToDouble(a) / bitsToDouble(b)); } -uint64_t +uint64_t FORCE_ALIGN moduloDouble(uint64_t b, uint64_t a) { return doubleToBits(fmod(bitsToDouble(a), bitsToDouble(b))); } -uint64_t +uint64_t FORCE_ALIGN negateDouble(uint64_t a) { return doubleToBits(- bitsToDouble(a)); } -uint32_t +uint32_t FORCE_ALIGN doubleToFloat(int64_t a) { return floatToBits(static_cast(bitsToDouble(a))); } -int32_t +int32_t FORCE_ALIGN doubleToInt(int64_t a) { return static_cast(bitsToDouble(a)); } -int64_t +int64_t FORCE_ALIGN doubleToLong(int64_t a) { return static_cast(bitsToDouble(a)); } -uint32_t +uint32_t FORCE_ALIGN addFloat(uint32_t b, uint32_t a) { return floatToBits(bitsToFloat(a) + bitsToFloat(b)); } -uint32_t +uint32_t FORCE_ALIGN subtractFloat(uint32_t b, uint32_t a) { return floatToBits(bitsToFloat(a) - bitsToFloat(b)); } -uint32_t +uint32_t FORCE_ALIGN multiplyFloat(uint32_t b, uint32_t a) { return floatToBits(bitsToFloat(a) * bitsToFloat(b)); } -uint32_t +uint32_t FORCE_ALIGN divideFloat(uint32_t b, uint32_t a) { return floatToBits(bitsToFloat(a) / bitsToFloat(b)); @@ -1364,7 +1364,7 @@ moduloFloat(uint32_t b, uint32_t a) return floatToBits(fmod(bitsToFloat(a), bitsToFloat(b))); } -uint32_t +uint32_t FORCE_ALIGN negateFloat(uint32_t a) { return floatToBits(- bitsToFloat(a)); @@ -1382,43 +1382,43 @@ moduloLong(int64_t b, int64_t a) return a % b; } -uint64_t +uint64_t FORCE_ALIGN floatToDouble(int32_t a) { return doubleToBits(static_cast(bitsToFloat(a))); } -int32_t +int32_t FORCE_ALIGN floatToInt(int32_t a) { return static_cast(bitsToFloat(a)); } -int64_t +int64_t FORCE_ALIGN floatToLong(int32_t a) { return static_cast(bitsToFloat(a)); } -uint64_t +uint64_t FORCE_ALIGN intToDouble(int32_t a) { return doubleToBits(static_cast(a)); } -uint32_t +uint32_t FORCE_ALIGN intToFloat(int32_t a) { return floatToBits(static_cast(a)); } -uint64_t +uint64_t FORCE_ALIGN longToDouble(int64_t a) { return doubleToBits(static_cast(a)); } -uint32_t +uint32_t FORCE_ALIGN longToFloat(int64_t a) { return floatToBits(static_cast(a)); @@ -1449,7 +1449,7 @@ makeBlankArray(MyThread* t, object (*constructor)(Thread*, uintptr_t, bool), } } -uintptr_t +uintptr_t FORCE_ALIGN lookUpAddress(int32_t key, uintptr_t* start, int32_t count, uintptr_t default_) { diff --git a/src/machine.cpp b/src/machine.cpp index 5391af5e86..dbbcde9880 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -2221,7 +2221,7 @@ isAssignableFrom(Thread* t, object a, object b) return false; } -bool +bool FORCE_ALIGN instanceOf(Thread* t, object class_, object o) { if (o == 0) { diff --git a/src/machine.h b/src/machine.h index fbf152d4ab..81a6617956 100644 --- a/src/machine.h +++ b/src/machine.h @@ -1491,7 +1491,7 @@ mark(Thread* t, object o, unsigned offset) } } -inline void +inline void FORCE_ALIGN set(Thread* t, object target, unsigned offset, object value) { cast(target, offset) = value; From af794d9be03ff65a234f81d5c69ad7178f84fbfb Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 16 Jun 2008 11:45:23 -0600 Subject: [PATCH 3/7] implement Date.toString, which just defers to ctime for now (part 2) --- classpath/java/util/Date.java | 6 ++++++ classpath/jni-util.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/classpath/java/util/Date.java b/classpath/java/util/Date.java index b81bf4459d..3de73c0c59 100644 --- a/classpath/java/util/Date.java +++ b/classpath/java/util/Date.java @@ -24,4 +24,10 @@ public class Date { public long getTime() { return when; } + + public String toString() { + return toString(when); + } + + private static native String toString(long when); } diff --git a/classpath/jni-util.h b/classpath/jni-util.h index e9308a5f1b..8d29a12d1b 100644 --- a/classpath/jni-util.h +++ b/classpath/jni-util.h @@ -18,6 +18,8 @@ # define JNIEXPORT __attribute__ ((visibility("default"))) #endif +#define UNUSED __attribute__((unused)) + namespace { inline void From 86a5e9ba8afb86579829e2c48a9c75b173715bdb Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Mon, 16 Jun 2008 11:47:54 -0600 Subject: [PATCH 4/7] Removed debugging that should not have been checked in --- src/compile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compile.cpp b/src/compile.cpp index 364046dd84..3feffa8b05 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -28,7 +28,7 @@ vmCall(); namespace { const bool Verbose = false; -const bool DebugNatives = true; +const bool DebugNatives = false; const bool DebugCallTable = false; const bool DebugMethodTree = false; const bool DebugFrameMaps = false; From 575df206cd1f34637c98b8d1f0a7f09e46e955e2 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 17 Jun 2008 09:05:57 -0600 Subject: [PATCH 5/7] fix System.currentTimeMillis on Windows --- classpath/java-lang.cpp | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index 967deaadb4..5fd06cc8fe 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -27,6 +27,8 @@ # include "winbase.h" # include "io.h" # include "tchar.h" +# include "sys/types.h" +# include "sys/timeb.h" # define SO_PREFIX "" #else # define SO_PREFIX "lib" @@ -388,24 +390,9 @@ extern "C" JNIEXPORT jlong JNICALL Java_java_lang_System_currentTimeMillis(JNIEnv*, jclass) { #ifdef WIN32 - static LARGE_INTEGER frequency; - static LARGE_INTEGER time; - static bool init = true; - - if (init) { - QueryPerformanceFrequency(&frequency); - - if (frequency.QuadPart == 0) { - return 0; - } - - init = false; - } - - QueryPerformanceCounter(&time); - return static_cast - (((static_cast(time.QuadPart)) * 1000.0) / - (static_cast(frequency.QuadPart))); + _timeb tb; + _ftime(&tb); + return (static_cast(tb.time) * 1000) + static_cast(tb.millitm); #else timeval tv = { 0, 0 }; gettimeofday(&tv, 0); From 3d84f31c1316e37cba9218b6e90acc39f449f849 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 17 Jun 2008 09:32:46 -0600 Subject: [PATCH 6/7] fix longCompareCR on 64-bit systems --- src/x86.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/x86.cpp b/src/x86.cpp index 0a515f2fba..9ee58700fe 100644 --- a/src/x86.cpp +++ b/src/x86.cpp @@ -1825,10 +1825,10 @@ longCompareCR(Context* c, unsigned size UNUSED, Assembler::Constant* a, int64_t v = a->value->value(); - ResolvedPromise low(v & 0xFFFFFFFF); + ResolvedPromise low(v & ~static_cast(0)); Assembler::Constant al(&low); - ResolvedPromise high((v >> 32) & 0xFFFFFFFF); + ResolvedPromise high((v >> 32) & ~static_cast(0)); Assembler::Constant ah(&high); Assembler::Register bh(b->high); From 27161691106ff8957de8b80a56adc1d243d2f7f2 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 17 Jun 2008 17:30:00 -0600 Subject: [PATCH 7/7] update version number to 0.1.1 --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index 0308a916b5..871b23ce28 100644 --- a/makefile +++ b/makefile @@ -1,7 +1,7 @@ MAKEFLAGS = -s name = avian -version = 0.1 +version = 0.1.1 build-arch = $(shell uname -m) ifeq ($(build-arch),i586)