blob: 4ebfd5e096ccb33b063d81e8c6ab34254eea37b1 [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
Carl Shapirob8fcf572010-04-16 17:33:15 -070094 /*
95 * Lock profiling threshold value in milliseconds. Acquires that
96 * exceed threshold are logged. Acquires within the threshold are
97 * logged with a probability of $\frac{time}{threshold}$ . If the
98 * threshold is unset no additional logging occurs.
99 */
Carl Shapirof0c514c2010-04-09 15:03:33 -0700100 u4 lockProfThreshold;
Carl Shapirof0c514c2010-04-09 15:03:33 -0700101
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800102 int (*vfprintfHook)(FILE*, const char*, va_list);
103 void (*exitHook)(int);
104 void (*abortHook)(void);
105
106 int jniGrefLimit; // 0 means no limit
107 bool reduceSignals;
108 bool noQuitHandler;
109 bool verifyDexChecksum;
110 char* stackTraceFile; // for SIGQUIT-inspired output
111
112 bool logStdio;
113
114 DexOptimizerMode dexOptMode;
115 DexClassVerifyMode classVerifyMode;
Barry Hayes5cbb2302010-02-02 14:07:37 -0800116
Barry Hayes962adba2010-03-17 12:12:39 -0700117 /*
118 * GC option flags.
119 */
The Android Open Source Project99409882009-03-18 22:20:24 -0700120 bool preciseGc;
Barry Hayes5cbb2302010-02-02 14:07:37 -0800121 bool overwriteFree;
Barry Hayes962adba2010-03-17 12:12:39 -0700122 bool preVerify;
123 bool postVerify;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800124 bool generateRegisterMaps;
125
126 int assertionCtrlCount;
127 AssertionControl* assertionCtrl;
128
129 ExecutionMode executionMode;
130
131 /*
132 * VM init management.
133 */
134 bool initializing;
135 int initExceptionCount;
136 bool optimizing;
137
138 /*
139 * java.lang.System properties set from the command line.
140 */
141 int numProps;
142 int maxProps;
143 char** propList;
144
145 /*
146 * Where the VM goes to find system classes.
147 */
148 ClassPathEntry* bootClassPath;
149 /* used by the DEX optimizer to load classes from an unfinished DEX */
150 DvmDex* bootClassPathOptExtra;
151 bool optimizingBootstrapClass;
152
153 /*
154 * Loaded classes, hashed by class name. Each entry is a ClassObject*,
155 * allocated in GC space.
156 */
157 HashTable* loadedClasses;
158
159 /*
160 * Value for the next class serial number to be assigned. This is
161 * incremented as we load classes. Failed loads and races may result
162 * in some numbers being skipped, and the serial number is not
163 * guaranteed to start at 1, so the current value should not be used
164 * as a count of loaded classes.
165 */
166 volatile int classSerialNumber;
167
168 /*
Barry Hayes2c987472009-04-06 10:03:48 -0700169 * Classes with a low classSerialNumber are probably in the zygote, and
170 * their InitiatingLoaderList is not used, to promote sharing. The list is
171 * kept here instead.
172 */
173 InitiatingLoaderList* initiatingLoaderList;
174
175 /*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800176 * Interned strings.
177 */
178 HashTable* internedStrings;
179
180 /*
181 * Quick lookups for popular classes used internally.
182 */
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800183 ClassObject* classJavaLangClass;
184 ClassObject* classJavaLangClassArray;
185 ClassObject* classJavaLangError;
186 ClassObject* classJavaLangObject;
187 ClassObject* classJavaLangObjectArray;
188 ClassObject* classJavaLangRuntimeException;
189 ClassObject* classJavaLangString;
190 ClassObject* classJavaLangThread;
191 ClassObject* classJavaLangVMThread;
192 ClassObject* classJavaLangThreadGroup;
193 ClassObject* classJavaLangThrowable;
Andy McFadden4fbba1f2010-02-03 07:21:14 -0800194 ClassObject* classJavaLangStackOverflowError;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800195 ClassObject* classJavaLangStackTraceElement;
196 ClassObject* classJavaLangStackTraceElementArray;
197 ClassObject* classJavaLangAnnotationAnnotationArray;
198 ClassObject* classJavaLangAnnotationAnnotationArrayArray;
199 ClassObject* classJavaLangReflectAccessibleObject;
200 ClassObject* classJavaLangReflectConstructor;
201 ClassObject* classJavaLangReflectConstructorArray;
202 ClassObject* classJavaLangReflectField;
203 ClassObject* classJavaLangReflectFieldArray;
204 ClassObject* classJavaLangReflectMethod;
205 ClassObject* classJavaLangReflectMethodArray;
206 ClassObject* classJavaLangReflectProxy;
207 ClassObject* classJavaLangExceptionInInitializerError;
Andy McFaddenb18992f2009-09-25 10:42:15 -0700208 ClassObject* classJavaLangRefPhantomReference;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800209 ClassObject* classJavaLangRefReference;
Andy McFadden8e5c7842009-07-23 17:47:18 -0700210 ClassObject* classJavaNioReadWriteDirectByteBuffer;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800211 ClassObject* classJavaSecurityAccessController;
212 ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationFactory;
213 ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMember;
214 ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMemberArray;
Andy McFadden5f612b82009-07-22 15:07:27 -0700215 ClassObject* classOrgApacheHarmonyNioInternalDirectBuffer;
Andy McFaddend5ab7262009-08-25 07:19:34 -0700216 jclass jclassOrgApacheHarmonyNioInternalDirectBuffer;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800217
218 /* synthetic classes for arrays of primitives */
219 ClassObject* classArrayBoolean;
220 ClassObject* classArrayChar;
221 ClassObject* classArrayFloat;
222 ClassObject* classArrayDouble;
223 ClassObject* classArrayByte;
224 ClassObject* classArrayShort;
225 ClassObject* classArrayInt;
226 ClassObject* classArrayLong;
227
228 /* method offsets - Object */
229 int voffJavaLangObject_equals;
230 int voffJavaLangObject_hashCode;
231 int voffJavaLangObject_toString;
232 int voffJavaLangObject_finalize;
233
234 /* field offsets - Class */
235 int offJavaLangClass_pd;
236
237 /* field offsets - String */
Andy McFaddendeeeeb22010-06-16 08:32:04 -0700238 int javaLangStringReady; /* 0=not init, 1=ready, -1=initing */
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800239 int offJavaLangString_value;
240 int offJavaLangString_count;
241 int offJavaLangString_offset;
242 int offJavaLangString_hashCode;
243
244 /* field offsets - Thread */
245 int offJavaLangThread_vmThread;
246 int offJavaLangThread_group;
247 int offJavaLangThread_daemon;
248 int offJavaLangThread_name;
249 int offJavaLangThread_priority;
250
251 /* method offsets - Thread */
252 int voffJavaLangThread_run;
253
254 /* field offsets - VMThread */
255 int offJavaLangVMThread_thread;
256 int offJavaLangVMThread_vmData;
257
258 /* method offsets - ThreadGroup */
259 int voffJavaLangThreadGroup_removeThread;
260
261 /* field offsets - Throwable */
262 int offJavaLangThrowable_stackState;
263 int offJavaLangThrowable_message;
264 int offJavaLangThrowable_cause;
265
266 /* field offsets - java.lang.reflect.* */
267 int offJavaLangReflectAccessibleObject_flag;
268 int offJavaLangReflectConstructor_slot;
269 int offJavaLangReflectConstructor_declClass;
270 int offJavaLangReflectField_slot;
271 int offJavaLangReflectField_declClass;
272 int offJavaLangReflectMethod_slot;
273 int offJavaLangReflectMethod_declClass;
274
275 /* field offsets - java.lang.ref.Reference */
276 int offJavaLangRefReference_referent;
277 int offJavaLangRefReference_queue;
278 int offJavaLangRefReference_queueNext;
279 int offJavaLangRefReference_vmData;
280
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800281 /* method pointers - java.lang.ref.Reference */
282 Method* methJavaLangRefReference_enqueueInternal;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800283
284 /* field offsets - java.nio.Buffer and java.nio.DirectByteBufferImpl */
285 //int offJavaNioBuffer_capacity;
286 //int offJavaNioDirectByteBufferImpl_pointer;
287
288 /* method pointers - java.security.AccessController */
289 volatile bool javaSecurityAccessControllerReady;
290 Method* methJavaSecurityAccessController_doPrivileged[4];
291
292 /* constructor method pointers; no vtable involved, so use Method* */
293 Method* methJavaLangStackTraceElement_init;
294 Method* methJavaLangExceptionInInitializerError_init;
Andy McFaddenb18992f2009-09-25 10:42:15 -0700295 Method* methJavaLangRefPhantomReference_init;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800296 Method* methJavaLangReflectConstructor_init;
297 Method* methJavaLangReflectField_init;
298 Method* methJavaLangReflectMethod_init;
299 Method* methOrgApacheHarmonyLangAnnotationAnnotationMember_init;
300
301 /* static method pointers - android.lang.annotation.* */
302 Method*
303 methOrgApacheHarmonyLangAnnotationAnnotationFactory_createAnnotation;
304
305 /* direct method pointers - java.lang.reflect.Proxy */
306 Method* methJavaLangReflectProxy_constructorPrototype;
307
308 /* field offsets - java.lang.reflect.Proxy */
309 int offJavaLangReflectProxy_h;
310
311 /* fake native entry point method */
312 Method* methFakeNativeEntry;
313
Andy McFadden8e5c7842009-07-23 17:47:18 -0700314 /* assorted direct buffer helpers */
315 Method* methJavaNioReadWriteDirectByteBuffer_init;
316 Method* methOrgApacheHarmonyLuniPlatformPlatformAddress_on;
Andy McFadden5f612b82009-07-22 15:07:27 -0700317 Method* methOrgApacheHarmonyNioInternalDirectBuffer_getEffectiveAddress;
Andy McFadden8e5c7842009-07-23 17:47:18 -0700318 int offJavaNioBuffer_capacity;
Andy McFadden8e696dc2009-07-24 15:28:16 -0700319 int offJavaNioBuffer_effectiveDirectAddress;
Andy McFadden8e5c7842009-07-23 17:47:18 -0700320 int offOrgApacheHarmonyLuniPlatformPlatformAddress_osaddr;
321 int voffOrgApacheHarmonyLuniPlatformPlatformAddress_toLong;
Andy McFadden5f612b82009-07-22 15:07:27 -0700322
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800323 /*
324 * VM-synthesized primitive classes, for arrays.
325 */
326 ClassObject* volatile primitiveClass[PRIM_MAX];
327
328 /*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800329 * Thread list. This always has at least one element in it (main),
330 * and main is always the first entry.
331 *
332 * The threadListLock is used for several things, including the thread
333 * start condition variable. Generally speaking, you must hold the
334 * threadListLock when:
335 * - adding/removing items from the list
336 * - waiting on or signaling threadStartCond
337 * - examining the Thread struct for another thread (this is to avoid
338 * one thread freeing the Thread struct while another thread is
339 * perusing it)
340 */
341 Thread* threadList;
342 pthread_mutex_t threadListLock;
343
344 pthread_cond_t threadStartCond;
345
346 /*
347 * The thread code grabs this before suspending all threads. There
Andy McFadden2aa43612009-06-17 16:29:30 -0700348 * are a few things that can cause a "suspend all":
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800349 * (1) the GC is starting;
350 * (2) the debugger has sent a "suspend all" request;
351 * (3) a thread has hit a breakpoint or exception that the debugger
352 * has marked as a "suspend all" event;
353 * (4) the SignalCatcher caught a signal that requires suspension.
Ben Chengba4fc8b2009-06-01 13:00:29 -0700354 * (5) (if implemented) the JIT needs to perform a heavyweight
355 * rearrangement of the translation cache or JitTable.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800356 *
357 * Because we use "safe point" self-suspension, it is never safe to
358 * do a blocking "lock" call on this mutex -- if it has been acquired,
359 * somebody is probably trying to put you to sleep. The leading '_' is
360 * intended as a reminder that this lock is special.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800361 */
362 pthread_mutex_t _threadSuspendLock;
363
364 /*
365 * Guards Thread->suspendCount for all threads, and provides the lock
366 * for the condition variable that all suspended threads sleep on
367 * (threadSuspendCountCond).
368 *
369 * This has to be separate from threadListLock because of the way
370 * threads put themselves to sleep.
371 */
372 pthread_mutex_t threadSuspendCountLock;
373
374 /*
375 * Suspended threads sleep on this. They should sleep on the condition
376 * variable until their "suspend count" is zero.
377 *
378 * Paired with "threadSuspendCountLock".
379 */
380 pthread_cond_t threadSuspendCountCond;
381
382 /*
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700383 * Sum of all threads' suspendCount fields. The JIT needs to know if any
384 * thread is suspended. Guarded by threadSuspendCountLock.
385 */
386 int sumThreadSuspendCount;
387
388 /*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800389 * MUTEX ORDERING: when locking multiple mutexes, always grab them in
390 * this order to avoid deadlock:
391 *
392 * (1) _threadSuspendLock (use lockThreadSuspend())
393 * (2) threadListLock (use dvmLockThreadList())
394 * (3) threadSuspendCountLock (use lockThreadSuspendCount())
395 */
396
397
398 /*
399 * Thread ID bitmap. We want threads to have small integer IDs so
400 * we can use them in "thin locks".
401 */
402 BitVector* threadIdMap;
403
404 /*
405 * Manage exit conditions. The VM exits when all non-daemon threads
406 * have exited. If the main thread returns early, we need to sleep
407 * on a condition variable.
408 */
409 int nonDaemonThreadCount; /* must hold threadListLock to access */
410 //pthread_mutex_t vmExitLock;
411 pthread_cond_t vmExitCond;
412
413 /*
414 * The set of DEX files loaded by custom class loaders.
415 */
416 HashTable* userDexFiles;
417
418 /*
419 * JNI global reference table.
420 */
Andy McFaddend5ab7262009-08-25 07:19:34 -0700421#ifdef USE_INDIRECT_REF
422 IndirectRefTable jniGlobalRefTable;
423#else
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800424 ReferenceTable jniGlobalRefTable;
Andy McFaddend5ab7262009-08-25 07:19:34 -0700425#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800426 pthread_mutex_t jniGlobalRefLock;
427 int jniGlobalRefHiMark;
428 int jniGlobalRefLoMark;
429
430 /*
Andy McFaddenc26bb632009-08-21 12:01:31 -0700431 * JNI pinned object table (used for primitive arrays).
432 */
433 ReferenceTable jniPinRefTable;
434 pthread_mutex_t jniPinRefLock;
435
436 /*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800437 * Native shared library table.
438 */
439 HashTable* nativeLibs;
440
441 /*
442 * GC heap lock. Functions like gcMalloc() acquire this before making
443 * any changes to the heap. It is held throughout garbage collection.
444 */
445 pthread_mutex_t gcHeapLock;
446
447 /* Opaque pointer representing the heap. */
448 GcHeap* gcHeap;
449
450 /*
Andy McFadden7fc3ce82009-07-14 15:57:23 -0700451 * Pre-allocated throwables.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800452 */
453 Object* outOfMemoryObj;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800454 Object* internalErrorObj;
Andy McFadden7fc3ce82009-07-14 15:57:23 -0700455 Object* noClassDefFoundErrorObj;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800456
457 /* Monitor list, so we can free them */
458 /*volatile*/ Monitor* monitorList;
459
460 /* Monitor for Thread.sleep() implementation */
461 Monitor* threadSleepMon;
462
463 /* set when we create a second heap inside the zygote */
464 bool newZygoteHeapAllocated;
465
466 /*
467 * TLS keys.
468 */
469 pthread_key_t pthreadKeySelf; /* Thread*, for dvmThreadSelf */
470
471 /*
472 * JNI allows you to have multiple VMs, but we limit ourselves to 1,
473 * so "vmList" is really just a pointer to the one and only VM.
474 */
475 JavaVM* vmList;
476
477 /*
478 * Cache results of "A instanceof B".
479 */
480 AtomicCache* instanceofCache;
481
482 /* instruction width table, used for optimization and verification */
483 InstructionWidth* instrWidth;
484 /* instruction flags table, used for verification */
485 InstructionFlags* instrFlags;
486 /* instruction format table, used for verification */
487 InstructionFormat* instrFormat;
488
Andy McFaddencb3c5422010-04-07 15:56:16 -0700489 /* inline substitution table, used during optimization */
490 InlineSub* inlineSubs;
491
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800492 /*
493 * Bootstrap class loader linear allocator.
494 */
495 LinearAllocHdr* pBootLoaderAlloc;
496
497
498 /*
499 * Heap worker thread.
500 */
501 bool heapWorkerInitialized;
502 bool heapWorkerReady;
503 bool haltHeapWorker;
504 pthread_t heapWorkerHandle;
505 pthread_mutex_t heapWorkerLock;
506 pthread_cond_t heapWorkerCond;
507 pthread_cond_t heapWorkerIdleCond;
508 pthread_mutex_t heapWorkerListLock;
509
510 /*
511 * Compute some stats on loaded classes.
512 */
The Android Open Source Project99409882009-03-18 22:20:24 -0700513 int numLoadedClasses;
514 int numDeclaredMethods;
515 int numDeclaredInstFields;
516 int numDeclaredStaticFields;
517
518 /* when using a native debugger, set this to suppress watchdog timers */
519 bool nativeDebuggerActive;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800520
521 /*
522 * JDWP debugger support.
Andy McFaddend51370f2009-08-05 15:20:27 -0700523 *
524 * Note "debuggerActive" is accessed from mterp, so its storage size and
525 * meaning must not be changed without updating the assembly sources.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800526 */
527 bool debuggerConnected; /* debugger or DDMS is connected */
Andy McFaddend51370f2009-08-05 15:20:27 -0700528 u1 debuggerActive; /* debugger is making requests */
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800529 JdwpState* jdwpState;
530
531 /*
532 * Registry of objects known to the debugger.
533 */
534 HashTable* dbgRegistry;
535
536 /*
Andy McFadden96516932009-10-28 17:39:02 -0700537 * Debugger breakpoint table.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800538 */
Andy McFadden96516932009-10-28 17:39:02 -0700539 BreakpointSet* breakpointSet;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800540
541 /*
542 * Single-step control struct. We currently only allow one thread to
543 * be single-stepping at a time, which is all that really makes sense,
544 * but it's possible we may need to expand this to be per-thread.
545 */
546 StepControl stepControl;
547
548 /*
549 * DDM features embedded in the VM.
550 */
551 bool ddmThreadNotification;
552
553 /*
554 * Zygote (partially-started process) support
555 */
556 bool zygote;
557
558 /*
559 * Used for tracking allocations that we report to DDMS. When the feature
560 * is enabled (through a DDMS request) the "allocRecords" pointer becomes
561 * non-NULL.
562 */
563 pthread_mutex_t allocTrackerLock;
564 AllocRecord* allocRecords;
565 int allocRecordHead; /* most-recently-added entry */
566 int allocRecordCount; /* #of valid entries */
567
568#ifdef WITH_ALLOC_LIMITS
569 /* set on first use of an alloc limit, never cleared */
570 bool checkAllocLimits;
571 /* allocation limit, for setGlobalAllocationLimit() regression testing */
572 int allocationLimit;
573#endif
574
575#ifdef WITH_DEADLOCK_PREDICTION
576 /* global lock on history tree accesses */
577 pthread_mutex_t deadlockHistoryLock;
578
579 enum { kDPOff=0, kDPWarn, kDPErr, kDPAbort } deadlockPredictMode;
580#endif
581
582#ifdef WITH_PROFILER
583 /*
584 * When a profiler is enabled, this is incremented. Distinct profilers
585 * include "dmtrace" method tracing, emulator method tracing, and
586 * possibly instruction counting.
587 *
588 * The purpose of this is to have a single value that the interpreter
589 * can check to see if any profiling activity is enabled.
590 */
591 volatile int activeProfilers;
592
593 /*
594 * State for method-trace profiling.
595 */
596 MethodTraceState methodTrace;
597
598 /*
599 * State for emulator tracing.
600 */
601 void* emulatorTracePage;
602 int emulatorTraceEnableCount;
603
604 /*
605 * Global state for memory allocation profiling.
606 */
607 AllocProfState allocProf;
608
609 /*
610 * Pointers to the original methods for things that have been inlined.
611 * This makes it easy for us to output method entry/exit records for
612 * the method calls we're not actually making.
613 */
614 Method** inlinedMethods;
615
616 /*
617 * Dalvik instruction counts (256 entries).
618 */
619 int* executedInstrCounts;
620 bool instructionCountEnableCount;
621#endif
622
623 /*
624 * Signal catcher thread (for SIGQUIT).
625 */
626 pthread_t signalCatcherHandle;
627 bool haltSignalCatcher;
628
629 /*
630 * Stdout/stderr conversion thread.
631 */
632 bool haltStdioConverter;
633 bool stdioConverterReady;
634 pthread_t stdioConverterHandle;
635 pthread_mutex_t stdioConverterLock;
636 pthread_cond_t stdioConverterCond;
637
638 /*
639 * pid of the system_server process. We track it so that when system server
640 * crashes the Zygote process will be killed and restarted.
641 */
642 pid_t systemServerPid;
643
San Mehat894dd462009-09-08 20:29:15 -0700644 int kernelGroupScheduling;
645
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800646//#define COUNT_PRECISE_METHODS
647#ifdef COUNT_PRECISE_METHODS
648 PointerSet* preciseMethods;
649#endif
The Android Open Source Project99409882009-03-18 22:20:24 -0700650
651 /* some RegisterMap statistics, useful during development */
652 void* registerMapStats;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800653};
654
655extern struct DvmGlobals gDvm;
656
Ben Chengba4fc8b2009-06-01 13:00:29 -0700657#if defined(WITH_JIT)
Ben Cheng38329f52009-07-07 14:19:20 -0700658
Ben Chengba4fc8b2009-06-01 13:00:29 -0700659/*
Ben Cheng6c10a972009-10-29 14:39:18 -0700660 * Exiting the compiled code w/o chaining will incur overhead to look up the
661 * target in the code cache which is extra work only when JIT is enabled. So
662 * we want to monitor it closely to make sure we don't have performance bugs.
663 */
664typedef enum NoChainExits {
665 kInlineCacheMiss = 0,
666 kCallsiteInterpreted,
667 kSwitchOverflow,
Bill Buzbeefccb31d2010-02-04 16:09:55 -0800668 kHeavyweightMonitor,
Ben Cheng6c10a972009-10-29 14:39:18 -0700669 kNoChainExitLast,
670} NoChainExits;
671
672/*
Ben Chengba4fc8b2009-06-01 13:00:29 -0700673 * JIT-specific global state
674 */
675struct DvmJitGlobals {
676 /*
677 * Guards writes to Dalvik PC (dPC), translated code address (codeAddr) and
678 * chain fields within the JIT hash table. Note carefully the access
679 * mechanism.
680 * Only writes are guarded, and the guarded fields must be updated in a
681 * specific order using atomic operations. Further, once a field is
682 * written it cannot be changed without halting all threads.
683 *
684 * The write order is:
685 * 1) codeAddr
686 * 2) dPC
687 * 3) chain [if necessary]
688 *
689 * This mutex also guards both read and write of curJitTableEntries.
690 */
691 pthread_mutex_t tableLock;
692
693 /* The JIT hash table. Note that for access speed, copies of this pointer
694 * are stored in each thread. */
695 struct JitEntry *pJitEntryTable;
696
697 /* Array of profile threshold counters */
698 unsigned char *pProfTable;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700699
Bill Buzbee06bb8392010-01-31 18:53:15 -0800700 /* Copy of pProfTable used for temporarily disabling the Jit */
701 unsigned char *pProfTableCopy;
702
Ben Chengba4fc8b2009-06-01 13:00:29 -0700703 /* Size of JIT hash table in entries. Must be a power of 2 */
Bill Buzbee27176222009-06-09 09:20:16 -0700704 unsigned int jitTableSize;
705
706 /* Mask used in hash function for JitTable. Should be jitTableSize-1 */
707 unsigned int jitTableMask;
708
709 /* How many entries in the JitEntryTable are in use */
710 unsigned int jitTableEntriesUsed;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700711
Ben Cheng94e79eb2010-02-04 16:15:59 -0800712 /* Bytes allocated for the code cache */
713 unsigned int codeCacheSize;
714
Ben Chengba4fc8b2009-06-01 13:00:29 -0700715 /* Trigger for trace selection */
716 unsigned short threshold;
717
718 /* JIT Compiler Control */
719 bool haltCompilerThread;
720 bool blockingMode;
721 pthread_t compilerHandle;
722 pthread_mutex_t compilerLock;
Ben Chengc3b92b22010-01-26 16:46:15 -0800723 pthread_mutex_t compilerICPatchLock;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700724 pthread_cond_t compilerQueueActivity;
725 pthread_cond_t compilerQueueEmpty;
Ben Cheng88a0f972010-02-24 15:00:40 -0800726 volatile int compilerQueueLength;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700727 int compilerHighWater;
728 int compilerWorkEnqueueIndex;
729 int compilerWorkDequeueIndex;
Ben Chengc3b92b22010-01-26 16:46:15 -0800730 int compilerICPatchIndex;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700731
732 /* JIT internal stats */
733 int compilerMaxQueued;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700734 int translationChains;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700735
736 /* Compiled code cache */
737 void* codeCache;
738
Ben Cheng8b258bf2009-06-24 17:27:07 -0700739 /* Bytes used by the code templates */
740 unsigned int templateSize;
741
Ben Chengba4fc8b2009-06-01 13:00:29 -0700742 /* Bytes already used in the code cache */
743 unsigned int codeCacheByteUsed;
744
745 /* Number of installed compilations in the cache */
746 unsigned int numCompilations;
747
748 /* Flag to indicate that the code cache is full */
749 bool codeCacheFull;
750
Ben Chengb88ec3c2010-05-17 12:50:33 -0700751 /* Page size - 1 */
752 unsigned int pageSizeMask;
753
754 /* Lock to change the protection type of the code cache */
755 pthread_mutex_t codeCacheProtectionLock;
756
Ben Cheng7a0bcd02010-01-22 16:45:45 -0800757 /* Number of times that the code cache has been reset */
758 int numCodeCacheReset;
759
Ben Chengc3b92b22010-01-26 16:46:15 -0800760 /* Number of times that the code cache reset request has been delayed */
761 int numCodeCacheResetDelayed;
762
Ben Chengba4fc8b2009-06-01 13:00:29 -0700763 /* true/false: compile/reject opcodes specified in the -Xjitop list */
764 bool includeSelectedOp;
765
766 /* true/false: compile/reject methods specified in the -Xjitmethod list */
767 bool includeSelectedMethod;
768
769 /* Disable JIT for selected opcodes - one bit for each opcode */
770 char opList[32];
771
772 /* Disable JIT for selected methods */
773 HashTable *methodTable;
774
Ben Chengba4fc8b2009-06-01 13:00:29 -0700775 /* Flag to dump all compiled code */
776 bool printMe;
Bill Buzbee6e963e12009-06-17 16:56:19 -0700777
778 /* Flag to count trace execution */
779 bool profile;
Ben Cheng8b258bf2009-06-24 17:27:07 -0700780
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700781 /* Vector to disable selected optimizations */
782 int disableOpt;
783
Ben Cheng8b258bf2009-06-24 17:27:07 -0700784 /* Table to track the overall and trace statistics of hot methods */
785 HashTable* methodStatsTable;
Ben Chengbcdc1de2009-08-21 16:18:46 -0700786
Ben Cheng33672452010-01-12 14:59:30 -0800787 /* Filter method compilation blacklist with call-graph information */
788 bool checkCallGraph;
789
Ben Chengc3b92b22010-01-26 16:46:15 -0800790 /* New translation chain has been set up */
791 volatile bool hasNewChain;
792
Ben Chengbcdc1de2009-08-21 16:18:46 -0700793#if defined(WITH_SELF_VERIFICATION)
794 /* Spin when error is detected, volatile so GDB can reset it */
795 volatile bool selfVerificationSpin;
796#endif
Ben Chengc3b92b22010-01-26 16:46:15 -0800797
Bill Buzbeefccb31d2010-02-04 16:09:55 -0800798 /* Framework or stand-alone? */
799 bool runningInAndroidFramework;
800
Ben Chengc5285b32010-02-14 16:17:36 -0800801 /* Framework callback happened? */
802 bool alreadyEnabledViaFramework;
803
804 /* Framework requests to disable the JIT for good */
805 bool disableJit;
806
Ben Chengdca71432010-03-16 16:04:11 -0700807#if defined(SIGNATURE_BREAKPOINT)
808 /* Signature breakpoint */
809 u4 signatureBreakpointSize; // # of words
810 u4 *signatureBreakpoint; // Signature content
811#endif
812
Ben Cheng978738d2010-05-13 13:45:57 -0700813#if defined(WITH_JIT_TUNING)
814 /* Performance tuning counters */
815 int addrLookupsFound;
816 int addrLookupsNotFound;
817 int noChainExit[kNoChainExitLast];
818 int normalExit;
819 int puntExit;
820 int invokeMonomorphic;
821 int invokePolymorphic;
822 int invokeNative;
823 int returnOp;
Ben Chengb88ec3c2010-05-17 12:50:33 -0700824 int icPatchInit;
825 int icPatchLockFree;
Ben Cheng978738d2010-05-13 13:45:57 -0700826 int icPatchQueued;
Ben Chengb88ec3c2010-05-17 12:50:33 -0700827 int icPatchRejected;
Ben Cheng978738d2010-05-13 13:45:57 -0700828 int icPatchDropped;
829 u8 jitTime;
830 int codeCachePatches;
831#endif
832
Ben Chengc3b92b22010-01-26 16:46:15 -0800833 /* Place arrays at the end to ease the display in gdb sessions */
834
835 /* Work order queue for compilations */
836 CompilerWorkOrder compilerWorkQueue[COMPILER_WORK_QUEUE_SIZE];
837
838 /* Work order queue for predicted chain patching */
839 ICPatchWorkOrder compilerICPatchQueue[COMPILER_IC_PATCH_QUEUE_SIZE];
Ben Chengba4fc8b2009-06-01 13:00:29 -0700840};
841
842extern struct DvmJitGlobals gDvmJit;
843
Ben Cheng978738d2010-05-13 13:45:57 -0700844#if defined(WITH_JIT_TUNING)
845extern int gDvmICHitCount;
846#endif
847
Ben Chengba4fc8b2009-06-01 13:00:29 -0700848#endif
849
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800850#endif /*_DALVIK_GLOBALS*/