src/share/vm/prims/jvmtiEnvThreadState.cpp

Wed, 23 Jan 2013 13:02:39 -0500

author
jprovino
date
Wed, 23 Jan 2013 13:02:39 -0500
changeset 4542
db9981fd3124
parent 4037
da91efe96a93
child 6146
c8c2d6b82499
permissions
-rw-r--r--

8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
Summary: Rename INCLUDE_ALTERNATE_GCS to INCLUDE_ALL_GCS and replace SERIALGC with INCLUDE_ALL_GCS.
Reviewed-by: coleenp, stefank

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 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "classfile/systemDictionary.hpp"
stefank@2314 27 #include "interpreter/interpreter.hpp"
stefank@2314 28 #include "jvmtifiles/jvmtiEnv.hpp"
stefank@2314 29 #include "memory/resourceArea.hpp"
stefank@2314 30 #include "prims/jvmtiEnvThreadState.hpp"
stefank@2314 31 #include "prims/jvmtiEventController.inline.hpp"
stefank@2314 32 #include "prims/jvmtiImpl.hpp"
stefank@2314 33 #include "runtime/handles.hpp"
stefank@2314 34 #include "runtime/handles.inline.hpp"
stefank@2314 35 #include "runtime/interfaceSupport.hpp"
stefank@2314 36 #include "runtime/javaCalls.hpp"
stefank@2314 37 #include "runtime/signature.hpp"
stefank@2314 38 #include "runtime/vframe.hpp"
stefank@2314 39 #include "runtime/vm_operations.hpp"
duke@435 40
duke@435 41
duke@435 42 ///////////////////////////////////////////////////////////////
duke@435 43 //
duke@435 44 // class JvmtiFramePop
duke@435 45 //
duke@435 46
duke@435 47 #ifndef PRODUCT
duke@435 48 void JvmtiFramePop::print() {
duke@435 49 tty->print_cr("_frame_number=%d", _frame_number);
duke@435 50 }
duke@435 51 #endif
duke@435 52
duke@435 53
duke@435 54 ///////////////////////////////////////////////////////////////
duke@435 55 //
duke@435 56 // class JvmtiFramePops - private methods
duke@435 57 //
duke@435 58
duke@435 59 void
duke@435 60 JvmtiFramePops::set(JvmtiFramePop& fp) {
duke@435 61 if (_pops->find(fp.frame_number()) < 0) {
duke@435 62 _pops->append(fp.frame_number());
duke@435 63 }
duke@435 64 }
duke@435 65
duke@435 66
duke@435 67 void
duke@435 68 JvmtiFramePops::clear(JvmtiFramePop& fp) {
duke@435 69 assert(_pops->length() > 0, "No more frame pops");
duke@435 70
duke@435 71 _pops->remove(fp.frame_number());
duke@435 72 }
duke@435 73
duke@435 74
duke@435 75 int
duke@435 76 JvmtiFramePops::clear_to(JvmtiFramePop& fp) {
duke@435 77 int cleared = 0;
duke@435 78 int index = 0;
duke@435 79 while (index < _pops->length()) {
duke@435 80 JvmtiFramePop pop = JvmtiFramePop(_pops->at(index));
duke@435 81 if (pop.above_on_stack(fp)) {
duke@435 82 _pops->remove_at(index);
duke@435 83 ++cleared;
duke@435 84 } else {
duke@435 85 ++index;
duke@435 86 }
duke@435 87 }
duke@435 88 return cleared;
duke@435 89 }
duke@435 90
duke@435 91
duke@435 92 ///////////////////////////////////////////////////////////////
duke@435 93 //
duke@435 94 // class JvmtiFramePops - public methods
duke@435 95 //
duke@435 96
duke@435 97 JvmtiFramePops::JvmtiFramePops() {
zgu@3900 98 _pops = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<int> (2, true);
duke@435 99 }
duke@435 100
duke@435 101 JvmtiFramePops::~JvmtiFramePops() {
duke@435 102 // return memory to c_heap.
duke@435 103 delete _pops;
duke@435 104 }
duke@435 105
duke@435 106
duke@435 107 #ifndef PRODUCT
duke@435 108 void JvmtiFramePops::print() {
duke@435 109 ResourceMark rm;
duke@435 110
duke@435 111 int n = _pops->length();
duke@435 112 for (int i=0; i<n; i++) {
duke@435 113 JvmtiFramePop fp = JvmtiFramePop(_pops->at(i));
duke@435 114 tty->print("%d: ", i);
duke@435 115 fp.print();
duke@435 116 tty->print_cr("");
duke@435 117 }
duke@435 118 }
duke@435 119 #endif
duke@435 120
duke@435 121 ///////////////////////////////////////////////////////////////
duke@435 122 //
duke@435 123 // class JvmtiEnvThreadState
duke@435 124 //
duke@435 125 // Instances of JvmtiEnvThreadState hang off of each JvmtiThreadState,
duke@435 126 // one per JvmtiEnv.
duke@435 127 //
duke@435 128
duke@435 129 JvmtiEnvThreadState::JvmtiEnvThreadState(JavaThread *thread, JvmtiEnvBase *env) :
duke@435 130 _event_enable() {
duke@435 131 _thread = thread;
duke@435 132 _env = (JvmtiEnv*)env;
duke@435 133 _next = NULL;
duke@435 134 _frame_pops = NULL;
duke@435 135 _current_bci = 0;
duke@435 136 _current_method_id = NULL;
duke@435 137 _breakpoint_posted = false;
duke@435 138 _single_stepping_posted = false;
duke@435 139 _agent_thread_local_storage_data = NULL;
duke@435 140 }
duke@435 141
duke@435 142 JvmtiEnvThreadState::~JvmtiEnvThreadState() {
duke@435 143 delete _frame_pops;
duke@435 144 _frame_pops = NULL;
duke@435 145 }
duke@435 146
duke@435 147 // Given that a new (potential) event has come in,
duke@435 148 // maintain the current JVMTI location on a per-thread per-env basis
duke@435 149 // and use it to filter out duplicate events:
duke@435 150 // - instruction rewrites
duke@435 151 // - breakpoint followed by single step
duke@435 152 // - single step at a breakpoint
coleenp@4037 153 void JvmtiEnvThreadState::compare_and_set_current_location(Method* new_method,
duke@435 154 address new_location, jvmtiEvent event) {
duke@435 155
duke@435 156 int new_bci = new_location - new_method->code_base();
duke@435 157
duke@435 158 // The method is identified and stored as a jmethodID which is safe in this
duke@435 159 // case because the class cannot be unloaded while a method is executing.
duke@435 160 jmethodID new_method_id = new_method->jmethod_id();
duke@435 161
duke@435 162 // the last breakpoint or single step was at this same location
duke@435 163 if (_current_bci == new_bci && _current_method_id == new_method_id) {
duke@435 164 switch (event) {
duke@435 165 case JVMTI_EVENT_BREAKPOINT:
duke@435 166 // Repeat breakpoint is complicated. If we previously posted a breakpoint
duke@435 167 // event at this location and if we also single stepped at this location
duke@435 168 // then we skip the duplicate breakpoint.
duke@435 169 _breakpoint_posted = _breakpoint_posted && _single_stepping_posted;
duke@435 170 break;
duke@435 171 case JVMTI_EVENT_SINGLE_STEP:
duke@435 172 // Repeat single step is easy: just don't post it again.
duke@435 173 // If step is pending for popframe then it may not be
duke@435 174 // a repeat step. The new_bci and method_id is same as current_bci
duke@435 175 // and current method_id after pop and step for recursive calls.
duke@435 176 // This has been handled by clearing the location
duke@435 177 _single_stepping_posted = true;
duke@435 178 break;
duke@435 179 default:
duke@435 180 assert(false, "invalid event value passed");
duke@435 181 break;
duke@435 182 }
duke@435 183 return;
duke@435 184 }
duke@435 185
duke@435 186 set_current_location(new_method_id, new_bci);
duke@435 187 _breakpoint_posted = false;
duke@435 188 _single_stepping_posted = false;
duke@435 189 }
duke@435 190
duke@435 191
duke@435 192 JvmtiFramePops* JvmtiEnvThreadState::get_frame_pops() {
duke@435 193 #ifdef ASSERT
duke@435 194 uint32_t debug_bits = 0;
duke@435 195 #endif
duke@435 196 assert(get_thread() == Thread::current() || JvmtiEnv::is_thread_fully_suspended(get_thread(), false, &debug_bits),
duke@435 197 "frame pop data only accessible from same thread or while suspended");
duke@435 198
duke@435 199 if (_frame_pops == NULL) {
duke@435 200 _frame_pops = new JvmtiFramePops();
duke@435 201 assert(_frame_pops != NULL, "_frame_pops != NULL");
duke@435 202 }
duke@435 203 return _frame_pops;
duke@435 204 }
duke@435 205
duke@435 206
duke@435 207 bool JvmtiEnvThreadState::has_frame_pops() {
duke@435 208 return _frame_pops == NULL? false : (_frame_pops->length() > 0);
duke@435 209 }
duke@435 210
duke@435 211 void JvmtiEnvThreadState::set_frame_pop(int frame_number) {
duke@435 212 #ifdef ASSERT
duke@435 213 uint32_t debug_bits = 0;
duke@435 214 #endif
duke@435 215 assert(get_thread() == Thread::current() || JvmtiEnv::is_thread_fully_suspended(get_thread(), false, &debug_bits),
duke@435 216 "frame pop data only accessible from same thread or while suspended");
duke@435 217 JvmtiFramePop fpop(frame_number);
duke@435 218 JvmtiEventController::set_frame_pop(this, fpop);
duke@435 219 }
duke@435 220
duke@435 221
duke@435 222 void JvmtiEnvThreadState::clear_frame_pop(int frame_number) {
duke@435 223 #ifdef ASSERT
duke@435 224 uint32_t debug_bits = 0;
duke@435 225 #endif
duke@435 226 assert(get_thread() == Thread::current() || JvmtiEnv::is_thread_fully_suspended(get_thread(), false, &debug_bits),
duke@435 227 "frame pop data only accessible from same thread or while suspended");
duke@435 228 JvmtiFramePop fpop(frame_number);
duke@435 229 JvmtiEventController::clear_frame_pop(this, fpop);
duke@435 230 }
duke@435 231
duke@435 232
duke@435 233 void JvmtiEnvThreadState::clear_to_frame_pop(int frame_number) {
duke@435 234 #ifdef ASSERT
duke@435 235 uint32_t debug_bits = 0;
duke@435 236 #endif
duke@435 237 assert(get_thread() == Thread::current() || JvmtiEnv::is_thread_fully_suspended(get_thread(), false, &debug_bits),
duke@435 238 "frame pop data only accessible from same thread or while suspended");
duke@435 239 JvmtiFramePop fpop(frame_number);
duke@435 240 JvmtiEventController::clear_to_frame_pop(this, fpop);
duke@435 241 }
duke@435 242
duke@435 243
duke@435 244 bool JvmtiEnvThreadState::is_frame_pop(int cur_frame_number) {
duke@435 245 #ifdef ASSERT
duke@435 246 uint32_t debug_bits = 0;
duke@435 247 #endif
duke@435 248 assert(get_thread() == Thread::current() || JvmtiEnv::is_thread_fully_suspended(get_thread(), false, &debug_bits),
duke@435 249 "frame pop data only accessible from same thread or while suspended");
duke@435 250 if (!get_thread()->is_interp_only_mode() || _frame_pops == NULL) {
duke@435 251 return false;
duke@435 252 }
duke@435 253 JvmtiFramePop fp(cur_frame_number);
duke@435 254 return get_frame_pops()->contains(fp);
duke@435 255 }
duke@435 256
duke@435 257
duke@435 258 class VM_GetCurrentLocation : public VM_Operation {
duke@435 259 private:
duke@435 260 JavaThread *_thread;
duke@435 261 jmethodID _method_id;
duke@435 262 int _bci;
duke@435 263
duke@435 264 public:
duke@435 265 VM_GetCurrentLocation(JavaThread *thread) {
duke@435 266 _thread = thread;
duke@435 267 }
duke@435 268 VMOp_Type type() const { return VMOp_GetCurrentLocation; }
duke@435 269 void doit() {
duke@435 270 ResourceMark rmark; // _thread != Thread::current()
duke@435 271 RegisterMap rm(_thread, false);
duke@435 272 javaVFrame* vf = _thread->last_java_vframe(&rm);
duke@435 273 assert(vf != NULL, "must have last java frame");
coleenp@4037 274 Method* method = vf->method();
duke@435 275 _method_id = method->jmethod_id();
duke@435 276 _bci = vf->bci();
duke@435 277 }
duke@435 278 void get_current_location(jmethodID *method_id, int *bci) {
duke@435 279 *method_id = _method_id;
duke@435 280 *bci = _bci;
duke@435 281 }
duke@435 282 };
duke@435 283
duke@435 284 void JvmtiEnvThreadState::reset_current_location(jvmtiEvent event_type, bool enabled) {
duke@435 285 assert(event_type == JVMTI_EVENT_SINGLE_STEP || event_type == JVMTI_EVENT_BREAKPOINT,
duke@435 286 "must be single-step or breakpoint event");
duke@435 287
duke@435 288 // Current location is used to detect the following:
duke@435 289 // 1) a breakpoint event followed by single-stepping to the same bci
duke@435 290 // 2) single-step to a bytecode that will be transformed to a fast version
duke@435 291 // We skip to avoid posting the duplicate single-stepping event.
duke@435 292
duke@435 293 // If single-stepping is disabled, clear current location so that
duke@435 294 // single-stepping to the same method and bcp at a later time will be
duke@435 295 // detected if single-stepping is enabled at that time (see 4388912).
duke@435 296
duke@435 297 // If single-stepping is enabled, set the current location to the
duke@435 298 // current method and bcp. This covers the following type of case,
duke@435 299 // e.g., the debugger stepi command:
duke@435 300 // - bytecode single stepped
duke@435 301 // - SINGLE_STEP event posted and SINGLE_STEP event disabled
duke@435 302 // - SINGLE_STEP event reenabled
duke@435 303 // - bytecode rewritten to fast version
duke@435 304
duke@435 305 // If breakpoint event is disabled, clear current location only if
duke@435 306 // single-stepping is not enabled. Otherwise, keep the thread location
duke@435 307 // to detect any duplicate events.
duke@435 308
duke@435 309 if (enabled) {
duke@435 310 // If enabling breakpoint, no need to reset.
duke@435 311 // Can't do anything if empty stack.
duke@435 312 if (event_type == JVMTI_EVENT_SINGLE_STEP && _thread->has_last_Java_frame()) {
duke@435 313 jmethodID method_id;
duke@435 314 int bci;
duke@435 315 // The java thread stack may not be walkable for a running thread
duke@435 316 // so get current location at safepoint.
duke@435 317 VM_GetCurrentLocation op(_thread);
duke@435 318 VMThread::execute(&op);
duke@435 319 op.get_current_location(&method_id, &bci);
duke@435 320 set_current_location(method_id, bci);
duke@435 321 }
duke@435 322 } else if (event_type == JVMTI_EVENT_SINGLE_STEP || !is_enabled(JVMTI_EVENT_SINGLE_STEP)) {
duke@435 323 // If this is to disable breakpoint, also check if single-step is not enabled
duke@435 324 clear_current_location();
duke@435 325 }
duke@435 326 }

mercurial