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