blob: fea40c25b410ebc333bd1b29e4fe2344deaf94d1 [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 McFaddenea414342010-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
Barry Hayes962adba2010-03-17 12:12:39 -0700121 /*
122 * GC option flags.
123 */
The Android Open Source Project99409882009-03-18 22:20:24 -0700124 bool preciseGc;
Barry Hayes962adba2010-03-17 12:12:39 -0700125 bool preVerify;
126 bool postVerify;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800127 bool generateRegisterMaps;
Carl Shapiroec805ea2010-06-28 16:28:26 -0700128 bool concurrentMarkSweep;
Barry Hayes6e5cf602010-06-22 12:32:59 -0700129 bool verifyCardTable;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800130
131 int assertionCtrlCount;
132 AssertionControl* assertionCtrl;
133
134 ExecutionMode executionMode;
135
136 /*
137 * VM init management.
138 */
139 bool initializing;
140 int initExceptionCount;
141 bool optimizing;
142
143 /*
144 * java.lang.System properties set from the command line.
145 */
146 int numProps;
147 int maxProps;
148 char** propList;
149
150 /*
151 * Where the VM goes to find system classes.
152 */
153 ClassPathEntry* bootClassPath;
154 /* used by the DEX optimizer to load classes from an unfinished DEX */
155 DvmDex* bootClassPathOptExtra;
156 bool optimizingBootstrapClass;
157
158 /*
159 * Loaded classes, hashed by class name. Each entry is a ClassObject*,
160 * allocated in GC space.
161 */
162 HashTable* loadedClasses;
163
164 /*
165 * Value for the next class serial number to be assigned. This is
166 * incremented as we load classes. Failed loads and races may result
167 * in some numbers being skipped, and the serial number is not
168 * guaranteed to start at 1, so the current value should not be used
169 * as a count of loaded classes.
170 */
171 volatile int classSerialNumber;
172
173 /*
Barry Hayes2c987472009-04-06 10:03:48 -0700174 * Classes with a low classSerialNumber are probably in the zygote, and
175 * their InitiatingLoaderList is not used, to promote sharing. The list is
176 * kept here instead.
177 */
178 InitiatingLoaderList* initiatingLoaderList;
179
180 /*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800181 * Interned strings.
182 */
Carl Shapirobb1e0e92010-07-21 14:49:25 -0700183
184 /* A mutex that guards access to the interned string tables. */
185 pthread_mutex_t internLock;
186
187 /* Hash table of strings interned by the user. */
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800188 HashTable* internedStrings;
189
Carl Shapirobb1e0e92010-07-21 14:49:25 -0700190 /* Hash table of strings interned by the class loader. */
191 HashTable* literalStrings;
192
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800193 /*
194 * Quick lookups for popular classes used internally.
195 */
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800196 ClassObject* classJavaLangClass;
197 ClassObject* classJavaLangClassArray;
198 ClassObject* classJavaLangError;
199 ClassObject* classJavaLangObject;
200 ClassObject* classJavaLangObjectArray;
201 ClassObject* classJavaLangRuntimeException;
202 ClassObject* classJavaLangString;
203 ClassObject* classJavaLangThread;
204 ClassObject* classJavaLangVMThread;
205 ClassObject* classJavaLangThreadGroup;
206 ClassObject* classJavaLangThrowable;
Andy McFadden4fbba1f2010-02-03 07:21:14 -0800207 ClassObject* classJavaLangStackOverflowError;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800208 ClassObject* classJavaLangStackTraceElement;
209 ClassObject* classJavaLangStackTraceElementArray;
210 ClassObject* classJavaLangAnnotationAnnotationArray;
211 ClassObject* classJavaLangAnnotationAnnotationArrayArray;
212 ClassObject* classJavaLangReflectAccessibleObject;
213 ClassObject* classJavaLangReflectConstructor;
214 ClassObject* classJavaLangReflectConstructorArray;
215 ClassObject* classJavaLangReflectField;
216 ClassObject* classJavaLangReflectFieldArray;
217 ClassObject* classJavaLangReflectMethod;
218 ClassObject* classJavaLangReflectMethodArray;
219 ClassObject* classJavaLangReflectProxy;
220 ClassObject* classJavaLangExceptionInInitializerError;
Andy McFaddenb18992f2009-09-25 10:42:15 -0700221 ClassObject* classJavaLangRefPhantomReference;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800222 ClassObject* classJavaLangRefReference;
Andy McFadden8e5c7842009-07-23 17:47:18 -0700223 ClassObject* classJavaNioReadWriteDirectByteBuffer;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800224 ClassObject* classJavaSecurityAccessController;
225 ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationFactory;
226 ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMember;
227 ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMemberArray;
Andy McFadden5f612b82009-07-22 15:07:27 -0700228 ClassObject* classOrgApacheHarmonyNioInternalDirectBuffer;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800229
230 /* synthetic classes for arrays of primitives */
231 ClassObject* classArrayBoolean;
232 ClassObject* classArrayChar;
233 ClassObject* classArrayFloat;
234 ClassObject* classArrayDouble;
235 ClassObject* classArrayByte;
236 ClassObject* classArrayShort;
237 ClassObject* classArrayInt;
238 ClassObject* classArrayLong;
239
240 /* method offsets - Object */
241 int voffJavaLangObject_equals;
242 int voffJavaLangObject_hashCode;
243 int voffJavaLangObject_toString;
244 int voffJavaLangObject_finalize;
245
246 /* field offsets - Class */
247 int offJavaLangClass_pd;
248
249 /* field offsets - String */
Andy McFaddendeeeeb22010-06-16 08:32:04 -0700250 int javaLangStringReady; /* 0=not init, 1=ready, -1=initing */
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800251 int offJavaLangString_value;
252 int offJavaLangString_count;
253 int offJavaLangString_offset;
254 int offJavaLangString_hashCode;
255
256 /* field offsets - Thread */
257 int offJavaLangThread_vmThread;
258 int offJavaLangThread_group;
259 int offJavaLangThread_daemon;
260 int offJavaLangThread_name;
261 int offJavaLangThread_priority;
262
263 /* method offsets - Thread */
264 int voffJavaLangThread_run;
265
266 /* field offsets - VMThread */
267 int offJavaLangVMThread_thread;
268 int offJavaLangVMThread_vmData;
269
270 /* method offsets - ThreadGroup */
271 int voffJavaLangThreadGroup_removeThread;
272
273 /* field offsets - Throwable */
274 int offJavaLangThrowable_stackState;
275 int offJavaLangThrowable_message;
276 int offJavaLangThrowable_cause;
277
278 /* field offsets - java.lang.reflect.* */
279 int offJavaLangReflectAccessibleObject_flag;
280 int offJavaLangReflectConstructor_slot;
281 int offJavaLangReflectConstructor_declClass;
282 int offJavaLangReflectField_slot;
283 int offJavaLangReflectField_declClass;
284 int offJavaLangReflectMethod_slot;
285 int offJavaLangReflectMethod_declClass;
286
287 /* field offsets - java.lang.ref.Reference */
288 int offJavaLangRefReference_referent;
289 int offJavaLangRefReference_queue;
290 int offJavaLangRefReference_queueNext;
Carl Shapiro2a6f4842010-07-09 16:50:54 -0700291 int offJavaLangRefReference_pendingNext;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800292
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800293 /* method pointers - java.lang.ref.Reference */
294 Method* methJavaLangRefReference_enqueueInternal;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800295
296 /* field offsets - java.nio.Buffer and java.nio.DirectByteBufferImpl */
297 //int offJavaNioBuffer_capacity;
298 //int offJavaNioDirectByteBufferImpl_pointer;
299
300 /* method pointers - java.security.AccessController */
Andy McFaddenfc3d3162010-08-05 14:34:26 -0700301 volatile int javaSecurityAccessControllerReady;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800302 Method* methJavaSecurityAccessController_doPrivileged[4];
303
304 /* constructor method pointers; no vtable involved, so use Method* */
305 Method* methJavaLangStackTraceElement_init;
306 Method* methJavaLangExceptionInInitializerError_init;
Andy McFaddenb18992f2009-09-25 10:42:15 -0700307 Method* methJavaLangRefPhantomReference_init;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800308 Method* methJavaLangReflectConstructor_init;
309 Method* methJavaLangReflectField_init;
310 Method* methJavaLangReflectMethod_init;
311 Method* methOrgApacheHarmonyLangAnnotationAnnotationMember_init;
312
313 /* static method pointers - android.lang.annotation.* */
314 Method*
315 methOrgApacheHarmonyLangAnnotationAnnotationFactory_createAnnotation;
316
317 /* direct method pointers - java.lang.reflect.Proxy */
318 Method* methJavaLangReflectProxy_constructorPrototype;
319
320 /* field offsets - java.lang.reflect.Proxy */
321 int offJavaLangReflectProxy_h;
322
323 /* fake native entry point method */
324 Method* methFakeNativeEntry;
325
Andy McFadden8e5c7842009-07-23 17:47:18 -0700326 /* assorted direct buffer helpers */
327 Method* methJavaNioReadWriteDirectByteBuffer_init;
328 Method* methOrgApacheHarmonyLuniPlatformPlatformAddress_on;
Andy McFadden5f612b82009-07-22 15:07:27 -0700329 Method* methOrgApacheHarmonyNioInternalDirectBuffer_getEffectiveAddress;
Andy McFadden8e5c7842009-07-23 17:47:18 -0700330 int offJavaNioBuffer_capacity;
Andy McFadden8e696dc2009-07-24 15:28:16 -0700331 int offJavaNioBuffer_effectiveDirectAddress;
Andy McFadden8e5c7842009-07-23 17:47:18 -0700332 int offOrgApacheHarmonyLuniPlatformPlatformAddress_osaddr;
Andy McFadden5f612b82009-07-22 15:07:27 -0700333
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800334 /*
335 * VM-synthesized primitive classes, for arrays.
336 */
337 ClassObject* volatile primitiveClass[PRIM_MAX];
338
339 /*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800340 * Thread list. This always has at least one element in it (main),
341 * and main is always the first entry.
342 *
343 * The threadListLock is used for several things, including the thread
344 * start condition variable. Generally speaking, you must hold the
345 * threadListLock when:
346 * - adding/removing items from the list
347 * - waiting on or signaling threadStartCond
348 * - examining the Thread struct for another thread (this is to avoid
349 * one thread freeing the Thread struct while another thread is
350 * perusing it)
351 */
352 Thread* threadList;
353 pthread_mutex_t threadListLock;
354
355 pthread_cond_t threadStartCond;
356
357 /*
358 * The thread code grabs this before suspending all threads. There
Andy McFadden2aa43612009-06-17 16:29:30 -0700359 * are a few things that can cause a "suspend all":
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800360 * (1) the GC is starting;
361 * (2) the debugger has sent a "suspend all" request;
362 * (3) a thread has hit a breakpoint or exception that the debugger
363 * has marked as a "suspend all" event;
364 * (4) the SignalCatcher caught a signal that requires suspension.
Ben Chengba4fc8b2009-06-01 13:00:29 -0700365 * (5) (if implemented) the JIT needs to perform a heavyweight
366 * rearrangement of the translation cache or JitTable.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800367 *
368 * Because we use "safe point" self-suspension, it is never safe to
369 * do a blocking "lock" call on this mutex -- if it has been acquired,
370 * somebody is probably trying to put you to sleep. The leading '_' is
371 * intended as a reminder that this lock is special.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800372 */
373 pthread_mutex_t _threadSuspendLock;
374
375 /*
376 * Guards Thread->suspendCount for all threads, and provides the lock
377 * for the condition variable that all suspended threads sleep on
378 * (threadSuspendCountCond).
379 *
380 * This has to be separate from threadListLock because of the way
381 * threads put themselves to sleep.
382 */
383 pthread_mutex_t threadSuspendCountLock;
384
385 /*
386 * Suspended threads sleep on this. They should sleep on the condition
387 * variable until their "suspend count" is zero.
388 *
389 * Paired with "threadSuspendCountLock".
390 */
391 pthread_cond_t threadSuspendCountCond;
392
393 /*
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700394 * Sum of all threads' suspendCount fields. The JIT needs to know if any
395 * thread is suspended. Guarded by threadSuspendCountLock.
396 */
397 int sumThreadSuspendCount;
398
399 /*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800400 * MUTEX ORDERING: when locking multiple mutexes, always grab them in
401 * this order to avoid deadlock:
402 *
403 * (1) _threadSuspendLock (use lockThreadSuspend())
404 * (2) threadListLock (use dvmLockThreadList())
405 * (3) threadSuspendCountLock (use lockThreadSuspendCount())
406 */
407
408
409 /*
410 * Thread ID bitmap. We want threads to have small integer IDs so
411 * we can use them in "thin locks".
412 */
413 BitVector* threadIdMap;
414
415 /*
416 * Manage exit conditions. The VM exits when all non-daemon threads
417 * have exited. If the main thread returns early, we need to sleep
418 * on a condition variable.
419 */
420 int nonDaemonThreadCount; /* must hold threadListLock to access */
421 //pthread_mutex_t vmExitLock;
422 pthread_cond_t vmExitCond;
423
424 /*
425 * The set of DEX files loaded by custom class loaders.
426 */
427 HashTable* userDexFiles;
428
429 /*
430 * JNI global reference table.
431 */
Andy McFaddend5ab7262009-08-25 07:19:34 -0700432#ifdef USE_INDIRECT_REF
433 IndirectRefTable jniGlobalRefTable;
434#else
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800435 ReferenceTable jniGlobalRefTable;
Andy McFaddend5ab7262009-08-25 07:19:34 -0700436#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800437 pthread_mutex_t jniGlobalRefLock;
438 int jniGlobalRefHiMark;
439 int jniGlobalRefLoMark;
440
441 /*
Andy McFaddenc26bb632009-08-21 12:01:31 -0700442 * JNI pinned object table (used for primitive arrays).
443 */
444 ReferenceTable jniPinRefTable;
445 pthread_mutex_t jniPinRefLock;
446
447 /*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800448 * Native shared library table.
449 */
450 HashTable* nativeLibs;
451
452 /*
453 * GC heap lock. Functions like gcMalloc() acquire this before making
454 * any changes to the heap. It is held throughout garbage collection.
455 */
456 pthread_mutex_t gcHeapLock;
457
Carl Shapiroec47e2e2010-07-01 17:44:46 -0700458 /*
459 * Condition variable to queue threads waiting to retry an
460 * allocation. Signaled after a concurrent GC is completed.
461 */
462 pthread_cond_t gcHeapCond;
463
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800464 /* Opaque pointer representing the heap. */
465 GcHeap* gcHeap;
466
Barry Hayes4496ed92010-07-12 09:52:20 -0700467 /* The card table base, modified as needed for marking cards. */
468 u1* biasedCardTableBase;
469
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800470 /*
Andy McFadden7fc3ce82009-07-14 15:57:23 -0700471 * Pre-allocated throwables.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800472 */
473 Object* outOfMemoryObj;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800474 Object* internalErrorObj;
Andy McFadden7fc3ce82009-07-14 15:57:23 -0700475 Object* noClassDefFoundErrorObj;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800476
477 /* Monitor list, so we can free them */
478 /*volatile*/ Monitor* monitorList;
479
480 /* Monitor for Thread.sleep() implementation */
481 Monitor* threadSleepMon;
482
483 /* set when we create a second heap inside the zygote */
484 bool newZygoteHeapAllocated;
485
486 /*
487 * TLS keys.
488 */
489 pthread_key_t pthreadKeySelf; /* Thread*, for dvmThreadSelf */
490
491 /*
492 * JNI allows you to have multiple VMs, but we limit ourselves to 1,
493 * so "vmList" is really just a pointer to the one and only VM.
494 */
495 JavaVM* vmList;
496
497 /*
498 * Cache results of "A instanceof B".
499 */
500 AtomicCache* instanceofCache;
501
502 /* instruction width table, used for optimization and verification */
503 InstructionWidth* instrWidth;
504 /* instruction flags table, used for verification */
505 InstructionFlags* instrFlags;
506 /* instruction format table, used for verification */
507 InstructionFormat* instrFormat;
508
Andy McFaddencb3c5422010-04-07 15:56:16 -0700509 /* inline substitution table, used during optimization */
510 InlineSub* inlineSubs;
511
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800512 /*
513 * Bootstrap class loader linear allocator.
514 */
515 LinearAllocHdr* pBootLoaderAlloc;
516
517
518 /*
519 * Heap worker thread.
520 */
521 bool heapWorkerInitialized;
522 bool heapWorkerReady;
523 bool haltHeapWorker;
524 pthread_t heapWorkerHandle;
525 pthread_mutex_t heapWorkerLock;
526 pthread_cond_t heapWorkerCond;
527 pthread_cond_t heapWorkerIdleCond;
528 pthread_mutex_t heapWorkerListLock;
529
530 /*
531 * Compute some stats on loaded classes.
532 */
The Android Open Source Project99409882009-03-18 22:20:24 -0700533 int numLoadedClasses;
534 int numDeclaredMethods;
535 int numDeclaredInstFields;
536 int numDeclaredStaticFields;
537
538 /* when using a native debugger, set this to suppress watchdog timers */
539 bool nativeDebuggerActive;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800540
541 /*
542 * JDWP debugger support.
Andy McFaddend51370f2009-08-05 15:20:27 -0700543 *
544 * Note "debuggerActive" is accessed from mterp, so its storage size and
545 * meaning must not be changed without updating the assembly sources.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800546 */
547 bool debuggerConnected; /* debugger or DDMS is connected */
Andy McFaddend51370f2009-08-05 15:20:27 -0700548 u1 debuggerActive; /* debugger is making requests */
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800549 JdwpState* jdwpState;
550
551 /*
552 * Registry of objects known to the debugger.
553 */
554 HashTable* dbgRegistry;
555
556 /*
Andy McFadden96516932009-10-28 17:39:02 -0700557 * Debugger breakpoint table.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800558 */
Andy McFadden96516932009-10-28 17:39:02 -0700559 BreakpointSet* breakpointSet;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800560
561 /*
562 * Single-step control struct. We currently only allow one thread to
563 * be single-stepping at a time, which is all that really makes sense,
564 * but it's possible we may need to expand this to be per-thread.
565 */
566 StepControl stepControl;
567
568 /*
569 * DDM features embedded in the VM.
570 */
571 bool ddmThreadNotification;
572
573 /*
574 * Zygote (partially-started process) support
575 */
576 bool zygote;
577
578 /*
579 * Used for tracking allocations that we report to DDMS. When the feature
580 * is enabled (through a DDMS request) the "allocRecords" pointer becomes
581 * non-NULL.
582 */
583 pthread_mutex_t allocTrackerLock;
584 AllocRecord* allocRecords;
585 int allocRecordHead; /* most-recently-added entry */
586 int allocRecordCount; /* #of valid entries */
587
588#ifdef WITH_ALLOC_LIMITS
589 /* set on first use of an alloc limit, never cleared */
590 bool checkAllocLimits;
591 /* allocation limit, for setGlobalAllocationLimit() regression testing */
592 int allocationLimit;
593#endif
594
595#ifdef WITH_DEADLOCK_PREDICTION
596 /* global lock on history tree accesses */
597 pthread_mutex_t deadlockHistoryLock;
598
599 enum { kDPOff=0, kDPWarn, kDPErr, kDPAbort } deadlockPredictMode;
600#endif
601
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800602 /*
603 * When a profiler is enabled, this is incremented. Distinct profilers
604 * include "dmtrace" method tracing, emulator method tracing, and
605 * possibly instruction counting.
606 *
607 * The purpose of this is to have a single value that the interpreter
608 * can check to see if any profiling activity is enabled.
609 */
610 volatile int activeProfilers;
611
612 /*
613 * State for method-trace profiling.
614 */
615 MethodTraceState methodTrace;
616
617 /*
618 * State for emulator tracing.
619 */
620 void* emulatorTracePage;
621 int emulatorTraceEnableCount;
622
623 /*
624 * Global state for memory allocation profiling.
625 */
626 AllocProfState allocProf;
627
628 /*
629 * Pointers to the original methods for things that have been inlined.
630 * This makes it easy for us to output method entry/exit records for
Andy McFadden0d615c32010-08-18 12:19:51 -0700631 * the method calls we're not actually making. (Used by method
632 * profiling.)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800633 */
634 Method** inlinedMethods;
635
636 /*
637 * Dalvik instruction counts (256 entries).
638 */
639 int* executedInstrCounts;
640 bool instructionCountEnableCount;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800641
642 /*
643 * Signal catcher thread (for SIGQUIT).
644 */
645 pthread_t signalCatcherHandle;
646 bool haltSignalCatcher;
647
648 /*
649 * Stdout/stderr conversion thread.
650 */
651 bool haltStdioConverter;
652 bool stdioConverterReady;
653 pthread_t stdioConverterHandle;
654 pthread_mutex_t stdioConverterLock;
655 pthread_cond_t stdioConverterCond;
656
657 /*
658 * pid of the system_server process. We track it so that when system server
659 * crashes the Zygote process will be killed and restarted.
660 */
661 pid_t systemServerPid;
662
San Mehat894dd462009-09-08 20:29:15 -0700663 int kernelGroupScheduling;
664
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800665//#define COUNT_PRECISE_METHODS
666#ifdef COUNT_PRECISE_METHODS
667 PointerSet* preciseMethods;
668#endif
The Android Open Source Project99409882009-03-18 22:20:24 -0700669
670 /* some RegisterMap statistics, useful during development */
671 void* registerMapStats;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800672};
673
674extern struct DvmGlobals gDvm;
675
Ben Chengba4fc8b2009-06-01 13:00:29 -0700676#if defined(WITH_JIT)
Ben Cheng38329f52009-07-07 14:19:20 -0700677
Ben Chengba4fc8b2009-06-01 13:00:29 -0700678/*
Ben Cheng6c10a972009-10-29 14:39:18 -0700679 * Exiting the compiled code w/o chaining will incur overhead to look up the
680 * target in the code cache which is extra work only when JIT is enabled. So
681 * we want to monitor it closely to make sure we don't have performance bugs.
682 */
683typedef enum NoChainExits {
684 kInlineCacheMiss = 0,
685 kCallsiteInterpreted,
686 kSwitchOverflow,
Bill Buzbeefccb31d2010-02-04 16:09:55 -0800687 kHeavyweightMonitor,
Ben Cheng6c10a972009-10-29 14:39:18 -0700688 kNoChainExitLast,
689} NoChainExits;
690
691/*
Ben Chengba4fc8b2009-06-01 13:00:29 -0700692 * JIT-specific global state
693 */
694struct DvmJitGlobals {
695 /*
696 * Guards writes to Dalvik PC (dPC), translated code address (codeAddr) and
697 * chain fields within the JIT hash table. Note carefully the access
698 * mechanism.
699 * Only writes are guarded, and the guarded fields must be updated in a
700 * specific order using atomic operations. Further, once a field is
701 * written it cannot be changed without halting all threads.
702 *
703 * The write order is:
704 * 1) codeAddr
705 * 2) dPC
706 * 3) chain [if necessary]
707 *
708 * This mutex also guards both read and write of curJitTableEntries.
709 */
710 pthread_mutex_t tableLock;
711
712 /* The JIT hash table. Note that for access speed, copies of this pointer
713 * are stored in each thread. */
714 struct JitEntry *pJitEntryTable;
715
716 /* Array of profile threshold counters */
717 unsigned char *pProfTable;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700718
Bill Buzbee06bb8392010-01-31 18:53:15 -0800719 /* Copy of pProfTable used for temporarily disabling the Jit */
720 unsigned char *pProfTableCopy;
721
Ben Chengba4fc8b2009-06-01 13:00:29 -0700722 /* Size of JIT hash table in entries. Must be a power of 2 */
Bill Buzbee27176222009-06-09 09:20:16 -0700723 unsigned int jitTableSize;
724
725 /* Mask used in hash function for JitTable. Should be jitTableSize-1 */
726 unsigned int jitTableMask;
727
728 /* How many entries in the JitEntryTable are in use */
729 unsigned int jitTableEntriesUsed;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700730
Ben Cheng94e79eb2010-02-04 16:15:59 -0800731 /* Bytes allocated for the code cache */
732 unsigned int codeCacheSize;
733
Ben Chengba4fc8b2009-06-01 13:00:29 -0700734 /* Trigger for trace selection */
735 unsigned short threshold;
736
737 /* JIT Compiler Control */
738 bool haltCompilerThread;
739 bool blockingMode;
740 pthread_t compilerHandle;
741 pthread_mutex_t compilerLock;
Ben Chengc3b92b22010-01-26 16:46:15 -0800742 pthread_mutex_t compilerICPatchLock;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700743 pthread_cond_t compilerQueueActivity;
744 pthread_cond_t compilerQueueEmpty;
Ben Cheng88a0f972010-02-24 15:00:40 -0800745 volatile int compilerQueueLength;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700746 int compilerHighWater;
747 int compilerWorkEnqueueIndex;
748 int compilerWorkDequeueIndex;
Ben Chengc3b92b22010-01-26 16:46:15 -0800749 int compilerICPatchIndex;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700750
751 /* JIT internal stats */
752 int compilerMaxQueued;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700753 int translationChains;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700754
755 /* Compiled code cache */
756 void* codeCache;
757
Ben Cheng8b258bf2009-06-24 17:27:07 -0700758 /* Bytes used by the code templates */
759 unsigned int templateSize;
760
Ben Chengba4fc8b2009-06-01 13:00:29 -0700761 /* Bytes already used in the code cache */
762 unsigned int codeCacheByteUsed;
763
764 /* Number of installed compilations in the cache */
765 unsigned int numCompilations;
766
767 /* Flag to indicate that the code cache is full */
768 bool codeCacheFull;
769
Ben Chengb88ec3c2010-05-17 12:50:33 -0700770 /* Page size - 1 */
771 unsigned int pageSizeMask;
772
773 /* Lock to change the protection type of the code cache */
774 pthread_mutex_t codeCacheProtectionLock;
775
Ben Cheng7a0bcd02010-01-22 16:45:45 -0800776 /* Number of times that the code cache has been reset */
777 int numCodeCacheReset;
778
Ben Chengc3b92b22010-01-26 16:46:15 -0800779 /* Number of times that the code cache reset request has been delayed */
780 int numCodeCacheResetDelayed;
781
Ben Chengba4fc8b2009-06-01 13:00:29 -0700782 /* true/false: compile/reject opcodes specified in the -Xjitop list */
783 bool includeSelectedOp;
784
785 /* true/false: compile/reject methods specified in the -Xjitmethod list */
786 bool includeSelectedMethod;
787
788 /* Disable JIT for selected opcodes - one bit for each opcode */
789 char opList[32];
790
791 /* Disable JIT for selected methods */
792 HashTable *methodTable;
793
Ben Chengba4fc8b2009-06-01 13:00:29 -0700794 /* Flag to dump all compiled code */
795 bool printMe;
Bill Buzbee6e963e12009-06-17 16:56:19 -0700796
797 /* Flag to count trace execution */
798 bool profile;
Ben Cheng8b258bf2009-06-24 17:27:07 -0700799
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700800 /* Vector to disable selected optimizations */
801 int disableOpt;
802
Ben Cheng8b258bf2009-06-24 17:27:07 -0700803 /* Table to track the overall and trace statistics of hot methods */
804 HashTable* methodStatsTable;
Ben Chengbcdc1de2009-08-21 16:18:46 -0700805
Ben Cheng33672452010-01-12 14:59:30 -0800806 /* Filter method compilation blacklist with call-graph information */
807 bool checkCallGraph;
808
Ben Chengc3b92b22010-01-26 16:46:15 -0800809 /* New translation chain has been set up */
810 volatile bool hasNewChain;
811
Ben Chengbcdc1de2009-08-21 16:18:46 -0700812#if defined(WITH_SELF_VERIFICATION)
813 /* Spin when error is detected, volatile so GDB can reset it */
814 volatile bool selfVerificationSpin;
815#endif
Ben Chengc3b92b22010-01-26 16:46:15 -0800816
Bill Buzbeefccb31d2010-02-04 16:09:55 -0800817 /* Framework or stand-alone? */
818 bool runningInAndroidFramework;
819
Ben Chengc5285b32010-02-14 16:17:36 -0800820 /* Framework callback happened? */
821 bool alreadyEnabledViaFramework;
822
823 /* Framework requests to disable the JIT for good */
824 bool disableJit;
825
Ben Chengdca71432010-03-16 16:04:11 -0700826#if defined(SIGNATURE_BREAKPOINT)
827 /* Signature breakpoint */
828 u4 signatureBreakpointSize; // # of words
829 u4 *signatureBreakpoint; // Signature content
830#endif
831
Ben Cheng978738d2010-05-13 13:45:57 -0700832#if defined(WITH_JIT_TUNING)
833 /* Performance tuning counters */
834 int addrLookupsFound;
835 int addrLookupsNotFound;
836 int noChainExit[kNoChainExitLast];
837 int normalExit;
838 int puntExit;
839 int invokeMonomorphic;
840 int invokePolymorphic;
841 int invokeNative;
Ben Cheng7a2697d2010-06-07 13:44:23 -0700842 int invokeMonoGetterInlined;
843 int invokeMonoSetterInlined;
844 int invokePolyGetterInlined;
845 int invokePolySetterInlined;
Ben Cheng978738d2010-05-13 13:45:57 -0700846 int returnOp;
Ben Chengb88ec3c2010-05-17 12:50:33 -0700847 int icPatchInit;
848 int icPatchLockFree;
Ben Cheng978738d2010-05-13 13:45:57 -0700849 int icPatchQueued;
Ben Chengb88ec3c2010-05-17 12:50:33 -0700850 int icPatchRejected;
Ben Cheng978738d2010-05-13 13:45:57 -0700851 int icPatchDropped;
852 u8 jitTime;
853 int codeCachePatches;
854#endif
855
Ben Chengc3b92b22010-01-26 16:46:15 -0800856 /* Place arrays at the end to ease the display in gdb sessions */
857
858 /* Work order queue for compilations */
859 CompilerWorkOrder compilerWorkQueue[COMPILER_WORK_QUEUE_SIZE];
860
861 /* Work order queue for predicted chain patching */
862 ICPatchWorkOrder compilerICPatchQueue[COMPILER_IC_PATCH_QUEUE_SIZE];
Ben Chengba4fc8b2009-06-01 13:00:29 -0700863};
864
865extern struct DvmJitGlobals gDvmJit;
866
Ben Cheng978738d2010-05-13 13:45:57 -0700867#if defined(WITH_JIT_TUNING)
868extern int gDvmICHitCount;
869#endif
870
Ben Chengba4fc8b2009-06-01 13:00:29 -0700871#endif
872
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800873#endif /*_DALVIK_GLOBALS*/