thread.h revision f7ad17e108b9357d7c94c6218a8521140a667f3d
18d768a954b101a9532f980253ac46be2c53aba11Elliott Hughes/* 28d768a954b101a9532f980253ac46be2c53aba11Elliott Hughes * Copyright (C) 2011 The Android Open Source Project 38d768a954b101a9532f980253ac46be2c53aba11Elliott Hughes * 48d768a954b101a9532f980253ac46be2c53aba11Elliott Hughes * Licensed under the Apache License, Version 2.0 (the "License"); 58d768a954b101a9532f980253ac46be2c53aba11Elliott Hughes * you may not use this file except in compliance with the License. 68d768a954b101a9532f980253ac46be2c53aba11Elliott Hughes * You may obtain a copy of the License at 78d768a954b101a9532f980253ac46be2c53aba11Elliott Hughes * 88d768a954b101a9532f980253ac46be2c53aba11Elliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 98d768a954b101a9532f980253ac46be2c53aba11Elliott Hughes * 108d768a954b101a9532f980253ac46be2c53aba11Elliott Hughes * Unless required by applicable law or agreed to in writing, software 118d768a954b101a9532f980253ac46be2c53aba11Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 128d768a954b101a9532f980253ac46be2c53aba11Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138d768a954b101a9532f980253ac46be2c53aba11Elliott Hughes * See the License for the specific language governing permissions and 148d768a954b101a9532f980253ac46be2c53aba11Elliott Hughes * limitations under the License. 158d768a954b101a9532f980253ac46be2c53aba11Elliott Hughes */ 160e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro 170e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro#ifndef ART_SRC_THREAD_H_ 180e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro#define ART_SRC_THREAD_H_ 190e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro 20b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro#include <pthread.h> 21a09576416788b916095739e43a16917e7948f3a4Elliott Hughes 2202b48d1dae0c3adc01ef6668226fb648fb52990aElliott Hughes#include <bitset> 23a09576416788b916095739e43a16917e7948f3a4Elliott Hughes#include <iosfwd> 24b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers#include <list> 258daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes#include <string> 26e343b76af81a005ef64f5e75a555389fd9147dabjeffhao#include <vector> 27b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro 281f87008b165d26541d832ff805250afdc89c253dBrian Carlstrom#include "dex_file.h" 29578bbdc684db8ed68e9fedbc678669d27fa68b6eBrian Carlstrom#include "globals.h" 3069f5bc6759f256a146eefd8a7141d39fcc3b0421Elliott Hughes#include "jni_internal.h" 31578bbdc684db8ed68e9fedbc678669d27fa68b6eBrian Carlstrom#include "logging.h" 32578bbdc684db8ed68e9fedbc678669d27fa68b6eBrian Carlstrom#include "macros.h" 338daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes#include "mutex.h" 34b765be0d656c3073402693aeaf64e95a0e49f218Brian Carlstrom#include "mem_map.h" 35578bbdc684db8ed68e9fedbc678669d27fa68b6eBrian Carlstrom#include "offsets.h" 369d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes#include "runtime_stats.h" 3768e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes#include "stack.h" 38e343b76af81a005ef64f5e75a555389fd9147dabjeffhao#include "trace.h" 39bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers#include "UniquePtr.h" 40b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers 410e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapironamespace art { 420e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro 4369f5bc6759f256a146eefd8a7141d39fcc3b0421Elliott Hughesclass Array; 4437f7a40f6789bb287f287a9af00777af9d6428eeElliott Hughesclass Class; 451f87008b165d26541d832ff805250afdc89c253dBrian Carlstromclass ClassLinker; 46edcc09c737b00462881f147602656739d029571eElliott Hughesclass ClassLoader; 47bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogersclass Context; 48475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughesclass DebugInvokeReq; 49a40f9bc48afe3a9d38be2fa298fece13ed82ba28Brian Carlstromclass Method; 508daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughesclass Monitor; 510e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiroclass Object; 52b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiroclass Runtime; 53f7ad17e108b9357d7c94c6218a8521140a667f3dLogan Chienclass ShadowFrame; 5468e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughesclass StackIndirectReferenceTable; 5555df06be4369f5d8ab5eb61a5d22809255171036Shih-wei Liaoclass StackTraceElement; 561da522de18ac6e4c2913c3233529e9dd115059f8buzbeeclass StaticStorageBase; 5740381fb9dc4b4cf274f1e58b2cdf4396202c6189Brian Carlstromclass Thread; 5840381fb9dc4b4cf274f1e58b2cdf4396202c6189Brian Carlstromclass ThreadList; 5940381fb9dc4b4cf274f1e58b2cdf4396202c6189Brian Carlstromclass Throwable; 601da522de18ac6e4c2913c3233529e9dd115059f8buzbee 6155df06be4369f5d8ab5eb61a5d22809255171036Shih-wei Liaotemplate<class T> class ObjectArray; 624417536522fd2a9d8215d8672331984769c9520bShih-wei Liaotemplate<class T> class PrimitiveArray; 634417536522fd2a9d8215d8672331984769c9520bShih-wei Liaotypedef PrimitiveArray<int32_t> IntArray; 640e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro 6585d1545e985ac689db4bad7849880e843707c862Elliott Hughesclass PACKED Thread { 660e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro public: 678daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes /* thread priorities, from java.lang.Thread */ 688daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes enum Priority { 698daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes kMinPriority = 1, 708daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes kNormPriority = 5, 718daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes kMaxPriority = 10, 728daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes }; 73b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro enum State { 74499c5133d361e7c659fc38e5ccfeb1280a7996f5Elliott Hughes // These correspond to JDWP states (but needn't share the same values). 75499c5133d361e7c659fc38e5ccfeb1280a7996f5Elliott Hughes kTerminated = 0, // TS_ZOMBIE 76499c5133d361e7c659fc38e5ccfeb1280a7996f5Elliott Hughes kRunnable = 1, // TS_RUNNING 773ce4b266a8e620ae4205922d828acc5976a99006Elliott Hughes kTimedWaiting = 2, // TS_WAIT in Object.wait() with a timeout 78499c5133d361e7c659fc38e5ccfeb1280a7996f5Elliott Hughes kBlocked = 3, // TS_MONITOR on a monitor 79499c5133d361e7c659fc38e5ccfeb1280a7996f5Elliott Hughes kWaiting = 4, // TS_WAIT in Object.wait() 8093e74e8d879270071c3aa163f8495ada8d21f42fElliott Hughes // Non-JDWP states. 81c0f0933249cf516b37717faa766e1e9808f7c1f8Elliott Hughes kStarting = 5, // native thread started, not yet ready to run managed code 82c0f0933249cf516b37717faa766e1e9808f7c1f8Elliott Hughes kNative = 6, // off in a JNI native method 83c0f0933249cf516b37717faa766e1e9808f7c1f8Elliott Hughes kVmWait = 7, // waiting on an internal runtime resource 84c0f0933249cf516b37717faa766e1e9808f7c1f8Elliott Hughes kSuspended = 8, // suspended, usually by GC or debugger 85b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro }; 86b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro 87932746a4f22951abcba7b7c4c94c27b1bf164272Ian Rogers // Space to throw a StackOverflowError in. 88aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom static const size_t kStackOverflowReservedBytes = 4 * KB; 89c143c55718342519db5398e41dda31422cf16c79buzbee 9072db0d77d6c476c71c5bbaa14a80ca77f23a47f3Brian Carlstrom static const size_t kDefaultStackSize = 96 * KB; 9161e019d291583029c01b61b93bea750f2b663c37Carl Shapiro 929b576b4ed1dbe035952f3106d8f4b6993125ed6fShih-wei Liao class StackVisitor { 939b576b4ed1dbe035952f3106d8f4b6993125ed6fShih-wei Liao public: 940cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers virtual ~StackVisitor() {} 95530fa005e2944d3b12712f80d974f0e753f568efElliott Hughes // Return 'true' if we should continue to visit more frames, 'false' to stop. 96530fa005e2944d3b12712f80d974f0e753f568efElliott Hughes virtual bool VisitFrame(const Frame& frame, uintptr_t pc) = 0; 979b576b4ed1dbe035952f3106d8f4b6993125ed6fShih-wei Liao }; 989b576b4ed1dbe035952f3106d8f4b6993125ed6fShih-wei Liao 99462c94449720e0dc6b93d7138d835d345ccf67aeElliott Hughes // Creates a new native thread corresponding to the given managed peer. 100462c94449720e0dc6b93d7138d835d345ccf67aeElliott Hughes // Used to implement Thread.start. 101d369bb76dee0df2d2a106e9bf7f4e6446ed6deaaElliott Hughes static void Create(Object* peer, size_t stack_size); 10261e019d291583029c01b61b93bea750f2b663c37Carl Shapiro 103462c94449720e0dc6b93d7138d835d345ccf67aeElliott Hughes // Attaches the calling native thread to the runtime, returning the new native peer. 104462c94449720e0dc6b93d7138d835d345ccf67aeElliott Hughes // Used to implement JNI AttachCurrentThread and AttachCurrentThreadAsDaemon calls. 105462c94449720e0dc6b93d7138d835d345ccf67aeElliott Hughes static Thread* Attach(const char* thread_name, bool as_daemon, Object* thread_group); 106b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro 107caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom // Reset internal state of child thread after fork. 108caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom void InitAfterFork(); 109caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom 110b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro static Thread* Current() { 111d0e7e777c412071a911dd2c008b20b7d879fd392Carl Shapiro void* thread = pthread_getspecific(Thread::pthread_key_self_); 112d0e7e777c412071a911dd2c008b20b7d879fd392Carl Shapiro return reinterpret_cast<Thread*>(thread); 1130e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro } 1140e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro 115761928d24e4e7ed7776b52243eaf9095ad35f448Elliott Hughes static Thread* FromManagedThread(Object* thread_peer); 11601158d7a57c8321370667a6045220237d16e0da8Elliott Hughes static Thread* FromManagedThread(JNIEnv* env, jobject thread); 1178e4aac52962d54cb4be2078b9cd95685e067133aElliott Hughes static uint32_t LockOwnerFromThreadLock(Object* thread_lock); 1188daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes 119899e789bd4741c0172268f7838ce8ab220a5f916Elliott Hughes // When full == true, dumps the detailed thread state and the thread stack (used for SIGQUIT). 120899e789bd4741c0172268f7838ce8ab220a5f916Elliott Hughes // When full == false, dumps a one-line summary of thread state (used for operator<<). 121899e789bd4741c0172268f7838ce8ab220a5f916Elliott Hughes void Dump(std::ostream& os, bool full = true) const; 122a09576416788b916095739e43a16917e7948f3a4Elliott Hughes 1230cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers State GetState() const { 1240cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers return state_; 1250cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers } 1260cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers 1278d768a954b101a9532f980253ac46be2c53aba11Elliott Hughes State SetState(State new_state); 128a4060e5fe4729fa30bde965efc35779690478fa4Elliott Hughes void SetStateWithoutSuspendCheck(State new_state); 1298d768a954b101a9532f980253ac46be2c53aba11Elliott Hughes 130038a806df72f884d22283a84a31c9a1d35ba1fdfElliott Hughes bool IsDaemon(); 131761928d24e4e7ed7776b52243eaf9095ad35f448Elliott Hughes bool IsSuspended(); 132038a806df72f884d22283a84a31c9a1d35ba1fdfElliott Hughes 1338d768a954b101a9532f980253ac46be2c53aba11Elliott Hughes void WaitUntilSuspended(); 1340cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers 1355f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes bool HoldsLock(Object*); 1365f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes 1378daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes /* 1388daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes * Changes the priority of this thread to match that of the java.lang.Thread object. 1398daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes * 1408daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes * We map a priority value from 1-10 to Linux "nice" values, where lower 1418daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes * numbers indicate higher priority. 1428daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes */ 1438daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes void SetNativePriority(int newPriority); 1448daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes 1458daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes /* 1468daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes * Returns the thread priority for the current thread by querying the system. 1478daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes * This is useful when attaching a thread through JNI. 1488daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes * 1498daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes * Returns a value from 1 to 10 (compatible with java.lang.Thread values). 1508daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes */ 1518daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes static int GetNativePriority(); 1528daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes 153462c94449720e0dc6b93d7138d835d345ccf67aeElliott Hughes // Returns the "main" ThreadGroup, used when attaching user threads. 154462c94449720e0dc6b93d7138d835d345ccf67aeElliott Hughes static Object* GetMainThreadGroup(); 155462c94449720e0dc6b93d7138d835d345ccf67aeElliott Hughes // Returns the "system" ThreadGroup, used when attaching our internal threads. 156462c94449720e0dc6b93d7138d835d345ccf67aeElliott Hughes static Object* GetSystemThreadGroup(); 157462c94449720e0dc6b93d7138d835d345ccf67aeElliott Hughes 1580cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers bool CanAccessDirectReferences() const { 159caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom#ifdef MOVING_GARBAGE_COLLECTOR 160a59d1793b89d0fd62c7544c94da4b6e5dac95ad5Elliott Hughes // TODO: when we have a moving collector, we'll need: return state_ == kRunnable; 161caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom#endif 162a59d1793b89d0fd62c7544c94da4b6e5dac95ad5Elliott Hughes return true; 1630cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers } 1640cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers 165dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes uint32_t GetThinLockId() const { 166dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes return thin_lock_id_; 167b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro } 168b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro 169d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes pid_t GetTid() const { 170d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes return tid_; 171d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes } 172e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes 173ffb465f23d9549dd591e6aa62e9250523cb00233Elliott Hughes // Returns the java.lang.Thread's name, or NULL if this Thread* doesn't have a peer. 174899e789bd4741c0172268f7838ce8ab220a5f916Elliott Hughes String* GetThreadName() const; 175899e789bd4741c0172268f7838ce8ab220a5f916Elliott Hughes 176ffb465f23d9549dd591e6aa62e9250523cb00233Elliott Hughes // Sets 'name' to the java.lang.Thread's name. This requires no transition to managed code, 177ffb465f23d9549dd591e6aa62e9250523cb00233Elliott Hughes // allocation, or locking. 178ffb465f23d9549dd591e6aa62e9250523cb00233Elliott Hughes void GetThreadName(std::string& name) const; 179ffb465f23d9549dd591e6aa62e9250523cb00233Elliott Hughes 180899e789bd4741c0172268f7838ce8ab220a5f916Elliott Hughes // Sets the thread's name. 181899e789bd4741c0172268f7838ce8ab220a5f916Elliott Hughes void SetThreadName(const char* name); 182fc86162ce2a3467acb690e18cc8bd9b3daafc606Elliott Hughes 183d369bb76dee0df2d2a106e9bf7f4e6446ed6deaaElliott Hughes Object* GetPeer() const { 1848daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes return peer_; 1858daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes } 1868daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes 187a215526d5c789cbef0f81a1f9aba22541a841ccaElliott Hughes Object* GetThreadGroup() const; 188a215526d5c789cbef0f81a1f9aba22541a841ccaElliott Hughes 1899d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes RuntimeStats* GetStats() { 1909d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes return &stats_; 1919d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes } 1929d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes 193d07986fad0d08cdf05505cf9230714a2cf0dd9aeElliott Hughes int GetSuspendCount() const { 194d07986fad0d08cdf05505cf9230714a2cf0dd9aeElliott Hughes return suspend_count_; 195d07986fad0d08cdf05505cf9230714a2cf0dd9aeElliott Hughes } 1960cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers 197d07986fad0d08cdf05505cf9230714a2cf0dd9aeElliott Hughes // Returns the current Method* and native PC (not dex PC) for this thread. 198d07986fad0d08cdf05505cf9230714a2cf0dd9aeElliott Hughes Method* GetCurrentMethod(uintptr_t* pc = NULL, Method*** sp = NULL) const; 19933dc7717cd16592bcc825350bea6305be9eb2ea1jeffhao 2000e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro bool IsExceptionPending() const { 201b20a554613609dc372073d2ebd9fbc3925a429f5Elliott Hughes return exception_ != NULL; 2020e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro } 2030e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro 204e5b0dc83537bf915c6abe4efeae6e501daf75a27Elliott Hughes Throwable* GetException() const { 2050cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers DCHECK(CanAccessDirectReferences()); 2060e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro return exception_; 2070e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro } 2080e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro 2090cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers void SetException(Throwable* new_exception) { 2100cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers DCHECK(CanAccessDirectReferences()); 2110cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers CHECK(new_exception != NULL); 2120cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers // TODO: CHECK(exception_ == NULL); 2130cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers exception_ = new_exception; // TODO 2140cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers } 2150cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers 2160cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers void ClearException() { 2170cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers exception_ = NULL; 218a09576416788b916095739e43a16917e7948f3a4Elliott Hughes } 219a09576416788b916095739e43a16917e7948f3a4Elliott Hughes 220bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers // Find catch block and perform long jump to appropriate exception handle 221ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers void DeliverException(); 222bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers 223bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers Context* GetLongJumpContext(); 224bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers 2251a18c8c1c0e4ea1ff06177e93c7ff703376dcee2Shih-wei Liao Frame GetTopOfStack() const { 2261a18c8c1c0e4ea1ff06177e93c7ff703376dcee2Shih-wei Liao return top_of_managed_stack_; 2271a18c8c1c0e4ea1ff06177e93c7ff703376dcee2Shih-wei Liao } 2281a18c8c1c0e4ea1ff06177e93c7ff703376dcee2Shih-wei Liao 2291a18c8c1c0e4ea1ff06177e93c7ff703376dcee2Shih-wei Liao // TODO: this is here for testing, remove when we have exception unit tests 2301a18c8c1c0e4ea1ff06177e93c7ff703376dcee2Shih-wei Liao // that use the real stack 231bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers void SetTopOfStack(void* stack, uintptr_t pc) { 2320cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers top_of_managed_stack_.SetSP(reinterpret_cast<Method**>(stack)); 233bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers top_of_managed_stack_pc_ = pc; 2340e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro } 2350e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro 236bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers void SetTopOfStackPC(uintptr_t pc) { 237bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers top_of_managed_stack_pc_ = pc; 238bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers } 239bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers 2405cb5ad27944efb08d4556b3c0d362302e37e832bElliott Hughes // 'msg' may be NULL. 2415cb5ad27944efb08d4556b3c0d362302e37e832bElliott Hughes void ThrowNewException(const char* exception_class_descriptor, const char* msg); 2425cb5ad27944efb08d4556b3c0d362302e37e832bElliott Hughes 2435cb5ad27944efb08d4556b3c0d362302e37e832bElliott Hughes void ThrowNewExceptionF(const char* exception_class_descriptor, const char* fmt, ...) 244362f9bc807169bcfc8761dde067bbfb79b5ad0fdElliott Hughes __attribute__((format(printf, 3, 4))); 245a5b897eae4b6f9f9608faa9eada7ddf42bf1bfd2Elliott Hughes 2464a2b41793d18d402286ae37e9de4fd392bc75a08Elliott Hughes void ThrowNewExceptionV(const char* exception_class_descriptor, const char* fmt, va_list ap); 2474a2b41793d18d402286ae37e9de4fd392bc75a08Elliott Hughes 2482ced6a534157d5d963693346904389c19775d2daElliott Hughes // OutOfMemoryError is special, because we need to pre-allocate an instance. 2492ced6a534157d5d963693346904389c19775d2daElliott Hughes void ThrowOutOfMemoryError(const char* msg); 250418dfe7849f45535b5388a91bd7a16cfc20a612bElliott Hughes void ThrowOutOfMemoryError(Class* c, size_t byte_count); 25179082e367845bbd68ec44ef2ddd1be8ef0e1550fElliott Hughes 2521a18c8c1c0e4ea1ff06177e93c7ff703376dcee2Shih-wei Liao Frame FindExceptionHandler(void* throw_pc, void** handler_pc); 2531a18c8c1c0e4ea1ff06177e93c7ff703376dcee2Shih-wei Liao 2541a18c8c1c0e4ea1ff06177e93c7ff703376dcee2Shih-wei Liao void* FindExceptionHandlerInMethod(const Method* method, 2551a18c8c1c0e4ea1ff06177e93c7ff703376dcee2Shih-wei Liao void* throw_pc, 2561a18c8c1c0e4ea1ff06177e93c7ff703376dcee2Shih-wei Liao const DexFile& dex_file, 2571a18c8c1c0e4ea1ff06177e93c7ff703376dcee2Shih-wei Liao ClassLinker* class_linker); 258c143c55718342519db5398e41dda31422cf16c79buzbee 259be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes static void Startup(); 260038a806df72f884d22283a84a31c9a1d35ba1fdfElliott Hughes static void FinishStartup(); 261c1674ed06662420213441ff2b818f2f71f9098dcElliott Hughes static void Shutdown(); 262b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro 263b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers // JNI methods 26469f5bc6759f256a146eefd8a7141d39fcc3b0421Elliott Hughes JNIEnvExt* GetJniEnv() const { 265b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers return jni_env_; 266b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers } 267b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers 268408f79aeb676251ba35667a64e86c20638d7cb0bIan Rogers // Number of references allocated in SIRTs on this thread 269408f79aeb676251ba35667a64e86c20638d7cb0bIan Rogers size_t NumSirtReferences(); 270a8cd9f4a849835af7856f9c9782ea59e11ddef85Ian Rogers 271408f79aeb676251ba35667a64e86c20638d7cb0bIan Rogers // Is the given obj in this thread's stack indirect reference table? 272408f79aeb676251ba35667a64e86c20638d7cb0bIan Rogers bool SirtContains(jobject obj); 273408f79aeb676251ba35667a64e86c20638d7cb0bIan Rogers 2748dfc9d551a9603eb8bc8463621b7bc73c3035169Shih-wei Liao void SirtVisitRoots(Heap::RootVisitor* visitor, void* arg); 2758dfc9d551a9603eb8bc8463621b7bc73c3035169Shih-wei Liao 276f7ad17e108b9357d7c94c6218a8521140a667f3dLogan Chien void ShadowFrameVisitRoots(Heap::RootVisitor* visitor, void* arg); 277f7ad17e108b9357d7c94c6218a8521140a667f3dLogan Chien 278408f79aeb676251ba35667a64e86c20638d7cb0bIan Rogers // Convert a jobject into a Object* 279408f79aeb676251ba35667a64e86c20638d7cb0bIan Rogers Object* DecodeJObject(jobject obj); 280b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers 2818daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes // Implements java.lang.Thread.interrupted. 2828daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes bool Interrupted() { 28385d1545e985ac689db4bad7849880e843707c862Elliott Hughes MutexLock mu(*wait_mutex_); 2848daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes bool interrupted = interrupted_; 2858daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes interrupted_ = false; 2868daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes return interrupted; 2878daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes } 2888daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes 2898daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes // Implements java.lang.Thread.isInterrupted. 2908daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes bool IsInterrupted() { 29185d1545e985ac689db4bad7849880e843707c862Elliott Hughes MutexLock mu(*wait_mutex_); 2928daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes return interrupted_; 2938daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes } 2948daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes 2955f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes void Interrupt() { 29685d1545e985ac689db4bad7849880e843707c862Elliott Hughes MutexLock mu(*wait_mutex_); 2975f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes if (interrupted_) { 2985f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes return; 2995f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes } 3005f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes interrupted_ = true; 3015f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes NotifyLocked(); 3025f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes } 3035f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes 3045f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes void Notify() { 30585d1545e985ac689db4bad7849880e843707c862Elliott Hughes MutexLock mu(*wait_mutex_); 3065f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes NotifyLocked(); 3075f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes } 3085f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes 3096de0860c491d390b7a53be436519ef2d9234c4c9Ian Rogers // Linked list recording transitions from native to managed code 310b04f69f90d2594092bec5b294bbe7329d295bd66Ian Rogers void PushNativeToManagedRecord(NativeToManagedRecord* record); 311b04f69f90d2594092bec5b294bbe7329d295bd66Ian Rogers void PopNativeToManagedRecord(const NativeToManagedRecord& record); 3126de0860c491d390b7a53be436519ef2d9234c4c9Ian Rogers 313bffb15585b8fd43d3ca534ddbb85e7f591595951Brian Carlstrom const ClassLoader* GetClassLoaderOverride() { 3140cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers // TODO: need to place the class_loader_override_ in a handle 3150cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers // DCHECK(CanAccessDirectReferences()); 316c143c55718342519db5398e41dda31422cf16c79buzbee return class_loader_override_; 317c143c55718342519db5398e41dda31422cf16c79buzbee } 318c143c55718342519db5398e41dda31422cf16c79buzbee 319bffb15585b8fd43d3ca534ddbb85e7f591595951Brian Carlstrom void SetClassLoaderOverride(const ClassLoader* class_loader_override) { 320c143c55718342519db5398e41dda31422cf16c79buzbee class_loader_override_ = class_loader_override; 321c143c55718342519db5398e41dda31422cf16c79buzbee } 322c143c55718342519db5398e41dda31422cf16c79buzbee 323aaa208006d7c8cc0f381c4aa9b525be24066c495Ian Rogers // Create the internal representation of a stack trace, that is more time 324aaa208006d7c8cc0f381c4aa9b525be24066c495Ian Rogers // and space efficient to compute than the StackTraceElement[] 32501158d7a57c8321370667a6045220237d16e0da8Elliott Hughes jobject CreateInternalStackTrace(JNIEnv* env) const; 32601158d7a57c8321370667a6045220237d16e0da8Elliott Hughes 32701158d7a57c8321370667a6045220237d16e0da8Elliott Hughes // Convert an internal stack trace representation (returned by CreateInternalStackTrace) to a 32801158d7a57c8321370667a6045220237d16e0da8Elliott Hughes // StackTraceElement[]. If output_array is NULL, a new array is created, otherwise as many 32901158d7a57c8321370667a6045220237d16e0da8Elliott Hughes // frames as will fit are written into the given array. If stack_depth is non-NULL, it's updated 33001158d7a57c8321370667a6045220237d16e0da8Elliott Hughes // with the number of valid frames in the returned array. 33101158d7a57c8321370667a6045220237d16e0da8Elliott Hughes static jobjectArray InternalStackTraceToStackTraceElementArray(JNIEnv* env, jobject internal, 33201158d7a57c8321370667a6045220237d16e0da8Elliott Hughes jobjectArray output_array = NULL, int* stack_depth = NULL); 33355df06be4369f5d8ab5eb61a5d22809255171036Shih-wei Liao 334d6b1f6190c8ec42facb08aca34b093244774b318Ian Rogers void VisitRoots(Heap::RootVisitor* visitor, void* arg); 335410c0c876f326e14c176a39ba21fc4dd3f7db8abElliott Hughes 336250455229aa0cc07bbd18174efe510bd52631a99jeffhao#if VERIFY_OBJECT_ENABLED 337250455229aa0cc07bbd18174efe510bd52631a99jeffhao void VerifyStack(); 338250455229aa0cc07bbd18174efe510bd52631a99jeffhao#else 339250455229aa0cc07bbd18174efe510bd52631a99jeffhao void VerifyStack() {} 340250455229aa0cc07bbd18174efe510bd52631a99jeffhao#endif 341250455229aa0cc07bbd18174efe510bd52631a99jeffhao 342be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes // 343be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes // Offsets of various members of native Thread class, used by compiled code. 344be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes // 345be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes 346be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes static ThreadOffset SelfOffset() { 347be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes return ThreadOffset(OFFSETOF_MEMBER(Thread, self_)); 348be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes } 349be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes 350be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes static ThreadOffset ExceptionOffset() { 351be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes return ThreadOffset(OFFSETOF_MEMBER(Thread, exception_)); 352be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes } 353be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes 35454e7df1896a4066cbb9fe6f72249829f0b8c49c6Elliott Hughes static ThreadOffset ThinLockIdOffset() { 355be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes return ThreadOffset(OFFSETOF_MEMBER(Thread, thin_lock_id_)); 356be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes } 357be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes 358be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes static ThreadOffset CardTableOffset() { 359be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes return ThreadOffset(OFFSETOF_MEMBER(Thread, card_table_)); 360be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes } 361be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes 362be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes static ThreadOffset SuspendCountOffset() { 363be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes return ThreadOffset(OFFSETOF_MEMBER(Thread, suspend_count_)); 364be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes } 365be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes 366be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes static ThreadOffset StateOffset() { 36793e74e8d879270071c3aa163f8495ada8d21f42fElliott Hughes return ThreadOffset(OFFSETOF_VOLATILE_MEMBER(Thread, state_)); 368be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes } 369be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes 370932746a4f22951abcba7b7c4c94c27b1bf164272Ian Rogers // Size of stack less any space reserved for stack overflow 371932746a4f22951abcba7b7c4c94c27b1bf164272Ian Rogers size_t GetStackSize() { 37230fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers return stack_size_ - (stack_end_ - stack_begin_); 373932746a4f22951abcba7b7c4c94c27b1bf164272Ian Rogers } 374932746a4f22951abcba7b7c4c94c27b1bf164272Ian Rogers 375932746a4f22951abcba7b7c4c94c27b1bf164272Ian Rogers // Set the stack end to that to be used during a stack overflow 376932746a4f22951abcba7b7c4c94c27b1bf164272Ian Rogers void SetStackEndForStackOverflow() { 377932746a4f22951abcba7b7c4c94c27b1bf164272Ian Rogers // During stack overflow we allow use of the full stack 37830fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers if (stack_end_ == stack_begin_) { 3793b6baaa203fa63f1522b2172a1645f90412afdaeElliott Hughes DumpStack(std::cerr); 3803b6baaa203fa63f1522b2172a1645f90412afdaeElliott Hughes LOG(FATAL) << "Need to increase kStackOverflowReservedBytes (currently " 3813b6baaa203fa63f1522b2172a1645f90412afdaeElliott Hughes << kStackOverflowReservedBytes << ")"; 3823b6baaa203fa63f1522b2172a1645f90412afdaeElliott Hughes } 3833b6baaa203fa63f1522b2172a1645f90412afdaeElliott Hughes 38430fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers stack_end_ = stack_begin_; 385932746a4f22951abcba7b7c4c94c27b1bf164272Ian Rogers } 386932746a4f22951abcba7b7c4c94c27b1bf164272Ian Rogers 387932746a4f22951abcba7b7c4c94c27b1bf164272Ian Rogers // Set the stack end to that to be used during regular execution 388932746a4f22951abcba7b7c4c94c27b1bf164272Ian Rogers void ResetDefaultStackEnd() { 389932746a4f22951abcba7b7c4c94c27b1bf164272Ian Rogers // Our stacks grow down, so we want stack_end_ to be near there, but reserving enough room 390932746a4f22951abcba7b7c4c94c27b1bf164272Ian Rogers // to throw a StackOverflowError. 39130fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers stack_end_ = stack_begin_ + kStackOverflowReservedBytes; 392932746a4f22951abcba7b7c4c94c27b1bf164272Ian Rogers } 393932746a4f22951abcba7b7c4c94c27b1bf164272Ian Rogers 394449b4bdf90b527ef7a42faaf087494538e62363cElliott Hughes static ThreadOffset StackEndOffset() { 395449b4bdf90b527ef7a42faaf087494538e62363cElliott Hughes return ThreadOffset(OFFSETOF_MEMBER(Thread, stack_end_)); 396be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes } 397be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes 398be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes static ThreadOffset JniEnvOffset() { 399be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes return ThreadOffset(OFFSETOF_MEMBER(Thread, jni_env_)); 400be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes } 401be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes 402be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes static ThreadOffset TopOfManagedStackOffset() { 403be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes return ThreadOffset(OFFSETOF_MEMBER(Thread, top_of_managed_stack_) + 404be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes OFFSETOF_MEMBER(Frame, sp_)); 405be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes } 406be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes 407bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers static ThreadOffset TopOfManagedStackPcOffset() { 408bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers return ThreadOffset(OFFSETOF_MEMBER(Thread, top_of_managed_stack_pc_)); 409bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers } 410bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers 411f7ad17e108b9357d7c94c6218a8521140a667f3dLogan Chien void PushShadowFrame(ShadowFrame* frame); 412f7ad17e108b9357d7c94c6218a8521140a667f3dLogan Chien ShadowFrame* PopShadowFrame(); 413f7ad17e108b9357d7c94c6218a8521140a667f3dLogan Chien 41440381fb9dc4b4cf274f1e58b2cdf4396202c6189Brian Carlstrom void PushSirt(StackIndirectReferenceTable* sirt); 41540381fb9dc4b4cf274f1e58b2cdf4396202c6189Brian Carlstrom StackIndirectReferenceTable* PopSirt(); 41640381fb9dc4b4cf274f1e58b2cdf4396202c6189Brian Carlstrom 417be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes static ThreadOffset TopSirtOffset() { 418be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes return ThreadOffset(OFFSETOF_MEMBER(Thread, top_sirt_)); 419be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes } 420be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes 421530fa005e2944d3b12712f80d974f0e753f568efElliott Hughes void WalkStack(StackVisitor* visitor, bool include_upcalls = false) const; 4229407c60800c95902fba0b3c3265520d47c1e7052Shih-wei Liao 423475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes DebugInvokeReq* GetInvokeReq() { 424475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes return debug_invoke_req_; 425475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes } 426475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes 427c0f0933249cf516b37717faa766e1e9808f7c1f8Elliott Hughes void SetDebuggerUpdatesEnabled(bool enabled); 428c0f0933249cf516b37717faa766e1e9808f7c1f8Elliott Hughes 429e343b76af81a005ef64f5e75a555389fd9147dabjeffhao bool IsTraceStackEmpty() const { 430e343b76af81a005ef64f5e75a555389fd9147dabjeffhao return trace_stack_->empty(); 431e343b76af81a005ef64f5e75a555389fd9147dabjeffhao } 432e343b76af81a005ef64f5e75a555389fd9147dabjeffhao 433a9ef3fd82bebc6370fc3ddbb094988feb6c83022jeffhao TraceStackFrame GetTraceStackFrame(uint32_t depth) const { 434a9ef3fd82bebc6370fc3ddbb094988feb6c83022jeffhao return trace_stack_->at(trace_stack_->size() - depth - 1); 435a9ef3fd82bebc6370fc3ddbb094988feb6c83022jeffhao } 436a9ef3fd82bebc6370fc3ddbb094988feb6c83022jeffhao 437e343b76af81a005ef64f5e75a555389fd9147dabjeffhao void PushTraceStackFrame(const TraceStackFrame& frame) { 438e343b76af81a005ef64f5e75a555389fd9147dabjeffhao trace_stack_->push_back(frame); 439e343b76af81a005ef64f5e75a555389fd9147dabjeffhao } 440e343b76af81a005ef64f5e75a555389fd9147dabjeffhao 441e343b76af81a005ef64f5e75a555389fd9147dabjeffhao TraceStackFrame PopTraceStackFrame() { 442e343b76af81a005ef64f5e75a555389fd9147dabjeffhao TraceStackFrame frame = trace_stack_->back(); 443e343b76af81a005ef64f5e75a555389fd9147dabjeffhao trace_stack_->pop_back(); 444e343b76af81a005ef64f5e75a555389fd9147dabjeffhao return frame; 445e343b76af81a005ef64f5e75a555389fd9147dabjeffhao } 446e343b76af81a005ef64f5e75a555389fd9147dabjeffhao 447a4060e5fe4729fa30bde965efc35779690478fa4Elliott Hughes void CheckSafeToLockOrUnlock(MutexRank rank, bool is_locking); 448a4060e5fe4729fa30bde965efc35779690478fa4Elliott Hughes void CheckSafeToWait(MutexRank rank); 449ffb465f23d9549dd591e6aa62e9250523cb00233Elliott Hughes 4500e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro private: 451dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes Thread(); 452c1674ed06662420213441ff2b818f2f71f9098dcElliott Hughes ~Thread(); 453c0f0933249cf516b37717faa766e1e9808f7c1f8Elliott Hughes void Destroy(); 454c0f0933249cf516b37717faa766e1e9808f7c1f8Elliott Hughes friend class ThreadList; // For ~Thread and Destroy. 4550e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro 456462c94449720e0dc6b93d7138d835d345ccf67aeElliott Hughes void CreatePeer(const char* name, bool as_daemon, Object* thread_group); 4575fe594f576225dd7d333835e39c448a71ea9b433Elliott Hughes friend class Runtime; // For CreatePeer. 4585fe594f576225dd7d333835e39c448a71ea9b433Elliott Hughes 459d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes void DumpState(std::ostream& os) const; 460d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes void DumpStack(std::ostream& os) const; 461ffb465f23d9549dd591e6aa62e9250523cb00233Elliott Hughes void DumpNativeStack(std::ostream& os) const; 462d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes 463accd83d1523545ac69bafd38e72a7d5cff8e2facElliott Hughes // Out-of-line conveniences for debugging in gdb. 464498508c1187dc07d3eae5476784cde20f5224d93Elliott Hughes static Thread* CurrentFromGdb(); // Like Thread::Current. 465accd83d1523545ac69bafd38e72a7d5cff8e2facElliott Hughes void DumpFromGdb() const; // Like Thread::Dump(std::cerr). 466accd83d1523545ac69bafd38e72a7d5cff8e2facElliott Hughes 46793e74e8d879270071c3aa163f8495ada8d21f42fElliott Hughes static void* CreateCallback(void* arg); 46893e74e8d879270071c3aa163f8495ada8d21f42fElliott Hughes 469accd83d1523545ac69bafd38e72a7d5cff8e2facElliott Hughes void HandleUncaughtExceptions(); 4704514d3c0e69a49f5dbe19138330a2bb2aee36d63Brian Carlstrom void RemoveFromThreadGroup(); 471accd83d1523545ac69bafd38e72a7d5cff8e2facElliott Hughes 472462c94449720e0dc6b93d7138d835d345ccf67aeElliott Hughes void Init(); 4735d76c435082332ef79a22962386fa92a0870e378Ian Rogers void InitCardTable(); 474b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers void InitCpu(); 4753ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee void InitFunctionPointers(); 476caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom void InitTid(); 477caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom void InitPthreadKeySelf(); 478be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes void InitStackHwm(); 479be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes 4805f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes void NotifyLocked() { 4815f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes if (wait_monitor_ != NULL) { 48285d1545e985ac689db4bad7849880e843707c862Elliott Hughes wait_cond_->Signal(); 4835f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes } 4845f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes } 4855f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes 486be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes static void ThreadExitCallback(void* arg); 487b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers 488dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes // Thin lock thread id. This is a small integer used by the thin lock implementation. 489dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes // This is not to be confused with the native thread's tid, nor is it the value returned 490dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes // by java.lang.Thread.getId --- this is a distinct value, used only for locking. One 491dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes // important difference between this id and the ids visible to managed code is that these 492dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes // ones get reused (to ensure that they fit in the number of bits available). 493dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes uint32_t thin_lock_id_; 494b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers 495d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes // System thread id. 496d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes pid_t tid_; 497d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes 498dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes // Our managed peer (an instance of java.lang.Thread). 499d369bb76dee0df2d2a106e9bf7f4e6446ed6deaaElliott Hughes Object* peer_; 5008daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes 5018e4aac52962d54cb4be2078b9cd95685e067133aElliott Hughes // The top_of_managed_stack_ and top_of_managed_stack_pc_ fields are accessed from 5028e4aac52962d54cb4be2078b9cd95685e067133aElliott Hughes // compiled code, so we keep them early in the structure to (a) avoid having to keep 5038e4aac52962d54cb4be2078b9cd95685e067133aElliott Hughes // fixing the assembler offsets and (b) improve the chances that these will still be aligned. 5048e4aac52962d54cb4be2078b9cd95685e067133aElliott Hughes 5058e4aac52962d54cb4be2078b9cd95685e067133aElliott Hughes // Top of the managed stack, written out prior to the state transition from 50668e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes // kRunnable to kNative. Uses include giving the starting point for scanning 5078e4aac52962d54cb4be2078b9cd95685e067133aElliott Hughes // a managed stack when a thread is in native code. 5088e4aac52962d54cb4be2078b9cd95685e067133aElliott Hughes Frame top_of_managed_stack_; 5098e4aac52962d54cb4be2078b9cd95685e067133aElliott Hughes // PC corresponding to the call out of the top_of_managed_stack_ frame 5108e4aac52962d54cb4be2078b9cd95685e067133aElliott Hughes uintptr_t top_of_managed_stack_pc_; 5118e4aac52962d54cb4be2078b9cd95685e067133aElliott Hughes 5128daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes // Guards the 'interrupted_' and 'wait_monitor_' members. 51385d1545e985ac689db4bad7849880e843707c862Elliott Hughes mutable Mutex* wait_mutex_; 51485d1545e985ac689db4bad7849880e843707c862Elliott Hughes ConditionVariable* wait_cond_; 5158daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes // Pointer to the monitor lock we're currently waiting on (or NULL), guarded by wait_mutex_. 5168daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes Monitor* wait_monitor_; 5178daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes // Thread "interrupted" status; stays raised until queried or thrown, guarded by wait_mutex_. 5188e4aac52962d54cb4be2078b9cd95685e067133aElliott Hughes uint32_t interrupted_; 5195f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes // The next thread in the wait set this thread is part of. 5205f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes Thread* wait_next_; 5218e4aac52962d54cb4be2078b9cd95685e067133aElliott Hughes // If we're blocked in MonitorEnter, this is the object we're trying to lock. 5228e4aac52962d54cb4be2078b9cd95685e067133aElliott Hughes Object* monitor_enter_object_; 5235f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes 5245f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes friend class Monitor; 525dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes 5269d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes RuntimeStats stats_; 5279d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes 5285d76c435082332ef79a22962386fa92a0870e378Ian Rogers // The biased card table, see CardTable for details 5295d76c435082332ef79a22962386fa92a0870e378Ian Rogers byte* card_table_; 530c143c55718342519db5398e41dda31422cf16c79buzbee 531449b4bdf90b527ef7a42faaf087494538e62363cElliott Hughes // The end of this thread's stack. This is the lowest safely-addressable address on the stack. 532449b4bdf90b527ef7a42faaf087494538e62363cElliott Hughes // We leave extra space so there's room for the code that throws StackOverflowError. 533449b4bdf90b527ef7a42faaf087494538e62363cElliott Hughes byte* stack_end_; 534be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes 535932746a4f22951abcba7b7c4c94c27b1bf164272Ian Rogers // Size of the stack 536932746a4f22951abcba7b7c4c94c27b1bf164272Ian Rogers size_t stack_size_; 537932746a4f22951abcba7b7c4c94c27b1bf164272Ian Rogers 538932746a4f22951abcba7b7c4c94c27b1bf164272Ian Rogers // The "lowest addressable byte" of the stack 53930fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers byte* stack_begin_; 540932746a4f22951abcba7b7c4c94c27b1bf164272Ian Rogers 5416de0860c491d390b7a53be436519ef2d9234c4c9Ian Rogers // A linked list (of stack allocated records) recording transitions from 5426de0860c491d390b7a53be436519ef2d9234c4c9Ian Rogers // native to managed code. 5436de0860c491d390b7a53be436519ef2d9234c4c9Ian Rogers NativeToManagedRecord* native_to_managed_record_; 5446de0860c491d390b7a53be436519ef2d9234c4c9Ian Rogers 545408f79aeb676251ba35667a64e86c20638d7cb0bIan Rogers // Top of linked list of stack indirect reference tables or NULL for none 546408f79aeb676251ba35667a64e86c20638d7cb0bIan Rogers StackIndirectReferenceTable* top_sirt_; 547b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers 548f7ad17e108b9357d7c94c6218a8521140a667f3dLogan Chien // Top of linked list of shadow stack or NULL for none 549f7ad17e108b9357d7c94c6218a8521140a667f3dLogan Chien // Some backend may require shadow frame to ease the GC work. 550f7ad17e108b9357d7c94c6218a8521140a667f3dLogan Chien ShadowFrame* top_shadow_frame_; 551f7ad17e108b9357d7c94c6218a8521140a667f3dLogan Chien 552b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers // Every thread may have an associated JNI environment 55369f5bc6759f256a146eefd8a7141d39fcc3b0421Elliott Hughes JNIEnvExt* jni_env_; 554b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers 55593e74e8d879270071c3aa163f8495ada8d21f42fElliott Hughes volatile State state_; 556b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro 55769759eaa6fd4386f1e6d8748052ad221087b3476Carl Shapiro // Initialized to "this". On certain architectures (such as x86) reading 55869759eaa6fd4386f1e6d8748052ad221087b3476Carl Shapiro // off of Thread::Current is easy but getting the address of Thread::Current 55969759eaa6fd4386f1e6d8748052ad221087b3476Carl Shapiro // is hard. This field can be read off of Thread::Current to give the address. 56069759eaa6fd4386f1e6d8748052ad221087b3476Carl Shapiro Thread* self_; 56169759eaa6fd4386f1e6d8748052ad221087b3476Carl Shapiro 56269759eaa6fd4386f1e6d8748052ad221087b3476Carl Shapiro Runtime* runtime_; 56369759eaa6fd4386f1e6d8748052ad221087b3476Carl Shapiro 56469759eaa6fd4386f1e6d8748052ad221087b3476Carl Shapiro // The pending exception or NULL. 565e5b0dc83537bf915c6abe4efeae6e501daf75a27Elliott Hughes Throwable* exception_; 5660e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro 56745a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers // A non-zero value is used to tell the current thread to enter a safe point 56845a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers // at the next poll. 56945a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers int suspend_count_; 570234ab15b00f8120282d1833e5d7480eca2e35a29Elliott Hughes // How much of 'suspend_count_' is by request of the debugger, used to set things right 571234ab15b00f8120282d1833e5d7480eca2e35a29Elliott Hughes // when the debugger detaches. Must be <= suspend_count_. 572234ab15b00f8120282d1833e5d7480eca2e35a29Elliott Hughes int debug_suspend_count_; 57345a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers 574edcc09c737b00462881f147602656739d029571eElliott Hughes // Needed to get the right ClassLoader in JNI_OnLoad, but also 575edcc09c737b00462881f147602656739d029571eElliott Hughes // useful for testing. 576bffb15585b8fd43d3ca534ddbb85e7f591595951Brian Carlstrom const ClassLoader* class_loader_override_; 577c143c55718342519db5398e41dda31422cf16c79buzbee 578bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers // Thread local, lazily allocated, long jump context. Used to deliver exceptions. 57985d1545e985ac689db4bad7849880e843707c862Elliott Hughes Context* long_jump_context_; 580bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers 581418dfe7849f45535b5388a91bd7a16cfc20a612bElliott Hughes // A boolean telling us whether we're recursively throwing OOME. 582726079d3e2e50854cd6ca4c393f4529a796dba58Elliott Hughes uint32_t throwing_OutOfMemoryError_; 583726079d3e2e50854cd6ca4c393f4529a796dba58Elliott Hughes 584726079d3e2e50854cd6ca4c393f4529a796dba58Elliott Hughes Throwable* pre_allocated_OutOfMemoryError_; 585418dfe7849f45535b5388a91bd7a16cfc20a612bElliott Hughes 586475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes // JDWP invoke-during-breakpoint support. 587475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes DebugInvokeReq* debug_invoke_req_; 588475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes 58981ff3184e7eb8de4605c7646674ea4f9fa29b5f3Elliott Hughes // TLS key used to retrieve the Thread*. 590b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro static pthread_key_t pthread_key_self_; 591b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro 592e343b76af81a005ef64f5e75a555389fd9147dabjeffhao // Additional stack used by method tracer to store method and return pc values. 593e343b76af81a005ef64f5e75a555389fd9147dabjeffhao // Stored as a pointer since std::vector is not PACKED. 594e343b76af81a005ef64f5e75a555389fd9147dabjeffhao std::vector<TraceStackFrame>* trace_stack_; 595e343b76af81a005ef64f5e75a555389fd9147dabjeffhao 596899e789bd4741c0172268f7838ce8ab220a5f916Elliott Hughes // A cached copy of the java.lang.Thread's name. 597899e789bd4741c0172268f7838ce8ab220a5f916Elliott Hughes std::string* name_; 598899e789bd4741c0172268f7838ce8ab220a5f916Elliott Hughes 599ffb465f23d9549dd591e6aa62e9250523cb00233Elliott Hughes uint32_t held_mutexes_[kMaxMutexRank + 1]; 600ffb465f23d9549dd591e6aa62e9250523cb00233Elliott Hughes 601a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers public: 602a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers // Runtime support function pointers 603a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pDebugMe)(Method*, uint32_t); 604a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void* (*pMemcpy)(void*, const void*, size_t); 605a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers uint64_t (*pShlLong)(uint64_t, uint32_t); 606a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers uint64_t (*pShrLong)(uint64_t, uint32_t); 607a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers uint64_t (*pUshrLong)(uint64_t, uint32_t); 608a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers float (*pI2f)(int); 609a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers int (*pF2iz)(float); 610a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers float (*pD2f)(double); 611a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers double (*pF2d)(float); 612a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers double (*pI2d)(int); 613a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers int (*pD2iz)(double); 614c6f3bb87ffbb44d902c4a1f67a71bb108bd01560Ian Rogers float (*pL2f)(int64_t); 615c6f3bb87ffbb44d902c4a1f67a71bb108bd01560Ian Rogers double (*pL2d)(int64_t); 616c6f3bb87ffbb44d902c4a1f67a71bb108bd01560Ian Rogers int64_t (*pF2l)(float); 617c6f3bb87ffbb44d902c4a1f67a71bb108bd01560Ian Rogers int64_t (*pD2l)(double); 618a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers float (*pFadd)(float, float); 619a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers float (*pFsub)(float, float); 620a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers float (*pFdiv)(float, float); 621a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers float (*pFmul)(float, float); 622a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers float (*pFmodf)(float, float); 623a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers double (*pDadd)(double, double); 624a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers double (*pDsub)(double, double); 625a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers double (*pDdiv)(double, double); 626a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers double (*pDmul)(double, double); 627a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers double (*pFmod)(double, double); 628a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers int (*pIdivmod)(int, int); 629a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers int (*pIdiv)(int, int); 630c6f3bb87ffbb44d902c4a1f67a71bb108bd01560Ian Rogers int64_t (*pLadd)(int64_t, int64_t); 631c6f3bb87ffbb44d902c4a1f67a71bb108bd01560Ian Rogers int64_t (*pLsub)(int64_t, int64_t); 632c6f3bb87ffbb44d902c4a1f67a71bb108bd01560Ian Rogers int64_t (*pLand)(int64_t, int64_t); 633c6f3bb87ffbb44d902c4a1f67a71bb108bd01560Ian Rogers int64_t (*pLor)(int64_t, int64_t); 634c6f3bb87ffbb44d902c4a1f67a71bb108bd01560Ian Rogers int64_t (*pLxor)(int64_t, int64_t); 635c6f3bb87ffbb44d902c4a1f67a71bb108bd01560Ian Rogers int64_t (*pLmul)(int64_t, int64_t); 636c6f3bb87ffbb44d902c4a1f67a71bb108bd01560Ian Rogers int64_t (*pLdivmod)(int64_t, int64_t); 637a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pCheckSuspendFromCode)(Thread*); // Stub that is called when the suspend count is non-zero 638a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pTestSuspendFromCode)(); // Stub that is periodically called to test the suspend count 639a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void* (*pAllocObjectFromCode)(uint32_t, void*); 640a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void* (*pAllocObjectFromCodeWithAccessCheck)(uint32_t, void*); 641a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void* (*pAllocArrayFromCode)(uint32_t, void*, int32_t); 642a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void* (*pAllocArrayFromCodeWithAccessCheck)(uint32_t, void*, int32_t); 643a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pCanPutArrayElementFromCode)(void*, void*); 644a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void* (*pCheckAndAllocArrayFromCode)(uint32_t, void*, int32_t); 645a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void* (*pCheckAndAllocArrayFromCodeWithAccessCheck)(uint32_t, void*, int32_t); 646a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pCheckCastFromCode)(void*, void*); 647a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers Object* (*pDecodeJObjectInThread)(Thread* thread, jobject obj); 648a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pDeliverException)(void*); 649a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers Method* (*pFindInterfaceMethodInCache)(Class*, uint32_t, const Method*, struct DvmDex*); 650a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void* (*pFindNativeMethod)(Thread* thread); 651a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers int32_t (*pGet32Instance)(uint32_t, void*); 652a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers int64_t (*pGet64Instance)(uint32_t, void*); 653a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void* (*pGetObjInstance)(uint32_t, void*); 654a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers int32_t (*pGet32Static)(uint32_t); 655a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers int64_t (*pGet64Static)(uint32_t); 656a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void* (*pGetObjStatic)(uint32_t); 657a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pHandleFillArrayDataFromCode)(void*, void*); 658a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void* (*pInitializeStaticStorage)(uint32_t, void*); 659a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers uint32_t (*pInstanceofNonTrivialFromCode)(const Class*, const Class*); 660c8b306f5221658c7e4b5516be8917dc8c9288e7eIan Rogers void (*pInvokeDirectTrampolineWithAccessCheck)(uint32_t, void*); 661a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pInvokeInterfaceTrampoline)(uint32_t, void*); 662a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pInvokeInterfaceTrampolineWithAccessCheck)(uint32_t, void*); 663c8b306f5221658c7e4b5516be8917dc8c9288e7eIan Rogers void (*pInvokeStaticTrampolineWithAccessCheck)(uint32_t, void*); 664a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pInvokeSuperTrampolineWithAccessCheck)(uint32_t, void*); 665a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pInvokeVirtualTrampolineWithAccessCheck)(uint32_t, void*); 666a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void* (*pInitializeTypeFromCode)(uint32_t, void*); 667a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void* (*pInitializeTypeAndVerifyAccessFromCode)(uint32_t, void*); 668a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pLockObjectFromCode)(void*); 669a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void* (*pResolveStringFromCode)(void*, uint32_t); 670a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers int (*pSet32Instance)(uint32_t, void*, int32_t); // field_idx, obj, src 671a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers int (*pSet64Instance)(uint32_t, void*, int64_t); 672a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers int (*pSetObjInstance)(uint32_t, void*, void*); 673a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers int (*pSet32Static)(uint32_t, int32_t); 674a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers int (*pSet64Static)(uint32_t, int64_t); 675a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers int (*pSetObjStatic)(uint32_t, void*); 676a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pThrowStackOverflowFromCode)(void*); 677a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pThrowNullPointerFromCode)(); 678a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pThrowArrayBoundsFromCode)(int32_t, int32_t); 679a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pThrowDivZeroFromCode)(); 680a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pThrowVerificationErrorFromCode)(int32_t, int32_t); 681a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pThrowNegArraySizeFromCode)(int32_t); 682a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pThrowNoSuchMethodFromCode)(int32_t); 683a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pThrowAbstractMethodErrorFromCode)(Method* method, Thread* thread, Method** sp); 684a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pUnlockObjectFromCode)(void*); 6851984651929744dd603fd082e23eacd877b9bc177Ian Rogers const void* (*pUnresolvedDirectMethodTrampolineFromCode)(Method*, Method**, Thread*, 6861984651929744dd603fd082e23eacd877b9bc177Ian Rogers Runtime::TrampolineType); 687a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers void (*pUpdateDebuggerFromCode)(void*, void*, int32_t, void*); 68811f9d2130e938511efceb6d2a4793cee7dfdde35Bill Buzbee bool (*pCmplFloat)(float, float); 68911f9d2130e938511efceb6d2a4793cee7dfdde35Bill Buzbee bool (*pCmpgFloat)(float, float); 69011f9d2130e938511efceb6d2a4793cee7dfdde35Bill Buzbee bool (*pCmplDouble)(double, double); 69111f9d2130e938511efceb6d2a4793cee7dfdde35Bill Buzbee bool (*pCmpgDouble)(double, double); 692fc9e6fabed89d948fa8c0e9d673e430076712c60buzbee int (*pIndexOf)(void*, uint32_t, uint32_t, uint32_t); 693fc9e6fabed89d948fa8c0e9d673e430076712c60buzbee int (*pStringCompareTo)(void*, void*); 694fc9e6fabed89d948fa8c0e9d673e430076712c60buzbee int (*pMemcmp16)(void*, void*, int32_t); 695a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers 696a32a6fd4a781262dff4fec102da053d16b7ef6c0Ian Rogers private: 6970e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro DISALLOW_COPY_AND_ASSIGN(Thread); 6980e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro}; 699bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers 700330304de14dc7118b45b8e7b5bd11a172fa61701Elliott Hughesstd::ostream& operator<<(std::ostream& os, const Thread& thread); 701b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogersstd::ostream& operator<<(std::ostream& os, const Thread::State& state); 7020e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro 703ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughesclass ScopedThreadStateChange { 704ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes public: 705ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes ScopedThreadStateChange(Thread* thread, Thread::State new_state) : thread_(thread) { 706ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes old_thread_state_ = thread_->SetState(new_state); 707ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes } 708ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes 709ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes ~ScopedThreadStateChange() { 710ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes thread_->SetState(old_thread_state_); 711ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes } 712ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes 713ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes private: 714ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes Thread* thread_; 715ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes Thread::State old_thread_state_; 716ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes DISALLOW_COPY_AND_ASSIGN(ScopedThreadStateChange); 717ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes}; 718ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes 7190e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro} // namespace art 7200e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro 7210e5d75d5ca2b8a44fab0c862276a466cbab39859Carl Shapiro#endif // ART_SRC_THREAD_H_ 722