• Home
  • Raw
  • Download

Lines Matching full:the

1 # Interaction of compiled code and the runtime
5 …and Panda runtime should interact with each other. This document describes the following aspects i…
8 * The structure of compiled code stack frames and stack traversing
9 * Transition from the interpeter to compiled code and vise versa
10 * Calling the runtime
14 Documentation of meta information generated by the compiler is located in compiled_method_info.md d…
16 ## Panda runtime (the runtime)
17 Panda runtime as a set of functions aimed to execute managed code. The runtime consists of several …
18 The document refers to the interpreter and the compiler modules.
20 The interpreter is a part of the runtime aimed to execute bytecode of managed functions. The interp…
23 The compiler is aimed to translate managed function's bytecode to native code. The compiler has an …
24 …Interface::CompileMethodSync` which starts compilation. When the function gets compiled the compil…
25 changes its entrypoint to newly generated code. Next time when the function gets called native code…
28 Panda runtime and managed code must call functions according to the target calling convention.
29 Compiled code of a managed function must accept one extra argumnent: the pointer to `panda::Method`…
30 This argument must be the first argument.
34 When the compiler generates native code for this function for ARM target it must consider that
35 the function accepts 3 arguments:
36 - a pointer to `panda::Method` in the register R0.
37 - `a` in the register R1
38 - `b` in the register R2
40 The function must return the result in the register R0.
43 `panda::ManagedThread` has the following fields that compiled code may use:
50 | stack_frame_kind_ | StackFrameKind | A kind of the current stack frame (compiled code o…
57 … runtime entrypoints. A runtime entrypoint is a function which conforms to the target calling conv…
58 A table of the entrypoints is located in `panda::ManagedThread::runtime_entrypoints_` which could b…
61 `panda::Method` describes a managed function in the runtime.
62 This document refers to the following fields of `panda::Method`:
66 | hotness_counter_ | A hotness counter of the managed function. |
70 The field `hotness_counter_` reflects hotness of a managed function. The interpreter increments it …
72 When the hotness counter gets saturated (reaches the threshold) the interpreter triggers compilatio…
73 Panda runtime provides a command line option to tune the hotness counter threshold: `--compiler-hot…
76 …trypoint is a pointer to native code which can execute the function. This code must conform to the
78 The managed function could have compiled code or it could be executed by the interpreter.
79 In the case the function has compiled code the `compiled_entry_point_` must point to compiled code.…
80the case the function is executed by the interpreter the `compiled_entry_point_` must point to a r…
83 A stack frame contains data necessary to execute the function the frame belongs to.
84 The runtime can create several kinds of stack frames. But all the frames of managed code must have
87 …rame is decribed by `panda::Frame` class. The class has fields to store virtual registers and a po…
88 All the consecutive interpreter stack frames are organized into a linked list. The field `panda::Fr…
91 …esponsible to reserve stack frame for its purpose and then release it when the function doesn't ne…
92 Generaly compiled function builds the stack frame in prolog and releases it in epilog. If a compile…
93 the stack frame it can omit its creation.
94 When compiled code is executing the `stack pointer` register must point to a valid stack frame (new…
95 `frame pointer` register must point to correct place in the frame before the following operations:
100 Release of the stack frame could be done by restoring values of `stack pointer` and `frame pointer`…
102 …of caller and callee must be continuous in the stack i.e. the callee's stack frame must immediatel…
104 A compiled code stack frame must have the following structure:
134 - properties - define properties of the frame, f.e. whether it is OSR frame or not.
135 - `panda::Method*` - a pointer to `panda::Method` which describes the called function.
136 - frame pointer - pointer to the previous frame. The value of `frame pointer` register at the momen…
137 - return address - address to which control will be transfered after the function gets returned.
140 `stack pointer` register contains a pointer to the last stack element.
141 `frame pointer` register contains a pointer to the place in the stack where the return address is s…
143 …cial class for getting cframe layout: `class CFrameLayout`. Everything related to the cframe layout
148 prepare arguments in the registers and the stack (if necessary) and jump to callee's entrypoint.
149 Resolving of a function could be done by calling the corresponding runtime entrypoint.
153 could be described by the following pseudocode:
156 // r0 contains a pointer to the current `panda::Method`
166 // 3rd step: call the function
168 // r0 contains the function result
172 The Compiler have an entrypoints table. Each entrypoint contains a link to the Bridge Function.
173 The Bridge Functions are auto-generated for each runtime function to be called using the macro asse…
174 The Bridge Function sets up the Boundary Frame and performs the call to the actual runtime function.
176 To do a runtime call from compiled code the Compiler generates:
177 * putting callee saved (if need) and param holding (if any) register values to the stack
178 * (callee saved regisers goes to Bridge Function stack frame, caller saved registers goes to the cu…
183 The bridge function does:
184 * setup the Bridge Function stack frame
185 * push the caller saved registers (except of registers holding function parameters) to the caller's…
186 * adjust Stack Pointer, and pass execution to the runtime function
187 * restore the Stack Pointer and caller saved registers
208 + 16-byte alignment pad to the next frame +
211 ## Transition from the interpreter to compiled code
212 When the interpreter handles a call instruction first it should resolve the callee method.
213 Depending on the callee's entrypoint there may be different cases.
214 If the entrypoint points to `CompiledCodeToInterpreterBridge` then the callee should be executed by…
215 In other cases the interpreter calls the function `InterpreterToCompiledCodeBridge` passing to it t…
216 the call instruction, the interpreter's frame and the pointer to `panda::ManagedThread`.
218 `InterpreterToCompiledCodeBridge` function does the following:
220 * Set the pointer to `panda::ManagedThread` to the thread register.
222 * Prepare the arguments according to the target calling convention. The function uses the bytecode …
223 and interpreter's frame to retreive the function's arguments.
224 * Jump to the callee's entrypoint.
225 * After the return save the result to the interpreter stack frame.
227 * Drop the boundary stack frame.
229 …iledCodeBridge`'s boundary stack frame is necessary to link the interpreter's frame with the compi…
237 d k | pointer to the |
247 The structure of boundary frame is the same as a stack frame of compiled code.
248 Instead of pointer to `panda::Method` the frame contains constant `INTERPRETER_TO_COMPILED_CODE_BRI…
249 Frame pointer points to the previous interpreter frame.
251 ## Transition from compiled code to the interpreter
252 If a function should be executed by the interpreter it must have `CompiledCodeToInterpreterBridge` …
253 `CompiledCodeToInterpreterBridge` does the following:
256 * Fill in the interpreter frame by the arguments passed to `CompiledCodeToInterpreterBridge` in the
257 * Call the interpreter.
258 * Store the result in registers or in the stack according to the target calling convention.
259 * Drop the boundary stack frame.
262 …rpreterBridge`'s boundary stack frame is necessary to link the compiled code's frame with the inte…
281 The structure of boundary frame is the same as a stack frame of compiled code.
282 Instead of a pointer to `panda::Method` the frame contains constant `COMPILED_CODE_TO_INTERPRETER_B…
283 Frame pointer points to the previous frame in compiled code stack frame.
284 The field `panda::Frame::prev_` must point to the boundary frame pointer.
287 Stack traversing is performed by the runtime. When the runtime examinates a managed thread's stack
288 Stack unwinding always starts from the top frame. Its kind could be determined from `panda::Managed…
289 to the top frame could be determined depends on the kind of the top stack frame:
290 * The top stack frame is an interpreter stack frame. Address of the interpreter's frame could be re…
291 * The top stack frame is a compiled code stack frame. `frame pointer` register contains the address…
293 Having a pointer to the top stack frame, its kind and structure the runtime can move to the next fr…
294 Moving to the next frame is done according to the table below:
296 | Kind of the current stack frame | How to get a pointer to the next stack frame | Kind of the prev…
299 …COMPILED_CODE_BRIDGE boundary stack frame | Read `pointer to the interpreter frame` from the stack…
300 | COMPILED_CODE_TO_INTERPRETER_BRIDGE boundary stack frame | Read `frame pointer` from the stack | …
303 Thus the runtime can traverse all the managed stack frames moving from one frame to the previous fr…
304 crossing the boundary frames.
307 * Compiled code could be combined from several managed functions (inlined functions). If the runtim…
308 during handling a compiled code stack frame it uses meta information generated by the compiler (See…
309 …piled code may save any callee-saved registers on the stack. Before moving to the next stack frame…
310 To do that the runtime uses information about callee-saved registers stored on the stack. This info…
311 …k unwinding. For example, when GC moves an object, it must update all the references to the object.
312 The runtime should provide an internal API for changing values of virtual registers.
315 Consider the following call sequence:
321 Functions `foo` and `baz` are executed by the interpreter and the function `bar` has compiled code.
322 In this situation the stack might look as follow:
355 d k | pointer to the | -+
377 The runtime determines kind of the top stack frame by reading `panda::ManagedThread::stack_frame_ki…
378 `panda::ManagedThread::GetCurrentFrame()` method must return the pointer to `baz`'s interpreter sta…
379 To go to the previous frame the runtime reads the field `panda::Frame::prev_` which must point to `…
380 It means that to get `bar`'s stack frame the runtime must read `frame pointer` and the kind of the
381 At this step the runtime has a pointer to `bar`'s compiled code stack frame. To go to the next fram…
382 …ndary stack frame. To reach `foo`'s interpreter stack frame the runtime reads `pointer to the inte…
386 …eoptimize()` runtime entrypoint to continue execution of the method in the interpreter from the po…
387 The function reconstructs the interpreter stack frame and calls the interpreter.
388 …ned functions) `Deoptimize` reconstructs interpreter stack frame and calls the interpreter for eac…
393 The function `ThrowException` does the following:
394 * Saves all the callee-saved registers to the stack
395 * Stores the pointer to the exception object to `panda::ManagedThread::pending_exception_`
396 …wind compiled code stack frames to find the corresponding exception handler by going from one stac…
398 If the corresponding catch handler is found in the current stack frame the runtime jumps to the han…
400 …_CODE_BRIDGE boundary stack frame is reached the runtime returns to the interpreter letting it to …
401 Returning to the interpreter is performed as follow:
402 1. Determine the return address to the boundary frame. The return address is stored in the followin…
403 2. Set the pointer to the boundary frame into stack pointer, assign the return address determined a…
405 … there is no catch handler in the current frame then the runtime restores values of callee-saved r…
409 …iled code stack frame is performed according meta information generated by the compiler (See compi…
411 The interpreter must ignore the returned value if `panda::ManagedThread::pending_exception_` is not…