Fiber analysis of--kilim framework of Java coprocessor Framework

Source: Internet
Author: User

1. The role of fiber in KilimFiber is used to manage and save the state of a function stack frame in the call hierarchy during task execution, where the function stack frame is the same as the function stack frame in the JVM runtime, but fiber does not copy all the information in the function stack frame intact, such as all variables in the local variable table , but after code analysis there is a selection of the necessary reserved variables, generally only need to save the subsequent execution process of the required variables, such as static constants and so on need not be saved to fiber, because the static variable can be directly loaded into the operand stack by the byte code such as Iconst.
2. What is the true meaning of PC in Kilim fiber? Fiber in the PC, the literal meaning is the program counter, the actual meaning is: If the PC value is 0, it means the first execution, the program execution process and bytecode enhancement before the process is the same; if the PC value is n, then jump directly to the nth pauseable method in this function to begin execution, Note that the previous execution to the nth Pauseable method is paused, at which time the task resumes execution, and the bytecode level is executed through the tableswitch instruction directly to the Pauseable method, or again into the function execution body. And so on, the entire function call chain follows this logical flow
The typical functions are as follows:
public void function () throw pauseable
{
XXX; Initialization of temporary variables, etc.
A (); Function A is pauseable, and if execution is paused, pc=1
B (); Function B is pauseable, if the execution to function B is paused, then pc=2, the next time you resume the function () functions from the portal to jump directly to here, the execution functions b
C (); Function C is pauseable, if the execution to function B is paused, then pc=3, the next time you resume from function () functions to jump directly to here, execute functions C
}
3. What is the role of state in fiber in Kilim? The state function in fiber is mainly embodied in the two variables of curstate and Statestack, which are used to maintain function stack frames during function call chain execution.
When a task is about to execute a pauseable method, the fiber down method is called first to record the current execution to the next level in the entire function call chain, and to log curstate and the PC.
When a task pauses during execution of a pauseable method, the task's pause method is called internally, and pause calls the Togglepause method directly, depending on whether curstate is null or not. To set the value of the fiber ispausing, and ispausing indicates whether the task is paused or resumed, the corresponding source code is as follows:
if (curstate = = null) {
SetState (pause_state);
} else {
Statestack[istack] = null;
Ispausing = false;
}

When a task finishes executing a pauseable method, the fiber's up method is called, which identifies the call to a Pauseable method to return, and the return value of the UP method indicates whether the Pauseable method returns normally or pauses. Because the up method internally depends on whether the ispausing variable value in fiber and the stack frame of this function Statestack[istack] is NULL to determine if the pause is paused, and whether the function stack frame has been saved. If it is pausing__no_state, indicating that the function is paused, the function has not saved the stack frame, you need to use this function stack frame, general subsequent execution of the required variables (including function arguments, function local variables) to the state, that is, Statestack[istack], Here is a list of the 4 possible states for a pausable method to complete:

not_pausing__no_state = 0;
Not_pausing__has_state = 1;
Pausing__no_state = 2;
Pausing__has_state = 3;

Fiber analysis of--kilim framework of Java coprocessor Framework

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.