aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/erl_nif.c
AgeCommit message (Collapse)Author
2019-08-22Optimize continuation pointer managementBjörn Gustavsson
The BEAM instructions for calling a function don't save the continuation pointer (return address) on the stack, but to a special BEAM register called CP. It is the responsibility of the called function to save CP to the stack frame before calling other functions. In the earlier implementations of BEAM on Sparc, CP was located in a CPU register. That meant that the continuation pointer was never written to memory when calling simple functions that didn't call other functions at all or ended in a tail-call to another function. The modern BEAM no longer keeps CP in CPU register. Instead, it is kept in the `process` struct (in `p->cp`). That means the continuation pointer must be written to the memory on every call, and if the called function will call other functions, it will must read the continuation pointer from `p->cp` and store it on the stack. This commit eliminates the concept of the CP register and modifies the call instructions to directly store the continuation pointer on the stack. That makes allocation and trimming of stack frames slightly faster. A more important benefit is simplification of code that handles continuation pointers. Because all continuation pointers are now stored on the stack, the special case of handling `p->cp` disappears. Co-authored-by: John Högberg <[email protected]>
2019-05-28Merge pull request #2189 from ↵John Högberg
jhogberg/john/erts/seq-trace-on-spawn/OTP-15232/ERL-700 Propagate seq_trace tokens to spawned processes
2019-04-05Fail when we cannot encode term in binaryRickard Green
Fail when we cannot encode term in binary instead of producing a faulty result.
2019-03-21seq_trace: Inherit trace token on spawnJohn Högberg
Trace tokens can be lost when a process delegates message sending to a child process, which is pretty surprising and limits the usefulness of seq tracing. One example of this is gen_statem:call/4 which uses a child process to implement timeouts without the risk of a late message arriving to the caller. This commit attempts to remedy this by propagating the trace token to spawned processes, and adds optional tracing for process spawning as well.
2019-03-19Merge branch 'sverker/enif_whereis_pid-dirty-dtor'Sverker Eriksson
into sverker/master/enif_whereis_pid-dirty-dtor
2019-03-19erts: Schedule resource destructors alwaysSverker Eriksson
to run user NIF code in a more known execution context. Fixes problems like user calling enif_whereis_pid() in destructor which may need to release process main lock in order to lock reg_tab.
2019-03-08Merge pull request #2175 from jhogberg/john/erts/enif_term_type/OTP-15640John Högberg
erts: Add enif_term_type
2019-03-07erts: Add enif_term_typeJohn Högberg
This helps avoid long sequences of enif_is_xxx in code that serializes terms (such as JSON encoders) by letting the user switch on the type.
2019-03-06Merge branch 'rickard/send-bump-reds/ERL-773/OTP-15513'Rickard Green
* rickard/send-bump-reds/ERL-773/OTP-15513: Fix faulty assertion Bump reductions on send based on message size
2019-02-26Bump reductions on send based on message sizeRickard Green
2019-02-22Merge PR-2147 from sverker/sverker/enif-null-pid/OTP-15011Sverker Eriksson
Add enif_set_pid_undefined & enif_is_pid_undefined
2019-02-22Merge branch ↵Lukas Larsson
'lukas/erts/fragment-dist-messages/OTP-13397/OTP-15610/OTP-15611/OTP-15612/OTP-15613' * lukas/erts/fragment-dist-messages/OTP-13397/OTP-15610/OTP-15611/OTP-15612/OTP-15613: erts: Add debug dist obuf memory leak check win32: Fix ./otp_build debuginfo_win32 Make ld.sh on windows print better error reason erts: Fix so that externals with creation 0 compare equal to all erts: Expand etp to look for free processes erts: Implement trapping while sending distr exit/down erts: Add ERL_NODE_BOOKKEEP to node tables refc erts: Refactor ErtsSendContext to be ErtsDSigSendContext erts: Add distr testcases for fragmentation erts: Make remote send of exit/2 trap erts: Implement fragmentation of distrubution messages erts: Expand distribution protocol documentation erts: Move reason in dist messages to payload erts: Remove a copy of distribution data payload erts: Yield later during process exit and allow free procs to run erts: Refactor rbt _yielding to use reductions erts: Limit binary printout for %.XT in erts_print
2019-02-20Merge branch 'maint'Sverker Eriksson
2019-02-20erts: Add enif_set_pid_undefined & enif_is_pid_undefinedSverker Eriksson
2019-02-18erts: Make enif_consume_timeslice no-op on dirty schedSverker Eriksson
2019-02-11Merge branch 'maint'Sverker Eriksson
2019-02-06erts: Fix faulty debug assert in enif_selectSverker Eriksson
2019-02-05erts: Refactor rbt _yielding to use reductionsLukas Larsson
All of the Red-Black Tree _yielding functions have been updated to work with reductions returned by the called function instead of yielding on each element.
2019-02-01erts: Add enif_make_monitor_termSverker Eriksson
2019-01-07erts: Add enif_select_read|write with 'msg_env' argumentSverker Eriksson
2018-08-09Merge branch 'maint'Rickard Green
* maint: Fix caching of NIF environment when executing dirty
2018-08-09Merge branch 'rickard/full-cache-nif-env/OTP-15223/ERL-695' into maintRickard Green
* rickard/full-cache-nif-env/OTP-15223/ERL-695: Fix caching of NIF environment when executing dirty
2018-08-09Fix caching of NIF environment when executing dirtyRickard Green
2018-08-03Merge branch 'maint'Lukas Larsson
2018-08-03erts: Fix seq_trace to not clear token for system messagesLukas Larsson
A lot of erts internal messages used behind APIs to create non-blocking calls, e.g. port_command, would cause the seq_trace token to be cleared from the caller when it should not. This commit fixes that and adds asserts that makes sure that all messages sent have to correct token set. Fixes: ERL-602
2018-07-27Change "can not" into "cannot"Raimo Niskanen
I did not find any legitimate use of "can not", however skipped changing e.g RFCs archived in the source tree.
2018-06-05Merge branch 'sverker/enif_binary_to_term-bug/OTP-15080' into maint-20Erlang/OTP
* sverker/enif_binary_to_term-bug/OTP-15080: erts: Fix bug in enif_binary_to_term for immediates
2018-05-17Merge PR-1819 from sverker/enif_binary_to_term-bug/OTP-15080Sverker Eriksson
Fix bug in enif_binary_to_term for immediates
2018-05-16erts: Fix bug in enif_binary_to_term for immediatesSverker Eriksson
Symptom: Heap corruption Expanded test case to provoke this bug and test some more term types.
2018-04-26erts: Optimize monitor signal by message piggybackSverker Eriksson
If no message/signal is sent (to same destination) then monitor signal is flushed when process is scheduled out.
2018-04-16erts: Keep track of which NIF a scheduler is executingJohn Högberg
This may be of interest in crash dumps and allows the upcoming allocation tagging feature to track allocations on a per-NIF basis. Note that this is only updated when user code calls a NIF; it's not altered when the emulator calls NIFs during code upgrades or tracing.
2018-03-28Merge branch 'sverker/driver-taints/OTP-14960'Sverker Eriksson
* sverker/driver-taints/OTP-14960: erts: Include foreign static linked drivers in taints erts: Fix harmless bug in macro IS_DRIVER_VERSION_GE erts: Remove our own NIF modules from "taints" erts: Refactor erts_static_nif_get_nif_init erts: Add dynamic loaded drivers to list of "taints"
2018-03-23Add enif_make_map_from_arraysJohn Högberg
2018-03-22Merge branch 'sverker/enif-name-funcs/OTP-14994'Sverker Eriksson
2018-03-22erts: Improve NIF load incompatibility errorsSverker Eriksson
2018-03-22erts: Add enif_vfprintf and enif_vsnprintfSverker Eriksson
2018-03-22erts: Add enif_*_name functionsSverker Eriksson
2018-03-21Implementation of true asynchronous signaling between processesRickard Green
Communication between Erlang processes has conceptually always been performed through asynchronous signaling. The runtime system implementation has however previously preformed most operation synchronously. In a system with only one true thread of execution, this is not problematic (often the opposite). In a system with multiple threads of execution (as current runtime system implementation with SMP support) it becomes problematic. This since it often involves locking of structures when updating them which in turn cause resource contention. Utilizing true asynchronous communication often avoids these resource contention issues. The case that triggered this change was contention on the link lock due to frequent updates of the monitor trees during communication with a frequently used server. The signal order delivery guarantees of the language makes it hard to change the implementation of only some signals to use true asynchronous signaling. Therefore the implementations of (almost) all signals have been changed. Currently the following signals have been implemented as true asynchronous signals: - Message signals - Exit signals - Monitor signals - Demonitor signals - Monitor triggered signals (DOWN, CHANGE, etc) - Link signals - Unlink signals - Group leader signals All of the above already defined as asynchronous signals in the language. The implementation of messages signals was quite asynchronous to begin with, but had quite strict delivery constraints due to the ordering guarantees of signals between a pair of processes. The previously used message queue partitioned into two halves has been replaced by a more general signal queue partitioned into three parts that service all kinds of signals. More details regarding the signal queue can be found in comments in the erl_proc_sig_queue.h file. The monitor and link implementations have also been completely replaced in order to fit the new asynchronous signaling implementation as good as possible. More details regarding the new monitor and link implementations can be found in the erl_monitor_link.h file.
2018-03-20erts: Remove our own NIF modules from "taints"Sverker Eriksson
Dynamic NIF libs and those added with config option --enable-static-nifs are considered as taints.
2018-03-20erts: Refactor erts_static_nif_get_nif_initSverker Eriksson
to return pointer to ErtsStaticNifEntry.
2018-03-20erts: Add dynamic loaded drivers to list of "taints"Sverker Eriksson
2018-03-09Always use sys_memcpy/cmp/etc instead of plain memcpy/cmp/etcJohn Högberg
2018-02-26Make enif_make_binary return heap binaries if possibleJohn Högberg
This does not avoid allocating a ProcBin since we still need to release the binary somehow (and using the tmp obj list is slightly slower since it's an unavoidable off-heap allocation), but it does give us a hard limit on how long said ProcBin will live, which is a lot better than before. OTP-14845
2018-02-26Unconditionally transfer ownership to the created termJohn Högberg
This fixes two corner-cases: 1) We will no longer return an invalid term when a binary inspected on environment A is used in enif_make_binary on environment B 2) A double-free in this sequence of events: * enif_alloc_binary(size, &bin); * enif_ioq_enq_binary(ioq, &bin, skip); * enif_make_binary(env, &bin); * enif_make_binary(env, &bin); OTP-14931 OTP-14932
2018-02-26Tweak asserts and explain why the copy buf doesn't use the tmp obj listJohn Högberg
2018-02-26Free temporary iovecs through the tmp object listJohn Högberg
Attaching to a ProcBin is the fastest way to delay the release of an already allocated Binary, but alloc_tmp_obj is a lot faster when starting from scratch since it usually uses temp_alloc.
2018-02-23Add a helper function for attaching tmp objects to NIF environmentsJohn Högberg
2018-02-19Merge branch 'maint'John Högberg
2018-02-15Handle unaligned binaries in enif_inspect_iovecJohn Högberg
2018-01-16Merge branch 'sverker/build-proc-bin'Sverker Eriksson