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