1 /*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
46
47 JvmtiThreadState *JvmtiThreadState::_head = NULL;
48
49 JvmtiThreadState::JvmtiThreadState(JavaThread* thread)
50 : _thread_event_enable() {
51 assert(JvmtiThreadState_lock->is_locked(), "sanity check");
52 _thread = thread;
53 _exception_detected = false;
54 _exception_caught = false;
55 _debuggable = true;
56 _hide_single_stepping = false;
57 _hide_level = 0;
58 _pending_step_for_popframe = false;
59 _class_being_redefined = NULL;
60 _class_load_kind = jvmti_class_load_kind_load;
61 _head_env_thread_state = NULL;
62 _dynamic_code_event_collector = NULL;
63 _vm_object_alloc_event_collector = NULL;
64 _the_class_for_redefinition_verification = NULL;
65 _scratch_class_for_redefinition_verification = NULL;
66
67 // JVMTI ForceEarlyReturn support
68 _pending_step_for_earlyret = false;
69 _earlyret_state = earlyret_inactive;
70 _earlyret_tos = ilgl;
71 _earlyret_value.j = 0L;
72 _earlyret_oop = NULL;
73
74 // add all the JvmtiEnvThreadState to the new JvmtiThreadState
75 {
76 JvmtiEnvIterator it;
77 for (JvmtiEnvBase* env = it.first(); env != NULL; env = it.next(env)) {
78 if (env->is_valid()) {
79 add_env(env);
80 }
81 }
82 }
83
84 // link us into the list
85 {
227 javaVFrame *jvf = get_thread()->last_java_vframe(®_map);
228 int n = 0;
229 // tty->print_cr("CSD: counting frames on %s ...",
230 // JvmtiTrace::safe_get_thread_name(get_thread()));
231 while (jvf != NULL) {
232 Method* method = jvf->method();
233 // tty->print_cr("CSD: frame - method %s.%s - loc %d",
234 // method->klass_name()->as_C_string(),
235 // method->name()->as_C_string(),
236 // jvf->bci() );
237 jvf = jvf->java_sender();
238 n++;
239 }
240 // tty->print_cr("CSD: frame count: %d", n);
241 return n;
242 }
243
244
245 void JvmtiThreadState::invalidate_cur_stack_depth() {
246 Thread *cur = Thread::current();
247 uint32_t debug_bits = 0;
248
249 // The caller can be the VMThread at a safepoint, the current thread
250 // or the target thread must be suspended.
251 guarantee((cur->is_VM_thread() && SafepointSynchronize::is_at_safepoint()) ||
252 (JavaThread *)cur == get_thread() ||
253 JvmtiEnv::is_thread_fully_suspended(get_thread(), false, &debug_bits),
254 "sanity check");
255
256 _cur_stack_depth = UNKNOWN_STACK_DEPTH;
257 }
258
259 void JvmtiThreadState::incr_cur_stack_depth() {
260 guarantee(JavaThread::current() == get_thread(), "must be current thread");
261
262 if (!is_interp_only_mode()) {
263 _cur_stack_depth = UNKNOWN_STACK_DEPTH;
264 }
265 if (_cur_stack_depth != UNKNOWN_STACK_DEPTH) {
266 ++_cur_stack_depth;
267 }
268 }
269
270 void JvmtiThreadState::decr_cur_stack_depth() {
271 guarantee(JavaThread::current() == get_thread(), "must be current thread");
272
273 if (!is_interp_only_mode()) {
274 _cur_stack_depth = UNKNOWN_STACK_DEPTH;
275 }
276 if (_cur_stack_depth != UNKNOWN_STACK_DEPTH) {
277 --_cur_stack_depth;
278 assert(_cur_stack_depth >= 0, "incr/decr_cur_stack_depth mismatch");
279 }
280 }
281
282 int JvmtiThreadState::cur_stack_depth() {
283 uint32_t debug_bits = 0;
284 guarantee(JavaThread::current() == get_thread() ||
285 JvmtiEnv::is_thread_fully_suspended(get_thread(), false, &debug_bits),
286 "must be current thread or suspended");
287
288 if (!is_interp_only_mode() || _cur_stack_depth == UNKNOWN_STACK_DEPTH) {
289 _cur_stack_depth = count_frames();
290 } else {
291 // heavy weight assert
292 assert(_cur_stack_depth == count_frames(),
293 "cur_stack_depth out of sync");
294 }
295 return _cur_stack_depth;
296 }
297
298 bool JvmtiThreadState::may_be_walked() {
299 return (get_thread()->is_being_ext_suspended() || (JavaThread::current() == get_thread()));
300 }
301
302
303 void JvmtiThreadState::process_pending_step_for_popframe() {
304 // We are single stepping as the last part of the PopFrame() dance
305 // so we have some house keeping to do.
306
307 JavaThread *thr = get_thread();
|
1 /*
2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
46
47 JvmtiThreadState *JvmtiThreadState::_head = NULL;
48
49 JvmtiThreadState::JvmtiThreadState(JavaThread* thread)
50 : _thread_event_enable() {
51 assert(JvmtiThreadState_lock->is_locked(), "sanity check");
52 _thread = thread;
53 _exception_detected = false;
54 _exception_caught = false;
55 _debuggable = true;
56 _hide_single_stepping = false;
57 _hide_level = 0;
58 _pending_step_for_popframe = false;
59 _class_being_redefined = NULL;
60 _class_load_kind = jvmti_class_load_kind_load;
61 _head_env_thread_state = NULL;
62 _dynamic_code_event_collector = NULL;
63 _vm_object_alloc_event_collector = NULL;
64 _the_class_for_redefinition_verification = NULL;
65 _scratch_class_for_redefinition_verification = NULL;
66 _cur_stack_depth = UNKNOWN_STACK_DEPTH;
67
68 // JVMTI ForceEarlyReturn support
69 _pending_step_for_earlyret = false;
70 _earlyret_state = earlyret_inactive;
71 _earlyret_tos = ilgl;
72 _earlyret_value.j = 0L;
73 _earlyret_oop = NULL;
74
75 // add all the JvmtiEnvThreadState to the new JvmtiThreadState
76 {
77 JvmtiEnvIterator it;
78 for (JvmtiEnvBase* env = it.first(); env != NULL; env = it.next(env)) {
79 if (env->is_valid()) {
80 add_env(env);
81 }
82 }
83 }
84
85 // link us into the list
86 {
228 javaVFrame *jvf = get_thread()->last_java_vframe(®_map);
229 int n = 0;
230 // tty->print_cr("CSD: counting frames on %s ...",
231 // JvmtiTrace::safe_get_thread_name(get_thread()));
232 while (jvf != NULL) {
233 Method* method = jvf->method();
234 // tty->print_cr("CSD: frame - method %s.%s - loc %d",
235 // method->klass_name()->as_C_string(),
236 // method->name()->as_C_string(),
237 // jvf->bci() );
238 jvf = jvf->java_sender();
239 n++;
240 }
241 // tty->print_cr("CSD: frame count: %d", n);
242 return n;
243 }
244
245
246 void JvmtiThreadState::invalidate_cur_stack_depth() {
247 Thread *cur = Thread::current();
248
249 guarantee((cur->is_VM_thread() && SafepointSynchronize::is_at_safepoint()) ||
250 (JavaThread *)cur == get_thread(),
251 "must be current thread or at safepont");
252
253 _cur_stack_depth = UNKNOWN_STACK_DEPTH;
254 }
255
256 void JvmtiThreadState::incr_cur_stack_depth() {
257 guarantee(JavaThread::current() == get_thread(), "must be current thread");
258
259 if (!is_interp_only_mode()) {
260 _cur_stack_depth = UNKNOWN_STACK_DEPTH;
261 }
262 if (_cur_stack_depth != UNKNOWN_STACK_DEPTH) {
263 ++_cur_stack_depth;
264 }
265 }
266
267 void JvmtiThreadState::decr_cur_stack_depth() {
268 guarantee(JavaThread::current() == get_thread(), "must be current thread");
269
270 if (!is_interp_only_mode()) {
271 _cur_stack_depth = UNKNOWN_STACK_DEPTH;
272 }
273 if (_cur_stack_depth != UNKNOWN_STACK_DEPTH) {
274 --_cur_stack_depth;
275 assert(_cur_stack_depth >= 0, "incr/decr_cur_stack_depth mismatch");
276 }
277 }
278
279 int JvmtiThreadState::cur_stack_depth() {
280 Thread *cur = Thread::current();
281
282 guarantee((cur->is_VM_thread() && SafepointSynchronize::is_at_safepoint()) ||
283 (JavaThread *)cur == get_thread(),
284 "must be current thread or at safepont");
285
286 if (!is_interp_only_mode() || _cur_stack_depth == UNKNOWN_STACK_DEPTH) {
287 _cur_stack_depth = count_frames();
288 } else {
289 // heavy weight assert
290 assert(_cur_stack_depth == count_frames(),
291 "cur_stack_depth out of sync");
292 }
293 return _cur_stack_depth;
294 }
295
296 bool JvmtiThreadState::may_be_walked() {
297 return (get_thread()->is_being_ext_suspended() || (JavaThread::current() == get_thread()));
298 }
299
300
301 void JvmtiThreadState::process_pending_step_for_popframe() {
302 // We are single stepping as the last part of the PopFrame() dance
303 // so we have some house keeping to do.
304
305 JavaThread *thr = get_thread();
|