From 51b510cbea3d7853028618473604436bca26c7f0 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Tue, 29 Jul 2014 12:47:57 -0600 Subject: [PATCH 1/7] first pass at cmake + visual studio support --- CMakeLists.txt | 5 +++-- cmake/Platform.cmake | 7 +++++++ include/avian/codegen/compiler.h | 5 +++++ include/avian/util/cpp.h | 10 ++++++++++ src/avian/common.h | 22 +--------------------- src/system/CMakeLists.txt | 8 ++++++-- src/tools/binary-to-object/main.cpp | 3 ++- src/tools/object-writer/pe.cpp | 12 +++++++++--- src/tools/object-writer/tools.cpp | 18 +++++++++--------- src/tools/type-generator/io.h | 2 +- src/tools/type-generator/main.cpp | 7 ++++--- unittest/CMakeLists.txt | 2 -- 12 files changed, 57 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 864c3aabd5..19c4b900b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,9 +16,10 @@ add_definitions ( -D__STDC_CONSTANT_MACROS ) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -fno-exceptions -std=c++0x") - include ("cmake/Platform.cmake") + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PLATFORM_CXX_FLAGS}") + include (CTest) # Sadly, we can't use the 'test' target, as that's coopted by ctest diff --git a/cmake/Platform.cmake b/cmake/Platform.cmake index 85470acdeb..1bfb373ee7 100644 --- a/cmake/Platform.cmake +++ b/cmake/Platform.cmake @@ -6,3 +6,10 @@ IF (APPLE) SET(PLATFORM_LIBS ${CORE_FOUNDATION_LIBRARY}) ENDIF() + +IF (MSVC) + SET(PLATFORM_CXX_FLAGS "/Wall") +ELSE() + SET(PLATFORM_CXX_FLAGS "-Wall -Werror -fno-exceptions -std=c++0x") + SET(PLATFORM_LIBS ${PLATFORM_LIBS} pthread dl) +ENDIF() diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 9e96e79539..5086367cd4 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -32,8 +32,13 @@ class Args { template Args(Ts... ts) +#ifndef _MSC_VER : values{ts...} +#endif { +#ifdef _MSC_VER + setArrayElements(values, ts...); +#endif } operator util::Slice() diff --git a/include/avian/util/cpp.h b/include/avian/util/cpp.h index 6be12af1a8..209df50a46 100644 --- a/include/avian/util/cpp.h +++ b/include/avian/util/cpp.h @@ -44,6 +44,16 @@ struct ArgumentCount<> { enum { Result = 0 }; }; +template +void setArrayElements(T*) { +} + +template +void setArrayElements(T* arr, T elem, Ts... ts) { + *arr = elem; + setArrayElements(arr, ts...); +} + } // namespace util } // namespace avian diff --git a/src/avian/common.h b/src/avian/common.h index 82cdc046ce..b08e2dc659 100644 --- a/src/avian/common.h +++ b/src/avian/common.h @@ -39,29 +39,9 @@ #define strncasecmp _strnicmp -#define FP_NAN 0 -#define FP_INFINITE 1 #define FP_UNDEF 2 -inline int fpclassify(double d) -{ - switch (_fpclass(d)) { - case _FPCLASS_SNAN: - case _FPCLASS_QNAN: - return FP_NAN; - case _FPCLASS_PINF: - case _FPCLASS_NINF: - return FP_INFINITE; - } - return FP_UNDEF; -} - -inline int signbit(double d) -{ - return _copysign(1.0, d) < 0; -} - -#define not! +#define not ! #define or || #define and && #define xor ^ diff --git a/src/system/CMakeLists.txt b/src/system/CMakeLists.txt index 566ac8100f..5c6f2a58fa 100644 --- a/src/system/CMakeLists.txt +++ b/src/system/CMakeLists.txt @@ -1,3 +1,7 @@ -# TODO: use posix.cpp or windows.cpp, depending on platform -add_library(avian_system posix.cpp posix/crash.cpp) +if (MSVC) + #todo: support mingw compiler + add_library(avian_system windows.cpp windows/crash.cpp) +else() + add_library(avian_system posix.cpp posix/crash.cpp) +endif() diff --git a/src/tools/binary-to-object/main.cpp b/src/tools/binary-to-object/main.cpp index 4cd9ff5879..8889dbaf24 100644 --- a/src/tools/binary-to-object/main.cpp +++ b/src/tools/binary-to-object/main.cpp @@ -16,6 +16,7 @@ #include #ifdef WIN32 #include +#include #else #include #include @@ -90,7 +91,7 @@ void usageAndExit(const char* name) int main(int argc, const char** argv) { - if (argc < 7 or argc > 10) { + if (argc < 7 || argc > 10) { usageAndExit(argv[0]); } diff --git a/src/tools/object-writer/pe.cpp b/src/tools/object-writer/pe.cpp index dd3e976041..8384cbd64a 100644 --- a/src/tools/object-writer/pe.cpp +++ b/src/tools/object-writer/pe.cpp @@ -40,6 +40,12 @@ namespace { #define IMAGE_SCN_MEM_WRITE 0x80000000 #define IMAGE_SCN_CNT_CODE 32 +#ifdef _MSC_VER +#define PACKED_STRUCT _declspec(align(1)) +#else +#define PACKED_STRUCT __attribute__((packed)) +#endif + struct IMAGE_FILE_HEADER { uint16_t Machine; uint16_t NumberOfSections; @@ -48,7 +54,7 @@ struct IMAGE_FILE_HEADER { uint32_t NumberOfSymbols; uint16_t SizeOfOptionalHeader; uint16_t Characteristics; -} __attribute__((packed)); +} PACKED_STRUCT; struct IMAGE_SECTION_HEADER { uint8_t Name[IMAGE_SIZEOF_SHORT_NAME]; @@ -64,7 +70,7 @@ struct IMAGE_SECTION_HEADER { uint16_t NumberOfRelocations; uint16_t NumberOfLinenumbers; uint32_t Characteristics; -} __attribute__((packed)); +} PACKED_STRUCT; struct IMAGE_SYMBOL { union { @@ -78,7 +84,7 @@ struct IMAGE_SYMBOL { uint16_t Type; uint8_t StorageClass; uint8_t NumberOfAuxSymbols; -} __attribute__((packed)); +} PACKED_STRUCT; // --- winnt.h ---- inline unsigned pad(unsigned n) diff --git a/src/tools/object-writer/tools.cpp b/src/tools/object-writer/tools.cpp index 5bd3739825..ad736efd24 100644 --- a/src/tools/object-writer/tools.cpp +++ b/src/tools/object-writer/tools.cpp @@ -94,13 +94,13 @@ Platform* Platform::first = 0; PlatformInfo::Format PlatformInfo::formatFromString(const char* format) { - if (strcmp(format, "elf") == 0 or strcmp(format, "linux") == 0 - or strcmp(format, "freebsd") == 0 or strcmp(format, "qnx") == 0) { + if (strcmp(format, "elf") == 0 || strcmp(format, "linux") == 0 + || strcmp(format, "freebsd") == 0 || strcmp(format, "qnx") == 0) { return Elf; - } else if (strcmp(format, "pe") == 0 or strcmp(format, "windows") == 0) { + } else if (strcmp(format, "pe") == 0 || strcmp(format, "windows") == 0) { return Pe; - } else if (strcmp(format, "macho") == 0 or strcmp(format, "darwin") == 0 - or strcmp(format, "ios") == 0 or strcmp(format, "macosx") == 0) { + } else if (strcmp(format, "macho") == 0 || strcmp(format, "darwin") == 0 + || strcmp(format, "ios") == 0 || strcmp(format, "macosx") == 0) { return MachO; } else { return UnknownFormat; @@ -110,13 +110,13 @@ PlatformInfo::Format PlatformInfo::formatFromString(const char* format) PlatformInfo::Architecture PlatformInfo::archFromString(const char* arch) { if (strcmp(arch, "i386") == 0) { - return x86; + return Architecture::x86; } else if (strcmp(arch, "x86_64") == 0) { - return x86_64; + return Architecture::x86_64; } else if (strcmp(arch, "arm") == 0) { - return Arm; + return Architecture::Arm; } else { - return UnknownArch; + return Architecture::UnknownArch; } } diff --git a/src/tools/type-generator/io.h b/src/tools/type-generator/io.h index 346ca5fa84..f0ae32135f 100644 --- a/src/tools/type-generator/io.h +++ b/src/tools/type-generator/io.h @@ -124,7 +124,7 @@ class Output { { static const int Size = 32; char s[Size]; - int c UNUSED = ::snprintf(s, Size, "%d", i); + int c UNUSED = vm::snprintf(s, Size, "%d", i); assert(c > 0 and c < Size); write(s); } diff --git a/src/tools/type-generator/main.cpp b/src/tools/type-generator/main.cpp index 30549afd43..32dcf6f7f0 100644 --- a/src/tools/type-generator/main.cpp +++ b/src/tools/type-generator/main.cpp @@ -172,7 +172,7 @@ class Class { return ss.str(); } - void dumpToStdout() const AVIAN_EXPORT + void dumpToStdout() const { printf("%s\n", dump().c_str()); } @@ -615,13 +615,14 @@ const char* fieldType(const char* spec) void parseJavaClass(Module& module, ClassParser& clparser, Stream* s) { - uint32_t magic UNUSED = s->read4(); + uint32_t magic = s->read4(); assert(magic == 0xCAFEBABE); + (void)magic; s->read2(); // minor version s->read2(); // major version unsigned poolCount = s->read2() - 1; - uintptr_t pool[poolCount]; + std::vector pool(poolCount, -1); for (unsigned i = 0; i < poolCount; ++i) { unsigned c = s->read1(); diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 0f4520d162..d810e3ffba 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -16,8 +16,6 @@ target_link_libraries (avian_unittest avian_system avian_heap avian_util - pthread - dl ${PLATFORM_LIBS} ) From ef3f77695c1c00295e6a0fb4bb8b650983f1889c Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Tue, 29 Jul 2014 13:36:45 -0600 Subject: [PATCH 2/7] use inline asm for sse detection --- src/codegen/target/x86/detect.cpp | 37 +++++++++++-- src/x86.S | 88 ------------------------------- src/x86.masm | 34 ------------ 3 files changed, 34 insertions(+), 125 deletions(-) diff --git a/src/codegen/target/x86/detect.cpp b/src/codegen/target/x86/detect.cpp index cfa09cc243..d6c9f1fc06 100644 --- a/src/codegen/target/x86/detect.cpp +++ b/src/codegen/target/x86/detect.cpp @@ -13,11 +13,39 @@ #include "context.h" +#ifndef _MSC_VER +#include +#else +// MSVC implementation: +static int __get_cpuid(unsigned int __level, + unsigned int* __eax, + unsigned int* __ebx, + unsigned int* __ecx, + unsigned int* __edx) +{ + _asm + { + mov eax, __level; + cpuid; + mov[__eax], eax; + mov[__ebx], ebx; + mov[__ecx], ecx; + mov[__edx], edx; + } + return 1; +} +#define bit_SSE (1 << 25) +#define bit_SSE2 (1 << 26) + +#endif + namespace avian { namespace codegen { namespace x86 { -extern "C" bool detectFeature(unsigned ecx, unsigned edx); +// TODO: this should be moved such that it's called by the client (e.g. whatever +// allocates the Archivecture). That way, we can link the x86 code generator on +// another architecture (e.g. arm). bool useSSE(ArchitectureContext* c) { @@ -27,8 +55,11 @@ bool useSSE(ArchitectureContext* c) } else if (c->useNativeFeatures) { static int supported = -1; if (supported == -1) { - supported = detectFeature(0, 0x2000000) // SSE 1 - and detectFeature(0, 0x4000000); // SSE 2 + unsigned eax; + unsigned ebx; + unsigned ecx; + unsigned edx; + supported = __get_cpuid(1, &eax, &ebx, &ecx, &edx) && (edx & bit_SSE) && (edx & bit_SSE2); } return supported; } else { diff --git a/src/x86.S b/src/x86.S index 704ad5d61c..c02882d31d 100644 --- a/src/x86.S +++ b/src/x86.S @@ -27,37 +27,6 @@ #define CHECKPOINT_STACK 48 #ifdef __MINGW32__ -.globl GLOBAL(detectFeature) -GLOBAL(detectFeature): - pushq %rbp - movq %rsp, %rbp - pushq %rdx - pushq %rcx - pushq %rbx - pushq %rsi - pushq %rdi - movl %ecx, %edi - movl %edx, %esi - movl $1, %eax - cpuid - andl %esi, %edx - andl %edi, %ecx - orl %edx, %ecx - test %ecx, %ecx - je LOCAL(NOSSE) - movl $1, %eax - jmp LOCAL(SSEEND) -LOCAL(NOSSE): - movl $0, %eax -LOCAL(SSEEND): - popq %rdi - popq %rsi - popq %rbx - popq %rcx - popq %rdx - movq %rbp,%rsp - popq %rbp - ret .globl GLOBAL(vmNativeCall) GLOBAL(vmNativeCall): @@ -219,31 +188,6 @@ GLOBAL(vmRun_returnAddress): ret #else // not __MINGW32__ -.globl GLOBAL(detectFeature) -GLOBAL(detectFeature): - pushq %rbp - movq %rsp, %rbp - pushq %rdx - pushq %rcx - pushq %rbx - movl $1, %eax - cpuid - andl %esi, %edx - andl %edi, %ecx - orl %edx, %ecx - test %ecx, %ecx - je LOCAL(NOSSE) - movl $1, %eax - jmp LOCAL(SSEEND) -LOCAL(NOSSE): - movl $0, %eax -LOCAL(SSEEND): - popq %rbx - popq %rcx - popq %rdx - movq %rbp,%rsp - popq %rbp - ret .globl GLOBAL(vmNativeCall) GLOBAL(vmNativeCall): @@ -403,38 +347,6 @@ GLOBAL(vmRun_returnAddress): #define CHECKPOINT_STACK 24 #define CHECKPOINT_BASE 28 -.globl GLOBAL(detectFeature) -GLOBAL(detectFeature): - pushl %ebp - movl %esp, %ebp - pushl %edx - pushl %ecx - pushl %ebx - pushl %esi - pushl %edi - movl 12(%ebp), %esi - movl 8(%ebp), %edi - movl $1, %eax - cpuid - andl %esi, %edx - andl %edi, %ecx - orl %edx, %ecx - test %ecx, %ecx - je LOCAL(NOSSE) - movl $1, %eax - jmp LOCAL(SSEEND) -LOCAL(NOSSE): - movl $0, %eax -LOCAL(SSEEND): - popl %edi - popl %esi - popl %ebx - popl %ecx - popl %edx - movl %ebp,%esp - popl %ebp - ret - .globl GLOBAL(vmNativeCall) GLOBAL(vmNativeCall): pushl %ebp diff --git a/src/x86.masm b/src/x86.masm index db2030576a..10b992b771 100644 --- a/src/x86.masm +++ b/src/x86.masm @@ -30,40 +30,6 @@ 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 From d8e0f5cc067f4282fb43617d544ab73464d96c2b Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Tue, 29 Jul 2014 15:31:17 -0600 Subject: [PATCH 3/7] fix zlib headers / linking for windows --- cmake/Platform.cmake | 3 +++ src/tools/type-generator/CMakeLists.txt | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cmake/Platform.cmake b/cmake/Platform.cmake index 1bfb373ee7..20116488a7 100644 --- a/cmake/Platform.cmake +++ b/cmake/Platform.cmake @@ -13,3 +13,6 @@ ELSE() SET(PLATFORM_CXX_FLAGS "-Wall -Werror -fno-exceptions -std=c++0x") SET(PLATFORM_LIBS ${PLATFORM_LIBS} pthread dl) ENDIF() + +find_package(ZLIB REQUIRED) +include_directories(${ZLIB_INCLUDE_DIRS}) diff --git a/src/tools/type-generator/CMakeLists.txt b/src/tools/type-generator/CMakeLists.txt index 1c4b64382e..53bb7cabb1 100644 --- a/src/tools/type-generator/CMakeLists.txt +++ b/src/tools/type-generator/CMakeLists.txt @@ -4,8 +4,6 @@ target_link_libraries(type_generator avian_jvm_finder avian_system avian_util - z - pthread - dl + ${ZLIB_LIBRARIES} ${PLATFORM_LIBS} ) From 374a39651be7ed964571607057549920949e48bf Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Tue, 29 Jul 2014 18:57:02 -0600 Subject: [PATCH 4/7] allow passing flags to ci.sh script --- test/ci.sh | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/test/ci.sh b/test/ci.sh index 11ec7352db..90d0ebfb18 100755 --- a/test/ci.sh +++ b/test/ci.sh @@ -23,18 +23,14 @@ run_cmake() { cd .. } -if [ ${#} -gt 0 ]; then - run make ${@} -else - run_cmake -DCMAKE_BUILD_TYPE=Debug +run_cmake -DCMAKE_BUILD_TYPE=Debug - run make jdk-test - run make test - run make mode=debug test - run make process=interpret test - run make bootimage=true test - run make mode=debug bootimage=true test - run make openjdk=$JAVA_HOME test - run make tails=true continuations=true heapdump=true test - run make codegen-targets=all -fi +run make jdk-test +run make ${@} test +run make ${@} mode=debug test +run make ${@} process=interpret test +run make ${@} bootimage=true test +run make ${@} mode=debug bootimage=true test +run make ${@} openjdk=$JAVA_HOME test +run make ${@} tails=true continuations=true heapdump=true test +run make ${@} codegen-targets=all From ce1a5f5c28bb751530214c8581e9480e399357ed Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Tue, 29 Jul 2014 19:12:43 -0600 Subject: [PATCH 5/7] fix macosx arch=i386 process=interpret build --- src/interpret.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/interpret.cpp b/src/interpret.cpp index b1f5a648fe..4c908fa09a 100644 --- a/src/interpret.cpp +++ b/src/interpret.cpp @@ -1288,7 +1288,7 @@ loop: } goto loop; - case dup: { + case vm::dup: { if (DebugStack) { fprintf(stderr, "dup\n"); } @@ -1323,7 +1323,7 @@ loop: } goto loop; - case dup2: { + case vm::dup2: { if (DebugStack) { fprintf(stderr, "dup2\n"); } From d47fcdc34902e3adae786d2b7a977f962767e8ec Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Tue, 29 Jul 2014 19:29:29 -0600 Subject: [PATCH 6/7] fix ubuntu precise mingw math.h problems --- 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 ae378e45d1..9784f127a3 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -8,7 +8,6 @@ There is NO WARRANTY for this software. See license.txt for details. */ -#include "math.h" #include "stdlib.h" #include "time.h" #include "string.h" @@ -19,6 +18,11 @@ #include "fcntl.h" #include "ctype.h" +// Make sure M_* constants (in particular M_E) are exposed in math.h. +// This was a problem on the default mingw install on ubuntu precise +#undef __STRICT_ANSI__ +#include "math.h" + #ifdef PLATFORM_WINDOWS #include "windows.h" From e92230c89c99e82d72a654071f461bc5fafc1604 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Jul 2014 08:38:48 -0600 Subject: [PATCH 7/7] use c++11-conformant _WIN32 test macro --- src/lzma/main.cpp | 6 +++--- src/tools/binary-to-object/main.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lzma/main.cpp b/src/lzma/main.cpp index daf75c9cde..91d828df01 100644 --- a/src/lzma/main.cpp +++ b/src/lzma/main.cpp @@ -4,7 +4,7 @@ #include #include #include -#ifdef WIN32 +#ifdef _WIN32 #include #else #include @@ -65,7 +65,7 @@ int main(int argc, const char** argv) struct stat s; int r = fstat(fd, &s); if (r != -1) { -#ifdef WIN32 +#ifdef _WIN32 HANDLE fm; HANDLE h = (HANDLE)_get_osfhandle(fd); @@ -178,7 +178,7 @@ int main(int argc, const char** argv) fprintf(stderr, "unable to determine uncompressed size\n"); } -#ifdef WIN32 +#ifdef _WIN32 UnmapViewOfFile(data); #else munmap(data, size); diff --git a/src/tools/binary-to-object/main.cpp b/src/tools/binary-to-object/main.cpp index 8889dbaf24..1636d46dfd 100644 --- a/src/tools/binary-to-object/main.cpp +++ b/src/tools/binary-to-object/main.cpp @@ -14,7 +14,7 @@ #include #include -#ifdef WIN32 +#ifdef _WIN32 #include #include #else @@ -120,7 +120,7 @@ int main(int argc, const char** argv) struct stat s; int r = fstat(fd, &s); if (r != -1) { -#ifdef WIN32 +#ifdef _WIN32 HANDLE fm; HANDLE h = (HANDLE)_get_osfhandle(fd); @@ -157,7 +157,7 @@ int main(int argc, const char** argv) fprintf(stderr, "unable to open %s\n", argv[2]); } -#ifdef WIN32 +#ifdef _WIN32 UnmapViewOfFile(data); #else munmap(data, size);