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 | |
Elliott Hughes | 49dc060 | 2011-02-10 12:03:34 -0800 | [diff] [blame] | 32 | #include <cutils/array.h> |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 33 | #include <stdarg.h> |
| 34 | #include <pthread.h> |
| 35 | |
| 36 | #define MAX_BREAKPOINTS 20 /* used for a debugger optimization */ |
| 37 | |
Andy McFadden | 9651693 | 2009-10-28 17:39:02 -0700 | [diff] [blame] | 38 | /* private structures */ |
| 39 | typedef struct GcHeap GcHeap; |
| 40 | typedef struct BreakpointSet BreakpointSet; |
Andy McFadden | cb3c542 | 2010-04-07 15:56:16 -0700 | [diff] [blame] | 41 | typedef struct InlineSub InlineSub; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 42 | |
| 43 | /* |
| 44 | * One of these for each -ea/-da/-esa/-dsa on the command line. |
| 45 | */ |
| 46 | typedef struct AssertionControl { |
| 47 | char* pkgOrClass; /* package/class string, or NULL for esa/dsa */ |
| 48 | int pkgOrClassLen; /* string length, for quick compare */ |
| 49 | bool enable; /* enable or disable */ |
| 50 | bool isPackage; /* string ended with "..."? */ |
| 51 | } AssertionControl; |
| 52 | |
| 53 | /* |
| 54 | * Execution mode, e.g. interpreter vs. JIT. |
| 55 | */ |
| 56 | typedef enum ExecutionMode { |
| 57 | kExecutionModeUnknown = 0, |
| 58 | kExecutionModeInterpPortable, |
| 59 | kExecutionModeInterpFast, |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 60 | #if defined(WITH_JIT) |
| 61 | kExecutionModeJit, |
| 62 | #endif |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 63 | } ExecutionMode; |
| 64 | |
| 65 | /* |
buzbee | cb3081f | 2011-01-14 13:37:31 -0800 | [diff] [blame] | 66 | * Execution sub modes, e.g. debugging, profiling, etc. |
| 67 | * Treated as bit flags for fast access. These values are used directly |
| 68 | * by assembly code in the mterp interpeter and may also be used by |
| 69 | * code generated by the JIT. Take care when changing. |
| 70 | */ |
| 71 | typedef enum ExecutionSubModes { |
| 72 | kSubModeNormal = 0x00, |
| 73 | kSubModeMethodTrace = 0x01, |
| 74 | kSubModeEmulatorTrace = 0x02, |
| 75 | kSubModeInstCounting = 0x04, |
| 76 | kSubModeDebuggerActive = 0x08, |
| 77 | kSubModeSuspendRequest = 0x10, /* Set if any suspend request active */ |
| 78 | } ExecutionSubModes; |
| 79 | |
| 80 | /* |
Andy McFadden | 701d272 | 2010-12-01 16:18:19 -0800 | [diff] [blame] | 81 | * Register map generation mode. Only applicable when generateRegisterMaps |
| 82 | * is enabled. (The "disabled" state is not folded into this because |
| 83 | * there are callers like dexopt that want to enable/disable without |
| 84 | * specifying the configuration details.) |
| 85 | * |
| 86 | * "TypePrecise" is slower and requires additional storage for the register |
| 87 | * maps, but allows type-precise GC. "LivePrecise" is even slower and |
| 88 | * requires additional heap during processing, but allows live-precise GC. |
| 89 | */ |
| 90 | typedef enum { |
| 91 | kRegisterMapModeUnknown = 0, |
| 92 | kRegisterMapModeTypePrecise, |
| 93 | kRegisterMapModeLivePrecise |
| 94 | } RegisterMapMode; |
| 95 | |
| 96 | /* |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 97 | * All fields are initialized to zero. |
| 98 | * |
| 99 | * Storage allocated here must be freed by a subsystem shutdown function or |
| 100 | * from within freeGlobals(). |
| 101 | */ |
| 102 | struct DvmGlobals { |
| 103 | /* |
| 104 | * Some options from the command line or environment. |
| 105 | */ |
| 106 | char* bootClassPathStr; |
| 107 | char* classPathStr; |
| 108 | |
Carl Shapiro | df9f08b | 2011-01-18 17:59:30 -0800 | [diff] [blame] | 109 | size_t heapStartingSize; |
| 110 | size_t heapMaximumSize; |
| 111 | size_t heapGrowthLimit; |
| 112 | size_t stackSize; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 113 | |
| 114 | bool verboseGc; |
| 115 | bool verboseJni; |
| 116 | bool verboseClass; |
Andy McFadden | 43eb501 | 2010-02-01 16:56:53 -0800 | [diff] [blame] | 117 | bool verboseShutdown; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 118 | |
| 119 | bool jdwpAllowed; // debugging allowed for this process? |
| 120 | bool jdwpConfigured; // has debugging info been provided? |
| 121 | int jdwpTransport; |
| 122 | bool jdwpServer; |
| 123 | char* jdwpHost; |
| 124 | int jdwpPort; |
| 125 | bool jdwpSuspend; |
| 126 | |
Andy McFadden | ea41434 | 2010-08-25 12:05:44 -0700 | [diff] [blame] | 127 | /* use wall clock as method profiler clock source? */ |
| 128 | bool profilerWallClock; |
| 129 | |
Carl Shapiro | b8fcf57 | 2010-04-16 17:33:15 -0700 | [diff] [blame] | 130 | /* |
| 131 | * Lock profiling threshold value in milliseconds. Acquires that |
| 132 | * exceed threshold are logged. Acquires within the threshold are |
| 133 | * logged with a probability of $\frac{time}{threshold}$ . If the |
| 134 | * threshold is unset no additional logging occurs. |
| 135 | */ |
Carl Shapiro | f0c514c | 2010-04-09 15:03:33 -0700 | [diff] [blame] | 136 | u4 lockProfThreshold; |
Carl Shapiro | f0c514c | 2010-04-09 15:03:33 -0700 | [diff] [blame] | 137 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 138 | int (*vfprintfHook)(FILE*, const char*, va_list); |
| 139 | void (*exitHook)(int); |
| 140 | void (*abortHook)(void); |
Brad Fitzpatrick | 3b55675 | 2010-12-13 16:53:28 -0800 | [diff] [blame] | 141 | bool (*isSensitiveThreadHook)(void); |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 142 | |
| 143 | int jniGrefLimit; // 0 means no limit |
Elliott Hughes | 8afa9df | 2010-07-07 14:47:25 -0700 | [diff] [blame] | 144 | char* jniTrace; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 145 | bool reduceSignals; |
| 146 | bool noQuitHandler; |
| 147 | bool verifyDexChecksum; |
| 148 | char* stackTraceFile; // for SIGQUIT-inspired output |
| 149 | |
| 150 | bool logStdio; |
| 151 | |
| 152 | DexOptimizerMode dexOptMode; |
| 153 | DexClassVerifyMode classVerifyMode; |
Barry Hayes | 5cbb230 | 2010-02-02 14:07:37 -0800 | [diff] [blame] | 154 | |
Andy McFadden | 701d272 | 2010-12-01 16:18:19 -0800 | [diff] [blame] | 155 | bool generateRegisterMaps; |
| 156 | RegisterMapMode registerMapMode; |
| 157 | |
Andy McFadden | 3f64a02 | 2010-11-12 16:55:21 -0800 | [diff] [blame] | 158 | bool monitorVerification; |
| 159 | |
Andy McFadden | c58b9ef | 2010-09-09 12:54:43 -0700 | [diff] [blame] | 160 | bool dexOptForSmp; |
| 161 | |
Barry Hayes | 962adba | 2010-03-17 12:12:39 -0700 | [diff] [blame] | 162 | /* |
| 163 | * GC option flags. |
| 164 | */ |
The Android Open Source Project | 9940988 | 2009-03-18 22:20:24 -0700 | [diff] [blame] | 165 | bool preciseGc; |
Barry Hayes | 962adba | 2010-03-17 12:12:39 -0700 | [diff] [blame] | 166 | bool preVerify; |
| 167 | bool postVerify; |
Carl Shapiro | ec805ea | 2010-06-28 16:28:26 -0700 | [diff] [blame] | 168 | bool concurrentMarkSweep; |
Barry Hayes | 6e5cf60 | 2010-06-22 12:32:59 -0700 | [diff] [blame] | 169 | bool verifyCardTable; |
Carl Shapiro | 821fd06 | 2011-01-19 12:56:14 -0800 | [diff] [blame] | 170 | bool disableExplicitGc; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 171 | |
| 172 | int assertionCtrlCount; |
| 173 | AssertionControl* assertionCtrl; |
| 174 | |
| 175 | ExecutionMode executionMode; |
| 176 | |
| 177 | /* |
| 178 | * VM init management. |
| 179 | */ |
| 180 | bool initializing; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 181 | bool optimizing; |
| 182 | |
| 183 | /* |
Elliott Hughes | 49dc060 | 2011-02-10 12:03:34 -0800 | [diff] [blame] | 184 | * java.lang.System properties set from the command line with -D. |
| 185 | * This is effectively a set, where later entries override earlier |
| 186 | * ones. |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 187 | */ |
Elliott Hughes | 49dc060 | 2011-02-10 12:03:34 -0800 | [diff] [blame] | 188 | Array* properties; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 189 | |
| 190 | /* |
| 191 | * Where the VM goes to find system classes. |
| 192 | */ |
| 193 | ClassPathEntry* bootClassPath; |
| 194 | /* used by the DEX optimizer to load classes from an unfinished DEX */ |
| 195 | DvmDex* bootClassPathOptExtra; |
| 196 | bool optimizingBootstrapClass; |
| 197 | |
| 198 | /* |
| 199 | * Loaded classes, hashed by class name. Each entry is a ClassObject*, |
| 200 | * allocated in GC space. |
| 201 | */ |
| 202 | HashTable* loadedClasses; |
| 203 | |
| 204 | /* |
| 205 | * Value for the next class serial number to be assigned. This is |
| 206 | * incremented as we load classes. Failed loads and races may result |
| 207 | * in some numbers being skipped, and the serial number is not |
| 208 | * guaranteed to start at 1, so the current value should not be used |
| 209 | * as a count of loaded classes. |
| 210 | */ |
| 211 | volatile int classSerialNumber; |
| 212 | |
| 213 | /* |
Barry Hayes | 2c98747 | 2009-04-06 10:03:48 -0700 | [diff] [blame] | 214 | * Classes with a low classSerialNumber are probably in the zygote, and |
| 215 | * their InitiatingLoaderList is not used, to promote sharing. The list is |
| 216 | * kept here instead. |
| 217 | */ |
| 218 | InitiatingLoaderList* initiatingLoaderList; |
| 219 | |
| 220 | /* |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 221 | * Interned strings. |
| 222 | */ |
Carl Shapiro | bb1e0e9 | 2010-07-21 14:49:25 -0700 | [diff] [blame] | 223 | |
| 224 | /* A mutex that guards access to the interned string tables. */ |
| 225 | pthread_mutex_t internLock; |
| 226 | |
| 227 | /* Hash table of strings interned by the user. */ |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 228 | HashTable* internedStrings; |
| 229 | |
Carl Shapiro | bb1e0e9 | 2010-07-21 14:49:25 -0700 | [diff] [blame] | 230 | /* Hash table of strings interned by the class loader. */ |
| 231 | HashTable* literalStrings; |
| 232 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 233 | /* |
Dan Bornstein | 318839c | 2011-03-14 11:00:35 -0700 | [diff] [blame] | 234 | * Classes constructed directly by the vm. |
| 235 | */ |
| 236 | |
| 237 | /* the class Class */ |
| 238 | ClassObject* classJavaLangClass; |
| 239 | |
| 240 | /* synthetic classes representing primitive types */ |
| 241 | ClassObject* typeVoid; |
| 242 | ClassObject* typeBoolean; |
| 243 | ClassObject* typeByte; |
| 244 | ClassObject* typeShort; |
| 245 | ClassObject* typeChar; |
| 246 | ClassObject* typeInt; |
| 247 | ClassObject* typeLong; |
| 248 | ClassObject* typeFloat; |
| 249 | ClassObject* typeDouble; |
| 250 | |
| 251 | /* synthetic classes for arrays of primitives */ |
| 252 | ClassObject* classArrayBoolean; |
| 253 | ClassObject* classArrayByte; |
| 254 | ClassObject* classArrayShort; |
| 255 | ClassObject* classArrayChar; |
| 256 | ClassObject* classArrayInt; |
| 257 | ClassObject* classArrayLong; |
| 258 | ClassObject* classArrayFloat; |
| 259 | ClassObject* classArrayDouble; |
| 260 | |
| 261 | /* |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 262 | * Quick lookups for popular classes used internally. |
| 263 | */ |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 264 | ClassObject* classJavaLangClassArray; |
Andy McFadden | 0970976 | 2011-03-18 14:27:06 -0700 | [diff] [blame] | 265 | ClassObject* classJavaLangClassLoader; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 266 | ClassObject* classJavaLangObject; |
| 267 | ClassObject* classJavaLangObjectArray; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 268 | ClassObject* classJavaLangString; |
| 269 | ClassObject* classJavaLangThread; |
| 270 | ClassObject* classJavaLangVMThread; |
| 271 | ClassObject* classJavaLangThreadGroup; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 272 | ClassObject* classJavaLangStackTraceElement; |
| 273 | ClassObject* classJavaLangStackTraceElementArray; |
| 274 | ClassObject* classJavaLangAnnotationAnnotationArray; |
| 275 | ClassObject* classJavaLangAnnotationAnnotationArrayArray; |
| 276 | ClassObject* classJavaLangReflectAccessibleObject; |
| 277 | ClassObject* classJavaLangReflectConstructor; |
| 278 | ClassObject* classJavaLangReflectConstructorArray; |
| 279 | ClassObject* classJavaLangReflectField; |
| 280 | ClassObject* classJavaLangReflectFieldArray; |
| 281 | ClassObject* classJavaLangReflectMethod; |
| 282 | ClassObject* classJavaLangReflectMethodArray; |
| 283 | ClassObject* classJavaLangReflectProxy; |
Andy McFadden | 8e5c784 | 2009-07-23 17:47:18 -0700 | [diff] [blame] | 284 | ClassObject* classJavaNioReadWriteDirectByteBuffer; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 285 | ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationFactory; |
| 286 | ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMember; |
| 287 | ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMemberArray; |
Carl Shapiro | 3475f9c | 2011-03-21 13:35:24 -0700 | [diff] [blame] | 288 | ClassObject* classJavaLangRefFinalizerReference; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 289 | |
Dan Bornstein | 32bb3da | 2011-02-24 15:47:20 -0800 | [diff] [blame] | 290 | /* |
| 291 | * classes representing exception types. The names here don't include |
| 292 | * packages, just to keep the use sites a bit less verbose. All are |
| 293 | * in java.lang, except where noted. |
| 294 | */ |
Dan Bornstein | 85ba81d | 2011-03-03 13:10:04 -0800 | [diff] [blame] | 295 | ClassObject* exAbstractMethodError; |
Dan Bornstein | 6d167a4 | 2011-02-25 13:31:45 -0800 | [diff] [blame] | 296 | ClassObject* exArithmeticException; |
| 297 | ClassObject* exArrayIndexOutOfBoundsException; |
| 298 | ClassObject* exArrayStoreException; |
| 299 | ClassObject* exClassCastException; |
Dan Bornstein | 85ba81d | 2011-03-03 13:10:04 -0800 | [diff] [blame] | 300 | ClassObject* exClassCircularityError; |
Dan Bornstein | 2c8e25b | 2011-02-25 15:49:29 -0800 | [diff] [blame] | 301 | ClassObject* exClassFormatError; |
Dan Bornstein | 9b598e3 | 2011-03-01 10:28:42 -0800 | [diff] [blame] | 302 | ClassObject* exClassNotFoundException; |
Dan Bornstein | 32bb3da | 2011-02-24 15:47:20 -0800 | [diff] [blame] | 303 | ClassObject* exError; |
| 304 | ClassObject* exExceptionInInitializerError; |
Dan Bornstein | 2c8e25b | 2011-02-25 15:49:29 -0800 | [diff] [blame] | 305 | ClassObject* exFileNotFoundException; /* in java.io */ |
| 306 | ClassObject* exIOException; /* in java.io */ |
Dan Bornstein | 537e29e | 2011-03-02 16:28:04 -0800 | [diff] [blame] | 307 | ClassObject* exIllegalAccessError; |
Dan Bornstein | 9b598e3 | 2011-03-01 10:28:42 -0800 | [diff] [blame] | 308 | ClassObject* exIllegalAccessException; |
Dan Bornstein | bc606f5 | 2011-03-01 13:22:13 -0800 | [diff] [blame] | 309 | ClassObject* exIllegalArgumentException; |
| 310 | ClassObject* exIllegalMonitorStateException; |
| 311 | ClassObject* exIllegalStateException; |
| 312 | ClassObject* exIllegalThreadStateException; |
Dan Bornstein | 537e29e | 2011-03-02 16:28:04 -0800 | [diff] [blame] | 313 | ClassObject* exIncompatibleClassChangeError; |
Dan Bornstein | a3b3512 | 2011-03-03 16:17:37 -0800 | [diff] [blame] | 314 | ClassObject* exInstantiationError; |
Dan Bornstein | bc606f5 | 2011-03-01 13:22:13 -0800 | [diff] [blame] | 315 | ClassObject* exInstantiationException; |
Dan Bornstein | 8521311 | 2011-03-01 16:16:12 -0800 | [diff] [blame] | 316 | ClassObject* exInternalError; |
Dan Bornstein | 9b598e3 | 2011-03-01 10:28:42 -0800 | [diff] [blame] | 317 | ClassObject* exInterruptedException; |
Dan Bornstein | 537e29e | 2011-03-02 16:28:04 -0800 | [diff] [blame] | 318 | ClassObject* exLinkageError; |
Dan Bornstein | 2c8e25b | 2011-02-25 15:49:29 -0800 | [diff] [blame] | 319 | ClassObject* exNegativeArraySizeException; |
Dan Bornstein | 8521311 | 2011-03-01 16:16:12 -0800 | [diff] [blame] | 320 | ClassObject* exNoClassDefFoundError; |
Dan Bornstein | 537e29e | 2011-03-02 16:28:04 -0800 | [diff] [blame] | 321 | ClassObject* exNoSuchFieldError; |
Dan Bornstein | 9b598e3 | 2011-03-01 10:28:42 -0800 | [diff] [blame] | 322 | ClassObject* exNoSuchFieldException; |
Dan Bornstein | 537e29e | 2011-03-02 16:28:04 -0800 | [diff] [blame] | 323 | ClassObject* exNoSuchMethodError; |
Dan Bornstein | 2c8e25b | 2011-02-25 15:49:29 -0800 | [diff] [blame] | 324 | ClassObject* exNullPointerException; |
Dan Bornstein | 85ba81d | 2011-03-03 13:10:04 -0800 | [diff] [blame] | 325 | ClassObject* exOutOfMemoryError; |
Dan Bornstein | 32bb3da | 2011-02-24 15:47:20 -0800 | [diff] [blame] | 326 | ClassObject* exRuntimeException; |
| 327 | ClassObject* exStackOverflowError; |
Dan Bornstein | 9b598e3 | 2011-03-01 10:28:42 -0800 | [diff] [blame] | 328 | ClassObject* exStaleDexCacheError; /* in dalvik.system */ |
Dan Bornstein | 7a86c44 | 2011-02-28 11:23:26 -0800 | [diff] [blame] | 329 | ClassObject* exStringIndexOutOfBoundsException; |
Dan Bornstein | 32bb3da | 2011-02-24 15:47:20 -0800 | [diff] [blame] | 330 | ClassObject* exThrowable; |
Dan Bornstein | 85ba81d | 2011-03-03 13:10:04 -0800 | [diff] [blame] | 331 | ClassObject* exTypeNotPresentException; |
Dan Bornstein | 8521311 | 2011-03-01 16:16:12 -0800 | [diff] [blame] | 332 | ClassObject* exUnsatisfiedLinkError; |
Dan Bornstein | 7a86c44 | 2011-02-28 11:23:26 -0800 | [diff] [blame] | 333 | ClassObject* exUnsupportedOperationException; |
Dan Bornstein | 85ba81d | 2011-03-03 13:10:04 -0800 | [diff] [blame] | 334 | ClassObject* exVerifyError; |
Dan Bornstein | 7a86c44 | 2011-02-28 11:23:26 -0800 | [diff] [blame] | 335 | ClassObject* exVirtualMachineError; |
Dan Bornstein | 32bb3da | 2011-02-24 15:47:20 -0800 | [diff] [blame] | 336 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 337 | /* method offsets - Object */ |
| 338 | int voffJavaLangObject_equals; |
| 339 | int voffJavaLangObject_hashCode; |
| 340 | int voffJavaLangObject_toString; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 341 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 342 | /* field offsets - String */ |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 343 | int offJavaLangString_value; |
| 344 | int offJavaLangString_count; |
| 345 | int offJavaLangString_offset; |
| 346 | int offJavaLangString_hashCode; |
| 347 | |
| 348 | /* field offsets - Thread */ |
| 349 | int offJavaLangThread_vmThread; |
| 350 | int offJavaLangThread_group; |
| 351 | int offJavaLangThread_daemon; |
| 352 | int offJavaLangThread_name; |
| 353 | int offJavaLangThread_priority; |
| 354 | |
| 355 | /* method offsets - Thread */ |
| 356 | int voffJavaLangThread_run; |
| 357 | |
Andy McFadden | 86c9593 | 2011-03-23 16:15:36 -0700 | [diff] [blame^] | 358 | /* field offsets - ThreadGroup */ |
| 359 | int offJavaLangThreadGroup_name; |
| 360 | int offJavaLangThreadGroup_parent; |
| 361 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 362 | /* field offsets - VMThread */ |
| 363 | int offJavaLangVMThread_thread; |
| 364 | int offJavaLangVMThread_vmData; |
| 365 | |
| 366 | /* method offsets - ThreadGroup */ |
| 367 | int voffJavaLangThreadGroup_removeThread; |
| 368 | |
| 369 | /* field offsets - Throwable */ |
| 370 | int offJavaLangThrowable_stackState; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 371 | int offJavaLangThrowable_cause; |
| 372 | |
Andy McFadden | 0477139 | 2010-10-07 15:12:14 -0700 | [diff] [blame] | 373 | /* method offsets - ClassLoader */ |
| 374 | int voffJavaLangClassLoader_loadClass; |
| 375 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 376 | /* field offsets - java.lang.reflect.* */ |
| 377 | int offJavaLangReflectAccessibleObject_flag; |
| 378 | int offJavaLangReflectConstructor_slot; |
| 379 | int offJavaLangReflectConstructor_declClass; |
| 380 | int offJavaLangReflectField_slot; |
| 381 | int offJavaLangReflectField_declClass; |
| 382 | int offJavaLangReflectMethod_slot; |
| 383 | int offJavaLangReflectMethod_declClass; |
| 384 | |
| 385 | /* field offsets - java.lang.ref.Reference */ |
| 386 | int offJavaLangRefReference_referent; |
| 387 | int offJavaLangRefReference_queue; |
| 388 | int offJavaLangRefReference_queueNext; |
Carl Shapiro | 2a6f484 | 2010-07-09 16:50:54 -0700 | [diff] [blame] | 389 | int offJavaLangRefReference_pendingNext; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 390 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 391 | /* method pointers - java.lang.ref.Reference */ |
| 392 | Method* methJavaLangRefReference_enqueueInternal; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 393 | |
Carl Shapiro | 3475f9c | 2011-03-21 13:35:24 -0700 | [diff] [blame] | 394 | /* more method pointers - java.lang.ref.FinalizerReference */ |
| 395 | Method* methJavaLangRefFinalizerReferenceAdd; |
| 396 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 397 | /* constructor method pointers; no vtable involved, so use Method* */ |
| 398 | Method* methJavaLangStackTraceElement_init; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 399 | Method* methJavaLangReflectConstructor_init; |
| 400 | Method* methJavaLangReflectField_init; |
| 401 | Method* methJavaLangReflectMethod_init; |
| 402 | Method* methOrgApacheHarmonyLangAnnotationAnnotationMember_init; |
| 403 | |
| 404 | /* static method pointers - android.lang.annotation.* */ |
| 405 | Method* |
| 406 | methOrgApacheHarmonyLangAnnotationAnnotationFactory_createAnnotation; |
| 407 | |
| 408 | /* direct method pointers - java.lang.reflect.Proxy */ |
| 409 | Method* methJavaLangReflectProxy_constructorPrototype; |
| 410 | |
| 411 | /* field offsets - java.lang.reflect.Proxy */ |
| 412 | int offJavaLangReflectProxy_h; |
| 413 | |
| 414 | /* fake native entry point method */ |
| 415 | Method* methFakeNativeEntry; |
| 416 | |
Andy McFadden | 8e5c784 | 2009-07-23 17:47:18 -0700 | [diff] [blame] | 417 | /* assorted direct buffer helpers */ |
| 418 | Method* methJavaNioReadWriteDirectByteBuffer_init; |
Andy McFadden | 8e5c784 | 2009-07-23 17:47:18 -0700 | [diff] [blame] | 419 | int offJavaNioBuffer_capacity; |
Andy McFadden | 8e696dc | 2009-07-24 15:28:16 -0700 | [diff] [blame] | 420 | int offJavaNioBuffer_effectiveDirectAddress; |
Andy McFadden | 5f612b8 | 2009-07-22 15:07:27 -0700 | [diff] [blame] | 421 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 422 | /* |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 423 | * Thread list. This always has at least one element in it (main), |
| 424 | * and main is always the first entry. |
| 425 | * |
| 426 | * The threadListLock is used for several things, including the thread |
| 427 | * start condition variable. Generally speaking, you must hold the |
| 428 | * threadListLock when: |
| 429 | * - adding/removing items from the list |
| 430 | * - waiting on or signaling threadStartCond |
| 431 | * - examining the Thread struct for another thread (this is to avoid |
| 432 | * one thread freeing the Thread struct while another thread is |
| 433 | * perusing it) |
| 434 | */ |
| 435 | Thread* threadList; |
| 436 | pthread_mutex_t threadListLock; |
| 437 | |
| 438 | pthread_cond_t threadStartCond; |
| 439 | |
| 440 | /* |
| 441 | * The thread code grabs this before suspending all threads. There |
Andy McFadden | 2aa4361 | 2009-06-17 16:29:30 -0700 | [diff] [blame] | 442 | * 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] | 443 | * (1) the GC is starting; |
| 444 | * (2) the debugger has sent a "suspend all" request; |
| 445 | * (3) a thread has hit a breakpoint or exception that the debugger |
| 446 | * has marked as a "suspend all" event; |
| 447 | * (4) the SignalCatcher caught a signal that requires suspension. |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 448 | * (5) (if implemented) the JIT needs to perform a heavyweight |
| 449 | * rearrangement of the translation cache or JitTable. |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 450 | * |
| 451 | * Because we use "safe point" self-suspension, it is never safe to |
| 452 | * do a blocking "lock" call on this mutex -- if it has been acquired, |
| 453 | * somebody is probably trying to put you to sleep. The leading '_' is |
| 454 | * intended as a reminder that this lock is special. |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 455 | */ |
| 456 | pthread_mutex_t _threadSuspendLock; |
| 457 | |
| 458 | /* |
| 459 | * Guards Thread->suspendCount for all threads, and provides the lock |
| 460 | * for the condition variable that all suspended threads sleep on |
| 461 | * (threadSuspendCountCond). |
| 462 | * |
| 463 | * This has to be separate from threadListLock because of the way |
| 464 | * threads put themselves to sleep. |
| 465 | */ |
| 466 | pthread_mutex_t threadSuspendCountLock; |
| 467 | |
| 468 | /* |
| 469 | * Suspended threads sleep on this. They should sleep on the condition |
| 470 | * variable until their "suspend count" is zero. |
| 471 | * |
| 472 | * Paired with "threadSuspendCountLock". |
| 473 | */ |
| 474 | pthread_cond_t threadSuspendCountCond; |
| 475 | |
| 476 | /* |
buzbee | cb3081f | 2011-01-14 13:37:31 -0800 | [diff] [blame] | 477 | * Sum of all threads' suspendCount fields. Guarded by |
| 478 | * threadSuspendCountLock. |
Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 479 | */ |
| 480 | int sumThreadSuspendCount; |
| 481 | |
| 482 | /* |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 483 | * MUTEX ORDERING: when locking multiple mutexes, always grab them in |
| 484 | * this order to avoid deadlock: |
| 485 | * |
| 486 | * (1) _threadSuspendLock (use lockThreadSuspend()) |
| 487 | * (2) threadListLock (use dvmLockThreadList()) |
| 488 | * (3) threadSuspendCountLock (use lockThreadSuspendCount()) |
| 489 | */ |
| 490 | |
| 491 | |
| 492 | /* |
| 493 | * Thread ID bitmap. We want threads to have small integer IDs so |
| 494 | * we can use them in "thin locks". |
| 495 | */ |
| 496 | BitVector* threadIdMap; |
| 497 | |
| 498 | /* |
| 499 | * Manage exit conditions. The VM exits when all non-daemon threads |
| 500 | * have exited. If the main thread returns early, we need to sleep |
| 501 | * on a condition variable. |
| 502 | */ |
| 503 | int nonDaemonThreadCount; /* must hold threadListLock to access */ |
| 504 | //pthread_mutex_t vmExitLock; |
| 505 | pthread_cond_t vmExitCond; |
| 506 | |
| 507 | /* |
| 508 | * The set of DEX files loaded by custom class loaders. |
| 509 | */ |
| 510 | HashTable* userDexFiles; |
| 511 | |
| 512 | /* |
| 513 | * JNI global reference table. |
| 514 | */ |
Andy McFadden | d5ab726 | 2009-08-25 07:19:34 -0700 | [diff] [blame] | 515 | IndirectRefTable jniGlobalRefTable; |
Carl Shapiro | e4c3b5e | 2011-03-08 13:44:51 -0800 | [diff] [blame] | 516 | IndirectRefTable jniWeakGlobalRefTable; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 517 | pthread_mutex_t jniGlobalRefLock; |
Carl Shapiro | e4c3b5e | 2011-03-08 13:44:51 -0800 | [diff] [blame] | 518 | pthread_mutex_t jniWeakGlobalRefLock; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 519 | int jniGlobalRefHiMark; |
| 520 | int jniGlobalRefLoMark; |
| 521 | |
| 522 | /* |
Andy McFadden | c26bb63 | 2009-08-21 12:01:31 -0700 | [diff] [blame] | 523 | * JNI pinned object table (used for primitive arrays). |
| 524 | */ |
| 525 | ReferenceTable jniPinRefTable; |
| 526 | pthread_mutex_t jniPinRefLock; |
| 527 | |
| 528 | /* |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 529 | * Native shared library table. |
| 530 | */ |
| 531 | HashTable* nativeLibs; |
| 532 | |
| 533 | /* |
| 534 | * GC heap lock. Functions like gcMalloc() acquire this before making |
| 535 | * any changes to the heap. It is held throughout garbage collection. |
| 536 | */ |
| 537 | pthread_mutex_t gcHeapLock; |
| 538 | |
Carl Shapiro | ec47e2e | 2010-07-01 17:44:46 -0700 | [diff] [blame] | 539 | /* |
| 540 | * Condition variable to queue threads waiting to retry an |
| 541 | * allocation. Signaled after a concurrent GC is completed. |
| 542 | */ |
| 543 | pthread_cond_t gcHeapCond; |
| 544 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 545 | /* Opaque pointer representing the heap. */ |
| 546 | GcHeap* gcHeap; |
| 547 | |
Barry Hayes | 4496ed9 | 2010-07-12 09:52:20 -0700 | [diff] [blame] | 548 | /* The card table base, modified as needed for marking cards. */ |
| 549 | u1* biasedCardTableBase; |
| 550 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 551 | /* |
Andy McFadden | 7fc3ce8 | 2009-07-14 15:57:23 -0700 | [diff] [blame] | 552 | * Pre-allocated throwables. |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 553 | */ |
| 554 | Object* outOfMemoryObj; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 555 | Object* internalErrorObj; |
Andy McFadden | 7fc3ce8 | 2009-07-14 15:57:23 -0700 | [diff] [blame] | 556 | Object* noClassDefFoundErrorObj; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 557 | |
| 558 | /* Monitor list, so we can free them */ |
| 559 | /*volatile*/ Monitor* monitorList; |
| 560 | |
| 561 | /* Monitor for Thread.sleep() implementation */ |
| 562 | Monitor* threadSleepMon; |
| 563 | |
| 564 | /* set when we create a second heap inside the zygote */ |
| 565 | bool newZygoteHeapAllocated; |
| 566 | |
| 567 | /* |
| 568 | * TLS keys. |
| 569 | */ |
| 570 | pthread_key_t pthreadKeySelf; /* Thread*, for dvmThreadSelf */ |
| 571 | |
| 572 | /* |
| 573 | * JNI allows you to have multiple VMs, but we limit ourselves to 1, |
| 574 | * so "vmList" is really just a pointer to the one and only VM. |
| 575 | */ |
| 576 | JavaVM* vmList; |
| 577 | |
| 578 | /* |
| 579 | * Cache results of "A instanceof B". |
| 580 | */ |
| 581 | AtomicCache* instanceofCache; |
| 582 | |
Andy McFadden | cb3c542 | 2010-04-07 15:56:16 -0700 | [diff] [blame] | 583 | /* inline substitution table, used during optimization */ |
| 584 | InlineSub* inlineSubs; |
| 585 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 586 | /* |
| 587 | * Bootstrap class loader linear allocator. |
| 588 | */ |
| 589 | LinearAllocHdr* pBootLoaderAlloc; |
| 590 | |
| 591 | |
| 592 | /* |
| 593 | * Heap worker thread. |
| 594 | */ |
| 595 | bool heapWorkerInitialized; |
| 596 | bool heapWorkerReady; |
| 597 | bool haltHeapWorker; |
| 598 | pthread_t heapWorkerHandle; |
| 599 | pthread_mutex_t heapWorkerLock; |
| 600 | pthread_cond_t heapWorkerCond; |
| 601 | pthread_cond_t heapWorkerIdleCond; |
| 602 | pthread_mutex_t heapWorkerListLock; |
| 603 | |
| 604 | /* |
| 605 | * Compute some stats on loaded classes. |
| 606 | */ |
The Android Open Source Project | 9940988 | 2009-03-18 22:20:24 -0700 | [diff] [blame] | 607 | int numLoadedClasses; |
| 608 | int numDeclaredMethods; |
| 609 | int numDeclaredInstFields; |
| 610 | int numDeclaredStaticFields; |
| 611 | |
| 612 | /* when using a native debugger, set this to suppress watchdog timers */ |
| 613 | bool nativeDebuggerActive; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 614 | |
| 615 | /* |
| 616 | * JDWP debugger support. |
| 617 | */ |
| 618 | bool debuggerConnected; /* debugger or DDMS is connected */ |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 619 | JdwpState* jdwpState; |
| 620 | |
| 621 | /* |
| 622 | * Registry of objects known to the debugger. |
| 623 | */ |
| 624 | HashTable* dbgRegistry; |
| 625 | |
| 626 | /* |
Andy McFadden | 9651693 | 2009-10-28 17:39:02 -0700 | [diff] [blame] | 627 | * Debugger breakpoint table. |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 628 | */ |
Andy McFadden | 9651693 | 2009-10-28 17:39:02 -0700 | [diff] [blame] | 629 | BreakpointSet* breakpointSet; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 630 | |
| 631 | /* |
| 632 | * Single-step control struct. We currently only allow one thread to |
| 633 | * be single-stepping at a time, which is all that really makes sense, |
| 634 | * but it's possible we may need to expand this to be per-thread. |
| 635 | */ |
| 636 | StepControl stepControl; |
| 637 | |
| 638 | /* |
| 639 | * DDM features embedded in the VM. |
| 640 | */ |
| 641 | bool ddmThreadNotification; |
| 642 | |
| 643 | /* |
| 644 | * Zygote (partially-started process) support |
| 645 | */ |
| 646 | bool zygote; |
| 647 | |
| 648 | /* |
| 649 | * Used for tracking allocations that we report to DDMS. When the feature |
| 650 | * is enabled (through a DDMS request) the "allocRecords" pointer becomes |
| 651 | * non-NULL. |
| 652 | */ |
| 653 | pthread_mutex_t allocTrackerLock; |
| 654 | AllocRecord* allocRecords; |
| 655 | int allocRecordHead; /* most-recently-added entry */ |
| 656 | int allocRecordCount; /* #of valid entries */ |
| 657 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 658 | /* |
buzbee | cb3081f | 2011-01-14 13:37:31 -0800 | [diff] [blame] | 659 | * When normal control flow needs to be interrupted because |
| 660 | * of an attached debugger, profiler, thread stop request, etc., |
| 661 | * a bit is set here. We collapse all stop reasons into |
| 662 | * a single location for performance reasons. |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 663 | */ |
buzbee | cb3081f | 2011-01-14 13:37:31 -0800 | [diff] [blame] | 664 | volatile int interpBreak; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 665 | |
| 666 | /* |
| 667 | * State for method-trace profiling. |
| 668 | */ |
| 669 | MethodTraceState methodTrace; |
Andy McFadden | 2ff04ab | 2011-03-08 15:22:14 -0800 | [diff] [blame] | 670 | Method* methodTraceGcMethod; |
| 671 | Method* methodTraceClassPrepMethod; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 672 | |
| 673 | /* |
| 674 | * State for emulator tracing. |
| 675 | */ |
| 676 | void* emulatorTracePage; |
| 677 | int emulatorTraceEnableCount; |
| 678 | |
| 679 | /* |
| 680 | * Global state for memory allocation profiling. |
| 681 | */ |
| 682 | AllocProfState allocProf; |
| 683 | |
| 684 | /* |
| 685 | * Pointers to the original methods for things that have been inlined. |
| 686 | * This makes it easy for us to output method entry/exit records for |
Andy McFadden | 0d615c3 | 2010-08-18 12:19:51 -0700 | [diff] [blame] | 687 | * the method calls we're not actually making. (Used by method |
| 688 | * profiling.) |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 689 | */ |
| 690 | Method** inlinedMethods; |
| 691 | |
| 692 | /* |
Dan Bornstein | ccaab18 | 2010-12-03 15:32:40 -0800 | [diff] [blame] | 693 | * Dalvik instruction counts (kNumPackedOpcodes entries). |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 694 | */ |
| 695 | int* executedInstrCounts; |
Andy McFadden | 5183a19 | 2010-10-22 15:26:07 -0700 | [diff] [blame] | 696 | int instructionCountEnableCount; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 697 | |
| 698 | /* |
| 699 | * Signal catcher thread (for SIGQUIT). |
| 700 | */ |
| 701 | pthread_t signalCatcherHandle; |
| 702 | bool haltSignalCatcher; |
| 703 | |
| 704 | /* |
| 705 | * Stdout/stderr conversion thread. |
| 706 | */ |
| 707 | bool haltStdioConverter; |
| 708 | bool stdioConverterReady; |
| 709 | pthread_t stdioConverterHandle; |
| 710 | pthread_mutex_t stdioConverterLock; |
| 711 | pthread_cond_t stdioConverterCond; |
| 712 | |
| 713 | /* |
| 714 | * pid of the system_server process. We track it so that when system server |
| 715 | * crashes the Zygote process will be killed and restarted. |
| 716 | */ |
| 717 | pid_t systemServerPid; |
| 718 | |
San Mehat | 894dd46 | 2009-09-08 20:29:15 -0700 | [diff] [blame] | 719 | int kernelGroupScheduling; |
| 720 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 721 | //#define COUNT_PRECISE_METHODS |
| 722 | #ifdef COUNT_PRECISE_METHODS |
| 723 | PointerSet* preciseMethods; |
| 724 | #endif |
The Android Open Source Project | 9940988 | 2009-03-18 22:20:24 -0700 | [diff] [blame] | 725 | |
| 726 | /* some RegisterMap statistics, useful during development */ |
| 727 | void* registerMapStats; |
Andy McFadden | 470cbbb | 2010-11-04 16:31:37 -0700 | [diff] [blame] | 728 | |
| 729 | #ifdef VERIFIER_STATS |
| 730 | VerifierStats verifierStats; |
| 731 | #endif |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 732 | }; |
| 733 | |
| 734 | extern struct DvmGlobals gDvm; |
| 735 | |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 736 | #if defined(WITH_JIT) |
Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 737 | |
buzbee | 2e152ba | 2010-12-15 16:32:35 -0800 | [diff] [blame] | 738 | /* Trace profiling modes. Ordering matters - off states before on states */ |
| 739 | typedef enum TraceProfilingModes { |
| 740 | kTraceProfilingDisabled = 0, // Not profiling |
| 741 | kTraceProfilingPeriodicOff = 1, // Periodic profiling, off phase |
| 742 | kTraceProfilingContinuous = 2, // Always profiling |
| 743 | kTraceProfilingPeriodicOn = 3 // Periodic profiling, on phase |
| 744 | } TraceProfilingModes; |
| 745 | |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 746 | /* |
Ben Cheng | 6c10a97 | 2009-10-29 14:39:18 -0700 | [diff] [blame] | 747 | * Exiting the compiled code w/o chaining will incur overhead to look up the |
| 748 | * target in the code cache which is extra work only when JIT is enabled. So |
| 749 | * we want to monitor it closely to make sure we don't have performance bugs. |
| 750 | */ |
| 751 | typedef enum NoChainExits { |
| 752 | kInlineCacheMiss = 0, |
| 753 | kCallsiteInterpreted, |
| 754 | kSwitchOverflow, |
Bill Buzbee | fccb31d | 2010-02-04 16:09:55 -0800 | [diff] [blame] | 755 | kHeavyweightMonitor, |
Ben Cheng | 6c10a97 | 2009-10-29 14:39:18 -0700 | [diff] [blame] | 756 | kNoChainExitLast, |
| 757 | } NoChainExits; |
| 758 | |
| 759 | /* |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 760 | * JIT-specific global state |
| 761 | */ |
| 762 | struct DvmJitGlobals { |
| 763 | /* |
| 764 | * Guards writes to Dalvik PC (dPC), translated code address (codeAddr) and |
| 765 | * chain fields within the JIT hash table. Note carefully the access |
| 766 | * mechanism. |
| 767 | * Only writes are guarded, and the guarded fields must be updated in a |
| 768 | * specific order using atomic operations. Further, once a field is |
| 769 | * written it cannot be changed without halting all threads. |
| 770 | * |
| 771 | * The write order is: |
| 772 | * 1) codeAddr |
| 773 | * 2) dPC |
| 774 | * 3) chain [if necessary] |
| 775 | * |
| 776 | * This mutex also guards both read and write of curJitTableEntries. |
| 777 | */ |
| 778 | pthread_mutex_t tableLock; |
| 779 | |
| 780 | /* The JIT hash table. Note that for access speed, copies of this pointer |
| 781 | * are stored in each thread. */ |
| 782 | struct JitEntry *pJitEntryTable; |
| 783 | |
buzbee | 2e152ba | 2010-12-15 16:32:35 -0800 | [diff] [blame] | 784 | /* Array of compilation trigger threshold counters */ |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 785 | unsigned char *pProfTable; |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 786 | |
buzbee | 2e152ba | 2010-12-15 16:32:35 -0800 | [diff] [blame] | 787 | /* Trace profiling counters */ |
| 788 | struct JitTraceProfCounters *pJitTraceProfCounters; |
| 789 | |
Bill Buzbee | 06bb839 | 2010-01-31 18:53:15 -0800 | [diff] [blame] | 790 | /* Copy of pProfTable used for temporarily disabling the Jit */ |
| 791 | unsigned char *pProfTableCopy; |
| 792 | |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 793 | /* 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] | 794 | unsigned int jitTableSize; |
| 795 | |
| 796 | /* Mask used in hash function for JitTable. Should be jitTableSize-1 */ |
| 797 | unsigned int jitTableMask; |
| 798 | |
| 799 | /* How many entries in the JitEntryTable are in use */ |
| 800 | unsigned int jitTableEntriesUsed; |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 801 | |
Ben Cheng | 94e79eb | 2010-02-04 16:15:59 -0800 | [diff] [blame] | 802 | /* Bytes allocated for the code cache */ |
| 803 | unsigned int codeCacheSize; |
| 804 | |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 805 | /* Trigger for trace selection */ |
| 806 | unsigned short threshold; |
| 807 | |
| 808 | /* JIT Compiler Control */ |
| 809 | bool haltCompilerThread; |
| 810 | bool blockingMode; |
buzbee | 18fba34 | 2011-01-19 15:31:15 -0800 | [diff] [blame] | 811 | bool methodTraceSupport; |
Ben Cheng | 7ab74e1 | 2011-02-03 14:02:06 -0800 | [diff] [blame] | 812 | bool genSuspendPoll; |
Ben Cheng | 385828e | 2011-03-04 16:48:33 -0800 | [diff] [blame] | 813 | Thread* compilerThread; |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 814 | pthread_t compilerHandle; |
| 815 | pthread_mutex_t compilerLock; |
Ben Cheng | c3b92b2 | 2010-01-26 16:46:15 -0800 | [diff] [blame] | 816 | pthread_mutex_t compilerICPatchLock; |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 817 | pthread_cond_t compilerQueueActivity; |
| 818 | pthread_cond_t compilerQueueEmpty; |
Ben Cheng | 88a0f97 | 2010-02-24 15:00:40 -0800 | [diff] [blame] | 819 | volatile int compilerQueueLength; |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 820 | int compilerHighWater; |
| 821 | int compilerWorkEnqueueIndex; |
| 822 | int compilerWorkDequeueIndex; |
Ben Cheng | c3b92b2 | 2010-01-26 16:46:15 -0800 | [diff] [blame] | 823 | int compilerICPatchIndex; |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 824 | |
| 825 | /* JIT internal stats */ |
| 826 | int compilerMaxQueued; |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 827 | int translationChains; |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 828 | |
| 829 | /* Compiled code cache */ |
| 830 | void* codeCache; |
| 831 | |
Ben Cheng | 385828e | 2011-03-04 16:48:33 -0800 | [diff] [blame] | 832 | /* |
| 833 | * This is used to store the base address of an in-flight compilation whose |
| 834 | * class object pointers have been calculated to populate literal pool. |
| 835 | * Once the compiler thread has changed its status to VM_WAIT, we cannot |
| 836 | * guarantee whether GC has happened before the code address has been |
| 837 | * installed to the JIT table. Because of that, this field can only |
| 838 | * been cleared/overwritten by the compiler thread if it is in the |
| 839 | * THREAD_RUNNING state or in a safe point. |
| 840 | */ |
| 841 | void *inflightBaseAddr; |
| 842 | |
buzbee | 18fba34 | 2011-01-19 15:31:15 -0800 | [diff] [blame] | 843 | /* Translation cache version (protected by compilerLock */ |
| 844 | int cacheVersion; |
| 845 | |
Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 846 | /* Bytes used by the code templates */ |
| 847 | unsigned int templateSize; |
| 848 | |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 849 | /* Bytes already used in the code cache */ |
| 850 | unsigned int codeCacheByteUsed; |
| 851 | |
| 852 | /* Number of installed compilations in the cache */ |
| 853 | unsigned int numCompilations; |
| 854 | |
| 855 | /* Flag to indicate that the code cache is full */ |
| 856 | bool codeCacheFull; |
| 857 | |
Ben Cheng | b88ec3c | 2010-05-17 12:50:33 -0700 | [diff] [blame] | 858 | /* Page size - 1 */ |
| 859 | unsigned int pageSizeMask; |
| 860 | |
| 861 | /* Lock to change the protection type of the code cache */ |
| 862 | pthread_mutex_t codeCacheProtectionLock; |
| 863 | |
Ben Cheng | 7a0bcd0 | 2010-01-22 16:45:45 -0800 | [diff] [blame] | 864 | /* Number of times that the code cache has been reset */ |
| 865 | int numCodeCacheReset; |
| 866 | |
Ben Cheng | c3b92b2 | 2010-01-26 16:46:15 -0800 | [diff] [blame] | 867 | /* Number of times that the code cache reset request has been delayed */ |
| 868 | int numCodeCacheResetDelayed; |
| 869 | |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 870 | /* true/false: compile/reject opcodes specified in the -Xjitop list */ |
| 871 | bool includeSelectedOp; |
| 872 | |
| 873 | /* true/false: compile/reject methods specified in the -Xjitmethod list */ |
| 874 | bool includeSelectedMethod; |
| 875 | |
| 876 | /* Disable JIT for selected opcodes - one bit for each opcode */ |
| 877 | char opList[32]; |
| 878 | |
| 879 | /* Disable JIT for selected methods */ |
| 880 | HashTable *methodTable; |
| 881 | |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 882 | /* Flag to dump all compiled code */ |
| 883 | bool printMe; |
Bill Buzbee | 6e963e1 | 2009-06-17 16:56:19 -0700 | [diff] [blame] | 884 | |
Ben Cheng | 46cd4fb | 2011-03-16 17:19:06 -0700 | [diff] [blame] | 885 | /* Per-process debug flag toggled when receiving a SIGUSR2 */ |
| 886 | bool receivedSIGUSR2; |
| 887 | |
buzbee | 2e152ba | 2010-12-15 16:32:35 -0800 | [diff] [blame] | 888 | /* Trace profiling mode */ |
| 889 | TraceProfilingModes profileMode; |
| 890 | |
| 891 | /* Periodic trace profiling countdown timer */ |
| 892 | int profileCountdown; |
Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 893 | |
Ben Cheng | dcf3e5d | 2009-09-11 13:42:05 -0700 | [diff] [blame] | 894 | /* Vector to disable selected optimizations */ |
| 895 | int disableOpt; |
| 896 | |
Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 897 | /* Table to track the overall and trace statistics of hot methods */ |
| 898 | HashTable* methodStatsTable; |
Ben Cheng | bcdc1de | 2009-08-21 16:18:46 -0700 | [diff] [blame] | 899 | |
Ben Cheng | 3367245 | 2010-01-12 14:59:30 -0800 | [diff] [blame] | 900 | /* Filter method compilation blacklist with call-graph information */ |
| 901 | bool checkCallGraph; |
| 902 | |
Ben Cheng | c3b92b2 | 2010-01-26 16:46:15 -0800 | [diff] [blame] | 903 | /* New translation chain has been set up */ |
| 904 | volatile bool hasNewChain; |
| 905 | |
Ben Cheng | bcdc1de | 2009-08-21 16:18:46 -0700 | [diff] [blame] | 906 | #if defined(WITH_SELF_VERIFICATION) |
| 907 | /* Spin when error is detected, volatile so GDB can reset it */ |
| 908 | volatile bool selfVerificationSpin; |
| 909 | #endif |
Ben Cheng | c3b92b2 | 2010-01-26 16:46:15 -0800 | [diff] [blame] | 910 | |
Bill Buzbee | fccb31d | 2010-02-04 16:09:55 -0800 | [diff] [blame] | 911 | /* Framework or stand-alone? */ |
| 912 | bool runningInAndroidFramework; |
| 913 | |
Ben Cheng | c5285b3 | 2010-02-14 16:17:36 -0800 | [diff] [blame] | 914 | /* Framework callback happened? */ |
| 915 | bool alreadyEnabledViaFramework; |
| 916 | |
| 917 | /* Framework requests to disable the JIT for good */ |
| 918 | bool disableJit; |
| 919 | |
Ben Cheng | dca7143 | 2010-03-16 16:04:11 -0700 | [diff] [blame] | 920 | #if defined(SIGNATURE_BREAKPOINT) |
| 921 | /* Signature breakpoint */ |
| 922 | u4 signatureBreakpointSize; // # of words |
| 923 | u4 *signatureBreakpoint; // Signature content |
| 924 | #endif |
| 925 | |
Ben Cheng | 978738d | 2010-05-13 13:45:57 -0700 | [diff] [blame] | 926 | #if defined(WITH_JIT_TUNING) |
| 927 | /* Performance tuning counters */ |
| 928 | int addrLookupsFound; |
| 929 | int addrLookupsNotFound; |
| 930 | int noChainExit[kNoChainExitLast]; |
| 931 | int normalExit; |
| 932 | int puntExit; |
| 933 | int invokeMonomorphic; |
| 934 | int invokePolymorphic; |
| 935 | int invokeNative; |
Ben Cheng | 7a2697d | 2010-06-07 13:44:23 -0700 | [diff] [blame] | 936 | int invokeMonoGetterInlined; |
| 937 | int invokeMonoSetterInlined; |
| 938 | int invokePolyGetterInlined; |
| 939 | int invokePolySetterInlined; |
Ben Cheng | 978738d | 2010-05-13 13:45:57 -0700 | [diff] [blame] | 940 | int returnOp; |
Ben Cheng | b88ec3c | 2010-05-17 12:50:33 -0700 | [diff] [blame] | 941 | int icPatchInit; |
| 942 | int icPatchLockFree; |
Ben Cheng | 978738d | 2010-05-13 13:45:57 -0700 | [diff] [blame] | 943 | int icPatchQueued; |
Ben Cheng | b88ec3c | 2010-05-17 12:50:33 -0700 | [diff] [blame] | 944 | int icPatchRejected; |
Ben Cheng | 978738d | 2010-05-13 13:45:57 -0700 | [diff] [blame] | 945 | int icPatchDropped; |
Ben Cheng | 978738d | 2010-05-13 13:45:57 -0700 | [diff] [blame] | 946 | int codeCachePatches; |
Ben Cheng | 385828e | 2011-03-04 16:48:33 -0800 | [diff] [blame] | 947 | int numCompilerThreadBlockGC; |
| 948 | u8 jitTime; |
| 949 | u8 compilerThreadBlockGCStart; |
| 950 | u8 compilerThreadBlockGCTime; |
| 951 | u8 maxCompilerThreadBlockGCTime; |
Ben Cheng | 978738d | 2010-05-13 13:45:57 -0700 | [diff] [blame] | 952 | #endif |
| 953 | |
Ben Cheng | c3b92b2 | 2010-01-26 16:46:15 -0800 | [diff] [blame] | 954 | /* Place arrays at the end to ease the display in gdb sessions */ |
| 955 | |
| 956 | /* Work order queue for compilations */ |
| 957 | CompilerWorkOrder compilerWorkQueue[COMPILER_WORK_QUEUE_SIZE]; |
| 958 | |
| 959 | /* Work order queue for predicted chain patching */ |
| 960 | ICPatchWorkOrder compilerICPatchQueue[COMPILER_IC_PATCH_QUEUE_SIZE]; |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 961 | }; |
| 962 | |
| 963 | extern struct DvmJitGlobals gDvmJit; |
| 964 | |
Ben Cheng | 978738d | 2010-05-13 13:45:57 -0700 | [diff] [blame] | 965 | #if defined(WITH_JIT_TUNING) |
| 966 | extern int gDvmICHitCount; |
| 967 | #endif |
| 968 | |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 969 | #endif |
| 970 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 971 | #endif /*_DALVIK_GLOBALS*/ |