From 54d58e1502ab6b53645da7e67f1fff879206d805 Mon Sep 17 00:00:00 2001 From: Hugh Sanderson Date: Tue, 30 Jul 2024 19:54:14 +0800 Subject: [PATCH 01/15] Allocate pthread structures using 'new' to avoid copying and respect alignment. For https://github.com/HaxeFoundation/hxcpp/issues/1136 --- include/hx/Thread.h | 40 ++++++++++++++++++++++++---------------- src/hx/Thread.cpp | 32 ++++++++++++++++++-------------- src/hx/gc/Immix.cpp | 2 +- 3 files changed, 43 insertions(+), 31 deletions(-) diff --git a/include/hx/Thread.h b/include/hx/Thread.h index b2c3bbfb4..069d51e87 100644 --- a/include/hx/Thread.h +++ b/include/hx/Thread.h @@ -91,22 +91,28 @@ struct HxMutex pthread_mutexattr_t mta; pthread_mutexattr_init(&mta); pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE); - mValid = pthread_mutex_init(&mMutex,&mta) ==0; + mMutex = new pthread_mutex_t(); + mValid = pthread_mutex_init(mMutex,&mta) ==0; } - ~HxMutex() { if (mValid) pthread_mutex_destroy(&mMutex); } - void Lock() { pthread_mutex_lock(&mMutex); } - void Unlock() { pthread_mutex_unlock(&mMutex); } - bool TryLock() { return !pthread_mutex_trylock(&mMutex); } + ~HxMutex() + { + if (mValid) + pthread_mutex_destroy(mMutex); + delete mMutex; + } + void Lock() { pthread_mutex_lock(mMutex); } + void Unlock() { pthread_mutex_unlock(mMutex); } + bool TryLock() { return !pthread_mutex_trylock(mMutex); } bool IsValid() { return mValid; } void Clean() { if (mValid) - pthread_mutex_destroy(&mMutex); + pthread_mutex_destroy(mMutex); mValid = 0; } bool mValid; - pthread_mutex_t mMutex; + pthread_mutex_t *mMutex; }; #define THREAD_FUNC_TYPE void * @@ -196,13 +202,14 @@ struct HxSemaphore { mSet = false; mValid = true; - pthread_cond_init(&mCondition,0); + mCondition = new pthread_cond_t(); + pthread_cond_init(mCondition,0); } ~HxSemaphore() { if (mValid) { - pthread_cond_destroy(&mCondition); + pthread_cond_destroy(mCondition); } } // For autolock @@ -213,13 +220,13 @@ struct HxSemaphore if (!mSet) { mSet = true; - pthread_cond_signal( &mCondition ); + pthread_cond_signal( mCondition ); } } void QSet() { mSet = true; - pthread_cond_signal( &mCondition ); + pthread_cond_signal( mCondition ); } void Reset() { @@ -231,14 +238,14 @@ struct HxSemaphore { AutoLock lock(mMutex); while( !mSet ) - pthread_cond_wait( &mCondition, &mMutex.mMutex ); + pthread_cond_wait( mCondition, mMutex.mMutex ); mSet = false; } // when we already hold the mMutex lock ... void QWait() { while( !mSet ) - pthread_cond_wait( &mCondition, &mMutex.mMutex ); + pthread_cond_wait( mCondition, mMutex.mMutex ); mSet = false; } // Returns true if the wait was success, false on timeout. @@ -262,7 +269,7 @@ struct HxSemaphore int result = 0; // Wait for set to be true... - while( !mSet && (result=pthread_cond_timedwait( &mCondition, &mMutex.mMutex, &spec )) != ETIMEDOUT) + while( !mSet && (result=pthread_cond_timedwait( mCondition, mMutex.mMutex, &spec )) != ETIMEDOUT) { if (result!=0) { @@ -290,13 +297,14 @@ struct HxSemaphore if (mValid) { mValid = false; - pthread_cond_destroy(&mCondition); + pthread_cond_destroy(mCondition); } + delete mCondition; } HxMutex mMutex; - pthread_cond_t mCondition; + pthread_cond_t *mCondition; bool mSet; bool mValid; }; diff --git a/src/hx/Thread.cpp b/src/hx/Thread.cpp index 0dedb89d9..733933b1f 100644 --- a/src/hx/Thread.cpp +++ b/src/hx/Thread.cpp @@ -628,8 +628,8 @@ class hxCondition : public hx::Object { CONDITION_VARIABLE cond; #endif #else - pthread_cond_t cond; - pthread_mutex_t mutex; + pthread_cond_t *cond; + pthread_mutex_t *mutex; #endif hx::InternalFinalizer *mFinalizer; hxCondition() { @@ -645,11 +645,13 @@ class hxCondition : public hx::Object { #else pthread_condattr_t cond_attr; pthread_condattr_init(&cond_attr); - pthread_cond_init(&cond, &cond_attr); + cond = new pthread_cond_t(); + pthread_cond_init(cond, &cond_attr); pthread_condattr_destroy(&cond_attr); pthread_mutexattr_t mutex_attr; pthread_mutexattr_init(&mutex_attr); - pthread_mutex_init(&mutex, &mutex_attr); + mutex = new pthread_mutex_t(); + pthread_mutex_init(mutex, &mutex_attr); pthread_mutexattr_destroy(&mutex_attr); #endif } @@ -667,8 +669,10 @@ class hxCondition : public hx::Object { DeleteCriticalSection(&cond->cs); #endif #else - pthread_cond_destroy(&cond->cond); - pthread_mutex_destroy(&cond->mutex); + pthread_cond_destroy(cond->cond); + delete cond->cond; + pthread_mutex_destroy(cond->mutex); + delete cond->mutex; #endif } } @@ -679,7 +683,7 @@ class hxCondition : public hx::Object { EnterCriticalSection(&cs); #endif #else - pthread_mutex_lock(&mutex); + pthread_mutex_lock(mutex); #endif } @@ -691,7 +695,7 @@ class hxCondition : public hx::Object { return false; #endif #else - return pthread_mutex_trylock(&mutex); + return pthread_mutex_trylock(mutex); #endif } @@ -701,17 +705,17 @@ class hxCondition : public hx::Object { LeaveCriticalSection(&cs); #endif #else - pthread_mutex_unlock(&mutex); + pthread_mutex_unlock(mutex); #endif } void Wait() { #ifdef HX_WINDOWS #ifndef HXCPP_WINXP_COMPAT - SleepConditionVariableCS(&cond,&cs,INFINITE); + SleepConditionVariableCS(cond,&cs,INFINITE); #endif #else - pthread_cond_wait(&cond, &mutex); + pthread_cond_wait(cond, mutex); #endif } @@ -735,7 +739,7 @@ class hxCondition : public hx::Object { delta -= idelta2 * 1e9; t.tv_sec = tv.tv_sec + idelta + idelta2; t.tv_nsec = (long)delta; - return pthread_cond_timedwait(&cond, &mutex, &t); + return pthread_cond_timedwait(cond, mutex, &t); #endif } void Signal() { @@ -744,7 +748,7 @@ class hxCondition : public hx::Object { WakeConditionVariable(&cond); #endif #else - pthread_cond_signal(&cond); + pthread_cond_signal(cond); #endif } void Broadcast() { @@ -753,7 +757,7 @@ class hxCondition : public hx::Object { WakeAllConditionVariable(&cond); #endif #else - pthread_cond_broadcast(&cond); + pthread_cond_broadcast(cond); #endif } }; diff --git a/src/hx/gc/Immix.cpp b/src/hx/gc/Immix.cpp index 4894f79e3..00d2f2ff5 100644 --- a/src/hx/gc/Immix.cpp +++ b/src/hx/gc/Immix.cpp @@ -580,7 +580,7 @@ static ThreadPoolLock sThreadPoolLock; typedef pthread_cond_t ThreadPoolSignal; inline void WaitThreadLocked(ThreadPoolSignal &ioSignal) { - pthread_cond_wait(&ioSignal, &sThreadPoolLock.mMutex); + pthread_cond_wait(&ioSignal, sThreadPoolLock.mMutex); } #else typedef HxSemaphore ThreadPoolSignal; From 00913ef4f2b1c685dcd81baf9ae139d3d4036168 Mon Sep 17 00:00:00 2001 From: Hugh Sanderson Date: Wed, 31 Jul 2024 09:37:20 +0800 Subject: [PATCH 02/15] Fix windows compile error --- src/hx/Thread.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hx/Thread.cpp b/src/hx/Thread.cpp index 733933b1f..e5af49df3 100644 --- a/src/hx/Thread.cpp +++ b/src/hx/Thread.cpp @@ -712,7 +712,7 @@ class hxCondition : public hx::Object { void Wait() { #ifdef HX_WINDOWS #ifndef HXCPP_WINXP_COMPAT - SleepConditionVariableCS(cond,&cs,INFINITE); + SleepConditionVariableCS(&cond,&cs,INFINITE); #endif #else pthread_cond_wait(cond, mutex); From 8dc8020f8465027de6c2aaaed90718bc693651ed Mon Sep 17 00:00:00 2001 From: Hugh Sanderson Date: Wed, 31 Jul 2024 10:07:28 +0800 Subject: [PATCH 03/15] Add some basic .asm support --- toolchain/msvc-toolchain.xml | 2 ++ tools/hxcpp/BuildTool.hx | 2 ++ tools/hxcpp/Compiler.hx | 15 ++++++++++++--- tools/hxcpp/File.hx | 2 ++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/toolchain/msvc-toolchain.xml b/toolchain/msvc-toolchain.xml index 26c7a826c..83749ba16 100644 --- a/toolchain/msvc-toolchain.xml +++ b/toolchain/msvc-toolchain.xml @@ -108,6 +108,8 @@ + + diff --git a/tools/hxcpp/BuildTool.hx b/tools/hxcpp/BuildTool.hx index a98a00361..cd562929e 100644 --- a/tools/hxcpp/BuildTool.hx +++ b/tools/hxcpp/BuildTool.hx @@ -900,6 +900,7 @@ class BuildTool case "objcflag" : c.mOBJCFlags.push(substitute(el.att.value)); case "rcflag" : c.mRcFlags.push( substitute((el.att.value)) ); case "mmflag" : c.mMMFlags.push(substitute(el.att.value)); + case "asmflag" : c.mAsmFlags.push(substitute(el.att.value)); case "pchflag" : c.mPCHFlags.push(substitute(el.att.value)); case "objdir" : c.mObjDir = substitute((el.att.value)); case "outflag" : c.mOutFlag = substitute((el.att.value)); @@ -907,6 +908,7 @@ class BuildTool case "rcexe" : c.mRcExe = substitute((el.att.name)); case "rcext" : c.mRcExt = substitute((el.att.value)); case "ext" : c.mExt = substitute((el.att.value)); + case "asmExe" : c.mAsmExe = substitute((el.att.value)); case "pch" : c.setPCH( substitute((el.att.value)) ); case "getversion" : c.mGetCompilerVersion = substitute((el.att.value)); case "section" : createCompiler(el,c); diff --git a/tools/hxcpp/Compiler.hx b/tools/hxcpp/Compiler.hx index bf3c2372f..2d0b5bb17 100644 --- a/tools/hxcpp/Compiler.hx +++ b/tools/hxcpp/Compiler.hx @@ -35,8 +35,10 @@ class Compiler public var mCPPFlags:Array; public var mOBJCFlags:Array; public var mPCHFlags:Array; + public var mAsmFlags:Array; public var mAddGCCIdentity:Bool; public var mExe:String; + public var mAsmExe:String; public var mOutFlag:String; public var mObjDir:String; public var mRelObjDir:String; @@ -72,12 +74,14 @@ class Compiler mOBJCFlags = []; mMMFlags = []; mPCHFlags = []; + mAsmFlags = []; mAddGCCIdentity = false; mCompilerVersion = null; mRcExt = ".res"; mObjDir = "obj"; mOutFlag = "-o"; mExe = inExe; + mAsmExe = inExe; mID = inID; mExt = ".o"; mPCHExt = ".pch"; @@ -172,12 +176,13 @@ class Compiler function getArgs(inFile:File) { var nvcc = inFile.isNvcc(); + var asm = inFile.isAsm(); var isRc = mRcExe!=null && inFile.isResource(); var args = nvcc ? inFile.mGroup.mCompilerFlags.concat( BuildTool.getNvccFlags() ) : inFile.mCompilerFlags.concat(inFile.mGroup.mCompilerFlags); var tagFilter = inFile.getTags().split(","); addOptimTags(tagFilter); - if (!isRc) + if (!isRc && !asm) for(flag in mFlags) flag.add(args,tagFilter); var ext = mExt.toLowerCase(); @@ -191,7 +196,10 @@ class Compiler addIdentity(ext,args); var allowPch = false; - if (nvcc) + + if (asm) + args = args.concat(mAsmFlags); + else if (nvcc) args = args.concat(mNvccFlags); else if (isRc) args = args.concat(mRcFlags); @@ -297,7 +305,8 @@ class Compiler var obj_name = getObjName(inFile); var args = getArgs(inFile); var nvcc = inFile.isNvcc(); - var exe = nvcc ? BuildTool.getNvcc() : mExe; + var asm = inFile.isAsm(); + var exe = asm ? mAsmExe : nvcc ? BuildTool.getNvcc() : mExe; var isRc = mRcExe!=null && inFile.isResource(); if (isRc) exe = mRcExe; diff --git a/tools/hxcpp/File.hx b/tools/hxcpp/File.hx index 7b04621a6..f31b9ee9c 100644 --- a/tools/hxcpp/File.hx +++ b/tools/hxcpp/File.hx @@ -44,6 +44,8 @@ class File public function isNvcc() return mGroup.mNvcc; + public function isAsm() return mName.endsWith(".asm"); + public function isResource() return mName.endsWith(".rc"); public function keep(inDefines:Map) From 1260d8995f712f6585964c54be3153dd07cfe574 Mon Sep 17 00:00:00 2001 From: Hugh Sanderson Date: Fri, 9 Aug 2024 16:21:56 +0800 Subject: [PATCH 04/15] Add some simple nasm support --- tools/hxcpp/BuildTool.hx | 1 + tools/hxcpp/Compiler.hx | 6 ++++-- tools/hxcpp/File.hx | 2 ++ tools/hxcpp/FileGroup.hx | 9 +++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tools/hxcpp/BuildTool.hx b/tools/hxcpp/BuildTool.hx index cd562929e..e5103747a 100644 --- a/tools/hxcpp/BuildTool.hx +++ b/tools/hxcpp/BuildTool.hx @@ -1037,6 +1037,7 @@ class BuildTool substitute(el.att.variable), substitute(el.att.target) ); case "options" : group.addOptions( substitute(el.att.name) ); case "config" : group.mConfig = substitute(el.att.name); + case "assembler" : group.mAssembler = substitute(el.att.name); case "compilerflag" : if (el.has.name) group.addCompilerFlag( substitute(el.att.name) ); diff --git a/tools/hxcpp/Compiler.hx b/tools/hxcpp/Compiler.hx index 2d0b5bb17..277fed341 100644 --- a/tools/hxcpp/Compiler.hx +++ b/tools/hxcpp/Compiler.hx @@ -1,6 +1,7 @@ import haxe.crypto.Md5; import haxe.io.Path; import sys.FileSystem; +using StringTools; private class FlagInfo { @@ -306,7 +307,8 @@ class Compiler var args = getArgs(inFile); var nvcc = inFile.isNvcc(); var asm = inFile.isAsm(); - var exe = asm ? mAsmExe : nvcc ? BuildTool.getNvcc() : mExe; + var exe = asm ? inFile.getAsmExe(mAsmExe) : nvcc ? BuildTool.getNvcc() : mExe; + var nasm = asm && (exe.endsWith("nasm") || exe.endsWith("nasm.exe")); var isRc = mRcExe!=null && inFile.isResource(); if (isRc) exe = mRcExe; @@ -368,7 +370,7 @@ class Compiler args.push( (new Path( inFile.mDir + inFile.mName)).toString() ); } - var out = nvcc ? "-o " : mOutFlag; + var out = (nvcc||nasm) ? "-o " : mOutFlag; if (out.substr(-1)==" ") { args.push(out.substr(0,out.length-1)); diff --git a/tools/hxcpp/File.hx b/tools/hxcpp/File.hx index f31b9ee9c..4b3ab33ff 100644 --- a/tools/hxcpp/File.hx +++ b/tools/hxcpp/File.hx @@ -46,6 +46,8 @@ class File public function isAsm() return mName.endsWith(".asm"); + public function getAsmExe(compilerAsm:String) return mGroup.getAsmExe(compilerAsm); + public function isResource() return mName.endsWith(".rc"); public function keep(inDefines:Map) diff --git a/tools/hxcpp/FileGroup.hx b/tools/hxcpp/FileGroup.hx index f7820c8be..b88490d20 100644 --- a/tools/hxcpp/FileGroup.hx +++ b/tools/hxcpp/FileGroup.hx @@ -25,6 +25,7 @@ class FileGroup public var mCacheProject:String; public var mTags:String; public var mNvcc:Bool; + public var mAssembler:String; public var mObjPrefix:String; public function new(inDir:String,inId:String,inSetImportDir = false) @@ -73,6 +74,14 @@ class FileGroup return Lambda.exists(mFiles, function(file:File) { return true; } ); } + public function getAsmExe(compilerAsm:String) + { + if (mAssembler==null || mAssembler=="") + return compilerAsm; + return mAssembler; + } + + public function filter(defines:Map) { var newFiles = new Map(); From 904ea40643b050a5a154c5e4c33a83fd2aec18b1 Mon Sep 17 00:00:00 2001 From: Mihai Alexandru <77043862+MAJigsaw77@users.noreply.github.com> Date: Sun, 18 Aug 2024 07:28:24 +0000 Subject: [PATCH 05/15] Fix Callstack Retrieval in Critical Error Handler. (#1143) * Update Debug.cpp * Update Debug.cpp --- src/hx/Debug.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hx/Debug.cpp b/src/hx/Debug.cpp index 462cdaae1..9cd52c3f0 100644 --- a/src/hx/Debug.cpp +++ b/src/hx/Debug.cpp @@ -77,12 +77,15 @@ static void CriticalErrorHandler(String inErr, bool allowFixup) return; #endif +#ifdef HXCPP_STACK_TRACE + hx::StackContext *ctx = hx::StackContext::getCurrent(); + ctx->beginCatch(true); +#endif + if (sCriticalErrorHandler!=null()) sCriticalErrorHandler(inErr); #ifdef HXCPP_STACK_TRACE - hx::StackContext *ctx = hx::StackContext::getCurrent(); - ctx->beginCatch(true); ctx->dumpExceptionStack(); #endif From 306a97812f969f724414391c75871596d58b9964 Mon Sep 17 00:00:00 2001 From: Hugh Sanderson Date: Tue, 27 Aug 2024 11:09:16 +0800 Subject: [PATCH 06/15] Update the 'out of date' counter. For #1142 --- toolchain/haxe-target.xml | 4 ++-- tools/hxcpp/BuildTool.hx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/toolchain/haxe-target.xml b/toolchain/haxe-target.xml index fd2134137..076dce221 100644 --- a/toolchain/haxe-target.xml +++ b/toolchain/haxe-target.xml @@ -1,7 +1,7 @@ - + @@ -12,7 +12,7 @@ - + diff --git a/tools/hxcpp/BuildTool.hx b/tools/hxcpp/BuildTool.hx index e5103747a..cd809ff00 100644 --- a/tools/hxcpp/BuildTool.hx +++ b/tools/hxcpp/BuildTool.hx @@ -2334,8 +2334,8 @@ class BuildTool public function checkToolVersion(inVersion:String) { var ver = Std.parseInt(inVersion); - if (ver>3) - Log.error("Your version of hxcpp.n is out-of-date. Please update."); + if (ver>4) + Log.error("Your version of hxcpp.n is out-of-date. Please update by compiling 'haxe compile.hxml' in hxcpp/tools/hxcpp."); } public function resolvePath(inPath:String) From 615cf5d34a3f79115f09a91d8afaa66167cf0455 Mon Sep 17 00:00:00 2001 From: Hugh Sanderson Date: Wed, 28 Aug 2024 16:52:42 +0800 Subject: [PATCH 07/15] Add BINARYEN_EXTRA_PASSES='--spill-pointers' for emscipten to improve GC on wasm target. --- toolchain/emscripten-toolchain.xml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/toolchain/emscripten-toolchain.xml b/toolchain/emscripten-toolchain.xml index cfe102144..f99d3a545 100644 --- a/toolchain/emscripten-toolchain.xml +++ b/toolchain/emscripten-toolchain.xml @@ -28,10 +28,11 @@ But you may be able to adjust the node stack size ti fix this. --> - + + @@ -99,6 +100,11 @@ +
+ + +
+ @@ -141,27 +147,23 @@
- -
- -
- - + +
- +
- + From 01ef3fa595cceb6a4e045eff38191f6d6cf1cece Mon Sep 17 00:00:00 2001 From: Hugh Sanderson Date: Wed, 28 Aug 2024 17:52:46 +0800 Subject: [PATCH 08/15] Support name and value entries in flag specifications. --- toolchain/haxe-target.xml | 2 +- tools/hxcpp/BuildTool.hx | 31 ++++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/toolchain/haxe-target.xml b/toolchain/haxe-target.xml index 076dce221..cfff7ceeb 100644 --- a/toolchain/haxe-target.xml +++ b/toolchain/haxe-target.xml @@ -1,7 +1,7 @@ - + diff --git a/tools/hxcpp/BuildTool.hx b/tools/hxcpp/BuildTool.hx index cd809ff00..92be6063c 100644 --- a/tools/hxcpp/BuildTool.hx +++ b/tools/hxcpp/BuildTool.hx @@ -894,7 +894,11 @@ class BuildTool if (valid(el,"")) switch(el.name) { - case "flag" : c.addFlag(substitute(el.att.value), el.has.tag?substitute(el.att.tag):""); + case "flag" : + var tag = el.has.tag?substitute(el.att.tag):""; + if (el.has.name) + c.addFlag(substitute(el.att.name), tag); + c.addFlag(substitute(el.att.value), tag); case "cflag" : c.mCFlags.push(substitute(el.att.value)); case "cppflag" : c.mCPPFlags.push(substitute(el.att.value)); case "objcflag" : c.mOBJCFlags.push(substitute(el.att.value)); @@ -1090,7 +1094,10 @@ class BuildTool if (valid(el,"")) switch(el.name) { - case "flag" : l.mFlags.push(substitute(el.att.value)); + case "flag" : + if (el.has.name) + l.mFlags.push(substitute(el.att.name)); + l.mFlags.push(substitute(el.att.value)); case "ext" : l.mExt = (substitute(el.att.value)); case "outflag" : l.mOutFlag = (substitute(el.att.value)); case "libdir" : l.mLibDir = (substitute(el.att.name)); @@ -1150,9 +1157,10 @@ class BuildTool if (valid(el,"")) switch(el.name) { - case "flag" : s.mFlags.push(substitute(el.att.value)); - case "outPre" : s.mOutPre = substitute(el.att.value); - case "outPost" : s.mOutPost = substitute(el.att.value); + case "flag" : + if (el.has.name) + s.mFlags.push(substitute(el.att.name)); + s.mFlags.push(substitute(el.att.value)); case "exe" : s.mExe = substitute((el.att.name)); } } @@ -1160,7 +1168,6 @@ class BuildTool return s; } - public function createStripper(inXML:XmlAccess,inBase:Stripper):Stripper { var s = (inBase!=null && !inXML.has.replace) ? inBase : @@ -1170,7 +1177,10 @@ class BuildTool if (valid(el,"")) switch(el.name) { - case "flag" : s.mFlags.push(substitute(el.att.value)); + case "flag" : + if (el.has.name) + s.mFlags.push(substitute(el.att.name)); + s.mFlags.push(substitute(el.att.value)); case "exe" : s.mExe = substitute((el.att.name)); } } @@ -1238,7 +1248,10 @@ class BuildTool target.mLibs.push(lib); } - case "flag" : target.mFlags.push( substitute(el.att.value) ); + case "flag" : + if (el.has.name) + target.mFlags.push( substitute(el.att.name) ); + target.mFlags.push( substitute(el.att.value) ); case "depend" : target.mDepends.push( substitute(el.att.name) ); case "vflag" : target.mFlags.push( substitute(el.att.name) ); @@ -2334,7 +2347,7 @@ class BuildTool public function checkToolVersion(inVersion:String) { var ver = Std.parseInt(inVersion); - if (ver>4) + if (ver>5) Log.error("Your version of hxcpp.n is out-of-date. Please update by compiling 'haxe compile.hxml' in hxcpp/tools/hxcpp."); } From 9c8cc142913f4bd33681cadc9f2fce3863c59694 Mon Sep 17 00:00:00 2001 From: Mihai Alexandru <77043862+MAJigsaw77@users.noreply.github.com> Date: Wed, 28 Aug 2024 09:56:26 +0000 Subject: [PATCH 09/15] Fix deprecated non-prototype warnings in Zlib for non-MSVC compilers. (#1144) * Update Build.xml * Update Build.xml * Oops, forgot about this one --- src/hx/libs/zlib/Build.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/hx/libs/zlib/Build.xml b/src/hx/libs/zlib/Build.xml index de938de3e..de1c69cc5 100644 --- a/src/hx/libs/zlib/Build.xml +++ b/src/hx/libs/zlib/Build.xml @@ -13,6 +13,10 @@ + + + + From 17ac6e8a023a8c7a6af0dd8d41f86879e550b5b1 Mon Sep 17 00:00:00 2001 From: Hugh Sanderson Date: Thu, 29 Aug 2024 13:59:45 +0800 Subject: [PATCH 10/15] Update emscripten config to match standard installations. Add some emscipten specific GC paths. --- src/hx/gc/Immix.cpp | 147 ++++++++++++++++++++--------- toolchain/emscripten-toolchain.xml | 85 +++++++++++++---- toolchain/haxe-target.xml | 2 +- tools/hxcpp/BuildTool.hx | 6 +- tools/hxcpp/Setup.hx | 28 +++++- 5 files changed, 199 insertions(+), 69 deletions(-) diff --git a/src/hx/gc/Immix.cpp b/src/hx/gc/Immix.cpp index 00d2f2ff5..458e33a4f 100644 --- a/src/hx/gc/Immix.cpp +++ b/src/hx/gc/Immix.cpp @@ -7,6 +7,14 @@ #include "GcRegCapture.h" #include +#ifdef EMSCRIPTEN + #include + #ifdef HXCPP_SINGLE_THREADED_APP + // Use provided tools to measure stack extent + #define HXCPP_EXPLICIT_STACK_EXTENT + #endif +#endif + #include #include @@ -28,7 +36,6 @@ int gSlowPath = 0; using hx::gByteMarkID; using hx::gRememberedByteMarkID; -// #define HXCPP_SINGLE_THREADED_APP namespace hx { @@ -108,10 +115,6 @@ static size_t sgMaximumFreeSpace = 1024*1024*1024; static size_t sgMaximumFreeSpace = 1024*1024*1024; #endif -#ifdef EMSCRIPTEN -// #define HXCPP_STACK_UP -#endif - // #define HXCPP_GC_DEBUG_LEVEL 1 @@ -5762,8 +5765,10 @@ class LocalAllocator : public hx::StackContext bool mMoreHoles; + #ifndef HXCPP_EXPLICIT_STACK_EXTENT int *mTopOfStack; int *mBottomOfStack; + #endif hx::RegisterCaptureBuffer mRegisterBuf; int mRegisterBufSize; @@ -5801,7 +5806,9 @@ class LocalAllocator : public hx::StackContext void AttachThread(int *inTopOfStack) { + #ifndef HXCPP_EXPLICIT_STACK_EXTENT mTopOfStack = mBottomOfStack = inTopOfStack; + #endif mRegisterBufSize = 0; mStackLocks = 0; @@ -5859,7 +5866,9 @@ class LocalAllocator : public hx::StackContext } #endif + #ifndef HXCPP_EXPLICIT_STACK_EXTENT mTopOfStack = mBottomOfStack = 0; + #endif sGlobalAlloc->RemoveLocalLocked(this); @@ -5891,7 +5900,7 @@ class LocalAllocator : public hx::StackContext // Other places may call this to ensure the the current thread is registered // indefinitely (until forcefully revoked) // - // Normally liraries/mains will then let this dangle. + // Normally libraries/mains will then let this dangle. // // However after the main, on android it calls SetTopOfStack(0,true), to unregister the thread, // because it is likely to be the ui thread, and the remaining call will be from @@ -5916,13 +5925,28 @@ class LocalAllocator : public hx::StackContext // SetTopOfStack(top,true) -> add stack lock // SetTopOfStack(0,_) -> pop stack lock. If all gone, clear global stack lock // + + #ifdef HXCPP_EXPLICIT_STACK_EXTENT // { + + void SetTopOfStack(int *inTop,bool inPush) { } + void PushTopOfStack(void *inTop) { } + void PopTopOfStack() { } + void SetBottomOfStack(int *inBottom) { } + void PauseForCollect() { } + void EnterGCFreeZone() { } + bool TryGCFreeZone() { return true; } + bool TryExitGCFreeZone() { return false; } + void ExitGCFreeZoneLocked() { } + + + #else // } !HXCPP_EXPLICIT_STACK_EXTENT { void SetTopOfStack(int *inTop,bool inPush) { if (inTop) { if (!mTopOfStack) mTopOfStack = inTop; - // EMSCRIPTEN the stack grows upwards + // EMSCRIPTEN the stack grows upwards - not wasm. // It could be that the main routine was called from deep with in the stack, // then some callback was called from a higher location on the stack #ifdef HXCPP_STACK_UP @@ -5987,39 +6011,6 @@ class LocalAllocator : public hx::StackContext #endif } - virtual void SetupStackAndCollect(bool inMajor, bool inForceCompact, bool inLocked=false,bool inFreeIsFragged=false) - { - #ifndef HXCPP_SINGLE_THREADED_APP - #if HXCPP_DEBUG - if (mGCFreeZone) - CriticalGCError("Collecting from a GC-free thread"); - #endif - #endif - - volatile int dummy = 1; - mBottomOfStack = (int *)&dummy; - - CAPTURE_REGS; - - if (!mTopOfStack) - mTopOfStack = mBottomOfStack; - // EMSCRIPTEN the stack grows upwards - #ifdef HXCPP_STACK_UP - if (mBottomOfStack < mTopOfStack) - mTopOfStack = mBottomOfStack; - #else - if (mBottomOfStack > mTopOfStack) - mTopOfStack = mBottomOfStack; - #endif - - #ifdef VerifyStackRead - VerifyStackRead(mBottomOfStack, mTopOfStack) - #endif - - - sGlobalAlloc->Collect(inMajor, inForceCompact, inLocked, inFreeIsFragged); - } - void PauseForCollect() { @@ -6145,6 +6136,58 @@ class LocalAllocator : public hx::StackContext #endif } + #endif // } HXCPP_EXPLICIT_STACK_EXTENT + + + void SetupStackAndCollect(bool inMajor, bool inForceCompact, bool inLocked=false,bool inFreeIsFragged=false) + { + #ifndef HXCPP_SINGLE_THREADED_APP + #if HXCPP_DEBUG + if (mGCFreeZone) + CriticalGCError("Collecting from a GC-free thread"); + #endif + #endif + + #ifndef HXCPP_EXPLICIT_STACK_EXTENT + volatile int dummy = 1; + mBottomOfStack = (int *)&dummy; + + CAPTURE_REGS; + + if (!mTopOfStack) + mTopOfStack = mBottomOfStack; + + // EMSCRIPTEN the stack grows upwards + #ifdef HXCPP_STACK_UP + if (mBottomOfStack < mTopOfStack) + mTopOfStack = mBottomOfStack; + #else + if (mBottomOfStack > mTopOfStack) + mTopOfStack = mBottomOfStack; + #endif + + #ifdef VerifyStackRead + VerifyStackRead(mBottomOfStack, mTopOfStack) + #endif + + #endif + + + sGlobalAlloc->Collect(inMajor, inForceCompact, inLocked, inFreeIsFragged); + } + + + + + + + + + + + + + void ExpandAlloc(int &ioSize) { #ifdef HXCPP_GC_NURSERY @@ -6331,11 +6374,13 @@ class LocalAllocator : public hx::StackContext void Mark(hx::MarkContext *__inCtx) { + #ifndef HXCPP_SINGLE_THREADED_APP if (!mTopOfStack) { Reset(); return; } + #endif #ifdef SHOW_MEM_EVENTS //int here = 0; @@ -6345,19 +6390,33 @@ class LocalAllocator : public hx::StackContext #ifdef HXCPP_DEBUG MarkPushClass("Stack",__inCtx); MarkSetMember("Stack",__inCtx); + + #ifdef HXCPP_EXPLICIT_STACK_EXTENT + hx::MarkConservative( (int *)emscripten_stack_get_current(),(int *)emscripten_stack_get_base(), __inCtx); + #else if (mTopOfStack && mBottomOfStack) hx::MarkConservative(mBottomOfStack, mTopOfStack , __inCtx); + #endif + #ifdef HXCPP_SCRIPTABLE MarkSetMember("ScriptStack",__inCtx); hx::MarkConservative((int *)(stack), (int *)(pointer),__inCtx); #endif MarkSetMember("Registers",__inCtx); hx::MarkConservative(CAPTURE_REG_START, CAPTURE_REG_END, __inCtx); + + MarkPopClass(__inCtx); #else - if (mTopOfStack && mBottomOfStack) - hx::MarkConservative(mBottomOfStack, mTopOfStack , __inCtx); - hx::MarkConservative(CAPTURE_REG_START, CAPTURE_REG_END, __inCtx); + + #ifdef HXCPP_EXPLICIT_STACK_EXTENT + hx::MarkConservative( (int *)emscripten_stack_get_current(), (int *) emscripten_stack_get_base(), __inCtx); + #else + if (mTopOfStack && mBottomOfStack) + hx::MarkConservative(mBottomOfStack, mTopOfStack , __inCtx); + hx::MarkConservative(CAPTURE_REG_START, CAPTURE_REG_END, __inCtx); + #endif + #ifdef HXCPP_SCRIPTABLE hx::MarkConservative((int *)(stack), (int *)(pointer),__inCtx); #endif @@ -6390,6 +6449,7 @@ inline LocalAllocator *GetLocalAlloc(bool inAllowEmpty=false) #endif } +#ifndef HXCPP_SINGLE_THREADED_APP void WaitForSafe(LocalAllocator *inAlloc) { inAlloc->WaitForSafe(); @@ -6399,6 +6459,7 @@ void ReleaseFromSafe(LocalAllocator *inAlloc) { inAlloc->ReleaseFromSafe(); } +#endif void MarkLocalAlloc(LocalAllocator *inAlloc,hx::MarkContext *__inCtx) { diff --git a/toolchain/emscripten-toolchain.xml b/toolchain/emscripten-toolchain.xml index f99d3a545..ab5316a57 100644 --- a/toolchain/emscripten-toolchain.xml +++ b/toolchain/emscripten-toolchain.xml @@ -1,17 +1,60 @@ + + - - + + + + + + + + +
- - - + + + +
@@ -41,6 +84,10 @@ +
+ + +
@@ -100,9 +147,12 @@ -
- - + + + +
+ +
@@ -119,18 +169,13 @@ -
- - -
-
-
+
@@ -140,10 +185,13 @@
+ +
@@ -153,9 +201,12 @@
-
- - + + + +
+ +
diff --git a/toolchain/haxe-target.xml b/toolchain/haxe-target.xml index cfff7ceeb..a795596ab 100644 --- a/toolchain/haxe-target.xml +++ b/toolchain/haxe-target.xml @@ -1,7 +1,7 @@ - + diff --git a/tools/hxcpp/BuildTool.hx b/tools/hxcpp/BuildTool.hx index 92be6063c..22f85d898 100644 --- a/tools/hxcpp/BuildTool.hx +++ b/tools/hxcpp/BuildTool.hx @@ -1612,8 +1612,8 @@ class BuildTool { Setup.initHXCPPConfig(defines); Setup.setupEmscripten(defines); - var node = defines.get("EMSCRIPTEN_NODE_JS"); - Log.v( node==null ? "EMSCRIPTEN_NODE_JS undefined, using 'node'" : 'Using $node from EMSCRIPTEN_NODE_JS'); + var node = defines.get("EMSDK_NODE"); + Log.v( node==null ? "EMSDK_NODE undefined, using 'node'" : 'Using $node from EMSDK_NODE'); if (node=="" || node==null) node = "node"; @@ -2347,7 +2347,7 @@ class BuildTool public function checkToolVersion(inVersion:String) { var ver = Std.parseInt(inVersion); - if (ver>5) + if (ver>6) Log.error("Your version of hxcpp.n is out-of-date. Please update by compiling 'haxe compile.hxml' in hxcpp/tools/hxcpp."); } diff --git a/tools/hxcpp/Setup.hx b/tools/hxcpp/Setup.hx index 546fc7efa..1b6eb36ff 100644 --- a/tools/hxcpp/Setup.hx +++ b/tools/hxcpp/Setup.hx @@ -267,11 +267,12 @@ class Setup public static function setupEmscripten(ioDefines:Hash) { - // Setup EMSCRIPTEN_SDK if possible - else assume developer has it in path - if (!ioDefines.exists("EMSCRIPTEN_SDK")) + // Setup EMSDK if possible - else assume developer has it in path + if (!ioDefines.exists("EMSDK") ) { var home = ioDefines.get("HXCPP_HOME"); var file = home + "/.emscripten"; + Log.v('No EMSDK provided, checking $file'); if (FileSystem.exists(file)) { var content = sys.io.File.getContent(file); @@ -285,16 +286,33 @@ class Setup var val= value.matched(2); if (name=="EMSCRIPTEN_ROOT") { - ioDefines.set("EMSCRIPTEN_SDK", val); + ioDefines.set("EMSDK", val); } if (name=="PYTHON") - ioDefines.set("EMSCRIPTEN_PYTHON", val); + ioDefines.set("EMSDK_PYTHON", val); if (name=="NODE_JS") - ioDefines.set("EMSCRIPTEN_NODE_JS", val); + ioDefines.set("EMSDK_NODE", val); } } } } + else + { + Log.v('Using provided EMSDK ${ioDefines.get("EMSDK")}'); + } + + if (!ioDefines.exists("EMSDK_PYTHON")) + { + Log.v("No EMSDK_PYTHON provided, using 'python'"); + } + else + Log.v('Using provided EMSDK_PYTHON ${ioDefines.get("EMSDK_PYTHON")}'); + + if (!ioDefines.exists("EMSDK_NODE")) + { + Log.v("No EMSDK_NODE provided, using 'node'"); + ioDefines.set("EMSDK_NODE", "node"); + } } From 08f88ff314eeaa165dd76272f92c8030cc879ec2 Mon Sep 17 00:00:00 2001 From: Mihai Alexandru <77043862+MAJigsaw77@users.noreply.github.com> Date: Fri, 30 Aug 2024 07:06:33 +0000 Subject: [PATCH 11/15] Resolved multiple warnings on `Apple` targets. (#1145) * Update CFFI.cpp * Update Dynamic.cpp * Update mac-toolchain.xml * Update mac-toolchain.xml * Update my_api.cpp * Update Immix.cpp * Removed whitespaces and adjusted ios and tvos toolchains. --- src/Dynamic.cpp | 2 +- src/hx/CFFI.cpp | 2 +- src/hx/gc/Immix.cpp | 6 +++--- src/hx/libs/mysql/my_api.cpp | 6 +++--- toolchain/appletvos-toolchain.xml | 12 ++++++++---- toolchain/appletvsim-toolchain.xml | 12 ++++++++---- toolchain/iphoneos-toolchain.xml | 6 ++++-- toolchain/iphonesim-toolchain.xml | 6 ++++-- toolchain/mac-toolchain.xml | 18 +++++++++++++----- 9 files changed, 45 insertions(+), 25 deletions(-) diff --git a/src/Dynamic.cpp b/src/Dynamic.cpp index 7a51401b5..9d52c070e 100644 --- a/src/Dynamic.cpp +++ b/src/Dynamic.cpp @@ -217,7 +217,7 @@ class PointerData : public hx::Object String toString() { char buf[100]; - sprintf(buf,"Pointer(%p)", mValue); + snprintf(buf,sizeof(buf),"Pointer(%p)", mValue); return String(buf); } String __ToString() const { return String(mValue); } diff --git a/src/hx/CFFI.cpp b/src/hx/CFFI.cpp index 81575a67c..592c8e230 100644 --- a/src/hx/CFFI.cpp +++ b/src/hx/CFFI.cpp @@ -106,7 +106,7 @@ class Abstract_obj : public Object return _hxcpp_toString( Dynamic(this) ); char buffer[40]; - sprintf(buffer,"0x%p", mHandle); + snprintf(buffer,sizeof(buffer),"0x%p", mHandle); return HX_CSTRING("Abstract(") + __hxcpp_get_kind(this) + diff --git a/src/hx/gc/Immix.cpp b/src/hx/gc/Immix.cpp index 458e33a4f..253199c53 100644 --- a/src/hx/gc/Immix.cpp +++ b/src/hx/gc/Immix.cpp @@ -4632,11 +4632,11 @@ class GlobalAllocator char strBuf[100]; if (byteslast_error,err,param); + snprintf(m->last_error,sizeof(m->last_error),err,param); free(p2); return; } } - sprintf(m->last_error,err,param); + snprintf(m->last_error,sizeof(m->last_error),err,param); m->errcode = -1; } @@ -408,7 +408,7 @@ const char *mysql_character_set_name( MYSQL *m ) { const char *name = myp_charset_name(m->infos.server_charset); if( name == NULL ) { static char tmp[512]; - sprintf(tmp,"#%d",m->infos.server_charset); + snprintf(tmp,sizeof(tmp),"#%d",m->infos.server_charset); return tmp; } return name; diff --git a/toolchain/appletvos-toolchain.xml b/toolchain/appletvos-toolchain.xml index 7bc504e1b..9b70a3eeb 100644 --- a/toolchain/appletvos-toolchain.xml +++ b/toolchain/appletvos-toolchain.xml @@ -24,8 +24,10 @@ - - + + + + @@ -69,8 +71,10 @@ - - + + + + diff --git a/toolchain/appletvsim-toolchain.xml b/toolchain/appletvsim-toolchain.xml index a571f07f4..1e80b5abd 100644 --- a/toolchain/appletvsim-toolchain.xml +++ b/toolchain/appletvsim-toolchain.xml @@ -22,8 +22,10 @@ - - + + + + @@ -76,8 +78,10 @@ - - + + + + diff --git a/toolchain/iphoneos-toolchain.xml b/toolchain/iphoneos-toolchain.xml index c3fd3307e..305aa6a49 100644 --- a/toolchain/iphoneos-toolchain.xml +++ b/toolchain/iphoneos-toolchain.xml @@ -95,8 +95,10 @@ - - + + + + diff --git a/toolchain/iphonesim-toolchain.xml b/toolchain/iphonesim-toolchain.xml index c509b4edd..b98a703ad 100644 --- a/toolchain/iphonesim-toolchain.xml +++ b/toolchain/iphonesim-toolchain.xml @@ -89,8 +89,10 @@ - - + + + + diff --git a/toolchain/mac-toolchain.xml b/toolchain/mac-toolchain.xml index c8e0f760d..f7928cdb0 100644 --- a/toolchain/mac-toolchain.xml +++ b/toolchain/mac-toolchain.xml @@ -31,8 +31,11 @@ - - + + + + + @@ -74,8 +77,10 @@ - - + + + + @@ -99,7 +104,10 @@ - + + + + From 61f3911525d7717cf6a5f4f3c46fe02a68734000 Mon Sep 17 00:00:00 2001 From: Hugh Sanderson Date: Mon, 16 Sep 2024 16:53:10 +0800 Subject: [PATCH 12/15] Disable JIT for emscripten. Add a better message for when isDirectory fails. --- toolchain/finish-setup.xml | 1 + tools/hxcpp/BuildTool.hx | 2 ++ 2 files changed, 3 insertions(+) diff --git a/toolchain/finish-setup.xml b/toolchain/finish-setup.xml index 0b6aefc9e..eef2be1ec 100644 --- a/toolchain/finish-setup.xml +++ b/toolchain/finish-setup.xml @@ -10,6 +10,7 @@ + diff --git a/tools/hxcpp/BuildTool.hx b/tools/hxcpp/BuildTool.hx index 22f85d898..8e20a1469 100644 --- a/tools/hxcpp/BuildTool.hx +++ b/tools/hxcpp/BuildTool.hx @@ -2418,6 +2418,8 @@ class BuildTool path = path.split("\\").join("/"); var filename = ""; var parts = path.split("/"); + if (!FileSystem.exists(path)) + Log.error("File does not exist:" + path); if (!FileSystem.isDirectory(path)) filename = parts.pop(); From 8e19a0926f3fcc7e1d5bd1fec6e96de32274619f Mon Sep 17 00:00:00 2001 From: Hugh Sanderson Date: Tue, 17 Sep 2024 16:01:43 +0800 Subject: [PATCH 13/15] Fix HXCPP_GC_GENERATIONAL in combination with HXCPP_ALIGN_ALLOC --- include/hx/GC.h | 81 ++++++++++--------- include/hxcpp.h | 2 +- src/hx/gc/Immix.cpp | 148 +++++++++++++++++++++-------------- test/haxe/compile.hxml | 2 +- toolchain/common-defines.xml | 2 + 5 files changed, 140 insertions(+), 95 deletions(-) diff --git a/include/hx/GC.h b/include/hx/GC.h index 5370c142e..a9148c505 100644 --- a/include/hx/GC.h +++ b/include/hx/GC.h @@ -363,7 +363,12 @@ class ImmixAllocator { #ifdef HXCPP_GC_NURSERY + #ifdef HXCPP_ALIGN_ALLOC + // make sure buffer is 8-byte aligned + unsigned char *buffer = alloc->spaceFirst + ( (size_t)alloc->spaceFirst & 4 ); + #else unsigned char *buffer = alloc->spaceFirst; + #endif unsigned char *end = buffer + (inSize + 4); if ( end > alloc->spaceOversize ) @@ -381,6 +386,10 @@ class ImmixAllocator ((unsigned int *)buffer)[-1] = inSize; } + #if defined(HXCPP_GC_CHECK_POINTER) && defined(HXCPP_GC_DEBUG_ALWAYS_MOVE) + hx::GCOnNewPointer(buffer); + #endif + #ifdef HXCPP_TELEMETRY __hxt_gc_new((hx::StackContext *)alloc,buffer, inSize, inName); #endif @@ -388,41 +397,43 @@ class ImmixAllocator return buffer; #else - #ifndef HXCPP_ALIGN_ALLOC - // Inline the fast-path if we can - // We know the object can hold a pointer (vtable) and that the size is int-aligned - int start = alloc->spaceStart; - int end = start + sizeof(int) + inSize; - - if ( end <= alloc->spaceEnd ) - { - alloc->spaceStart = end; - - unsigned int *buffer = (unsigned int *)(alloc->allocBase + start); - - int startRow = start>>IMMIX_LINE_BITS; - - alloc->allocStartFlags[ startRow ] |= gImmixStartFlag[start&127]; - - if (inContainer) - *buffer++ = (( (end+(IMMIX_LINE_LEN-1))>>IMMIX_LINE_BITS) -startRow) | - (inSize<>IMMIX_LINE_BITS) -startRow) | - (inSize<spaceStart; + #ifdef HXCPP_ALIGN_ALLOC + // Ensure odd alignment in 8 bytes + start += 4 - (start & 4); + #endif + int end = start + sizeof(int) + inSize; + + if ( end <= alloc->spaceEnd ) + { + alloc->spaceStart = end; + + unsigned int *buffer = (unsigned int *)(alloc->allocBase + start); + + int startRow = start>>IMMIX_LINE_BITS; + + alloc->allocStartFlags[ startRow ] |= gImmixStartFlag[start&127]; + + if (inContainer) + *buffer++ = (( (end+(IMMIX_LINE_LEN-1))>>IMMIX_LINE_BITS) -startRow) | + (inSize<>IMMIX_LINE_BITS) -startRow) | + (inSize<CallAlloc(inSize, inContainer ? IMMIX_ALLOC_IS_CONTAINER : 0); diff --git a/include/hxcpp.h b/include/hxcpp.h index b2568d142..faa1b4db2 100755 --- a/include/hxcpp.h +++ b/include/hxcpp.h @@ -70,7 +70,7 @@ // Must allign allocs to 8 bytes to match floating point requirement? // Ints must br read on 4-byte boundary -#if defined(EMSCRIPTEN) || defined(GCW0) +#if (!defined(HXCPP_ALIGN_FLOAT) && (defined(EMSCRIPTEN) || defined(GCW0)) ) #define HXCPP_ALIGN_ALLOC #endif diff --git a/src/hx/gc/Immix.cpp b/src/hx/gc/Immix.cpp index 253199c53..05d0ac842 100644 --- a/src/hx/gc/Immix.cpp +++ b/src/hx/gc/Immix.cpp @@ -140,7 +140,7 @@ static size_t sgMaximumFreeSpace = 1024*1024*1024; //#define HXCPP_GC_SUMMARY //#define PROFILE_COLLECT //#define PROFILE_THREAD_USAGE -//#define HX_GC_VERIFY +//#define HXCPP_GC_VERIFY //#define HX_GC_VERIFY_ALLOC_START //#define SHOW_MEM_EVENTS //#define SHOW_MEM_EVENTS_VERBOSE @@ -158,7 +158,7 @@ static size_t sgMaximumFreeSpace = 1024*1024*1024; // every collect so you can see where it goes wrong (usually requires HX_GC_FIXED_BLOCKS) //#define HX_WATCH -#if defined(HX_GC_VERIFY) && defined(HXCPP_GC_GENERATIONAL) +#if defined(HXCPP_GC_VERIFY) && defined(HXCPP_GC_GENERATIONAL) #define HX_GC_VERIFY_GENERATIONAL #endif @@ -192,7 +192,7 @@ static bool sGcVerifyGenerational = false; #endif -#if HX_HAS_ATOMIC && (HXCPP_GC_DEBUG_LEVEL==0) && !defined(HX_GC_VERIFY) && !defined(EMSCRIPTEN) +#if HX_HAS_ATOMIC && (HXCPP_GC_DEBUG_LEVEL==0) && !defined(HXCPP_GC_VERIFY) && !defined(EMSCRIPTEN) #if defined(HX_MACOS) || defined(HX_WINDOWS) || defined(HX_LINUX) enum { MAX_GC_THREADS = 4 }; #else @@ -728,6 +728,13 @@ static int gBlockInfoEmptySlots = 0; #define ZEROED_THREAD 1 #define ZEROED_AUTO 2 +// Align padding based on block offset +#ifdef HXCPP_ALIGN_ALLOC + #define ALIGN_PADDING(x) (4-(x&4)) +#else + #define ALIGN_PADDING(x) 0 +#endif + struct BlockDataInfo { int mId; @@ -1202,6 +1209,13 @@ struct BlockDataInfo int last = scan + mRanges[h].length; if (inOffset> IMMIX_ALLOC_SIZE_SHIFT); int allocSize = size + sizeof(int); - while(allocSize>destLen) + while(allocSize + ALIGN_PADDING(destPos)>destLen) { hole++; if (hole>IMMIX_LINE_BITS; destStarts[ startRow ] |= hx::gImmixStartFlag[destPos&127]; @@ -3897,6 +3929,8 @@ class GlobalAllocator return 0; } + + int MoveSurvivors(hx::QuickVec *inRemembered) { int sourceScan = 0; @@ -3951,7 +3985,7 @@ class GlobalAllocator int allocSize = size + sizeof(int); // Find dest reqion ... - while(destHole==0 || destLen=destInfo->mHoles) @@ -3981,6 +4015,11 @@ class GlobalAllocator // TODO - not copy + paste + printf("Move!\n"); + #ifdef HXCPP_ALIGN_ALLOC + destPos += ALIGN_PADDING(destPos); + #endif + int startRow = destPos>>IMMIX_LINE_BITS; destStarts[ startRow ] |= hx::gImmixStartFlag[destPos&127]; @@ -4060,7 +4099,7 @@ class GlobalAllocator gAllocGroups[mAllBlocks[i]->mGroupId].isEmpty=false; } - #ifdef HX_GC_VERIFY + #ifdef HXCPP_GC_VERIFY typedef std::pair< void *, void * > ReleasedRange; std::vector releasedRange; std::vector releasedGids; @@ -4076,7 +4115,7 @@ class GlobalAllocator #ifdef SHOW_MEM_EVENTS_VERBOSE GCLOG("Release group %d: %p -> %p\n", i, g.alloc, g.alloc+groupBytes); #endif - #ifdef HX_GC_VERIFY + #ifdef HXCPP_GC_VERIFY releasedRange.push_back( ReleasedRange(g.alloc, g.alloc+groupBytes) ); releasedGids.push_back(i); #endif @@ -4105,7 +4144,7 @@ class GlobalAllocator } else { - #ifdef HX_GC_VERIFY + #ifdef HXCPP_GC_VERIFY for(int g=0;gmGroupId == releasedGids[g]) { @@ -4117,7 +4156,7 @@ class GlobalAllocator } } - #ifdef HX_GC_VERIFY + #ifdef HXCPP_GC_VERIFY for(int i=0;iverify("After mark"); #endif @@ -4793,7 +4832,7 @@ class GlobalAllocator } #endif - #ifdef HX_GC_VERIFY + #ifdef HXCPP_GC_VERIFY void VerifyBlockOrder() { for(int i=1;ispaceEnd || !(spaceStart & 7)) - size += 4; + // Do nothing here - aligning to the end of the row will bump the + // next allocation, so it's not clear if its a good idea. + #else + #ifdef HXCPP_GC_NURSERY + int spaceStart = spaceFirst - allocBase - 4; + int spaceEnd = spaceOversize - allocBase - 4; + #endif + + int size = ioSize + sizeof(int); + int end = spaceStart + size; + if (end <= spaceEnd) + { + int linePad = IMMIX_LINE_LEN - (end & (IMMIX_LINE_LEN-1)); + if (linePad>0 && linePad<=64) + ioSize += linePad; + } #endif - int end = spaceStart + size; - if (end <= spaceEnd) - { - int linePad = IMMIX_LINE_LEN - (end & (IMMIX_LINE_LEN-1)); - if (linePad>0 && linePad<=64) - ioSize += linePad; - } } @@ -6226,20 +6260,13 @@ class LocalAllocator : public hx::StackContext if (inSize==0) return hx::emptyAlloc; - #if defined(HXCPP_VISIT_ALLOCS) && defined(HXCPP_M64) + #if defined(HXCPP_VISIT_ALLOCS) && (defined(HXCPP_M64)||defined(HXCPP_ARM64)) // Make sure we can fit a relocation pointer int allocSize = sizeof(int) + std::max(8,inSize); #else int allocSize = sizeof(int) + inSize; #endif - #ifdef HXCPP_ALIGN_ALLOC - // If we start in even-int offset, we need to skip 8 bytes to get alloc on even-int - int skip4 = allocSize+spaceStart>spaceEnd || !(spaceStart & 7) ? 4 : 0; - #else - enum { skip4 = 0 }; - #endif - #if HXCPP_GC_DEBUG_LEVEL>0 if (inSize & 3) DebuggerTrap(); #endif @@ -6248,6 +6275,10 @@ class LocalAllocator : public hx::StackContext { #ifdef HXCPP_GC_NURSERY unsigned char *buffer = spaceFirst; + #ifdef HXCPP_ALIGN_ALLOC + if ((size_t)buffer & 0x4 ) + buffer += 4; + #endif unsigned char *end = buffer + allocSize; if ( end <= spaceOversize ) @@ -6268,13 +6299,14 @@ class LocalAllocator : public hx::StackContext if (s>spaceFirst && mFraggedRows) *mFraggedRows += (s - spaceFirst)>>IMMIX_LINE_BITS; #else - int end = spaceStart + allocSize + skip4; + #ifdef HXCPP_ALIGN_ALLOC + if (!((size_t)spaceStart & 0x4 )) + spaceStart += 4; + #endif + + int end = spaceStart + allocSize; if (end <= spaceEnd) { - #ifdef HXCPP_ALIGN_ALLOC - spaceStart += skip4; - #endif - unsigned int *buffer = (unsigned int *)(allocBase + spaceStart); int startRow = spaceStart>>IMMIX_LINE_BITS; diff --git a/test/haxe/compile.hxml b/test/haxe/compile.hxml index 2a23d789e..eedd52a3d 100644 --- a/test/haxe/compile.hxml +++ b/test/haxe/compile.hxml @@ -2,4 +2,4 @@ -r TestMain.hx -D HXCPP_GC_GENERATIONAL -L utest ---cpp bin \ No newline at end of file +--cpp bin diff --git a/toolchain/common-defines.xml b/toolchain/common-defines.xml index 517d9b401..3f8c111a9 100644 --- a/toolchain/common-defines.xml +++ b/toolchain/common-defines.xml @@ -24,6 +24,7 @@ + @@ -36,6 +37,7 @@ + From 5ed582597a091d19e0edf535cb91d74202807f58 Mon Sep 17 00:00:00 2001 From: Aidan Lee Date: Tue, 17 Sep 2024 18:32:16 +0100 Subject: [PATCH 14/15] add cppia test for multi level inheritance in host (#1154) * add cppia test for multi level inheritance in host * only run new tests for haxe 5 * fix version define --- test/cppia/Client.hx | 8 ++++++++ test/cppia/ClientExtendedExtendedRoot.hx | 7 +++++++ test/cppia/Common.hx | 1 + test/cppia/CppiaHost.hx | 15 +++++++++++++++ test/cppia/HostExtendedRoot.hx | 7 +++++++ test/cppia/HostRoot.hx | 11 +++++++++++ 6 files changed, 49 insertions(+) create mode 100644 test/cppia/ClientExtendedExtendedRoot.hx create mode 100644 test/cppia/HostExtendedRoot.hx create mode 100644 test/cppia/HostRoot.hx diff --git a/test/cppia/Client.hx b/test/cppia/Client.hx index f73cb3078..85a8b274a 100644 --- a/test/cppia/Client.hx +++ b/test/cppia/Client.hx @@ -159,6 +159,14 @@ class Client return; } + + final extending = new ClientExtendedExtendedRoot(); + + extending.addValue(); + + Common.clientRoot = extending; + + Common.clientImplementation = new ClientOne(); Common.status = "ok"; diff --git a/test/cppia/ClientExtendedExtendedRoot.hx b/test/cppia/ClientExtendedExtendedRoot.hx new file mode 100644 index 000000000..9465dc60e --- /dev/null +++ b/test/cppia/ClientExtendedExtendedRoot.hx @@ -0,0 +1,7 @@ +class ClientExtendedExtendedRoot extends HostExtendedRoot { + override function addValue() { + super.addValue(); + + values.push(2); + } +} \ No newline at end of file diff --git a/test/cppia/Common.hx b/test/cppia/Common.hx index 7f4c1920f..99f80f815 100644 --- a/test/cppia/Common.hx +++ b/test/cppia/Common.hx @@ -3,6 +3,7 @@ class Common public static var status:String = "tests not run"; public static var hostImplementation:pack.HostInterface; public static var clientImplementation:pack.HostInterface; + public static var clientRoot:HostRoot; public static var callbackSet:Int = 0; public static var callback: Void->Void; diff --git a/test/cppia/CppiaHost.hx b/test/cppia/CppiaHost.hx index 3ef7e3108..611a09c2e 100644 --- a/test/cppia/CppiaHost.hx +++ b/test/cppia/CppiaHost.hx @@ -1,6 +1,7 @@ import cpp.cppia.Host; import HostBase; +import HostExtendedRoot; class HostOne implements pack.HostInterface { @@ -84,6 +85,20 @@ class CppiaHost Sys.println("Bad cppia closure"); Sys.exit(-1); } + + #if (haxe >= version("4.3.6")) + if (Common.clientRoot == null) { + Sys.println("null client root class"); + Sys.exit(-1); + } + switch Common.clientRoot.values { + case [ 0, 1, 2 ]: + // + case _: + Sys.println("Unexpected items in array"); + Sys.exit(-1); + } + #end } } } diff --git a/test/cppia/HostExtendedRoot.hx b/test/cppia/HostExtendedRoot.hx new file mode 100644 index 000000000..ad45ae1b3 --- /dev/null +++ b/test/cppia/HostExtendedRoot.hx @@ -0,0 +1,7 @@ +class HostExtendedRoot extends HostRoot { + override function addValue() { + super.addValue(); + + values.push(1); + } +} \ No newline at end of file diff --git a/test/cppia/HostRoot.hx b/test/cppia/HostRoot.hx new file mode 100644 index 000000000..1d4181918 --- /dev/null +++ b/test/cppia/HostRoot.hx @@ -0,0 +1,11 @@ +class HostRoot { + public final values:Array; + + public function new() { + values = []; + } + + public function addValue() { + values.push(0); + } +} \ No newline at end of file From 66b8f880744cff339c925aeb52a3b8328cf9f300 Mon Sep 17 00:00:00 2001 From: Hugh Sanderson Date: Sun, 6 Oct 2024 13:37:11 +0800 Subject: [PATCH 15/15] Add 'set' with no name to dump current values. Check for undefined values when linking android --- toolchain/android-toolchain-clang.xml | 3 +++ tools/hxcpp/BuildTool.hx | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/toolchain/android-toolchain-clang.xml b/toolchain/android-toolchain-clang.xml index a6583b3b8..6ebbd5001 100644 --- a/toolchain/android-toolchain-clang.xml +++ b/toolchain/android-toolchain-clang.xml @@ -92,6 +92,9 @@ + + +