text
stringlengths
0
601k
let add_edge_after son ancestor = add_edge ancestor son 0
let add_RAW_dependencies node arg = try let ancestor = Hashtbl . find code_results arg . loc in add_edge ancestor node ancestor . delay with Not_found -> ( )
let add_WAR_dependencies node res = let ancestors = Hashtbl . find_all code_uses res . loc in List . iter ( add_edge_after node ) ancestors
let add_WAW_dependencies node res = try let ancestor = Hashtbl . find code_results res . loc in add_edge ancestor node 0 with Not_found -> ( )
let is_critical critical_outputs results = try for i = 0 to Array . length results - 1 do let r = results . ( i ) . loc in for j = 0 to Array . length critical_outputs - 1 do if critical_outputs . ( j ) . loc = r then raise Exit done done ; false with Exit -> true
let rec longest_path critical_outputs node = if node . length < 0 then begin match node . sons with [ ] -> node . length <- if is_critical critical_outputs node . instr . res || node . instr . desc = Lreloadretaddr then node . delay else 0 | sons -> node . length <- List . fold_left ( fun len ( son , delay ) -> max len...
let rec remove_instr node = function [ ] -> [ ] | instr :: rem -> if instr == node then rem else instr :: remove_instr node rem
let some_load = ( Iload ( Cmm . Word_int , Arch . identity_addressing ) ) Icall_ind _ -> false | Icall_imm _ -> false | Itailcall_ind _ -> false | Itailcall_imm _ -> false | Iextcall _ -> false | Istackoffset _ -> false | Ialloc _ -> false | _ -> true match instr . desc with Lop op -> self # oper_in_basic_block op && n...
let reset ( ) = clear_code_dag ( )
let collection eq_list = let rec collection ( { eq_desc } as eq ) = match eq_desc with | EQand ( and_eq_list ) -> And ( List . map collection and_eq_list ) | EQbefore ( before_eq_list ) -> Before ( List . map collection before_eq_list ) | _ -> Leaf ( eq ) in And ( List . map collection eq_list )
let schedule eq_list = let fusion g eq_list = let join eq1 eq2 = match eq1 . eq_desc , eq2 . eq_desc with | EQmatch ( _ , e1 , m_h_list1 ) , EQmatch ( _ , e2 , m_h_list2 ) | _ -> false in let relation { eq_index = n1 } { eq_index = n2 } = ( Graph . is_before g n1 n2 ) || ( Graph . is_before g n2 n1 ) in let rec recook ...
let rec equation ( { eq_desc } as eq ) = match eq_desc with | EQeq _ | EQpluseq _ | EQinit _ | EQnext _ | EQder _ -> eq | EQmatch ( total , e , p_h_list ) -> { eq with eq_desc = match_eq total e p_h_list } | EQreset ( res_eq_list , e ) -> { eq with eq_desc = reset_eq res_eq_list e } | EQand ( and_eq_list ) -> { eq with...
let exp ( { e_desc = desc } as e ) = let desc = match desc with | Elet ( l , e ) -> Elet ( local l , e ) | _ -> desc in { e with e_desc = desc }
let implementation impl = match impl . desc with | Eopen _ | Etypedecl _ | Econstdecl _ -> impl | Efundecl ( n , ( { f_body = e } as body ) ) -> { impl with desc = Efundecl ( n , { body with f_body = exp e } ) }
let implementation_list impl_list = Zmisc . iter implementation impl_list
type ' a t = _ ' ScheduledFuture java_instance
let cancel f i = Java . call " ScheduledFuture . cancel ( cancelboolean ) cancelboolean " f i " ocamljava_future_get " " ocamljava_future_get_time "
let is_cancelled f = Java . call " ScheduledFuture . isCancelled ( isCancelled ) isCancelled " f
let is_done f = Java . call " ScheduledFuture . isDone ( isDone ) isDone " f
let get_delay f timeunit = Java . call " ScheduledFuture . getDelay ( getDelayTimeUnit ) getDelayTimeUnit " f timeunit " java null "
let null = null ( ) " java is_null " " java is_not_null "
let wrap x = if is_null x then None else Some x
let unwrap = function | Some x -> x | None -> null
type t = _ ' ScheduledThreadPoolExecutor java_instance " ocamljava_scheduledthreadpoolexecutor_make "
let make ~ core_pool_size rhe = scheduledthreadpoolexecutor_make core_pool_size rhe
let await_termination stpe time timeunit = Java . call " ScheduledThreadPoolExecutor . awaitTermination ( awaitTerminationlong , TimeUnit ) TimeUnit " stpe time timeunit
let get_active_count stpe = Java . call " ScheduledThreadPoolExecutor . getActiveCount ( getActiveCount ) getActiveCount " stpe
let get_completed_task_count stpe = Java . call " ScheduledThreadPoolExecutor . getCompletedTaskCount ( getCompletedTaskCount ) getCompletedTaskCount " stpe
let get_continue_existing_periodic_tasks_after_shutdown_policy stpe = Java . call " ScheduledThreadPoolExecutor . getContinueExistingPeriodicTasksAfterShutdownPolicy ( getContinueExistingPeriodicTasksAfterShutdownPolicy ) getContinueExistingPeriodicTasksAfterShutdownPolicy " stpe
let get_core_pool_size stpe = Java . call " ScheduledThreadPoolExecutor . getCorePoolSize ( getCorePoolSize ) getCorePoolSize " stpe
let get_execute_existing_delayed_tasks_after_shutdown_policy stpe = Java . call " ScheduledThreadPoolExecutor . getExecuteExistingDelayedTasksAfterShutdownPolicy ( getExecuteExistingDelayedTasksAfterShutdownPolicy ) getExecuteExistingDelayedTasksAfterShutdownPolicy " stpe
let get_keep_alive_time stpe timeunit = Java . call " ScheduledThreadPoolExecutor . getKeepAliveTime ( getKeepAliveTimeTimeUnit ) getKeepAliveTimeTimeUnit " stpe timeunit
let get_largest_pool_size stpe = Java . call " ScheduledThreadPoolExecutor . getLargestPoolSize ( getLargestPoolSize ) getLargestPoolSize " stpe
let get_maximum_pool_size stpe = Java . call " ScheduledThreadPoolExecutor . getMaximumPoolSize ( getMaximumPoolSize ) getMaximumPoolSize " stpe
let get_pool_size stpe = Java . call " ScheduledThreadPoolExecutor . getPoolSize ( getPoolSize ) getPoolSize " stpe
let get_rejected_execution_handler stpe = Java . call " ScheduledThreadPoolExecutor . getRejectedExecutionHandler ( getRejectedExecutionHandler ) getRejectedExecutionHandler " stpe
let get_remove_on_cancel_policy stpe = Java . call " ScheduledThreadPoolExecutor . getRemoveOnCancelPolicy ( getRemoveOnCancelPolicy ) getRemoveOnCancelPolicy " stpe
let get_task_count stpe = Java . call " ScheduledThreadPoolExecutor . getTaskCount ( getTaskCount ) getTaskCount " stpe " ocamljava_threadpoolexecutor_invoke_all " " ocamljava_threadpoolexecutor_invoke_all_time " " ocamljava_threadpoolexecutor_invoke_any " " ocamljava_threadpoolexecutor_invoke_any_time "
let is_shutdown stpe = Java . call " ScheduledThreadPoolExecutor . isShutdown ( isShutdown ) isShutdown " stpe
let is_terminated stpe = Java . call " ScheduledThreadPoolExecutor . isTerminated ( isTerminated ) isTerminated " stpe
let is_terminating stpe = Java . call " ScheduledThreadPoolExecutor . isTerminating ( isTerminating ) isTerminating " stpe " ocamljava_scheduledthreadpoolexecutor_schedule " " ocamljava_scheduledthreadpoolexecutor_schedule_at_fixed_rate " " ocamljava_scheduledthreadpoolexecutor_schedule_at_fixed_rate " " ocamljava_sche...
let set_continue_existing_periodic_tasks_after_shutdown_policy stpe b = Java . call " ScheduledThreadPoolExecutor . setContinueExistingPeriodicTasksAfterShutdownPolicy ( setContinueExistingPeriodicTasksAfterShutdownPolicyboolean ) setContinueExistingPeriodicTasksAfterShutdownPolicyboolean " stpe b
let set_core_pool_size stpe sz = Java . call " ScheduledThreadPoolExecutor . setCorePoolSize ( setCorePoolSizeint ) setCorePoolSizeint " stpe sz
let set_execute_existing_delayed_tasks_after_shutdown_policy stpe b = Java . call " ScheduledThreadPoolExecutor . setExecuteExistingDelayedTasksAfterShutdownPolicy ( setExecuteExistingDelayedTasksAfterShutdownPolicyboolean ) setExecuteExistingDelayedTasksAfterShutdownPolicyboolean " stpe b
let set_keep_alive_time stpe time timeunit = Java . call " ScheduledThreadPoolExecutor . setKeepAliveTime ( setKeepAliveTimelong , TimeUnit ) TimeUnit " stpe time timeunit
let set_maximum_pool_size stpe sz = Java . call " ScheduledThreadPoolExecutor . setMaximumPoolSize ( setMaximumPoolSizeint ) setMaximumPoolSizeint " stpe sz
let set_rejected_execution_handler stpe reh = Java . call " ScheduledThreadPoolExecutor . setRejectedExecutionHandler ( setRejectedExecutionHandlerRejectedExecutionHandler ) setRejectedExecutionHandlerRejectedExecutionHandler " stpe reh
let set_remove_on_cancel_policy stpe b = Java . call " ScheduledThreadPoolExecutor . setRemoveOnCancelPolicy ( setRemoveOnCancelPolicyboolean ) setRemoveOnCancelPolicyboolean " stpe b
let shutdown stpe = Java . call " ScheduledThreadPoolExecutor . shutdown ( shutdown ) shutdown " stpe " ocamljava_threadpoolexecutor_shutdown_now " " ocamljava_threadpoolexecutor_submit " " java null "
let null = null ( ) " java is_null " " java is_not_null "
let wrap x = if is_null x then None else Some x
let unwrap = function | Some x -> x | None -> null
let to_http service region req = let uri = Uri . add_query_params ( Uri . of_string ( Aws . Util . of_option_exn ( Endpoints . url_of service region ) ) ) ( List . append [ " Version " , [ " 2014 - 11 - 01 " ] ; " Action " , [ " ScheduleKeyDeletion " ] ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . render ( S...
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Util . option_bind ( Xml . member " ScheduleKeyDeletionResponse " ( snd xml ) ) ( Xml . member " ScheduleKeyDeletionResult " ) in try Util . or_error ( Util . option_bind resp ScheduleKeyDeletionResponse . parse ) ( let open Error in BadResponse {...
let parse_error code err = let errors = [ ] @ Errors_internal . common in match Errors_internal . of_string err with | Some var -> if List . mem var errors && match Errors_internal . to_http_code var with | Some var -> var = code | None -> true then Some var else None | None -> None
let is_master ( ) = Int . equal 0 ( Worker . current_worker_id ( ) )
type t = | SequentialScheduler | ParallelScheduler of Worker . t list
module Policy = struct type t = number_of_workers : int -> number_of_tasks : int -> int let divide_work ~ number_of_workers ~ number_of_tasks policy = policy ~ number_of_workers ~ number_of_tasks let legacy_fixed_chunk_size chunk_size = assert ( chunk_size > 0 ) ; fun ~ number_of_workers ~ number_of_tasks -> Core . Int...
let entry = Worker . register_entry_point ~ restore ( : fun ( log_state , profiling_state , statistics_state ) -> Log . GlobalState . restore log_state ; Profiling . GlobalState . restore profiling_state ; Statistics . GlobalState . restore statistics_state ; ( ) )
let create ~ configuration ( { : Configuration . Analysis . parallel ; number_of_workers ; _ } as configuration ) ( ) = let heap_handle = Memory . get_heap_handle configuration in if parallel then let workers = Hack_parallel . Std . Worker . make ~ saved_state : ( Log . GlobalState . get ( ) , Profiling . GlobalState ....
let create_sequential ( ) = SequentialScheduler
let destroy = function | SequentialScheduler -> ( ) | ParallelScheduler workers -> List . iter workers ~ f : Worker . kill
let with_scheduler ~ configuration ~ f = let scheduler = create ~ configuration ( ) in match scheduler with | SequentialScheduler -> f SequentialScheduler | ParallelScheduler _ -> Exn . protectx ~ f scheduler ~ finally ( : fun _ -> destroy scheduler )
let run_process process = let result = process ( ) in Statistics . flush ( ) ; result
let map_reduce scheduler ~ policy ~ initial ~ map ~ reduce ~ inputs ( ) = let sequential_map_reduce ( ) = map initial inputs |> fun mapped -> reduce mapped initial in match scheduler with | ParallelScheduler workers -> let number_of_workers = List . length workers in let number_of_chunks = Policy . divide_work ~ number...
let iter scheduler ~ policy ~ f ~ inputs = map_reduce scheduler ~ policy ~ initial ( ) : ~ map ( : fun _ inputs -> f inputs ) ~ reduce ( : fun _ _ -> ( ) ) ~ inputs ( )
let is_parallel = function | SequentialScheduler -> false | ParallelScheduler _ -> true
let once_per_worker scheduler ~ configuration : _ ~ f = match scheduler with | SequentialScheduler -> ( ) | ParallelScheduler workers -> let handles = List . map workers ~ f ( : fun worker -> Worker . call worker f ( ) ) in let rec collect_all = function | [ ] -> ( ) | handles -> let { Worker . readys ; waiters } = Wor...
module Ivar = struct open Types . Ivar let create_with_cell cell = { cell } let create ( ) = create_with_cell Empty let create_full ( type a ) ( a : a ) = ( Obj . magic : a Immutable . t -> a t ) { cell = Full a } ; ; end
module Bvar = struct open Types . Bvar let create ( ) = of_repr { has_any_waiters = false ; ivar = Ivar . create ( ) } end
module Very_low_priority_worker = struct module Exec_result = struct type t = Types . Very_low_priority_worker . Exec_result . t = | Finished | Not_finished [ @@ deriving sexp_of ] end type t = Types . Very_low_priority_worker . t = { execution_context : Execution_context . t ; exec : unit -> Exec_result . t } [ @@ der...
type t = Scheduler0 . t = { mutable check_access : ( unit -> unit ) option ; mutable job_pool : Job_pool . t ; normal_priority_jobs : Job_queue . t ; low_priority_jobs : Job_queue . t ; very_low_priority_workers : Very_low_priority_worker . t Deque . t ; mutable main_execution_context : Execution_context . t ; mutable ...
let uncaught_exn t = match t . uncaught_exn with | None -> None | Some ( exn , sexp ) -> Some ( Error . create " unhandled exception " ( exn , sexp ) [ % sexp_of : Exn . t * Sexp . t ] ) ; ;
let num_pending_jobs t = Job_queue . length t . normal_priority_jobs + Job_queue . length t . low_priority_jobs ; ;
let num_jobs_run t = Job_queue . num_jobs_run t . normal_priority_jobs + Job_queue . num_jobs_run t . low_priority_jobs ; ;
let last_cycle_num_jobs t = t . last_cycle_num_jobs
let invariant t : unit = try let check f field = f ( Field . get field t ) in Fields . iter ~ check_access : ignore ~ job_pool ( : check Job_pool . invariant ) ~ normal_priority_jobs ( : check Job_queue . invariant ) ~ low_priority_jobs ( : check Job_queue . invariant ) ~ very_low_priority_workers : ( check ( fun q -> ...
let free_job t job = Pool . free t . job_pool job
let enqueue t ( execution_context : Execution_context . t ) f a = if is_none t . uncaught_exn then ( let priority = execution_context . priority in let job_queue = match priority with | Normal -> t . normal_priority_jobs | Low -> t . low_priority_jobs in Job_queue . enqueue job_queue execution_context f a ; match t . j...
let enqueue_job t job ~ free_job = let job_pool = t . job_pool in enqueue t ( Pool . get job_pool job Pool . Slot . t0 ) ( Pool . get job_pool job Pool . Slot . t1 ) ( Pool . get job_pool job Pool . Slot . t2 ) ; if free_job then Pool . free t . job_pool job ; ;
let handle_fired ( time_source : _ Synchronous_time_source . T1 . t ) job_or_event = let open Job_or_event . Match in let ( K k ) = kind job_or_event in match k , project k job_or_event with | Job , job -> enqueue_job time_source . scheduler job ~ free_job : true | Event , event -> Synchronous_time_source . fire time_s...
let create ( ) = let now = Time_ns . now ( ) in let rec t = { check_access = None ; job_pool = Job_pool . create ( ) ; normal_priority_jobs = Job_queue . create ( ) ; low_priority_jobs = Job_queue . create ( ) ; very_low_priority_workers = Deque . create ( ) ; main_execution_context = Execution_context . main ; current...
let is_dead t = is_some t . uncaught_exn
let set_check_access t f = t . check_access <- f
let t_ref = match Result . try_with create with | Ok t -> ref t | Error exn -> Debug . log " Async cannot create its raw scheduler " exn [ % sexp_of : exn ] ; exit 1 ; ;
let check_access t = match t . check_access with | None -> ( ) | Some f -> f ( ) ; ;
let t ( ) = let t = ! t_ref in check_access t ; t ; ;
let current_execution_context t = if t . record_backtraces then Execution_context . record_backtrace t . current_execution_context else t . current_execution_context ; ;
let with_execution_context t tmp_context ~ f = let old_context = current_execution_context t in set_execution_context t tmp_context ; protect ~ f ~ finally ( : fun ( ) -> set_execution_context t old_context ) ; ;
let create_job ( type a ) t execution_context f a = if Pool . is_full t . job_pool then t . job_pool <- Pool . grow t . job_pool ; Pool . new3 t . job_pool execution_context ( Obj . magic ( f : a -> unit ) : Obj . t -> unit ) ( Obj . repr ( a : a ) ) ; ;
let got_uncaught_exn t exn sexp = if debug then Debug . log " got_uncaught_exn " ( exn , sexp ) [ % sexp_of : Exn . t * Sexp . t ] ; List . iter [ t . normal_priority_jobs ; t . low_priority_jobs ] ~ f : Job_queue . clear ; t . uncaught_exn <- Some ( exn , sexp ) ; ;
let start_cycle t ~ max_num_jobs_per_priority = let n = Max_num_jobs_per_priority_per_cycle . raw max_num_jobs_per_priority in Job_queue . set_jobs_left_this_cycle t . normal_priority_jobs n ; Job_queue . set_jobs_left_this_cycle t . low_priority_jobs n ; ;
let rec run_jobs t = match Job_queue . run_jobs t . normal_priority_jobs t with | Error _ as e -> e | Ok ( ) -> ( match Job_queue . run_jobs t . low_priority_jobs t with | Error _ as e -> e | Ok ( ) -> if Job_queue . can_run_a_job t . normal_priority_jobs || Job_queue . can_run_a_job t . low_priority_jobs then run_jobs...
let stabilize t = start_cycle t ~ max_num_jobs_per_priority : ( Max_num_jobs_per_priority_per_cycle . create_exn Int . max_value ) ; match run_jobs t with | Ok ( ) -> Ok ( ) | Error ( exn , _backtrace ) -> Error exn ; ;
let create_time_source ( ? timing_wheel_config = Async_kernel_config . timing_wheel_config ) ~ now ( ) = let t = t ( ) in let events = Timing_wheel . create ~ config : timing_wheel_config ~ start : now in let rec time_source : _ Synchronous_time_source . T1 . t = { id = Types . Time_source_id . create ( ) ; advance_err...
let wall_clock ( ) = Synchronous_time_source . read_only ( t ( ) ) . time_source
let test_policy _ = let assert_divide ~ number_of_workers ~ number_of_tasks ~ expected policy = let actual = Policy . divide_work policy ~ number_of_workers ~ number_of_tasks in assert_equal ~ cmp : Int . equal ~ printer : Int . to_string expected actual in assert_divide ( Policy . fixed_chunk_size ~ minimum_chunks_per...
let ( ) = " scheduler " >::: [ " policy " >:: test_policy ] |> Test . run
let test s f = let f = Fiber . with_error_handler f ~ on_error ( : fun exn -> Format . printf " % a . " @ Exn_with_backtrace . pp_uncaught exn ) in S . run s f let s = S . create ( ) in S . run s ( Fiber . of_thunk ( fun ( ) -> print_endline " running " ; Fiber . return ( ) ) ) ; [ % expect { | running } ] | let s = S ...
Ireload -> 4 | Iload ( _ , _ ) -> 4 | Iconst_float _ -> 4 | Iintop ( Imul ) -> 10 | Iintop_imm ( Imul , _ ) -> 10 | Iaddf | Isubf | Imulf -> 8 | Idivf -> 40 | _ -> 2 | Ialloc _ -> 4 | Iintop ( Imulh ) -> 15 | Iintop ( Idiv | Imod ) -> 20 | Iintop ( Icomp _ ) -> 4 | Iintop_imm ( Icomp _ , _ ) -> 4 | _ -> 1 end