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