⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interp.c

📁 jam vm 最新Java虚拟机!为开源项目源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
    DEF_OPC_210(OPC_D2F,        OPC_X2Y(double, float);    )#define OPC_fp2int(SRC_TYPE)            \{                                       \    int res;                            \    SRC_TYPE value;                     \    ostack -= sizeof(SRC_TYPE)/4;       \    value = *(SRC_TYPE *)ostack;        \                                        \    if(value >= (SRC_TYPE)INT_MAX)      \        res = INT_MAX;                  \    else if(value <= (SRC_TYPE)INT_MIN) \        res = INT_MIN;                  \    else if(value != value)             \        res = 0;                        \    else                                \        res = (int) value;              \                                        \    PUSH_0(res, 1);                     \}    DEF_OPC_210(OPC_F2I,        OPC_fp2int(float);    )    DEF_OPC_210(OPC_D2I,        OPC_fp2int(double);    )#define OPC_fp2long(SRC_TYPE)              \{                                          \    long long res;                         \    SRC_TYPE value;                        \    ostack -= sizeof(SRC_TYPE)/4;          \    value = *(SRC_TYPE *)ostack;           \                                           \    if(value >= (SRC_TYPE)LLONG_MAX)       \        res = LLONG_MAX;                   \    else if(value <= (SRC_TYPE)LLONG_MIN)  \        res = LLONG_MIN;                   \    else if(value != value)                \        res = 0;                           \    else                                   \        res = (long long) value;           \                                           \    PUSH_LONG(res, 1);                     \}    DEF_OPC_210(OPC_F2L,        OPC_fp2long(float);    )    DEF_OPC_210(OPC_D2L,        OPC_fp2long(double);    )    DEF_OPC_210(OPC_I2B, {        signed char v = *--ostack & 0xff;        PUSH_0(v, 1);    })    DEF_OPC_210(OPC_I2C, {        int v = *--ostack & 0xffff;        PUSH_0(v, 1);    })    DEF_OPC_210(OPC_I2S, {        signed short v = *--ostack & 0xffff;        PUSH_0((int) v, 1);    })#ifdef USE_CACHE    DEF_OPC_012(OPC_LCMP, {        long long v1 = *(long long*)&ostack[-2];        int r = (v1 == cache.l) ? 0 : ((v1 < cache.l) ? -1 : 1);        cache.i.v1 = r;        ostack -= 2;        DISPATCH(1, 1);    })#else    DEF_OPC_012(OPC_LCMP, {        long long v2 = *(long long*)&ostack[-2];        long long v1 = *(long long*)&ostack[-4];        ostack[-4] = (v1 == v2) ? 0 : ((v1 < v2) ? -1 : 1);        ostack -= 3;        DISPATCH(0, 1);    })#endif#define FCMP(TYPE, isNan)                                 \({                                                        \    int res;                                              \    TYPE v1, v2;                                          \    ostack -= sizeof(TYPE)/4; v2 = *(TYPE *)ostack;       \    ostack -= sizeof(TYPE)/4; v1 = *(TYPE *)ostack;       \    if(v1 == v2)                                          \        res = 0;                                          \    else if(v1 < v2)                                      \        res = -1;                                         \    else if(v1 > v2)                                      \         res = 1;                                         \    else                                                  \         res = isNan;                                     \    PUSH_0(res, 1);                                       \})    DEF_OPC_210(OPC_DCMPG,        FCMP(double, 1);    )    DEF_OPC_210(OPC_DCMPL,        FCMP(double, -1);    )    DEF_OPC_210(OPC_FCMPG,        FCMP(float, 1);    )    DEF_OPC_210(OPC_FCMPL,        FCMP(float, -1);    )#ifdef DIRECT    DEF_OPC_210_2(            OPC_GOTO,            OPC_GOTO_W,#else    DEF_OPC_210(OPC_GOTO,#endif        BRANCH(TRUE);    )#ifdef DIRECT    DEF_OPC_210_2(            OPC_JSR,            OPC_JSR_W,#else    DEF_OPC_210(OPC_JSR,#endif        *ostack++ = (uintptr_t)pc;        BRANCH(TRUE);    )    DEF_OPC_210(OPC_RET,        pc = (CodePntr)lvars[SINGLE_INDEX(pc)];        DISPATCH_RET(3);    )    DEF_OPC_012_2(            OPC_LRETURN,            OPC_DRETURN,#ifdef USE_CACHE        *(u8*)lvars = cache.l;#else        ostack -= 2;        *(u8*)lvars = *(u8*)ostack;#endif        lvars += 2;        goto methodReturn;    )    DEF_OPC_210(OPC_ARRAYLENGTH, {        Object *array = (Object *)*--ostack;        NULL_POINTER_CHECK(array);        PUSH_0(ARRAY_LEN(array), 1);    })    DEF_OPC_210(OPC_ATHROW, {        Object *obj = (Object *)ostack[-1];        frame->last_pc = pc;        NULL_POINTER_CHECK(obj);                        ee->exception = obj;        goto throwException;    })    DEF_OPC_210(OPC_NEWARRAY, {        int type = ARRAY_TYPE(pc);        int count = *--ostack;        Object *obj;        frame->last_pc = pc;        if((obj = allocTypeArray(type, count)) == NULL)            goto throwException;        PUSH_0((uintptr_t)obj, 2);    })    DEF_OPC_210(OPC_MONITORENTER, {        Object *obj = (Object *)*--ostack;        NULL_POINTER_CHECK(obj);        objectLock(obj);        DISPATCH(0, 1);    })    DEF_OPC_210(OPC_MONITOREXIT, {        Object *obj = (Object *)*--ostack;        NULL_POINTER_CHECK(obj);        objectUnlock(obj);        DISPATCH(0, 1);    })#ifdef DIRECT    DEF_OPC_RW(OPC_LDC, ({        int idx, cache;        Operand operand;        WITH_OPCODE_CHANGE_CP_DINDEX(OPC_LDC, idx, cache);        frame->last_pc = pc;        operand.u = resolveSingleConstant(mb->class, idx);        if(exceptionOccured0(ee))            goto throwException;        if(CP_TYPE(cp, idx) == CONSTANT_ResolvedClass ||           CP_TYPE(cp, idx) == CONSTANT_ResolvedString) {            operand.i = idx;            OPCODE_REWRITE(OPC_LDC_W_QUICK, cache, operand);        } else            OPCODE_REWRITE(OPC_LDC_QUICK, cache, operand);        REDISPATCH    });)    DEF_OPC_210(OPC_TABLESWITCH, {        SwitchTable *table = (SwitchTable*)pc->operand.pntr;        int index = *--ostack;        if(index < table->low || index > table->high)            pc = table->deflt;        else            pc = table->entries[index - table->low];        DISPATCH_SWITCH    })    DEF_OPC_210(OPC_LOOKUPSWITCH, {        LookupTable *table = (LookupTable*)pc->operand.pntr;        int key = *--ostack;        int i;        for(i = 0; (i < table->num_entries) && (key != table->entries[i].key); i++);        pc = (i == table->num_entries ? table->deflt                                      : table->entries[i].handler);        DISPATCH_SWITCH    })    DEF_OPC_RW(OPC_GETSTATIC, ({        int idx, cache;        FieldBlock *fb;        Operand operand;                       WITH_OPCODE_CHANGE_CP_DINDEX(OPC_GETSTATIC, idx, cache);        frame->last_pc = pc;        fb = resolveField(mb->class, idx);        if(exceptionOccured0(ee))            goto throwException;        operand.pntr = fb;        OPCODE_REWRITE(((*fb->type == 'J') || (*fb->type == 'D') ?                 OPC_GETSTATIC2_QUICK : OPC_GETSTATIC_QUICK), cache, operand);        REDISPATCH    });)    DEF_OPC_RW(OPC_PUTSTATIC, ({        int idx, cache;        FieldBlock *fb;        Operand operand;        WITH_OPCODE_CHANGE_CP_DINDEX(OPC_PUTSTATIC, idx, cache);        frame->last_pc = pc;        fb = resolveField(mb->class, idx);        if(exceptionOccured0(ee))            goto throwException;        operand.pntr = fb;        OPCODE_REWRITE(((*fb->type == 'J') || (*fb->type == 'D') ?                 OPC_PUTSTATIC2_QUICK : OPC_PUTSTATIC_QUICK), cache, operand);        REDISPATCH    });)    DEF_OPC_RW(OPC_GETFIELD, ({        int idx, cache;        FieldBlock *fb;        Operand operand;        WITH_OPCODE_CHANGE_CP_DINDEX(OPC_GETFIELD, idx, cache);        frame->last_pc = pc;        fb = resolveField(mb->class, idx);        if(exceptionOccured0(ee))            goto throwException;        operand.i = fb->offset;        OPCODE_REWRITE(((*fb->type == 'J') || (*fb->type == 'D') ?                  OPC_GETFIELD2_QUICK : OPC_GETFIELD_QUICK), cache, operand);        REDISPATCH    });)    DEF_OPC_RW(OPC_PUTFIELD, ({        int idx, cache;        FieldBlock *fb;        Operand operand;        WITH_OPCODE_CHANGE_CP_DINDEX(OPC_PUTFIELD, idx, cache);        frame->last_pc = pc;        fb = resolveField(mb->class, idx);        if(exceptionOccured0(ee))            goto throwException;        operand.i = fb->offset;        OPCODE_REWRITE(((*fb->type == 'J') || (*fb->type == 'D') ?                  OPC_PUTFIELD2_QUICK : OPC_PUTFIELD_QUICK), cache, operand);        REDISPATCH    });)    DEF_OPC_RW(OPC_INVOKEVIRTUAL, ({        int idx, cache;        Operand operand;        WITH_OPCODE_CHANGE_CP_DINDEX(OPC_INVOKEVIRTUAL, idx, cache);        frame->last_pc = pc;        new_mb = resolveMethod(mb->class, idx);         if(exceptionOccured0(ee))            goto throwException;        operand.uu.u1 = new_mb->args_count;        operand.uu.u2 = new_mb->method_table_index;        OPCODE_REWRITE(OPC_INVOKEVIRTUAL_QUICK, cache, operand);        REDISPATCH    });)    DEF_OPC_RW(OPC_INVOKESPECIAL, ({        int idx, cache;        Operand operand;        WITH_OPCODE_CHANGE_CP_DINDEX(OPC_INVOKESPECIAL, idx, cache);        frame->last_pc = pc;        new_mb = resolveMethod(mb->class, idx);         if(exceptionOccured0(ee))            goto throwException;        /* Check if invoking a super method... */        if((CLASS_CB(mb->class)->access_flags & ACC_SUPER) &&              ((new_mb->access_flags & ACC_PRIVATE) == 0) && (new_mb->name[0] != '<')) {            operand.i = new_mb->method_table_index;            OPCODE_REWRITE(OPC_INVOKESUPER_QUICK, cache, operand);        } else {            operand.pntr = new_mb;            OPCODE_REWRITE(OPC_INVOKENONVIRTUAL_QUICK, cache, operand);        }        REDISPATCH    });)    DEF_OPC_RW(OPC_INVOKESTATIC, ({        int idx, cache;        Operand operand;        WITH_OPCODE_CHANGE_CP_DINDEX(OPC_INVOKESTATIC, idx, cache);        frame->last_pc = pc;        new_mb = resolveMethod(mb->class, idx);         if(exceptionOccured0(ee))            goto throwException;        operand.pntr = new_mb;        OPCODE_REWRITE(OPC_INVOKESTATIC_QUICK, cache, operand);        REDISPATCH    });)    DEF_OPC_RW(OPC_INVOKEINTERFACE, ({        int idx, cache;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -