duke@435: /* stefank@2314: * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ stefank@2314: stefank@2314: #ifndef SHARE_VM_PRIMS_JVMTIENVTHREADSTATE_HPP stefank@2314: #define SHARE_VM_PRIMS_JVMTIENVTHREADSTATE_HPP stefank@2314: stefank@2314: #include "jvmtifiles/jvmti.h" stefank@2314: #include "memory/allocation.hpp" stefank@2314: #include "memory/allocation.inline.hpp" stefank@2314: #include "oops/instanceKlass.hpp" stefank@2314: #include "prims/jvmtiEventController.hpp" stefank@2314: #include "utilities/globalDefinitions.hpp" stefank@2314: #include "utilities/growableArray.hpp" duke@435: bobv@2036: class JvmtiEnv; bobv@2036: duke@435: /////////////////////////////////////////////////////////////// duke@435: // duke@435: // class JvmtiFramePop duke@435: // Used by : JvmtiFramePops duke@435: // Used by JVMTI methods: none directly. duke@435: // duke@435: // Wrapper class for FramePop, used in the JvmtiFramePops class. duke@435: // duke@435: // Two problems: 1) this isn't being used as a ValueObj class, in duke@435: // several places there are constructors for it. 2) It seems like duke@435: // overkill as a means to get an assert and name the geater than duke@435: // operator. I'm trying to to rewrite everything. duke@435: duke@435: class JvmtiFramePop VALUE_OBJ_CLASS_SPEC { duke@435: private: duke@435: // Frame number counting from BOTTOM (oldest) frame; duke@435: // bottom frame == #0 duke@435: int _frame_number; duke@435: public: duke@435: JvmtiFramePop() {} duke@435: JvmtiFramePop(int frame_number) { duke@435: assert(frame_number >= 0, "invalid frame number"); duke@435: _frame_number = frame_number; duke@435: } duke@435: duke@435: int frame_number() { return _frame_number; } duke@435: int above_on_stack(JvmtiFramePop& other) { return _frame_number > other._frame_number; } duke@435: void print() PRODUCT_RETURN; duke@435: }; duke@435: duke@435: duke@435: /////////////////////////////////////////////////////////////// duke@435: // duke@435: // class JvmtiFramePops duke@435: // Used by : JvmtiThreadState duke@435: // Used by JVMTI methods: none directly. duke@435: // duke@435: // A collection of JvmtiFramePop. duke@435: // It records what frames on a threads stack should post frame_pop events when they're exited. duke@435: // duke@435: duke@435: class JvmtiFramePops : public CHeapObj { duke@435: private: duke@435: GrowableArray* _pops; duke@435: duke@435: // should only be used by JvmtiEventControllerPrivate duke@435: // to insure they only occur at safepoints. duke@435: // Todo: add checks for safepoint duke@435: friend class JvmtiEventControllerPrivate; duke@435: void set(JvmtiFramePop& fp); duke@435: void clear(JvmtiFramePop& fp); duke@435: int clear_to(JvmtiFramePop& fp); duke@435: duke@435: public: duke@435: JvmtiFramePops(); duke@435: ~JvmtiFramePops(); duke@435: duke@435: bool contains(JvmtiFramePop& fp) { return _pops->contains(fp.frame_number()); } duke@435: int length() { return _pops->length(); } duke@435: void print() PRODUCT_RETURN; duke@435: }; duke@435: duke@435: duke@435: /////////////////////////////////////////////////////////////// duke@435: // duke@435: // class JvmtiEnvThreadState duke@435: // duke@435: // 2. Cache of pending frame_pop_events, created by NotifyFramePop duke@435: // and lazily initialized. duke@435: // 3: Location of last executed instruction, used to filter out duplicate duke@435: // events due to instruction rewriting. duke@435: duke@435: class JvmtiEnvThreadState : public CHeapObj { duke@435: private: duke@435: friend class JvmtiEnv; duke@435: JavaThread *_thread; duke@435: JvmtiEnv *_env; duke@435: JvmtiEnvThreadState *_next; duke@435: jmethodID _current_method_id; duke@435: int _current_bci; duke@435: bool _breakpoint_posted; duke@435: bool _single_stepping_posted; duke@435: JvmtiEnvThreadEventEnable _event_enable; duke@435: void *_agent_thread_local_storage_data; // per env and per thread agent allocated data. duke@435: duke@435: // Class used to store pending framepops. duke@435: // lazily initialized by get_frame_pops(); duke@435: JvmtiFramePops *_frame_pops; duke@435: duke@435: inline void set_current_location(jmethodID method_id, int bci) { duke@435: _current_method_id = method_id; duke@435: _current_bci = bci; duke@435: } duke@435: duke@435: friend class JvmtiEnvThreadStateIterator; duke@435: JvmtiEnvThreadState* next() { return _next; } duke@435: duke@435: friend class JvmtiThreadState; duke@435: void set_next(JvmtiEnvThreadState* link) { _next = link; } duke@435: duke@435: public: duke@435: JvmtiEnvThreadState(JavaThread *thread, JvmtiEnvBase *env); duke@435: ~JvmtiEnvThreadState(); duke@435: duke@435: bool is_enabled(jvmtiEvent event_type) { return _event_enable.is_enabled(event_type); } duke@435: duke@435: JvmtiEnvThreadEventEnable *event_enable() { return &_event_enable; } duke@435: void *get_agent_thread_local_storage_data() { return _agent_thread_local_storage_data; } duke@435: void set_agent_thread_local_storage_data (void *data) { _agent_thread_local_storage_data = data; } duke@435: duke@435: duke@435: // If the thread is in the given method at the given duke@435: // location just return. Otherwise, reset the current location duke@435: // and reset _breakpoint_posted and _single_stepping_posted. duke@435: // _breakpoint_posted and _single_stepping_posted are only cleared duke@435: // here. duke@435: void compare_and_set_current_location(methodOop method, address location, jvmtiEvent event); duke@435: duke@435: void clear_current_location() { set_current_location((jmethodID)NULL, 0); } duke@435: duke@435: void reset_current_location(jvmtiEvent event, bool enabled); duke@435: duke@435: inline void set_breakpoint_posted() { _breakpoint_posted = true; } duke@435: inline void set_single_stepping_posted() { duke@435: _single_stepping_posted = true; duke@435: } duke@435: inline bool breakpoint_posted() { return _breakpoint_posted; } duke@435: inline bool single_stepping_posted() { duke@435: return _single_stepping_posted; duke@435: } duke@435: duke@435: inline JavaThread *get_thread() { return _thread; } duke@435: inline JvmtiEnv *get_env() { return _env; } duke@435: duke@435: // lazily initialize _frame_pops duke@435: JvmtiFramePops* get_frame_pops(); duke@435: duke@435: bool has_frame_pops(); duke@435: duke@435: // quickly test whether we should deliver a frame pop event on return from sp duke@435: bool is_frame_pop(int cur_stack_depth); duke@435: duke@435: void set_frame_pop(int frame_number); duke@435: void clear_frame_pop(int frame_number); duke@435: void clear_to_frame_pop(int frame_number); duke@435: duke@435: }; duke@435: stefank@2314: #endif // SHARE_VM_PRIMS_JVMTIENVTHREADSTATE_HPP