class JavaVMExt; class JNIEnvExt; template<class MirrorType> class ObjPtr; class Thread;
namespace mirror { class Object;
} // namespace mirror
// Scoped change into and out of a particular state. Handles Runnable transitions that require // more complicated suspension checking. The subclasses ScopedObjectAccessUnchecked and // ScopedObjectAccess are used to handle the change into Runnable to Get direct access to objects, // the unchecked variant doesn't aid annotalysis. class ScopedThreadStateChange : public ValueObject { public:
ALWAYS_INLINE ScopedThreadStateChange(Thread* self, ThreadState new_thread_state)
REQUIRES(!Locks::thread_suspend_count_lock_);
// Used when we want a scoped JNI thread state but have no thread/JNIEnv. Consequently doesn't // change into Runnable or acquire a share on the mutator_lock_. // Note: The reinterpret_cast is backed by a static_assert in the cc file. Avoid a down_cast, // as it prevents forward declaration of JavaVMExt. explicit ScopedObjectAccessAlreadyRunnable(JavaVM* vm)
: self_(nullptr), env_(nullptr), vm_(reinterpret_cast<JavaVMExt*>(vm)) {}
// Here purely to force inlining.
ALWAYS_INLINE ~ScopedObjectAccessAlreadyRunnable() {}
// Self thread, can be null.
Thread* const self_; // The full JNIEnv.
JNIEnvExt* const env_; // The full JavaVM.
JavaVMExt* const vm_;
};
// Entry/exit processing for transitions from Native to Runnable (ie within JNI functions). // // This class performs the necessary thread state switching to and from Runnable and lets us // amortize the cost of working out the current thread. Additionally it lets us check (and repair) // apps that are using a JNIEnv on the wrong thread. The class also decodes and encodes Objects // into jobjects via methods of this class. Performing this here enforces the Runnable thread state // for use of Object, thereby inhibiting the Object being modified by GC whilst native or VM code // is also manipulating the Object. // // The destructor transitions back to the previous thread state, typically Native. In this state // GC and thread suspension may occur. // // For annotalysis the subclass ScopedObjectAccess (below) makes it explicit that a shared of // the mutator_lock_ will be acquired on construction. class ScopedObjectAccessUnchecked : public ScopedObjectAccessAlreadyRunnable { public:
ALWAYS_INLINE explicit ScopedObjectAccessUnchecked(JNIEnv* env)
REQUIRES(!Locks::thread_suspend_count_lock_);
// Used when we want a scoped JNI thread state but have no thread/JNIEnv. Consequently doesn't // change into Runnable or acquire a share on the mutator_lock_. explicit ScopedObjectAccessUnchecked(JavaVM* vm) ALWAYS_INLINE
: ScopedObjectAccessAlreadyRunnable(vm), tsc_() {}
private: // The scoped thread state change makes sure that we are runnable and restores the thread state // in the destructor. const ScopedThreadStateChange tsc_;
// Annotalysis helping variant of the above. class ScopedObjectAccess : public ScopedObjectAccessUnchecked { public:
ALWAYS_INLINE explicit ScopedObjectAccess(JNIEnv* env)
REQUIRES(!Locks::thread_suspend_count_lock_)
SHARED_LOCK_FUNCTION(Locks::mutator_lock_);
// Base class will release share of lock. Invoked after this destructor.
~ScopedObjectAccess() UNLOCK_FUNCTION(Locks::mutator_lock_) ALWAYS_INLINE;
private: // TODO: remove this constructor. It is used by check JNI's ScopedCheck to make it believe that // routines operating with just a VM are sound, they are not, but when you have just a VM // you cannot call the unsound routines. explicit ScopedObjectAccess(JavaVM* vm) SHARED_LOCK_FUNCTION(Locks::mutator_lock_)
: ScopedObjectAccessUnchecked(vm) {}
// Annotalysis helper for going to a suspended state from runnable. class ScopedThreadSuspension : public ValueObject { public:
ALWAYS_INLINE explicit ScopedThreadSuspension(Thread* self, ThreadState suspended_state)
REQUIRES(!Locks::thread_suspend_count_lock_, !Roles::uninterruptible_)
UNLOCK_FUNCTION(Locks::mutator_lock_);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.