aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/src/code.erl
diff options
context:
space:
mode:
authorPaul Guyot <[email protected]>2010-07-11 19:50:40 +0200
committerBjörn Gustavsson <[email protected]>2010-07-28 13:59:03 +0200
commita8b8ec5e858da86531933b545f752f436e411b58 (patch)
treedd4d14cc0c313d2f98cdba22996e0c83869ca8b7 /lib/kernel/src/code.erl
parentc4b4edaaf03ac12e12080cb4a3768edbb6ecf77d (diff)
downloadotp-a8b8ec5e858da86531933b545f752f436e411b58.tar.gz
otp-a8b8ec5e858da86531933b545f752f436e411b58.tar.bz2
otp-a8b8ec5e858da86531933b545f752f436e411b58.zip
Load native code for modules loaded before the code server
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.
Diffstat (limited to 'lib/kernel/src/code.erl')
-rw-r--r--lib/kernel/src/code.erl18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/kernel/src/code.erl b/lib/kernel/src/code.erl
index 42d4818f08..ec256d5806 100644
--- a/lib/kernel/src/code.erl
+++ b/lib/kernel/src/code.erl
@@ -304,6 +304,8 @@ do_start(Flags) ->
true ->
ok
end,
+ % Quietly load the native code for all modules loaded so far.
+ catch load_native_code_for_all_loaded(),
Ok2;
Other ->
Other
@@ -496,3 +498,19 @@ has_ext(Ext, Extlen,File) ->
to_path(X) ->
filename:join(packages:split(X)).
+
+-spec load_native_code_for_all_loaded() -> ok.
+load_native_code_for_all_loaded() ->
+ Architecture = erlang:system_info(hipe_architecture),
+ ChunkName = hipe_unified_loader:chunk_name(Architecture),
+ lists:foreach(fun({Module, BeamFilename}) ->
+ case code:is_module_native(Module) of
+ false ->
+ case beam_lib:chunks(BeamFilename, [ChunkName]) of
+ {ok,{_,[{_,Bin}]}} when is_binary(Bin) ->
+ load_native_partial(Module, Bin);
+ {error, beam_lib, _} -> ok
+ end;
+ true -> ok
+ end
+ end, all_loaded()).