OSDN Git Service

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