From 13848cb520fe589fa0d59556a6a3baa8d4d65eba Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Mon, 21 Jan 2013 18:19:55 +0200 Subject: [PATCH 001/106] java.lang.Math.log() and java.lang.Math.tan() --- classpath/java-lang.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index 865f3c3fb4..a671a53d1d 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -785,6 +785,12 @@ Java_java_lang_Math_cos(JNIEnv*, jclass, jdouble val) return cos(val); } +extern "C" JNIEXPORT jdouble JNICALL +Java_java_lang_Math_tan(JNIEnv*, jclass, jdouble val) +{ + return tan(val); +} + extern "C" JNIEXPORT jdouble JNICALL Java_java_lang_Math_sqrt(JNIEnv*, jclass, jdouble val) { @@ -797,6 +803,12 @@ Java_java_lang_Math_pow(JNIEnv*, jclass, jdouble val, jdouble exp) return pow(val, exp); } +extern "C" JNIEXPORT jdouble JNICALL +Java_java_lang_Math_log(JNIEnv*, jclass, jdouble val) +{ + return log(val); +} + extern "C" JNIEXPORT jdouble JNICALL Java_java_lang_Math_floor(JNIEnv*, jclass, jdouble val) { From 7699c12597d81bf6848056a791210ae98992eb1b Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 21 Jan 2013 22:43:29 +0100 Subject: [PATCH 002/106] Add java lang math methods --- classpath/java-lang.cpp | 38 +++++++++++++++++++++++++ classpath/java/io/RandomAccessFile.java | 6 ++++ classpath/java/lang/Math.java | 6 ++++ 3 files changed, 50 insertions(+) diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index a671a53d1d..6a33a7b7c1 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -791,6 +791,44 @@ Java_java_lang_Math_tan(JNIEnv*, jclass, jdouble val) return tan(val); } +extern "C" JNIEXPORT jdouble JNICALL +Java_java_lang_Math_asin(JNIEnv*, jclass, jdouble val) +{ + return asin(val); +} + +extern "C" JNIEXPORT jdouble JNICALL +Java_java_lang_Math_acos(JNIEnv*, jclass, jdouble val) +{ + return acos(val); +} + +extern "C" JNIEXPORT jdouble JNICALL +Java_java_lang_Math_atan(JNIEnv*, jclass, jdouble val) +{ + return atan(val); +} + + +extern "C" JNIEXPORT jdouble JNICALL +Java_java_lang_Math_sinh(JNIEnv*, jclass, jdouble val) +{ + return sinh(val); +} + +extern "C" JNIEXPORT jdouble JNICALL +Java_java_lang_Math_cosh(JNIEnv*, jclass, jdouble val) +{ + return cosh(val); +} + +extern "C" JNIEXPORT jdouble JNICALL +Java_java_lang_Math_tanh(JNIEnv*, jclass, jdouble val) +{ + return tanh(val); +} + + extern "C" JNIEXPORT jdouble JNICALL Java_java_lang_Math_sqrt(JNIEnv*, jclass, jdouble val) { diff --git a/classpath/java/io/RandomAccessFile.java b/classpath/java/io/RandomAccessFile.java index b6e88dd00e..6ed7eeaceb 100644 --- a/classpath/java/io/RandomAccessFile.java +++ b/classpath/java/io/RandomAccessFile.java @@ -56,6 +56,12 @@ public class RandomAccessFile { this.position = position; } + public int skipBytes(int count) throws IOException { + if (position + count > length()) throw new IOException(); + this.position = position + count; + return count; + } + public void readFully(byte[] buffer, int offset, int length) throws IOException { diff --git a/classpath/java/lang/Math.java b/classpath/java/lang/Math.java index 44eea9db17..5f4933244d 100644 --- a/classpath/java/lang/Math.java +++ b/classpath/java/lang/Math.java @@ -93,6 +93,12 @@ public final class Math { public static native double tan(double v); + public static native double cosh(double v); + + public static native double sinh(double v); + + public static native double tanh(double v); + public static native double acos(double v); public static native double asin(double v); From 57f4463c4c7a8e602f069ed27b2e6a6fcc5455b3 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Tue, 22 Jan 2013 21:10:16 +0200 Subject: [PATCH 003/106] RandomAccessFile --- classpath/java-io.cpp | 153 ++++++------------------ classpath/java/io/RandomAccessFile.java | 73 ++++++++--- 2 files changed, 90 insertions(+), 136 deletions(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index 86020f57c8..b016c5c17a 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -155,69 +155,9 @@ doWrite(JNIEnv* e, jint fd, const jbyte* data, jint length) } } + #ifdef PLATFORM_WINDOWS -class Mapping { - public: - Mapping(uint8_t* start, size_t length, HANDLE mapping, HANDLE file): - start(start), - length(length), - mapping(mapping), - file(file) - { } - - uint8_t* start; - size_t length; - HANDLE mapping; - HANDLE file; -}; - -inline Mapping* -map(JNIEnv* e, string_t path) -{ - Mapping* result = 0; - HANDLE file = CreateFileW(path, FILE_READ_DATA, - FILE_SHARE_READ | FILE_SHARE_WRITE, 0, - OPEN_EXISTING, 0, 0); - if (file != INVALID_HANDLE_VALUE) { - unsigned size = GetFileSize(file, 0); - if (size != INVALID_FILE_SIZE) { - HANDLE mapping = CreateFileMapping(file, 0, PAGE_READONLY, 0, size, 0); - if (mapping) { - void* data = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0); - if (data) { - void* p = allocate(e, sizeof(Mapping)); - if (not e->ExceptionCheck()) { - result = new (p) - Mapping(static_cast(data), size, file, mapping); - } - } - - if (result == 0) { - CloseHandle(mapping); - } - } - } - - if (result == 0) { - CloseHandle(file); - } - } - if (result == 0 and not e->ExceptionCheck()) { - throwNew(e, "java/io/IOException", "%d", GetLastError()); - } - return result; -} - -inline void -unmap(JNIEnv*, Mapping* mapping) -{ - UnmapViewOfFile(mapping->start); - CloseHandle(mapping->mapping); - CloseHandle(mapping->file); - free(mapping); -} - class Directory { public: Directory(): handle(0), findNext(false) { } @@ -250,51 +190,9 @@ class Directory { #else // not PLATFORM_WINDOWS -class Mapping { - public: - Mapping(uint8_t* start, size_t length): - start(start), - length(length) - { } - - uint8_t* start; - size_t length; -}; - -inline Mapping* -map(JNIEnv* e, string_t path) -{ - Mapping* result = 0; - int fd = open(path, O_RDONLY); - if (fd != -1) { - struct stat s; - int r = fstat(fd, &s); - if (r != -1) { - void* data = mmap(0, s.st_size, PROT_READ, MAP_PRIVATE, fd, 0); - if (data) { - void* p = allocate(e, sizeof(Mapping)); - if (not e->ExceptionCheck()) { - result = new (p) Mapping(static_cast(data), s.st_size); - } - } - } - close(fd); - } - if (result == 0 and not e->ExceptionCheck()) { - throwNewErrno(e, "java/io/IOException"); - } - return result; -} - -inline void -unmap(JNIEnv*, Mapping* mapping) -{ - munmap(mapping->start, mapping->length); - free(mapping); -} - #endif // not PLATFORM_WINDOWS + } // namespace inline string_t getChars(JNIEnv* e, jstring path) { @@ -785,35 +683,54 @@ Java_java_io_RandomAccessFile_open(JNIEnv* e, jclass, jstring path, { string_t chars = getChars(e, path); if (chars) { - Mapping* mapping = map(e, chars); + int fd = ::open((const char*)chars, O_RDONLY); + releaseChars(e, path, chars); + if (fd == -1) { + throwNewErrno(e, "java/io/IOException"); + return; + } + struct ::stat fileStats; + if(::fstat(fd, &fileStats) == -1) { + ::close(fd); + throwNewErrno(e, "java/io/IOException"); + return; + } - jlong peer = reinterpret_cast(mapping); + jlong peer = fd; e->SetLongArrayRegion(result, 0, 1, &peer); - jlong length = (mapping ? mapping->length : 0); + jlong length = fileStats.st_size; e->SetLongArrayRegion(result, 1, 1, &length); - - releaseChars(e, path, chars); } } -extern "C" JNIEXPORT void JNICALL -Java_java_io_RandomAccessFile_copy(JNIEnv* e, jclass, jlong peer, +extern "C" JNIEXPORT jint JNICALL +Java_java_io_RandomAccessFile_readBytes(JNIEnv* e, jclass, jlong peer, jlong position, jbyteArray buffer, int offset, int length) { + int fd = (int)peer; + if(::lseek(fd, position, SEEK_SET) == -1) { + throwNewErrno(e, "java/io/IOException"); + return -1; + } + uint8_t* dst = reinterpret_cast (e->GetPrimitiveArrayCritical(buffer, 0)); - - memcpy(dst + offset, - reinterpret_cast(peer)->start + position, - length); - + ssize_t bytesRead = ::read(fd, dst + offset, length); e->ReleasePrimitiveArrayCritical(buffer, dst, 0); + + if(bytesRead == -1) { + throwNewErrno(e, "java/io/IOException"); + return -1; + } + + return (jint)bytesRead; } extern "C" JNIEXPORT void JNICALL -Java_java_io_RandomAccessFile_close(JNIEnv* e, jclass, jlong peer) +Java_java_io_RandomAccessFile_close(JNIEnv*/* e*/, jclass, jlong peer) { - unmap(e, reinterpret_cast(peer)); + int fd = (int)peer; + ::close(fd); } diff --git a/classpath/java/io/RandomAccessFile.java b/classpath/java/io/RandomAccessFile.java index 6ed7eeaceb..18bacb99f3 100644 --- a/classpath/java/io/RandomAccessFile.java +++ b/classpath/java/io/RandomAccessFile.java @@ -10,6 +10,8 @@ package java.io; +import java.lang.IllegalArgumentException; + public class RandomAccessFile { private long peer; private File file; @@ -61,27 +63,62 @@ public class RandomAccessFile { this.position = position + count; return count; } - - public void readFully(byte[] buffer, int offset, int length) - throws IOException - { - if (peer == 0) throw new IOException(); - - if (length == 0) return; - - if (position + length > this.length) { - if (position + length > length()) throw new EOFException(); - } - - if (offset < 0 || offset + length > buffer.length) + + public int read(byte b[], int off, int len) throws IOException { + if(b == null) + throw new IllegalArgumentException(); + if (peer == 0) + throw new IOException(); + if(len == 0) + return 0; + if (position + len > this.length) + throw new EOFException(); + if (off < 0 || off + len > b.length) throw new ArrayIndexOutOfBoundsException(); - - copy(peer, position, buffer, offset, length); - - position += length; + int bytesRead = readBytes(peer, position, b, off, len); + position += bytesRead; + return bytesRead; + } + + public int read(byte b[]) throws IOException { + if(b == null) + throw new IllegalArgumentException(); + if (peer == 0) + throw new IOException(); + if(b.length == 0) + return 0; + if (position + b.length > this.length) + throw new EOFException(); + int bytesRead = readBytes(peer, position, b, 0, b.length); + position += bytesRead; + return bytesRead; } - private static native void copy(long peer, long position, byte[] buffer, + public void readFully(byte b[], int off, int len) throws IOException { + if(b == null) + throw new IllegalArgumentException(); + if (peer == 0) + throw new IOException(); + if(len == 0) + return; + if (position + len > this.length) + throw new EOFException(); + if (off < 0 || off + len > b.length) + throw new ArrayIndexOutOfBoundsException(); + int n = 0; + do { + int count = readBytes(peer, position, b, off + n, len - n); + if (count < 0) + throw new EOFException(); + n += count; + } while (n < len); + } + + public void readFully(byte b[]) throws IOException { + readFully(b, 0, b.length); + } + + private static native int readBytes(long peer, long position, byte[] buffer, int offset, int length); public void close() throws IOException { From eea079ea701349f109f924c9d201390a5b3baa22 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 22 Jan 2013 20:25:37 +0100 Subject: [PATCH 004/106] Fix RAF --- classpath/java/io/RandomAccessFile.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/classpath/java/io/RandomAccessFile.java b/classpath/java/io/RandomAccessFile.java index 18bacb99f3..da9a8356b6 100644 --- a/classpath/java/io/RandomAccessFile.java +++ b/classpath/java/io/RandomAccessFile.java @@ -108,7 +108,8 @@ public class RandomAccessFile { int n = 0; do { int count = readBytes(peer, position, b, off + n, len - n); - if (count < 0) + position += count; + if (count == 0) throw new EOFException(); n += count; } while (n < len); From 4cd8ab59100c87801caa5177dc2c775d94c0aad1 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 24 Jan 2013 00:55:23 +0100 Subject: [PATCH 005/106] Add android platform --- classpath/java-lang.cpp | 2 ++ makefile | 15 +++++++++++++++ src/posix.cpp | 15 +++++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index 6a33a7b7c1..4cafd5e6cc 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -54,7 +54,9 @@ # include "signal.h" # include "sys/time.h" # include "sys/types.h" +# ifndef __ANDROID__ # include "sys/sysctl.h" +# endif # include "sys/utsname.h" # include "sys/wait.h" diff --git a/makefile b/makefile index b3cbd88a57..ab9031331b 100755 --- a/makefile +++ b/makefile @@ -353,6 +353,21 @@ ifeq ($(platform),freebsd) "-I$(JAVA_HOME)/include/freebsd" -I$(src) -pthread cflags = $(build-cflags) endif +ifeq ($(platform),android) + asm = arm + pointer-size = 4 + no-psabi = -Wno-psabi + toolchain = $(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86/ + cflags = -std=gnu++0x -I$(ANDROID_NDK)/platforms/android-5/arch-arm/usr/include \ + -I$(toolchain)/lib/gcc/arm-linux-androideabi/4.7/include $(common-cflags) + cflags += -marm $(no-psabi) + + cxx = $(toolchain)/bin/arm-linux-androideabi-g++ + cc = $(toolchain)/bin/arm-linux-androideabi-gcc + ar = $(toolchain)/bin/arm-linux-androideabi-ar + ranlib = $(toolchain)/bin/arm-linux-androideabi-ranlib + strip = $(toolchain)/bin/arm-linux-androideabi-strip +endif ifeq ($(platform),darwin) target-format = macho diff --git a/src/posix.cpp b/src/posix.cpp index da575eb8a4..c033956ad5 100644 --- a/src/posix.cpp +++ b/src/posix.cpp @@ -12,10 +12,21 @@ # define __STDC_CONSTANT_MACROS #endif +#include "sys/types.h" #ifdef __APPLE__ # include "CoreFoundation/CoreFoundation.h" # include "sys/ucontext.h" # undef assert +#elif defined __ANDROID__ +# include /* for sigcontext */ +# include /* for stack_t */ +typedef struct ucontext { + unsigned long uc_flags; + struct ucontext *uc_link; + stack_t uc_stack; + struct sigcontext uc_mcontext; + unsigned long uc_sigmask; +} ucontext_t; #else # if defined __FreeBSD__ # include "limits.h" @@ -24,7 +35,7 @@ #endif #include "sys/mman.h" -#include "sys/types.h" + #include "sys/stat.h" #include "sys/time.h" #include "time.h" @@ -37,10 +48,10 @@ #include "stdint.h" #include "dirent.h" #include "sched.h" - #include "arch.h" #include "system.h" + #define ACQUIRE(x) MutexResource MAKE_NAME(mutexResource_) (x) using namespace vm; From b0cae77b2a49b66dc5df3c0d6b4e1aeb4ce9145d Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 24 Jan 2013 16:17:52 +0200 Subject: [PATCH 006/106] Android toolchain --- makefile | 41 +++++++++++++++++++++++++++++++++-------- src/arm.h | 4 ++++ src/posix.cpp | 16 ++++++++-------- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/makefile b/makefile index ab9031331b..60b34a11f3 100755 --- a/makefile +++ b/makefile @@ -357,13 +357,34 @@ ifeq ($(platform),android) asm = arm pointer-size = 4 no-psabi = -Wno-psabi - toolchain = $(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86/ - cflags = -std=gnu++0x -I$(ANDROID_NDK)/platforms/android-5/arch-arm/usr/include \ - -I$(toolchain)/lib/gcc/arm-linux-androideabi/4.7/include $(common-cflags) - cflags += -marm $(no-psabi) + use-lto = false + ifeq ($(build-platform),cygwin) + ndk = "$$(cygpath -u "$(ANDROID_NDK)")" + else + ndk = $(ANDROID_NDK) + endif + + build-cflags = $(common-cflags) -I$(src) + ifeq ($(subst cygwin,windows,$(subst mingw32,windows,$(build-platform))),windows) + toolchain-host-platform = $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform))) + build-system = windows + build-cxx = i686-w64-mingw32-g++ + build-cc = i686-w64-mingw32-gcc + build-lflags = -lz -lpthread + sysroot = "$$(cygpath -w "$(ndk)/platforms/android-5/arch-arm")" + build-cflags += "-I$(JAVA_HOME)/include/win32" + else + toolchain-host-platform = $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform)))-$(build-arch) + sysroot = $(ndk)/platforms/android-5/arch-arm + build-cflags += "-I$(JAVA_HOME)/include/linux" + endif + toolchain = $(ndk)/toolchains/arm-linux-androideabi-4.7/prebuilt/$(toolchain-host-platform) + cflags = "-I$(sysroot)/usr/include" "-I$(JAVA_HOME)/include/linux" $(common-cflags) "-I$(src)" -std=c++11 -marm $(no-psabi) + lflags = $(common-lflags) -ldl + use-lto = false - cxx = $(toolchain)/bin/arm-linux-androideabi-g++ - cc = $(toolchain)/bin/arm-linux-androideabi-gcc + cxx = $(toolchain)/bin/arm-linux-androideabi-g++ --sysroot="$(sysroot)" + cc = $(toolchain)/bin/arm-linux-androideabi-gcc --sysroot="$(sysroot)" ar = $(toolchain)/bin/arm-linux-androideabi-ar ranlib = $(toolchain)/bin/arm-linux-androideabi-ranlib strip = $(toolchain)/bin/arm-linux-androideabi-strip @@ -540,7 +561,9 @@ ifeq ($(mode),fast) else optimization-cflags = -O3 -g3 -DNDEBUG endif - use-lto = true + ifeq ($(use-lto),) + use-lto = true + endif endif ifeq ($(mode),small) ifeq ($(use-clang),true) @@ -548,7 +571,9 @@ ifeq ($(mode),small) else optimization-cflags = -Os -g3 -DNDEBUG endif - use-lto = true + ifeq ($(use-lto),) + use-lto = true + endif endif ifeq ($(use-lto),true) diff --git a/src/arm.h b/src/arm.h index 15299ec762..7e7a4d61dd 100644 --- a/src/arm.h +++ b/src/arm.h @@ -98,6 +98,10 @@ loadMemoryBarrier() memoryBarrier(); } +#if defined(__ANDROID__) +// http://code.google.com/p/android/issues/detail?id=1803 +extern "C" void __clear_cache (void *beg __attribute__((__unused__)), void *end __attribute__((__unused__))); +#endif inline void syncInstructionCache(const void* start, unsigned size) { diff --git a/src/posix.cpp b/src/posix.cpp index c033956ad5..95c4286b60 100644 --- a/src/posix.cpp +++ b/src/posix.cpp @@ -17,16 +17,16 @@ # include "CoreFoundation/CoreFoundation.h" # include "sys/ucontext.h" # undef assert -#elif defined __ANDROID__ +#elif defined(__ANDROID__) # include /* for sigcontext */ # include /* for stack_t */ -typedef struct ucontext { - unsigned long uc_flags; - struct ucontext *uc_link; - stack_t uc_stack; - struct sigcontext uc_mcontext; - unsigned long uc_sigmask; -} ucontext_t; + typedef struct ucontext { + unsigned long uc_flags; + struct ucontext *uc_link; + stack_t uc_stack; + struct sigcontext uc_mcontext; + unsigned long uc_sigmask; + } ucontext_t; #else # if defined __FreeBSD__ # include "limits.h" From 62104e843c3c0c6d67b55fad6002a063a2c78280 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 24 Jan 2013 06:39:14 -0800 Subject: [PATCH 007/106] Path fix --- makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/makefile b/makefile index 60b34a11f3..707ab486a6 100755 --- a/makefile +++ b/makefile @@ -365,26 +365,27 @@ ifeq ($(platform),android) endif build-cflags = $(common-cflags) -I$(src) + build-lflags = -lz -lpthread ifeq ($(subst cygwin,windows,$(subst mingw32,windows,$(build-platform))),windows) toolchain-host-platform = $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform))) build-system = windows build-cxx = i686-w64-mingw32-g++ build-cc = i686-w64-mingw32-gcc - build-lflags = -lz -lpthread sysroot = "$$(cygpath -w "$(ndk)/platforms/android-5/arch-arm")" build-cflags += "-I$(JAVA_HOME)/include/win32" else - toolchain-host-platform = $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform)))-$(build-arch) + toolchain-host-platform = $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform)))-* sysroot = $(ndk)/platforms/android-5/arch-arm build-cflags += "-I$(JAVA_HOME)/include/linux" endif toolchain = $(ndk)/toolchains/arm-linux-androideabi-4.7/prebuilt/$(toolchain-host-platform) cflags = "-I$(sysroot)/usr/include" "-I$(JAVA_HOME)/include/linux" $(common-cflags) "-I$(src)" -std=c++11 -marm $(no-psabi) - lflags = $(common-lflags) -ldl + lflags = "-L$(sysroot)/usr/lib" $(common-lflags) -ldl use-lto = false cxx = $(toolchain)/bin/arm-linux-androideabi-g++ --sysroot="$(sysroot)" cc = $(toolchain)/bin/arm-linux-androideabi-gcc --sysroot="$(sysroot)" + as = $(toolchain)/bin/arm-linux-androideabi-as --sysroot="$(sysroot)" ar = $(toolchain)/bin/arm-linux-androideabi-ar ranlib = $(toolchain)/bin/arm-linux-androideabi-ranlib strip = $(toolchain)/bin/arm-linux-androideabi-strip From 8da990f593e4fc44666668ff5d5b6b2de05f16fd Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 25 Jan 2013 23:36:13 +0100 Subject: [PATCH 008/106] Fix android makefile --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index 707ab486a6..9b4ffb954a 100755 --- a/makefile +++ b/makefile @@ -365,7 +365,7 @@ ifeq ($(platform),android) endif build-cflags = $(common-cflags) -I$(src) - build-lflags = -lz -lpthread + #build-lflags = -lz -lpthread -ldl ifeq ($(subst cygwin,windows,$(subst mingw32,windows,$(build-platform))),windows) toolchain-host-platform = $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform))) build-system = windows From ba807611282bd8072ecf1be64506c727d71d618c Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 26 Jan 2013 20:51:46 +0100 Subject: [PATCH 009/106] Add android redirect to logcat --- classpath/java-io.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index b016c5c17a..1e9acdef76 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -644,6 +644,9 @@ Java_java_io_FileOutputStream_open(JNIEnv* e, jclass, jstring path, jboolean app return -1; } } +#ifdef __ANDROID__ +#include +#endif extern "C" JNIEXPORT void JNICALL Java_java_io_FileOutputStream_write__II(JNIEnv* e, jclass, jint fd, jint c) @@ -657,13 +660,18 @@ Java_java_io_FileOutputStream_write__I_3BII (JNIEnv* e, jclass, jint fd, jbyteArray b, jint offset, jint length) { jbyte* data = static_cast(malloc(length)); + if (data == 0) { throwNew(e, "java/lang/OutOfMemoryError", 0); return; } e->GetByteArrayRegion(b, offset, length, data); - + #ifdef __ANDROID__ + if(fd == 1) { + __android_log_print(ANDROID_LOG_WARN, "net.osmand:native", "%.*s",length, data); + } + #endif if (not e->ExceptionCheck()) { doWrite(e, fd, data, length); } From ed94eafe16ed69b916e66b54cd8499ac95ae36a8 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 26 Jan 2013 21:33:43 +0100 Subject: [PATCH 010/106] Fix proguard warnings Conflicts: TODO.if.merge --- vm.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/vm.pro b/vm.pro index 4cdb1654ee..8d1ab22177 100644 --- a/vm.pro +++ b/vm.pro @@ -71,6 +71,7 @@ -keep public class java.io.IOException -keep public class java.io.FileNotFoundException -keep public class java.net.SocketException +-keep public class java.util.Locale # ClassLoader.getSystemClassloader() depends on the existence of this class: From 0cbaad649589b92fb756458e232a67dcb7e2a3a7 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Mon, 28 Jan 2013 17:20:52 +0200 Subject: [PATCH 011/106] Windows Phone 8 / Windows RT initial support Conflicts: makefile --- classpath/java-io.cpp | 39 +++- classpath/java-lang.cpp | 71 ++++++- makefile | 401 ++++++++++++++++++++++++++++++-------- src/arm.h | 28 ++- src/arm.masm | 77 ++++++++ src/binaryToObject/pe.cpp | 33 ++-- src/bootimage.cpp | 44 +++-- src/common.h | 8 +- src/interpret.cpp | 19 +- src/machine.h | 3 + src/system.h | 6 + src/windows.cpp | 143 +++++++++++++- src/x86.masm | 166 ++++++++++++++++ 13 files changed, 912 insertions(+), 126 deletions(-) create mode 100644 src/arm.masm create mode 100644 src/x86.masm diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index 1e9acdef76..db9882e051 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -83,6 +83,16 @@ typedef char char_t; #endif // not PLATFORM_WINDOWS +#ifndef WINAPI_FAMILY +# ifndef WINAPI_PARTITION_DESKTOP +# define WINAPI_PARTITION_DESKTOP 1 +# endif + +# ifndef WINAPI_FAMILY_PARTITION +# define WINAPI_FAMILY_PARTITION(x) (x) +# endif +#endif // WINAPI_FAMILY + inline void* operator new(size_t, void* p) throw() { return p; } typedef const char_t* string_t; @@ -214,6 +224,7 @@ extern "C" JNIEXPORT jstring JNICALL Java_java_io_File_toAbsolutePath(JNIEnv* e UNUSED, jclass, jstring path) { #ifdef PLATFORM_WINDOWS +# if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) string_t chars = getChars(e, path); if (chars) { const unsigned BufferSize = MAX_PATH; @@ -228,6 +239,11 @@ Java_java_io_File_toAbsolutePath(JNIEnv* e UNUSED, jclass, jstring path) } return path; +# else + // WinRT has no concept of full paths + throwNewErrno(e, "java/io/IOException"); + return path; +# endif #else jstring result = path; string_t chars = getChars(e, path); @@ -256,11 +272,24 @@ Java_java_io_File_length(JNIEnv* e, jclass, jstring path) LARGE_INTEGER fileSize; string_t chars = getChars(e, path); + #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) HANDLE file = CreateFileW (chars, FILE_READ_DATA, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); + #else + HANDLE file = CreateFile2 + (chars, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr); + #endif releaseChars(e, path, chars); if (file != INVALID_HANDLE_VALUE) + { + #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) GetFileSizeEx(file, &fileSize); + #else + FILE_STANDARD_INFO info; + if(GetFileInformationByHandleEx(file, FileStandardInfo, &info, sizeof(info))) + fileSize = info.EndOfFile; + #endif + } else return 0; CloseHandle(file); return static_cast(fileSize.QuadPart); @@ -496,7 +525,11 @@ Java_java_io_File_openDir(JNIEnv* e, jclass, jstring path) releaseChars(e, path, chars); Directory* d = new (malloc(sizeof(Directory))) Directory; + #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) d->handle = FindFirstFileW(RUNTIME_ARRAY_BODY(buffer), &(d->data)); + #else + d->handle = FindFirstFileExW(RUNTIME_ARRAY_BODY(buffer), FindExInfoStandard, &(d->data), FindExSearchNameMatch, NULL, 0); + #endif if (d->handle == INVALID_HANDLE_VALUE) { d->dispose(); d = 0; @@ -725,7 +758,11 @@ Java_java_io_RandomAccessFile_readBytes(JNIEnv* e, jclass, jlong peer, uint8_t* dst = reinterpret_cast (e->GetPrimitiveArrayCritical(buffer, 0)); +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) ssize_t bytesRead = ::read(fd, dst + offset, length); +#else + auto bytesRead = ::read(fd, dst + offset, length); +#endif e->ReleasePrimitiveArrayCritical(buffer, dst, 0); if(bytesRead == -1) { @@ -737,7 +774,7 @@ Java_java_io_RandomAccessFile_readBytes(JNIEnv* e, jclass, jlong peer, } extern "C" JNIEXPORT void JNICALL -Java_java_io_RandomAccessFile_close(JNIEnv*/* e*/, jclass, jlong peer) +Java_java_io_RandomAccessFile_close(JNIEnv* /* e*/, jclass, jlong peer) { int fd = (int)peer; ::close(fd); diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index 4cafd5e6cc..0414216194 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -62,6 +62,16 @@ #endif // not PLATFORM_WINDOWS +#ifndef WINAPI_FAMILY +# ifndef WINAPI_PARTITION_DESKTOP +# define WINAPI_PARTITION_DESKTOP 1 +# endif + +# ifndef WINAPI_FAMILY_PARTITION +# define WINAPI_FAMILY_PARTITION(x) (x) +# endif +#endif // WINAPI_FAMILY + namespace { #ifdef PLATFORM_WINDOWS char* getErrorStr(DWORD err){ @@ -70,7 +80,8 @@ namespace { snprintf(errStr, 9, "%d", (int) err); return errStr; - // The better way to do this, if I could figure out how to convert LPTSTR to char* + //TODO: + // The better way to do this, if I could figure out how to convert LPTSTR to char* //char* errStr; //LPTSTR s; //if(FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | @@ -83,6 +94,7 @@ namespace { //return errStr; } +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) void makePipe(JNIEnv* e, HANDLE p[2]) { SECURITY_ATTRIBUTES sa; @@ -95,6 +107,7 @@ namespace { throwNew(e, "java/io/IOException", getErrorStr(GetLastError())); } } +#endif int descriptor(JNIEnv* e, HANDLE h) { @@ -196,7 +209,7 @@ extern "C" JNIEXPORT void JNICALL Java_java_lang_Runtime_exec(JNIEnv* e, jclass, jobjectArray command, jlongArray process) { - +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) int size = 0; for (int i = 0; i < e->GetArrayLength(command); ++i){ jstring element = (jstring) e->GetObjectArrayElement(command, i); @@ -267,11 +280,15 @@ Java_java_lang_Runtime_exec(JNIEnv* e, jclass, e->SetLongArrayRegion(process, 0, 1, &pid); jlong tid = reinterpret_cast(pi.hThread); e->SetLongArrayRegion(process, 1, 1, &tid); +#else + throwNew(e, "java/io/Exception", strdup("Not supported on WinRT/WinPhone8")); +#endif } extern "C" JNIEXPORT jint JNICALL Java_java_lang_Runtime_waitFor(JNIEnv* e, jclass, jlong pid, jlong tid) { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) DWORD exitCode; WaitForSingleObject(reinterpret_cast(pid), INFINITE); BOOL success = GetExitCodeProcess(reinterpret_cast(pid), &exitCode); @@ -283,14 +300,23 @@ Java_java_lang_Runtime_waitFor(JNIEnv* e, jclass, jlong pid, jlong tid) CloseHandle(reinterpret_cast(tid)); return exitCode; +#else + throwNew(e, "java/io/Exception", strdup("Not supported on WinRT/WinPhone8")); + return -1; +#endif } extern "C" JNIEXPORT void JNICALL -Java_java_lang_Runtime_kill(JNIEnv*, jclass, jlong pid) { +Java_java_lang_Runtime_kill(JNIEnv* e UNUSED, jclass, jlong pid) { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) TerminateProcess(reinterpret_cast(pid), 1); +#else + throwNew(e, "java/io/Exception", strdup("Not supported on WinRT/WinPhone8")); +#endif } Locale getLocale() { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) const char* lang = ""; const char* reg = ""; unsigned langid = GetUserDefaultUILanguage(); @@ -362,8 +388,11 @@ Locale getLocale() { default: lang = "en"; } - Locale locale(lang, reg); - return locale; + return Locale(lang, reg); +#else + //TODO: CultureInfo.CurrentCulture + return Locale("en", "US"); +#endif } #else extern "C" JNIEXPORT void JNICALL @@ -531,8 +560,15 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, } else if (strcmp(chars, "file.separator") == 0) { r = e->NewStringUTF("\\"); } else if (strcmp(chars, "os.name") == 0) { +# if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) r = e->NewStringUTF("Windows"); +# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE) + r = e->NewStringUTF("Windows Phone"); +# else + r = e->NewStringUTF("Windows RT"); +# endif } else if (strcmp(chars, "os.version") == 0) { +# if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) unsigned size = 32; RUNTIME_ARRAY(char, buffer, size); OSVERSIONINFO OSversion; @@ -540,6 +576,10 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, ::GetVersionEx(&OSversion); snprintf(RUNTIME_ARRAY_BODY(buffer), size, "%i.%i", (int)OSversion.dwMajorVersion, (int)OSversion.dwMinorVersion); r = e->NewStringUTF(RUNTIME_ARRAY_BODY(buffer)); +# else + // Currently there is no alternative on WinRT/WP8 + r = e->NewStringUTF("8.0"); +# endif } else if (strcmp(chars, "os.arch") == 0) { #ifdef ARCH_x86_32 r = e->NewStringUTF("x86"); @@ -551,15 +591,28 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, r = e->NewStringUTF("arm"); #endif } else if (strcmp(chars, "java.io.tmpdir") == 0) { +# if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) TCHAR buffer[MAX_PATH]; GetTempPath(MAX_PATH, buffer); r = e->NewStringUTF(buffer); +# else + //TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ + //Windows.Storage.ApplicationData.Current.TemporaryFolder + r = 0; +# endif } else if (strcmp(chars, "user.dir") == 0) { +# if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) TCHAR buffer[MAX_PATH]; GetCurrentDirectory(MAX_PATH, buffer); r = e->NewStringUTF(buffer); +# else + //TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ + //Windows.ApplicationModel.Package.Current.InstalledLocation + r = 0; +# endif } else if (strcmp(chars, "user.home") == 0) { # ifdef _MSC_VER +# if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) WCHAR buffer[MAX_PATH]; size_t needed; if (_wgetenv_s(&needed, buffer, MAX_PATH, L"USERPROFILE") == 0) { @@ -567,6 +620,11 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, } else { r = 0; } +# else + //TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ + //Windows.Storage.KnownFolders.DocumentsLibrary; + r = 0; +# endif # else LPWSTR home = _wgetenv(L"USERPROFILE"); r = e->NewString(reinterpret_cast(home), lstrlenW(home)); @@ -654,6 +712,9 @@ namespace { #elif defined __APPLE__ # include # define environ (*_NSGetEnviron()) +#elif defined(WINAPI_FAMILY) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +// WinRT/WP8 does not provide alternative for environment variables +char* environ[] = { 0 }; #else extern char** environ; #endif diff --git a/makefile b/makefile index 9b4ffb954a..28ef8be401 100755 --- a/makefile +++ b/makefile @@ -51,7 +51,7 @@ ifeq ($(continuations),true) endif root := $(shell (cd .. && pwd)) -build = build/$(platform)-$(arch)$(options) +build = $(build-prefix)build/$(platform)-$(arch)$(options) classpath-build = $(build)/classpath test-build = $(build)/test src = src @@ -59,6 +59,8 @@ classpath-src = classpath test = test win32 ?= $(root)/win32 win64 ?= $(root)/win64 +winrt ?= $(root)/winrt +wp8 ?= $(root)/wp8 classpath = avian @@ -183,6 +185,18 @@ strip-all = --strip-all rdynamic = -rdynamic +cflags_debug = -O0 -g3 +cflags_debug_fast = -O0 -g3 +cflags_stress = -O0 -g3 +cflags_stress_major = -O0 -g3 +ifeq ($(use-clang),true) + cflags_fast = -O4 -g3 + cflags_small = -Oz -g3 +else + cflags_fast = -O3 -g3 + cflags_small = -Os -g3 +endif + # note that we suppress the non-virtual-dtor warning because we never # use the delete operator, which means we don't need virtual # destructors: @@ -198,7 +212,7 @@ common-cflags = $(warnings) -fno-rtti -fno-exceptions -I$(classpath-src) \ -DUSE_ATOMIC_OPERATIONS -DAVIAN_JAVA_HOME=\"$(javahome)\" \ -DAVIAN_EMBED_PREFIX=\"$(embed-prefix)\" $(target-cflags) -asmflags = $(target-cflags) +asmflags = $(target-cflags) -I$(src) ifneq (,$(filter i386 x86_64,$(arch))) ifeq ($(use-frame-pointer),true) @@ -237,6 +251,18 @@ pointer-size = 8 so-prefix = lib so-suffix = .so +static-prefix = lib +static-suffix = .a + +output = -o $(1) +asm-output = -o $(1) +asm-input = -c $(1) +asm-format = S +as = $(cc) +ld = $(cxx) +build-ld = $(build-cc) + +static = -static shared = -shared no-error = -Wno-error @@ -244,6 +270,8 @@ no-error = -Wno-error openjdk-extra-cflags = -fvisibility=hidden bootimage-cflags = -DTARGET_BYTES_PER_WORD=$(pointer-size) +bootimage-symbols = _binary_bootimage_bin_start:_binary_bootimage_bin_end +codeimage-symbols = _binary_codeimage_bin_start:_binary_codeimage_bin_end developer-dir := $(shell if test -d /Developer; then echo /Developer; \ else echo /Applications/Xcode.app/Contents/Developer; fi) @@ -354,41 +382,68 @@ ifeq ($(platform),freebsd) cflags = $(build-cflags) endif ifeq ($(platform),android) - asm = arm - pointer-size = 4 - no-psabi = -Wno-psabi - use-lto = false - ifeq ($(build-platform),cygwin) + ifeq ($(build-platform),cygwin) ndk = "$$(cygpath -u "$(ANDROID_NDK)")" else ndk = $(ANDROID_NDK) endif + ifeq ($(android-version),) + android-version = 5 + endif + + ifeq ($(android-toolchain),) + android-toolchain = 4.7 + endif + + ifeq ($(arch),arm) + android-toolchain-name = arm-linux-androideabi + android-toolchain-prefix = arm-linux-androideabi- + endif + ifeq ($(arch),i386) + android-toolchain-name = x86 + android-toolchain-prefix = i686-linux-android- + endif + + ifeq ($(android-arm-arch),) + android-arm-arch = armv5 + endif + + options := $(options)-api$(android-version)-$(android-toolchain)-$(android-arm-arch) + build-cflags = $(common-cflags) -I$(src) - #build-lflags = -lz -lpthread -ldl + build-lflags = -lz -lpthread ifeq ($(subst cygwin,windows,$(subst mingw32,windows,$(build-platform))),windows) toolchain-host-platform = $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform))) build-system = windows build-cxx = i686-w64-mingw32-g++ build-cc = i686-w64-mingw32-gcc - sysroot = "$$(cygpath -w "$(ndk)/platforms/android-5/arch-arm")" + sysroot = "$$(cygpath -w "$(ndk)/platforms/android-$(android-version)/arch-arm")" build-cflags += "-I$(JAVA_HOME)/include/win32" else toolchain-host-platform = $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform)))-* - sysroot = $(ndk)/platforms/android-5/arch-arm + sysroot = $(ndk)/platforms/android-$(android-version)/arch-arm build-cflags += "-I$(JAVA_HOME)/include/linux" + build-lflags += -ldl endif - toolchain = $(ndk)/toolchains/arm-linux-androideabi-4.7/prebuilt/$(toolchain-host-platform) - cflags = "-I$(sysroot)/usr/include" "-I$(JAVA_HOME)/include/linux" $(common-cflags) "-I$(src)" -std=c++11 -marm $(no-psabi) - lflags = "-L$(sysroot)/usr/lib" $(common-lflags) -ldl + toolchain = $(ndk)/toolchains/$(android-toolchain-name)-$(android-toolchain)/prebuilt/$(toolchain-host-platform) + cflags = "-I$(sysroot)/usr/include" "-I$(JAVA_HOME)/include/linux" $(common-cflags) "-I$(src)" -std=c++11 $(no-psabi) + lflags = "-L$(sysroot)/usr/lib" $(common-lflags) -llog + target-format = elf use-lto = false - cxx = $(toolchain)/bin/arm-linux-androideabi-g++ --sysroot="$(sysroot)" - cc = $(toolchain)/bin/arm-linux-androideabi-gcc --sysroot="$(sysroot)" - as = $(toolchain)/bin/arm-linux-androideabi-as --sysroot="$(sysroot)" - ar = $(toolchain)/bin/arm-linux-androideabi-ar - ranlib = $(toolchain)/bin/arm-linux-androideabi-ranlib - strip = $(toolchain)/bin/arm-linux-androideabi-strip + ifeq ($(arch),arm) + cflags += -marm -march=$(android-arm-arch) -ftree-vectorize -ffast-math -mfloat-abi=softfp + endif + ifeq ($(arch),i386) + endif + + cxx = $(toolchain)/bin/$(android-toolchain-prefix)g++ --sysroot="$(sysroot)" + cc = $(toolchain)/bin/$(android-toolchain-prefix)gcc --sysroot="$(sysroot)" + as = $(cxx) + ar = $(toolchain)/bin/$(android-toolchain-prefix)ar + ranlib = $(toolchain)/bin/$(android-toolchain-prefix)ranlib + strip = $(toolchain)/bin/$(android-toolchain-prefix)strip endif ifeq ($(platform),darwin) @@ -475,7 +530,9 @@ ifeq ($(platform),darwin) endif ifeq ($(platform),windows) - target-format = pe + ifeq ($(target-format),) + target-format = pe + endif inc = "$(win32)/include" lib = "$(win32)/lib" @@ -488,7 +545,8 @@ ifeq ($(platform),windows) so-suffix = .dll exe-suffix = .exe - lflags = -L$(lib) $(common-lflags) -lws2_32 -liphlpapi -mwindows -mconsole + lflags = -L$(lib) $(common-lflags) -lws2_32 -liphlpapi -mconsole + bootimage-generator-lflags = -static-libstdc++ -static-libgcc cflags = -I$(inc) $(common-cflags) -DWINVER=0x0500 ifeq (,$(filter mingw32 cygwin,$(build-platform))) @@ -539,39 +597,197 @@ ifeq ($(platform),windows) embed-loader-o = $(build-embed)/embed-loader.o endif +ifeq ($(platform),wp8) + ifeq ($(shell uname -s | grep -i -c WOW64),1) + programFiles = Program Files (x86) + else + programFiles = Program Files + endif + ifeq ($(MSVS_ROOT),) + # Environment variable MSVS_ROOT not found. It should be something like + # "C:\$(programFiles)\Microsoft Visual Studio 11.0" + MSVS_ROOT = C:\$(programFiles)\Microsoft Visual Studio 11.0 + endif + ifeq ($(MSVC_ROOT),) + # Environment variable MSVC_ROOT not found. It should be something like + # "C:\$(programFiles)\Microsoft Visual Studio 11.0\VC" + MSVC_ROOT = $(MSVS_ROOT)\VC + endif + ifeq ($(WP80_SDK),) + # Environment variable WP8_SDK not found. It should be something like + # "C:\Program Files[ (x86)]\Microsoft Visual Studio 11.0\VC\WPSDK\WP80" + # TODO: Lookup in SOFTWARE\Microsoft\Microsoft SDKs\WindowsPhone\v8.0 + WP80_SDK = C:\$(programFiles)\Microsoft Visual Studio 11.0\VC\WPSDK\WP80 + endif + ifeq ($(WP80_KIT),) + # Environment variable WP8_KIT not found. It should be something like + # "c:\Program Files[ (x86)]\Windows Phone Kits\8.0" + # TODO: Lookup in SOFTWARE\Microsoft\Microsoft SDKs\WindowsPhone\v8.0 + WP80_KIT = C:\$(programFiles)\Windows Phone Kits\8.0 + endif + ifeq ($(WIN8_KIT),) + # Environment variable WIN8_KIT not found. It should be something like + # "c:\Program Files[ (x86)]\Windows Kits\8.0" + WIN8_KIT = C:\$(programFiles)\Windows Kits\8.0 + endif + ifeq ($(build-platform),cygwin) + windows-path = cygpath -w + else + windows-path = $(native-path) + endif + windows-java-home := $(shell $(windows-path) "$(JAVA_HOME)") + target-format = pe + ms_cl_compiler = wp8 + use-lto = false + supports_avian_executable = false + process = interpret + ifneq ($(process),compile) + options := -$(process) + endif + bootimage = true + ifeq ($(bootimage),true) + options := $(options)-bootimage + endif + system = windows + build-system = windows + static-prefix = + static-suffix = .lib + so-prefix = + so-suffix = .dll + exe-suffix = .exe + + ifeq ($(arch),arm) + wp8_arch = \x86_arm + vc_arch = \arm + w8kit_arch = arm + deps_arch = ARM + as = "$$(cygpath -u "$(WP80_SDK)\bin\x86_arm\armasm.exe")" + cxx = "$$(cygpath -u "$(WP80_SDK)\bin\x86_arm\cl.exe")" + ld = "$$(cygpath -u "$(WP80_SDK)\bin\x86_arm\link.exe")" + asmflags = -machine ARM -32 + asm-output = -o $(1) + asm-input = $(1) + machine_type = ARM + bootimage-symbols = binary_bootimage_bin_start:binary_bootimage_bin_end + codeimage-symbols = binary_codeimage_bin_start:binary_codeimage_bin_end + endif + ifeq ($(arch),i386) + wp8_arch = + vc_arch = + w8kit_arch = x86 + deps_arch = x86 + as = "$$(cygpath -u "$(WP80_SDK)\bin\ml.exe")" + cxx = "$$(cygpath -u "$(WP80_SDK)\bin\cl.exe")" + ld = "$$(cygpath -u "$(WP80_SDK)\bin\link.exe")" + asmflags += -nologo + asm-output = $(output) + machine_type = X86 + endif + + PATH := $(shell cygpath -u "$(MSVS_ROOT)\Common7\IDE"):$(shell cygpath -u "$(WP80_SDK)\bin$(wp8_arch)"):$(shell cygpath -u "$(WP80_SDK)\bin"):${PATH} + + build-cflags = $(common-cflags) -I$(src) -I$(inc) -mthreads + build-lflags = -lz -lpthread + + cflags = -nologo \ + -I"$(WP80_SDK)\include" -I"$(WP80_KIT)\Include" -I"$(WP80_KIT)\Include\minwin" -I"$(WP80_KIT)\Include\mincore" \ + -DWINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP \ + -DAVIAN_VERSION=\"$(version)\" -D_JNI_IMPLEMENTATION_ \ + -DUSE_ATOMIC_OPERATIONS -DAVIAN_JAVA_HOME=\"$(javahome)\" \ + -DAVIAN_EMBED_PREFIX=\"$(embed-prefix)\" \ + -I"$(shell $(windows-path) "$(wp8)/zlib/upstream")" \ + -Fd$(build)/$(name).pdb -I"$(shell $(windows-path) "$(wp8)/include")" -I$(src) -I$(classpath-src) \ + -I"$(build)" \ + -I"$(windows-java-home)/include" -I"$(windows-java-home)/include/win32" \ + -DTARGET_BYTES_PER_WORD=$(pointer-size) + + common-lflags = $(classpath-lflags) + + arflags = -MACHINE:$(machine_type) + lflags = $(common-lflags) -nologo \ + -MACHINE:$(machine_type) \ + -LIBPATH:"$(WP80_KIT)\lib\$(w8kit_arch)" -LIBPATH:"$(WIN8_KIT)\Lib\win8\um\$(w8kit_arch)" -LIBPATH:"$(MSVC_ROOT)\lib$(vc_arch)" \ + ws2_32.lib \ + "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\zlib.lib")" "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\ThreadEmulation.lib")" + + cc = $(cxx) + asm-format = masm + shared = -dll + ar = "$$(cygpath -u "$(WP80_SDK)\bin\lib.exe")" + arflags += -nologo + ifeq ($(build-platform),cygwin) + build-cxx = i686-w64-mingw32-g++ + build-cc = i686-w64-mingw32-gcc + dlltool = i686-w64-mingw32-dlltool + ranlib = + strip = + endif + output = -Fo$(1) + + cflags_debug = -Od -Zi -MDd + cflags_debug_fast = -Od -Zi -MDd + cflags_stress = -O0 -g3 -MD + cflags_stress_major = -O0 -g3 -MD + cflags_fast = -O2 -Zi -MD + cflags_small = -O1s -Zi -MD + # -GL [whole program optimization] in 'fast' and 'small' breaks compilation for some reason + + ifeq ($(mode),debug) + cflags += + lflags += + endif + ifeq ($(mode),debug-fast) + cflags += -DNDEBUG + lflags += + endif + ifeq ($(mode),stress_major) + cflags += + lflags += + endif + ifeq ($(mode),fast) + cflags += + lflags += + endif + # -LTCG is needed only if -GL is used + ifeq ($(mode),fast) + cflags += -DNDEBUG + lflags += -LTCG + arflags += + endif + ifeq ($(mode),small) + cflags += -DNDEBUG + lflags += -LTCG + arflags += + endif + + strip = : +endif + ifeq ($(mode),debug) - optimization-cflags = -O0 -g3 - converter-cflags += -O0 -g3 + optimization-cflags = $(cflags_debug) + converter-cflags += $(cflags_debug) strip = : endif ifeq ($(mode),debug-fast) - optimization-cflags = -O0 -g3 -DNDEBUG + optimization-cflags = $(cflags_debug_fast) -DNDEBUG strip = : endif ifeq ($(mode),stress) - optimization-cflags = -O0 -g3 -DVM_STRESS + optimization-cflags = $(cflags_stress) -DVM_STRESS strip = : endif ifeq ($(mode),stress-major) - optimization-cflags = -O0 -g3 -DVM_STRESS -DVM_STRESS_MAJOR + optimization-cflags = $(cflags_stress_major) -DVM_STRESS -DVM_STRESS_MAJOR strip = : endif ifeq ($(mode),fast) - ifeq ($(use-clang),true) - optimization-cflags = -O4 -g3 -DNDEBUG - else - optimization-cflags = -O3 -g3 -DNDEBUG - endif + optimization-cflags = $(cflags_fast) -DNDEBUG ifeq ($(use-lto),) use-lto = true endif endif ifeq ($(mode),small) - ifeq ($(use-clang),true) - optimization-cflags = -Oz -g3 -DNDEBUG - else - optimization-cflags = -Os -g3 -DNDEBUG - endif + optimization-cflags = $(cflags_small) -DNDEBUG ifeq ($(use-lto),) use-lto = true endif @@ -596,6 +812,7 @@ endif cflags += $(optimization-cflags) +ifndef ms_cl_compiler ifneq ($(platform),darwin) ifeq ($(arch),i386) # this is necessary to support __sync_bool_compare_and_swap: @@ -603,16 +820,9 @@ ifeq ($(arch),i386) lflags += -march=i586 endif endif - -output = -o $(1) -as := $(cc) -ld := $(cc) -build-ld := $(build-cc) - -static = -static +endif ifdef msvc - static = no-error = windows-path = $(native-path) windows-java-home := $(shell $(windows-path) "$(JAVA_HOME)") @@ -621,6 +831,7 @@ ifdef msvc cc = $(cxx) ld = "$(msvc)/BIN/link.exe" mt = "mt.exe" + manifest-flags = -MANIFEST -MANIFESTFILE:$(@).manifest cflags = -nologo -DAVIAN_VERSION=\"$(version)\" -D_JNI_IMPLEMENTATION_ \ -DUSE_ATOMIC_OPERATIONS -DAVIAN_JAVA_HOME=\"$(javahome)\" \ -DAVIAN_EMBED_PREFIX=\"$(embed-prefix)\" \ @@ -629,7 +840,7 @@ ifdef msvc -I"$(windows-java-home)/include" -I"$(windows-java-home)/include/win32" \ -DTARGET_BYTES_PER_WORD=$(pointer-size) - ifneq ($(lzma),) + ifneq ($(lzma),) cflags += -I$(shell $(windows-path) "$(lzma)") endif @@ -656,9 +867,11 @@ ifdef msvc strip = : endif +build-cflags += -DAVIAN_HOST_TARGET + c-objects = $(foreach x,$(1),$(patsubst $(2)/%.c,$(3)/%.o,$(x))) cpp-objects = $(foreach x,$(1),$(patsubst $(2)/%.cpp,$(3)/%.o,$(x))) -asm-objects = $(foreach x,$(1),$(patsubst $(2)/%.S,$(3)/%-asm.o,$(x))) +asm-objects = $(foreach x,$(1),$(patsubst $(2)/%.$(asm-format),$(3)/%-asm.o,$(x))) java-classes = $(foreach x,$(1),$(patsubst $(2)/%.java,$(3)/%.class,$(x))) generated-code = \ @@ -684,7 +897,7 @@ vm-sources = \ $(src)/jnienv.cpp \ $(src)/process.cpp -vm-asm-sources = $(src)/$(asm).S +vm-asm-sources = $(src)/$(asm).$(asm-format) target-asm = $(asm) @@ -702,8 +915,9 @@ ifeq ($(process),compile) $(src)/compiler.cpp \ $(src)/$(target-asm).cpp - vm-asm-sources += $(src)/compile-$(asm).S + vm-asm-sources += $(src)/compile-$(asm).$(asm-format) endif +cflags += -DAVIAN_PROCESS_$(process) vm-cpp-objects = $(call cpp-objects,$(vm-sources),$(src),$(build)) vm-asm-objects = $(call asm-objects,$(vm-asm-sources),$(src),$(build)) @@ -835,7 +1049,7 @@ converter-objects = $(call cpp-objects,$(converter-sources),$(src),$(build)) converter-tool-objects = $(call cpp-objects,$(converter-tool-sources),$(src),$(build)) converter = $(build)/binaryToObject/binaryToObject -static-library = $(build)/lib$(name).a +static-library = $(build)/$(static-prefix)$(name)${static-suffix} executable = $(build)/$(name)${exe-suffix} dynamic-library = $(build)/$(so-prefix)jvm$(so-suffix) executable-dynamic = $(build)/$(name)-dynamic${exe-suffix} @@ -945,9 +1159,15 @@ test-flags = -Djava.library.path=$(build) -cp $(build)/test test-args = $(test-flags) $(input) .PHONY: build +ifneq ($(supports_avian_executable),false) build: $(static-library) $(executable) $(dynamic-library) $(lzma-loader) \ $(lzma-encoder) $(executable-dynamic) $(classpath-dep) $(test-dep) \ $(test-extra-dep) $(embed) +else +build: $(static-library) $(dynamic-library) $(lzma-loader) \ + $(lzma-encoder) $(classpath-dep) $(test-dep) \ + $(test-extra-dep) $(embed) +endif $(test-dep): $(classpath-dep) @@ -992,7 +1212,7 @@ clean: @echo "removing build" rm -rf build -$(build)/compile-x86-asm.o: $(src)/continuations-x86.S +$(build)/compile-x86-asm.o: $(src)/continuations-x86.$(asm-format) gen-arg = $(shell echo $(1) | sed -e 's:$(build)/type-\(.*\)\.cpp:\1:') $(generated-code): %.cpp: $(src)/types.def $(generator) $(classpath-dep) @@ -1043,7 +1263,7 @@ endef define compile-asm-object @echo "compiling $(@)" @mkdir -p $(dir $(@)) - $(as) -I$(src) $(asmflags) -c $(<) -o $(@) + $(as) $(asmflags) $(call asm-output,$(@)) $(call asm-input,$(<)) endef $(vm-cpp-objects): $(build)/%.o: $(src)/%.cpp $(vm-depends) @@ -1054,10 +1274,12 @@ $(test-cpp-objects): $(test-build)/%.o: $(test)/%.cpp $(vm-depends) $(test-library): $(test-cpp-objects) @echo "linking $(@)" -ifdef msvc +ifdef ms_cl_compiler $(ld) $(shared) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \ - -IMPLIB:$(test-build)/$(name).lib -MANIFESTFILE:$(@).manifest - $(mt) -manifest $(@).manifest -outputresource:"$(@);2" + -IMPLIB:$(test-build)/$(name).lib $(manifest-flags) +ifdef mt + $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);2" +endif else $(ld) $(^) $(shared) $(lflags) -o $(@) endif @@ -1065,10 +1287,12 @@ endif ifdef embed $(embed): $(embed-objects) $(embed-loader-o) @echo "building $(embed)" -ifdef msvc +ifdef ms_cl_compiler $(ld) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \ - -IMPLIB:$(@).lib -MANIFESTFILE:$(@).manifest - $(mt) -manifest $(@).manifest -outputresource:"$(@);1" + -IMPLIB:$(@).lib $(manifest-flags) +ifdef mt + $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" +endif else $(cxx) $(^) $(lflags) $(static) $(call output,$(@)) endif @@ -1086,10 +1310,12 @@ $(embed-loader-o): $(embed-loader) $(converter) $(embed-loader): $(embed-loader-objects) $(static-library) @mkdir -p $(dir $(@)) cd $(dir $(@)) && $(ar) x ../../../$(static-library) -ifdef msvc +ifdef ms_cl_compiler $(ld) $(lflags) $(dir $(@))/*.o -out:$(@) -PDB:$(@).pdb \ - -IMPLIB:$(@).lib -MANIFESTFILE:$(@).manifest - $(mt) -manifest $(@).manifest -outputresource:"$(@);1" + -IMPLIB:$(@).lib $(manifest-flags) +ifdef mt + $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" +endif else $(dlltool) -z $(addsuffix .def,$(basename $(@))) $(dir $(@))/*.o $(dlltool) -d $(addsuffix .def,$(basename $(@))) -e $(addsuffix .exp,$(basename $(@))) @@ -1109,7 +1335,7 @@ $(build)/%.o: $(lzma)/C/%.c @mkdir -p $(dir $(@)) $(cxx) $(cflags) $(no-error) -c $$($(windows-path) $(<)) $(call output,$(@)) -$(vm-asm-objects): $(build)/%-asm.o: $(src)/%.S +$(vm-asm-objects): $(build)/%-asm.o: $(src)/%.$(asm-format) $(compile-asm-object) $(bootimage-generator-objects): $(build)/%.o: $(src)/%.cpp $(vm-depends) @@ -1196,14 +1422,18 @@ $(static-library): $(vm-objects) $(classpath-objects) $(vm-heapwalk-objects) \ $(javahome-object) $(boot-javahome-object) $(lzma-decode-objects) @echo "creating $(@)" rm -rf $(@) +ifdef ms_cl_compiler + $(ar) $(arflags) $(^) -out:$(@) +else $(ar) cru $(@) $(^) $(ranlib) $(@) +endif -$(bootimage-object) $(codeimage-object): $(bootimage-generator) \ - $(build)/classpath.jar +$(bootimage-object) $(codeimage-object): $(bootimage-generator) + @echo "generating bootimage and codeimage binaries using $(<)" $(<) -cp $(classpath-build) -bootimage $(bootimage-object) -codeimage $(codeimage-object) \ - -bootimage-symbols _binary_bootimage_bin_start:_binary_bootimage_bin_end \ - -codeimage-symbols _binary_codeimage_bin_start:_binary_codeimage_bin_end + -bootimage-symbols $(bootimage-symbols) \ + -codeimage-symbols $(codeimage-symbols) executable-objects = $(vm-objects) $(classpath-objects) $(driver-object) \ $(vm-heapwalk-objects) $(boot-object) $(vm-classpath-objects) \ @@ -1212,10 +1442,12 @@ executable-objects = $(vm-objects) $(classpath-objects) $(driver-object) \ $(executable): $(executable-objects) @echo "linking $(@)" ifeq ($(platform),windows) -ifdef msvc +ifdef ms_cl_compiler $(ld) $(lflags) $(executable-objects) -out:$(@) -PDB:$(@).pdb \ - -IMPLIB:$(@).lib -MANIFESTFILE:$(@).manifest - $(mt) -manifest $(@).manifest -outputresource:"$(@);1" + -IMPLIB:$(@).lib $(manifest-flags) +ifdef mt + $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" +endif else $(dlltool) -z $(@).def $(executable-objects) $(dlltool) -d $(@).def -e $(@).exp @@ -1229,6 +1461,7 @@ endif $(bootimage-generator): $(bootimage-generator-objects) echo arch=$(arch) platform=$(platform) $(MAKE) mode=$(mode) \ + build-prefix=$(build)/host/ \ arch=$(build-arch) \ target-arch=$(arch) \ platform=$(bootimage-platform) \ @@ -1247,17 +1480,19 @@ $(build-bootimage-generator): \ $(lzma-decode-objects) $(lzma-encode-objects) @echo "linking $(@)" ifeq ($(platform),windows) -ifdef msvc - $(ld) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb -IMPLIB:$(@).lib \ - -MANIFESTFILE:$(@).manifest - $(mt) -manifest $(@).manifest -outputresource:"$(@);1" +ifdef ms_cl_compiler + $(ld) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \ + -IMPLIB:$(@).lib $(manifest-flags) +ifdef mt + $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" +endif else $(dlltool) -z $(@).def $(^) $(dlltool) -d $(@).def -e $(@).exp - $(ld) $(@).exp $(^) $(lflags) -o $(@) + $(ld) $(@).exp $(^) $(bootimage-generator-lflags) $(lflags) -o $(@) endif else - $(ld) $(^) $(rdynamic) $(lflags) -o $(@) + $(ld) $(^) $(rdynamic) $(bootimage-generator-lflags) $(lflags) -o $(@) endif $(dynamic-library): $(vm-objects) $(dynamic-object) $(classpath-objects) \ @@ -1265,10 +1500,12 @@ $(dynamic-library): $(vm-objects) $(dynamic-object) $(classpath-objects) \ $(classpath-libraries) $(javahome-object) $(boot-javahome-object) \ $(lzma-decode-objects) @echo "linking $(@)" -ifdef msvc +ifdef ms_cl_compiler $(ld) $(shared) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \ - -IMPLIB:$(build)/$(name).lib -MANIFESTFILE:$(@).manifest - $(mt) -manifest $(@).manifest -outputresource:"$(@);2" + -IMPLIB:$(build)/$(name).lib $(manifest-flags) +ifdef mt + $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);2" +endif else $(ld) $(^) $(version-script-flag) $(soname-flag) \ $(shared) $(lflags) $(bootimage-lflags) \ @@ -1280,11 +1517,13 @@ endif # Ubuntu 11.10 which may be fixable without disabling LTO. $(executable-dynamic): $(driver-dynamic-objects) $(dynamic-library) @echo "linking $(@)" -ifdef msvc +ifdef ms_cl_compiler $(ld) $(lflags) -LIBPATH:$(build) -DEFAULTLIB:$(name) \ - -PDB:$(@).pdb -IMPLIB:$(@).lib $(driver-dynamic-objects) -out:$(@) \ - -MANIFESTFILE:$(@).manifest - $(mt) -manifest $(@).manifest -outputresource:"$(@);1" + -PDB:$(@).pdb -IMPLIB:$(@).lib $(driver-dynamic-objects) \ + -out:$(@) $(manifest-flags) +ifdef mt + $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" +endif else $(ld) $(driver-dynamic-objects) -L$(build) -ljvm $(lflags) $(no-lto) -o $(@) endif diff --git a/src/arm.h b/src/arm.h index 7e7a4d61dd..adfd92b4ad 100644 --- a/src/arm.h +++ b/src/arm.h @@ -71,33 +71,53 @@ namespace vm { inline void trap() { +#ifdef _MSC_VER + __debugbreak(); +#else asm("bkpt"); +#endif } +#ifndef _MSC_VER inline void memoryBarrier() { asm("nop"); } +#endif inline void storeStoreMemoryBarrier() { +#ifdef _MSC_VER + _ReadWriteBarrier(); +#else memoryBarrier(); +#endif } inline void storeLoadMemoryBarrier() { +#ifdef _MSC_VER + MemoryBarrier(); +#else memoryBarrier(); +#endif } inline void loadMemoryBarrier() { +#ifdef _MSC_VER + _ReadWriteBarrier(); +#else memoryBarrier(); +#endif } +#if defined(AVIAN_PROCESS_compile) + #if defined(__ANDROID__) // http://code.google.com/p/android/issues/detail?id=1803 extern "C" void __clear_cache (void *beg __attribute__((__unused__)), void *end __attribute__((__unused__))); @@ -116,6 +136,8 @@ syncInstructionCache(const void* start, unsigned size) #endif } +#endif // AVIAN_PROCESS_compile + #ifndef __APPLE__ typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr); # define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0) @@ -160,7 +182,7 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t* argumentTypes, unsigned vfpIndex = 0; unsigned vfpBackfillIndex UNUSED = 0; - uintptr_t stack[(argumentCount * 8) / BytesPerWord]; // is > argumentSize to account for padding + uintptr_t* stack = new uintptr_t[(argumentCount * 8) / BytesPerWord]; // is > argumentSize to account for padding unsigned stackIndex = 0; unsigned ai = 0; @@ -250,10 +272,12 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t* argumentTypes, } unsigned stackSize = stackIndex*BytesPerWord + ((stackIndex & 1) << 2); - return vmNativeCall + auto retVal = vmNativeCall (function, stackSize, stack, stackIndex * BytesPerWord, (gprIndex ? gprTable : 0), (vfpIndex ? vfpTable : 0), returnType); + delete[] stack; + return retVal; } } // namespace vm diff --git a/src/arm.masm b/src/arm.masm new file mode 100644 index 0000000000..8fc09eb875 --- /dev/null +++ b/src/arm.masm @@ -0,0 +1,77 @@ + AREA text, CODE, ARM + + EXPORT vmNativeCall [FUNC] +vmNativeCall + ; arguments: + ; r0 -> r4 : function + ; r1 -> r5 : stackTotal + ; r2 : memoryTable + ; r3 : memoryCount + ; [sp, #0] -> r6 : gprTable + + mov ip, sp ; save stack frame + stmfd sp!, {r4-r6, lr} ; save clobbered non-volatile regs + + ; mv args into non-volatile regs + mov r4, r0 + mov r5, r1 + ldr r6, [ip] + + ; setup stack arguments if necessary + sub sp, sp, r5 ; allocate stack + mov ip, sp +loop + tst r3, r3 + ldrne r0, [r2], #4 + strne r0, [ip], #4 + subne r3, r3, #4 + bne loop + + ; setup argument registers if necessary + tst r6, r6 + ldmneia r6, {r0-r3} + + blx r4 ; call function + add sp, sp, r5 ; deallocate stack + + ldmfd sp!, {r4-r6, pc} ; restore non-volatile regs and return + + EXPORT vmJump [FUNC] +vmJump + mov lr, r0 + ldr r0, [sp] + ldr r1, [sp, #4] + mov sp, r2 + mov r8, r3 + bx lr + +CHECKPOINT_THREAD EQU 4 +CHECKPOINT_STACK EQU 24 + + EXPORT vmRun [FUNC] +vmRun + ; r0: function + ; r1: arguments + ; r2: checkpoint + stmfd sp!, {r4-r11, lr} + ; align stack + sub sp, sp, #12 + + str sp, [r2, #CHECKPOINT_STACK] + + mov r12, r0 + ldr r0, [r2, #CHECKPOINT_THREAD] + + blx r12 + + EXPORT vmRun_returnAddress [FUNC] +vmRun_returnAddress + add sp, sp, #12 + ldmfd sp!, {r4-r11, lr} + bx lr + + EXPORT vmTrap [FUNC] +vmTrap + bkpt 3 + + END \ No newline at end of file diff --git a/src/binaryToObject/pe.cpp b/src/binaryToObject/pe.cpp index 8d5d5fc444..186e491447 100644 --- a/src/binaryToObject/pe.cpp +++ b/src/binaryToObject/pe.cpp @@ -17,13 +17,17 @@ namespace { -#define IMAGE_SIZEOF_SHORT_NAME 8 +// --- winnt.h ---- +#define IMAGE_SIZEOF_SHORT_NAME 8 -#define IMAGE_FILE_RELOCS_STRIPPED 1 -#define IMAGE_FILE_LINE_NUMS_STRIPPED 4 -#define IMAGE_FILE_MACHINE_AMD64 0x8664 -#define IMAGE_FILE_MACHINE_I386 0x014c -#define IMAGE_FILE_32BIT_MACHINE 256 +#define IMAGE_FILE_RELOCS_STRIPPED 0x0001 // Relocation info stripped from file. +#define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 // Line nunbers stripped from file. +#define IMAGE_FILE_MACHINE_AMD64 0x8664 // AMD64 (K8) +#define IMAGE_FILE_MACHINE_I386 0x014c // Intel 386. +#define IMAGE_FILE_MACHINE_ARM 0x01c0 // ARM Little-Endian +#define IMAGE_FILE_MACHINE_THUMB 0x01c2 // ARM Thumb/Thumb-2 Little-Endian +#define IMAGE_FILE_MACHINE_ARMNT 0x01c4 // ARM Thumb-2 Little-Endian +#define IMAGE_FILE_32BIT_MACHINE 0x0100 // 32 bit word machine. #define IMAGE_SCN_ALIGN_1BYTES 0x100000 #define IMAGE_SCN_ALIGN_2BYTES 0x200000 @@ -73,6 +77,7 @@ struct IMAGE_SYMBOL { uint8_t StorageClass; uint8_t NumberOfAuxSymbols; } __attribute__((packed)); +// --- winnt.h ---- inline unsigned pad(unsigned n) @@ -82,7 +87,7 @@ pad(unsigned n) using namespace avian::tools; -template +template class WindowsPlatform : public Platform { public: @@ -202,12 +207,15 @@ public: int machine; int machineMask; - if (BytesPerWord == 8) { + if (Architecture == PlatformInfo::x86_64) { machine = IMAGE_FILE_MACHINE_AMD64; machineMask = 0; - } else { // if (BytesPerWord == 8) + } else if (Architecture == PlatformInfo::x86) { machine = IMAGE_FILE_MACHINE_I386; machineMask = IMAGE_FILE_32BIT_MACHINE; + } else if (Architecture == PlatformInfo::Arm) { + machine = IMAGE_FILE_MACHINE_ARMNT; + machineMask = IMAGE_FILE_32BIT_MACHINE; } int sectionMask; @@ -269,10 +277,11 @@ public: } WindowsPlatform(): - Platform(PlatformInfo(PlatformInfo::Pe, BytesPerWord == 4 ? PlatformInfo::x86 : PlatformInfo::x86_64)) {} + Platform(PlatformInfo(PlatformInfo::Pe, Architecture)) {} }; -WindowsPlatform<4> windows32Platform; -WindowsPlatform<8> windows64Platform; +WindowsPlatform<4, PlatformInfo::x86> windows32Platform; +WindowsPlatform<8, PlatformInfo::x86_64> windows64Platform; +WindowsPlatform<4, PlatformInfo::Arm> windowsRtPlatform; // Windows Phone 8 and Windows RT } // namespace diff --git a/src/bootimage.cpp b/src/bootimage.cpp index f82e73f9f5..ec04196ca0 100644 --- a/src/bootimage.cpp +++ b/src/bootimage.cpp @@ -342,7 +342,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, unsigned count = s.read2() - 1; if (count) { - Type types[count + 2]; + Type* types = new Type[count + 2]; types[0] = Type_object; types[1] = Type_intptr_t; @@ -410,6 +410,9 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, (t, typeMaps, hashMapFind (t, root(t, Machine::PoolMap), c, objectHash, objectEqual), array, objectHash); + + delete[] types; + types = 0; } } @@ -420,7 +423,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, object fields = allFields(t, typeMaps, c, &count, &array); PROTECT(t, fields); - Field memberFields[count + 1]; + Field* memberFields = new Field[count + 1]; unsigned memberIndex; unsigned buildMemberOffset; @@ -454,7 +457,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, const unsigned StaticHeader = 3; - Field staticFields[count + StaticHeader]; + Field* staticFields = new Field[count + StaticHeader]; init(new (staticFields) Field, Type_object, 0, BytesPerWord, 0, TargetBytesPerWord); @@ -586,6 +589,12 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, hashMapInsert (t, typeMaps, classStaticTable(t, c), array, objectHash); } + + delete[] memberFields; + memberFields = 0; + + delete[] staticFields; + staticFields = 0; } } } @@ -1334,7 +1343,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp } ++ count; - Field fields[count]; + Field* fields = new Field[count]; init(new (fields) Field, Type_object, 0, BytesPerWord, 0, TargetBytesPerWord); @@ -1462,6 +1471,9 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp hashMapInsert (t, typeMaps, vm::type(t, static_cast(i)), array, objectHash); + + delete[] fields; + fields = 0; } constants = makeCodeImage @@ -1646,10 +1658,10 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp Platform* platform = Platform::getPlatform(PlatformInfo((PlatformInfo::Format)AVIAN_TARGET_FORMAT, (PlatformInfo::Architecture)AVIAN_TARGET_ARCH)); - // if(!platform) { - // fprintf(stderr, "unsupported platform: %s/%s\n", os, architecture); - // return false; - // } + if(!platform) { + fprintf(stderr, "unsupported platform: target-format = %d / target-arch = %d\n", AVIAN_TARGET_FORMAT, AVIAN_TARGET_ARCH); + abort(); + } SymbolInfo bootimageSymbols[] = { SymbolInfo(0, bootimageStart), @@ -1768,7 +1780,7 @@ bool ArgParser::parse(int ac, const char** av) { } bool found = false; for(Arg* arg = first; arg; arg = arg->next) { - if(strcmp(arg->name, &av[i][1]) == 0) { + if(::strcmp(arg->name, &av[i][1]) == 0) { found = true; if (arg->desc == 0) { arg->value = "true"; @@ -1905,20 +1917,26 @@ public: exit(1); } +# if AVIAN_TARGET_FORMAT != AVIAN_FORMAT_PE +# define SYMBOL_PREFIX "_" +# else +# define SYMBOL_PREFIX +# endif + if(!bootimageStart) { - bootimageStart = strdup("_binary_bootimage_bin_start"); + bootimageStart = strdup(SYMBOL_PREFIX"binary_bootimage_bin_start"); } if(!bootimageEnd) { - bootimageEnd = strdup("_binary_bootimage_bin_end"); + bootimageEnd = strdup(SYMBOL_PREFIX"binary_bootimage_bin_end"); } if(!codeimageStart) { - codeimageStart = strdup("_binary_codeimage_bin_start"); + codeimageStart = strdup(SYMBOL_PREFIX"binary_codeimage_bin_start"); } if(!codeimageEnd) { - codeimageEnd = strdup("_binary_codeimage_bin_end"); + codeimageEnd = strdup(SYMBOL_PREFIX"binary_codeimage_bin_end"); } } diff --git a/src/common.h b/src/common.h index adab2f587f..c99f23410e 100644 --- a/src/common.h +++ b/src/common.h @@ -94,7 +94,13 @@ typedef int64_t intptr_t; typedef uint64_t uintptr_t; # define UINT64_C(x) x##L # define ARCH_x86_64 -@ define BYTES_PER_WORD 8 +# define BYTES_PER_WORD 8 +# elif defined _M_ARM_FP +typedef int32_t intptr_t; +typedef uint32_t uintptr_t; +# define UINT64_C(x) x##LL +# define ARCH_arm +# define BYTES_PER_WORD 4 # else # error "unsupported architecture" # endif diff --git a/src/interpret.cpp b/src/interpret.cpp index 4a324fd084..9399e96657 100644 --- a/src/interpret.cpp +++ b/src/interpret.cpp @@ -18,7 +18,7 @@ using namespace vm; -namespace { +namespace local { const unsigned FrameBaseOffset = 0; const unsigned FrameNextOffset = 1; @@ -2321,7 +2321,7 @@ interpret3(Thread* t, const int base) object class_ = resolveClassInPool(t, frameMethod(t, frame), index - 1); PROTECT(t, class_); - int32_t counts[dimensions]; + int32_t* counts = new int32_t[dimensions]; for (int i = dimensions - 1; i >= 0; --i) { counts[i] = popInt(t); if (UNLIKELY(counts[i] < 0)) { @@ -2338,6 +2338,9 @@ interpret3(Thread* t, const int base) populateMultiArray(t, array, counts, 0, dimensions); pushObject(t, array); + + delete[] counts; + counts = 0; } goto loop; case new_: { @@ -3100,7 +3103,7 @@ class MyProcessor: public Processor { (&byteArrayBody(t, methodSpec(t, method), 0)); pushArguments(t, this_, spec, arguments); - return ::invoke(t, method); + return local::invoke(t, method); } virtual object @@ -3124,7 +3127,7 @@ class MyProcessor: public Processor { (&byteArrayBody(t, methodSpec(t, method), 0)); pushArguments(t, this_, spec, arguments); - return ::invoke(t, method); + return local::invoke(t, method); } virtual object @@ -3148,7 +3151,7 @@ class MyProcessor: public Processor { (&byteArrayBody(t, methodSpec(t, method), 0)); pushArguments(t, this_, spec, indirectObjects, arguments); - return ::invoke(t, method); + return local::invoke(t, method); } virtual object @@ -3174,7 +3177,7 @@ class MyProcessor: public Processor { assert(t, ((methodFlags(t, method) & ACC_STATIC) == 0) xor (this_ == 0)); - return ::invoke(t, method); + return local::invoke(t, method); } virtual object getStackTrace(vm::Thread* t, vm::Thread*) { @@ -3254,8 +3257,8 @@ namespace vm { Processor* makeProcessor(System* system, Allocator* allocator, bool) { - return new (allocator->allocate(sizeof(MyProcessor))) - MyProcessor(system, allocator); + return new (allocator->allocate(sizeof(local::MyProcessor))) + local::MyProcessor(system, allocator); } } // namespace vm diff --git a/src/machine.h b/src/machine.h index 2924a13fb7..420a0192cb 100644 --- a/src/machine.h +++ b/src/machine.h @@ -1325,6 +1325,9 @@ checkDaemon(Thread* t); object& root(Thread* t, Machine::Root root); +#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) +# define vmRun vmRun_ +#endif extern "C" uint64_t vmRun(uint64_t (*function)(Thread*, uintptr_t*), uintptr_t* arguments, void* checkpoint); diff --git a/src/system.h b/src/system.h index c36aefacd9..14a29c7272 100644 --- a/src/system.h +++ b/src/system.h @@ -97,11 +97,13 @@ class System { virtual void disposeAll() = 0; }; +#if defined(AVIAN_PROCESS_compile) class SignalHandler { public: virtual bool handleSignal(void** ip, void** frame, void** stack, void** thread) = 0; }; +#endif class MonitorResource { public: @@ -121,17 +123,21 @@ class System { virtual bool success(Status) = 0; virtual void* tryAllocate(unsigned sizeInBytes) = 0; virtual void free(const void* p) = 0; +#if defined(AVIAN_PROCESS_compile) virtual void* tryAllocateExecutable(unsigned sizeInBytes) = 0; virtual void freeExecutable(const void* p, unsigned sizeInBytes) = 0; +#endif virtual Status attach(Runnable*) = 0; virtual Status start(Runnable*) = 0; virtual Status make(Mutex**) = 0; virtual Status make(Monitor**) = 0; virtual Status make(Local**) = 0; +#if defined(AVIAN_PROCESS_compile) virtual Status handleSegFault(SignalHandler* handler) = 0; virtual Status handleDivideByZero(SignalHandler* handler) = 0; virtual Status visit(Thread* thread, Thread* target, ThreadVisitor* visitor) = 0; +#endif virtual uint64_t call(void* function, uintptr_t* arguments, uint8_t* types, unsigned count, unsigned size, unsigned returnType) = 0; diff --git a/src/windows.cpp b/src/windows.cpp index 532b66e161..2d8c4c16c4 100644 --- a/src/windows.cpp +++ b/src/windows.cpp @@ -26,6 +26,71 @@ #include "arch.h" #include "system.h" +#if defined(WINAPI_FAMILY) + +#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + +#define WaitForSingleObject(hHandle, dwMilliseconds) \ + WaitForSingleObjectEx((hHandle), (dwMilliseconds), FALSE) + +#define CreateEvent(lpEventAttributes, bManualReset, bInitialState, lpName) \ + CreateEventEx((lpEventAttributes), (lpName), ((bManualReset)?CREATE_EVENT_MANUAL_RESET:0)|((bInitialState)?CREATE_EVENT_INITIAL_SET:0), EVENT_MODIFY_STATE) + +#define CreateMutex(lpEventAttributes, bInitialOwner, lpName) \ + CreateMutexEx((lpEventAttributes), (lpName), (bInitialOwner)?CREATE_MUTEX_INITIAL_OWNER:0, MUTEX_MODIFY_STATE) + +#include "thread-emulation.h" + +#endif + +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE) +// Headers in Windows Phone 8 DevKit contain severe error, so let's define needed functions on our own +extern "C" +{ +WINBASEAPI +_Ret_maybenull_ +HANDLE +WINAPI +CreateFileMappingFromApp( + _In_ HANDLE hFile, + _In_opt_ PSECURITY_ATTRIBUTES SecurityAttributes, + _In_ ULONG PageProtection, + _In_ ULONG64 MaximumSize, + _In_opt_ PCWSTR Name + ); + +WINBASEAPI +_Ret_maybenull_ __out_data_source(FILE) +PVOID +WINAPI +MapViewOfFileFromApp( + _In_ HANDLE hFileMappingObject, + _In_ ULONG DesiredAccess, + _In_ ULONG64 FileOffset, + _In_ SIZE_T NumberOfBytesToMap + ); + +WINBASEAPI +BOOL +WINAPI +UnmapViewOfFile( + _In_ LPCVOID lpBaseAddress + ); +} +#endif // WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE) + +#else + +#ifndef WINAPI_PARTITION_DESKTOP +#define WINAPI_PARTITION_DESKTOP 1 +#endif + +#ifndef WINAPI_FAMILY_PARTITION +#define WINAPI_FAMILY_PARTITION(x) (x) +#endif + +#endif + #define ACQUIRE(s, x) MutexResource MAKE_NAME(mutexResource_) (s, x) using namespace vm; @@ -49,16 +114,20 @@ class MutexResource { HANDLE m; }; +#if defined(AVIAN_PROCESS_compile) const unsigned SegFaultIndex = 0; const unsigned DivideByZeroIndex = 1; const unsigned HandlerCount = 2; +#endif class MySystem; MySystem* system; +#if defined(AVIAN_PROCESS_compile) LONG CALLBACK handleException(LPEXCEPTION_POINTERS e); +#endif DWORD WINAPI run(void* r) @@ -559,18 +628,22 @@ class MySystem: public System { }; MySystem(const char* crashDumpDirectory): +#if defined(AVIAN_PROCESS_compile) oldHandler(0), +#endif crashDumpDirectory(crashDumpDirectory) { expect(this, system == 0); system = this; +#if defined(AVIAN_PROCESS_compile) memset(handlers, 0, sizeof(handlers)); +#endif mutex = CreateMutex(0, false, 0); assert(this, mutex); } - +#if defined(AVIAN_PROCESS_compile) bool findHandler() { for (unsigned i = 0; i < HandlerCount; ++i) { if (handlers[i]) return true; @@ -578,6 +651,7 @@ class MySystem: public System { return false; } + //TODO: http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.application.unhandledexception(v=vs.105).aspx int registerHandler(System::SignalHandler* handler, int index) { if (handler) { handlers[index] = handler; @@ -609,7 +683,7 @@ class MySystem: public System { return 1; } } - +#endif virtual void* tryAllocate(unsigned sizeInBytes) { return malloc(sizeInBytes); } @@ -618,6 +692,7 @@ class MySystem: public System { if (p) ::free(const_cast(p)); } + #if defined(AVIAN_PROCESS_compile) virtual void* tryAllocateExecutable(unsigned sizeInBytes) { return VirtualAlloc (0, sizeInBytes, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); @@ -627,6 +702,7 @@ class MySystem: public System { int r UNUSED = VirtualFree(const_cast(p), 0, MEM_RELEASE); assert(this, r); } + #endif virtual bool success(Status s) { return s == 0; @@ -666,6 +742,7 @@ class MySystem: public System { return 0; } +#if defined(AVIAN_PROCESS_compile) virtual Status handleSegFault(SignalHandler* handler) { return registerHandler(handler, SegFaultIndex); } @@ -710,6 +787,7 @@ class MySystem: public System { return (success ? 0 : 1); } +#endif virtual uint64_t call(void* function, uintptr_t* arguments, uint8_t* types, unsigned count, unsigned size, unsigned returnType) @@ -719,15 +797,39 @@ class MySystem: public System { virtual Status map(System::Region** region, const char* name) { Status status = 1; - +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) HANDLE file = CreateFile(name, FILE_READ_DATA, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); +#else + size_t nameLen = strlen(name); + wchar_t* wideName = new wchar_t[nameLen + 1]; + size_t convertedChars = 0; + mbstowcs_s(&convertedChars, wideName, nameLen + 1, name, nameLen); + HANDLE file = CreateFile2(wideName, GENERIC_READ, FILE_SHARE_READ, + OPEN_EXISTING, 0); + delete[] wideName; +#endif if (file != INVALID_HANDLE_VALUE) { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) unsigned size = GetFileSize(file, 0); +#else + FILE_STANDARD_INFO info; + unsigned size = INVALID_FILE_SIZE; + if(GetFileInformationByHandleEx(file, FileStandardInfo, &info, sizeof(info))) + size = info.EndOfFile.QuadPart; +#endif if (size != INVALID_FILE_SIZE) { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) HANDLE mapping = CreateFileMapping(file, 0, PAGE_READONLY, 0, size, 0); +#else + HANDLE mapping = CreateFileMappingFromApp(file, 0, PAGE_READONLY, size, 0); +#endif if (mapping) { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) void* data = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0); +#else + void* data = MapViewOfFileFromApp(mapping, FILE_MAP_READ, 0, 0); +#endif if (data) { *region = new (allocate(this, sizeof(Region))) Region(this, static_cast(data), size, file, mapping); @@ -757,7 +859,12 @@ class MySystem: public System { memcpy(RUNTIME_ARRAY_BODY(buffer) + length, "\\*", 3); Directory* d = new (allocate(this, sizeof(Directory))) Directory(this); + +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) d->handle = FindFirstFile(RUNTIME_ARRAY_BODY(buffer), &(d->data)); +#else + d->handle = FindFirstFileEx(RUNTIME_ARRAY_BODY(buffer), FindExInfoStandard, &(d->data), FindExSearchNameMatch, 0, 0); +#endif if (d->handle == INVALID_HANDLE_VALUE) { d->dispose(); } else { @@ -797,6 +904,7 @@ class MySystem: public System { } virtual const char* toAbsolutePath(Allocator* allocator, const char* name) { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) if (strncmp(name, "//", 2) == 0 or strncmp(name, "\\\\", 2) == 0 or strncmp(name + 1, ":/", 2) == 0 @@ -808,6 +916,11 @@ class MySystem: public System { GetCurrentDirectory(MAX_PATH, buffer); return append(allocator, buffer, "\\", name); } +#else + //TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ + //Windows.ApplicationModel.Package.Current.InstalledLocation + return name; +#endif } virtual Status load(System::Library** lib, @@ -816,9 +929,23 @@ class MySystem: public System { HMODULE handle; unsigned nameLength = (name ? strlen(name) : 0); if (name) { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) handle = LoadLibrary(name); +#else + size_t nameLen = strlen(name); + wchar_t* wideName = new wchar_t[nameLen + 1]; + size_t convertedChars = 0; + mbstowcs_s(&convertedChars, wideName, nameLen + 1, name, nameLen); + handle = LoadPackagedLibrary(wideName, 0); + delete[] wideName; +#endif } else { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) handle = GetModuleHandle(0); +#else + // Most of WinRT/WP8 applications can not host native object files inside main executable + assert(this, false); +#endif } if (handle) { @@ -866,7 +993,11 @@ class MySystem: public System { } virtual void yield() { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) SwitchToThread(); +#else + YieldProcessor(); +#endif } virtual void exit(int code) { @@ -886,11 +1017,15 @@ class MySystem: public System { } HANDLE mutex; +#if defined(AVIAN_PROCESS_compile) SignalHandler* handlers[HandlerCount]; LPTOP_LEVEL_EXCEPTION_FILTER oldHandler; +#endif const char* crashDumpDirectory; }; +#if defined(AVIAN_PROCESS_compile) + #pragma pack(push,4) struct MINIDUMP_EXCEPTION_INFORMATION { DWORD thread; @@ -1005,6 +1140,8 @@ handleException(LPEXCEPTION_POINTERS e) return EXCEPTION_CONTINUE_SEARCH; } +#endif + } // namespace namespace vm { diff --git a/src/x86.masm b/src/x86.masm new file mode 100644 index 0000000000..715669f8c1 --- /dev/null +++ b/src/x86.masm @@ -0,0 +1,166 @@ +comment # + Copyright (c) 2008-2011, 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. +# + +.586 +.MODEL FLAT, C + +VOID_TYPE equ 0 +INT8_TYPE equ 1 +INT16_TYPE equ 2 +INT32_TYPE equ 3 +INT64_TYPE equ 4 +FLOAT_TYPE equ 5 +DOUBLE_TYPE equ 6 +POINTER_TYPE equ 7 + +CHECKPOINT_THREAD equ 4 +CHECKPOINT_STACK equ 24 +CHECKPOINT_BASE equ 28 + +_TEXT SEGMENT + +public C detectFeature +detectFeature: + push ebp + mov ebp,esp + push edx + push ecx + push ebx + push esi + push edi + mov esi,ds:dword ptr[12+ebp] + mov edi,ds:dword ptr[8+ebp] + mov eax,1 + cpuid + and edx,esi + and ecx,edi + or ecx,edx + test ecx,ecx + je LNOSSE + mov eax,1 + jmp LSSEEND + +LNOSSE: + mov eax,0 + +LSSEEND: + pop edi + pop esi + pop ebx + pop ecx + pop edx + mov esp,ebp + pop ebp + ret + +public C vmNativeCall +vmNativeCall: + push ebp + mov ebp,esp + mov ecx,ds:dword ptr[16+ebp] + sub esp,ecx + mov ecx,0 + jmp Ltest + +Lloop: + mov eax,ecx + mov edx,ecx + add edx,esp + add eax,ds:dword ptr[12+ebp] + mov eax,ds:dword ptr[eax] + mov ds:dword ptr[edx],eax + add ecx,4 + +Ltest: + cmp ecx,ds:dword ptr[16+ebp] + jb Lloop + call dword ptr[8+ebp] + mov ecx,ds:dword ptr[20+ebp] + +Lvoid: + cmp ecx,offset VOID_TYPE + jne Lint64 + jmp Lexit + +Lint64: + cmp ecx,offset INT64_TYPE + jne Lfloat + jmp Lexit + +Lfloat: + cmp ecx,offset FLOAT_TYPE + jne Ldouble + fstp ds:dword ptr[8+ebp] + mov eax,ds:dword ptr[8+ebp] + jmp Lexit + +Ldouble: + cmp ecx,offset DOUBLE_TYPE + jne Lexit + fstp ds:dword ptr[8+ebp] + mov eax,ds:dword ptr[8+ebp] + mov edx,ds:dword ptr[12+ebp] + +Lexit: + mov esp,ebp + pop ebp + ret + +public C vmJump +vmJump: + mov esi,ds:dword ptr[4+esp] + mov ebp,ds:dword ptr[8+esp] + mov ebx,ds:dword ptr[16+esp] + mov eax,ds:dword ptr[20+esp] + mov edx,ds:dword ptr[24+esp] + mov esp,ds:dword ptr[12+esp] + jmp esi + +VMRUN_FRAME_SIZE equ 24 + +public C vmRun_ +vmRun_: + ; 8(%ebp): function + ; 12(%ebp): arguments + ; 16(%ebp): checkpoint + push ebp + mov ebp,esp + sub esp,offset VMRUN_FRAME_SIZE + + mov ds:dword ptr[8+esp],ebx + mov ds:dword ptr[12+esp],esi + mov ds:dword ptr[16+esp],edi + + mov eax,ds:dword ptr[12+ebp] + mov ds:dword ptr[4+esp],eax + + mov ecx,ds:dword ptr[16+ebp] + mov eax,ds:dword ptr[CHECKPOINT_THREAD+ecx] + mov ds:dword ptr[0+esp],eax + + mov ds:dword ptr[CHECKPOINT_STACK+ecx],esp + + call dword ptr[8+ebp] + +public C vmRun_returnAddress +vmRun_returnAddress: + + mov ebx,ds:dword ptr[8+esp] + mov esi,ds:dword ptr[12+esp] + mov edi,ds:dword ptr[16+esp] + + add esp,offset VMRUN_FRAME_SIZE + pop ebp + ret + +_TEXT ENDS +END \ No newline at end of file From c5adad9dce69d6c280289b1804d972a9a96950f2 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Mon, 28 Jan 2013 19:15:29 +0200 Subject: [PATCH 012/106] Makefile fix --- makefile | 16 ++++++++++------ src/arm.h | 4 ++-- src/system.h | 6 +++--- src/windows.cpp | 18 +++++++++--------- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/makefile b/makefile index 28ef8be401..066b4327c3 100755 --- a/makefile +++ b/makefile @@ -51,7 +51,8 @@ ifeq ($(continuations),true) endif root := $(shell (cd .. && pwd)) -build = $(build-prefix)build/$(platform)-$(arch)$(options) +build = build/$(platform)-$(arch)$(options) +host-build-root = $(build)/host classpath-build = $(build)/classpath test-build = $(build)/test src = src @@ -135,7 +136,7 @@ ifneq ($(openjdk),) javahome = "$$($(native-path) "$(openjdk)/jre")" endif - classpath = openjdk + classpath = openjdk boot-classpath := "$(boot-classpath)$(path-separator)$$($(native-path) "$(openjdk)/jre/lib/rt.jar")" build-javahome = $(openjdk)/jre endif @@ -640,7 +641,7 @@ ifeq ($(platform),wp8) ms_cl_compiler = wp8 use-lto = false supports_avian_executable = false - process = interpret + process = compile ifneq ($(process),compile) options := -$(process) endif @@ -918,6 +919,9 @@ ifeq ($(process),compile) vm-asm-sources += $(src)/compile-$(asm).$(asm-format) endif cflags += -DAVIAN_PROCESS_$(process) +ifdef aot_only + cflags += -DAVIAN_AOT_ONLY +endif vm-cpp-objects = $(call cpp-objects,$(vm-sources),$(src),$(build)) vm-asm-objects = $(call asm-objects,$(vm-asm-sources),$(src),$(build)) @@ -1430,7 +1434,7 @@ else endif $(bootimage-object) $(codeimage-object): $(bootimage-generator) - @echo "generating bootimage and codeimage binaries using $(<)" + @echo "generating bootimage and codeimage binaries from $(classpath-build) using $(<)" $(<) -cp $(classpath-build) -bootimage $(bootimage-object) -codeimage $(codeimage-object) \ -bootimage-symbols $(bootimage-symbols) \ -codeimage-symbols $(codeimage-symbols) @@ -1459,9 +1463,9 @@ endif $(strip) $(strip-all) $(@) $(bootimage-generator): $(bootimage-generator-objects) - echo arch=$(arch) platform=$(platform) + echo building $(bootimage-generator) arch=$(build-arch) platform=$(bootimage-platform) $(MAKE) mode=$(mode) \ - build-prefix=$(build)/host/ \ + build=$(host-build-root) \ arch=$(build-arch) \ target-arch=$(arch) \ platform=$(bootimage-platform) \ diff --git a/src/arm.h b/src/arm.h index adfd92b4ad..302355c453 100644 --- a/src/arm.h +++ b/src/arm.h @@ -116,7 +116,7 @@ loadMemoryBarrier() #endif } -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) #if defined(__ANDROID__) // http://code.google.com/p/android/issues/detail?id=1803 @@ -136,7 +136,7 @@ syncInstructionCache(const void* start, unsigned size) #endif } -#endif // AVIAN_PROCESS_compile +#endif // AVIAN_AOT_ONLY #ifndef __APPLE__ typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr); diff --git a/src/system.h b/src/system.h index 14a29c7272..ee80d2a7cb 100644 --- a/src/system.h +++ b/src/system.h @@ -97,7 +97,7 @@ class System { virtual void disposeAll() = 0; }; -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) class SignalHandler { public: virtual bool handleSignal(void** ip, void** frame, void** stack, @@ -123,7 +123,7 @@ class System { virtual bool success(Status) = 0; virtual void* tryAllocate(unsigned sizeInBytes) = 0; virtual void free(const void* p) = 0; -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) virtual void* tryAllocateExecutable(unsigned sizeInBytes) = 0; virtual void freeExecutable(const void* p, unsigned sizeInBytes) = 0; #endif @@ -132,7 +132,7 @@ class System { virtual Status make(Mutex**) = 0; virtual Status make(Monitor**) = 0; virtual Status make(Local**) = 0; -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) virtual Status handleSegFault(SignalHandler* handler) = 0; virtual Status handleDivideByZero(SignalHandler* handler) = 0; virtual Status visit(Thread* thread, Thread* target, diff --git a/src/windows.cpp b/src/windows.cpp index 2d8c4c16c4..f6b9627254 100644 --- a/src/windows.cpp +++ b/src/windows.cpp @@ -114,7 +114,7 @@ class MutexResource { HANDLE m; }; -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) const unsigned SegFaultIndex = 0; const unsigned DivideByZeroIndex = 1; @@ -124,7 +124,7 @@ const unsigned HandlerCount = 2; class MySystem; MySystem* system; -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) LONG CALLBACK handleException(LPEXCEPTION_POINTERS e); #endif @@ -628,7 +628,7 @@ class MySystem: public System { }; MySystem(const char* crashDumpDirectory): -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) oldHandler(0), #endif crashDumpDirectory(crashDumpDirectory) @@ -636,14 +636,14 @@ class MySystem: public System { expect(this, system == 0); system = this; -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) memset(handlers, 0, sizeof(handlers)); #endif mutex = CreateMutex(0, false, 0); assert(this, mutex); } -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) bool findHandler() { for (unsigned i = 0; i < HandlerCount; ++i) { if (handlers[i]) return true; @@ -692,7 +692,7 @@ class MySystem: public System { if (p) ::free(const_cast(p)); } - #if defined(AVIAN_PROCESS_compile) + #if !defined(AVIAN_AOT_ONLY) virtual void* tryAllocateExecutable(unsigned sizeInBytes) { return VirtualAlloc (0, sizeInBytes, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); @@ -742,7 +742,7 @@ class MySystem: public System { return 0; } -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) virtual Status handleSegFault(SignalHandler* handler) { return registerHandler(handler, SegFaultIndex); } @@ -1017,14 +1017,14 @@ class MySystem: public System { } HANDLE mutex; -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) SignalHandler* handlers[HandlerCount]; LPTOP_LEVEL_EXCEPTION_FILTER oldHandler; #endif const char* crashDumpDirectory; }; -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) #pragma pack(push,4) struct MINIDUMP_EXCEPTION_INFORMATION { From a78959a480a7ae5c862d358fcb1942f32485242e Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Mon, 28 Jan 2013 20:51:35 +0200 Subject: [PATCH 013/106] Replaced TODO comments with messages ; More correct AVIAN_AOT_ONLY usage --- classpath/java-lang.cpp | 15 +++++------ makefile | 1 + src/arm.cpp | 26 ++++++++++--------- src/arm.masm | 12 +++++++++ src/compile.cpp | 7 +++++- src/system.h | 4 --- src/windows.cpp | 55 ++++++++++++++++++++++------------------- src/x86.masm | 2 ++ 8 files changed, 72 insertions(+), 50 deletions(-) diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index 0414216194..9d2562e265 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -80,8 +80,8 @@ namespace { snprintf(errStr, 9, "%d", (int) err); return errStr; - //TODO: - // The better way to do this, if I could figure out how to convert LPTSTR to char* + #pragma message("TODO") + // The better way to do this, if I could figure out how to convert LPTSTR to char* //char* errStr; //LPTSTR s; //if(FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | @@ -390,7 +390,7 @@ Locale getLocale() { return Locale(lang, reg); #else - //TODO: CultureInfo.CurrentCulture + #pragma message("TODO: CultureInfo.CurrentCulture") return Locale("en", "US"); #endif } @@ -596,8 +596,7 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, GetTempPath(MAX_PATH, buffer); r = e->NewStringUTF(buffer); # else - //TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ - //Windows.Storage.ApplicationData.Current.TemporaryFolder + #pragma message("TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ Windows.Storage.ApplicationData.Current.TemporaryFolder") r = 0; # endif } else if (strcmp(chars, "user.dir") == 0) { @@ -606,8 +605,7 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, GetCurrentDirectory(MAX_PATH, buffer); r = e->NewStringUTF(buffer); # else - //TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ - //Windows.ApplicationModel.Package.Current.InstalledLocation + #pragma message("TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ Windows.ApplicationModel.Package.Current.InstalledLocation") r = 0; # endif } else if (strcmp(chars, "user.home") == 0) { @@ -621,8 +619,7 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, r = 0; } # else - //TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ - //Windows.Storage.KnownFolders.DocumentsLibrary; + #pragma message("TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ Windows.Storage.KnownFolders.DocumentsLibrary") r = 0; # endif # else diff --git a/makefile b/makefile index 066b4327c3..5f28ef4b3a 100755 --- a/makefile +++ b/makefile @@ -642,6 +642,7 @@ ifeq ($(platform),wp8) use-lto = false supports_avian_executable = false process = compile + aot_only = true ifneq ($(process),compile) options := -$(process) endif diff --git a/src/arm.cpp b/src/arm.cpp index ae657e30d5..1d4dbc8dd1 100644 --- a/src/arm.cpp +++ b/src/arm.cpp @@ -18,7 +18,7 @@ using namespace vm; -namespace { +namespace local { namespace isa { // SYSTEM REGISTERS @@ -252,7 +252,7 @@ class MyBlock: public Assembler::Block { this->start = start; this->next = static_cast(next); - ::resolve(this); + local::resolve(this); return start + size + padding(this, size); } @@ -2150,7 +2150,7 @@ class MyArchitecture: public Assembler::Architecture { } virtual unsigned argumentFootprint(unsigned footprint) { - return ::argumentFootprint(footprint); + return local::argumentFootprint(footprint); } virtual bool argumentAlignment() { @@ -2239,7 +2239,7 @@ class MyArchitecture: public Assembler::Architecture { unsigned targetParameterFootprint, void** ip, void** stack) { - ::nextFrame(&con, static_cast(start), size, footprint, link, + local::nextFrame(&con, static_cast(start), size, footprint, link, mostRecent, targetParameterFootprint, ip, stack); } @@ -2550,11 +2550,12 @@ class MyAssembler: public Assembler { } virtual void pushFrame(unsigned argumentCount, ...) { - struct { + struct Argument { unsigned size; OperandType type; Operand* operand; - } arguments[argumentCount]; + }; + Argument* arguments = new Argument[argumentCount]; va_list a; va_start(a, argumentCount); unsigned footprint = 0; @@ -2589,6 +2590,9 @@ class MyAssembler: public Assembler { offset += ceiling(arguments[i].size, TargetBytesPerWord); } } + + delete[] arguments; + arguments = 0; } virtual void allocateFrame(unsigned footprint) { @@ -2798,7 +2802,7 @@ class MyAssembler: public Assembler { bool jump = needJump(b); if (jump) { write4 - (dst + dstOffset, ::b((poolSize + TargetBytesPerWord - 8) >> 2)); + (dst + dstOffset, isa::b((poolSize + TargetBytesPerWord - 8) >> 2)); } dstOffset += poolSize + (jump ? TargetBytesPerWord : 0); @@ -2832,7 +2836,7 @@ class MyAssembler: public Assembler { } virtual Promise* offset(bool forTrace) { - return ::offset(&con, forTrace); + return local::offset(&con, forTrace); } virtual Block* endBlock(bool startNew) { @@ -2903,15 +2907,15 @@ namespace vm { Assembler::Architecture* makeArchitecture(System* system, bool) { - return new (allocate(system, sizeof(MyArchitecture))) MyArchitecture(system); + return new (allocate(system, sizeof(local::MyArchitecture))) local::MyArchitecture(system); } Assembler* makeAssembler(System* system, Allocator* allocator, Zone* zone, Assembler::Architecture* architecture) { - return new(zone) MyAssembler(system, allocator, zone, - static_cast(architecture)); + return new(zone) local::MyAssembler(system, allocator, zone, + static_cast(architecture)); } } // namespace vm diff --git a/src/arm.masm b/src/arm.masm index 8fc09eb875..2af5048ec7 100644 --- a/src/arm.masm +++ b/src/arm.masm @@ -1,3 +1,15 @@ +; Copyright (c) 2008-2011, 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. +; +; ORIGIN: https://github.com/gkvas/avian/tree/wince + AREA text, CODE, ARM EXPORT vmNativeCall [FUNC] diff --git a/src/compile.cpp b/src/compile.cpp index 6989d6446d..7fa51817c7 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -7389,8 +7389,9 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context) { trap(); } - +#if !defined(AVIAN_AOT_ONLY) syncInstructionCache(start, codeSize); +#endif } void @@ -9152,7 +9153,9 @@ class MyProcessor: public Processor { virtual void dispose() { if (codeAllocator.base) { +#if !defined(AVIAN_AOT_ONLY) s->freeExecutable(codeAllocator.base, codeAllocator.capacity); +#endif } compilationHandlers->dispose(allocator); @@ -9313,11 +9316,13 @@ class MyProcessor: public Processor { } virtual void boot(Thread* t, BootImage* image, uint8_t* code) { +#if !defined(AVIAN_AOT_ONLY) if (codeAllocator.base == 0) { codeAllocator.base = static_cast (s->tryAllocateExecutable(ExecutableAreaSizeInBytes)); codeAllocator.capacity = ExecutableAreaSizeInBytes; } +#endif if (image and code) { local::boot(static_cast(t), image, code); diff --git a/src/system.h b/src/system.h index ee80d2a7cb..ef69317f0b 100644 --- a/src/system.h +++ b/src/system.h @@ -97,13 +97,11 @@ class System { virtual void disposeAll() = 0; }; -#if !defined(AVIAN_AOT_ONLY) class SignalHandler { public: virtual bool handleSignal(void** ip, void** frame, void** stack, void** thread) = 0; }; -#endif class MonitorResource { public: @@ -132,12 +130,10 @@ class System { virtual Status make(Mutex**) = 0; virtual Status make(Monitor**) = 0; virtual Status make(Local**) = 0; -#if !defined(AVIAN_AOT_ONLY) virtual Status handleSegFault(SignalHandler* handler) = 0; virtual Status handleDivideByZero(SignalHandler* handler) = 0; virtual Status visit(Thread* thread, Thread* target, ThreadVisitor* visitor) = 0; -#endif virtual uint64_t call(void* function, uintptr_t* arguments, uint8_t* types, unsigned count, unsigned size, unsigned returnType) = 0; diff --git a/src/windows.cpp b/src/windows.cpp index f6b9627254..8c7512eab1 100644 --- a/src/windows.cpp +++ b/src/windows.cpp @@ -114,17 +114,15 @@ class MutexResource { HANDLE m; }; -#if !defined(AVIAN_AOT_ONLY) const unsigned SegFaultIndex = 0; const unsigned DivideByZeroIndex = 1; const unsigned HandlerCount = 2; -#endif class MySystem; MySystem* system; -#if !defined(AVIAN_AOT_ONLY) +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) LONG CALLBACK handleException(LPEXCEPTION_POINTERS e); #endif @@ -628,7 +626,7 @@ class MySystem: public System { }; MySystem(const char* crashDumpDirectory): -#if !defined(AVIAN_AOT_ONLY) +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) oldHandler(0), #endif crashDumpDirectory(crashDumpDirectory) @@ -636,14 +634,12 @@ class MySystem: public System { expect(this, system == 0); system = this; -#if !defined(AVIAN_AOT_ONLY) memset(handlers, 0, sizeof(handlers)); -#endif mutex = CreateMutex(0, false, 0); assert(this, mutex); } -#if !defined(AVIAN_AOT_ONLY) + bool findHandler() { for (unsigned i = 0; i < HandlerCount; ++i) { if (handlers[i]) return true; @@ -651,31 +647,38 @@ class MySystem: public System { return false; } - //TODO: http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.application.unhandledexception(v=vs.105).aspx int registerHandler(System::SignalHandler* handler, int index) { if (handler) { handlers[index] = handler; - + +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) if (oldHandler == 0) { -#ifdef ARCH_x86_32 +# ifdef ARCH_x86_32 oldHandler = SetUnhandledExceptionFilter(handleException); -#elif defined ARCH_x86_64 +# elif defined ARCH_x86_64 AddVectoredExceptionHandler(1, handleException); oldHandler = reinterpret_cast(1); -#endif +# endif } +#else + #pragma message("TODO: http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.application.unhandledexception(v=vs.105).aspx") +#endif return 0; } else if (handlers[index]) { handlers[index] = 0; if (not findHandler()) { -#ifdef ARCH_x86_32 +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +# ifdef ARCH_x86_32 SetUnhandledExceptionFilter(oldHandler); oldHandler = 0; -#elif defined ARCH_x86_64 +# elif defined ARCH_x86_64 // do nothing, handlers are never "unregistered" anyway -#endif +# endif +#else + #pragma message("TODO: http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.application.unhandledexception(v=vs.105).aspx") +#endif } return 0; @@ -683,7 +686,7 @@ class MySystem: public System { return 1; } } -#endif + virtual void* tryAllocate(unsigned sizeInBytes) { return malloc(sizeInBytes); } @@ -742,7 +745,6 @@ class MySystem: public System { return 0; } -#if !defined(AVIAN_AOT_ONLY) virtual Status handleSegFault(SignalHandler* handler) { return registerHandler(handler, SegFaultIndex); } @@ -754,6 +756,7 @@ class MySystem: public System { virtual Status visit(System::Thread* st UNUSED, System::Thread* sTarget, ThreadVisitor* visitor) { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) assert(this, st != sTarget); Thread* target = static_cast(sTarget); @@ -769,15 +772,15 @@ class MySystem: public System { rv = GetThreadContext(target->thread, &context); if (rv) { -#ifdef ARCH_x86_32 +# ifdef ARCH_x86_32 visitor->visit(reinterpret_cast(context.Eip), reinterpret_cast(context.Ebp), reinterpret_cast(context.Esp)); -#elif defined ARCH_x86_64 +# elif defined ARCH_x86_64 visitor->visit(reinterpret_cast(context.Rip), reinterpret_cast(context.Rbp), reinterpret_cast(context.Rsp)); -#endif +# endif success = true; } @@ -786,8 +789,11 @@ class MySystem: public System { } return (success ? 0 : 1); - } +#else + #pragma message("TODO: http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.application.unhandledexception(v=vs.105).aspx") + return false; #endif + } virtual uint64_t call(void* function, uintptr_t* arguments, uint8_t* types, unsigned count, unsigned size, unsigned returnType) @@ -917,8 +923,7 @@ class MySystem: public System { return append(allocator, buffer, "\\", name); } #else - //TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ - //Windows.ApplicationModel.Package.Current.InstalledLocation + #pragma message("TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ Windows.ApplicationModel.Package.Current.InstalledLocation") return name; #endif } @@ -1017,14 +1022,14 @@ class MySystem: public System { } HANDLE mutex; -#if !defined(AVIAN_AOT_ONLY) SignalHandler* handlers[HandlerCount]; +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) LPTOP_LEVEL_EXCEPTION_FILTER oldHandler; #endif const char* crashDumpDirectory; }; -#if !defined(AVIAN_AOT_ONLY) +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) #pragma pack(push,4) struct MINIDUMP_EXCEPTION_INFORMATION { diff --git a/src/x86.masm b/src/x86.masm index 715669f8c1..640637d5af 100644 --- a/src/x86.masm +++ b/src/x86.masm @@ -8,6 +8,8 @@ comment # There is NO WARRANTY for this software. See license.txt for details. + + ORIGIN: https://github.com/gkvas/avian/tree/wince # .586 From 9c67acfaf1567ab59772af575409772423f2674b Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Tue, 29 Jan 2013 09:40:29 +0200 Subject: [PATCH 014/106] WinRT/WP8 process=compile --- makefile | 2 + src/arm.masm | 10 +- src/compile-arm.masm | 252 +++++++++++++++++++++++++++++++++++++++++++ src/compile-x86.masm | 173 +++++++++++++++++++++++++++++ 4 files changed, 432 insertions(+), 5 deletions(-) create mode 100644 src/compile-arm.masm create mode 100644 src/compile-x86.masm diff --git a/makefile b/makefile index 5f28ef4b3a..b4512c010f 100755 --- a/makefile +++ b/makefile @@ -1217,7 +1217,9 @@ clean: @echo "removing build" rm -rf build +ifeq ($(continuations),true) $(build)/compile-x86-asm.o: $(src)/continuations-x86.$(asm-format) +endif gen-arg = $(shell echo $(1) | sed -e 's:$(build)/type-\(.*\)\.cpp:\1:') $(generated-code): %.cpp: $(src)/types.def $(generator) $(classpath-dep) diff --git a/src/arm.masm b/src/arm.masm index 2af5048ec7..e7bd2d864c 100644 --- a/src/arm.masm +++ b/src/arm.masm @@ -12,7 +12,7 @@ AREA text, CODE, ARM - EXPORT vmNativeCall [FUNC] + EXPORT vmNativeCall vmNativeCall ; arguments: ; r0 -> r4 : function @@ -48,7 +48,7 @@ loop ldmfd sp!, {r4-r6, pc} ; restore non-volatile regs and return - EXPORT vmJump [FUNC] + EXPORT vmJump vmJump mov lr, r0 ldr r0, [sp] @@ -60,7 +60,7 @@ vmJump CHECKPOINT_THREAD EQU 4 CHECKPOINT_STACK EQU 24 - EXPORT vmRun [FUNC] + EXPORT vmRun vmRun ; r0: function ; r1: arguments @@ -76,13 +76,13 @@ vmRun blx r12 - EXPORT vmRun_returnAddress [FUNC] + EXPORT vmRun_returnAddress vmRun_returnAddress add sp, sp, #12 ldmfd sp!, {r4-r11, lr} bx lr - EXPORT vmTrap [FUNC] + EXPORT vmTrap vmTrap bkpt 3 diff --git a/src/compile-arm.masm b/src/compile-arm.masm new file mode 100644 index 0000000000..a9c1e59cef --- /dev/null +++ b/src/compile-arm.masm @@ -0,0 +1,252 @@ +; Copyright (c) 2008-2011, 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. +; +; ORIGIN: https://github.com/gkvas/avian/tree/wince + +; types.inc +VOID_TYPE equ 0 +INT8_TYPE equ 1 +INT16_TYPE equ 2 +INT32_TYPE equ 3 +INT64_TYPE equ 4 +FLOAT_TYPE equ 5 +DOUBLE_TYPE equ 6 +POINTER_TYPE equ 7 + +; target-fields.inc +;TARGET_BYTES_PER_WORD = 4 + +TARGET_THREAD_EXCEPTION equ 44 +TARGET_THREAD_EXCEPTIONSTACKADJUSTMENT equ 2164 +TARGET_THREAD_EXCEPTIONOFFSET equ 2168 +TARGET_THREAD_EXCEPTIONHANDLER equ 2172 + +TARGET_THREAD_IP equ 2144 +TARGET_THREAD_STACK equ 2148 +TARGET_THREAD_NEWSTACK equ 2152 +TARGET_THREAD_SCRATCH equ 2156 +TARGET_THREAD_CONTINUATION equ 2160 +TARGET_THREAD_TAILADDRESS equ 2176 +TARGET_THREAD_VIRTUALCALLTARGET equ 2180 +TARGET_THREAD_VIRTUALCALLINDEX equ 2184 +TARGET_THREAD_HEAPIMAGE equ 2188 +TARGET_THREAD_CODEIMAGE equ 2192 +TARGET_THREAD_THUNKTABLE equ 2196 +TARGET_THREAD_STACKLIMIT equ 2220 + + AREA text, CODE, ARM + +BYTES_PER_WORD equ 4 + +CONTINUATION_NEXT equ 4 +CONTINUATION_ADDRESS equ 16 +CONTINUATION_RETURN_ADDRESS_OFFSET equ 20 +CONTINUATION_FRAME_POINTER_OFFSET equ 24 +CONTINUATION_LENGTH equ 28 +CONTINUATION_BODY equ 32 + + EXPORT vmInvoke +vmInvoke + + ; arguments + ; r0 : thread + ; r1 : function + ; r2 : arguments + ; r3 : argumentFootprint + ; [sp, #0] : frameSize (not used) + ; [sp, #4] : returnType + + + ; save all non-volatile registers + stmfd sp!, {r4-r11, lr} + + ; save return type + ldr r4, [sp, #4] + str r4, [sp, #-4]! + + str sp, [r0, #TARGET_THREAD_SCRATCH] + + ; align stack, if necessary + eor r4, sp, r3 + tst r4, #4 + subne sp, sp, #4 + + ; copy arguments into place + sub sp, sp, r3 + mov r4, #0 + b vmInvoke_argumentTest + +vmInvoke_argumentLoop + ldr r5, [r2, r4] + str r5, [sp, r4] + add r4, r4, #BYTES_PER_WORD + +vmInvoke_argumentTest + cmp r4, r3 + blt vmInvoke_argumentLoop + + ; we use r8 to hold the thread pointer, by convention + mov r8, r0 + + ; load and call function address + blx r1 + + EXPORT vmInvoke_returnAddress +vmInvoke_returnAddress + ; restore stack pointer + ldr sp, [r8, #TARGET_THREAD_SCRATCH] + + ; clear MyThread::stack to avoid confusing another thread calling + ; java.lang.Thread.getStackTrace on this one. See + ; MyProcess::getStackTrace in compile.cpp for details on how we get + ; a reliable stack trace from a thread that might be interrupted at + ; any point in its execution. + mov r5, #0 + str r5, [r8, #TARGET_THREAD_STACK] + + EXPORT vmInvoke_safeStack +vmInvoke_safeStack + +;if AVIAN_CONTINUATIONS +; ; call the next continuation, if any +; ldr r5,[r8,#TARGET_THREAD_CONTINUATION] +; cmp r5,#0 +; beq vmInvoke_exit) +; +; ldr r6,[r5,#CONTINUATION_LENGTH] +; lsl r6,r6,#2 +; neg r7,r6 +; add r7,r7,#-80 +; mov r4,sp +; str r4,[sp,r7]! +; +; add r7,r5,#CONTINUATION_BODY +; +; mov r11,#0 +; b vmInvoke_continuationTest +; +;vmInvoke_continuationLoop +; ldr r9,[r7,r11] +; str r9,[sp,r11] +; add r11,r11,#4 +; +;vmInvoke_continuationTest +; cmp r11,r6 +; ble vmInvoke_continuationLoop) +; +; ldr r7,[r5,#CONTINUATION_RETURN_ADDRESS_OFFSET] +; ldr r10,vmInvoke_returnAddress_word +; ldr r11,vmInvoke_getAddress_word +;vmInvoke_getAddress +; add r11,pc,r11 +; ldr r11,[r11,r10] +; str r11,[sp,r7] +; +; ldr r7,[r5,#CONTINUATION_NEXT] +; str r7,[r8,#TARGET_THREAD_CONTINUATION] +; +; ; call the continuation unless we're handling an exception +; ldr r7,[r8,#TARGET_THREAD_EXCEPTION] +; cmp r7,#0 +; bne vmInvoke_handleException) +; ldr r7,[r5,#CONTINUATION_ADDRESS] +; bx r7 +; +;vmInvoke_handleException +; ; we're handling an exception - call the exception handler instead +; mov r11,#0 +; str r11,[r8,#TARGET_THREAD_EXCEPTION] +; ldr r11,[r8,#TARGET_THREAD_EXCEPTIONSTACKADJUSTMENT] +; ldr r9,[sp] +; neg r11,r11 +; str r9,[sp,r11]! +; ldr r11,[r8,#TARGET_THREAD_EXCEPTIONOFFSET] +; str r7,[sp,r11] +; +; ldr r7,[r8,#TARGET_THREAD_EXCEPTIONHANDLER] +; bx r7 +; +;vmInvoke_exit +;endif ; AVIAN_CONTINUATIONS + + mov ip, #0 + str ip, [r8, #TARGET_THREAD_STACK] + + ; restore return type + ldr ip, [sp], #4 + + ; restore callee-saved registers + ldmfd sp!, {r4-r11, lr} + +vmInvoke_return + bx lr + + EXPORT vmJumpAndInvoke +vmJumpAndInvoke +;if :DEF:AVIAN_CONTINUATIONS +; ; r0: thread +; ; r1: address +; ; r2: stack +; ; r3: argumentFootprint +; ; [sp,#0]: arguments +; ; [sp,#4]: frameSize +; +; ldr r5,[sp,#0] +; ldr r6,[sp,#4] +; +; ; allocate new frame, adding room for callee-saved registers, plus +; ; 4 bytes of padding since the calculation of frameSize assumes 4 +; ; bytes have already been allocated to save the return address, +; ; which is not true in this case +; sub r2,r2,r6 +; sub r2,r2,#84 +; +; mov r8,r0 +; +; ; copy arguments into place +; mov r6,#0 +; b vmJumpAndInvoke_argumentTest +; +;vmJumpAndInvoke_argumentLoop +; ldr r12,[r5,r6] +; str r12,[r2,r6] +; add r6,r6,#4 +; +;vmJumpAndInvoke_argumentTest +; cmp r6,r3 +; ble vmJumpAndInvoke_argumentLoop +; +; ; the arguments have been copied, so we can set the real stack +; ; pointer now +; mov sp,r2 +; +; ; set return address to vmInvoke_returnAddress +; ldr r10,vmInvoke_returnAddress_word) +; ldr r11,vmJumpAndInvoke_getAddress_word) +;vmJumpAndInvoke_getAddress +; add r11,pc,r11 +; ldr lr,[r11,r10] +; +; bx r1 +; +;vmInvoke_returnAddress_word +; .word GLOBAL(vmInvoke_returnAddress)(GOT) +;vmInvoke_getAddress_word +; .word _GLOBAL_OFFSET_TABLE_-(vmInvoke_getAddress)+8) +;vmJumpAndInvoke_getAddress_word +; .word _GLOBAL_OFFSET_TABLE_-(vmJumpAndInvoke_getAddress)+8) +; +;else ; not AVIAN_CONTINUATIONS + ; vmJumpAndInvoke should only be called when continuations are + ; enabled + bkpt 0 +;endif ; not AVIAN_CONTINUATIONS + + END \ No newline at end of file diff --git a/src/compile-x86.masm b/src/compile-x86.masm new file mode 100644 index 0000000000..f07d799faf --- /dev/null +++ b/src/compile-x86.masm @@ -0,0 +1,173 @@ +comment # + Copyright (c) 2008-2011, 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. + + ORIGIN: https://github.com/gkvas/avian/tree/wince +# + +.586 +.MODEL FLAT, C + +comment # types.h # +VOID_TYPE equ 0 +INT8_TYPE equ 1 +INT16_TYPE equ 2 +INT32_TYPE equ 3 +INT64_TYPE equ 4 +FLOAT_TYPE equ 5 +DOUBLE_TYPE equ 6 +POINTER_TYPE equ 7 + +comment # target-fields.h # +ifdef TARGET_BYTES_PER_WORD + if TARGET_BYTES_PER_WORD eq 8 + +TARGET_THREAD_EXCEPTION equ 80 +TARGET_THREAD_EXCEPTIONSTACKADJUSTMENT equ 2256 +TARGET_THREAD_EXCEPTIONOFFSET equ 2264 +TARGET_THREAD_EXCEPTIONHANDLER equ 2272 + +TARGET_THREAD_IP equ 2216 +TARGET_THREAD_STACK equ 2224 +TARGET_THREAD_NEWSTACK equ 2232 +TARGET_THREAD_SCRATCH equ 2240 +TARGET_THREAD_CONTINUATION equ 2248 +TARGET_THREAD_TAILADDRESS equ 2280 +TARGET_THREAD_VIRTUALCALLTARGET equ 2288 +TARGET_THREAD_VIRTUALCALLINDEX equ 2296 +TARGET_THREAD_HEAPIMAGE equ 2304 +TARGET_THREAD_CODEIMAGE equ 2312 +TARGET_THREAD_THUNKTABLE equ 2320 +TARGET_THREAD_STACKLIMIT equ 2368 + + elseif TARGET_BYTES_PER_WORD eq 4 + +TARGET_THREAD_EXCEPTION equ 44 +TARGET_THREAD_EXCEPTIONSTACKADJUSTMENT equ 2164 +TARGET_THREAD_EXCEPTIONOFFSET equ 2168 +TARGET_THREAD_EXCEPTIONHANDLER equ 2172 + +TARGET_THREAD_IP equ 2144 +TARGET_THREAD_STACK equ 2148 +TARGET_THREAD_NEWSTACK equ 2152 +TARGET_THREAD_SCRATCH equ 2156 +TARGET_THREAD_CONTINUATION equ 2160 +TARGET_THREAD_TAILADDRESS equ 2176 +TARGET_THREAD_VIRTUALCALLTARGET equ 2180 +TARGET_THREAD_VIRTUALCALLINDEX equ 2184 +TARGET_THREAD_HEAPIMAGE equ 2188 +TARGET_THREAD_CODEIMAGE equ 2192 +TARGET_THREAD_THUNKTABLE equ 2196 +TARGET_THREAD_STACKLIMIT equ 2220 + + else + error + endif +else + error +endif + +ifdef AVIAN_USE_FRAME_POINTER + ALIGNMENT_ADJUSTMENT equ 0 +else + ALIGNMENT_ADJUSTMENT equ 12 +endif + +CALLEE_SAVED_REGISTER_FOOTPRINT equ 16 + ALIGNMENT_ADJUSTMENT + +_TEXT SEGMENT + +public C vmInvoke +vmInvoke: + push ebp + mov ebp,esp + + ; 8(%ebp): thread + ; 12(%ebp): function + ; 16(%ebp): arguments + ; 20(%ebp): argumentFootprint + ; 24(%ebp): frameSize + ; 28(%ebp): returnType + + ; allocate stack space for callee-saved registers + sub esp,offset CALLEE_SAVED_REGISTER_FOOTPRINT + + ; remember this stack position, since we won't be able to rely on + ; %rbp being restored when the call returns + mov eax,ds:dword ptr[8+ebp] + mov ds:dword ptr[TARGET_THREAD_SCRATCH+eax],esp + + mov ds:dword ptr[0+esp],ebx + mov ds:dword ptr[4+esp],esi + mov ds:dword ptr[8+esp],edi + + ; allocate stack space for arguments + sub esp,ds:dword ptr[24+ebp] + + ; we use ebx to hold the thread pointer, by convention + mov ebx,eax + + ; copy arguments into place + mov ecx,0 + mov edx,ds:dword ptr[16+ebp] + jmp LvmInvoke_argumentTest + +LvmInvoke_argumentLoop: + mov eax,ds:dword ptr[edx+ecx*1] + mov ds:dword ptr[esp+ecx*1],eax + add ecx,4 + +LvmInvoke_argumentTest: + cmp ecx,ds:dword ptr[20+ebp] + jb LvmInvoke_argumentLoop + + ; call function + call dword ptr[12+ebp] + +public vmInvoke_returnAddress +vmInvoke_returnAddress: + ; restore stack pointer + mov esp,ds:dword ptr[TARGET_THREAD_SCRATCH+ebx] + + ; clear MyThread::stack to avoid confusing another thread calling + ; java.lang.Thread.getStackTrace on this one. See + ; MyProcess::getStackTrace in compile.cpp for details on how we get + ; a reliable stack trace from a thread that might be interrupted at + ; any point in its execution. + mov ds:dword ptr[TARGET_THREAD_STACK+ebx],0 + +public vmInvoke_safeStack +vmInvoke_safeStack: + + ; restore callee-saved registers + mov ebx,ds:dword ptr[0+esp] + mov esi,ds:dword ptr[4+esp] + mov edi,ds:dword ptr[8+esp] + + add esp,offset CALLEE_SAVED_REGISTER_FOOTPRINT + + mov ecx,ds:dword ptr[28+esp] + + pop ebp + ret + +LgetPC: + mov esi,ds:dword ptr[esp] + ret + +public vmJumpAndInvoke +vmJumpAndInvoke: + ; vmJumpAndInvoke should only be called when continuations are + ; enabled + int 3 + +_TEXT ENDS + +END From ce1f76a3e99b279269d548f5a235d245befa09af Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 28 Jan 2013 01:46:15 +0100 Subject: [PATCH 015/106] Add last modified to file --- classpath/java-io.cpp | 22 ++++++++++++++++++++++ classpath/java/io/File.java | 7 +++++++ 2 files changed, 29 insertions(+) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index db9882e051..c12ee64368 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -541,6 +541,28 @@ Java_java_io_File_openDir(JNIEnv* e, jclass, jstring path) } } +extern "C" JNIEXPORT jlong JNICALL +Java_java_io_File_lastModified(JNIEnv* e, jclass, jstring path) +{ + string_t chars = getChars(e, path); + if (chars) { + #ifdef PLATFORM_WINDOWS + # error "Implementation of last modified :)" + #else + struct stat st; + if (stat(chars, &st)) { + return 0; + } else { + return (static_cast(st.st_mtim.tv_sec) * 1000) + + (static_cast(st.st_mtim.tv_nsec) / (1000*1000)); + } + + #endif + } else { + return 0; + } +} + extern "C" JNIEXPORT jstring JNICALL Java_java_io_File_readDir(JNIEnv* e, jclass, jlong handle) { diff --git a/classpath/java/io/File.java b/classpath/java/io/File.java index b66aa03ff9..8eceed4b71 100644 --- a/classpath/java/io/File.java +++ b/classpath/java/io/File.java @@ -294,12 +294,19 @@ public class File implements Serializable { } } + public long lastModified() { + return lastModified(path); + } private static native long openDir(String path); + private static native long lastModified(String path); + private static native String readDir(long handle); private static native long closeDir(long handle); + + private static class Pair { public final String value; public final Pair next; From 1590bd0554ed2c7a9c134b4ac4341e1b9a4a19dc Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Tue, 29 Jan 2013 12:44:55 +0200 Subject: [PATCH 016/106] Fix library overwriting ; proper assembler flags --- makefile | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/makefile b/makefile index b4512c010f..d15ac115a5 100755 --- a/makefile +++ b/makefile @@ -666,7 +666,7 @@ ifeq ($(platform),wp8) as = "$$(cygpath -u "$(WP80_SDK)\bin\x86_arm\armasm.exe")" cxx = "$$(cygpath -u "$(WP80_SDK)\bin\x86_arm\cl.exe")" ld = "$$(cygpath -u "$(WP80_SDK)\bin\x86_arm\link.exe")" - asmflags = -machine ARM -32 + asmflags = $(target-cflags) -machine ARM -32 asm-output = -o $(1) asm-input = $(1) machine_type = ARM @@ -678,6 +678,7 @@ ifeq ($(platform),wp8) vc_arch = w8kit_arch = x86 deps_arch = x86 + asmflags = $(target-cflags) -safeseh as = "$$(cygpath -u "$(WP80_SDK)\bin\ml.exe")" cxx = "$$(cygpath -u "$(WP80_SDK)\bin\cl.exe")" ld = "$$(cygpath -u "$(WP80_SDK)\bin\link.exe")" @@ -705,12 +706,31 @@ ifeq ($(platform),wp8) common-lflags = $(classpath-lflags) + ifeq ($(mode),debug) + build-type = Debug + endif + ifeq ($(mode),debug-fast) + build-type = Debug + endif + ifeq ($(mode),stress_major) + build-type = Release + endif + ifeq ($(mode),fast) + build-type = Release + endif + ifeq ($(mode),fast) + build-type = Release + endif + ifeq ($(mode),small) + build-type = Release + endif + arflags = -MACHINE:$(machine_type) lflags = $(common-lflags) -nologo \ -MACHINE:$(machine_type) \ -LIBPATH:"$(WP80_KIT)\lib\$(w8kit_arch)" -LIBPATH:"$(WIN8_KIT)\Lib\win8\um\$(w8kit_arch)" -LIBPATH:"$(MSVC_ROOT)\lib$(vc_arch)" \ ws2_32.lib \ - "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\zlib.lib")" "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\ThreadEmulation.lib")" + "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\zlib.lib")" "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\ThreadEmulation.lib")" cc = $(cxx) asm-format = masm @@ -1508,8 +1528,8 @@ $(dynamic-library): $(vm-objects) $(dynamic-object) $(classpath-objects) \ $(lzma-decode-objects) @echo "linking $(@)" ifdef ms_cl_compiler - $(ld) $(shared) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \ - -IMPLIB:$(build)/$(name).lib $(manifest-flags) + $(ld) $(shared) $(lflags) $(^) -out:$(@) -PDB:$(subst .dll,.pdb,$(@)) \ + -IMPLIB:$(subst .dll,.lib,$(@)) $(manifest-flags) ifdef mt $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);2" endif From 4840f4a01946507f1f0e8003caac0bc77f3d9d36 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Tue, 29 Jan 2013 14:21:02 +0200 Subject: [PATCH 017/106] Fixes to WP8/WinRT support --- classpath/java-io.cpp | 3 ++- makefile | 4 +--- src/bootimage.cpp | 14 ++++---------- src/windows.cpp | 4 ++-- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index c12ee64368..3860e67ecd 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -547,7 +547,8 @@ Java_java_io_File_lastModified(JNIEnv* e, jclass, jstring path) string_t chars = getChars(e, path); if (chars) { #ifdef PLATFORM_WINDOWS - # error "Implementation of last modified :)" + # pragma message("Implementation of last modified") + return 0; #else struct stat st; if (stat(chars, &st)) { diff --git a/makefile b/makefile index d15ac115a5..8106406a22 100755 --- a/makefile +++ b/makefile @@ -618,7 +618,7 @@ ifeq ($(platform),wp8) # Environment variable WP8_SDK not found. It should be something like # "C:\Program Files[ (x86)]\Microsoft Visual Studio 11.0\VC\WPSDK\WP80" # TODO: Lookup in SOFTWARE\Microsoft\Microsoft SDKs\WindowsPhone\v8.0 - WP80_SDK = C:\$(programFiles)\Microsoft Visual Studio 11.0\VC\WPSDK\WP80 + WP80_SDK = $(MSVS_ROOT)\VC\WPSDK\WP80 endif ifeq ($(WP80_KIT),) # Environment variable WP8_KIT not found. It should be something like @@ -670,8 +670,6 @@ ifeq ($(platform),wp8) asm-output = -o $(1) asm-input = $(1) machine_type = ARM - bootimage-symbols = binary_bootimage_bin_start:binary_bootimage_bin_end - codeimage-symbols = binary_codeimage_bin_start:binary_codeimage_bin_end endif ifeq ($(arch),i386) wp8_arch = diff --git a/src/bootimage.cpp b/src/bootimage.cpp index ec04196ca0..5b725f5058 100644 --- a/src/bootimage.cpp +++ b/src/bootimage.cpp @@ -1917,26 +1917,20 @@ public: exit(1); } -# if AVIAN_TARGET_FORMAT != AVIAN_FORMAT_PE -# define SYMBOL_PREFIX "_" -# else -# define SYMBOL_PREFIX -# endif - if(!bootimageStart) { - bootimageStart = strdup(SYMBOL_PREFIX"binary_bootimage_bin_start"); + bootimageStart = strdup("_binary_bootimage_bin_start"); } if(!bootimageEnd) { - bootimageEnd = strdup(SYMBOL_PREFIX"binary_bootimage_bin_end"); + bootimageEnd = strdup("_binary_bootimage_bin_end"); } if(!codeimageStart) { - codeimageStart = strdup(SYMBOL_PREFIX"binary_codeimage_bin_start"); + codeimageStart = strdup("_binary_codeimage_bin_start"); } if(!codeimageEnd) { - codeimageEnd = strdup(SYMBOL_PREFIX"binary_codeimage_bin_end"); + codeimageEnd = strdup("_binary_codeimage_bin_end"); } } diff --git a/src/windows.cpp b/src/windows.cpp index 8c7512eab1..d0b5228368 100644 --- a/src/windows.cpp +++ b/src/windows.cpp @@ -34,10 +34,10 @@ WaitForSingleObjectEx((hHandle), (dwMilliseconds), FALSE) #define CreateEvent(lpEventAttributes, bManualReset, bInitialState, lpName) \ - CreateEventEx((lpEventAttributes), (lpName), ((bManualReset)?CREATE_EVENT_MANUAL_RESET:0)|((bInitialState)?CREATE_EVENT_INITIAL_SET:0), EVENT_MODIFY_STATE) + CreateEventEx((lpEventAttributes), (lpName), ((bManualReset)?CREATE_EVENT_MANUAL_RESET:0)|((bInitialState)?CREATE_EVENT_INITIAL_SET:0), EVENT_ALL_ACCESS) #define CreateMutex(lpEventAttributes, bInitialOwner, lpName) \ - CreateMutexEx((lpEventAttributes), (lpName), (bInitialOwner)?CREATE_MUTEX_INITIAL_OWNER:0, MUTEX_MODIFY_STATE) + CreateMutexEx((lpEventAttributes), (lpName), (bInitialOwner)?CREATE_MUTEX_INITIAL_OWNER:0, MUTEX_ALL_ACCESS) #include "thread-emulation.h" From fa034c75261ac1c4747188e0abdf333b62d9c4f4 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Tue, 29 Jan 2013 19:23:22 +0200 Subject: [PATCH 018/106] Additional AOT_ONLY ifdef --- src/compile.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/compile.cpp b/src/compile.cpp index 7fa51817c7..d0cf31cfec 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -9339,11 +9339,15 @@ class MyProcessor: public Processor { root(t, MethodTreeSentinal)); } +#ifdef AVIAN_AOT_ONLY + thunks = bootThunks; +#else local::compileThunks(static_cast(t), &codeAllocator); if (not (image and code)) { bootThunks = thunks; } +#endif segFaultHandler.m = t->m; expect(t, t->m->system->success From d6ba068b4bab6b386ea4c4f881d6efbc6bd37d57 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Wed, 30 Jan 2013 07:31:02 +0200 Subject: [PATCH 019/106] Makefile changes, added additional compiler flags --- makefile | 110 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 59 insertions(+), 51 deletions(-) diff --git a/makefile b/makefile index 8106406a22..f24997fed7 100755 --- a/makefile +++ b/makefile @@ -50,6 +50,7 @@ ifeq ($(continuations),true) options := $(options)-continuations endif +aot-only = false root := $(shell (cd .. && pwd)) build = build/$(platform)-$(arch)$(options) host-build-root = $(build)/host @@ -539,7 +540,6 @@ ifeq ($(platform),windows) lib = "$(win32)/lib" embed-prefix = c:/avian-embedded - system = windows so-prefix = @@ -642,7 +642,7 @@ ifeq ($(platform),wp8) use-lto = false supports_avian_executable = false process = compile - aot_only = true + aot-only = true ifneq ($(process),compile) options := -$(process) endif @@ -676,11 +676,16 @@ ifeq ($(platform),wp8) vc_arch = w8kit_arch = x86 deps_arch = x86 - asmflags = $(target-cflags) -safeseh + asmflags = $(target-cflags) -safeseh -nologo -Gd as = "$$(cygpath -u "$(WP80_SDK)\bin\ml.exe")" cxx = "$$(cygpath -u "$(WP80_SDK)\bin\cl.exe")" ld = "$$(cygpath -u "$(WP80_SDK)\bin\link.exe")" - asmflags += -nologo + ifeq ($(mode),debug) + asmflags += -Zd + endif + ifeq ($(mode),debug-fast) + asmflags += -Zd + endif asm-output = $(output) machine_type = X86 endif @@ -700,7 +705,8 @@ ifeq ($(platform),wp8) -Fd$(build)/$(name).pdb -I"$(shell $(windows-path) "$(wp8)/include")" -I$(src) -I$(classpath-src) \ -I"$(build)" \ -I"$(windows-java-home)/include" -I"$(windows-java-home)/include/win32" \ - -DTARGET_BYTES_PER_WORD=$(pointer-size) + -DTARGET_BYTES_PER_WORD=$(pointer-size) \ + -Gd common-lflags = $(classpath-lflags) @@ -783,6 +789,52 @@ ifeq ($(platform),wp8) strip = : endif +ifdef msvc + no-error = + windows-path = $(native-path) + windows-java-home := $(shell $(windows-path) "$(JAVA_HOME)") + zlib := $(shell $(windows-path) "$(win32)/msvc") + ms_cl_compiler = regular + cxx = "$(msvc)/BIN/cl.exe" + cc = $(cxx) + ld = "$(msvc)/BIN/link.exe" + mt = "mt.exe" + manifest-flags = -MANIFEST -MANIFESTFILE:$(@).manifest + cflags = -nologo -DAVIAN_VERSION=\"$(version)\" -D_JNI_IMPLEMENTATION_ \ + -DUSE_ATOMIC_OPERATIONS -DAVIAN_JAVA_HOME=\"$(javahome)\" \ + -DAVIAN_EMBED_PREFIX=\"$(embed-prefix)\" \ + -Fd$(build)/$(name).pdb -I"$(zlib)/include" -I$(src) -I$(classpath-src) \ + -I"$(build)" \ + -I"$(windows-java-home)/include" -I"$(windows-java-home)/include/win32" \ + -DTARGET_BYTES_PER_WORD=$(pointer-size) + + ifneq ($(lzma),) + cflags += -I$(shell $(windows-path) "$(lzma)") + endif + + shared = -dll + lflags = -nologo -LIBPATH:"$(zlib)/lib" -DEFAULTLIB:ws2_32 \ + -DEFAULTLIB:zlib -DEFAULTLIB:user32 -MANIFEST -debug + output = -Fo$(1) + + ifeq ($(mode),debug) + cflags += -Od -Zi -MDd + endif + ifeq ($(mode),debug-fast) + cflags += -Od -Zi -DNDEBUG + endif + ifeq ($(mode),fast) + cflags += -O2 -GL -Zi -DNDEBUG + lflags += -LTCG + endif + ifeq ($(mode),small) + cflags += -O1s -Zi -GL -DNDEBUG + lflags += -LTCG + endif + + strip = : +endif + ifeq ($(mode),debug) optimization-cflags = $(cflags_debug) converter-cflags += $(cflags_debug) @@ -842,51 +894,6 @@ endif endif endif -ifdef msvc - no-error = - windows-path = $(native-path) - windows-java-home := $(shell $(windows-path) "$(JAVA_HOME)") - zlib := $(shell $(windows-path) "$(win32)/msvc") - cxx = "$(msvc)/BIN/cl.exe" - cc = $(cxx) - ld = "$(msvc)/BIN/link.exe" - mt = "mt.exe" - manifest-flags = -MANIFEST -MANIFESTFILE:$(@).manifest - cflags = -nologo -DAVIAN_VERSION=\"$(version)\" -D_JNI_IMPLEMENTATION_ \ - -DUSE_ATOMIC_OPERATIONS -DAVIAN_JAVA_HOME=\"$(javahome)\" \ - -DAVIAN_EMBED_PREFIX=\"$(embed-prefix)\" \ - -Fd$(build)/$(name).pdb -I"$(zlib)/include" -I$(src) -I$(classpath-src) \ - -I"$(build)" \ - -I"$(windows-java-home)/include" -I"$(windows-java-home)/include/win32" \ - -DTARGET_BYTES_PER_WORD=$(pointer-size) - - ifneq ($(lzma),) - cflags += -I$(shell $(windows-path) "$(lzma)") - endif - - shared = -dll - lflags = -nologo -LIBPATH:"$(zlib)/lib" -DEFAULTLIB:ws2_32 \ - -DEFAULTLIB:zlib -DEFAULTLIB:user32 -MANIFEST -debug - output = -Fo$(1) - - ifeq ($(mode),debug) - cflags += -Od -Zi -MDd - endif - ifeq ($(mode),debug-fast) - cflags += -Od -Zi -DNDEBUG - endif - ifeq ($(mode),fast) - cflags += -O2 -GL -Zi -DNDEBUG - lflags += -LTCG - endif - ifeq ($(mode),small) - cflags += -O1s -Zi -GL -DNDEBUG - lflags += -LTCG - endif - - strip = : -endif - build-cflags += -DAVIAN_HOST_TARGET c-objects = $(foreach x,$(1),$(patsubst $(2)/%.c,$(3)/%.o,$(x))) @@ -938,7 +945,7 @@ ifeq ($(process),compile) vm-asm-sources += $(src)/compile-$(asm).$(asm-format) endif cflags += -DAVIAN_PROCESS_$(process) -ifdef aot_only +ifeq ($(aot-only),true) cflags += -DAVIAN_AOT_ONLY endif @@ -1488,6 +1495,7 @@ $(bootimage-generator): $(bootimage-generator-objects) $(MAKE) mode=$(mode) \ build=$(host-build-root) \ arch=$(build-arch) \ + aot-only=false \ target-arch=$(arch) \ platform=$(bootimage-platform) \ target-format=$(target-format) \ From 5a1b478b89f426a54308b3ef4ee0ec68d269842e Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Wed, 30 Jan 2013 10:42:05 +0200 Subject: [PATCH 020/106] Allow output of exceptions to debugger. Generate WinMD file --- makefile | 46 ++++++++++++++++++++++++++++------------------ src/machine.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 19 deletions(-) diff --git a/makefile b/makefile index f24997fed7..d150eb7270 100755 --- a/makefile +++ b/makefile @@ -593,8 +593,8 @@ ifeq ($(platform),windows) shared += -Wl,--add-stdcall-alias endif - embed = $(build-embed)/embed.exe - embed-loader = $(build-embed-loader)/embed-loader.exe + embed = $(build-embed)/embed$(exe-suffix) + embed-loader = $(build-embed-loader)/embed-loader$(exe-suffix) embed-loader-o = $(build-embed)/embed-loader.o endif @@ -657,6 +657,7 @@ ifeq ($(platform),wp8) so-prefix = so-suffix = .dll exe-suffix = .exe + manifest-flags = -MANIFEST:NO ifeq ($(arch),arm) wp8_arch = \x86_arm @@ -696,8 +697,9 @@ ifeq ($(platform),wp8) build-lflags = -lz -lpthread cflags = -nologo \ + -AI"$(WP80_KIT)\Windows Metadata" \ -I"$(WP80_SDK)\include" -I"$(WP80_KIT)\Include" -I"$(WP80_KIT)\Include\minwin" -I"$(WP80_KIT)\Include\mincore" \ - -DWINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP \ + -DWINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP -D_USRDLL -D_WINDLL \ -DAVIAN_VERSION=\"$(version)\" -D_JNI_IMPLEMENTATION_ \ -DUSE_ATOMIC_OPERATIONS -DAVIAN_JAVA_HOME=\"$(javahome)\" \ -DAVIAN_EMBED_PREFIX=\"$(embed-prefix)\" \ @@ -735,6 +737,11 @@ ifeq ($(platform),wp8) -LIBPATH:"$(WP80_KIT)\lib\$(w8kit_arch)" -LIBPATH:"$(WIN8_KIT)\Lib\win8\um\$(w8kit_arch)" -LIBPATH:"$(MSVC_ROOT)\lib$(vc_arch)" \ ws2_32.lib \ "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\zlib.lib")" "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\ThreadEmulation.lib")" + lflags += -NXCOMPAT -DYNAMICBASE -SUBSYSTEM:CONSOLE -TLBID:1 + lflags += -NODEFAULTLIB:"ole32.lib" WindowsPhoneCore.lib + lflags += -WINMD -WINMDFILE:$(subst $(so-suffix),.winmd,$(@)) + #lflags += -WINMD:NO + #lflags += -APPCONTAINER cc = $(cxx) asm-format = masm @@ -750,6 +757,7 @@ ifeq ($(platform),wp8) endif output = -Fo$(1) + #TODO: -MT or -ZW? cflags_debug = -Od -Zi -MDd cflags_debug_fast = -Od -Zi -MDd cflags_stress = -O0 -g3 -MD @@ -1079,10 +1087,10 @@ converter-objects = $(call cpp-objects,$(converter-sources),$(src),$(build)) converter-tool-objects = $(call cpp-objects,$(converter-tool-sources),$(src),$(build)) converter = $(build)/binaryToObject/binaryToObject -static-library = $(build)/$(static-prefix)$(name)${static-suffix} +static-library = $(build)/$(static-prefix)$(name)$(static-suffix) executable = $(build)/$(name)${exe-suffix} dynamic-library = $(build)/$(so-prefix)jvm$(so-suffix) -executable-dynamic = $(build)/$(name)-dynamic${exe-suffix} +executable-dynamic = $(build)/$(name)-dynamic$(exe-suffix) ifneq ($(classpath),avian) # Assembler, ConstantPool, and Stream are not technically needed for a @@ -1307,7 +1315,8 @@ $(test-cpp-objects): $(test-build)/%.o: $(test)/%.cpp $(vm-depends) $(test-library): $(test-cpp-objects) @echo "linking $(@)" ifdef ms_cl_compiler - $(ld) $(shared) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \ + $(ld) $(shared) $(lflags) $(^) -out:$(@) \ + -debug -PDB:$(subst $(so-suffix),.pdb,$(@)) \ -IMPLIB:$(test-build)/$(name).lib $(manifest-flags) ifdef mt $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);2" @@ -1320,8 +1329,8 @@ ifdef embed $(embed): $(embed-objects) $(embed-loader-o) @echo "building $(embed)" ifdef ms_cl_compiler - $(ld) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \ - -IMPLIB:$(@).lib $(manifest-flags) + $(ld) $(lflags) $(^) -out:$(@) \ + -debug -PDB:$(subst $(exe-suffix),.pdb,$(@)) $(manifest-flags) ifdef mt $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" endif @@ -1343,8 +1352,8 @@ $(embed-loader): $(embed-loader-objects) $(static-library) @mkdir -p $(dir $(@)) cd $(dir $(@)) && $(ar) x ../../../$(static-library) ifdef ms_cl_compiler - $(ld) $(lflags) $(dir $(@))/*.o -out:$(@) -PDB:$(@).pdb \ - -IMPLIB:$(@).lib $(manifest-flags) + $(ld) $(lflags) $(dir $(@))/*.o -out:$(@) \ + -debug -PDB:$(subst $(exe-suffix),.pdb,$(@)) $(manifest-flags) ifdef mt $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" endif @@ -1475,8 +1484,8 @@ $(executable): $(executable-objects) @echo "linking $(@)" ifeq ($(platform),windows) ifdef ms_cl_compiler - $(ld) $(lflags) $(executable-objects) -out:$(@) -PDB:$(@).pdb \ - -IMPLIB:$(@).lib $(manifest-flags) + $(ld) $(lflags) $(executable-objects) -out:$(@) \ + -debug -PDB:$(subst $(exe-suffix),.pdb,$(@)) $(manifest-flags) ifdef mt $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" endif @@ -1514,8 +1523,8 @@ $(build-bootimage-generator): \ @echo "linking $(@)" ifeq ($(platform),windows) ifdef ms_cl_compiler - $(ld) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \ - -IMPLIB:$(@).lib $(manifest-flags) + $(ld) $(bootimage-generator-lflags) $(lflags) $(^) -out:$(@) \ + -debug -PDB:$(subst $(exe-suffix),.pdb,$(@)) $(manifest-flags) ifdef mt $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" endif @@ -1534,8 +1543,9 @@ $(dynamic-library): $(vm-objects) $(dynamic-object) $(classpath-objects) \ $(lzma-decode-objects) @echo "linking $(@)" ifdef ms_cl_compiler - $(ld) $(shared) $(lflags) $(^) -out:$(@) -PDB:$(subst .dll,.pdb,$(@)) \ - -IMPLIB:$(subst .dll,.lib,$(@)) $(manifest-flags) + $(ld) $(shared) $(lflags) $(^) -out:$(@) \ + -debug -PDB:$(subst $(so-suffix),.pdb,$(@)) \ + -IMPLIB:$(subst $(so-suffix),.lib,$(@)) $(manifest-flags) ifdef mt $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);2" endif @@ -1552,8 +1562,8 @@ $(executable-dynamic): $(driver-dynamic-objects) $(dynamic-library) @echo "linking $(@)" ifdef ms_cl_compiler $(ld) $(lflags) -LIBPATH:$(build) -DEFAULTLIB:$(name) \ - -PDB:$(@).pdb -IMPLIB:$(@).lib $(driver-dynamic-objects) \ - -out:$(@) $(manifest-flags) + -debug -PDB:$(subst $(exe-suffix),.pdb,$(@)) + $(driver-dynamic-objects) -out:$(@) $(manifest-flags) ifdef mt $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" endif diff --git a/src/machine.cpp b/src/machine.cpp index 5e08655898..c3c398bd92 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -17,6 +17,11 @@ #include "arch.h" #include "lzma.h" +#if defined(PLATFORM_WINDOWS) +# define WIN32_LEAN_AND_MEAN +# include +#endif + using namespace vm; namespace { @@ -4741,18 +4746,33 @@ printTrace(Thread* t, object exception) for (object e = exception; e; e = throwableCause(t, e)) { if (e != exception) { fprintf(errorLog(t), "caused by: "); +#if defined(PLATFORM_WINDOWS) + OutputDebugStringA("caused by: "); +#endif } fprintf(errorLog(t), "%s", &byteArrayBody (t, className(t, objectClass(t, e)), 0)); - +#if defined(PLATFORM_WINDOWS) + OutputDebugStringA((const CHAR*)&byteArrayBody + (t, className(t, objectClass(t, e)), 0)); +#endif + if (throwableMessage(t, e)) { object m = throwableMessage(t, e); THREAD_RUNTIME_ARRAY(t, char, message, stringLength(t, m) + 1); stringChars(t, m, RUNTIME_ARRAY_BODY(message)); fprintf(errorLog(t), ": %s\n", RUNTIME_ARRAY_BODY(message)); +#if defined(PLATFORM_WINDOWS) + OutputDebugStringA(": "); + OutputDebugStringA(RUNTIME_ARRAY_BODY(message)); + OutputDebugStringA("\n"); +#endif } else { fprintf(errorLog(t), "\n"); +#if defined(PLATFORM_WINDOWS) + OutputDebugStringA("\n"); +#endif } object trace = throwableTrace(t, e); @@ -4767,16 +4787,35 @@ printTrace(Thread* t, object exception) (t, traceElementMethod(t, e), traceElementIp(t, e)); fprintf(errorLog(t), " at %s.%s ", class_, method); +#if defined(PLATFORM_WINDOWS) + OutputDebugStringA(" at "); + OutputDebugStringA((const CHAR*)class_); + OutputDebugStringA("."); + OutputDebugStringA((const CHAR*)method); + OutputDebugStringA(" "); +#endif switch (line) { case NativeLine: fprintf(errorLog(t), "(native)\n"); +#if defined(PLATFORM_WINDOWS) + OutputDebugStringA("(native)\n"); +#endif break; case UnknownLine: fprintf(errorLog(t), "(unknown line)\n"); +#if defined(PLATFORM_WINDOWS) + OutputDebugStringA("(unknown line)\n"); +#endif break; default: fprintf(errorLog(t), "(line %d)\n", line); +#if defined(PLATFORM_WINDOWS) + OutputDebugStringA("(line "); + char buf[35]; + OutputDebugStringA(itoa(line, buf, 10)); + OutputDebugStringA(")\n"); +#endif } } } From 7cd194b5de0b24f701578c0add8c12a4fd0dd9b2 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Wed, 30 Jan 2013 11:31:06 +0200 Subject: [PATCH 021/106] Finally, proper jvm.dll linking for WP8 --- makefile | 8 +++----- src/machine.h | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/makefile b/makefile index d150eb7270..ab404633c1 100755 --- a/makefile +++ b/makefile @@ -734,14 +734,12 @@ ifeq ($(platform),wp8) arflags = -MACHINE:$(machine_type) lflags = $(common-lflags) -nologo \ -MACHINE:$(machine_type) \ - -LIBPATH:"$(WP80_KIT)\lib\$(w8kit_arch)" -LIBPATH:"$(WIN8_KIT)\Lib\win8\um\$(w8kit_arch)" -LIBPATH:"$(MSVC_ROOT)\lib$(vc_arch)" \ + -LIBPATH:"$(WP80_KIT)\lib\$(w8kit_arch)" -LIBPATH:"$(WP80_SDK)\lib$(vc_arch)" -LIBPATH:"$(WIN8_KIT)\Lib\win8\um\$(w8kit_arch)" \ ws2_32.lib \ "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\zlib.lib")" "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\ThreadEmulation.lib")" lflags += -NXCOMPAT -DYNAMICBASE -SUBSYSTEM:CONSOLE -TLBID:1 - lflags += -NODEFAULTLIB:"ole32.lib" WindowsPhoneCore.lib - lflags += -WINMD -WINMDFILE:$(subst $(so-suffix),.winmd,$(@)) - #lflags += -WINMD:NO - #lflags += -APPCONTAINER + lflags += -NODEFAULTLIB:"ole32.lib" -NODEFAULTLIB:"kernel32.lib" + lflags += PhoneAppModelHost.lib WindowsPhoneCore.lib -WINMD -WINMDFILE:$(subst $(so-suffix),.winmd,$(@)) cc = $(cxx) asm-format = masm diff --git a/src/machine.h b/src/machine.h index 420a0192cb..5a2812c2b7 100644 --- a/src/machine.h +++ b/src/machine.h @@ -2695,7 +2695,7 @@ throw_(Thread* t, object e) t->exception = e; - // printTrace(t, e); + printTrace(t, e); popResources(t); From d468d7eabacfaf9ce59440a34b6c7a705744edba Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 31 Jan 2013 12:54:51 +0200 Subject: [PATCH 022/106] Fix WP8/WinRT ARM build --- makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/makefile b/makefile index ab404633c1..f0cb5494fb 100755 --- a/makefile +++ b/makefile @@ -667,10 +667,12 @@ ifeq ($(platform),wp8) as = "$$(cygpath -u "$(WP80_SDK)\bin\x86_arm\armasm.exe")" cxx = "$$(cygpath -u "$(WP80_SDK)\bin\x86_arm\cl.exe")" ld = "$$(cygpath -u "$(WP80_SDK)\bin\x86_arm\link.exe")" - asmflags = $(target-cflags) -machine ARM -32 + asmflags = -machine ARM -32 asm-output = -o $(1) asm-input = $(1) machine_type = ARM + bootimage-symbols = binary_bootimage_bin_start:binary_bootimage_bin_end + codeimage-symbols = binary_codeimage_bin_start:binary_codeimage_bin_end endif ifeq ($(arch),i386) wp8_arch = From 9b9bc1de00b89b6130102f5d666da3c3e48a492f Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 31 Jan 2013 12:55:12 +0200 Subject: [PATCH 023/106] Fix crash on memory validation --- src/windows.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/windows.cpp b/src/windows.cpp index d0b5228368..98fc8e5d96 100644 --- a/src/windows.cpp +++ b/src/windows.cpp @@ -924,7 +924,7 @@ class MySystem: public System { } #else #pragma message("TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ Windows.ApplicationModel.Package.Current.InstalledLocation") - return name; + return copy(allocator, name); #endif } From e523547b1939f07f5feef30fe50deb9a3513380b Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 31 Jan 2013 14:54:23 +0200 Subject: [PATCH 024/106] Allow avian.bootstrap to accept multiple libraries --- src/jnienv.cpp | 10 ---------- src/jnienv.h | 10 ++++++++++ src/machine.cpp | 23 ++++++++++++++++++++++- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/jnienv.cpp b/src/jnienv.cpp index 2a70b10855..c8f27fb0b7 100644 --- a/src/jnienv.cpp +++ b/src/jnienv.cpp @@ -3709,16 +3709,6 @@ populateJNITables(JavaVMVTable* vmTable, JNIEnvVTable* envTable) } // namespace vm -#define BOOTSTRAP_PROPERTY "avian.bootstrap" -#define CRASHDIR_PROPERTY "avian.crash.dir" -#define EMBED_PREFIX_PROPERTY "avian.embed.prefix" -#define CLASSPATH_PROPERTY "java.class.path" -#define JAVA_HOME_PROPERTY "java.home" -#define BOOTCLASSPATH_PREPEND_OPTION "bootclasspath/p" -#define BOOTCLASSPATH_OPTION "bootclasspath" -#define BOOTCLASSPATH_APPEND_OPTION "bootclasspath/a" -#define BOOTCLASSPATH_APPEND_OPTION "bootclasspath/a" - extern "C" JNIEXPORT jint JNICALL JNI_GetDefaultJavaVMInitArgs(void*) { diff --git a/src/jnienv.h b/src/jnienv.h index 5b8c46685b..8dbd1f8c7d 100644 --- a/src/jnienv.h +++ b/src/jnienv.h @@ -13,6 +13,16 @@ #include "machine.h" +#define BOOTSTRAP_PROPERTY "avian.bootstrap" +#define CRASHDIR_PROPERTY "avian.crash.dir" +#define EMBED_PREFIX_PROPERTY "avian.embed.prefix" +#define CLASSPATH_PROPERTY "java.class.path" +#define JAVA_HOME_PROPERTY "java.home" +#define BOOTCLASSPATH_PREPEND_OPTION "bootclasspath/p" +#define BOOTCLASSPATH_OPTION "bootclasspath" +#define BOOTCLASSPATH_APPEND_OPTION "bootclasspath/a" +#define BOOTCLASSPATH_APPEND_OPTION "bootclasspath/a" + namespace vm { void diff --git a/src/machine.cpp b/src/machine.cpp index c3c398bd92..e060cd0a9e 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -3008,6 +3008,13 @@ Machine::Machine(System* system, Heap* heap, Finder* bootFinder, populateJNITables(&javaVMVTable, &jniEnvVTable); + const char* bootstrapProperty = strdup(findProperty(this, BOOTSTRAP_PROPERTY)); + const char* bootstrapPropertyEnd = bootstrapProperty + (bootstrapProperty ? strlen(bootstrapProperty) : 0); + char* codeLibraryName = (char*)bootstrapProperty; + char* codeLibraryNameEnd = 0; + if (codeLibraryName && (codeLibraryNameEnd = strchr(codeLibraryName, system->pathSeparator()))) + *codeLibraryNameEnd = 0; + if (not system->success(system->make(&localThread)) or not system->success(system->make(&stateLock)) or not system->success(system->make(&heapLock)) or @@ -3015,10 +3022,24 @@ Machine::Machine(System* system, Heap* heap, Finder* bootFinder, not system->success(system->make(&referenceLock)) or not system->success(system->make(&shutdownLock)) or not system->success - (system->load(&libraries, findProperty(this, "avian.bootstrap")))) + (system->load(&libraries, bootstrapProperty))) { system->abort(); } + + System::Library* additionalLibrary = 0; + while (codeLibraryNameEnd && codeLibraryNameEnd + 1 < bootstrapPropertyEnd) { + codeLibraryName = codeLibraryNameEnd + 1; + codeLibraryNameEnd = strchr(codeLibraryName, system->pathSeparator()); + if (codeLibraryNameEnd) + *codeLibraryNameEnd = 0; + + if (!system->success(system->load(&additionalLibrary, codeLibraryName))) + system->abort(); + libraries->setNext(additionalLibrary); + } + + free((void*)bootstrapProperty); } void From 2e3856211b3433f502f88be3f0095e71a480602f Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 31 Jan 2013 22:06:35 +0200 Subject: [PATCH 025/106] Fix crash if no avian.boostrap is specified --- src/machine.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/machine.cpp b/src/machine.cpp index e060cd0a9e..a0cd3184ce 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -3008,7 +3008,8 @@ Machine::Machine(System* system, Heap* heap, Finder* bootFinder, populateJNITables(&javaVMVTable, &jniEnvVTable); - const char* bootstrapProperty = strdup(findProperty(this, BOOTSTRAP_PROPERTY)); + const char* bootstrapProperty = findProperty(this, BOOTSTRAP_PROPERTY); + const char* bootstrapPropertyDup = bootstrapProperty ? strdup(bootstrapProperty) : 0; const char* bootstrapPropertyEnd = bootstrapProperty + (bootstrapProperty ? strlen(bootstrapProperty) : 0); char* codeLibraryName = (char*)bootstrapProperty; char* codeLibraryNameEnd = 0; @@ -3039,7 +3040,8 @@ Machine::Machine(System* system, Heap* heap, Finder* bootFinder, libraries->setNext(additionalLibrary); } - free((void*)bootstrapProperty); + if(bootstrapPropertyDup) + free((void*)bootstrapPropertyDup); } void From 8e879f80a757bc9e47dcd597e4ba7777f21728e8 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 31 Jan 2013 22:07:56 +0200 Subject: [PATCH 026/106] Fix crash if no avian.boostrap is specified (oops) --- src/machine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/machine.cpp b/src/machine.cpp index a0cd3184ce..dce3bfe185 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -3011,7 +3011,7 @@ Machine::Machine(System* system, Heap* heap, Finder* bootFinder, const char* bootstrapProperty = findProperty(this, BOOTSTRAP_PROPERTY); const char* bootstrapPropertyDup = bootstrapProperty ? strdup(bootstrapProperty) : 0; const char* bootstrapPropertyEnd = bootstrapProperty + (bootstrapProperty ? strlen(bootstrapProperty) : 0); - char* codeLibraryName = (char*)bootstrapProperty; + char* codeLibraryName = (char*)bootstrapPropertyDup; char* codeLibraryNameEnd = 0; if (codeLibraryName && (codeLibraryNameEnd = strchr(codeLibraryName, system->pathSeparator()))) *codeLibraryNameEnd = 0; From ba0ec3759d139cc793f54a0836ba20ae89f1205c Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 31 Jan 2013 22:08:26 +0200 Subject: [PATCH 027/106] Fix crash if no avian.boostrap is specified (oops) --- src/machine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/machine.cpp b/src/machine.cpp index dce3bfe185..84a34caf67 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -3010,7 +3010,7 @@ Machine::Machine(System* system, Heap* heap, Finder* bootFinder, const char* bootstrapProperty = findProperty(this, BOOTSTRAP_PROPERTY); const char* bootstrapPropertyDup = bootstrapProperty ? strdup(bootstrapProperty) : 0; - const char* bootstrapPropertyEnd = bootstrapProperty + (bootstrapProperty ? strlen(bootstrapProperty) : 0); + const char* bootstrapPropertyEnd = bootstrapPropertyDup + (bootstrapPropertyDup ? strlen(bootstrapPropertyDup) : 0); char* codeLibraryName = (char*)bootstrapPropertyDup; char* codeLibraryNameEnd = 0; if (codeLibraryName && (codeLibraryNameEnd = strchr(codeLibraryName, system->pathSeparator()))) From 3287b1354a247d732c0a101af999514ae88eb839 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 31 Jan 2013 22:10:42 +0200 Subject: [PATCH 028/106] Fix crash if no avian.boostrap is specified (oops) --- src/machine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/machine.cpp b/src/machine.cpp index 84a34caf67..d2d225e7e5 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -3023,7 +3023,7 @@ Machine::Machine(System* system, Heap* heap, Finder* bootFinder, not system->success(system->make(&referenceLock)) or not system->success(system->make(&shutdownLock)) or not system->success - (system->load(&libraries, bootstrapProperty))) + (system->load(&libraries, bootstrapPropertyDup))) { system->abort(); } From a03fda0c1d69d49fbbfa47d57990964c7d61156d Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Fri, 1 Feb 2013 16:36:29 +0200 Subject: [PATCH 029/106] Instead of throwing exception, just return initial file name --- classpath/java-io.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index 3860e67ecd..580efe96d2 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -240,8 +240,8 @@ Java_java_io_File_toAbsolutePath(JNIEnv* e UNUSED, jclass, jstring path) return path; # else - // WinRT has no concept of full paths - throwNewErrno(e, "java/io/IOException"); + // WinRT has no concept of full paths, so any file + // accessed should already have full path, or it has explicit origin return path; # endif #else From 3f22c6d8e3223a46b6db1975eed7ee7e59d9716a Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Fri, 1 Feb 2013 16:40:12 +0200 Subject: [PATCH 030/106] Remove debug code --- classpath/java-io.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index 580efe96d2..bb1adce8b3 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -700,9 +700,6 @@ Java_java_io_FileOutputStream_open(JNIEnv* e, jclass, jstring path, jboolean app return -1; } } -#ifdef __ANDROID__ -#include -#endif extern "C" JNIEXPORT void JNICALL Java_java_io_FileOutputStream_write__II(JNIEnv* e, jclass, jint fd, jint c) @@ -723,11 +720,6 @@ Java_java_io_FileOutputStream_write__I_3BII } e->GetByteArrayRegion(b, offset, length, data); - #ifdef __ANDROID__ - if(fd == 1) { - __android_log_print(ANDROID_LOG_WARN, "net.osmand:native", "%.*s",length, data); - } - #endif if (not e->ExceptionCheck()) { doWrite(e, fd, data, length); } From ebf6277660472f9fb1fde8c5c349781b59130905 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Fri, 1 Feb 2013 16:55:37 +0200 Subject: [PATCH 031/106] java.io.RandomAccessFile for WinPhone8 / WinRT --- classpath/java-io.cpp | 57 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index bb1adce8b3..39186a0274 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -739,6 +739,9 @@ Java_java_io_RandomAccessFile_open(JNIEnv* e, jclass, jstring path, { string_t chars = getChars(e, path); if (chars) { + jlong peer = 0; + jlong length = 0; + #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) int fd = ::open((const char*)chars, O_RDONLY); releaseChars(e, path, chars); if (fd == -1) { @@ -751,11 +754,27 @@ Java_java_io_RandomAccessFile_open(JNIEnv* e, jclass, jstring path, throwNewErrno(e, "java/io/IOException"); return; } + peer = fd; + length = fileStats.st_size; + #else + HANDLE hFile = CreateFile2 + (chars, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr); + if (hFile == INVALID_HANDLE_VALUE) { + throwNewErrno(e, "java/io/IOException"); + return; + } + + FILE_STANDARD_INFO info; + if(!GetFileInformationByHandleEx(hFile, FileStandardInfo, &info, sizeof(info))) { + throwNewErrno(e, "java/io/IOException"); + return; + } + + peer = (jlong)hFile; + length = info.EndOfFile.QuadPart; + #endif - jlong peer = fd; e->SetLongArrayRegion(result, 0, 1, &peer); - - jlong length = fileStats.st_size; e->SetLongArrayRegion(result, 1, 1, &length); } } @@ -765,6 +784,7 @@ Java_java_io_RandomAccessFile_readBytes(JNIEnv* e, jclass, jlong peer, jlong position, jbyteArray buffer, int offset, int length) { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) int fd = (int)peer; if(::lseek(fd, position, SEEK_SET) == -1) { throwNewErrno(e, "java/io/IOException"); @@ -773,24 +793,45 @@ Java_java_io_RandomAccessFile_readBytes(JNIEnv* e, jclass, jlong peer, uint8_t* dst = reinterpret_cast (e->GetPrimitiveArrayCritical(buffer, 0)); -#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + ssize_t bytesRead = ::read(fd, dst + offset, length); -#else - auto bytesRead = ::read(fd, dst + offset, length); -#endif e->ReleasePrimitiveArrayCritical(buffer, dst, 0); if(bytesRead == -1) { throwNewErrno(e, "java/io/IOException"); return -1; } - +#else + HANDLE hFile = (HANDLE)peer; + LARGE_INTEGER lPos; + lPos.QuadPart = position; + if(!SetFilePointerEx(hFile, lPos, nullptr, FILE_BEGIN)) { + throwNewErrno(e, "java/io/IOException"); + return -1; + } + + uint8_t* dst = reinterpret_cast + (e->GetPrimitiveArrayCritical(buffer, 0)); + + DWORD bytesRead = 0; + if(!ReadFile(hFile, dst + offset, length, &bytesRead, nullptr)) { + throwNewErrno(e, "java/io/IOException"); + return -1; + } + e->ReleasePrimitiveArrayCritical(buffer, dst, 0); +#endif + return (jint)bytesRead; } extern "C" JNIEXPORT void JNICALL Java_java_io_RandomAccessFile_close(JNIEnv* /* e*/, jclass, jlong peer) { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) int fd = (int)peer; ::close(fd); +#else + HANDLE hFile = (HANDLE)peer; + CloseHandle(hFile); +#endif } From cb46cb0ba871f9354fb3bda685affc022e730021 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Fri, 1 Feb 2013 17:49:08 +0200 Subject: [PATCH 032/106] WP8/WinRT : Proper absolute path WP8/WinRT : Last modified time --- classpath/java-io.cpp | 122 +++++++++++++++++++++++++++++++----------- 1 file changed, 91 insertions(+), 31 deletions(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index 39186a0274..880d91cf56 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -240,8 +240,29 @@ Java_java_io_File_toAbsolutePath(JNIEnv* e UNUSED, jclass, jstring path) return path; # else - // WinRT has no concept of full paths, so any file - // accessed should already have full path, or it has explicit origin + string_t chars = getChars(e, path); + if(chars) { + LARGE_INTEGER fileSize; + HANDLE file = CreateFile2 + (chars, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr); + releaseChars(e, path, chars); + + if (file == INVALID_HANDLE_VALUE) + return path; + + uint8_t buffer[sizeof(FILE_NAME_INFO) + sizeof(WCHAR)*MAX_PATH]; + memset(&buffer[0], 0, sizeof(buffer)); + FILE_NAME_INFO* pInfo = reinterpret_cast(&buffer[0]); + if(!GetFileInformationByHandleEx(file, FileNameInfo, pInfo, sizeof(buffer))) + { + CloseHandle(file); + return path; + } + CloseHandle(file); + + return e->NewString + (reinterpret_cast(pInfo->FileName), pInfo->FileNameLength / sizeof(WCHAR)); + } return path; # endif #else @@ -267,33 +288,40 @@ Java_java_io_File_toAbsolutePath(JNIEnv* e UNUSED, jclass, jstring path) extern "C" JNIEXPORT jlong JNICALL Java_java_io_File_length(JNIEnv* e, jclass, jstring path) { - #ifdef PLATFORM_WINDOWS - LARGE_INTEGER fileSize; string_t chars = getChars(e, path); - #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) - HANDLE file = CreateFileW - (chars, FILE_READ_DATA, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); - #else - HANDLE file = CreateFile2 - (chars, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr); - #endif - releaseChars(e, path, chars); - if (file != INVALID_HANDLE_VALUE) - { + if(chars) { + LARGE_INTEGER fileSize; #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) - GetFileSizeEx(file, &fileSize); + HANDLE file = CreateFileW + (chars, FILE_READ_DATA, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); + #else + HANDLE file = CreateFile2 + (chars, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr); + #endif + releaseChars(e, path, chars); + if (file == INVALID_HANDLE_VALUE) + return 0; + #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + if(!GetFileSizeEx(file, &fileSize)) + { + CloseHandle(file); + return 0; + } #else FILE_STANDARD_INFO info; - if(GetFileInformationByHandleEx(file, FileStandardInfo, &info, sizeof(info))) - fileSize = info.EndOfFile; + if(!GetFileInformationByHandleEx(file, FileStandardInfo, &info, sizeof(info))) + { + CloseHandle(file); + return 0; + } + fileSize = info.EndOfFile; #endif - } - else return 0; - CloseHandle(file); - return static_cast(fileSize.QuadPart); + CloseHandle(file); + return static_cast(fileSize.QuadPart); + } #else string_t chars = getChars(e, path); @@ -547,21 +575,52 @@ Java_java_io_File_lastModified(JNIEnv* e, jclass, jstring path) string_t chars = getChars(e, path); if (chars) { #ifdef PLATFORM_WINDOWS - # pragma message("Implementation of last modified") - return 0; - #else - struct stat st; - if (stat(chars, &st)) { + #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + HANDLE hFile = CreateFileW + (chars, FILE_READ_DATA, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); + #else + HANDLE hFile = CreateFile2 + (chars, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr); + #endif + releaseChars(e, path, chars); + if (hFile == INVALID_HANDLE_VALUE) + return 0; + LARGE_INTEGER fileDate, filetimeToUnixEpochAdjustment; + filetimeToUnixEpochAdjustment.QuadPart = 11644473600000L * 10000L; + #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + FILETIME fileLastWriteTime; + if (!GetFileTime(hFile, 0, 0, &fileLastWriteTime)) + { + CloseHandle(hFile); + return 0; + } + fileDate.HighPart = fileLastWriteTime.dwHighDateTime; + fileDate.LowPart = fileLastWriteTime.dwLowDateTime; + #else + FILE_BASIC_INFO fileInfo; + if (!GetFileInformationByHandleEx(hFile, FileBasicInfo, &fileInfo, sizeof(fileInfo))) + { + CloseHandle(hFile); + return 0; + } + fileDate = fileInfo.ChangeTime; + #endif + CloseHandle(hFile); + fileDate.QuadPart -= filetimeToUnixEpochAdjustment.QuadPart; + return fileDate.QuadPart / 10000000L; + #else + struct stat fileStat; + if (stat(chars, &fileStat) == -1) { + releaseChars(e, path, chars); return 0; - } else { - return (static_cast(st.st_mtim.tv_sec) * 1000) + - (static_cast(st.st_mtim.tv_nsec) / (1000*1000)); } + return (static_cast(st.st_mtim.tv_sec) * 1000) + + (static_cast(st.st_mtim.tv_nsec) / (1000*1000)); #endif - } else { - return 0; } + + return 0; } extern "C" JNIEXPORT jstring JNICALL @@ -766,6 +825,7 @@ Java_java_io_RandomAccessFile_open(JNIEnv* e, jclass, jstring path, FILE_STANDARD_INFO info; if(!GetFileInformationByHandleEx(hFile, FileStandardInfo, &info, sizeof(info))) { + CloseHandle(hFile); throwNewErrno(e, "java/io/IOException"); return; } From c33c148b6b5c7295f3881df29def2b920cee4c47 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Fri, 1 Feb 2013 18:18:52 +0200 Subject: [PATCH 033/106] Add notifications about improvements possible --- classpath/java-io.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index 880d91cf56..74f2ab9617 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -289,7 +289,8 @@ extern "C" JNIEXPORT jlong JNICALL Java_java_io_File_length(JNIEnv* e, jclass, jstring path) { #ifdef PLATFORM_WINDOWS - + // Option: without opening file + // http://msdn.microsoft.com/en-us/library/windows/desktop/aa364946(v=vs.85).aspx string_t chars = getChars(e, path); if(chars) { LARGE_INTEGER fileSize; @@ -575,6 +576,8 @@ Java_java_io_File_lastModified(JNIEnv* e, jclass, jstring path) string_t chars = getChars(e, path); if (chars) { #ifdef PLATFORM_WINDOWS + // Option: without opening file + // http://msdn.microsoft.com/en-us/library/windows/desktop/aa364946(v=vs.85).aspx #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) HANDLE hFile = CreateFileW (chars, FILE_READ_DATA, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); From 34179f33322029f7c6409f8b0d82675d1f6fdc30 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Fri, 1 Feb 2013 20:54:15 +0200 Subject: [PATCH 034/106] Added comments regarding java.io.File.toAbsolute() and WinRT/WP8 --- classpath/java-io.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index 74f2ab9617..3d26a49f02 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -240,6 +240,13 @@ Java_java_io_File_toAbsolutePath(JNIEnv* e UNUSED, jclass, jstring path) return path; # else +// This could have worked, if GetFileInformationByHandleEx() returned volume information also +// There is a chance to get it, or using GetFullPathName, that is claimed to be unsupported +// or from System.IO.Path.GetFullPath(), but it's CLR and I see no way of calling it from +// C++/CX code +// Best wishes to everyone who will win this fight, +// Alexey Pelykh +/* string_t chars = getChars(e, path); if(chars) { LARGE_INTEGER fileSize; @@ -263,6 +270,7 @@ Java_java_io_File_toAbsolutePath(JNIEnv* e UNUSED, jclass, jstring path) return e->NewString (reinterpret_cast(pInfo->FileName), pInfo->FileNameLength / sizeof(WCHAR)); } +*/ return path; # endif #else From 41c726989627b903e6572c872ad1395eb0895c7e Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Sat, 2 Feb 2013 09:38:03 +0200 Subject: [PATCH 035/106] Support new WinRT interop --- classpath/java-io.cpp | 38 ++++++++++++++------------------------ makefile | 9 +++++---- 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index 3d26a49f02..ba4812a5a4 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -55,6 +55,15 @@ typedef wchar_t char_t; +#if defined(WINAPI_FAMILY) +#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + +#include "avian-interop.h" +#define SKIP_OPERATOR_NEW + +#endif +#endif + #else // not PLATFORM_WINDOWS # include @@ -93,7 +102,9 @@ typedef char char_t; # endif #endif // WINAPI_FAMILY +#if !defined(SKIP_OPERATOR_NEW) inline void* operator new(size_t, void* p) throw() { return p; } +#endif typedef const char_t* string_t; @@ -240,37 +251,16 @@ Java_java_io_File_toAbsolutePath(JNIEnv* e UNUSED, jclass, jstring path) return path; # else -// This could have worked, if GetFileInformationByHandleEx() returned volume information also -// There is a chance to get it, or using GetFullPathName, that is claimed to be unsupported -// or from System.IO.Path.GetFullPath(), but it's CLR and I see no way of calling it from -// C++/CX code -// Best wishes to everyone who will win this fight, -// Alexey Pelykh -/* string_t chars = getChars(e, path); if(chars) { - LARGE_INTEGER fileSize; - HANDLE file = CreateFile2 - (chars, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr); + std::wstring partialPath = chars; releaseChars(e, path, chars); - if (file == INVALID_HANDLE_VALUE) - return path; - - uint8_t buffer[sizeof(FILE_NAME_INFO) + sizeof(WCHAR)*MAX_PATH]; - memset(&buffer[0], 0, sizeof(buffer)); - FILE_NAME_INFO* pInfo = reinterpret_cast(&buffer[0]); - if(!GetFileInformationByHandleEx(file, FileNameInfo, pInfo, sizeof(buffer))) - { - CloseHandle(file); - return path; - } - CloseHandle(file); + std::wstring fullPath = AvianInterop::GetFullPath(partialPath); return e->NewString - (reinterpret_cast(pInfo->FileName), pInfo->FileNameLength / sizeof(WCHAR)); + (reinterpret_cast(fullPath.c_str()), fullPath.length()); } -*/ return path; # endif #else diff --git a/makefile b/makefile index f0cb5494fb..73f5c69936 100755 --- a/makefile +++ b/makefile @@ -705,12 +705,12 @@ ifeq ($(platform),wp8) -DAVIAN_VERSION=\"$(version)\" -D_JNI_IMPLEMENTATION_ \ -DUSE_ATOMIC_OPERATIONS -DAVIAN_JAVA_HOME=\"$(javahome)\" \ -DAVIAN_EMBED_PREFIX=\"$(embed-prefix)\" \ - -I"$(shell $(windows-path) "$(wp8)/zlib/upstream")" \ - -Fd$(build)/$(name).pdb -I"$(shell $(windows-path) "$(wp8)/include")" -I$(src) -I$(classpath-src) \ + -I"$(shell $(windows-path) "$(wp8)/zlib/upstream")" -I"$(shell $(windows-path) "$(wp8)/interop/avian-interop-client")" \ + -I"$(shell $(windows-path) "$(wp8)/include")" -I$(src) -I$(classpath-src) \ -I"$(build)" \ -I"$(windows-java-home)/include" -I"$(windows-java-home)/include/win32" \ -DTARGET_BYTES_PER_WORD=$(pointer-size) \ - -Gd + -Gd -EHsc common-lflags = $(classpath-lflags) @@ -738,7 +738,8 @@ ifeq ($(platform),wp8) -MACHINE:$(machine_type) \ -LIBPATH:"$(WP80_KIT)\lib\$(w8kit_arch)" -LIBPATH:"$(WP80_SDK)\lib$(vc_arch)" -LIBPATH:"$(WIN8_KIT)\Lib\win8\um\$(w8kit_arch)" \ ws2_32.lib \ - "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\zlib.lib")" "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\ThreadEmulation.lib")" + "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\zlib.lib")" "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\ThreadEmulation.lib")" \ + "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\AvianInteropClient.lib")" lflags += -NXCOMPAT -DYNAMICBASE -SUBSYSTEM:CONSOLE -TLBID:1 lflags += -NODEFAULTLIB:"ole32.lib" -NODEFAULTLIB:"kernel32.lib" lflags += PhoneAppModelHost.lib WindowsPhoneCore.lib -WINMD -WINMDFILE:$(subst $(so-suffix),.winmd,$(@)) From 2362235b4c033976ca38ed54714050424923eff0 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Sat, 2 Feb 2013 10:14:47 +0200 Subject: [PATCH 036/106] getErrorStr() for Windows platforms --- classpath/java-lang.cpp | 45 +++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index 9d2562e265..dc54af5fed 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -74,25 +74,36 @@ namespace { #ifdef PLATFORM_WINDOWS - char* getErrorStr(DWORD err){ - // The poor man's error string, just print the error code - char * errStr = (char*) malloc(9 * sizeof(char)); - snprintf(errStr, 9, "%d", (int) err); + +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + char* getErrorStr(DWORD err) { + LPSTR errorStr = 0; + if(!FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, err, LANG_SYSTEM_DEFAULT, (LPSTR)&errorStr, 0, 0)) + { + char* errStr = (char*) malloc(9 * sizeof(char)); + snprintf(errStr, 9, "%d", (int) err); + return errStr; + } + char* errStr = strdup(errorStr); + LocalFree(errorStr); return errStr; - - #pragma message("TODO") - // The better way to do this, if I could figure out how to convert LPTSTR to char* - //char* errStr; - //LPTSTR s; - //if(FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | - // FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, 0, &s, 0, NULL) == 0) - //{ - // errStr.Format("Unknown error occurred (%08x)", err); - //} else { - // errStr = s; - //} - //return errStr; } +#else + char* getErrorStr(DWORD err) { + LPSTR errorStr = (LPSTR)malloc(4096); //NOTE: something constant + if(!FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, err, LANG_SYSTEM_DEFAULT, errorStr, 0, 0)) + { + free(errorStr); + + char* errStr = (char*) malloc(9 * sizeof(char)); + snprintf(errStr, 9, "%d", (int) err); + return errStr; + } + char* errStr = strdup(errorStr); + free(errorStr); + return errStr; + } +#endif #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) void makePipe(JNIEnv* e, HANDLE p[2]) From 0ff703d1c0227e905fd64f9059082459d2d583a9 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Sat, 2 Feb 2013 11:00:33 +0200 Subject: [PATCH 037/106] Culture fixes ; Path extensions --- classpath/java-lang.cpp | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index dc54af5fed..704e2ae6a5 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -69,6 +69,12 @@ # ifndef WINAPI_FAMILY_PARTITION # define WINAPI_FAMILY_PARTITION(x) (x) +# endif +#else +# if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + +# include "avian-interop.h" + # endif #endif // WINAPI_FAMILY @@ -401,8 +407,20 @@ Locale getLocale() { return Locale(lang, reg); #else - #pragma message("TODO: CultureInfo.CurrentCulture") - return Locale("en", "US"); + std::wstring culture = AvianInterop::GetCurrentUICulture(); + char* cultureName = strdup(std::string(culture.begin(), culture.end()).c_str()); + char* delimiter = strchr(cultureName, '-'); + if(!delimiter) + { + free(cultureName); + return Locale("en", "US"); + } + const char* lang = cultureName; + const char* reg = delimiter + 1; + *delimiter = 0; + Locale locale(lang, reg); + free(cultureName); + return locale; #endif } #else @@ -607,8 +625,8 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, GetTempPath(MAX_PATH, buffer); r = e->NewStringUTF(buffer); # else - #pragma message("TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ Windows.Storage.ApplicationData.Current.TemporaryFolder") - r = 0; + std::wstring tmpDir = AvianInterop::GetTemporaryFolder(); + r = e->NewString((const jchar*)tmpDir.c_str(), tmpDir.length()); # endif } else if (strcmp(chars, "user.dir") == 0) { # if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) @@ -616,8 +634,8 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, GetCurrentDirectory(MAX_PATH, buffer); r = e->NewStringUTF(buffer); # else - #pragma message("TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ Windows.ApplicationModel.Package.Current.InstalledLocation") - r = 0; + std::wstring userDir = AvianInterop::GetInstalledLocation(); + r = e->NewString((const jchar*)userDir.c_str(), userDir.length()); # endif } else if (strcmp(chars, "user.home") == 0) { # ifdef _MSC_VER @@ -630,8 +648,8 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, r = 0; } # else - #pragma message("TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ Windows.Storage.KnownFolders.DocumentsLibrary") - r = 0; + std::wstring userHome = AvianInterop::GetDocumentsLibraryLocation(); + r = e->NewString((const jchar*)userHome.c_str(), userHome.length()); # endif # else LPWSTR home = _wgetenv(L"USERPROFILE"); From 1d60ababd3683e9e83b468c082cd7650d127959d Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Sat, 2 Feb 2013 12:27:36 +0200 Subject: [PATCH 038/106] Support built-in jars when wusing multi-library --- src/jnienv.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/jnienv.cpp b/src/jnienv.cpp index c8f27fb0b7..4295c7e0a3 100644 --- a/src/jnienv.cpp +++ b/src/jnienv.cpp @@ -3729,7 +3729,7 @@ JNI_CreateJavaVM(Machine** m, Thread** t, void* args) unsigned heapLimit = 0; unsigned stackLimit = 0; - const char* bootLibrary = 0; + const char* bootLibraries = 0; const char* classpath = 0; const char* javaHome = AVIAN_JAVA_HOME; const char* embedPrefix = AVIAN_EMBED_PREFIX; @@ -3765,7 +3765,7 @@ JNI_CreateJavaVM(Machine** m, Thread** t, void* args) if (strncmp(p, BOOTSTRAP_PROPERTY "=", sizeof(BOOTSTRAP_PROPERTY)) == 0) { - bootLibrary = p + sizeof(BOOTSTRAP_PROPERTY); + bootLibraries = p + sizeof(BOOTSTRAP_PROPERTY); } else if (strncmp(p, CRASHDIR_PROPERTY "=", sizeof(CRASHDIR_PROPERTY)) == 0) { @@ -3819,9 +3819,16 @@ JNI_CreateJavaVM(Machine** m, Thread** t, void* args) *RUNTIME_ARRAY_BODY(bootClasspathBuffer) = 0; } + char* bootLibrary = bootLibraries ? strdup(bootLibraries) : 0; + char* bootLibraryEnd = bootLibrary ? strchr(bootLibrary, PATH_SEPARATOR) : 0; + if(bootLibraryEnd) + *bootLibraryEnd = 0; + Finder* bf = makeFinder (s, h, RUNTIME_ARRAY_BODY(bootClasspathBuffer), bootLibrary); Finder* af = makeFinder(s, h, classpath, bootLibrary); + if(bootLibrary) + free(bootLibrary); Processor* p = makeProcessor(s, h, true); const char** properties = static_cast From 023af5102efc4c7754ae865a35c4114fe2299419 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Sat, 2 Feb 2013 19:42:47 +0200 Subject: [PATCH 039/106] Remove empty lines Conflicts: classpath/java-lang.cpp --- classpath/java-lang.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index 704e2ae6a5..88a4cf5ef6 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -898,6 +898,11 @@ Java_java_lang_Math_atan(JNIEnv*, jclass, jdouble val) return atan(val); } +extern "C" JNIEXPORT jdouble JNICALL +Java_java_lang_Math_atan2(JNIEnv*, jclass, jdouble y, jdouble x) +{ + return atan2(y, x); +} extern "C" JNIEXPORT jdouble JNICALL Java_java_lang_Math_sinh(JNIEnv*, jclass, jdouble val) @@ -917,7 +922,6 @@ Java_java_lang_Math_tanh(JNIEnv*, jclass, jdouble val) return tanh(val); } - extern "C" JNIEXPORT jdouble JNICALL Java_java_lang_Math_sqrt(JNIEnv*, jclass, jdouble val) { From 33d4f008f42a7d62dff17476ef1999d1853acd81 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Sat, 2 Feb 2013 20:09:28 +0200 Subject: [PATCH 040/106] Fix dword<>qword mistake --- src/x86.masm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/x86.masm b/src/x86.masm index 640637d5af..2f9dedcbd2 100644 --- a/src/x86.masm +++ b/src/x86.masm @@ -108,7 +108,7 @@ Lfloat: Ldouble: cmp ecx,offset DOUBLE_TYPE jne Lexit - fstp ds:dword ptr[8+ebp] + fstp ds:qword ptr[8+ebp] mov eax,ds:dword ptr[8+ebp] mov edx,ds:dword ptr[12+ebp] From 18cb5ba3792e43589302c4ea242681c2f414c9ae Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Sun, 3 Feb 2013 12:27:30 +0200 Subject: [PATCH 041/106] Make clean target more robust Conflicts: .gitignore --- .gitignore | 1 + makefile | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 201518bb12..588446f90d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ build bin /lib /distrib +*.pdb diff --git a/makefile b/makefile index 73f5c69936..af5533815f 100755 --- a/makefile +++ b/makefile @@ -1248,6 +1248,11 @@ javadoc: .PHONY: clean clean: + @echo "removing $(build)" + rm -rf $(build) + +.PHONY: clean-all +clean-all: @echo "removing build" rm -rf build From edbea8ac2be4dd5dd3ae2b02f7b14b0d85c8048e Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Mon, 4 Feb 2013 19:45:06 +0200 Subject: [PATCH 042/106] Comment out printTrace --- src/machine.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/machine.h b/src/machine.h index 5a2812c2b7..420a0192cb 100644 --- a/src/machine.h +++ b/src/machine.h @@ -2695,7 +2695,7 @@ throw_(Thread* t, object e) t->exception = e; - printTrace(t, e); + // printTrace(t, e); popResources(t); From e6fc4e3bea0c84087133e488beaf103430da2b8b Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Mon, 4 Feb 2013 20:02:46 +0200 Subject: [PATCH 043/106] RUNTIME_ARRAY usage --- src/arm.cpp | 5 +---- src/arm.h | 6 ++---- src/bootimage.cpp | 42 +++++++++++++++--------------------------- src/common.h | 4 ++++ src/interpret.cpp | 5 +---- 5 files changed, 23 insertions(+), 39 deletions(-) diff --git a/src/arm.cpp b/src/arm.cpp index 1d4dbc8dd1..3016c4658b 100644 --- a/src/arm.cpp +++ b/src/arm.cpp @@ -2555,7 +2555,7 @@ class MyAssembler: public Assembler { OperandType type; Operand* operand; }; - Argument* arguments = new Argument[argumentCount]; + RUNTIME_ARRAY(Argument, arguments, argumentCount); va_list a; va_start(a, argumentCount); unsigned footprint = 0; @@ -2590,9 +2590,6 @@ class MyAssembler: public Assembler { offset += ceiling(arguments[i].size, TargetBytesPerWord); } } - - delete[] arguments; - arguments = 0; } virtual void allocateFrame(unsigned footprint) { diff --git a/src/arm.h b/src/arm.h index 302355c453..5593c86f92 100644 --- a/src/arm.h +++ b/src/arm.h @@ -182,7 +182,7 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t* argumentTypes, unsigned vfpIndex = 0; unsigned vfpBackfillIndex UNUSED = 0; - uintptr_t* stack = new uintptr_t[(argumentCount * 8) / BytesPerWord]; // is > argumentSize to account for padding + RUNTIME_ARRAY(uintptr_t, stack, (argumentCount * 8) / BytesPerWord); // is > argumentSize to account for padding unsigned stackIndex = 0; unsigned ai = 0; @@ -272,12 +272,10 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t* argumentTypes, } unsigned stackSize = stackIndex*BytesPerWord + ((stackIndex & 1) << 2); - auto retVal = vmNativeCall + return vmNativeCall (function, stackSize, stack, stackIndex * BytesPerWord, (gprIndex ? gprTable : 0), (vfpIndex ? vfpTable : 0), returnType); - delete[] stack; - return retVal; } } // namespace vm diff --git a/src/bootimage.cpp b/src/bootimage.cpp index 5b725f5058..5ec14b51e6 100644 --- a/src/bootimage.cpp +++ b/src/bootimage.cpp @@ -342,7 +342,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, unsigned count = s.read2() - 1; if (count) { - Type* types = new Type[count + 2]; + RUNTIME_ARRAY(Type, types, count + 2); types[0] = Type_object; types[1] = Type_intptr_t; @@ -410,9 +410,6 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, (t, typeMaps, hashMapFind (t, root(t, Machine::PoolMap), c, objectHash, objectEqual), array, objectHash); - - delete[] types; - types = 0; } } @@ -423,7 +420,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, object fields = allFields(t, typeMaps, c, &count, &array); PROTECT(t, fields); - Field* memberFields = new Field[count + 1]; + RUNTIME_ARRAY(Field, memberFields, count + 1); unsigned memberIndex; unsigned buildMemberOffset; @@ -447,7 +444,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, ++ memberIndex; } } else { - init(new (memberFields) Field, Type_object, 0, BytesPerWord, 0, + init(new (&memberFields[0]) Field, Type_object, 0, BytesPerWord, 0, TargetBytesPerWord); memberIndex = 1; @@ -457,15 +454,15 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, const unsigned StaticHeader = 3; - Field* staticFields = new Field[count + StaticHeader]; + RUNTIME_ARRAY(Field, staticFields, count + StaticHeader); - init(new (staticFields) Field, Type_object, 0, BytesPerWord, 0, + init(new (&staticFields[0]) Field, Type_object, 0, BytesPerWord, 0, TargetBytesPerWord); - init(new (staticFields + 1) Field, Type_intptr_t, BytesPerWord, + init(new (&staticFields[1]) Field, Type_intptr_t, BytesPerWord, BytesPerWord, TargetBytesPerWord, TargetBytesPerWord); - init(new (staticFields + 2) Field, Type_object, BytesPerWord * 2, + init(new (&staticFields[2]) Field, Type_object, BytesPerWord * 2, BytesPerWord, TargetBytesPerWord * 2, TargetBytesPerWord); unsigned staticIndex = StaticHeader; @@ -515,7 +512,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, buildStaticOffset = fieldOffset(t, field); - init(new (staticFields + staticIndex) Field, type, + init(new (&staticFields[staticIndex]) Field, type, buildStaticOffset, buildSize, targetStaticOffset, targetSize); @@ -529,7 +526,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, buildMemberOffset = fieldOffset(t, field); - init(new (memberFields + memberIndex) Field, type, + init(new (&memberFields[memberIndex]) Field, type, buildMemberOffset, buildSize, targetMemberOffset, targetSize); @@ -552,7 +549,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, ceiling(targetMemberOffset, TargetBytesPerWord), memberIndex); for (unsigned i = 0; i < memberIndex; ++i) { - Field* f = memberFields + i; + Field* f = &memberFields[i]; expect(t, f->buildOffset < map->buildFixedSizeInWords * BytesPerWord); @@ -576,7 +573,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, TypeMap::SingletonKind); for (unsigned i = 0; i < staticIndex; ++i) { - Field* f = staticFields + i; + Field* f = &staticFields[i]; expect(t, f->buildOffset < map->buildFixedSizeInWords * BytesPerWord); @@ -589,12 +586,6 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, hashMapInsert (t, typeMaps, classStaticTable(t, c), array, objectHash); } - - delete[] memberFields; - memberFields = 0; - - delete[] staticFields; - staticFields = 0; } } } @@ -1343,9 +1334,9 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp } ++ count; - Field* fields = new Field[count]; + RUNTIME_ARRAY(Field, fields, count); - init(new (fields) Field, Type_object, 0, BytesPerWord, 0, + init(new (&fields[0]) Field, Type_object, 0, BytesPerWord, 0, TargetBytesPerWord); unsigned buildOffset = BytesPerWord; @@ -1423,7 +1414,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp ++ targetOffset; } - init(new (fields + j) Field, type, buildOffset, buildSize, + init(new (&fields[j]) Field, type, buildOffset, buildSize, targetOffset, targetSize); buildOffset += buildSize; @@ -1458,7 +1449,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp targetArrayElementSize, arrayElementType); for (unsigned j = 0; j < fixedFieldCount; ++j) { - Field* f = fields + j; + Field* f = &fields[j]; expect(t, f->buildOffset < map->buildFixedSizeInWords * BytesPerWord); @@ -1471,9 +1462,6 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp hashMapInsert (t, typeMaps, vm::type(t, static_cast(i)), array, objectHash); - - delete[] fields; - fields = 0; } constants = makeCodeImage diff --git a/src/common.h b/src/common.h index c99f23410e..6803fe4c34 100644 --- a/src/common.h +++ b/src/common.h @@ -243,6 +243,10 @@ class RuntimeArray { free(body); } + T& operator[] (const unsigned index) { + return body[index]; + } + T* body; }; diff --git a/src/interpret.cpp b/src/interpret.cpp index 9399e96657..42183e98f0 100644 --- a/src/interpret.cpp +++ b/src/interpret.cpp @@ -2321,7 +2321,7 @@ interpret3(Thread* t, const int base) object class_ = resolveClassInPool(t, frameMethod(t, frame), index - 1); PROTECT(t, class_); - int32_t* counts = new int32_t[dimensions]; + RUNTIME_ARRAY(int32_t, counts, dimensions); for (int i = dimensions - 1; i >= 0; --i) { counts[i] = popInt(t); if (UNLIKELY(counts[i] < 0)) { @@ -2338,9 +2338,6 @@ interpret3(Thread* t, const int base) populateMultiArray(t, array, counts, 0, dimensions); pushObject(t, array); - - delete[] counts; - counts = 0; } goto loop; case new_: { From 9e4144f92baa6ce3b2ff5954492e8073df8690b5 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Tue, 5 Feb 2013 08:41:37 +0200 Subject: [PATCH 044/106] Trace writeout refactor --- src/machine.cpp | 73 ++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 43 deletions(-) diff --git a/src/machine.cpp b/src/machine.cpp index d2d225e7e5..46f331c32d 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -4759,6 +4759,27 @@ visitRoots(Machine* m, Heap::Visitor* v) } } +void +logTrace(FILE* f, const char* fmt, ...) +{ + va_list a; + va_start(a, fmt); +#ifdef PLATFORM_WINDOWS + const unsigned length = _vscprintf(fmt, a); +#else + const unsigned length = vsnprintf(0, 0, fmt, a); +#endif + RUNTIME_ARRAY(char, buffer, length + 1); + vsnprintf(&buffer[0], length, fmt, a); + buffer[length] = 0; + va_end(a); + + ::fprintf(f, "%s", &buffer[0]); +#ifdef PLATFORM_WINDOWS + ::OutputDebugStringA(&buffer[0]); +#endif +} + void printTrace(Thread* t, object exception) { @@ -4768,34 +4789,19 @@ printTrace(Thread* t, object exception) for (object e = exception; e; e = throwableCause(t, e)) { if (e != exception) { - fprintf(errorLog(t), "caused by: "); -#if defined(PLATFORM_WINDOWS) - OutputDebugStringA("caused by: "); -#endif + logTrace(errorLog(t), "caused by: "); } - fprintf(errorLog(t), "%s", &byteArrayBody + logTrace(errorLog(t), "%s", &byteArrayBody (t, className(t, objectClass(t, e)), 0)); -#if defined(PLATFORM_WINDOWS) - OutputDebugStringA((const CHAR*)&byteArrayBody - (t, className(t, objectClass(t, e)), 0)); -#endif if (throwableMessage(t, e)) { object m = throwableMessage(t, e); THREAD_RUNTIME_ARRAY(t, char, message, stringLength(t, m) + 1); stringChars(t, m, RUNTIME_ARRAY_BODY(message)); - fprintf(errorLog(t), ": %s\n", RUNTIME_ARRAY_BODY(message)); -#if defined(PLATFORM_WINDOWS) - OutputDebugStringA(": "); - OutputDebugStringA(RUNTIME_ARRAY_BODY(message)); - OutputDebugStringA("\n"); -#endif + logTrace(errorLog(t), ": %s\n", RUNTIME_ARRAY_BODY(message)); } else { - fprintf(errorLog(t), "\n"); -#if defined(PLATFORM_WINDOWS) - OutputDebugStringA("\n"); -#endif + logTrace(errorLog(t), "\n"); } object trace = throwableTrace(t, e); @@ -4809,36 +4815,17 @@ printTrace(Thread* t, object exception) int line = t->m->processor->lineNumber (t, traceElementMethod(t, e), traceElementIp(t, e)); - fprintf(errorLog(t), " at %s.%s ", class_, method); -#if defined(PLATFORM_WINDOWS) - OutputDebugStringA(" at "); - OutputDebugStringA((const CHAR*)class_); - OutputDebugStringA("."); - OutputDebugStringA((const CHAR*)method); - OutputDebugStringA(" "); -#endif + logTrace(errorLog(t), " at %s.%s ", class_, method); switch (line) { case NativeLine: - fprintf(errorLog(t), "(native)\n"); -#if defined(PLATFORM_WINDOWS) - OutputDebugStringA("(native)\n"); -#endif + logTrace(errorLog(t), "(native)\n"); break; case UnknownLine: - fprintf(errorLog(t), "(unknown line)\n"); -#if defined(PLATFORM_WINDOWS) - OutputDebugStringA("(unknown line)\n"); -#endif + logTrace(errorLog(t), "(unknown line)\n"); break; default: - fprintf(errorLog(t), "(line %d)\n", line); -#if defined(PLATFORM_WINDOWS) - OutputDebugStringA("(line "); - char buf[35]; - OutputDebugStringA(itoa(line, buf, 10)); - OutputDebugStringA(")\n"); -#endif + logTrace(errorLog(t), "(line %d)\n", line); } } } @@ -4848,7 +4835,7 @@ printTrace(Thread* t, object exception) } } - fflush(errorLog(t)); + ::fflush(errorLog(t)); } object From f2d2c9af294654821dbfb6a35261f48190c426c7 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 7 Feb 2013 11:43:39 +0200 Subject: [PATCH 045/106] Fix for windows ::open --- classpath/java-io.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index ba4812a5a4..acc0582feb 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -802,7 +802,11 @@ Java_java_io_RandomAccessFile_open(JNIEnv* e, jclass, jstring path, jlong peer = 0; jlong length = 0; #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + #if defined(PLATFORM_WINDOWS) + int fd = ::_wopen(chars, O_RDONLY); + #else int fd = ::open((const char*)chars, O_RDONLY); + #endif releaseChars(e, path, chars); if (fd == -1) { throwNewErrno(e, "java/io/IOException"); From d97fe5304f431fc43ccd0c1bbf62090c362ffeac Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 5 Feb 2013 10:13:59 -0700 Subject: [PATCH 046/106] use THREAD_RUNTIME_ARRAY instead of RUNTIME_ARRAY where appropriate This ensures that if the stack is unwound for an exception we'll still release the memory. --- src/bootimage.cpp | 8 ++++---- src/interpret.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bootimage.cpp b/src/bootimage.cpp index 5ec14b51e6..45dd4e3364 100644 --- a/src/bootimage.cpp +++ b/src/bootimage.cpp @@ -342,7 +342,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, unsigned count = s.read2() - 1; if (count) { - RUNTIME_ARRAY(Type, types, count + 2); + THREAD_RUNTIME_ARRAY(t, Type, types, count + 2); types[0] = Type_object; types[1] = Type_intptr_t; @@ -420,7 +420,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, object fields = allFields(t, typeMaps, c, &count, &array); PROTECT(t, fields); - RUNTIME_ARRAY(Field, memberFields, count + 1); + THREAD_RUNTIME_ARRAY(t, Field, memberFields, count + 1); unsigned memberIndex; unsigned buildMemberOffset; @@ -454,7 +454,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, const unsigned StaticHeader = 3; - RUNTIME_ARRAY(Field, staticFields, count + StaticHeader); + THREAD_RUNTIME_ARRAY(t, Field, staticFields, count + StaticHeader); init(new (&staticFields[0]) Field, Type_object, 0, BytesPerWord, 0, TargetBytesPerWord); @@ -1334,7 +1334,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp } ++ count; - RUNTIME_ARRAY(Field, fields, count); + THREAD_RUNTIME_ARRAY(t, Field, fields, count); init(new (&fields[0]) Field, Type_object, 0, BytesPerWord, 0, TargetBytesPerWord); diff --git a/src/interpret.cpp b/src/interpret.cpp index 42183e98f0..4b5b3cd006 100644 --- a/src/interpret.cpp +++ b/src/interpret.cpp @@ -647,7 +647,7 @@ invokeNative(Thread* t, object method) { THREAD_RESOURCE0(t, popFrame(static_cast(t))); unsigned footprint = methodParameterFootprint(t, method); - RUNTIME_ARRAY(uintptr_t, args, footprint); + THREAD_RUNTIME_ARRAY(t, uintptr_t, args, footprint); unsigned sp = frameBase(t, t->frame); unsigned argOffset = 0; if ((methodFlags(t, method) & ACC_STATIC) == 0) { @@ -2321,7 +2321,7 @@ interpret3(Thread* t, const int base) object class_ = resolveClassInPool(t, frameMethod(t, frame), index - 1); PROTECT(t, class_); - RUNTIME_ARRAY(int32_t, counts, dimensions); + THREAD_RUNTIME_ARRAY(t, int32_t, counts, dimensions); for (int i = dimensions - 1; i >= 0; --i) { counts[i] = popInt(t); if (UNLIKELY(counts[i] < 0)) { From 82d4ced1600371fa70c2bb8b26db31e44e8bedf2 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 6 Feb 2013 10:04:55 -0700 Subject: [PATCH 047/106] specify UTF-8 encoding to javac This fixes "illegal character" errors when compiling e.g. Misc.java on systems where the default encoding is not UTF-8. --- makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/makefile b/makefile index af5533815f..e5fd4dd16b 100755 --- a/makefile +++ b/makefile @@ -179,7 +179,7 @@ dlltool = dlltool vg = nice valgrind --num-callers=32 --db-attach=yes --freelist-vol=100000000 vg += --leak-check=full --suppressions=valgrind.supp db = gdb --args -javac = "$(JAVA_HOME)/bin/javac" +javac = "$(JAVA_HOME)/bin/javac" -encoding UTF-8 javah = "$(JAVA_HOME)/bin/javah" jar = "$(JAVA_HOME)/bin/jar" strip = strip @@ -433,7 +433,7 @@ ifeq ($(platform),android) lflags = "-L$(sysroot)/usr/lib" $(common-lflags) -llog target-format = elf use-lto = false - + ifeq ($(arch),arm) cflags += -marm -march=$(android-arm-arch) -ftree-vectorize -ffast-math -mfloat-abi=softfp endif From ef11cd1d8da77d83f059c5d34a26f4c6aa23c770 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 6 Feb 2013 11:38:30 -0700 Subject: [PATCH 048/106] rename clean to clean-current, and clean-all back to clean This way, the clean target continues to do what it always did: delete the whole build directory. You can use clean-current to just delete the currently-configured build directory. --- makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/makefile b/makefile index e5fd4dd16b..f7da20fd08 100755 --- a/makefile +++ b/makefile @@ -1246,13 +1246,13 @@ javadoc: -header "Avian v$(version)" \ -bottom "http://oss.readytalk.com/avian" -.PHONY: clean -clean: +.PHONY: clean-current +clean-current: @echo "removing $(build)" rm -rf $(build) -.PHONY: clean-all -clean-all: +.PHONY: clean +clean: @echo "removing build" rm -rf build From 524166046365ded0f192c8593f4cfe880c80f203 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 6 Feb 2013 11:40:06 -0700 Subject: [PATCH 049/106] fix SIGSEGV and off-by-one error in logDebug We must use separate va_start/va_end pairs for each call to vsnprintf on Linux and possibly other platforms in order to avoid a crash. Also, we need to give it room to null terminate the string at the right point. --- src/machine.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/machine.cpp b/src/machine.cpp index 46f331c32d..83b8c88620 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -4769,11 +4769,14 @@ logTrace(FILE* f, const char* fmt, ...) #else const unsigned length = vsnprintf(0, 0, fmt, a); #endif - RUNTIME_ARRAY(char, buffer, length + 1); - vsnprintf(&buffer[0], length, fmt, a); - buffer[length] = 0; va_end(a); + RUNTIME_ARRAY(char, buffer, length + 1); + va_start(a, fmt); + vsnprintf(&buffer[0], length + 1, fmt, a); + va_end(a); + buffer[length] = 0; + ::fprintf(f, "%s", &buffer[0]); #ifdef PLATFORM_WINDOWS ::OutputDebugStringA(&buffer[0]); From b38eecbefa3a55c878d8af7bf82c43c1ce225d0d Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 7 Feb 2013 11:35:48 -0700 Subject: [PATCH 050/106] specify O_BINARY when opening files on Windows --- classpath/java-io.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index acc0582feb..f2e9fd3c18 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -803,9 +803,9 @@ Java_java_io_RandomAccessFile_open(JNIEnv* e, jclass, jstring path, jlong length = 0; #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) #if defined(PLATFORM_WINDOWS) - int fd = ::_wopen(chars, O_RDONLY); + int fd = ::_wopen(chars, O_RDONLY | OPEN_MASK); #else - int fd = ::open((const char*)chars, O_RDONLY); + int fd = ::open((const char*)chars, O_RDONLY | OPEN_MASK); #endif releaseChars(e, path, chars); if (fd == -1) { From 6d4f797b66e217549ed23f4173a3a1e1847d9fc5 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 7 Feb 2013 11:39:04 -0700 Subject: [PATCH 051/106] fix handling of non-ascii characters in filenames on Windows --- src/windows.cpp | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/windows.cpp b/src/windows.cpp index 98fc8e5d96..e6e189671d 100644 --- a/src/windows.cpp +++ b/src/windows.cpp @@ -803,17 +803,15 @@ class MySystem: public System { virtual Status map(System::Region** region, const char* name) { Status status = 1; + size_t nameLen = strlen(name) * 2; + RUNTIME_ARRAY(wchar_t, wideName, nameLen + 1); + MultiByteToWideChar(CP_UTF8, 0, name, -1, wideName, nameLen + 1); #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) - HANDLE file = CreateFile(name, FILE_READ_DATA, FILE_SHARE_READ, 0, - OPEN_EXISTING, 0, 0); + HANDLE file = CreateFileW(wideName, FILE_READ_DATA, FILE_SHARE_READ, 0, + OPEN_EXISTING, 0, 0); #else - size_t nameLen = strlen(name); - wchar_t* wideName = new wchar_t[nameLen + 1]; - size_t convertedChars = 0; - mbstowcs_s(&convertedChars, wideName, nameLen + 1, name, nameLen); HANDLE file = CreateFile2(wideName, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, 0); - delete[] wideName; #endif if (file != INVALID_HANDLE_VALUE) { #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) @@ -882,21 +880,21 @@ class MySystem: public System { } virtual FileType stat(const char* name, unsigned* length) { - struct _stat s; - int r = _stat(name, &s); - if (r == 0) { - if (S_ISREG(s.st_mode)) { - *length = s.st_size; - return TypeFile; - } else if (S_ISDIR(s.st_mode)) { - *length = 0; + size_t nameLen = strlen(name) * 2; + RUNTIME_ARRAY(wchar_t, wideName, nameLen + 1); + MultiByteToWideChar(CP_UTF8, 0, name, -1, wideName, nameLen + 1); + WIN32_FILE_ATTRIBUTE_DATA data; + if (GetFileAttributesExW + (wideName, GetFileExInfoStandard, &data)) + { + if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { return TypeDirectory; } else { - *length = 0; - return TypeUnknown; + *length = (data.nFileSizeHigh * static_cast(MAXDWORD + 1)) + + data.nFileSizeLow; + return TypeFile; } } else { - *length = 0; return TypeDoesNotExist; } } @@ -934,15 +932,14 @@ class MySystem: public System { HMODULE handle; unsigned nameLength = (name ? strlen(name) : 0); if (name) { + size_t nameLen = nameLength * 2; + RUNTIME_ARRAY(wchar_t, wideName, nameLen + 1); + MultiByteToWideChar(CP_UTF8, 0, name, -1, wideName, nameLen + 1); + #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) - handle = LoadLibrary(name); + handle = LoadLibraryW(wideName); #else - size_t nameLen = strlen(name); - wchar_t* wideName = new wchar_t[nameLen + 1]; - size_t convertedChars = 0; - mbstowcs_s(&convertedChars, wideName, nameLen + 1, name, nameLen); handle = LoadPackagedLibrary(wideName, 0); - delete[] wideName; #endif } else { #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) From 07e3294937e8792cd25f513606a8a5607afe73e8 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 8 Feb 2013 09:34:26 -0700 Subject: [PATCH 052/106] use rpath=$ORIGIN instead of LD_LIBRARY_PATH Hi If libjvm.so is in the same directory as avian-dynamic, then there's no need for LD_LIBRARY_PATH to include that directory, we can just set the rpath in avian-dynamic to $ORIGIN when linking it. Working patch attached. Regards Damjan --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index b3cbd88a57..fe83a35381 100755 --- a/makefile +++ b/makefile @@ -1245,7 +1245,7 @@ ifdef msvc -MANIFESTFILE:$(@).manifest $(mt) -manifest $(@).manifest -outputresource:"$(@);1" else - $(ld) $(driver-dynamic-objects) -L$(build) -ljvm $(lflags) $(no-lto) -o $(@) + $(ld) $(driver-dynamic-objects) -L$(build) -ljvm $(lflags) $(no-lto) -Wl,-rpath=\$$ORIGIN -z origin -o $(@) endif $(strip) $(strip-all) $(@) From 85ce7696ca78c532a33adc657c561c416b5d9e52 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Mon, 21 Jan 2013 18:19:55 +0200 Subject: [PATCH 053/106] java.lang.Math.log() and java.lang.Math.tan() --- classpath/java-lang.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index 865f3c3fb4..a671a53d1d 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -785,6 +785,12 @@ Java_java_lang_Math_cos(JNIEnv*, jclass, jdouble val) return cos(val); } +extern "C" JNIEXPORT jdouble JNICALL +Java_java_lang_Math_tan(JNIEnv*, jclass, jdouble val) +{ + return tan(val); +} + extern "C" JNIEXPORT jdouble JNICALL Java_java_lang_Math_sqrt(JNIEnv*, jclass, jdouble val) { @@ -797,6 +803,12 @@ Java_java_lang_Math_pow(JNIEnv*, jclass, jdouble val, jdouble exp) return pow(val, exp); } +extern "C" JNIEXPORT jdouble JNICALL +Java_java_lang_Math_log(JNIEnv*, jclass, jdouble val) +{ + return log(val); +} + extern "C" JNIEXPORT jdouble JNICALL Java_java_lang_Math_floor(JNIEnv*, jclass, jdouble val) { From d6aff87ef967fe4dd43ece7e159aab1508de3e1b Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 21 Jan 2013 22:43:29 +0100 Subject: [PATCH 054/106] Add java lang math methods --- classpath/java-lang.cpp | 38 +++++++++++++++++++++++++ classpath/java/io/RandomAccessFile.java | 6 ++++ classpath/java/lang/Math.java | 6 ++++ 3 files changed, 50 insertions(+) diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index a671a53d1d..6a33a7b7c1 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -791,6 +791,44 @@ Java_java_lang_Math_tan(JNIEnv*, jclass, jdouble val) return tan(val); } +extern "C" JNIEXPORT jdouble JNICALL +Java_java_lang_Math_asin(JNIEnv*, jclass, jdouble val) +{ + return asin(val); +} + +extern "C" JNIEXPORT jdouble JNICALL +Java_java_lang_Math_acos(JNIEnv*, jclass, jdouble val) +{ + return acos(val); +} + +extern "C" JNIEXPORT jdouble JNICALL +Java_java_lang_Math_atan(JNIEnv*, jclass, jdouble val) +{ + return atan(val); +} + + +extern "C" JNIEXPORT jdouble JNICALL +Java_java_lang_Math_sinh(JNIEnv*, jclass, jdouble val) +{ + return sinh(val); +} + +extern "C" JNIEXPORT jdouble JNICALL +Java_java_lang_Math_cosh(JNIEnv*, jclass, jdouble val) +{ + return cosh(val); +} + +extern "C" JNIEXPORT jdouble JNICALL +Java_java_lang_Math_tanh(JNIEnv*, jclass, jdouble val) +{ + return tanh(val); +} + + extern "C" JNIEXPORT jdouble JNICALL Java_java_lang_Math_sqrt(JNIEnv*, jclass, jdouble val) { diff --git a/classpath/java/io/RandomAccessFile.java b/classpath/java/io/RandomAccessFile.java index b6e88dd00e..6ed7eeaceb 100644 --- a/classpath/java/io/RandomAccessFile.java +++ b/classpath/java/io/RandomAccessFile.java @@ -56,6 +56,12 @@ public class RandomAccessFile { this.position = position; } + public int skipBytes(int count) throws IOException { + if (position + count > length()) throw new IOException(); + this.position = position + count; + return count; + } + public void readFully(byte[] buffer, int offset, int length) throws IOException { diff --git a/classpath/java/lang/Math.java b/classpath/java/lang/Math.java index 44eea9db17..5f4933244d 100644 --- a/classpath/java/lang/Math.java +++ b/classpath/java/lang/Math.java @@ -93,6 +93,12 @@ public final class Math { public static native double tan(double v); + public static native double cosh(double v); + + public static native double sinh(double v); + + public static native double tanh(double v); + public static native double acos(double v); public static native double asin(double v); From f1b2b3f78d3e9b2ae48990fb41f65205276a0a20 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Tue, 22 Jan 2013 21:10:16 +0200 Subject: [PATCH 055/106] RandomAccessFile --- classpath/java-io.cpp | 153 ++++++------------------ classpath/java/io/RandomAccessFile.java | 73 ++++++++--- 2 files changed, 90 insertions(+), 136 deletions(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index 86020f57c8..b016c5c17a 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -155,69 +155,9 @@ doWrite(JNIEnv* e, jint fd, const jbyte* data, jint length) } } + #ifdef PLATFORM_WINDOWS -class Mapping { - public: - Mapping(uint8_t* start, size_t length, HANDLE mapping, HANDLE file): - start(start), - length(length), - mapping(mapping), - file(file) - { } - - uint8_t* start; - size_t length; - HANDLE mapping; - HANDLE file; -}; - -inline Mapping* -map(JNIEnv* e, string_t path) -{ - Mapping* result = 0; - HANDLE file = CreateFileW(path, FILE_READ_DATA, - FILE_SHARE_READ | FILE_SHARE_WRITE, 0, - OPEN_EXISTING, 0, 0); - if (file != INVALID_HANDLE_VALUE) { - unsigned size = GetFileSize(file, 0); - if (size != INVALID_FILE_SIZE) { - HANDLE mapping = CreateFileMapping(file, 0, PAGE_READONLY, 0, size, 0); - if (mapping) { - void* data = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0); - if (data) { - void* p = allocate(e, sizeof(Mapping)); - if (not e->ExceptionCheck()) { - result = new (p) - Mapping(static_cast(data), size, file, mapping); - } - } - - if (result == 0) { - CloseHandle(mapping); - } - } - } - - if (result == 0) { - CloseHandle(file); - } - } - if (result == 0 and not e->ExceptionCheck()) { - throwNew(e, "java/io/IOException", "%d", GetLastError()); - } - return result; -} - -inline void -unmap(JNIEnv*, Mapping* mapping) -{ - UnmapViewOfFile(mapping->start); - CloseHandle(mapping->mapping); - CloseHandle(mapping->file); - free(mapping); -} - class Directory { public: Directory(): handle(0), findNext(false) { } @@ -250,51 +190,9 @@ class Directory { #else // not PLATFORM_WINDOWS -class Mapping { - public: - Mapping(uint8_t* start, size_t length): - start(start), - length(length) - { } - - uint8_t* start; - size_t length; -}; - -inline Mapping* -map(JNIEnv* e, string_t path) -{ - Mapping* result = 0; - int fd = open(path, O_RDONLY); - if (fd != -1) { - struct stat s; - int r = fstat(fd, &s); - if (r != -1) { - void* data = mmap(0, s.st_size, PROT_READ, MAP_PRIVATE, fd, 0); - if (data) { - void* p = allocate(e, sizeof(Mapping)); - if (not e->ExceptionCheck()) { - result = new (p) Mapping(static_cast(data), s.st_size); - } - } - } - close(fd); - } - if (result == 0 and not e->ExceptionCheck()) { - throwNewErrno(e, "java/io/IOException"); - } - return result; -} - -inline void -unmap(JNIEnv*, Mapping* mapping) -{ - munmap(mapping->start, mapping->length); - free(mapping); -} - #endif // not PLATFORM_WINDOWS + } // namespace inline string_t getChars(JNIEnv* e, jstring path) { @@ -785,35 +683,54 @@ Java_java_io_RandomAccessFile_open(JNIEnv* e, jclass, jstring path, { string_t chars = getChars(e, path); if (chars) { - Mapping* mapping = map(e, chars); + int fd = ::open((const char*)chars, O_RDONLY); + releaseChars(e, path, chars); + if (fd == -1) { + throwNewErrno(e, "java/io/IOException"); + return; + } + struct ::stat fileStats; + if(::fstat(fd, &fileStats) == -1) { + ::close(fd); + throwNewErrno(e, "java/io/IOException"); + return; + } - jlong peer = reinterpret_cast(mapping); + jlong peer = fd; e->SetLongArrayRegion(result, 0, 1, &peer); - jlong length = (mapping ? mapping->length : 0); + jlong length = fileStats.st_size; e->SetLongArrayRegion(result, 1, 1, &length); - - releaseChars(e, path, chars); } } -extern "C" JNIEXPORT void JNICALL -Java_java_io_RandomAccessFile_copy(JNIEnv* e, jclass, jlong peer, +extern "C" JNIEXPORT jint JNICALL +Java_java_io_RandomAccessFile_readBytes(JNIEnv* e, jclass, jlong peer, jlong position, jbyteArray buffer, int offset, int length) { + int fd = (int)peer; + if(::lseek(fd, position, SEEK_SET) == -1) { + throwNewErrno(e, "java/io/IOException"); + return -1; + } + uint8_t* dst = reinterpret_cast (e->GetPrimitiveArrayCritical(buffer, 0)); - - memcpy(dst + offset, - reinterpret_cast(peer)->start + position, - length); - + ssize_t bytesRead = ::read(fd, dst + offset, length); e->ReleasePrimitiveArrayCritical(buffer, dst, 0); + + if(bytesRead == -1) { + throwNewErrno(e, "java/io/IOException"); + return -1; + } + + return (jint)bytesRead; } extern "C" JNIEXPORT void JNICALL -Java_java_io_RandomAccessFile_close(JNIEnv* e, jclass, jlong peer) +Java_java_io_RandomAccessFile_close(JNIEnv*/* e*/, jclass, jlong peer) { - unmap(e, reinterpret_cast(peer)); + int fd = (int)peer; + ::close(fd); } diff --git a/classpath/java/io/RandomAccessFile.java b/classpath/java/io/RandomAccessFile.java index 6ed7eeaceb..18bacb99f3 100644 --- a/classpath/java/io/RandomAccessFile.java +++ b/classpath/java/io/RandomAccessFile.java @@ -10,6 +10,8 @@ package java.io; +import java.lang.IllegalArgumentException; + public class RandomAccessFile { private long peer; private File file; @@ -61,27 +63,62 @@ public class RandomAccessFile { this.position = position + count; return count; } - - public void readFully(byte[] buffer, int offset, int length) - throws IOException - { - if (peer == 0) throw new IOException(); - - if (length == 0) return; - - if (position + length > this.length) { - if (position + length > length()) throw new EOFException(); - } - - if (offset < 0 || offset + length > buffer.length) + + public int read(byte b[], int off, int len) throws IOException { + if(b == null) + throw new IllegalArgumentException(); + if (peer == 0) + throw new IOException(); + if(len == 0) + return 0; + if (position + len > this.length) + throw new EOFException(); + if (off < 0 || off + len > b.length) throw new ArrayIndexOutOfBoundsException(); - - copy(peer, position, buffer, offset, length); - - position += length; + int bytesRead = readBytes(peer, position, b, off, len); + position += bytesRead; + return bytesRead; + } + + public int read(byte b[]) throws IOException { + if(b == null) + throw new IllegalArgumentException(); + if (peer == 0) + throw new IOException(); + if(b.length == 0) + return 0; + if (position + b.length > this.length) + throw new EOFException(); + int bytesRead = readBytes(peer, position, b, 0, b.length); + position += bytesRead; + return bytesRead; } - private static native void copy(long peer, long position, byte[] buffer, + public void readFully(byte b[], int off, int len) throws IOException { + if(b == null) + throw new IllegalArgumentException(); + if (peer == 0) + throw new IOException(); + if(len == 0) + return; + if (position + len > this.length) + throw new EOFException(); + if (off < 0 || off + len > b.length) + throw new ArrayIndexOutOfBoundsException(); + int n = 0; + do { + int count = readBytes(peer, position, b, off + n, len - n); + if (count < 0) + throw new EOFException(); + n += count; + } while (n < len); + } + + public void readFully(byte b[]) throws IOException { + readFully(b, 0, b.length); + } + + private static native int readBytes(long peer, long position, byte[] buffer, int offset, int length); public void close() throws IOException { From c8ca83836a906eee2aa59c8694dd5e3757cc0555 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 22 Jan 2013 20:25:37 +0100 Subject: [PATCH 056/106] Fix RAF --- classpath/java/io/RandomAccessFile.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/classpath/java/io/RandomAccessFile.java b/classpath/java/io/RandomAccessFile.java index 18bacb99f3..da9a8356b6 100644 --- a/classpath/java/io/RandomAccessFile.java +++ b/classpath/java/io/RandomAccessFile.java @@ -108,7 +108,8 @@ public class RandomAccessFile { int n = 0; do { int count = readBytes(peer, position, b, off + n, len - n); - if (count < 0) + position += count; + if (count == 0) throw new EOFException(); n += count; } while (n < len); From 3a42db9f6f59a4b73eae16d6a620d8716b4cbe17 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 24 Jan 2013 00:55:23 +0100 Subject: [PATCH 057/106] Add android platform --- classpath/java-lang.cpp | 2 ++ makefile | 15 +++++++++++++++ src/posix.cpp | 15 +++++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index 6a33a7b7c1..4cafd5e6cc 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -54,7 +54,9 @@ # include "signal.h" # include "sys/time.h" # include "sys/types.h" +# ifndef __ANDROID__ # include "sys/sysctl.h" +# endif # include "sys/utsname.h" # include "sys/wait.h" diff --git a/makefile b/makefile index fe83a35381..f6c474c0dc 100755 --- a/makefile +++ b/makefile @@ -353,6 +353,21 @@ ifeq ($(platform),freebsd) "-I$(JAVA_HOME)/include/freebsd" -I$(src) -pthread cflags = $(build-cflags) endif +ifeq ($(platform),android) + asm = arm + pointer-size = 4 + no-psabi = -Wno-psabi + toolchain = $(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86/ + cflags = -std=gnu++0x -I$(ANDROID_NDK)/platforms/android-5/arch-arm/usr/include \ + -I$(toolchain)/lib/gcc/arm-linux-androideabi/4.7/include $(common-cflags) + cflags += -marm $(no-psabi) + + cxx = $(toolchain)/bin/arm-linux-androideabi-g++ + cc = $(toolchain)/bin/arm-linux-androideabi-gcc + ar = $(toolchain)/bin/arm-linux-androideabi-ar + ranlib = $(toolchain)/bin/arm-linux-androideabi-ranlib + strip = $(toolchain)/bin/arm-linux-androideabi-strip +endif ifeq ($(platform),darwin) target-format = macho diff --git a/src/posix.cpp b/src/posix.cpp index da575eb8a4..c033956ad5 100644 --- a/src/posix.cpp +++ b/src/posix.cpp @@ -12,10 +12,21 @@ # define __STDC_CONSTANT_MACROS #endif +#include "sys/types.h" #ifdef __APPLE__ # include "CoreFoundation/CoreFoundation.h" # include "sys/ucontext.h" # undef assert +#elif defined __ANDROID__ +# include /* for sigcontext */ +# include /* for stack_t */ +typedef struct ucontext { + unsigned long uc_flags; + struct ucontext *uc_link; + stack_t uc_stack; + struct sigcontext uc_mcontext; + unsigned long uc_sigmask; +} ucontext_t; #else # if defined __FreeBSD__ # include "limits.h" @@ -24,7 +35,7 @@ #endif #include "sys/mman.h" -#include "sys/types.h" + #include "sys/stat.h" #include "sys/time.h" #include "time.h" @@ -37,10 +48,10 @@ #include "stdint.h" #include "dirent.h" #include "sched.h" - #include "arch.h" #include "system.h" + #define ACQUIRE(x) MutexResource MAKE_NAME(mutexResource_) (x) using namespace vm; From b1990ba55f4af59a51802ba869dc82427638e97a Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 24 Jan 2013 16:17:52 +0200 Subject: [PATCH 058/106] Android toolchain --- makefile | 41 +++++++++++++++++++++++++++++++++-------- src/arm.h | 4 ++++ src/posix.cpp | 16 ++++++++-------- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/makefile b/makefile index f6c474c0dc..ece9a050c4 100755 --- a/makefile +++ b/makefile @@ -357,13 +357,34 @@ ifeq ($(platform),android) asm = arm pointer-size = 4 no-psabi = -Wno-psabi - toolchain = $(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86/ - cflags = -std=gnu++0x -I$(ANDROID_NDK)/platforms/android-5/arch-arm/usr/include \ - -I$(toolchain)/lib/gcc/arm-linux-androideabi/4.7/include $(common-cflags) - cflags += -marm $(no-psabi) + use-lto = false + ifeq ($(build-platform),cygwin) + ndk = "$$(cygpath -u "$(ANDROID_NDK)")" + else + ndk = $(ANDROID_NDK) + endif + + build-cflags = $(common-cflags) -I$(src) + ifeq ($(subst cygwin,windows,$(subst mingw32,windows,$(build-platform))),windows) + toolchain-host-platform = $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform))) + build-system = windows + build-cxx = i686-w64-mingw32-g++ + build-cc = i686-w64-mingw32-gcc + build-lflags = -lz -lpthread + sysroot = "$$(cygpath -w "$(ndk)/platforms/android-5/arch-arm")" + build-cflags += "-I$(JAVA_HOME)/include/win32" + else + toolchain-host-platform = $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform)))-$(build-arch) + sysroot = $(ndk)/platforms/android-5/arch-arm + build-cflags += "-I$(JAVA_HOME)/include/linux" + endif + toolchain = $(ndk)/toolchains/arm-linux-androideabi-4.7/prebuilt/$(toolchain-host-platform) + cflags = "-I$(sysroot)/usr/include" "-I$(JAVA_HOME)/include/linux" $(common-cflags) "-I$(src)" -std=c++11 -marm $(no-psabi) + lflags = $(common-lflags) -ldl + use-lto = false - cxx = $(toolchain)/bin/arm-linux-androideabi-g++ - cc = $(toolchain)/bin/arm-linux-androideabi-gcc + cxx = $(toolchain)/bin/arm-linux-androideabi-g++ --sysroot="$(sysroot)" + cc = $(toolchain)/bin/arm-linux-androideabi-gcc --sysroot="$(sysroot)" ar = $(toolchain)/bin/arm-linux-androideabi-ar ranlib = $(toolchain)/bin/arm-linux-androideabi-ranlib strip = $(toolchain)/bin/arm-linux-androideabi-strip @@ -540,7 +561,9 @@ ifeq ($(mode),fast) else optimization-cflags = -O3 -g3 -DNDEBUG endif - use-lto = true + ifeq ($(use-lto),) + use-lto = true + endif endif ifeq ($(mode),small) ifeq ($(use-clang),true) @@ -548,7 +571,9 @@ ifeq ($(mode),small) else optimization-cflags = -Os -g3 -DNDEBUG endif - use-lto = true + ifeq ($(use-lto),) + use-lto = true + endif endif ifeq ($(use-lto),true) diff --git a/src/arm.h b/src/arm.h index 15299ec762..7e7a4d61dd 100644 --- a/src/arm.h +++ b/src/arm.h @@ -98,6 +98,10 @@ loadMemoryBarrier() memoryBarrier(); } +#if defined(__ANDROID__) +// http://code.google.com/p/android/issues/detail?id=1803 +extern "C" void __clear_cache (void *beg __attribute__((__unused__)), void *end __attribute__((__unused__))); +#endif inline void syncInstructionCache(const void* start, unsigned size) { diff --git a/src/posix.cpp b/src/posix.cpp index c033956ad5..95c4286b60 100644 --- a/src/posix.cpp +++ b/src/posix.cpp @@ -17,16 +17,16 @@ # include "CoreFoundation/CoreFoundation.h" # include "sys/ucontext.h" # undef assert -#elif defined __ANDROID__ +#elif defined(__ANDROID__) # include /* for sigcontext */ # include /* for stack_t */ -typedef struct ucontext { - unsigned long uc_flags; - struct ucontext *uc_link; - stack_t uc_stack; - struct sigcontext uc_mcontext; - unsigned long uc_sigmask; -} ucontext_t; + typedef struct ucontext { + unsigned long uc_flags; + struct ucontext *uc_link; + stack_t uc_stack; + struct sigcontext uc_mcontext; + unsigned long uc_sigmask; + } ucontext_t; #else # if defined __FreeBSD__ # include "limits.h" From 1f77d150401fd5fa6aad41b198a55133b84cd995 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 24 Jan 2013 06:39:14 -0800 Subject: [PATCH 059/106] Path fix --- makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/makefile b/makefile index ece9a050c4..5333c7ebb7 100755 --- a/makefile +++ b/makefile @@ -365,26 +365,27 @@ ifeq ($(platform),android) endif build-cflags = $(common-cflags) -I$(src) + build-lflags = -lz -lpthread ifeq ($(subst cygwin,windows,$(subst mingw32,windows,$(build-platform))),windows) toolchain-host-platform = $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform))) build-system = windows build-cxx = i686-w64-mingw32-g++ build-cc = i686-w64-mingw32-gcc - build-lflags = -lz -lpthread sysroot = "$$(cygpath -w "$(ndk)/platforms/android-5/arch-arm")" build-cflags += "-I$(JAVA_HOME)/include/win32" else - toolchain-host-platform = $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform)))-$(build-arch) + toolchain-host-platform = $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform)))-* sysroot = $(ndk)/platforms/android-5/arch-arm build-cflags += "-I$(JAVA_HOME)/include/linux" endif toolchain = $(ndk)/toolchains/arm-linux-androideabi-4.7/prebuilt/$(toolchain-host-platform) cflags = "-I$(sysroot)/usr/include" "-I$(JAVA_HOME)/include/linux" $(common-cflags) "-I$(src)" -std=c++11 -marm $(no-psabi) - lflags = $(common-lflags) -ldl + lflags = "-L$(sysroot)/usr/lib" $(common-lflags) -ldl use-lto = false cxx = $(toolchain)/bin/arm-linux-androideabi-g++ --sysroot="$(sysroot)" cc = $(toolchain)/bin/arm-linux-androideabi-gcc --sysroot="$(sysroot)" + as = $(toolchain)/bin/arm-linux-androideabi-as --sysroot="$(sysroot)" ar = $(toolchain)/bin/arm-linux-androideabi-ar ranlib = $(toolchain)/bin/arm-linux-androideabi-ranlib strip = $(toolchain)/bin/arm-linux-androideabi-strip From c368a8b74aee3b0a6c84fc1d3c635b34cdc3a241 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 25 Jan 2013 23:36:13 +0100 Subject: [PATCH 060/106] Fix android makefile --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index 5333c7ebb7..5d8aa9f6e6 100755 --- a/makefile +++ b/makefile @@ -365,7 +365,7 @@ ifeq ($(platform),android) endif build-cflags = $(common-cflags) -I$(src) - build-lflags = -lz -lpthread + #build-lflags = -lz -lpthread -ldl ifeq ($(subst cygwin,windows,$(subst mingw32,windows,$(build-platform))),windows) toolchain-host-platform = $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform))) build-system = windows From 51e8a00f5879db30176c9953b34a33fa430e24a7 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 26 Jan 2013 20:51:46 +0100 Subject: [PATCH 061/106] Add android redirect to logcat --- classpath/java-io.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index b016c5c17a..1e9acdef76 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -644,6 +644,9 @@ Java_java_io_FileOutputStream_open(JNIEnv* e, jclass, jstring path, jboolean app return -1; } } +#ifdef __ANDROID__ +#include +#endif extern "C" JNIEXPORT void JNICALL Java_java_io_FileOutputStream_write__II(JNIEnv* e, jclass, jint fd, jint c) @@ -657,13 +660,18 @@ Java_java_io_FileOutputStream_write__I_3BII (JNIEnv* e, jclass, jint fd, jbyteArray b, jint offset, jint length) { jbyte* data = static_cast(malloc(length)); + if (data == 0) { throwNew(e, "java/lang/OutOfMemoryError", 0); return; } e->GetByteArrayRegion(b, offset, length, data); - + #ifdef __ANDROID__ + if(fd == 1) { + __android_log_print(ANDROID_LOG_WARN, "net.osmand:native", "%.*s",length, data); + } + #endif if (not e->ExceptionCheck()) { doWrite(e, fd, data, length); } From cc237b94c4222447b0a07c436d5c296373047425 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 26 Jan 2013 21:33:43 +0100 Subject: [PATCH 062/106] Fix proguard warnings Conflicts: TODO.if.merge --- vm.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/vm.pro b/vm.pro index 4cdb1654ee..8d1ab22177 100644 --- a/vm.pro +++ b/vm.pro @@ -71,6 +71,7 @@ -keep public class java.io.IOException -keep public class java.io.FileNotFoundException -keep public class java.net.SocketException +-keep public class java.util.Locale # ClassLoader.getSystemClassloader() depends on the existence of this class: From 2f2cac556c603d13283f38d0fc59fe91b8a21e2d Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Mon, 28 Jan 2013 17:20:52 +0200 Subject: [PATCH 063/106] Windows Phone 8 / Windows RT initial support Conflicts: makefile --- classpath/java-io.cpp | 39 +++- classpath/java-lang.cpp | 71 ++++++- makefile | 401 ++++++++++++++++++++++++++++++-------- src/arm.h | 28 ++- src/arm.masm | 77 ++++++++ src/binaryToObject/pe.cpp | 33 ++-- src/bootimage.cpp | 44 +++-- src/common.h | 8 +- src/interpret.cpp | 19 +- src/machine.h | 3 + src/system.h | 6 + src/windows.cpp | 143 +++++++++++++- src/x86.masm | 166 ++++++++++++++++ 13 files changed, 912 insertions(+), 126 deletions(-) create mode 100644 src/arm.masm create mode 100644 src/x86.masm diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index 1e9acdef76..db9882e051 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -83,6 +83,16 @@ typedef char char_t; #endif // not PLATFORM_WINDOWS +#ifndef WINAPI_FAMILY +# ifndef WINAPI_PARTITION_DESKTOP +# define WINAPI_PARTITION_DESKTOP 1 +# endif + +# ifndef WINAPI_FAMILY_PARTITION +# define WINAPI_FAMILY_PARTITION(x) (x) +# endif +#endif // WINAPI_FAMILY + inline void* operator new(size_t, void* p) throw() { return p; } typedef const char_t* string_t; @@ -214,6 +224,7 @@ extern "C" JNIEXPORT jstring JNICALL Java_java_io_File_toAbsolutePath(JNIEnv* e UNUSED, jclass, jstring path) { #ifdef PLATFORM_WINDOWS +# if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) string_t chars = getChars(e, path); if (chars) { const unsigned BufferSize = MAX_PATH; @@ -228,6 +239,11 @@ Java_java_io_File_toAbsolutePath(JNIEnv* e UNUSED, jclass, jstring path) } return path; +# else + // WinRT has no concept of full paths + throwNewErrno(e, "java/io/IOException"); + return path; +# endif #else jstring result = path; string_t chars = getChars(e, path); @@ -256,11 +272,24 @@ Java_java_io_File_length(JNIEnv* e, jclass, jstring path) LARGE_INTEGER fileSize; string_t chars = getChars(e, path); + #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) HANDLE file = CreateFileW (chars, FILE_READ_DATA, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); + #else + HANDLE file = CreateFile2 + (chars, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr); + #endif releaseChars(e, path, chars); if (file != INVALID_HANDLE_VALUE) + { + #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) GetFileSizeEx(file, &fileSize); + #else + FILE_STANDARD_INFO info; + if(GetFileInformationByHandleEx(file, FileStandardInfo, &info, sizeof(info))) + fileSize = info.EndOfFile; + #endif + } else return 0; CloseHandle(file); return static_cast(fileSize.QuadPart); @@ -496,7 +525,11 @@ Java_java_io_File_openDir(JNIEnv* e, jclass, jstring path) releaseChars(e, path, chars); Directory* d = new (malloc(sizeof(Directory))) Directory; + #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) d->handle = FindFirstFileW(RUNTIME_ARRAY_BODY(buffer), &(d->data)); + #else + d->handle = FindFirstFileExW(RUNTIME_ARRAY_BODY(buffer), FindExInfoStandard, &(d->data), FindExSearchNameMatch, NULL, 0); + #endif if (d->handle == INVALID_HANDLE_VALUE) { d->dispose(); d = 0; @@ -725,7 +758,11 @@ Java_java_io_RandomAccessFile_readBytes(JNIEnv* e, jclass, jlong peer, uint8_t* dst = reinterpret_cast (e->GetPrimitiveArrayCritical(buffer, 0)); +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) ssize_t bytesRead = ::read(fd, dst + offset, length); +#else + auto bytesRead = ::read(fd, dst + offset, length); +#endif e->ReleasePrimitiveArrayCritical(buffer, dst, 0); if(bytesRead == -1) { @@ -737,7 +774,7 @@ Java_java_io_RandomAccessFile_readBytes(JNIEnv* e, jclass, jlong peer, } extern "C" JNIEXPORT void JNICALL -Java_java_io_RandomAccessFile_close(JNIEnv*/* e*/, jclass, jlong peer) +Java_java_io_RandomAccessFile_close(JNIEnv* /* e*/, jclass, jlong peer) { int fd = (int)peer; ::close(fd); diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index 4cafd5e6cc..0414216194 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -62,6 +62,16 @@ #endif // not PLATFORM_WINDOWS +#ifndef WINAPI_FAMILY +# ifndef WINAPI_PARTITION_DESKTOP +# define WINAPI_PARTITION_DESKTOP 1 +# endif + +# ifndef WINAPI_FAMILY_PARTITION +# define WINAPI_FAMILY_PARTITION(x) (x) +# endif +#endif // WINAPI_FAMILY + namespace { #ifdef PLATFORM_WINDOWS char* getErrorStr(DWORD err){ @@ -70,7 +80,8 @@ namespace { snprintf(errStr, 9, "%d", (int) err); return errStr; - // The better way to do this, if I could figure out how to convert LPTSTR to char* + //TODO: + // The better way to do this, if I could figure out how to convert LPTSTR to char* //char* errStr; //LPTSTR s; //if(FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | @@ -83,6 +94,7 @@ namespace { //return errStr; } +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) void makePipe(JNIEnv* e, HANDLE p[2]) { SECURITY_ATTRIBUTES sa; @@ -95,6 +107,7 @@ namespace { throwNew(e, "java/io/IOException", getErrorStr(GetLastError())); } } +#endif int descriptor(JNIEnv* e, HANDLE h) { @@ -196,7 +209,7 @@ extern "C" JNIEXPORT void JNICALL Java_java_lang_Runtime_exec(JNIEnv* e, jclass, jobjectArray command, jlongArray process) { - +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) int size = 0; for (int i = 0; i < e->GetArrayLength(command); ++i){ jstring element = (jstring) e->GetObjectArrayElement(command, i); @@ -267,11 +280,15 @@ Java_java_lang_Runtime_exec(JNIEnv* e, jclass, e->SetLongArrayRegion(process, 0, 1, &pid); jlong tid = reinterpret_cast(pi.hThread); e->SetLongArrayRegion(process, 1, 1, &tid); +#else + throwNew(e, "java/io/Exception", strdup("Not supported on WinRT/WinPhone8")); +#endif } extern "C" JNIEXPORT jint JNICALL Java_java_lang_Runtime_waitFor(JNIEnv* e, jclass, jlong pid, jlong tid) { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) DWORD exitCode; WaitForSingleObject(reinterpret_cast(pid), INFINITE); BOOL success = GetExitCodeProcess(reinterpret_cast(pid), &exitCode); @@ -283,14 +300,23 @@ Java_java_lang_Runtime_waitFor(JNIEnv* e, jclass, jlong pid, jlong tid) CloseHandle(reinterpret_cast(tid)); return exitCode; +#else + throwNew(e, "java/io/Exception", strdup("Not supported on WinRT/WinPhone8")); + return -1; +#endif } extern "C" JNIEXPORT void JNICALL -Java_java_lang_Runtime_kill(JNIEnv*, jclass, jlong pid) { +Java_java_lang_Runtime_kill(JNIEnv* e UNUSED, jclass, jlong pid) { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) TerminateProcess(reinterpret_cast(pid), 1); +#else + throwNew(e, "java/io/Exception", strdup("Not supported on WinRT/WinPhone8")); +#endif } Locale getLocale() { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) const char* lang = ""; const char* reg = ""; unsigned langid = GetUserDefaultUILanguage(); @@ -362,8 +388,11 @@ Locale getLocale() { default: lang = "en"; } - Locale locale(lang, reg); - return locale; + return Locale(lang, reg); +#else + //TODO: CultureInfo.CurrentCulture + return Locale("en", "US"); +#endif } #else extern "C" JNIEXPORT void JNICALL @@ -531,8 +560,15 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, } else if (strcmp(chars, "file.separator") == 0) { r = e->NewStringUTF("\\"); } else if (strcmp(chars, "os.name") == 0) { +# if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) r = e->NewStringUTF("Windows"); +# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE) + r = e->NewStringUTF("Windows Phone"); +# else + r = e->NewStringUTF("Windows RT"); +# endif } else if (strcmp(chars, "os.version") == 0) { +# if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) unsigned size = 32; RUNTIME_ARRAY(char, buffer, size); OSVERSIONINFO OSversion; @@ -540,6 +576,10 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, ::GetVersionEx(&OSversion); snprintf(RUNTIME_ARRAY_BODY(buffer), size, "%i.%i", (int)OSversion.dwMajorVersion, (int)OSversion.dwMinorVersion); r = e->NewStringUTF(RUNTIME_ARRAY_BODY(buffer)); +# else + // Currently there is no alternative on WinRT/WP8 + r = e->NewStringUTF("8.0"); +# endif } else if (strcmp(chars, "os.arch") == 0) { #ifdef ARCH_x86_32 r = e->NewStringUTF("x86"); @@ -551,15 +591,28 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, r = e->NewStringUTF("arm"); #endif } else if (strcmp(chars, "java.io.tmpdir") == 0) { +# if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) TCHAR buffer[MAX_PATH]; GetTempPath(MAX_PATH, buffer); r = e->NewStringUTF(buffer); +# else + //TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ + //Windows.Storage.ApplicationData.Current.TemporaryFolder + r = 0; +# endif } else if (strcmp(chars, "user.dir") == 0) { +# if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) TCHAR buffer[MAX_PATH]; GetCurrentDirectory(MAX_PATH, buffer); r = e->NewStringUTF(buffer); +# else + //TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ + //Windows.ApplicationModel.Package.Current.InstalledLocation + r = 0; +# endif } else if (strcmp(chars, "user.home") == 0) { # ifdef _MSC_VER +# if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) WCHAR buffer[MAX_PATH]; size_t needed; if (_wgetenv_s(&needed, buffer, MAX_PATH, L"USERPROFILE") == 0) { @@ -567,6 +620,11 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, } else { r = 0; } +# else + //TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ + //Windows.Storage.KnownFolders.DocumentsLibrary; + r = 0; +# endif # else LPWSTR home = _wgetenv(L"USERPROFILE"); r = e->NewString(reinterpret_cast(home), lstrlenW(home)); @@ -654,6 +712,9 @@ namespace { #elif defined __APPLE__ # include # define environ (*_NSGetEnviron()) +#elif defined(WINAPI_FAMILY) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +// WinRT/WP8 does not provide alternative for environment variables +char* environ[] = { 0 }; #else extern char** environ; #endif diff --git a/makefile b/makefile index 5d8aa9f6e6..5ca549e988 100755 --- a/makefile +++ b/makefile @@ -51,7 +51,7 @@ ifeq ($(continuations),true) endif root := $(shell (cd .. && pwd)) -build = build/$(platform)-$(arch)$(options) +build = $(build-prefix)build/$(platform)-$(arch)$(options) classpath-build = $(build)/classpath test-build = $(build)/test src = src @@ -59,6 +59,8 @@ classpath-src = classpath test = test win32 ?= $(root)/win32 win64 ?= $(root)/win64 +winrt ?= $(root)/winrt +wp8 ?= $(root)/wp8 classpath = avian @@ -183,6 +185,18 @@ strip-all = --strip-all rdynamic = -rdynamic +cflags_debug = -O0 -g3 +cflags_debug_fast = -O0 -g3 +cflags_stress = -O0 -g3 +cflags_stress_major = -O0 -g3 +ifeq ($(use-clang),true) + cflags_fast = -O4 -g3 + cflags_small = -Oz -g3 +else + cflags_fast = -O3 -g3 + cflags_small = -Os -g3 +endif + # note that we suppress the non-virtual-dtor warning because we never # use the delete operator, which means we don't need virtual # destructors: @@ -198,7 +212,7 @@ common-cflags = $(warnings) -fno-rtti -fno-exceptions -I$(classpath-src) \ -DUSE_ATOMIC_OPERATIONS -DAVIAN_JAVA_HOME=\"$(javahome)\" \ -DAVIAN_EMBED_PREFIX=\"$(embed-prefix)\" $(target-cflags) -asmflags = $(target-cflags) +asmflags = $(target-cflags) -I$(src) ifneq (,$(filter i386 x86_64,$(arch))) ifeq ($(use-frame-pointer),true) @@ -237,6 +251,18 @@ pointer-size = 8 so-prefix = lib so-suffix = .so +static-prefix = lib +static-suffix = .a + +output = -o $(1) +asm-output = -o $(1) +asm-input = -c $(1) +asm-format = S +as = $(cc) +ld = $(cxx) +build-ld = $(build-cc) + +static = -static shared = -shared no-error = -Wno-error @@ -244,6 +270,8 @@ no-error = -Wno-error openjdk-extra-cflags = -fvisibility=hidden bootimage-cflags = -DTARGET_BYTES_PER_WORD=$(pointer-size) +bootimage-symbols = _binary_bootimage_bin_start:_binary_bootimage_bin_end +codeimage-symbols = _binary_codeimage_bin_start:_binary_codeimage_bin_end developer-dir := $(shell if test -d /Developer; then echo /Developer; \ else echo /Applications/Xcode.app/Contents/Developer; fi) @@ -354,41 +382,68 @@ ifeq ($(platform),freebsd) cflags = $(build-cflags) endif ifeq ($(platform),android) - asm = arm - pointer-size = 4 - no-psabi = -Wno-psabi - use-lto = false - ifeq ($(build-platform),cygwin) + ifeq ($(build-platform),cygwin) ndk = "$$(cygpath -u "$(ANDROID_NDK)")" else ndk = $(ANDROID_NDK) endif + ifeq ($(android-version),) + android-version = 5 + endif + + ifeq ($(android-toolchain),) + android-toolchain = 4.7 + endif + + ifeq ($(arch),arm) + android-toolchain-name = arm-linux-androideabi + android-toolchain-prefix = arm-linux-androideabi- + endif + ifeq ($(arch),i386) + android-toolchain-name = x86 + android-toolchain-prefix = i686-linux-android- + endif + + ifeq ($(android-arm-arch),) + android-arm-arch = armv5 + endif + + options := $(options)-api$(android-version)-$(android-toolchain)-$(android-arm-arch) + build-cflags = $(common-cflags) -I$(src) - #build-lflags = -lz -lpthread -ldl + build-lflags = -lz -lpthread ifeq ($(subst cygwin,windows,$(subst mingw32,windows,$(build-platform))),windows) toolchain-host-platform = $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform))) build-system = windows build-cxx = i686-w64-mingw32-g++ build-cc = i686-w64-mingw32-gcc - sysroot = "$$(cygpath -w "$(ndk)/platforms/android-5/arch-arm")" + sysroot = "$$(cygpath -w "$(ndk)/platforms/android-$(android-version)/arch-arm")" build-cflags += "-I$(JAVA_HOME)/include/win32" else toolchain-host-platform = $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform)))-* - sysroot = $(ndk)/platforms/android-5/arch-arm + sysroot = $(ndk)/platforms/android-$(android-version)/arch-arm build-cflags += "-I$(JAVA_HOME)/include/linux" + build-lflags += -ldl endif - toolchain = $(ndk)/toolchains/arm-linux-androideabi-4.7/prebuilt/$(toolchain-host-platform) - cflags = "-I$(sysroot)/usr/include" "-I$(JAVA_HOME)/include/linux" $(common-cflags) "-I$(src)" -std=c++11 -marm $(no-psabi) - lflags = "-L$(sysroot)/usr/lib" $(common-lflags) -ldl + toolchain = $(ndk)/toolchains/$(android-toolchain-name)-$(android-toolchain)/prebuilt/$(toolchain-host-platform) + cflags = "-I$(sysroot)/usr/include" "-I$(JAVA_HOME)/include/linux" $(common-cflags) "-I$(src)" -std=c++11 $(no-psabi) + lflags = "-L$(sysroot)/usr/lib" $(common-lflags) -llog + target-format = elf use-lto = false - cxx = $(toolchain)/bin/arm-linux-androideabi-g++ --sysroot="$(sysroot)" - cc = $(toolchain)/bin/arm-linux-androideabi-gcc --sysroot="$(sysroot)" - as = $(toolchain)/bin/arm-linux-androideabi-as --sysroot="$(sysroot)" - ar = $(toolchain)/bin/arm-linux-androideabi-ar - ranlib = $(toolchain)/bin/arm-linux-androideabi-ranlib - strip = $(toolchain)/bin/arm-linux-androideabi-strip + ifeq ($(arch),arm) + cflags += -marm -march=$(android-arm-arch) -ftree-vectorize -ffast-math -mfloat-abi=softfp + endif + ifeq ($(arch),i386) + endif + + cxx = $(toolchain)/bin/$(android-toolchain-prefix)g++ --sysroot="$(sysroot)" + cc = $(toolchain)/bin/$(android-toolchain-prefix)gcc --sysroot="$(sysroot)" + as = $(cxx) + ar = $(toolchain)/bin/$(android-toolchain-prefix)ar + ranlib = $(toolchain)/bin/$(android-toolchain-prefix)ranlib + strip = $(toolchain)/bin/$(android-toolchain-prefix)strip endif ifeq ($(platform),darwin) @@ -475,7 +530,9 @@ ifeq ($(platform),darwin) endif ifeq ($(platform),windows) - target-format = pe + ifeq ($(target-format),) + target-format = pe + endif inc = "$(win32)/include" lib = "$(win32)/lib" @@ -488,7 +545,8 @@ ifeq ($(platform),windows) so-suffix = .dll exe-suffix = .exe - lflags = -L$(lib) $(common-lflags) -lws2_32 -liphlpapi -mwindows -mconsole + lflags = -L$(lib) $(common-lflags) -lws2_32 -liphlpapi -mconsole + bootimage-generator-lflags = -static-libstdc++ -static-libgcc cflags = -I$(inc) $(common-cflags) -DWINVER=0x0500 ifeq (,$(filter mingw32 cygwin,$(build-platform))) @@ -539,39 +597,197 @@ ifeq ($(platform),windows) embed-loader-o = $(build-embed)/embed-loader.o endif +ifeq ($(platform),wp8) + ifeq ($(shell uname -s | grep -i -c WOW64),1) + programFiles = Program Files (x86) + else + programFiles = Program Files + endif + ifeq ($(MSVS_ROOT),) + # Environment variable MSVS_ROOT not found. It should be something like + # "C:\$(programFiles)\Microsoft Visual Studio 11.0" + MSVS_ROOT = C:\$(programFiles)\Microsoft Visual Studio 11.0 + endif + ifeq ($(MSVC_ROOT),) + # Environment variable MSVC_ROOT not found. It should be something like + # "C:\$(programFiles)\Microsoft Visual Studio 11.0\VC" + MSVC_ROOT = $(MSVS_ROOT)\VC + endif + ifeq ($(WP80_SDK),) + # Environment variable WP8_SDK not found. It should be something like + # "C:\Program Files[ (x86)]\Microsoft Visual Studio 11.0\VC\WPSDK\WP80" + # TODO: Lookup in SOFTWARE\Microsoft\Microsoft SDKs\WindowsPhone\v8.0 + WP80_SDK = C:\$(programFiles)\Microsoft Visual Studio 11.0\VC\WPSDK\WP80 + endif + ifeq ($(WP80_KIT),) + # Environment variable WP8_KIT not found. It should be something like + # "c:\Program Files[ (x86)]\Windows Phone Kits\8.0" + # TODO: Lookup in SOFTWARE\Microsoft\Microsoft SDKs\WindowsPhone\v8.0 + WP80_KIT = C:\$(programFiles)\Windows Phone Kits\8.0 + endif + ifeq ($(WIN8_KIT),) + # Environment variable WIN8_KIT not found. It should be something like + # "c:\Program Files[ (x86)]\Windows Kits\8.0" + WIN8_KIT = C:\$(programFiles)\Windows Kits\8.0 + endif + ifeq ($(build-platform),cygwin) + windows-path = cygpath -w + else + windows-path = $(native-path) + endif + windows-java-home := $(shell $(windows-path) "$(JAVA_HOME)") + target-format = pe + ms_cl_compiler = wp8 + use-lto = false + supports_avian_executable = false + process = interpret + ifneq ($(process),compile) + options := -$(process) + endif + bootimage = true + ifeq ($(bootimage),true) + options := $(options)-bootimage + endif + system = windows + build-system = windows + static-prefix = + static-suffix = .lib + so-prefix = + so-suffix = .dll + exe-suffix = .exe + + ifeq ($(arch),arm) + wp8_arch = \x86_arm + vc_arch = \arm + w8kit_arch = arm + deps_arch = ARM + as = "$$(cygpath -u "$(WP80_SDK)\bin\x86_arm\armasm.exe")" + cxx = "$$(cygpath -u "$(WP80_SDK)\bin\x86_arm\cl.exe")" + ld = "$$(cygpath -u "$(WP80_SDK)\bin\x86_arm\link.exe")" + asmflags = -machine ARM -32 + asm-output = -o $(1) + asm-input = $(1) + machine_type = ARM + bootimage-symbols = binary_bootimage_bin_start:binary_bootimage_bin_end + codeimage-symbols = binary_codeimage_bin_start:binary_codeimage_bin_end + endif + ifeq ($(arch),i386) + wp8_arch = + vc_arch = + w8kit_arch = x86 + deps_arch = x86 + as = "$$(cygpath -u "$(WP80_SDK)\bin\ml.exe")" + cxx = "$$(cygpath -u "$(WP80_SDK)\bin\cl.exe")" + ld = "$$(cygpath -u "$(WP80_SDK)\bin\link.exe")" + asmflags += -nologo + asm-output = $(output) + machine_type = X86 + endif + + PATH := $(shell cygpath -u "$(MSVS_ROOT)\Common7\IDE"):$(shell cygpath -u "$(WP80_SDK)\bin$(wp8_arch)"):$(shell cygpath -u "$(WP80_SDK)\bin"):${PATH} + + build-cflags = $(common-cflags) -I$(src) -I$(inc) -mthreads + build-lflags = -lz -lpthread + + cflags = -nologo \ + -I"$(WP80_SDK)\include" -I"$(WP80_KIT)\Include" -I"$(WP80_KIT)\Include\minwin" -I"$(WP80_KIT)\Include\mincore" \ + -DWINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP \ + -DAVIAN_VERSION=\"$(version)\" -D_JNI_IMPLEMENTATION_ \ + -DUSE_ATOMIC_OPERATIONS -DAVIAN_JAVA_HOME=\"$(javahome)\" \ + -DAVIAN_EMBED_PREFIX=\"$(embed-prefix)\" \ + -I"$(shell $(windows-path) "$(wp8)/zlib/upstream")" \ + -Fd$(build)/$(name).pdb -I"$(shell $(windows-path) "$(wp8)/include")" -I$(src) -I$(classpath-src) \ + -I"$(build)" \ + -I"$(windows-java-home)/include" -I"$(windows-java-home)/include/win32" \ + -DTARGET_BYTES_PER_WORD=$(pointer-size) + + common-lflags = $(classpath-lflags) + + arflags = -MACHINE:$(machine_type) + lflags = $(common-lflags) -nologo \ + -MACHINE:$(machine_type) \ + -LIBPATH:"$(WP80_KIT)\lib\$(w8kit_arch)" -LIBPATH:"$(WIN8_KIT)\Lib\win8\um\$(w8kit_arch)" -LIBPATH:"$(MSVC_ROOT)\lib$(vc_arch)" \ + ws2_32.lib \ + "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\zlib.lib")" "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\ThreadEmulation.lib")" + + cc = $(cxx) + asm-format = masm + shared = -dll + ar = "$$(cygpath -u "$(WP80_SDK)\bin\lib.exe")" + arflags += -nologo + ifeq ($(build-platform),cygwin) + build-cxx = i686-w64-mingw32-g++ + build-cc = i686-w64-mingw32-gcc + dlltool = i686-w64-mingw32-dlltool + ranlib = + strip = + endif + output = -Fo$(1) + + cflags_debug = -Od -Zi -MDd + cflags_debug_fast = -Od -Zi -MDd + cflags_stress = -O0 -g3 -MD + cflags_stress_major = -O0 -g3 -MD + cflags_fast = -O2 -Zi -MD + cflags_small = -O1s -Zi -MD + # -GL [whole program optimization] in 'fast' and 'small' breaks compilation for some reason + + ifeq ($(mode),debug) + cflags += + lflags += + endif + ifeq ($(mode),debug-fast) + cflags += -DNDEBUG + lflags += + endif + ifeq ($(mode),stress_major) + cflags += + lflags += + endif + ifeq ($(mode),fast) + cflags += + lflags += + endif + # -LTCG is needed only if -GL is used + ifeq ($(mode),fast) + cflags += -DNDEBUG + lflags += -LTCG + arflags += + endif + ifeq ($(mode),small) + cflags += -DNDEBUG + lflags += -LTCG + arflags += + endif + + strip = : +endif + ifeq ($(mode),debug) - optimization-cflags = -O0 -g3 - converter-cflags += -O0 -g3 + optimization-cflags = $(cflags_debug) + converter-cflags += $(cflags_debug) strip = : endif ifeq ($(mode),debug-fast) - optimization-cflags = -O0 -g3 -DNDEBUG + optimization-cflags = $(cflags_debug_fast) -DNDEBUG strip = : endif ifeq ($(mode),stress) - optimization-cflags = -O0 -g3 -DVM_STRESS + optimization-cflags = $(cflags_stress) -DVM_STRESS strip = : endif ifeq ($(mode),stress-major) - optimization-cflags = -O0 -g3 -DVM_STRESS -DVM_STRESS_MAJOR + optimization-cflags = $(cflags_stress_major) -DVM_STRESS -DVM_STRESS_MAJOR strip = : endif ifeq ($(mode),fast) - ifeq ($(use-clang),true) - optimization-cflags = -O4 -g3 -DNDEBUG - else - optimization-cflags = -O3 -g3 -DNDEBUG - endif + optimization-cflags = $(cflags_fast) -DNDEBUG ifeq ($(use-lto),) use-lto = true endif endif ifeq ($(mode),small) - ifeq ($(use-clang),true) - optimization-cflags = -Oz -g3 -DNDEBUG - else - optimization-cflags = -Os -g3 -DNDEBUG - endif + optimization-cflags = $(cflags_small) -DNDEBUG ifeq ($(use-lto),) use-lto = true endif @@ -596,6 +812,7 @@ endif cflags += $(optimization-cflags) +ifndef ms_cl_compiler ifneq ($(platform),darwin) ifeq ($(arch),i386) # this is necessary to support __sync_bool_compare_and_swap: @@ -603,16 +820,9 @@ ifeq ($(arch),i386) lflags += -march=i586 endif endif - -output = -o $(1) -as := $(cc) -ld := $(cc) -build-ld := $(build-cc) - -static = -static +endif ifdef msvc - static = no-error = windows-path = $(native-path) windows-java-home := $(shell $(windows-path) "$(JAVA_HOME)") @@ -621,6 +831,7 @@ ifdef msvc cc = $(cxx) ld = "$(msvc)/BIN/link.exe" mt = "mt.exe" + manifest-flags = -MANIFEST -MANIFESTFILE:$(@).manifest cflags = -nologo -DAVIAN_VERSION=\"$(version)\" -D_JNI_IMPLEMENTATION_ \ -DUSE_ATOMIC_OPERATIONS -DAVIAN_JAVA_HOME=\"$(javahome)\" \ -DAVIAN_EMBED_PREFIX=\"$(embed-prefix)\" \ @@ -629,7 +840,7 @@ ifdef msvc -I"$(windows-java-home)/include" -I"$(windows-java-home)/include/win32" \ -DTARGET_BYTES_PER_WORD=$(pointer-size) - ifneq ($(lzma),) + ifneq ($(lzma),) cflags += -I$(shell $(windows-path) "$(lzma)") endif @@ -656,9 +867,11 @@ ifdef msvc strip = : endif +build-cflags += -DAVIAN_HOST_TARGET + c-objects = $(foreach x,$(1),$(patsubst $(2)/%.c,$(3)/%.o,$(x))) cpp-objects = $(foreach x,$(1),$(patsubst $(2)/%.cpp,$(3)/%.o,$(x))) -asm-objects = $(foreach x,$(1),$(patsubst $(2)/%.S,$(3)/%-asm.o,$(x))) +asm-objects = $(foreach x,$(1),$(patsubst $(2)/%.$(asm-format),$(3)/%-asm.o,$(x))) java-classes = $(foreach x,$(1),$(patsubst $(2)/%.java,$(3)/%.class,$(x))) generated-code = \ @@ -684,7 +897,7 @@ vm-sources = \ $(src)/jnienv.cpp \ $(src)/process.cpp -vm-asm-sources = $(src)/$(asm).S +vm-asm-sources = $(src)/$(asm).$(asm-format) target-asm = $(asm) @@ -702,8 +915,9 @@ ifeq ($(process),compile) $(src)/compiler.cpp \ $(src)/$(target-asm).cpp - vm-asm-sources += $(src)/compile-$(asm).S + vm-asm-sources += $(src)/compile-$(asm).$(asm-format) endif +cflags += -DAVIAN_PROCESS_$(process) vm-cpp-objects = $(call cpp-objects,$(vm-sources),$(src),$(build)) vm-asm-objects = $(call asm-objects,$(vm-asm-sources),$(src),$(build)) @@ -835,7 +1049,7 @@ converter-objects = $(call cpp-objects,$(converter-sources),$(src),$(build)) converter-tool-objects = $(call cpp-objects,$(converter-tool-sources),$(src),$(build)) converter = $(build)/binaryToObject/binaryToObject -static-library = $(build)/lib$(name).a +static-library = $(build)/$(static-prefix)$(name)${static-suffix} executable = $(build)/$(name)${exe-suffix} dynamic-library = $(build)/$(so-prefix)jvm$(so-suffix) executable-dynamic = $(build)/$(name)-dynamic${exe-suffix} @@ -945,9 +1159,15 @@ test-flags = -Djava.library.path=$(build) -cp $(build)/test test-args = $(test-flags) $(input) .PHONY: build +ifneq ($(supports_avian_executable),false) build: $(static-library) $(executable) $(dynamic-library) $(lzma-loader) \ $(lzma-encoder) $(executable-dynamic) $(classpath-dep) $(test-dep) \ $(test-extra-dep) $(embed) +else +build: $(static-library) $(dynamic-library) $(lzma-loader) \ + $(lzma-encoder) $(classpath-dep) $(test-dep) \ + $(test-extra-dep) $(embed) +endif $(test-dep): $(classpath-dep) @@ -992,7 +1212,7 @@ clean: @echo "removing build" rm -rf build -$(build)/compile-x86-asm.o: $(src)/continuations-x86.S +$(build)/compile-x86-asm.o: $(src)/continuations-x86.$(asm-format) gen-arg = $(shell echo $(1) | sed -e 's:$(build)/type-\(.*\)\.cpp:\1:') $(generated-code): %.cpp: $(src)/types.def $(generator) $(classpath-dep) @@ -1043,7 +1263,7 @@ endef define compile-asm-object @echo "compiling $(@)" @mkdir -p $(dir $(@)) - $(as) -I$(src) $(asmflags) -c $(<) -o $(@) + $(as) $(asmflags) $(call asm-output,$(@)) $(call asm-input,$(<)) endef $(vm-cpp-objects): $(build)/%.o: $(src)/%.cpp $(vm-depends) @@ -1054,10 +1274,12 @@ $(test-cpp-objects): $(test-build)/%.o: $(test)/%.cpp $(vm-depends) $(test-library): $(test-cpp-objects) @echo "linking $(@)" -ifdef msvc +ifdef ms_cl_compiler $(ld) $(shared) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \ - -IMPLIB:$(test-build)/$(name).lib -MANIFESTFILE:$(@).manifest - $(mt) -manifest $(@).manifest -outputresource:"$(@);2" + -IMPLIB:$(test-build)/$(name).lib $(manifest-flags) +ifdef mt + $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);2" +endif else $(ld) $(^) $(shared) $(lflags) -o $(@) endif @@ -1065,10 +1287,12 @@ endif ifdef embed $(embed): $(embed-objects) $(embed-loader-o) @echo "building $(embed)" -ifdef msvc +ifdef ms_cl_compiler $(ld) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \ - -IMPLIB:$(@).lib -MANIFESTFILE:$(@).manifest - $(mt) -manifest $(@).manifest -outputresource:"$(@);1" + -IMPLIB:$(@).lib $(manifest-flags) +ifdef mt + $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" +endif else $(cxx) $(^) $(lflags) $(static) $(call output,$(@)) endif @@ -1086,10 +1310,12 @@ $(embed-loader-o): $(embed-loader) $(converter) $(embed-loader): $(embed-loader-objects) $(static-library) @mkdir -p $(dir $(@)) cd $(dir $(@)) && $(ar) x ../../../$(static-library) -ifdef msvc +ifdef ms_cl_compiler $(ld) $(lflags) $(dir $(@))/*.o -out:$(@) -PDB:$(@).pdb \ - -IMPLIB:$(@).lib -MANIFESTFILE:$(@).manifest - $(mt) -manifest $(@).manifest -outputresource:"$(@);1" + -IMPLIB:$(@).lib $(manifest-flags) +ifdef mt + $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" +endif else $(dlltool) -z $(addsuffix .def,$(basename $(@))) $(dir $(@))/*.o $(dlltool) -d $(addsuffix .def,$(basename $(@))) -e $(addsuffix .exp,$(basename $(@))) @@ -1109,7 +1335,7 @@ $(build)/%.o: $(lzma)/C/%.c @mkdir -p $(dir $(@)) $(cxx) $(cflags) $(no-error) -c $$($(windows-path) $(<)) $(call output,$(@)) -$(vm-asm-objects): $(build)/%-asm.o: $(src)/%.S +$(vm-asm-objects): $(build)/%-asm.o: $(src)/%.$(asm-format) $(compile-asm-object) $(bootimage-generator-objects): $(build)/%.o: $(src)/%.cpp $(vm-depends) @@ -1196,14 +1422,18 @@ $(static-library): $(vm-objects) $(classpath-objects) $(vm-heapwalk-objects) \ $(javahome-object) $(boot-javahome-object) $(lzma-decode-objects) @echo "creating $(@)" rm -rf $(@) +ifdef ms_cl_compiler + $(ar) $(arflags) $(^) -out:$(@) +else $(ar) cru $(@) $(^) $(ranlib) $(@) +endif -$(bootimage-object) $(codeimage-object): $(bootimage-generator) \ - $(build)/classpath.jar +$(bootimage-object) $(codeimage-object): $(bootimage-generator) + @echo "generating bootimage and codeimage binaries using $(<)" $(<) -cp $(classpath-build) -bootimage $(bootimage-object) -codeimage $(codeimage-object) \ - -bootimage-symbols _binary_bootimage_bin_start:_binary_bootimage_bin_end \ - -codeimage-symbols _binary_codeimage_bin_start:_binary_codeimage_bin_end + -bootimage-symbols $(bootimage-symbols) \ + -codeimage-symbols $(codeimage-symbols) executable-objects = $(vm-objects) $(classpath-objects) $(driver-object) \ $(vm-heapwalk-objects) $(boot-object) $(vm-classpath-objects) \ @@ -1212,10 +1442,12 @@ executable-objects = $(vm-objects) $(classpath-objects) $(driver-object) \ $(executable): $(executable-objects) @echo "linking $(@)" ifeq ($(platform),windows) -ifdef msvc +ifdef ms_cl_compiler $(ld) $(lflags) $(executable-objects) -out:$(@) -PDB:$(@).pdb \ - -IMPLIB:$(@).lib -MANIFESTFILE:$(@).manifest - $(mt) -manifest $(@).manifest -outputresource:"$(@);1" + -IMPLIB:$(@).lib $(manifest-flags) +ifdef mt + $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" +endif else $(dlltool) -z $(@).def $(executable-objects) $(dlltool) -d $(@).def -e $(@).exp @@ -1229,6 +1461,7 @@ endif $(bootimage-generator): $(bootimage-generator-objects) echo arch=$(arch) platform=$(platform) $(MAKE) mode=$(mode) \ + build-prefix=$(build)/host/ \ arch=$(build-arch) \ target-arch=$(arch) \ platform=$(bootimage-platform) \ @@ -1247,17 +1480,19 @@ $(build-bootimage-generator): \ $(lzma-decode-objects) $(lzma-encode-objects) @echo "linking $(@)" ifeq ($(platform),windows) -ifdef msvc - $(ld) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb -IMPLIB:$(@).lib \ - -MANIFESTFILE:$(@).manifest - $(mt) -manifest $(@).manifest -outputresource:"$(@);1" +ifdef ms_cl_compiler + $(ld) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \ + -IMPLIB:$(@).lib $(manifest-flags) +ifdef mt + $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" +endif else $(dlltool) -z $(@).def $(^) $(dlltool) -d $(@).def -e $(@).exp - $(ld) $(@).exp $(^) $(lflags) -o $(@) + $(ld) $(@).exp $(^) $(bootimage-generator-lflags) $(lflags) -o $(@) endif else - $(ld) $(^) $(rdynamic) $(lflags) -o $(@) + $(ld) $(^) $(rdynamic) $(bootimage-generator-lflags) $(lflags) -o $(@) endif $(dynamic-library): $(vm-objects) $(dynamic-object) $(classpath-objects) \ @@ -1265,10 +1500,12 @@ $(dynamic-library): $(vm-objects) $(dynamic-object) $(classpath-objects) \ $(classpath-libraries) $(javahome-object) $(boot-javahome-object) \ $(lzma-decode-objects) @echo "linking $(@)" -ifdef msvc +ifdef ms_cl_compiler $(ld) $(shared) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \ - -IMPLIB:$(build)/$(name).lib -MANIFESTFILE:$(@).manifest - $(mt) -manifest $(@).manifest -outputresource:"$(@);2" + -IMPLIB:$(build)/$(name).lib $(manifest-flags) +ifdef mt + $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);2" +endif else $(ld) $(^) $(version-script-flag) $(soname-flag) \ $(shared) $(lflags) $(bootimage-lflags) \ @@ -1280,11 +1517,13 @@ endif # Ubuntu 11.10 which may be fixable without disabling LTO. $(executable-dynamic): $(driver-dynamic-objects) $(dynamic-library) @echo "linking $(@)" -ifdef msvc +ifdef ms_cl_compiler $(ld) $(lflags) -LIBPATH:$(build) -DEFAULTLIB:$(name) \ - -PDB:$(@).pdb -IMPLIB:$(@).lib $(driver-dynamic-objects) -out:$(@) \ - -MANIFESTFILE:$(@).manifest - $(mt) -manifest $(@).manifest -outputresource:"$(@);1" + -PDB:$(@).pdb -IMPLIB:$(@).lib $(driver-dynamic-objects) \ + -out:$(@) $(manifest-flags) +ifdef mt + $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" +endif else $(ld) $(driver-dynamic-objects) -L$(build) -ljvm $(lflags) $(no-lto) -Wl,-rpath=\$$ORIGIN -z origin -o $(@) endif diff --git a/src/arm.h b/src/arm.h index 7e7a4d61dd..adfd92b4ad 100644 --- a/src/arm.h +++ b/src/arm.h @@ -71,33 +71,53 @@ namespace vm { inline void trap() { +#ifdef _MSC_VER + __debugbreak(); +#else asm("bkpt"); +#endif } +#ifndef _MSC_VER inline void memoryBarrier() { asm("nop"); } +#endif inline void storeStoreMemoryBarrier() { +#ifdef _MSC_VER + _ReadWriteBarrier(); +#else memoryBarrier(); +#endif } inline void storeLoadMemoryBarrier() { +#ifdef _MSC_VER + MemoryBarrier(); +#else memoryBarrier(); +#endif } inline void loadMemoryBarrier() { +#ifdef _MSC_VER + _ReadWriteBarrier(); +#else memoryBarrier(); +#endif } +#if defined(AVIAN_PROCESS_compile) + #if defined(__ANDROID__) // http://code.google.com/p/android/issues/detail?id=1803 extern "C" void __clear_cache (void *beg __attribute__((__unused__)), void *end __attribute__((__unused__))); @@ -116,6 +136,8 @@ syncInstructionCache(const void* start, unsigned size) #endif } +#endif // AVIAN_PROCESS_compile + #ifndef __APPLE__ typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr); # define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0) @@ -160,7 +182,7 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t* argumentTypes, unsigned vfpIndex = 0; unsigned vfpBackfillIndex UNUSED = 0; - uintptr_t stack[(argumentCount * 8) / BytesPerWord]; // is > argumentSize to account for padding + uintptr_t* stack = new uintptr_t[(argumentCount * 8) / BytesPerWord]; // is > argumentSize to account for padding unsigned stackIndex = 0; unsigned ai = 0; @@ -250,10 +272,12 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t* argumentTypes, } unsigned stackSize = stackIndex*BytesPerWord + ((stackIndex & 1) << 2); - return vmNativeCall + auto retVal = vmNativeCall (function, stackSize, stack, stackIndex * BytesPerWord, (gprIndex ? gprTable : 0), (vfpIndex ? vfpTable : 0), returnType); + delete[] stack; + return retVal; } } // namespace vm diff --git a/src/arm.masm b/src/arm.masm new file mode 100644 index 0000000000..8fc09eb875 --- /dev/null +++ b/src/arm.masm @@ -0,0 +1,77 @@ + AREA text, CODE, ARM + + EXPORT vmNativeCall [FUNC] +vmNativeCall + ; arguments: + ; r0 -> r4 : function + ; r1 -> r5 : stackTotal + ; r2 : memoryTable + ; r3 : memoryCount + ; [sp, #0] -> r6 : gprTable + + mov ip, sp ; save stack frame + stmfd sp!, {r4-r6, lr} ; save clobbered non-volatile regs + + ; mv args into non-volatile regs + mov r4, r0 + mov r5, r1 + ldr r6, [ip] + + ; setup stack arguments if necessary + sub sp, sp, r5 ; allocate stack + mov ip, sp +loop + tst r3, r3 + ldrne r0, [r2], #4 + strne r0, [ip], #4 + subne r3, r3, #4 + bne loop + + ; setup argument registers if necessary + tst r6, r6 + ldmneia r6, {r0-r3} + + blx r4 ; call function + add sp, sp, r5 ; deallocate stack + + ldmfd sp!, {r4-r6, pc} ; restore non-volatile regs and return + + EXPORT vmJump [FUNC] +vmJump + mov lr, r0 + ldr r0, [sp] + ldr r1, [sp, #4] + mov sp, r2 + mov r8, r3 + bx lr + +CHECKPOINT_THREAD EQU 4 +CHECKPOINT_STACK EQU 24 + + EXPORT vmRun [FUNC] +vmRun + ; r0: function + ; r1: arguments + ; r2: checkpoint + stmfd sp!, {r4-r11, lr} + ; align stack + sub sp, sp, #12 + + str sp, [r2, #CHECKPOINT_STACK] + + mov r12, r0 + ldr r0, [r2, #CHECKPOINT_THREAD] + + blx r12 + + EXPORT vmRun_returnAddress [FUNC] +vmRun_returnAddress + add sp, sp, #12 + ldmfd sp!, {r4-r11, lr} + bx lr + + EXPORT vmTrap [FUNC] +vmTrap + bkpt 3 + + END \ No newline at end of file diff --git a/src/binaryToObject/pe.cpp b/src/binaryToObject/pe.cpp index 8d5d5fc444..186e491447 100644 --- a/src/binaryToObject/pe.cpp +++ b/src/binaryToObject/pe.cpp @@ -17,13 +17,17 @@ namespace { -#define IMAGE_SIZEOF_SHORT_NAME 8 +// --- winnt.h ---- +#define IMAGE_SIZEOF_SHORT_NAME 8 -#define IMAGE_FILE_RELOCS_STRIPPED 1 -#define IMAGE_FILE_LINE_NUMS_STRIPPED 4 -#define IMAGE_FILE_MACHINE_AMD64 0x8664 -#define IMAGE_FILE_MACHINE_I386 0x014c -#define IMAGE_FILE_32BIT_MACHINE 256 +#define IMAGE_FILE_RELOCS_STRIPPED 0x0001 // Relocation info stripped from file. +#define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 // Line nunbers stripped from file. +#define IMAGE_FILE_MACHINE_AMD64 0x8664 // AMD64 (K8) +#define IMAGE_FILE_MACHINE_I386 0x014c // Intel 386. +#define IMAGE_FILE_MACHINE_ARM 0x01c0 // ARM Little-Endian +#define IMAGE_FILE_MACHINE_THUMB 0x01c2 // ARM Thumb/Thumb-2 Little-Endian +#define IMAGE_FILE_MACHINE_ARMNT 0x01c4 // ARM Thumb-2 Little-Endian +#define IMAGE_FILE_32BIT_MACHINE 0x0100 // 32 bit word machine. #define IMAGE_SCN_ALIGN_1BYTES 0x100000 #define IMAGE_SCN_ALIGN_2BYTES 0x200000 @@ -73,6 +77,7 @@ struct IMAGE_SYMBOL { uint8_t StorageClass; uint8_t NumberOfAuxSymbols; } __attribute__((packed)); +// --- winnt.h ---- inline unsigned pad(unsigned n) @@ -82,7 +87,7 @@ pad(unsigned n) using namespace avian::tools; -template +template class WindowsPlatform : public Platform { public: @@ -202,12 +207,15 @@ public: int machine; int machineMask; - if (BytesPerWord == 8) { + if (Architecture == PlatformInfo::x86_64) { machine = IMAGE_FILE_MACHINE_AMD64; machineMask = 0; - } else { // if (BytesPerWord == 8) + } else if (Architecture == PlatformInfo::x86) { machine = IMAGE_FILE_MACHINE_I386; machineMask = IMAGE_FILE_32BIT_MACHINE; + } else if (Architecture == PlatformInfo::Arm) { + machine = IMAGE_FILE_MACHINE_ARMNT; + machineMask = IMAGE_FILE_32BIT_MACHINE; } int sectionMask; @@ -269,10 +277,11 @@ public: } WindowsPlatform(): - Platform(PlatformInfo(PlatformInfo::Pe, BytesPerWord == 4 ? PlatformInfo::x86 : PlatformInfo::x86_64)) {} + Platform(PlatformInfo(PlatformInfo::Pe, Architecture)) {} }; -WindowsPlatform<4> windows32Platform; -WindowsPlatform<8> windows64Platform; +WindowsPlatform<4, PlatformInfo::x86> windows32Platform; +WindowsPlatform<8, PlatformInfo::x86_64> windows64Platform; +WindowsPlatform<4, PlatformInfo::Arm> windowsRtPlatform; // Windows Phone 8 and Windows RT } // namespace diff --git a/src/bootimage.cpp b/src/bootimage.cpp index f82e73f9f5..ec04196ca0 100644 --- a/src/bootimage.cpp +++ b/src/bootimage.cpp @@ -342,7 +342,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, unsigned count = s.read2() - 1; if (count) { - Type types[count + 2]; + Type* types = new Type[count + 2]; types[0] = Type_object; types[1] = Type_intptr_t; @@ -410,6 +410,9 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, (t, typeMaps, hashMapFind (t, root(t, Machine::PoolMap), c, objectHash, objectEqual), array, objectHash); + + delete[] types; + types = 0; } } @@ -420,7 +423,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, object fields = allFields(t, typeMaps, c, &count, &array); PROTECT(t, fields); - Field memberFields[count + 1]; + Field* memberFields = new Field[count + 1]; unsigned memberIndex; unsigned buildMemberOffset; @@ -454,7 +457,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, const unsigned StaticHeader = 3; - Field staticFields[count + StaticHeader]; + Field* staticFields = new Field[count + StaticHeader]; init(new (staticFields) Field, Type_object, 0, BytesPerWord, 0, TargetBytesPerWord); @@ -586,6 +589,12 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, hashMapInsert (t, typeMaps, classStaticTable(t, c), array, objectHash); } + + delete[] memberFields; + memberFields = 0; + + delete[] staticFields; + staticFields = 0; } } } @@ -1334,7 +1343,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp } ++ count; - Field fields[count]; + Field* fields = new Field[count]; init(new (fields) Field, Type_object, 0, BytesPerWord, 0, TargetBytesPerWord); @@ -1462,6 +1471,9 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp hashMapInsert (t, typeMaps, vm::type(t, static_cast(i)), array, objectHash); + + delete[] fields; + fields = 0; } constants = makeCodeImage @@ -1646,10 +1658,10 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp Platform* platform = Platform::getPlatform(PlatformInfo((PlatformInfo::Format)AVIAN_TARGET_FORMAT, (PlatformInfo::Architecture)AVIAN_TARGET_ARCH)); - // if(!platform) { - // fprintf(stderr, "unsupported platform: %s/%s\n", os, architecture); - // return false; - // } + if(!platform) { + fprintf(stderr, "unsupported platform: target-format = %d / target-arch = %d\n", AVIAN_TARGET_FORMAT, AVIAN_TARGET_ARCH); + abort(); + } SymbolInfo bootimageSymbols[] = { SymbolInfo(0, bootimageStart), @@ -1768,7 +1780,7 @@ bool ArgParser::parse(int ac, const char** av) { } bool found = false; for(Arg* arg = first; arg; arg = arg->next) { - if(strcmp(arg->name, &av[i][1]) == 0) { + if(::strcmp(arg->name, &av[i][1]) == 0) { found = true; if (arg->desc == 0) { arg->value = "true"; @@ -1905,20 +1917,26 @@ public: exit(1); } +# if AVIAN_TARGET_FORMAT != AVIAN_FORMAT_PE +# define SYMBOL_PREFIX "_" +# else +# define SYMBOL_PREFIX +# endif + if(!bootimageStart) { - bootimageStart = strdup("_binary_bootimage_bin_start"); + bootimageStart = strdup(SYMBOL_PREFIX"binary_bootimage_bin_start"); } if(!bootimageEnd) { - bootimageEnd = strdup("_binary_bootimage_bin_end"); + bootimageEnd = strdup(SYMBOL_PREFIX"binary_bootimage_bin_end"); } if(!codeimageStart) { - codeimageStart = strdup("_binary_codeimage_bin_start"); + codeimageStart = strdup(SYMBOL_PREFIX"binary_codeimage_bin_start"); } if(!codeimageEnd) { - codeimageEnd = strdup("_binary_codeimage_bin_end"); + codeimageEnd = strdup(SYMBOL_PREFIX"binary_codeimage_bin_end"); } } diff --git a/src/common.h b/src/common.h index adab2f587f..c99f23410e 100644 --- a/src/common.h +++ b/src/common.h @@ -94,7 +94,13 @@ typedef int64_t intptr_t; typedef uint64_t uintptr_t; # define UINT64_C(x) x##L # define ARCH_x86_64 -@ define BYTES_PER_WORD 8 +# define BYTES_PER_WORD 8 +# elif defined _M_ARM_FP +typedef int32_t intptr_t; +typedef uint32_t uintptr_t; +# define UINT64_C(x) x##LL +# define ARCH_arm +# define BYTES_PER_WORD 4 # else # error "unsupported architecture" # endif diff --git a/src/interpret.cpp b/src/interpret.cpp index 4a324fd084..9399e96657 100644 --- a/src/interpret.cpp +++ b/src/interpret.cpp @@ -18,7 +18,7 @@ using namespace vm; -namespace { +namespace local { const unsigned FrameBaseOffset = 0; const unsigned FrameNextOffset = 1; @@ -2321,7 +2321,7 @@ interpret3(Thread* t, const int base) object class_ = resolveClassInPool(t, frameMethod(t, frame), index - 1); PROTECT(t, class_); - int32_t counts[dimensions]; + int32_t* counts = new int32_t[dimensions]; for (int i = dimensions - 1; i >= 0; --i) { counts[i] = popInt(t); if (UNLIKELY(counts[i] < 0)) { @@ -2338,6 +2338,9 @@ interpret3(Thread* t, const int base) populateMultiArray(t, array, counts, 0, dimensions); pushObject(t, array); + + delete[] counts; + counts = 0; } goto loop; case new_: { @@ -3100,7 +3103,7 @@ class MyProcessor: public Processor { (&byteArrayBody(t, methodSpec(t, method), 0)); pushArguments(t, this_, spec, arguments); - return ::invoke(t, method); + return local::invoke(t, method); } virtual object @@ -3124,7 +3127,7 @@ class MyProcessor: public Processor { (&byteArrayBody(t, methodSpec(t, method), 0)); pushArguments(t, this_, spec, arguments); - return ::invoke(t, method); + return local::invoke(t, method); } virtual object @@ -3148,7 +3151,7 @@ class MyProcessor: public Processor { (&byteArrayBody(t, methodSpec(t, method), 0)); pushArguments(t, this_, spec, indirectObjects, arguments); - return ::invoke(t, method); + return local::invoke(t, method); } virtual object @@ -3174,7 +3177,7 @@ class MyProcessor: public Processor { assert(t, ((methodFlags(t, method) & ACC_STATIC) == 0) xor (this_ == 0)); - return ::invoke(t, method); + return local::invoke(t, method); } virtual object getStackTrace(vm::Thread* t, vm::Thread*) { @@ -3254,8 +3257,8 @@ namespace vm { Processor* makeProcessor(System* system, Allocator* allocator, bool) { - return new (allocator->allocate(sizeof(MyProcessor))) - MyProcessor(system, allocator); + return new (allocator->allocate(sizeof(local::MyProcessor))) + local::MyProcessor(system, allocator); } } // namespace vm diff --git a/src/machine.h b/src/machine.h index 2924a13fb7..420a0192cb 100644 --- a/src/machine.h +++ b/src/machine.h @@ -1325,6 +1325,9 @@ checkDaemon(Thread* t); object& root(Thread* t, Machine::Root root); +#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) +# define vmRun vmRun_ +#endif extern "C" uint64_t vmRun(uint64_t (*function)(Thread*, uintptr_t*), uintptr_t* arguments, void* checkpoint); diff --git a/src/system.h b/src/system.h index c36aefacd9..14a29c7272 100644 --- a/src/system.h +++ b/src/system.h @@ -97,11 +97,13 @@ class System { virtual void disposeAll() = 0; }; +#if defined(AVIAN_PROCESS_compile) class SignalHandler { public: virtual bool handleSignal(void** ip, void** frame, void** stack, void** thread) = 0; }; +#endif class MonitorResource { public: @@ -121,17 +123,21 @@ class System { virtual bool success(Status) = 0; virtual void* tryAllocate(unsigned sizeInBytes) = 0; virtual void free(const void* p) = 0; +#if defined(AVIAN_PROCESS_compile) virtual void* tryAllocateExecutable(unsigned sizeInBytes) = 0; virtual void freeExecutable(const void* p, unsigned sizeInBytes) = 0; +#endif virtual Status attach(Runnable*) = 0; virtual Status start(Runnable*) = 0; virtual Status make(Mutex**) = 0; virtual Status make(Monitor**) = 0; virtual Status make(Local**) = 0; +#if defined(AVIAN_PROCESS_compile) virtual Status handleSegFault(SignalHandler* handler) = 0; virtual Status handleDivideByZero(SignalHandler* handler) = 0; virtual Status visit(Thread* thread, Thread* target, ThreadVisitor* visitor) = 0; +#endif virtual uint64_t call(void* function, uintptr_t* arguments, uint8_t* types, unsigned count, unsigned size, unsigned returnType) = 0; diff --git a/src/windows.cpp b/src/windows.cpp index 532b66e161..2d8c4c16c4 100644 --- a/src/windows.cpp +++ b/src/windows.cpp @@ -26,6 +26,71 @@ #include "arch.h" #include "system.h" +#if defined(WINAPI_FAMILY) + +#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + +#define WaitForSingleObject(hHandle, dwMilliseconds) \ + WaitForSingleObjectEx((hHandle), (dwMilliseconds), FALSE) + +#define CreateEvent(lpEventAttributes, bManualReset, bInitialState, lpName) \ + CreateEventEx((lpEventAttributes), (lpName), ((bManualReset)?CREATE_EVENT_MANUAL_RESET:0)|((bInitialState)?CREATE_EVENT_INITIAL_SET:0), EVENT_MODIFY_STATE) + +#define CreateMutex(lpEventAttributes, bInitialOwner, lpName) \ + CreateMutexEx((lpEventAttributes), (lpName), (bInitialOwner)?CREATE_MUTEX_INITIAL_OWNER:0, MUTEX_MODIFY_STATE) + +#include "thread-emulation.h" + +#endif + +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE) +// Headers in Windows Phone 8 DevKit contain severe error, so let's define needed functions on our own +extern "C" +{ +WINBASEAPI +_Ret_maybenull_ +HANDLE +WINAPI +CreateFileMappingFromApp( + _In_ HANDLE hFile, + _In_opt_ PSECURITY_ATTRIBUTES SecurityAttributes, + _In_ ULONG PageProtection, + _In_ ULONG64 MaximumSize, + _In_opt_ PCWSTR Name + ); + +WINBASEAPI +_Ret_maybenull_ __out_data_source(FILE) +PVOID +WINAPI +MapViewOfFileFromApp( + _In_ HANDLE hFileMappingObject, + _In_ ULONG DesiredAccess, + _In_ ULONG64 FileOffset, + _In_ SIZE_T NumberOfBytesToMap + ); + +WINBASEAPI +BOOL +WINAPI +UnmapViewOfFile( + _In_ LPCVOID lpBaseAddress + ); +} +#endif // WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE) + +#else + +#ifndef WINAPI_PARTITION_DESKTOP +#define WINAPI_PARTITION_DESKTOP 1 +#endif + +#ifndef WINAPI_FAMILY_PARTITION +#define WINAPI_FAMILY_PARTITION(x) (x) +#endif + +#endif + #define ACQUIRE(s, x) MutexResource MAKE_NAME(mutexResource_) (s, x) using namespace vm; @@ -49,16 +114,20 @@ class MutexResource { HANDLE m; }; +#if defined(AVIAN_PROCESS_compile) const unsigned SegFaultIndex = 0; const unsigned DivideByZeroIndex = 1; const unsigned HandlerCount = 2; +#endif class MySystem; MySystem* system; +#if defined(AVIAN_PROCESS_compile) LONG CALLBACK handleException(LPEXCEPTION_POINTERS e); +#endif DWORD WINAPI run(void* r) @@ -559,18 +628,22 @@ class MySystem: public System { }; MySystem(const char* crashDumpDirectory): +#if defined(AVIAN_PROCESS_compile) oldHandler(0), +#endif crashDumpDirectory(crashDumpDirectory) { expect(this, system == 0); system = this; +#if defined(AVIAN_PROCESS_compile) memset(handlers, 0, sizeof(handlers)); +#endif mutex = CreateMutex(0, false, 0); assert(this, mutex); } - +#if defined(AVIAN_PROCESS_compile) bool findHandler() { for (unsigned i = 0; i < HandlerCount; ++i) { if (handlers[i]) return true; @@ -578,6 +651,7 @@ class MySystem: public System { return false; } + //TODO: http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.application.unhandledexception(v=vs.105).aspx int registerHandler(System::SignalHandler* handler, int index) { if (handler) { handlers[index] = handler; @@ -609,7 +683,7 @@ class MySystem: public System { return 1; } } - +#endif virtual void* tryAllocate(unsigned sizeInBytes) { return malloc(sizeInBytes); } @@ -618,6 +692,7 @@ class MySystem: public System { if (p) ::free(const_cast(p)); } + #if defined(AVIAN_PROCESS_compile) virtual void* tryAllocateExecutable(unsigned sizeInBytes) { return VirtualAlloc (0, sizeInBytes, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); @@ -627,6 +702,7 @@ class MySystem: public System { int r UNUSED = VirtualFree(const_cast(p), 0, MEM_RELEASE); assert(this, r); } + #endif virtual bool success(Status s) { return s == 0; @@ -666,6 +742,7 @@ class MySystem: public System { return 0; } +#if defined(AVIAN_PROCESS_compile) virtual Status handleSegFault(SignalHandler* handler) { return registerHandler(handler, SegFaultIndex); } @@ -710,6 +787,7 @@ class MySystem: public System { return (success ? 0 : 1); } +#endif virtual uint64_t call(void* function, uintptr_t* arguments, uint8_t* types, unsigned count, unsigned size, unsigned returnType) @@ -719,15 +797,39 @@ class MySystem: public System { virtual Status map(System::Region** region, const char* name) { Status status = 1; - +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) HANDLE file = CreateFile(name, FILE_READ_DATA, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); +#else + size_t nameLen = strlen(name); + wchar_t* wideName = new wchar_t[nameLen + 1]; + size_t convertedChars = 0; + mbstowcs_s(&convertedChars, wideName, nameLen + 1, name, nameLen); + HANDLE file = CreateFile2(wideName, GENERIC_READ, FILE_SHARE_READ, + OPEN_EXISTING, 0); + delete[] wideName; +#endif if (file != INVALID_HANDLE_VALUE) { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) unsigned size = GetFileSize(file, 0); +#else + FILE_STANDARD_INFO info; + unsigned size = INVALID_FILE_SIZE; + if(GetFileInformationByHandleEx(file, FileStandardInfo, &info, sizeof(info))) + size = info.EndOfFile.QuadPart; +#endif if (size != INVALID_FILE_SIZE) { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) HANDLE mapping = CreateFileMapping(file, 0, PAGE_READONLY, 0, size, 0); +#else + HANDLE mapping = CreateFileMappingFromApp(file, 0, PAGE_READONLY, size, 0); +#endif if (mapping) { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) void* data = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0); +#else + void* data = MapViewOfFileFromApp(mapping, FILE_MAP_READ, 0, 0); +#endif if (data) { *region = new (allocate(this, sizeof(Region))) Region(this, static_cast(data), size, file, mapping); @@ -757,7 +859,12 @@ class MySystem: public System { memcpy(RUNTIME_ARRAY_BODY(buffer) + length, "\\*", 3); Directory* d = new (allocate(this, sizeof(Directory))) Directory(this); + +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) d->handle = FindFirstFile(RUNTIME_ARRAY_BODY(buffer), &(d->data)); +#else + d->handle = FindFirstFileEx(RUNTIME_ARRAY_BODY(buffer), FindExInfoStandard, &(d->data), FindExSearchNameMatch, 0, 0); +#endif if (d->handle == INVALID_HANDLE_VALUE) { d->dispose(); } else { @@ -797,6 +904,7 @@ class MySystem: public System { } virtual const char* toAbsolutePath(Allocator* allocator, const char* name) { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) if (strncmp(name, "//", 2) == 0 or strncmp(name, "\\\\", 2) == 0 or strncmp(name + 1, ":/", 2) == 0 @@ -808,6 +916,11 @@ class MySystem: public System { GetCurrentDirectory(MAX_PATH, buffer); return append(allocator, buffer, "\\", name); } +#else + //TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ + //Windows.ApplicationModel.Package.Current.InstalledLocation + return name; +#endif } virtual Status load(System::Library** lib, @@ -816,9 +929,23 @@ class MySystem: public System { HMODULE handle; unsigned nameLength = (name ? strlen(name) : 0); if (name) { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) handle = LoadLibrary(name); +#else + size_t nameLen = strlen(name); + wchar_t* wideName = new wchar_t[nameLen + 1]; + size_t convertedChars = 0; + mbstowcs_s(&convertedChars, wideName, nameLen + 1, name, nameLen); + handle = LoadPackagedLibrary(wideName, 0); + delete[] wideName; +#endif } else { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) handle = GetModuleHandle(0); +#else + // Most of WinRT/WP8 applications can not host native object files inside main executable + assert(this, false); +#endif } if (handle) { @@ -866,7 +993,11 @@ class MySystem: public System { } virtual void yield() { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) SwitchToThread(); +#else + YieldProcessor(); +#endif } virtual void exit(int code) { @@ -886,11 +1017,15 @@ class MySystem: public System { } HANDLE mutex; +#if defined(AVIAN_PROCESS_compile) SignalHandler* handlers[HandlerCount]; LPTOP_LEVEL_EXCEPTION_FILTER oldHandler; +#endif const char* crashDumpDirectory; }; +#if defined(AVIAN_PROCESS_compile) + #pragma pack(push,4) struct MINIDUMP_EXCEPTION_INFORMATION { DWORD thread; @@ -1005,6 +1140,8 @@ handleException(LPEXCEPTION_POINTERS e) return EXCEPTION_CONTINUE_SEARCH; } +#endif + } // namespace namespace vm { diff --git a/src/x86.masm b/src/x86.masm new file mode 100644 index 0000000000..715669f8c1 --- /dev/null +++ b/src/x86.masm @@ -0,0 +1,166 @@ +comment # + Copyright (c) 2008-2011, 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. +# + +.586 +.MODEL FLAT, C + +VOID_TYPE equ 0 +INT8_TYPE equ 1 +INT16_TYPE equ 2 +INT32_TYPE equ 3 +INT64_TYPE equ 4 +FLOAT_TYPE equ 5 +DOUBLE_TYPE equ 6 +POINTER_TYPE equ 7 + +CHECKPOINT_THREAD equ 4 +CHECKPOINT_STACK equ 24 +CHECKPOINT_BASE equ 28 + +_TEXT SEGMENT + +public C detectFeature +detectFeature: + push ebp + mov ebp,esp + push edx + push ecx + push ebx + push esi + push edi + mov esi,ds:dword ptr[12+ebp] + mov edi,ds:dword ptr[8+ebp] + mov eax,1 + cpuid + and edx,esi + and ecx,edi + or ecx,edx + test ecx,ecx + je LNOSSE + mov eax,1 + jmp LSSEEND + +LNOSSE: + mov eax,0 + +LSSEEND: + pop edi + pop esi + pop ebx + pop ecx + pop edx + mov esp,ebp + pop ebp + ret + +public C vmNativeCall +vmNativeCall: + push ebp + mov ebp,esp + mov ecx,ds:dword ptr[16+ebp] + sub esp,ecx + mov ecx,0 + jmp Ltest + +Lloop: + mov eax,ecx + mov edx,ecx + add edx,esp + add eax,ds:dword ptr[12+ebp] + mov eax,ds:dword ptr[eax] + mov ds:dword ptr[edx],eax + add ecx,4 + +Ltest: + cmp ecx,ds:dword ptr[16+ebp] + jb Lloop + call dword ptr[8+ebp] + mov ecx,ds:dword ptr[20+ebp] + +Lvoid: + cmp ecx,offset VOID_TYPE + jne Lint64 + jmp Lexit + +Lint64: + cmp ecx,offset INT64_TYPE + jne Lfloat + jmp Lexit + +Lfloat: + cmp ecx,offset FLOAT_TYPE + jne Ldouble + fstp ds:dword ptr[8+ebp] + mov eax,ds:dword ptr[8+ebp] + jmp Lexit + +Ldouble: + cmp ecx,offset DOUBLE_TYPE + jne Lexit + fstp ds:dword ptr[8+ebp] + mov eax,ds:dword ptr[8+ebp] + mov edx,ds:dword ptr[12+ebp] + +Lexit: + mov esp,ebp + pop ebp + ret + +public C vmJump +vmJump: + mov esi,ds:dword ptr[4+esp] + mov ebp,ds:dword ptr[8+esp] + mov ebx,ds:dword ptr[16+esp] + mov eax,ds:dword ptr[20+esp] + mov edx,ds:dword ptr[24+esp] + mov esp,ds:dword ptr[12+esp] + jmp esi + +VMRUN_FRAME_SIZE equ 24 + +public C vmRun_ +vmRun_: + ; 8(%ebp): function + ; 12(%ebp): arguments + ; 16(%ebp): checkpoint + push ebp + mov ebp,esp + sub esp,offset VMRUN_FRAME_SIZE + + mov ds:dword ptr[8+esp],ebx + mov ds:dword ptr[12+esp],esi + mov ds:dword ptr[16+esp],edi + + mov eax,ds:dword ptr[12+ebp] + mov ds:dword ptr[4+esp],eax + + mov ecx,ds:dword ptr[16+ebp] + mov eax,ds:dword ptr[CHECKPOINT_THREAD+ecx] + mov ds:dword ptr[0+esp],eax + + mov ds:dword ptr[CHECKPOINT_STACK+ecx],esp + + call dword ptr[8+ebp] + +public C vmRun_returnAddress +vmRun_returnAddress: + + mov ebx,ds:dword ptr[8+esp] + mov esi,ds:dword ptr[12+esp] + mov edi,ds:dword ptr[16+esp] + + add esp,offset VMRUN_FRAME_SIZE + pop ebp + ret + +_TEXT ENDS +END \ No newline at end of file From 1b43caf8155758fee761b4ee7b127797d5e97cdc Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Mon, 28 Jan 2013 19:15:29 +0200 Subject: [PATCH 064/106] Makefile fix --- makefile | 16 ++++++++++------ src/arm.h | 4 ++-- src/system.h | 6 +++--- src/windows.cpp | 18 +++++++++--------- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/makefile b/makefile index 5ca549e988..074095eff6 100755 --- a/makefile +++ b/makefile @@ -51,7 +51,8 @@ ifeq ($(continuations),true) endif root := $(shell (cd .. && pwd)) -build = $(build-prefix)build/$(platform)-$(arch)$(options) +build = build/$(platform)-$(arch)$(options) +host-build-root = $(build)/host classpath-build = $(build)/classpath test-build = $(build)/test src = src @@ -135,7 +136,7 @@ ifneq ($(openjdk),) javahome = "$$($(native-path) "$(openjdk)/jre")" endif - classpath = openjdk + classpath = openjdk boot-classpath := "$(boot-classpath)$(path-separator)$$($(native-path) "$(openjdk)/jre/lib/rt.jar")" build-javahome = $(openjdk)/jre endif @@ -640,7 +641,7 @@ ifeq ($(platform),wp8) ms_cl_compiler = wp8 use-lto = false supports_avian_executable = false - process = interpret + process = compile ifneq ($(process),compile) options := -$(process) endif @@ -918,6 +919,9 @@ ifeq ($(process),compile) vm-asm-sources += $(src)/compile-$(asm).$(asm-format) endif cflags += -DAVIAN_PROCESS_$(process) +ifdef aot_only + cflags += -DAVIAN_AOT_ONLY +endif vm-cpp-objects = $(call cpp-objects,$(vm-sources),$(src),$(build)) vm-asm-objects = $(call asm-objects,$(vm-asm-sources),$(src),$(build)) @@ -1430,7 +1434,7 @@ else endif $(bootimage-object) $(codeimage-object): $(bootimage-generator) - @echo "generating bootimage and codeimage binaries using $(<)" + @echo "generating bootimage and codeimage binaries from $(classpath-build) using $(<)" $(<) -cp $(classpath-build) -bootimage $(bootimage-object) -codeimage $(codeimage-object) \ -bootimage-symbols $(bootimage-symbols) \ -codeimage-symbols $(codeimage-symbols) @@ -1459,9 +1463,9 @@ endif $(strip) $(strip-all) $(@) $(bootimage-generator): $(bootimage-generator-objects) - echo arch=$(arch) platform=$(platform) + echo building $(bootimage-generator) arch=$(build-arch) platform=$(bootimage-platform) $(MAKE) mode=$(mode) \ - build-prefix=$(build)/host/ \ + build=$(host-build-root) \ arch=$(build-arch) \ target-arch=$(arch) \ platform=$(bootimage-platform) \ diff --git a/src/arm.h b/src/arm.h index adfd92b4ad..302355c453 100644 --- a/src/arm.h +++ b/src/arm.h @@ -116,7 +116,7 @@ loadMemoryBarrier() #endif } -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) #if defined(__ANDROID__) // http://code.google.com/p/android/issues/detail?id=1803 @@ -136,7 +136,7 @@ syncInstructionCache(const void* start, unsigned size) #endif } -#endif // AVIAN_PROCESS_compile +#endif // AVIAN_AOT_ONLY #ifndef __APPLE__ typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr); diff --git a/src/system.h b/src/system.h index 14a29c7272..ee80d2a7cb 100644 --- a/src/system.h +++ b/src/system.h @@ -97,7 +97,7 @@ class System { virtual void disposeAll() = 0; }; -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) class SignalHandler { public: virtual bool handleSignal(void** ip, void** frame, void** stack, @@ -123,7 +123,7 @@ class System { virtual bool success(Status) = 0; virtual void* tryAllocate(unsigned sizeInBytes) = 0; virtual void free(const void* p) = 0; -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) virtual void* tryAllocateExecutable(unsigned sizeInBytes) = 0; virtual void freeExecutable(const void* p, unsigned sizeInBytes) = 0; #endif @@ -132,7 +132,7 @@ class System { virtual Status make(Mutex**) = 0; virtual Status make(Monitor**) = 0; virtual Status make(Local**) = 0; -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) virtual Status handleSegFault(SignalHandler* handler) = 0; virtual Status handleDivideByZero(SignalHandler* handler) = 0; virtual Status visit(Thread* thread, Thread* target, diff --git a/src/windows.cpp b/src/windows.cpp index 2d8c4c16c4..f6b9627254 100644 --- a/src/windows.cpp +++ b/src/windows.cpp @@ -114,7 +114,7 @@ class MutexResource { HANDLE m; }; -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) const unsigned SegFaultIndex = 0; const unsigned DivideByZeroIndex = 1; @@ -124,7 +124,7 @@ const unsigned HandlerCount = 2; class MySystem; MySystem* system; -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) LONG CALLBACK handleException(LPEXCEPTION_POINTERS e); #endif @@ -628,7 +628,7 @@ class MySystem: public System { }; MySystem(const char* crashDumpDirectory): -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) oldHandler(0), #endif crashDumpDirectory(crashDumpDirectory) @@ -636,14 +636,14 @@ class MySystem: public System { expect(this, system == 0); system = this; -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) memset(handlers, 0, sizeof(handlers)); #endif mutex = CreateMutex(0, false, 0); assert(this, mutex); } -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) bool findHandler() { for (unsigned i = 0; i < HandlerCount; ++i) { if (handlers[i]) return true; @@ -692,7 +692,7 @@ class MySystem: public System { if (p) ::free(const_cast(p)); } - #if defined(AVIAN_PROCESS_compile) + #if !defined(AVIAN_AOT_ONLY) virtual void* tryAllocateExecutable(unsigned sizeInBytes) { return VirtualAlloc (0, sizeInBytes, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); @@ -742,7 +742,7 @@ class MySystem: public System { return 0; } -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) virtual Status handleSegFault(SignalHandler* handler) { return registerHandler(handler, SegFaultIndex); } @@ -1017,14 +1017,14 @@ class MySystem: public System { } HANDLE mutex; -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) SignalHandler* handlers[HandlerCount]; LPTOP_LEVEL_EXCEPTION_FILTER oldHandler; #endif const char* crashDumpDirectory; }; -#if defined(AVIAN_PROCESS_compile) +#if !defined(AVIAN_AOT_ONLY) #pragma pack(push,4) struct MINIDUMP_EXCEPTION_INFORMATION { From 4d03650544f2d6bbc7879c6697e594639d7b94ed Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Mon, 28 Jan 2013 20:51:35 +0200 Subject: [PATCH 065/106] Replaced TODO comments with messages ; More correct AVIAN_AOT_ONLY usage --- classpath/java-lang.cpp | 15 +++++------ makefile | 1 + src/arm.cpp | 26 ++++++++++--------- src/arm.masm | 12 +++++++++ src/compile.cpp | 7 +++++- src/system.h | 4 --- src/windows.cpp | 55 ++++++++++++++++++++++------------------- src/x86.masm | 2 ++ 8 files changed, 72 insertions(+), 50 deletions(-) diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index 0414216194..9d2562e265 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -80,8 +80,8 @@ namespace { snprintf(errStr, 9, "%d", (int) err); return errStr; - //TODO: - // The better way to do this, if I could figure out how to convert LPTSTR to char* + #pragma message("TODO") + // The better way to do this, if I could figure out how to convert LPTSTR to char* //char* errStr; //LPTSTR s; //if(FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | @@ -390,7 +390,7 @@ Locale getLocale() { return Locale(lang, reg); #else - //TODO: CultureInfo.CurrentCulture + #pragma message("TODO: CultureInfo.CurrentCulture") return Locale("en", "US"); #endif } @@ -596,8 +596,7 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, GetTempPath(MAX_PATH, buffer); r = e->NewStringUTF(buffer); # else - //TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ - //Windows.Storage.ApplicationData.Current.TemporaryFolder + #pragma message("TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ Windows.Storage.ApplicationData.Current.TemporaryFolder") r = 0; # endif } else if (strcmp(chars, "user.dir") == 0) { @@ -606,8 +605,7 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, GetCurrentDirectory(MAX_PATH, buffer); r = e->NewStringUTF(buffer); # else - //TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ - //Windows.ApplicationModel.Package.Current.InstalledLocation + #pragma message("TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ Windows.ApplicationModel.Package.Current.InstalledLocation") r = 0; # endif } else if (strcmp(chars, "user.home") == 0) { @@ -621,8 +619,7 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, r = 0; } # else - //TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ - //Windows.Storage.KnownFolders.DocumentsLibrary; + #pragma message("TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ Windows.Storage.KnownFolders.DocumentsLibrary") r = 0; # endif # else diff --git a/makefile b/makefile index 074095eff6..ddaa378425 100755 --- a/makefile +++ b/makefile @@ -642,6 +642,7 @@ ifeq ($(platform),wp8) use-lto = false supports_avian_executable = false process = compile + aot_only = true ifneq ($(process),compile) options := -$(process) endif diff --git a/src/arm.cpp b/src/arm.cpp index ae657e30d5..1d4dbc8dd1 100644 --- a/src/arm.cpp +++ b/src/arm.cpp @@ -18,7 +18,7 @@ using namespace vm; -namespace { +namespace local { namespace isa { // SYSTEM REGISTERS @@ -252,7 +252,7 @@ class MyBlock: public Assembler::Block { this->start = start; this->next = static_cast(next); - ::resolve(this); + local::resolve(this); return start + size + padding(this, size); } @@ -2150,7 +2150,7 @@ class MyArchitecture: public Assembler::Architecture { } virtual unsigned argumentFootprint(unsigned footprint) { - return ::argumentFootprint(footprint); + return local::argumentFootprint(footprint); } virtual bool argumentAlignment() { @@ -2239,7 +2239,7 @@ class MyArchitecture: public Assembler::Architecture { unsigned targetParameterFootprint, void** ip, void** stack) { - ::nextFrame(&con, static_cast(start), size, footprint, link, + local::nextFrame(&con, static_cast(start), size, footprint, link, mostRecent, targetParameterFootprint, ip, stack); } @@ -2550,11 +2550,12 @@ class MyAssembler: public Assembler { } virtual void pushFrame(unsigned argumentCount, ...) { - struct { + struct Argument { unsigned size; OperandType type; Operand* operand; - } arguments[argumentCount]; + }; + Argument* arguments = new Argument[argumentCount]; va_list a; va_start(a, argumentCount); unsigned footprint = 0; @@ -2589,6 +2590,9 @@ class MyAssembler: public Assembler { offset += ceiling(arguments[i].size, TargetBytesPerWord); } } + + delete[] arguments; + arguments = 0; } virtual void allocateFrame(unsigned footprint) { @@ -2798,7 +2802,7 @@ class MyAssembler: public Assembler { bool jump = needJump(b); if (jump) { write4 - (dst + dstOffset, ::b((poolSize + TargetBytesPerWord - 8) >> 2)); + (dst + dstOffset, isa::b((poolSize + TargetBytesPerWord - 8) >> 2)); } dstOffset += poolSize + (jump ? TargetBytesPerWord : 0); @@ -2832,7 +2836,7 @@ class MyAssembler: public Assembler { } virtual Promise* offset(bool forTrace) { - return ::offset(&con, forTrace); + return local::offset(&con, forTrace); } virtual Block* endBlock(bool startNew) { @@ -2903,15 +2907,15 @@ namespace vm { Assembler::Architecture* makeArchitecture(System* system, bool) { - return new (allocate(system, sizeof(MyArchitecture))) MyArchitecture(system); + return new (allocate(system, sizeof(local::MyArchitecture))) local::MyArchitecture(system); } Assembler* makeAssembler(System* system, Allocator* allocator, Zone* zone, Assembler::Architecture* architecture) { - return new(zone) MyAssembler(system, allocator, zone, - static_cast(architecture)); + return new(zone) local::MyAssembler(system, allocator, zone, + static_cast(architecture)); } } // namespace vm diff --git a/src/arm.masm b/src/arm.masm index 8fc09eb875..2af5048ec7 100644 --- a/src/arm.masm +++ b/src/arm.masm @@ -1,3 +1,15 @@ +; Copyright (c) 2008-2011, 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. +; +; ORIGIN: https://github.com/gkvas/avian/tree/wince + AREA text, CODE, ARM EXPORT vmNativeCall [FUNC] diff --git a/src/compile.cpp b/src/compile.cpp index 6989d6446d..7fa51817c7 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -7389,8 +7389,9 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context) { trap(); } - +#if !defined(AVIAN_AOT_ONLY) syncInstructionCache(start, codeSize); +#endif } void @@ -9152,7 +9153,9 @@ class MyProcessor: public Processor { virtual void dispose() { if (codeAllocator.base) { +#if !defined(AVIAN_AOT_ONLY) s->freeExecutable(codeAllocator.base, codeAllocator.capacity); +#endif } compilationHandlers->dispose(allocator); @@ -9313,11 +9316,13 @@ class MyProcessor: public Processor { } virtual void boot(Thread* t, BootImage* image, uint8_t* code) { +#if !defined(AVIAN_AOT_ONLY) if (codeAllocator.base == 0) { codeAllocator.base = static_cast (s->tryAllocateExecutable(ExecutableAreaSizeInBytes)); codeAllocator.capacity = ExecutableAreaSizeInBytes; } +#endif if (image and code) { local::boot(static_cast(t), image, code); diff --git a/src/system.h b/src/system.h index ee80d2a7cb..ef69317f0b 100644 --- a/src/system.h +++ b/src/system.h @@ -97,13 +97,11 @@ class System { virtual void disposeAll() = 0; }; -#if !defined(AVIAN_AOT_ONLY) class SignalHandler { public: virtual bool handleSignal(void** ip, void** frame, void** stack, void** thread) = 0; }; -#endif class MonitorResource { public: @@ -132,12 +130,10 @@ class System { virtual Status make(Mutex**) = 0; virtual Status make(Monitor**) = 0; virtual Status make(Local**) = 0; -#if !defined(AVIAN_AOT_ONLY) virtual Status handleSegFault(SignalHandler* handler) = 0; virtual Status handleDivideByZero(SignalHandler* handler) = 0; virtual Status visit(Thread* thread, Thread* target, ThreadVisitor* visitor) = 0; -#endif virtual uint64_t call(void* function, uintptr_t* arguments, uint8_t* types, unsigned count, unsigned size, unsigned returnType) = 0; diff --git a/src/windows.cpp b/src/windows.cpp index f6b9627254..8c7512eab1 100644 --- a/src/windows.cpp +++ b/src/windows.cpp @@ -114,17 +114,15 @@ class MutexResource { HANDLE m; }; -#if !defined(AVIAN_AOT_ONLY) const unsigned SegFaultIndex = 0; const unsigned DivideByZeroIndex = 1; const unsigned HandlerCount = 2; -#endif class MySystem; MySystem* system; -#if !defined(AVIAN_AOT_ONLY) +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) LONG CALLBACK handleException(LPEXCEPTION_POINTERS e); #endif @@ -628,7 +626,7 @@ class MySystem: public System { }; MySystem(const char* crashDumpDirectory): -#if !defined(AVIAN_AOT_ONLY) +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) oldHandler(0), #endif crashDumpDirectory(crashDumpDirectory) @@ -636,14 +634,12 @@ class MySystem: public System { expect(this, system == 0); system = this; -#if !defined(AVIAN_AOT_ONLY) memset(handlers, 0, sizeof(handlers)); -#endif mutex = CreateMutex(0, false, 0); assert(this, mutex); } -#if !defined(AVIAN_AOT_ONLY) + bool findHandler() { for (unsigned i = 0; i < HandlerCount; ++i) { if (handlers[i]) return true; @@ -651,31 +647,38 @@ class MySystem: public System { return false; } - //TODO: http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.application.unhandledexception(v=vs.105).aspx int registerHandler(System::SignalHandler* handler, int index) { if (handler) { handlers[index] = handler; - + +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) if (oldHandler == 0) { -#ifdef ARCH_x86_32 +# ifdef ARCH_x86_32 oldHandler = SetUnhandledExceptionFilter(handleException); -#elif defined ARCH_x86_64 +# elif defined ARCH_x86_64 AddVectoredExceptionHandler(1, handleException); oldHandler = reinterpret_cast(1); -#endif +# endif } +#else + #pragma message("TODO: http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.application.unhandledexception(v=vs.105).aspx") +#endif return 0; } else if (handlers[index]) { handlers[index] = 0; if (not findHandler()) { -#ifdef ARCH_x86_32 +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +# ifdef ARCH_x86_32 SetUnhandledExceptionFilter(oldHandler); oldHandler = 0; -#elif defined ARCH_x86_64 +# elif defined ARCH_x86_64 // do nothing, handlers are never "unregistered" anyway -#endif +# endif +#else + #pragma message("TODO: http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.application.unhandledexception(v=vs.105).aspx") +#endif } return 0; @@ -683,7 +686,7 @@ class MySystem: public System { return 1; } } -#endif + virtual void* tryAllocate(unsigned sizeInBytes) { return malloc(sizeInBytes); } @@ -742,7 +745,6 @@ class MySystem: public System { return 0; } -#if !defined(AVIAN_AOT_ONLY) virtual Status handleSegFault(SignalHandler* handler) { return registerHandler(handler, SegFaultIndex); } @@ -754,6 +756,7 @@ class MySystem: public System { virtual Status visit(System::Thread* st UNUSED, System::Thread* sTarget, ThreadVisitor* visitor) { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) assert(this, st != sTarget); Thread* target = static_cast(sTarget); @@ -769,15 +772,15 @@ class MySystem: public System { rv = GetThreadContext(target->thread, &context); if (rv) { -#ifdef ARCH_x86_32 +# ifdef ARCH_x86_32 visitor->visit(reinterpret_cast(context.Eip), reinterpret_cast(context.Ebp), reinterpret_cast(context.Esp)); -#elif defined ARCH_x86_64 +# elif defined ARCH_x86_64 visitor->visit(reinterpret_cast(context.Rip), reinterpret_cast(context.Rbp), reinterpret_cast(context.Rsp)); -#endif +# endif success = true; } @@ -786,8 +789,11 @@ class MySystem: public System { } return (success ? 0 : 1); - } +#else + #pragma message("TODO: http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.application.unhandledexception(v=vs.105).aspx") + return false; #endif + } virtual uint64_t call(void* function, uintptr_t* arguments, uint8_t* types, unsigned count, unsigned size, unsigned returnType) @@ -917,8 +923,7 @@ class MySystem: public System { return append(allocator, buffer, "\\", name); } #else - //TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ - //Windows.ApplicationModel.Package.Current.InstalledLocation + #pragma message("TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ Windows.ApplicationModel.Package.Current.InstalledLocation") return name; #endif } @@ -1017,14 +1022,14 @@ class MySystem: public System { } HANDLE mutex; -#if !defined(AVIAN_AOT_ONLY) SignalHandler* handlers[HandlerCount]; +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) LPTOP_LEVEL_EXCEPTION_FILTER oldHandler; #endif const char* crashDumpDirectory; }; -#if !defined(AVIAN_AOT_ONLY) +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) #pragma pack(push,4) struct MINIDUMP_EXCEPTION_INFORMATION { diff --git a/src/x86.masm b/src/x86.masm index 715669f8c1..640637d5af 100644 --- a/src/x86.masm +++ b/src/x86.masm @@ -8,6 +8,8 @@ comment # There is NO WARRANTY for this software. See license.txt for details. + + ORIGIN: https://github.com/gkvas/avian/tree/wince # .586 From dca12d3cd0e44716ab0c0a27d1b086840eafd679 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Tue, 29 Jan 2013 09:40:29 +0200 Subject: [PATCH 066/106] WinRT/WP8 process=compile --- makefile | 2 + src/arm.masm | 10 +- src/compile-arm.masm | 252 +++++++++++++++++++++++++++++++++++++++++++ src/compile-x86.masm | 173 +++++++++++++++++++++++++++++ 4 files changed, 432 insertions(+), 5 deletions(-) create mode 100644 src/compile-arm.masm create mode 100644 src/compile-x86.masm diff --git a/makefile b/makefile index ddaa378425..29465173c1 100755 --- a/makefile +++ b/makefile @@ -1217,7 +1217,9 @@ clean: @echo "removing build" rm -rf build +ifeq ($(continuations),true) $(build)/compile-x86-asm.o: $(src)/continuations-x86.$(asm-format) +endif gen-arg = $(shell echo $(1) | sed -e 's:$(build)/type-\(.*\)\.cpp:\1:') $(generated-code): %.cpp: $(src)/types.def $(generator) $(classpath-dep) diff --git a/src/arm.masm b/src/arm.masm index 2af5048ec7..e7bd2d864c 100644 --- a/src/arm.masm +++ b/src/arm.masm @@ -12,7 +12,7 @@ AREA text, CODE, ARM - EXPORT vmNativeCall [FUNC] + EXPORT vmNativeCall vmNativeCall ; arguments: ; r0 -> r4 : function @@ -48,7 +48,7 @@ loop ldmfd sp!, {r4-r6, pc} ; restore non-volatile regs and return - EXPORT vmJump [FUNC] + EXPORT vmJump vmJump mov lr, r0 ldr r0, [sp] @@ -60,7 +60,7 @@ vmJump CHECKPOINT_THREAD EQU 4 CHECKPOINT_STACK EQU 24 - EXPORT vmRun [FUNC] + EXPORT vmRun vmRun ; r0: function ; r1: arguments @@ -76,13 +76,13 @@ vmRun blx r12 - EXPORT vmRun_returnAddress [FUNC] + EXPORT vmRun_returnAddress vmRun_returnAddress add sp, sp, #12 ldmfd sp!, {r4-r11, lr} bx lr - EXPORT vmTrap [FUNC] + EXPORT vmTrap vmTrap bkpt 3 diff --git a/src/compile-arm.masm b/src/compile-arm.masm new file mode 100644 index 0000000000..a9c1e59cef --- /dev/null +++ b/src/compile-arm.masm @@ -0,0 +1,252 @@ +; Copyright (c) 2008-2011, 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. +; +; ORIGIN: https://github.com/gkvas/avian/tree/wince + +; types.inc +VOID_TYPE equ 0 +INT8_TYPE equ 1 +INT16_TYPE equ 2 +INT32_TYPE equ 3 +INT64_TYPE equ 4 +FLOAT_TYPE equ 5 +DOUBLE_TYPE equ 6 +POINTER_TYPE equ 7 + +; target-fields.inc +;TARGET_BYTES_PER_WORD = 4 + +TARGET_THREAD_EXCEPTION equ 44 +TARGET_THREAD_EXCEPTIONSTACKADJUSTMENT equ 2164 +TARGET_THREAD_EXCEPTIONOFFSET equ 2168 +TARGET_THREAD_EXCEPTIONHANDLER equ 2172 + +TARGET_THREAD_IP equ 2144 +TARGET_THREAD_STACK equ 2148 +TARGET_THREAD_NEWSTACK equ 2152 +TARGET_THREAD_SCRATCH equ 2156 +TARGET_THREAD_CONTINUATION equ 2160 +TARGET_THREAD_TAILADDRESS equ 2176 +TARGET_THREAD_VIRTUALCALLTARGET equ 2180 +TARGET_THREAD_VIRTUALCALLINDEX equ 2184 +TARGET_THREAD_HEAPIMAGE equ 2188 +TARGET_THREAD_CODEIMAGE equ 2192 +TARGET_THREAD_THUNKTABLE equ 2196 +TARGET_THREAD_STACKLIMIT equ 2220 + + AREA text, CODE, ARM + +BYTES_PER_WORD equ 4 + +CONTINUATION_NEXT equ 4 +CONTINUATION_ADDRESS equ 16 +CONTINUATION_RETURN_ADDRESS_OFFSET equ 20 +CONTINUATION_FRAME_POINTER_OFFSET equ 24 +CONTINUATION_LENGTH equ 28 +CONTINUATION_BODY equ 32 + + EXPORT vmInvoke +vmInvoke + + ; arguments + ; r0 : thread + ; r1 : function + ; r2 : arguments + ; r3 : argumentFootprint + ; [sp, #0] : frameSize (not used) + ; [sp, #4] : returnType + + + ; save all non-volatile registers + stmfd sp!, {r4-r11, lr} + + ; save return type + ldr r4, [sp, #4] + str r4, [sp, #-4]! + + str sp, [r0, #TARGET_THREAD_SCRATCH] + + ; align stack, if necessary + eor r4, sp, r3 + tst r4, #4 + subne sp, sp, #4 + + ; copy arguments into place + sub sp, sp, r3 + mov r4, #0 + b vmInvoke_argumentTest + +vmInvoke_argumentLoop + ldr r5, [r2, r4] + str r5, [sp, r4] + add r4, r4, #BYTES_PER_WORD + +vmInvoke_argumentTest + cmp r4, r3 + blt vmInvoke_argumentLoop + + ; we use r8 to hold the thread pointer, by convention + mov r8, r0 + + ; load and call function address + blx r1 + + EXPORT vmInvoke_returnAddress +vmInvoke_returnAddress + ; restore stack pointer + ldr sp, [r8, #TARGET_THREAD_SCRATCH] + + ; clear MyThread::stack to avoid confusing another thread calling + ; java.lang.Thread.getStackTrace on this one. See + ; MyProcess::getStackTrace in compile.cpp for details on how we get + ; a reliable stack trace from a thread that might be interrupted at + ; any point in its execution. + mov r5, #0 + str r5, [r8, #TARGET_THREAD_STACK] + + EXPORT vmInvoke_safeStack +vmInvoke_safeStack + +;if AVIAN_CONTINUATIONS +; ; call the next continuation, if any +; ldr r5,[r8,#TARGET_THREAD_CONTINUATION] +; cmp r5,#0 +; beq vmInvoke_exit) +; +; ldr r6,[r5,#CONTINUATION_LENGTH] +; lsl r6,r6,#2 +; neg r7,r6 +; add r7,r7,#-80 +; mov r4,sp +; str r4,[sp,r7]! +; +; add r7,r5,#CONTINUATION_BODY +; +; mov r11,#0 +; b vmInvoke_continuationTest +; +;vmInvoke_continuationLoop +; ldr r9,[r7,r11] +; str r9,[sp,r11] +; add r11,r11,#4 +; +;vmInvoke_continuationTest +; cmp r11,r6 +; ble vmInvoke_continuationLoop) +; +; ldr r7,[r5,#CONTINUATION_RETURN_ADDRESS_OFFSET] +; ldr r10,vmInvoke_returnAddress_word +; ldr r11,vmInvoke_getAddress_word +;vmInvoke_getAddress +; add r11,pc,r11 +; ldr r11,[r11,r10] +; str r11,[sp,r7] +; +; ldr r7,[r5,#CONTINUATION_NEXT] +; str r7,[r8,#TARGET_THREAD_CONTINUATION] +; +; ; call the continuation unless we're handling an exception +; ldr r7,[r8,#TARGET_THREAD_EXCEPTION] +; cmp r7,#0 +; bne vmInvoke_handleException) +; ldr r7,[r5,#CONTINUATION_ADDRESS] +; bx r7 +; +;vmInvoke_handleException +; ; we're handling an exception - call the exception handler instead +; mov r11,#0 +; str r11,[r8,#TARGET_THREAD_EXCEPTION] +; ldr r11,[r8,#TARGET_THREAD_EXCEPTIONSTACKADJUSTMENT] +; ldr r9,[sp] +; neg r11,r11 +; str r9,[sp,r11]! +; ldr r11,[r8,#TARGET_THREAD_EXCEPTIONOFFSET] +; str r7,[sp,r11] +; +; ldr r7,[r8,#TARGET_THREAD_EXCEPTIONHANDLER] +; bx r7 +; +;vmInvoke_exit +;endif ; AVIAN_CONTINUATIONS + + mov ip, #0 + str ip, [r8, #TARGET_THREAD_STACK] + + ; restore return type + ldr ip, [sp], #4 + + ; restore callee-saved registers + ldmfd sp!, {r4-r11, lr} + +vmInvoke_return + bx lr + + EXPORT vmJumpAndInvoke +vmJumpAndInvoke +;if :DEF:AVIAN_CONTINUATIONS +; ; r0: thread +; ; r1: address +; ; r2: stack +; ; r3: argumentFootprint +; ; [sp,#0]: arguments +; ; [sp,#4]: frameSize +; +; ldr r5,[sp,#0] +; ldr r6,[sp,#4] +; +; ; allocate new frame, adding room for callee-saved registers, plus +; ; 4 bytes of padding since the calculation of frameSize assumes 4 +; ; bytes have already been allocated to save the return address, +; ; which is not true in this case +; sub r2,r2,r6 +; sub r2,r2,#84 +; +; mov r8,r0 +; +; ; copy arguments into place +; mov r6,#0 +; b vmJumpAndInvoke_argumentTest +; +;vmJumpAndInvoke_argumentLoop +; ldr r12,[r5,r6] +; str r12,[r2,r6] +; add r6,r6,#4 +; +;vmJumpAndInvoke_argumentTest +; cmp r6,r3 +; ble vmJumpAndInvoke_argumentLoop +; +; ; the arguments have been copied, so we can set the real stack +; ; pointer now +; mov sp,r2 +; +; ; set return address to vmInvoke_returnAddress +; ldr r10,vmInvoke_returnAddress_word) +; ldr r11,vmJumpAndInvoke_getAddress_word) +;vmJumpAndInvoke_getAddress +; add r11,pc,r11 +; ldr lr,[r11,r10] +; +; bx r1 +; +;vmInvoke_returnAddress_word +; .word GLOBAL(vmInvoke_returnAddress)(GOT) +;vmInvoke_getAddress_word +; .word _GLOBAL_OFFSET_TABLE_-(vmInvoke_getAddress)+8) +;vmJumpAndInvoke_getAddress_word +; .word _GLOBAL_OFFSET_TABLE_-(vmJumpAndInvoke_getAddress)+8) +; +;else ; not AVIAN_CONTINUATIONS + ; vmJumpAndInvoke should only be called when continuations are + ; enabled + bkpt 0 +;endif ; not AVIAN_CONTINUATIONS + + END \ No newline at end of file diff --git a/src/compile-x86.masm b/src/compile-x86.masm new file mode 100644 index 0000000000..f07d799faf --- /dev/null +++ b/src/compile-x86.masm @@ -0,0 +1,173 @@ +comment # + Copyright (c) 2008-2011, 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. + + ORIGIN: https://github.com/gkvas/avian/tree/wince +# + +.586 +.MODEL FLAT, C + +comment # types.h # +VOID_TYPE equ 0 +INT8_TYPE equ 1 +INT16_TYPE equ 2 +INT32_TYPE equ 3 +INT64_TYPE equ 4 +FLOAT_TYPE equ 5 +DOUBLE_TYPE equ 6 +POINTER_TYPE equ 7 + +comment # target-fields.h # +ifdef TARGET_BYTES_PER_WORD + if TARGET_BYTES_PER_WORD eq 8 + +TARGET_THREAD_EXCEPTION equ 80 +TARGET_THREAD_EXCEPTIONSTACKADJUSTMENT equ 2256 +TARGET_THREAD_EXCEPTIONOFFSET equ 2264 +TARGET_THREAD_EXCEPTIONHANDLER equ 2272 + +TARGET_THREAD_IP equ 2216 +TARGET_THREAD_STACK equ 2224 +TARGET_THREAD_NEWSTACK equ 2232 +TARGET_THREAD_SCRATCH equ 2240 +TARGET_THREAD_CONTINUATION equ 2248 +TARGET_THREAD_TAILADDRESS equ 2280 +TARGET_THREAD_VIRTUALCALLTARGET equ 2288 +TARGET_THREAD_VIRTUALCALLINDEX equ 2296 +TARGET_THREAD_HEAPIMAGE equ 2304 +TARGET_THREAD_CODEIMAGE equ 2312 +TARGET_THREAD_THUNKTABLE equ 2320 +TARGET_THREAD_STACKLIMIT equ 2368 + + elseif TARGET_BYTES_PER_WORD eq 4 + +TARGET_THREAD_EXCEPTION equ 44 +TARGET_THREAD_EXCEPTIONSTACKADJUSTMENT equ 2164 +TARGET_THREAD_EXCEPTIONOFFSET equ 2168 +TARGET_THREAD_EXCEPTIONHANDLER equ 2172 + +TARGET_THREAD_IP equ 2144 +TARGET_THREAD_STACK equ 2148 +TARGET_THREAD_NEWSTACK equ 2152 +TARGET_THREAD_SCRATCH equ 2156 +TARGET_THREAD_CONTINUATION equ 2160 +TARGET_THREAD_TAILADDRESS equ 2176 +TARGET_THREAD_VIRTUALCALLTARGET equ 2180 +TARGET_THREAD_VIRTUALCALLINDEX equ 2184 +TARGET_THREAD_HEAPIMAGE equ 2188 +TARGET_THREAD_CODEIMAGE equ 2192 +TARGET_THREAD_THUNKTABLE equ 2196 +TARGET_THREAD_STACKLIMIT equ 2220 + + else + error + endif +else + error +endif + +ifdef AVIAN_USE_FRAME_POINTER + ALIGNMENT_ADJUSTMENT equ 0 +else + ALIGNMENT_ADJUSTMENT equ 12 +endif + +CALLEE_SAVED_REGISTER_FOOTPRINT equ 16 + ALIGNMENT_ADJUSTMENT + +_TEXT SEGMENT + +public C vmInvoke +vmInvoke: + push ebp + mov ebp,esp + + ; 8(%ebp): thread + ; 12(%ebp): function + ; 16(%ebp): arguments + ; 20(%ebp): argumentFootprint + ; 24(%ebp): frameSize + ; 28(%ebp): returnType + + ; allocate stack space for callee-saved registers + sub esp,offset CALLEE_SAVED_REGISTER_FOOTPRINT + + ; remember this stack position, since we won't be able to rely on + ; %rbp being restored when the call returns + mov eax,ds:dword ptr[8+ebp] + mov ds:dword ptr[TARGET_THREAD_SCRATCH+eax],esp + + mov ds:dword ptr[0+esp],ebx + mov ds:dword ptr[4+esp],esi + mov ds:dword ptr[8+esp],edi + + ; allocate stack space for arguments + sub esp,ds:dword ptr[24+ebp] + + ; we use ebx to hold the thread pointer, by convention + mov ebx,eax + + ; copy arguments into place + mov ecx,0 + mov edx,ds:dword ptr[16+ebp] + jmp LvmInvoke_argumentTest + +LvmInvoke_argumentLoop: + mov eax,ds:dword ptr[edx+ecx*1] + mov ds:dword ptr[esp+ecx*1],eax + add ecx,4 + +LvmInvoke_argumentTest: + cmp ecx,ds:dword ptr[20+ebp] + jb LvmInvoke_argumentLoop + + ; call function + call dword ptr[12+ebp] + +public vmInvoke_returnAddress +vmInvoke_returnAddress: + ; restore stack pointer + mov esp,ds:dword ptr[TARGET_THREAD_SCRATCH+ebx] + + ; clear MyThread::stack to avoid confusing another thread calling + ; java.lang.Thread.getStackTrace on this one. See + ; MyProcess::getStackTrace in compile.cpp for details on how we get + ; a reliable stack trace from a thread that might be interrupted at + ; any point in its execution. + mov ds:dword ptr[TARGET_THREAD_STACK+ebx],0 + +public vmInvoke_safeStack +vmInvoke_safeStack: + + ; restore callee-saved registers + mov ebx,ds:dword ptr[0+esp] + mov esi,ds:dword ptr[4+esp] + mov edi,ds:dword ptr[8+esp] + + add esp,offset CALLEE_SAVED_REGISTER_FOOTPRINT + + mov ecx,ds:dword ptr[28+esp] + + pop ebp + ret + +LgetPC: + mov esi,ds:dword ptr[esp] + ret + +public vmJumpAndInvoke +vmJumpAndInvoke: + ; vmJumpAndInvoke should only be called when continuations are + ; enabled + int 3 + +_TEXT ENDS + +END From 2d11e7ccd40fa27194d3e97b81b8ada9269ac730 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 28 Jan 2013 01:46:15 +0100 Subject: [PATCH 067/106] Add last modified to file --- classpath/java-io.cpp | 22 ++++++++++++++++++++++ classpath/java/io/File.java | 7 +++++++ 2 files changed, 29 insertions(+) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index db9882e051..c12ee64368 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -541,6 +541,28 @@ Java_java_io_File_openDir(JNIEnv* e, jclass, jstring path) } } +extern "C" JNIEXPORT jlong JNICALL +Java_java_io_File_lastModified(JNIEnv* e, jclass, jstring path) +{ + string_t chars = getChars(e, path); + if (chars) { + #ifdef PLATFORM_WINDOWS + # error "Implementation of last modified :)" + #else + struct stat st; + if (stat(chars, &st)) { + return 0; + } else { + return (static_cast(st.st_mtim.tv_sec) * 1000) + + (static_cast(st.st_mtim.tv_nsec) / (1000*1000)); + } + + #endif + } else { + return 0; + } +} + extern "C" JNIEXPORT jstring JNICALL Java_java_io_File_readDir(JNIEnv* e, jclass, jlong handle) { diff --git a/classpath/java/io/File.java b/classpath/java/io/File.java index b66aa03ff9..8eceed4b71 100644 --- a/classpath/java/io/File.java +++ b/classpath/java/io/File.java @@ -294,12 +294,19 @@ public class File implements Serializable { } } + public long lastModified() { + return lastModified(path); + } private static native long openDir(String path); + private static native long lastModified(String path); + private static native String readDir(long handle); private static native long closeDir(long handle); + + private static class Pair { public final String value; public final Pair next; From 5e0b073eff7466e5535f006ef61c1b8fae952f70 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Tue, 29 Jan 2013 12:44:55 +0200 Subject: [PATCH 068/106] Fix library overwriting ; proper assembler flags --- makefile | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/makefile b/makefile index 29465173c1..d21344e852 100755 --- a/makefile +++ b/makefile @@ -666,7 +666,7 @@ ifeq ($(platform),wp8) as = "$$(cygpath -u "$(WP80_SDK)\bin\x86_arm\armasm.exe")" cxx = "$$(cygpath -u "$(WP80_SDK)\bin\x86_arm\cl.exe")" ld = "$$(cygpath -u "$(WP80_SDK)\bin\x86_arm\link.exe")" - asmflags = -machine ARM -32 + asmflags = $(target-cflags) -machine ARM -32 asm-output = -o $(1) asm-input = $(1) machine_type = ARM @@ -678,6 +678,7 @@ ifeq ($(platform),wp8) vc_arch = w8kit_arch = x86 deps_arch = x86 + asmflags = $(target-cflags) -safeseh as = "$$(cygpath -u "$(WP80_SDK)\bin\ml.exe")" cxx = "$$(cygpath -u "$(WP80_SDK)\bin\cl.exe")" ld = "$$(cygpath -u "$(WP80_SDK)\bin\link.exe")" @@ -705,12 +706,31 @@ ifeq ($(platform),wp8) common-lflags = $(classpath-lflags) + ifeq ($(mode),debug) + build-type = Debug + endif + ifeq ($(mode),debug-fast) + build-type = Debug + endif + ifeq ($(mode),stress_major) + build-type = Release + endif + ifeq ($(mode),fast) + build-type = Release + endif + ifeq ($(mode),fast) + build-type = Release + endif + ifeq ($(mode),small) + build-type = Release + endif + arflags = -MACHINE:$(machine_type) lflags = $(common-lflags) -nologo \ -MACHINE:$(machine_type) \ -LIBPATH:"$(WP80_KIT)\lib\$(w8kit_arch)" -LIBPATH:"$(WIN8_KIT)\Lib\win8\um\$(w8kit_arch)" -LIBPATH:"$(MSVC_ROOT)\lib$(vc_arch)" \ ws2_32.lib \ - "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\zlib.lib")" "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\ThreadEmulation.lib")" + "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\zlib.lib")" "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\ThreadEmulation.lib")" cc = $(cxx) asm-format = masm @@ -1508,8 +1528,8 @@ $(dynamic-library): $(vm-objects) $(dynamic-object) $(classpath-objects) \ $(lzma-decode-objects) @echo "linking $(@)" ifdef ms_cl_compiler - $(ld) $(shared) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \ - -IMPLIB:$(build)/$(name).lib $(manifest-flags) + $(ld) $(shared) $(lflags) $(^) -out:$(@) -PDB:$(subst .dll,.pdb,$(@)) \ + -IMPLIB:$(subst .dll,.lib,$(@)) $(manifest-flags) ifdef mt $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);2" endif From acdd297fb2662f6a86fa202076ca4033b4b0ee73 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Tue, 29 Jan 2013 14:21:02 +0200 Subject: [PATCH 069/106] Fixes to WP8/WinRT support --- classpath/java-io.cpp | 3 ++- makefile | 4 +--- src/bootimage.cpp | 14 ++++---------- src/windows.cpp | 4 ++-- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index c12ee64368..3860e67ecd 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -547,7 +547,8 @@ Java_java_io_File_lastModified(JNIEnv* e, jclass, jstring path) string_t chars = getChars(e, path); if (chars) { #ifdef PLATFORM_WINDOWS - # error "Implementation of last modified :)" + # pragma message("Implementation of last modified") + return 0; #else struct stat st; if (stat(chars, &st)) { diff --git a/makefile b/makefile index d21344e852..5044abd4d5 100755 --- a/makefile +++ b/makefile @@ -618,7 +618,7 @@ ifeq ($(platform),wp8) # Environment variable WP8_SDK not found. It should be something like # "C:\Program Files[ (x86)]\Microsoft Visual Studio 11.0\VC\WPSDK\WP80" # TODO: Lookup in SOFTWARE\Microsoft\Microsoft SDKs\WindowsPhone\v8.0 - WP80_SDK = C:\$(programFiles)\Microsoft Visual Studio 11.0\VC\WPSDK\WP80 + WP80_SDK = $(MSVS_ROOT)\VC\WPSDK\WP80 endif ifeq ($(WP80_KIT),) # Environment variable WP8_KIT not found. It should be something like @@ -670,8 +670,6 @@ ifeq ($(platform),wp8) asm-output = -o $(1) asm-input = $(1) machine_type = ARM - bootimage-symbols = binary_bootimage_bin_start:binary_bootimage_bin_end - codeimage-symbols = binary_codeimage_bin_start:binary_codeimage_bin_end endif ifeq ($(arch),i386) wp8_arch = diff --git a/src/bootimage.cpp b/src/bootimage.cpp index ec04196ca0..5b725f5058 100644 --- a/src/bootimage.cpp +++ b/src/bootimage.cpp @@ -1917,26 +1917,20 @@ public: exit(1); } -# if AVIAN_TARGET_FORMAT != AVIAN_FORMAT_PE -# define SYMBOL_PREFIX "_" -# else -# define SYMBOL_PREFIX -# endif - if(!bootimageStart) { - bootimageStart = strdup(SYMBOL_PREFIX"binary_bootimage_bin_start"); + bootimageStart = strdup("_binary_bootimage_bin_start"); } if(!bootimageEnd) { - bootimageEnd = strdup(SYMBOL_PREFIX"binary_bootimage_bin_end"); + bootimageEnd = strdup("_binary_bootimage_bin_end"); } if(!codeimageStart) { - codeimageStart = strdup(SYMBOL_PREFIX"binary_codeimage_bin_start"); + codeimageStart = strdup("_binary_codeimage_bin_start"); } if(!codeimageEnd) { - codeimageEnd = strdup(SYMBOL_PREFIX"binary_codeimage_bin_end"); + codeimageEnd = strdup("_binary_codeimage_bin_end"); } } diff --git a/src/windows.cpp b/src/windows.cpp index 8c7512eab1..d0b5228368 100644 --- a/src/windows.cpp +++ b/src/windows.cpp @@ -34,10 +34,10 @@ WaitForSingleObjectEx((hHandle), (dwMilliseconds), FALSE) #define CreateEvent(lpEventAttributes, bManualReset, bInitialState, lpName) \ - CreateEventEx((lpEventAttributes), (lpName), ((bManualReset)?CREATE_EVENT_MANUAL_RESET:0)|((bInitialState)?CREATE_EVENT_INITIAL_SET:0), EVENT_MODIFY_STATE) + CreateEventEx((lpEventAttributes), (lpName), ((bManualReset)?CREATE_EVENT_MANUAL_RESET:0)|((bInitialState)?CREATE_EVENT_INITIAL_SET:0), EVENT_ALL_ACCESS) #define CreateMutex(lpEventAttributes, bInitialOwner, lpName) \ - CreateMutexEx((lpEventAttributes), (lpName), (bInitialOwner)?CREATE_MUTEX_INITIAL_OWNER:0, MUTEX_MODIFY_STATE) + CreateMutexEx((lpEventAttributes), (lpName), (bInitialOwner)?CREATE_MUTEX_INITIAL_OWNER:0, MUTEX_ALL_ACCESS) #include "thread-emulation.h" From 4228f69a0d3b9bf8adaeba995ef98d8398a8ff4a Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Tue, 29 Jan 2013 19:23:22 +0200 Subject: [PATCH 070/106] Additional AOT_ONLY ifdef --- src/compile.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/compile.cpp b/src/compile.cpp index 7fa51817c7..d0cf31cfec 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -9339,11 +9339,15 @@ class MyProcessor: public Processor { root(t, MethodTreeSentinal)); } +#ifdef AVIAN_AOT_ONLY + thunks = bootThunks; +#else local::compileThunks(static_cast(t), &codeAllocator); if (not (image and code)) { bootThunks = thunks; } +#endif segFaultHandler.m = t->m; expect(t, t->m->system->success From aaa60aebff56a545f2fc08db751773f1efdedb2f Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Wed, 30 Jan 2013 07:31:02 +0200 Subject: [PATCH 071/106] Makefile changes, added additional compiler flags --- makefile | 110 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 59 insertions(+), 51 deletions(-) diff --git a/makefile b/makefile index 5044abd4d5..5db25dbe11 100755 --- a/makefile +++ b/makefile @@ -50,6 +50,7 @@ ifeq ($(continuations),true) options := $(options)-continuations endif +aot-only = false root := $(shell (cd .. && pwd)) build = build/$(platform)-$(arch)$(options) host-build-root = $(build)/host @@ -539,7 +540,6 @@ ifeq ($(platform),windows) lib = "$(win32)/lib" embed-prefix = c:/avian-embedded - system = windows so-prefix = @@ -642,7 +642,7 @@ ifeq ($(platform),wp8) use-lto = false supports_avian_executable = false process = compile - aot_only = true + aot-only = true ifneq ($(process),compile) options := -$(process) endif @@ -676,11 +676,16 @@ ifeq ($(platform),wp8) vc_arch = w8kit_arch = x86 deps_arch = x86 - asmflags = $(target-cflags) -safeseh + asmflags = $(target-cflags) -safeseh -nologo -Gd as = "$$(cygpath -u "$(WP80_SDK)\bin\ml.exe")" cxx = "$$(cygpath -u "$(WP80_SDK)\bin\cl.exe")" ld = "$$(cygpath -u "$(WP80_SDK)\bin\link.exe")" - asmflags += -nologo + ifeq ($(mode),debug) + asmflags += -Zd + endif + ifeq ($(mode),debug-fast) + asmflags += -Zd + endif asm-output = $(output) machine_type = X86 endif @@ -700,7 +705,8 @@ ifeq ($(platform),wp8) -Fd$(build)/$(name).pdb -I"$(shell $(windows-path) "$(wp8)/include")" -I$(src) -I$(classpath-src) \ -I"$(build)" \ -I"$(windows-java-home)/include" -I"$(windows-java-home)/include/win32" \ - -DTARGET_BYTES_PER_WORD=$(pointer-size) + -DTARGET_BYTES_PER_WORD=$(pointer-size) \ + -Gd common-lflags = $(classpath-lflags) @@ -783,6 +789,52 @@ ifeq ($(platform),wp8) strip = : endif +ifdef msvc + no-error = + windows-path = $(native-path) + windows-java-home := $(shell $(windows-path) "$(JAVA_HOME)") + zlib := $(shell $(windows-path) "$(win32)/msvc") + ms_cl_compiler = regular + cxx = "$(msvc)/BIN/cl.exe" + cc = $(cxx) + ld = "$(msvc)/BIN/link.exe" + mt = "mt.exe" + manifest-flags = -MANIFEST -MANIFESTFILE:$(@).manifest + cflags = -nologo -DAVIAN_VERSION=\"$(version)\" -D_JNI_IMPLEMENTATION_ \ + -DUSE_ATOMIC_OPERATIONS -DAVIAN_JAVA_HOME=\"$(javahome)\" \ + -DAVIAN_EMBED_PREFIX=\"$(embed-prefix)\" \ + -Fd$(build)/$(name).pdb -I"$(zlib)/include" -I$(src) -I$(classpath-src) \ + -I"$(build)" \ + -I"$(windows-java-home)/include" -I"$(windows-java-home)/include/win32" \ + -DTARGET_BYTES_PER_WORD=$(pointer-size) + + ifneq ($(lzma),) + cflags += -I$(shell $(windows-path) "$(lzma)") + endif + + shared = -dll + lflags = -nologo -LIBPATH:"$(zlib)/lib" -DEFAULTLIB:ws2_32 \ + -DEFAULTLIB:zlib -DEFAULTLIB:user32 -MANIFEST -debug + output = -Fo$(1) + + ifeq ($(mode),debug) + cflags += -Od -Zi -MDd + endif + ifeq ($(mode),debug-fast) + cflags += -Od -Zi -DNDEBUG + endif + ifeq ($(mode),fast) + cflags += -O2 -GL -Zi -DNDEBUG + lflags += -LTCG + endif + ifeq ($(mode),small) + cflags += -O1s -Zi -GL -DNDEBUG + lflags += -LTCG + endif + + strip = : +endif + ifeq ($(mode),debug) optimization-cflags = $(cflags_debug) converter-cflags += $(cflags_debug) @@ -842,51 +894,6 @@ endif endif endif -ifdef msvc - no-error = - windows-path = $(native-path) - windows-java-home := $(shell $(windows-path) "$(JAVA_HOME)") - zlib := $(shell $(windows-path) "$(win32)/msvc") - cxx = "$(msvc)/BIN/cl.exe" - cc = $(cxx) - ld = "$(msvc)/BIN/link.exe" - mt = "mt.exe" - manifest-flags = -MANIFEST -MANIFESTFILE:$(@).manifest - cflags = -nologo -DAVIAN_VERSION=\"$(version)\" -D_JNI_IMPLEMENTATION_ \ - -DUSE_ATOMIC_OPERATIONS -DAVIAN_JAVA_HOME=\"$(javahome)\" \ - -DAVIAN_EMBED_PREFIX=\"$(embed-prefix)\" \ - -Fd$(build)/$(name).pdb -I"$(zlib)/include" -I$(src) -I$(classpath-src) \ - -I"$(build)" \ - -I"$(windows-java-home)/include" -I"$(windows-java-home)/include/win32" \ - -DTARGET_BYTES_PER_WORD=$(pointer-size) - - ifneq ($(lzma),) - cflags += -I$(shell $(windows-path) "$(lzma)") - endif - - shared = -dll - lflags = -nologo -LIBPATH:"$(zlib)/lib" -DEFAULTLIB:ws2_32 \ - -DEFAULTLIB:zlib -DEFAULTLIB:user32 -MANIFEST -debug - output = -Fo$(1) - - ifeq ($(mode),debug) - cflags += -Od -Zi -MDd - endif - ifeq ($(mode),debug-fast) - cflags += -Od -Zi -DNDEBUG - endif - ifeq ($(mode),fast) - cflags += -O2 -GL -Zi -DNDEBUG - lflags += -LTCG - endif - ifeq ($(mode),small) - cflags += -O1s -Zi -GL -DNDEBUG - lflags += -LTCG - endif - - strip = : -endif - build-cflags += -DAVIAN_HOST_TARGET c-objects = $(foreach x,$(1),$(patsubst $(2)/%.c,$(3)/%.o,$(x))) @@ -938,7 +945,7 @@ ifeq ($(process),compile) vm-asm-sources += $(src)/compile-$(asm).$(asm-format) endif cflags += -DAVIAN_PROCESS_$(process) -ifdef aot_only +ifeq ($(aot-only),true) cflags += -DAVIAN_AOT_ONLY endif @@ -1488,6 +1495,7 @@ $(bootimage-generator): $(bootimage-generator-objects) $(MAKE) mode=$(mode) \ build=$(host-build-root) \ arch=$(build-arch) \ + aot-only=false \ target-arch=$(arch) \ platform=$(bootimage-platform) \ target-format=$(target-format) \ From d51db00136422d464ece304a489f5b3cbbe5ea47 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Wed, 30 Jan 2013 10:42:05 +0200 Subject: [PATCH 072/106] Allow output of exceptions to debugger. Generate WinMD file --- makefile | 46 ++++++++++++++++++++++++++++------------------ src/machine.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 19 deletions(-) diff --git a/makefile b/makefile index 5db25dbe11..7c5123f33f 100755 --- a/makefile +++ b/makefile @@ -593,8 +593,8 @@ ifeq ($(platform),windows) shared += -Wl,--add-stdcall-alias endif - embed = $(build-embed)/embed.exe - embed-loader = $(build-embed-loader)/embed-loader.exe + embed = $(build-embed)/embed$(exe-suffix) + embed-loader = $(build-embed-loader)/embed-loader$(exe-suffix) embed-loader-o = $(build-embed)/embed-loader.o endif @@ -657,6 +657,7 @@ ifeq ($(platform),wp8) so-prefix = so-suffix = .dll exe-suffix = .exe + manifest-flags = -MANIFEST:NO ifeq ($(arch),arm) wp8_arch = \x86_arm @@ -696,8 +697,9 @@ ifeq ($(platform),wp8) build-lflags = -lz -lpthread cflags = -nologo \ + -AI"$(WP80_KIT)\Windows Metadata" \ -I"$(WP80_SDK)\include" -I"$(WP80_KIT)\Include" -I"$(WP80_KIT)\Include\minwin" -I"$(WP80_KIT)\Include\mincore" \ - -DWINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP \ + -DWINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP -D_USRDLL -D_WINDLL \ -DAVIAN_VERSION=\"$(version)\" -D_JNI_IMPLEMENTATION_ \ -DUSE_ATOMIC_OPERATIONS -DAVIAN_JAVA_HOME=\"$(javahome)\" \ -DAVIAN_EMBED_PREFIX=\"$(embed-prefix)\" \ @@ -735,6 +737,11 @@ ifeq ($(platform),wp8) -LIBPATH:"$(WP80_KIT)\lib\$(w8kit_arch)" -LIBPATH:"$(WIN8_KIT)\Lib\win8\um\$(w8kit_arch)" -LIBPATH:"$(MSVC_ROOT)\lib$(vc_arch)" \ ws2_32.lib \ "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\zlib.lib")" "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\ThreadEmulation.lib")" + lflags += -NXCOMPAT -DYNAMICBASE -SUBSYSTEM:CONSOLE -TLBID:1 + lflags += -NODEFAULTLIB:"ole32.lib" WindowsPhoneCore.lib + lflags += -WINMD -WINMDFILE:$(subst $(so-suffix),.winmd,$(@)) + #lflags += -WINMD:NO + #lflags += -APPCONTAINER cc = $(cxx) asm-format = masm @@ -750,6 +757,7 @@ ifeq ($(platform),wp8) endif output = -Fo$(1) + #TODO: -MT or -ZW? cflags_debug = -Od -Zi -MDd cflags_debug_fast = -Od -Zi -MDd cflags_stress = -O0 -g3 -MD @@ -1079,10 +1087,10 @@ converter-objects = $(call cpp-objects,$(converter-sources),$(src),$(build)) converter-tool-objects = $(call cpp-objects,$(converter-tool-sources),$(src),$(build)) converter = $(build)/binaryToObject/binaryToObject -static-library = $(build)/$(static-prefix)$(name)${static-suffix} +static-library = $(build)/$(static-prefix)$(name)$(static-suffix) executable = $(build)/$(name)${exe-suffix} dynamic-library = $(build)/$(so-prefix)jvm$(so-suffix) -executable-dynamic = $(build)/$(name)-dynamic${exe-suffix} +executable-dynamic = $(build)/$(name)-dynamic$(exe-suffix) ifneq ($(classpath),avian) # Assembler, ConstantPool, and Stream are not technically needed for a @@ -1307,7 +1315,8 @@ $(test-cpp-objects): $(test-build)/%.o: $(test)/%.cpp $(vm-depends) $(test-library): $(test-cpp-objects) @echo "linking $(@)" ifdef ms_cl_compiler - $(ld) $(shared) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \ + $(ld) $(shared) $(lflags) $(^) -out:$(@) \ + -debug -PDB:$(subst $(so-suffix),.pdb,$(@)) \ -IMPLIB:$(test-build)/$(name).lib $(manifest-flags) ifdef mt $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);2" @@ -1320,8 +1329,8 @@ ifdef embed $(embed): $(embed-objects) $(embed-loader-o) @echo "building $(embed)" ifdef ms_cl_compiler - $(ld) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \ - -IMPLIB:$(@).lib $(manifest-flags) + $(ld) $(lflags) $(^) -out:$(@) \ + -debug -PDB:$(subst $(exe-suffix),.pdb,$(@)) $(manifest-flags) ifdef mt $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" endif @@ -1343,8 +1352,8 @@ $(embed-loader): $(embed-loader-objects) $(static-library) @mkdir -p $(dir $(@)) cd $(dir $(@)) && $(ar) x ../../../$(static-library) ifdef ms_cl_compiler - $(ld) $(lflags) $(dir $(@))/*.o -out:$(@) -PDB:$(@).pdb \ - -IMPLIB:$(@).lib $(manifest-flags) + $(ld) $(lflags) $(dir $(@))/*.o -out:$(@) \ + -debug -PDB:$(subst $(exe-suffix),.pdb,$(@)) $(manifest-flags) ifdef mt $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" endif @@ -1475,8 +1484,8 @@ $(executable): $(executable-objects) @echo "linking $(@)" ifeq ($(platform),windows) ifdef ms_cl_compiler - $(ld) $(lflags) $(executable-objects) -out:$(@) -PDB:$(@).pdb \ - -IMPLIB:$(@).lib $(manifest-flags) + $(ld) $(lflags) $(executable-objects) -out:$(@) \ + -debug -PDB:$(subst $(exe-suffix),.pdb,$(@)) $(manifest-flags) ifdef mt $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" endif @@ -1514,8 +1523,8 @@ $(build-bootimage-generator): \ @echo "linking $(@)" ifeq ($(platform),windows) ifdef ms_cl_compiler - $(ld) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \ - -IMPLIB:$(@).lib $(manifest-flags) + $(ld) $(bootimage-generator-lflags) $(lflags) $(^) -out:$(@) \ + -debug -PDB:$(subst $(exe-suffix),.pdb,$(@)) $(manifest-flags) ifdef mt $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" endif @@ -1534,8 +1543,9 @@ $(dynamic-library): $(vm-objects) $(dynamic-object) $(classpath-objects) \ $(lzma-decode-objects) @echo "linking $(@)" ifdef ms_cl_compiler - $(ld) $(shared) $(lflags) $(^) -out:$(@) -PDB:$(subst .dll,.pdb,$(@)) \ - -IMPLIB:$(subst .dll,.lib,$(@)) $(manifest-flags) + $(ld) $(shared) $(lflags) $(^) -out:$(@) \ + -debug -PDB:$(subst $(so-suffix),.pdb,$(@)) \ + -IMPLIB:$(subst $(so-suffix),.lib,$(@)) $(manifest-flags) ifdef mt $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);2" endif @@ -1552,8 +1562,8 @@ $(executable-dynamic): $(driver-dynamic-objects) $(dynamic-library) @echo "linking $(@)" ifdef ms_cl_compiler $(ld) $(lflags) -LIBPATH:$(build) -DEFAULTLIB:$(name) \ - -PDB:$(@).pdb -IMPLIB:$(@).lib $(driver-dynamic-objects) \ - -out:$(@) $(manifest-flags) + -debug -PDB:$(subst $(exe-suffix),.pdb,$(@)) + $(driver-dynamic-objects) -out:$(@) $(manifest-flags) ifdef mt $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" endif diff --git a/src/machine.cpp b/src/machine.cpp index 5e08655898..c3c398bd92 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -17,6 +17,11 @@ #include "arch.h" #include "lzma.h" +#if defined(PLATFORM_WINDOWS) +# define WIN32_LEAN_AND_MEAN +# include +#endif + using namespace vm; namespace { @@ -4741,18 +4746,33 @@ printTrace(Thread* t, object exception) for (object e = exception; e; e = throwableCause(t, e)) { if (e != exception) { fprintf(errorLog(t), "caused by: "); +#if defined(PLATFORM_WINDOWS) + OutputDebugStringA("caused by: "); +#endif } fprintf(errorLog(t), "%s", &byteArrayBody (t, className(t, objectClass(t, e)), 0)); - +#if defined(PLATFORM_WINDOWS) + OutputDebugStringA((const CHAR*)&byteArrayBody + (t, className(t, objectClass(t, e)), 0)); +#endif + if (throwableMessage(t, e)) { object m = throwableMessage(t, e); THREAD_RUNTIME_ARRAY(t, char, message, stringLength(t, m) + 1); stringChars(t, m, RUNTIME_ARRAY_BODY(message)); fprintf(errorLog(t), ": %s\n", RUNTIME_ARRAY_BODY(message)); +#if defined(PLATFORM_WINDOWS) + OutputDebugStringA(": "); + OutputDebugStringA(RUNTIME_ARRAY_BODY(message)); + OutputDebugStringA("\n"); +#endif } else { fprintf(errorLog(t), "\n"); +#if defined(PLATFORM_WINDOWS) + OutputDebugStringA("\n"); +#endif } object trace = throwableTrace(t, e); @@ -4767,16 +4787,35 @@ printTrace(Thread* t, object exception) (t, traceElementMethod(t, e), traceElementIp(t, e)); fprintf(errorLog(t), " at %s.%s ", class_, method); +#if defined(PLATFORM_WINDOWS) + OutputDebugStringA(" at "); + OutputDebugStringA((const CHAR*)class_); + OutputDebugStringA("."); + OutputDebugStringA((const CHAR*)method); + OutputDebugStringA(" "); +#endif switch (line) { case NativeLine: fprintf(errorLog(t), "(native)\n"); +#if defined(PLATFORM_WINDOWS) + OutputDebugStringA("(native)\n"); +#endif break; case UnknownLine: fprintf(errorLog(t), "(unknown line)\n"); +#if defined(PLATFORM_WINDOWS) + OutputDebugStringA("(unknown line)\n"); +#endif break; default: fprintf(errorLog(t), "(line %d)\n", line); +#if defined(PLATFORM_WINDOWS) + OutputDebugStringA("(line "); + char buf[35]; + OutputDebugStringA(itoa(line, buf, 10)); + OutputDebugStringA(")\n"); +#endif } } } From c6694287e93467181ed2508835f114580238c041 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Wed, 30 Jan 2013 11:31:06 +0200 Subject: [PATCH 073/106] Finally, proper jvm.dll linking for WP8 --- makefile | 8 +++----- src/machine.h | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/makefile b/makefile index 7c5123f33f..7d6200c476 100755 --- a/makefile +++ b/makefile @@ -734,14 +734,12 @@ ifeq ($(platform),wp8) arflags = -MACHINE:$(machine_type) lflags = $(common-lflags) -nologo \ -MACHINE:$(machine_type) \ - -LIBPATH:"$(WP80_KIT)\lib\$(w8kit_arch)" -LIBPATH:"$(WIN8_KIT)\Lib\win8\um\$(w8kit_arch)" -LIBPATH:"$(MSVC_ROOT)\lib$(vc_arch)" \ + -LIBPATH:"$(WP80_KIT)\lib\$(w8kit_arch)" -LIBPATH:"$(WP80_SDK)\lib$(vc_arch)" -LIBPATH:"$(WIN8_KIT)\Lib\win8\um\$(w8kit_arch)" \ ws2_32.lib \ "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\zlib.lib")" "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\ThreadEmulation.lib")" lflags += -NXCOMPAT -DYNAMICBASE -SUBSYSTEM:CONSOLE -TLBID:1 - lflags += -NODEFAULTLIB:"ole32.lib" WindowsPhoneCore.lib - lflags += -WINMD -WINMDFILE:$(subst $(so-suffix),.winmd,$(@)) - #lflags += -WINMD:NO - #lflags += -APPCONTAINER + lflags += -NODEFAULTLIB:"ole32.lib" -NODEFAULTLIB:"kernel32.lib" + lflags += PhoneAppModelHost.lib WindowsPhoneCore.lib -WINMD -WINMDFILE:$(subst $(so-suffix),.winmd,$(@)) cc = $(cxx) asm-format = masm diff --git a/src/machine.h b/src/machine.h index 420a0192cb..5a2812c2b7 100644 --- a/src/machine.h +++ b/src/machine.h @@ -2695,7 +2695,7 @@ throw_(Thread* t, object e) t->exception = e; - // printTrace(t, e); + printTrace(t, e); popResources(t); From 71052fa50c4a836901883730765c4221013e4255 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 31 Jan 2013 12:54:51 +0200 Subject: [PATCH 074/106] Fix WP8/WinRT ARM build --- makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/makefile b/makefile index 7d6200c476..355589ec02 100755 --- a/makefile +++ b/makefile @@ -667,10 +667,12 @@ ifeq ($(platform),wp8) as = "$$(cygpath -u "$(WP80_SDK)\bin\x86_arm\armasm.exe")" cxx = "$$(cygpath -u "$(WP80_SDK)\bin\x86_arm\cl.exe")" ld = "$$(cygpath -u "$(WP80_SDK)\bin\x86_arm\link.exe")" - asmflags = $(target-cflags) -machine ARM -32 + asmflags = -machine ARM -32 asm-output = -o $(1) asm-input = $(1) machine_type = ARM + bootimage-symbols = binary_bootimage_bin_start:binary_bootimage_bin_end + codeimage-symbols = binary_codeimage_bin_start:binary_codeimage_bin_end endif ifeq ($(arch),i386) wp8_arch = From c13149088ec630460e225aed010bec3a0d39c450 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 31 Jan 2013 12:55:12 +0200 Subject: [PATCH 075/106] Fix crash on memory validation --- src/windows.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/windows.cpp b/src/windows.cpp index d0b5228368..98fc8e5d96 100644 --- a/src/windows.cpp +++ b/src/windows.cpp @@ -924,7 +924,7 @@ class MySystem: public System { } #else #pragma message("TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ Windows.ApplicationModel.Package.Current.InstalledLocation") - return name; + return copy(allocator, name); #endif } From 9ed312451a220a970041b4182e00cc9b87ce5841 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 31 Jan 2013 14:54:23 +0200 Subject: [PATCH 076/106] Allow avian.bootstrap to accept multiple libraries --- src/jnienv.cpp | 10 ---------- src/jnienv.h | 10 ++++++++++ src/machine.cpp | 23 ++++++++++++++++++++++- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/jnienv.cpp b/src/jnienv.cpp index 2a70b10855..c8f27fb0b7 100644 --- a/src/jnienv.cpp +++ b/src/jnienv.cpp @@ -3709,16 +3709,6 @@ populateJNITables(JavaVMVTable* vmTable, JNIEnvVTable* envTable) } // namespace vm -#define BOOTSTRAP_PROPERTY "avian.bootstrap" -#define CRASHDIR_PROPERTY "avian.crash.dir" -#define EMBED_PREFIX_PROPERTY "avian.embed.prefix" -#define CLASSPATH_PROPERTY "java.class.path" -#define JAVA_HOME_PROPERTY "java.home" -#define BOOTCLASSPATH_PREPEND_OPTION "bootclasspath/p" -#define BOOTCLASSPATH_OPTION "bootclasspath" -#define BOOTCLASSPATH_APPEND_OPTION "bootclasspath/a" -#define BOOTCLASSPATH_APPEND_OPTION "bootclasspath/a" - extern "C" JNIEXPORT jint JNICALL JNI_GetDefaultJavaVMInitArgs(void*) { diff --git a/src/jnienv.h b/src/jnienv.h index 5b8c46685b..8dbd1f8c7d 100644 --- a/src/jnienv.h +++ b/src/jnienv.h @@ -13,6 +13,16 @@ #include "machine.h" +#define BOOTSTRAP_PROPERTY "avian.bootstrap" +#define CRASHDIR_PROPERTY "avian.crash.dir" +#define EMBED_PREFIX_PROPERTY "avian.embed.prefix" +#define CLASSPATH_PROPERTY "java.class.path" +#define JAVA_HOME_PROPERTY "java.home" +#define BOOTCLASSPATH_PREPEND_OPTION "bootclasspath/p" +#define BOOTCLASSPATH_OPTION "bootclasspath" +#define BOOTCLASSPATH_APPEND_OPTION "bootclasspath/a" +#define BOOTCLASSPATH_APPEND_OPTION "bootclasspath/a" + namespace vm { void diff --git a/src/machine.cpp b/src/machine.cpp index c3c398bd92..e060cd0a9e 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -3008,6 +3008,13 @@ Machine::Machine(System* system, Heap* heap, Finder* bootFinder, populateJNITables(&javaVMVTable, &jniEnvVTable); + const char* bootstrapProperty = strdup(findProperty(this, BOOTSTRAP_PROPERTY)); + const char* bootstrapPropertyEnd = bootstrapProperty + (bootstrapProperty ? strlen(bootstrapProperty) : 0); + char* codeLibraryName = (char*)bootstrapProperty; + char* codeLibraryNameEnd = 0; + if (codeLibraryName && (codeLibraryNameEnd = strchr(codeLibraryName, system->pathSeparator()))) + *codeLibraryNameEnd = 0; + if (not system->success(system->make(&localThread)) or not system->success(system->make(&stateLock)) or not system->success(system->make(&heapLock)) or @@ -3015,10 +3022,24 @@ Machine::Machine(System* system, Heap* heap, Finder* bootFinder, not system->success(system->make(&referenceLock)) or not system->success(system->make(&shutdownLock)) or not system->success - (system->load(&libraries, findProperty(this, "avian.bootstrap")))) + (system->load(&libraries, bootstrapProperty))) { system->abort(); } + + System::Library* additionalLibrary = 0; + while (codeLibraryNameEnd && codeLibraryNameEnd + 1 < bootstrapPropertyEnd) { + codeLibraryName = codeLibraryNameEnd + 1; + codeLibraryNameEnd = strchr(codeLibraryName, system->pathSeparator()); + if (codeLibraryNameEnd) + *codeLibraryNameEnd = 0; + + if (!system->success(system->load(&additionalLibrary, codeLibraryName))) + system->abort(); + libraries->setNext(additionalLibrary); + } + + free((void*)bootstrapProperty); } void From bde33c97f8852fbdf78cce2adc3f35bc47e47138 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 31 Jan 2013 22:06:35 +0200 Subject: [PATCH 077/106] Fix crash if no avian.boostrap is specified --- src/machine.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/machine.cpp b/src/machine.cpp index e060cd0a9e..a0cd3184ce 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -3008,7 +3008,8 @@ Machine::Machine(System* system, Heap* heap, Finder* bootFinder, populateJNITables(&javaVMVTable, &jniEnvVTable); - const char* bootstrapProperty = strdup(findProperty(this, BOOTSTRAP_PROPERTY)); + const char* bootstrapProperty = findProperty(this, BOOTSTRAP_PROPERTY); + const char* bootstrapPropertyDup = bootstrapProperty ? strdup(bootstrapProperty) : 0; const char* bootstrapPropertyEnd = bootstrapProperty + (bootstrapProperty ? strlen(bootstrapProperty) : 0); char* codeLibraryName = (char*)bootstrapProperty; char* codeLibraryNameEnd = 0; @@ -3039,7 +3040,8 @@ Machine::Machine(System* system, Heap* heap, Finder* bootFinder, libraries->setNext(additionalLibrary); } - free((void*)bootstrapProperty); + if(bootstrapPropertyDup) + free((void*)bootstrapPropertyDup); } void From bd2a836395b649fb491bf9596d495faec93c4918 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 31 Jan 2013 22:07:56 +0200 Subject: [PATCH 078/106] Fix crash if no avian.boostrap is specified (oops) --- src/machine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/machine.cpp b/src/machine.cpp index a0cd3184ce..dce3bfe185 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -3011,7 +3011,7 @@ Machine::Machine(System* system, Heap* heap, Finder* bootFinder, const char* bootstrapProperty = findProperty(this, BOOTSTRAP_PROPERTY); const char* bootstrapPropertyDup = bootstrapProperty ? strdup(bootstrapProperty) : 0; const char* bootstrapPropertyEnd = bootstrapProperty + (bootstrapProperty ? strlen(bootstrapProperty) : 0); - char* codeLibraryName = (char*)bootstrapProperty; + char* codeLibraryName = (char*)bootstrapPropertyDup; char* codeLibraryNameEnd = 0; if (codeLibraryName && (codeLibraryNameEnd = strchr(codeLibraryName, system->pathSeparator()))) *codeLibraryNameEnd = 0; From d0ac63292cb1b62a1cb315fac415b1d06cde702c Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 31 Jan 2013 22:08:26 +0200 Subject: [PATCH 079/106] Fix crash if no avian.boostrap is specified (oops) --- src/machine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/machine.cpp b/src/machine.cpp index dce3bfe185..84a34caf67 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -3010,7 +3010,7 @@ Machine::Machine(System* system, Heap* heap, Finder* bootFinder, const char* bootstrapProperty = findProperty(this, BOOTSTRAP_PROPERTY); const char* bootstrapPropertyDup = bootstrapProperty ? strdup(bootstrapProperty) : 0; - const char* bootstrapPropertyEnd = bootstrapProperty + (bootstrapProperty ? strlen(bootstrapProperty) : 0); + const char* bootstrapPropertyEnd = bootstrapPropertyDup + (bootstrapPropertyDup ? strlen(bootstrapPropertyDup) : 0); char* codeLibraryName = (char*)bootstrapPropertyDup; char* codeLibraryNameEnd = 0; if (codeLibraryName && (codeLibraryNameEnd = strchr(codeLibraryName, system->pathSeparator()))) From 74c9f60b98d92590d780f37a87db19b795168a2a Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 31 Jan 2013 22:10:42 +0200 Subject: [PATCH 080/106] Fix crash if no avian.boostrap is specified (oops) --- src/machine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/machine.cpp b/src/machine.cpp index 84a34caf67..d2d225e7e5 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -3023,7 +3023,7 @@ Machine::Machine(System* system, Heap* heap, Finder* bootFinder, not system->success(system->make(&referenceLock)) or not system->success(system->make(&shutdownLock)) or not system->success - (system->load(&libraries, bootstrapProperty))) + (system->load(&libraries, bootstrapPropertyDup))) { system->abort(); } From c3b437a381d4a8201f39d514c8a86c632bc5159f Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Fri, 1 Feb 2013 16:36:29 +0200 Subject: [PATCH 081/106] Instead of throwing exception, just return initial file name --- classpath/java-io.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index 3860e67ecd..580efe96d2 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -240,8 +240,8 @@ Java_java_io_File_toAbsolutePath(JNIEnv* e UNUSED, jclass, jstring path) return path; # else - // WinRT has no concept of full paths - throwNewErrno(e, "java/io/IOException"); + // WinRT has no concept of full paths, so any file + // accessed should already have full path, or it has explicit origin return path; # endif #else From 9d8c825cbc2c3090cbe0dfca3e919a32e62a48c5 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Fri, 1 Feb 2013 16:40:12 +0200 Subject: [PATCH 082/106] Remove debug code --- classpath/java-io.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index 580efe96d2..bb1adce8b3 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -700,9 +700,6 @@ Java_java_io_FileOutputStream_open(JNIEnv* e, jclass, jstring path, jboolean app return -1; } } -#ifdef __ANDROID__ -#include -#endif extern "C" JNIEXPORT void JNICALL Java_java_io_FileOutputStream_write__II(JNIEnv* e, jclass, jint fd, jint c) @@ -723,11 +720,6 @@ Java_java_io_FileOutputStream_write__I_3BII } e->GetByteArrayRegion(b, offset, length, data); - #ifdef __ANDROID__ - if(fd == 1) { - __android_log_print(ANDROID_LOG_WARN, "net.osmand:native", "%.*s",length, data); - } - #endif if (not e->ExceptionCheck()) { doWrite(e, fd, data, length); } From 11eda6af3e532794d4ee42863958f29a58358e9e Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Fri, 1 Feb 2013 16:55:37 +0200 Subject: [PATCH 083/106] java.io.RandomAccessFile for WinPhone8 / WinRT --- classpath/java-io.cpp | 57 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index bb1adce8b3..39186a0274 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -739,6 +739,9 @@ Java_java_io_RandomAccessFile_open(JNIEnv* e, jclass, jstring path, { string_t chars = getChars(e, path); if (chars) { + jlong peer = 0; + jlong length = 0; + #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) int fd = ::open((const char*)chars, O_RDONLY); releaseChars(e, path, chars); if (fd == -1) { @@ -751,11 +754,27 @@ Java_java_io_RandomAccessFile_open(JNIEnv* e, jclass, jstring path, throwNewErrno(e, "java/io/IOException"); return; } + peer = fd; + length = fileStats.st_size; + #else + HANDLE hFile = CreateFile2 + (chars, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr); + if (hFile == INVALID_HANDLE_VALUE) { + throwNewErrno(e, "java/io/IOException"); + return; + } + + FILE_STANDARD_INFO info; + if(!GetFileInformationByHandleEx(hFile, FileStandardInfo, &info, sizeof(info))) { + throwNewErrno(e, "java/io/IOException"); + return; + } + + peer = (jlong)hFile; + length = info.EndOfFile.QuadPart; + #endif - jlong peer = fd; e->SetLongArrayRegion(result, 0, 1, &peer); - - jlong length = fileStats.st_size; e->SetLongArrayRegion(result, 1, 1, &length); } } @@ -765,6 +784,7 @@ Java_java_io_RandomAccessFile_readBytes(JNIEnv* e, jclass, jlong peer, jlong position, jbyteArray buffer, int offset, int length) { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) int fd = (int)peer; if(::lseek(fd, position, SEEK_SET) == -1) { throwNewErrno(e, "java/io/IOException"); @@ -773,24 +793,45 @@ Java_java_io_RandomAccessFile_readBytes(JNIEnv* e, jclass, jlong peer, uint8_t* dst = reinterpret_cast (e->GetPrimitiveArrayCritical(buffer, 0)); -#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + ssize_t bytesRead = ::read(fd, dst + offset, length); -#else - auto bytesRead = ::read(fd, dst + offset, length); -#endif e->ReleasePrimitiveArrayCritical(buffer, dst, 0); if(bytesRead == -1) { throwNewErrno(e, "java/io/IOException"); return -1; } - +#else + HANDLE hFile = (HANDLE)peer; + LARGE_INTEGER lPos; + lPos.QuadPart = position; + if(!SetFilePointerEx(hFile, lPos, nullptr, FILE_BEGIN)) { + throwNewErrno(e, "java/io/IOException"); + return -1; + } + + uint8_t* dst = reinterpret_cast + (e->GetPrimitiveArrayCritical(buffer, 0)); + + DWORD bytesRead = 0; + if(!ReadFile(hFile, dst + offset, length, &bytesRead, nullptr)) { + throwNewErrno(e, "java/io/IOException"); + return -1; + } + e->ReleasePrimitiveArrayCritical(buffer, dst, 0); +#endif + return (jint)bytesRead; } extern "C" JNIEXPORT void JNICALL Java_java_io_RandomAccessFile_close(JNIEnv* /* e*/, jclass, jlong peer) { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) int fd = (int)peer; ::close(fd); +#else + HANDLE hFile = (HANDLE)peer; + CloseHandle(hFile); +#endif } From e358a681b2714b8e7b3030f0071cc0199625bb75 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Fri, 1 Feb 2013 17:49:08 +0200 Subject: [PATCH 084/106] WP8/WinRT : Proper absolute path WP8/WinRT : Last modified time --- classpath/java-io.cpp | 122 +++++++++++++++++++++++++++++++----------- 1 file changed, 91 insertions(+), 31 deletions(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index 39186a0274..880d91cf56 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -240,8 +240,29 @@ Java_java_io_File_toAbsolutePath(JNIEnv* e UNUSED, jclass, jstring path) return path; # else - // WinRT has no concept of full paths, so any file - // accessed should already have full path, or it has explicit origin + string_t chars = getChars(e, path); + if(chars) { + LARGE_INTEGER fileSize; + HANDLE file = CreateFile2 + (chars, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr); + releaseChars(e, path, chars); + + if (file == INVALID_HANDLE_VALUE) + return path; + + uint8_t buffer[sizeof(FILE_NAME_INFO) + sizeof(WCHAR)*MAX_PATH]; + memset(&buffer[0], 0, sizeof(buffer)); + FILE_NAME_INFO* pInfo = reinterpret_cast(&buffer[0]); + if(!GetFileInformationByHandleEx(file, FileNameInfo, pInfo, sizeof(buffer))) + { + CloseHandle(file); + return path; + } + CloseHandle(file); + + return e->NewString + (reinterpret_cast(pInfo->FileName), pInfo->FileNameLength / sizeof(WCHAR)); + } return path; # endif #else @@ -267,33 +288,40 @@ Java_java_io_File_toAbsolutePath(JNIEnv* e UNUSED, jclass, jstring path) extern "C" JNIEXPORT jlong JNICALL Java_java_io_File_length(JNIEnv* e, jclass, jstring path) { - #ifdef PLATFORM_WINDOWS - LARGE_INTEGER fileSize; string_t chars = getChars(e, path); - #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) - HANDLE file = CreateFileW - (chars, FILE_READ_DATA, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); - #else - HANDLE file = CreateFile2 - (chars, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr); - #endif - releaseChars(e, path, chars); - if (file != INVALID_HANDLE_VALUE) - { + if(chars) { + LARGE_INTEGER fileSize; #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) - GetFileSizeEx(file, &fileSize); + HANDLE file = CreateFileW + (chars, FILE_READ_DATA, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); + #else + HANDLE file = CreateFile2 + (chars, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr); + #endif + releaseChars(e, path, chars); + if (file == INVALID_HANDLE_VALUE) + return 0; + #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + if(!GetFileSizeEx(file, &fileSize)) + { + CloseHandle(file); + return 0; + } #else FILE_STANDARD_INFO info; - if(GetFileInformationByHandleEx(file, FileStandardInfo, &info, sizeof(info))) - fileSize = info.EndOfFile; + if(!GetFileInformationByHandleEx(file, FileStandardInfo, &info, sizeof(info))) + { + CloseHandle(file); + return 0; + } + fileSize = info.EndOfFile; #endif - } - else return 0; - CloseHandle(file); - return static_cast(fileSize.QuadPart); + CloseHandle(file); + return static_cast(fileSize.QuadPart); + } #else string_t chars = getChars(e, path); @@ -547,21 +575,52 @@ Java_java_io_File_lastModified(JNIEnv* e, jclass, jstring path) string_t chars = getChars(e, path); if (chars) { #ifdef PLATFORM_WINDOWS - # pragma message("Implementation of last modified") - return 0; - #else - struct stat st; - if (stat(chars, &st)) { + #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + HANDLE hFile = CreateFileW + (chars, FILE_READ_DATA, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); + #else + HANDLE hFile = CreateFile2 + (chars, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr); + #endif + releaseChars(e, path, chars); + if (hFile == INVALID_HANDLE_VALUE) + return 0; + LARGE_INTEGER fileDate, filetimeToUnixEpochAdjustment; + filetimeToUnixEpochAdjustment.QuadPart = 11644473600000L * 10000L; + #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + FILETIME fileLastWriteTime; + if (!GetFileTime(hFile, 0, 0, &fileLastWriteTime)) + { + CloseHandle(hFile); + return 0; + } + fileDate.HighPart = fileLastWriteTime.dwHighDateTime; + fileDate.LowPart = fileLastWriteTime.dwLowDateTime; + #else + FILE_BASIC_INFO fileInfo; + if (!GetFileInformationByHandleEx(hFile, FileBasicInfo, &fileInfo, sizeof(fileInfo))) + { + CloseHandle(hFile); + return 0; + } + fileDate = fileInfo.ChangeTime; + #endif + CloseHandle(hFile); + fileDate.QuadPart -= filetimeToUnixEpochAdjustment.QuadPart; + return fileDate.QuadPart / 10000000L; + #else + struct stat fileStat; + if (stat(chars, &fileStat) == -1) { + releaseChars(e, path, chars); return 0; - } else { - return (static_cast(st.st_mtim.tv_sec) * 1000) + - (static_cast(st.st_mtim.tv_nsec) / (1000*1000)); } + return (static_cast(st.st_mtim.tv_sec) * 1000) + + (static_cast(st.st_mtim.tv_nsec) / (1000*1000)); #endif - } else { - return 0; } + + return 0; } extern "C" JNIEXPORT jstring JNICALL @@ -766,6 +825,7 @@ Java_java_io_RandomAccessFile_open(JNIEnv* e, jclass, jstring path, FILE_STANDARD_INFO info; if(!GetFileInformationByHandleEx(hFile, FileStandardInfo, &info, sizeof(info))) { + CloseHandle(hFile); throwNewErrno(e, "java/io/IOException"); return; } From 234bba59271a7cd0b95d6c880823b0556a3d34e0 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Fri, 1 Feb 2013 18:18:52 +0200 Subject: [PATCH 085/106] Add notifications about improvements possible --- classpath/java-io.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index 880d91cf56..74f2ab9617 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -289,7 +289,8 @@ extern "C" JNIEXPORT jlong JNICALL Java_java_io_File_length(JNIEnv* e, jclass, jstring path) { #ifdef PLATFORM_WINDOWS - + // Option: without opening file + // http://msdn.microsoft.com/en-us/library/windows/desktop/aa364946(v=vs.85).aspx string_t chars = getChars(e, path); if(chars) { LARGE_INTEGER fileSize; @@ -575,6 +576,8 @@ Java_java_io_File_lastModified(JNIEnv* e, jclass, jstring path) string_t chars = getChars(e, path); if (chars) { #ifdef PLATFORM_WINDOWS + // Option: without opening file + // http://msdn.microsoft.com/en-us/library/windows/desktop/aa364946(v=vs.85).aspx #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) HANDLE hFile = CreateFileW (chars, FILE_READ_DATA, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); From 6376a491b6170544259b1a00640e9112d1a0b236 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Fri, 1 Feb 2013 20:54:15 +0200 Subject: [PATCH 086/106] Added comments regarding java.io.File.toAbsolute() and WinRT/WP8 --- classpath/java-io.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index 74f2ab9617..3d26a49f02 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -240,6 +240,13 @@ Java_java_io_File_toAbsolutePath(JNIEnv* e UNUSED, jclass, jstring path) return path; # else +// This could have worked, if GetFileInformationByHandleEx() returned volume information also +// There is a chance to get it, or using GetFullPathName, that is claimed to be unsupported +// or from System.IO.Path.GetFullPath(), but it's CLR and I see no way of calling it from +// C++/CX code +// Best wishes to everyone who will win this fight, +// Alexey Pelykh +/* string_t chars = getChars(e, path); if(chars) { LARGE_INTEGER fileSize; @@ -263,6 +270,7 @@ Java_java_io_File_toAbsolutePath(JNIEnv* e UNUSED, jclass, jstring path) return e->NewString (reinterpret_cast(pInfo->FileName), pInfo->FileNameLength / sizeof(WCHAR)); } +*/ return path; # endif #else From 362f4aaa89fd09f784294a8703a14438105dd3af Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Sat, 2 Feb 2013 09:38:03 +0200 Subject: [PATCH 087/106] Support new WinRT interop --- classpath/java-io.cpp | 38 ++++++++++++++------------------------ makefile | 9 +++++---- 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index 3d26a49f02..ba4812a5a4 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -55,6 +55,15 @@ typedef wchar_t char_t; +#if defined(WINAPI_FAMILY) +#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + +#include "avian-interop.h" +#define SKIP_OPERATOR_NEW + +#endif +#endif + #else // not PLATFORM_WINDOWS # include @@ -93,7 +102,9 @@ typedef char char_t; # endif #endif // WINAPI_FAMILY +#if !defined(SKIP_OPERATOR_NEW) inline void* operator new(size_t, void* p) throw() { return p; } +#endif typedef const char_t* string_t; @@ -240,37 +251,16 @@ Java_java_io_File_toAbsolutePath(JNIEnv* e UNUSED, jclass, jstring path) return path; # else -// This could have worked, if GetFileInformationByHandleEx() returned volume information also -// There is a chance to get it, or using GetFullPathName, that is claimed to be unsupported -// or from System.IO.Path.GetFullPath(), but it's CLR and I see no way of calling it from -// C++/CX code -// Best wishes to everyone who will win this fight, -// Alexey Pelykh -/* string_t chars = getChars(e, path); if(chars) { - LARGE_INTEGER fileSize; - HANDLE file = CreateFile2 - (chars, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr); + std::wstring partialPath = chars; releaseChars(e, path, chars); - if (file == INVALID_HANDLE_VALUE) - return path; - - uint8_t buffer[sizeof(FILE_NAME_INFO) + sizeof(WCHAR)*MAX_PATH]; - memset(&buffer[0], 0, sizeof(buffer)); - FILE_NAME_INFO* pInfo = reinterpret_cast(&buffer[0]); - if(!GetFileInformationByHandleEx(file, FileNameInfo, pInfo, sizeof(buffer))) - { - CloseHandle(file); - return path; - } - CloseHandle(file); + std::wstring fullPath = AvianInterop::GetFullPath(partialPath); return e->NewString - (reinterpret_cast(pInfo->FileName), pInfo->FileNameLength / sizeof(WCHAR)); + (reinterpret_cast(fullPath.c_str()), fullPath.length()); } -*/ return path; # endif #else diff --git a/makefile b/makefile index 355589ec02..5877510956 100755 --- a/makefile +++ b/makefile @@ -705,12 +705,12 @@ ifeq ($(platform),wp8) -DAVIAN_VERSION=\"$(version)\" -D_JNI_IMPLEMENTATION_ \ -DUSE_ATOMIC_OPERATIONS -DAVIAN_JAVA_HOME=\"$(javahome)\" \ -DAVIAN_EMBED_PREFIX=\"$(embed-prefix)\" \ - -I"$(shell $(windows-path) "$(wp8)/zlib/upstream")" \ - -Fd$(build)/$(name).pdb -I"$(shell $(windows-path) "$(wp8)/include")" -I$(src) -I$(classpath-src) \ + -I"$(shell $(windows-path) "$(wp8)/zlib/upstream")" -I"$(shell $(windows-path) "$(wp8)/interop/avian-interop-client")" \ + -I"$(shell $(windows-path) "$(wp8)/include")" -I$(src) -I$(classpath-src) \ -I"$(build)" \ -I"$(windows-java-home)/include" -I"$(windows-java-home)/include/win32" \ -DTARGET_BYTES_PER_WORD=$(pointer-size) \ - -Gd + -Gd -EHsc common-lflags = $(classpath-lflags) @@ -738,7 +738,8 @@ ifeq ($(platform),wp8) -MACHINE:$(machine_type) \ -LIBPATH:"$(WP80_KIT)\lib\$(w8kit_arch)" -LIBPATH:"$(WP80_SDK)\lib$(vc_arch)" -LIBPATH:"$(WIN8_KIT)\Lib\win8\um\$(w8kit_arch)" \ ws2_32.lib \ - "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\zlib.lib")" "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\ThreadEmulation.lib")" + "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\zlib.lib")" "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\ThreadEmulation.lib")" \ + "$(shell $(windows-path) "$(wp8)\lib\$(deps_arch)\$(build-type)\AvianInteropClient.lib")" lflags += -NXCOMPAT -DYNAMICBASE -SUBSYSTEM:CONSOLE -TLBID:1 lflags += -NODEFAULTLIB:"ole32.lib" -NODEFAULTLIB:"kernel32.lib" lflags += PhoneAppModelHost.lib WindowsPhoneCore.lib -WINMD -WINMDFILE:$(subst $(so-suffix),.winmd,$(@)) From d6a5544f2b5144a09605e31a2cca3cbd36b7b4c5 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Sat, 2 Feb 2013 10:14:47 +0200 Subject: [PATCH 088/106] getErrorStr() for Windows platforms --- classpath/java-lang.cpp | 45 +++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index 9d2562e265..dc54af5fed 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -74,25 +74,36 @@ namespace { #ifdef PLATFORM_WINDOWS - char* getErrorStr(DWORD err){ - // The poor man's error string, just print the error code - char * errStr = (char*) malloc(9 * sizeof(char)); - snprintf(errStr, 9, "%d", (int) err); + +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + char* getErrorStr(DWORD err) { + LPSTR errorStr = 0; + if(!FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, err, LANG_SYSTEM_DEFAULT, (LPSTR)&errorStr, 0, 0)) + { + char* errStr = (char*) malloc(9 * sizeof(char)); + snprintf(errStr, 9, "%d", (int) err); + return errStr; + } + char* errStr = strdup(errorStr); + LocalFree(errorStr); return errStr; - - #pragma message("TODO") - // The better way to do this, if I could figure out how to convert LPTSTR to char* - //char* errStr; - //LPTSTR s; - //if(FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | - // FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, 0, &s, 0, NULL) == 0) - //{ - // errStr.Format("Unknown error occurred (%08x)", err); - //} else { - // errStr = s; - //} - //return errStr; } +#else + char* getErrorStr(DWORD err) { + LPSTR errorStr = (LPSTR)malloc(4096); //NOTE: something constant + if(!FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, err, LANG_SYSTEM_DEFAULT, errorStr, 0, 0)) + { + free(errorStr); + + char* errStr = (char*) malloc(9 * sizeof(char)); + snprintf(errStr, 9, "%d", (int) err); + return errStr; + } + char* errStr = strdup(errorStr); + free(errorStr); + return errStr; + } +#endif #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) void makePipe(JNIEnv* e, HANDLE p[2]) From e7ad04fc7a4026fad8682b993502b5c3a2f7abbc Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Sat, 2 Feb 2013 11:00:33 +0200 Subject: [PATCH 089/106] Culture fixes ; Path extensions --- classpath/java-lang.cpp | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index dc54af5fed..704e2ae6a5 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -69,6 +69,12 @@ # ifndef WINAPI_FAMILY_PARTITION # define WINAPI_FAMILY_PARTITION(x) (x) +# endif +#else +# if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + +# include "avian-interop.h" + # endif #endif // WINAPI_FAMILY @@ -401,8 +407,20 @@ Locale getLocale() { return Locale(lang, reg); #else - #pragma message("TODO: CultureInfo.CurrentCulture") - return Locale("en", "US"); + std::wstring culture = AvianInterop::GetCurrentUICulture(); + char* cultureName = strdup(std::string(culture.begin(), culture.end()).c_str()); + char* delimiter = strchr(cultureName, '-'); + if(!delimiter) + { + free(cultureName); + return Locale("en", "US"); + } + const char* lang = cultureName; + const char* reg = delimiter + 1; + *delimiter = 0; + Locale locale(lang, reg); + free(cultureName); + return locale; #endif } #else @@ -607,8 +625,8 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, GetTempPath(MAX_PATH, buffer); r = e->NewStringUTF(buffer); # else - #pragma message("TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ Windows.Storage.ApplicationData.Current.TemporaryFolder") - r = 0; + std::wstring tmpDir = AvianInterop::GetTemporaryFolder(); + r = e->NewString((const jchar*)tmpDir.c_str(), tmpDir.length()); # endif } else if (strcmp(chars, "user.dir") == 0) { # if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) @@ -616,8 +634,8 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, GetCurrentDirectory(MAX_PATH, buffer); r = e->NewStringUTF(buffer); # else - #pragma message("TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ Windows.ApplicationModel.Package.Current.InstalledLocation") - r = 0; + std::wstring userDir = AvianInterop::GetInstalledLocation(); + r = e->NewString((const jchar*)userDir.c_str(), userDir.length()); # endif } else if (strcmp(chars, "user.home") == 0) { # ifdef _MSC_VER @@ -630,8 +648,8 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, r = 0; } # else - #pragma message("TODO:http://lunarfrog.com/blog/2012/05/21/winrt-folders-access/ Windows.Storage.KnownFolders.DocumentsLibrary") - r = 0; + std::wstring userHome = AvianInterop::GetDocumentsLibraryLocation(); + r = e->NewString((const jchar*)userHome.c_str(), userHome.length()); # endif # else LPWSTR home = _wgetenv(L"USERPROFILE"); From b918389672f80208585a9cb424642b52a236a1b5 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Sat, 2 Feb 2013 12:27:36 +0200 Subject: [PATCH 090/106] Support built-in jars when wusing multi-library --- src/jnienv.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/jnienv.cpp b/src/jnienv.cpp index c8f27fb0b7..4295c7e0a3 100644 --- a/src/jnienv.cpp +++ b/src/jnienv.cpp @@ -3729,7 +3729,7 @@ JNI_CreateJavaVM(Machine** m, Thread** t, void* args) unsigned heapLimit = 0; unsigned stackLimit = 0; - const char* bootLibrary = 0; + const char* bootLibraries = 0; const char* classpath = 0; const char* javaHome = AVIAN_JAVA_HOME; const char* embedPrefix = AVIAN_EMBED_PREFIX; @@ -3765,7 +3765,7 @@ JNI_CreateJavaVM(Machine** m, Thread** t, void* args) if (strncmp(p, BOOTSTRAP_PROPERTY "=", sizeof(BOOTSTRAP_PROPERTY)) == 0) { - bootLibrary = p + sizeof(BOOTSTRAP_PROPERTY); + bootLibraries = p + sizeof(BOOTSTRAP_PROPERTY); } else if (strncmp(p, CRASHDIR_PROPERTY "=", sizeof(CRASHDIR_PROPERTY)) == 0) { @@ -3819,9 +3819,16 @@ JNI_CreateJavaVM(Machine** m, Thread** t, void* args) *RUNTIME_ARRAY_BODY(bootClasspathBuffer) = 0; } + char* bootLibrary = bootLibraries ? strdup(bootLibraries) : 0; + char* bootLibraryEnd = bootLibrary ? strchr(bootLibrary, PATH_SEPARATOR) : 0; + if(bootLibraryEnd) + *bootLibraryEnd = 0; + Finder* bf = makeFinder (s, h, RUNTIME_ARRAY_BODY(bootClasspathBuffer), bootLibrary); Finder* af = makeFinder(s, h, classpath, bootLibrary); + if(bootLibrary) + free(bootLibrary); Processor* p = makeProcessor(s, h, true); const char** properties = static_cast From 24e1e1a74561e1168e7c51d086cc3b3f25d62e14 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Sat, 2 Feb 2013 19:42:47 +0200 Subject: [PATCH 091/106] Remove empty lines Conflicts: classpath/java-lang.cpp --- classpath/java-lang.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index 704e2ae6a5..88a4cf5ef6 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -898,6 +898,11 @@ Java_java_lang_Math_atan(JNIEnv*, jclass, jdouble val) return atan(val); } +extern "C" JNIEXPORT jdouble JNICALL +Java_java_lang_Math_atan2(JNIEnv*, jclass, jdouble y, jdouble x) +{ + return atan2(y, x); +} extern "C" JNIEXPORT jdouble JNICALL Java_java_lang_Math_sinh(JNIEnv*, jclass, jdouble val) @@ -917,7 +922,6 @@ Java_java_lang_Math_tanh(JNIEnv*, jclass, jdouble val) return tanh(val); } - extern "C" JNIEXPORT jdouble JNICALL Java_java_lang_Math_sqrt(JNIEnv*, jclass, jdouble val) { From f3c443dbfa5496738aa71f547c9ef8276a2d2a55 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Sat, 2 Feb 2013 20:09:28 +0200 Subject: [PATCH 092/106] Fix dword<>qword mistake --- src/x86.masm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/x86.masm b/src/x86.masm index 640637d5af..2f9dedcbd2 100644 --- a/src/x86.masm +++ b/src/x86.masm @@ -108,7 +108,7 @@ Lfloat: Ldouble: cmp ecx,offset DOUBLE_TYPE jne Lexit - fstp ds:dword ptr[8+ebp] + fstp ds:qword ptr[8+ebp] mov eax,ds:dword ptr[8+ebp] mov edx,ds:dword ptr[12+ebp] From 197d4f7f8957f7f1227b308b965d34591e3bee96 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Sun, 3 Feb 2013 12:27:30 +0200 Subject: [PATCH 093/106] Make clean target more robust Conflicts: .gitignore --- .gitignore | 1 + makefile | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 201518bb12..588446f90d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ build bin /lib /distrib +*.pdb diff --git a/makefile b/makefile index 5877510956..6c846335fa 100755 --- a/makefile +++ b/makefile @@ -1248,6 +1248,11 @@ javadoc: .PHONY: clean clean: + @echo "removing $(build)" + rm -rf $(build) + +.PHONY: clean-all +clean-all: @echo "removing build" rm -rf build From e4bd01f7f36524fe7186e1c6bda5223d2ce8c51c Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Mon, 4 Feb 2013 19:45:06 +0200 Subject: [PATCH 094/106] Comment out printTrace --- src/machine.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/machine.h b/src/machine.h index 5a2812c2b7..420a0192cb 100644 --- a/src/machine.h +++ b/src/machine.h @@ -2695,7 +2695,7 @@ throw_(Thread* t, object e) t->exception = e; - printTrace(t, e); + // printTrace(t, e); popResources(t); From 83e55ce9cc33b470365bf62b999fcb563c1f7ec1 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Mon, 4 Feb 2013 20:02:46 +0200 Subject: [PATCH 095/106] RUNTIME_ARRAY usage --- src/arm.cpp | 5 +---- src/arm.h | 6 ++---- src/bootimage.cpp | 42 +++++++++++++++--------------------------- src/common.h | 4 ++++ src/interpret.cpp | 5 +---- 5 files changed, 23 insertions(+), 39 deletions(-) diff --git a/src/arm.cpp b/src/arm.cpp index 1d4dbc8dd1..3016c4658b 100644 --- a/src/arm.cpp +++ b/src/arm.cpp @@ -2555,7 +2555,7 @@ class MyAssembler: public Assembler { OperandType type; Operand* operand; }; - Argument* arguments = new Argument[argumentCount]; + RUNTIME_ARRAY(Argument, arguments, argumentCount); va_list a; va_start(a, argumentCount); unsigned footprint = 0; @@ -2590,9 +2590,6 @@ class MyAssembler: public Assembler { offset += ceiling(arguments[i].size, TargetBytesPerWord); } } - - delete[] arguments; - arguments = 0; } virtual void allocateFrame(unsigned footprint) { diff --git a/src/arm.h b/src/arm.h index 302355c453..5593c86f92 100644 --- a/src/arm.h +++ b/src/arm.h @@ -182,7 +182,7 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t* argumentTypes, unsigned vfpIndex = 0; unsigned vfpBackfillIndex UNUSED = 0; - uintptr_t* stack = new uintptr_t[(argumentCount * 8) / BytesPerWord]; // is > argumentSize to account for padding + RUNTIME_ARRAY(uintptr_t, stack, (argumentCount * 8) / BytesPerWord); // is > argumentSize to account for padding unsigned stackIndex = 0; unsigned ai = 0; @@ -272,12 +272,10 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t* argumentTypes, } unsigned stackSize = stackIndex*BytesPerWord + ((stackIndex & 1) << 2); - auto retVal = vmNativeCall + return vmNativeCall (function, stackSize, stack, stackIndex * BytesPerWord, (gprIndex ? gprTable : 0), (vfpIndex ? vfpTable : 0), returnType); - delete[] stack; - return retVal; } } // namespace vm diff --git a/src/bootimage.cpp b/src/bootimage.cpp index 5b725f5058..5ec14b51e6 100644 --- a/src/bootimage.cpp +++ b/src/bootimage.cpp @@ -342,7 +342,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, unsigned count = s.read2() - 1; if (count) { - Type* types = new Type[count + 2]; + RUNTIME_ARRAY(Type, types, count + 2); types[0] = Type_object; types[1] = Type_intptr_t; @@ -410,9 +410,6 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, (t, typeMaps, hashMapFind (t, root(t, Machine::PoolMap), c, objectHash, objectEqual), array, objectHash); - - delete[] types; - types = 0; } } @@ -423,7 +420,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, object fields = allFields(t, typeMaps, c, &count, &array); PROTECT(t, fields); - Field* memberFields = new Field[count + 1]; + RUNTIME_ARRAY(Field, memberFields, count + 1); unsigned memberIndex; unsigned buildMemberOffset; @@ -447,7 +444,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, ++ memberIndex; } } else { - init(new (memberFields) Field, Type_object, 0, BytesPerWord, 0, + init(new (&memberFields[0]) Field, Type_object, 0, BytesPerWord, 0, TargetBytesPerWord); memberIndex = 1; @@ -457,15 +454,15 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, const unsigned StaticHeader = 3; - Field* staticFields = new Field[count + StaticHeader]; + RUNTIME_ARRAY(Field, staticFields, count + StaticHeader); - init(new (staticFields) Field, Type_object, 0, BytesPerWord, 0, + init(new (&staticFields[0]) Field, Type_object, 0, BytesPerWord, 0, TargetBytesPerWord); - init(new (staticFields + 1) Field, Type_intptr_t, BytesPerWord, + init(new (&staticFields[1]) Field, Type_intptr_t, BytesPerWord, BytesPerWord, TargetBytesPerWord, TargetBytesPerWord); - init(new (staticFields + 2) Field, Type_object, BytesPerWord * 2, + init(new (&staticFields[2]) Field, Type_object, BytesPerWord * 2, BytesPerWord, TargetBytesPerWord * 2, TargetBytesPerWord); unsigned staticIndex = StaticHeader; @@ -515,7 +512,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, buildStaticOffset = fieldOffset(t, field); - init(new (staticFields + staticIndex) Field, type, + init(new (&staticFields[staticIndex]) Field, type, buildStaticOffset, buildSize, targetStaticOffset, targetSize); @@ -529,7 +526,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, buildMemberOffset = fieldOffset(t, field); - init(new (memberFields + memberIndex) Field, type, + init(new (&memberFields[memberIndex]) Field, type, buildMemberOffset, buildSize, targetMemberOffset, targetSize); @@ -552,7 +549,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, ceiling(targetMemberOffset, TargetBytesPerWord), memberIndex); for (unsigned i = 0; i < memberIndex; ++i) { - Field* f = memberFields + i; + Field* f = &memberFields[i]; expect(t, f->buildOffset < map->buildFixedSizeInWords * BytesPerWord); @@ -576,7 +573,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, TypeMap::SingletonKind); for (unsigned i = 0; i < staticIndex; ++i) { - Field* f = staticFields + i; + Field* f = &staticFields[i]; expect(t, f->buildOffset < map->buildFixedSizeInWords * BytesPerWord); @@ -589,12 +586,6 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, hashMapInsert (t, typeMaps, classStaticTable(t, c), array, objectHash); } - - delete[] memberFields; - memberFields = 0; - - delete[] staticFields; - staticFields = 0; } } } @@ -1343,9 +1334,9 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp } ++ count; - Field* fields = new Field[count]; + RUNTIME_ARRAY(Field, fields, count); - init(new (fields) Field, Type_object, 0, BytesPerWord, 0, + init(new (&fields[0]) Field, Type_object, 0, BytesPerWord, 0, TargetBytesPerWord); unsigned buildOffset = BytesPerWord; @@ -1423,7 +1414,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp ++ targetOffset; } - init(new (fields + j) Field, type, buildOffset, buildSize, + init(new (&fields[j]) Field, type, buildOffset, buildSize, targetOffset, targetSize); buildOffset += buildSize; @@ -1458,7 +1449,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp targetArrayElementSize, arrayElementType); for (unsigned j = 0; j < fixedFieldCount; ++j) { - Field* f = fields + j; + Field* f = &fields[j]; expect(t, f->buildOffset < map->buildFixedSizeInWords * BytesPerWord); @@ -1471,9 +1462,6 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp hashMapInsert (t, typeMaps, vm::type(t, static_cast(i)), array, objectHash); - - delete[] fields; - fields = 0; } constants = makeCodeImage diff --git a/src/common.h b/src/common.h index c99f23410e..6803fe4c34 100644 --- a/src/common.h +++ b/src/common.h @@ -243,6 +243,10 @@ class RuntimeArray { free(body); } + T& operator[] (const unsigned index) { + return body[index]; + } + T* body; }; diff --git a/src/interpret.cpp b/src/interpret.cpp index 9399e96657..42183e98f0 100644 --- a/src/interpret.cpp +++ b/src/interpret.cpp @@ -2321,7 +2321,7 @@ interpret3(Thread* t, const int base) object class_ = resolveClassInPool(t, frameMethod(t, frame), index - 1); PROTECT(t, class_); - int32_t* counts = new int32_t[dimensions]; + RUNTIME_ARRAY(int32_t, counts, dimensions); for (int i = dimensions - 1; i >= 0; --i) { counts[i] = popInt(t); if (UNLIKELY(counts[i] < 0)) { @@ -2338,9 +2338,6 @@ interpret3(Thread* t, const int base) populateMultiArray(t, array, counts, 0, dimensions); pushObject(t, array); - - delete[] counts; - counts = 0; } goto loop; case new_: { From d5d2e50ac71883d9764094d7c536182c8e2dbba1 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Tue, 5 Feb 2013 08:41:37 +0200 Subject: [PATCH 096/106] Trace writeout refactor --- src/machine.cpp | 73 ++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 43 deletions(-) diff --git a/src/machine.cpp b/src/machine.cpp index d2d225e7e5..46f331c32d 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -4759,6 +4759,27 @@ visitRoots(Machine* m, Heap::Visitor* v) } } +void +logTrace(FILE* f, const char* fmt, ...) +{ + va_list a; + va_start(a, fmt); +#ifdef PLATFORM_WINDOWS + const unsigned length = _vscprintf(fmt, a); +#else + const unsigned length = vsnprintf(0, 0, fmt, a); +#endif + RUNTIME_ARRAY(char, buffer, length + 1); + vsnprintf(&buffer[0], length, fmt, a); + buffer[length] = 0; + va_end(a); + + ::fprintf(f, "%s", &buffer[0]); +#ifdef PLATFORM_WINDOWS + ::OutputDebugStringA(&buffer[0]); +#endif +} + void printTrace(Thread* t, object exception) { @@ -4768,34 +4789,19 @@ printTrace(Thread* t, object exception) for (object e = exception; e; e = throwableCause(t, e)) { if (e != exception) { - fprintf(errorLog(t), "caused by: "); -#if defined(PLATFORM_WINDOWS) - OutputDebugStringA("caused by: "); -#endif + logTrace(errorLog(t), "caused by: "); } - fprintf(errorLog(t), "%s", &byteArrayBody + logTrace(errorLog(t), "%s", &byteArrayBody (t, className(t, objectClass(t, e)), 0)); -#if defined(PLATFORM_WINDOWS) - OutputDebugStringA((const CHAR*)&byteArrayBody - (t, className(t, objectClass(t, e)), 0)); -#endif if (throwableMessage(t, e)) { object m = throwableMessage(t, e); THREAD_RUNTIME_ARRAY(t, char, message, stringLength(t, m) + 1); stringChars(t, m, RUNTIME_ARRAY_BODY(message)); - fprintf(errorLog(t), ": %s\n", RUNTIME_ARRAY_BODY(message)); -#if defined(PLATFORM_WINDOWS) - OutputDebugStringA(": "); - OutputDebugStringA(RUNTIME_ARRAY_BODY(message)); - OutputDebugStringA("\n"); -#endif + logTrace(errorLog(t), ": %s\n", RUNTIME_ARRAY_BODY(message)); } else { - fprintf(errorLog(t), "\n"); -#if defined(PLATFORM_WINDOWS) - OutputDebugStringA("\n"); -#endif + logTrace(errorLog(t), "\n"); } object trace = throwableTrace(t, e); @@ -4809,36 +4815,17 @@ printTrace(Thread* t, object exception) int line = t->m->processor->lineNumber (t, traceElementMethod(t, e), traceElementIp(t, e)); - fprintf(errorLog(t), " at %s.%s ", class_, method); -#if defined(PLATFORM_WINDOWS) - OutputDebugStringA(" at "); - OutputDebugStringA((const CHAR*)class_); - OutputDebugStringA("."); - OutputDebugStringA((const CHAR*)method); - OutputDebugStringA(" "); -#endif + logTrace(errorLog(t), " at %s.%s ", class_, method); switch (line) { case NativeLine: - fprintf(errorLog(t), "(native)\n"); -#if defined(PLATFORM_WINDOWS) - OutputDebugStringA("(native)\n"); -#endif + logTrace(errorLog(t), "(native)\n"); break; case UnknownLine: - fprintf(errorLog(t), "(unknown line)\n"); -#if defined(PLATFORM_WINDOWS) - OutputDebugStringA("(unknown line)\n"); -#endif + logTrace(errorLog(t), "(unknown line)\n"); break; default: - fprintf(errorLog(t), "(line %d)\n", line); -#if defined(PLATFORM_WINDOWS) - OutputDebugStringA("(line "); - char buf[35]; - OutputDebugStringA(itoa(line, buf, 10)); - OutputDebugStringA(")\n"); -#endif + logTrace(errorLog(t), "(line %d)\n", line); } } } @@ -4848,7 +4835,7 @@ printTrace(Thread* t, object exception) } } - fflush(errorLog(t)); + ::fflush(errorLog(t)); } object From 0a1743ebf2cc53d68c0b4b524d882d584b97ccd9 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 7 Feb 2013 11:43:39 +0200 Subject: [PATCH 097/106] Fix for windows ::open --- classpath/java-io.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index ba4812a5a4..acc0582feb 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -802,7 +802,11 @@ Java_java_io_RandomAccessFile_open(JNIEnv* e, jclass, jstring path, jlong peer = 0; jlong length = 0; #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + #if defined(PLATFORM_WINDOWS) + int fd = ::_wopen(chars, O_RDONLY); + #else int fd = ::open((const char*)chars, O_RDONLY); + #endif releaseChars(e, path, chars); if (fd == -1) { throwNewErrno(e, "java/io/IOException"); From 837e2847ece5ba6858f91f8365f59f82517f3177 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Sat, 9 Feb 2013 13:09:58 +0200 Subject: [PATCH 098/106] WP8 target refine --- makefile | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/makefile b/makefile index 6c846335fa..f020bb4b37 100755 --- a/makefile +++ b/makefile @@ -641,14 +641,9 @@ ifeq ($(platform),wp8) ms_cl_compiler = wp8 use-lto = false supports_avian_executable = false - process = compile aot-only = true - ifneq ($(process),compile) - options := -$(process) - endif - bootimage = true - ifeq ($(bootimage),true) - options := $(options)-bootimage + ifneq ($(bootimage),true) + $(error Windows Phone 8 target requires bootimage=true) endif system = windows build-system = windows From dd14b10d8d6a5484f0ed515b467f5bbb84edadd3 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Sat, 9 Feb 2013 13:18:39 +0200 Subject: [PATCH 099/106] Lost assignment --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index f020bb4b37..9b3034eb37 100755 --- a/makefile +++ b/makefile @@ -643,7 +643,7 @@ ifeq ($(platform),wp8) supports_avian_executable = false aot-only = true ifneq ($(bootimage),true) - $(error Windows Phone 8 target requires bootimage=true) + x := $(error Windows Phone 8 target requires bootimage=true) endif system = windows build-system = windows From 5d35d64c80b39b251dca93051940f061da58319e Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Sun, 10 Feb 2013 09:31:41 +0200 Subject: [PATCH 100/106] Disable operator new warning --- src/common.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/common.h b/src/common.h index 6803fe4c34..907a8375b4 100644 --- a/src/common.h +++ b/src/common.h @@ -220,8 +220,17 @@ typedef intptr_t __attribute__((__may_alias__)) intptr_alias_t; type name; \ } MAKE_NAME(resource_)(name); +#ifdef _MSC_VER +# pragma warning( push ) +# pragma warning( disable : 4291 ) +#endif + inline void* operator new(size_t, void* p) throw() { return p; } +#ifdef _MSC_VER +# pragma warning( pop ) +#endif + namespace vm { inline intptr_alias_t& From 9c632b778b382f18db3413c2bcaa44d883967fed Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Sun, 10 Feb 2013 09:41:46 +0200 Subject: [PATCH 101/106] Proper warning disabling --- src/common.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/common.h b/src/common.h index 907a8375b4..1f74d3382e 100644 --- a/src/common.h +++ b/src/common.h @@ -221,16 +221,10 @@ typedef intptr_t __attribute__((__may_alias__)) intptr_alias_t; } MAKE_NAME(resource_)(name); #ifdef _MSC_VER -# pragma warning( push ) # pragma warning( disable : 4291 ) #endif - inline void* operator new(size_t, void* p) throw() { return p; } -#ifdef _MSC_VER -# pragma warning( pop ) -#endif - namespace vm { inline intptr_alias_t& From dc943c250a249f3e75614f95fca769d9ea9ba934 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 12 Feb 2013 08:15:39 -0700 Subject: [PATCH 102/106] delay incrementing Thread::criticalLevel until after entering ActiveState If we increment the value while we're still in IdleState, another thread may try to GC before we are able to enter ActiveState, which will lead to an assertion failure when the footprint function is called. --- src/jnienv.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/jnienv.cpp b/src/jnienv.cpp index 2a70b10855..e512b18066 100644 --- a/src/jnienv.cpp +++ b/src/jnienv.cpp @@ -160,10 +160,12 @@ GetStringRegion(Thread* t, jstring s, jsize start, jsize length, jchar* dst) const jchar* JNICALL GetStringCritical(Thread* t, jstring s, jboolean* isCopy) { - if ((t->criticalLevel ++) == 0) { + if (t->criticalLevel == 0) { enter(t, Thread::ActiveState); } + ++ t->criticalLevel; + if (isCopy) { *isCopy = true; } @@ -3141,9 +3143,11 @@ SetDoubleArrayRegion(Thread* t, jdoubleArray array, jint offset, jint length, void* JNICALL GetPrimitiveArrayCritical(Thread* t, jarray array, jboolean* isCopy) { - if ((t->criticalLevel ++) == 0) { + if (t->criticalLevel == 0) { enter(t, Thread::ActiveState); } + + ++ t->criticalLevel; if (isCopy) { *isCopy = true; From d1a7b660856ab9f3827604d0d09e565cf7d9341a Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 12 Feb 2013 08:22:21 -0700 Subject: [PATCH 103/106] don't specify -Wl,-rpath argument on Darwin or Windows It remains to be seen what form that argument should take on those operating systems; for now, it only causes trouble, so we'll just leave it out. --- makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/makefile b/makefile index fe83a35381..362d4a756d 100755 --- a/makefile +++ b/makefile @@ -239,6 +239,8 @@ so-suffix = .so shared = -shared +rpath = -Wl,-rpath=\$$ORIGIN + no-error = -Wno-error openjdk-extra-cflags = -fvisibility=hidden @@ -391,6 +393,7 @@ ifeq ($(platform),darwin) strip-all = -S -x so-suffix = .dylib shared = -dynamiclib + rpath = sdk-dir = $(developer-dir)/Platforms/iPhoneOS.platform/Developer/SDKs @@ -450,6 +453,7 @@ ifeq ($(platform),windows) so-prefix = so-suffix = .dll exe-suffix = .exe + rpath = lflags = -L$(lib) $(common-lflags) -lws2_32 -liphlpapi -mwindows -mconsole cflags = -I$(inc) $(common-cflags) -DWINVER=0x0500 @@ -1245,7 +1249,7 @@ ifdef msvc -MANIFESTFILE:$(@).manifest $(mt) -manifest $(@).manifest -outputresource:"$(@);1" else - $(ld) $(driver-dynamic-objects) -L$(build) -ljvm $(lflags) $(no-lto) -Wl,-rpath=\$$ORIGIN -z origin -o $(@) + $(ld) $(driver-dynamic-objects) -L$(build) -ljvm $(lflags) $(no-lto) $(rpath) -z origin -o $(@) endif $(strip) $(strip-all) $(@) From 752d02e7786b807185e3f4cd254ee988c01f830f Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 12 Feb 2013 09:22:17 -0700 Subject: [PATCH 104/106] make bootimage-object depend on openjdk-jar-dep This ensures that the OpenJDK classes have been extracted prior to bootimage creation. --- makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/makefile b/makefile index f7da20fd08..6106d2b08b 100755 --- a/makefile +++ b/makefile @@ -1476,7 +1476,8 @@ else $(ranlib) $(@) endif -$(bootimage-object) $(codeimage-object): $(bootimage-generator) +$(bootimage-object) $(codeimage-object): $(bootimage-generator) \ + $(openjdk-jar-dep) @echo "generating bootimage and codeimage binaries from $(classpath-build) using $(<)" $(<) -cp $(classpath-build) -bootimage $(bootimage-object) -codeimage $(codeimage-object) \ -bootimage-symbols $(bootimage-symbols) \ From 937343d0d3967a176899f7c1a03294a0f36d77fb Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 12 Feb 2013 09:27:47 -0700 Subject: [PATCH 105/106] don't specify -Wl,-rpath argument on Darwin or Windows (take 2) --- makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/makefile b/makefile index bfe755c23a..7ca50ab600 100755 --- a/makefile +++ b/makefile @@ -267,7 +267,7 @@ build-ld = $(build-cc) static = -static shared = -shared -rpath = -Wl,-rpath=\$$ORIGIN +rpath = -Wl,-rpath=\$$ORIGIN -Wl,-z,origin no-error = -Wno-error @@ -1573,7 +1573,7 @@ ifdef mt $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" endif else - $(ld) $(driver-dynamic-objects) -L$(build) -ljvm $(lflags) $(no-lto) $(rpath) -z origin -o $(@) + $(ld) $(driver-dynamic-objects) -L$(build) -ljvm $(lflags) $(no-lto) $(rpath) -o $(@) endif $(strip) $(strip-all) $(@) From 3812d012a35b2af495561beac20adfd92b086133 Mon Sep 17 00:00:00 2001 From: Damjan Jovanovic Date: Tue, 12 Feb 2013 11:00:52 -0700 Subject: [PATCH 106/106] update documentation to indicate that LD_LIBRARY_PATH is not (always) needed --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c09ec39db6..1e35318627 100644 --- a/README.md +++ b/README.md @@ -249,12 +249,11 @@ where OpenJDK is installed, e.g.: This will build Avian as a conventional JVM (e.g. libjvm.so) which loads its boot class library and native libraries (e.g. libjava.so) -from _/usr/lib/jvm/java-7-openjdk/jre_ at runtime. To run an -application in this configuration, you'll need to make sure the VM is -in your library search path. For example: +from _/usr/lib/jvm/java-7-openjdk/jre_ at runtime. In this configuration, +OpenJDK needs to remain installed for Avian to work, and you can run +applications like this: - $ LD_LIBRARY_PATH=build/linux-x86_64-openjdk \ - build/linux-x86_64-openjdk/avian-dynamic -cp /path/to/my/application \ + $ build/linux-x86_64-openjdk/avian-dynamic -cp /path/to/my/application \ com.example.MyApplication Alternatively, you can enable a stand-alone build using OpenJDK by