From 6f1d02dae741a114256bc13002ef93dc6c5f4553 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 28 Oct 2008 15:40:50 -0600 Subject: [PATCH] remove the libstdc++ dependency once and for all The trick is to make all destructors non-virtual. This is safe because we never use the delete operator, which is the only case where virtual destructors are relevant. This is a better solution than implementing our own delete operator, because we want libraries loaded at runtime to use the libstdc++ version, not ours. --- makefile | 13 +++++-------- src/allocator.h | 1 - src/assembler.h | 8 -------- src/boot.cpp | 7 ++----- src/compiler.cpp | 4 ---- src/compiler.h | 4 ---- src/finder.cpp | 2 +- src/finder.h | 1 - src/heap.h | 4 ---- src/machine.h | 2 +- src/processor.h | 6 ------ src/stream.h | 1 - src/system.h | 12 ------------ src/x86.cpp | 2 -- 14 files changed, 9 insertions(+), 58 deletions(-) diff --git a/makefile b/makefile index 7db5d3de86..3b2cbca49e 100644 --- a/makefile +++ b/makefile @@ -50,7 +50,11 @@ strip-all = --strip-all rdynamic = -rdynamic -warnings = -Wall -Wextra -Werror -Wunused-parameter -Winit-self +# note that we supress the non-virtual-dtor warning because we never +# use the delete operator, which means we don't need virtual +# destructors: +warnings = -Wall -Wextra -Werror -Wunused-parameter -Winit-self \ + -Wno-non-virtual-dtor common-cflags = $(warnings) -fno-rtti -fno-exceptions \ "-I$(JAVA_HOME)/include" -idirafter $(src) -I$(native-build) \ @@ -62,15 +66,8 @@ build-cflags = $(common-cflags) -fPIC -fvisibility=hidden \ cflags = $(build-cflags) -use-libstdcpp = true - common-lflags = -lm -lz -ifeq ($(use-libstdcpp),true) - common-lflags += -lstdc++ - common-cflags += -DUSE_LIBSTDCPP -endif - build-lflags = lflags = $(common-lflags) -lpthread -ldl diff --git a/src/allocator.h b/src/allocator.h index 4951a7be08..c78273ad8e 100644 --- a/src/allocator.h +++ b/src/allocator.h @@ -17,7 +17,6 @@ namespace vm { class Allocator { public: - virtual ~Allocator() { } virtual void* tryAllocate(unsigned size) = 0; virtual void* allocate(unsigned size) = 0; virtual void free(const void* p, unsigned size) = 0; diff --git a/src/assembler.h b/src/assembler.h index cfaa0d5b59..eceedc5993 100644 --- a/src/assembler.h +++ b/src/assembler.h @@ -78,8 +78,6 @@ const int AnyRegister = -2; class Promise { public: - virtual ~Promise() { } - virtual int64_t value() = 0; virtual bool resolved() = 0; }; @@ -101,8 +99,6 @@ class ResolvedPromise: public Promise { class TraceHandler { public: - virtual ~TraceHandler() { } - virtual void handleTrace(Promise* address) = 0; }; @@ -146,8 +142,6 @@ class Assembler { class Client { public: - virtual ~Client() { } - virtual int acquireTemporary (uint32_t mask = ~static_cast(0)) = 0; virtual void releaseTemporary(int r) = 0; @@ -156,8 +150,6 @@ class Assembler { virtual void restore(int r) = 0; }; - virtual ~Assembler() { } - virtual void setClient(Client* client) = 0; virtual unsigned registerCount() = 0; diff --git a/src/boot.cpp b/src/boot.cpp index f6f0c95ba6..9f4c96a612 100644 --- a/src/boot.cpp +++ b/src/boot.cpp @@ -11,12 +11,9 @@ #include "stdint.h" #include "stdlib.h" -#ifndef USE_LIBSTDCPP -// since we aren't linking against libstdc++, we must implement some -// dummy functions: +// since we aren't linking against libstdc++, we must implement this +// ourselves: extern "C" void __cxa_pure_virtual(void) { abort(); } -void operator delete(void*) { abort(); } -#endif #ifdef __MINGW32__ # define EXPORT __declspec(dllexport) diff --git a/src/compiler.cpp b/src/compiler.cpp index bf6c4f0d4e..1ef9659829 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -48,8 +48,6 @@ class Site { public: Site(): next(0) { } - virtual ~Site() { } - virtual Site* readTarget(Context*, Read*) { return this; } virtual unsigned copyCost(Context*, Site*) = 0; @@ -364,8 +362,6 @@ class Event { sequence(sequence), stackReset(false) { } - virtual ~Event() { } - virtual void compile(Context* c) = 0; virtual bool skipMove(unsigned) { return false; } diff --git a/src/compiler.h b/src/compiler.h index 2433b3caba..999b31f220 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -21,8 +21,6 @@ class Compiler { public: class Client { public: - virtual ~Client() { } - virtual intptr_t getThunk(UnaryOperation op, unsigned size) = 0; virtual intptr_t getThunk(BinaryOperation op, unsigned size) = 0; }; @@ -32,8 +30,6 @@ class Compiler { class Operand { }; - virtual ~Compiler() { } - virtual void pushState() = 0; virtual void popState() = 0; virtual void saveStack() = 0; diff --git a/src/finder.cpp b/src/finder.cpp index dbef2c9bb2..091593d9ea 100644 --- a/src/finder.cpp +++ b/src/finder.cpp @@ -60,7 +60,7 @@ equal(const void* a, unsigned al, const void* b, unsigned bl) class Element { public: Element(): next(0) { } - virtual ~Element() { } + virtual System::Region* find(const char* name) = 0; virtual bool exists(const char* name) = 0; virtual void dispose() = 0; diff --git a/src/finder.h b/src/finder.h index 6b3a868f68..64eb4c287b 100644 --- a/src/finder.h +++ b/src/finder.h @@ -19,7 +19,6 @@ namespace vm { class Finder { public: - virtual ~Finder() { } virtual System::Region* find(const char* name) = 0; virtual bool exists(const char* name) = 0; virtual const char* path() = 0; diff --git a/src/heap.h b/src/heap.h index bf4dc5a360..bc8f9a5a1c 100644 --- a/src/heap.h +++ b/src/heap.h @@ -32,19 +32,16 @@ class Heap: public Allocator { class Visitor { public: - virtual ~Visitor() { } virtual void visit(void*) = 0; }; class Walker { public: - virtual ~Walker() { } virtual bool visit(unsigned) = 0; }; class Client { public: - virtual ~Client() { } virtual void collect(void* context, CollectionType type) = 0; virtual void visitRoots(Visitor*) = 0; virtual bool isFixed(void*) = 0; @@ -54,7 +51,6 @@ class Heap: public Allocator { virtual void walk(void*, Walker*) = 0; }; - virtual ~Heap() { } virtual void setClient(Client* client) = 0; virtual void collect(CollectionType type, unsigned footprint) = 0; virtual void* allocateFixed(Allocator* allocator, unsigned sizeInWords, diff --git a/src/machine.h b/src/machine.h index c27e394c5b..3c12722c21 100644 --- a/src/machine.h +++ b/src/machine.h @@ -1212,7 +1212,7 @@ class Thread { t->protector = this; } - virtual ~Protector() { + ~Protector() { t->protector = next; } diff --git a/src/processor.h b/src/processor.h index 459970143e..a0ef3491b2 100644 --- a/src/processor.h +++ b/src/processor.h @@ -23,15 +23,11 @@ class Processor { class StackVisitor { public: - virtual ~StackVisitor() { } - virtual bool visit(StackWalker* walker) = 0; }; class StackWalker { public: - virtual ~StackWalker() { } - virtual void walk(StackVisitor* v) = 0; virtual object method() = 0; @@ -41,8 +37,6 @@ class Processor { virtual unsigned count() = 0; }; - virtual ~Processor() { } - virtual Thread* makeThread(Machine* m, object javaThread, Thread* parent) = 0; diff --git a/src/stream.h b/src/stream.h index c740d082b1..bf59e41865 100644 --- a/src/stream.h +++ b/src/stream.h @@ -19,7 +19,6 @@ class Stream { public: class Client { public: - virtual ~Client() { } virtual void NO_RETURN handleError() = 0; }; diff --git a/src/system.h b/src/system.h index 69d42a25e1..3a5cb3cf22 100644 --- a/src/system.h +++ b/src/system.h @@ -28,7 +28,6 @@ class System { class Thread { public: - virtual ~Thread() { } virtual void interrupt() = 0; virtual void join() = 0; virtual void dispose() = 0; @@ -36,13 +35,11 @@ class System { class ThreadVisitor { public: - virtual ~ThreadVisitor() { } virtual void visit(void* ip, void* base, void* stack) = 0; }; class Runnable { public: - virtual ~Runnable() { } virtual void attach(Thread*) = 0; virtual void run() = 0; virtual bool interrupted() = 0; @@ -51,7 +48,6 @@ class System { class Mutex { public: - virtual ~Mutex() { } virtual void acquire() = 0; virtual void release() = 0; virtual void dispose() = 0; @@ -59,7 +55,6 @@ class System { class Monitor { public: - virtual ~Monitor() { } virtual bool tryAcquire(Thread* context) = 0; virtual void acquire(Thread* context) = 0; virtual void release(Thread* context) = 0; @@ -72,7 +67,6 @@ class System { class Local { public: - virtual ~Local() { } virtual void* get() = 0; virtual void set(void* p) = 0; virtual void dispose() = 0; @@ -80,7 +74,6 @@ class System { class Region { public: - virtual ~Region() { } virtual const uint8_t* start() = 0; virtual size_t length() = 0; virtual void dispose() = 0; @@ -88,7 +81,6 @@ class System { class Library { public: - virtual ~Library() { } virtual void* resolve(const char* function) = 0; virtual const char* name() = 0; virtual bool mapName() = 0; @@ -99,8 +91,6 @@ class System { class SignalHandler { public: - virtual ~SignalHandler() { } - virtual bool handleSignal(void** ip, void** base, void** stack, void** thread) = 0; }; @@ -120,8 +110,6 @@ class System { System::Monitor* m; }; - virtual ~System() { } - virtual bool success(Status) = 0; virtual void* tryAllocate(unsigned sizeInBytes) = 0; virtual void free(const void* p) = 0; diff --git a/src/x86.cpp b/src/x86.cpp index 3b6c050f40..8da31a0d8f 100644 --- a/src/x86.cpp +++ b/src/x86.cpp @@ -130,8 +130,6 @@ class Task { public: Task(Task* next): next(next) { } - virtual ~Task() { } - virtual void run(Context* c) = 0; Task* next;