From eaf1d205cd4ab07610271ad7ad73d71ba53b4c0e Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 24 Oct 2007 11:24:19 -0600 Subject: [PATCH] more windows port fixes --- classpath/java-io.cpp | 8 +++++--- classpath/java-lang.cpp | 9 ++++----- classpath/java-nio.cpp | 12 ++++++------ classpath/java-util-zip.cpp | 6 ++++-- makefile | 4 ++-- src/builtin.cpp | 9 +++++---- src/machine.h | 6 +++++- src/process.h | 22 ++++++++++++++++++++++ src/x86.S | 24 ++++++++++++------------ src/x86.h | 15 ++++++++------- 10 files changed, 73 insertions(+), 42 deletions(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index f0f58a1c43..21c11ecea0 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -8,11 +8,9 @@ #include "jni.h" #include "jni-util.h" -#undef JNIEXPORT -#define JNIEXPORT __attribute__ ((visibility("default"))) - #ifdef WIN32 # include + # define OPEN _open # define CLOSE _close # define READ _read @@ -25,6 +23,7 @@ # define OPEN_MASK O_BINARY #else # include + # define OPEN open # define CLOSE close # define READ read @@ -35,6 +34,9 @@ # define CREAT creat # define UNLINK unlink # define OPEN_MASK 0 + +# undef JNIEXPORT +# define JNIEXPORT __attribute__ ((visibility("default"))) #endif namespace { diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index 53697a9f96..1ffaeed354 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -11,9 +11,12 @@ #ifdef WIN32 # include "windows.h" +#else +# undef JNIEXPORT +# define JNIEXPORT __attribute__ ((visibility("default"))) #endif -#ifdef __MINGW32__ +#ifdef WIN32 # define SO_PREFIX "" #else # define SO_PREFIX "lib" @@ -27,9 +30,6 @@ # define SO_SUFFIX ".so" #endif -#undef JNIEXPORT -#define JNIEXPORT __attribute__ ((visibility("default"))) - extern "C" JNIEXPORT jstring JNICALL Java_java_lang_System_getProperty(JNIEnv* e, jclass, jint code) { @@ -55,7 +55,6 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jint code) case JavaIoTmpdir: { TCHAR buffer[MAX_PATH]; GetTempPath(MAX_PATH, buffer); - fprintf(stderr, "tmpdir: %s\n", buffer); return e->NewStringUTF(buffer); } diff --git a/classpath/java-nio.cpp b/classpath/java-nio.cpp index 59dda5c83a..dfea44d947 100644 --- a/classpath/java-nio.cpp +++ b/classpath/java-nio.cpp @@ -4,6 +4,9 @@ #include #include +#include "jni.h" +#include "jni-util.h" + #ifdef WIN32 # include # include @@ -12,14 +15,11 @@ # include # include # include + +# undef JNIEXPORT +# define JNIEXPORT __attribute__ ((visibility("default"))) #endif -#include "jni.h" -#include "jni-util.h" - -#undef JNIEXPORT -#define JNIEXPORT __attribute__ ((visibility("default"))) - #define java_nio_channels_SelectionKey_OP_READ 1L #define java_nio_channels_SelectionKey_OP_WRITE 4L #define java_nio_channels_SelectionKey_OP_ACCEPT 16L diff --git a/classpath/java-util-zip.cpp b/classpath/java-util-zip.cpp index b9e685fe4e..47cdfeefa9 100644 --- a/classpath/java-util-zip.cpp +++ b/classpath/java-util-zip.cpp @@ -5,8 +5,10 @@ #include "jni.h" #include "jni-util.h" -#undef JNIEXPORT -#define JNIEXPORT __attribute__ ((visibility("default"))) +#ifndef WIN32 +# undef JNIEXPORT +# define JNIEXPORT __attribute__ ((visibility("default"))) +#endif extern "C" JNIEXPORT jlong JNICALL Java_java_util_zip_Inflater_make diff --git a/makefile b/makefile index 0d16eaf4e3..47219923c6 100644 --- a/makefile +++ b/makefile @@ -80,7 +80,7 @@ ifeq ($(platform),windows) ranlib = i586-mingw32msvc-ranlib rdynamic = -Wl,--export-dynamic - lflags = -L$(lib) -lm -lz -lws2_32 -Wl,--kill-at + lflags = -L$(lib) -lm -lz -lws2_32 -Wl,--kill-at -mwindows -mconsole cflags = $(common-cflags) -I$(inc) endif @@ -262,7 +262,7 @@ $(jni-objects): $(bld)/%.o: $(classpath)/%.cpp ifeq ($(platform),windows) $(archive): $(interpreter-objects) $(jni-objects) @echo "creating $(@)" - $(dlltool) --export-all-symbols -z $(@).def $(^) + $(dlltool) -z $(@).def $(^) $(dlltool) -k -d $(@).def -e $(@).exp $(ar) cru $(@) $(@).exp $(^) $(ranlib) $(@) diff --git a/src/builtin.cpp b/src/builtin.cpp index b323d1b26c..f8735fd81a 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -2,8 +2,11 @@ #include "constants.h" #include "processor.h" -#undef JNIEXPORT -#define JNIEXPORT __attribute__ ((visibility("default"))) +#ifdef __MINGW32__ +# define JNIEXPORT __declspec(dllexport) +#else +# define JNIEXPORT __attribute__ ((visibility("default"))) +#endif using namespace vm; @@ -520,8 +523,6 @@ Java_java_lang_Runtime_load(Thread* t, jclass, jstring name, jboolean mapName) } } - fprintf(stderr, "load %s; map name: %d\n", n, mapName); - System::Library* lib; if (LIKELY(t->m->system->success (t->m->system->load(&lib, n, mapName, t->m->libraries)))) diff --git a/src/machine.h b/src/machine.h index 848cf4ae50..ed02ea9847 100644 --- a/src/machine.h +++ b/src/machine.h @@ -7,7 +7,11 @@ #include "finder.h" #include "processor.h" -#define JNICALL +#ifdef __MINGW32__ +# define JNICALL __stdcall +#else +# define JNICALL +#endif #define PROTECT(thread, name) \ Thread::SingleProtector MAKE_NAME(protector_) (thread, &name); diff --git a/src/process.h b/src/process.h index 34287751cb..4dc27a51dc 100644 --- a/src/process.h +++ b/src/process.h @@ -140,6 +140,28 @@ resolveNativeMethod(Thread* t, object method) if (p) { return p; } +#ifdef __MINGW32__ + else { + // on windows, we also try the _%s@%d variant, since the SWT + // libraries use it. + + unsigned footprint = methodParameterFootprint(t, method) + 1; + if (methodFlags(t, method) & ACC_STATIC) { + ++ footprint; + } + + unsigned size = byteArrayLength(t, methodCode(t, method)) + 5; + char buffer[size]; + snprintf(buffer, size, "_%s@%d", + &byteArrayBody(t, methodCode(t, method), 0), + footprint * BytesPerWord); + + p = lib->resolve(buffer); + if (p) { + return p; + } + } +#endif } return 0; } diff --git a/src/x86.S b/src/x86.S index fc30148917..86159b40ce 100644 --- a/src/x86.S +++ b/src/x86.S @@ -4,8 +4,8 @@ #ifdef __x86_64__ -.globl amd64Call -amd64Call: +.globl vmNativeCall +vmNativeCall: pushq %rbp // %rdi aka 0(%rbp): function @@ -104,14 +104,14 @@ exit: ret #elif defined __i386__ - -#if defined __APPLE__ || defined __MINGW32__ -.globl _cdeclCall -_cdeclCall: -#else -.globl cdeclCall -cdeclCall: -#endif + +# if defined __APPLE__ || defined __MINGW32__ +.globl _vmNativeCall +_vmNativeCall: +# else +.globl vmNativeCall +vmNativeCall: +# endif pushl %ebp movl %esp,%ebp @@ -125,10 +125,10 @@ cdeclCall: subl %ecx,%esp -#ifdef __APPLE__ +# ifdef __APPLE__ // align to a 16 byte boundary on Darwin andl $0xFFFFFFF0,%esp -#endif +# endif // copy arguments into place movl $0,%ecx diff --git a/src/x86.h b/src/x86.h index 4b9c877d92..a3412c6283 100644 --- a/src/x86.h +++ b/src/x86.h @@ -7,8 +7,8 @@ #ifdef __i386__ extern "C" uint64_t -cdeclCall(void* function, void* stack, unsigned stackSize, - unsigned returnType); +vmNativeCall(void* function, void* stack, unsigned stackSize, + unsigned returnType); namespace vm { @@ -16,7 +16,7 @@ inline uint64_t dynamicCall(void* function, uintptr_t* arguments, uint8_t*, unsigned, unsigned argumentsSize, unsigned returnType) { - return cdeclCall(function, arguments, argumentsSize, returnType); + return vmNativeCall(function, arguments, argumentsSize, returnType); } } // namespace vm @@ -24,8 +24,8 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t*, #elif defined __x86_64__ extern "C" uint64_t -amd64Call(void* function, void* stack, unsigned stackSize, - void* gprTable, void* sseTable, unsigned returnType); +vmNativeCall(void* function, void* stack, unsigned stackSize, + void* gprTable, void* sseTable, unsigned returnType); namespace vm { @@ -65,8 +65,9 @@ dynamicCall(void* function, uint64_t* arguments, uint8_t* argumentTypes, } } - return amd64Call(function, stack, stackIndex * 8, (gprIndex ? gprTable : 0), - (sseIndex ? sseTable : 0), returnType); + return vmNativeCall(function, stack, stackIndex * 8, + (gprIndex ? gprTable : 0), + (sseIndex ? sseTable : 0), returnType); } } // namespace vm