Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f00680e

Browse files
committed
Add VERIFY_STACK_READ to allow testing of top and bottom of stack
1 parent 797ec85 commit f00680e

1 file changed

Lines changed: 65 additions & 13 deletions

File tree

src/hx/gc/Immix.cpp

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,6 +2458,30 @@ void HxFreeGCBlock(void *p) { HxFree(p); }
24582458
#endif // HX_MEMORY_H_OVERRIDE
24592459

24602460

2461+
//#define VERIFY_STACK_READ
2462+
2463+
#ifdef VERIFY_STACK_READ
2464+
// Just have something to do...
2465+
int gVerifyVoidCount = 0;
2466+
void VerifyStackRead(int *inBottom, int *inTop)
2467+
{
2468+
#ifdef EMSCRIPTEN
2469+
if (inTop<inBottom)
2470+
std::swap(inBottom,inTop);
2471+
#endif
2472+
2473+
int n = inTop - inBottom;
2474+
int check = std::min(n,5);
2475+
for(int c=0;c<check;c++)
2476+
{
2477+
if (inBottom[c]==0)
2478+
gVerifyVoidCount++;
2479+
if (inTop[-1-c]==0)
2480+
gVerifyVoidCount++;
2481+
}
2482+
}
2483+
#endif
2484+
24612485

24622486

24632487
class GlobalAllocator
@@ -4034,6 +4058,10 @@ namespace hx
40344058

40354059
void MarkConservative(int *inBottom, int *inTop,hx::MarkContext *__inCtx)
40364060
{
4061+
#ifdef VERIFY_STACK_READ
4062+
VerifyStackRead(inBottom, inTop);
4063+
#endif
4064+
40374065
#ifdef SHOW_MEM_EVENTS
40384066
GCLOG("Mark conservative %p...%p (%d)\n", inBottom, inTop, (int)(inTop-inBottom) );
40394067
#endif
@@ -4140,6 +4168,7 @@ class LocalAllocator : public hx::StackContext
41404168
void AttachThread(int *inTopOfStack)
41414169
{
41424170
mTopOfStack = mBottomOfStack = inTopOfStack;
4171+
41434172
mRegisterBufSize = 0;
41444173
mStackLocks = 0;
41454174
mGlobalStackLock = false;
@@ -4161,6 +4190,7 @@ class LocalAllocator : public hx::StackContext
41614190
onThreadDetach();
41624191
if (!sGlobalAlloc->ReturnToPool(this))
41634192
delete this;
4193+
mTopOfStack = mBottomOfStack = 0;
41644194
hx::tlsStackContext = 0;
41654195
}
41664196

@@ -4242,6 +4272,11 @@ class LocalAllocator : public hx::StackContext
42424272
ReturnToPool();
42434273
}
42444274
}
4275+
4276+
4277+
#ifdef VerifyStackRead
4278+
VerifyStackRead(mBottomOfStack, mTopOfStack)
4279+
#endif
42454280
}
42464281

42474282

@@ -4269,6 +4304,9 @@ class LocalAllocator : public hx::StackContext
42694304
void SetBottomOfStack(int *inBottom)
42704305
{
42714306
mBottomOfStack = inBottom;
4307+
#ifdef VerifyStackRead
4308+
VerifyStackRead(mBottomOfStack, mTopOfStack)
4309+
#endif
42724310
}
42734311

42744312
virtual void SetupStack()
@@ -4284,6 +4322,10 @@ class LocalAllocator : public hx::StackContext
42844322
mTopOfStack = mBottomOfStack;
42854323
#endif
42864324

4325+
#ifdef VerifyStackRead
4326+
VerifyStackRead(mBottomOfStack, mTopOfStack)
4327+
#endif
4328+
42874329
if (mGCFreeZone)
42884330
ExitGCFreeZone();
42894331

@@ -4298,6 +4340,10 @@ class LocalAllocator : public hx::StackContext
42984340
volatile int dummy = 1;
42994341
mBottomOfStack = (int *)&dummy;
43004342
CAPTURE_REGS;
4343+
#ifdef VerifyStackRead
4344+
VerifyStackRead(mBottomOfStack, mTopOfStack)
4345+
#endif
4346+
43014347
mReadyForCollect.Set();
43024348
mCollectDone.Wait();
43034349
}
@@ -4311,6 +4357,10 @@ class LocalAllocator : public hx::StackContext
43114357
{
43124358
CAPTURE_REGS;
43134359
}
4360+
#ifdef VerifyStackRead
4361+
VerifyStackRead(mBottomOfStack, mTopOfStack)
4362+
#endif
4363+
43144364
mReadyForCollect.Set();
43154365
}
43164366

@@ -4491,27 +4541,29 @@ class LocalAllocator : public hx::StackContext
44914541
#endif
44924542

44934543
#ifdef HXCPP_DEBUG
4494-
MarkPushClass("Stack",__inCtx);
4495-
MarkSetMember("Stack",__inCtx);
4496-
hx::MarkConservative(mBottomOfStack, mTopOfStack , __inCtx);
4544+
MarkPushClass("Stack",__inCtx);
4545+
MarkSetMember("Stack",__inCtx);
4546+
if (mTopOfStack && mBottomOfStack)
4547+
hx::MarkConservative(mBottomOfStack, mTopOfStack , __inCtx);
44974548
#ifdef HXCPP_SCRIPTABLE
4498-
MarkSetMember("ScriptStack",__inCtx);
4499-
hx::MarkConservative((int *)(stack), (int *)(pointer),__inCtx);
4549+
MarkSetMember("ScriptStack",__inCtx);
4550+
hx::MarkConservative((int *)(stack), (int *)(pointer),__inCtx);
45004551
#endif
4501-
MarkSetMember("Registers",__inCtx);
4502-
hx::MarkConservative(CAPTURE_REG_START, CAPTURE_REG_END, __inCtx);
4503-
MarkPopClass(__inCtx);
4552+
MarkSetMember("Registers",__inCtx);
4553+
hx::MarkConservative(CAPTURE_REG_START, CAPTURE_REG_END, __inCtx);
4554+
MarkPopClass(__inCtx);
45044555
#else
4505-
hx::MarkConservative(mBottomOfStack, mTopOfStack , __inCtx);
4506-
hx::MarkConservative(CAPTURE_REG_START, CAPTURE_REG_END, __inCtx);
4556+
if (mTopOfStack && mBottomOfStack)
4557+
hx::MarkConservative(mBottomOfStack, mTopOfStack , __inCtx);
4558+
hx::MarkConservative(CAPTURE_REG_START, CAPTURE_REG_END, __inCtx);
45074559
#ifdef HXCPP_SCRIPTABLE
4508-
hx::MarkConservative((int *)(stack), (int *)(pointer),__inCtx);
4560+
hx::MarkConservative((int *)(stack), (int *)(pointer),__inCtx);
45094561
#endif
45104562
#endif
45114563

45124564
#ifdef HXCPP_COMBINE_STRINGS
4513-
if (stringSet)
4514-
MarkMember( *(hx::Object **)&stringSet, __inCtx);
4565+
if (stringSet)
4566+
MarkMember( *(hx::Object **)&stringSet, __inCtx);
45154567
#endif
45164568

45174569
Reset();

0 commit comments

Comments
 (0)