[Git][ghc/ghc][master] 2 commits: rts: use performBlockingMajorGC in hs_perform_gc and fix ffi023

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Sat Mar 25 07:47:01 UTC 2023



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
b2d14d0b by Cheng Shao at 2023-03-25T03:46:43-04:00
rts: use performBlockingMajorGC in hs_perform_gc and fix ffi023

This patch does a few things:

- Add the missing RtsSymbols.c entry of performBlockingMajorGC
- Make hs_perform_gc call performBlockingMajorGC, which restores
  previous behavior
- Use hs_perform_gc in ffi023
- Remove rts_clearMemory() call in ffi023, it now works again in some
  test ways previously marked as broken. Fixes #23089

- - - - -
d9ae24ad by Cheng Shao at 2023-03-25T03:46:44-04:00
testsuite: add the rts_clearMemory test case

This patch adds a standalone test case for rts_clearMemory that mimics
how it's typically used by wasm backend users and ensures this RTS API
isn't broken by future RTS refactorings. Fixes #23901.

- - - - -


8 changed files:

- rts/HsFFI.c
- rts/RtsSymbols.c
- testsuite/.gitignore
- testsuite/tests/ffi/should_run/Makefile
- testsuite/tests/ffi/should_run/all.T
- testsuite/tests/ffi/should_run/ffi023_c.c
- + testsuite/tests/ffi/should_run/rts_clearMemory.hs
- + testsuite/tests/ffi/should_run/rts_clearMemory_c.c


Changes:

=====================================
rts/HsFFI.c
=====================================
@@ -24,8 +24,8 @@ hs_set_argv(int argc, char *argv[])
 void
 hs_perform_gc(void)
 {
-    /* Hmmm, the FFI spec is a bit vague, but it seems to imply a major GC... */
-    performMajorGC();
+    /* Hmmm, the FFI spec is a bit vague, but it seems to imply a blocking major GC... */
+    performBlockingMajorGC();
 }
 
 // Lock the stable pointer table


=====================================
rts/RtsSymbols.c
=====================================
@@ -649,6 +649,7 @@ extern char **environ;
       SymI_HasProto(updateRemembSetPushClosure_)                          \
       SymI_HasProto(performGC)                                          \
       SymI_HasProto(performMajorGC)                                     \
+      SymI_HasProto(performBlockingMajorGC)                             \
       SymI_HasProto(prog_argc)                                          \
       SymI_HasProto(prog_argv)                                          \
       SymI_HasDataProto(stg_putMVarzh)                                      \


=====================================
testsuite/.gitignore
=====================================
@@ -732,6 +732,7 @@ mk/ghcconfig*_test___spaces_ghc*.exe.mk
 /tests/ffi/should_run/ffi021
 /tests/ffi/should_run/ffi022
 /tests/ffi/should_run/ffi023
+/tests/ffi/should_run/rts_clearMemory
 /tests/ffi/should_run/ffi_parsing_001
 /tests/ffi/should_run/fptr01
 /tests/ffi/should_run/fptr02


=====================================
testsuite/tests/ffi/should_run/Makefile
=====================================
@@ -25,6 +25,9 @@ T5594_setup :
 ffi023_setup :
 	'$(TEST_HC)' $(TEST_HC_OPTS) -c ffi023.hs
 
+rts_clearMemory_setup :
+	'$(TEST_HC)' $(TEST_HC_OPTS) -c rts_clearMemory.hs
+
 .PHONY: Capi_Ctype_001
 Capi_Ctype_001:
 	'$(HSC2HS)' Capi_Ctype_A_001.hsc


=====================================
testsuite/tests/ffi/should_run/all.T
=====================================
@@ -191,7 +191,6 @@ test('T8083', [omit_ways(['ghci']), req_c], compile_and_run, ['T8083_c.c'])
 test('T9274', [omit_ways(['ghci'])], compile_and_run, [''])
 
 test('ffi023', [ omit_ways(['ghci']),
-                expect_broken_for(23089, ['threaded2', 'nonmoving_thr', 'nonmoving_thr_sanity', 'nonmoving_thr_ghc']),
                 extra_run_opts('1000 4'),
                 js_broken(22363),
                 pre_cmd('$MAKE -s --no-print-directory ffi023_setup') ],
@@ -200,6 +199,18 @@ test('ffi023', [ omit_ways(['ghci']),
                 # needs it.
               compile_and_run, ['ffi023_c.c'])
 
+test('rts_clearMemory', [
+     # We only care about different GC configurations under the
+     # single-threaded RTS for the time being.
+     only_ways(['normal', 'optasm' ,'g1', 'nursery_chunks', 'nonmoving', 'compacting_gc']),
+     extra_ways(['g1', 'nursery_chunks', 'nonmoving', 'compacting_gc']),
+     # On windows, nonmoving way fails with bad exit code (2816)
+     when(opsys('mingw32'), fragile(23091)),
+     js_broken(22363),
+     pre_cmd('$MAKE -s --no-print-directory rts_clearMemory_setup') ],
+     # Same hack as ffi023
+     compile_and_run, ['rts_clearMemory_c.c -no-hs-main'])
+
 test('T12134', [omit_ways(['ghci']), req_c], compile_and_run, ['T12134_c.c'])
 
 test('T12614', [omit_ways(['ghci']), req_c], compile_and_run, ['T12614_c.c'])


=====================================
testsuite/tests/ffi/should_run/ffi023_c.c
=====================================
@@ -4,7 +4,6 @@
 
 HsInt out (HsInt x)
 {
-    performBlockingMajorGC();
-    rts_clearMemory();
+    hs_perform_gc();
     return incall(x);
 }


=====================================
testsuite/tests/ffi/should_run/rts_clearMemory.hs
=====================================
@@ -0,0 +1,15 @@
+module RtsClearMemory
+  ( foo,
+  )
+where
+
+import Control.DeepSeq
+import Control.Exception
+import Data.Functor
+
+-- | Behold, mortal! This function doth summon forth a horde of trash,
+-- mere playthings for the garbage collector's insatiable appetite.
+foo :: Int -> IO ()
+foo n = void $ evaluate $ force [0 .. n]
+
+foreign export ccall foo :: Int -> IO ()


=====================================
testsuite/tests/ffi/should_run/rts_clearMemory_c.c
=====================================
@@ -0,0 +1,12 @@
+#include <Rts.h>
+#include "rts_clearMemory_stub.h"
+
+int main(int argc, char *argv[]) {
+  hs_init_with_rtsopts(&argc, &argv);
+
+  for (int i = 0; i < 8; ++i) {
+    foo(1000000);
+    hs_perform_gc();
+    rts_clearMemory();
+  }
+}



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/62fa7faaf8ca2d34cda3e3b7c4c6b2d13efa16fe...d9ae24ad3de71e14364665ff1741aa3551e7c526

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/62fa7faaf8ca2d34cda3e3b7c4c6b2d13efa16fe...d9ae24ad3de71e14364665ff1741aa3551e7c526
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230325/46ead7eb/attachment-0001.html>


More information about the ghc-commits mailing list