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