Fri, 13 Sep 2013 12:48:50 -0700
8024346: ~CautiouslyPreserveExceptionMark - assert(!_thread->has_pending_exception()) failed: unexpected exception generated
Summary: Pending exceptions must be handled properly after a call to the JVMTI merge_cp_and_rewrite
Reviewed-by: coleenp, dholmes
Contributed-by: serguei.spitsyn@oracle.com
duke@435 | 1 | /* |
coleenp@4037 | 2 | * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
stefank@2314 | 24 | |
stefank@2314 | 25 | #ifndef SHARE_VM_PRIMS_JVMTIENVTHREADSTATE_HPP |
stefank@2314 | 26 | #define SHARE_VM_PRIMS_JVMTIENVTHREADSTATE_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "jvmtifiles/jvmti.h" |
stefank@2314 | 29 | #include "memory/allocation.hpp" |
stefank@2314 | 30 | #include "memory/allocation.inline.hpp" |
stefank@2314 | 31 | #include "oops/instanceKlass.hpp" |
stefank@2314 | 32 | #include "prims/jvmtiEventController.hpp" |
stefank@2314 | 33 | #include "utilities/globalDefinitions.hpp" |
stefank@2314 | 34 | #include "utilities/growableArray.hpp" |
duke@435 | 35 | |
bobv@2036 | 36 | class JvmtiEnv; |
bobv@2036 | 37 | |
duke@435 | 38 | /////////////////////////////////////////////////////////////// |
duke@435 | 39 | // |
duke@435 | 40 | // class JvmtiFramePop |
duke@435 | 41 | // Used by : JvmtiFramePops |
duke@435 | 42 | // Used by JVMTI methods: none directly. |
duke@435 | 43 | // |
duke@435 | 44 | // Wrapper class for FramePop, used in the JvmtiFramePops class. |
duke@435 | 45 | // |
duke@435 | 46 | // Two problems: 1) this isn't being used as a ValueObj class, in |
duke@435 | 47 | // several places there are constructors for it. 2) It seems like |
duke@435 | 48 | // overkill as a means to get an assert and name the geater than |
duke@435 | 49 | // operator. I'm trying to to rewrite everything. |
duke@435 | 50 | |
duke@435 | 51 | class JvmtiFramePop VALUE_OBJ_CLASS_SPEC { |
duke@435 | 52 | private: |
duke@435 | 53 | // Frame number counting from BOTTOM (oldest) frame; |
duke@435 | 54 | // bottom frame == #0 |
duke@435 | 55 | int _frame_number; |
duke@435 | 56 | public: |
duke@435 | 57 | JvmtiFramePop() {} |
duke@435 | 58 | JvmtiFramePop(int frame_number) { |
duke@435 | 59 | assert(frame_number >= 0, "invalid frame number"); |
duke@435 | 60 | _frame_number = frame_number; |
duke@435 | 61 | } |
duke@435 | 62 | |
duke@435 | 63 | int frame_number() { return _frame_number; } |
duke@435 | 64 | int above_on_stack(JvmtiFramePop& other) { return _frame_number > other._frame_number; } |
duke@435 | 65 | void print() PRODUCT_RETURN; |
duke@435 | 66 | }; |
duke@435 | 67 | |
duke@435 | 68 | |
duke@435 | 69 | /////////////////////////////////////////////////////////////// |
duke@435 | 70 | // |
duke@435 | 71 | // class JvmtiFramePops |
duke@435 | 72 | // Used by : JvmtiThreadState |
duke@435 | 73 | // Used by JVMTI methods: none directly. |
duke@435 | 74 | // |
duke@435 | 75 | // A collection of JvmtiFramePop. |
duke@435 | 76 | // It records what frames on a threads stack should post frame_pop events when they're exited. |
duke@435 | 77 | // |
duke@435 | 78 | |
zgu@3900 | 79 | class JvmtiFramePops : public CHeapObj<mtInternal> { |
duke@435 | 80 | private: |
duke@435 | 81 | GrowableArray<int>* _pops; |
duke@435 | 82 | |
duke@435 | 83 | // should only be used by JvmtiEventControllerPrivate |
duke@435 | 84 | // to insure they only occur at safepoints. |
duke@435 | 85 | // Todo: add checks for safepoint |
duke@435 | 86 | friend class JvmtiEventControllerPrivate; |
duke@435 | 87 | void set(JvmtiFramePop& fp); |
duke@435 | 88 | void clear(JvmtiFramePop& fp); |
duke@435 | 89 | int clear_to(JvmtiFramePop& fp); |
duke@435 | 90 | |
duke@435 | 91 | public: |
duke@435 | 92 | JvmtiFramePops(); |
duke@435 | 93 | ~JvmtiFramePops(); |
duke@435 | 94 | |
duke@435 | 95 | bool contains(JvmtiFramePop& fp) { return _pops->contains(fp.frame_number()); } |
duke@435 | 96 | int length() { return _pops->length(); } |
duke@435 | 97 | void print() PRODUCT_RETURN; |
duke@435 | 98 | }; |
duke@435 | 99 | |
duke@435 | 100 | |
duke@435 | 101 | /////////////////////////////////////////////////////////////// |
duke@435 | 102 | // |
duke@435 | 103 | // class JvmtiEnvThreadState |
duke@435 | 104 | // |
duke@435 | 105 | // 2. Cache of pending frame_pop_events, created by NotifyFramePop |
duke@435 | 106 | // and lazily initialized. |
duke@435 | 107 | // 3: Location of last executed instruction, used to filter out duplicate |
duke@435 | 108 | // events due to instruction rewriting. |
duke@435 | 109 | |
zgu@3900 | 110 | class JvmtiEnvThreadState : public CHeapObj<mtInternal> { |
duke@435 | 111 | private: |
duke@435 | 112 | friend class JvmtiEnv; |
duke@435 | 113 | JavaThread *_thread; |
duke@435 | 114 | JvmtiEnv *_env; |
duke@435 | 115 | JvmtiEnvThreadState *_next; |
duke@435 | 116 | jmethodID _current_method_id; |
duke@435 | 117 | int _current_bci; |
duke@435 | 118 | bool _breakpoint_posted; |
duke@435 | 119 | bool _single_stepping_posted; |
duke@435 | 120 | JvmtiEnvThreadEventEnable _event_enable; |
duke@435 | 121 | void *_agent_thread_local_storage_data; // per env and per thread agent allocated data. |
duke@435 | 122 | |
duke@435 | 123 | // Class used to store pending framepops. |
duke@435 | 124 | // lazily initialized by get_frame_pops(); |
duke@435 | 125 | JvmtiFramePops *_frame_pops; |
duke@435 | 126 | |
duke@435 | 127 | inline void set_current_location(jmethodID method_id, int bci) { |
duke@435 | 128 | _current_method_id = method_id; |
duke@435 | 129 | _current_bci = bci; |
duke@435 | 130 | } |
duke@435 | 131 | |
duke@435 | 132 | friend class JvmtiEnvThreadStateIterator; |
duke@435 | 133 | JvmtiEnvThreadState* next() { return _next; } |
duke@435 | 134 | |
duke@435 | 135 | friend class JvmtiThreadState; |
duke@435 | 136 | void set_next(JvmtiEnvThreadState* link) { _next = link; } |
duke@435 | 137 | |
duke@435 | 138 | public: |
duke@435 | 139 | JvmtiEnvThreadState(JavaThread *thread, JvmtiEnvBase *env); |
duke@435 | 140 | ~JvmtiEnvThreadState(); |
duke@435 | 141 | |
duke@435 | 142 | bool is_enabled(jvmtiEvent event_type) { return _event_enable.is_enabled(event_type); } |
duke@435 | 143 | |
duke@435 | 144 | JvmtiEnvThreadEventEnable *event_enable() { return &_event_enable; } |
duke@435 | 145 | void *get_agent_thread_local_storage_data() { return _agent_thread_local_storage_data; } |
duke@435 | 146 | void set_agent_thread_local_storage_data (void *data) { _agent_thread_local_storage_data = data; } |
duke@435 | 147 | |
duke@435 | 148 | |
duke@435 | 149 | // If the thread is in the given method at the given |
duke@435 | 150 | // location just return. Otherwise, reset the current location |
duke@435 | 151 | // and reset _breakpoint_posted and _single_stepping_posted. |
duke@435 | 152 | // _breakpoint_posted and _single_stepping_posted are only cleared |
duke@435 | 153 | // here. |
coleenp@4037 | 154 | void compare_and_set_current_location(Method* method, address location, jvmtiEvent event); |
duke@435 | 155 | |
duke@435 | 156 | void clear_current_location() { set_current_location((jmethodID)NULL, 0); } |
duke@435 | 157 | |
duke@435 | 158 | void reset_current_location(jvmtiEvent event, bool enabled); |
duke@435 | 159 | |
duke@435 | 160 | inline void set_breakpoint_posted() { _breakpoint_posted = true; } |
duke@435 | 161 | inline void set_single_stepping_posted() { |
duke@435 | 162 | _single_stepping_posted = true; |
duke@435 | 163 | } |
duke@435 | 164 | inline bool breakpoint_posted() { return _breakpoint_posted; } |
duke@435 | 165 | inline bool single_stepping_posted() { |
duke@435 | 166 | return _single_stepping_posted; |
duke@435 | 167 | } |
duke@435 | 168 | |
duke@435 | 169 | inline JavaThread *get_thread() { return _thread; } |
duke@435 | 170 | inline JvmtiEnv *get_env() { return _env; } |
duke@435 | 171 | |
duke@435 | 172 | // lazily initialize _frame_pops |
duke@435 | 173 | JvmtiFramePops* get_frame_pops(); |
duke@435 | 174 | |
duke@435 | 175 | bool has_frame_pops(); |
duke@435 | 176 | |
duke@435 | 177 | // quickly test whether we should deliver a frame pop event on return from sp |
duke@435 | 178 | bool is_frame_pop(int cur_stack_depth); |
duke@435 | 179 | |
duke@435 | 180 | void set_frame_pop(int frame_number); |
duke@435 | 181 | void clear_frame_pop(int frame_number); |
duke@435 | 182 | void clear_to_frame_pop(int frame_number); |
duke@435 | 183 | |
duke@435 | 184 | }; |
duke@435 | 185 | |
stefank@2314 | 186 | #endif // SHARE_VM_PRIMS_JVMTIENVTHREADSTATE_HPP |