A gentle introduction to JIT and dynamic compilation / code generation

A deceptively simple framework for generating dynamic code in C / C ++ has already been discussed in another question . Are there any gentle introductions to the topic with code examples?

My eyes begin to bleed as I look at the very confusing open source JIT compilers when my needs are much more modest.

Are there any good texts on this subject that do not take on a doctorate in computer science? I am looking for well-worn patterns, everything to consider, performance considerations, etc. Electronic or tree resources can be equally valuable. You can take on knowledge of assembly language (and not just x86).

+3
source share
3

, , :

typedef void (*code_ptr)();
unsigned long instruction_pointer = entry_point;
std::map<unsigned long, code_ptr> code_map;


void execute_block() {
    code_ptr f;
    std::map<unsigned long, void *>::iterator it = code_map.find(instruction_pointer);
    if(it != code_map.end()) {
        f = it->second
    } else {
        f = generate_code_block();
        code_map[instruction_pointer] = f;
    }
    f();
    instruction_pointer = update_instruction_pointer();
}

void execute() {
    while(true) {
        execute_block();
    }
}

, . , , " " ( , ), , , . , , , .

:)

, , , "", .

EDIT: , , " "

2: , . , ( , , , ), "" , . . , f() "update_instruction_pointer", , , , "" ret jmp , ( ), . , VM, "execute_block".

+4

- , JIT, , , , .

- VM. VM , .

, , - ( ? SSA?), , .

"" . , , 4, "push" , "stack_variable_5" - . "", 5, "stack_variable_4 = stack_variable_4 + stack_variable_5" .

. . "push" , . , . , "XY +" , "var (X)", "var (X) var (Y)", var, "push" (var (X) ", (Y))".

+2

( ) SSCLI. , :)

0

Source: https://habr.com/ru/post/1698781/


All Articles