File: hipe_jit.erl

package info (click to toggle)
erlang 1%3A11.b.2-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 54,332 kB
  • ctags: 138,013
  • sloc: erlang: 566,932; ansic: 185,450; makefile: 14,148; java: 7,835; sh: 7,307; lisp: 5,249; pascal: 3,225; perl: 2,290; asm: 1,325; cpp: 306; tcl: 245; csh: 29; python: 21; sed: 9
file content (71 lines) | stat: -rw-r--r-- 1,806 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
%% -*- erlang-indent-level: 2 -*-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Copyright (c) 2002 by Erik Johansson.  
%% ====================================================================
%%  Filename : 	hipe_jit.erl
%%  Module   :	hipe_jit
%%  Purpose  :  
%%  Notes    : 
%%  History  :	* 2002-03-14 Erik Johansson (happi@csd.uu.se): Created.
%%  CVS      :
%%              $Author: kostis $
%%              $Date: 2004/01/31 00:38:38 $
%%              $Revision: 1.2 $
%% ====================================================================
%% @doc
%%    A tool to enable using the HiPE compiler as an automatic JIT
%%    compiler rather than a user-controlled one.
%% @end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

-module(hipe_jit).
-export([start/0]).

-record(state,{mode=start,threshold=5000,sleep=5000,time=1000}).

%% @spec start() -> pid()
%%
%% @doc
%%    Starts an Erlang process which calls the HiPE compiler every
%%    now and then (when it sees it fit to do so).
%% @end
start() ->
  spawn(fun() ->
	  loop(#state{})
	end).

loop(State) ->
  case State#state.mode of
    start ->
      start(State);
    wait ->
      wait(State);
    _ ->
      sleep(State)
  end.

sleep(State) ->
  receive 
    quit -> ok
  after State#state.sleep ->
    loop(State#state{mode=start})
  end.

start(State) ->
  catch hipe_profile:prof(),
  catch hipe_profile:clear(),
  loop(State#state{mode=wait}).

wait(State) ->
  receive 
    quit -> ok
  after State#state.time ->
    R = [M || {M,C} <- (catch hipe_profile:mods_res()),
			C > State#state.threshold],
    catch hipe_profile:prof_off(),
    lists:foreach(fun(M) ->
		    io:format("Compile ~w\n",[M]),
		    hipe:c(M,[o2,verbose])
		  end, R)
  end,
  loop(State#state{mode=sleep}).