diff --git a/classpath/jni-util.h b/classpath/jni-util.h index 4973891704..57e545a14b 100644 --- a/classpath/jni-util.h +++ b/classpath/jni-util.h @@ -73,8 +73,6 @@ typedef unsigned __int64 uint64_t; #endif // not _MSC_VER -namespace { - inline void throwNew(JNIEnv* e, const char* class_, const char* message, ...) { @@ -149,7 +147,4 @@ class RuntimeArray { #endif // not _MSC_VER - -} // namespace - #endif//JNI_UTIL diff --git a/makefile b/makefile index 42ef1b95e7..b528fc2fb3 100755 --- a/makefile +++ b/makefile @@ -138,8 +138,13 @@ endif input = List -build-cxx = g++ -build-cc = gcc +ifeq ($(use-clang),true) + build-cxx = clang + build-cc = clang +else + build-cxx = g++ + build-cc = gcc +endif mflag = ifneq ($(platform),darwin) @@ -195,7 +200,8 @@ build-cflags = $(common-cflags) -fPIC -fvisibility=hidden \ converter-cflags = -D__STDC_CONSTANT_MACROS -Isrc/binaryToObject -Isrc/ \ -fno-rtti -fno-exceptions \ -DAVIAN_TARGET_ARCH=AVIAN_ARCH_UNKNOWN \ - -DAVIAN_TARGET_PLATFORM=AVIAN_PLATFORM_UNKNOWN + -DAVIAN_TARGET_PLATFORM=AVIAN_PLATFORM_UNKNOWN \ + -Wall -Wextra -Werror -Wunused-parameter -Winit-self cflags = $(build-cflags) @@ -446,23 +452,32 @@ ifeq ($(mode),stress-major) strip = : endif ifeq ($(mode),fast) - optimization-cflags = -O3 -g3 -DNDEBUG + optimization-cflags = -O4 -g3 -DNDEBUG use-lto = true endif ifeq ($(mode),small) - optimization-cflags = -Os -g3 -DNDEBUG + ifeq ($(use-clang),true) + optimization-cflags = -Oz -g3 -DNDEBUG + else + optimization-cflags = -Os -g3 -DNDEBUG + endif use-lto = true endif ifeq ($(use-lto),true) -# only try to use LTO when GCC 4.6.0 or greater is available - gcc-major := $(shell $(cc) -dumpversion | cut -f1 -d.) - gcc-minor := $(shell $(cc) -dumpversion | cut -f2 -d.) - ifeq ($(shell expr 4 \< $(gcc-major) \ - \| \( 4 \<= $(gcc-major) \& 6 \<= $(gcc-minor) \)),1) + ifeq ($(use-clang),true) optimization-cflags += -flto - no-lto = -fno-lto lflags += $(optimization-cflags) + else +# only try to use LTO when GCC 4.6.0 or greater is available + gcc-major := $(shell $(cc) -dumpversion | cut -f1 -d.) + gcc-minor := $(shell $(cc) -dumpversion | cut -f2 -d.) + ifeq ($(shell expr 4 \< $(gcc-major) \ + \| \( 4 \<= $(gcc-major) \& 6 \<= $(gcc-minor) \)),1) + optimization-cflags += -flto + no-lto = -fno-lto + lflags += $(optimization-cflags) + endif endif endif diff --git a/readme.txt b/readme.txt index 6c08030677..ac54ca700f 100644 --- a/readme.txt +++ b/readme.txt @@ -63,6 +63,7 @@ Build requirements include: * GNU make 3.80 or later * GCC 3.4 or later (4.5.1 or later for Windows/x86_64) + or LLVM Clang 3.1 or later (see use-clang option below) * JDK 1.5 or later * MinGW 3.4 or later (only if compiling for Windows) * zlib 1.2.3 or later @@ -83,6 +84,7 @@ certain flags described below, all of which are optional. heapdump={true,false} \ tails={true,false} \ continuations={true,false} \ + use-clang={true,false} \ openjdk= \ openjdk-src= @@ -134,6 +136,11 @@ certain flags described below, all of which are optional. only valid for process=compile builds. default: false + * use-clang - if true, use LLVM's clang instead of GCC to build. + Note that this does not currently affect cross compiles, only + native builds. + default: false + * openjdk - if set, use OpenJDK class library instead of the default Avian class library. See "Building with the OpenJDK Class Library" below for details. diff --git a/src/binaryToObject/elf.cpp b/src/binaryToObject/elf.cpp index caf7c9c545..b4e0025b02 100644 --- a/src/binaryToObject/elf.cpp +++ b/src/binaryToObject/elf.cpp @@ -131,8 +131,9 @@ unsigned getElfPlatform(PlatformInfo::Architecture arch) { return EM_ARM; case PlatformInfo::PowerPC: return EM_PPC; + default: + return ~0; } - return ~0; } const char* getSectionName(unsigned accessFlags, unsigned& sectionFlags) { @@ -255,8 +256,8 @@ public: SectionWriter(FileWriter& file): file(file), name(""), - data(0), - dataSize(0) + dataSize(0), + data(0) { memset(&header, 0, sizeof(SectionHeader)); file.sectionCount++; @@ -279,8 +280,8 @@ public: file(file), name(chname), - data(data), - dataSize(dataSize) + dataSize(dataSize), + data(data) { if(strcmp(chname, ".shstrtab") == 0) { file.sectionStringTableSectionNumber = file.sectionCount; @@ -359,11 +360,11 @@ public: file.writeHeader(out); - for(int i = 0; i < file.sectionCount; i++) { + for(unsigned i = 0; i < file.sectionCount; i++) { sections[i].writeHeader(out); } - for(int i = 0; i < file.sectionCount; i++) { + for(unsigned i = 0; i < file.sectionCount; i++) { sections[i].writeData(out); } diff --git a/src/binaryToObject/mach-o.cpp b/src/binaryToObject/mach-o.cpp index 50d7e56d78..dd89ddb304 100644 --- a/src/binaryToObject/mach-o.cpp +++ b/src/binaryToObject/mach-o.cpp @@ -183,14 +183,14 @@ public: FileHeader header = { V4(Magic), // magic - V4(cpuType), - V4(cpuSubType), + static_cast(V4(cpuType)), + static_cast(V4(cpuSubType)), V4(MH_OBJECT), // filetype, V4(2), // ncmds V4(sizeof(SegmentCommand) + sizeof(Section) + sizeof(SymtabCommand)), // sizeofcmds - V4(0) // flags + { V4(0) } // flags }; AddrTy finalSize = pad(data.count); @@ -206,8 +206,8 @@ public: + sizeof(Section) + sizeof(SymtabCommand))), // fileoff VANY(static_cast(finalSize)), // filesize - V4(7), // maxprot - V4(7), // initprot + static_cast(V4(7)), // maxprot + static_cast(V4(7)), // initprot V4(1), // nsects V4(0) // flags }; @@ -243,7 +243,7 @@ public: strings.write("_", 1); strings.add(sym->name); NList symbol = { - V4(offset), // n_un + { V4(offset) }, // n_un V1(N_SECT | N_EXT), // n_type V1(1), // n_sect V2(0), // n_desc @@ -281,6 +281,8 @@ public: out->writeChunk(symbolList.data, symbolList.length); out->writeChunk(strings.data, strings.length); + + return true; } MachOPlatform(PlatformInfo::Architecture arch): diff --git a/src/binaryToObject/main.cpp b/src/binaryToObject/main.cpp index d8f801a5e3..851a805bec 100644 --- a/src/binaryToObject/main.cpp +++ b/src/binaryToObject/main.cpp @@ -33,7 +33,7 @@ void* operator new(size_t size) { return malloc(size); } -void operator delete(void* mem) { abort(); } +void operator delete(void*) { abort(); } namespace { diff --git a/src/binaryToObject/pe.cpp b/src/binaryToObject/pe.cpp index 32f13cc4fa..69ca719bc1 100644 --- a/src/binaryToObject/pe.cpp +++ b/src/binaryToObject/pe.cpp @@ -129,11 +129,11 @@ public: void addSymbol(String name, unsigned addr, unsigned sectionNumber, unsigned type, unsigned storageClass) { unsigned nameOffset = strings.add(name); IMAGE_SYMBOL symbol = { - { 0 }, // Name + { { 0, 0 } }, // Name addr, // Value - sectionNumber, // SectionNumber - type, // Type - storageClass, // StorageClass + static_cast(sectionNumber), // SectionNumber + static_cast(type), // Type + static_cast(storageClass), // StorageClass 0, // NumberOfAuxSymbols }; symbol.N.Name.Long = nameOffset+4; @@ -165,9 +165,9 @@ public: size_t dataSize): file(file), - data(data), dataSize(dataSize), - finalSize(pad(dataSize)) + finalSize(pad(dataSize)), + data(data) { file.sectionCount++; file.dataStart += sizeof(IMAGE_SECTION_HEADER); diff --git a/src/bootimage.cpp b/src/bootimage.cpp index 17a27f198d..a4555a9f6e 100644 --- a/src/bootimage.cpp +++ b/src/bootimage.cpp @@ -62,14 +62,6 @@ enum Type { class Field { public: - Field() { } - - Field(Type type, unsigned buildOffset, unsigned buildSize, - unsigned targetOffset, unsigned targetSize): - type(type), buildOffset(buildOffset), buildSize(buildSize), - targetOffset(targetOffset), targetSize(targetSize) - { } - Type type; unsigned buildOffset; unsigned buildSize; @@ -77,6 +69,17 @@ class Field { unsigned targetSize; }; +void +init(Field* f, Type type, unsigned buildOffset, unsigned buildSize, + unsigned targetOffset, unsigned targetSize) +{ + f->type = type; + f->buildOffset = buildOffset; + f->buildSize = buildSize; + f->targetOffset = targetOffset; + f->targetSize = targetSize; +} + class TypeMap { public: enum Kind { @@ -397,9 +400,9 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, map->targetFixedOffsets()[i * BytesPerWord] = i * TargetBytesPerWord; - new (map->fixedFields() + i) Field - (types[i], i * BytesPerWord, BytesPerWord, - i * TargetBytesPerWord, TargetBytesPerWord); + init(new (map->fixedFields() + i) Field, types[i], + i * BytesPerWord, BytesPerWord, i * TargetBytesPerWord, + TargetBytesPerWord); } hashMapInsert @@ -446,8 +449,8 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, ++ memberIndex; } } else { - new (memberFields) Field - (Type_object, 0, BytesPerWord, 0, TargetBytesPerWord); + init(new (memberFields) Field, Type_object, 0, BytesPerWord, 0, + TargetBytesPerWord); memberIndex = 1; buildMemberOffset = BytesPerWord; @@ -456,12 +459,11 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, Field staticFields[count + 2]; - new (staticFields) Field - (Type_object, 0, BytesPerWord, 0, TargetBytesPerWord); + init(new (staticFields) Field, Type_object, 0, BytesPerWord, 0, + TargetBytesPerWord); - new (staticFields + 1) Field - (Type_intptr_t, BytesPerWord, BytesPerWord, TargetBytesPerWord, - TargetBytesPerWord); + init(new (staticFields + 1) Field, Type_intptr_t, BytesPerWord, + BytesPerWord, TargetBytesPerWord, TargetBytesPerWord); unsigned staticIndex = 2; unsigned buildStaticOffset = BytesPerWord * 2; @@ -510,9 +512,9 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, buildStaticOffset = fieldOffset(t, field); - new (staticFields + staticIndex) Field - (type, buildStaticOffset, buildSize, targetStaticOffset, - targetSize); + init(new (staticFields + staticIndex) Field, type, + buildStaticOffset, buildSize, targetStaticOffset, + targetSize); targetStaticOffset += targetSize; @@ -524,9 +526,9 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, buildMemberOffset = fieldOffset(t, field); - new (memberFields + memberIndex) Field - (type, buildMemberOffset, buildSize, targetMemberOffset, - targetSize); + init(new (memberFields + memberIndex) Field, type, + buildMemberOffset, buildSize, targetMemberOffset, + targetSize); targetMemberOffset += targetSize; @@ -693,12 +695,6 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, return constants; } -unsigned -objectSize(Thread* t, object o) -{ - return baseSize(t, o, objectClass(t, o)); -} - void visitRoots(Thread* t, BootImage* image, HeapWalker* w, object constants) { @@ -1267,12 +1263,6 @@ updateConstants(Thread* t, object constants, HeapMap* heapTable) } } -unsigned -offset(object a, uintptr_t* b) -{ - return reinterpret_cast(b) - reinterpret_cast(a); -} - BootImage::Thunk targetThunk(BootImage::Thunk t) { @@ -1347,7 +1337,8 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp Field fields[count]; - new (fields) Field(Type_object, 0, BytesPerWord, 0, TargetBytesPerWord); + init(new (fields) Field, Type_object, 0, BytesPerWord, 0, + TargetBytesPerWord); unsigned buildOffset = BytesPerWord; unsigned targetOffset = TargetBytesPerWord; @@ -1424,8 +1415,8 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp ++ targetOffset; } - new (fields + j) Field - (type, buildOffset, buildSize, targetOffset, targetSize); + init(new (fields + j) Field, type, buildOffset, buildSize, + targetOffset, targetSize); buildOffset += buildSize; targetOffset += targetSize; diff --git a/src/compile.cpp b/src/compile.cpp index 5e54cd8616..157f1fd24b 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -288,14 +288,6 @@ transition(MyThread* t, void* ip, void* stack, object continuation, MyThread::doTransition(t, ip, stack, continuation, trace); } -unsigned -parameterOffset(MyThread* t, object method) -{ - return methodParameterFootprint(t, method) - + t->arch->frameFooterSize() - + t->arch->frameReturnAddressSize() - 1; -} - object resolveThisPointer(MyThread* t, void* stack) { diff --git a/src/compiler.cpp b/src/compiler.cpp index 56a2709e42..e3e24103c6 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -579,27 +579,6 @@ cons(Context* c, void* value, Cell* next) return new (c->zone) Cell(next, value); } -Cell* -append(Context* c, Cell* first, Cell* second) -{ - if (first) { - if (second) { - Cell* start = cons(c, first->value, second); - Cell* end = start; - for (Cell* cell = first->next; cell; cell = cell->next) { - Cell* n = cons(c, cell->value, second); - end->next = n; - end = n; - } - return start; - } else { - return first; - } - } else { - return second; - } -} - Cell* reverseDestroy(Cell* cell) { @@ -992,25 +971,6 @@ valid(Read* r) return r and r->valid(); } -bool -hasBuddy(Context* c, Value* a, Value* b) -{ - if (a == b) { - return true; - } - - int i = 0; - for (Value* p = a->buddy; p != a; p = p->buddy) { - if (p == b) { - return true; - } - if (++i > 1000) { - abort(c); - } - } - return false; -} - Read* live(Context* c UNUSED, Value* v) { @@ -5302,16 +5262,17 @@ propagateJunctionSites(Context* c, Event* e) class SiteRecord { public: - SiteRecord(Site* site, Value* value): - site(site), value(value) - { } - - SiteRecord() { } - Site* site; Value* value; }; +void +init(SiteRecord* r, Site* s, Value* v) +{ + r->site = s; + r->value = v; +} + class SiteRecordList { public: SiteRecordList(SiteRecord* records, unsigned capacity): @@ -5329,7 +5290,7 @@ freeze(Context* c, SiteRecordList* frozen, Site* s, Value* v) assert(c, frozen->index < frozen->capacity); s->freeze(c, v); - new (frozen->records + (frozen->index ++)) SiteRecord(s, v); + init(new (frozen->records + (frozen->index ++)) SiteRecord, s, v); } void @@ -5866,17 +5827,6 @@ compile(Context* c, uintptr_t stackOverflowHandler, unsigned stackLimitOffset) c->firstBlock = firstBlock; } -unsigned -count(Stack* s) -{ - unsigned c = 0; - while (s) { - ++ c; - s = s->next; - } - return c; -} - void restore(Context* c, ForkState* state) { diff --git a/src/heap.cpp b/src/heap.cpp index b99de70de7..ed5d8777d4 100644 --- a/src/heap.cpp +++ b/src/heap.cpp @@ -60,7 +60,6 @@ void NO_RETURN abort(Context*); void assert(Context*, bool); #endif -System* system(Context*); void* tryAllocate(Context* c, unsigned size); void* allocate(Context* c, unsigned size); void free(Context* c, const void* p, unsigned size); @@ -689,12 +688,6 @@ class Context { int64_t totalTime; }; -inline System* -system(Context* c) -{ - return c->system; -} - const char* segment(Context* c, void* p) { diff --git a/src/heapwalk.cpp b/src/heapwalk.cpp index a34baf96dc..811382a825 100644 --- a/src/heapwalk.cpp +++ b/src/heapwalk.cpp @@ -231,16 +231,6 @@ get(object o, unsigned offsetInWords) (mask(cast(o, offsetInWords * BytesPerWord))); } -unsigned -objectSize(Thread* t, object o) -{ - unsigned n = baseSize(t, o, objectClass(t, o)); - if (objectExtended(t, o)) { - ++ n; - } - return n; -} - unsigned walk(Context* c, HeapVisitor* v, object p) { diff --git a/src/machine.cpp b/src/machine.cpp index 4c99de36de..53b6a0f66d 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -35,14 +35,6 @@ atomicIncrement(uint32_t* p, int v) } #endif -bool -find(Thread* t, Thread* o) -{ - return (t == o) - or (t->peer and find(t->peer, o)) - or (t->child and find(t->child, o)); -} - void join(Thread* t, Thread* o) { @@ -56,28 +48,6 @@ join(Thread* t, Thread* o) } } -unsigned -count(Thread* t, Thread* o) -{ - unsigned c = 0; - - if (t != o) ++ c; - if (t->peer) c += count(t->peer, o); - if (t->child) c += count(t->child, o); - - return c; -} - -Thread** -fill(Thread* t, Thread* o, Thread** array) -{ - if (t != o) *(array++) = t; - if (t->peer) array = fill(t->peer, o, array); - if (t->child) array = fill(t->child, o, array); - - return array; -} - void dispose(Thread* t, Thread* o, bool remove) { diff --git a/src/type-generator.cpp b/src/type-generator.cpp index ca5bd37056..813cce7dcd 100644 --- a/src/type-generator.cpp +++ b/src/type-generator.cpp @@ -70,12 +70,6 @@ equal(const char* a, const char* b) return strcmp(a, b) == 0; } -inline bool -startsWith(const char* a, const char* b) -{ - return strncmp(a, b, strlen(a)) == 0; -} - inline bool endsWith(const char* a, const char* b) { @@ -284,14 +278,6 @@ setCdr(Object* o, Object* v) static_cast(o)->cdr = v; } -unsigned -length(Object* o) -{ - unsigned c = 0; - for (; o; o = cdr(o)) ++c; - return c; -} - class List { public: Object* first; @@ -1078,53 +1064,6 @@ parseSubdeclaration(Object* t, Object* p, Object* declarations) } } -bool -memberEqual(Object* a, Object* b) -{ - if (a->type == b->type) { - switch (a->type) { - case Object::Scalar: - return equal(memberTypeName(a), memberTypeName(b)) - and memberNoAssert(a) == memberNoAssert(b) - and memberNoGC(a) == memberNoGC(b); - - // todo: compare array fields - - default: return false; - } - } else { - return false; - } -} - -bool -specEqual(Object* a, Object* b) -{ - if (a->type == Object::Type and - b->type == Object::Type) - { - MemberIterator ai(a); - MemberIterator bi(b); - while (ai.hasMore()) { - if (not bi.hasMore()) { - return false; - } - - if (not memberEqual(ai.next(), bi.next())) { - return false; - } - } - - if (bi.hasMore()) { - return false; - } else { - return true; - } - } else { - return false; - } -} - const char* append(const char* a, const char* b, const char* c, const char* d) { @@ -1725,13 +1664,6 @@ writeConstructorInitializations(Output* out, Object* t) } } -unsigned -typeMemberCount(Object* o) -{ - if (o == 0) return 0; - return length(typeMembers(o)) + typeMemberCount(typeSuper(o)); -} - void writeInitializerDeclarations(Output* out, Object* declarations) { @@ -1888,17 +1820,6 @@ writeEnums(Output* out, Object* declarations) } } -unsigned -memberCount(Object* o) -{ - unsigned c = 0; - for (MemberIterator it(o); it.hasMore();) { - it.next(); - ++c; - } - return c; -} - unsigned methodCount(Object* o) { diff --git a/src/x86.cpp b/src/x86.cpp index 095a567c63..6875449953 100644 --- a/src/x86.cpp +++ b/src/x86.cpp @@ -198,44 +198,12 @@ assert(ArchitectureContext* c, bool v) } #endif // not NDEBUG -void -expect(Context* c, bool v) -{ - expect(c->s, v); -} - ResolvedPromise* resolved(Context* c, int64_t value) { return new(c->zone) ResolvedPromise(value); } -class CodePromise: public Promise { - public: - CodePromise(Context* c, unsigned offset): c(c), offset(offset) { } - - virtual int64_t value() { - if (resolved()) { - return reinterpret_cast(c->result + offset); - } - - abort(c); - } - - virtual bool resolved() { - return c->result != 0; - } - - Context* c; - unsigned offset; -}; - -CodePromise* -codePromise(Context* c, unsigned offset) -{ - return new (c->zone) CodePromise(c, offset); -} - class Offset: public Promise { public: Offset(Context* c, MyBlock* block, unsigned offset, AlignmentPadding* limit): @@ -629,14 +597,6 @@ opcode(Context* c, uint8_t op1, uint8_t op2) c->code.append(op2); } -void -opcode(Context* c, uint8_t op1, uint8_t op2, uint8_t op3) -{ - c->code.append(op1); - c->code.append(op2); - c->code.append(op3); -} - void return_(Context* c) {