Skip to content

Instantly share code, notes, and snippets.

@MasterDuke17
Last active Dec 29, 2021
Embed
What would you like to do?
47c47
< CINCLUDES = -I3rdparty/libuv/include -I3rdparty/libuv/src -I3rdparty/libatomicops/src -I3rdparty/libtommath -I3rdparty/dyncall/dynload -I3rdparty/dyncall/dyncall -I3rdparty/dyncall/dyncallback \
---
> CINCLUDES = -I3rdparty/mimalloc/include -I3rdparty/mimalloc/src -I3rdparty/libuv/include -I3rdparty/libuv/src -I3rdparty/libatomicops/src -I3rdparty/libtommath -I3rdparty/dyncall/dynload -I3rdparty/dyncall/dyncall -I3rdparty/dyncall/dyncallback \
59c59
< DLL_LIBS = 3rdparty/cmp/libcmp.a 3rdparty/dyncall/dyncall/libdyncall_s.a 3rdparty/dyncall/dyncallback/libdyncallback_s.a 3rdparty/dyncall/dynload/libdynload_s.a 3rdparty/libatomicops/src/libatomic_ops.a 3rdparty/tinymt/libtinymt.a 3rdparty/sha1/libsha1.a 3rdparty/libtommath/libtommath.a 3rdparty/libuv/libuv.a $(LDLIBS)
---
> DLL_LIBS = 3rdparty/cmp/libcmp.a 3rdparty/dyncall/dyncall/libdyncall_s.a 3rdparty/dyncall/dyncallback/libdyncallback_s.a 3rdparty/dyncall/dynload/libdynload_s.a 3rdparty/libatomicops/src/libatomic_ops.a 3rdparty/mimalloc/libmimalloc.a 3rdparty/tinymt/libtinymt.a 3rdparty/sha1/libsha1.a 3rdparty/libtommath/libtommath.a 3rdparty/libuv/libuv.a $(LDLIBS)
539c539
< THIRDPARTY = 3rdparty/cmp/libcmp.a 3rdparty/dyncall/dyncall/libdyncall_s.a 3rdparty/dyncall/dyncallback/libdyncallback_s.a 3rdparty/dyncall/dynload/libdynload_s.a 3rdparty/libatomicops/src/libatomic_ops.a 3rdparty/tinymt/libtinymt.a 3rdparty/sha1/libsha1.a 3rdparty/libtommath/libtommath.a 3rdparty/libuv/libuv.a
---
> THIRDPARTY = 3rdparty/cmp/libcmp.a 3rdparty/dyncall/dyncall/libdyncall_s.a 3rdparty/dyncall/dyncallback/libdyncallback_s.a 3rdparty/dyncall/dynload/libdynload_s.a 3rdparty/libatomicops/src/libatomic_ops.a 3rdparty/mimalloc/libmimalloc.a 3rdparty/tinymt/libtinymt.a 3rdparty/sha1/libsha1.a 3rdparty/libtommath/libtommath.a 3rdparty/libuv/libuv.a
599a600,601
> $(MKPATH) "$(DESTDIR)$(PREFIX)/include/mimalloc"
> $(CP) 3rdparty/mimalloc/include/mimalloc.h "$(DESTDIR)$(PREFIX)/include/mimalloc"
738a741,743
> 3rdparty/mimalloc/libmimalloc.a:
> $(MSG) linking $@
> $(CMD) $(NOOUT)
diff --git Configure.pl Configure.pl
index 908aef0df..febe61dda 100755
--- Configure.pl
+++ Configure.pl
@@ -92,7 +92,7 @@ if ( $args{relocatable} && ($^O eq 'aix' || $^O eq 'openbsd') ) {
}
for (qw(coverage static big-endian has-libtommath has-sha has-libuv
- has-libatomic_ops asan ubsan tsan valgrind dtrace show-vec)) {
+ has-libatomic_ops asan ubsan tsan valgrind dtrace show-vec has-mimalloc)) {
$args{$_} = 0 unless defined $args{$_};
}
@@ -258,6 +258,18 @@ $config{cincludes} = '' unless defined $config{cincludes};
$config{moar_cincludes} = '' unless defined $config{moar_cincludes};
$config{lincludes} = '' unless defined $config{lincludes};
$config{install} = '' unless defined $config{install};
+if ($args{'has-mimalloc'}) {
+ $defaults{-thirdparty}->{mimalloc} = undef;
+ unshift @{$config{usrlibs}}, 'mimalloc';
+ setup_native_library('mimalloc') if $config{pkgconfig_works};
+}
+else {
+ $config{moar_cincludes} .= ' ' . $defaults{ccinc} . '3rdparty/mimalloc/include'
+ . ' ' . $defaults{ccinc} . '3rdparty/mimalloc/src';
+ $config{install} .= "\t\$(MKPATH) \"\$(DESTDIR)\$(PREFIX)/include/mimalloc\"\n"
+ . "\t\$(CP) 3rdparty/mimalloc/include/mimalloc.h \"\$(DESTDIR)\$(PREFIX)/include/mimalloc\"\n";
+ push @hllincludes, 'mimalloc';
+}
if ($args{'has-libuv'}) {
$defaults{-thirdparty}->{uv} = undef;
unshift @{$config{usrlibs}}, 'uv';
@@ -461,7 +473,7 @@ if (not $args{static} and $config{prefix} ne '/usr') {
push @ldflags, $config{ldrpath} if !$args{relocatable};
}
push @ldflags, '-fsanitize=address' if $args{asan};
-push @ldflags, '-fsanitize=thread' if $args{tsan};
+push @ldflags, '-fsanitize=thread' if $args{tsan};
push @ldflags, $ENV{LDFLAGS} if $ENV{LDFLAGS};
$config{ldflags} = join ' ', @ldflags;
diff --git LICENSE LICENSE
index 7365d9b5d..1fbcd2ad9 100644
--- LICENSE
+++ LICENSE
@@ -30,3 +30,4 @@ Unofficial summary of the intended application of the Artistic License 2.0:
- sha1 Public Domain
- tinymt MIT
- freebsd MIT
+- mimalloc MIT
diff --git build/Makefile.in build/Makefile.in
index 1e8257a5e..e3287cf12 100644
--- build/Makefile.in
+++ build/Makefile.in
@@ -701,6 +701,9 @@ tools/repr_size_table@exe@: tools/repr_size_table@obj@ @moarlib@ $(DLL_LIBS)
$(MSG) Building $@
$(CMD)$(LD) @ldout@$@ $(LDFLAGS) $(MINGW_UNICODE) $< @moarlib@ $(DLL_LIBS)
+@mmlib@:
+ $(MSG) linking $@
+ $(CMD)@mmrule@ $(NOOUT)
@uvlib@: $(UV_OBJECTS)
$(MSG) linking $@
diff --git build/check.mk.in build/check.mk.in
index 01b910ece..5b8ca898a 100644
--- build/check.mk.in
+++ build/check.mk.in
@@ -1,4 +1,5 @@
CINCLUDES := -Isrc \
+ -isystem 3rdparty/mimalloc/include \
-isystem 3rdparty/libuv/include \
-isystem 3rdparty/libatomicops/src \
-isystem 3rdparty/libtommath \
diff --git build/setup.pm build/setup.pm
index 3ac754db2..5e544e4f7 100644
--- build/setup.pm
+++ build/setup.pm
@@ -7,6 +7,13 @@ my $devnull = devnull();
# 3rdparty library configuration
+my %TP_MM = (
+ name => 'mimalloc',
+ path => '3rdparty/mimalloc',
+ src => [ '3rdparty/mimalloc' ],
+ rule => '',
+);
+
my %TP_LAO = (
name => 'atomic_ops',
path => '3rdparty/libatomicops/src',
@@ -74,6 +81,7 @@ my %TP_UV = (
);
our %THIRDPARTY = (
+ mm => { %TP_MM },
lao => { %TP_LAO },
tom => { %TP_TOM },
sha => { %TP_SHA },
diff --git src/core/alloc.h src/core/alloc.h
index d5f25b21c..35932b92e 100644
--- src/core/alloc.h
+++ src/core/alloc.h
@@ -1,5 +1,5 @@
MVM_STATIC_INLINE void * MVM_malloc(size_t size) {
- void *ptr = malloc(size);
+ void *ptr = mi_malloc(size);
if (!ptr)
MVM_panic_allocation_failed(size);
@@ -8,7 +8,7 @@ MVM_STATIC_INLINE void * MVM_malloc(size_t size) {
}
MVM_STATIC_INLINE void * MVM_calloc(size_t num, size_t size) {
- void *ptr = calloc(num, size);
+ void *ptr = mi_calloc(num, size);
if (!ptr)
MVM_panic_allocation_failed(num * size);
@@ -17,7 +17,7 @@ MVM_STATIC_INLINE void * MVM_calloc(size_t num, size_t size) {
}
MVM_STATIC_INLINE void * MVM_realloc(void *p, size_t size) {
- void *ptr = realloc(p, size);
+ void *ptr = mi_realloc(p, size);
if (!ptr && size > 0)
MVM_panic_allocation_failed(size);
@@ -26,7 +26,7 @@ MVM_STATIC_INLINE void * MVM_realloc(void *p, size_t size) {
}
MVM_STATIC_INLINE void * MVM_recalloc(void *p, size_t old_size, size_t size) {
- void *ptr = realloc(p, size);
+ void *ptr = mi_realloc(p, size);
if (size > 0) {
if (!ptr)
@@ -40,7 +40,7 @@ MVM_STATIC_INLINE void * MVM_recalloc(void *p, size_t old_size, size_t size) {
}
MVM_STATIC_INLINE void MVM_free(void *p) {
- free(p);
+ mi_free(p);
}
#define MVM_free_null(addr) do { \
diff --git src/debug/debugserver.c src/debug/debugserver.c
index 7fd783cf3..156f6ffc0 100644
--- src/debug/debugserver.c
+++ src/debug/debugserver.c
@@ -3,10 +3,6 @@
#define DEBUGSERVER_MAJOR_PROTOCOL_VERSION 1
#define DEBUGSERVER_MINOR_PROTOCOL_VERSION 3
-#define bool int
-#define true TRUE
-#define false FALSE
-
#include "cmp.h"
#include "platform/socket.h"
@@ -2674,7 +2670,7 @@ static MVMint32 request_object_associatives(MVMThreadContext *dtc, cmp_ctx_t *ct
MVMuint8 debugspam_network;
-static bool socket_reader(cmp_ctx_t *ctx, void *data, size_t limit) {
+static _Bool socket_reader(cmp_ctx_t *ctx, void *data, size_t limit) {
size_t idx;
size_t total_read = 0;
ssize_t read;
@@ -2733,7 +2729,7 @@ static size_t socket_writer(cmp_ctx_t *ctx, const void *data, size_t limit) {
return 1;
}
-static bool is_valid_int(cmp_object_t *obj, MVMuint64 *result) {
+static _Bool is_valid_int(cmp_object_t *obj, MVMuint64 *result) {
switch (obj->type) {
case CMP_TYPE_POSITIVE_FIXNUM:
case CMP_TYPE_UINT8:
@@ -2770,7 +2766,7 @@ static bool is_valid_int(cmp_object_t *obj, MVMuint64 *result) {
return 1;
}
-static bool is_valid_num(cmp_object_t *obj, MVMnum64 *result) {
+static _Bool is_valid_num(cmp_object_t *obj, MVMnum64 *result) {
switch (obj->type) {
case CMP_TYPE_FLOAT:
*result = obj->as.flt;
diff --git src/moar.c src/moar.c
index de2575c10..13df05e57 100644
--- src/moar.c
+++ src/moar.c
@@ -54,13 +54,13 @@ static FILE *fopen_perhaps_with_pid(char *env_var, char *path, const char *mode)
if (found_percents > 1) {
result = MVM_platform_fopen(path, mode);
} else {
- char *fixed_path = malloc(path_length + 16);
+ char *fixed_path = MVM_malloc(path_length + 16);
MVMint64 pid = MVM_proc_getpid(NULL);
/* We make the brave assumption that
* pids only go up to 16 characters. */
snprintf(fixed_path, path_length + 16, path, pid);
result = MVM_platform_fopen(fixed_path, mode);
- free(fixed_path);
+ MVM_free(fixed_path);
}
} else {
result = MVM_platform_fopen(path, mode);
diff --git src/moar.h src/moar.h
index ce0ca3c67..b0dbad3a9 100644
--- src/moar.h
+++ src/moar.h
@@ -23,6 +23,9 @@
/* platform-specific setjmp override */
#include <platform/setjmp.h>
+/* mimalloc needs to come early so other libs use it */
+#include <mimalloc.h>
+
/* libuv
* must precede atomic_ops.h so we get the ordering of Winapi headers right
*/
diff --git tools/release.sh tools/release.sh
index 16c1a8226..980c7a83c 100755
--- tools/release.sh
+++ tools/release.sh
@@ -5,7 +5,7 @@ VERSION=$1
{
echo MANIFEST
git ls-files | perl -ne "print unless /^3rdparty\/\w+$/"
- for submod in 3rdparty/libatomicops/ 3rdparty/dyncall/ 3rdparty/libuv/ 3rdparty/dynasm/ 3rdparty/libtommath/ 3rdparty/cmp/ 3rdparty/ryu/; do
+ for submod in 3rdparty/libatomicops/ 3rdparty/dyncall/ 3rdparty/libuv/ 3rdparty/dynasm/ 3rdparty/libtommath/ 3rdparty/cmp/ 3rdparty/ryu/ 3rdparty/mimalloc; do
cd $submod
git ls-files | perl -pe "s{^}{$submod}"
cd ../..;
echo linking libmoar.so
gcc -o libmoar.so -O3 -DNDEBUG -g3 -Wl,-rpath,"//home/dan/Source/perl6/install/lib" -shared -fPIC src/core/callsite.o src/core/args.o src/core/exceptions.o src/core/interp.o src/core/str_hash_table.o src/core/fixkey_hash_table.o src/core/index_hash_table.o src/core/ptr_hash_table.o src/core/uni_hash_table.o src/core/threadcontext.o src/core/compunit.o src/core/bytecode.o src/core/frame.o src/core/callstack.o src/core/validation.o src/core/bytecodedump.o src/core/threads.o src/core/ops.o src/core/hll.o src/core/loadbytecode.o src/core/coerce.o src/core/dll.o src/core/ext.o src/core/nativecall.o src/core/nativecall_dyncall.o src/core/continuation.o src/core/intcache.o src/core/fixedsizealloc.o src/core/regionalloc.o src/debug/debugserver.o src/gen/config.o src/gc/orchestrate.o src/gc/allocation.o src/gc/worklist.o src/gc/roots.o src/gc/collect.o src/gc/gen2.o src/gc/wb.o src/gc/objectid.o src/gc/finalize.o src/gc/debug.o src/io/io.o src/io/eventloop.o src/io/syncfile.o src/io/syncsocket.o src/io/fileops.o src/io/dirops.o src/io/procops.o src/io/timers.o src/io/filewatchers.o src/io/signals.o src/io/asyncsocket.o src/io/asyncsocketudp.o src/6model/reprs.o src/6model/reprconv.o src/6model/containers.o src/6model/parametric.o src/6model/reprs/MVMString.o src/6model/reprs/VMArray.o src/6model/reprs/MVMHash.o src/6model/reprs/MVMCFunction.o src/6model/reprs/KnowHOWREPR.o src/6model/reprs/KnowHOWAttributeREPR.o src/6model/reprs/P6str.o src/6model/reprs/P6opaque.o src/6model/reprs/MVMCode.o src/6model/reprs/MVMOSHandle.o src/6model/reprs/MVMCompUnit.o src/6model/reprs/MVMStaticFrame.o src/6model/reprs/P6int.o src/6model/reprs/P6num.o src/6model/reprs/Uninstantiable.o src/6model/reprs/HashAttrStore.o src/6model/reprs/MVMThread.o src/6model/reprs/MVMIter.o src/6model/reprs/MVMContext.o src/6model/reprs/SCRef.o src/6model/reprs/P6bigint.o src/6model/reprs/NFA.o src/6model/reprs/MVMException.o src/6model/reprs/MVMDLLSym.o src/6model/reprs/MVMContinuation.o src/6model/reprs/NativeCall.o src/6model/reprs/CPointer.o src/6model/reprs/CStr.o src/6model/reprs/CArray.o src/6model/reprs/CStruct.o src/6model/reprs/CUnion.o src/6model/reprs/ReentrantMutex.o src/6model/reprs/ConditionVariable.o src/6model/reprs/Semaphore.o src/6model/reprs/ConcBlockingQueue.o src/6model/reprs/MVMAsyncTask.o src/6model/reprs/MVMNull.o src/6model/reprs/CPPStruct.o src/6model/reprs/NativeRef.o src/6model/reprs/MultiDimArray.o src/6model/reprs/Decoder.o src/6model/reprs/MVMSpeshLog.o src/6model/reprs/MVMStaticFrameSpesh.o src/6model/reprs/MVMCapture.o src/6model/reprs/MVMTracked.o src/6model/6model.o src/6model/bootstrap.o src/6model/sc.o src/6model/serialization.o src/disp/boot.o src/disp/registry.o src/disp/inline_cache.o src/disp/program.o src/disp/syscall.o src/disp/resume.o src/spesh/dump.o src/spesh/graph.o src/spesh/codegen.o src/spesh/manipulate.o src/spesh/args.o src/spesh/usages.o src/spesh/facts.o src/spesh/optimize.o src/spesh/dead_bb_elimination.o src/spesh/dead_ins_elimination.o src/spesh/deopt.o src/spesh/log.o src/spesh/threshold.o src/spesh/inline.o src/spesh/osr.o src/spesh/lookup.o src/spesh/iterator.o src/spesh/worker.o src/spesh/debug.o src/spesh/stats.o src/spesh/plan.o src/spesh/arg_guard.o src/spesh/frame_walker.o src/spesh/pea.o src/6model/reprs/MVMSpeshCandidate.o src/spesh/disp.o src/strings/decode_stream.o src/strings/ascii.o src/strings/parse_num.o src/strings/utf8.o src/strings/utf8_c8.o src/strings/nfg.o src/strings/ops.o src/strings/unicode.o src/strings/normalize.o src/strings/latin1.o src/strings/utf16.o src/strings/windows1252.o src/strings/shiftjis.o src/strings/gb2312.o src/strings/gb18030.o src/math/bigintops.o src/profiler/instrument.o src/profiler/log.o src/profiler/profile.o src/profiler/heapsnapshot.o src/profiler/telemeh.o src/profiler/configuration.o src/instrument/crossthreadwrite.o src/instrument/line_coverage.o src/platform/sys.o src/platform/random.o src/platform/memmem32.o 3rdparty/freebsd/memmem.o 3rdparty/ryu/ryu/d2s.o src/platform/malloc_trim.o src/moar.o src/platform/posix/mmap.o src/platform/posix/time.o src/platform/posix/io.o src/platform/posix/fork.o src/jit/graph.o src/jit/label.o src/jit/compile.o src/jit/dump.o src/jit/expr.o src/jit/tile.o src/jit/linear_scan.o src/jit/interface.o src/jit/x64/emit.o src/jit/x64/arch.o 3rdparty/cmp/libcmp.a 3rdparty/dyncall/dyncall/libdyncall_s.a 3rdparty/dyncall/dyncallback/libdyncallback_s.a 3rdparty/dyncall/dynload/libdynload_s.a 3rdparty/libatomicops/src/libatomic_ops.a 3rdparty/tinymt/libtinymt.a 3rdparty/sha1/libsha1.a 3rdparty/libtommath/libtommath.a 3rdparty/libuv/libuv.a 3rdparty/mimalloc/libmimalloc.a -lm -lpthread -lrt -ldl -lzstd
echo linking moar
gcc -o moar -O3 -DNDEBUG -g3 -Wl,-rpath,"//home/dan/Source/perl6/install/lib" src/main.o -L. -lmoar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment