aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/beam_load.c
AgeCommit message (Collapse)Author
2018-04-04Merge pull request #1725 from michalmuskala/fun-literalsBjörn Gustavsson
Compile external fun expressions to literals OTP-15003
2018-03-26Compile external fun expressions to literalsMichał Muskała
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.
2018-03-21Add an option to ?MODULE:module_info/1 for listing NIFsJohn Högberg
2018-03-14erts: Fix faulty sys_memcpy of 0 bytesSverker Eriksson
2018-03-09Always use sys_memcpy/cmp/etc instead of plain memcpy/cmp/etcJohn Högberg
2018-01-24Merge branch 'maint'Sverker Eriksson
2018-01-24Merge branch 'sverker/hipe-load-fixing/OTP-14891' into maintSverker Eriksson
2018-01-17Fix slow hipe executionSverker Eriksson
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.
2018-01-11Merge branch 'maint'Rickard Green
* maint: Fix encoding of filenames in stacktraces
2018-01-11Fix encoding of filenames in stacktracesRickard Green
2017-11-27erts: Fix bad merge of PR #1644Björn Gustavsson
2017-11-27Merge branch 'maint'John Högberg
2017-11-24Fix purging of modules with "fake literals"Björn Gustavsson
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
2017-11-13Refuse to load "literals" that can be confused with registersBjörn Gustavsson
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
2017-10-30Merge branch 'lukas/erts/misc_fixes'Lukas Larsson
* 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
2017-10-30erts: Fix a bunch of compiler warningsLukas Larsson
2017-10-17Merge branch 'sverker/on_load-nonblocking/OTP-14680'Sverker Eriksson
* sverker/on_load-nonblocking/OTP-14680: erts: Remove scheduler blocking during finish_after_on_load_2
2017-10-12erts: Remove scheduler blocking during finish_after_on_load_2Sverker Eriksson
for normal case. We still block for default trace and hipe.
2017-10-05Pack operands into the instruction wordBjörn Gustavsson
On 64-bit machines where the C code is always at address below 4Gb, pack one or more operands into the instruction word.
2017-10-01beam_load.c: Generalize the 'P' operator in the packing engineBjörn Gustavsson
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.
2017-10-01Refactor macros for accessing Beam instructionsBjörn Gustavsson
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.
2017-09-14Pack failure labels in i_select_val2 and i_select_tuple_arity2Björn Gustavsson
2017-09-14Rewrite select_val_bins so that its labels can be packedBjörn Gustavsson
2017-09-14Pack sequences of trailing 'f' operandsBjörn Gustavsson
Pack sequences of trailing 'f' operands for instructions such at jump_on_val or i_select_val_lins.
2017-09-14Implement packing of 'f' and 'j'Björn Gustavsson
2017-09-14Use relative failure labelsBjörn Gustavsson
Relative failure in itself is not an optimization, but we plan to pack failure labels in the future to save memory.
2017-09-14Remove JUMP_OFFSETBjörn Gustavsson
It has served its purpose.
2017-09-13Refactor instructions to support relative jumpsBjörn Gustavsson
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.
2017-09-01Merge pull request #1550 from bjorng/bjorn/erts/unique-literalsBjörn Gustavsson
De-duplicate bignums in the literal pool
2017-08-29De-duplicate bignums in the literal poolBjörn Gustavsson
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.
2017-08-28Remove backward compatibility support for float literalsBjörn Gustavsson
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.
2017-08-23Add the 'S' type for a register sourceBjörn Gustavsson
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.
2017-08-23Pack instructions using 'q', 'c', and 's'Björn Gustavsson
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.
2017-08-23beam_makeops: Introduce the new type 'W' (machine word)Björn Gustavsson
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.
2017-08-23Use the wait_timeout_{un}locked_int instructionsBjörn Gustavsson
The transformations were incorrect.
2017-08-15Slightly optimize updating of mapsBjörn Gustavsson
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.
2017-08-11Break out most instructions from beam_emu.cBjörn Gustavsson
2017-07-17erts: Replace usage of all erts_smp prefixes to just ertsLukas Larsson
2017-07-17erts: Remove ERTS_SMP and USE_THREAD definesLukas Larsson
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
2017-07-06Introduce new_small_map_lit opMichal Muskala
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.
2017-05-08Merge branch 'sverker/is_module_native-trace-bug/OTP-14390'Sverker Eriksson
* 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()
2017-05-04erts: Fix code:is_module_native for local traceSverker Eriksson
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.
2017-05-04erts: Move and rename erts_is_native_break()Sverker Eriksson
2017-05-04Update copyright yearRaimo Niskanen
2017-04-12erts: Introduce struct binary_internalsSverker Eriksson
to replace macro ERTS_INTERNAL_BINARY_FIELDS as header in Binary and friends.
2017-04-11erts: Introduce erts_bin_releaseSverker Eriksson
2017-04-05erts: Remove deliberate leak of hipe fun entriesSverker Eriksson
should be fixed since 32729cab75325de58bf127e6e8836348071b8682
2017-04-04erts: Refactor ErtsCodeInfo.nativeSverker Eriksson
into union with actual usage types.
2017-03-17erts: Change HIPE allocations from sys_allocSverker Eriksson
to long lived, short lived and native stack.
2017-02-14erts: Add deallocation veto for magic destructorsSverker Eriksson
A magic destructor can return 0 and thereby take control and prolong the lifetime of a magic binary.