aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/beam_emu.c
AgeCommit message (Collapse)Author
2011-04-11Fix thread unsafe accessRickard Green
Fix thread unsafe access to process status field introduced in OTP-9125.
2011-04-11Only set status P_WAITING when neededRickard Green
The status of a process was unnecessarily set to waiting before the process was enqueued in a run queue. This bug was harmless up until OTP-R14B01. In OTP-R14B02 erlang:hibernate/3 was fixed (OTP-9125). After the introduction of OTP-9125, the previously harmless process status bug sometimes caused erroneous badarg exceptions from process_info().
2011-03-29Fix duplicate entries in stacktraces after calling certain BIFsBjörn Gustavsson
Calling a BIF thaf is called as a function (such as process_info/{1,2}) would leave a non-zero value in c_p->cp, which would lead to duplicate entries in the stacktrace.
2011-03-10Merge branch 'pg/fix-hibernate-with-hipe' into devSverker Eriksson
* pg/fix-hibernate-with-hipe: Update copyright years Fix NULL-free bug in hibernate on debug emulator Fix several bugs related to hibernate/3 and HiPE Conflicts: erts/emulator/test/hibernate_SUITE.erl OTP-9125
2011-03-04erts: Initialize register that may be referenced by garbage collectionBjörn Gustavsson
The call_fun() function in the BEAM emulator is supposed to to put the fun term in the x register following the actual arguments and environment for the fun. But if the fun is not loaded and a call to the error_handler:undefined_lambda/3 function is set up, the x(3) register will not be initialized. The lack of initialization is very unlikely to cause a problem in practice, because all of the following things must happen: 1) An unloaded fun must be called (i.e. the fun must have been received from another node or from a file or dets table). 2) The process must be scheduled out before the call to the error_handler:undefined_lambda/3 function can take place. 3) The process must be garbage collected before the process is scheduled in. 4) The x(3) register must contain a stale cons or box pointer that happens to point into the the heap of the currently executing process. (Because of the literal pool, the GC will never copy anything that is outside of the heap.) I was not able to write a test case that would force an emulator crash.
2011-03-02Merge branch 'pan/halfword-tmp-heap-fixes/OTP-8332' into devPatrik Nyblom
* pan/halfword-tmp-heap-fixes/OTP-8332: Fix assymetric (Un)UseTmpHeap in erl_process.c Conflicts: erts/emulator/beam/beam_emu.c
2011-02-25Merge branch 'rickard/temp_alloc_check/OTP-9028' into devRickard Green
* rickard/temp_alloc_check/OTP-9028: Verify that temp allocated memory is released
2011-02-23beam_emu: Eliminate redundant #ifdefBjörn Gustavsson
The halfword emulator used to require special handling, but no longer does.
2011-02-23beam_emu: Remove unnecessary decrement of I in "case_end r"Björn Gustavsson
It is not necessary to decrement I, because an exception is about to be generated. Furthermore, I pointing *before* the instruction that caused the exception may cause problems in the future.
2011-02-10Verify that temp allocated memory is releasedRickard Green
2011-01-29Fix several bugs related to hibernate/3 and HiPEPaul Guyot
This commit fixes four related bugs: - calling hibernate/3 using a dynamic call would fail with badarg as hibernate/3 as a BIF was not implemented. hibernate/3 is generally provided as a Beam instruction, and code is translated to use this instruction when loaded. - calling hibernate/3 from HiPE would fail with badarg because this would call the aforementioned BIF which was not implemented. - calling hibernate/3 with some HiPE-native garbage in the process heap would randomly crash at the next garbage collect. This bug only happened in a complex, yet reproduceable scenarios, where native code calls beam code that calls hibernate/3, and the process has some garbage when being hibernated and the process generates garbage when awaken. - when entering HiPE, the process current_function can be set and be inaccurate. The fix is three folded: - hibernate_3 BIF now actually works instead of throwing a badarg. While hibernate_3 BIF was (usually) not called from BEAM, it is called from HiPE. hibernate behaviour is very close to the scheduler and this is why it is implemented as an instruction in BEAM. The fix consists in doing the actual hibernation (through the now exported erts_hibernate function) and setting the process flag to TRAP as well as the process status to P_WAITING. On BIF epilogue in both BEAM and HiPE, this status is tested on TRAP and if set, the scheduler is invoked. The i_hibernate instruction and translation code is now redundant and could be deleted. - hibernation now also empties the HiPE native stack, with a new function hipe_empty_nstack provided by Mikael Pettersson. - when entering HiPE through hipe_mode_switch, p->current is cleared, as suggested by Mikael Pettersson. p->current normally hold a pointer to the {M,F,A} of the current function if it exists. When hibernating, it is set to {erlang,hibernate,3}, and all stdlib hibernate tests (gen_server_SUITE:hibernate/1, proc_lib_suite:hibernate/1, etc.) actually rely on this information. Clearing p->current fixes the tests and avoids the surprise one might have when querying the process info of a process that hibernated and woke up in a native function. Non-regression tests are provided, a test for the dynamic call as well as a Makefile-handled duplication of the hibernate_SUITE into hibernate_native_SUITE for the HiPE case.
2011-01-17Introduce a few more variations of the move instructionsBjörn Gustavsson
Frequency counts show that move Const x(1) move Const x(2) are very common.
2011-01-17Combine a move + jump sequence into the move_jump instructionBjörn Gustavsson
That will save one word and small amount of time for each occurrence.
2011-01-17Optimize and clean-up the exact equality/non-equality instructionsBjörn Gustavsson
The is_eq_exact/3 and is_ne_exact/3 instructions are commonly used with one immediate or literal operand. Introduce three new specialized instructions: i_is_eq_exact_literal/3 i_is_ne_exact_immed/3 i_is_ne_exact_literal/3 The i_is_ne_exact_literal/3 instruction is not very frequently used, but its existence is justified because we removed in a a previous commit the special instruction for matching bignums and we now use i_is_ne_exact_literal/3 instead. For consistency, rename the existing is_eq_immed/3 instruction to is_eq_exact_immed/3. While at it, remove the optimization of an is_eq/3 instruction with an immediate operand because that optimization is already done by the compiler.
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 GetArg1() in the badmatch and case_end instructionsBjörn Gustavsson
Create separate instructions for each register type. The "badmatch x(0)" and "case_end x(0)" (which are very common) will only require a single word each, compared to two words when GetArg1() is used.
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 jump_on_val* instructionsBjörn Gustavsson
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-17beam_emu: Eliminate sloppy use of tmp_arg1 and tmp_arg2Björn Gustavsson
The tmp_arg1 and tmp_arg2 variables are intended for transferring values from the fetch/2 instructions to instructions such as i_plus/3. In many places, however, tmp_arg1 and tmp_arg2 are used as general temporary variables within a single instruction. Improve the code generation by replacing sloppy use of tmp_arg1 and tmp_arg2 with block-local variables. In most cases, that will allow the temporary values to be kept in registers.
2011-01-17beam_emu: Don't inline helper functions into process_main()Björn Gustavsson
By default, GCC will inline calls to helper functions. Since process_main() is already huge, there is no reason to inline the helper functions (and some of them are used very seldom).
2011-01-17beam_emu: Clean up calling of the error_handler moduleBjörn Gustavsson
There were two separate functions (call_error_handler() and call_breakpoint_handler()) that were identical except for the name of the function in the error_handler module being called. Generalize call_error_handler() by adding a function name argument so that it can be used for both purposes. Also let the call_error_handler() return the new program counter instead of passing it in c_p->i. That slightly decrease the code size at the call site. There is also no need to use the Dispatch() macro to yet again decrease the reduction counter, because that has just been done by the call instruction that caused the execution of the call_error_handler or i_debug_breakpoint instruction.
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-17Allow packing of some more instructionsBjö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 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-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.
2011-01-13Fix assymetric (Un)UseTmpHeap in erl_process.cPatrik Nyblom
Also added ASSERTion in beam_emu.c that the tmp-heap-counter in 0.
2010-08-30Merge branch 'pan/ets_binary_overhead/OTP-8762' into devPatrik Nyblom
* pan/ets_binary_overhead/OTP-8762: Remove binary overhead counter from ets objects
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-08-12Increase vheap counter to Uint64Björn-Egil Dahlberg
This will reduce the risk of integer wrapping in bin vheap counting. The vheap size series will now use the golden ratio instead of doubling and fibonacci sequences. OTP #8730
2010-07-22Mending halfword heap emulatorSverker Eriksson
2010-07-20One off-heap list, to eliminate two words per ETS object.Sverker Eriksson
Merging the three off-heap lists (binaries, funs and externals) into one list. This reduces memory consumption by two words (pointers) per ETS object.
2010-06-03Teach call time trace patterns to include bifsBjörn-Egil Dahlberg
2010-06-03Teach call count tracing to use atomicsBjörn-Egil Dahlberg
Call count previously used a global lock for accessing and writing its counter in the breakpoint. This is now changed to atomics instead. The change will let call count tracing and cprof to scale better when increasing the number of schedulers.
2010-06-03Add a scheduler array for BpData at BeamInstr[-4]Björn-Egil Dahlberg
To solve the issue of multiple schedulers constantly updating the head pointer to the bp data wheel, each scheduler now has its own entrypoint to the wheel. This head pointer can be updated without a locking being taken. Previously there were no lock ...
2010-06-03Fix BeamInstr for call_timeBjörn-Egil Dahlberg
2010-06-03Teach call_time trace to use intruction pointersBjörn-Egil Dahlberg
call_time trace will use instruction pointers instead of breakpoint data pointers. More costly lookup but the bdt structure might be deallocated, we do not want that. Remove unnecessary pattern lock.
2010-06-03Add return_time trace and PSD deletionsBjörn-Egil Dahlberg
2010-06-03Call time breakpoint tracing frameworkBjörn-Egil Dahlberg
Initial commit with a new breakpoint instruction and PSD areas for temporary time storage during tracing.
2010-05-20Remove the bs_bits_to_bytes/3 instructionBjörn Gustavsson
The last compiler to generate code that uses the bs_bits_to_bytes/3 instruction was the R11 compiler. Since we don't support loading R11 *.beam files in R14, removing the remaining support for the instruction.
2010-05-20erts: Stop supporting non-literal empty tuplesBjörn Gustavsson
Since R12B, empty tuples are literals. Thus the compiler will no longer generate the instruction: put_tuple 0 Destination for creating an empty tuple. It is now time to stop supporting that instruction in the run-time system. While we are at it, correct a typo.
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-05-11erts: Implement recv_mark/1 and recv_set/1 for realBjörn Gustavsson
The recv_mark/1 instruction will both save the current position in the message queue and a mark (the address of the loop_rec/2 instruction just following the recv_set/1 instruction). The recv_mark/1 instruction will only use the saved position if the mark is correct. The reason for saving and verifying the mark is that the compiler does not need to guarantee that no other receive instruction can be executed in between the recv_mark/1 and recv_set/1 instructions (the mark will be cleared by the remove_message/0 instruction when a message is removed from the message queue). That means that arbitrary function calls in between those instruction can be allowed.
2010-04-30emulator: Remove stray OSE/Delta supportBjörn Gustavsson
2010-04-28OTP-8474 NIF improvements after R13B04Sverker Eriksson
New NIF API function enif_make_new_binary
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.