00001 /*! 00002 * @file jlObject.c 00003 * 00004 * @brief Native implementation of @c @b java.lang.Object 00005 * 00006 * @todo Perform intelligent check on input parameter 00007 * @b objhash range for all functions. 00008 * 00009 * @todo In real life, the @b objhashthis values and @b clsidxthis 00010 * values will be valid or these functions could not be 00011 * invoked since these data types are @e mandatory for 00012 * referencing them. This probably means that the parameter 00013 * valididty checking could probably be relaxed. 00014 * 00015 * 00016 * @section Control 00017 * 00018 * \$URL: https://svn.apache.org/path/name/jlObject.c $ \$Id: jlObject.c 0 09/28/2005 dlydick $ 00019 * 00020 * Copyright 2005 The Apache Software Foundation 00021 * or its licensors, as applicable. 00022 * 00023 * Licensed under the Apache License, Version 2.0 ("the License"); 00024 * you may not use this file except in compliance with the License. 00025 * You may obtain a copy of the License at 00026 * 00027 * http://www.apache.org/licenses/LICENSE-2.0 00028 * 00029 * Unless required by applicable law or agreed to in writing, 00030 * software distributed under the License is distributed on an 00031 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 00032 * either express or implied. 00033 * 00034 * See the License for the specific language governing permissions 00035 * and limitations under the License. 00036 * 00037 * @version \$LastChangedRevision: 0 $ 00038 * 00039 * @date \$LastChangedDate: 09/28/2005 $ 00040 * 00041 * @author \$LastChangedBy: dlydick $ 00042 * Original code contributed by Daniel Lydick on 09/28/2005. 00043 * 00044 * @section Reference 00045 * 00046 */ 00047 00048 #include "arch.h" 00049 ARCH_COPYRIGHT_APACHE(jlObject, c, "$URL: https://svn.apache.org/path/name/jlObject.c $ $Id: jlObject.c 0 09/28/2005 dlydick $"); 00050 00051 00052 #include "jvmcfg.h" 00053 #include "classfile.h" 00054 #include "jvm.h" 00055 #include "linkage.h" 00056 #include "jvmclass.h" 00057 00058 00059 /*! 00060 * @name Native implementation of class static functions. 00061 * 00062 * The class index of the current class is always passed 00063 * as the first parameter. 00064 * 00065 * @note These @c @b java.lang.Object methods are unusual in that 00066 * they does not require a @c @b jobject (in parlance of this 00067 * implementation, a @link #jvm_object_hash jvm_object_hash@endlink) 00068 * to run because they are declared as @c @b static methods. As 00069 * implemented here, the usual @b objhashthis parameter is therefore 00070 * replaced by * @b clsidxthis. The thread context is located in 00071 * @link #CURRENT_THREAD CURRENT_THREAD@endlink. 00072 * 00073 */ 00074 00075 /*@{ */ /* Begin grouped definitions */ 00076 00077 /*@} */ /* End of grouped definitions */ 00078 00079 00080 /*! 00081 * @name Native implementation of object instance functions. 00082 * 00083 * The object hash of @c @b this object is always passed 00084 * as the first parameter. 00085 * 00086 */ 00087 00088 00089 /*@{ */ /* Begin grouped definitions */ 00090 00091 /*! 00092 * @brief Native implementation 00093 * of @c @b java.lang.Object.getClass() 00094 * 00095 * 00096 * @param objhashthis Object table hash of @c @b this object. 00097 * 00098 * 00099 * @returns @c @b java.lang.Object of OBJECT(objhashthis) 00100 * 00101 */ 00102 jvm_object_hash jlObject_getClass(jvm_object_hash objhashthis) 00103 { 00104 return( 00105 CLASS(OBJECT_CLASS_LINKAGE(objhashthis)->clsidx).class_objhash); 00106 00107 } /* END of jlObject_getClass() */ 00108 00109 00110 /*! 00111 * @brief Native implementation 00112 * of @c @b java.lang.Object.hashCode() 00113 * 00114 * 00115 * @param objhashthis Object table hash of @c @b this object. 00116 * 00117 * 00118 * @returns input @b objhashthis by definition 00119 * 00120 */ 00121 jvm_object_hash jlObject_hashCode(jvm_object_hash objhashthis) 00122 { 00123 return(objhashthis); 00124 00125 } /* END of jlObject_hashCode() */ 00126 00127 00128 /*! 00129 * @name Native implementations of java.lang.Object.wait() functions. 00130 * 00131 * @brief Implementation of related functions 00132 * @c @b java.lang.Object.wait() and 00133 * @c @b java.lang.Object.wait(jlong) . 00134 * 00135 * If this thread is not @link #THREAD_STATUS_INUSE 00136 THREAD_STATUS_INUSE@endlink, result is @link #jfalse jfalse@endlink. 00137 * Results are undefined if thread has the @b SLEEP, @b JOIN4EVER, 00138 * @b JOINTIMED, or @b INTERRUPTIBLEIO status or if thread has 00139 * been @b NOTIFIED or @b INTERRUPTED. 00140 * 00141 * This will only succeed if thread is in @b RUNNING state. 00142 * 00143 * It will fail of thread did not hold the object's monitor lock 00144 * so it could release it here. 00145 * 00146 * @param objhashthis Object table hash of @c @b this object. 00147 * 00148 * @param sleeptime Number of timer ticks (milliseconds) to sleep. 00149 * 00150 * 00151 * @returns @link #jvoid jvoid@endlink 00152 * 00153 * 00154 * @throws JVMCLASS_JAVA_LANG_INTERRUPTEDEXCEPTION 00155 * @link #JVMCLASS_JAVA_LANG_INTERRUPTEDEXCEPTION 00156 if another thread had interrupted this thread@endlink. 00157 * 00158 * @throws JVMCLASS_JAVA_LANG_ILLEGALMONITORSTATEEXCEPTION 00159 * @link #JVMCLASS_JAVA_LANG_ILLEGALMONITORSTATEEXCEPTION 00160 if current thread does not own the object's monitor lock@endlink. 00161 * 00162 * 00163 * @todo Make sure thread interruption logic below here is working. 00164 * 00165 */ 00166 00167 /*@{ */ /* Begin grouped definitions */ 00168 00169 /*! 00170 * @brief Wait until object monitor lock is released. 00171 * 00172 */ 00173 00174 jvoid jlObject_wait4ever(jvm_object_hash objhashthis) 00175 { 00176 if (((rtrue == VERIFY_OBJECT_THREAD_LINKAGE(objhashthis)) && 00177 (rtrue == VERIFY_THREAD_LINKAGE( 00178 OBJECT_THREAD_LINKAGE(objhashthis)->thridx))) && 00179 (OBJECT_STATUS_MLOCK & OBJECT(objhashthis).status) && 00180 (CURRENT_THREAD == (OBJECT(objhashthis).mlock_thridx))) 00181 { 00182 jvm_thread_index thridx = 00183 OBJECT_CLASS_LINKAGE(objhashthis)->thridx; 00184 00185 THREAD(thridx).status |= THREAD_STATUS_WAIT4EVER; 00186 (rvoid) objectutil_release(objhashthis, thridx); 00187 00188 return; 00189 } 00190 00191 /* This thread does not own the object's monitor lock */ 00192 thread_throw_exception(CURRENT_THREAD, 00193 THREAD_STATUS_THREW_EXCEPTION, 00194 JVMCLASS_JAVA_LANG_ILLEGALMONITORSTATEEXCEPTION); 00195 /*NOTREACHED*/ 00196 return; /* Satisfy compiler */ 00197 00198 } /* END of JlObject_wait4ever() */ 00199 00200 00201 /*! 00202 * @brief Wait until object monitor lock is released or a timeout 00203 * period has expired. 00204 * 00205 */ 00206 00207 jvoid jlObject_waittimed(jvm_object_hash objhashthis, 00208 jlong sleeptime) 00209 { 00210 if (((rtrue == VERIFY_OBJECT_THREAD_LINKAGE(objhashthis)) && 00211 (rtrue == VERIFY_THREAD_LINKAGE( 00212 OBJECT_THREAD_LINKAGE(objhashthis)->thridx))) && 00213 (OBJECT_STATUS_MLOCK & OBJECT(objhashthis).status) && 00214 (CURRENT_THREAD == (OBJECT(objhashthis).mlock_thridx))) 00215 { 00216 jvm_thread_index thridxthis = 00217 OBJECT_CLASS_LINKAGE(objhashthis)->thridx; 00218 THREAD(thridxthis).status |= THREAD_STATUS_JOINTIMED; 00219 THREAD(thridxthis).sleeptime = sleeptime; 00220 (rvoid) objectutil_release(objhashthis, thridxthis); 00221 00222 return; 00223 } 00224 00225 /* This thread does not own the object's monitor lock */ 00226 thread_throw_exception(CURRENT_THREAD, 00227 THREAD_STATUS_THREW_EXCEPTION, 00228 JVMCLASS_JAVA_LANG_ILLEGALMONITORSTATEEXCEPTION); 00229 /*NOTREACHED*/ 00230 return; /* Satisfy compiler */ 00231 00232 } /* END of JlObject_waittimed() */ 00233 00234 /*@} */ /* End of grouped definitions */ 00235 00236 00237 #if 0 00238 /*! 00239 * @brief Native implementation of @c @b java.lang.Object.clone() 00240 * 00241 * 00242 * @param objhashthis Object table hash of @c @b this object. 00243 * 00244 * 00245 * @returns object hash of object clone. 00246 * 00247 * @todo then need to throw SecurityException in 00248 * outer JVM loop when @link #jfalse jfalse@endlink. 00249 * 00250 */ 00251 00252 jvm_object_hash jlObject_clone(jvm_object_hash objhashthis) 00253 { 00254 if ((rtrue == VERIFY_OBJECT_THREAD_LINKAGE(objhashthis)) && 00255 (rtrue == VERIFY_THREAD_LINKAGE( 00256 OBJECT_THREAD_LINKAGE(objhashthis)->thridx))) 00257 { 00258 /* @todo Need to finish this implementation */ 00259 00260 return(jvm_object_hash_null); 00261 } 00262 return(jvm_object_hash_null); 00263 00264 } /* END of jlObject_clone() */ 00265 #endif 00266 00267 /*@} */ /* End of grouped definitions */ 00268 00269 00270 00271 /* EOF */ 00272