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