aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/src/code.erl
AgeCommit message (Collapse)Author
2018-03-07Short-circuit code:ensure_loaded for already-loaded modulesMichał Muskała
This checks if the module is already loaded using erlang:module_loaded before calling the code server. This should improve performance of the call significantly since the case where module is already loaded is the common one. The change shouldn't cause any problems. It's worth noting that code:ensure_modules_loaded already does a similar check.
2017-05-04Update copyright yearRaimo Niskanen
2017-02-06Use magic refs for code loading stateRickard Green
2016-11-25Add code:module_status/1 and modified_modules/0Richard Carlsson
These functions use the MD5 beam/native checksum to determine whether the code for a module has changed on disk and is a candidate for loading.
2016-11-22Handle prefetched pathsRichard Carlsson
2016-11-22Restructure code:which() and where_is_file()Richard Carlsson
2016-11-21Remove remnants of module package supportRichard Carlsson
2016-10-17kernel,hipe: Fix dialyzer warningsSverker Eriksson
2016-04-13Merge branch 'henrik/update-copyrightyear'Henrik Nord
* henrik/update-copyrightyear: update copyright-year
2016-03-31code: Remove 'bad_path' error code from set_path/1Björn Gustavsson
code:set_path/1 no longer returns {error,bad_path} (an exception will be thrown instead).
2016-03-15update copyright-yearHenrik Nord
2016-02-25code: Add functions that can load multiple modulesBjörn Gustavsson
Add functions to 'code' to allow loading of multiple modules at once. code:atomic_load(Modules) will load all modules at once, or fail having loaded none of them. Since we cannot guarantee the atomicity if there are modules with -on_load functions, the list of modules must not contain any modules with an -on_load function. Also, to make it possible to put an application into an inactive state for as short time as possible, also add code:prepare_loading/1 and code:finish_loading/1. They are used like this: {ok,Prepared} = code:prepare_loading(Modules) . . . ok = code:finish_loading(Prepared) code:ensure_modules_loaded/1 is useful as a pure optimization to ensure that modules that will be needed soon have indeed been loaded. It will not reload modules that have already been loaded and it *will* accept modules that have an on_load function. Therefore, it does not make sense to give any atomicity guarantees. I did consider overloading the existing code:ensure_loaded/1 function, but rejected it because the return value is very different. Having different forms of return values depending on the types of arguments is confusing.
2016-01-28Merge branch 'bjorn/kernel/clean-up-code_server'Björn Gustavsson
* bjorn/kernel/clean-up-code_server: code_server: Add specs for all exported functions code_server: Add types to the state record code_server: Don't export internal system_* functions Simplify starting of code server Remove first argument of code_server:call()
2016-01-28Merge branch 'maint'Björn Gustavsson
* maint: Update documentation for code-loading functions code: Correct the types for error returns Eliminate run-time system crash in code:load_abs/1
2016-01-28code: Correct the types for error returnsBjörn Gustavsson
The specifications for functions that load code in the 'code' module (e.g. code:load_file/1) have some problems: * The specs claim that the functions can return {error,on_load}, but they never do. However, they can return {error,on_load_failure} if the -on_load function in a module fails. * The specs claim that the functions can return {error,native_code}, but they never do. While we are it, also extend the on_load_errors/1 test case to test that the load functions return {error,on_load_failure} when an -on_load function fails.
2016-01-27Simplify starting of code serverBjörn Gustavsson
There is unnecessary knowledge about the -nostick option in the 'kernel' module. -nostick can be handled entirely in the 'code' module. There is no need to have both code:start_link/0 and code:start_link/1. code:start_link/0 is sufficient. Also get rid of error handling for things that cannot happen: The 'init' module has made sure that init:get_argument(root) can't fail, so there is no need for any error-reporting code. (See e1dc0aa4.) We also don't need to test the return value from code_server:start_link/1, because it will always return {ok,Pid} (or crash).
2016-01-27Remove first argument of code_server:call()Björn Gustavsson
Remove the first argument for code_server:call(). It makes no sense. The only caller is 'code'. Note that the code_server module is undocumented and that code_server:call() is an internal helper function.
2016-01-25Eliminate run-time system crash in code:load_abs/1Björn Gustavsson
The run-time system would terminate if code:load_abs/1 was called with a filename containing any non-latin1 characters. The reason is that code_server would attempt to construct a module name from the filename using list_to_atom/1 and that atoms currently are limited to the latin1 character set. But how should the error be reported? I have decided to that the simplest and least confusing way is to move the call to list_to_atom/1 to 'code' module and let it crash the calling process. The resulting stack back trace will make it clear what the reason for the crash was.
2015-12-14Remove the code path cache in the code serverBjörn Gustavsson
In practice, it does not seem that code path cache can improve performance. Looking for any file that is not found will cause the cache to be rebuilt, which will negate any gain of using the cache.
2015-06-18Change license text to APLv2Bruce Yinhe
2015-06-04Avoid exception overhead if HiPE is disabledRichard Carlsson
2015-05-22code: Eliminate dialyzer warnings for unmatched returnsBjörn Gustavsson
We want to have the core applications of Erlang/OTP free from any dialyzer warnings. Eliminate the warnings for unmatched returns that were introduced in 7309ff4c3832.
2015-05-13code: Correct type spec for code:make_stub_module/3Björn Gustavsson
e47490f83e561a changed the size of Info argument tuple (third argument) for code:make_stub_module/3 from 2 to 3, but did not update the spec in code.erl.
2015-05-07code: Make load_native_code_for_all_loaded/0 comply to specBjörn Gustavsson
7309ff4c38325 introduced a mismatch between load_native_code_for_all_loaded/0 and its spec. We could just delete spec, but it is cleaner to ensure that the function always returns 'ok'. Noticed-by: Tuncer Ayaz
2015-05-06code: Reduce overhead of native code checking for loaded modulesBjörn Gustavsson
When the code server has been started, the function load_native_code_for_all_loaded/0 will check whether the .beam files for all loaded modules contain any native code. If there is native code, it will be loaded. If there is no native code, on my computer the check will take about 10 ms. That time can be reduced to about 2 ms if we replace the call to code beam_lib:chunks/2 with a call to prim_file:read_file/1 to read the file and a call to code:get_chunk/2 to check whether the chunk for native code is present. Furthermore, the entire check can be spawned off to a separate process and done in parallel with OTP starting up.
2013-05-06Fix unmatched_returns warnings in STDLIB and KernelHans Bolinder
2013-02-01Add a new function code:get_mode() can be used to detect how the code ↵Vlad Dumitrescu
servers behaves Rationale: Some applications (like erlide) have code to be loaded dynamically on a node. It may be slow to load everything upfront every time, so if the node is in interactive mode, we would like to just append to the load path. Currently, there is no direct way to detect if the node is running in embedded mode or not so that we can do the right thing.
2013-01-25Update copyright yearsBjörn-Egil Dahlberg
2013-01-25Make adjustments for UnicodeHans Bolinder
2013-01-09kernel: Eliminate use of packages in code and code_serverBjörn Gustavsson
2012-07-18Merge branch 'maint'Henrik Nord
Conflicts: erts/preloaded/ebin/erl_prim_loader.beam lib/kernel/src/code.erl
2012-07-06[erts,kernel,stdlib] fix escript/primary archive reloadingTuncer Ayaz
If the mtime of an escript/primary archive file changes after being added to the code path, correctly reload the archive and update the cache. The existing code didn't consider that it might be a zip archive and failed: =ERROR REPORT==== 3-Aug-2011::09:21:21 === File operation error: bad_central_directory. Target: /escript_archive/module.beam. Function: get_file. Process: code_server. Thanks David Reid and Hakan Mattson.
2012-01-27Move types and specs from erl_bif_types.erl to modulesHans Bolinder
2011-11-26code: Clean up loading of code_server prerequisitesBjörn Gustavsson
Reorganize in a systematic way the code that loads the modules needed by the code_server process. While at it, remove the useless hipe_unified_loader:load_hipe_modules/0 function.
2011-06-20Add more specs and typesHans Bolinder
An incorrect spec, rpc:yield/1, has been fixed.
2011-01-31Sanitize the specs of the code moduleKostis Sagonas
After the addition of unicode_binary() to the file:filename() type, dialyzer started complaining about erroneous or incomplete specs in some functions of the 'code' module. The culprit was hard-coded information in erl_bif_types for functions of this module, which were not updated. Since these functions have proper specs these days and code duplication (pun intended) is never a good idea, their type information was removed from erl_bif_types. While doing this, some erroneous comments were fixed in the code module and also made sure that the code now runs without dialyzer warnings even when the -Wunmatched_returns option is used. Some cleanups were applied to erl_bif_types too.
2010-12-03Merge branch 'ks/erl_bif_types-cleanup/OTP-8961' into devPatrik Nyblom
* ks/erl_bif_types-cleanup/OTP-8961: Fix type information of 'file' and 'code' modules Conflicts: lib/hipe/cerl/erl_bif_types.erl
2010-11-30Corrected testcases broken by unicode filenamesPatrik Nyblom
Also corrected type-info for bifs
2010-11-29Fix type information of 'file' and 'code' modulesKostis Sagonas
Dialyzer for a long time now has had hard-coded type information about key functions of the 'file' and 'code' modules in 'erl_bif_types'. Some of this information was not up-to-date according to the published Erlang/OTP documentation, while some other part contained small errors. Now that specs are available, this information should be moved to the corresponding files, not be hard-coded in erl_bif_types. This change takes out all information for the 'file' module and fixes some small errors in type information for the 'code' module.
2010-07-28Load native code for modules loaded before the code serverPaul Guyot
When configuring erlang with --enable-native-libs, some core modules are compiled with hipe, yet because they are loaded before the code server, their native code is not loaded. The fix consists in quietly trying to load the native code for all loaded modules just after the code server is started.
2010-06-03kernel: Add declaration for exported typesKostis Sagonas
2010-04-28kernel: Clean up as suggested by tidierKostis Sagonas
2010-04-19code:clash/0: match correct return value from erl_prim_loader:list_dir/1Tuncer Ayaz
erl_prim_loader:list_dir/1 returns error on failure and not {error,_}. Also update tests in code_SUITE:clash/1. Defect was introduced with fix for listing .ez archives in 49da83de4b. Initial code:clash/0 tests added in 79194d5fa7. Signed-off-by: Tuncer Ayaz <[email protected]>
2010-02-05Fix handling of archive (.ez) files in code:clash/0Tuncer Ayaz
code:clash/0 did not take into account .ez files when listing contents of code path entries. Using erl_prim_loader:list_dir/1 instead of file:list_dir/1 fixes the problem. Signed-off-by: Tuncer Ayaz <[email protected]>
2010-01-27OTP-8387 Explicit top directories in archive files are now optional.Håkan Mattsson
For example, if an archive (app-vsn.ez) just contains an app-vsn/ebin/mod.beam file, the file info for the app-vsn and app-vsn/ebin directories are faked using the file info from the archive file as origin. The virtual direcories can also be listed. For short, the top directories are virtual if they does not exist.
2009-11-20The R13B03 release.OTP_R13B03Erlang/OTP