This commit touches neither boot/ocamlc nor boot/ocamllex
It has the side-effect of fixing the cleanup rules which did not use the
$(EXE) extension when removing a file although it was produced with the
$(EXE) extension.
Introduce type Obj.raw_data and functions Obj.raw_field, Obj.set_raw_field to manipulate out-of-heap pointers in no-naked-pointers mode, and more generally all other data that is not a well-formed OCaml value
Some OCaml objects contain data that cannot be safely represented
as an OCaml value (type Obj.t). For example, in no-naked-pointers mode,
this is the case for code pointers inside closures, and for the
"custom operations" pointers inside custom blocks.
This PR introduces a type Obj.raw_data (an alias for nativeint)
to encapsulate this data, and functions
Obj.raw_field / Obj.set_raw_field to read and write the "raw" contents
of fields of blocks.
Note: just like it is wrong to access code pointers and custom operations
using Obj.field / Obj.set_field, it is wrong to access regular fields
possibly containing pointers into the OCaml heap using
Obj.raw_field / Obj.set_raw_field. The OCaml heap block can be
reclaimed or moved after its address was captured by Obj.raw_field.
Symmetrically, Obj.set_raw_field on a regular field bypasses the
write barrier of the GC.
This module provides a purely sequential implementation of the
concurrent atomic references provided by the Multicore OCaml
standard library:
https://github.com/ocaml-multicore/ocaml-multicore/blob/parallel_minor_gc/stdlib/atomic.mli
This sequential implementation is provided in the interest of
compatibility: when people will start writing code to run on
Multicore, it would be nice if their use of Atomic was
backward-compatible with older versions of OCaml without having to
import additional compatibility layers. *)
- Add the key argument in the description of 'merge'
- Note that the keys of 'union f m1 m2' are a subset of the
input keys, not all the keys, since
bindings (union (fun _ _ _ -> None) m m) = []
- Fix grammar in the descriptions of 'filter', 'union', 'merge'
- Fix mismatched variable name in the description of 'partition'
- Note that 'find' and 'find_opt' return values, not bindings
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).
The docs on this are out of date: they say runtime warnings are enabled by
default, but the source code has a commit 6c90da4 pointing to
https://github.com/ocaml/ocaml/pull/210 that disables them by default.
It seems like enabling runtime warnings by default never made its way into a
release and the docs could just be updated to say that runtime warnings are
disabled by default.
Signed-off-by: Edwin Török <edvin.torok@citrix.com>
This moves the configure-generated parts of Makefile.common to a
separate (generated) Makefile, allowing Makefile.common to be a normal
Makefile.
OCaml's build system Makefile's now include Makefile.build_config (which
itself includes Makefile.config) but Makefile.config is still installed
as before. This allows configure to generate variables which are
specific to the build process and are not intended to be exported to the
installation.
The Gc.Memprof module provides a low-level API, that will hopefully be
paired with user libraries that provide high-level instrumentation
choices.
A natural question is: how are the higher-level API going to expose
their choice of instrumentation to their users? With the current
Memprof.start API (before this patch), they would have to either
provide their own `start` function wrapping Memprof.start, or provide
a tuple of callbacks for to their users to pass to Memprof.start
themselves.
val start : params -> unit
(* or *)
val callback : params ->
((allocation -> foo option) * (allocation -> bar option) * ... )
With an explicit record, it is easier for libraries to expose an
instrumentation choice (possibility parametrized over
user-provided settings):
val tracker : params -> (foo, bar) Gc.Memprof.tracker
In addition, providing a record instead of optional parameters makes
it much easier to provide "default settings" (helper functions) that
instantiates the types `'minor` and `'ḿajor`, see for example
`simple_tracker` in this patch (which stores the same information for
the minor and major heap, and does not observe promotion), or to later
define checking predicates that can verify that a given choice of
callbacks is sensible (for example: providing a major-dealloc callback
but no promotion callback (dropping all tracked value on promotion) is
probably not a good idea).
Bootstrap: to avoid requiring an awkward bootstrap, this commit keeps
the (now unused) function caml_memprof_start_byt unchanged -- it is
used in the bootstrap binaries, so removing it would break the
build. The intention is to remove it in the following commit.
Printexc.uncaught_exception_handler ceases to be an option ref and becomes
a ref to the handler function initialized to
Printexc.default_uncaught_exception_handler.
This lets users write code that is robust to the addition of new
geometry fields.
Format.(pp_update_geometry ppf (fun geo -> {geo with ...}))
Today the only way to set the geometry is
Format.pp_set_geometry ppf ~margin ~max_indent
we cannot add optional parameters after the [ppf] argument, and adding
new labeled parameters would break user code.
(Also: it's often convenient to work with the record directly, for
example to reset a previous geometry saved with [pp_get_geometry];
this is indirectly provided by [pp_update_geometry].)
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.
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.
Deprecated warnings should point to `Array` alternatives rather than
those in `ArrayLabels`
Removed module references from function docs to avoid confusing between
StdLabels, Array and ArrayLabels
No change entry needed
- Removal of string arguments from exceptions in docs
- Changed references to ArrayLabels instead of Array whenever
a labeled argument is present
- Fixes to code examples using the wrong argument(wrong name, or missing label)
No change entry needed
The previous mechanism worked for C calls that raise an exception, but not for C calls that call back into OCaml code which raises an exception.
This commit addresses the issue by saving the PC in the interpreter stack before a C call, so that the backtrace mechanism always sees it.
However, if an external is declared in the .ml file and exposed in the .mli file as a val, then ocamlc generates a wrapper that adds a spurious entry in the stack frame. In this PR, this change in behavior results in the re-declaration of Printexc.get_callstack as an external instead of a val, so that the spurious stack frame does not appear in call stacks obtained from Printexc.get_callstack.
* Fix free identifiers in spacetime
* Fix free identifiers in tools/gdb-macros
* [minor] Fix Caml_state fields in comments, and other comment updates
* Changes
This commit makes it possible to build the OCaml compiler according to
its configuration by simply runnning make. There is no need to specify
neither world nor world.opt explicitly, although the two targets
remain available.
This commit also introduces (and starts making use of) the
NATIVE_COMPILER build variable whosse value is true when the native
compiler is enabled and false otherwise.
This commit deduplicates some of the Makefile rules used to compile C files.
Rather than having one such rule per Makefile for each directory
containing C files, the relevant rules are moved to Makefile.common.in.
MPR#7672: add a Filename.quote_command function
This function takes care of quoting the command and its arguments
so that they are correctly parsed by the system shell
(/bin/sh for Unix, cmd.exe for Win32).
Redirections for std input (< file) and std output (> file) and
std error (2> file) can also be specified as optional arguments.
A 2>&1 redirection is used if stdout and stderr are redirected to the
same file.
The result is a string that can be passed directly to Sys.command or
to the Unix functions that expect shell command lines.
Two bugs were present before the patch:
- Formatting_gen would always be printed as "@{",
so for example "@[foo@]" would be reprinted as "@{foo@]"
- The Formatting_gen payload would be printed as a string literal,
escaping '%', while it is a raw string representation of a format;
so for example "@[<%d>" would be reprinted as "@[<%%d>"
(This second bug was spotted by Florian Angeletti)
- Currently the check is a no-op, because the "emit a warning if the
check fails" was never implemented. (It would actually require some
work to pass a source location there to emit a warning, so it's not
trivial.)
- The check is implemented by calling `open_box_of_string` and
catching the `Failure _` exception if that function fails. This is
just wrong: `Failure _` should be reserved to fatal program errors,
and should not be caught for control-flow.
- The current implement is buggy (it fails all the time, but we don't
notice because no warning is emitted):
CamlinternalFormat.open_box_of_string expects a string of the form
"v 3", but check_open_box would pass a string of the form "<v 3>"
(or an empty string), which is the payload of the format value. So
the check always fails.
- The idea of the check is wrong: "@[<x>foo@]" is an incorrect format
string to pass to Format (the box indication does not make sense),
but it is a perfectly fine format string to pass to Printf, where it
just prints "@[<x>foo@]" on the output. So we cannot complain to the
user at type-checking time, when we don't know how the format string
will be used, whether the boxes will be interpreted as actual boxes
or string literals.
This makes sure that:
- Callbacks are never called when another is running
- The postponed queue is purged when setting memprof parameters
We now use a FIFO implemented as a circular buffer for remembering of
postponed blocks.
The workaround used for ignoring samples in the minor heap in native
mode now makes allocation very slow (or non-terminating) when the
sampling rate is not small enough. This will be fixed when sampling in
the minor heap in native mode will be implemented.
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
If an allocation fails, the decrement of young_ptr should be undone
before the GC is entered. This happened correctly on bytecode but not
on native code.
This commit (squash of pull request #8619) fixes it for all the
platforms supported by ocamlopt.
amd64: add alternate entry points caml_call_gc{1,2,3} for code size
optimisation.
powerpc: introduce one GC call point per allocation size per function.
Each call point corrects the allocation pointer r31 before calling
caml_call_gc.
i386, arm, arm64, s390x: update the allocation pointer after the
conditional branch to the GC, not before.
arm64: simplify the code generator: Ialloc can assume that less than
0x1_0000 bytes are allocated, since the max allocation size for the
minor heap is less than that.
This is a partial cherry-pick of commit 8ceec on multicore.
A #! line should not exceed 128 characters (including the \0
terminator). This adds a test - both to the generation of the camlheader
files and also to the -use-runtime flag which falls back to #!/bin/sh
and uses exec to invoke the the interpreter.
fixes#7156
Two new functions exposed:
```ocaml
val to_string_default: exn -> string
(** [Printexc.to_string_default e] returns a string representation of the
exception [e], ignoring all registered exception printers.
@since 4.09
*)
val use_printers: exn -> string option
(** [Printexc.use_printers e] returns [None] if there are no registered
printers and [Some s] with else as the resulting string otherwise.
@since 4.09
*)
```
When running a script with "ocaml foo.ml", the toplevel needs to
run foo.ml with a different Sys.argv than the initial value, since
foo.ml must not see the initial "ocaml" argument.
Previously, this was done with Obj.truncate to shorten the Sys.argv
array. This patch changes it by introducing a primitive %sys_argv.
Uses of this primitive expand to a call to a new C primitive, which
returns the argv array (and can be modified by the toplevel).
CamlinternalMod contains an optimisation for the initialisation
of recursive modules containing closures, where dummy closures
are updated in-place. This optimisation was buggy on bytecode,
since the bytecode interpreter relies on the lengths of blocks
containing closures (see #4008).
This commit disables the optimisation for bytecode (where it
had much less effect than on native code, and where performance
is of less concern anyway). The optimisation is still applied
on native-code, but without the use of Obj.truncate.
Also adds a test for #4008 (which introduced the truncate).
Hashtbl.MakeSeeded.{add,replace}_seq were not using the hash function
provided by the functor (Hashtbl.MakeSeeded.of_seq uses replace_seq and
so also has to be redefined locally).