blob: 6ba6d5ac9fe2f96b967394712e79b82826f0d5cc [file] [log] [blame]
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * Variables with library scope.
19 *
20 * Prefer this over scattered static and global variables -- it's easier to
21 * view the state in a debugger, it makes clean shutdown simpler, we can
22 * trivially dump the state into a crash log, and it dodges most naming
23 * collisions that will arise when we are embedded in a larger program.
24 *
25 * If we want multiple VMs per process, this can get stuffed into TLS (or
26 * accessed through a Thread field). May need to pass it around for some
27 * of the early initialization functions.
28 */
29#ifndef _DALVIK_GLOBALS
30#define _DALVIK_GLOBALS
31
32#include <stdarg.h>
33#include <pthread.h>
34
35#define MAX_BREAKPOINTS 20 /* used for a debugger optimization */
36
Andy McFadden96516932009-10-28 17:39:02 -070037/* private structures */
38typedef struct GcHeap GcHeap;
39typedef struct BreakpointSet BreakpointSet;
Andy McFaddencb3c5422010-04-07 15:56:16 -070040typedef struct InlineSub InlineSub;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080041
42/*
43 * One of these for each -ea/-da/-esa/-dsa on the command line.
44 */
45typedef struct AssertionControl {
46 char* pkgOrClass; /* package/class string, or NULL for esa/dsa */
47 int pkgOrClassLen; /* string length, for quick compare */
48 bool enable; /* enable or disable */
49 bool isPackage; /* string ended with "..."? */
50} AssertionControl;
51
52/*
53 * Execution mode, e.g. interpreter vs. JIT.
54 */
55typedef enum ExecutionMode {
56 kExecutionModeUnknown = 0,
57 kExecutionModeInterpPortable,
58 kExecutionModeInterpFast,
Ben Chengba4fc8b2009-06-01 13:00:29 -070059#if defined(WITH_JIT)
60 kExecutionModeJit,
61#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080062} ExecutionMode;
63
64/*
65 * All fields are initialized to zero.
66 *
67 * Storage allocated here must be freed by a subsystem shutdown function or
68 * from within freeGlobals().
69 */
70struct DvmGlobals {
71 /*
72 * Some options from the command line or environment.
73 */
74 char* bootClassPathStr;
75 char* classPathStr;
76
77 unsigned int heapSizeStart;
78 unsigned int heapSizeMax;
79 unsigned int stackSize;
80
81 bool verboseGc;
82 bool verboseJni;
83 bool verboseClass;
Andy McFadden43eb5012010-02-01 16:56:53 -080084 bool verboseShutdown;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080085
86 bool jdwpAllowed; // debugging allowed for this process?
87 bool jdwpConfigured; // has debugging info been provided?
88 int jdwpTransport;
89 bool jdwpServer;
90 char* jdwpHost;
91 int jdwpPort;
92 bool jdwpSuspend;
93
Andy McFaddenfe1d6d52010-08-25 12:05:44 -070094 /* use wall clock as method profiler clock source? */
95 bool profilerWallClock;
96
Carl Shapirob8fcf572010-04-16 17:33:15 -070097 /*
98 * Lock profiling threshold value in milliseconds. Acquires that
99 * exceed threshold are logged. Acquires within the threshold are
100 * logged with a probability of $\frac{time}{threshold}$ . If the
101 * threshold is unset no additional logging occurs.
102 */
Carl Shapirof0c514c2010-04-09 15:03:33 -0700103 u4 lockProfThreshold;
Carl Shapirof0c514c2010-04-09 15:03:33 -0700104
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800105 int (*vfprintfHook)(FILE*, const char*, va_list);
106 void (*exitHook)(int);
107 void (*abortHook)(void);
108
109 int jniGrefLimit; // 0 means no limit
Elliott Hughes8afa9df2010-07-07 14:47:25 -0700110 char* jniTrace;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800111 bool reduceSignals;
112 bool noQuitHandler;
113 bool verifyDexChecksum;
114 char* stackTraceFile; // for SIGQUIT-inspired output
115
116 bool logStdio;
117
118 DexOptimizerMode dexOptMode;
119 DexClassVerifyMode classVerifyMode;
Barry Hayes5cbb2302010-02-02 14:07:37 -0800120
Andy McFadden139bd972010-09-09 12:54:43 -0700121 bool dexOptForSmp;
122
Barry Hayes962adba2010-03-17 12:12:39 -0700123 /*
124 * GC option flags.
125 */
The Android Open Source Project99409882009-03-18 22:20:24 -0700126 bool preciseGc;
Barry Hayes962adba2010-03-17 12:12:39 -0700127 bool preVerify;
128 bool postVerify;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800129 bool generateRegisterMaps;
Carl Shapiroec805ea2010-06-28 16:28:26 -0700130 bool concurrentMarkSweep;
Barry Hayes6e5cf602010-06-22 12:32:59 -0700131 bool verifyCardTable;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800132
133 int assertionCtrlCount;
134 AssertionControl* assertionCtrl;
135
136 ExecutionMode executionMode;
137
138 /*
139 * VM init management.
140 */
141 bool initializing;
142 int initExceptionCount;
143 bool optimizing;
144
145 /*
146 * java.lang.System properties set from the command line.
147 */
148 int numProps;
149 int maxProps;
150 char** propList;
151
152 /*
153 * Where the VM goes to find system classes.
154 */
155 ClassPathEntry* bootClassPath;
156 /* used by the DEX optimizer to load classes from an unfinished DEX */
157 DvmDex* bootClassPathOptExtra;
158 bool optimizingBootstrapClass;
159
160 /*
161 * Loaded classes, hashed by class name. Each entry is a ClassObject*,
162 * allocated in GC space.
163 */
164 HashTable* loadedClasses;
165
166 /*
167 * Value for the next class serial number to be assigned. This is
168 * incremented as we load classes. Failed loads and races may result
169 * in some numbers being skipped, and the serial number is not
170 * guaranteed to start at 1, so the current value should not be used
171 * as a count of loaded classes.
172 */
173 volatile int classSerialNumber;
174
175 /*
Barry Hayes2c987472009-04-06 10:03:48 -0700176 * Classes with a low classSerialNumber are probably in the zygote, and
177 * their InitiatingLoaderList is not used, to promote sharing. The list is
178 * kept here instead.
179 */
180 InitiatingLoaderList* initiatingLoaderList;
181
182 /*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800183 * Interned strings.
184 */
Carl Shapirobb1e0e92010-07-21 14:49:25 -0700185
186 /* A mutex that guards access to the interned string tables. */
187 pthread_mutex_t internLock;
188
189 /* Hash table of strings interned by the user. */
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800190 HashTable* internedStrings;
191
Carl Shapirobb1e0e92010-07-21 14:49:25 -0700192 /* Hash table of strings interned by the class loader. */
193 HashTable* literalStrings;
194
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800195 /*
196 * Quick lookups for popular classes used internally.
197 */
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800198 ClassObject* classJavaLangClass;
199 ClassObject* classJavaLangClassArray;
200 ClassObject* classJavaLangError;
201 ClassObject* classJavaLangObject;
202 ClassObject* classJavaLangObjectArray;
203 ClassObject* classJavaLangRuntimeException;
204 ClassObject* classJavaLangString;
205 ClassObject* classJavaLangThread;
206 ClassObject* classJavaLangVMThread;
207 ClassObject* classJavaLangThreadGroup;
208 ClassObject* classJavaLangThrowable;
Andy McFadden4fbba1f2010-02-03 07:21:14 -0800209 ClassObject* classJavaLangStackOverflowError;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800210 ClassObject* classJavaLangStackTraceElement;
211 ClassObject* classJavaLangStackTraceElementArray;
212 ClassObject* classJavaLangAnnotationAnnotationArray;
213 ClassObject* classJavaLangAnnotationAnnotationArrayArray;
214 ClassObject* classJavaLangReflectAccessibleObject;
215 ClassObject* classJavaLangReflectConstructor;
216 ClassObject* classJavaLangReflectConstructorArray;
217 ClassObject* classJavaLangReflectField;
218 ClassObject* classJavaLangReflectFieldArray;
219 ClassObject* classJavaLangReflectMethod;
220 ClassObject* classJavaLangReflectMethodArray;
221 ClassObject* classJavaLangReflectProxy;
222 ClassObject* classJavaLangExceptionInInitializerError;
Andy McFaddenb18992f2009-09-25 10:42:15 -0700223 ClassObject* classJavaLangRefPhantomReference;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800224 ClassObject* classJavaLangRefReference;
Andy McFadden8e5c7842009-07-23 17:47:18 -0700225 ClassObject* classJavaNioReadWriteDirectByteBuffer;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800226 ClassObject* classJavaSecurityAccessController;
227 ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationFactory;
228 ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMember;
229 ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMemberArray;
Andy McFadden5f612b82009-07-22 15:07:27 -0700230 ClassObject* classOrgApacheHarmonyNioInternalDirectBuffer;
Andy McFaddend5ab7262009-08-25 07:19:34 -0700231 jclass jclassOrgApacheHarmonyNioInternalDirectBuffer;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800232
233 /* synthetic classes for arrays of primitives */
234 ClassObject* classArrayBoolean;
235 ClassObject* classArrayChar;
236 ClassObject* classArrayFloat;
237 ClassObject* classArrayDouble;
238 ClassObject* classArrayByte;
239 ClassObject* classArrayShort;
240 ClassObject* classArrayInt;
241 ClassObject* classArrayLong;
242
243 /* method offsets - Object */
244 int voffJavaLangObject_equals;
245 int voffJavaLangObject_hashCode;
246 int voffJavaLangObject_toString;
247 int voffJavaLangObject_finalize;
248
249 /* field offsets - Class */
250 int offJavaLangClass_pd;
251
252 /* field offsets - String */
Andy McFaddendeeeeb22010-06-16 08:32:04 -0700253 int javaLangStringReady; /* 0=not init, 1=ready, -1=initing */
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800254 int offJavaLangString_value;
255 int offJavaLangString_count;
256 int offJavaLangString_offset;
257 int offJavaLangString_hashCode;
258
259 /* field offsets - Thread */
260 int offJavaLangThread_vmThread;
261 int offJavaLangThread_group;
262 int offJavaLangThread_daemon;
263 int offJavaLangThread_name;
264 int offJavaLangThread_priority;
265
266 /* method offsets - Thread */
267 int voffJavaLangThread_run;
268
269 /* field offsets - VMThread */
270 int offJavaLangVMThread_thread;
271 int offJavaLangVMThread_vmData;
272
273 /* method offsets - ThreadGroup */
274 int voffJavaLangThreadGroup_removeThread;
275
276 /* field offsets - Throwable */
277 int offJavaLangThrowable_stackState;
278 int offJavaLangThrowable_message;
279 int offJavaLangThrowable_cause;
280
281 /* field offsets - java.lang.reflect.* */
282 int offJavaLangReflectAccessibleObject_flag;
283 int offJavaLangReflectConstructor_slot;
284 int offJavaLangReflectConstructor_declClass;
285 int offJavaLangReflectField_slot;
286 int offJavaLangReflectField_declClass;
287 int offJavaLangReflectMethod_slot;
288 int offJavaLangReflectMethod_declClass;
289
290 /* field offsets - java.lang.ref.Reference */
291 int offJavaLangRefReference_referent;
292 int offJavaLangRefReference_queue;
293 int offJavaLangRefReference_queueNext;
Carl Shapiro2a6f4842010-07-09 16:50:54 -0700294 int offJavaLangRefReference_pendingNext;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800295
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800296 /* method pointers - java.lang.ref.Reference */
297 Method* methJavaLangRefReference_enqueueInternal;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800298
299 /* field offsets - java.nio.Buffer and java.nio.DirectByteBufferImpl */
300 //int offJavaNioBuffer_capacity;
301 //int offJavaNioDirectByteBufferImpl_pointer;
302
303 /* method pointers - java.security.AccessController */
Andy McFaddenfc3d3162010-08-05 14:34:26 -0700304 volatile int javaSecurityAccessControllerReady;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800305 Method* methJavaSecurityAccessController_doPrivileged[4];
306
307 /* constructor method pointers; no vtable involved, so use Method* */
308 Method* methJavaLangStackTraceElement_init;
309 Method* methJavaLangExceptionInInitializerError_init;
Andy McFaddenb18992f2009-09-25 10:42:15 -0700310 Method* methJavaLangRefPhantomReference_init;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800311 Method* methJavaLangReflectConstructor_init;
312 Method* methJavaLangReflectField_init;
313 Method* methJavaLangReflectMethod_init;
314 Method* methOrgApacheHarmonyLangAnnotationAnnotationMember_init;
315
316 /* static method pointers - android.lang.annotation.* */
317 Method*
318 methOrgApacheHarmonyLangAnnotationAnnotationFactory_createAnnotation;
319
320 /* direct method pointers - java.lang.reflect.Proxy */
321 Method* methJavaLangReflectProxy_constructorPrototype;
322
323 /* field offsets - java.lang.reflect.Proxy */
324 int offJavaLangReflectProxy_h;
325
326 /* fake native entry point method */
327 Method* methFakeNativeEntry;
328
Andy McFadden8e5c7842009-07-23 17:47:18 -0700329 /* assorted direct buffer helpers */
330 Method* methJavaNioReadWriteDirectByteBuffer_init;
331 Method* methOrgApacheHarmonyLuniPlatformPlatformAddress_on;
Andy McFadden5f612b82009-07-22 15:07:27 -0700332 Method* methOrgApacheHarmonyNioInternalDirectBuffer_getEffectiveAddress;
Andy McFadden8e5c7842009-07-23 17:47:18 -0700333 int offJavaNioBuffer_capacity;
Andy McFadden8e696dc2009-07-24 15:28:16 -0700334 int offJavaNioBuffer_effectiveDirectAddress;
Andy McFadden8e5c7842009-07-23 17:47:18 -0700335 int offOrgApacheHarmonyLuniPlatformPlatformAddress_osaddr;
336 int voffOrgApacheHarmonyLuniPlatformPlatformAddress_toLong;
Andy McFadden5f612b82009-07-22 15:07:27 -0700337
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800338 /*
339 * VM-synthesized primitive classes, for arrays.
340 */
341 ClassObject* volatile primitiveClass[PRIM_MAX];
342
343 /*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800344 * Thread list. This always has at least one element in it (main),
345 * and main is always the first entry.
346 *
347 * The threadListLock is used for several things, including the thread
348 * start condition variable. Generally speaking, you must hold the
349 * threadListLock when:
350 * - adding/removing items from the list
351 * - waiting on or signaling threadStartCond
352 * - examining the Thread struct for another thread (this is to avoid
353 * one thread freeing the Thread struct while another thread is
354 * perusing it)
355 */
356 Thread* threadList;
357 pthread_mutex_t threadListLock;
358
359 pthread_cond_t threadStartCond;
360
361 /*
362 * The thread code grabs this before suspending all threads. There
Andy McFadden2aa43612009-06-17 16:29:30 -0700363 * are a few things that can cause a "suspend all":
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800364 * (1) the GC is starting;
365 * (2) the debugger has sent a "suspend all" request;
366 * (3) a thread has hit a breakpoint or exception that the debugger
367 * has marked as a "suspend all" event;
368 * (4) the SignalCatcher caught a signal that requires suspension.
Ben Chengba4fc8b2009-06-01 13:00:29 -0700369 * (5) (if implemented) the JIT needs to perform a heavyweight
370 * rearrangement of the translation cache or JitTable.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800371 *
372 * Because we use "safe point" self-suspension, it is never safe to
373 * do a blocking "lock" call on this mutex -- if it has been acquired,
374 * somebody is probably trying to put you to sleep. The leading '_' is
375 * intended as a reminder that this lock is special.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800376 */
377 pthread_mutex_t _threadSuspendLock;
378
379 /*
380 * Guards Thread->suspendCount for all threads, and provides the lock
381 * for the condition variable that all suspended threads sleep on
382 * (threadSuspendCountCond).
383 *
384 * This has to be separate from threadListLock because of the way
385 * threads put themselves to sleep.
386 */
387 pthread_mutex_t threadSuspendCountLock;
388
389 /*
390 * Suspended threads sleep on this. They should sleep on the condition
391 * variable until their "suspend count" is zero.
392 *
393 * Paired with "threadSuspendCountLock".
394 */
395 pthread_cond_t threadSuspendCountCond;
396
397 /*
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700398 * Sum of all threads' suspendCount fields. The JIT needs to know if any
399 * thread is suspended. Guarded by threadSuspendCountLock.
400 */
401 int sumThreadSuspendCount;
402
403 /*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800404 * MUTEX ORDERING: when locking multiple mutexes, always grab them in
405 * this order to avoid deadlock:
406 *
407 * (1) _threadSuspendLock (use lockThreadSuspend())
408 * (2) threadListLock (use dvmLockThreadList())
409 * (3) threadSuspendCountLock (use lockThreadSuspendCount())
410 */
411
412
413 /*
414 * Thread ID bitmap. We want threads to have small integer IDs so
415 * we can use them in "thin locks".
416 */
417 BitVector* threadIdMap;
418
419 /*
420 * Manage exit conditions. The VM exits when all non-daemon threads
421 * have exited. If the main thread returns early, we need to sleep
422 * on a condition variable.
423 */
424 int nonDaemonThreadCount; /* must hold threadListLock to access */
425 //pthread_mutex_t vmExitLock;
426 pthread_cond_t vmExitCond;
427
428 /*
429 * The set of DEX files loaded by custom class loaders.
430 */
431 HashTable* userDexFiles;
432
433 /*
434 * JNI global reference table.
435 */
Andy McFaddend5ab7262009-08-25 07:19:34 -0700436#ifdef USE_INDIRECT_REF
437 IndirectRefTable jniGlobalRefTable;
438#else
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800439 ReferenceTable jniGlobalRefTable;
Andy McFaddend5ab7262009-08-25 07:19:34 -0700440#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800441 pthread_mutex_t jniGlobalRefLock;
442 int jniGlobalRefHiMark;
443 int jniGlobalRefLoMark;
444
445 /*
Andy McFaddenc26bb632009-08-21 12:01:31 -0700446 * JNI pinned object table (used for primitive arrays).
447 */
448 ReferenceTable jniPinRefTable;
449 pthread_mutex_t jniPinRefLock;
450
451 /*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800452 * Native shared library table.
453 */
454 HashTable* nativeLibs;
455
456 /*
457 * GC heap lock. Functions like gcMalloc() acquire this before making
458 * any changes to the heap. It is held throughout garbage collection.
459 */
460 pthread_mutex_t gcHeapLock;
461
Carl Shapiroec47e2e2010-07-01 17:44:46 -0700462 /*
463 * Condition variable to queue threads waiting to retry an
464 * allocation. Signaled after a concurrent GC is completed.
465 */
466 pthread_cond_t gcHeapCond;
467
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800468 /* Opaque pointer representing the heap. */
469 GcHeap* gcHeap;
470
Barry Hayes4496ed92010-07-12 09:52:20 -0700471 /* The card table base, modified as needed for marking cards. */
472 u1* biasedCardTableBase;
473
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800474 /*
Andy McFadden7fc3ce82009-07-14 15:57:23 -0700475 * Pre-allocated throwables.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800476 */
477 Object* outOfMemoryObj;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800478 Object* internalErrorObj;
Andy McFadden7fc3ce82009-07-14 15:57:23 -0700479 Object* noClassDefFoundErrorObj;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800480
481 /* Monitor list, so we can free them */
482 /*volatile*/ Monitor* monitorList;
483
484 /* Monitor for Thread.sleep() implementation */
485 Monitor* threadSleepMon;
486
487 /* set when we create a second heap inside the zygote */
488 bool newZygoteHeapAllocated;
489
490 /*
491 * TLS keys.
492 */
493 pthread_key_t pthreadKeySelf; /* Thread*, for dvmThreadSelf */
494
495 /*
496 * JNI allows you to have multiple VMs, but we limit ourselves to 1,
497 * so "vmList" is really just a pointer to the one and only VM.
498 */
499 JavaVM* vmList;
500
501 /*
502 * Cache results of "A instanceof B".
503 */
504 AtomicCache* instanceofCache;
505
506 /* instruction width table, used for optimization and verification */
507 InstructionWidth* instrWidth;
508 /* instruction flags table, used for verification */
509 InstructionFlags* instrFlags;
510 /* instruction format table, used for verification */
511 InstructionFormat* instrFormat;
512
Andy McFaddencb3c5422010-04-07 15:56:16 -0700513 /* inline substitution table, used during optimization */
514 InlineSub* inlineSubs;
515
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800516 /*
517 * Bootstrap class loader linear allocator.
518 */
519 LinearAllocHdr* pBootLoaderAlloc;
520
521
522 /*
523 * Heap worker thread.
524 */
525 bool heapWorkerInitialized;
526 bool heapWorkerReady;
527 bool haltHeapWorker;
528 pthread_t heapWorkerHandle;
529 pthread_mutex_t heapWorkerLock;
530 pthread_cond_t heapWorkerCond;
531 pthread_cond_t heapWorkerIdleCond;
532 pthread_mutex_t heapWorkerListLock;
533
534 /*
535 * Compute some stats on loaded classes.
536 */
The Android Open Source Project99409882009-03-18 22:20:24 -0700537 int numLoadedClasses;
538 int numDeclaredMethods;
539 int numDeclaredInstFields;
540 int numDeclaredStaticFields;
541
542 /* when using a native debugger, set this to suppress watchdog timers */
543 bool nativeDebuggerActive;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800544
545 /*
546 * JDWP debugger support.
Andy McFaddend51370f2009-08-05 15:20:27 -0700547 *
548 * Note "debuggerActive" is accessed from mterp, so its storage size and
549 * meaning must not be changed without updating the assembly sources.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800550 */
551 bool debuggerConnected; /* debugger or DDMS is connected */
Andy McFaddend51370f2009-08-05 15:20:27 -0700552 u1 debuggerActive; /* debugger is making requests */
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800553 JdwpState* jdwpState;
554
555 /*
556 * Registry of objects known to the debugger.
557 */
558 HashTable* dbgRegistry;
559
560 /*
Andy McFadden96516932009-10-28 17:39:02 -0700561 * Debugger breakpoint table.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800562 */
Andy McFadden96516932009-10-28 17:39:02 -0700563 BreakpointSet* breakpointSet;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800564
565 /*
566 * Single-step control struct. We currently only allow one thread to
567 * be single-stepping at a time, which is all that really makes sense,
568 * but it's possible we may need to expand this to be per-thread.
569 */
570 StepControl stepControl;
571
572 /*
573 * DDM features embedded in the VM.
574 */
575 bool ddmThreadNotification;
576
577 /*
578 * Zygote (partially-started process) support
579 */
580 bool zygote;
581
582 /*
583 * Used for tracking allocations that we report to DDMS. When the feature
584 * is enabled (through a DDMS request) the "allocRecords" pointer becomes
585 * non-NULL.
586 */
587 pthread_mutex_t allocTrackerLock;
588 AllocRecord* allocRecords;
589 int allocRecordHead; /* most-recently-added entry */
590 int allocRecordCount; /* #of valid entries */
591
592#ifdef WITH_ALLOC_LIMITS
593 /* set on first use of an alloc limit, never cleared */
594 bool checkAllocLimits;
595 /* allocation limit, for setGlobalAllocationLimit() regression testing */
596 int allocationLimit;
597#endif
598
599#ifdef WITH_DEADLOCK_PREDICTION
600 /* global lock on history tree accesses */
601 pthread_mutex_t deadlockHistoryLock;
602
603 enum { kDPOff=0, kDPWarn, kDPErr, kDPAbort } deadlockPredictMode;
604#endif
605
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800606 /*
607 * When a profiler is enabled, this is incremented. Distinct profilers
608 * include "dmtrace" method tracing, emulator method tracing, and
609 * possibly instruction counting.
610 *
611 * The purpose of this is to have a single value that the interpreter
612 * can check to see if any profiling activity is enabled.
613 */
614 volatile int activeProfilers;
615
616 /*
617 * State for method-trace profiling.
618 */
619 MethodTraceState methodTrace;
620
621 /*
622 * State for emulator tracing.
623 */
624 void* emulatorTracePage;
625 int emulatorTraceEnableCount;
626
627 /*
628 * Global state for memory allocation profiling.
629 */
630 AllocProfState allocProf;
631
632 /*
633 * Pointers to the original methods for things that have been inlined.
634 * This makes it easy for us to output method entry/exit records for
Andy McFadden0d615c32010-08-18 12:19:51 -0700635 * the method calls we're not actually making. (Used by method
636 * profiling.)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800637 */
638 Method** inlinedMethods;
639
640 /*
641 * Dalvik instruction counts (256 entries).
642 */
643 int* executedInstrCounts;
644 bool instructionCountEnableCount;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800645
646 /*
647 * Signal catcher thread (for SIGQUIT).
648 */
649 pthread_t signalCatcherHandle;
650 bool haltSignalCatcher;
651
652 /*
653 * Stdout/stderr conversion thread.
654 */
655 bool haltStdioConverter;
656 bool stdioConverterReady;
657 pthread_t stdioConverterHandle;
658 pthread_mutex_t stdioConverterLock;
659 pthread_cond_t stdioConverterCond;
660
661 /*
662 * pid of the system_server process. We track it so that when system server
663 * crashes the Zygote process will be killed and restarted.
664 */
665 pid_t systemServerPid;
666
San Mehat894dd462009-09-08 20:29:15 -0700667 int kernelGroupScheduling;
668
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800669//#define COUNT_PRECISE_METHODS
670#ifdef COUNT_PRECISE_METHODS
671 PointerSet* preciseMethods;
672#endif
The Android Open Source Project99409882009-03-18 22:20:24 -0700673
674 /* some RegisterMap statistics, useful during development */
675 void* registerMapStats;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800676};
677
678extern struct DvmGlobals gDvm;
679
Ben Chengba4fc8b2009-06-01 13:00:29 -0700680#if defined(WITH_JIT)
Ben Cheng38329f52009-07-07 14:19:20 -0700681
Ben Chengba4fc8b2009-06-01 13:00:29 -0700682/*
Ben Cheng6c10a972009-10-29 14:39:18 -0700683 * Exiting the compiled code w/o chaining will incur overhead to look up the
684 * target in the code cache which is extra work only when JIT is enabled. So
685 * we want to monitor it closely to make sure we don't have performance bugs.
686 */
687typedef enum NoChainExits {
688 kInlineCacheMiss = 0,
689 kCallsiteInterpreted,
690 kSwitchOverflow,
Bill Buzbeefccb31d2010-02-04 16:09:55 -0800691 kHeavyweightMonitor,
Ben Cheng6c10a972009-10-29 14:39:18 -0700692 kNoChainExitLast,
693} NoChainExits;
694
695/*
Ben Chengba4fc8b2009-06-01 13:00:29 -0700696 * JIT-specific global state
697 */
698struct DvmJitGlobals {
699 /*
700 * Guards writes to Dalvik PC (dPC), translated code address (codeAddr) and
701 * chain fields within the JIT hash table. Note carefully the access
702 * mechanism.
703 * Only writes are guarded, and the guarded fields must be updated in a
704 * specific order using atomic operations. Further, once a field is
705 * written it cannot be changed without halting all threads.
706 *
707 * The write order is:
708 * 1) codeAddr
709 * 2) dPC
710 * 3) chain [if necessary]
711 *
712 * This mutex also guards both read and write of curJitTableEntries.
713 */
714 pthread_mutex_t tableLock;
715
716 /* The JIT hash table. Note that for access speed, copies of this pointer
717 * are stored in each thread. */
718 struct JitEntry *pJitEntryTable;
719
720 /* Array of profile threshold counters */
721 unsigned char *pProfTable;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700722
Bill Buzbee06bb8392010-01-31 18:53:15 -0800723 /* Copy of pProfTable used for temporarily disabling the Jit */
724 unsigned char *pProfTableCopy;
725
Ben Chengba4fc8b2009-06-01 13:00:29 -0700726 /* Size of JIT hash table in entries. Must be a power of 2 */
Bill Buzbee27176222009-06-09 09:20:16 -0700727 unsigned int jitTableSize;
728
729 /* Mask used in hash function for JitTable. Should be jitTableSize-1 */
730 unsigned int jitTableMask;
731
732 /* How many entries in the JitEntryTable are in use */
733 unsigned int jitTableEntriesUsed;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700734
Ben Cheng94e79eb2010-02-04 16:15:59 -0800735 /* Bytes allocated for the code cache */
736 unsigned int codeCacheSize;
737
Ben Chengba4fc8b2009-06-01 13:00:29 -0700738 /* Trigger for trace selection */
739 unsigned short threshold;
740
741 /* JIT Compiler Control */
742 bool haltCompilerThread;
743 bool blockingMode;
744 pthread_t compilerHandle;
745 pthread_mutex_t compilerLock;
Ben Chengc3b92b22010-01-26 16:46:15 -0800746 pthread_mutex_t compilerICPatchLock;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700747 pthread_cond_t compilerQueueActivity;
748 pthread_cond_t compilerQueueEmpty;
Ben Cheng88a0f972010-02-24 15:00:40 -0800749 volatile int compilerQueueLength;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700750 int compilerHighWater;
751 int compilerWorkEnqueueIndex;
752 int compilerWorkDequeueIndex;
Ben Chengc3b92b22010-01-26 16:46:15 -0800753 int compilerICPatchIndex;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700754
755 /* JIT internal stats */
756 int compilerMaxQueued;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700757 int translationChains;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700758
759 /* Compiled code cache */
760 void* codeCache;
761
Ben Cheng8b258bf2009-06-24 17:27:07 -0700762 /* Bytes used by the code templates */
763 unsigned int templateSize;
764
Ben Chengba4fc8b2009-06-01 13:00:29 -0700765 /* Bytes already used in the code cache */
766 unsigned int codeCacheByteUsed;
767
768 /* Number of installed compilations in the cache */
769 unsigned int numCompilations;
770
771 /* Flag to indicate that the code cache is full */
772 bool codeCacheFull;
773
Ben Chengb88ec3c2010-05-17 12:50:33 -0700774 /* Page size - 1 */
775 unsigned int pageSizeMask;
776
777 /* Lock to change the protection type of the code cache */
778 pthread_mutex_t codeCacheProtectionLock;
779
Ben Cheng7a0bcd02010-01-22 16:45:45 -0800780 /* Number of times that the code cache has been reset */
781 int numCodeCacheReset;
782
Ben Chengc3b92b22010-01-26 16:46:15 -0800783 /* Number of times that the code cache reset request has been delayed */
784 int numCodeCacheResetDelayed;
785
Ben Chengba4fc8b2009-06-01 13:00:29 -0700786 /* true/false: compile/reject opcodes specified in the -Xjitop list */
787 bool includeSelectedOp;
788
789 /* true/false: compile/reject methods specified in the -Xjitmethod list */
790 bool includeSelectedMethod;
791
792 /* Disable JIT for selected opcodes - one bit for each opcode */
793 char opList[32];
794
795 /* Disable JIT for selected methods */
796 HashTable *methodTable;
797
Ben Chengba4fc8b2009-06-01 13:00:29 -0700798 /* Flag to dump all compiled code */
799 bool printMe;
Bill Buzbee6e963e12009-06-17 16:56:19 -0700800
801 /* Flag to count trace execution */
802 bool profile;
Ben Cheng8b258bf2009-06-24 17:27:07 -0700803
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700804 /* Vector to disable selected optimizations */
805 int disableOpt;
806
Ben Cheng8b258bf2009-06-24 17:27:07 -0700807 /* Table to track the overall and trace statistics of hot methods */
808 HashTable* methodStatsTable;
Ben Chengbcdc1de2009-08-21 16:18:46 -0700809
Ben Cheng33672452010-01-12 14:59:30 -0800810 /* Filter method compilation blacklist with call-graph information */
811 bool checkCallGraph;
812
Ben Chengc3b92b22010-01-26 16:46:15 -0800813 /* New translation chain has been set up */
814 volatile bool hasNewChain;
815
Ben Chengbcdc1de2009-08-21 16:18:46 -0700816#if defined(WITH_SELF_VERIFICATION)
817 /* Spin when error is detected, volatile so GDB can reset it */
818 volatile bool selfVerificationSpin;
819#endif
Ben Chengc3b92b22010-01-26 16:46:15 -0800820
Bill Buzbeefccb31d2010-02-04 16:09:55 -0800821 /* Framework or stand-alone? */
822 bool runningInAndroidFramework;
823
Ben Chengc5285b32010-02-14 16:17:36 -0800824 /* Framework callback happened? */
825 bool alreadyEnabledViaFramework;
826
827 /* Framework requests to disable the JIT for good */
828 bool disableJit;
829
Ben Chengdca71432010-03-16 16:04:11 -0700830#if defined(SIGNATURE_BREAKPOINT)
831 /* Signature breakpoint */
832 u4 signatureBreakpointSize; // # of words
833 u4 *signatureBreakpoint; // Signature content
834#endif
835
Ben Cheng978738d2010-05-13 13:45:57 -0700836#if defined(WITH_JIT_TUNING)
837 /* Performance tuning counters */
838 int addrLookupsFound;
839 int addrLookupsNotFound;
840 int noChainExit[kNoChainExitLast];
841 int normalExit;
842 int puntExit;
843 int invokeMonomorphic;
844 int invokePolymorphic;
845 int invokeNative;
Ben Cheng7a2697d2010-06-07 13:44:23 -0700846 int invokeMonoGetterInlined;
847 int invokeMonoSetterInlined;
848 int invokePolyGetterInlined;
849 int invokePolySetterInlined;
Ben Cheng978738d2010-05-13 13:45:57 -0700850 int returnOp;
Ben Chengb88ec3c2010-05-17 12:50:33 -0700851 int icPatchInit;
852 int icPatchLockFree;
Ben Cheng978738d2010-05-13 13:45:57 -0700853 int icPatchQueued;
Ben Chengb88ec3c2010-05-17 12:50:33 -0700854 int icPatchRejected;
Ben Cheng978738d2010-05-13 13:45:57 -0700855 int icPatchDropped;
856 u8 jitTime;
857 int codeCachePatches;
858#endif
859
Ben Chengc3b92b22010-01-26 16:46:15 -0800860 /* Place arrays at the end to ease the display in gdb sessions */
861
862 /* Work order queue for compilations */
863 CompilerWorkOrder compilerWorkQueue[COMPILER_WORK_QUEUE_SIZE];
864
865 /* Work order queue for predicted chain patching */
866 ICPatchWorkOrder compilerICPatchQueue[COMPILER_IC_PATCH_QUEUE_SIZE];
Ben Chengba4fc8b2009-06-01 13:00:29 -0700867};
868
869extern struct DvmJitGlobals gDvmJit;
870
Ben Cheng978738d2010-05-13 13:45:57 -0700871#if defined(WITH_JIT_TUNING)
872extern int gDvmICHitCount;
873#endif
874
Ben Chengba4fc8b2009-06-01 13:00:29 -0700875#endif
876
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800877#endif /*_DALVIK_GLOBALS*/