📄 nativecore.c
字号:
} else { /* We will already have thrown an appropriate error */ } END_TEMPORARY_ROOTS return; } } raiseException("java/lang/IllegalAccessException"); return;}/*========================================================================= * FUNCTION: getName()Ljava/lang/String; (VIRTUAL) * CLASS: java.lang.Class * TYPE: virtual native function * OVERVIEW: Return the name of the class as a string. * INTERFACE (operand stack manipulation): * parameters: 'this' pointer * returns: Name of the class as a string. *=======================================================================*/void Java_java_lang_Class_getName(void){ CLASS clazz = topStackAsType(CLASS); START_TEMPORARY_ROOTS DECLARE_TEMPORARY_ROOT(char*, name, getClassName((CLASS)clazz)); STRING_INSTANCE result; char *ptr = strchr(name, '/'); /* Replace all slashes in the string with dots */ while (ptr != NULL) { *ptr = '.'; ptr = strchr(ptr + 1, '/'); } result = instantiateString(name, strlen(name)); topStackAsType(STRING_INSTANCE) = result; END_TEMPORARY_ROOTS}/*========================================================================= * FUNCTION: isArray()Z (VIRTUAL) * CLASS: java.lang.Class * TYPE: virtual native function * OVERVIEW: true if the class is an array class * INTERFACE (operand stack manipulation): * parameters: 'this' pointer * returns: true if the object is an instance. *=======================================================================*/void Java_java_lang_Class_isArray(void){ CLASS clazz = topStackAsType(CLASS); topStack = !!IS_ARRAY_CLASS(clazz); /* Double negation is intentional */}/*========================================================================= * FUNCTION: isInstance(Ljava/lang/Object;)Z (VIRTUAL) * CLASS: java.lang.Class * TYPE: virtual native function * OVERVIEW: true if the object is an instance of "this" class * INTERFACE (operand stack manipulation): * parameters: 'this' pointer, object * returns: a boolean *=======================================================================*/void Java_java_lang_Class_isInstance(void){ OBJECT object = popStackAsType(OBJECT); CLASS thisClass = topStackAsType(CLASS); topStack = (object != NULL) && isAssignableTo(object->ofClass, thisClass);}/*========================================================================= * FUNCTION: isAssignableFrom(Ljava/lang/Class;)Z (VIRTUAL) * CLASS: java.lang.Class * TYPE: virtual native function * OVERVIEW: true if objects of the argument class can always be * assigned to variables of the "this" class. * parameters: 'this' pointer, object * returns: a boolean *=======================================================================*/void Java_java_lang_Class_isAssignableFrom(void){ CLASS argClass = popStackAsType(CLASS); CLASS thisClass = topStackAsType(CLASS); if (argClass == NULL) { raiseException(NullPointerException); } else { topStack = !!isAssignableTo(argClass, thisClass); /* Double negation is intentional */ }}/*========================================================================= * FUNCTION: static byte[] getResourceAsStream0(String s); * CLASS: java.lang.class * TYPE: virtual native function * OVERVIEW: Internal system function * INTERFACE * parameters: * returns: * * This is just a stub function, until the real definition is written *=======================================================================*/void Java_java_lang_Class_getResourceAsStream0(void){ topStackAsType(cell *) = NULL;}/*========================================================================= * Native functions of class java.lang.Thread *=======================================================================*//*========================================================================= * FUNCTION: activeCount()I; (STATIC) * CLASS: java.lang.Thread * TYPE: static native function * OVERVIEW: Return the number of threads alive. * INTERFACE (operand stack manipulation): * parameters: <none> * returns: the number of threads alive *=======================================================================*/void Java_java_lang_Thread_activeCount(void){ pushStack(activeThreadCount());}/*========================================================================= * FUNCTION: currentThread()Ljava/lang/Thread; (STATIC) * CLASS: java.lang.Thread * TYPE: static native function * OVERVIEW: Return pointer to the currently executing Java thread. * INTERFACE (operand stack manipulation): * parameters: <none> * returns: pointer to a JAVATHREAD object (instance of Thread.class) *=======================================================================*/void Java_java_lang_Thread_currentThread(void){ pushStackAsType(JAVATHREAD, CurrentThread->javaThread);}/*========================================================================= * FUNCTION: yield()V (STATIC) * CLASS: java.lang.Thread * TYPE: static native function * OVERVIEW: Force a task switch. * INTERFACE (operand stack manipulation): * parameters: <none> * returns: <nothing> *=======================================================================*/void Java_java_lang_Thread_yield(void){ signalTimeToReschedule();}/*========================================================================= * FUNCTION: sleep(J)V (STATIC) * CLASS: java.lang.Thread * TYPE: static native function * OVERVIEW: Pause execution of the thread for a timer period * INTERFACE (operand stack manipulation): * parameters: Long of the number of ms to sleep for *=======================================================================*/void Java_java_lang_Thread_sleep(void){ long64 period; popLong(period); /* only block if the time period is not zero */ if (ll_zero_gt(period)) { /* Copy CurrentThread because suspendThread clears it */ THREAD thisThread = CurrentThread; /* Suspend the current thread before we add the timer */ suspendThread(); /* Now add the timer (this is the safe way) */ registerAlarm(thisThread, period, resumeThread); } else if (ll_zero_eq(period)) { signalTimeToReschedule(); } else { raiseException("java/lang/IllegalArgumentException"); }}/*========================================================================= * FUNCTION: iowait()V (STATIC) * CLASS: com.sun.cldc.io.GeneralBase * TYPE: static native function * OVERVIEW: Pause execution of the thread for a period * INTERFACE (operand stack manipulation): * parameters: <none> * returns: <nothing> *=======================================================================*//* * The following native function is called by the I/O protocol classes to * suspend execution of a Java thread that is waiting for I/0. (This is only * done when the only way to achieve the effect of asynchronous I/O is * to poll an I/O stream.) The options here are to either put the Java thread * into a set period of sleep, or to simply yield to another Java thread. The * former option can be used (in conjunction with the regular thread scheduling * code) to force a task to sleep for a while in order to conserve power. The * latter option will produce a smaller latency restarting the thread then the * data is available. * * By default we simply yield */#ifndef GENERIC_IO_WAIT_TIME#define GENERIC_IO_WAIT_TIME 0#endifvoid Java_com_sun_cldc_io_GeneralBase_iowait(void){#if GENERIC_IO_WAIT_TIME > 0 /* Suspend the current thread for GENERIC_IO_WAIT_TIME milliseconds */ THREAD thisThread = CurrentThread; suspendThread(); registerAlarm(thisThread, (long64)GENERIC_IO_WAIT_TIME, resumeThread);#else /* Try to switch to another thread */ signalTimeToReschedule();#endif}/*========================================================================= * FUNCTION: start()V (VIRTUAL) * CLASS: java.lang.Thread * TYPE: virtual native function * OVERVIEW: Start executing the 'run' method of the target * object given to the thread. * INTERFACE (operand stack manipulation): * parameters: 'this' pointer (implicitly) * returns: <nothing> *=======================================================================*/void Java_java_lang_Thread_start(void){ START_TEMPORARY_ROOTS DECLARE_TEMPORARY_ROOT(JAVATHREAD, javaThread, popStackAsType(JAVATHREAD)); DECLARE_TEMPORARY_ROOT(THREAD, VMthread, getVMthread(&javaThread)); /* Check if a separate Runnable object has been provided */ INSTANCE target = (javaThread->target) ? javaThread->target : (INSTANCE)javaThread; METHOD thisMethod; /* Ensure that the thread is not already active */ if (VMthread->state != THREAD_JUST_BORN) { raiseException("java/lang/IllegalThreadStateException"); goto done; } /* Find the 'run' method and set the thread to execute it */ thisMethod = lookupMethod((CLASS)target->ofClass, runNameAndType, target->ofClass); if (thisMethod == NULL) { raiseException("java/lang/Error"); goto done; } /* May call pushFrame(), which can cause GC */ initThreadBehavior(VMthread, thisMethod, (OBJECT)target); /* Since 'run' is a virtual method, it must have */ /* 'this' in its first local variable */ *(INSTANCE *)&VMthread->stack->cells[0] = target; /* Make the thread alive, and tell it that it can run */ startThread(VMthread); resumeThread(VMthread); done: END_TEMPORARY_ROOTS}/*========================================================================= * FUNCTION: isAlive()Z (VIRTUAL) * CLASS: java.lang.Thread * TYPE: virtual native function * OVERVIEW: Check if a thread is active. * INTERFACE (operand stack manipulation): * parameters: 'this' pointer (implicitly) * returns: true if thread is active, false otherwise *=======================================================================*/void Java_java_lang_Thread_isAlive(void){ topStack = isActivated(topStackAsType(JAVATHREAD)->VMthread);}/*========================================================================= * FUNCTION: setPriority0(I)V (VIRTUAL) * CLASS: java.lang.Thread * TYPE: virtual native function * OVERVIEW: Set the priority of the current thread. * INTERFACE (operand stack manipulation): * parameters: 'this' pointer (implicitly), new priority * returns: <nothing> *=======================================================================*/void Java_java_lang_Thread_setPriority0(void){ int priority = popStack(); THREAD VMthread; /* Ensure that the internal thread execution */ /* structure has been created */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -