OSDN Git Service

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