blob: 6d6f3b62e4e756174a1b4c5605c2dc3039c47f16 [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
Carl Shapiro6b4ba582010-04-09 15:03:33 -070093 u4 lockProfThreshold;
94 u4 lockProfSample;
95
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080096 int (*vfprintfHook)(FILE*, const char*, va_list);
97 void (*exitHook)(int);
98 void (*abortHook)(void);
99
100 int jniGrefLimit; // 0 means no limit
101 bool reduceSignals;
102 bool noQuitHandler;
103 bool verifyDexChecksum;
104 char* stackTraceFile; // for SIGQUIT-inspired output
105
106 bool logStdio;
107
108 DexOptimizerMode dexOptMode;
109 DexClassVerifyMode classVerifyMode;
The Android Open Source Project99409882009-03-18 22:20:24 -0700110 bool preciseGc;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800111 bool generateRegisterMaps;
112
113 int assertionCtrlCount;
114 AssertionControl* assertionCtrl;
115
116 ExecutionMode executionMode;
117
118 /*
119 * VM init management.
120 */
121 bool initializing;
122 int initExceptionCount;
123 bool optimizing;
124
125 /*
126 * java.lang.System properties set from the command line.
127 */
128 int numProps;
129 int maxProps;
130 char** propList;
131
132 /*
133 * Where the VM goes to find system classes.
134 */
135 ClassPathEntry* bootClassPath;
136 /* used by the DEX optimizer to load classes from an unfinished DEX */
137 DvmDex* bootClassPathOptExtra;
138 bool optimizingBootstrapClass;
139
140 /*
141 * Loaded classes, hashed by class name. Each entry is a ClassObject*,
142 * allocated in GC space.
143 */
144 HashTable* loadedClasses;
145
146 /*
147 * Value for the next class serial number to be assigned. This is
148 * incremented as we load classes. Failed loads and races may result
149 * in some numbers being skipped, and the serial number is not
150 * guaranteed to start at 1, so the current value should not be used
151 * as a count of loaded classes.
152 */
153 volatile int classSerialNumber;
154
155 /*
Barry Hayes2c987472009-04-06 10:03:48 -0700156 * Classes with a low classSerialNumber are probably in the zygote, and
157 * their InitiatingLoaderList is not used, to promote sharing. The list is
158 * kept here instead.
159 */
160 InitiatingLoaderList* initiatingLoaderList;
161
162 /*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800163 * Interned strings.
164 */
165 HashTable* internedStrings;
166
167 /*
168 * Quick lookups for popular classes used internally.
169 */
170 ClassObject* unlinkedJavaLangClass; // see unlinkedJavaLangClassObject
171 ClassObject* classJavaLangClass;
172 ClassObject* classJavaLangClassArray;
173 ClassObject* classJavaLangError;
174 ClassObject* classJavaLangObject;
175 ClassObject* classJavaLangObjectArray;
176 ClassObject* classJavaLangRuntimeException;
177 ClassObject* classJavaLangString;
178 ClassObject* classJavaLangThread;
179 ClassObject* classJavaLangVMThread;
180 ClassObject* classJavaLangThreadGroup;
181 ClassObject* classJavaLangThrowable;
Andy McFadden4fbba1f2010-02-03 07:21:14 -0800182 ClassObject* classJavaLangStackOverflowError;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800183 ClassObject* classJavaLangStackTraceElement;
184 ClassObject* classJavaLangStackTraceElementArray;
185 ClassObject* classJavaLangAnnotationAnnotationArray;
186 ClassObject* classJavaLangAnnotationAnnotationArrayArray;
187 ClassObject* classJavaLangReflectAccessibleObject;
188 ClassObject* classJavaLangReflectConstructor;
189 ClassObject* classJavaLangReflectConstructorArray;
190 ClassObject* classJavaLangReflectField;
191 ClassObject* classJavaLangReflectFieldArray;
192 ClassObject* classJavaLangReflectMethod;
193 ClassObject* classJavaLangReflectMethodArray;
194 ClassObject* classJavaLangReflectProxy;
195 ClassObject* classJavaLangExceptionInInitializerError;
Andy McFaddenb18992f2009-09-25 10:42:15 -0700196 ClassObject* classJavaLangRefPhantomReference;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800197 ClassObject* classJavaLangRefReference;
Andy McFadden8e5c7842009-07-23 17:47:18 -0700198 ClassObject* classJavaNioReadWriteDirectByteBuffer;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800199 ClassObject* classJavaSecurityAccessController;
200 ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationFactory;
201 ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMember;
202 ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMemberArray;
Andy McFadden5f612b82009-07-22 15:07:27 -0700203 ClassObject* classOrgApacheHarmonyNioInternalDirectBuffer;
Andy McFaddend5ab7262009-08-25 07:19:34 -0700204 jclass jclassOrgApacheHarmonyNioInternalDirectBuffer;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800205
206 /* synthetic classes for arrays of primitives */
207 ClassObject* classArrayBoolean;
208 ClassObject* classArrayChar;
209 ClassObject* classArrayFloat;
210 ClassObject* classArrayDouble;
211 ClassObject* classArrayByte;
212 ClassObject* classArrayShort;
213 ClassObject* classArrayInt;
214 ClassObject* classArrayLong;
215
216 /* method offsets - Object */
217 int voffJavaLangObject_equals;
218 int voffJavaLangObject_hashCode;
219 int voffJavaLangObject_toString;
220 int voffJavaLangObject_finalize;
221
222 /* field offsets - Class */
223 int offJavaLangClass_pd;
224
225 /* field offsets - String */
226 volatile int javaLangStringReady; /* 0=not init, 1=ready, -1=initing */
227 int offJavaLangString_value;
228 int offJavaLangString_count;
229 int offJavaLangString_offset;
230 int offJavaLangString_hashCode;
231
232 /* field offsets - Thread */
233 int offJavaLangThread_vmThread;
234 int offJavaLangThread_group;
235 int offJavaLangThread_daemon;
236 int offJavaLangThread_name;
237 int offJavaLangThread_priority;
238
239 /* method offsets - Thread */
240 int voffJavaLangThread_run;
241
242 /* field offsets - VMThread */
243 int offJavaLangVMThread_thread;
244 int offJavaLangVMThread_vmData;
245
246 /* method offsets - ThreadGroup */
247 int voffJavaLangThreadGroup_removeThread;
248
249 /* field offsets - Throwable */
250 int offJavaLangThrowable_stackState;
251 int offJavaLangThrowable_message;
252 int offJavaLangThrowable_cause;
253
254 /* field offsets - java.lang.reflect.* */
255 int offJavaLangReflectAccessibleObject_flag;
256 int offJavaLangReflectConstructor_slot;
257 int offJavaLangReflectConstructor_declClass;
258 int offJavaLangReflectField_slot;
259 int offJavaLangReflectField_declClass;
260 int offJavaLangReflectMethod_slot;
261 int offJavaLangReflectMethod_declClass;
262
263 /* field offsets - java.lang.ref.Reference */
264 int offJavaLangRefReference_referent;
265 int offJavaLangRefReference_queue;
266 int offJavaLangRefReference_queueNext;
267 int offJavaLangRefReference_vmData;
268
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800269 /* method pointers - java.lang.ref.Reference */
270 Method* methJavaLangRefReference_enqueueInternal;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800271
272 /* field offsets - java.nio.Buffer and java.nio.DirectByteBufferImpl */
273 //int offJavaNioBuffer_capacity;
274 //int offJavaNioDirectByteBufferImpl_pointer;
275
276 /* method pointers - java.security.AccessController */
277 volatile bool javaSecurityAccessControllerReady;
278 Method* methJavaSecurityAccessController_doPrivileged[4];
279
280 /* constructor method pointers; no vtable involved, so use Method* */
281 Method* methJavaLangStackTraceElement_init;
282 Method* methJavaLangExceptionInInitializerError_init;
Andy McFaddenb18992f2009-09-25 10:42:15 -0700283 Method* methJavaLangRefPhantomReference_init;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800284 Method* methJavaLangReflectConstructor_init;
285 Method* methJavaLangReflectField_init;
286 Method* methJavaLangReflectMethod_init;
287 Method* methOrgApacheHarmonyLangAnnotationAnnotationMember_init;
288
289 /* static method pointers - android.lang.annotation.* */
290 Method*
291 methOrgApacheHarmonyLangAnnotationAnnotationFactory_createAnnotation;
292
293 /* direct method pointers - java.lang.reflect.Proxy */
294 Method* methJavaLangReflectProxy_constructorPrototype;
295
296 /* field offsets - java.lang.reflect.Proxy */
297 int offJavaLangReflectProxy_h;
298
299 /* fake native entry point method */
300 Method* methFakeNativeEntry;
301
Andy McFadden8e5c7842009-07-23 17:47:18 -0700302 /* assorted direct buffer helpers */
303 Method* methJavaNioReadWriteDirectByteBuffer_init;
304 Method* methOrgApacheHarmonyLuniPlatformPlatformAddress_on;
Andy McFadden5f612b82009-07-22 15:07:27 -0700305 Method* methOrgApacheHarmonyNioInternalDirectBuffer_getEffectiveAddress;
Andy McFadden8e5c7842009-07-23 17:47:18 -0700306 int offJavaNioBuffer_capacity;
Andy McFadden8e696dc2009-07-24 15:28:16 -0700307 int offJavaNioBuffer_effectiveDirectAddress;
Andy McFadden8e5c7842009-07-23 17:47:18 -0700308 int offOrgApacheHarmonyLuniPlatformPlatformAddress_osaddr;
309 int voffOrgApacheHarmonyLuniPlatformPlatformAddress_toLong;
Andy McFadden5f612b82009-07-22 15:07:27 -0700310
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800311 /*
312 * VM-synthesized primitive classes, for arrays.
313 */
314 ClassObject* volatile primitiveClass[PRIM_MAX];
315
316 /*
317 * A placeholder ClassObject used during ClassObject
318 * construction.
319 */
320 ClassObject unlinkedJavaLangClassObject;
321
322 /*
323 * Thread list. This always has at least one element in it (main),
324 * and main is always the first entry.
325 *
326 * The threadListLock is used for several things, including the thread
327 * start condition variable. Generally speaking, you must hold the
328 * threadListLock when:
329 * - adding/removing items from the list
330 * - waiting on or signaling threadStartCond
331 * - examining the Thread struct for another thread (this is to avoid
332 * one thread freeing the Thread struct while another thread is
333 * perusing it)
334 */
335 Thread* threadList;
336 pthread_mutex_t threadListLock;
337
338 pthread_cond_t threadStartCond;
339
340 /*
341 * The thread code grabs this before suspending all threads. There
Andy McFadden2aa43612009-06-17 16:29:30 -0700342 * are a few things that can cause a "suspend all":
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800343 * (1) the GC is starting;
344 * (2) the debugger has sent a "suspend all" request;
345 * (3) a thread has hit a breakpoint or exception that the debugger
346 * has marked as a "suspend all" event;
347 * (4) the SignalCatcher caught a signal that requires suspension.
Ben Chengba4fc8b2009-06-01 13:00:29 -0700348 * (5) (if implemented) the JIT needs to perform a heavyweight
349 * rearrangement of the translation cache or JitTable.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800350 *
351 * Because we use "safe point" self-suspension, it is never safe to
352 * do a blocking "lock" call on this mutex -- if it has been acquired,
353 * somebody is probably trying to put you to sleep. The leading '_' is
354 * intended as a reminder that this lock is special.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800355 */
356 pthread_mutex_t _threadSuspendLock;
357
358 /*
359 * Guards Thread->suspendCount for all threads, and provides the lock
360 * for the condition variable that all suspended threads sleep on
361 * (threadSuspendCountCond).
362 *
363 * This has to be separate from threadListLock because of the way
364 * threads put themselves to sleep.
365 */
366 pthread_mutex_t threadSuspendCountLock;
367
368 /*
369 * Suspended threads sleep on this. They should sleep on the condition
370 * variable until their "suspend count" is zero.
371 *
372 * Paired with "threadSuspendCountLock".
373 */
374 pthread_cond_t threadSuspendCountCond;
375
376 /*
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700377 * Sum of all threads' suspendCount fields. The JIT needs to know if any
378 * thread is suspended. Guarded by threadSuspendCountLock.
379 */
380 int sumThreadSuspendCount;
381
382 /*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800383 * MUTEX ORDERING: when locking multiple mutexes, always grab them in
384 * this order to avoid deadlock:
385 *
386 * (1) _threadSuspendLock (use lockThreadSuspend())
387 * (2) threadListLock (use dvmLockThreadList())
388 * (3) threadSuspendCountLock (use lockThreadSuspendCount())
389 */
390
391
392 /*
393 * Thread ID bitmap. We want threads to have small integer IDs so
394 * we can use them in "thin locks".
395 */
396 BitVector* threadIdMap;
397
398 /*
399 * Manage exit conditions. The VM exits when all non-daemon threads
400 * have exited. If the main thread returns early, we need to sleep
401 * on a condition variable.
402 */
403 int nonDaemonThreadCount; /* must hold threadListLock to access */
404 //pthread_mutex_t vmExitLock;
405 pthread_cond_t vmExitCond;
406
407 /*
408 * The set of DEX files loaded by custom class loaders.
409 */
410 HashTable* userDexFiles;
411
412 /*
413 * JNI global reference table.
414 */
Andy McFaddend5ab7262009-08-25 07:19:34 -0700415#ifdef USE_INDIRECT_REF
416 IndirectRefTable jniGlobalRefTable;
417#else
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800418 ReferenceTable jniGlobalRefTable;
Andy McFaddend5ab7262009-08-25 07:19:34 -0700419#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800420 pthread_mutex_t jniGlobalRefLock;
421 int jniGlobalRefHiMark;
422 int jniGlobalRefLoMark;
423
424 /*
Andy McFaddenc26bb632009-08-21 12:01:31 -0700425 * JNI pinned object table (used for primitive arrays).
426 */
427 ReferenceTable jniPinRefTable;
428 pthread_mutex_t jniPinRefLock;
429
Andy McFaddenb18992f2009-09-25 10:42:15 -0700430 /* special ReferenceQueue for JNI weak globals */
431 Object* jniWeakGlobalRefQueue;
432
Andy McFaddenc26bb632009-08-21 12:01:31 -0700433 /*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800434 * Native shared library table.
435 */
436 HashTable* nativeLibs;
437
438 /*
439 * GC heap lock. Functions like gcMalloc() acquire this before making
440 * any changes to the heap. It is held throughout garbage collection.
441 */
442 pthread_mutex_t gcHeapLock;
443
444 /* Opaque pointer representing the heap. */
445 GcHeap* gcHeap;
446
447 /*
Andy McFadden7fc3ce82009-07-14 15:57:23 -0700448 * Pre-allocated throwables.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800449 */
450 Object* outOfMemoryObj;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800451 Object* internalErrorObj;
Andy McFadden7fc3ce82009-07-14 15:57:23 -0700452 Object* noClassDefFoundErrorObj;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800453
454 /* Monitor list, so we can free them */
455 /*volatile*/ Monitor* monitorList;
456
457 /* Monitor for Thread.sleep() implementation */
458 Monitor* threadSleepMon;
459
460 /* set when we create a second heap inside the zygote */
461 bool newZygoteHeapAllocated;
462
463 /*
464 * TLS keys.
465 */
466 pthread_key_t pthreadKeySelf; /* Thread*, for dvmThreadSelf */
467
468 /*
469 * JNI allows you to have multiple VMs, but we limit ourselves to 1,
470 * so "vmList" is really just a pointer to the one and only VM.
471 */
472 JavaVM* vmList;
473
474 /*
475 * Cache results of "A instanceof B".
476 */
477 AtomicCache* instanceofCache;
478
479 /* instruction width table, used for optimization and verification */
480 InstructionWidth* instrWidth;
481 /* instruction flags table, used for verification */
482 InstructionFlags* instrFlags;
483 /* instruction format table, used for verification */
484 InstructionFormat* instrFormat;
485
486 /*
487 * Bootstrap class loader linear allocator.
488 */
489 LinearAllocHdr* pBootLoaderAlloc;
490
491
492 /*
493 * Heap worker thread.
494 */
495 bool heapWorkerInitialized;
496 bool heapWorkerReady;
497 bool haltHeapWorker;
498 pthread_t heapWorkerHandle;
499 pthread_mutex_t heapWorkerLock;
500 pthread_cond_t heapWorkerCond;
501 pthread_cond_t heapWorkerIdleCond;
502 pthread_mutex_t heapWorkerListLock;
503
504 /*
505 * Compute some stats on loaded classes.
506 */
The Android Open Source Project99409882009-03-18 22:20:24 -0700507 int numLoadedClasses;
508 int numDeclaredMethods;
509 int numDeclaredInstFields;
510 int numDeclaredStaticFields;
511
512 /* when using a native debugger, set this to suppress watchdog timers */
513 bool nativeDebuggerActive;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800514
515 /*
516 * JDWP debugger support.
Andy McFaddend51370f2009-08-05 15:20:27 -0700517 *
518 * Note "debuggerActive" is accessed from mterp, so its storage size and
519 * meaning must not be changed without updating the assembly sources.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800520 */
521 bool debuggerConnected; /* debugger or DDMS is connected */
Andy McFaddend51370f2009-08-05 15:20:27 -0700522 u1 debuggerActive; /* debugger is making requests */
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800523 JdwpState* jdwpState;
524
525 /*
526 * Registry of objects known to the debugger.
527 */
528 HashTable* dbgRegistry;
529
530 /*
Andy McFadden96516932009-10-28 17:39:02 -0700531 * Debugger breakpoint table.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800532 */
Andy McFadden96516932009-10-28 17:39:02 -0700533 BreakpointSet* breakpointSet;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800534
535 /*
536 * Single-step control struct. We currently only allow one thread to
537 * be single-stepping at a time, which is all that really makes sense,
538 * but it's possible we may need to expand this to be per-thread.
539 */
540 StepControl stepControl;
541
542 /*
543 * DDM features embedded in the VM.
544 */
545 bool ddmThreadNotification;
546
547 /*
548 * Zygote (partially-started process) support
549 */
550 bool zygote;
551
552 /*
553 * Used for tracking allocations that we report to DDMS. When the feature
554 * is enabled (through a DDMS request) the "allocRecords" pointer becomes
555 * non-NULL.
556 */
557 pthread_mutex_t allocTrackerLock;
558 AllocRecord* allocRecords;
559 int allocRecordHead; /* most-recently-added entry */
560 int allocRecordCount; /* #of valid entries */
561
562#ifdef WITH_ALLOC_LIMITS
563 /* set on first use of an alloc limit, never cleared */
564 bool checkAllocLimits;
565 /* allocation limit, for setGlobalAllocationLimit() regression testing */
566 int allocationLimit;
567#endif
568
569#ifdef WITH_DEADLOCK_PREDICTION
570 /* global lock on history tree accesses */
571 pthread_mutex_t deadlockHistoryLock;
572
573 enum { kDPOff=0, kDPWarn, kDPErr, kDPAbort } deadlockPredictMode;
574#endif
575
576#ifdef WITH_PROFILER
577 /*
578 * When a profiler is enabled, this is incremented. Distinct profilers
579 * include "dmtrace" method tracing, emulator method tracing, and
580 * possibly instruction counting.
581 *
582 * The purpose of this is to have a single value that the interpreter
583 * can check to see if any profiling activity is enabled.
584 */
585 volatile int activeProfilers;
586
587 /*
588 * State for method-trace profiling.
589 */
590 MethodTraceState methodTrace;
591
592 /*
593 * State for emulator tracing.
594 */
595 void* emulatorTracePage;
596 int emulatorTraceEnableCount;
597
598 /*
599 * Global state for memory allocation profiling.
600 */
601 AllocProfState allocProf;
602
603 /*
604 * Pointers to the original methods for things that have been inlined.
605 * This makes it easy for us to output method entry/exit records for
606 * the method calls we're not actually making.
607 */
608 Method** inlinedMethods;
609
610 /*
611 * Dalvik instruction counts (256 entries).
612 */
613 int* executedInstrCounts;
614 bool instructionCountEnableCount;
615#endif
616
617 /*
618 * Signal catcher thread (for SIGQUIT).
619 */
620 pthread_t signalCatcherHandle;
621 bool haltSignalCatcher;
622
623 /*
624 * Stdout/stderr conversion thread.
625 */
626 bool haltStdioConverter;
627 bool stdioConverterReady;
628 pthread_t stdioConverterHandle;
629 pthread_mutex_t stdioConverterLock;
630 pthread_cond_t stdioConverterCond;
631
632 /*
633 * pid of the system_server process. We track it so that when system server
634 * crashes the Zygote process will be killed and restarted.
635 */
636 pid_t systemServerPid;
637
San Mehat894dd462009-09-08 20:29:15 -0700638 int kernelGroupScheduling;
639
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800640//#define COUNT_PRECISE_METHODS
641#ifdef COUNT_PRECISE_METHODS
642 PointerSet* preciseMethods;
643#endif
The Android Open Source Project99409882009-03-18 22:20:24 -0700644
645 /* some RegisterMap statistics, useful during development */
646 void* registerMapStats;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800647};
648
649extern struct DvmGlobals gDvm;
650
Ben Chengba4fc8b2009-06-01 13:00:29 -0700651#if defined(WITH_JIT)
Ben Cheng38329f52009-07-07 14:19:20 -0700652
Ben Chengba4fc8b2009-06-01 13:00:29 -0700653/*
Ben Cheng6c10a972009-10-29 14:39:18 -0700654 * Exiting the compiled code w/o chaining will incur overhead to look up the
655 * target in the code cache which is extra work only when JIT is enabled. So
656 * we want to monitor it closely to make sure we don't have performance bugs.
657 */
658typedef enum NoChainExits {
659 kInlineCacheMiss = 0,
660 kCallsiteInterpreted,
661 kSwitchOverflow,
Bill Buzbeeeb695c62010-02-04 16:09:55 -0800662 kHeavyweightMonitor,
Ben Cheng6c10a972009-10-29 14:39:18 -0700663 kNoChainExitLast,
664} NoChainExits;
665
666/*
Ben Chengba4fc8b2009-06-01 13:00:29 -0700667 * JIT-specific global state
668 */
669struct DvmJitGlobals {
670 /*
671 * Guards writes to Dalvik PC (dPC), translated code address (codeAddr) and
672 * chain fields within the JIT hash table. Note carefully the access
673 * mechanism.
674 * Only writes are guarded, and the guarded fields must be updated in a
675 * specific order using atomic operations. Further, once a field is
676 * written it cannot be changed without halting all threads.
677 *
678 * The write order is:
679 * 1) codeAddr
680 * 2) dPC
681 * 3) chain [if necessary]
682 *
683 * This mutex also guards both read and write of curJitTableEntries.
684 */
685 pthread_mutex_t tableLock;
686
687 /* The JIT hash table. Note that for access speed, copies of this pointer
688 * are stored in each thread. */
689 struct JitEntry *pJitEntryTable;
690
691 /* Array of profile threshold counters */
692 unsigned char *pProfTable;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700693
Bill Buzbee06bb8392010-01-31 18:53:15 -0800694 /* Copy of pProfTable used for temporarily disabling the Jit */
695 unsigned char *pProfTableCopy;
696
Ben Chengba4fc8b2009-06-01 13:00:29 -0700697 /* Size of JIT hash table in entries. Must be a power of 2 */
Bill Buzbee27176222009-06-09 09:20:16 -0700698 unsigned int jitTableSize;
699
700 /* Mask used in hash function for JitTable. Should be jitTableSize-1 */
701 unsigned int jitTableMask;
702
703 /* How many entries in the JitEntryTable are in use */
704 unsigned int jitTableEntriesUsed;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700705
Ben Cheng7b133ef2010-02-04 16:15:59 -0800706 /* Bytes allocated for the code cache */
707 unsigned int codeCacheSize;
708
Ben Chengba4fc8b2009-06-01 13:00:29 -0700709 /* Trigger for trace selection */
710 unsigned short threshold;
711
712 /* JIT Compiler Control */
713 bool haltCompilerThread;
714 bool blockingMode;
715 pthread_t compilerHandle;
716 pthread_mutex_t compilerLock;
Ben Cheng6999d842010-01-26 16:46:15 -0800717 pthread_mutex_t compilerICPatchLock;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700718 pthread_cond_t compilerQueueActivity;
719 pthread_cond_t compilerQueueEmpty;
Ben Cheng88a0f972010-02-24 15:00:40 -0800720 volatile int compilerQueueLength;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700721 int compilerHighWater;
722 int compilerWorkEnqueueIndex;
723 int compilerWorkDequeueIndex;
Ben Cheng6999d842010-01-26 16:46:15 -0800724 int compilerICPatchIndex;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700725
726 /* JIT internal stats */
727 int compilerMaxQueued;
728 int addrLookupsFound;
729 int addrLookupsNotFound;
Ben Cheng6c10a972009-10-29 14:39:18 -0700730 int noChainExit[kNoChainExitLast];
Ben Chengba4fc8b2009-06-01 13:00:29 -0700731 int normalExit;
732 int puntExit;
733 int translationChains;
Ben Cheng86717f72010-03-05 15:27:21 -0800734 int invokeMonomorphic;
735 int invokePolymorphic;
Ben Cheng38329f52009-07-07 14:19:20 -0700736 int invokeNative;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700737 int returnOp;
Ben Cheng86717f72010-03-05 15:27:21 -0800738 u8 jitTime;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700739
740 /* Compiled code cache */
741 void* codeCache;
742
Ben Cheng8b258bf2009-06-24 17:27:07 -0700743 /* Bytes used by the code templates */
744 unsigned int templateSize;
745
Ben Chengba4fc8b2009-06-01 13:00:29 -0700746 /* Bytes already used in the code cache */
747 unsigned int codeCacheByteUsed;
748
749 /* Number of installed compilations in the cache */
750 unsigned int numCompilations;
751
752 /* Flag to indicate that the code cache is full */
753 bool codeCacheFull;
754
Ben Cheng7a0bcd02010-01-22 16:45:45 -0800755 /* Number of times that the code cache has been reset */
756 int numCodeCacheReset;
757
Ben Cheng6999d842010-01-26 16:46:15 -0800758 /* Number of times that the code cache reset request has been delayed */
759 int numCodeCacheResetDelayed;
760
Ben Chengba4fc8b2009-06-01 13:00:29 -0700761 /* true/false: compile/reject opcodes specified in the -Xjitop list */
762 bool includeSelectedOp;
763
764 /* true/false: compile/reject methods specified in the -Xjitmethod list */
765 bool includeSelectedMethod;
766
767 /* Disable JIT for selected opcodes - one bit for each opcode */
768 char opList[32];
769
770 /* Disable JIT for selected methods */
771 HashTable *methodTable;
772
Ben Chengba4fc8b2009-06-01 13:00:29 -0700773 /* Flag to dump all compiled code */
774 bool printMe;
Bill Buzbee6e963e12009-06-17 16:56:19 -0700775
776 /* Flag to count trace execution */
777 bool profile;
Ben Cheng8b258bf2009-06-24 17:27:07 -0700778
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700779 /* Vector to disable selected optimizations */
780 int disableOpt;
781
Bill Buzbee9a8c75a2009-11-08 14:31:20 -0800782 /* Code address of special interpret-only pseudo-translation */
783 void *interpretTemplate;
784
Ben Cheng8b258bf2009-06-24 17:27:07 -0700785 /* Table to track the overall and trace statistics of hot methods */
786 HashTable* methodStatsTable;
Ben Chengbcdc1de2009-08-21 16:18:46 -0700787
Ben Cheng33672452010-01-12 14:59:30 -0800788 /* Filter method compilation blacklist with call-graph information */
789 bool checkCallGraph;
790
Ben Cheng6999d842010-01-26 16:46:15 -0800791 /* New translation chain has been set up */
792 volatile bool hasNewChain;
793
Ben Chengbcdc1de2009-08-21 16:18:46 -0700794#if defined(WITH_SELF_VERIFICATION)
795 /* Spin when error is detected, volatile so GDB can reset it */
796 volatile bool selfVerificationSpin;
797#endif
Ben Cheng6999d842010-01-26 16:46:15 -0800798
Bill Buzbeeeb695c62010-02-04 16:09:55 -0800799 /* Framework or stand-alone? */
800 bool runningInAndroidFramework;
801
Ben Chengf30acbb2010-02-14 16:17:36 -0800802 /* Framework callback happened? */
803 bool alreadyEnabledViaFramework;
804
805 /* Framework requests to disable the JIT for good */
806 bool disableJit;
807
Ben Chengdca71432010-03-16 16:04:11 -0700808#if defined(SIGNATURE_BREAKPOINT)
809 /* Signature breakpoint */
810 u4 signatureBreakpointSize; // # of words
811 u4 *signatureBreakpoint; // Signature content
812#endif
813
Ben Cheng6999d842010-01-26 16:46:15 -0800814 /* Place arrays at the end to ease the display in gdb sessions */
815
816 /* Work order queue for compilations */
817 CompilerWorkOrder compilerWorkQueue[COMPILER_WORK_QUEUE_SIZE];
818
819 /* Work order queue for predicted chain patching */
820 ICPatchWorkOrder compilerICPatchQueue[COMPILER_IC_PATCH_QUEUE_SIZE];
Ben Chengba4fc8b2009-06-01 13:00:29 -0700821};
822
823extern struct DvmJitGlobals gDvmJit;
824
825#endif
826
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800827#endif /*_DALVIK_GLOBALS*/