blob: 3af995ad23c31118384ea122284d1eea1114fb37 [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;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080040
41/*
42 * One of these for each -ea/-da/-esa/-dsa on the command line.
43 */
44typedef struct AssertionControl {
45 char* pkgOrClass; /* package/class string, or NULL for esa/dsa */
46 int pkgOrClassLen; /* string length, for quick compare */
47 bool enable; /* enable or disable */
48 bool isPackage; /* string ended with "..."? */
49} AssertionControl;
50
51/*
52 * Execution mode, e.g. interpreter vs. JIT.
53 */
54typedef enum ExecutionMode {
55 kExecutionModeUnknown = 0,
56 kExecutionModeInterpPortable,
57 kExecutionModeInterpFast,
Ben Chengba4fc8b2009-06-01 13:00:29 -070058#if defined(WITH_JIT)
59 kExecutionModeJit,
60#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080061} ExecutionMode;
62
63/*
64 * All fields are initialized to zero.
65 *
66 * Storage allocated here must be freed by a subsystem shutdown function or
67 * from within freeGlobals().
68 */
69struct DvmGlobals {
70 /*
71 * Some options from the command line or environment.
72 */
73 char* bootClassPathStr;
74 char* classPathStr;
75
76 unsigned int heapSizeStart;
77 unsigned int heapSizeMax;
78 unsigned int stackSize;
79
80 bool verboseGc;
81 bool verboseJni;
82 bool verboseClass;
Andy McFadden43eb5012010-02-01 16:56:53 -080083 bool verboseShutdown;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080084
85 bool jdwpAllowed; // debugging allowed for this process?
86 bool jdwpConfigured; // has debugging info been provided?
87 int jdwpTransport;
88 bool jdwpServer;
89 char* jdwpHost;
90 int jdwpPort;
91 bool jdwpSuspend;
92
93 int (*vfprintfHook)(FILE*, const char*, va_list);
94 void (*exitHook)(int);
95 void (*abortHook)(void);
96
97 int jniGrefLimit; // 0 means no limit
98 bool reduceSignals;
99 bool noQuitHandler;
100 bool verifyDexChecksum;
101 char* stackTraceFile; // for SIGQUIT-inspired output
102
103 bool logStdio;
104
105 DexOptimizerMode dexOptMode;
106 DexClassVerifyMode classVerifyMode;
The Android Open Source Project99409882009-03-18 22:20:24 -0700107 bool preciseGc;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800108 bool generateRegisterMaps;
109
110 int assertionCtrlCount;
111 AssertionControl* assertionCtrl;
112
113 ExecutionMode executionMode;
114
115 /*
116 * VM init management.
117 */
118 bool initializing;
119 int initExceptionCount;
120 bool optimizing;
121
122 /*
123 * java.lang.System properties set from the command line.
124 */
125 int numProps;
126 int maxProps;
127 char** propList;
128
129 /*
130 * Where the VM goes to find system classes.
131 */
132 ClassPathEntry* bootClassPath;
133 /* used by the DEX optimizer to load classes from an unfinished DEX */
134 DvmDex* bootClassPathOptExtra;
135 bool optimizingBootstrapClass;
136
137 /*
138 * Loaded classes, hashed by class name. Each entry is a ClassObject*,
139 * allocated in GC space.
140 */
141 HashTable* loadedClasses;
142
143 /*
144 * Value for the next class serial number to be assigned. This is
145 * incremented as we load classes. Failed loads and races may result
146 * in some numbers being skipped, and the serial number is not
147 * guaranteed to start at 1, so the current value should not be used
148 * as a count of loaded classes.
149 */
150 volatile int classSerialNumber;
151
152 /*
Barry Hayes2c987472009-04-06 10:03:48 -0700153 * Classes with a low classSerialNumber are probably in the zygote, and
154 * their InitiatingLoaderList is not used, to promote sharing. The list is
155 * kept here instead.
156 */
157 InitiatingLoaderList* initiatingLoaderList;
158
159 /*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800160 * Interned strings.
161 */
162 HashTable* internedStrings;
163
164 /*
165 * Quick lookups for popular classes used internally.
166 */
167 ClassObject* unlinkedJavaLangClass; // see unlinkedJavaLangClassObject
168 ClassObject* classJavaLangClass;
169 ClassObject* classJavaLangClassArray;
170 ClassObject* classJavaLangError;
171 ClassObject* classJavaLangObject;
172 ClassObject* classJavaLangObjectArray;
173 ClassObject* classJavaLangRuntimeException;
174 ClassObject* classJavaLangString;
175 ClassObject* classJavaLangThread;
176 ClassObject* classJavaLangVMThread;
177 ClassObject* classJavaLangThreadGroup;
178 ClassObject* classJavaLangThrowable;
Andy McFadden4fbba1f2010-02-03 07:21:14 -0800179 ClassObject* classJavaLangStackOverflowError;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800180 ClassObject* classJavaLangStackTraceElement;
181 ClassObject* classJavaLangStackTraceElementArray;
182 ClassObject* classJavaLangAnnotationAnnotationArray;
183 ClassObject* classJavaLangAnnotationAnnotationArrayArray;
184 ClassObject* classJavaLangReflectAccessibleObject;
185 ClassObject* classJavaLangReflectConstructor;
186 ClassObject* classJavaLangReflectConstructorArray;
187 ClassObject* classJavaLangReflectField;
188 ClassObject* classJavaLangReflectFieldArray;
189 ClassObject* classJavaLangReflectMethod;
190 ClassObject* classJavaLangReflectMethodArray;
191 ClassObject* classJavaLangReflectProxy;
192 ClassObject* classJavaLangExceptionInInitializerError;
Andy McFaddenb18992f2009-09-25 10:42:15 -0700193 ClassObject* classJavaLangRefPhantomReference;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800194 ClassObject* classJavaLangRefReference;
Andy McFadden8e5c7842009-07-23 17:47:18 -0700195 ClassObject* classJavaNioReadWriteDirectByteBuffer;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800196 ClassObject* classJavaSecurityAccessController;
197 ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationFactory;
198 ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMember;
199 ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMemberArray;
Andy McFadden5f612b82009-07-22 15:07:27 -0700200 ClassObject* classOrgApacheHarmonyNioInternalDirectBuffer;
Andy McFaddend5ab7262009-08-25 07:19:34 -0700201 jclass jclassOrgApacheHarmonyNioInternalDirectBuffer;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800202
203 /* synthetic classes for arrays of primitives */
204 ClassObject* classArrayBoolean;
205 ClassObject* classArrayChar;
206 ClassObject* classArrayFloat;
207 ClassObject* classArrayDouble;
208 ClassObject* classArrayByte;
209 ClassObject* classArrayShort;
210 ClassObject* classArrayInt;
211 ClassObject* classArrayLong;
212
213 /* method offsets - Object */
214 int voffJavaLangObject_equals;
215 int voffJavaLangObject_hashCode;
216 int voffJavaLangObject_toString;
217 int voffJavaLangObject_finalize;
218
219 /* field offsets - Class */
220 int offJavaLangClass_pd;
221
222 /* field offsets - String */
223 volatile int javaLangStringReady; /* 0=not init, 1=ready, -1=initing */
224 int offJavaLangString_value;
225 int offJavaLangString_count;
226 int offJavaLangString_offset;
227 int offJavaLangString_hashCode;
228
229 /* field offsets - Thread */
230 int offJavaLangThread_vmThread;
231 int offJavaLangThread_group;
232 int offJavaLangThread_daemon;
233 int offJavaLangThread_name;
234 int offJavaLangThread_priority;
235
236 /* method offsets - Thread */
237 int voffJavaLangThread_run;
238
239 /* field offsets - VMThread */
240 int offJavaLangVMThread_thread;
241 int offJavaLangVMThread_vmData;
242
243 /* method offsets - ThreadGroup */
244 int voffJavaLangThreadGroup_removeThread;
245
246 /* field offsets - Throwable */
247 int offJavaLangThrowable_stackState;
248 int offJavaLangThrowable_message;
249 int offJavaLangThrowable_cause;
250
251 /* field offsets - java.lang.reflect.* */
252 int offJavaLangReflectAccessibleObject_flag;
253 int offJavaLangReflectConstructor_slot;
254 int offJavaLangReflectConstructor_declClass;
255 int offJavaLangReflectField_slot;
256 int offJavaLangReflectField_declClass;
257 int offJavaLangReflectMethod_slot;
258 int offJavaLangReflectMethod_declClass;
259
260 /* field offsets - java.lang.ref.Reference */
261 int offJavaLangRefReference_referent;
262 int offJavaLangRefReference_queue;
263 int offJavaLangRefReference_queueNext;
264 int offJavaLangRefReference_vmData;
265
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800266 /* method pointers - java.lang.ref.Reference */
267 Method* methJavaLangRefReference_enqueueInternal;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800268
269 /* field offsets - java.nio.Buffer and java.nio.DirectByteBufferImpl */
270 //int offJavaNioBuffer_capacity;
271 //int offJavaNioDirectByteBufferImpl_pointer;
272
273 /* method pointers - java.security.AccessController */
274 volatile bool javaSecurityAccessControllerReady;
275 Method* methJavaSecurityAccessController_doPrivileged[4];
276
277 /* constructor method pointers; no vtable involved, so use Method* */
278 Method* methJavaLangStackTraceElement_init;
279 Method* methJavaLangExceptionInInitializerError_init;
Andy McFaddenb18992f2009-09-25 10:42:15 -0700280 Method* methJavaLangRefPhantomReference_init;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800281 Method* methJavaLangReflectConstructor_init;
282 Method* methJavaLangReflectField_init;
283 Method* methJavaLangReflectMethod_init;
284 Method* methOrgApacheHarmonyLangAnnotationAnnotationMember_init;
285
286 /* static method pointers - android.lang.annotation.* */
287 Method*
288 methOrgApacheHarmonyLangAnnotationAnnotationFactory_createAnnotation;
289
290 /* direct method pointers - java.lang.reflect.Proxy */
291 Method* methJavaLangReflectProxy_constructorPrototype;
292
293 /* field offsets - java.lang.reflect.Proxy */
294 int offJavaLangReflectProxy_h;
295
296 /* fake native entry point method */
297 Method* methFakeNativeEntry;
298
Andy McFadden8e5c7842009-07-23 17:47:18 -0700299 /* assorted direct buffer helpers */
300 Method* methJavaNioReadWriteDirectByteBuffer_init;
301 Method* methOrgApacheHarmonyLuniPlatformPlatformAddress_on;
Andy McFadden5f612b82009-07-22 15:07:27 -0700302 Method* methOrgApacheHarmonyNioInternalDirectBuffer_getEffectiveAddress;
Andy McFadden8e5c7842009-07-23 17:47:18 -0700303 int offJavaNioBuffer_capacity;
Andy McFadden8e696dc2009-07-24 15:28:16 -0700304 int offJavaNioBuffer_effectiveDirectAddress;
Andy McFadden8e5c7842009-07-23 17:47:18 -0700305 int offOrgApacheHarmonyLuniPlatformPlatformAddress_osaddr;
306 int voffOrgApacheHarmonyLuniPlatformPlatformAddress_toLong;
Andy McFadden5f612b82009-07-22 15:07:27 -0700307
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800308 /*
309 * VM-synthesized primitive classes, for arrays.
310 */
311 ClassObject* volatile primitiveClass[PRIM_MAX];
312
313 /*
314 * A placeholder ClassObject used during ClassObject
315 * construction.
316 */
317 ClassObject unlinkedJavaLangClassObject;
318
319 /*
320 * Thread list. This always has at least one element in it (main),
321 * and main is always the first entry.
322 *
323 * The threadListLock is used for several things, including the thread
324 * start condition variable. Generally speaking, you must hold the
325 * threadListLock when:
326 * - adding/removing items from the list
327 * - waiting on or signaling threadStartCond
328 * - examining the Thread struct for another thread (this is to avoid
329 * one thread freeing the Thread struct while another thread is
330 * perusing it)
331 */
332 Thread* threadList;
333 pthread_mutex_t threadListLock;
334
335 pthread_cond_t threadStartCond;
336
337 /*
338 * The thread code grabs this before suspending all threads. There
Andy McFadden2aa43612009-06-17 16:29:30 -0700339 * are a few things that can cause a "suspend all":
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800340 * (1) the GC is starting;
341 * (2) the debugger has sent a "suspend all" request;
342 * (3) a thread has hit a breakpoint or exception that the debugger
343 * has marked as a "suspend all" event;
344 * (4) the SignalCatcher caught a signal that requires suspension.
Ben Chengba4fc8b2009-06-01 13:00:29 -0700345 * (5) (if implemented) the JIT needs to perform a heavyweight
346 * rearrangement of the translation cache or JitTable.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800347 *
348 * Because we use "safe point" self-suspension, it is never safe to
349 * do a blocking "lock" call on this mutex -- if it has been acquired,
350 * somebody is probably trying to put you to sleep. The leading '_' is
351 * intended as a reminder that this lock is special.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800352 */
353 pthread_mutex_t _threadSuspendLock;
354
355 /*
356 * Guards Thread->suspendCount for all threads, and provides the lock
357 * for the condition variable that all suspended threads sleep on
358 * (threadSuspendCountCond).
359 *
360 * This has to be separate from threadListLock because of the way
361 * threads put themselves to sleep.
362 */
363 pthread_mutex_t threadSuspendCountLock;
364
365 /*
366 * Suspended threads sleep on this. They should sleep on the condition
367 * variable until their "suspend count" is zero.
368 *
369 * Paired with "threadSuspendCountLock".
370 */
371 pthread_cond_t threadSuspendCountCond;
372
373 /*
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700374 * Sum of all threads' suspendCount fields. The JIT needs to know if any
375 * thread is suspended. Guarded by threadSuspendCountLock.
376 */
377 int sumThreadSuspendCount;
378
379 /*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800380 * MUTEX ORDERING: when locking multiple mutexes, always grab them in
381 * this order to avoid deadlock:
382 *
383 * (1) _threadSuspendLock (use lockThreadSuspend())
384 * (2) threadListLock (use dvmLockThreadList())
385 * (3) threadSuspendCountLock (use lockThreadSuspendCount())
386 */
387
388
389 /*
390 * Thread ID bitmap. We want threads to have small integer IDs so
391 * we can use them in "thin locks".
392 */
393 BitVector* threadIdMap;
394
395 /*
396 * Manage exit conditions. The VM exits when all non-daemon threads
397 * have exited. If the main thread returns early, we need to sleep
398 * on a condition variable.
399 */
400 int nonDaemonThreadCount; /* must hold threadListLock to access */
401 //pthread_mutex_t vmExitLock;
402 pthread_cond_t vmExitCond;
403
404 /*
405 * The set of DEX files loaded by custom class loaders.
406 */
407 HashTable* userDexFiles;
408
409 /*
410 * JNI global reference table.
411 */
Andy McFaddend5ab7262009-08-25 07:19:34 -0700412#ifdef USE_INDIRECT_REF
413 IndirectRefTable jniGlobalRefTable;
414#else
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800415 ReferenceTable jniGlobalRefTable;
Andy McFaddend5ab7262009-08-25 07:19:34 -0700416#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800417 pthread_mutex_t jniGlobalRefLock;
418 int jniGlobalRefHiMark;
419 int jniGlobalRefLoMark;
420
421 /*
Andy McFaddenc26bb632009-08-21 12:01:31 -0700422 * JNI pinned object table (used for primitive arrays).
423 */
424 ReferenceTable jniPinRefTable;
425 pthread_mutex_t jniPinRefLock;
426
Andy McFaddenb18992f2009-09-25 10:42:15 -0700427 /* special ReferenceQueue for JNI weak globals */
428 Object* jniWeakGlobalRefQueue;
429
Andy McFaddenc26bb632009-08-21 12:01:31 -0700430 /*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800431 * Native shared library table.
432 */
433 HashTable* nativeLibs;
434
435 /*
436 * GC heap lock. Functions like gcMalloc() acquire this before making
437 * any changes to the heap. It is held throughout garbage collection.
438 */
439 pthread_mutex_t gcHeapLock;
440
441 /* Opaque pointer representing the heap. */
442 GcHeap* gcHeap;
443
444 /*
Andy McFadden7fc3ce82009-07-14 15:57:23 -0700445 * Pre-allocated throwables.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800446 */
447 Object* outOfMemoryObj;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800448 Object* internalErrorObj;
Andy McFadden7fc3ce82009-07-14 15:57:23 -0700449 Object* noClassDefFoundErrorObj;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800450
451 /* Monitor list, so we can free them */
452 /*volatile*/ Monitor* monitorList;
453
454 /* Monitor for Thread.sleep() implementation */
455 Monitor* threadSleepMon;
456
457 /* set when we create a second heap inside the zygote */
458 bool newZygoteHeapAllocated;
459
460 /*
461 * TLS keys.
462 */
463 pthread_key_t pthreadKeySelf; /* Thread*, for dvmThreadSelf */
464
465 /*
466 * JNI allows you to have multiple VMs, but we limit ourselves to 1,
467 * so "vmList" is really just a pointer to the one and only VM.
468 */
469 JavaVM* vmList;
470
471 /*
472 * Cache results of "A instanceof B".
473 */
474 AtomicCache* instanceofCache;
475
476 /* instruction width table, used for optimization and verification */
477 InstructionWidth* instrWidth;
478 /* instruction flags table, used for verification */
479 InstructionFlags* instrFlags;
480 /* instruction format table, used for verification */
481 InstructionFormat* instrFormat;
482
483 /*
484 * Bootstrap class loader linear allocator.
485 */
486 LinearAllocHdr* pBootLoaderAlloc;
487
488
489 /*
490 * Heap worker thread.
491 */
492 bool heapWorkerInitialized;
493 bool heapWorkerReady;
494 bool haltHeapWorker;
495 pthread_t heapWorkerHandle;
496 pthread_mutex_t heapWorkerLock;
497 pthread_cond_t heapWorkerCond;
498 pthread_cond_t heapWorkerIdleCond;
499 pthread_mutex_t heapWorkerListLock;
500
501 /*
502 * Compute some stats on loaded classes.
503 */
The Android Open Source Project99409882009-03-18 22:20:24 -0700504 int numLoadedClasses;
505 int numDeclaredMethods;
506 int numDeclaredInstFields;
507 int numDeclaredStaticFields;
508
509 /* when using a native debugger, set this to suppress watchdog timers */
510 bool nativeDebuggerActive;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800511
512 /*
513 * JDWP debugger support.
Andy McFaddend51370f2009-08-05 15:20:27 -0700514 *
515 * Note "debuggerActive" is accessed from mterp, so its storage size and
516 * meaning must not be changed without updating the assembly sources.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800517 */
518 bool debuggerConnected; /* debugger or DDMS is connected */
Andy McFaddend51370f2009-08-05 15:20:27 -0700519 u1 debuggerActive; /* debugger is making requests */
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800520 JdwpState* jdwpState;
521
522 /*
523 * Registry of objects known to the debugger.
524 */
525 HashTable* dbgRegistry;
526
527 /*
Andy McFadden96516932009-10-28 17:39:02 -0700528 * Debugger breakpoint table.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800529 */
Andy McFadden96516932009-10-28 17:39:02 -0700530 BreakpointSet* breakpointSet;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800531
532 /*
533 * Single-step control struct. We currently only allow one thread to
534 * be single-stepping at a time, which is all that really makes sense,
535 * but it's possible we may need to expand this to be per-thread.
536 */
537 StepControl stepControl;
538
539 /*
540 * DDM features embedded in the VM.
541 */
542 bool ddmThreadNotification;
543
544 /*
545 * Zygote (partially-started process) support
546 */
547 bool zygote;
548
549 /*
550 * Used for tracking allocations that we report to DDMS. When the feature
551 * is enabled (through a DDMS request) the "allocRecords" pointer becomes
552 * non-NULL.
553 */
554 pthread_mutex_t allocTrackerLock;
555 AllocRecord* allocRecords;
556 int allocRecordHead; /* most-recently-added entry */
557 int allocRecordCount; /* #of valid entries */
558
559#ifdef WITH_ALLOC_LIMITS
560 /* set on first use of an alloc limit, never cleared */
561 bool checkAllocLimits;
562 /* allocation limit, for setGlobalAllocationLimit() regression testing */
563 int allocationLimit;
564#endif
565
566#ifdef WITH_DEADLOCK_PREDICTION
567 /* global lock on history tree accesses */
568 pthread_mutex_t deadlockHistoryLock;
569
570 enum { kDPOff=0, kDPWarn, kDPErr, kDPAbort } deadlockPredictMode;
571#endif
572
573#ifdef WITH_PROFILER
574 /*
575 * When a profiler is enabled, this is incremented. Distinct profilers
576 * include "dmtrace" method tracing, emulator method tracing, and
577 * possibly instruction counting.
578 *
579 * The purpose of this is to have a single value that the interpreter
580 * can check to see if any profiling activity is enabled.
581 */
582 volatile int activeProfilers;
583
584 /*
585 * State for method-trace profiling.
586 */
587 MethodTraceState methodTrace;
588
589 /*
590 * State for emulator tracing.
591 */
592 void* emulatorTracePage;
593 int emulatorTraceEnableCount;
594
595 /*
596 * Global state for memory allocation profiling.
597 */
598 AllocProfState allocProf;
599
600 /*
601 * Pointers to the original methods for things that have been inlined.
602 * This makes it easy for us to output method entry/exit records for
603 * the method calls we're not actually making.
604 */
605 Method** inlinedMethods;
606
607 /*
608 * Dalvik instruction counts (256 entries).
609 */
610 int* executedInstrCounts;
611 bool instructionCountEnableCount;
612#endif
613
614 /*
615 * Signal catcher thread (for SIGQUIT).
616 */
617 pthread_t signalCatcherHandle;
618 bool haltSignalCatcher;
619
620 /*
621 * Stdout/stderr conversion thread.
622 */
623 bool haltStdioConverter;
624 bool stdioConverterReady;
625 pthread_t stdioConverterHandle;
626 pthread_mutex_t stdioConverterLock;
627 pthread_cond_t stdioConverterCond;
628
629 /*
630 * pid of the system_server process. We track it so that when system server
631 * crashes the Zygote process will be killed and restarted.
632 */
633 pid_t systemServerPid;
634
San Mehat894dd462009-09-08 20:29:15 -0700635 int kernelGroupScheduling;
636
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800637//#define COUNT_PRECISE_METHODS
638#ifdef COUNT_PRECISE_METHODS
639 PointerSet* preciseMethods;
640#endif
The Android Open Source Project99409882009-03-18 22:20:24 -0700641
642 /* some RegisterMap statistics, useful during development */
643 void* registerMapStats;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800644};
645
646extern struct DvmGlobals gDvm;
647
Ben Chengba4fc8b2009-06-01 13:00:29 -0700648#if defined(WITH_JIT)
Ben Cheng38329f52009-07-07 14:19:20 -0700649
Ben Chengba4fc8b2009-06-01 13:00:29 -0700650/*
Ben Cheng6c10a972009-10-29 14:39:18 -0700651 * Exiting the compiled code w/o chaining will incur overhead to look up the
652 * target in the code cache which is extra work only when JIT is enabled. So
653 * we want to monitor it closely to make sure we don't have performance bugs.
654 */
655typedef enum NoChainExits {
656 kInlineCacheMiss = 0,
657 kCallsiteInterpreted,
658 kSwitchOverflow,
Bill Buzbeeeb695c62010-02-04 16:09:55 -0800659 kHeavyweightMonitor,
Ben Cheng6c10a972009-10-29 14:39:18 -0700660 kNoChainExitLast,
661} NoChainExits;
662
663/*
Ben Chengba4fc8b2009-06-01 13:00:29 -0700664 * JIT-specific global state
665 */
666struct DvmJitGlobals {
667 /*
668 * Guards writes to Dalvik PC (dPC), translated code address (codeAddr) and
669 * chain fields within the JIT hash table. Note carefully the access
670 * mechanism.
671 * Only writes are guarded, and the guarded fields must be updated in a
672 * specific order using atomic operations. Further, once a field is
673 * written it cannot be changed without halting all threads.
674 *
675 * The write order is:
676 * 1) codeAddr
677 * 2) dPC
678 * 3) chain [if necessary]
679 *
680 * This mutex also guards both read and write of curJitTableEntries.
681 */
682 pthread_mutex_t tableLock;
683
684 /* The JIT hash table. Note that for access speed, copies of this pointer
685 * are stored in each thread. */
686 struct JitEntry *pJitEntryTable;
687
688 /* Array of profile threshold counters */
689 unsigned char *pProfTable;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700690
Bill Buzbee06bb8392010-01-31 18:53:15 -0800691 /* Copy of pProfTable used for temporarily disabling the Jit */
692 unsigned char *pProfTableCopy;
693
Ben Chengba4fc8b2009-06-01 13:00:29 -0700694 /* Size of JIT hash table in entries. Must be a power of 2 */
Bill Buzbee27176222009-06-09 09:20:16 -0700695 unsigned int jitTableSize;
696
697 /* Mask used in hash function for JitTable. Should be jitTableSize-1 */
698 unsigned int jitTableMask;
699
700 /* How many entries in the JitEntryTable are in use */
701 unsigned int jitTableEntriesUsed;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700702
Ben Cheng7b133ef2010-02-04 16:15:59 -0800703 /* Bytes allocated for the code cache */
704 unsigned int codeCacheSize;
705
Ben Chengba4fc8b2009-06-01 13:00:29 -0700706 /* Trigger for trace selection */
707 unsigned short threshold;
708
709 /* JIT Compiler Control */
710 bool haltCompilerThread;
711 bool blockingMode;
712 pthread_t compilerHandle;
713 pthread_mutex_t compilerLock;
Ben Cheng6999d842010-01-26 16:46:15 -0800714 pthread_mutex_t compilerICPatchLock;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700715 pthread_cond_t compilerQueueActivity;
716 pthread_cond_t compilerQueueEmpty;
717 int compilerQueueLength;
718 int compilerHighWater;
719 int compilerWorkEnqueueIndex;
720 int compilerWorkDequeueIndex;
Ben Cheng6999d842010-01-26 16:46:15 -0800721 int compilerICPatchIndex;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700722
723 /* JIT internal stats */
724 int compilerMaxQueued;
725 int addrLookupsFound;
726 int addrLookupsNotFound;
Ben Cheng6c10a972009-10-29 14:39:18 -0700727 int noChainExit[kNoChainExitLast];
Ben Chengba4fc8b2009-06-01 13:00:29 -0700728 int normalExit;
729 int puntExit;
730 int translationChains;
Ben Cheng38329f52009-07-07 14:19:20 -0700731 int invokeChain;
732 int invokePredictedChain;
733 int invokeNative;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700734 int returnOp;
735
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 Cheng7a0bcd02010-01-22 16:45:45 -0800751 /* Number of times that the code cache has been reset */
752 int numCodeCacheReset;
753
Ben Cheng6999d842010-01-26 16:46:15 -0800754 /* Number of times that the code cache reset request has been delayed */
755 int numCodeCacheResetDelayed;
756
Ben Chengba4fc8b2009-06-01 13:00:29 -0700757 /* true/false: compile/reject opcodes specified in the -Xjitop list */
758 bool includeSelectedOp;
759
760 /* true/false: compile/reject methods specified in the -Xjitmethod list */
761 bool includeSelectedMethod;
762
763 /* Disable JIT for selected opcodes - one bit for each opcode */
764 char opList[32];
765
766 /* Disable JIT for selected methods */
767 HashTable *methodTable;
768
Ben Chengba4fc8b2009-06-01 13:00:29 -0700769 /* Flag to dump all compiled code */
770 bool printMe;
Bill Buzbee6e963e12009-06-17 16:56:19 -0700771
772 /* Flag to count trace execution */
773 bool profile;
Ben Cheng8b258bf2009-06-24 17:27:07 -0700774
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700775 /* Vector to disable selected optimizations */
776 int disableOpt;
777
Bill Buzbee9a8c75a2009-11-08 14:31:20 -0800778 /* Code address of special interpret-only pseudo-translation */
779 void *interpretTemplate;
780
Ben Cheng8b258bf2009-06-24 17:27:07 -0700781 /* Table to track the overall and trace statistics of hot methods */
782 HashTable* methodStatsTable;
Ben Chengbcdc1de2009-08-21 16:18:46 -0700783
Ben Cheng33672452010-01-12 14:59:30 -0800784 /* Filter method compilation blacklist with call-graph information */
785 bool checkCallGraph;
786
Ben Cheng6999d842010-01-26 16:46:15 -0800787 /* New translation chain has been set up */
788 volatile bool hasNewChain;
789
Ben Chengbcdc1de2009-08-21 16:18:46 -0700790#if defined(WITH_SELF_VERIFICATION)
791 /* Spin when error is detected, volatile so GDB can reset it */
792 volatile bool selfVerificationSpin;
793#endif
Ben Cheng6999d842010-01-26 16:46:15 -0800794
Bill Buzbeeeb695c62010-02-04 16:09:55 -0800795 /* Framework or stand-alone? */
796 bool runningInAndroidFramework;
797
Ben Cheng6999d842010-01-26 16:46:15 -0800798 /* Place arrays at the end to ease the display in gdb sessions */
799
800 /* Work order queue for compilations */
801 CompilerWorkOrder compilerWorkQueue[COMPILER_WORK_QUEUE_SIZE];
802
803 /* Work order queue for predicted chain patching */
804 ICPatchWorkOrder compilerICPatchQueue[COMPILER_IC_PATCH_QUEUE_SIZE];
Ben Chengba4fc8b2009-06-01 13:00:29 -0700805};
806
807extern struct DvmJitGlobals gDvmJit;
808
809#endif
810
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800811#endif /*_DALVIK_GLOBALS*/