From 8f47dd6babe0416c01b7f00a0c486b8a19804e04 Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Mon, 23 Oct 2023 14:20:19 +0800 Subject: [PATCH 1/6] debug --- Kernel/Containers/list.ipp | 1 + tests/Kernel/Containers/list_test.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/Kernel/Containers/list.ipp b/Kernel/Containers/list.ipp index d9e34afec..52fc86ffb 100644 --- a/Kernel/Containers/list.ipp +++ b/Kernel/Containers/list.ipp @@ -192,6 +192,7 @@ list reverse (list l) { list r; while (!is_nil (l)) { + mem_info (); r= list (l->item, r); l= l->next; } diff --git a/tests/Kernel/Containers/list_test.cpp b/tests/Kernel/Containers/list_test.cpp index 3325c579a..67f4023c6 100644 --- a/tests/Kernel/Containers/list_test.cpp +++ b/tests/Kernel/Containers/list_test.cpp @@ -140,3 +140,14 @@ TEST_CASE ("contains") { CHECK_EQ (contains (normal, 2L), true); CHECK_EQ (contains (normal, 3L), true); } + +TEST_CASE ("long list") { + mem_info (); + list long_l; + for (int i=0; i<300000; i++) { + if (i % 5000 == 0) { + mem_info (); + } + long_l= list ("hello", long_l); + } +} \ No newline at end of file From 623c2f41abe497b448eef713dc246703c55899c6 Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Mon, 23 Oct 2023 15:28:55 +0800 Subject: [PATCH 2/6] wip --- tests/Kernel/Containers/list_test.cpp | 18 ++++++++++-------- xmake.lua | 3 +++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/Kernel/Containers/list_test.cpp b/tests/Kernel/Containers/list_test.cpp index 67f4023c6..c7193f30d 100644 --- a/tests/Kernel/Containers/list_test.cpp +++ b/tests/Kernel/Containers/list_test.cpp @@ -141,13 +141,15 @@ TEST_CASE ("contains") { CHECK_EQ (contains (normal, 3L), true); } -TEST_CASE ("long list") { - mem_info (); +TEST_CASE ("long list under stack size") { + int initial_mem_used= mem_used (); + cout << "Initial mem used: " << initial_mem_used << LF; list long_l; - for (int i=0; i<300000; i++) { - if (i % 5000 == 0) { - mem_info (); - } - long_l= list ("hello", long_l); + // increase the size to 5000, there will be a stackoverflow on Windows + for (int i=0; i<4000; i++) { + long_l= list ("88888888", long_l); } -} \ No newline at end of file + int final_mem_used= mem_used (); + cout << "Final mem used: " << final_mem_used << LF; + cout << "Actual mem used: " << final_mem_used - initial_mem_used << LF; +} diff --git a/xmake.lua b/xmake.lua index 6b8f01ab3..757f30b49 100644 --- a/xmake.lua +++ b/xmake.lua @@ -187,6 +187,9 @@ function add_test_target(filepath) if is_plat("windows") then add_cxxflags("/utf-8") add_ldflags("/LTCG") + -- https://learn.microsoft.com/en-us/cpp/build/reference/stack-stack-allocations?view=msvc-170 + -- explicitly set stack size to 1M on windows + add_ldflags("/STACK:1048576") end if is_plat("windows") or is_plat("mingw") then From 411d1553e7f04b66b8cb2871383ea64d8065acc9 Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Mon, 23 Oct 2023 15:31:57 +0800 Subject: [PATCH 3/6] wip --- xmake.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xmake.lua b/xmake.lua index 757f30b49..2dca8aece 100644 --- a/xmake.lua +++ b/xmake.lua @@ -182,6 +182,8 @@ function add_test_target(filepath) if is_plat("linux") then add_syslinks("stdc++", "m") + -- explicitly set stack size to 1M on linux + add_ldflags("-Wl,--stack,1048576") end if is_plat("windows") then From 8bab65736d3cab4fdde8654e4fc4cff830ff68c8 Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Mon, 23 Oct 2023 15:35:54 +0800 Subject: [PATCH 4/6] Revert "wip" This reverts commit 411d1553e7f04b66b8cb2871383ea64d8065acc9. --- xmake.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/xmake.lua b/xmake.lua index 2dca8aece..757f30b49 100644 --- a/xmake.lua +++ b/xmake.lua @@ -182,8 +182,6 @@ function add_test_target(filepath) if is_plat("linux") then add_syslinks("stdc++", "m") - -- explicitly set stack size to 1M on linux - add_ldflags("-Wl,--stack,1048576") end if is_plat("windows") then From 90ade2845959e2afc5e000a7818005a4e8483a48 Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Mon, 23 Oct 2023 15:37:40 +0800 Subject: [PATCH 5/6] wip --- Kernel/Containers/list.ipp | 1 - 1 file changed, 1 deletion(-) diff --git a/Kernel/Containers/list.ipp b/Kernel/Containers/list.ipp index 52fc86ffb..d9e34afec 100644 --- a/Kernel/Containers/list.ipp +++ b/Kernel/Containers/list.ipp @@ -192,7 +192,6 @@ list reverse (list l) { list r; while (!is_nil (l)) { - mem_info (); r= list (l->item, r); l= l->next; } From c18a38ae931c77faea31ade08463c76a255a5806 Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Mon, 23 Oct 2023 15:50:42 +0800 Subject: [PATCH 6/6] wip --- tests/Kernel/Containers/list_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Kernel/Containers/list_test.cpp b/tests/Kernel/Containers/list_test.cpp index c7193f30d..470a8634c 100644 --- a/tests/Kernel/Containers/list_test.cpp +++ b/tests/Kernel/Containers/list_test.cpp @@ -146,7 +146,7 @@ TEST_CASE ("long list under stack size") { cout << "Initial mem used: " << initial_mem_used << LF; list long_l; // increase the size to 5000, there will be a stackoverflow on Windows - for (int i=0; i<4000; i++) { + for (int i= 0; i < 4000; i++) { long_l= list ("88888888", long_l); } int final_mem_used= mem_used ();