Main Page | Namespace List | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

jlThread.h

Go to the documentation of this file.
00001 #ifndef _jlThread_h_included_
00002 #define _jlThread_h_included_
00003 
00004 /*!
00005  * @file jlThread.h
00006  *
00007  * @brief Public interface to native implementation of
00008  * @c @b java.lang.Thread
00009  *
00010  * Two parallel sets of definitions are used here, one for internal
00011  * implementation purposes, the other for the JNI interface.  The first
00012  * uses internal data types (via @link #JLTHREAD_LOCAL_DEFINED
00013    \#ifdef JLTHREAD_LOCAL_DEFINED@endlink) where the second does not.
00014  * Instead, it uses @c @b <jni.h> data types.  Those types @e must
00015  * match up for JNI to work, yet by keeping them
00016  * absolutely separate, application JNI code does @e not have
00017  * @b any dependencies on the core code of this JVM implementation.
00018  *
00019  * Even though there is only apparently @e one set of definitions,
00020  * the @c @b \#ifdef statement controls which set is used.
00021  *
00022  * This file must be included by JNI code along with the
00023  * @c @b java.lang.Class JNI header file.  The following example
00024  * shows how to call one of the @e local native methods of this class
00025  * from the JNI environment.  Notice that although this is not necessary
00026  * due to the local implementation shortcut defined in
00027  * @link jvm/src/native.c native.c@endlink, it is not only possible,
00028  * but sometimes quite desirable to do so.
00029  *
00030  * @verbatim
00031    #include <jni.h>
00032    #include <solaris/jni_md.h>    ... or appropriate platform-specifics
00033   
00034    #include "java_lang_Thread.h"  ... JNI definitions
00035    #include "jlThread.h"          ... this file
00036   
00037    JNIEXPORT jboolean JNICALL
00038        Java_java_lang_Thread_holdsLock(JNIEnv *env,
00039                                        jclass  thisclass,
00040                                        jobject thisobj)
00041    {
00042        jboolean b;
00043 
00044        b = jlThread_holdsLock(thisclass,
00045                               thisobj); ... call native implementation
00046 
00047        return(b);
00048    }
00049    @endverbatim
00050  *
00051  * @attention This local native method implementation is defined
00052  *            in @link jvm/src/native.c native.c@endlink and
00053  *            does @e not make use of the @b JNIENV pointer in
00054  *            @e any manner.
00055  *
00056  * @attention Although @link #jvalue jvalue@endlink is indeed a part
00057  *            of both this implementation and the standard JNI interface
00058  *            through @c @b <jni.h> , it is @e not recommended to use
00059  *            it if at all possible.  Due to the fact that both
00060  *            definitions involve unions, along with the slightly
00061  *            differing contents between the two versions, it is almost
00062  *            certain that there will be compilation compatibility
00063  *            problems in the memory layouts from one platform to
00064  *            another, and possibly between the layouts between them on
00065  *            any given platform.  Since @link #jvalue jvalue@endlink
00066  *            is not specificaly a @e Java type, but instead a JNI
00067  *            construction, this may not be a problem, but this
00068  *            advisory is raised anyway in order to encourage reliable
00069  *            implementation of JNI.
00070  *
00071  *
00072  * @section Control
00073  *
00074  * \$URL: https://svn.apache.org/path/name/jlThread.h $ \$Id: jlThread.h 0 09/28/2005 dlydick $
00075  *
00076  * Copyright 2005 The Apache Software Foundation
00077  * or its licensors, as applicable.
00078  *
00079  * Licensed under the Apache License, Version 2.0 ("the License");
00080  * you may not use this file except in compliance with the License.
00081  * You may obtain a copy of the License at
00082  *
00083  *     http://www.apache.org/licenses/LICENSE-2.0
00084  *
00085  * Unless required by applicable law or agreed to in writing,
00086  * software distributed under the License is distributed on an
00087  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
00088  * either express or implied.
00089  *
00090  * See the License for the specific language governing permissions
00091  * and limitations under the License.
00092  *
00093  * @version \$LastChangedRevision: 0 $
00094  *
00095  * @date \$LastChangedDate: 09/28/2005 $
00096  *
00097  * @author \$LastChangedBy: dlydick $
00098  *         Original code contributed by Daniel Lydick on 09/28/2005.
00099  *
00100  * @section Reference
00101  *
00102  */
00103 
00104 /**********************************************************************/
00105 #ifdef JLTHREAD_LOCAL_DEFINED
00106 
00107 ARCH_COPYRIGHT_APACHE(jlThread, h, "$URL: https://svn.apache.org/path/name/jlThread.h $ $Id: jlThread.h 0 09/28/2005 dlydick $");
00108 
00109 /**********************************************************************/
00110 #else /* JLTHREAD_LOCAL_DEFINED */
00111 
00112 #include "jlObject.h"
00113 
00114 /* There is currently nothing else needed here */
00115 
00116 #endif /* JLTHREAD_LOCAL_DEFINED */
00117 /**********************************************************************/
00118 
00119 /*!
00120  * @name Unified set of prototypes for functions
00121  * in @link jvm/src/jlThread.c jlThread.c@endlink
00122  *
00123  * @brief JNI table index and external reference to
00124  * each function that locally implements a JNI native method.
00125  *
00126  * The JVM native interface ordinal definition base for this class
00127  * is 40.  An enumeration is used so the compiler can help the use
00128  * to not choose duplicate values.
00129  *
00130  */
00131 
00132 /*@{ */ /* Begin grouped definitions */
00133 
00134 typedef enum
00135 {
00136 
00137     JLTHREAD_NMO_CURRENTTHREAD = 40, /**< Ordinal for
00138                       @link #jlThread_currentThread() yield()@endlink */
00139 
00140     JLTHREAD_NMO_YIELD = 41,        /**< Ordinal for
00141                               @link #jlThread_yield() yield()@endlink */
00142 
00143     JLTHREAD_NMO_INTERRUPT = 42,    /**< Ordinal for
00144                        @link #jlThread_interrupt() interrupt()@endlink*/
00145 
00146     JLTHREAD_NMO_INTERRUPTED = 43,  /**< Ordinal for
00147                   @link #jlThread_interrupted() interrupted()@endlink */
00148 
00149     JLTHREAD_NMO_ISINTERRUPTED = 44, /**< Ordinal for
00150               @link #jlThread_isInterrupted() isInterrupted()@endlink */
00151 
00152     JLTHREAD_NMO_SLEEP = 45,        /**< Ordinal for
00153                               @link #jlThread_sleep() sleep()@endlink */
00154 
00155     JLTHREAD_NMO_SLEEP_NANOS = 46,  /**< Ordinal for
00156                   @link #jlThread_sleep_nanos() sleep_nanos()@endlink */
00157 
00158     JLTHREAD_NMO_JOIN4EVER = 47,    /**< Ordinal for
00159                        @link #jlThread_join4ever() join4ever()@endlink*/
00160 
00161     JLTHREAD_NMO_JOINTIMED = 48,    /**< Ordinal for
00162                        @link #jlThread_jointimed() jointimed()@endlink*/
00163 
00164     JLTHREAD_NMO_JOINTIMED_NANOS = 49, /**< Ordinal for
00165           @link #jlThread_jointimed_nanos() jointimed_nanos()@endlink */
00166 
00167     JLTHREAD_NMO_ISALIVE = 50,        /**< Ordinal for
00168                        @link #jlThread_isAlive() isAlive()@endlink */
00169 
00170     JLTHREAD_NMO_START = 51,          /**< Ordinal for
00171                            @link #jlThread_start() holdsLock()@endlink*/
00172 
00173     JLTHREAD_NMO_COUNTSTACKFRAMES = 52, /**< Ordinal for
00174         @link #jlThread_countStackFrames() countStackFrames()@endlink */
00175 
00176     JLTHREAD_NMO_HOLDSLOCK = 53,      /**< Ordinal for
00177                        @link #jlThread_holdsLock() holdsLock()@endlink*/
00178 
00179     JLTHREAD_NMO_SETPRIORITY = 54,    /**< Ordinal for
00180                   @link #jlThread_setPriority() setPriority()@endlink */
00181 
00182     JLTHREAD_NMO_GETPRIORITY = 55,    /**< Ordinal for
00183                   @link #jlThread_getPriority() getPriority()@endlink */
00184 
00185     JLTHREAD_NMO_DESTROY = 56,        /**< Ordinal for
00186                           @link #jlThread_destroy() destroy()@endlink */
00187 
00188     JLTHREAD_NMO_CHECKACCESS = 57,    /**< Ordinal for
00189                   @link #jlThread_checkAccess() checkAccess()@endlink */
00190 
00191     JLTHREAD_NMO_SETDAEMON = 58,      /**< Ordinal for
00192                       @link #jlThread_setDaemon() setDaemon()@endlink */
00193 
00194     JLTHREAD_NMO_ISDAEMON = 59,       /**< Ordinal for
00195                         @link #jlThread_isDaemon() isDaemon()@endlink */
00196 
00197     JLTHREAD_NMO_STOP = 60,           /**< Ordinal for
00198                                 @link #jlThread_stop() stop()@endlink */
00199 
00200     JLTHREAD_NMO_SUSPEND = 61,        /**< Ordinal for
00201                              @link #jlThread_suspend() stop()@endlink */
00202 
00203     JLTHREAD_NMO_RESUME = 62,         /**< Ordinal for
00204                              @link #jlThread_resume() stop()@endlink */
00205 
00206 } jlThread_nmo_enum;
00207 
00208 /*
00209  * Add one function prototype below
00210  * for each local native method enumeration above:
00211  */
00212 
00213 /*!
00214  * @brief JNI hook to @link #jlThread_currentThread()
00215    currentThread()@endlink
00216  */
00217 extern
00218     jvm_object_hash jlThread_currentThread(jvm_class_index clsidxTHR);
00219 
00220 /*!
00221  * @brief JNI hook to @link #jlThread_yield() yield()@endlink
00222  */
00223 extern jvoid jlThread_yield(jvm_class_index clsidxTHR);
00224 
00225 /*!
00226  * @brief JNI hook to @link #jlThread_interrupt() interrupt()@endlink
00227  */
00228 extern jvoid jlThread_interrupt(jvm_object_hash objhashthis);
00229 
00230 /*!
00231  *@brief JNI hook to @link #jlThread_interrupted() interrupted()@endlink
00232  */
00233 extern jboolean jlThread_interrupted(jvm_object_hash objhashTHR);
00234 
00235 /*!
00236  * @brief JNI hook to
00237  * @link #jlThread_isInterrupted() isInterrupted()@endlink
00238  */
00239 extern jboolean jlThread_isInterrupted(jvm_object_hash objhashthis);
00240 
00241 /*!
00242  * @brief JNI hook to @link #jlThread_sleep() sleep()@endlink
00243  */
00244 extern jboolean jlThread_sleep(jvm_class_index clsidxTHR,
00245                                jlong           sleeptime_milliseconds);
00246 
00247 /*!
00248  * @brief JNI hook to
00249  * @link #jlThread_sleep_nanos() sleep_nanos()@endlink
00250  */
00251 extern jboolean jlThread_sleep_nanos(jvm_class_index clsidxTHR,
00252                                      jlong       sleeptime_milliseconds,
00253                                      jint        sleeptime_nanoseconds);
00254 
00255 /*!
00256  * @brief JNI hook to @link #jlThread_join4ever() join4ever()@endlink
00257  */
00258 extern jvoid jlThread_join4ever(jvm_object_hash objhashthis);
00259 
00260 /*!
00261  * @brief JNI hook to @link #jlThread_jointimed() jointimed()@endlink
00262  */
00263 extern jvoid jlThread_jointimed(jvm_object_hash objhashthis,
00264                                 jlong           sleeptime);
00265 
00266 /*!
00267  * @brief JNI hook to
00268  * @link #jlThread_jointimed_nanos() jointimed_nanos()@endlink
00269  */
00270 extern jvoid jlThread_jointimed_nanos(jvm_object_hash objhashthis,
00271                                       jlong           sleeptime,
00272                                       jint          sleeptime_nanos);
00273 
00274 /*!
00275  * @brief JNI hook to @link #jlThread_jointimed() jointimed()@endlink
00276  */
00277 extern jboolean jlThread_isAlive(jvm_object_hash objhashthis);
00278 
00279 /*!
00280  * @brief JNI hook to @link #jlThread_start() start()@endlink
00281  */
00282 extern jboolean jlThread_start(jvm_object_hash objhashthis);
00283 
00284 /*!
00285  * @brief JNI hook to
00286  * @link #jlThread_countStackFrames() countStackFrames()@endlink
00287  */
00288 extern jint jlThread_countStackFrames(jvm_object_hash objhashthis);
00289 
00290 /*!
00291  * @brief JNI hook to @link #jlThread_holdsLock() holdsLock()@endlink
00292  */
00293 extern jboolean jlThread_holdsLock(jvm_class_index clsidxTHR,
00294                                    jvm_object_hash objhashLOCK);
00295 
00296 /*!
00297  * @brief JNI hook to
00298  * @link #jlThread_setPriority() setPriority()@endlink
00299  */
00300 extern jboolean jlThread_setPriority(jvm_object_hash objhashthis,
00301                                      jint             priority);
00302 
00303 /*!
00304  * @brief JNI hook to
00305  * @link #jlThread_getPriority() getPriority()@endlink
00306  */
00307 extern jint jlThread_getPriority(jvm_object_hash objhashthis);
00308 
00309 /*!
00310  * @brief JNI hook to @link #jlThread_destroy() destroy()@endlink
00311  */
00312 extern jboolean jlThread_destroy(jvm_object_hash objhashthis);
00313 
00314 /*!
00315  * @brief JNI hook to
00316  * @link #jlThread_checkAccess() checkAccess()@endlink
00317  */
00318 extern jboolean jlThread_checkAccess(jvm_object_hash objhashthis);
00319 
00320 /*!
00321  * @brief JNI hook to @link #jlThread_setDaemon() setDaemon()@endlink
00322  */
00323 extern jvoid jlThread_setDaemon(jvm_object_hash objhashthis,
00324                                 jboolean isdaemon);
00325 
00326 /*!
00327  * @brief JNI hook to @link #jlThread_isDaemon() isDaemon()@endlink
00328  */
00329 extern jboolean jlThread_isDaemon(jvm_object_hash objhashthis);
00330 
00331 /*!
00332  * @brief JNI hook to @link #jlThread_stop() stop()@endlink
00333  */
00334 extern jvoid jlThread_stop(jvm_object_hash objhashthis);
00335 
00336 /*!
00337  * @brief JNI hook to @link #jlThread_suspend() suspend()@endlink
00338  */
00339 extern jvoid jlThread_suspend(jvm_object_hash objhashthis);
00340 
00341 /*!
00342  * @brief JNI hook to @link #jlThread_resume() resume()@endlink
00343  */
00344 extern jvoid jlThread_resume(jvm_object_hash objhashthis);
00345 
00346 /*@} */ /* End grouped definitions */
00347 
00348 
00349 /**********************************************************************/
00350 
00351 /*!
00352  * @name Connection to local native method tables.
00353  *
00354  * @brief These manifest constant code fragments are designed to be
00355  * inserted directly into locations in
00356  * @link jvm/src/native.c native.c@endlink without any other
00357  * modification to that file except a @e single entry to actually
00358  * invoke the method.
00359  *
00360  */
00361 /*@{*/
00362 
00363 /*!
00364  * @brief Complete list of local native method ordinals
00365  * for @c @b java.lang.Thread
00366  */
00367 #define NATIVE_TABLE_JLTHREAD           \
00368     case JLTHREAD_NMO_CURRENTTHREAD:    \
00369     case JLTHREAD_NMO_YIELD:            \
00370     case JLTHREAD_NMO_INTERRUPT:        \
00371     case JLTHREAD_NMO_INTERRUPTED:      \
00372     case JLTHREAD_NMO_ISINTERRUPTED:    \
00373     case JLTHREAD_NMO_SLEEP:            \
00374     case JLTHREAD_NMO_SLEEP_NANOS:      \
00375     case JLTHREAD_NMO_JOIN4EVER:        \
00376     case JLTHREAD_NMO_JOINTIMED:        \
00377     case JLTHREAD_NMO_JOINTIMED_NANOS:  \
00378     case JLTHREAD_NMO_ISALIVE:          \
00379     case JLTHREAD_NMO_START:            \
00380     case JLTHREAD_NMO_COUNTSTACKFRAMES: \
00381     case JLTHREAD_NMO_HOLDSLOCK:        \
00382     case JLTHREAD_NMO_SETPRIORITY:      \
00383     case JLTHREAD_NMO_GETPRIORITY:      \
00384     case JLTHREAD_NMO_DESTROY:          \
00385     case JLTHREAD_NMO_CHECKACCESS:      \
00386     case JLTHREAD_NMO_SETDAEMON:        \
00387     case JLTHREAD_NMO_ISDAEMON:         \
00388     case JLTHREAD_NMO_STOP:
00389 
00390 /*!
00391  * @brief Table of local native methods and their descriptors
00392  * for @c @b java.lang.Thread
00393  */
00394 #define NATIVE_TABLE_JLTHREAD_ORDINALS                                 \
00395     {                                                                  \
00396 /*static*/ { JLTHREAD_NMO_CURRENTTHREAD,"currentThread",               \
00397                                            "()Ljava/lang/Thread;"   }, \
00398 /*static*/ { JLTHREAD_NMO_YIELD,        "yield",            "()V"   }, \
00399            { JLTHREAD_NMO_INTERRUPT,    "interrupt",        "()V"   }, \
00400 /*static*/ { JLTHREAD_NMO_INTERRUPTED,  "interrupted",      "()Z"   }, \
00401            { JLTHREAD_NMO_ISINTERRUPTED,"isInterrupted",    "()Z"   }, \
00402 /*static*/ { JLTHREAD_NMO_SLEEP,        "sleep",            "(J)V"  }, \
00403 /*static*/ { JLTHREAD_NMO_SLEEP_NANOS,  "sleep",            "(JI)V" }, \
00404            { JLTHREAD_NMO_JOIN4EVER,    "join",             "()V"   }, \
00405            { JLTHREAD_NMO_JOINTIMED,    "join",             "(J)V"  }, \
00406            { JLTHREAD_NMO_JOINTIMED_NANOS,                             \
00407                                         "join",             "(JI)V" }, \
00408            { JLTHREAD_NMO_ISALIVE,      "isAlive",          "()Z"   }, \
00409            { JLTHREAD_NMO_START,        "start",            "()V"   }, \
00410            { JLTHREAD_NMO_COUNTSTACKFRAMES,                            \
00411                                         "countStackFrames", "()I"   }, \
00412 /*static*/ { JLTHREAD_NMO_HOLDSLOCK,    "holdsLock",                   \
00413                                            "(Ljava/lang/Object;)Z" },  \
00414            { JLTHREAD_NMO_SETPRIORITY,  "setPriority",     "(I)V"  },  \
00415            { JLTHREAD_NMO_GETPRIORITY,  "getPriority",     "()I"   },  \
00416            { JLTHREAD_NMO_DESTROY,      "destroy",         "()V"   },  \
00417            { JLTHREAD_NMO_CHECKACCESS,  "checkAccess",     "()V"   },  \
00418            { JLTHREAD_NMO_SETDAEMON,    "setDaemon",       "(Z)V"  },  \
00419            { JLTHREAD_NMO_ISDAEMON,     "isDaemon",        "()Z"   },  \
00420            { JLTHREAD_NMO_STOP,         "stop",            "()V"   },  \
00421            { JLTHREAD_NMO_SUSPEND,      "suspend",         "()V"   },  \
00422            { JLTHREAD_NMO_RESUME,       "resume",          "()V"   },  \
00423                                                                        \
00424         /* Add other method entries here */                            \
00425                                                                        \
00426                                                                        \
00427         /* End of table marker, regardless of static array[size] */    \
00428         { JVMCFG_JLOBJECT_NMO_NULL,                                    \
00429           CHEAT_AND_USE_NULL_TO_INITIALIZE,                            \
00430           CHEAT_AND_USE_NULL_TO_INITIALIZE }                           \
00431     }
00432 
00433 /*!
00434  * @brief @c @b (jvoid) local native method ordinal table
00435  * for @c @b java.lang.Thread
00436  */
00437 #define NATIVE_TABLE_JLTHREAD_JVOID     \
00438     case JLTHREAD_NMO_YIELD:            \
00439     case JLTHREAD_NMO_INTERRUPT:        \
00440     case JLTHREAD_NMO_SLEEP:            \
00441     case JLTHREAD_NMO_SLEEP_NANOS:      \
00442     case JLTHREAD_NMO_JOIN4EVER:        \
00443     case JLTHREAD_NMO_JOINTIMED:        \
00444     case JLTHREAD_NMO_JOINTIMED_NANOS:  \
00445     case JLTHREAD_NMO_START:            \
00446     case JLTHREAD_NMO_SETPRIORITY:      \
00447     case JLTHREAD_NMO_DESTROY:          \
00448     case JLTHREAD_NMO_CHECKACCESS:      \
00449     case JLTHREAD_NMO_SETDAEMON:        \
00450     case JLTHREAD_NMO_STOP:             \
00451     case JLTHREAD_NMO_SUSPEND:          \
00452     case JLTHREAD_NMO_RESUME:
00453 
00454 /*!
00455  * @brief @c @b (jobject) local native method ordinal table
00456  * for @c @b java.lang.Thread
00457  */
00458 #define NATIVE_TABLE_JLTHREAD_JOBJECT   \
00459     case JLTHREAD_NMO_CURRENTTHREAD:
00460 
00461 /*!
00462  * @brief @c @b (jint) local native method ordinal table
00463  * for @c @b java.lang.Thread
00464  */
00465 #define NATIVE_TABLE_JLTHREAD_JINT      \
00466     case JLTHREAD_NMO_INTERRUPTED:      \
00467     case JLTHREAD_NMO_ISINTERRUPTED:    \
00468     case JLTHREAD_NMO_ISALIVE:          \
00469     case JLTHREAD_NMO_COUNTSTACKFRAMES: \
00470     case JLTHREAD_NMO_HOLDSLOCK:        \
00471     case JLTHREAD_NMO_GETPRIORITY:      \
00472     case JLTHREAD_NMO_ISDAEMON:
00473 
00474 #define NATIVE_TABLE_JLTHREAD_JFLOAT  /**< No @c @b (jfloat) methods */
00475 #define NATIVE_TABLE_JLTHREAD_JLONG   /**< No @c @b (jlong) methods */
00476 #define NATIVE_TABLE_JLTHREAD_JDOUBLE /**< No @c @b (jdouble) methods*/
00477 
00478 /*@}*/
00479 
00480 #endif /* _jlThread_h_included_ */
00481 
00482 
00483 /* EOF */
00484 

Generated on Fri Sep 30 18:48:58 2005 by  doxygen 1.4.4