示例#1
0
extern "C" __declspec(dllexport) PyJittedCode* JitCompile(PyCodeObject* code) {
    if (strcmp(PyUnicode_AsUTF8(code->co_name), "<module>") == 0) {
        return nullptr;
    }
#ifdef DEBUG_TRACE
    static int compileCount = 0, failCount = 0;
    printf("Compiling %s from %s line %d #%d (%d failures so far)\r\n",
        PyUnicode_AsUTF8(code->co_name),
        PyUnicode_AsUTF8(code->co_filename),
        code->co_firstlineno,
        ++compileCount,
        failCount);
#endif

    PythonCompiler jitter(code);
    AbstractInterpreter interp(code, &jitter);
    auto res = interp.compile();

    if (res == nullptr) {
#ifdef DEBUG_TRACE
        printf("Compilation failure #%d\r\n", ++failCount);
#endif
        return nullptr;
    }

    auto jittedCode = (PyJittedCode*)PyJittedCode_New();
    if (jittedCode == nullptr) {
        // OOM
        delete res;
        return nullptr;
    }

    g_jittedCode[jittedCode] = res;
    jittedCode->j_evalfunc = &Jit_EvalHelper; //(Py_EvalFunc)res->get_code_addr();
    jittedCode->j_evalstate = res->get_code_addr();
    return jittedCode;
}
示例#2
0
void Method::apply_vtable_patches()
{
    Global_Env * vm_env = VM_Global_State::loader_env;

    if (_vtable_patch == NULL) {
        // Constructors are never entered into a vtable.
        return;
    }

    vm_env->p_vtable_patch_lock->_lock();

    void *code_addr = get_code_addr();

    VTable_Patches *vp = (VTable_Patches *)_vtable_patch;
    for(;  (vp != NULL);  vp = vp->next) {
        for (int i = 0;  i < MAX_VTABLE_PATCH_ENTRIES;  i++) {
            if (vp->patch_table[i] != NULL) {
                *((void **)vp->patch_table[i]) = code_addr;
            }
        }
    }

    vm_env->p_vtable_patch_lock->_unlock();
} //Method::apply_vtable_patches