📄 nativecore.c
字号:
/*0280*/ if (classHasAccessToClass(currentClass, clazz)) {
/*0281*/ METHOD method = lookupMethod(clazz, initNameAndType, currentClass);
/*0282*/ if ( (method != NULL)
/*0283*/ && (method->ofClass == (INSTANCE_CLASS)clazz)
/*0284*/ /* I don't understand why, but we're not allowed access to
/*0285./ * a protected <init> method of a superclass. */
/*0286*/ && classHasAccessToMember(currentClass,
/*0287*/ (method->accessFlags & ~ACC_PROTECTED),
/*0288*/ (INSTANCE_CLASS)clazz)
/*0289*/
/*0290*/ )
/*0291*/ {
/*0292*/ START_TEMPORARY_ROOTS
/*0293*/ DECLARE_TEMPORARY_ROOT(INSTANCE, object,
/*0294*/ instantiate((INSTANCE_CLASS)clazz));
/*0295*/ if (object != NULL) {
/*0296*/ /* Put the result back on the stack */
/*0297*/ topStackAsType(INSTANCE) = object; /* Will get the result */
/*0298*/ /* We now need to call the initializer. We'd like to just
/*0299./ * push a second copy of the object onto the stack, and then
/*0300./ * do pushFrame(method). But we can't, because that would
/*0301./ * not necessarily coincide with the stack map of the
/*0302./ * current method.
/*0303./ */
/*0304*/ pushFrame(RunCustomCodeMethod);
/*0305*/ pushStackAsType(CustomCodeCallbackFunction,
/*0306*/ &newInstanceReturnObject);
/*0307*/ pushStackAsType(INSTANCE, object);
/*0308*/ /* pushFrame may signal a stack overflow. */
/*0309*/ pushFrame(method);
/*0310*/ } else {
/*0311*/ /* We will already have thrown an appropriate error */
/*0312*/ }
/*0313*/ END_TEMPORARY_ROOTS
/*0314*/ return;
/*0315*/ }
/*0316*/ }
/*0317*/ raiseException("java/lang/IllegalAccessException");
/*0318*/ return;
/*0319*/}
/*0320*/
/*0321*//*=========================================================================
/*0322./ * FUNCTION: getName()Ljava/lang/String; (VIRTUAL)
/*0323./ * CLASS: java.lang.Class
/*0324./ * TYPE: virtual native function
/*0325./ * OVERVIEW: Return the name of the class as a string.
/*0326./ * INTERFACE (operand stack manipulation):
/*0327./ * parameters: 'this' pointer
/*0328./ * returns: Name of the class as a string.
/*0329./ *=======================================================================*/
/*0330*/
/*0331*/void Java_java_lang_Class_getName(void)
/*0332*/{
/*0333*/ CLASS clazz = topStackAsType(CLASS);
/*0334*/ START_TEMPORARY_ROOTS
/*0335*/ DECLARE_TEMPORARY_ROOT(char*, name, getClassName((CLASS)clazz));
/*0336*/ STRING_INSTANCE result;
/*0337*/ char *ptr = strchr(name, '/');
/*0338*/ /* Replace all slashes in the string with dots */
/*0339*/ while (ptr != NULL) {
/*0340*/ *ptr = '.';
/*0341*/ ptr = strchr(ptr + 1, '/');
/*0342*/ }
/*0343*/ result = instantiateString(name, strlen(name));
/*0344*/ topStackAsType(STRING_INSTANCE) = result;
/*0345*/ END_TEMPORARY_ROOTS
/*0346*/}
/*0347*/
/*0348*//*=========================================================================
/*0349./ * FUNCTION: isArray()Z
/*0350./ * CLASS: java.lang.Class
/*0351./ * TYPE: virtual native function
/*0352./ * OVERVIEW: true if the class is an array class
/*0353./ * INTERFACE (operand stack manipulation):
/*0354./ * parameters: 'this' pointer
/*0355./ * returns: true if the object is an instance.
/*0356./ *=======================================================================*/
/*0357*/
/*0358*/void Java_java_lang_Class_isArray(void)
/*0359*/{
/*0360*/ CLASS clazz = topStackAsType(CLASS);
/*0361*/ topStack = !!IS_ARRAY_CLASS(clazz);
/*0362*/ /* Double negation is intentional */
/*0363*/}
/*0364*/
/*0365*//*=========================================================================
/*0366./ * FUNCTION: boolean isInstance(Object)
/*0367./ * CLASS: java.lang.Class
/*0368./ * TYPE: virtual native function
/*0369./ * OVERVIEW: true if the object is an instance of "this" class
/*0370./ * INTERFACE (operand stack manipulation):
/*0371./ * parameters: 'this' pointer, object
/*0372./ * returns:
/*0373./ *=======================================================================*/
/*0374*/
/*0375*/void Java_java_lang_Class_isInstance(void)
/*0376*/{
/*0377*/ OBJECT object = popStackAsType(OBJECT);
/*0378*/ CLASS thisClass = topStackAsType(CLASS);
/*0379*/ topStack = (object != NULL) && isAssignableTo(object->ofClass, thisClass);
/*0380*/}
/*0381*/
/*0382*//*=========================================================================
/*0383./ * FUNCTION: boolean isAssignableFrom(Class)
/*0384./ * CLASS: java.lang.Class
/*0385./ * TYPE: virtual native function
/*0386./ * OVERVIEW: true if objects of the argument class can always be
/*0387./ * assigned to variables of the "this" class.
/*0388./ * parameters: 'this' pointer, object
/*0389./ * returns:
/*0390./ *=======================================================================*/
/*0391*/
/*0392*/void Java_java_lang_Class_isAssignableFrom(void)
/*0393*/{
/*0394*/ CLASS argClass = popStackAsType(CLASS);
/*0395*/ CLASS thisClass = topStackAsType(CLASS);
/*0396*/ if (argClass == NULL) {
/*0397*/ raiseException(NullPointerException);
/*0398*/ } else {
/*0399*/ topStack = !!isAssignableTo(argClass, thisClass);
/*0400*/ }
/*0401*/}
/*0402*/
/*0403*//*=========================================================================
/*0404./ * FUNCTION: static byte[] getResourceAsStream0(String s);
/*0405./ * CLASS: java.lang.class
/*0406./ * TYPE: virtual native function
/*0407./ * OVERVIEW: Internal system function
/*0408./ * INTERFACE
/*0409./ * parameters:
/*0410./ * returns:
/*0411./ *
/*0412./ * This is just a stub function, until the real definition is written
/*0413./ *=======================================================================*/
/*0414*/
/*0415*/void Java_java_lang_Class_getResourceAsStream0(void)
/*0416*/{
/*0417*/ topStackAsType(cell *) = NULL;
/*0418*/}
/*0419*/
/*0420*//*=========================================================================
/*0421./ * Native functions of class java.lang.Thread
/*0422./ *=======================================================================*/
/*0423*/
/*0424*//*=========================================================================
/*0425./ * FUNCTION: activeCount()I; (STATIC)
/*0426./ * CLASS: java.lang.Thread
/*0427./ * TYPE: static native function
/*0428./ * OVERVIEW: Return the number of threads alive.
/*0429./ * INTERFACE (operand stack manipulation):
/*0430./ * parameters: <none>
/*0431./ * returns: the number of threads alive
/*0432./ *=======================================================================*/
/*0433*/
/*0434*/void Java_java_lang_Thread_activeCount(void)
/*0435*/{
/*0436*/ pushStack(activeThreadCount());
/*0437*/}
/*0438*/
/*0439*//*=========================================================================
/*0440./ * FUNCTION: currentThread()Ljava/lang/Thread; (STATIC)
/*0441./ * CLASS: java.lang.Thread
/*0442./ * TYPE: static native function
/*0443./ * OVERVIEW: Return pointer to the currently executing Java thread.
/*0444./ * INTERFACE (operand stack manipulation):
/*0445./ * parameters: <none>
/*0446./ * returns: pointer to a JAVATHREAD object (instance of Thread.class)
/*0447./ *=======================================================================*/
/*0448*/
/*0449*/void Java_java_lang_Thread_currentThread(void)
/*0450*/{
/*0451*/ pushStackAsType(JAVATHREAD, CurrentThread->javaThread);
/*0452*/}
/*0453*/
/*0454*//*=========================================================================
/*0455./ * FUNCTION: yield()V (STATIC)
/*0456./ * CLASS: java.lang.Thread
/*0457./ * TYPE: static native function
/*0458./ * OVERVIEW: Force a task switch.
/*0459./ * INTERFACE (operand stack manipulation):
/*0460./ * parameters: <none>
/*0461./ * returns: <nothing>
/*0462./ *=======================================================================*/
/*0463*/
/*0464*/void Java_java_lang_Thread_yield(void)
/*0465*/{
/*0466*/ signalTimeToReschedule();
/*0467*/}
/*0468*/
/*0469*//*=========================================================================
/*0470./ * FUNCTION: sleep(J)V (STATIC)
/*0471./ * CLASS: java.lang.Thread
/*0472./ * TYPE: static native function
/*0473./ * OVERVIEW: Pause execution of the thread for a timer period
/*0474./ * INTERFACE (operand stack manipulation):
/*0475./ * parameters: Long of the number of ms to sleep for
/*0476./ *=======================================================================*/
/*0477*/
/*0478*/void Java_java_lang_Thread_sleep(void)
/*0479*/{
/*0480*/ long64 period;
/*0481*/ popLong(period);
/*0482*/
/*0483*/ /* only block if the time period is not zero */
/*0484*/ if (ll_zero_gt(period)) {
/*0485*/ /* Copy CurrentThread because suspendThread clears it */
/*0486*/ THREAD thisThread = CurrentThread;
/*0487*/
/*0488*/ /* Suspend the current thread before we add the timer */
/*0489*/ suspendThread();
/*0490*/
/*0491*/ /* Now add the timer (this is the safe way) */
/*0492*/ registerAlarm(thisThread, period, resumeThread); //\\thread.c:1112
/*0493*/ } else if (ll_zero_eq(period)) {
/*0494*/ signalTimeToReschedule();
/*0495*/ } else {
/*0496*/ raiseException("java/lang/IllegalArgumentException");
/*0497*/ }
/*0498*/}
/*0499*/
/*0500*//*=========================================================================
/*0501./ * FUNCTION: iowait()V (STATIC)
/*0502./ * CLASS: com.sun.cldc.io.GeneralBase
/*0503./ * TYPE: static native function
/*0504./ * OVERVIEW: Pause execution of the thread for a period
/*0505./ * INTERFACE (operand stack manipulation):
/*0506./ * parameters: <none>
/*0507./ * returns: <nothing>
/*0508./ *=======================================================================*/
/*0509*/
/*0510*//*
/*0511./ * The following native function is called by the I/O protocol classes to
/*0512./ * suspend execution of a Java thread that is waiting for I/0. (This is only
/*0513./ * done when the only way to achieve the effect of asynchronous I/O is
/*0514./ * to poll an I/O stream.) The options here are to either put the Java thread
/*0515./ * into a set period of sleep, or to simply yield to another Java thread. The
/*0516./ * former option can be used (in conjunction with the regular thread scheduling
/*0517./ * code) to force a task to sleep for a while in order to conserve power. The
/*0518./ * latter option will produce a smaller latency restarting the thread then the
/*0519./ * data is available.
/*0520./ *
/*0521./ * By default we simply yield
/*0522./ */
/*0523*/
/*0524*/#ifndef GENERIC_IO_WAIT_TIME
/*0525*/#define GENERIC_IO_WAIT_TIME 0
/*0526*/#endif
/*0527*/
/*0528*/void Java_com_sun_cldc_io_GeneralBase_iowait(void)
/*0529*/{
/*0530*/#if GENERIC_IO_WAIT_TIME > 0
/*0531*/ /* Suspend the current thread for GENERIC_IO_WAIT_TIME milliseconds */
/*0532*/ THREAD thisThread = CurrentThread;
/*0533*/ suspendThread();
/*0534*/ registerAlarm(thisThread, (long64)GENERIC_IO_WAIT_TIME, resumeThread);
/*0535*/#else
/*0536*/ /* Try to switch to another thread */
/*0537*/ signalTimeToReschedule();
/*0538*/#endif
/*0539*/}
/*0540*/
/*0541*//*=========================================================================
/*0542./ * FUNCTION: start()V (VIRTUAL)
/*0543./ * CLASS: java.lang.Thread
/*0544./ * TYPE: virtual native function
/*0545./ * OVERVIEW: Start executing the 'run' method of the target
/*0546./ * object given to the thread.
/*0547./ * INTERFACE (operand stack manipulation):
/*0548./ * parameters: 'this' pointer (implicitly)
/*0549./ * returns: <nothing>
/*0550./ *=======================================================================*/
/*0551*/
/*0552*/void Java_java_lang_Thread_start(void)
/*0553*/{
/*0554*/ START_TEMPORARY_ROOTS
/*0555*/ DECLARE_TEMPORARY_ROOT(JAVATHREAD, javaThread,
/*0556*/ popStackAsType(JAVATHREAD));
//\\DECLARE_TEMPORARY_ROOT捌
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -