aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/beam_load.c
AgeCommit message (Collapse)Author
2011-12-07BEAM loader: Fix bug that allowed loading of more than two versionsBjörn Gustavsson
In commit b67d3e5447f4b2bca3ed92f3db84adb3f79f9b16 (which cleaned up handling of error reasons), the test of the return value from beam_make_current_old() in insert_new_code() was not updated, which meant that it never was true and any number of versions of code could be loaded for a module.
2011-12-02Iron out bugs in Win64 found in daily buildsPatrik Nyblom
Almost all uses of the 'long' datatype is removed from VM and tests Emulator test now runs w/o drivers crashing Nasty abs bug fixed in VM as well as type errors in allocator debug functions Still one allocator test that fails, domain knowledge is needed to fix that. Fix type inconsistency in beam_load causing crashes
2011-11-26beam_load.c: Add init_iff_file() for verifying the IFF headerBjörn Gustavsson
Add init_iff_file() for verifying the IFF header. Also let it handle compressed BEAM files so that it will be done in one place. That means that code:get_chunk/2 and code:module_md5/1 will now support compressed BEAM files.
2011-11-26beam_code.c: Don't reinvent state initialization and deallocationBjörn Gustavsson
2011-11-26beam_load.c: Optimize code:get_chunk/2Björn Gustavsson
The undocumented code:get_chunk/2 BIF is supposed to be a fast way to extract a chunk from a BEAM file when loading native code. In practice, it might not have been faster because it happened to calculate an MD5 checksum for the chunk it extracted because it shared the scan_iff_file() function with the erlang:load_module/2 BIF. Split scan_iff_file() into scan_iff_file() and verify_chunks(), so that the unnecessary MD5 calculation can be avoided.
2011-11-26beam_load.c: Eliminate memory leak in code:make_stub_module/3Björn Gustavsson
code:make_stub_module/3 leaked memory if given either a corrupt BEAM file, or a compressed BEAM file and an error occurred, or a binary not aligned on byte boundaries.
2011-11-18Merge branch 'pan/binary_match_scope/OTP-9701'Patrik Nyblom
* pan/binary_match_scope/OTP-9701: Remove remaining gcc 4.6 assigned-but-not-used warnings from erts Remove GCC 4.6 set-but-not-used warning from erl_bif_binary Make binary:match with scope return correct values
2011-11-17external.c: Remove the option to create over-sized heap binariesBjörn Gustavsson
Since refc binaries are now supported in literal pools, there is no longer any need to allow the creation of over-sized heap binaries.
2011-11-17Allow refc binaries in literal poolsBjörn Gustavsson
To simplify the implementation of literal pools (constant pools) for the R12 release, a shortcut was taken regarding binaries -- all binaries would be stored as heap binaries regardless of size. To allow a module containing literals to be unloaded, literal terms are copied when sent to another process. That means that huge literal binaries will also be copied if they are sent to another process, which could be surprising. Another problem is that the arity field in the header for the heap object may not be wide enough to handle big binaries. Therefore, bite the bullet and allow refc binaries to be stored in literal pools. In short, the following need to be changed: * Each loaded module needs a MSO list, linking all refc binaries in the literal pool. * When check_process_code/2 copies literals to a process heap, it must link each referenced binary into the MSO list for the process and increment the reference counter for the binary. * purge_module/1 must decrement the reference counter for each refc binary in the literal pool.
2011-11-16Remove remaining gcc 4.6 assigned-but-not-used warnings from ertsPatrik Nyblom
2011-11-14BEAM loader: Refactor code loading into separate functionsBjörn Gustavsson
Break apart code loading into the three functions: erts_alloc_loader_state() erts_prepare_loading() erts_finish_loading() The erts_alloc_loader_state() and erts_prepare_loading() can be executed with all schedulers running. Only erts_finish_loading() needs to be run in a single-scheduling system.
2011-11-14beam_load.c: Factor out cleaning up of the loader state into free_state()Björn Gustavsson
2011-11-14BEAM loader: Clean up handling of error reasonsBjörn Gustavsson
There is no reason to have erts_load_module() return integer values, only to have the caller convert the values to atoms. Return the appropriate atom directly from the place where the error is generated instead. Return NIL if the module was successfully loaded.
2011-11-14beam_load.c: Simplify handling of the bs_put_string_II instructionBjörn Gustavsson
Remove the special-case handling of the bs_put_string_II instruction; simply use the string patch mechanism that is already used for the i_bs_match_string_* instructions.
2011-11-14beam_load.c: Remove the unused struct LoadedCodeBjörn Gustavsson
2011-11-09Merge branch 'sverk/bif-args/OTP-9662'Sverker Eriksson
* sverk/bif-args/OTP-9662: erts,hipe: Limited support for hipe cross compilation erts-hipe: Change THE_NON_VALUE for HiPE enabled debug emulator erts-hipe: Enable debug compiled hipe-VM with lock checker erts-hipe: Rename fail_bif_interface_0 to standard_bif_interface_0 erts-hipe: Deliberate leak of native fun entries erts-hipe: Fix new trap conventions for x86, amd64 and ppc Store the trap address in p->i Store the trap arguments in the X register array erts-hipe: Make some primops use new BIF calling convention erts-hipe: Adapt generated BIF wrappers for new calling convention erts-hipe: Remove obscuring macros in generated assembler code erts-hipe: Make hipe enabled emulator compile with new BIF calls Simplify the instructions for calling BIFs Change the calling convention for BIFs Use the proper macros in all BIFs Conflicts: erts/emulator/beam/bif.h erts/emulator/beam/erl_bif_info.c
2011-11-02beam_loader: Support external funs in the literal poolBjörn Gustavsson
A future release of the compiler might want to treat external funs as literals. Make sure that the loader can cope with an export entry being created from both an entry in the literal pool and from the export table (i.e. if an external fun refers to an exported function in the same module).
2011-11-02beam_load.c: Clarify error message when loading unsupported BEAM filesBjörn Gustavsson
Make it clear for the user what has happened and how to fix it when an attempt is made to load a BEAM file containing new instructions that the current run-time system cannot handle. Suggested-by: Thomas Lindgren
2011-10-26erts-hipe: Deliberate leak of native fun entriesSverker Eriksson
This is a workaround as hipe code upgrade/unloading does not work properly.
2011-10-26Use the proper macros in all BIFsBjörn Gustavsson
As a preparation for changing the calling convention for BIFs, make sure that all BIFs use the macros. Also, eliminate all calls from one BIF to another, since that also breaks the calling convention abstraction.
2011-10-11Simplify transformations of gc_bif[123] instructionsBjörn Gustavsson
Each gc_bif[123] instruction must have both a transformation in ops.tab and special code in gen_guard_bif[123](). Rewrite it to do most of the work in gen_guard_bif[123]().
2011-10-11Refactor 'too_old_compiler' handlingBjörn Gustavsson
In the handling of generic instructions, we used to always test whether the instruction was 'too_old_compiler' and abort loading with a special error message. Refactor the code so that we only do test if we an error has occurred. That will allow us to make the test more expensive in the future, allowing us to customize error messages for certain opcode without any cost in the successful case.
2011-10-11Introduce 'try_me_else_fail'Björn Gustavsson
2011-10-11Combine 'store_var' with 'next_arg'Björn Gustavsson
'store_var' is always followed by 'next_arg'.
2011-10-11Merge 'next_instr' and 'is_op' into 'next_instr'Björn Gustavsson
'next_instr' is always followed by 'is_op'.
2011-10-11Merge 'new_instr' and 'store_op' into 'new_instr'Björn Gustavsson
Since the 'new_instr' instruction always occurs before the 'store_op' instruction, we can merge the instructions into one. Also, there is no need to include the arity of the BEAM instruction as an operand, since the arity can be looked up based on the opcode.
2011-10-11Combine a 'call' instruction with the following 'end' instructionBjörn Gustavsson
A 'call' instruction in the loader transformation language is always followed by an 'end' instruction, so we can replace the 'call' instruction with a 'call_end' instruction.
2011-10-11Get rid of redundant 'try_me_else' and 'fail' instructionsBjörn Gustavsson
If the left part of a transformation will always match, omit the the 'try_me_else' and 'fail' instructions. As part of this optimization, make it an error to have a transformation that can never be reached because of a previous transformation that will always match. (Remove one transformation from ops.tab that was found to be unreachable.)
2011-09-29Merge branch 'dev' into majorLukas Larsson
* dev: Prevent valgrind warning for erts_alloc_permanent_cache_aligned [erts] Fix memory leak in erts_make_stub_module (hipe loading)
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-18erl: Add +L to suppress loading of line number informationBjörn Gustavsson
2011-08-16Lookup and include filenames and line numbers in exceptionsBjörn Gustavsson
2011-08-16Refactor building of the exception stacktraceBjörn Gustavsson
As a preparation for providing information about the source location for an MFA item in an exception stacktrace, refactor the code that builds the exception stacktrace. Basically we need two passes over the saved continuation counters: a first pass to calculate the needed heap space and a second pass to actually build the stacktrace.
2011-08-16BEAM loader: Load the line tableBjörn Gustavsson
2011-08-16compiler, emulator: Introduce the line/1 instructionBjörn Gustavsson
Introduce the line/1 instruction in the compiler and the BEAM virtual machine. It will not yet be generated by the compiler and will not actually carry any information.
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