Skip to content

homework 11: implement tracing dfs func#12

Merged
Ex4amp1e merged 7 commits into
mainfrom
gc
Jan 11, 2026
Merged

homework 11: implement tracing dfs func#12
Ex4amp1e merged 7 commits into
mainfrom
gc

Conversation

@Ex4amp1e
Copy link
Copy Markdown
Owner

@Ex4amp1e Ex4amp1e commented Jan 11, 2026

Finding with unstable test:

Even if the slice elements are on the heap, &heapPointerX for a local variable returns the address on the stack, which can different, and as result CI was getting different {{expectedPointers}} {{pointers}}.

The problem was that the address of a local stack variable was being taken, not the heap-allocated object.

Root cause:

var heapPointer1 = &heapObjects[1] is local func var on stack, even it is storing global heap addr. So it is stored on the func stack.
uintptr(unsafe.Pointer(&heapPointer1)) - it is actually taking addr of the func local var on stack,

Important: This address is not stable because:

  • Go can move local variables around on the stack
  • The stack can grow, causing variables to end up on different stack pages
  • The stack may be allocated at different memory locations in CI versus local runs

Solution:

Solution is to use global variables or heap-allocated objects - then the uintptr values are always stable.

Error:

So, we can see pretty same right-side addresses, but different stack bytes (61 and 50)

=== RUN   TestTrace
    homework_test.go:78: 
        	Error Trace:	/home/runner/work/deep-go/deep-go/homeworks/11_garbage_collector/homework_test.go:78
        	Error:      	elements differ
        	            	
        	            	extra elements in list A:
        	            	([]interface {}) (len=8) {
        	            	 (uintptr) 0xc000061f08,
        	            	 (uintptr) 0xc000061ec0,
        	            	 (uintptr) 0xc000061f00,
        	            	 (uintptr) 0xc000061ec8,
        	            	 (uintptr) 0xc000061ed0,
        	            	 (uintptr) 0xc000061ef0,
        	            	 (uintptr) 0xc000061ef8,
        	            	 (uintptr) 0xc000061ed8
        	            	}
        	            	
        	            	
        	            	extra elements in list B:
        	            	([]interface {}) (len=8) {
        	            	 (uintptr) 0xc000050f08,
        	            	 (uintptr) 0xc000050ec8,
        	            	 (uintptr) 0xc000050ec0,
        	            	 (uintptr) 0xc000050f00,
        	            	 (uintptr) 0xc000050ed0,
        	            	 (uintptr) 0xc000050ef0,
        	            	 (uintptr) 0xc000050ef8,
        	            	 (uintptr) 0xc000050ed8
        	            	}
        	            	
        	            	
        	            	listA:
        	            	([]uintptr) (len=8) {
        	            	 (uintptr) 0xc000061f08,
        	            	 (uintptr) 0xc000061ec0,
        	            	 (uintptr) 0xc000061f00,
        	            	 (uintptr) 0xc000061ec8,
        	            	 (uintptr) 0xc000061ed0,
        	            	 (uintptr) 0xc000061ef0,
        	            	 (uintptr) 0xc000061ef8,
        	            	 (uintptr) 0xc000061ed8
        	            	}
        	            	
        	            	
        	            	listB:
        	            	([]uintptr) (len=8) {
        	            	 (uintptr) 0xc000050f08,
        	            	 (uintptr) 0xc000050ec8,
        	            	 (uintptr) 0xc000050ec0,
        	            	 (uintptr) 0xc000050f00,
        	            	 (uintptr) 0xc000050ed0,
        	            	 (uintptr) 0xc000050ef0,
        	            	 (uintptr) 0xc000050ef8,
        	            	 (uintptr) 0xc000050ed8
        	            	}
        	Test:       	TestTrace
--- FAIL: TestTrace (0.00s)

Signed-off-by: Vladislav Byrgazov <vlados.byrgazov@gmail.com>
Signed-off-by: Vladislav Byrgazov <vlados.byrgazov@gmail.com>
Signed-off-by: Vladislav Byrgazov <vlados.byrgazov@gmail.com>
Signed-off-by: Vladislav Byrgazov <vlados.byrgazov@gmail.com>
Signed-off-by: Vladislav Byrgazov <vlados.byrgazov@gmail.com>
Signed-off-by: Vladislav Byrgazov <vlados.byrgazov@gmail.com>
Signed-off-by: Vladislav Byrgazov <vlados.byrgazov@gmail.com>
@Ex4amp1e Ex4amp1e merged commit b2fc55f into main Jan 11, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant