The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * Variables with library scope. |
| 19 | * |
| 20 | * Prefer this over scattered static and global variables -- it's easier to |
| 21 | * view the state in a debugger, it makes clean shutdown simpler, we can |
| 22 | * trivially dump the state into a crash log, and it dodges most naming |
| 23 | * collisions that will arise when we are embedded in a larger program. |
| 24 | * |
| 25 | * If we want multiple VMs per process, this can get stuffed into TLS (or |
| 26 | * accessed through a Thread field). May need to pass it around for some |
| 27 | * of the early initialization functions. |
| 28 | */ |
| 29 | #ifndef _DALVIK_GLOBALS |
| 30 | #define _DALVIK_GLOBALS |
| 31 | |
| 32 | #include <stdarg.h> |
| 33 | #include <pthread.h> |
| 34 | |
| 35 | #define MAX_BREAKPOINTS 20 /* used for a debugger optimization */ |
| 36 | |
Andy McFadden | 9651693 | 2009-10-28 17:39:02 -0700 | [diff] [blame] | 37 | /* private structures */ |
| 38 | typedef struct GcHeap GcHeap; |
| 39 | typedef struct BreakpointSet BreakpointSet; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 40 | |
| 41 | /* |
| 42 | * One of these for each -ea/-da/-esa/-dsa on the command line. |
| 43 | */ |
| 44 | typedef struct AssertionControl { |
| 45 | char* pkgOrClass; /* package/class string, or NULL for esa/dsa */ |
| 46 | int pkgOrClassLen; /* string length, for quick compare */ |
| 47 | bool enable; /* enable or disable */ |
| 48 | bool isPackage; /* string ended with "..."? */ |
| 49 | } AssertionControl; |
| 50 | |
| 51 | /* |
| 52 | * Execution mode, e.g. interpreter vs. JIT. |
| 53 | */ |
| 54 | typedef enum ExecutionMode { |
| 55 | kExecutionModeUnknown = 0, |
| 56 | kExecutionModeInterpPortable, |
| 57 | kExecutionModeInterpFast, |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 58 | #if defined(WITH_JIT) |
| 59 | kExecutionModeJit, |
| 60 | #endif |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 61 | } ExecutionMode; |
| 62 | |
| 63 | /* |
| 64 | * All fields are initialized to zero. |
| 65 | * |
| 66 | * Storage allocated here must be freed by a subsystem shutdown function or |
| 67 | * from within freeGlobals(). |
| 68 | */ |
| 69 | struct DvmGlobals { |
| 70 | /* |
| 71 | * Some options from the command line or environment. |
| 72 | */ |
| 73 | char* bootClassPathStr; |
| 74 | char* classPathStr; |
| 75 | |
| 76 | unsigned int heapSizeStart; |
| 77 | unsigned int heapSizeMax; |
| 78 | unsigned int stackSize; |
| 79 | |
| 80 | bool verboseGc; |
| 81 | bool verboseJni; |
| 82 | bool verboseClass; |
Andy McFadden | 43eb501 | 2010-02-01 16:56:53 -0800 | [diff] [blame] | 83 | bool verboseShutdown; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 84 | |
| 85 | bool jdwpAllowed; // debugging allowed for this process? |
| 86 | bool jdwpConfigured; // has debugging info been provided? |
| 87 | int jdwpTransport; |
| 88 | bool jdwpServer; |
| 89 | char* jdwpHost; |
| 90 | int jdwpPort; |
| 91 | bool jdwpSuspend; |
| 92 | |
| 93 | int (*vfprintfHook)(FILE*, const char*, va_list); |
| 94 | void (*exitHook)(int); |
| 95 | void (*abortHook)(void); |
| 96 | |
| 97 | int jniGrefLimit; // 0 means no limit |
| 98 | bool reduceSignals; |
| 99 | bool noQuitHandler; |
| 100 | bool verifyDexChecksum; |
| 101 | char* stackTraceFile; // for SIGQUIT-inspired output |
| 102 | |
| 103 | bool logStdio; |
| 104 | |
| 105 | DexOptimizerMode dexOptMode; |
| 106 | DexClassVerifyMode classVerifyMode; |
The Android Open Source Project | 9940988 | 2009-03-18 22:20:24 -0700 | [diff] [blame] | 107 | bool preciseGc; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 108 | bool generateRegisterMaps; |
| 109 | |
| 110 | int assertionCtrlCount; |
| 111 | AssertionControl* assertionCtrl; |
| 112 | |
| 113 | ExecutionMode executionMode; |
| 114 | |
| 115 | /* |
| 116 | * VM init management. |
| 117 | */ |
| 118 | bool initializing; |
| 119 | int initExceptionCount; |
| 120 | bool optimizing; |
| 121 | |
| 122 | /* |
| 123 | * java.lang.System properties set from the command line. |
| 124 | */ |
| 125 | int numProps; |
| 126 | int maxProps; |
| 127 | char** propList; |
| 128 | |
| 129 | /* |
| 130 | * Where the VM goes to find system classes. |
| 131 | */ |
| 132 | ClassPathEntry* bootClassPath; |
| 133 | /* used by the DEX optimizer to load classes from an unfinished DEX */ |
| 134 | DvmDex* bootClassPathOptExtra; |
| 135 | bool optimizingBootstrapClass; |
| 136 | |
| 137 | /* |
| 138 | * Loaded classes, hashed by class name. Each entry is a ClassObject*, |
| 139 | * allocated in GC space. |
| 140 | */ |
| 141 | HashTable* loadedClasses; |
| 142 | |
| 143 | /* |
| 144 | * Value for the next class serial number to be assigned. This is |
| 145 | * incremented as we load classes. Failed loads and races may result |
| 146 | * in some numbers being skipped, and the serial number is not |
| 147 | * guaranteed to start at 1, so the current value should not be used |
| 148 | * as a count of loaded classes. |
| 149 | */ |
| 150 | volatile int classSerialNumber; |
| 151 | |
| 152 | /* |
Barry Hayes | 2c98747 | 2009-04-06 10:03:48 -0700 | [diff] [blame] | 153 | * Classes with a low classSerialNumber are probably in the zygote, and |
| 154 | * their InitiatingLoaderList is not used, to promote sharing. The list is |
| 155 | * kept here instead. |
| 156 | */ |
| 157 | InitiatingLoaderList* initiatingLoaderList; |
| 158 | |
| 159 | /* |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 160 | * Interned strings. |
| 161 | */ |
| 162 | HashTable* internedStrings; |
| 163 | |
| 164 | /* |
| 165 | * Quick lookups for popular classes used internally. |
| 166 | */ |
| 167 | ClassObject* unlinkedJavaLangClass; // see unlinkedJavaLangClassObject |
| 168 | ClassObject* classJavaLangClass; |
| 169 | ClassObject* classJavaLangClassArray; |
| 170 | ClassObject* classJavaLangError; |
| 171 | ClassObject* classJavaLangObject; |
| 172 | ClassObject* classJavaLangObjectArray; |
| 173 | ClassObject* classJavaLangRuntimeException; |
| 174 | ClassObject* classJavaLangString; |
| 175 | ClassObject* classJavaLangThread; |
| 176 | ClassObject* classJavaLangVMThread; |
| 177 | ClassObject* classJavaLangThreadGroup; |
| 178 | ClassObject* classJavaLangThrowable; |
Andy McFadden | 4fbba1f | 2010-02-03 07:21:14 -0800 | [diff] [blame] | 179 | ClassObject* classJavaLangStackOverflowError; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 180 | ClassObject* classJavaLangStackTraceElement; |
| 181 | ClassObject* classJavaLangStackTraceElementArray; |
| 182 | ClassObject* classJavaLangAnnotationAnnotationArray; |
| 183 | ClassObject* classJavaLangAnnotationAnnotationArrayArray; |
| 184 | ClassObject* classJavaLangReflectAccessibleObject; |
| 185 | ClassObject* classJavaLangReflectConstructor; |
| 186 | ClassObject* classJavaLangReflectConstructorArray; |
| 187 | ClassObject* classJavaLangReflectField; |
| 188 | ClassObject* classJavaLangReflectFieldArray; |
| 189 | ClassObject* classJavaLangReflectMethod; |
| 190 | ClassObject* classJavaLangReflectMethodArray; |
| 191 | ClassObject* classJavaLangReflectProxy; |
| 192 | ClassObject* classJavaLangExceptionInInitializerError; |
Andy McFadden | b18992f | 2009-09-25 10:42:15 -0700 | [diff] [blame] | 193 | ClassObject* classJavaLangRefPhantomReference; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 194 | ClassObject* classJavaLangRefReference; |
Andy McFadden | 8e5c784 | 2009-07-23 17:47:18 -0700 | [diff] [blame] | 195 | ClassObject* classJavaNioReadWriteDirectByteBuffer; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 196 | ClassObject* classJavaSecurityAccessController; |
| 197 | ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationFactory; |
| 198 | ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMember; |
| 199 | ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMemberArray; |
Andy McFadden | 5f612b8 | 2009-07-22 15:07:27 -0700 | [diff] [blame] | 200 | ClassObject* classOrgApacheHarmonyNioInternalDirectBuffer; |
Andy McFadden | d5ab726 | 2009-08-25 07:19:34 -0700 | [diff] [blame] | 201 | jclass jclassOrgApacheHarmonyNioInternalDirectBuffer; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 202 | |
| 203 | /* synthetic classes for arrays of primitives */ |
| 204 | ClassObject* classArrayBoolean; |
| 205 | ClassObject* classArrayChar; |
| 206 | ClassObject* classArrayFloat; |
| 207 | ClassObject* classArrayDouble; |
| 208 | ClassObject* classArrayByte; |
| 209 | ClassObject* classArrayShort; |
| 210 | ClassObject* classArrayInt; |
| 211 | ClassObject* classArrayLong; |
| 212 | |
| 213 | /* method offsets - Object */ |
| 214 | int voffJavaLangObject_equals; |
| 215 | int voffJavaLangObject_hashCode; |
| 216 | int voffJavaLangObject_toString; |
| 217 | int voffJavaLangObject_finalize; |
| 218 | |
| 219 | /* field offsets - Class */ |
| 220 | int offJavaLangClass_pd; |
| 221 | |
| 222 | /* field offsets - String */ |
| 223 | volatile int javaLangStringReady; /* 0=not init, 1=ready, -1=initing */ |
| 224 | int offJavaLangString_value; |
| 225 | int offJavaLangString_count; |
| 226 | int offJavaLangString_offset; |
| 227 | int offJavaLangString_hashCode; |
| 228 | |
| 229 | /* field offsets - Thread */ |
| 230 | int offJavaLangThread_vmThread; |
| 231 | int offJavaLangThread_group; |
| 232 | int offJavaLangThread_daemon; |
| 233 | int offJavaLangThread_name; |
| 234 | int offJavaLangThread_priority; |
| 235 | |
| 236 | /* method offsets - Thread */ |
| 237 | int voffJavaLangThread_run; |
| 238 | |
| 239 | /* field offsets - VMThread */ |
| 240 | int offJavaLangVMThread_thread; |
| 241 | int offJavaLangVMThread_vmData; |
| 242 | |
| 243 | /* method offsets - ThreadGroup */ |
| 244 | int voffJavaLangThreadGroup_removeThread; |
| 245 | |
| 246 | /* field offsets - Throwable */ |
| 247 | int offJavaLangThrowable_stackState; |
| 248 | int offJavaLangThrowable_message; |
| 249 | int offJavaLangThrowable_cause; |
| 250 | |
| 251 | /* field offsets - java.lang.reflect.* */ |
| 252 | int offJavaLangReflectAccessibleObject_flag; |
| 253 | int offJavaLangReflectConstructor_slot; |
| 254 | int offJavaLangReflectConstructor_declClass; |
| 255 | int offJavaLangReflectField_slot; |
| 256 | int offJavaLangReflectField_declClass; |
| 257 | int offJavaLangReflectMethod_slot; |
| 258 | int offJavaLangReflectMethod_declClass; |
| 259 | |
| 260 | /* field offsets - java.lang.ref.Reference */ |
| 261 | int offJavaLangRefReference_referent; |
| 262 | int offJavaLangRefReference_queue; |
| 263 | int offJavaLangRefReference_queueNext; |
| 264 | int offJavaLangRefReference_vmData; |
| 265 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 266 | /* method pointers - java.lang.ref.Reference */ |
| 267 | Method* methJavaLangRefReference_enqueueInternal; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 268 | |
| 269 | /* field offsets - java.nio.Buffer and java.nio.DirectByteBufferImpl */ |
| 270 | //int offJavaNioBuffer_capacity; |
| 271 | //int offJavaNioDirectByteBufferImpl_pointer; |
| 272 | |
| 273 | /* method pointers - java.security.AccessController */ |
| 274 | volatile bool javaSecurityAccessControllerReady; |
| 275 | Method* methJavaSecurityAccessController_doPrivileged[4]; |
| 276 | |
| 277 | /* constructor method pointers; no vtable involved, so use Method* */ |
| 278 | Method* methJavaLangStackTraceElement_init; |
| 279 | Method* methJavaLangExceptionInInitializerError_init; |
Andy McFadden | b18992f | 2009-09-25 10:42:15 -0700 | [diff] [blame] | 280 | Method* methJavaLangRefPhantomReference_init; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 281 | Method* methJavaLangReflectConstructor_init; |
| 282 | Method* methJavaLangReflectField_init; |
| 283 | Method* methJavaLangReflectMethod_init; |
| 284 | Method* methOrgApacheHarmonyLangAnnotationAnnotationMember_init; |
| 285 | |
| 286 | /* static method pointers - android.lang.annotation.* */ |
| 287 | Method* |
| 288 | methOrgApacheHarmonyLangAnnotationAnnotationFactory_createAnnotation; |
| 289 | |
| 290 | /* direct method pointers - java.lang.reflect.Proxy */ |
| 291 | Method* methJavaLangReflectProxy_constructorPrototype; |
| 292 | |
| 293 | /* field offsets - java.lang.reflect.Proxy */ |
| 294 | int offJavaLangReflectProxy_h; |
| 295 | |
| 296 | /* fake native entry point method */ |
| 297 | Method* methFakeNativeEntry; |
| 298 | |
Andy McFadden | 8e5c784 | 2009-07-23 17:47:18 -0700 | [diff] [blame] | 299 | /* assorted direct buffer helpers */ |
| 300 | Method* methJavaNioReadWriteDirectByteBuffer_init; |
| 301 | Method* methOrgApacheHarmonyLuniPlatformPlatformAddress_on; |
Andy McFadden | 5f612b8 | 2009-07-22 15:07:27 -0700 | [diff] [blame] | 302 | Method* methOrgApacheHarmonyNioInternalDirectBuffer_getEffectiveAddress; |
Andy McFadden | 8e5c784 | 2009-07-23 17:47:18 -0700 | [diff] [blame] | 303 | int offJavaNioBuffer_capacity; |
Andy McFadden | 8e696dc | 2009-07-24 15:28:16 -0700 | [diff] [blame] | 304 | int offJavaNioBuffer_effectiveDirectAddress; |
Andy McFadden | 8e5c784 | 2009-07-23 17:47:18 -0700 | [diff] [blame] | 305 | int offOrgApacheHarmonyLuniPlatformPlatformAddress_osaddr; |
| 306 | int voffOrgApacheHarmonyLuniPlatformPlatformAddress_toLong; |
Andy McFadden | 5f612b8 | 2009-07-22 15:07:27 -0700 | [diff] [blame] | 307 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 308 | /* |
| 309 | * VM-synthesized primitive classes, for arrays. |
| 310 | */ |
| 311 | ClassObject* volatile primitiveClass[PRIM_MAX]; |
| 312 | |
| 313 | /* |
| 314 | * A placeholder ClassObject used during ClassObject |
| 315 | * construction. |
| 316 | */ |
| 317 | ClassObject unlinkedJavaLangClassObject; |
| 318 | |
| 319 | /* |
| 320 | * Thread list. This always has at least one element in it (main), |
| 321 | * and main is always the first entry. |
| 322 | * |
| 323 | * The threadListLock is used for several things, including the thread |
| 324 | * start condition variable. Generally speaking, you must hold the |
| 325 | * threadListLock when: |
| 326 | * - adding/removing items from the list |
| 327 | * - waiting on or signaling threadStartCond |
| 328 | * - examining the Thread struct for another thread (this is to avoid |
| 329 | * one thread freeing the Thread struct while another thread is |
| 330 | * perusing it) |
| 331 | */ |
| 332 | Thread* threadList; |
| 333 | pthread_mutex_t threadListLock; |
| 334 | |
| 335 | pthread_cond_t threadStartCond; |
| 336 | |
| 337 | /* |
| 338 | * The thread code grabs this before suspending all threads. There |
Andy McFadden | 2aa4361 | 2009-06-17 16:29:30 -0700 | [diff] [blame] | 339 | * are a few things that can cause a "suspend all": |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 340 | * (1) the GC is starting; |
| 341 | * (2) the debugger has sent a "suspend all" request; |
| 342 | * (3) a thread has hit a breakpoint or exception that the debugger |
| 343 | * has marked as a "suspend all" event; |
| 344 | * (4) the SignalCatcher caught a signal that requires suspension. |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 345 | * (5) (if implemented) the JIT needs to perform a heavyweight |
| 346 | * rearrangement of the translation cache or JitTable. |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 347 | * |
| 348 | * Because we use "safe point" self-suspension, it is never safe to |
| 349 | * do a blocking "lock" call on this mutex -- if it has been acquired, |
| 350 | * somebody is probably trying to put you to sleep. The leading '_' is |
| 351 | * intended as a reminder that this lock is special. |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 352 | */ |
| 353 | pthread_mutex_t _threadSuspendLock; |
| 354 | |
| 355 | /* |
| 356 | * Guards Thread->suspendCount for all threads, and provides the lock |
| 357 | * for the condition variable that all suspended threads sleep on |
| 358 | * (threadSuspendCountCond). |
| 359 | * |
| 360 | * This has to be separate from threadListLock because of the way |
| 361 | * threads put themselves to sleep. |
| 362 | */ |
| 363 | pthread_mutex_t threadSuspendCountLock; |
| 364 | |
| 365 | /* |
| 366 | * Suspended threads sleep on this. They should sleep on the condition |
| 367 | * variable until their "suspend count" is zero. |
| 368 | * |
| 369 | * Paired with "threadSuspendCountLock". |
| 370 | */ |
| 371 | pthread_cond_t threadSuspendCountCond; |
| 372 | |
| 373 | /* |
Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 374 | * Sum of all threads' suspendCount fields. The JIT needs to know if any |
| 375 | * thread is suspended. Guarded by threadSuspendCountLock. |
| 376 | */ |
| 377 | int sumThreadSuspendCount; |
| 378 | |
| 379 | /* |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 380 | * MUTEX ORDERING: when locking multiple mutexes, always grab them in |
| 381 | * this order to avoid deadlock: |
| 382 | * |
| 383 | * (1) _threadSuspendLock (use lockThreadSuspend()) |
| 384 | * (2) threadListLock (use dvmLockThreadList()) |
| 385 | * (3) threadSuspendCountLock (use lockThreadSuspendCount()) |
| 386 | */ |
| 387 | |
| 388 | |
| 389 | /* |
| 390 | * Thread ID bitmap. We want threads to have small integer IDs so |
| 391 | * we can use them in "thin locks". |
| 392 | */ |
| 393 | BitVector* threadIdMap; |
| 394 | |
| 395 | /* |
| 396 | * Manage exit conditions. The VM exits when all non-daemon threads |
| 397 | * have exited. If the main thread returns early, we need to sleep |
| 398 | * on a condition variable. |
| 399 | */ |
| 400 | int nonDaemonThreadCount; /* must hold threadListLock to access */ |
| 401 | //pthread_mutex_t vmExitLock; |
| 402 | pthread_cond_t vmExitCond; |
| 403 | |
| 404 | /* |
| 405 | * The set of DEX files loaded by custom class loaders. |
| 406 | */ |
| 407 | HashTable* userDexFiles; |
| 408 | |
| 409 | /* |
| 410 | * JNI global reference table. |
| 411 | */ |
Andy McFadden | d5ab726 | 2009-08-25 07:19:34 -0700 | [diff] [blame] | 412 | #ifdef USE_INDIRECT_REF |
| 413 | IndirectRefTable jniGlobalRefTable; |
| 414 | #else |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 415 | ReferenceTable jniGlobalRefTable; |
Andy McFadden | d5ab726 | 2009-08-25 07:19:34 -0700 | [diff] [blame] | 416 | #endif |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 417 | pthread_mutex_t jniGlobalRefLock; |
| 418 | int jniGlobalRefHiMark; |
| 419 | int jniGlobalRefLoMark; |
| 420 | |
| 421 | /* |
Andy McFadden | c26bb63 | 2009-08-21 12:01:31 -0700 | [diff] [blame] | 422 | * JNI pinned object table (used for primitive arrays). |
| 423 | */ |
| 424 | ReferenceTable jniPinRefTable; |
| 425 | pthread_mutex_t jniPinRefLock; |
| 426 | |
Andy McFadden | b18992f | 2009-09-25 10:42:15 -0700 | [diff] [blame] | 427 | /* special ReferenceQueue for JNI weak globals */ |
| 428 | Object* jniWeakGlobalRefQueue; |
| 429 | |
Andy McFadden | c26bb63 | 2009-08-21 12:01:31 -0700 | [diff] [blame] | 430 | /* |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 431 | * Native shared library table. |
| 432 | */ |
| 433 | HashTable* nativeLibs; |
| 434 | |
| 435 | /* |
| 436 | * GC heap lock. Functions like gcMalloc() acquire this before making |
| 437 | * any changes to the heap. It is held throughout garbage collection. |
| 438 | */ |
| 439 | pthread_mutex_t gcHeapLock; |
| 440 | |
| 441 | /* Opaque pointer representing the heap. */ |
| 442 | GcHeap* gcHeap; |
| 443 | |
| 444 | /* |
Andy McFadden | 7fc3ce8 | 2009-07-14 15:57:23 -0700 | [diff] [blame] | 445 | * Pre-allocated throwables. |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 446 | */ |
| 447 | Object* outOfMemoryObj; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 448 | Object* internalErrorObj; |
Andy McFadden | 7fc3ce8 | 2009-07-14 15:57:23 -0700 | [diff] [blame] | 449 | Object* noClassDefFoundErrorObj; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 450 | |
| 451 | /* Monitor list, so we can free them */ |
| 452 | /*volatile*/ Monitor* monitorList; |
| 453 | |
| 454 | /* Monitor for Thread.sleep() implementation */ |
| 455 | Monitor* threadSleepMon; |
| 456 | |
| 457 | /* set when we create a second heap inside the zygote */ |
| 458 | bool newZygoteHeapAllocated; |
| 459 | |
| 460 | /* |
| 461 | * TLS keys. |
| 462 | */ |
| 463 | pthread_key_t pthreadKeySelf; /* Thread*, for dvmThreadSelf */ |
| 464 | |
| 465 | /* |
| 466 | * JNI allows you to have multiple VMs, but we limit ourselves to 1, |
| 467 | * so "vmList" is really just a pointer to the one and only VM. |
| 468 | */ |
| 469 | JavaVM* vmList; |
| 470 | |
| 471 | /* |
| 472 | * Cache results of "A instanceof B". |
| 473 | */ |
| 474 | AtomicCache* instanceofCache; |
| 475 | |
| 476 | /* instruction width table, used for optimization and verification */ |
| 477 | InstructionWidth* instrWidth; |
| 478 | /* instruction flags table, used for verification */ |
| 479 | InstructionFlags* instrFlags; |
| 480 | /* instruction format table, used for verification */ |
| 481 | InstructionFormat* instrFormat; |
| 482 | |
| 483 | /* |
| 484 | * Bootstrap class loader linear allocator. |
| 485 | */ |
| 486 | LinearAllocHdr* pBootLoaderAlloc; |
| 487 | |
| 488 | |
| 489 | /* |
| 490 | * Heap worker thread. |
| 491 | */ |
| 492 | bool heapWorkerInitialized; |
| 493 | bool heapWorkerReady; |
| 494 | bool haltHeapWorker; |
| 495 | pthread_t heapWorkerHandle; |
| 496 | pthread_mutex_t heapWorkerLock; |
| 497 | pthread_cond_t heapWorkerCond; |
| 498 | pthread_cond_t heapWorkerIdleCond; |
| 499 | pthread_mutex_t heapWorkerListLock; |
| 500 | |
| 501 | /* |
| 502 | * Compute some stats on loaded classes. |
| 503 | */ |
The Android Open Source Project | 9940988 | 2009-03-18 22:20:24 -0700 | [diff] [blame] | 504 | int numLoadedClasses; |
| 505 | int numDeclaredMethods; |
| 506 | int numDeclaredInstFields; |
| 507 | int numDeclaredStaticFields; |
| 508 | |
| 509 | /* when using a native debugger, set this to suppress watchdog timers */ |
| 510 | bool nativeDebuggerActive; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 511 | |
| 512 | /* |
| 513 | * JDWP debugger support. |
Andy McFadden | d51370f | 2009-08-05 15:20:27 -0700 | [diff] [blame] | 514 | * |
| 515 | * Note "debuggerActive" is accessed from mterp, so its storage size and |
| 516 | * meaning must not be changed without updating the assembly sources. |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 517 | */ |
| 518 | bool debuggerConnected; /* debugger or DDMS is connected */ |
Andy McFadden | d51370f | 2009-08-05 15:20:27 -0700 | [diff] [blame] | 519 | u1 debuggerActive; /* debugger is making requests */ |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 520 | JdwpState* jdwpState; |
| 521 | |
| 522 | /* |
| 523 | * Registry of objects known to the debugger. |
| 524 | */ |
| 525 | HashTable* dbgRegistry; |
| 526 | |
| 527 | /* |
Andy McFadden | 9651693 | 2009-10-28 17:39:02 -0700 | [diff] [blame] | 528 | * Debugger breakpoint table. |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 529 | */ |
Andy McFadden | 9651693 | 2009-10-28 17:39:02 -0700 | [diff] [blame] | 530 | BreakpointSet* breakpointSet; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 531 | |
| 532 | /* |
| 533 | * Single-step control struct. We currently only allow one thread to |
| 534 | * be single-stepping at a time, which is all that really makes sense, |
| 535 | * but it's possible we may need to expand this to be per-thread. |
| 536 | */ |
| 537 | StepControl stepControl; |
| 538 | |
| 539 | /* |
| 540 | * DDM features embedded in the VM. |
| 541 | */ |
| 542 | bool ddmThreadNotification; |
| 543 | |
| 544 | /* |
| 545 | * Zygote (partially-started process) support |
| 546 | */ |
| 547 | bool zygote; |
| 548 | |
| 549 | /* |
| 550 | * Used for tracking allocations that we report to DDMS. When the feature |
| 551 | * is enabled (through a DDMS request) the "allocRecords" pointer becomes |
| 552 | * non-NULL. |
| 553 | */ |
| 554 | pthread_mutex_t allocTrackerLock; |
| 555 | AllocRecord* allocRecords; |
| 556 | int allocRecordHead; /* most-recently-added entry */ |
| 557 | int allocRecordCount; /* #of valid entries */ |
| 558 | |
| 559 | #ifdef WITH_ALLOC_LIMITS |
| 560 | /* set on first use of an alloc limit, never cleared */ |
| 561 | bool checkAllocLimits; |
| 562 | /* allocation limit, for setGlobalAllocationLimit() regression testing */ |
| 563 | int allocationLimit; |
| 564 | #endif |
| 565 | |
| 566 | #ifdef WITH_DEADLOCK_PREDICTION |
| 567 | /* global lock on history tree accesses */ |
| 568 | pthread_mutex_t deadlockHistoryLock; |
| 569 | |
| 570 | enum { kDPOff=0, kDPWarn, kDPErr, kDPAbort } deadlockPredictMode; |
| 571 | #endif |
| 572 | |
| 573 | #ifdef WITH_PROFILER |
| 574 | /* |
| 575 | * When a profiler is enabled, this is incremented. Distinct profilers |
| 576 | * include "dmtrace" method tracing, emulator method tracing, and |
| 577 | * possibly instruction counting. |
| 578 | * |
| 579 | * The purpose of this is to have a single value that the interpreter |
| 580 | * can check to see if any profiling activity is enabled. |
| 581 | */ |
| 582 | volatile int activeProfilers; |
| 583 | |
| 584 | /* |
| 585 | * State for method-trace profiling. |
| 586 | */ |
| 587 | MethodTraceState methodTrace; |
| 588 | |
| 589 | /* |
| 590 | * State for emulator tracing. |
| 591 | */ |
| 592 | void* emulatorTracePage; |
| 593 | int emulatorTraceEnableCount; |
| 594 | |
| 595 | /* |
| 596 | * Global state for memory allocation profiling. |
| 597 | */ |
| 598 | AllocProfState allocProf; |
| 599 | |
| 600 | /* |
| 601 | * Pointers to the original methods for things that have been inlined. |
| 602 | * This makes it easy for us to output method entry/exit records for |
| 603 | * the method calls we're not actually making. |
| 604 | */ |
| 605 | Method** inlinedMethods; |
| 606 | |
| 607 | /* |
| 608 | * Dalvik instruction counts (256 entries). |
| 609 | */ |
| 610 | int* executedInstrCounts; |
| 611 | bool instructionCountEnableCount; |
| 612 | #endif |
| 613 | |
| 614 | /* |
| 615 | * Signal catcher thread (for SIGQUIT). |
| 616 | */ |
| 617 | pthread_t signalCatcherHandle; |
| 618 | bool haltSignalCatcher; |
| 619 | |
| 620 | /* |
| 621 | * Stdout/stderr conversion thread. |
| 622 | */ |
| 623 | bool haltStdioConverter; |
| 624 | bool stdioConverterReady; |
| 625 | pthread_t stdioConverterHandle; |
| 626 | pthread_mutex_t stdioConverterLock; |
| 627 | pthread_cond_t stdioConverterCond; |
| 628 | |
| 629 | /* |
| 630 | * pid of the system_server process. We track it so that when system server |
| 631 | * crashes the Zygote process will be killed and restarted. |
| 632 | */ |
| 633 | pid_t systemServerPid; |
| 634 | |
San Mehat | 894dd46 | 2009-09-08 20:29:15 -0700 | [diff] [blame] | 635 | int kernelGroupScheduling; |
| 636 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 637 | //#define COUNT_PRECISE_METHODS |
| 638 | #ifdef COUNT_PRECISE_METHODS |
| 639 | PointerSet* preciseMethods; |
| 640 | #endif |
The Android Open Source Project | 9940988 | 2009-03-18 22:20:24 -0700 | [diff] [blame] | 641 | |
| 642 | /* some RegisterMap statistics, useful during development */ |
| 643 | void* registerMapStats; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 644 | }; |
| 645 | |
| 646 | extern struct DvmGlobals gDvm; |
| 647 | |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 648 | #if defined(WITH_JIT) |
Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 649 | |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 650 | /* |
Ben Cheng | 6c10a97 | 2009-10-29 14:39:18 -0700 | [diff] [blame] | 651 | * Exiting the compiled code w/o chaining will incur overhead to look up the |
| 652 | * target in the code cache which is extra work only when JIT is enabled. So |
| 653 | * we want to monitor it closely to make sure we don't have performance bugs. |
| 654 | */ |
| 655 | typedef enum NoChainExits { |
| 656 | kInlineCacheMiss = 0, |
| 657 | kCallsiteInterpreted, |
| 658 | kSwitchOverflow, |
Bill Buzbee | eb695c6 | 2010-02-04 16:09:55 -0800 | [diff] [blame] | 659 | kHeavyweightMonitor, |
Ben Cheng | 6c10a97 | 2009-10-29 14:39:18 -0700 | [diff] [blame] | 660 | kNoChainExitLast, |
| 661 | } NoChainExits; |
| 662 | |
| 663 | /* |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 664 | * JIT-specific global state |
| 665 | */ |
| 666 | struct DvmJitGlobals { |
| 667 | /* |
| 668 | * Guards writes to Dalvik PC (dPC), translated code address (codeAddr) and |
| 669 | * chain fields within the JIT hash table. Note carefully the access |
| 670 | * mechanism. |
| 671 | * Only writes are guarded, and the guarded fields must be updated in a |
| 672 | * specific order using atomic operations. Further, once a field is |
| 673 | * written it cannot be changed without halting all threads. |
| 674 | * |
| 675 | * The write order is: |
| 676 | * 1) codeAddr |
| 677 | * 2) dPC |
| 678 | * 3) chain [if necessary] |
| 679 | * |
| 680 | * This mutex also guards both read and write of curJitTableEntries. |
| 681 | */ |
| 682 | pthread_mutex_t tableLock; |
| 683 | |
| 684 | /* The JIT hash table. Note that for access speed, copies of this pointer |
| 685 | * are stored in each thread. */ |
| 686 | struct JitEntry *pJitEntryTable; |
| 687 | |
| 688 | /* Array of profile threshold counters */ |
| 689 | unsigned char *pProfTable; |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 690 | |
Bill Buzbee | 06bb839 | 2010-01-31 18:53:15 -0800 | [diff] [blame] | 691 | /* Copy of pProfTable used for temporarily disabling the Jit */ |
| 692 | unsigned char *pProfTableCopy; |
| 693 | |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 694 | /* Size of JIT hash table in entries. Must be a power of 2 */ |
Bill Buzbee | 2717622 | 2009-06-09 09:20:16 -0700 | [diff] [blame] | 695 | unsigned int jitTableSize; |
| 696 | |
| 697 | /* Mask used in hash function for JitTable. Should be jitTableSize-1 */ |
| 698 | unsigned int jitTableMask; |
| 699 | |
| 700 | /* How many entries in the JitEntryTable are in use */ |
| 701 | unsigned int jitTableEntriesUsed; |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 702 | |
Ben Cheng | 7b133ef | 2010-02-04 16:15:59 -0800 | [diff] [blame] | 703 | /* Bytes allocated for the code cache */ |
| 704 | unsigned int codeCacheSize; |
| 705 | |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 706 | /* Trigger for trace selection */ |
| 707 | unsigned short threshold; |
| 708 | |
| 709 | /* JIT Compiler Control */ |
| 710 | bool haltCompilerThread; |
| 711 | bool blockingMode; |
| 712 | pthread_t compilerHandle; |
| 713 | pthread_mutex_t compilerLock; |
Ben Cheng | 6999d84 | 2010-01-26 16:46:15 -0800 | [diff] [blame] | 714 | pthread_mutex_t compilerICPatchLock; |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 715 | pthread_cond_t compilerQueueActivity; |
| 716 | pthread_cond_t compilerQueueEmpty; |
Ben Cheng | 88a0f97 | 2010-02-24 15:00:40 -0800 | [diff] [blame] | 717 | volatile int compilerQueueLength; |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 718 | int compilerHighWater; |
| 719 | int compilerWorkEnqueueIndex; |
| 720 | int compilerWorkDequeueIndex; |
Ben Cheng | 6999d84 | 2010-01-26 16:46:15 -0800 | [diff] [blame] | 721 | int compilerICPatchIndex; |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 722 | |
| 723 | /* JIT internal stats */ |
| 724 | int compilerMaxQueued; |
| 725 | int addrLookupsFound; |
| 726 | int addrLookupsNotFound; |
Ben Cheng | 6c10a97 | 2009-10-29 14:39:18 -0700 | [diff] [blame] | 727 | int noChainExit[kNoChainExitLast]; |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 728 | int normalExit; |
| 729 | int puntExit; |
| 730 | int translationChains; |
Ben Cheng | 86717f7 | 2010-03-05 15:27:21 -0800 | [diff] [blame] | 731 | int invokeMonomorphic; |
| 732 | int invokePolymorphic; |
Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 733 | int invokeNative; |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 734 | int returnOp; |
Ben Cheng | 86717f7 | 2010-03-05 15:27:21 -0800 | [diff] [blame] | 735 | u8 jitTime; |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 736 | |
| 737 | /* Compiled code cache */ |
| 738 | void* codeCache; |
| 739 | |
Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 740 | /* Bytes used by the code templates */ |
| 741 | unsigned int templateSize; |
| 742 | |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 743 | /* Bytes already used in the code cache */ |
| 744 | unsigned int codeCacheByteUsed; |
| 745 | |
| 746 | /* Number of installed compilations in the cache */ |
| 747 | unsigned int numCompilations; |
| 748 | |
| 749 | /* Flag to indicate that the code cache is full */ |
| 750 | bool codeCacheFull; |
| 751 | |
Ben Cheng | 7a0bcd0 | 2010-01-22 16:45:45 -0800 | [diff] [blame] | 752 | /* Number of times that the code cache has been reset */ |
| 753 | int numCodeCacheReset; |
| 754 | |
Ben Cheng | 6999d84 | 2010-01-26 16:46:15 -0800 | [diff] [blame] | 755 | /* Number of times that the code cache reset request has been delayed */ |
| 756 | int numCodeCacheResetDelayed; |
| 757 | |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 758 | /* true/false: compile/reject opcodes specified in the -Xjitop list */ |
| 759 | bool includeSelectedOp; |
| 760 | |
| 761 | /* true/false: compile/reject methods specified in the -Xjitmethod list */ |
| 762 | bool includeSelectedMethod; |
| 763 | |
| 764 | /* Disable JIT for selected opcodes - one bit for each opcode */ |
| 765 | char opList[32]; |
| 766 | |
| 767 | /* Disable JIT for selected methods */ |
| 768 | HashTable *methodTable; |
| 769 | |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 770 | /* Flag to dump all compiled code */ |
| 771 | bool printMe; |
Bill Buzbee | 6e963e1 | 2009-06-17 16:56:19 -0700 | [diff] [blame] | 772 | |
| 773 | /* Flag to count trace execution */ |
| 774 | bool profile; |
Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 775 | |
Ben Cheng | dcf3e5d | 2009-09-11 13:42:05 -0700 | [diff] [blame] | 776 | /* Vector to disable selected optimizations */ |
| 777 | int disableOpt; |
| 778 | |
Bill Buzbee | 9a8c75a | 2009-11-08 14:31:20 -0800 | [diff] [blame] | 779 | /* Code address of special interpret-only pseudo-translation */ |
| 780 | void *interpretTemplate; |
| 781 | |
Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 782 | /* Table to track the overall and trace statistics of hot methods */ |
| 783 | HashTable* methodStatsTable; |
Ben Cheng | bcdc1de | 2009-08-21 16:18:46 -0700 | [diff] [blame] | 784 | |
Ben Cheng | 3367245 | 2010-01-12 14:59:30 -0800 | [diff] [blame] | 785 | /* Filter method compilation blacklist with call-graph information */ |
| 786 | bool checkCallGraph; |
| 787 | |
Ben Cheng | 6999d84 | 2010-01-26 16:46:15 -0800 | [diff] [blame] | 788 | /* New translation chain has been set up */ |
| 789 | volatile bool hasNewChain; |
| 790 | |
Ben Cheng | bcdc1de | 2009-08-21 16:18:46 -0700 | [diff] [blame] | 791 | #if defined(WITH_SELF_VERIFICATION) |
| 792 | /* Spin when error is detected, volatile so GDB can reset it */ |
| 793 | volatile bool selfVerificationSpin; |
| 794 | #endif |
Ben Cheng | 6999d84 | 2010-01-26 16:46:15 -0800 | [diff] [blame] | 795 | |
Bill Buzbee | eb695c6 | 2010-02-04 16:09:55 -0800 | [diff] [blame] | 796 | /* Framework or stand-alone? */ |
| 797 | bool runningInAndroidFramework; |
| 798 | |
Ben Cheng | f30acbb | 2010-02-14 16:17:36 -0800 | [diff] [blame] | 799 | /* Framework callback happened? */ |
| 800 | bool alreadyEnabledViaFramework; |
| 801 | |
| 802 | /* Framework requests to disable the JIT for good */ |
| 803 | bool disableJit; |
| 804 | |
Ben Cheng | dca7143 | 2010-03-16 16:04:11 -0700 | [diff] [blame^] | 805 | #if defined(SIGNATURE_BREAKPOINT) |
| 806 | /* Signature breakpoint */ |
| 807 | u4 signatureBreakpointSize; // # of words |
| 808 | u4 *signatureBreakpoint; // Signature content |
| 809 | #endif |
| 810 | |
Ben Cheng | 6999d84 | 2010-01-26 16:46:15 -0800 | [diff] [blame] | 811 | /* Place arrays at the end to ease the display in gdb sessions */ |
| 812 | |
| 813 | /* Work order queue for compilations */ |
| 814 | CompilerWorkOrder compilerWorkQueue[COMPILER_WORK_QUEUE_SIZE]; |
| 815 | |
| 816 | /* Work order queue for predicted chain patching */ |
| 817 | ICPatchWorkOrder compilerICPatchQueue[COMPILER_IC_PATCH_QUEUE_SIZE]; |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 818 | }; |
| 819 | |
| 820 | extern struct DvmJitGlobals gDvmJit; |
| 821 | |
| 822 | #endif |
| 823 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 824 | #endif /*_DALVIK_GLOBALS*/ |