jvmtiThreadState.hpp revision 609
0N/A/*
0N/A * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A *
0N/A */
0N/A
0N/A#ifndef _JAVA_JVMTITHREADSTATE_H_
0N/A#define _JAVA_JVMTITHREADSTATE_H_
0N/A
0N/A//
0N/A// Forward Declarations
0N/A//
0N/A
0N/Aclass JvmtiEnvBase;
0N/Aclass JvmtiEnvThreadState;
0N/Aclass JvmtiDynamicCodeEventCollector;
0N/A
0N/Aenum JvmtiClassLoadKind {
0N/A jvmti_class_load_kind_load = 100,
0N/A jvmti_class_load_kind_retransform,
0N/A jvmti_class_load_kind_redefine
0N/A};
0N/A
0N/A///////////////////////////////////////////////////////////////
0N/A//
0N/A// class JvmtiEnvThreadStateIterator
0N/A//
0N/A// The only safe means of iterating through the JvmtiEnvThreadStates
0N/A// in a JvmtiThreadState.
0N/A// Note that this iteratation includes invalid environments pending
0N/A// deallocation -- in fact, some uses depend on this behavior.
0N/A//
0N/Aclass JvmtiEnvThreadStateIterator : public StackObj {
0N/A private:
0N/A JvmtiThreadState* state;
0N/A public:
0N/A JvmtiEnvThreadStateIterator(JvmtiThreadState* thread_state);
0N/A ~JvmtiEnvThreadStateIterator();
0N/A JvmtiEnvThreadState* first();
0N/A JvmtiEnvThreadState* next(JvmtiEnvThreadState* ets);
0N/A};
0N/A
0N/A
0N/A///////////////////////////////////////////////////////////////
0N/A//
0N/A// class JvmtiThreadState
0N/A//
0N/A// The Jvmti state for each thread (across all JvmtiEnv):
0N/A// 1. Local table of enabled events.
0N/Aclass JvmtiThreadState : public CHeapObj {
0N/A private:
0N/A friend class JvmtiEnv;
0N/A JavaThread *_thread;
0N/A bool _exception_detected;
0N/A bool _exception_caught;
0N/A bool _hide_single_stepping;
0N/A bool _pending_step_for_popframe;
0N/A bool _pending_step_for_earlyret;
0N/A int _hide_level;
0N/A
0N/A // Used to send class being redefined/retransformed and kind of transform
0N/A // info to the class file load hook event handler.
0N/A KlassHandle *_class_being_redefined;
0N/A JvmtiClassLoadKind _class_load_kind;
0N/A
0N/A // This is only valid when is_interp_only_mode() returns true
0N/A int _cur_stack_depth;
0N/A
0N/A JvmtiThreadEventEnable _thread_event_enable;
0N/A
0N/A // for support of JvmtiEnvThreadState
0N/A JvmtiEnvThreadState* _head_env_thread_state;
0N/A
0N/A // doubly-linked linear list of active thread state
0N/A // needed in order to iterate the list without holding Threads_lock
0N/A static JvmtiThreadState *_head;
0N/A JvmtiThreadState *_next;
0N/A JvmtiThreadState *_prev;
0N/A
0N/A // holds the current dynamic code event collector, NULL if no event collector in use
0N/A JvmtiDynamicCodeEventCollector* _dynamic_code_event_collector;
0N/A // holds the current vm object alloc event collector, NULL if no event collector in use
0N/A JvmtiVMObjectAllocEventCollector* _vm_object_alloc_event_collector;
0N/A
0N/A // Should only be created by factory methods
0N/A JvmtiThreadState(JavaThread *thread);
0N/A
0N/A friend class JvmtiEnvThreadStateIterator;
0N/A inline JvmtiEnvThreadState* head_env_thread_state();
0N/A inline void set_head_env_thread_state(JvmtiEnvThreadState* ets);
0N/A
0N/A public:
0N/A ~JvmtiThreadState();
0N/A
0N/A // is event_type enabled and usable for this thread in any enviroments?
0N/A bool is_enabled(jvmtiEvent event_type) {
0N/A return _thread_event_enable.is_enabled(event_type);
0N/A }
0N/A
0N/A JvmtiThreadEventEnable *thread_event_enable() {
0N/A return &_thread_event_enable;
0N/A }
0N/A
0N/A // Must only be called in situations where the state is for the current thread and
0N/A // the environment can not go away. To be safe, the returned JvmtiEnvThreadState
0N/A // must be used in such a way as there can be no intervening safepoints.
0N/A inline JvmtiEnvThreadState* env_thread_state(JvmtiEnvBase *env);
0N/A
0N/A static void periodic_clean_up();
0N/A
0N/A void add_env(JvmtiEnvBase *env);
0N/A
0N/A // Used by the interpreter for fullspeed debugging support
0N/A bool is_interp_only_mode() { return _thread->is_interp_only_mode(); }
0N/A void enter_interp_only_mode();
0N/A void leave_interp_only_mode();
0N/A
0N/A // access to the linked list of all JVMTI thread states
0N/A static JvmtiThreadState *first() {
0N/A assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
0N/A return _head;
0N/A }
0N/A
0N/A JvmtiThreadState *next() {
0N/A return _next;
0N/A }
0N/A
0N/A // Current stack depth is only valid when is_interp_only_mode() returns true.
0N/A // These functions should only be called at a safepoint - usually called from same thread.
0N/A // Returns the number of Java activations on the stack.
0N/A int cur_stack_depth();
0N/A void invalidate_cur_stack_depth();
0N/A void incr_cur_stack_depth();
0N/A void decr_cur_stack_depth();
0N/A
0N/A int count_frames();
0N/A
0N/A inline JavaThread *get_thread() { return _thread; }
0N/A inline bool is_exception_detected() { return _exception_detected; }
0N/A inline bool is_exception_caught() { return _exception_caught; }
0N/A inline void set_exception_detected() { _exception_detected = true;
0N/A _exception_caught = false; }
0N/A inline void set_exception_caught() { _exception_caught = true;
0N/A _exception_detected = false; }
0N/A
0N/A inline void clear_hide_single_stepping() {
0N/A if (_hide_level > 0) {
0N/A _hide_level--;
0N/A } else {
0N/A assert(_hide_single_stepping, "hide_single_stepping is out of phase");
0N/A _hide_single_stepping = false;
0N/A }
0N/A }
0N/A inline bool hide_single_stepping() { return _hide_single_stepping; }
0N/A inline void set_hide_single_stepping() {
0N/A if (_hide_single_stepping) {
0N/A _hide_level++;
0N/A } else {
0N/A assert(_hide_level == 0, "hide_level is out of phase");
0N/A _hide_single_stepping = true;
0N/A }
0N/A }
0N/A
0N/A // Step pending flag is set when PopFrame is called and it is cleared
0N/A // when step for the Pop Frame is completed.
0N/A // This logic is used to distinguish b/w step for pop frame and repeat step.
0N/A void set_pending_step_for_popframe() { _pending_step_for_popframe = true; }
0N/A void clr_pending_step_for_popframe() { _pending_step_for_popframe = false; }
0N/A bool is_pending_step_for_popframe() { return _pending_step_for_popframe; }
0N/A void process_pending_step_for_popframe();
0N/A
0N/A // Step pending flag is set when ForceEarlyReturn is called and it is cleared
0N/A // when step for the ForceEarlyReturn is completed.
0N/A // This logic is used to distinguish b/w step for early return and repeat step.
0N/A void set_pending_step_for_earlyret() { _pending_step_for_earlyret = true; }
0N/A void clr_pending_step_for_earlyret() { _pending_step_for_earlyret = false; }
0N/A bool is_pending_step_for_earlyret() { return _pending_step_for_earlyret; }
0N/A void process_pending_step_for_earlyret();
0N/A
0N/A // Setter and getter method is used to send redefined class info
0N/A // when class file load hook event is posted.
0N/A // It is set while loading redefined class and cleared before the
0N/A // class file load hook event is posted.
0N/A inline void set_class_being_redefined(KlassHandle *h_class, JvmtiClassLoadKind kind) {
0N/A _class_being_redefined = h_class;
0N/A _class_load_kind = kind;
0N/A }
0N/A
0N/A inline void clear_class_being_redefined() {
0N/A _class_being_redefined = NULL;
0N/A _class_load_kind = jvmti_class_load_kind_load;
0N/A }
0N/A
0N/A inline KlassHandle *get_class_being_redefined() {
0N/A return _class_being_redefined;
0N/A }
0N/A
0N/A inline JvmtiClassLoadKind get_class_load_kind() {
0N/A return _class_load_kind;
0N/A }
0N/A
0N/A // RedefineClasses support
0N/A // The bug 6214132 caused the verification to fail.
0N/A //
0N/A // Below is the detailed description of the fix approach taken:
0N/A // 1. What's done in RedefineClasses() before verification:
0N/A // a) A reference to the class being redefined (_the_class) and a
0N/A // reference to new version of the class (_scratch_class) are
0N/A // saved here for use during the bytecode verification phase of
0N/A // RedefineClasses. See RedefineVerifyMark for how these fields
0N/A // are managed.
0N/A // b) The _java_mirror field from _the_class is copied to the
0N/A // _java_mirror field in _scratch_class. This means that a jclass
0N/A // returned for _the_class or _scratch_class will refer to the
0N/A // same Java mirror. The verifier will see the "one true mirror"
0N/A // for the class being verified.
0N/A // 2. What is done at verification:
0N/A // When the verifier makes calls into the VM to ask questions about
0N/A // the class being verified, it will pass the jclass to JVM_* functions.
0N/A // The jclass is always pointing to the mirror of _the_class.
0N/A // ~28 JVM_* functions called by the verifier for the information
0N/A // about CP entries and klass structure should check the jvmtiThreadState
0N/A // info about equivalent klass versions and use it to replace a klassOop
0N/A // of _the_class with a klassOop of _scratch_class. The function
0N/A // class_to_verify_considering_redefinition() must be called for it.
0N/A //
0N/A // Note again, that this redirection happens only for the verifier thread.
0N/A // Other threads have very small overhead by checking the existence
0N/A // of the jvmtiThreadSate and the information about klasses equivalence.
0N/A // No JNI functions need to be changed, they don't reference the klass guts.
0N/A // The JavaThread pointer is already available in all JVM_* functions
0N/A // used by the verifier, so there is no extra performance issue with it.
0N/A
0N/A private:
0N/A KlassHandle *_the_class_for_redefinition_verification;
0N/A KlassHandle *_scratch_class_for_redefinition_verification;
0N/A
0N/A public:
0N/A inline void set_class_versions_map(KlassHandle *the_class,
0N/A KlassHandle *scratch_class) {
0N/A _the_class_for_redefinition_verification = the_class;
0N/A _scratch_class_for_redefinition_verification = scratch_class;
0N/A }
0N/A
0N/A inline void clear_class_versions_map() { set_class_versions_map(NULL, NULL); }
0N/A
0N/A static inline
0N/A klassOop class_to_verify_considering_redefinition(klassOop klass,
0N/A JavaThread *thread) {
0N/A JvmtiThreadState *state = thread->jvmti_thread_state();
0N/A if (state != NULL && state->_the_class_for_redefinition_verification != NULL) {
0N/A if ((*(state->_the_class_for_redefinition_verification))() == klass) {
0N/A klass = (*(state->_scratch_class_for_redefinition_verification))();
0N/A }
0N/A }
0N/A return klass;
0N/A }
0N/A
0N/A // Todo: get rid of this!
0N/A private:
0N/A bool _debuggable;
0N/A public:
0N/A // Should the thread be enumerated by jvmtiInternal::GetAllThreads?
0N/A bool is_debuggable() { return _debuggable; }
0N/A // If a thread cannot be suspended (has no valid last_java_frame) then it gets marked !debuggable
0N/A void set_debuggable(bool debuggable) { _debuggable = debuggable; }
0N/A
0N/A public:
0N/A
0N/A bool may_be_walked();
0N/A
0N/A // Thread local event collector setter and getter methods.
0N/A JvmtiDynamicCodeEventCollector* get_dynamic_code_event_collector() {
0N/A return _dynamic_code_event_collector;
0N/A }
0N/A JvmtiVMObjectAllocEventCollector* get_vm_object_alloc_event_collector() {
0N/A return _vm_object_alloc_event_collector;
0N/A }
0N/A void set_dynamic_code_event_collector(JvmtiDynamicCodeEventCollector* collector) {
0N/A _dynamic_code_event_collector = collector;
0N/A }
0N/A void set_vm_object_alloc_event_collector(JvmtiVMObjectAllocEventCollector* collector) {
0N/A _vm_object_alloc_event_collector = collector;
0N/A }
0N/A
0N/A
0N/A //
0N/A // Frame routines
0N/A //
0N/A
0N/A public:
0N/A
0N/A // true when the thread was suspended with a pointer to the last Java frame.
0N/A bool has_last_frame() { return _thread->has_last_Java_frame(); }
0N/A
0N/A void update_for_pop_top_frame();
0N/A
0N/A // already holding JvmtiThreadState_lock - retrieve or create JvmtiThreadState
609N/A // Can return NULL if JavaThread is exiting.
0N/A inline static JvmtiThreadState *state_for_while_locked(JavaThread *thread) {
0N/A assert(JvmtiThreadState_lock->is_locked(), "sanity check");
0N/A
0N/A JvmtiThreadState *state = thread->jvmti_thread_state();
0N/A if (state == NULL) {
608N/A if (thread->is_exiting()) {
608N/A // don't add a JvmtiThreadState to a thread that is exiting
608N/A return NULL;
608N/A }
608N/A
0N/A state = new JvmtiThreadState(thread);
0N/A }
0N/A return state;
0N/A }
0N/A
0N/A // retrieve or create JvmtiThreadState
609N/A // Can return NULL if JavaThread is exiting.
0N/A inline static JvmtiThreadState *state_for(JavaThread *thread) {
0N/A JvmtiThreadState *state = thread->jvmti_thread_state();
0N/A if (state == NULL) {
0N/A MutexLocker mu(JvmtiThreadState_lock);
0N/A // check again with the lock held
0N/A state = state_for_while_locked(thread);
0N/A } else {
0N/A CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
0N/A }
0N/A return state;
0N/A }
0N/A
0N/A // JVMTI ForceEarlyReturn support
0N/A
0N/A // This is set to earlyret_pending to signal that top Java frame
0N/A // should be returned immediately
0N/A public:
0N/A int _earlyret_state;
0N/A TosState _earlyret_tos;
0N/A jvalue _earlyret_value;
0N/A oop _earlyret_oop; // Used to return an oop result into Java code from
0N/A // ForceEarlyReturnObject, GC-preserved
0N/A
0N/A // Setting and clearing earlyret_state
0N/A // earlyret_pending indicates that a ForceEarlyReturn() has been
0N/A // requested and not yet been completed.
0N/A public:
0N/A enum EarlyretState {
0N/A earlyret_inactive = 0,
0N/A earlyret_pending = 1
0N/A };
0N/A
0N/A void set_earlyret_pending(void) { _earlyret_state = earlyret_pending; }
0N/A void clr_earlyret_pending(void) { _earlyret_state = earlyret_inactive; }
0N/A bool is_earlyret_pending(void) { return (_earlyret_state == earlyret_pending); }
0N/A
0N/A TosState earlyret_tos() { return _earlyret_tos; }
0N/A oop earlyret_oop() const { return _earlyret_oop; }
0N/A void set_earlyret_oop (oop x) { _earlyret_oop = x; }
0N/A jvalue earlyret_value() { return _earlyret_value; }
0N/A void set_earlyret_value(jvalue val, TosState tos) { _earlyret_tos = tos; _earlyret_value = val; }
0N/A void clr_earlyret_value() { _earlyret_tos = ilgl; _earlyret_value.j = 0L; }
0N/A
0N/A static ByteSize earlyret_state_offset() { return byte_offset_of(JvmtiThreadState, _earlyret_state); }
0N/A static ByteSize earlyret_tos_offset() { return byte_offset_of(JvmtiThreadState, _earlyret_tos); }
0N/A static ByteSize earlyret_oop_offset() { return byte_offset_of(JvmtiThreadState, _earlyret_oop); }
0N/A static ByteSize earlyret_value_offset() { return byte_offset_of(JvmtiThreadState, _earlyret_value); }
0N/A
0N/A void oops_do(OopClosure* f); // GC support
0N/A};
0N/A
0N/Aclass RedefineVerifyMark : public StackObj {
0N/A private:
0N/A JvmtiThreadState *_state;
0N/A
0N/A public:
0N/A RedefineVerifyMark(KlassHandle *the_class, KlassHandle *scratch_class,
0N/A JvmtiThreadState *state) : _state(state)
0N/A {
0N/A _state->set_class_versions_map(the_class, scratch_class);
0N/A (*scratch_class)->set_java_mirror((*the_class)->java_mirror());
0N/A }
0N/A
0N/A ~RedefineVerifyMark() {
0N/A _state->clear_class_versions_map();
0N/A }
0N/A};
0N/A
0N/A#endif /* _JAVA_JVMTITHREADSTATE_H_ */