📄 execute.c
字号:
/* * Copyright (c) 1998-2002 Sun Microsystems, Inc. All Rights Reserved. * * This software is the confidential and proprietary information of Sun * Microsystems, Inc. ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Sun. * * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING * THIS SOFTWARE OR ITS DERIVATIVES. * * Use is subject to license terms. *//*========================================================================= * SYSTEM: KVM * SUBSYSTEM: Bytecode interpreter * FILE: execute.c * OVERVIEW: This file defines the interpreter execution loop. * The interpreter was completely restructured for * KVM 1.0.2. This file defines the heart of the * interpreter, while the actual bytecode definitions * are located in file bytecodes.c. * AUTHOR: Major reorganization by Nik Shaylor 9/5/2000 *=======================================================================*//*========================================================================= * Local include files *=======================================================================*/#include "global.h"#include "execute.h"/*========================================================================= * Redefine the Virtual Machine global registers *=======================================================================*/#define ip ip_global#define fp fp_global#define sp sp_global#define lp lp_global#define cp cp_global#undef getIP#define getIP() (ip)#undef getFP#define getFP() (fp)#undef getSP#define getSP() (sp)#undef getLP#define getLP() (lp)#undef getCP#define getCP() (cp)#undef setIP#define setIP(x) (ip = (x))#undef setFP#define setFP(x) (fp = (x))#undef setSP#define setSP(x) (sp = (x))#undef setLP#define setLP(x) (lp = (x))#undef setCP#define setCP(x) (cp = (x))/*========================================================================= * Instrumentation counters *=======================================================================*/#if INSTRUMENTint calls;int reshed;int bytecodes;int slowcodes;int branches;#endif/************************************************************************* * Start of infrequent bytecodes option * *************************************************************************/OBJECT thisObjectGCSafe = NULL;#if SPLITINFREQUENTBYTECODES/*========================================================================= * VMSAVE - Save the VM state *=======================================================================*/#define VMSAVE /**//*========================================================================= * VMRESTORE - Restore the VM state *=======================================================================*/#define VMRESTORE /**//*========================================================================= * TOKEN - Macro to get the current bytecode *=======================================================================*/#define TOKEN token/*========================================================================= * FUNCTION: SlowInterpret() * TYPE: private operation * OVERVIEW: Execute bytecode (infrequently used Java bytecodes). * INTERFACE: * parameters: The bytecode to be executed * returns: <nothing> * * NOTES: * This function is called by the main Interpret() loop when the * main loop does not contain the code for a specific bytecode. * There are two reasons for this. First, the main loop runs using * local copies of the main interpreter variables (ip, sp, etc.) and * when a routine needs to be called that requires access to these * variables via global memory, then the local copies are written * back to their global counterpoints, and this routine is called * to re-dispatch the bytecode in global context. Second, any * infrequently executed bytecodes are normally put here to make * the main interpreter loop as small as possible -- by doing this * the C compiler will often optimize the main loop better. *=======================================================================*/void SlowInterpret(ByteCode token) { METHOD thisMethod; OBJECT thisObject; const char *exception; int invokerSize; INC_SLOWCODES switch (token) {/*=======================================================================*//* Include the bytecode definitions we need for this function *//*=======================================================================*/#if !ALTERNATIVE_FAST_INTERPRETER#define STANDARDBYTECODES 0#define FLOATBYTECODES 0#define FASTBYTECODES 0#define INFREQUENTSTANDARDBYTECODES 1#else#define STANDARDBYTECODES 0#define FLOATBYTECODES IMPLEMENTS_FLOAT#define FASTBYTECODES ENABLEFASTBYTECODES#define INFREQUENTSTANDARDBYTECODES 1#endif#include "bytecodes.c"#undef STANDARDBYTECODES#undef FLOATBYTECODES#undef FASTBYTECODES#undef INFREQUENTSTANDARDBYTECODES/*=======================================================================*/#if COMMONBRANCHING branchPoint: { INC_BRANCHES ip += getShort(ip + 1); goto reschedulePoint; }#endif callMethod_interface: { invokerSize = 5; /* Size of the bytecode */ goto callMethod_general; } callMethod_virtual: callMethod_static: callMethod_special: invokerSize = 3; /* Size of the bytecode */ callMethod_general: { int res; INC_CALLS /* Check if the method is a native method */ if (thisMethod->accessFlags & ACC_NATIVE) { ip += invokerSize; invokeNativeFunction(thisMethod); TRACE_METHOD_EXIT(thisMethod) goto reschedulePoint; } if (thisMethod->accessFlags & ACC_ABSTRACT) { fatalError(KVM_MSG_ABSTRACT_METHOD_INVOKED); } /* Create an execution frame for executing a Java method */ thisObjectGCSafe = thisObject; res = pushFrame(thisMethod); if (res) { fp->previousIp += invokerSize; } if (res) { if (thisMethod->accessFlags & ACC_SYNCHRONIZED) { monitorEnter(thisObjectGCSafe); fp->syncObject = thisObjectGCSafe; } } thisObjectGCSafe = NULL; goto reschedulePoint; } handleNullPointerException: { raiseException(NullPointerException); goto reschedulePoint; } handleArrayIndexOutOfBoundsException: { exception = ArrayIndexOutOfBoundsException; goto handleException; } handleArithmeticException: { exception = ArithmeticException; goto handleException; } handleArrayStoreException: { exception = ArrayStoreException; goto handleException; } handleClassCastException: { raiseException(ClassCastException); goto reschedulePoint; } handleJavaLangError: { exception = JavaLangError_name; goto handleException; } handleException: { VMSAVE raiseException(exception); VMRESTORE goto reschedulePoint; } default: { sprintf(str_buffer, KVM_MSG_ILLEGAL_BYTECODE_1LONGPARAM, (long)token); fatalError(str_buffer); break; } }#if PADTABLE notImplemented:#endif fatalError(KVM_MSG_SLOWINTERPRETER_STOPPED);#if !ALTERNATIVE_FAST_INTERPRETERnext3: ip+=3;#elsenext3: ip++;next2: ip++;next1: ip++;#endifnext0:reschedulePoint: return;}/*========================================================================= * Undefine the macros we needed just for this function *=======================================================================*/#undef VMSAVE#undef VMRESTORE#undef TOKEN#endif /* SPLITINFREQUENTBYTECODES *//************************************************************************* * End of infrequent bytecodes option * *************************************************************************//************************************************************************* * Start of regular bytecodes processing * *************************************************************************//*========================================================================= * VMSAVE - Save the VM state *=======================================================================*/#define VMSAVE { \ SAVEIP \ SAVEFP \ SAVESP \ SAVELP \ SAVECP \}/*========================================================================= * VMRESTORE - Restore the VM state *=======================================================================*/#define VMRESTORE { \ RESTOREIP \ RESTOREFP \ RESTORESP \ RESTORELP \ RESTORECP \}/*========================================================================= * TOKEN - Macro to get the current bytecode *=======================================================================*/#if ENABLE_JAVA_DEBUGGER#define TOKEN token#else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -