Globals.h revision ea4143449084917fb5ec25b1f3b29a1130284432
1/*
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
37/* private structures */
38typedef struct GcHeap GcHeap;
39typedef struct BreakpointSet BreakpointSet;
40typedef struct InlineSub InlineSub;
41
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,
59#if defined(WITH_JIT)
60    kExecutionModeJit,
61#endif
62} 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;
84    bool        verboseShutdown;
85
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
94    /* use wall clock as method profiler clock source? */
95    bool        profilerWallClock;
96
97    /*
98     * Lock profiling threshold value in milliseconds.  Acquires that
99     * exceed threshold are logged.  Acquires within the threshold are
100     * logged with a probability of $\frac{time}{threshold}$ .  If the
101     * threshold is unset no additional logging occurs.
102     */
103    u4          lockProfThreshold;
104
105    int         (*vfprintfHook)(FILE*, const char*, va_list);
106    void        (*exitHook)(int);
107    void        (*abortHook)(void);
108
109    int         jniGrefLimit;       // 0 means no limit
110    char*       jniTrace;
111    bool        reduceSignals;
112    bool        noQuitHandler;
113    bool        verifyDexChecksum;
114    char*       stackTraceFile;     // for SIGQUIT-inspired output
115
116    bool        logStdio;
117
118    DexOptimizerMode    dexOptMode;
119    DexClassVerifyMode  classVerifyMode;
120
121    /*
122     * GC option flags.
123     */
124    bool        preciseGc;
125    bool        preVerify;
126    bool        postVerify;
127    bool        generateRegisterMaps;
128    bool        concurrentMarkSweep;
129    bool        verifyCardTable;
130
131    int         assertionCtrlCount;
132    AssertionControl*   assertionCtrl;
133
134    ExecutionMode   executionMode;
135
136    /*
137     * VM init management.
138     */
139    bool        initializing;
140    int         initExceptionCount;
141    bool        optimizing;
142
143    /*
144     * java.lang.System properties set from the command line.
145     */
146    int         numProps;
147    int         maxProps;
148    char**      propList;
149
150    /*
151     * Where the VM goes to find system classes.
152     */
153    ClassPathEntry* bootClassPath;
154    /* used by the DEX optimizer to load classes from an unfinished DEX */
155    DvmDex*     bootClassPathOptExtra;
156    bool        optimizingBootstrapClass;
157
158    /*
159     * Loaded classes, hashed by class name.  Each entry is a ClassObject*,
160     * allocated in GC space.
161     */
162    HashTable*  loadedClasses;
163
164    /*
165     * Value for the next class serial number to be assigned.  This is
166     * incremented as we load classes.  Failed loads and races may result
167     * in some numbers being skipped, and the serial number is not
168     * guaranteed to start at 1, so the current value should not be used
169     * as a count of loaded classes.
170     */
171    volatile int classSerialNumber;
172
173    /*
174     * Classes with a low classSerialNumber are probably in the zygote, and
175     * their InitiatingLoaderList is not used, to promote sharing. The list is
176     * kept here instead.
177     */
178    InitiatingLoaderList* initiatingLoaderList;
179
180    /*
181     * Interned strings.
182     */
183
184    /* A mutex that guards access to the interned string tables. */
185    pthread_mutex_t internLock;
186
187    /* Hash table of strings interned by the user. */
188    HashTable*  internedStrings;
189
190    /* Hash table of strings interned by the class loader. */
191    HashTable*  literalStrings;
192
193    /*
194     * Quick lookups for popular classes used internally.
195     */
196    ClassObject* classJavaLangClass;
197    ClassObject* classJavaLangClassArray;
198    ClassObject* classJavaLangError;
199    ClassObject* classJavaLangObject;
200    ClassObject* classJavaLangObjectArray;
201    ClassObject* classJavaLangRuntimeException;
202    ClassObject* classJavaLangString;
203    ClassObject* classJavaLangThread;
204    ClassObject* classJavaLangVMThread;
205    ClassObject* classJavaLangThreadGroup;
206    ClassObject* classJavaLangThrowable;
207    ClassObject* classJavaLangStackOverflowError;
208    ClassObject* classJavaLangStackTraceElement;
209    ClassObject* classJavaLangStackTraceElementArray;
210    ClassObject* classJavaLangAnnotationAnnotationArray;
211    ClassObject* classJavaLangAnnotationAnnotationArrayArray;
212    ClassObject* classJavaLangReflectAccessibleObject;
213    ClassObject* classJavaLangReflectConstructor;
214    ClassObject* classJavaLangReflectConstructorArray;
215    ClassObject* classJavaLangReflectField;
216    ClassObject* classJavaLangReflectFieldArray;
217    ClassObject* classJavaLangReflectMethod;
218    ClassObject* classJavaLangReflectMethodArray;
219    ClassObject* classJavaLangReflectProxy;
220    ClassObject* classJavaLangExceptionInInitializerError;
221    ClassObject* classJavaLangRefPhantomReference;
222    ClassObject* classJavaLangRefReference;
223    ClassObject* classJavaNioReadWriteDirectByteBuffer;
224    ClassObject* classJavaSecurityAccessController;
225    ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationFactory;
226    ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMember;
227    ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMemberArray;
228    ClassObject* classOrgApacheHarmonyNioInternalDirectBuffer;
229
230    /* synthetic classes for arrays of primitives */
231    ClassObject* classArrayBoolean;
232    ClassObject* classArrayChar;
233    ClassObject* classArrayFloat;
234    ClassObject* classArrayDouble;
235    ClassObject* classArrayByte;
236    ClassObject* classArrayShort;
237    ClassObject* classArrayInt;
238    ClassObject* classArrayLong;
239
240    /* method offsets - Object */
241    int         voffJavaLangObject_equals;
242    int         voffJavaLangObject_hashCode;
243    int         voffJavaLangObject_toString;
244    int         voffJavaLangObject_finalize;
245
246    /* field offsets - Class */
247    int         offJavaLangClass_pd;
248
249    /* field offsets - String */
250    int         javaLangStringReady;    /* 0=not init, 1=ready, -1=initing */
251    int         offJavaLangString_value;
252    int         offJavaLangString_count;
253    int         offJavaLangString_offset;
254    int         offJavaLangString_hashCode;
255
256    /* field offsets - Thread */
257    int         offJavaLangThread_vmThread;
258    int         offJavaLangThread_group;
259    int         offJavaLangThread_daemon;
260    int         offJavaLangThread_name;
261    int         offJavaLangThread_priority;
262
263    /* method offsets - Thread */
264    int         voffJavaLangThread_run;
265
266    /* field offsets - VMThread */
267    int         offJavaLangVMThread_thread;
268    int         offJavaLangVMThread_vmData;
269
270    /* method offsets - ThreadGroup */
271    int         voffJavaLangThreadGroup_removeThread;
272
273    /* field offsets - Throwable */
274    int         offJavaLangThrowable_stackState;
275    int         offJavaLangThrowable_message;
276    int         offJavaLangThrowable_cause;
277
278    /* field offsets - java.lang.reflect.* */
279    int         offJavaLangReflectAccessibleObject_flag;
280    int         offJavaLangReflectConstructor_slot;
281    int         offJavaLangReflectConstructor_declClass;
282    int         offJavaLangReflectField_slot;
283    int         offJavaLangReflectField_declClass;
284    int         offJavaLangReflectMethod_slot;
285    int         offJavaLangReflectMethod_declClass;
286
287    /* field offsets - java.lang.ref.Reference */
288    int         offJavaLangRefReference_referent;
289    int         offJavaLangRefReference_queue;
290    int         offJavaLangRefReference_queueNext;
291    int         offJavaLangRefReference_pendingNext;
292
293    /* method pointers - java.lang.ref.Reference */
294    Method*     methJavaLangRefReference_enqueueInternal;
295
296    /* field offsets - java.nio.Buffer and java.nio.DirectByteBufferImpl */
297    //int         offJavaNioBuffer_capacity;
298    //int         offJavaNioDirectByteBufferImpl_pointer;
299
300    /* method pointers - java.security.AccessController */
301    volatile int javaSecurityAccessControllerReady;
302    Method*     methJavaSecurityAccessController_doPrivileged[4];
303
304    /* constructor method pointers; no vtable involved, so use Method* */
305    Method*     methJavaLangStackTraceElement_init;
306    Method*     methJavaLangExceptionInInitializerError_init;
307    Method*     methJavaLangRefPhantomReference_init;
308    Method*     methJavaLangReflectConstructor_init;
309    Method*     methJavaLangReflectField_init;
310    Method*     methJavaLangReflectMethod_init;
311    Method*     methOrgApacheHarmonyLangAnnotationAnnotationMember_init;
312
313    /* static method pointers - android.lang.annotation.* */
314    Method*
315        methOrgApacheHarmonyLangAnnotationAnnotationFactory_createAnnotation;
316
317    /* direct method pointers - java.lang.reflect.Proxy */
318    Method*     methJavaLangReflectProxy_constructorPrototype;
319
320    /* field offsets - java.lang.reflect.Proxy */
321    int         offJavaLangReflectProxy_h;
322
323    /* fake native entry point method */
324    Method*     methFakeNativeEntry;
325
326    /* assorted direct buffer helpers */
327    Method*     methJavaNioReadWriteDirectByteBuffer_init;
328    Method*     methOrgApacheHarmonyLuniPlatformPlatformAddress_on;
329    Method*     methOrgApacheHarmonyNioInternalDirectBuffer_getEffectiveAddress;
330    int         offJavaNioBuffer_capacity;
331    int         offJavaNioBuffer_effectiveDirectAddress;
332    int         offOrgApacheHarmonyLuniPlatformPlatformAddress_osaddr;
333
334    /*
335     * VM-synthesized primitive classes, for arrays.
336     */
337    ClassObject* volatile primitiveClass[PRIM_MAX];
338
339    /*
340     * Thread list.  This always has at least one element in it (main),
341     * and main is always the first entry.
342     *
343     * The threadListLock is used for several things, including the thread
344     * start condition variable.  Generally speaking, you must hold the
345     * threadListLock when:
346     *  - adding/removing items from the list
347     *  - waiting on or signaling threadStartCond
348     *  - examining the Thread struct for another thread (this is to avoid
349     *    one thread freeing the Thread struct while another thread is
350     *    perusing it)
351     */
352    Thread*     threadList;
353    pthread_mutex_t threadListLock;
354
355    pthread_cond_t threadStartCond;
356
357    /*
358     * The thread code grabs this before suspending all threads.  There
359     * are a few things that can cause a "suspend all":
360     *  (1) the GC is starting;
361     *  (2) the debugger has sent a "suspend all" request;
362     *  (3) a thread has hit a breakpoint or exception that the debugger
363     *      has marked as a "suspend all" event;
364     *  (4) the SignalCatcher caught a signal that requires suspension.
365     *  (5) (if implemented) the JIT needs to perform a heavyweight
366     *      rearrangement of the translation cache or JitTable.
367     *
368     * Because we use "safe point" self-suspension, it is never safe to
369     * do a blocking "lock" call on this mutex -- if it has been acquired,
370     * somebody is probably trying to put you to sleep.  The leading '_' is
371     * intended as a reminder that this lock is special.
372     */
373    pthread_mutex_t _threadSuspendLock;
374
375    /*
376     * Guards Thread->suspendCount for all threads, and provides the lock
377     * for the condition variable that all suspended threads sleep on
378     * (threadSuspendCountCond).
379     *
380     * This has to be separate from threadListLock because of the way
381     * threads put themselves to sleep.
382     */
383    pthread_mutex_t threadSuspendCountLock;
384
385    /*
386     * Suspended threads sleep on this.  They should sleep on the condition
387     * variable until their "suspend count" is zero.
388     *
389     * Paired with "threadSuspendCountLock".
390     */
391    pthread_cond_t  threadSuspendCountCond;
392
393    /*
394     * Sum of all threads' suspendCount fields.  The JIT needs to know if any
395     * thread is suspended.  Guarded by threadSuspendCountLock.
396     */
397    int  sumThreadSuspendCount;
398
399    /*
400     * MUTEX ORDERING: when locking multiple mutexes, always grab them in
401     * this order to avoid deadlock:
402     *
403     *  (1) _threadSuspendLock      (use lockThreadSuspend())
404     *  (2) threadListLock          (use dvmLockThreadList())
405     *  (3) threadSuspendCountLock  (use lockThreadSuspendCount())
406     */
407
408
409    /*
410     * Thread ID bitmap.  We want threads to have small integer IDs so
411     * we can use them in "thin locks".
412     */
413    BitVector*  threadIdMap;
414
415    /*
416     * Manage exit conditions.  The VM exits when all non-daemon threads
417     * have exited.  If the main thread returns early, we need to sleep
418     * on a condition variable.
419     */
420    int         nonDaemonThreadCount;   /* must hold threadListLock to access */
421    //pthread_mutex_t vmExitLock;
422    pthread_cond_t  vmExitCond;
423
424    /*
425     * The set of DEX files loaded by custom class loaders.
426     */
427    HashTable*  userDexFiles;
428
429    /*
430     * JNI global reference table.
431     */
432#ifdef USE_INDIRECT_REF
433    IndirectRefTable jniGlobalRefTable;
434#else
435    ReferenceTable  jniGlobalRefTable;
436#endif
437    pthread_mutex_t jniGlobalRefLock;
438    int         jniGlobalRefHiMark;
439    int         jniGlobalRefLoMark;
440
441    /*
442     * JNI pinned object table (used for primitive arrays).
443     */
444    ReferenceTable  jniPinRefTable;
445    pthread_mutex_t jniPinRefLock;
446
447    /*
448     * Native shared library table.
449     */
450    HashTable*  nativeLibs;
451
452    /*
453     * GC heap lock.  Functions like gcMalloc() acquire this before making
454     * any changes to the heap.  It is held throughout garbage collection.
455     */
456    pthread_mutex_t gcHeapLock;
457
458    /*
459     * Condition variable to queue threads waiting to retry an
460     * allocation.  Signaled after a concurrent GC is completed.
461     */
462    pthread_cond_t gcHeapCond;
463
464    /* Opaque pointer representing the heap. */
465    GcHeap*     gcHeap;
466
467    /* The card table base, modified as needed for marking cards. */
468    u1*         biasedCardTableBase;
469
470    /*
471     * Pre-allocated throwables.
472     */
473    Object*     outOfMemoryObj;
474    Object*     internalErrorObj;
475    Object*     noClassDefFoundErrorObj;
476
477    /* Monitor list, so we can free them */
478    /*volatile*/ Monitor* monitorList;
479
480    /* Monitor for Thread.sleep() implementation */
481    Monitor*    threadSleepMon;
482
483    /* set when we create a second heap inside the zygote */
484    bool        newZygoteHeapAllocated;
485
486    /*
487     * TLS keys.
488     */
489    pthread_key_t pthreadKeySelf;       /* Thread*, for dvmThreadSelf */
490
491    /*
492     * JNI allows you to have multiple VMs, but we limit ourselves to 1,
493     * so "vmList" is really just a pointer to the one and only VM.
494     */
495    JavaVM*     vmList;
496
497    /*
498     * Cache results of "A instanceof B".
499     */
500    AtomicCache* instanceofCache;
501
502    /* instruction width table, used for optimization and verification */
503    InstructionWidth*   instrWidth;
504    /* instruction flags table, used for verification */
505    InstructionFlags*   instrFlags;
506    /* instruction format table, used for verification */
507    InstructionFormat*  instrFormat;
508
509    /* inline substitution table, used during optimization */
510    InlineSub*          inlineSubs;
511
512    /*
513     * Bootstrap class loader linear allocator.
514     */
515    LinearAllocHdr* pBootLoaderAlloc;
516
517
518    /*
519     * Heap worker thread.
520     */
521    bool            heapWorkerInitialized;
522    bool            heapWorkerReady;
523    bool            haltHeapWorker;
524    pthread_t       heapWorkerHandle;
525    pthread_mutex_t heapWorkerLock;
526    pthread_cond_t  heapWorkerCond;
527    pthread_cond_t  heapWorkerIdleCond;
528    pthread_mutex_t heapWorkerListLock;
529
530    /*
531     * Compute some stats on loaded classes.
532     */
533    int         numLoadedClasses;
534    int         numDeclaredMethods;
535    int         numDeclaredInstFields;
536    int         numDeclaredStaticFields;
537
538    /* when using a native debugger, set this to suppress watchdog timers */
539    bool        nativeDebuggerActive;
540
541    /*
542     * JDWP debugger support.
543     *
544     * Note "debuggerActive" is accessed from mterp, so its storage size and
545     * meaning must not be changed without updating the assembly sources.
546     */
547    bool        debuggerConnected;      /* debugger or DDMS is connected */
548    u1          debuggerActive;         /* debugger is making requests */
549    JdwpState*  jdwpState;
550
551    /*
552     * Registry of objects known to the debugger.
553     */
554    HashTable*  dbgRegistry;
555
556    /*
557     * Debugger breakpoint table.
558     */
559    BreakpointSet*  breakpointSet;
560
561    /*
562     * Single-step control struct.  We currently only allow one thread to
563     * be single-stepping at a time, which is all that really makes sense,
564     * but it's possible we may need to expand this to be per-thread.
565     */
566    StepControl stepControl;
567
568    /*
569     * DDM features embedded in the VM.
570     */
571    bool        ddmThreadNotification;
572
573    /*
574     * Zygote (partially-started process) support
575     */
576    bool        zygote;
577
578    /*
579     * Used for tracking allocations that we report to DDMS.  When the feature
580     * is enabled (through a DDMS request) the "allocRecords" pointer becomes
581     * non-NULL.
582     */
583    pthread_mutex_t allocTrackerLock;
584    AllocRecord*    allocRecords;
585    int             allocRecordHead;        /* most-recently-added entry */
586    int             allocRecordCount;       /* #of valid entries */
587
588#ifdef WITH_ALLOC_LIMITS
589    /* set on first use of an alloc limit, never cleared */
590    bool        checkAllocLimits;
591    /* allocation limit, for setGlobalAllocationLimit() regression testing */
592    int         allocationLimit;
593#endif
594
595#ifdef WITH_DEADLOCK_PREDICTION
596    /* global lock on history tree accesses */
597    pthread_mutex_t deadlockHistoryLock;
598
599    enum { kDPOff=0, kDPWarn, kDPErr, kDPAbort } deadlockPredictMode;
600#endif
601
602    /*
603     * When a profiler is enabled, this is incremented.  Distinct profilers
604     * include "dmtrace" method tracing, emulator method tracing, and
605     * possibly instruction counting.
606     *
607     * The purpose of this is to have a single value that the interpreter
608     * can check to see if any profiling activity is enabled.
609     */
610    volatile int activeProfilers;
611
612    /*
613     * State for method-trace profiling.
614     */
615    MethodTraceState methodTrace;
616
617    /*
618     * State for emulator tracing.
619     */
620    void*       emulatorTracePage;
621    int         emulatorTraceEnableCount;
622
623    /*
624     * Global state for memory allocation profiling.
625     */
626    AllocProfState allocProf;
627
628    /*
629     * Pointers to the original methods for things that have been inlined.
630     * This makes it easy for us to output method entry/exit records for
631     * the method calls we're not actually making.  (Used by method
632     * profiling.)
633     */
634    Method**    inlinedMethods;
635
636    /*
637     * Dalvik instruction counts (256 entries).
638     */
639    int*        executedInstrCounts;
640    bool        instructionCountEnableCount;
641
642    /*
643     * Signal catcher thread (for SIGQUIT).
644     */
645    pthread_t   signalCatcherHandle;
646    bool        haltSignalCatcher;
647
648    /*
649     * Stdout/stderr conversion thread.
650     */
651    bool            haltStdioConverter;
652    bool            stdioConverterReady;
653    pthread_t       stdioConverterHandle;
654    pthread_mutex_t stdioConverterLock;
655    pthread_cond_t  stdioConverterCond;
656
657    /*
658     * pid of the system_server process. We track it so that when system server
659     * crashes the Zygote process will be killed and restarted.
660     */
661    pid_t systemServerPid;
662
663    int kernelGroupScheduling;
664
665//#define COUNT_PRECISE_METHODS
666#ifdef COUNT_PRECISE_METHODS
667    PointerSet* preciseMethods;
668#endif
669
670    /* some RegisterMap statistics, useful during development */
671    void*       registerMapStats;
672};
673
674extern struct DvmGlobals gDvm;
675
676#if defined(WITH_JIT)
677
678/*
679 * Exiting the compiled code w/o chaining will incur overhead to look up the
680 * target in the code cache which is extra work only when JIT is enabled. So
681 * we want to monitor it closely to make sure we don't have performance bugs.
682 */
683typedef enum NoChainExits {
684    kInlineCacheMiss = 0,
685    kCallsiteInterpreted,
686    kSwitchOverflow,
687    kHeavyweightMonitor,
688    kNoChainExitLast,
689} NoChainExits;
690
691/*
692 * JIT-specific global state
693 */
694struct DvmJitGlobals {
695    /*
696     * Guards writes to Dalvik PC (dPC), translated code address (codeAddr) and
697     * chain fields within the JIT hash table.  Note carefully the access
698     * mechanism.
699     * Only writes are guarded, and the guarded fields must be updated in a
700     * specific order using atomic operations.  Further, once a field is
701     * written it cannot be changed without halting all threads.
702     *
703     * The write order is:
704     *    1) codeAddr
705     *    2) dPC
706     *    3) chain [if necessary]
707     *
708     * This mutex also guards both read and write of curJitTableEntries.
709     */
710    pthread_mutex_t tableLock;
711
712    /* The JIT hash table.  Note that for access speed, copies of this pointer
713     * are stored in each thread. */
714    struct JitEntry *pJitEntryTable;
715
716    /* Array of profile threshold counters */
717    unsigned char *pProfTable;
718
719    /* Copy of pProfTable used for temporarily disabling the Jit */
720    unsigned char *pProfTableCopy;
721
722    /* Size of JIT hash table in entries.  Must be a power of 2 */
723    unsigned int jitTableSize;
724
725    /* Mask used in hash function for JitTable.  Should be jitTableSize-1 */
726    unsigned int jitTableMask;
727
728    /* How many entries in the JitEntryTable are in use */
729    unsigned int jitTableEntriesUsed;
730
731    /* Bytes allocated for the code cache */
732    unsigned int codeCacheSize;
733
734    /* Trigger for trace selection */
735    unsigned short threshold;
736
737    /* JIT Compiler Control */
738    bool               haltCompilerThread;
739    bool               blockingMode;
740    pthread_t          compilerHandle;
741    pthread_mutex_t    compilerLock;
742    pthread_mutex_t    compilerICPatchLock;
743    pthread_cond_t     compilerQueueActivity;
744    pthread_cond_t     compilerQueueEmpty;
745    volatile int       compilerQueueLength;
746    int                compilerHighWater;
747    int                compilerWorkEnqueueIndex;
748    int                compilerWorkDequeueIndex;
749    int                compilerICPatchIndex;
750
751    /* JIT internal stats */
752    int                compilerMaxQueued;
753    int                translationChains;
754
755    /* Compiled code cache */
756    void* codeCache;
757
758    /* Bytes used by the code templates */
759    unsigned int templateSize;
760
761    /* Bytes already used in the code cache */
762    unsigned int codeCacheByteUsed;
763
764    /* Number of installed compilations in the cache */
765    unsigned int numCompilations;
766
767    /* Flag to indicate that the code cache is full */
768    bool codeCacheFull;
769
770    /* Page size  - 1 */
771    unsigned int pageSizeMask;
772
773    /* Lock to change the protection type of the code cache */
774    pthread_mutex_t    codeCacheProtectionLock;
775
776    /* Number of times that the code cache has been reset */
777    int numCodeCacheReset;
778
779    /* Number of times that the code cache reset request has been delayed */
780    int numCodeCacheResetDelayed;
781
782    /* true/false: compile/reject opcodes specified in the -Xjitop list */
783    bool includeSelectedOp;
784
785    /* true/false: compile/reject methods specified in the -Xjitmethod list */
786    bool includeSelectedMethod;
787
788    /* Disable JIT for selected opcodes - one bit for each opcode */
789    char opList[32];
790
791    /* Disable JIT for selected methods */
792    HashTable *methodTable;
793
794    /* Flag to dump all compiled code */
795    bool printMe;
796
797    /* Flag to count trace execution */
798    bool profile;
799
800    /* Vector to disable selected optimizations */
801    int disableOpt;
802
803    /* Table to track the overall and trace statistics of hot methods */
804    HashTable*  methodStatsTable;
805
806    /* Filter method compilation blacklist with call-graph information */
807    bool checkCallGraph;
808
809    /* New translation chain has been set up */
810    volatile bool hasNewChain;
811
812#if defined(WITH_SELF_VERIFICATION)
813    /* Spin when error is detected, volatile so GDB can reset it */
814    volatile bool selfVerificationSpin;
815#endif
816
817    /* Framework or stand-alone? */
818    bool runningInAndroidFramework;
819
820    /* Framework callback happened? */
821    bool alreadyEnabledViaFramework;
822
823    /* Framework requests to disable the JIT for good */
824    bool disableJit;
825
826#if defined(SIGNATURE_BREAKPOINT)
827    /* Signature breakpoint */
828    u4 signatureBreakpointSize;         // # of words
829    u4 *signatureBreakpoint;            // Signature content
830#endif
831
832#if defined(WITH_JIT_TUNING)
833    /* Performance tuning counters */
834    int                addrLookupsFound;
835    int                addrLookupsNotFound;
836    int                noChainExit[kNoChainExitLast];
837    int                normalExit;
838    int                puntExit;
839    int                invokeMonomorphic;
840    int                invokePolymorphic;
841    int                invokeNative;
842    int                invokeMonoGetterInlined;
843    int                invokeMonoSetterInlined;
844    int                invokePolyGetterInlined;
845    int                invokePolySetterInlined;
846    int                returnOp;
847    int                icPatchInit;
848    int                icPatchLockFree;
849    int                icPatchQueued;
850    int                icPatchRejected;
851    int                icPatchDropped;
852    u8                 jitTime;
853    int                codeCachePatches;
854#endif
855
856    /* Place arrays at the end to ease the display in gdb sessions */
857
858    /* Work order queue for compilations */
859    CompilerWorkOrder compilerWorkQueue[COMPILER_WORK_QUEUE_SIZE];
860
861    /* Work order queue for predicted chain patching */
862    ICPatchWorkOrder compilerICPatchQueue[COMPILER_IC_PATCH_QUEUE_SIZE];
863};
864
865extern struct DvmJitGlobals gDvmJit;
866
867#if defined(WITH_JIT_TUNING)
868extern int gDvmICHitCount;
869#endif
870
871#endif
872
873#endif /*_DALVIK_GLOBALS*/
874