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