Age | Commit message (Collapse) | Author |
|
Compile external fun expressions to literals
OTP-15003
|
|
The expressions fun M:F/A, when all elements are literals are also
treated as a literal. Since they have consistent representation and
don't depend on the code currently loaded in the VM, this is safe.
This can provide significant performance improvements in code using such
functions extensively - a full function call to erlang:make_fun/3 is
replaced by a single move instruction and no register shuffling or
saving registers to stack is necessary. Additionally, compound data
types that contain such external functions as elements can be treated as
literals too.
The commit also changes the representation of external funs to be a
valid Erlang syntax and adds support for literal external funs to core
Erlang.
|
|
|
|
|
|
|
|
|
|
|
|
particularly slow erlc when compiler is hipe compiled.
hipe_unified_loader:load did not patch external call sites
and instead caused a double hipe mode switch per call.
hipe_unified_loader:load is only used
for early modules first loaded as beam
and by code:atomic_load and friends.
|
|
* maint:
Fix encoding of filenames in stacktraces
|
|
|
|
|
|
|
|
When compiling Erlang source code, the literal area for the
module can only contain data types that have a literal
syntax.
However, it is possible to sneak in other data types
(such as references) in the literal pool by compiling from
abstract or assembly code. Those "fake literals" would work
fine, but would crash the runtime system when the module containing
the literals was purged.
Although fake literals are not officially supported, the
runtime should not crash when attempting to use them.
Therefore, fix the garbage collection of literals and releasing
of literal areas.
https://bugs.erlang.org/browse/ERL-508
|
|
The 's' operand overloads the tags for pids and ports to represent
X and Y registers, respectively. At load time, refuse to load the
module if the "literal" term is not a pid or port, as it would be
interpreted as a register.
This does not happen with normally compiled code, but it can happen
if the compiler (or beam_asm) is abused like in the following example:
make_bad() ->
Pid = self(),
Forms = [{attribute, 0, module, bad_s_operand},
{attribute, 0, export, [{test, 0}]},
{function, 0, test, 0,
[{clause, 0, [], [],
[{call,0,{atom,0,tuple_size},[{integer, 0, Pid}]}]}]}],
{ok, Module, Bin} = compile:forms(Forms, [no_copt,no_postopt,report_errors]),
code:load_binary(Module, "bad_s_operand.erl", Bin).
With this commit applied, the following message will be printed
when make_bad() is run:
=ERROR REPORT==== 10-Nov-2017::14:47:59 ===
Loading of bad_s_operand.erl failed: badfile
=ERROR REPORT==== 10-Nov-2017::14:47:59 ===
beam/beam_load.c(2396): Error loading function bad_s_operand:test/0: op bif1_body: bsd:
the term '<0.60.0>' would be confused with a register
|
|
* lukas/erts/misc_fixes:
erts: Fix a bunch of compiler warnings
kernel: Fix gen_tcp_misc indentation
erts: Fail port_SUITE:huge_env if error code > 127
erts: Add lcnt prototype for dist locks update
|
|
|
|
* sverker/on_load-nonblocking/OTP-14680:
erts: Remove scheduler blocking during finish_after_on_load_2
|
|
for normal case.
We still block for default trace and hipe.
|
|
On 64-bit machines where the C code is always at address below 4Gb,
pack one or more operands into the instruction word.
|
|
In the 'P' operator, don't assume that a packed target label ('f'
or 'j') is always the leftmost argument. Instead, transfer the
patch position from the accumulator to the stack.
|
|
The BeamOp() macro in erl_vm.h is clumsy to use. All users
cast the return value to BeamInstr.
Define new macros that are easier to use. In the future,
we might want to pack an operand into the same word as
the pointer to the instruction, so we will define two macros.
BeamIsOpCode() is used to rewrite code like this:
if (Instr == (BeamInstr) BeamOp(op_i_func_info_IaaI) {
...
}
to:
if (BeamIsOpCode(Instr, op_i_func_info_IaaI)) {
...
}
BeamOpCodeAddr(op_apply_bif) is used when we need the address
for an instruction.
Also elimiminate the global variables em_* in beam_emu.c.
They are not really needed. Use the BeamOpCodeAddr() macro
instead.
|
|
|
|
|
|
Pack sequences of trailing 'f' operands for instructions
such at jump_on_val or i_select_val_lins.
|
|
|
|
Relative failure in itself is not an optimization, but we plan to
pack failure labels in the future to save memory.
|
|
It has served its purpose.
|
|
Introduce new macros that can be used for relative jumps and
use them consistently.
Test that everything works by using a non-zero constant JUMP_OFFSET.
The loader subtracts JUMP_OFFSET from loaded labels, and all
instructions that use 'f' operands add it back.
|
|
De-duplicate bignums in the literal pool
|
|
Duplicate literals in the literal pool is a waste of memory.
Also, having unique literals can simplify some loader optimizations,
because we can known that if two literal indices are distinct, the
values must be distcint too.
|
|
Starting from R16B, floating point constants are stored
in the literal pool.
The backward compatibility support for the old representation
of floats has been kept long enough. Also, we might want to
ensure that all literals are unique in the future, and we certainly
don't want to update this code to ensure uniqueness.
|
|
The type 'd' could be used both for destination registers and
source register.
Restrict the 'd' type to only be used for destinations, and
introduce the new 'S' type to be used when a source must be
a register.
|
|
Update the pack engine to safely push literal operands to the pack
stack and to safely pop them back to another code address. That
will allow packing of more instructions.
|
|
As a preparation for potentially improving packing in the future,
we will need to make sure that packable types have a defined maximum
size.
The packer algorithm assumes that two 'I' operands can be packed
into one 64-bit word, but there are instructions that use an 'I'
operand to store a pointer. It only works because those instructions
are not packed for other reasons.
Introduce the 'W' type and use it for operands that don't fit in
32 bits.
|
|
The transformations were incorrect.
|
|
The instruction put_map_assoc/5 (used for updating a map) has a
failure operand, but it can't actually fail provided that its "map"
argument is a map.
The following code:
M#{key=>value}.
will be compiled to:
{test,is_map,{f,3},[{x,0}]}.
{line,[...]}.
{put_map_assoc,{f,0},{x,0},{x,0},1,{list,[{atom,key},{atom,value}]}}.
return.
{label,3}.
%% Code that produces a 'badmap' exception follows.
Because of the is_map instruction, {x,0} always contains a map when
the put_map_assoc instruction is executed. Therefore we can remove
the failure operand. That will save one word, and also eliminate
two tests at run-time.
The only problem is that the compiler in OTP 17 did not emit a
is_map instruction before the put_map_assoc instruction. Therefore,
we must add an instruction that tests for a map if the code was
compiled with the OTP 17 compiler.
Unfortunately, there is no safe and relatively easy way to known that
the OTP 17 compiler was used, so we will check whether a compiler
before OTP 20 was used. OTP 20 introduced a new chunk type for atoms,
which is trivial to check.
|
|
|
|
|
|
This refactor was done using the unifdef tool like this:
for file in $(find erts/ -name *.[ch]); do unifdef -t -f defile -o $file $file; done
where defile contained:
#define ERTS_SMP 1
#define USE_THREADS 1
#define DDLL_SMP 1
#define ERTS_HAVE_SMP_EMU 1
#define SMP 1
#define ERL_BITS_REENTRANT 1
#define ERTS_USE_ASYNC_READY_Q 1
#define FDBLOCK 1
#undef ERTS_POLL_NEED_ASYNC_INTERRUPT_SUPPORT
#define ERTS_POLL_ASYNC_INTERRUPT_SUPPORT 0
#define ERTS_POLL_USE_WAKEUP_PIPE 1
#define ERTS_POLL_USE_UPDATE_REQUESTS_QUEUE 1
#undef ERTS_HAVE_PLAIN_EMU
#undef ERTS_SIGNAL_STATE
|
|
Take advantage of the fact that small maps have a tuple for keys.
When new map is constructed and all keys are literals, we can construct
the entire keys tuple as a literal.
This should reduce the memory of maps created with literal keys almost by half,
since they all can share the same keys tuple.
|
|
* sverker/is_module_native-trace-bug/OTP-14390:
erts: Fix code:is_module_native for local trace
erts: Move and rename erts_is_native_break()
|
|
Local trace on first function in module
made code:is_module_native/1 return true.
Use new erts_is_function_native() to make a proper check.
|
|
|
|
|
|
to replace macro ERTS_INTERNAL_BINARY_FIELDS
as header in Binary and friends.
|
|
|
|
should be fixed since
32729cab75325de58bf127e6e8836348071b8682
|
|
into union with actual usage types.
|
|
to long lived, short lived and native stack.
|
|
A magic destructor can return 0 and thereby take control
and prolong the lifetime of a magic binary.
|