📄 nativecore.c
字号:
/*0001*//*
/*0002./ * Copyright (c) 1998-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: Native function interface
/*0022./ * FILE: nativeCore.c
/*0023./ * OVERVIEW: This file defines the native functions needed
/*0024./ * by the Java virtual machine. The implementation
/*0025./ * is _not_ based on JNI (Java Native Interface),
/*0026./ * because JNI seems too expensive for small devices.
/*0027./ * AUTHOR: Antero Taivalsaari, Sun Labs
/*0028./ * Edited by Doug Simon 11/1998
/*0029./ * Frank Yellin
/*0030./ *=======================================================================*/
/*0031*/
/*0032*//*=========================================================================
/*0033./ * Include files
/*0034./ *=======================================================================*/
/*0035*/
/*0036*/#include <global.h>
/*0037*/
/*0038*//*=========================================================================
/*0039./ * FUNCTION: getClass()Ljava/lang/Class
/*0040./ * CLASS: java.lang.Object
/*0041./ * TYPE: virtual native function (reflection)
/*0042./ * OVERVIEW: Return the class object of the given object
/*0043./ * INTERFACE (operand stack manipulation):
/*0044./ * parameters: an object instance ('this')
/*0045./ * returns: a class object
/*0046./ * NOTE: Current implementation does not create array
/*0047./ * classes yet, so arrays return JavaLangObject.
/*0048./ *=======================================================================*/
/*0049*/
/*0050*/void Java_java_lang_Object_getClass(void)
/*0051*/{
/*0052*/ topStackAsType(CLASS) = topStackAsType(OBJECT)->ofClass;
/*0053*/}
/*0054*/
/*0055*//*=========================================================================
/*0056./ * FUNCTION: hashCode()I, identityHashCode()I
/*0057./ * CLASS: java.lang.Object, java.lang.System
/*0058./ * TYPE: virtual native function
/*0059./ * OVERVIEW: Generate a unique hash code for an object.
/*0060./ * INTERFACE (operand stack manipulation):
/*0061./ * parameters: this
/*0062./ * returns: hash code
/*0063./ *=======================================================================*/
/*0064*/
/*0065*/void Java_java_lang_Object_hashCode(void)
/*0066*/{
/*0067*/ /* The following must be two lines:
/*0068./ * objectHashCode can GC, and a compiler is allowed to assume that the
/*0069./ * value of sp hasn't changed if it is all on one line.
/*0070./ */
/*0071*/ OBJECT object = popStackAsType(OBJECT);
/*0072*/ long result = objectHashCode(object); /* this may GC */
/*0073*/ pushStack(result);
/*0074*/}
/*0075*/
/*0076*/void Java_java_lang_System_identityHashCode(void)
/*0077*/{
/*0078*/ OBJECT object = popStackAsType(OBJECT);
/*0079*/ long result = object == NULL ? 0 : objectHashCode(object); /* this may GC */
/*0080*/ pushStack(result);
/*0081*/}
/*0082*/
/*0083*//*=========================================================================
/*0084./ * FUNCTION: notify()V
/*0085./ * CLASS: java.lang.Object
/*0086./ * TYPE: virtual native function
/*0087./ * OVERVIEW: Release the first thread in the object's monitor.
/*0088./ * INTERFACE (operand stack manipulation):
/*0089./ * parameters: an object instance ('this')
/*0090./ * returns: <nothing>
/*0091./ * NOTE: This operation does nothing
/*0092./ * if the current thread is not the owner of the monitor.
/*0093./ *=======================================================================*/
/*0094*/
/*0095*/void Java_java_lang_Object_notify(void)
/*0096*/{
/*0097*/ OBJECT object = popStackAsType(OBJECT);
/*0098*/ monitorNotify(object, FALSE);
/*0099*/}
/*0100*/
/*0101*//*=========================================================================
/*0102./ * FUNCTION: notifyAll()V
/*0103./ * CLASS: java.lang.Object
/*0104./ * TYPE: virtual native function
/*0105./ * OVERVIEW: Release all threads in the object's monitor.
/*0106./ * INTERFACE (operand stack manipulation):
/*0107./ * parameters: an object instance ('this')
/*0108./ * returns: <nothing>
/*0109./ * NOTE: This operation does nothing
/*0110./ * if the current thread is not the owner of the monitor.
/*0111./ *=======================================================================*/
/*0112*/
/*0113*/void Java_java_lang_Object_notifyAll(void)
/*0114*/{
/*0115*/ OBJECT object = popStackAsType(OBJECT);
/*0116*/ monitorNotify(object, TRUE);
/*0117*/}
/*0118*/
/*0119*//*=========================================================================
/*0120./ * FUNCTION: wait()V
/*0121./ * CLASS: java.lang.Object
/*0122./ * TYPE: virtual native function
/*0123./ * OVERVIEW: Wait in the object's monitor forever.
/*0124./ * INTERFACE (operand stack manipulation):
/*0125./ * parameters: an object instance ('this').
/*0126./ * returns: <nothing>
/*0127./ * NOTE: This operation should throw IllegalMonitorState-
/*0128./ * Exception if the current thread is not the owner of
/*0129./ * the monitor. Other possible exceptions are:
/*0130./ * IllegalArgumentException, InterruptedException.
/*0131./ *=======================================================================*/
/*0132*/
/*0133*/void Java_java_lang_Object_wait(void)
/*0134*/{
/*0135*/ long64 period;
/*0136*/ OBJECT object;
/*0137*/
/*0138*/ popLong(period);
/*0139*/ object = popStackAsType(OBJECT);
/*0140*/
/*0141*/ /* only block if the time period is not zero */
/*0142*/ if (ll_zero_ge(period)) {
/*0143*/ monitorWait(object, period);
/*0144*/ } else {
/*0145*/ raiseException("java/lang/IllegalArgumentException");
/*0146*/ }
/*0147*/}
/*0148*/
/*0149*//*=========================================================================
/*0150./ * Native functions of class java.lang.Math
/*0151./ *=======================================================================*/
/*0152*/
/*0153*//*=========================================================================
/*0154./ * FUNCTION: randomInt()I
/*0155./ * CLASS: java.lang.Math
/*0156./ * TYPE: static native function
/*0157./ * OVERVIEW: Return a random integer value
/*0158./ * INTERFACE (operand stack manipulation):
/*0159./ * parameters: none
/*0160./ * returns: random integer
/*0161./ *=======================================================================*/
/*0162*/
/*0163*/void Java_java_lang_Math_randomInt(void)
/*0164*/{
/*0165*/ long result = RandomNumber_md();
/*0166*/ pushStack(result);
/*0167*/}
/*0168*/
/*0169*//*=========================================================================
/*0170./ * Native functions of class java.lang.Class
/*0171./ *=======================================================================*/
/*0172*/
/*0173*//*=========================================================================
/*0174./ * FUNCTION: isInterface()B
/*0175./ * CLASS: java.lang.Class
/*0176./ * TYPE: virtual native function
/*0177./ * OVERVIEW: Return true if the class is an interface class.
/*0178./ * INTERFACE (operand stack manipulation):
/*0179./ * parameters: 'this' pointer
/*0180./ * returns: Boolean indicating if the class is an interface.
/*0181./ *=======================================================================*/
/*0182*/
/*0183*/void Java_java_lang_Class_isInterface(void)
/*0184*/{
/*0185*/ CLASS clazz = topStackAsType(CLASS);
/*0186*/ topStack = ((clazz->accessFlags & ACC_INTERFACE) != 0);
/*0187*/}
/*0188*/
/*0189*//*=========================================================================
/*0190./ * FUNCTION: isPrimitive()B
/*0191./ * CLASS: java.lang.Class
/*0192./ * TYPE: virtual native function
/*0193./ * OVERVIEW: Return true if the class is a primitive class.
/*0194./ * INTERFACE (operand stack manipulation):
/*0195./ * parameters: 'this' pointer
/*0196./ * returns: Boolean indicating if the class is a primitive class.
/*0197./ *=======================================================================*/
/*0198*/
/*0199*/void Java_java_lang_Class_isPrimitive(void)
/*0200*/{
/*0201*/ topStack = FALSE; /* We do not support this feature */
/*0202*/}
/*0203*/
/*0204*//*=========================================================================
/*0205./ * FUNCTION: forName(Ljava/lang/String;)Ljava/lang/Class; (STATIC)
/*0206./ * CLASS: java.lang.Class
/*0207./ * TYPE: static native function (reflection)
/*0208./ * OVERVIEW: Given a string containing a class name (e.g.,
/*0209./ * "java.lang.Thread", return the corresponding
/*0210./ * class object.
/*0211./ * INTERFACE (operand stack manipulation):
/*0212./ * parameters: a string object
/*0213./ * returns: a class object
/*0214./ *=======================================================================*/
/*0215*/
/*0216*/void Java_java_lang_Class_forName(void)
/*0217*/{
/*0218*/ STRING_INSTANCE string = topStackAsType(STRING_INSTANCE);
/*0219*/ if (string == NULL) {
/*0220*/ raiseException(NullPointerException);
/*0221*/ } else {
/*0222*/ char* className = getStringContents((STRING_INSTANCE)string);
/*0223*/ CLASS thisClass = NULL;
/*0224*/ if (!strchr(className, '/')) {
/*0225*/ replaceLetters(className,'.','/');
/*0226*/ if (verifyName(className, LegalClass, FALSE)) {
/*0227*/ thisClass = getClass(className);
/*0228*/ /* The specification does not require that the current
/*0229./ * class have "access" to thisClass */
/*0230*/ if (thisClass) {
/*0231*/ topStackAsType(CLASS) = thisClass;
/*0232*/ if (!IS_ARRAY_CLASS(thisClass)) {
/*0233*/ if (!CLASS_INITIALIZED((INSTANCE_CLASS)thisClass)) {
/*0234*/ initializeClass((INSTANCE_CLASS)thisClass);
/*0235*/ }
/*0236*/ }
/*0237*/ }
/*0238*/ }
/*0239*/ }
/*0240*/ if (thisClass == NULL) {
/*0241*/ raiseExceptionMsg("java/lang/ClassNotFoundException",
/*0242*/ topStackAsType(STRING_INSTANCE));
/*0243*/ }
/*0244*/ }
/*0245*/}
/*0246*/
/*0247*//*=========================================================================
/*0248./ * FUNCTION: newInstance()Ljava/lang/Object; (VIRTUAL)
/*0249./ * CLASS: java.lang.Class
/*0250./ * TYPE: virtual native function (reflection)
/*0251./ * OVERVIEW: Instantiate an object of the given class
/*0252./ * INTERFACE (operand stack manipulation):
/*0253./ * parameters: 'this'
/*0254./ * returns: an instance of the class represented by 'this'
/*0255./ * NOTE: Current implementation does not create array
/*0256./ * classes properly.
/*0257./ *=======================================================================*/
/*0258*/
/*0259*/static void
/*0260*/newInstanceReturnObject(FRAME_HANDLE exceptionFrameH)
/*0261*/{
/*0262*/ if (exceptionFrameH == NULL) {
/*0263*/ popFrame();
/*0264*/ } else {
/*0265*/ /* We have no interest in dealing with exceptions */
/*0266*/ }
/*0267*/}
/*0268*/
/*0269*/void Java_java_lang_Class_newInstance(void)
/*0270*/{
/*0271*/ INSTANCE_CLASS currentClass = getFP()->thisMethod->ofClass;
/*0272*/ CLASS clazz = topStackAsType(CLASS);
/*0273*/
/*0274*/ if (IS_ARRAY_CLASS(clazz)
/*0275*/ || ((clazz->accessFlags & (ACC_INTERFACE | ACC_ABSTRACT)) != 0)) {
/*0276*/ raiseException("java/lang/InstantiationException");
/*0277*/ return;
/*0278*/ }
/*0279*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -