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

📄 execute.c

📁 This is a java virtual machine implement in c
💻 C
📖 第 1 页 / 共 2 页
字号:
/*0284./ * OVERVIEW:      Calls the real Interpret() and prints out the
/*0285./ *                instrumentation results
/*0286./ * INTERFACE:
/*0287./ *   parameters:  <none>
/*0288./ *   returns:     <nothing>
/*0289./ *=======================================================================*/
/*0290*/
/*0291*/void Interpret() {
/*0292*/    CurrentNativeMethod = NULL;
/*0293*/    START_TEMPORARY_ROOTS
/*0294*/        IS_TEMPORARY_ROOT(thisObjectGCSafe, NULL);
/*0295*/        FastInterpret();
/*0296*/    END_TEMPORARY_ROOTS
/*0311*/}
/*0312*/
/*0313*//*=========================================================================
/*0314./ * FUNCTION:      Interpret()
/*0315./ * TYPE:          public global operation
/*0316./ * OVERVIEW:      Execute bytecode.
/*0317./ * INTERFACE:
/*0318./ *   parameters:  <none>
/*0319./ *   returns:     <nothing>
/*0320./ *
/*0321./ * NOTES:         Remember to initialize all virtual machine registers
/*0322./ *                and the call stack before entering the interpreter.
/*0323./ *=======================================================================*/
/*0324*/
/*0325*/#if !ALTERNATIVE_FAST_INTERPRETER //\\癸莱599︽
/*0326*/void FastInterpret() {
/*0327*/
/*0328*/   /*
/*0329./    * Define as locals those machine registers that are appropriate.
/*0330./    * Typically you get a lot of bang for the buck simply by making
/*0331./    * ip and sp local, but if you can make all the VM registers 
/*0332./    * (ip, sp, lp, fp and cp) local, that's even better.
/*0333./    */
/*0334*/
/*0335*/#if IPISLOCAL
/*0336*/#undef ip
/*0337*/    register BYTE* ip; /*  Instruction pointer (program counter) */
/*0338*/#endif
/*0339*/
/*0340*/#if SPISLOCAL
/*0341*/#undef sp
/*0342*/    register cell* sp; /*  Execution stack pointer */
/*0343*/#endif
/*0344*/
/*0345*/#if LPISLOCAL
/*0346*/#undef lp
/*0347*/    register cell* lp; /*  Local variable pointer */
/*0348*/#endif
/*0349*/
/*0350*/#if FPISLOCAL
/*0351*/#undef fp
/*0352*/    register FRAME fp; /*  Current frame pointer */
/*0353*/#endif
/*0354*/
/*0355*/#if CPISLOCAL
/*0356*/#undef cp
/*0357*/    register CONSTANTPOOL  cp; /*  Constant pool pointer */
/*0358*/#endif
/*0359*/
/*0364*/   /*
/*0365./    * Define other local variables
/*0366./    */
/*0367*/
/*0368*/#if NEED_LONG_ALIGNMENT || NEED_DOUBLE_ALIGNMENT
/*0369*/    Java8 tdub;
/*0370*/#endif
/*0371*/    METHOD   thisMethod;
/*0372*/    OBJECT   thisObject;
/*0373*/    int      invokerSize;
/*0374*/    const char *exception;
/*0375*/
/*0376*/    VMRESTORE  /** Restore virtual machine registers to local variables **/
/*0377*/
/*0381*/    goto next0;
/*0383*/
/*0384*//*************************************************************************
/*0385./ *                  Top of the actual interpreter loop                   *
/*0386./ *************************************************************************/
/*0387*/
/*0388*/   /*
/*0389./    * If RESCHEDULEATBRANCH is not defined then we always test for thread
/*0390./    * scheduling before every bytecode. This is like in KVM 1.0 version.
/*0391./    */
/*0392*/
/*0393*/#if !RESCHEDULEATBRANCH
/*0394*/next3:  ip++;
/*0395*/next2:  ip++;
/*0396*/next1:  ip++;
/*0397*/next0:
/*0398*/reschedulePoint:
/*0399*/    RESCHEDULE
/*0400*/#endif
/*0401*/
/*0402*/   /*
/*0403./    * If RESCHEDULEATBRANCH is defined then we only test for thread
/*0404./    * scheduling when reschedulePoint is called.
/*0405./    */
/*0406*/
/*0407*/#if RESCHEDULEATBRANCH
/*0408*/reschedulePoint:
/*0409*/    RESCHEDULE
/*0413*/    goto next0;
/*0415*/
/*0416*/next3:  ip++;
/*0417*/next2:  ip++;
/*0418*/next1:  ip++;
/*0419*/next0:
/*0429*/#endif /* RESCHEDULEATBRANCH */
/*0430*/
/*0447*/   /*
/*0448./    *  Extreme debug option to call the garbage collector before every bytecode
/*0449./    */
/*0450*/    DO_VERY_EXCESSIVE_GARBAGE_COLLECTION
/*0451*/
/*0452*/   /*
/*0453./    * Dispatch the bytecode
/*0454./    */
/*0458*/    switch (((unsigned char)*ip)) {
/*0460*/
/*0461*//*=======================================================================*/
/*0462*//*      Include the bytecode definitions we need for this function       */
/*0463*//*=======================================================================*/
/*0464*/
/*0465*/#define STANDARDBYTECODES 1
/*0466*/#define FLOATBYTECODES    IMPLEMENTS_FLOAT
/*0467*/#define FASTBYTECODES     ENABLEFASTBYTECODES
/*0468*/#if SPLITINFREQUENTBYTECODES
/*0469*/#define INFREQUENTSTANDARDBYTECODES 0
/*0470*/#else
/*0471*/#define INFREQUENTSTANDARDBYTECODES 1
/*0472*/#endif
/*0473*/#include "bytecodes.c"
/*0474*/#undef STANDARDBYTECODES
/*0475*/#undef FLOATBYTECODES
/*0476*/#undef FASTBYTECODES
/*0477*/#undef INFREQUENTSTANDARDBYTECODES
/*0478*/
/*0479*//*=======================================================================*/
/*0480*/
/*0481*/   /*
/*0482./    * If COMMONBRANCHING is defined then include the code to load ip
/*0483./    * See the BRANCHIF macro
/*0484./    */
/*0485*/#if COMMONBRANCHING
/*0486*/        branchPoint: {
/*0488*/            ip += getShort(ip + 1);
/*0489*/            goto reschedulePoint;
/*0490*/        }
/*0491*/#endif
/*0492*/
/*0493*/        callMethod_interface:
/*0494*/            invokerSize = 5;       /* Size of the bytecode */
/*0495*/            goto callMethod_general;
/*0496*/
/*0497*/        callMethod_virtual:
/*0498*/        callMethod_static:
/*0499*/        callMethod_special:
/*0500*/            invokerSize = 3;       /* Size of the bytecode */
/*0501*/
/*0502*/        callMethod_general: {
/*0503*/            int res;
/*0506*/
/*0507*/            /*  Check if the method is a native method */
/*0508*/            if (thisMethod->accessFlags & ACC_NATIVE) {
/*0509*/                ip += invokerSize;
/*0510*/                VMSAVE
/*0511*/                invokeNativeFunction(thisMethod);
/*0512*/                VMRESTORE
/*0514*/                goto reschedulePoint;
/*0515*/            }
/*0516*/
/*0517*/            if (thisMethod->accessFlags & ACC_ABSTRACT) {
/*0518*/                fatalError(KVM_MSG_ABSTRACT_METHOD_INVOKED);
/*0519*/            }
/*0520*/
/*0521*/            thisObjectGCSafe = thisObject;
/*0522*/            VMSAVE
/*0523*/                res = pushFrame(thisMethod);
/*0524*/            VMRESTORE
/*0525*/
/*0526*/            if (res) {
/*0527*/                /* Advance to next inst on return */
/*0528*/                fp->previousIp += invokerSize;
/*0529*/
/*0530*/            }
/*0531*/            if (res) {
/*0532*/                if (thisMethod->accessFlags & ACC_SYNCHRONIZED) {
/*0533*/                    VMSAVE
/*0534*/                        monitorEnter(thisObjectGCSafe);
/*0535*/                    VMRESTORE
/*0536*/                    fp->syncObject = thisObjectGCSafe;
/*0537*/                }
/*0538*/            }
/*0539*/            thisObjectGCSafe = NULL;
/*0540*/            goto reschedulePoint;
/*0541*/        }
/*0542*/
/*0543*/#if SPLITINFREQUENTBYTECODES
/*0544*/        callSlowInterpret: {
/*0545*/            int __token = TOKEN;
/*0546*/            VMSAVE
/*0547*/            SlowInterpret(__token);
/*0548*/            VMRESTORE
/*0549*/            goto reschedulePoint;        /* test for rescheduling */
/*0550*/        }
/*0551*/#endif
/*0552*/
/*0553*/        handleNullPointerException: {
/*0554*/            exception = NullPointerException;
/*0555*/            goto handleException;
/*0556*/        }
/*0557*/
/*0558*/        handleArrayIndexOutOfBoundsException: {
/*0559*/            exception = ArrayIndexOutOfBoundsException;
/*0560*/            goto handleException;
/*0561*/        }
/*0562*/
/*0563*/        handleArithmeticException: {
/*0564*/            exception = ArithmeticException;
/*0565*/            goto handleException;
/*0566*/        }
/*0567*/
/*0568*/        handleArrayStoreException: {
/*0569*/            exception = ArrayStoreException;
/*0570*/            goto handleException;
/*0571*/        }
/*0572*/
/*0573*/        handleClassCastException: {
/*0574*/            exception = ClassCastException;
/*0575*/            goto handleException;
/*0576*/        }
/*0577*/
/*0578*/        handleException: {
/*0579*/            VMSAVE
/*0580*/            raiseException(exception);
/*0581*/            VMRESTORE
/*0582*/            goto reschedulePoint;
/*0583*/        }
/*0584*/
/*0585*/#if PADTABLE
/*0586*/        notImplemented:
/*0587*/#endif
/*0588*/
/*0589*/        default: {
/*0590*/            sprintf(str_buffer, KVM_MSG_ILLEGAL_BYTECODE_1LONGPARAM, 
/*0591*/                    (long)TOKEN);
/*0592*/            fatalError(str_buffer);
/*0593*/            break;
/*0594*/        }
/*0595*/    }
/*0596*/    fatalError(KVM_MSG_INTERPRETER_STOPPED);
/*0597*/}
/*0598*/
/*0599*/#endif /* ALTERNATIVE_FAST_INTERPRETER */
/*0600*/
/*0601*/

⌨️ 快捷键说明

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