OSDN Git Service

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