📄 bytecodes.c
字号:
/*0001*//*
/*0002./ * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved.
/*0003./ *
/*0004./ * This software is the confidential and proprietary information of Sun
/*0005./ * Microsystems, Inc. ("Confidential Information"). You shall not
/*0006./ * disclose such Confidential Information and shall use it only in
/*0007./ * accordance with the terms of the license agreement you entered into
/*0008./ * with Sun.
/*0009./ *
/*0010./ * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
/*0011./ * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
/*0012./ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
/*0013./ * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
/*0014./ * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
/*0015./ * THIS SOFTWARE OR ITS DERIVATIVES.
/*0016./ *
/*0017./ */
/*0018*/
/*0019*//*=========================================================================
/*0020./ * SYSTEM: KVM
/*0021./ * SUBSYSTEM: Bytecode interpreter
/*0022./ * FILE: bytecodes.c
/*0023./ * OVERVIEW: This file defines the implementation of each of the
/*0024./ * Java bytecodes.
/*0025./ * The code has been separated from interpret.c so that we
/*0026./ * can more easily use different kinds of interpretation
/*0027./ * techniques and customize the VM to use sub/supersets
/*0028./ * of bytecodes.
/*0029./ * AUTHOR: Rewritten for better performance and customizability
/*0030./ * by Nik Shaylor 9/5/2000
/*0031./ *=======================================================================*/
/*0032*/
/*0033*/
/*0034*//* --------------------------------------------------------------------- */
/*0035*/
/*0036*/#if STANDARDBYTECODES
/*0037*/SELECT(NOP) /* Do nothing */
/*0038*/DONE(1)
/*0039*/#endif
//\\case NOP:
//\\ {
//\\ }
//\\ goto next1;
/*0040*/
/*0041*//* --------------------------------------------------------------------- */
/*0042*/
/*0043*/#if STANDARDBYTECODES
/*0044*/SELECT(ACONST_NULL) /* Push null reference onto the operand stack */
/*0045*/ pushStack(0);
/*0046*/DONE(1)
/*0047*/#endif
//\\case ACONST_NULL:
//\\ {
//\\ *++sp = 0;
//\\ }
//\\ goto next1;
/*0048*/
/*0049*//* --------------------------------------------------------------------- */
/*0050*/
/*0051*/#if STANDARDBYTECODES
/*0052*/SELECT(ICONST_M1) /* Push null reference onto the operand stack */
/*0053*/ pushStack(-1);
/*0054*/DONE(1)
/*0055*/#endif
/*0056*/
/*0057*//* --------------------------------------------------------------------- */
/*0058*/
/*0059*/#if STANDARDBYTECODES
/*0060*/SELECT(ICONST_0) /* Push integer constant 0 onto the operand stack */
/*0061*/ pushStack(0);
/*0062*/DONE(1)
/*0063*/#endif
/*0064*/
/*0065*//* --------------------------------------------------------------------- */
/*0066*/
/*0067*/#if STANDARDBYTECODES
/*0068*/SELECT(ICONST_1) /* Push integer constant 1 onto the operand stack */
/*0069*/ pushStack(1);
/*0070*/DONE(1)
/*0071*/#endif
/*0072*/
/*0073*//* --------------------------------------------------------------------- */
/*0074*/
/*0075*/#if STANDARDBYTECODES
/*0076*/SELECT(ICONST_2) /* Push integer constant 2 onto the operand stack */
/*0077*/ pushStack(2);
/*0078*/DONE(1)
/*0079*/#endif
/*0080*/
/*0081*//* --------------------------------------------------------------------- */
/*0082*/
/*0083*/#if STANDARDBYTECODES
/*0084*/SELECT(ICONST_3) /* Push integer constant 3 onto the operand stack */
/*0085*/ pushStack(3);
/*0086*/DONE(1)
/*0087*/#endif
/*0088*/
/*0089*//* --------------------------------------------------------------------- */
/*0090*/
/*0091*/#if STANDARDBYTECODES
/*0092*/SELECT(ICONST_4) /* Push integer constant 4 onto the operand stack */
/*0093*/ pushStack(4);
/*0094*/DONE(1)
/*0095*/#endif
/*0096*/
/*0097*//* --------------------------------------------------------------------- */
/*0098*/
/*0099*/#if STANDARDBYTECODES
/*0100*/SELECT(ICONST_5) /* Push integer constant 5 onto the operand stack */
/*0101*/ pushStack(5);
/*0102*/DONE(1)
/*0103*/#endif
/*0104*/
/*0105*//* --------------------------------------------------------------------- */
/*0106*/
/*0107*/#if STANDARDBYTECODES
/*0108*/SELECT(LCONST_0) /* Push long integer constant 0 onto the operand stack */
/*0109*/ oneMore;
/*0110*/ ((long *)sp)[0] = 0;
/*0111*/ ((long *)sp)[1] = 0;
/*0112*/ oneMore;
/*0113*/DONE(1)
/*0114*/#endif
//\\case LCONST_0:
//\\ {
//\\ sp++;
//\\ ((long *)sp)[0] = 0;
//\\ ((long *)sp)[1] = 0;
//\\ sp++;
//\\ }
//\\ goto next1;
/*0115*/
/*0116*//* --------------------------------------------------------------------- */
/*0117*/
/*0118*/#if STANDARDBYTECODES
/*0119*/SELECT(LCONST_1) /* Push long integer constant 1 onto the operand stack */
/*0120*/ oneMore;
/*0121*/#if BIG_ENDIAN
/*0122*/ ((long *)sp)[0] = 0;
/*0123*/ ((long *)sp)[1] = 1;
/*0124*/#elif LITTLE_ENDIAN || !COMPILER_SUPPORTS_LONG
/*0125*/ ((long *)sp)[0] = 1;
/*0126*/ ((long *)sp)[1] = 0;
/*0127*/#else
/*0128*/ SET_LONG(sp, (ulong64)(1));
/*0129*/#endif
/*0130*/ oneMore;
/*0131*/DONE(1)
/*0132*/#endif
/*0133*/
/*0134*//* --------------------------------------------------------------------- */
/*0135*/
/*0136*/#if FLOATBYTECODES
/*0137*/SELECT(FCONST_0) /* Push float constant 0 onto the operand stack */
/*0138*/ oneMore;
/*0139*/ *(float*)sp = 0.0f;
/*0140*/DONE(1)
/*0141*/#endif
/*0142*/
/*0143*//* --------------------------------------------------------------------- */
/*0144*/
/*0145*/#if FLOATBYTECODES
/*0146*/SELECT(FCONST_1) /* Push float constant 1 onto the operand stack */
/*0147*/ oneMore;
/*0148*/ *(float*)sp = 1.0f;
/*0149*/DONE(1)
/*0150*/#endif
/*0151*/
/*0152*//* --------------------------------------------------------------------- */
/*0153*/
/*0154*/#if FLOATBYTECODES
/*0155*/SELECT(FCONST_2) /* Push float constant 2 onto the operand stack */
/*0156*/ oneMore;
/*0157*/ *(float*)sp = 2.0f;
/*0158*/DONE(1)
/*0159*/#endif
/*0160*/
/*0161*//* --------------------------------------------------------------------- */
/*0162*/
/*0163*/#if FLOATBYTECODES
/*0164*/SELECT(DCONST_0) /* Push double float constant 0 onto the operand stack */
/*0165*/ oneMore;
/*0166*/ SET_DOUBLE(sp, 0.0);
/*0167*/ oneMore;
/*0168*/DONE(1)
/*0169*/#endif
/*0170*/
/*0171*//* --------------------------------------------------------------------- */
/*0172*/
/*0173*/#if FLOATBYTECODES
/*0174*/SELECT(DCONST_1) /* Push double float constant 1 onto the operand stack */
/*0175*/ oneMore;
/*0176*/ SET_DOUBLE(sp, 1.0);
/*0177*/ oneMore;
/*0178*/DONE(1)
/*0179*/#endif
/*0180*/
/*0181*//* --------------------------------------------------------------------- */
/*0182*/
/*0183*/#if STANDARDBYTECODES
/*0184*/SELECT(BIPUSH) /* Push byte constant onto the operand stack */
/*0185*/ int i = ((signed char *)ip)[1];
/*0186*/ pushStack(i);
/*0187*/DONE(2)
/*0188*/#endif
//\\case BIPUSH:
//\\ {
//\\ int i = ((signed char *)ip)[1];
//\\ *++sp = i;
//\\ }
//\\ goto next2;
/*0189*/
/*0190*//* --------------------------------------------------------------------- */
/*0191*/
/*0192*/#if STANDARDBYTECODES
/*0193*/SELECT(SIPUSH) /* Push short constant onto the operand stack */
/*0194*/ short s = getShort(ip + 1);
/*0195*/ pushStack((int)s); /* Extends sign for negative numbers */
/*0196*/DONE(3)
/*0197*/#endif
/*0198*/
/*0199*//* --------------------------------------------------------------------- */
/*0200*/
/*0201*/#if STANDARDBYTECODES
/*0202*/SELECT(LDC) /* Push item from constant pool onto the operand stack */
/*0203*/ unsigned int cpIndex = ip[1];
/*0204*/ CONSTANTPOOL_ENTRY thisEntry = &cp->entries[cpIndex];
/*0205*/ pushStack(thisEntry->integer);
/*0206*/DONE(2)
/*0207*/#endif
//\\case LDC:
//\\ {
//\\ unsigned int cpIndex = ip[1]; //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -