aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/beam_load.c
AgeCommit message (Collapse)Author
2011-09-28[erts] Fix memory leak in erts_make_stub_module (hipe loading)Sverker Eriksson
Code area allocation was done twice; first in read_code_header() and then in erts_make_stub_module() itself.
2011-08-03Fix binary construction with huge literal sizesBjörn Gustavsson
Constructing binaries using the bit syntax with literals sizes that would not fit in an Uint will either cause an emulator crash or the loading to be aborted. Use the new TAG_o tag introduced in the previous commit to make sure that the attempt to create huge binary literals will generate a system_limit exception at run-time.
2011-08-03beam_load.c: Add overflow check of tag valuesBjörn Gustavsson
The handling of large values for other tags than TAG_i (integer) is buggy. Any tag value equal to or greater than 2^40 (5 bytes) will abort loading. Tag values fitting in 5 bytes will be truncated to 4 bytes values. Those bugs cause real problems because the bs_init2/6 and bs_init_bits/6 instructions unfortunately use TAG_u to encode literal sizes (using TAG_i would have been a better choice, but it is too late to change that now). Any binary size that cannot fit in an Uint should cause a system_limit exception at run-time, but instead the buggy handling will either cause an emulator crash (for values in the range 2^32 to 2^40-1) or abort loading. In this commit, implement overflow checking of tag values as a preparation for fixing the binary construction instructions. If any tag value cannot fit in an Uint (except for TAG_i), change the tag to the special TAG_o overflow tag.
2011-04-07Merge branch 'ta/erts-unused-vars' into devHenrik Nord
* ta/erts-unused-vars: erts: Remove unused variables OTP-9205
2011-03-29BEAM loader: Simplify handling of the func_info/3 instructionBjörn Gustavsson
For some historical reason, the transformation of a func_info/3 instruction to the internal i_func_info/4 instruction is more involved than it needs to be. Remove the gen_func_info() function in the loader and use a simple transformation.
2011-03-16erts: Remove unused variablesTuncer Ayaz
2011-02-23BEAM loader: Add an assertion to check for overflowed code spaceBjörn Gustavsson
While at it, clean up indentation of CHKBLK() macros.
2011-02-14Eliminate memory leak in code:make_stub/1Björn Gustavsson
2011-01-17Optimize addition of a small integer to a variableBjörn Gustavsson
Introduce a new i_increment/4 to optimize the addition of a register and a small integer. This instruction saves two instruction words compared to the standard instructions (an i_fetch/2 instruction followed by a i_plus/3 instruction) and will also be slightly faster.
2011-01-17Introduce a special instruction for select_val with two valuesBjörn Gustavsson
The new instruction will save one word (because no size operand is needed), and is slightly faster. Handle select_tuple_arity in the same way.
2011-01-17Eliminate use of GetArg2() in the i_element instructionBjörn Gustavsson
Use separate instructions for each register type.
2011-01-17Eliminate use of GetArg1() in the fast_element instructionBjörn Gustavsson
Use separate instructions for each register type.
2011-01-17Eliminate use of GetArg1() in the select_val instructionBjörn Gustavsson
Instead of having one i_select_val_sfI instruction that uses the GetArg1() macro to fetch the controlling expression, use three separate instructions for each of the register types. That will save one word when selecting on the {x,0} register. It should also be slightly faster since a conditional branch is eliminated. Although it seems that the BEAM compiler will never generate a constant controlling expression (even with optimizations turned off), we still make sure that they will work by evaluating the select_val instruction at load time. Handle the select_tuple_arity instruction in the same way.
2011-01-17Simplify a select_val instruction that selects only one valueBjörn Gustavsson
The compiler does not generate select_val instructions that only selects one value, but the loader may previously have created such an instruction when it splitted a select_val instruction that selected on bignums.
2011-01-17Optimize creation of tuplesBjörn Gustavsson
Combine the put_tuple/2 and all following put/1 instructions to one i_put_tuple/2 instruction. In general, that will reduce the number of instruction words by 50 percent. Measurements seem to indicate that the speed is about the same.
2011-01-17beam_load: Run the packing engine before loading list argumentsBjörn Gustavsson
2011-01-17Support packing of the 'I' type in a 64-bit emulatorBjörn Gustavsson
In many (not all) cases, the value for the 'I' type will fit into 32 bits.
2011-01-17Eliminate redundant jump instructionsBjörn Gustavsson
2011-01-17Eliminate the special instructions for selecting floats and bignumsBjörn Gustavsson
2011-01-17BEAM loader: Pack more instructions using a new 'Q' typeBjörn Gustavsson
Introduce a new 'Q' type, similar to 'P' except that it can be packed.
2011-01-17If the wordsize is 64 bits, pack up to 4 operands into a wordBjörn Gustavsson
In the 32-bit BEAM emulator, it is only possible to pack 3 register operands into one word. Therefore, the move2 instruction (that has 4 operands) needs two words for its operands. Take advantage of the larger wordsize in the 64-bit emulator and pack up to 4 operands into a single word.
2011-01-17BEAM loader: Combine is_type/1 and is_eq/1 instructionsBjörn Gustavsson
In the transformation engine in the loader, an is_eq/1 instruction is currently always preceded by an is_type/1 instruction. Therefore, save a word and slight amount of time by combining those instructions into an is_type_eq/2 instruction.
2011-01-17BEAM loader: Fix bug in handling of "rest" argumentsBjörn Gustavsson
It would only really work in simple case like: select_val S=q Fail=f Size=u Rest=* => ... where all operands for a single instruction where bound to variables, and not for more complicated cases such as: i_put_tuple Dst Arity Puts=* | put PutSrc => ...
2011-01-17Remove the last vestiges of the allocating fmove/2 instructionBjörn Gustavsson
There was a version of the BEAM loader and emulator that had two versions of the fmove/2 instruction, one version that allocated heap space internally and a newer version that assumed that a previous test_heap/2 instruction had already allocated the heap space. Though the allocating fmove/2 instruction is no longer supported, some vestiges of it still remains.
2010-09-01Merge branch 'pg/fix-segfault-on-crash_dump-with-hipe' into devBjörn Gustavsson
* pg/fix-segfault-on-crash_dump-with-hipe: Fix segmentation fault when dumping the crash log with hipe enabled and natively compiled modules OTP-8801
2010-08-27Fix segmentation fault when dumping the crash log with hipe enabled and ↵Paul Guyot
natively compiled modules When loading a module, code area is allocated and header fields code[MI_ATTR_SIZE] as well as code[MI_COMPILE_SIZE] are not cleared. They are only set later when freeze_code is called, if the module has attributes and compilation info, which should always be the case. When loading a native module (as a stub), code is allocated as well (to contain the stub functions), and code[MI_ATTR_SIZE] as well as code[MI_COMPILE_SIZE] are not cleared either. Yet, freeze_code will not be called (since there is no threaded code to freeze for native modules), and as a result, these header fields are never set. They can contain any garbage. Later on, when writing a crash dump, the attributes and compilation info are dumped, using these particular header fields. If the size is garbage, the dump attribute function will iterate until it segfaults. The fix consists in clearing code[MI_ATTR_SIZE] and code[MI_COMPILE_SIZE] in both cases (threaded code and native code). Even if non-native modules should contain code and attributes and therefore the values code[MI_ATTR_SIZE] and code[MI_COMPILE_SIZE] should be set by freeze_code, it seems cleaner and easier to maintain to clear the whole the header in the "initialize code area" section. As a result, crash dump will not segfault. Instead, native modules will have an empty attributes and compilation info section in the crash dump.
2010-08-19Remove binary overhead counter from ets objectsPatrik Nyblom
As the overhead counter got larger and never really was needed in ets objects, I removed them. A few stray comments of XXX:PaN type from halfword dev removed in the process.
2010-05-20Remove stray support for the put_literal/2 instructionBjörn Gustavsson
put_literal/2 was an experimental instruction added in R11 to support literals, but before the R12 release support for literals was implemented for all instruction, making the put_literal/2 instruction redundant. Although the beam_disasm module supports dissambley of instructions in older releases, there is no reason to have it support experimental instructions.
2010-05-17Add guard BIFs binary_part/2,3Patrik Nyblom
Add the gc_bif's to the VM. Add infrastructure for gc_bif's (guard bifs that can gc) with two and. three arguments in VM (loader and VM). Add compiler support for gc_bif with three arguments. Add compiler (and interpreter) support for new guard BIFs. Add testcases for new guard BIFs in compiler and emulator.
2010-03-22erts: Don't support the put_string/3 instructionBjörn Gustavsson
Since R14 does not need to load code that can also be loaded in an R11 run-time system, support for the put_string/3 instruction can be removed.
2010-03-22Merge branch 'pan/otp_8332_halfword' into devErlang/OTP
* pan/otp_8332_halfword: Teach testcase in driver_suite the new prototype for driver_async wx: Correct usage of driver callbacks from wx thread Adopt the new (R13B04) Nif functionality to the halfword codebase Support monitoring and demonitoring from driver threads Fix further test-suite problems Correct the VM to work for more test suites Teach {wordsize,internal|external} to system_info/1 Make tracing and distribution work Turn on instruction packing in the loader and virtual machine Add the BeamInstr data type for loaded BEAM code Fix the BEAM dissambler for the half-word emulator Store pointers to heap data in 32-bit words Add a custom mmap wrapper to force heaps into the lower address range Fit all heap data into the 32-bit address range
2010-03-10Fix further test-suite problemsPatrik Nyblom
Fix safe_mul in the loader, which caused failures in the bit syntax test cases. Fix yet another Uint in erl_alloc.h (ERTS_CACHE_LINE_SIZE) causing segmentation fault when we have many schedulers (why only in that situation?). Clean up erl_mseg (remove old code for the Linux 32-bit mmap flag). While at it, also remove compilation warnings.
2010-03-10Turn on instruction packing in the loader and virtual machinePatrik Nyblom
2010-03-10Add the BeamInstr data type for loaded BEAM codePatrik Nyblom
For cleanliness, use BeamInstr instead of the UWord data type to any machine-sized words that are used for BEAM instructions. Only use UWord for untyped words in general.
2010-03-10Store pointers to heap data in 32-bit wordsPatrik Nyblom
Store Erlang terms in 32-bit entities on the heap, expanding the pointers to 64-bit when needed. This works because all terms are stored on addresses in the 32-bit address range (the 32 most significant bits of pointers to term data are always 0). Introduce a new datatype called UWord (along with its companion SWord), which is an integer having the exact same size as the machine word (a void *), but might be larger than Eterm/Uint. Store code as machine words, as the instructions are pointers to executable code which might reside outside the 32-bit address range. Continuation pointers are stored on the 32-bit stack and hence must point to addresses in the low range, which means that loaded beam code much be placed in the low 32-bit address range (but, as said earlier, the instructions themselves are full words). No Erlang term data can be stored on C stacks (enforced by an earlier commit). This version gives a prompt, but test cases still fail (and dump core). The loader (and emulator loop) has instruction packing disabled. The main issues has been in rewriting loader and actual virtual machine. Subsystems (like distribution) does not work yet.
2009-11-29Fix glitches when native code modules are usedBjörn Gustavsson
The erlang:make_stub_module/3 BIF (which is only used for loading native code) does not zero the word that points out an on_load routine (if any). As that word most proably will contain a non-zero value, the erlang:module_loaded/1 BIF will think that the module has an on_load routine which has not returned and will always return 'false'. That in turns causes various problems for the native code test cases.
2009-11-20The R13B03 release.OTP_R13B03Erlang/OTP