annotate src/share/vm/prims/jvmtiThreadState.cpp @ 14653:0d8d78c0329a

6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync") Summary: It is more safe to get/update data for suspended threads at a safepoint Reviewed-by: dcubed, twisti, dholmes Contributed-by: serguei.spitsyn@oracle.com
author sspitsyn
date Sat, 01 Mar 2014 08:05:55 -0800
parents da91efe96a93
children 92aa6797d639
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
14653
0d8d78c0329a 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 6725
diff changeset
2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "jvmtifiles/jvmtiEnv.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "memory/gcLocker.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "memory/resourceArea.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "prims/jvmtiEventController.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "prims/jvmtiImpl.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "prims/jvmtiThreadState.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32 #include "runtime/vframe.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // marker for when the stack depth has been reset and is now unknown.
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // any negative number would work but small ones might obscure an
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // underrun error.
a61af66fc99e Initial load
duke
parents:
diff changeset
37 static const int UNKNOWN_STACK_DEPTH = -99;
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 ///////////////////////////////////////////////////////////////
a61af66fc99e Initial load
duke
parents:
diff changeset
40 //
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // class JvmtiThreadState
a61af66fc99e Initial load
duke
parents:
diff changeset
42 //
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // Instances of JvmtiThreadState hang off of each thread.
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // Thread local storage for JVMTI.
a61af66fc99e Initial load
duke
parents:
diff changeset
45 //
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 JvmtiThreadState *JvmtiThreadState::_head = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 JvmtiThreadState::JvmtiThreadState(JavaThread* thread)
a61af66fc99e Initial load
duke
parents:
diff changeset
50 : _thread_event_enable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 assert(JvmtiThreadState_lock->is_locked(), "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
52 _thread = thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 _exception_detected = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 _exception_caught = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 _debuggable = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 _hide_single_stepping = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 _hide_level = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 _pending_step_for_popframe = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 _class_being_redefined = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 _class_load_kind = jvmti_class_load_kind_load;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 _head_env_thread_state = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 _dynamic_code_event_collector = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 _vm_object_alloc_event_collector = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 _the_class_for_redefinition_verification = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 _scratch_class_for_redefinition_verification = NULL;
14653
0d8d78c0329a 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 6725
diff changeset
66 _cur_stack_depth = UNKNOWN_STACK_DEPTH;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // JVMTI ForceEarlyReturn support
a61af66fc99e Initial load
duke
parents:
diff changeset
69 _pending_step_for_earlyret = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 _earlyret_state = earlyret_inactive;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 _earlyret_tos = ilgl;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 _earlyret_value.j = 0L;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 _earlyret_oop = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // add all the JvmtiEnvThreadState to the new JvmtiThreadState
a61af66fc99e Initial load
duke
parents:
diff changeset
76 {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 JvmtiEnvIterator it;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 for (JvmtiEnvBase* env = it.first(); env != NULL; env = it.next(env)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 if (env->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 add_env(env);
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // link us into the list
a61af66fc99e Initial load
duke
parents:
diff changeset
86 {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // The thread state list manipulation code must not have safepoints.
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // See periodic_clean_up().
a61af66fc99e Initial load
duke
parents:
diff changeset
89 debug_only(No_Safepoint_Verifier nosafepoint;)
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 _prev = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 _next = _head;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 if (_head != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 _head->_prev = this;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 _head = this;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // set this as the state for the thread
a61af66fc99e Initial load
duke
parents:
diff changeset
100 thread->set_jvmti_thread_state(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 JvmtiThreadState::~JvmtiThreadState() {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 assert(JvmtiThreadState_lock->is_locked(), "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 // clear this as the state for the thread
a61af66fc99e Initial load
duke
parents:
diff changeset
108 get_thread()->set_jvmti_thread_state(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // zap our env thread states
a61af66fc99e Initial load
duke
parents:
diff changeset
111 {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 JvmtiEnvBase::entering_dying_thread_env_iteration();
a61af66fc99e Initial load
duke
parents:
diff changeset
113 JvmtiEnvThreadStateIterator it(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
114 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 JvmtiEnvThreadState* zap = ets;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 ets = it.next(ets);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 delete zap;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 JvmtiEnvBase::leaving_dying_thread_env_iteration();
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // remove us from the list
a61af66fc99e Initial load
duke
parents:
diff changeset
123 {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // The thread state list manipulation code must not have safepoints.
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // See periodic_clean_up().
a61af66fc99e Initial load
duke
parents:
diff changeset
126 debug_only(No_Safepoint_Verifier nosafepoint;)
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 if (_prev == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 assert(_head == this, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
130 _head = _next;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 assert(_head != this, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
133 _prev->_next = _next;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135 if (_next != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 _next->_prev = _prev;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138 _next = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 _prev = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 void
a61af66fc99e Initial load
duke
parents:
diff changeset
145 JvmtiThreadState::periodic_clean_up() {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 assert(SafepointSynchronize::is_at_safepoint(), "at safepoint");
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // This iteration is initialized with "_head" instead of "JvmtiThreadState::first()"
a61af66fc99e Initial load
duke
parents:
diff changeset
149 // because the latter requires the JvmtiThreadState_lock.
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // This iteration is safe at a safepoint as well, see the No_Safepoint_Verifier
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // asserts at all list manipulation sites.
a61af66fc99e Initial load
duke
parents:
diff changeset
152 for (JvmtiThreadState *state = _head; state != NULL; state = state->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // For each environment thread state corresponding to an invalid environment
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // unlink it from the list and deallocate it.
a61af66fc99e Initial load
duke
parents:
diff changeset
155 JvmtiEnvThreadStateIterator it(state);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 JvmtiEnvThreadState* previous_ets = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
157 JvmtiEnvThreadState* ets = it.first();
a61af66fc99e Initial load
duke
parents:
diff changeset
158 while (ets != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 if (ets->get_env()->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 previous_ets = ets;
a61af66fc99e Initial load
duke
parents:
diff changeset
161 ets = it.next(ets);
a61af66fc99e Initial load
duke
parents:
diff changeset
162 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 // This one isn't valid, remove it from the list and deallocate it
a61af66fc99e Initial load
duke
parents:
diff changeset
164 JvmtiEnvThreadState* defunct_ets = ets;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 ets = ets->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
166 if (previous_ets == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 assert(state->head_env_thread_state() == defunct_ets, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
168 state->set_head_env_thread_state(ets);
a61af66fc99e Initial load
duke
parents:
diff changeset
169 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 previous_ets->set_next(ets);
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172 delete defunct_ets;
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 void JvmtiThreadState::add_env(JvmtiEnvBase *env) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 assert(JvmtiThreadState_lock->is_locked(), "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
180
a61af66fc99e Initial load
duke
parents:
diff changeset
181 JvmtiEnvThreadState *new_ets = new JvmtiEnvThreadState(_thread, env);
a61af66fc99e Initial load
duke
parents:
diff changeset
182 // add this environment thread state to the end of the list (order is important)
a61af66fc99e Initial load
duke
parents:
diff changeset
183 {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 // list deallocation (which occurs at a safepoint) cannot occur simultaneously
a61af66fc99e Initial load
duke
parents:
diff changeset
185 debug_only(No_Safepoint_Verifier nosafepoint;)
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 JvmtiEnvThreadStateIterator it(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
188 JvmtiEnvThreadState* previous_ets = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
189 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 previous_ets = ets;
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192 if (previous_ets == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 set_head_env_thread_state(new_ets);
a61af66fc99e Initial load
duke
parents:
diff changeset
194 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 previous_ets->set_next(new_ets);
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201
a61af66fc99e Initial load
duke
parents:
diff changeset
202
a61af66fc99e Initial load
duke
parents:
diff changeset
203 void JvmtiThreadState::enter_interp_only_mode() {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 assert(_thread->get_interp_only_mode() == 0, "entering interp only when mode not zero");
a61af66fc99e Initial load
duke
parents:
diff changeset
205 _thread->increment_interp_only_mode();
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 void JvmtiThreadState::leave_interp_only_mode() {
a61af66fc99e Initial load
duke
parents:
diff changeset
210 assert(_thread->get_interp_only_mode() == 1, "leaving interp only when mode not one");
a61af66fc99e Initial load
duke
parents:
diff changeset
211 _thread->decrement_interp_only_mode();
a61af66fc99e Initial load
duke
parents:
diff changeset
212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 // Helper routine used in several places
a61af66fc99e Initial load
duke
parents:
diff changeset
216 int JvmtiThreadState::count_frames() {
14653
0d8d78c0329a 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 6725
diff changeset
217 guarantee(SafepointSynchronize::is_at_safepoint() ||
0d8d78c0329a 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 6725
diff changeset
218 (JavaThread *)Thread::current() == get_thread(),
0d8d78c0329a 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 6725
diff changeset
219 "must be current thread or at safepoint");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
220
a61af66fc99e Initial load
duke
parents:
diff changeset
221 if (!get_thread()->has_last_Java_frame()) return 0; // no Java frames
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
224 RegisterMap reg_map(get_thread());
a61af66fc99e Initial load
duke
parents:
diff changeset
225 javaVFrame *jvf = get_thread()->last_java_vframe(&reg_map);
a61af66fc99e Initial load
duke
parents:
diff changeset
226 int n = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // tty->print_cr("CSD: counting frames on %s ...",
a61af66fc99e Initial load
duke
parents:
diff changeset
228 // JvmtiTrace::safe_get_thread_name(get_thread()));
a61af66fc99e Initial load
duke
parents:
diff changeset
229 while (jvf != NULL) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4841
diff changeset
230 Method* method = jvf->method();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
231 // tty->print_cr("CSD: frame - method %s.%s - loc %d",
a61af66fc99e Initial load
duke
parents:
diff changeset
232 // method->klass_name()->as_C_string(),
a61af66fc99e Initial load
duke
parents:
diff changeset
233 // method->name()->as_C_string(),
a61af66fc99e Initial load
duke
parents:
diff changeset
234 // jvf->bci() );
a61af66fc99e Initial load
duke
parents:
diff changeset
235 jvf = jvf->java_sender();
a61af66fc99e Initial load
duke
parents:
diff changeset
236 n++;
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
238 // tty->print_cr("CSD: frame count: %d", n);
a61af66fc99e Initial load
duke
parents:
diff changeset
239 return n;
a61af66fc99e Initial load
duke
parents:
diff changeset
240 }
a61af66fc99e Initial load
duke
parents:
diff changeset
241
a61af66fc99e Initial load
duke
parents:
diff changeset
242
a61af66fc99e Initial load
duke
parents:
diff changeset
243 void JvmtiThreadState::invalidate_cur_stack_depth() {
14653
0d8d78c0329a 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 6725
diff changeset
244 guarantee(SafepointSynchronize::is_at_safepoint() ||
0d8d78c0329a 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 6725
diff changeset
245 (JavaThread *)Thread::current() == get_thread(),
0d8d78c0329a 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 6725
diff changeset
246 "must be current thread or at safepoint");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
247
a61af66fc99e Initial load
duke
parents:
diff changeset
248 _cur_stack_depth = UNKNOWN_STACK_DEPTH;
a61af66fc99e Initial load
duke
parents:
diff changeset
249 }
a61af66fc99e Initial load
duke
parents:
diff changeset
250
a61af66fc99e Initial load
duke
parents:
diff changeset
251 void JvmtiThreadState::incr_cur_stack_depth() {
a61af66fc99e Initial load
duke
parents:
diff changeset
252 guarantee(JavaThread::current() == get_thread(), "must be current thread");
a61af66fc99e Initial load
duke
parents:
diff changeset
253
a61af66fc99e Initial load
duke
parents:
diff changeset
254 if (!is_interp_only_mode()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
255 _cur_stack_depth = UNKNOWN_STACK_DEPTH;
a61af66fc99e Initial load
duke
parents:
diff changeset
256 }
a61af66fc99e Initial load
duke
parents:
diff changeset
257 if (_cur_stack_depth != UNKNOWN_STACK_DEPTH) {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 ++_cur_stack_depth;
a61af66fc99e Initial load
duke
parents:
diff changeset
259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
260 }
a61af66fc99e Initial load
duke
parents:
diff changeset
261
a61af66fc99e Initial load
duke
parents:
diff changeset
262 void JvmtiThreadState::decr_cur_stack_depth() {
a61af66fc99e Initial load
duke
parents:
diff changeset
263 guarantee(JavaThread::current() == get_thread(), "must be current thread");
a61af66fc99e Initial load
duke
parents:
diff changeset
264
a61af66fc99e Initial load
duke
parents:
diff changeset
265 if (!is_interp_only_mode()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
266 _cur_stack_depth = UNKNOWN_STACK_DEPTH;
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268 if (_cur_stack_depth != UNKNOWN_STACK_DEPTH) {
a61af66fc99e Initial load
duke
parents:
diff changeset
269 --_cur_stack_depth;
a61af66fc99e Initial load
duke
parents:
diff changeset
270 assert(_cur_stack_depth >= 0, "incr/decr_cur_stack_depth mismatch");
a61af66fc99e Initial load
duke
parents:
diff changeset
271 }
a61af66fc99e Initial load
duke
parents:
diff changeset
272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274 int JvmtiThreadState::cur_stack_depth() {
14653
0d8d78c0329a 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 6725
diff changeset
275 guarantee(SafepointSynchronize::is_at_safepoint() ||
0d8d78c0329a 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 6725
diff changeset
276 (JavaThread *)Thread::current() == get_thread(),
0d8d78c0329a 6471769: Error: assert(_cur_stack_depth == count_frames(),"cur_stack_depth out of sync")
sspitsyn
parents: 6725
diff changeset
277 "must be current thread or at safepoint");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
278
a61af66fc99e Initial load
duke
parents:
diff changeset
279 if (!is_interp_only_mode() || _cur_stack_depth == UNKNOWN_STACK_DEPTH) {
a61af66fc99e Initial load
duke
parents:
diff changeset
280 _cur_stack_depth = count_frames();
a61af66fc99e Initial load
duke
parents:
diff changeset
281 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
282 // heavy weight assert
a61af66fc99e Initial load
duke
parents:
diff changeset
283 assert(_cur_stack_depth == count_frames(),
a61af66fc99e Initial load
duke
parents:
diff changeset
284 "cur_stack_depth out of sync");
a61af66fc99e Initial load
duke
parents:
diff changeset
285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
286 return _cur_stack_depth;
a61af66fc99e Initial load
duke
parents:
diff changeset
287 }
a61af66fc99e Initial load
duke
parents:
diff changeset
288
a61af66fc99e Initial load
duke
parents:
diff changeset
289 bool JvmtiThreadState::may_be_walked() {
a61af66fc99e Initial load
duke
parents:
diff changeset
290 return (get_thread()->is_being_ext_suspended() || (JavaThread::current() == get_thread()));
a61af66fc99e Initial load
duke
parents:
diff changeset
291 }
a61af66fc99e Initial load
duke
parents:
diff changeset
292
a61af66fc99e Initial load
duke
parents:
diff changeset
293
a61af66fc99e Initial load
duke
parents:
diff changeset
294 void JvmtiThreadState::process_pending_step_for_popframe() {
a61af66fc99e Initial load
duke
parents:
diff changeset
295 // We are single stepping as the last part of the PopFrame() dance
a61af66fc99e Initial load
duke
parents:
diff changeset
296 // so we have some house keeping to do.
a61af66fc99e Initial load
duke
parents:
diff changeset
297
a61af66fc99e Initial load
duke
parents:
diff changeset
298 JavaThread *thr = get_thread();
a61af66fc99e Initial load
duke
parents:
diff changeset
299 if (thr->popframe_condition() != JavaThread::popframe_inactive) {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 // If the popframe_condition field is not popframe_inactive, then
a61af66fc99e Initial load
duke
parents:
diff changeset
301 // we missed all of the popframe_field cleanup points:
a61af66fc99e Initial load
duke
parents:
diff changeset
302 //
a61af66fc99e Initial load
duke
parents:
diff changeset
303 // - unpack_frames() was not called (nothing to deopt)
a61af66fc99e Initial load
duke
parents:
diff changeset
304 // - remove_activation_preserving_args_entry() was not called
a61af66fc99e Initial load
duke
parents:
diff changeset
305 // (did not get suspended in a call_vm() family call and did
a61af66fc99e Initial load
duke
parents:
diff changeset
306 // not complete a call_vm() family call on the way here)
a61af66fc99e Initial load
duke
parents:
diff changeset
307 thr->clear_popframe_condition();
a61af66fc99e Initial load
duke
parents:
diff changeset
308 }
a61af66fc99e Initial load
duke
parents:
diff changeset
309
a61af66fc99e Initial load
duke
parents:
diff changeset
310 // clearing the flag indicates we are done with the PopFrame() dance
a61af66fc99e Initial load
duke
parents:
diff changeset
311 clr_pending_step_for_popframe();
a61af66fc99e Initial load
duke
parents:
diff changeset
312
4841
af739d5ab23c 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 1972
diff changeset
313 // If exception was thrown in this frame, need to reset jvmti thread state.
af739d5ab23c 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 1972
diff changeset
314 // Single stepping may not get enabled correctly by the agent since
af739d5ab23c 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 1972
diff changeset
315 // exception state is passed in MethodExit event which may be sent at some
af739d5ab23c 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 1972
diff changeset
316 // time in the future. JDWP agent ignores MethodExit events if caused by
af739d5ab23c 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 1972
diff changeset
317 // an exception.
af739d5ab23c 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 1972
diff changeset
318 //
af739d5ab23c 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 1972
diff changeset
319 if (is_exception_detected()) {
af739d5ab23c 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 1972
diff changeset
320 clear_exception_detected();
af739d5ab23c 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 1972
diff changeset
321 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
322 // If step is pending for popframe then it may not be
a61af66fc99e Initial load
duke
parents:
diff changeset
323 // a repeat step. The new_bci and method_id is same as current_bci
a61af66fc99e Initial load
duke
parents:
diff changeset
324 // and current method_id after pop and step for recursive calls.
a61af66fc99e Initial load
duke
parents:
diff changeset
325 // Force the step by clearing the last location.
a61af66fc99e Initial load
duke
parents:
diff changeset
326 JvmtiEnvThreadStateIterator it(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
327 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
328 ets->clear_current_location();
a61af66fc99e Initial load
duke
parents:
diff changeset
329 }
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331
a61af66fc99e Initial load
duke
parents:
diff changeset
332
a61af66fc99e Initial load
duke
parents:
diff changeset
333 // Class: JvmtiThreadState
a61af66fc99e Initial load
duke
parents:
diff changeset
334 // Function: update_for_pop_top_frame
a61af66fc99e Initial load
duke
parents:
diff changeset
335 // Description:
a61af66fc99e Initial load
duke
parents:
diff changeset
336 // This function removes any frame pop notification request for
a61af66fc99e Initial load
duke
parents:
diff changeset
337 // the top frame and invalidates both the current stack depth and
a61af66fc99e Initial load
duke
parents:
diff changeset
338 // all cached frameIDs.
a61af66fc99e Initial load
duke
parents:
diff changeset
339 //
a61af66fc99e Initial load
duke
parents:
diff changeset
340 // Called by: PopFrame
a61af66fc99e Initial load
duke
parents:
diff changeset
341 //
a61af66fc99e Initial load
duke
parents:
diff changeset
342 void JvmtiThreadState::update_for_pop_top_frame() {
a61af66fc99e Initial load
duke
parents:
diff changeset
343 if (is_interp_only_mode()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
344 // remove any frame pop notification request for the top frame
a61af66fc99e Initial load
duke
parents:
diff changeset
345 // in any environment
a61af66fc99e Initial load
duke
parents:
diff changeset
346 int popframe_number = cur_stack_depth();
a61af66fc99e Initial load
duke
parents:
diff changeset
347 {
a61af66fc99e Initial load
duke
parents:
diff changeset
348 JvmtiEnvThreadStateIterator it(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
349 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
350 if (ets->is_frame_pop(popframe_number)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
351 ets->clear_frame_pop(popframe_number);
a61af66fc99e Initial load
duke
parents:
diff changeset
352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
354 }
a61af66fc99e Initial load
duke
parents:
diff changeset
355 // force stack depth to be recalculated
a61af66fc99e Initial load
duke
parents:
diff changeset
356 invalidate_cur_stack_depth();
a61af66fc99e Initial load
duke
parents:
diff changeset
357 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 assert(!is_enabled(JVMTI_EVENT_FRAME_POP), "Must have no framepops set");
a61af66fc99e Initial load
duke
parents:
diff changeset
359 }
a61af66fc99e Initial load
duke
parents:
diff changeset
360 }
a61af66fc99e Initial load
duke
parents:
diff changeset
361
a61af66fc99e Initial load
duke
parents:
diff changeset
362
a61af66fc99e Initial load
duke
parents:
diff changeset
363 void JvmtiThreadState::process_pending_step_for_earlyret() {
a61af66fc99e Initial load
duke
parents:
diff changeset
364 // We are single stepping as the last part of the ForceEarlyReturn
a61af66fc99e Initial load
duke
parents:
diff changeset
365 // dance so we have some house keeping to do.
a61af66fc99e Initial load
duke
parents:
diff changeset
366
a61af66fc99e Initial load
duke
parents:
diff changeset
367 if (is_earlyret_pending()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
368 // If the earlyret_state field is not earlyret_inactive, then
a61af66fc99e Initial load
duke
parents:
diff changeset
369 // we missed all of the earlyret_field cleanup points:
a61af66fc99e Initial load
duke
parents:
diff changeset
370 //
a61af66fc99e Initial load
duke
parents:
diff changeset
371 // - remove_activation() was not called
a61af66fc99e Initial load
duke
parents:
diff changeset
372 // (did not get suspended in a call_vm() family call and did
a61af66fc99e Initial load
duke
parents:
diff changeset
373 // not complete a call_vm() family call on the way here)
a61af66fc99e Initial load
duke
parents:
diff changeset
374 //
a61af66fc99e Initial load
duke
parents:
diff changeset
375 // One legitimate way for us to miss all the cleanup points is
a61af66fc99e Initial load
duke
parents:
diff changeset
376 // if we got here right after handling a compiled return. If that
a61af66fc99e Initial load
duke
parents:
diff changeset
377 // is the case, then we consider our return from compiled code to
a61af66fc99e Initial load
duke
parents:
diff changeset
378 // complete the ForceEarlyReturn request and we clear the condition.
a61af66fc99e Initial load
duke
parents:
diff changeset
379 clr_earlyret_pending();
a61af66fc99e Initial load
duke
parents:
diff changeset
380 set_earlyret_oop(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
381 clr_earlyret_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
382 }
a61af66fc99e Initial load
duke
parents:
diff changeset
383
a61af66fc99e Initial load
duke
parents:
diff changeset
384 // clearing the flag indicates we are done with
a61af66fc99e Initial load
duke
parents:
diff changeset
385 // the ForceEarlyReturn() dance
a61af66fc99e Initial load
duke
parents:
diff changeset
386 clr_pending_step_for_earlyret();
a61af66fc99e Initial load
duke
parents:
diff changeset
387
4841
af739d5ab23c 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 1972
diff changeset
388 // If exception was thrown in this frame, need to reset jvmti thread state.
af739d5ab23c 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 1972
diff changeset
389 // Single stepping may not get enabled correctly by the agent since
af739d5ab23c 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 1972
diff changeset
390 // exception state is passed in MethodExit event which may be sent at some
af739d5ab23c 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 1972
diff changeset
391 // time in the future. JDWP agent ignores MethodExit events if caused by
af739d5ab23c 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 1972
diff changeset
392 // an exception.
af739d5ab23c 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 1972
diff changeset
393 //
af739d5ab23c 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 1972
diff changeset
394 if (is_exception_detected()) {
af739d5ab23c 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 1972
diff changeset
395 clear_exception_detected();
af739d5ab23c 6972759: Step over not working after thrown exception and Pop
bpittore
parents: 1972
diff changeset
396 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
397 // If step is pending for earlyret then it may not be a repeat step.
a61af66fc99e Initial load
duke
parents:
diff changeset
398 // The new_bci and method_id is same as current_bci and current
a61af66fc99e Initial load
duke
parents:
diff changeset
399 // method_id after earlyret and step for recursive calls.
a61af66fc99e Initial load
duke
parents:
diff changeset
400 // Force the step by clearing the last location.
a61af66fc99e Initial load
duke
parents:
diff changeset
401 JvmtiEnvThreadStateIterator it(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
402 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
403 ets->clear_current_location();
a61af66fc99e Initial load
duke
parents:
diff changeset
404 }
a61af66fc99e Initial load
duke
parents:
diff changeset
405 }
a61af66fc99e Initial load
duke
parents:
diff changeset
406
a61af66fc99e Initial load
duke
parents:
diff changeset
407 void JvmtiThreadState::oops_do(OopClosure* f) {
a61af66fc99e Initial load
duke
parents:
diff changeset
408 f->do_oop((oop*) &_earlyret_oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
409 }