LEFT | RIGHT |
(no file at all) | |
1 /* | 1 /* |
2 This file is part of LilyPond, the GNU music typesetter. | 2 This file is part of LilyPond, the GNU music typesetter. |
3 | 3 |
4 Copyright (C) 2005--2020 Han-Wen Nienhuys <hanwen@xs4all.nl> | 4 Copyright (C) 2005--2020 Han-Wen Nienhuys <hanwen@xs4all.nl> |
5 | 5 |
6 LilyPond is free software: you can redistribute it and/or modify | 6 LilyPond is free software: you can redistribute it and/or modify |
7 it under the terms of the GNU General Public License as published by | 7 it under the terms of the GNU General Public License as published by |
8 the Free Software Foundation, either version 3 of the License, or | 8 the Free Software Foundation, either version 3 of the License, or |
9 (at your option) any later version. | 9 (at your option) any later version. |
10 | 10 |
11 LilyPond is distributed in the hope that it will be useful, | 11 LilyPond is distributed in the hope that it will be useful, |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 GNU General Public License for more details. | 14 GNU General Public License for more details. |
15 | 15 |
16 You should have received a copy of the GNU General Public License | 16 You should have received a copy of the GNU General Public License |
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>. | 17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>. |
18 */ | 18 */ |
19 | 19 |
20 #include "smobs.hh" | 20 #include "smobs.hh" |
21 #include "listener.hh" | 21 #include "listener.hh" |
22 | 22 |
| 23 #if (GUILEV2) |
| 24 #include <gc/gc.h> |
| 25 #endif |
| 26 |
23 Listener | 27 Listener |
24 Smob_core::get_listener (SCM callback) | 28 Smob_core::get_listener (SCM callback) |
25 { | 29 { |
26 return Listener (callback, self_scm ()); | 30 return Listener (callback, self_scm ()); |
| 31 } |
| 32 |
| 33 size_t Smob_core::count = 0; |
| 34 |
| 35 void |
| 36 Smob_core::maybe_grow_heap () |
| 37 { |
| 38 #if (GUILEV2) |
| 39 /* |
| 40 BDWGC has a special case for objects with finalizers |
| 41 |
| 42 https://github.com/ivmai/bdwgc/blob/v8.0.4/alloc.c#L1435 |
| 43 |
| 44 where it decides to not expand the heap if there are more than 500 |
| 45 objects with finalizers outstanding. |
| 46 |
| 47 Since smobs with free functions are implemented with finalizer, we |
| 48 always fall into this case. |
| 49 |
| 50 The symptom of this problem is that running with GC_PRINT_STATS=1 |
| 51 will print |
| 52 |
| 53 In-use heap: 85% (370824 KiB pointers + 60065 KiB other) |
| 54 In-use heap: 85% (370725 KiB pointers + 59737 KiB other) |
| 55 .. |
| 56 |
| 57 We can reconsider this hack if we have dropped all smob free functions from |
| 58 our code base. |
| 59 */ |
| 60 static GC_word last_gc_no; |
| 61 GC_word no = GC_get_gc_no (); |
| 62 if (no == last_gc_no) |
| 63 { |
| 64 return; |
| 65 } |
| 66 last_gc_no = no; |
| 67 |
| 68 GC_word size = GC_get_heap_size (); |
| 69 GC_word bytes_per_obj = 2000; |
| 70 GC_word want_heap = count * bytes_per_obj; |
| 71 if (size < want_heap) |
| 72 { |
| 73 GC_expand_hp (want_heap - size); |
| 74 } |
| 75 #endif |
27 } | 76 } |
28 | 77 |
29 /* | 78 /* |
30 The CDR contains the actual protected list. | 79 The CDR contains the actual protected list. |
31 */ | 80 */ |
32 static SCM smob_protection_list = SCM_EOL; | 81 static SCM smob_protection_list = SCM_EOL; |
33 | 82 |
34 void | 83 void |
35 init_smob_protection () | 84 init_smob_protection () |
36 { | 85 { |
(...skipping 25 matching lines...) Expand all Loading... |
62 | 111 |
63 | 112 |
64 Scm_init const *Scm_init::list_ = 0; | 113 Scm_init const *Scm_init::list_ = 0; |
65 | 114 |
66 void | 115 void |
67 Scm_init::init () | 116 Scm_init::init () |
68 { | 117 { |
69 for (Scm_init const *p = list_; p; p = p->next_) | 118 for (Scm_init const *p = list_; p; p = p->next_) |
70 p->fun_ (); | 119 p->fun_ (); |
71 } | 120 } |
LEFT | RIGHT |