Skip to content

Commit

Permalink
gc: use optimized mode by default (#10466)
Browse files Browse the repository at this point in the history
  • Loading branch information
UweKrueger committed Jun 15, 2021
1 parent 60c880a commit f3408a2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,27 @@ jobs:
run: |
thirdparty/tcc/tcc.exe -version
./v -cg -o v cmd/v # Make sure vtcc can build itself twice
- name: v self compilation with -gc boehm_full_opt
- name: v self compilation with -gc boehm
run: |
./v -gc boehm_full_opt -o v2 cmd/v && ./v2 -gc boehm_full_opt -o v3 cmd/v && ./v3 -gc boehm_full_opt -o v4 cmd/v
./v -gc boehm -o v2 cmd/v && ./v2 -gc boehm -o v3 cmd/v && ./v3 -gc boehm -o v4 cmd/v
mv v4 v
- name: v doctor
run: |
./v doctor
- name: Verify `v -gc boehm_full_opt test` works
- name: Verify `v -gc boehm test` works
run: |
./v -gc boehm_full_opt cmd/tools/test_if_v_test_system_works.v
./v -gc boehm cmd/tools/test_if_v_test_system_works.v
./cmd/tools/test_if_v_test_system_works
- name: Self tests with `-gc boehm_full_opt` with V compiler using Boehm-GC itself
run: ./v -gc boehm_full_opt -silent test-self
- name: Self tests with `-gc boehm` with V compiler using Boehm-GC itself
run: ./v -gc boehm -silent test-self
- name: Test leak detector
run: |
./v -gc boehm_leak -o testcase_leak vlib/v/tests/testcase_leak.v
./testcase_leak 2>leaks.txt
grep "Found 1 leaked object" leaks.txt && grep ", sz=1000," leaks.txt
- name: Test leak detector not being active for `-gc boehm_full_opt`
- name: Test leak detector not being active for `-gc boehm`
run: |
./v -gc boehm_full_opt -o testcase_leak vlib/v/tests/testcase_leak.v
./v -gc boehm -o testcase_leak vlib/v/tests/testcase_leak.v
./testcase_leak 2>leaks.txt
[ "$(stat -c %s leaks.txt)" = "0" ]
- name: Test leak detector not being active for normal compile
Expand Down
4 changes: 1 addition & 3 deletions vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,7 @@ pub fn (mut g Gen) init() {
if g.table.gostmts > 0 {
g.comptime_defines.writeln('#define __VTHREADS__ (1)')
}
if g.pref.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt, .boehm,
.boehm_leak,
] {
if g.pref.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt, .boehm_leak] {
g.comptime_defines.writeln('#define _VGCBOEHM (1)')
}
if g.pref.is_debug || 'debug' in g.pref.compile_defines {
Expand Down
8 changes: 2 additions & 6 deletions vlib/v/gen/c/cmain.v
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ fn (mut g Gen) gen_c_main_function_header() {

fn (mut g Gen) gen_c_main_header() {
g.gen_c_main_function_header()
if g.pref.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt, .boehm,
.boehm_leak,
] {
if g.pref.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt, .boehm_leak] {
g.writeln('#if defined(_VGCBOEHM)')
if g.pref.gc_mode == .boehm_leak {
g.writeln('\tGC_set_find_leak(1);')
Expand Down Expand Up @@ -176,9 +174,7 @@ pub fn (mut g Gen) gen_c_main_for_tests() {
main_fn_start_pos := g.out.len
g.writeln('')
g.gen_c_main_function_header()
if g.pref.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt, .boehm,
.boehm_leak,
] {
if g.pref.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt, .boehm_leak] {
g.writeln('#if defined(_VGCBOEHM)')
if g.pref.gc_mode == .boehm_leak {
g.writeln('\tGC_set_find_leak(1);')
Expand Down
4 changes: 2 additions & 2 deletions vlib/v/gen/c/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
g.inside_call = false
}
gen_keep_alive := node.is_keep_alive && node.return_type != ast.void_type
&& g.pref.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt, .boehm]
&& g.pref.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt]
gen_or := node.or_block.kind != .absent // && !g.is_autofree
is_gen_or_and_assign_rhs := gen_or && !g.discard_or_result
cur_line := if is_gen_or_and_assign_rhs || gen_keep_alive { // && !g.is_autofree {
Expand Down Expand Up @@ -954,7 +954,7 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
g.write(json_obj)
} else {
if node.is_keep_alive
&& g.pref.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt, .boehm] {
&& g.pref.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt] {
cur_line := g.go_before_stmt(0)
tmp_cnt_save = g.keep_alive_call_pregen(node)
g.write(cur_line)
Expand Down
10 changes: 6 additions & 4 deletions vlib/v/pref/pref.v
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub enum GarbageCollectionMode {
boehm_incr // incremental garbage colletion mode
boehm_full_opt // full garbage collection mode
boehm_incr_opt // incremental garbage colletion mode
boehm // default Boehm-GC mode for architecture
boehm_leak // leak detection mode (makes `gc_check_leaks()` work)
}

Expand Down Expand Up @@ -262,7 +261,7 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences
'-gc' {
gc_mode := cmdline.option(current_args, '-gc', '')
match gc_mode {
'' {
'', 'none' {
res.gc_mode = .no_gc
}
'boehm_full' {
Expand All @@ -288,8 +287,10 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences
parse_define(mut res, 'gcboehm_opt')
}
'boehm' {
res.gc_mode = .boehm
res.gc_mode = .boehm_full_opt // default mode
parse_define(mut res, 'gcboehm')
parse_define(mut res, 'gcboehm_full')
parse_define(mut res, 'gcboehm_opt')
}
'boehm_leak' {
res.gc_mode = .boehm_leak
Expand All @@ -298,12 +299,13 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences
}
else {
eprintln('unknown garbage collection mode `-gc $gc_mode`, supported modes are:`')
eprintln(' `-gc boehm` ............ default mode for the platform')
eprintln(' `-gc boehm` ............ default GC-mode (currently `boehm_full_opt`)')
eprintln(' `-gc boehm_full` ....... classic full collection')
eprintln(' `-gc boehm_incr` ....... incremental collection')
eprintln(' `-gc boehm_full_opt` ... optimized classic full collection')
eprintln(' `-gc boehm_incr_opt` ... optimized incremental collection')
eprintln(' `-gc boehm_leak` ....... leak detection (for debugging)')
eprintln(' `-gc none` ............. no garbage collection')
exit(1)
}
}
Expand Down

0 comments on commit f3408a2

Please sign in to comment.