Commit Graph

37 Commits (master)

Author SHA1 Message Date
Damien Doligez dff48afa72 If the major GC is in Phase_idle, caml_gc_major_slice must start a new
major GC cycle instead of just calling caml_major_collection_slice.
fixes #7813
2020-11-03 11:09:35 +01:00
Damien Doligez 2339a8c907 Change workflow of caml_gc_dispatch to make sure the major GC does not
stall when no minor allocations take place.
2020-11-03 10:49:33 +01:00
Jacques-Henri Jourdan f83d71830d Memprof: provide the guarantee that an allocation callback is always run in the same thread the allocation takes place.
This is done by using a local entry array for each thread, containing
tracked blocks whose allocation callback has not yet been called.

This allows some simplification in the code running callbacks for
young allocations. Indeed, since the entry array is local to one
thread, we know for sure that it cannot be modified during a callback,
and therefore we no longer need to remember the indices of the
corresponding new entries.
2020-10-19 17:08:17 +02:00
Nicolás Ojeda Bär 540996d21e Remove Spacetime 2020-10-08 20:28:12 +02:00
David Allsopp eb6d803222 caml_gc_dispatch doesn't need exporting 2020-09-04 15:53:29 +01:00
Jacques-Henri Jourdan 95400d7ee0 Make Ephemeron compatible with infix pointers. 2020-07-18 08:07:35 +02:00
Enguerrand Decorne b7f0494df5 Rewrite the instrumented runtime to store traces in the CTF format.
The instrumentation code in the instrumented runtime was replaced
with new APIs to gather runtime statistics and output them in a new format
(Common Trace Format).
This commit also exposes new functions in the Gc module to pause or resume
instrumentation during a program execution (Gc.eventlog_pause and
Gc.eventlog_resume).
2020-04-30 10:32:01 +02:00
David Allsopp d26d37bf97
Merge pull request #1176 from dra27/c89_headers
Aid compatibility with older Microsoft C compilers
2020-02-13 15:17:30 +00:00
David Allsopp a87ad8f18b Use -Wdeclaration-after-statement
This GCC flag encourages development of C files which will compile
without error on older Microsoft C compilers.
2020-02-11 10:07:04 +00:00
David Allsopp ecb79b2d56 Fix spacetime builds 2020-02-11 10:00:53 +00:00
David Allsopp 3aab294513 Replace static inline with Caml_inline
The inline keyword is consequently no longer forced on MSVC builds.
2020-02-11 09:33:55 +00:00
Stephen Dolan 07bf49db5b Statmemprof support for native allocations (incl. Comballoc) 2020-01-25 22:55:56 +01:00
Jacques-Henri Jourdan 0c8416478c Drop support for tags in memprof.
They are somewhat difficult to handle for native allocations, and it is not clear how useful they are. Moreover, they are easy to add back since [Gc.Memprof.allocation] is a private record.
2020-01-11 13:19:10 +01:00
Jacques-Henri Jourdan 975bc47f51 Make sure the atom table and minor heap have their own dedicated pages.
We need to make sure they do not share a page with code, otherwise the
GC and the polymorphic hash and comparison functions will follow code
pointers and potentially trigger a segfault.
2020-01-06 14:16:12 +01:00
Jacques-Henri Jourdan 7dbbfce890 New ephemeron-free API for Memprof.
The user can register several callbacks, which are called for various
events during the block's lifetime. We need to maintain a data
structure for tracked blocks in the runtime. When using threads,
callbacks can be called concurrently in a reentrant way, so the
functions manipulating this data structure need to be reentrant.
2019-12-21 10:21:48 +01:00
Stephen Dolan 47b03758f3 Add assertions to ensure young_ptr is correctly updated before GC.
In debug builds, the minor GC now asserts that young_ptr points to
a valid minor heap header before starting GC. Since very few bit
patterns are valid minor heap headers, this is unlikely to be true
by coincidence.

This patch also ensures that minor allocations have color 0. This
was inconsistent between backends before.
2019-10-22 11:47:31 +01:00
Stephen Dolan 34f97941ec Retain debug information about allocation sizes, for statmemprof.
This code is adapted from jhjourdan's 2c93ca1e711. Comballoc is
extended to keep track of allocation sizes and debug info for each
allocation, and the frame table format is modified to store them.

The native code GC-entry logic is changed to match bytecode, by
calling the garbage collector at most once per allocation.

amd64 only, for now.
2019-10-22 11:47:31 +01:00
Guillaume Munch-Maccagnoni 7820dd7a96 In long-running C code, force examining all callbacks at the next safe
point following every minor collection or major slice.

Also run signal handlers first.

Indeed, in some cases, caml_something_to_do is not reliable (spotted
by @jhjourdan):

* We could get into caml_process_pending_actions when
  caml_something_to_do is seen as set but not caml_pending_signals,
  making us miss the signal.

* If there are two different callbacks (say, a signal and a finaliser)
  arriving at the same time, then we set caml_something_to_do to 0
  when starting the first one while the second one is still waiting.
  We may want to run the second one if the first one is taking long.

In the latter case, the additional fix is to favour signals, which
have a lower latency requirement, whereas the latency of finalisers
keeps the same order of magnitude, and memprof callbacks are served on
a best-effort basis.
2019-10-17 20:14:19 +02:00
Guillaume Munch-Maccagnoni d0f70f757a Resource-safe C interface for async callbacks
Introduce caml_process_pending_actions and
caml_process_pending_actions_exn: a variant of the former which does
not raise but returns a value that has to be checked against
Is_exception_value.

I keep the current conventions from caml_callback{,_exn}: For a
resource-safe interface, we mostly care about the _exn variants, but
every time there is a public _exn function I provide a function that
raises directly for convenience.

They are introduced and documented in caml/signals.h.

Private functions are converted to their _exn variant on the way as
needed: for internal functions of the runtime, it is desirable to go
towards a complete elimination of functions that raise implicitly.

Get rid of the distant logic of caml_raise_in_async_callback. Instead,
caml_process_pending_events takes care itself of its something_to_do
"resource". This avoids calling the former function in places
unrelated to asynchronous callbacks.
2019-10-17 20:14:19 +02:00
Guillaume Munch-Maccagnoni d0c8219726 [minor] When calling gc_dispatch directly, avoid setting caml_something_to_do
caml_minor_collection is not a new function, it is already used in the
wild and used to be exposed in caml/minor_gc.h in the past. The change
simply amounts to replacing a call to caml_request_minor_gc() with an
assignment requested_minor_gc = 1, bypassing
caml_set_something_to_do().
2019-10-16 14:22:49 +02:00
Guillaume Munch-Maccagnoni 2433b9373f Separate caml_check_urgent_gc back into GC actions and async callbacks
In 8691, caml_check_urgent_gc was merged with the function that runs
asynchronous callbacks. The rationale was that caml_check_urgent_gc
already runs finalisers, and so could have run any asynchronous
callbacks.

We agreed on a different strategy: we know that users could not rely
on asynchronous callbacks being called at this point, so take the
opportunity to make it callback-safe, like was done for allocation
functions.

The new check_urgent_gc no longer calls finalisers (nor any
callbacks), and instead two internal functions are introduced:

* caml_do_urgent_gc_and_callbacks : function to perform actions
  unconditionally.

* caml_check_urgent_gc_and_callbacks : function that checks for
  something to do, and then executes all actions (GC and callbacks).
2019-10-15 19:24:41 +02:00
Jacques-Henri Jourdan 6027c9e72e Make sure async callbacks and urgent GC requests are called for every call to [caml_alloc_small_dispatch]. 2019-10-11 11:17:20 +02:00
Guillaume Munch-Maccagnoni b304042b29 Fix missing Caml_state (#8940)
* Fix free identifiers in spacetime

* Fix free identifiers in tools/gdb-macros

* [minor] Fix Caml_state fields in comments, and other comment updates

* Changes
2019-10-03 16:27:32 +02:00
Gabriel Scherer fd7cbd8c49
Merge pull request #8729 from jhjourdan/memprof_intern
Memprof support for unmarshalled data
2019-08-29 22:39:46 +02:00
Stephen Dolan dcf346450b Ensure that C allocation functions do not trigger callbacks.
Fixes a bug in #8691 and adds a test.
2019-08-29 09:35:42 +01:00
Jacques-Henri Jourdan c0dbbfdd71 Memprof: stop using C global roots, and use our own root system.
Registering and unregistering global C roots was time consuming.
2019-08-27 19:05:03 +02:00
KC Sivaramakrishnan 6efd278286 Remove a level of indirection for accessing minor tables from Caml_state. 2019-08-23 09:50:05 +05:30
KC Sivaramakrishnan 126383b2b2 Fix long lines 2019-08-23 09:50:05 +05:30
KC Sivaramakrishnan cededf23b9 Move local_roots, compare unorderd and gc request variables to domain state 2019-08-23 09:50:05 +05:30
KC Sivaramakrishnan 755f5444f1 Move all statistics variables to domain state 2019-08-23 09:50:05 +05:30
KC Sivaramakrishnan 28c5b9c860 Various minor heap pointers moved to domain state 2019-08-23 09:50:05 +05:30
KC Sivaramakrishnan 45b1e18f59 young_ptr and young_limit are now in domain state 2019-08-23 09:50:05 +05:30
Jacques-Henri Jourdan 42ab59aab1 Use [caml_something_to_do] both in native and bytecode mode to remember that callbacks are pending.
This make us able to get rid of to xxx_to_do variables in `final.c`
and `memprof.c`. The variable is reset to 0 when entering
`caml_check_urgent_gc`, which is now the main entry point for
asynchronous callbacks. In case a callback raises an exception, we
need to set it back to 1 to make sure no callback is missed.
2019-06-06 16:08:06 +02:00
Jacques-Henri Jourdan 79088fb09d Guarantee that no finalisers will be called while allocating memory in OCaml heap from C code.
The finalizers and all the other asynchronous callbacks (including
signal handlers, memprof callbacks and finalizers) are now called in a
common function, [caml_async_callbacks]. It is called in
[caml_check_urgent_gc] and wherever [caml_process_pending_signals] was
called.

This makes it possible to simplify the [caml_gc_dispatch] logic by
removing the loop it contains, since it no longer calls finalizers.
2019-06-05 14:25:26 +02:00
Jacques-Henri Jourdan cea1ff7534 Memprof sampling for blocks in the minor heap, allocated by C code.
Allocations ignored by this version
- Marshalling
- In the minor heap by natively-compiled OCaml code

Allocations potentially sampled
- In the major heap
- In the minor heap by C code and OCaml code in bytecode mode
2019-05-20 13:04:28 +02:00
Jacques-Henri Jourdan 052a950dea Statistical memory profiling of blocks allocated in the major heap. 2019-05-09 16:40:45 +02:00
Sébastien Hinderer d3e73595e5 Merge the asmrun and byterun directories into the runtime directory 2018-06-28 17:50:33 +02:00