jitintrinsic.c

来自「This is a resource based on j2me embedde」· C语言 代码 · 共 866 行 · 第 1/3 页

C
866
字号
/* * @(#)jitintrinsic.c	1.13 06/10/10 * * Copyright  1990-2008 Sun Microsystems, Inc. All Rights Reserved.   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER   *    * This program is free software; you can redistribute it and/or   * modify it under the terms of the GNU General Public License version   * 2 only, as published by the Free Software Foundation.    *    * This program is distributed in the hope that it will be useful, but   * WITHOUT ANY WARRANTY; without even the implied warranty of   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   * General Public License version 2 for more details (a copy is   * included at /legal/license.txt).    *    * You should have received a copy of the GNU General Public License   * version 2 along with this work; if not, write to the Free Software   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA   * 02110-1301 USA    *    * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa   * Clara, CA 95054 or visit www.sun.com if you need additional   * information or have any questions.  * */#include "javavm/include/defs.h"#include "javavm/include/objects.h"#include "javavm/include/classes.h"#include "javavm/include/globals.h"#include "javavm/include/utils.h"#include "javavm/include/preloader.h"#include "javavm/include/jit/jit.h"#include "javavm/include/porting/jit/jit.h"#include "javavm/include/jit/jitintrinsic.h"#include "javavm/include/jit/jitirnode.h"#ifdef CVMJIT_INTRINSICS/* NOTE: #define CVM_DEBUG_INTRINSICS to turn on debugging of JIT intrinsics   processing. *//* #define CVM_DEBUG_INTRINSICS */#define CVMJIT_INTRINSIC_ERROR  ((CVMUint16)-1)/* Purpose: Fills in the intrinsics list with info from the config list.            If an entry already exists for a method, the new entry will be            ignored. */static CVMUint16fillInIntrinsicsFromConfigs(CVMExecEnv *ee,                            const CVMJITIntrinsicConfigList *clist,                            CVMJITIntrinsic *ilist,                            CVMUint16 numberOfIntrinsics){    CVMUint16 origNumberOfIntrinsics = numberOfIntrinsics;    CVMUint16 i;    for (i = 0; i < clist->numberOfConfigs; i++) {        const CVMJITIntrinsicConfig *cf = &clist->configs[i];        CVMClassTypeID classTypeID;        CVMMethodTypeID methodTypeID;        CVMClassBlock *cb;        CVMMethodBlock *mb;        CVMUint16 j;        CVMBool isStatic;        isStatic = ((cf->properties & CVMJITINTRINSIC_IS_STATIC) != 0);        /* Get the classTypeID for the intrinsic: */        classTypeID = CVMtypeidNewClassID(ee, cf->className,                                          strlen(cf->className));        if (classTypeID == CVM_TYPEID_ERROR) {            goto errorCase;        }        /* Get the methodTypeID for the intrinsic: */        methodTypeID = CVMtypeidNewMethodIDFromNameAndSig(ee,                           cf->methodName, cf->methodSignature);        if (methodTypeID == CVM_TYPEID_ERROR) {            goto errorCase;        }        for (j = 0; j < origNumberOfIntrinsics; j++) {            if ((ilist[j].classTypeID == classTypeID) &&                (ilist[j].methodTypeID == methodTypeID)) {                break;            }        }        /* NOT Found!  Add it to the list: */        if (j == origNumberOfIntrinsics) {            CVMJITIntrinsic *intrinsic;            /* We only allow intrinsic methods for classes which are loaded               with the bootclassloader.  Hence, we do the class lookup with               NULL as the classloader: */            cb = CVMclassLookupClassWithoutLoading(ee, classTypeID, NULL);            if (cb != NULL) {                mb = CVMclassGetMethodBlock(cb, methodTypeID, isStatic);                CVMassert(mb != NULL);            } else {                mb = NULL;            }            intrinsic = &ilist[numberOfIntrinsics];            intrinsic->config = cf;            intrinsic->mb = mb;            intrinsic->classTypeID = classTypeID;            intrinsic->methodTypeID = methodTypeID;            intrinsic->intrinsicID = ++numberOfIntrinsics;            intrinsic->numberOfArgs = CVMtypeidGetArgsCount(methodTypeID);            intrinsic->numberOfArgsWords = CVMtypeidGetArgsSize(methodTypeID);            if ((intrinsic->config->properties & CVMJITINTRINSIC_IS_STATIC)                == 0) {                intrinsic->numberOfArgs++;                intrinsic->numberOfArgsWords++;            }#ifdef CVM_DEBUG_ASSERTS            if (mb != NULL) {                CVMassert(CVMmbArgsSize(mb) == intrinsic->numberOfArgsWords);            }#endif            if ((intrinsic->config->properties & CVMJITINTRINSIC_ADD_CCEE_ARG)                != 0) {                intrinsic->numberOfArgsWords++;            }#ifdef CVM_DEBUG            intrinsic->configList = clist;#endif        }    }    return numberOfIntrinsics;errorCase:#ifdef CVM_DEBUG    CVMconsolePrintf("Failed to allocate a typeID when initializing JIT "                     "intrinsics\n");#endif    return CVMJIT_INTRINSIC_ERROR;}/* Purpose: Comparator used for sorting the sortedJavaIntrinsics list and the            sortedNativeIntrinsics list. */static intcompareIntrinsic(const void *v1, const void *v2){    CVMJITIntrinsic *ip1;    CVMJITIntrinsic *ip2;    CVMassert(v1 != NULL);    CVMassert(v2 != NULL);    ip1 = *(CVMJITIntrinsic **)v1;    ip2 = *(CVMJITIntrinsic **)v2;    CVMassert(ip1->mb != NULL);    CVMassert(ip2->mb != NULL);    return ((CVMInt32)ip1->mb - (CVMInt32)ip2->mb);}/* Purpose: Comparator used for sorting the sortedUnknownIntrinsics list. */static intcompareUnknownIntrinsic(const void *v1, const void *v2){    CVMJITIntrinsic *ip1;    CVMJITIntrinsic *ip2;    CVMassert(v1 != NULL);    CVMassert(v2 != NULL);    ip1 = *(CVMJITIntrinsic **)v1;    ip2 = *(CVMJITIntrinsic **)v2;    if (ip1->classTypeID == ip2->classTypeID) {        return ((CVMInt32)ip1->methodTypeID - (CVMInt32)ip2->methodTypeID);    }    return ((CVMInt32)ip1->classTypeID - (CVMInt32)ip2->classTypeID);}#if defined(CVM_DEBUG_ASSERTS) || defined(CVM_DEBUG_INTRINSICS)#ifdef CVM_DEBUG#define SETUP_ERROR() { \    if (!headerDumped) {                                  \        CVMconsolePrintf("INTRINSIC %s.%s%s from %s:\n",  \            config->className, config->methodName,        \            config->methodSignature, irec->configList->name); \        headerDumped =  CVM_TRUE;                         \    }                                                     \    errors++;                                             \}#else#define SETUP_ERROR() { \    if (!headerDumped) {                                  \        CVMconsolePrintf("INTRINSIC %s.%s%s:\n",          \            config->className, config->methodName,        \            config->methodSignature);                     \        headerDumped =  CVM_TRUE;                         \    }                                                     \    errors++;                                             \}#endifstatic int verifyIntrinsic(CVMJITIntrinsic *irec, int errors){    const CVMJITIntrinsicConfig *config = irec->config;    CVMBool headerDumped = CVM_FALSE;    CVMUint16 properties = config->properties;    CVMUint16 irnodeFlags = config->irnodeFlags;    CVMUint16 cconv, spill, stackmap, cpdump, cceearg, killcache, flushstack;    /* Verify properties: */    cconv = properties & (CVMJITINTRINSIC_OPERATOR_ARGS |#ifdef CVMJIT_INTRINSICS_HAVE_PLATFORM_SPECIFIC_REG_ARGS			  CVMJITINTRINSIC_REG_ARGS |#endif                          CVMJITINTRINSIC_C_ARGS | CVMJITINTRINSIC_JAVA_ARGS);    if (cconv == 0) {        SETUP_ERROR();        CVMconsolePrintf("Error %d: Calling convention must be "            "CVMJITINTRINSIC_OPERATOR_ARGS, CVMJITINTRINSIC_C_ARGS, or "                         "CVMJITINTRINSIC_JAVA_ARGS\n", errors);    } else if ((cconv != CVMJITINTRINSIC_OPERATOR_ARGS) &&#ifdef CVMJIT_INTRINSICS_HAVE_PLATFORM_SPECIFIC_REG_ARGS               (cconv != CVMJITINTRINSIC_REG_ARGS) &&#endif               (cconv != CVMJITINTRINSIC_C_ARGS) &&               (cconv != CVMJITINTRINSIC_JAVA_ARGS)) {        SETUP_ERROR();        CVMconsolePrintf("Error %d: Too many calling conventions specified: ",                         errors);        if ((cconv & CVMJITINTRINSIC_OPERATOR_ARGS) != 0) {            CVMconsolePrintf("   CVMJITINTRINSIC_OPERATOR_ARGS\n");        }#ifdef CVMJIT_INTRINSICS_HAVE_PLATFORM_SPECIFIC_REG_ARGS        if ((cconv & CVMJITINTRINSIC_REG_ARGS) != 0) {            CVMconsolePrintf("   CVMJITINTRINSIC_REG_ARGS\n");        }#endif        if ((cconv & CVMJITINTRINSIC_C_ARGS) != 0) {            CVMconsolePrintf("   CVMJITINTRINSIC_C_ARGS\n");        }        if ((cconv & CVMJITINTRINSIC_JAVA_ARGS) != 0) {            CVMconsolePrintf("   CVMJITINTRINSIC_JAVA_ARGS\n");        }        CVMconsolePrintf("    Only one may be specified\n");    }    spill = properties & (CVMJITINTRINSIC_NEED_MINOR_SPILL |                          CVMJITINTRINSIC_NEED_MAJOR_SPILL);    if (cconv == CVMJITINTRINSIC_OPERATOR_ARGS) {        if (spill != 0) {            SETUP_ERROR();            CVMconsolePrintf("Error %d: CVMJITINTRINSIC_NEED_MINOR_SPILL and "                "CVMJITINTRINSIC_NEED_MAJOR_SPILL not supported for "                "CVMJITINTRINSIC_OPERATOR_ARGS calling convention\n");        }    } else         if (spill == (CVMJITINTRINSIC_NEED_MINOR_SPILL |                      CVMJITINTRINSIC_NEED_MAJOR_SPILL)) {        SETUP_ERROR();        CVMconsolePrintf("Error %d: Spill requirement is ambiguous: both "            "CVMJITINTRINSIC_NEED_MINOR_SPILL and "            "CVMJITINTRINSIC_NEED_MAJOR_SPILL are specified\n",            errors);    }    stackmap = properties & (CVMJITINTRINSIC_NEED_STACKMAP |                             CVMJITINTRINSIC_NEED_EXTENDED_STACKMAP);    if (cconv == CVMJITINTRINSIC_OPERATOR_ARGS) {        if (stackmap != 0) {            SETUP_ERROR();            CVMconsolePrintf("Error %d: CVMJITINTRINSIC_NEED_STACKMAP and "                "CVMJITINTRINSIC_NEED_EXTENDED_STACKMAP not supported for "                "CVMJITINTRINSIC_OPERATOR_ARGS calling convention\n", errors);        }    } else         if (stackmap == (CVMJITINTRINSIC_NEED_STACKMAP |                         CVMJITINTRINSIC_NEED_EXTENDED_STACKMAP)) {        SETUP_ERROR();        CVMconsolePrintf("Error %d: Stackmap requirement is ambiguous: both "            "CVMJITINTRINSIC_NEED_STACKMAP and "            "CVMJITINTRINSIC_NEED_EXTENDED_STACKMAP are specified\n",            errors);    }    cpdump = properties & CVMJITINTRINSIC_CP_DUMP_OK;    if (cconv == CVMJITINTRINSIC_OPERATOR_ARGS) {        if (cpdump != 0) {            SETUP_ERROR();            CVMconsolePrintf("Error %d: CVMJITINTRINSIC_CP_DUMP_OK "                "not supported for CVMJITINTRINSIC_OPERATOR_ARGS "                "calling convention\n", errors);

⌨️ 快捷键说明

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