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

📄 nativecore.c

📁 Nucleus_2_kvm_Hello 是kvm移植到Nucleus系统的源代码。。。好东西啊
💻 C
📖 第 1 页 / 共 4 页
字号:
/* * 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: Native function interface * FILE:      nativeCore.c * OVERVIEW:  This file defines the native functions needed *            by the Java virtual machine. The implementation *            is _not_ based on JNI (Java Native Interface), *            because JNI seems too expensive for small devices. * AUTHOR:    Antero Taivalsaari, Sun Labs, 1998 *            Edited by Doug Simon 11/1998 *            Frank Yellin *=======================================================================*//*========================================================================= * Include files *=======================================================================*/#include "global.h"/*========================================================================= * FUNCTION:      getClass()Ljava/lang/Class (VIRTUAL) * CLASS:         java.lang.Object * TYPE:          virtual native function (reflection) * OVERVIEW:      Return the class object of the given object * INTERFACE (operand stack manipulation): *   parameters:  an object instance ('this') *   returns:     a class object * NOTE:          Current implementation does not create array *                classes yet, so arrays return JavaLangObject. *=======================================================================*/void Java_java_lang_Object_getClass(void){    topStackAsType(CLASS) = topStackAsType(OBJECT)->ofClass;}/*========================================================================= * FUNCTION:      hashCode()I, identityHashCode()I (VIRTUAL) * CLASS:         java.lang.Object, java.lang.System * TYPE:          virtual native function * OVERVIEW:      Generate a unique hash code for an object. * INTERFACE (operand stack manipulation): *   parameters:  this *   returns:     hash code *=======================================================================*/void Java_java_lang_Object_hashCode(void){    /* The following must be two lines:     * objectHashCode can GC, and a compiler is allowed to assume that the     * value of sp hasn't changed if it is all on one line.     */    OBJECT object = popStackAsType(OBJECT);    long result = objectHashCode(object); /* this may GC */    pushStack(result);}void Java_java_lang_System_identityHashCode(void){    OBJECT object = popStackAsType(OBJECT);    long result = object == NULL ? 0 : objectHashCode(object); /* this may GC */    pushStack(result);}/*========================================================================= * FUNCTION:      notify()V (VIRTUAL) * CLASS:         java.lang.Object * TYPE:          virtual native function * OVERVIEW:      Release the first thread in the object's monitor. * INTERFACE (operand stack manipulation): *   parameters:  an object instance ('this') *   returns:     <nothing> * NOTE:          This operation does nothing *                if the current thread is not the owner of the monitor. *=======================================================================*/void Java_java_lang_Object_notify(void){    OBJECT object = popStackAsType(OBJECT);    monitorNotify(object, FALSE);}/*========================================================================= * FUNCTION:      notifyAll()V (VIRTUAL) * CLASS:         java.lang.Object * TYPE:          virtual native function * OVERVIEW:      Release all threads in the object's monitor. * INTERFACE (operand stack manipulation): *   parameters:  an object instance ('this') *   returns:     <nothing> * NOTE:          This operation does nothing *                if the current thread is not the owner of the monitor. *=======================================================================*/void Java_java_lang_Object_notifyAll(void){    OBJECT object = popStackAsType(OBJECT);    monitorNotify(object, TRUE);}/*========================================================================= * FUNCTION:      wait()V (VIRTUAL) * CLASS:         java.lang.Object * TYPE:          virtual native function * OVERVIEW:      Wait in the object's monitor forever. * INTERFACE (operand stack manipulation): *   parameters:  an object instance ('this'). *   returns:     <nothing> * NOTE:          This operation should throw IllegalMonitorState- *                Exception if the current thread is not the owner of *                the monitor. Other possible exceptions are: *                IllegalArgumentException, InterruptedException. *=======================================================================*/void Java_java_lang_Object_wait(void){    long64  period;    OBJECT object;    popLong(period);    object = popStackAsType(OBJECT);    /* only block if the time period is not zero */    if (ll_zero_ge(period)) {        monitorWait(object, period);    } else {        raiseException("java/lang/IllegalArgumentException");    }}/*========================================================================= * Native functions of class java.lang.Math *=======================================================================*//*========================================================================= * FUNCTION:      randomInt()I (STATIC) * CLASS:         java.lang.Math * TYPE:          static native function * OVERVIEW:      Return a random integer value * INTERFACE (operand stack manipulation): *   parameters:  none *   returns:     random integer *=======================================================================*/void Java_java_lang_Math_randomInt(void){    long result = RandomNumber_md();    pushStack(result);}/*========================================================================= * Native functions of class java.lang.Class *=======================================================================*//*========================================================================= * FUNCTION:      isInterface()B (VIRTUAL) * CLASS:         java.lang.Class * TYPE:          virtual native function * OVERVIEW:      Return true if the class is an interface class. * INTERFACE (operand stack manipulation): *   parameters:  'this' pointer *   returns:     Boolean indicating if the class is an interface. *=======================================================================*/void Java_java_lang_Class_isInterface(void){    CLASS clazz = topStackAsType(CLASS);    topStack = ((clazz->accessFlags & ACC_INTERFACE) != 0);}/*========================================================================= * FUNCTION:      isPrimitive()B (VIRTUAL) * CLASS:         java.lang.Class * TYPE:          virtual native function * OVERVIEW:      Return true if the class is a primitive class. * INTERFACE (operand stack manipulation): *   parameters:  'this' pointer *   returns:     Boolean indicating if the class is a primitive class. *=======================================================================*/void Java_java_lang_Class_isPrimitive(void){    topStack = FALSE; /* We do not support this feature */}/*========================================================================= * FUNCTION:      forName(Ljava/lang/String;)Ljava/lang/Class; (STATIC) * CLASS:         java.lang.Class * TYPE:          static native function (reflection) * OVERVIEW:      Given a string containing a class name (e.g., *                "java.lang.Thread", return the corresponding *                class object. * INTERFACE (operand stack manipulation): *   parameters:  a string object *   returns:     a class object *=======================================================================*/void Java_java_lang_Class_forName(void){    START_TEMPORARY_ROOTS        DECLARE_TEMPORARY_ROOT(STRING_INSTANCE, string,                                topStackAsType(STRING_INSTANCE));            if (string == NULL) {            raiseException(NullPointerException);        } else {            long length = string->length;            CLASS thisClass = NULL;            DECLARE_TEMPORARY_ROOT(char*, className, mallocBytes(length + 1));            getStringContentsSafely(string, className, length + 1);            if (strchr(className, '/') == NULL) {                replaceLetters(className,'.','/');                if (verifyName(className, LegalClass, FALSE)) {                    thisClass =                         getClassX((CONST_CHAR_HANDLE)&className, 0, length);                    /* The specification does not require that the current                     * class have "access" to thisClass */                }            }            if (thisClass != NULL) {                topStackAsType(CLASS) = thisClass;                if (!IS_ARRAY_CLASS(thisClass)) {                    if (!CLASS_INITIALIZED((INSTANCE_CLASS)thisClass)) {                        initializeClass((INSTANCE_CLASS)thisClass);                    }                }            } else {                 raiseExceptionMsg("java/lang/ClassNotFoundException",                                   string);            }        }    END_TEMPORARY_ROOTS}/*========================================================================= * FUNCTION:      newInstance()Ljava/lang/Object; (VIRTUAL) * CLASS:         java.lang.Class * TYPE:          virtual native function (reflection) * OVERVIEW:      Instantiate an object of the given class * INTERFACE (operand stack manipulation): *   parameters:  'this' *   returns:     an instance of the class represented by 'this' * NOTE:          Current implementation does not create array *                classes properly. *=======================================================================*/static voidnewInstanceReturnObject(FRAME_HANDLE exceptionFrameH){    if (exceptionFrameH == NULL) {        popFrame();    } else {        /* We have no interest in dealing with exceptions */    }}void Java_java_lang_Class_newInstance(void){    INSTANCE_CLASS currentClass = getFP()->thisMethod->ofClass;    CLASS clazz = topStackAsType(CLASS);    if (IS_ARRAY_CLASS(clazz)        || ((clazz->accessFlags & (ACC_INTERFACE | ACC_ABSTRACT)) != 0)) {        raiseException("java/lang/InstantiationException");        return;    }    if (classHasAccessToClass(currentClass, clazz)) {        METHOD method = lookupMethod(clazz, initNameAndType, currentClass);        if (   (method != NULL)            && (method->ofClass == (INSTANCE_CLASS)clazz)               /* I don't understand why, but we're not allowed access to                * a protected <init> method of a superclass. */            && classHasAccessToMember(currentClass,                    (method->accessFlags & ~ACC_PROTECTED),                   (INSTANCE_CLASS)clazz, (INSTANCE_CLASS)clazz)            )        {            START_TEMPORARY_ROOTS                DECLARE_TEMPORARY_ROOT(INSTANCE, object,                                       instantiate((INSTANCE_CLASS)clazz));                if (object != NULL) {                    /*  Put the result back on the stack */                    topStackAsType(INSTANCE) = object; /* Will get the result */                    /* We now need to call the initializer.  We'd like to just                     * push a second copy of the object onto the stack, and then                     * do pushFrame(method).  But we can't, because that would                     * not necessarily coincide with the stack map of the                     * current method.                     */                    pushFrame(RunCustomCodeMethod);                    pushStackAsType(CustomCodeCallbackFunction,                                    newInstanceReturnObject);                    pushStackAsType(INSTANCE, object);                    /* pushFrame may signal a stack overflow.  */                    pushFrame(method);

⌨️ 快捷键说明

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