Age | Commit message (Collapse) | Author |
|
* sverker/ets-select-fixation-owner-change-bug/OTP-15672:
erts: Fix ets:select table fixation leak at owner change
erts: Refactor common things into traverse_context_t
stdlib: Clarify docs for ets:info(_, safe_fixed)
|
|
Optimize tail-recursive calls of BIFs
OTP-15674
|
|
Symtom:
ETS table remains fixed after finished ets:select* call.
Problem:
The decision to unfix table after a yielding ets:select*
is based on table ownership, but ownership might have changed
while ets:select* was yielding.
Solution:
Remember and pass along whether table was fixed
when the traversal started.
|
|
and rename it from match_callbacks_t.
|
|
BEAM currently does not call BIFs at the end of a function in a
tail-recursive way. That is, when calling a BIF at the end of a
function, the BIF is first called, and then the stack frame
is deallocated, and then control is transferred to the caller.
If there is no stack frame when a BIF is called in the tail position,
the loader will emit a sequence of three instructions: first an
instruction that allocates a stack frame and saves the continuation
pointer (`allocate`), then an instruction that calls the BIF
(`call_bif`), and lastly an instruction that deallocates the stack
frame and returns to the caller (`deallocate_return`).
The old compiler would essentially allocate a stack frame for each
clause in a function, so it would not be that common that a BIF was
called in the tail position when there was no stack frame, so the
three-instruction sequence was deemed acceptable.
The new compiler only allocates stack frames when truly needed, so
the three-instruction BIF call sequence has become much more common.
This commit introduces a new `call_bif_only` instruction so that only
one instruction will be needed when calling a BIF in the tail position
when there is no stack frame. This instruction is also used when there
is a stack frame to make it possible to deallocate the stack frame
**before** calling the BIF, which may make a subsequent garbage
collection at the end of the BIF call cheaper (copying less garbage).
The one downside of this change is that the function that called the
BIF will not be included in the stack backtrace (similar to how a
tail-recursive call to an Erlang function will not be included in the
backtrace).
That was the quick summary of the commit. Here comes a detailed look
at how BIF calls are translated by the loader. The first example is a
function that calls `setelement/3` in the tail position:
update_no_stackframe(X) ->
setelement(5, X, new_value).
Here is the BEAM code:
{function, update_no_stackframe, 1, 12}.
{label,11}.
{line,[...]}.
{func_info,{atom,t},{atom,update_no_stackframe},1}.
{label,12}.
{move,{x,0},{x,1}}.
{move,{atom,new_value},{x,2}}.
{move,{integer,5},{x,0}}.
{line,[...]}.
{call_ext_only,3,{extfunc,erlang,setelement,3}}.
Because there is no stack frame, the `call_ext_only` instruction will
be used to call `setelement/3`:
{call_ext_only,3,{extfunc,erlang,setelement,3}}.
The loader will transform this instruction to a three-instruction
sequence:
0000000020BD8130: allocate_tt 0 3
0000000020BD8138: call_bif_e erlang:setelement/3
0000000020BD8148: deallocate_return_Q 0
Using the `call_bif_only` instruction introduced in this commit,
only one instruction is needed:
000000005DC377F0: call_bif_only_e erlang:setelement/3
`call_bif_only` calls the BIF and returns to the caller.
Now let's look at a function that already has a stack frame when
`setelement/3` is called:
update_with_stackframe(X) ->
foobar(X),
setelement(5, X, new_value).
Here is the BEAM code:
{function, update_with_stackframe, 1, 14}.
{label,13}.
{line,[...]}.
{func_info,{atom,t},{atom,update_with_stackframe},1}.
{label,14}.
{allocate,1,1}.
{move,{x,0},{y,0}}.
{line,[...]}.
{call,1,{f,16}}.
{move,{y,0},{x,1}}.
{move,{atom,new_value},{x,2}}.
{move,{integer,5},{x,0}}.
{line,[...]}.
{call_ext_last,3,{extfunc,erlang,setelement,3},1}.
Since there is a stack frame, the `call_ext_last` instruction will be used
to deallocate the stack frame and call the function:
{call_ext_last,3,{extfunc,erlang,setelement,3},1}.
Before this commit, the loader would translate this instruction to:
0000000020BD81B8: call_bif_e erlang:setelement/3
0000000020BD81C8: deallocate_return_Q 1
That is, the BIF is called before deallocating the stack frame and returning
to the calling function.
After this commit, the loader will translate the `call_ext_last` like this:
000000005DC37868: deallocate_Q 1
000000005DC37870: call_bif_only_e erlang:setelement/3
There are still two instructions, but now the stack frame will be
deallocated before calling the BIF, which could make the potential
garbage collection after the BIF call slightly more efficient (copying
less garbage).
We could have introduced a `call_bif_last` instruction, but the code
for calling a BIF is relatively large and there does not seem be a
practical way to share the code between `call_bif` and `call_bif_only`
(since the difference is at the end, after the BIF call). Therefore,
we did not want to clone the BIF calling code yet another time to
make a `call_bif_last` instruction.
|
|
Clarify beam_load error message on file/module mismatch
|
|
erts: Add enif_term_type
|
|
This is particularly important in case insensitive filesystems,
where attempting to invoke a module with the wrong case leads
to confusing error messages:
1> erlpress_core:foo().
beam/beam_load.c(1428): Error loading module 'erlpress_core':
module name in object code is erlPress_core
Loading of erlPress_core.beam failed: :badfile
This commit replaces object code by BEAM file and improves
the readability of the message.
|
|
* sverker/master/ets-no-mbuf-trapping/OTP-15660:
erts: Remove ets traversal yielding if heap fragment
|
|
Tune BEAM instructions for the new compiler (part 2)
|
|
into sverker/master/ets-no-mbuf-trapping/OTP-15660
|
|
into sverker/maint/ets-no-mbuf-trapping/OTP-15660
|
|
Many heap fragments do no longer make the GC slow.
Even worse, we are not guaranteed that a yield will provoke a GC
removing the fragments, which might lead to a one-yield-per-bucket
scenario if the heap fragment(s) still remains after each yield.
|
|
Use S operands instead of s operands for a slight speed increase
and reduction in code size of process_main(). Use micro instructions
for frequently executed instructions.
While at it, use safe multiplication in gen_get_integer() in
beam_load.c.
|
|
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.
|
|
* rickard/send-bump-reds/ERL-773/OTP-15513:
Fix faulty assertion
Bump reductions on send based on message size
|
|
|
|
|
|
|
|
Let sys.h define HAVE_OVERFLOW_CHECK_BUILTINS if the compiler supports
__builtin_mul_overflow() and the other overflow checking builtins.
The test is intentionally made in a sys.h and not as a configure test.
On Windows, beam_emu.c is always compiled using gcc, but the other
files are usually compiled with Microsoft's C compiler. With the
test in the header file, HAVE_OVERFLOW_CHECK_BUILTINS will be defined
when compiling beam_emu.c.
|
|
Starting in OTP 19 (in commit 9504c0dd71d0), the compiler emits
a test_unit instruction instead of a skip instruction at the end
of binary. We can do the same replacement in the loader to get
rid of the i_bs_skip_bits_all2 instruction.
|
|
On a 64-bit architecture, the size of any binary that would fit in the
memory must fit in a small, so we can fail immediately if the size
term is not a small.
|
|
The new compiler required adding support for Y register for all
binary matching instructions. That was (intentionally) done in a
naive way that simplicated duplicated the entire body of each
instruction.
Now it's time to be less naive. Rewrite the binary matching
instructions using micro instructions. Because some of the binary
instructions are huge, that will significantly decrease the size of
process_main().
When compiling with clang, a huge process_main() would mess up
profile-guide optimization resulting in a significant performance
degradation. On my Mac, profile-guide optimzation would decrease
the estone benchmark by 100K estones (about 20 percent). This commit
gives me back the lost estones.
|
|
Mark the obsoleted instructions bs_start_match2, bs_save2, bs_restore2, and
bs_context_to_binary as cold.
Remove support of a Y operand for bs_save2 and bs_restore2.
|
|
get_tuple_element with an Y register has become more frequent with
the new compiler.
|
|
The compiler used to generate "move Literal y(Y)" instructions very
rarely. Therefore, there was a transformation to avoid having a "move
c y" instruction.
With the new compiler, "move Literal y(Y)" instructions are relatively frequent, so we will need a "move c y" instruction.
|
|
|
|
|
|
|
|
|
|
|
|
* siri/logger/os-timestamp/OTP-15625:
Update preloaded
[logger] Change timestamp from erlang:system_time to os:system_time
|
|
The is_nonempty_list test is very frequently followed by
get_tl, and frequently followed by get_hd.
|
|
It turns out that the combination of is_nonempty_list
and test_heap is no longer frequent.
|
|
|
|
The test_arity instruction is often followed by get_tuple_element.
|
|
|
|
`swap x y` is rarely or never used. I found a single use of
`swap_temp x y x` in the sample of modules compiled by
`scripts/diffable`.
|
|
Of the `move_dup` instructions, only `move_dup x x x` was
frequently used. Remove the other register combinations.
With those instruction `move_dup` instructions removed, it
is necessary to add new predicates to avoid unsafe translation
to `move_shift` and `move2_par`.
Also add additional transformations to transform more `move`
instructions into `move2_par`. The existing transformation
would require the `move` instructions to be in the "right"
order in order to be transformed.
Remove `move3 x y x y x y` because it turns out to be rarely
executed.
|
|
This reverts commit df130102cdeca8d35fec95a0c926fd1cfec54eab.
|
|
|
|
|
|
|
|
Make iolist_size/1 yield
OTP-15631
|
|
The iolist_size/1 function did not yield even if the input list was
very long and a call to the function did only consume a single
reduction. This commit fixes these problems.
|
|
* maint:
erts: Fix macro redefinition
|
|
LIST_NEXT and LIST_PREV causes macro redefinitions from other include files.
beam/erl_ao_firstfit_alloc.c:103:9: warning: 'LIST_NEXT' macro redefined [-Wmacro-redefined]
^
/usr/include/sys/queue.h:507:9: note: previous definition is here
^
1 warning generated.
beam/erl_bestfit_alloc.c:125:9: warning: 'LIST_NEXT' macro redefined [-Wmacro-redefined]
^
/usr/include/sys/queue.h:507:9: note: previous definition is here
^
|
|
This is to align the timestamps with external logs.
|
|
Add enif_set_pid_undefined & enif_is_pid_undefined
|
|
'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
|