Globals.h revision fc3d31683a0120ba005f45f98dcbe1001064dafb
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    char*       jniTrace;
108    bool        reduceSignals;
109    bool        noQuitHandler;
110    bool        verifyDexChecksum;
111    char*       stackTraceFile;     // for SIGQUIT-inspired output
112
113    bool        logStdio;
114
115    DexOptimizerMode    dexOptMode;
116    DexClassVerifyMode  classVerifyMode;
117
118    /*
119     * GC option flags.
120     */
121    bool        preciseGc;
122    bool        preVerify;
123    bool        postVerify;
124    bool        generateRegisterMaps;
125    bool        concurrentMarkSweep;
126    bool        verifyCardTable;
127
128    int         assertionCtrlCount;
129    AssertionControl*   assertionCtrl;
130
131    ExecutionMode   executionMode;
132
133    /*
134     * VM init management.
135     */
136    bool        initializing;
137    int         initExceptionCount;
138    bool        optimizing;
139
140    /*
141     * java.lang.System properties set from the command line.
142     */
143    int         numProps;
144    int         maxProps;
145    char**      propList;
146
147    /*
148     * Where the VM goes to find system classes.
149     */
150    ClassPathEntry* bootClassPath;
151    /* used by the DEX optimizer to load classes from an unfinished DEX */
152    DvmDex*     bootClassPathOptExtra;
153    bool        optimizingBootstrapClass;
154
155    /*
156     * Loaded classes, hashed by class name.  Each entry is a ClassObject*,
157     * allocated in GC space.
158     */
159    HashTable*  loadedClasses;
160
161    /*
162     * Value for the next class serial number to be assigned.  This is
163     * incremented as we load classes.  Failed loads and races may result
164     * in some numbers being skipped, and the serial number is not
165     * guaranteed to start at 1, so the current value should not be used
166     * as a count of loaded classes.
167     */
168    volatile int classSerialNumber;
169
170    /*
171     * Classes with a low classSerialNumber are probably in the zygote, and
172     * their InitiatingLoaderList is not used, to promote sharing. The list is
173     * kept here instead.
174     */
175    InitiatingLoaderList* initiatingLoaderList;
176
177    /*
178     * Interned strings.
179     */
180
181    /* A mutex that guards access to the interned string tables. */
182    pthread_mutex_t internLock;
183
184    /* Hash table of strings interned by the user. */
185    HashTable*  internedStrings;
186
187    /* Hash table of strings interned by the class loader. */
188    HashTable*  literalStrings;
189
190    /*
191     * Quick lookups for popular classes used internally.
192     */
193    ClassObject* classJavaLangClass;
194    ClassObject* classJavaLangClassArray;
195    ClassObject* classJavaLangError;
196    ClassObject* classJavaLangObject;
197    ClassObject* classJavaLangObjectArray;
198    ClassObject* classJavaLangRuntimeException;
199    ClassObject* classJavaLangString;
200    ClassObject* classJavaLangThread;
201    ClassObject* classJavaLangVMThread;
202    ClassObject* classJavaLangThreadGroup;
203    ClassObject* classJavaLangThrowable;
204    ClassObject* classJavaLangStackOverflowError;
205    ClassObject* classJavaLangStackTraceElement;
206    ClassObject* classJavaLangStackTraceElementArray;
207    ClassObject* classJavaLangAnnotationAnnotationArray;
208    ClassObject* classJavaLangAnnotationAnnotationArrayArray;
209    ClassObject* classJavaLangReflectAccessibleObject;
210    ClassObject* classJavaLangReflectConstructor;
211    ClassObject* classJavaLangReflectConstructorArray;
212    ClassObject* classJavaLangReflectField;
213    ClassObject* classJavaLangReflectFieldArray;
214    ClassObject* classJavaLangReflectMethod;
215    ClassObject* classJavaLangReflectMethodArray;
216    ClassObject* classJavaLangReflectProxy;
217    ClassObject* classJavaLangExceptionInInitializerError;
218    ClassObject* classJavaLangRefPhantomReference;
219    ClassObject* classJavaLangRefReference;
220    ClassObject* classJavaNioReadWriteDirectByteBuffer;
221    ClassObject* classJavaSecurityAccessController;
222    ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationFactory;
223    ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMember;
224    ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMemberArray;
225    ClassObject* classOrgApacheHarmonyNioInternalDirectBuffer;
226    jclass      jclassOrgApacheHarmonyNioInternalDirectBuffer;
227
228    /* synthetic classes for arrays of primitives */
229    ClassObject* classArrayBoolean;
230    ClassObject* classArrayChar;
231    ClassObject* classArrayFloat;
232    ClassObject* classArrayDouble;
233    ClassObject* classArrayByte;
234    ClassObject* classArrayShort;
235    ClassObject* classArrayInt;
236    ClassObject* classArrayLong;
237
238    /* method offsets - Object */
239    int         voffJavaLangObject_equals;
240    int         voffJavaLangObject_hashCode;
241    int         voffJavaLangObject_toString;
242    int         voffJavaLangObject_finalize;
243
244    /* field offsets - Class */
245    int         offJavaLangClass_pd;
246
247    /* field offsets - String */
248    int         javaLangStringReady;    /* 0=not init, 1=ready, -1=initing */
249    int         offJavaLangString_value;
250    int         offJavaLangString_count;
251    int         offJavaLangString_offset;
252    int         offJavaLangString_hashCode;
253
254    /* field offsets - Thread */
255    int         offJavaLangThread_vmThread;
256    int         offJavaLangThread_group;
257    int         offJavaLangThread_daemon;
258    int         offJavaLangThread_name;
259    int         offJavaLangThread_priority;
260
261    /* method offsets - Thread */
262    int         voffJavaLangThread_run;
263
264    /* field offsets - VMThread */
265    int         offJavaLangVMThread_thread;
266    int         offJavaLangVMThread_vmData;
267
268    /* method offsets - ThreadGroup */
269    int         voffJavaLangThreadGroup_removeThread;
270
271    /* field offsets - Throwable */
272    int         offJavaLangThrowable_stackState;
273    int         offJavaLangThrowable_message;
274    int         offJavaLangThrowable_cause;
275
276    /* field offsets - java.lang.reflect.* */
277    int         offJavaLangReflectAccessibleObject_flag;
278    int         offJavaLangReflectConstructor_slot;
279    int         offJavaLangReflectConstructor_declClass;
280    int         offJavaLangReflectField_slot;
281    int         offJavaLangReflectField_declClass;
282    int         offJavaLangReflectMethod_slot;
283    int         offJavaLangReflectMethod_declClass;
284
285    /* field offsets - java.lang.ref.Reference */
286    int         offJavaLangRefReference_referent;
287    int         offJavaLangRefReference_queue;
288    int         offJavaLangRefReference_queueNext;
289    int         offJavaLangRefReference_pendingNext;
290
291    /* method pointers - java.lang.ref.Reference */
292    Method*     methJavaLangRefReference_enqueueInternal;
293
294    /* field offsets - java.nio.Buffer and java.nio.DirectByteBufferImpl */
295    //int         offJavaNioBuffer_capacity;
296    //int         offJavaNioDirectByteBufferImpl_pointer;
297
298    /* method pointers - java.security.AccessController */
299    volatile int javaSecurityAccessControllerReady;
300    Method*     methJavaSecurityAccessController_doPrivileged[4];
301
302    /* constructor method pointers; no vtable involved, so use Method* */
303    Method*     methJavaLangStackTraceElement_init;
304    Method*     methJavaLangExceptionInInitializerError_init;
305    Method*     methJavaLangRefPhantomReference_init;
306    Method*     methJavaLangReflectConstructor_init;
307    Method*     methJavaLangReflectField_init;
308    Method*     methJavaLangReflectMethod_init;
309    Method*     methOrgApacheHarmonyLangAnnotationAnnotationMember_init;
310
311    /* static method pointers - android.lang.annotation.* */
312    Method*
313        methOrgApacheHarmonyLangAnnotationAnnotationFactory_createAnnotation;
314
315    /* direct method pointers - java.lang.reflect.Proxy */
316    Method*     methJavaLangReflectProxy_constructorPrototype;
317
318    /* field offsets - java.lang.reflect.Proxy */
319    int         offJavaLangReflectProxy_h;
320
321    /* fake native entry point method */
322    Method*     methFakeNativeEntry;
323
324    /* assorted direct buffer helpers */
325    Method*     methJavaNioReadWriteDirectByteBuffer_init;
326    Method*     methOrgApacheHarmonyLuniPlatformPlatformAddress_on;
327    Method*     methOrgApacheHarmonyNioInternalDirectBuffer_getEffectiveAddress;
328    int         offJavaNioBuffer_capacity;
329    int         offJavaNioBuffer_effectiveDirectAddress;
330    int         offOrgApacheHarmonyLuniPlatformPlatformAddress_osaddr;
331    int         voffOrgApacheHarmonyLuniPlatformPlatformAddress_toLong;
332
333    /*
334     * VM-synthesized primitive classes, for arrays.
335     */
336    ClassObject* volatile primitiveClass[PRIM_MAX];
337
338    /*
339     * Thread list.  This always has at least one element in it (main),
340     * and main is always the first entry.
341     *
342     * The threadListLock is used for several things, including the thread
343     * start condition variable.  Generally speaking, you must hold the
344     * threadListLock when:
345     *  - adding/removing items from the list
346     *  - waiting on or signaling threadStartCond
347     *  - examining the Thread struct for another thread (this is to avoid
348     *    one thread freeing the Thread struct while another thread is
349     *    perusing it)
350     */
351    Thread*     threadList;
352    pthread_mutex_t threadListLock;
353
354    pthread_cond_t threadStartCond;
355
356    /*
357     * The thread code grabs this before suspending all threads.  There
358     * are a few things that can cause a "suspend all":
359     *  (1) the GC is starting;
360     *  (2) the debugger has sent a "suspend all" request;
361     *  (3) a thread has hit a breakpoint or exception that the debugger
362     *      has marked as a "suspend all" event;
363     *  (4) the SignalCatcher caught a signal that requires suspension.
364     *  (5) (if implemented) the JIT needs to perform a heavyweight
365     *      rearrangement of the translation cache or JitTable.
366     *
367     * Because we use "safe point" self-suspension, it is never safe to
368     * do a blocking "lock" call on this mutex -- if it has been acquired,
369     * somebody is probably trying to put you to sleep.  The leading '_' is
370     * intended as a reminder that this lock is special.
371     */
372    pthread_mutex_t _threadSuspendLock;
373
374    /*
375     * Guards Thread->suspendCount for all threads, and provides the lock
376     * for the condition variable that all suspended threads sleep on
377     * (threadSuspendCountCond).
378     *
379     * This has to be separate from threadListLock because of the way
380     * threads put themselves to sleep.
381     */
382    pthread_mutex_t threadSuspendCountLock;
383
384    /*
385     * Suspended threads sleep on this.  They should sleep on the condition
386     * variable until their "suspend count" is zero.
387     *
388     * Paired with "threadSuspendCountLock".
389     */
390    pthread_cond_t  threadSuspendCountCond;
391
392    /*
393     * Sum of all threads' suspendCount fields.  The JIT needs to know if any
394     * thread is suspended.  Guarded by threadSuspendCountLock.
395     */
396    int  sumThreadSuspendCount;
397
398    /*
399     * MUTEX ORDERING: when locking multiple mutexes, always grab them in
400     * this order to avoid deadlock:
401     *
402     *  (1) _threadSuspendLock      (use lockThreadSuspend())
403     *  (2) threadListLock          (use dvmLockThreadList())
404     *  (3) threadSuspendCountLock  (use lockThreadSuspendCount())
405     */
406
407
408    /*
409     * Thread ID bitmap.  We want threads to have small integer IDs so
410     * we can use them in "thin locks".
411     */
412    BitVector*  threadIdMap;
413
414    /*
415     * Manage exit conditions.  The VM exits when all non-daemon threads
416     * have exited.  If the main thread returns early, we need to sleep
417     * on a condition variable.
418     */
419    int         nonDaemonThreadCount;   /* must hold threadListLock to access */
420    //pthread_mutex_t vmExitLock;
421    pthread_cond_t  vmExitCond;
422
423    /*
424     * The set of DEX files loaded by custom class loaders.
425     */
426    HashTable*  userDexFiles;
427
428    /*
429     * JNI global reference table.
430     */
431#ifdef USE_INDIRECT_REF
432    IndirectRefTable jniGlobalRefTable;
433#else
434    ReferenceTable  jniGlobalRefTable;
435#endif
436    pthread_mutex_t jniGlobalRefLock;
437    int         jniGlobalRefHiMark;
438    int         jniGlobalRefLoMark;
439
440    /*
441     * JNI pinned object table (used for primitive arrays).
442     */
443    ReferenceTable  jniPinRefTable;
444    pthread_mutex_t jniPinRefLock;
445
446    /*
447     * Native shared library table.
448     */
449    HashTable*  nativeLibs;
450
451    /*
452     * GC heap lock.  Functions like gcMalloc() acquire this before making
453     * any changes to the heap.  It is held throughout garbage collection.
454     */
455    pthread_mutex_t gcHeapLock;
456
457    /*
458     * Condition variable to queue threads waiting to retry an
459     * allocation.  Signaled after a concurrent GC is completed.
460     */
461    pthread_cond_t gcHeapCond;
462
463    /* Opaque pointer representing the heap. */
464    GcHeap*     gcHeap;
465
466    /* The card table base, modified as needed for marking cards. */
467    u1*         biasedCardTableBase;
468
469    /*
470     * Pre-allocated throwables.
471     */
472    Object*     outOfMemoryObj;
473    Object*     internalErrorObj;
474    Object*     noClassDefFoundErrorObj;
475
476    /* Monitor list, so we can free them */
477    /*volatile*/ Monitor* monitorList;
478
479    /* Monitor for Thread.sleep() implementation */
480    Monitor*    threadSleepMon;
481
482    /* set when we create a second heap inside the zygote */
483    bool        newZygoteHeapAllocated;
484
485    /*
486     * TLS keys.
487     */
488    pthread_key_t pthreadKeySelf;       /* Thread*, for dvmThreadSelf */
489
490    /*
491     * JNI allows you to have multiple VMs, but we limit ourselves to 1,
492     * so "vmList" is really just a pointer to the one and only VM.
493     */
494    JavaVM*     vmList;
495
496    /*
497     * Cache results of "A instanceof B".
498     */
499    AtomicCache* instanceofCache;
500
501    /* instruction width table, used for optimization and verification */
502    InstructionWidth*   instrWidth;
503    /* instruction flags table, used for verification */
504    InstructionFlags*   instrFlags;
505    /* instruction format table, used for verification */
506    InstructionFormat*  instrFormat;
507
508    /* inline substitution table, used during optimization */
509    InlineSub*          inlineSubs;
510
511    /*
512     * Bootstrap class loader linear allocator.
513     */
514    LinearAllocHdr* pBootLoaderAlloc;
515
516
517    /*
518     * Heap worker thread.
519     */
520    bool            heapWorkerInitialized;
521    bool            heapWorkerReady;
522    bool            haltHeapWorker;
523    pthread_t       heapWorkerHandle;
524    pthread_mutex_t heapWorkerLock;
525    pthread_cond_t  heapWorkerCond;
526    pthread_cond_t  heapWorkerIdleCond;
527    pthread_mutex_t heapWorkerListLock;
528
529    /*
530     * Compute some stats on loaded classes.
531     */
532    int         numLoadedClasses;
533    int         numDeclaredMethods;
534    int         numDeclaredInstFields;
535    int         numDeclaredStaticFields;
536
537    /* when using a native debugger, set this to suppress watchdog timers */
538    bool        nativeDebuggerActive;
539
540    /*
541     * JDWP debugger support.
542     *
543     * Note "debuggerActive" is accessed from mterp, so its storage size and
544     * meaning must not be changed without updating the assembly sources.
545     */
546    bool        debuggerConnected;      /* debugger or DDMS is connected */
547    u1          debuggerActive;         /* debugger is making requests */
548    JdwpState*  jdwpState;
549
550    /*
551     * Registry of objects known to the debugger.
552     */
553    HashTable*  dbgRegistry;
554
555    /*
556     * Debugger breakpoint table.
557     */
558    BreakpointSet*  breakpointSet;
559
560    /*
561     * Single-step control struct.  We currently only allow one thread to
562     * be single-stepping at a time, which is all that really makes sense,
563     * but it's possible we may need to expand this to be per-thread.
564     */
565    StepControl stepControl;
566
567    /*
568     * DDM features embedded in the VM.
569     */
570    bool        ddmThreadNotification;
571
572    /*
573     * Zygote (partially-started process) support
574     */
575    bool        zygote;
576
577    /*
578     * Used for tracking allocations that we report to DDMS.  When the feature
579     * is enabled (through a DDMS request) the "allocRecords" pointer becomes
580     * non-NULL.
581     */
582    pthread_mutex_t allocTrackerLock;
583    AllocRecord*    allocRecords;
584    int             allocRecordHead;        /* most-recently-added entry */
585    int             allocRecordCount;       /* #of valid entries */
586
587#ifdef WITH_ALLOC_LIMITS
588    /* set on first use of an alloc limit, never cleared */
589    bool        checkAllocLimits;
590    /* allocation limit, for setGlobalAllocationLimit() regression testing */
591    int         allocationLimit;
592#endif
593
594#ifdef WITH_DEADLOCK_PREDICTION
595    /* global lock on history tree accesses */
596    pthread_mutex_t deadlockHistoryLock;
597
598    enum { kDPOff=0, kDPWarn, kDPErr, kDPAbort } deadlockPredictMode;
599#endif
600
601#ifdef WITH_PROFILER
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.
632     */
633    Method**    inlinedMethods;
634
635    /*
636     * Dalvik instruction counts (256 entries).
637     */
638    int*        executedInstrCounts;
639    bool        instructionCountEnableCount;
640#endif
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