Skip to content

Commit

Permalink
Move the load_native_code_for_all_loaded function and its invocation …
Browse files Browse the repository at this point in the history
…to the

code module

As noted by bgustavsson@, this function does not belong to code_server
since it is not executed by the code_server process but just after the
code_server is started, and code:do_start/1 is a better place to load
the native code of early loaded modules.
Also removed unnecessary parentheses around the catch statement.
  • Loading branch information
pguyot committed Jul 28, 2010
1 parent 2637b8a commit a30b889
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
18 changes: 18 additions & 0 deletions lib/kernel/src/code.erl
Expand Up @@ -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
Expand Down Expand Up @@ -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()).
21 changes: 1 addition & 20 deletions lib/kernel/src/code_server.erl
Expand Up @@ -48,10 +48,7 @@ start_link(Args) ->
Init = fun() -> init(Ref, Parent, Args) end,
spawn_link(Init),
receive
{Ref,Res} ->
% Quietly load the native code for all modules loaded so far.
(catch load_native_code_for_all_loaded()),
Res
{Ref,Res} -> Res
end.


Expand Down Expand Up @@ -1544,19 +1541,3 @@ to_atom(X) when is_list(X) -> list_to_atom(X).

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) ->
code:load_native_partial(Module, Bin);
{error, beam_lib, _} -> ok
end;
true -> ok
end
end, code:all_loaded()).

0 comments on commit a30b889

Please sign in to comment.