00001 #ifndef _object_h_included_ 00002 #define _object_h_included_ 00003 00004 /*! 00005 * @file object.h 00006 * 00007 * @brief Definition of the @c @b java.lang.Object structure in 00008 * this real machine implementation. 00009 * 00010 * When initializing an object, the following activities happen in 00011 * the object array: 00012 * 00013 * <b>(1)</b> Its @link #jvm_object_hash jvm_object_hash@endlink is 00014 * used to address an empty slot in the object storage area. 00015 * 00016 * <b>(2)</b> Its @link #ACC_PUBLIC ACC_xxx@endlink flags from the 00017 * class file are stored into 00018 * @link robject#access_flags access_flags@endlink. 00019 * 00020 * <b>(3)</b> Its @link #robject.mlock_thridx mlock_thridx@endlink 00021 * is cleared, that is, no thread holds its monitor lock. 00022 * 00023 * <b>(4)</b> Since it is not a 00024 * @link #jvm_object_hash_null jvm_object_hash_null@endlink 00025 * value, its 00026 * @link robject#status status@endlink is set to 00027 * @link #OBJECT_STATUS_INUSE OBJECT_STATUS_INUSE@endlink. 00028 * All other bits are clear. 00029 * 00030 * <b>(5)</b> Declare to garbage collection that this object is now 00031 * referenced. 00032 * 00033 * <b>(6)</b> The data value(s) are stored in the array 00034 * @link robject#object_instance_field_data 00035 object_instance_field_data@endlink according to their 00036 * various types. Since this array is a (jvalue), fields 00037 * of @e any @b mixed type may be stored here. For example, 00038 * An (int) is stored in 00039 * @link robject#object_instance_field_data 00040 object_instance_field_data@endlink.@link 00041 jvalue#_jint _jint@endlink), while an object reference is 00042 * stored in @link robject#object_instance_field_data 00043 object_instance_field_data@endlink.@link 00044 jvalue#_jobjhash _jobjhash@endlink. Notice that a 00045 * @c @b java.lang.Integer is @em not an (int), and 00046 * has its several fields stored in this array as their 00047 * normal types. 00048 * 00049 * 00050 * @section Control 00051 * 00052 * \$URL: https://svn.apache.org/path/name/object.h $ \$Id: object.h 0 09/28/2005 dlydick $ 00053 * 00054 * Copyright 2005 The Apache Software Foundation 00055 * or its licensors, as applicable. 00056 * 00057 * Licensed under the Apache License, Version 2.0 ("the License"); 00058 * you may not use this file except in compliance with the License. 00059 * You may obtain a copy of the License at 00060 * 00061 * http://www.apache.org/licenses/LICENSE-2.0 00062 * 00063 * Unless required by applicable law or agreed to in writing, 00064 * software distributed under the License is distributed on an 00065 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 00066 * either express or implied. 00067 * 00068 * See the License for the specific language governing permissions 00069 * and limitations under the License. 00070 * 00071 * @version \$LastChangedRevision: 0 $ 00072 * 00073 * @date \$LastChangedDate: 09/28/2005 $ 00074 * 00075 * @author \$LastChangedBy: dlydick $ 00076 * Original code contributed by Daniel Lydick on 09/28/2005. 00077 * 00078 * @section Reference 00079 * 00080 */ 00081 00082 ARCH_COPYRIGHT_APACHE(object, h, "$URL: https://svn.apache.org/path/name/object.h $ $Id: object.h 0 09/28/2005 dlydick $"); 00083 00084 00085 /* 00086 * Macros for addressing objects 00087 */ 00088 00089 /*! 00090 * @def OBJECT 00091 * @brief Access structures of object table at certain index. 00092 * 00093 * The object table, being an array of slots, provides space for 00094 * one object instance per slot. This macro references one of 00095 * them using the @p @b objhash index. 00096 * 00097 * @param objhash Object table index into the global 00098 * @link #rjvm.object rjvm.object[]@endlink array (via 00099 * @link #pjvm pjvm->object[]@endlink). 00100 * 00101 * 00102 * @returns pointer to a object slot 00103 */ 00104 #define OBJECT(objhash) pjvm->object[objhash] 00105 00106 /*! 00107 * @brief Type definition for references to Java classes, enums, 00108 * interfaces. 00109 * 00110 * This information points to the major structures 00111 * for purposes of cross-referencing objects to ClassFile structures, 00112 * objects to/from classes, and objects to/from threads. 00113 * 00114 * The macro CLASS_OBJECT_LINKAGE() is designed to access this structure 00115 * given any class table index. 00116 * 00117 * The macro OBJECT_CLASS_LINKAGE() is designed to access this structure 00118 * given any object hash. 00119 * 00120 * The macro THREAD_OBJECT_LINKAGE() is designed to access this 00121 * structure given any thread table index. 00122 * 00123 * The macro OBJECT_THREAD_LINKAGE() is designed to access this 00124 * structure given any object hash. 00125 */ 00126 typedef struct 00127 { 00128 ClassFile *pcfs; /**< Class file storage area */ 00129 00130 jvm_class_index clsidx; /**< JVM class table class defn index */ 00131 00132 jvm_thread_index thridx; /**< JVM thread table class defn index, 00133 * meaninful only if this is a 00134 * @c @b java.lang.Thread 00135 * object, else @link 00136 * #jvm_thread_index_null 00137 jvm_thread_index_null@endlink 00138 */ 00139 } jvm_table_linkage; 00140 00141 00142 /*! 00143 * @brief General object slot definition. 00144 */ 00145 typedef struct 00146 { 00147 rushort status; /**< Runtime status of object, bitwise */ 00148 00149 /*! 00150 * @name Object status bits 00151 * 00152 * @brief Bitwise status bits for the status of an object slot. 00153 * 00154 * These object status bits have direct 00155 * @link #CLASS_STATUS_EMPTY CLASS_STATUS_xxx@endlink equivalents and a 00156 * few @link #THREAD_STATUS_EMPTY THREAD_STATUS_xxx@endlink equivalents 00157 * also. There are no overloaded bit positions between them 00158 * (for ease of diagnostics). 00159 */ 00160 00161 /*@{ */ /* Begin grouped definitions */ 00162 00163 /****** First 2 bits same for class, object, and thread ***********/ 00164 #define OBJECT_STATUS_EMPTY 0x0000 /**< This slot is available 00165 for use */ 00166 #define OBJECT_STATUS_INUSE 0x0001 /**< This slot contains an object */ 00167 #define OBJECT_STATUS_NULL 0x0002 /**< NULL object (only 1 exists in 00168 * normal use, any else besides the 00169 * JVMCFG_NULL_OBJECT is an object 00170 * slot now being initialized.) */ 00171 /******************************************************************/ 00172 00173 /****** Next 2 bits same for class and object *********************/ 00174 #define OBJECT_STATUS_ARRAY 0x0004 /**< Object is an array instead of 00175 an object instance*/ 00176 #define OBJECT_STATUS_GCREQ 0x0008 /**< Object may be garbage 00177 collected */ 00178 /******************************************************************/ 00179 00180 /****** Next 5 bits unique between class and object ***************/ 00181 #define OBJECT_STATUS_CLASS 0x0020 /**< This object is a class 00182 definition instead of an 00183 object instance */ 00184 #define OBJECT_STATUS_SUBARRAY 0x0020/**< This is a subset of an array, 00185 that is, of smaller dimension*/ 00186 #define OBJECT_STATUS_THREAD 0x0040 /**< Object is a 00187 @c @b java/Lang/Thread */ 00188 #define OBJECT_STATUS_REFERENCE 0x0080 /**< Object instance variable is 00189 * a reference. This is the 00190 * @e same definition as for 00191 * @link #CLASS_STATUS_REFERENCE 00192 CLASS_STATUS_REFERENCE@endlink 00193 * and for 00194 * @link #LOCAL_STATUS_REFERENCE 00195 LOCAL_STATUS_REFERENCE@endlink, 00196 * the local variable reference 00197 * bit for variables on the stack 00198 * frame, where the GC algorithm 00199 * implements it. 00200 */ 00201 #define OBJECT_STATUS_MLOCK 0x0100 /**< Object monitor locked by 00202 @link #robject.mlock_thridx 00203 mlock_thridx@endlink */ 00204 /******************************************************************/ 00205 00206 /****** Next 4 bits unique between class and object ***************/ 00207 /******************************************************************/ 00208 00209 /****** Last 3 bits not used by class or object *******************/ 00210 #define OBJECT_STATUS_2000 0x2000 /**< not used */ 00211 #define OBJECT_STATUS_4000 0x4000 /**< not used */ 00212 #define OBJECT_STATUS_8000 0x8000 /**< not used */ 00213 /******************************************************************/ 00214 00215 /*@} */ /* End of grouped definitions */ 00216 00217 jvm_basetype arraybasetype; /**< Base element type of array, 00218 * meaningful only when @link 00219 #OBJECT_STATUS_ARRAY 00220 OBJECT_STATUS_ARRAY@endlink is set 00221 */ 00222 00223 jvm_array_dim arraydims; /** Num dimensions for array, 00224 * meaningful only when @link 00225 #OBJECT_STATUS_ARRAY 00226 OBJECT_STATUS_ARRAY@endlink is set 00227 */ 00228 00229 jint *arraylength; /**< Length of array in @e each 00230 * dimension, from this one on down 00231 * to object instances. Meaningful 00232 * only when when @link 00233 #OBJECT_STATUS_ARRAY 00234 OBJECT_STATUS_ARRAY@endlink is set 00235 */ 00236 00237 rvoid *arraydata; /**< Data for an arbitrary array. For 00238 * @link #arraydims arraydims@endlink 00239 * of 0, it is not used,for 00240 * @link #arraydims arraydims@endlink 00241 * of 1, contains data for 00242 <b><code>((basetype) array)[arraylength[0]]</code></b>. 00243 For @link #arraydims arraydims@endlink 00244 * greater than 1, contains object 00245 * reference array to next lower 00246 * dimension, 00247 <b><code>((jvm_object_hash *) &arraydata)[arraylength[0]]</code></b> 00248 */ 00249 00250 jint mlock_count; /**< Number of times the object monitor 00251 was locked */ 00252 00253 jvm_thread_index mlock_thridx; /**< This thread holds monitor lock, 00254 * meaningful only when @link 00255 #OBJECT_STATUS_MLOCK 00256 OBJECT_STATUS_MLOCK@endlink is set 00257 */ 00258 00259 jvm_object_hash objhash_superclass; /**< Instance of 00260 * of this object's superclass. 00261 * @link #JVMCFG_NULL_OBJECT 00262 JVMCFG_NULL_OBJECT@endlink indicates 00263 * that the parent class is a 00264 * @c @b java.lang.Object 00265 */ 00266 00267 jvm_access_flags access_flags; /**< Holds class file 00268 * @link #ACC_PUBLIC ACC_xxx@endlink 00269 * values 00270 */ 00271 00272 jvm_table_linkage table_linkage; /**< Connect related instances of 00273 * ClassFile, rclass, robject, and 00274 * rthread structures. Used intensively 00275 * all over the code, this table is 00276 * found in each and every robject and 00277 * is the central structure in the 00278 * linkage macros of 00279 * @link jvm/src/linkage.h 00280 * linkage.h@endlink . 00281 */ 00282 00283 jvalue *object_instance_field_data; /**< Object instance data 00284 * data contents array[]. The 00285 * associated field lookup table is 00286 * located in its rclass table entry 00287 * @link 00288 #rclass.object_instance_field_lookup 00289 rclass.object_instance_field_lookup@endlink 00290 00291 * since these lookups are the same for 00292 * every instance object of this class. 00293 * Not meaningful when @link 00294 #OBJECT_STATUS_ARRAY 00295 OBJECT_STATUS_ARRAY@endlink 00296 * is set. Instead, see 00297 * @link #arraydata arraydata@endlink 00298 */ 00299 00300 rvoid *pgarbage; /**< Garbage collection profile of 00301 * this class. An 00302 * @link #rvoid rvoid@endlink pointer 00303 * is used here to avoid linking this 00304 * structure to any particular GC 00305 * implementation. 00306 */ 00307 00308 } robject; 00309 00310 #ifndef LOCAL_STATUS_REFERENCE 00311 /*! 00312 * @brief Reserved symbol for garbage collection of 00313 * local variables, distinguishing primatives from reference types. 00314 * 00315 * When garbage collecting local variables on the stack, 00316 * there must be a distinction drawn between local variables that 00317 * are primative data types and those that area reference types. 00318 * This symbol is reserved for that purpose. If implemented, it 00319 * will @e always be found in the @b gc_XXX.c and @b gc_XXX.h source 00320 * files and will @e never be found anywhere else. However, it is 00321 * also mentioned in the documentation outside of GC modules; 00322 * therefore, it is documented here for completeness. 00323 * 00324 * The actual value and implementation of this symbol is dependent 00325 * on the GC system and the constraints given elsewhere in the 00326 * documentation. The value given here is a dummy value. Its 00327 * actual value must be declared previous to the inclusion in a 00328 * source file of this header file. 00329 * 00330 */ 00331 #define LOCAL_STATUS_REFERENCE OBJECT_STATUS_REFERENCE 00332 00333 #endif 00334 00335 /* Prototypes for functions in 'object.c' */ 00336 00337 extern rvoid object_init(rvoid); 00338 extern rvoid object_shutdown(rvoid); 00339 extern rvoid object_new_setup(jvm_object_hash objhash); 00340 extern jvm_object_hash object_instance_new(rushort special_obj, 00341 ClassFile *pcfs, 00342 jvm_class_index clsidx, 00343 jvm_array_dim arraydims, 00344 jint *arraylength, 00345 rboolean run_init_, 00346 jvm_thread_index thridx); 00347 extern rvoid object_instance_finalize(jvm_object_hash objhash, 00348 jvm_thread_index thridx); 00349 extern jvm_object_hash object_instance_delete(jvm_object_hash objhash, 00350 rboolean rmref); 00351 00352 00353 /* Prototypes for functions in 'objectutil.c' */ 00354 00355 extern rboolean objectutil_synchronize(jvm_object_hash objhashthis, 00356 jvm_thread_index thridx); 00357 00358 extern rvoid objectutil_unsynchronize(jvm_object_hash objhashthis, 00359 jvm_thread_index thridx); 00360 00361 extern rboolean objectutil_release(jvm_object_hash objhashthis, 00362 jvm_thread_index thridx); 00363 #endif /* _object_h_included_ */ 00364 00365 /* EOF */ 00366