HDevelop supports just-in-time (JIT) compilation of procedures for optimized performance of HDevelop programs. The JIT compiler is enabled in the “experienced user” settings of the preferences dialog (see section “General Options ▹ Experienced User”). Once enabled, JIT compilation works without any user intervention. Before executing a procedure for the first time, HDevelop automatically compiles it to optimized bytecode. The additional compilation time is only relevant when executing a procedure for the first time in the current session. A re-compilation is triggered by changes to the corresponding procedure.
Messages of the JIT compiler are logged to the output console (see section “Menu Window”). This includes informative events to indicate that a procedure has been (re-)compiled as well as warning events to indicate problems related to JIT compilation.
The speed-up that can be achieved by JIT compilation depends on the structure of the procedure code. If the procedure body contains only consecutive operator calls, the performance gain will be negligible. However, if the execution of a procedure includes a considerable amount of program line switching (for example, loops), the performance gain can be significant.
When using F7 during program execution to step into a procedure, the procedure is executed uncompiled by the HDevelop interpreter.
If an error occurs inside a compiled procedure, the whole procedure call is aborted. The program counter will not indicate the actual program line that caused the error. To debug the corresponding procedure you can step into the procedure call with F7(thereby interpreting its code) or disable JIT compilation altogether in the preferences.
Error message dialogs within try-catch blocks are always suppressed in JIT-compiled procedures regardless of the corresponding setting in the “experienced user” preferences (see section “General Options ▹ Experienced User”).
In HDevelop, the HALCON system parameter “use_window_thread” (see set_system) is activated by default to ensure that on windows systems all top level HALCON graphics and text windows are opened in a special window thread. This setting must not be deactivated. Otherwise, HDevelop may hang, for example, when displaying objects in a HALCON graphics window during regular execution and the window was previously opened during JIT-compiled execution.
JIT Compilation and Semantic Types
In JIT-compiled code, control variables always have the semantic type “any”. In most cases this does not cause any problems since the semantic type is used mainly for visualization purposes, for example, the inspection of variables. However, for thread IDs returned by the qualifier par_start (see section “Starting a Subthread”), the loss of the semantic type “thread_id” can lead to a different runtime behavior of JIT-compiled code. This is caused by the fact that the lifetime of a thread depends on any variables that are still referencing its thread ID. Now, when a control variable with the original semantic type “thread_id” is copied to another control variable inside a JIT-compiled procedure, HDevelop loses track of the additional reference because of the missing semantic type.
In general, procedures that manipulate variables with the semantic type “thread_id” should be excluded from JIT compilation, which is best done by classifying the semantic types of its parameters accordingly as described in section “Parameter Documentation”.
JIT compilation is not supported for procedures that use any of the following features:
If one of these features is found, the corresponding procedure is called uncompiled as before by the HDevelop interpreter.
Note that when an exception is thrown in compiled procedures, the data slot “call_stack_depth” is always returned as -1 (either when inspecting the exception in the variable window or using dev_get_exception_data).