Globals.h revision 0c2dc522d0e120f346cf0a40c8cf0c93346131c2
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_H_ 30#define DALVIK_GLOBALS_H_ 31 32#include <string> 33#include <vector> 34 35#include <stdarg.h> 36#include <pthread.h> 37 38/* private structures */ 39struct GcHeap; 40struct BreakpointSet; 41struct InlineSub; 42 43/* 44 * One of these for each -ea/-da/-esa/-dsa on the command line. 45 */ 46struct AssertionControl { 47 char* pkgOrClass; /* package/class string, or NULL for esa/dsa */ 48 int pkgOrClassLen; /* string length, for quick compare */ 49 bool enable; /* enable or disable */ 50 bool isPackage; /* string ended with "..."? */ 51}; 52 53/* 54 * Register map generation mode. Only applicable when generateRegisterMaps 55 * is enabled. (The "disabled" state is not folded into this because 56 * there are callers like dexopt that want to enable/disable without 57 * specifying the configuration details.) 58 * 59 * "TypePrecise" is slower and requires additional storage for the register 60 * maps, but allows type-precise GC. "LivePrecise" is even slower and 61 * requires additional heap during processing, but allows live-precise GC. 62 */ 63enum RegisterMapMode { 64 kRegisterMapModeUnknown = 0, 65 kRegisterMapModeTypePrecise, 66 kRegisterMapModeLivePrecise 67}; 68 69/* 70 * Profiler clock source. 71 */ 72enum ProfilerClockSource { 73 kProfilerClockSourceThreadCpu, 74 kProfilerClockSourceWall, 75 kProfilerClockSourceDual, 76}; 77 78/* 79 * All fields are initialized to zero. 80 * 81 * Storage allocated here must be freed by a subsystem shutdown function. 82 */ 83struct DvmGlobals { 84 /* 85 * Some options from the command line or environment. 86 */ 87 char* bootClassPathStr; 88 char* classPathStr; 89 90 size_t heapStartingSize; 91 size_t heapMaximumSize; 92 size_t heapGrowthLimit; 93 size_t stackSize; 94 size_t mainThreadStackSize; 95 96 bool verboseGc; 97 bool verboseJni; 98 bool verboseClass; 99 bool verboseShutdown; 100 101 bool jdwpAllowed; // debugging allowed for this process? 102 bool jdwpConfigured; // has debugging info been provided? 103 JdwpTransportType jdwpTransport; 104 bool jdwpServer; 105 char* jdwpHost; 106 int jdwpPort; 107 bool jdwpSuspend; 108 109 ProfilerClockSource profilerClockSource; 110 111 /* 112 * Lock profiling threshold value in milliseconds. Acquires that 113 * exceed threshold are logged. Acquires within the threshold are 114 * logged with a probability of $\frac{time}{threshold}$ . If the 115 * threshold is unset no additional logging occurs. 116 */ 117 u4 lockProfThreshold; 118 119 int (*vfprintfHook)(FILE*, const char*, va_list); 120 void (*exitHook)(int); 121 void (*abortHook)(void); 122 bool (*isSensitiveThreadHook)(void); 123 124 int jniGrefLimit; // 0 means no limit 125 char* jniTrace; 126 bool reduceSignals; 127 bool noQuitHandler; 128 bool verifyDexChecksum; 129 char* stackTraceFile; // for SIGQUIT-inspired output 130 131 bool logStdio; 132 133 DexOptimizerMode dexOptMode; 134 DexClassVerifyMode classVerifyMode; 135 136 bool generateRegisterMaps; 137 RegisterMapMode registerMapMode; 138 139 bool monitorVerification; 140 141 bool dexOptForSmp; 142 143 /* 144 * GC option flags. 145 */ 146 bool preciseGc; 147 bool preVerify; 148 bool postVerify; 149 bool concurrentMarkSweep; 150 bool verifyCardTable; 151 bool disableExplicitGc; 152 153 int assertionCtrlCount; 154 AssertionControl* assertionCtrl; 155 156 ExecutionMode executionMode; 157 158 bool commonInit; /* whether common stubs are generated */ 159 bool constInit; /* whether global constants are initialized */ 160 161 /* 162 * VM init management. 163 */ 164 bool initializing; 165 bool optimizing; 166 167 /* 168 * java.lang.System properties set from the command line with -D. 169 * This is effectively a set, where later entries override earlier 170 * ones. 171 */ 172 std::vector<std::string>* properties; 173 174 /* 175 * Where the VM goes to find system classes. 176 */ 177 ClassPathEntry* bootClassPath; 178 /* used by the DEX optimizer to load classes from an unfinished DEX */ 179 DvmDex* bootClassPathOptExtra; 180 bool optimizingBootstrapClass; 181 182 /* 183 * Loaded classes, hashed by class name. Each entry is a ClassObject*, 184 * allocated in GC space. 185 */ 186 HashTable* loadedClasses; 187 188 /* 189 * Value for the next class serial number to be assigned. This is 190 * incremented as we load classes. Failed loads and races may result 191 * in some numbers being skipped, and the serial number is not 192 * guaranteed to start at 1, so the current value should not be used 193 * as a count of loaded classes. 194 */ 195 volatile int classSerialNumber; 196 197 /* 198 * Classes with a low classSerialNumber are probably in the zygote, and 199 * their InitiatingLoaderList is not used, to promote sharing. The list is 200 * kept here instead. 201 */ 202 InitiatingLoaderList* initiatingLoaderList; 203 204 /* 205 * Interned strings. 206 */ 207 208 /* A mutex that guards access to the interned string tables. */ 209 pthread_mutex_t internLock; 210 211 /* Hash table of strings interned by the user. */ 212 HashTable* internedStrings; 213 214 /* Hash table of strings interned by the class loader. */ 215 HashTable* literalStrings; 216 217 /* 218 * Classes constructed directly by the vm. 219 */ 220 221 /* the class Class */ 222 ClassObject* classJavaLangClass; 223 224 /* synthetic classes representing primitive types */ 225 ClassObject* typeVoid; 226 ClassObject* typeBoolean; 227 ClassObject* typeByte; 228 ClassObject* typeShort; 229 ClassObject* typeChar; 230 ClassObject* typeInt; 231 ClassObject* typeLong; 232 ClassObject* typeFloat; 233 ClassObject* typeDouble; 234 235 /* synthetic classes for arrays of primitives */ 236 ClassObject* classArrayBoolean; 237 ClassObject* classArrayByte; 238 ClassObject* classArrayShort; 239 ClassObject* classArrayChar; 240 ClassObject* classArrayInt; 241 ClassObject* classArrayLong; 242 ClassObject* classArrayFloat; 243 ClassObject* classArrayDouble; 244 245 /* 246 * Quick lookups for popular classes used internally. 247 */ 248 ClassObject* classJavaLangClassArray; 249 ClassObject* classJavaLangClassLoader; 250 ClassObject* classJavaLangObject; 251 ClassObject* classJavaLangObjectArray; 252 ClassObject* classJavaLangString; 253 ClassObject* classJavaLangThread; 254 ClassObject* classJavaLangVMThread; 255 ClassObject* classJavaLangThreadGroup; 256 ClassObject* classJavaLangStackTraceElement; 257 ClassObject* classJavaLangStackTraceElementArray; 258 ClassObject* classJavaLangAnnotationAnnotationArray; 259 ClassObject* classJavaLangAnnotationAnnotationArrayArray; 260 ClassObject* classJavaLangReflectAccessibleObject; 261 ClassObject* classJavaLangReflectConstructor; 262 ClassObject* classJavaLangReflectConstructorArray; 263 ClassObject* classJavaLangReflectField; 264 ClassObject* classJavaLangReflectFieldArray; 265 ClassObject* classJavaLangReflectMethod; 266 ClassObject* classJavaLangReflectMethodArray; 267 ClassObject* classJavaLangReflectProxy; 268 ClassObject* classJavaNioReadWriteDirectByteBuffer; 269 ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationFactory; 270 ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMember; 271 ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMemberArray; 272 ClassObject* classOrgApacheHarmonyDalvikDdmcChunk; 273 ClassObject* classOrgApacheHarmonyDalvikDdmcDdmServer; 274 ClassObject* classJavaLangRefFinalizerReference; 275 276 /* 277 * classes representing exception types. The names here don't include 278 * packages, just to keep the use sites a bit less verbose. All are 279 * in java.lang, except where noted. 280 */ 281 ClassObject* exAbstractMethodError; 282 ClassObject* exArithmeticException; 283 ClassObject* exArrayIndexOutOfBoundsException; 284 ClassObject* exArrayStoreException; 285 ClassObject* exClassCastException; 286 ClassObject* exClassCircularityError; 287 ClassObject* exClassFormatError; 288 ClassObject* exClassNotFoundException; 289 ClassObject* exError; 290 ClassObject* exExceptionInInitializerError; 291 ClassObject* exFileNotFoundException; /* in java.io */ 292 ClassObject* exIOException; /* in java.io */ 293 ClassObject* exIllegalAccessError; 294 ClassObject* exIllegalAccessException; 295 ClassObject* exIllegalArgumentException; 296 ClassObject* exIllegalMonitorStateException; 297 ClassObject* exIllegalStateException; 298 ClassObject* exIllegalThreadStateException; 299 ClassObject* exIncompatibleClassChangeError; 300 ClassObject* exInstantiationError; 301 ClassObject* exInstantiationException; 302 ClassObject* exInternalError; 303 ClassObject* exInterruptedException; 304 ClassObject* exLinkageError; 305 ClassObject* exNegativeArraySizeException; 306 ClassObject* exNoClassDefFoundError; 307 ClassObject* exNoSuchFieldError; 308 ClassObject* exNoSuchFieldException; 309 ClassObject* exNoSuchMethodError; 310 ClassObject* exNullPointerException; 311 ClassObject* exOutOfMemoryError; 312 ClassObject* exRuntimeException; 313 ClassObject* exStackOverflowError; 314 ClassObject* exStaleDexCacheError; /* in dalvik.system */ 315 ClassObject* exStringIndexOutOfBoundsException; 316 ClassObject* exThrowable; 317 ClassObject* exTypeNotPresentException; 318 ClassObject* exUnsatisfiedLinkError; 319 ClassObject* exUnsupportedOperationException; 320 ClassObject* exVerifyError; 321 ClassObject* exVirtualMachineError; 322 323 /* method offsets - Object */ 324 int voffJavaLangObject_equals; 325 int voffJavaLangObject_hashCode; 326 int voffJavaLangObject_toString; 327 328 /* field offsets - String */ 329 int offJavaLangString_value; 330 int offJavaLangString_count; 331 int offJavaLangString_offset; 332 int offJavaLangString_hashCode; 333 334 /* field offsets - Thread */ 335 int offJavaLangThread_vmThread; 336 int offJavaLangThread_group; 337 int offJavaLangThread_daemon; 338 int offJavaLangThread_name; 339 int offJavaLangThread_priority; 340 int offJavaLangThread_uncaughtHandler; 341 int offJavaLangThread_contextClassLoader; 342 343 /* method offsets - Thread */ 344 int voffJavaLangThread_run; 345 346 /* field offsets - ThreadGroup */ 347 int offJavaLangThreadGroup_name; 348 int offJavaLangThreadGroup_parent; 349 350 /* field offsets - VMThread */ 351 int offJavaLangVMThread_thread; 352 int offJavaLangVMThread_vmData; 353 354 /* method offsets - ThreadGroup */ 355 int voffJavaLangThreadGroup_removeThread; 356 357 /* field offsets - Throwable */ 358 int offJavaLangThrowable_stackState; 359 int offJavaLangThrowable_cause; 360 361 /* method offsets - ClassLoader */ 362 int voffJavaLangClassLoader_loadClass; 363 364 /* direct method pointers - ClassLoader */ 365 Method* methJavaLangClassLoader_getSystemClassLoader; 366 367 /* field offsets - java.lang.reflect.* */ 368 int offJavaLangReflectConstructor_slot; 369 int offJavaLangReflectConstructor_declClass; 370 int offJavaLangReflectField_slot; 371 int offJavaLangReflectField_declClass; 372 int offJavaLangReflectMethod_slot; 373 int offJavaLangReflectMethod_declClass; 374 375 /* field offsets - java.lang.ref.Reference */ 376 int offJavaLangRefReference_referent; 377 int offJavaLangRefReference_queue; 378 int offJavaLangRefReference_queueNext; 379 int offJavaLangRefReference_pendingNext; 380 381 /* field offsets - java.lang.ref.FinalizerReference */ 382 int offJavaLangRefFinalizerReference_zombie; 383 384 /* method pointers - java.lang.ref.ReferenceQueue */ 385 Method* methJavaLangRefReferenceQueueAdd; 386 387 /* method pointers - java.lang.ref.FinalizerReference */ 388 Method* methJavaLangRefFinalizerReferenceAdd; 389 390 /* constructor method pointers; no vtable involved, so use Method* */ 391 Method* methJavaLangStackTraceElement_init; 392 Method* methJavaLangReflectConstructor_init; 393 Method* methJavaLangReflectField_init; 394 Method* methJavaLangReflectMethod_init; 395 Method* methOrgApacheHarmonyLangAnnotationAnnotationMember_init; 396 397 /* static method pointers - android.lang.annotation.* */ 398 Method* 399 methOrgApacheHarmonyLangAnnotationAnnotationFactory_createAnnotation; 400 401 /* direct method pointers - java.lang.reflect.Proxy */ 402 Method* methJavaLangReflectProxy_constructorPrototype; 403 404 /* field offsets - java.lang.reflect.Proxy */ 405 int offJavaLangReflectProxy_h; 406 407 /* field offsets - java.io.FileDescriptor */ 408 int offJavaIoFileDescriptor_descriptor; 409 410 /* direct method pointers - dalvik.system.NativeStart */ 411 Method* methDalvikSystemNativeStart_main; 412 Method* methDalvikSystemNativeStart_run; 413 414 /* assorted direct buffer helpers */ 415 Method* methJavaNioReadWriteDirectByteBuffer_init; 416 int offJavaNioBuffer_capacity; 417 int offJavaNioBuffer_effectiveDirectAddress; 418 419 /* direct method pointers - org.apache.harmony.dalvik.ddmc.DdmServer */ 420 Method* methDalvikDdmcServer_dispatch; 421 Method* methDalvikDdmcServer_broadcast; 422 423 /* field offsets - org.apache.harmony.dalvik.ddmc.Chunk */ 424 int offDalvikDdmcChunk_type; 425 int offDalvikDdmcChunk_data; 426 int offDalvikDdmcChunk_offset; 427 int offDalvikDdmcChunk_length; 428 429 /* 430 * Thread list. This always has at least one element in it (main), 431 * and main is always the first entry. 432 * 433 * The threadListLock is used for several things, including the thread 434 * start condition variable. Generally speaking, you must hold the 435 * threadListLock when: 436 * - adding/removing items from the list 437 * - waiting on or signaling threadStartCond 438 * - examining the Thread struct for another thread (this is to avoid 439 * one thread freeing the Thread struct while another thread is 440 * perusing it) 441 */ 442 Thread* threadList; 443 pthread_mutex_t threadListLock; 444 445 pthread_cond_t threadStartCond; 446 447 /* 448 * The thread code grabs this before suspending all threads. There 449 * are a few things that can cause a "suspend all": 450 * (1) the GC is starting; 451 * (2) the debugger has sent a "suspend all" request; 452 * (3) a thread has hit a breakpoint or exception that the debugger 453 * has marked as a "suspend all" event; 454 * (4) the SignalCatcher caught a signal that requires suspension. 455 * (5) (if implemented) the JIT needs to perform a heavyweight 456 * rearrangement of the translation cache or JitTable. 457 * 458 * Because we use "safe point" self-suspension, it is never safe to 459 * do a blocking "lock" call on this mutex -- if it has been acquired, 460 * somebody is probably trying to put you to sleep. The leading '_' is 461 * intended as a reminder that this lock is special. 462 */ 463 pthread_mutex_t _threadSuspendLock; 464 465 /* 466 * Guards Thread->suspendCount for all threads, and 467 * provides the lock for the condition variable that all suspended threads 468 * sleep on (threadSuspendCountCond). 469 * 470 * This has to be separate from threadListLock because of the way 471 * threads put themselves to sleep. 472 */ 473 pthread_mutex_t threadSuspendCountLock; 474 475 /* 476 * Suspended threads sleep on this. They should sleep on the condition 477 * variable until their "suspend count" is zero. 478 * 479 * Paired with "threadSuspendCountLock". 480 */ 481 pthread_cond_t threadSuspendCountCond; 482 483 /* 484 * Sum of all threads' suspendCount fields. Guarded by 485 * threadSuspendCountLock. 486 */ 487 int sumThreadSuspendCount; 488 489 /* 490 * MUTEX ORDERING: when locking multiple mutexes, always grab them in 491 * this order to avoid deadlock: 492 * 493 * (1) _threadSuspendLock (use lockThreadSuspend()) 494 * (2) threadListLock (use dvmLockThreadList()) 495 * (3) threadSuspendCountLock (use lockThreadSuspendCount()) 496 */ 497 498 499 /* 500 * Thread ID bitmap. We want threads to have small integer IDs so 501 * we can use them in "thin locks". 502 */ 503 BitVector* threadIdMap; 504 505 /* 506 * Manage exit conditions. The VM exits when all non-daemon threads 507 * have exited. If the main thread returns early, we need to sleep 508 * on a condition variable. 509 */ 510 int nonDaemonThreadCount; /* must hold threadListLock to access */ 511 pthread_cond_t vmExitCond; 512 513 /* 514 * The set of DEX files loaded by custom class loaders. 515 */ 516 HashTable* userDexFiles; 517 518 /* 519 * JNI global reference table. 520 */ 521 IndirectRefTable jniGlobalRefTable; 522 IndirectRefTable jniWeakGlobalRefTable; 523 pthread_mutex_t jniGlobalRefLock; 524 pthread_mutex_t jniWeakGlobalRefLock; 525 int jniGlobalRefHiMark; 526 int jniGlobalRefLoMark; 527 528 /* 529 * JNI pinned object table (used for primitive arrays). 530 */ 531 ReferenceTable jniPinRefTable; 532 pthread_mutex_t jniPinRefLock; 533 534 /* 535 * Native shared library table. 536 */ 537 HashTable* nativeLibs; 538 539 /* 540 * GC heap lock. Functions like gcMalloc() acquire this before making 541 * any changes to the heap. It is held throughout garbage collection. 542 */ 543 pthread_mutex_t gcHeapLock; 544 545 /* 546 * Condition variable to queue threads waiting to retry an 547 * allocation. Signaled after a concurrent GC is completed. 548 */ 549 pthread_cond_t gcHeapCond; 550 551 /* Opaque pointer representing the heap. */ 552 GcHeap* gcHeap; 553 554 /* The card table base, modified as needed for marking cards. */ 555 u1* biasedCardTableBase; 556 557 /* 558 * Pre-allocated throwables. 559 */ 560 Object* outOfMemoryObj; 561 Object* internalErrorObj; 562 Object* noClassDefFoundErrorObj; 563 564 /* Monitor list, so we can free them */ 565 /*volatile*/ Monitor* monitorList; 566 567 /* Monitor for Thread.sleep() implementation */ 568 Monitor* threadSleepMon; 569 570 /* set when we create a second heap inside the zygote */ 571 bool newZygoteHeapAllocated; 572 573 /* 574 * TLS keys. 575 */ 576 pthread_key_t pthreadKeySelf; /* Thread*, for dvmThreadSelf */ 577 578 /* 579 * Cache results of "A instanceof B". 580 */ 581 AtomicCache* instanceofCache; 582 583 /* inline substitution table, used during optimization */ 584 InlineSub* inlineSubs; 585 586 /* 587 * Bootstrap class loader linear allocator. 588 */ 589 LinearAllocHdr* pBootLoaderAlloc; 590 591 /* 592 * Compute some stats on loaded classes. 593 */ 594 int numLoadedClasses; 595 int numDeclaredMethods; 596 int numDeclaredInstFields; 597 int numDeclaredStaticFields; 598 599 /* when using a native debugger, set this to suppress watchdog timers */ 600 bool nativeDebuggerActive; 601 602 /* 603 * JDWP debugger support. 604 * 605 * Note: Each thread will normally determine whether the debugger is active 606 * for it by referring to its subMode flags. "debuggerActive" here should be 607 * seen as "debugger is making requests of 1 or more threads". 608 */ 609 bool debuggerConnected; /* debugger or DDMS is connected */ 610 bool debuggerActive; /* debugger is making requests */ 611 JdwpState* jdwpState; 612 613 /* 614 * Registry of objects known to the debugger. 615 */ 616 HashTable* dbgRegistry; 617 618 /* 619 * Debugger breakpoint table. 620 */ 621 BreakpointSet* breakpointSet; 622 623 /* 624 * Single-step control struct. We currently only allow one thread to 625 * be single-stepping at a time, which is all that really makes sense, 626 * but it's possible we may need to expand this to be per-thread. 627 */ 628 StepControl stepControl; 629 630 /* 631 * DDM features embedded in the VM. 632 */ 633 bool ddmThreadNotification; 634 635 /* 636 * Zygote (partially-started process) support 637 */ 638 bool zygote; 639 640 /* 641 * Used for tracking allocations that we report to DDMS. When the feature 642 * is enabled (through a DDMS request) the "allocRecords" pointer becomes 643 * non-NULL. 644 */ 645 pthread_mutex_t allocTrackerLock; 646 AllocRecord* allocRecords; 647 int allocRecordHead; /* most-recently-added entry */ 648 int allocRecordCount; /* #of valid entries */ 649 650 /* 651 * When a profiler is enabled, this is incremented. Distinct profilers 652 * include "dmtrace" method tracing, emulator method tracing, and 653 * possibly instruction counting. 654 * 655 * The purpose of this is to have a single value that shows whether any 656 * profiling is going on. Individual thread will normally check their 657 * thread-private subMode flags to take any profiling action. 658 */ 659 volatile int activeProfilers; 660 661 /* 662 * State for method-trace profiling. 663 */ 664 MethodTraceState methodTrace; 665 Method* methodTraceGcMethod; 666 Method* methodTraceClassPrepMethod; 667 668 /* 669 * State for emulator tracing. 670 */ 671 void* emulatorTracePage; 672 int emulatorTraceEnableCount; 673 674 /* 675 * Global state for memory allocation profiling. 676 */ 677 AllocProfState allocProf; 678 679 /* 680 * Pointers to the original methods for things that have been inlined. 681 * This makes it easy for us to output method entry/exit records for 682 * the method calls we're not actually making. (Used by method 683 * profiling.) 684 */ 685 Method** inlinedMethods; 686 687 /* 688 * Dalvik instruction counts (kNumPackedOpcodes entries). 689 */ 690 int* executedInstrCounts; 691 int instructionCountEnableCount; 692 693 /* 694 * Signal catcher thread (for SIGQUIT). 695 */ 696 pthread_t signalCatcherHandle; 697 bool haltSignalCatcher; 698 699 /* 700 * Stdout/stderr conversion thread. 701 */ 702 bool haltStdioConverter; 703 bool stdioConverterReady; 704 pthread_t stdioConverterHandle; 705 pthread_mutex_t stdioConverterLock; 706 pthread_cond_t stdioConverterCond; 707 int stdoutPipe[2]; 708 int stderrPipe[2]; 709 710 /* 711 * pid of the system_server process. We track it so that when system server 712 * crashes the Zygote process will be killed and restarted. 713 */ 714 pid_t systemServerPid; 715 716 int kernelGroupScheduling; 717 718//#define COUNT_PRECISE_METHODS 719#ifdef COUNT_PRECISE_METHODS 720 PointerSet* preciseMethods; 721#endif 722 723 /* some RegisterMap statistics, useful during development */ 724 void* registerMapStats; 725 726#ifdef VERIFIER_STATS 727 VerifierStats verifierStats; 728#endif 729 730 /* String pointed here will be deposited on the stack frame of dvmAbort */ 731 const char *lastMessage; 732}; 733 734extern struct DvmGlobals gDvm; 735 736#if defined(WITH_JIT) 737 738/* Trace profiling modes. Ordering matters - off states before on states */ 739enum TraceProfilingModes { 740 kTraceProfilingDisabled = 0, // Not profiling 741 kTraceProfilingPeriodicOff = 1, // Periodic profiling, off phase 742 kTraceProfilingContinuous = 2, // Always profiling 743 kTraceProfilingPeriodicOn = 3 // Periodic profiling, on phase 744}; 745 746/* 747 * Exiting the compiled code w/o chaining will incur overhead to look up the 748 * target in the code cache which is extra work only when JIT is enabled. So 749 * we want to monitor it closely to make sure we don't have performance bugs. 750 */ 751enum NoChainExits { 752 kInlineCacheMiss = 0, 753 kCallsiteInterpreted, 754 kSwitchOverflow, 755 kHeavyweightMonitor, 756 kNoChainExitLast, 757}; 758 759/* 760 * JIT-specific global state 761 */ 762struct DvmJitGlobals { 763 /* 764 * Guards writes to Dalvik PC (dPC), translated code address (codeAddr) and 765 * chain fields within the JIT hash table. Note carefully the access 766 * mechanism. 767 * Only writes are guarded, and the guarded fields must be updated in a 768 * specific order using atomic operations. Further, once a field is 769 * written it cannot be changed without halting all threads. 770 * 771 * The write order is: 772 * 1) codeAddr 773 * 2) dPC 774 * 3) chain [if necessary] 775 * 776 * This mutex also guards both read and write of curJitTableEntries. 777 */ 778 pthread_mutex_t tableLock; 779 780 /* The JIT hash table. Note that for access speed, copies of this pointer 781 * are stored in each thread. */ 782 struct JitEntry *pJitEntryTable; 783 784 /* Array of compilation trigger threshold counters */ 785 unsigned char *pProfTable; 786 787 /* Trace profiling counters */ 788 struct JitTraceProfCounters *pJitTraceProfCounters; 789 790 /* Copy of pProfTable used for temporarily disabling the Jit */ 791 unsigned char *pProfTableCopy; 792 793 /* Size of JIT hash table in entries. Must be a power of 2 */ 794 unsigned int jitTableSize; 795 796 /* Mask used in hash function for JitTable. Should be jitTableSize-1 */ 797 unsigned int jitTableMask; 798 799 /* How many entries in the JitEntryTable are in use */ 800 unsigned int jitTableEntriesUsed; 801 802 /* Bytes allocated for the code cache */ 803 unsigned int codeCacheSize; 804 805 /* Trigger for trace selection */ 806 unsigned short threshold; 807 808 /* JIT Compiler Control */ 809 bool haltCompilerThread; 810 bool blockingMode; 811 bool methodTraceSupport; 812 bool genSuspendPoll; 813 Thread* compilerThread; 814 pthread_t compilerHandle; 815 pthread_mutex_t compilerLock; 816 pthread_mutex_t compilerICPatchLock; 817 pthread_cond_t compilerQueueActivity; 818 pthread_cond_t compilerQueueEmpty; 819 volatile int compilerQueueLength; 820 int compilerHighWater; 821 int compilerWorkEnqueueIndex; 822 int compilerWorkDequeueIndex; 823 int compilerICPatchIndex; 824 825 /* JIT internal stats */ 826 int compilerMaxQueued; 827 int translationChains; 828 829 /* Compiled code cache */ 830 void* codeCache; 831 832 /* 833 * This is used to store the base address of an in-flight compilation whose 834 * class object pointers have been calculated to populate literal pool. 835 * Once the compiler thread has changed its status to VM_WAIT, we cannot 836 * guarantee whether GC has happened before the code address has been 837 * installed to the JIT table. Because of that, this field can only 838 * been cleared/overwritten by the compiler thread if it is in the 839 * THREAD_RUNNING state or in a safe point. 840 */ 841 void *inflightBaseAddr; 842 843 /* Translation cache version (protected by compilerLock */ 844 int cacheVersion; 845 846 /* Bytes used by the code templates */ 847 unsigned int templateSize; 848 849 /* Bytes already used in the code cache */ 850 unsigned int codeCacheByteUsed; 851 852 /* Number of installed compilations in the cache */ 853 unsigned int numCompilations; 854 855 /* Flag to indicate that the code cache is full */ 856 bool codeCacheFull; 857 858 /* Page size - 1 */ 859 unsigned int pageSizeMask; 860 861 /* Lock to change the protection type of the code cache */ 862 pthread_mutex_t codeCacheProtectionLock; 863 864 /* Number of times that the code cache has been reset */ 865 int numCodeCacheReset; 866 867 /* Number of times that the code cache reset request has been delayed */ 868 int numCodeCacheResetDelayed; 869 870 /* true/false: compile/reject opcodes specified in the -Xjitop list */ 871 bool includeSelectedOp; 872 873 /* true/false: compile/reject methods specified in the -Xjitmethod list */ 874 bool includeSelectedMethod; 875 876 /* true/false: compile/reject traces with offset specified in the -Xjitoffset list */ 877 bool includeSelectedOffset; 878 879 /* Disable JIT for selected opcodes - one bit for each opcode */ 880 char opList[(kNumPackedOpcodes+7)/8]; 881 882 /* Disable JIT for selected methods */ 883 HashTable *methodTable; 884 885 /* Disable JIT for selected classes */ 886 HashTable *classTable; 887 888 /* Disable JIT for selected offsets */ 889 unsigned int pcTable[COMPILER_PC_OFFSET_SIZE]; 890 int num_entries_pcTable; 891 892 /* Flag to dump all compiled code */ 893 bool printMe; 894 895 /* Flag to dump compiled binary code in bytes */ 896 bool printBinary; 897 898 /* Per-process debug flag toggled when receiving a SIGUSR2 */ 899 bool receivedSIGUSR2; 900 901 /* Trace profiling mode */ 902 TraceProfilingModes profileMode; 903 904 /* Periodic trace profiling countdown timer */ 905 int profileCountdown; 906 907 /* Vector to disable selected optimizations */ 908 int disableOpt; 909 910 /* Table to track the overall and trace statistics of hot methods */ 911 HashTable* methodStatsTable; 912 913 /* Filter method compilation blacklist with call-graph information */ 914 bool checkCallGraph; 915 916 /* New translation chain has been set up */ 917 volatile bool hasNewChain; 918 919#if defined(WITH_SELF_VERIFICATION) 920 /* Spin when error is detected, volatile so GDB can reset it */ 921 volatile bool selfVerificationSpin; 922#endif 923 924 /* Framework or stand-alone? */ 925 bool runningInAndroidFramework; 926 927 /* Framework callback happened? */ 928 bool alreadyEnabledViaFramework; 929 930 /* Framework requests to disable the JIT for good */ 931 bool disableJit; 932 933#if defined(SIGNATURE_BREAKPOINT) 934 /* Signature breakpoint */ 935 u4 signatureBreakpointSize; // # of words 936 u4 *signatureBreakpoint; // Signature content 937#endif 938 939#if defined(WITH_JIT_TUNING) 940 /* Performance tuning counters */ 941 int addrLookupsFound; 942 int addrLookupsNotFound; 943 int noChainExit[kNoChainExitLast]; 944 int normalExit; 945 int puntExit; 946 int invokeMonomorphic; 947 int invokePolymorphic; 948 int invokeNative; 949 int invokeMonoGetterInlined; 950 int invokeMonoSetterInlined; 951 int invokePolyGetterInlined; 952 int invokePolySetterInlined; 953 int returnOp; 954 int icPatchInit; 955 int icPatchLockFree; 956 int icPatchQueued; 957 int icPatchRejected; 958 int icPatchDropped; 959 int codeCachePatches; 960 int numCompilerThreadBlockGC; 961 u8 jitTime; 962 u8 compilerThreadBlockGCStart; 963 u8 compilerThreadBlockGCTime; 964 u8 maxCompilerThreadBlockGCTime; 965#endif 966 967#if defined(ARCH_IA32) 968 JitOptLevel optLevel; 969#endif 970 971 /* Place arrays at the end to ease the display in gdb sessions */ 972 973 /* Work order queue for compilations */ 974 CompilerWorkOrder compilerWorkQueue[COMPILER_WORK_QUEUE_SIZE]; 975 976 /* Work order queue for predicted chain patching */ 977 ICPatchWorkOrder compilerICPatchQueue[COMPILER_IC_PATCH_QUEUE_SIZE]; 978}; 979 980extern struct DvmJitGlobals gDvmJit; 981 982#if defined(WITH_JIT_TUNING) 983extern int gDvmICHitCount; 984#endif 985 986#endif 987 988struct DvmJniGlobals { 989 bool useCheckJni; 990 bool warnOnly; 991 bool forceCopy; 992 993 // Provide backwards compatibility for pre-ICS apps on ICS. 994 bool workAroundAppJniBugs; 995 996 // Debugging help for third-party developers. Similar to -Xjnitrace. 997 bool logThirdPartyJni; 998 999 // We only support a single JavaVM per process. 1000 JavaVM* jniVm; 1001}; 1002 1003extern struct DvmJniGlobals gDvmJni; 1004 1005#endif // DALVIK_GLOBALS_H_ 1006