Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 16 | |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 17 | #include "jdwp/jdwp_event.h" |
| 18 | |
| 19 | #include <stddef.h> /* for offsetof() */ |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 20 | #include <stdlib.h> |
| 21 | #include <string.h> |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 22 | #include <unistd.h> |
| 23 | |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 24 | #include "base/logging.h" |
Elliott Hughes | e222ee0 | 2012-12-13 14:41:43 -0800 | [diff] [blame] | 25 | #include "base/stringprintf.h" |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 26 | #include "debugger.h" |
| 27 | #include "jdwp/jdwp_constants.h" |
| 28 | #include "jdwp/jdwp_expand_buf.h" |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 29 | #include "jdwp/jdwp_priv.h" |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 30 | #include "thread-inl.h" |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 31 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 32 | /* |
| 33 | General notes: |
| 34 | |
| 35 | The event add/remove stuff usually happens from the debugger thread, |
| 36 | in response to requests from the debugger, but can also happen as the |
| 37 | result of an event in an arbitrary thread (e.g. an event with a "count" |
| 38 | mod expires). It's important to keep the event list locked when processing |
| 39 | events. |
| 40 | |
| 41 | Event posting can happen from any thread. The JDWP thread will not usually |
| 42 | post anything but VM start/death, but if a JDWP request causes a class |
| 43 | to be loaded, the ClassPrepare event will come from the JDWP thread. |
| 44 | |
| 45 | |
| 46 | We can have serialization issues when we post an event to the debugger. |
| 47 | For example, a thread could send an "I hit a breakpoint and am suspending |
| 48 | myself" message to the debugger. Before it manages to suspend itself, the |
| 49 | debugger's response ("not interested, resume thread") arrives and is |
| 50 | processed. We try to resume a thread that hasn't yet suspended. |
| 51 | |
| 52 | This means that, after posting an event to the debugger, we need to wait |
| 53 | for the event thread to suspend itself (and, potentially, all other threads) |
| 54 | before processing any additional requests from the debugger. While doing |
| 55 | so we need to be aware that multiple threads may be hitting breakpoints |
| 56 | or other events simultaneously, so we either need to wait for all of them |
| 57 | or serialize the events with each other. |
| 58 | |
| 59 | The current mechanism works like this: |
| 60 | Event thread: |
| 61 | - If I'm going to suspend, grab the "I am posting an event" token. Wait |
| 62 | for it if it's not currently available. |
| 63 | - Post the event to the debugger. |
| 64 | - If appropriate, suspend others and then myself. As part of suspending |
| 65 | myself, release the "I am posting" token. |
| 66 | JDWP thread: |
| 67 | - When an event arrives, see if somebody is posting an event. If so, |
| 68 | sleep until we can acquire the "I am posting an event" token. Release |
| 69 | it immediately and continue processing -- the event we have already |
| 70 | received should not interfere with other events that haven't yet |
| 71 | been posted. |
| 72 | |
| 73 | Some care must be taken to avoid deadlock: |
| 74 | |
| 75 | - thread A and thread B exit near-simultaneously, and post thread-death |
| 76 | events with a "suspend all" clause |
| 77 | - thread A gets the event token, thread B sits and waits for it |
| 78 | - thread A wants to suspend all other threads, but thread B is waiting |
| 79 | for the token and can't be suspended |
| 80 | |
| 81 | So we need to mark thread B in such a way that thread A doesn't wait for it. |
| 82 | |
| 83 | If we just bracket the "grab event token" call with a change to VMWAIT |
| 84 | before sleeping, the switch back to RUNNING state when we get the token |
| 85 | will cause thread B to suspend (remember, thread A's global suspend is |
| 86 | still in force, even after it releases the token). Suspending while |
| 87 | holding the event token is very bad, because it prevents the JDWP thread |
| 88 | from processing incoming messages. |
| 89 | |
| 90 | We need to change to VMWAIT state at the *start* of posting an event, |
| 91 | and stay there until we either finish posting the event or decide to |
| 92 | put ourselves to sleep. That way we don't interfere with anyone else and |
| 93 | don't allow anyone else to interfere with us. |
| 94 | */ |
| 95 | |
| 96 | |
| 97 | #define kJdwpEventCommandSet 64 |
| 98 | #define kJdwpCompositeCommand 100 |
| 99 | |
| 100 | namespace art { |
| 101 | |
| 102 | namespace JDWP { |
| 103 | |
| 104 | /* |
| 105 | * Stuff to compare against when deciding if a mod matches. Only the |
| 106 | * values for mods valid for the event being evaluated will be filled in. |
| 107 | * The rest will be zeroed. |
| 108 | */ |
| 109 | struct ModBasket { |
jeffhao | 162fd33 | 2013-01-08 16:21:01 -0800 | [diff] [blame] | 110 | ModBasket() : pLoc(NULL), threadId(0), classId(0), excepClassId(0), |
| 111 | caught(false), field(0), thisPtr(0) { } |
| 112 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 113 | const JdwpLocation* pLoc; /* LocationOnly */ |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 114 | std::string className; /* ClassMatch/ClassExclude */ |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 115 | ObjectId threadId; /* ThreadOnly */ |
| 116 | RefTypeId classId; /* ClassOnly */ |
| 117 | RefTypeId excepClassId; /* ExceptionOnly */ |
| 118 | bool caught; /* ExceptionOnly */ |
| 119 | FieldId field; /* FieldOnly */ |
| 120 | ObjectId thisPtr; /* InstanceOnly */ |
| 121 | /* nothing for StepOnly -- handled differently */ |
| 122 | }; |
| 123 | |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 124 | static bool NeedsFullDeoptimization(JdwpEventKind eventKind) { |
| 125 | switch (eventKind) { |
| 126 | case EK_METHOD_ENTRY: |
| 127 | case EK_METHOD_EXIT: |
| 128 | case EK_METHOD_EXIT_WITH_RETURN_VALUE: |
| 129 | case EK_SINGLE_STEP: |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame^] | 130 | case EK_FIELD_ACCESS: |
| 131 | case EK_FIELD_MODIFICATION: |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 132 | return true; |
| 133 | default: |
| 134 | return false; |
| 135 | } |
| 136 | } |
| 137 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 138 | /* |
| 139 | * Add an event to the list. Ordering is not important. |
| 140 | * |
| 141 | * If something prevents the event from being registered, e.g. it's a |
| 142 | * single-step request on a thread that doesn't exist, the event will |
| 143 | * not be added to the list, and an appropriate error will be returned. |
| 144 | */ |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 145 | JdwpError JdwpState::RegisterEvent(JdwpEvent* pEvent) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 146 | CHECK(pEvent != NULL); |
| 147 | CHECK(pEvent->prev == NULL); |
| 148 | CHECK(pEvent->next == NULL); |
| 149 | |
| 150 | /* |
| 151 | * If one or more "break"-type mods are used, register them with |
| 152 | * the interpreter. |
| 153 | */ |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 154 | DeoptimizationRequest req; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 155 | for (int i = 0; i < pEvent->modCount; i++) { |
| 156 | const JdwpEventMod* pMod = &pEvent->mods[i]; |
| 157 | if (pMod->modKind == MK_LOCATION_ONLY) { |
| 158 | /* should only be for Breakpoint, Step, and Exception */ |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 159 | Dbg::WatchLocation(&pMod->locationOnly.loc, &req); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 160 | } else if (pMod->modKind == MK_STEP) { |
| 161 | /* should only be for EK_SINGLE_STEP; should only be one */ |
| 162 | JdwpStepSize size = static_cast<JdwpStepSize>(pMod->step.size); |
| 163 | JdwpStepDepth depth = static_cast<JdwpStepDepth>(pMod->step.depth); |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 164 | JdwpError status = Dbg::ConfigureStep(pMod->step.threadId, size, depth); |
| 165 | if (status != ERR_NONE) { |
| 166 | return status; |
| 167 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 168 | } |
| 169 | } |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 170 | if (NeedsFullDeoptimization(pEvent->eventKind)) { |
| 171 | CHECK_EQ(req.kind, DeoptimizationRequest::kNothing); |
| 172 | CHECK(req.method == nullptr); |
| 173 | req.kind = DeoptimizationRequest::kFullDeoptimization; |
| 174 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 175 | |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 176 | { |
| 177 | /* |
| 178 | * Add to list. |
| 179 | */ |
| 180 | MutexLock mu(Thread::Current(), event_list_lock_); |
| 181 | if (event_list_ != NULL) { |
| 182 | pEvent->next = event_list_; |
| 183 | event_list_->prev = pEvent; |
| 184 | } |
| 185 | event_list_ = pEvent; |
| 186 | ++event_list_size_; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 187 | } |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 188 | |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 189 | // TODO we can do better job here since we should process only one request: the one we just |
| 190 | // created. |
| 191 | Dbg::RequestDeoptimization(req); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 192 | Dbg::ManageDeoptimization(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 193 | |
| 194 | return ERR_NONE; |
| 195 | } |
| 196 | |
| 197 | /* |
| 198 | * Remove an event from the list. This will also remove the event from |
| 199 | * any optimization tables, e.g. breakpoints. |
| 200 | * |
| 201 | * Does not free the JdwpEvent. |
| 202 | * |
| 203 | * Grab the eventLock before calling here. |
| 204 | */ |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 205 | void JdwpState::UnregisterEvent(JdwpEvent* pEvent) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 206 | if (pEvent->prev == NULL) { |
| 207 | /* head of the list */ |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 208 | CHECK(event_list_ == pEvent); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 209 | |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 210 | event_list_ = pEvent->next; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 211 | } else { |
| 212 | pEvent->prev->next = pEvent->next; |
| 213 | } |
| 214 | |
| 215 | if (pEvent->next != NULL) { |
| 216 | pEvent->next->prev = pEvent->prev; |
| 217 | pEvent->next = NULL; |
| 218 | } |
| 219 | pEvent->prev = NULL; |
| 220 | |
| 221 | /* |
| 222 | * Unhook us from the interpreter, if necessary. |
| 223 | */ |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 224 | DeoptimizationRequest req; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 225 | for (int i = 0; i < pEvent->modCount; i++) { |
| 226 | JdwpEventMod* pMod = &pEvent->mods[i]; |
| 227 | if (pMod->modKind == MK_LOCATION_ONLY) { |
| 228 | /* should only be for Breakpoint, Step, and Exception */ |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 229 | Dbg::UnwatchLocation(&pMod->locationOnly.loc, &req); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 230 | } |
| 231 | if (pMod->modKind == MK_STEP) { |
| 232 | /* should only be for EK_SINGLE_STEP; should only be one */ |
| 233 | Dbg::UnconfigureStep(pMod->step.threadId); |
| 234 | } |
| 235 | } |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 236 | if (NeedsFullDeoptimization(pEvent->eventKind)) { |
| 237 | CHECK_EQ(req.kind, DeoptimizationRequest::kNothing); |
| 238 | CHECK(req.method == nullptr); |
| 239 | req.kind = DeoptimizationRequest::kFullUndeoptimization; |
| 240 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 241 | |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 242 | --event_list_size_; |
| 243 | CHECK(event_list_size_ != 0 || event_list_ == NULL); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 244 | |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 245 | Dbg::RequestDeoptimization(req); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | /* |
| 249 | * Remove the event with the given ID from the list. |
| 250 | * |
| 251 | * Failure to find the event isn't really an error, but it is a little |
| 252 | * weird. (It looks like Eclipse will try to be extra careful and will |
| 253 | * explicitly remove one-off single-step events.) |
| 254 | */ |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 255 | void JdwpState::UnregisterEventById(uint32_t requestId) { |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 256 | bool found = false; |
| 257 | { |
| 258 | MutexLock mu(Thread::Current(), event_list_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 259 | |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 260 | for (JdwpEvent* pEvent = event_list_; pEvent != nullptr; pEvent = pEvent->next) { |
| 261 | if (pEvent->requestId == requestId) { |
| 262 | found = true; |
| 263 | UnregisterEvent(pEvent); |
| 264 | EventFree(pEvent); |
| 265 | break; /* there can be only one with a given ID */ |
| 266 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 267 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 270 | if (found) { |
| 271 | Dbg::ManageDeoptimization(); |
| 272 | } else { |
| 273 | LOG(DEBUG) << StringPrintf("Odd: no match when removing event reqId=0x%04x", requestId); |
| 274 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | /* |
| 278 | * Remove all entries from the event list. |
| 279 | */ |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 280 | void JdwpState::UnregisterAll() { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 281 | MutexLock mu(Thread::Current(), event_list_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 282 | |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 283 | JdwpEvent* pEvent = event_list_; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 284 | while (pEvent != NULL) { |
| 285 | JdwpEvent* pNextEvent = pEvent->next; |
| 286 | |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 287 | UnregisterEvent(pEvent); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 288 | EventFree(pEvent); |
| 289 | pEvent = pNextEvent; |
| 290 | } |
| 291 | |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 292 | event_list_ = NULL; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /* |
| 296 | * Allocate a JdwpEvent struct with enough space to hold the specified |
| 297 | * number of mod records. |
| 298 | */ |
| 299 | JdwpEvent* EventAlloc(int numMods) { |
| 300 | JdwpEvent* newEvent; |
| 301 | int allocSize = offsetof(JdwpEvent, mods) + numMods * sizeof(newEvent->mods[0]); |
| 302 | newEvent = reinterpret_cast<JdwpEvent*>(malloc(allocSize)); |
| 303 | memset(newEvent, 0, allocSize); |
| 304 | return newEvent; |
| 305 | } |
| 306 | |
| 307 | /* |
| 308 | * Free a JdwpEvent. |
| 309 | * |
| 310 | * Do not call this until the event has been removed from the list. |
| 311 | */ |
| 312 | void EventFree(JdwpEvent* pEvent) { |
| 313 | if (pEvent == NULL) { |
| 314 | return; |
| 315 | } |
| 316 | |
| 317 | /* make sure it was removed from the list */ |
| 318 | CHECK(pEvent->prev == NULL); |
| 319 | CHECK(pEvent->next == NULL); |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 320 | /* want to check state->event_list_ != pEvent */ |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 321 | |
| 322 | /* |
| 323 | * Free any hairy bits in the mods. |
| 324 | */ |
| 325 | for (int i = 0; i < pEvent->modCount; i++) { |
| 326 | if (pEvent->mods[i].modKind == MK_CLASS_MATCH) { |
| 327 | free(pEvent->mods[i].classMatch.classPattern); |
| 328 | pEvent->mods[i].classMatch.classPattern = NULL; |
| 329 | } |
| 330 | if (pEvent->mods[i].modKind == MK_CLASS_EXCLUDE) { |
| 331 | free(pEvent->mods[i].classExclude.classPattern); |
| 332 | pEvent->mods[i].classExclude.classPattern = NULL; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | free(pEvent); |
| 337 | } |
| 338 | |
| 339 | /* |
| 340 | * Allocate storage for matching events. To keep things simple we |
| 341 | * use an array with enough storage for the entire list. |
| 342 | * |
| 343 | * The state->eventLock should be held before calling. |
| 344 | */ |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 345 | static JdwpEvent** AllocMatchList(size_t event_count) { |
| 346 | return new JdwpEvent*[event_count]; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | /* |
| 350 | * Run through the list and remove any entries with an expired "count" mod |
| 351 | * from the event list, then free the match list. |
| 352 | */ |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 353 | void JdwpState::CleanupMatchList(JdwpEvent** match_list, int match_count) { |
| 354 | JdwpEvent** ppEvent = match_list; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 355 | |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 356 | while (match_count--) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 357 | JdwpEvent* pEvent = *ppEvent; |
| 358 | |
| 359 | for (int i = 0; i < pEvent->modCount; i++) { |
| 360 | if (pEvent->mods[i].modKind == MK_COUNT && pEvent->mods[i].count.count == 0) { |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 361 | VLOG(jdwp) << "##### Removing expired event"; |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 362 | UnregisterEvent(pEvent); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 363 | EventFree(pEvent); |
| 364 | break; |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | ppEvent++; |
| 369 | } |
| 370 | |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 371 | delete[] match_list; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | /* |
| 375 | * Match a string against a "restricted regular expression", which is just |
| 376 | * a string that may start or end with '*' (e.g. "*.Foo" or "java.*"). |
| 377 | * |
| 378 | * ("Restricted name globbing" might have been a better term.) |
| 379 | */ |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 380 | static bool PatternMatch(const char* pattern, const std::string& target) { |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 381 | size_t patLen = strlen(pattern); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 382 | if (pattern[0] == '*') { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 383 | patLen--; |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 384 | if (target.size() < patLen) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 385 | return false; |
| 386 | } |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 387 | return strcmp(pattern+1, target.c_str() + (target.size()-patLen)) == 0; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 388 | } else if (pattern[patLen-1] == '*') { |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 389 | return strncmp(pattern, target.c_str(), patLen-1) == 0; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 390 | } else { |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 391 | return strcmp(pattern, target.c_str()) == 0; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | |
| 395 | /* |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 396 | * See if the event's mods match up with the contents of "basket". |
| 397 | * |
| 398 | * If we find a Count mod before rejecting an event, we decrement it. We |
| 399 | * need to do this even if later mods cause us to ignore the event. |
| 400 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 401 | static bool ModsMatch(JdwpEvent* pEvent, ModBasket* basket) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 402 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 403 | JdwpEventMod* pMod = pEvent->mods; |
| 404 | |
| 405 | for (int i = pEvent->modCount; i > 0; i--, pMod++) { |
| 406 | switch (pMod->modKind) { |
| 407 | case MK_COUNT: |
| 408 | CHECK_GT(pMod->count.count, 0); |
| 409 | pMod->count.count--; |
| 410 | break; |
| 411 | case MK_CONDITIONAL: |
| 412 | CHECK(false); // should not be getting these |
| 413 | break; |
| 414 | case MK_THREAD_ONLY: |
| 415 | if (pMod->threadOnly.threadId != basket->threadId) { |
| 416 | return false; |
| 417 | } |
| 418 | break; |
| 419 | case MK_CLASS_ONLY: |
| 420 | if (!Dbg::MatchType(basket->classId, pMod->classOnly.refTypeId)) { |
| 421 | return false; |
| 422 | } |
| 423 | break; |
| 424 | case MK_CLASS_MATCH: |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 425 | if (!PatternMatch(pMod->classMatch.classPattern, basket->className)) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 426 | return false; |
| 427 | } |
| 428 | break; |
| 429 | case MK_CLASS_EXCLUDE: |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 430 | if (PatternMatch(pMod->classMatch.classPattern, basket->className)) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 431 | return false; |
| 432 | } |
| 433 | break; |
| 434 | case MK_LOCATION_ONLY: |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 435 | if (pMod->locationOnly.loc != *basket->pLoc) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 436 | return false; |
| 437 | } |
| 438 | break; |
| 439 | case MK_EXCEPTION_ONLY: |
| 440 | if (pMod->exceptionOnly.refTypeId != 0 && !Dbg::MatchType(basket->excepClassId, pMod->exceptionOnly.refTypeId)) { |
| 441 | return false; |
| 442 | } |
| 443 | if ((basket->caught && !pMod->exceptionOnly.caught) || (!basket->caught && !pMod->exceptionOnly.uncaught)) { |
| 444 | return false; |
| 445 | } |
| 446 | break; |
| 447 | case MK_FIELD_ONLY: |
| 448 | if (!Dbg::MatchType(basket->classId, pMod->fieldOnly.refTypeId) || pMod->fieldOnly.fieldId != basket->field) { |
| 449 | return false; |
| 450 | } |
| 451 | break; |
| 452 | case MK_STEP: |
| 453 | if (pMod->step.threadId != basket->threadId) { |
| 454 | return false; |
| 455 | } |
| 456 | break; |
| 457 | case MK_INSTANCE_ONLY: |
| 458 | if (pMod->instanceOnly.objectId != basket->thisPtr) { |
| 459 | return false; |
| 460 | } |
| 461 | break; |
| 462 | default: |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 463 | LOG(FATAL) << "unknown mod kind " << pMod->modKind; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 464 | break; |
| 465 | } |
| 466 | } |
| 467 | return true; |
| 468 | } |
| 469 | |
| 470 | /* |
| 471 | * Find all events of type "eventKind" with mods that match up with the |
| 472 | * rest of the arguments. |
| 473 | * |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 474 | * Found events are appended to "match_list", and "*pMatchCount" is advanced, |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 475 | * so this may be called multiple times for grouped events. |
| 476 | * |
| 477 | * DO NOT call this multiple times for the same eventKind, as Count mods are |
| 478 | * decremented during the scan. |
| 479 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 480 | void JdwpState::FindMatchingEvents(JdwpEventKind eventKind, ModBasket* basket, |
| 481 | JdwpEvent** match_list, int* pMatchCount) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 482 | /* start after the existing entries */ |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 483 | match_list += *pMatchCount; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 484 | |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 485 | JdwpEvent* pEvent = event_list_; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 486 | while (pEvent != NULL) { |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 487 | if (pEvent->eventKind == eventKind && ModsMatch(pEvent, basket)) { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 488 | *match_list++ = pEvent; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 489 | (*pMatchCount)++; |
| 490 | } |
| 491 | |
| 492 | pEvent = pEvent->next; |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | /* |
| 497 | * Scan through the list of matches and determine the most severe |
| 498 | * suspension policy. |
| 499 | */ |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 500 | static JdwpSuspendPolicy scanSuspendPolicy(JdwpEvent** match_list, int match_count) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 501 | JdwpSuspendPolicy policy = SP_NONE; |
| 502 | |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 503 | while (match_count--) { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 504 | if ((*match_list)->suspend_policy > policy) { |
| 505 | policy = (*match_list)->suspend_policy; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 506 | } |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 507 | match_list++; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | return policy; |
| 511 | } |
| 512 | |
| 513 | /* |
| 514 | * Three possibilities: |
| 515 | * SP_NONE - do nothing |
| 516 | * SP_EVENT_THREAD - suspend ourselves |
| 517 | * SP_ALL - suspend everybody except JDWP support thread |
| 518 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 519 | void JdwpState::SuspendByPolicy(JdwpSuspendPolicy suspend_policy, JDWP::ObjectId thread_self_id) { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 520 | VLOG(jdwp) << "SuspendByPolicy(" << suspend_policy << ")"; |
| 521 | if (suspend_policy == SP_NONE) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 522 | return; |
| 523 | } |
| 524 | |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 525 | if (suspend_policy == SP_ALL) { |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 526 | Dbg::SuspendVM(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 527 | } else { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 528 | CHECK_EQ(suspend_policy, SP_EVENT_THREAD); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | /* this is rare but possible -- see CLASS_PREPARE handling */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 532 | if (thread_self_id == debug_thread_id_) { |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 533 | LOG(INFO) << "NOTE: SuspendByPolicy not suspending JDWP thread"; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 534 | return; |
| 535 | } |
| 536 | |
| 537 | DebugInvokeReq* pReq = Dbg::GetInvokeReq(); |
| 538 | while (true) { |
| 539 | pReq->ready = true; |
| 540 | Dbg::SuspendSelf(); |
| 541 | pReq->ready = false; |
| 542 | |
| 543 | /* |
| 544 | * The JDWP thread has told us (and possibly all other threads) to |
| 545 | * resume. See if it has left anything in our DebugInvokeReq mailbox. |
| 546 | */ |
Sebastien Hertz | d38667a | 2013-11-25 15:43:54 +0100 | [diff] [blame] | 547 | if (!pReq->invoke_needed) { |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 548 | /*LOGD("SuspendByPolicy: no invoke needed");*/ |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 549 | break; |
| 550 | } |
| 551 | |
| 552 | /* grab this before posting/suspending again */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 553 | SetWaitForEventThread(thread_self_id); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 554 | |
Elliott Hughes | d07986f | 2011-12-06 18:27:45 -0800 | [diff] [blame] | 555 | /* leave pReq->invoke_needed_ raised so we can check reentrancy */ |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 556 | Dbg::ExecuteMethod(pReq); |
| 557 | |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 558 | pReq->error = ERR_NONE; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 559 | } |
| 560 | } |
| 561 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 562 | void JdwpState::SendRequestAndPossiblySuspend(ExpandBuf* pReq, JdwpSuspendPolicy suspend_policy, |
| 563 | ObjectId threadId) { |
| 564 | Thread* self = Thread::Current(); |
| 565 | self->AssertThreadSuspensionIsAllowable(); |
| 566 | /* send request and possibly suspend ourselves */ |
| 567 | if (pReq != NULL) { |
| 568 | JDWP::ObjectId thread_self_id = Dbg::GetThreadSelfId(); |
| 569 | self->TransitionFromRunnableToSuspended(kWaitingForDebuggerSend); |
| 570 | if (suspend_policy != SP_NONE) { |
| 571 | SetWaitForEventThread(threadId); |
| 572 | } |
| 573 | EventFinish(pReq); |
| 574 | SuspendByPolicy(suspend_policy, thread_self_id); |
| 575 | self->TransitionFromSuspendedToRunnable(); |
| 576 | } |
| 577 | } |
| 578 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 579 | /* |
| 580 | * Determine if there is a method invocation in progress in the current |
| 581 | * thread. |
| 582 | * |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 583 | * We look at the "invoke_needed" flag in the per-thread DebugInvokeReq |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 584 | * state. If set, we're in the process of invoking a method. |
| 585 | */ |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 586 | bool JdwpState::InvokeInProgress() { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 587 | DebugInvokeReq* pReq = Dbg::GetInvokeReq(); |
Sebastien Hertz | d38667a | 2013-11-25 15:43:54 +0100 | [diff] [blame] | 588 | return pReq->invoke_needed; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | /* |
| 592 | * We need the JDWP thread to hold off on doing stuff while we post an |
| 593 | * event and then suspend ourselves. |
| 594 | * |
| 595 | * Call this with a threadId of zero if you just want to wait for the |
| 596 | * current thread operation to complete. |
| 597 | * |
| 598 | * This could go to sleep waiting for another thread, so it's important |
| 599 | * that the thread be marked as VMWAIT before calling here. |
| 600 | */ |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 601 | void JdwpState::SetWaitForEventThread(ObjectId threadId) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 602 | bool waited = false; |
| 603 | |
| 604 | /* this is held for very brief periods; contention is unlikely */ |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 605 | Thread* self = Thread::Current(); |
| 606 | MutexLock mu(self, event_thread_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 607 | |
| 608 | /* |
| 609 | * If another thread is already doing stuff, wait for it. This can |
| 610 | * go to sleep indefinitely. |
| 611 | */ |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 612 | while (event_thread_id_ != 0) { |
Ian Rogers | d9e4e0c | 2014-01-23 20:11:40 -0800 | [diff] [blame] | 613 | VLOG(jdwp) << StringPrintf("event in progress (%#" PRIx64 "), %#" PRIx64 " sleeping", |
| 614 | event_thread_id_, threadId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 615 | waited = true; |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 616 | event_thread_cond_.Wait(self); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | if (waited || threadId != 0) { |
Ian Rogers | d9e4e0c | 2014-01-23 20:11:40 -0800 | [diff] [blame] | 620 | VLOG(jdwp) << StringPrintf("event token grabbed (%#" PRIx64 ")", threadId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 621 | } |
| 622 | if (threadId != 0) { |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 623 | event_thread_id_ = threadId; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 624 | } |
| 625 | } |
| 626 | |
| 627 | /* |
| 628 | * Clear the threadId and signal anybody waiting. |
| 629 | */ |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 630 | void JdwpState::ClearWaitForEventThread() { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 631 | /* |
| 632 | * Grab the mutex. Don't try to go in/out of VMWAIT mode, as this |
| 633 | * function is called by dvmSuspendSelf(), and the transition back |
| 634 | * to RUNNING would confuse it. |
| 635 | */ |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 636 | Thread* self = Thread::Current(); |
| 637 | MutexLock mu(self, event_thread_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 638 | |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 639 | CHECK_NE(event_thread_id_, 0U); |
Ian Rogers | d9e4e0c | 2014-01-23 20:11:40 -0800 | [diff] [blame] | 640 | VLOG(jdwp) << StringPrintf("cleared event token (%#" PRIx64 ")", event_thread_id_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 641 | |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 642 | event_thread_id_ = 0; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 643 | |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 644 | event_thread_cond_.Signal(self); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | |
| 648 | /* |
| 649 | * Prep an event. Allocates storage for the message and leaves space for |
| 650 | * the header. |
| 651 | */ |
| 652 | static ExpandBuf* eventPrep() { |
| 653 | ExpandBuf* pReq = expandBufAlloc(); |
| 654 | expandBufAddSpace(pReq, kJDWPHeaderLen); |
| 655 | return pReq; |
| 656 | } |
| 657 | |
| 658 | /* |
| 659 | * Write the header into the buffer and send the packet off to the debugger. |
| 660 | * |
| 661 | * Takes ownership of "pReq" (currently discards it). |
| 662 | */ |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 663 | void JdwpState::EventFinish(ExpandBuf* pReq) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 664 | uint8_t* buf = expandBufGetBuffer(pReq); |
| 665 | |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 666 | Set4BE(buf, expandBufGetLength(pReq)); |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 667 | Set4BE(buf+4, NextRequestSerial()); |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 668 | Set1(buf+8, 0); /* flags */ |
| 669 | Set1(buf+9, kJdwpEventCommandSet); |
| 670 | Set1(buf+10, kJdwpCompositeCommand); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 671 | |
Sebastien Hertz | 99660e1 | 2014-02-19 15:04:42 +0100 | [diff] [blame] | 672 | // Prevents from interleaving commands and events. Otherwise we could end up in sending an event |
| 673 | // before sending the reply of the command being processed and would lead to bad synchronization |
| 674 | // between the debugger and the debuggee. |
| 675 | WaitForProcessingRequest(); |
| 676 | |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 677 | SendRequest(pReq); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 678 | |
| 679 | expandBufFree(pReq); |
| 680 | } |
| 681 | |
| 682 | |
| 683 | /* |
| 684 | * Tell the debugger that we have finished initializing. This is always |
| 685 | * sent, even if the debugger hasn't requested it. |
| 686 | * |
| 687 | * This should be sent "before the main thread is started and before |
| 688 | * any application code has been executed". The thread ID in the message |
| 689 | * must be for the main thread. |
| 690 | */ |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 691 | bool JdwpState::PostVMStart() { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 692 | JdwpSuspendPolicy suspend_policy; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 693 | ObjectId threadId = Dbg::GetThreadSelfId(); |
| 694 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 695 | if (options_->suspend) { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 696 | suspend_policy = SP_ALL; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 697 | } else { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 698 | suspend_policy = SP_NONE; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 699 | } |
| 700 | |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 701 | ExpandBuf* pReq = eventPrep(); |
| 702 | { |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 703 | MutexLock mu(Thread::Current(), event_list_lock_); // probably don't need this here |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 704 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 705 | VLOG(jdwp) << "EVENT: " << EK_VM_START; |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 706 | VLOG(jdwp) << " suspend_policy=" << suspend_policy; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 707 | |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 708 | expandBufAdd1(pReq, suspend_policy); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 709 | expandBufAdd4BE(pReq, 1); |
| 710 | |
| 711 | expandBufAdd1(pReq, EK_VM_START); |
| 712 | expandBufAdd4BE(pReq, 0); /* requestId */ |
| 713 | expandBufAdd8BE(pReq, threadId); |
| 714 | } |
| 715 | |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 716 | Dbg::ManageDeoptimization(); |
| 717 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 718 | /* send request and possibly suspend ourselves */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 719 | SendRequestAndPossiblySuspend(pReq, suspend_policy, threadId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 720 | |
| 721 | return true; |
| 722 | } |
| 723 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 724 | /* |
| 725 | * A location of interest has been reached. This handles: |
| 726 | * Breakpoint |
| 727 | * SingleStep |
| 728 | * MethodEntry |
| 729 | * MethodExit |
| 730 | * These four types must be grouped together in a single response. The |
| 731 | * "eventFlags" indicates the type of event(s) that have happened. |
| 732 | * |
| 733 | * Valid mods: |
| 734 | * Count, ThreadOnly, ClassOnly, ClassMatch, ClassExclude, InstanceOnly |
| 735 | * LocationOnly (for breakpoint/step only) |
| 736 | * Step (for step only) |
| 737 | * |
| 738 | * Interesting test cases: |
| 739 | * - Put a breakpoint on a native method. Eclipse creates METHOD_ENTRY |
| 740 | * and METHOD_EXIT events with a ClassOnly mod on the method's class. |
| 741 | * - Use "run to line". Eclipse creates a BREAKPOINT with Count=1. |
| 742 | * - Single-step to a line with a breakpoint. Should get a single |
| 743 | * event message with both events in it. |
| 744 | */ |
Jeff Hao | 579b024 | 2013-11-18 13:16:49 -0800 | [diff] [blame] | 745 | bool JdwpState::PostLocationEvent(const JdwpLocation* pLoc, ObjectId thisPtr, int eventFlags, |
| 746 | const JValue* returnValue) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 747 | ModBasket basket; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 748 | basket.pLoc = pLoc; |
Elliott Hughes | 7484741 | 2012-06-20 18:10:21 -0700 | [diff] [blame] | 749 | basket.classId = pLoc->class_id; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 750 | basket.thisPtr = thisPtr; |
| 751 | basket.threadId = Dbg::GetThreadSelfId(); |
Elliott Hughes | 7484741 | 2012-06-20 18:10:21 -0700 | [diff] [blame] | 752 | basket.className = Dbg::GetClassName(pLoc->class_id); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 753 | |
| 754 | /* |
| 755 | * On rare occasions we may need to execute interpreted code in the VM |
| 756 | * while handling a request from the debugger. Don't fire breakpoints |
| 757 | * while doing so. (I don't think we currently do this at all, so |
| 758 | * this is mostly paranoia.) |
| 759 | */ |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 760 | if (basket.threadId == debug_thread_id_) { |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 761 | VLOG(jdwp) << "Ignoring location event in JDWP thread"; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 762 | return false; |
| 763 | } |
| 764 | |
| 765 | /* |
| 766 | * The debugger variable display tab may invoke the interpreter to format |
| 767 | * complex objects. We want to ignore breakpoints and method entry/exit |
| 768 | * traps while working on behalf of the debugger. |
| 769 | * |
| 770 | * If we don't ignore them, the VM will get hung up, because we'll |
| 771 | * suspend on a breakpoint while the debugger is still waiting for its |
| 772 | * method invocation to complete. |
| 773 | */ |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 774 | if (InvokeInProgress()) { |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 775 | VLOG(jdwp) << "Not checking breakpoints during invoke (" << basket.className << ")"; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 776 | return false; |
| 777 | } |
| 778 | |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 779 | int match_count = 0; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 780 | ExpandBuf* pReq = NULL; |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 781 | JdwpSuspendPolicy suspend_policy = SP_NONE; |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 782 | { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 783 | MutexLock mu(Thread::Current(), event_list_lock_); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 784 | JdwpEvent** match_list = AllocMatchList(event_list_size_); |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 785 | if ((eventFlags & Dbg::kBreakpoint) != 0) { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 786 | FindMatchingEvents(EK_BREAKPOINT, &basket, match_list, &match_count); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 787 | } |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 788 | if ((eventFlags & Dbg::kSingleStep) != 0) { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 789 | FindMatchingEvents(EK_SINGLE_STEP, &basket, match_list, &match_count); |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 790 | } |
| 791 | if ((eventFlags & Dbg::kMethodEntry) != 0) { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 792 | FindMatchingEvents(EK_METHOD_ENTRY, &basket, match_list, &match_count); |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 793 | } |
| 794 | if ((eventFlags & Dbg::kMethodExit) != 0) { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 795 | FindMatchingEvents(EK_METHOD_EXIT, &basket, match_list, &match_count); |
Jeff Hao | 579b024 | 2013-11-18 13:16:49 -0800 | [diff] [blame] | 796 | FindMatchingEvents(EK_METHOD_EXIT_WITH_RETURN_VALUE, &basket, match_list, &match_count); |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 797 | } |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 798 | if (match_count != 0) { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 799 | VLOG(jdwp) << "EVENT: " << match_list[0]->eventKind << "(" << match_count << " total) " |
Elliott Hughes | a96836a | 2013-01-17 12:27:49 -0800 | [diff] [blame] | 800 | << basket.className << "." << Dbg::GetMethodName(pLoc->method_id) |
Ian Rogers | d9e4e0c | 2014-01-23 20:11:40 -0800 | [diff] [blame] | 801 | << StringPrintf(" thread=%#" PRIx64 " dex_pc=%#" PRIx64 ")", |
| 802 | basket.threadId, pLoc->dex_pc); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 803 | |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 804 | suspend_policy = scanSuspendPolicy(match_list, match_count); |
| 805 | VLOG(jdwp) << " suspend_policy=" << suspend_policy; |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 806 | |
| 807 | pReq = eventPrep(); |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 808 | expandBufAdd1(pReq, suspend_policy); |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 809 | expandBufAdd4BE(pReq, match_count); |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 810 | |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 811 | for (int i = 0; i < match_count; i++) { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 812 | expandBufAdd1(pReq, match_list[i]->eventKind); |
| 813 | expandBufAdd4BE(pReq, match_list[i]->requestId); |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 814 | expandBufAdd8BE(pReq, basket.threadId); |
Elliott Hughes | 6e9d22c | 2012-06-22 15:02:37 -0700 | [diff] [blame] | 815 | expandBufAddLocation(pReq, *pLoc); |
Jeff Hao | 579b024 | 2013-11-18 13:16:49 -0800 | [diff] [blame] | 816 | if (match_list[i]->eventKind == EK_METHOD_EXIT_WITH_RETURN_VALUE) { |
| 817 | Dbg::OutputMethodReturnValue(pLoc->method_id, returnValue, pReq); |
| 818 | } |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 819 | } |
| 820 | } |
| 821 | |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 822 | CleanupMatchList(match_list, match_count); |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 823 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 824 | |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 825 | Dbg::ManageDeoptimization(); |
| 826 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 827 | SendRequestAndPossiblySuspend(pReq, suspend_policy, basket.threadId); |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 828 | return match_count != 0; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 829 | } |
| 830 | |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame^] | 831 | bool JdwpState::PostFieldEvent(const JdwpLocation* pLoc, RefTypeId typeId, FieldId fieldId, |
| 832 | ObjectId thisPtr, const JValue* fieldValue, bool is_modification) { |
| 833 | ModBasket basket; |
| 834 | basket.pLoc = pLoc; |
| 835 | basket.classId = pLoc->class_id; |
| 836 | basket.thisPtr = thisPtr; |
| 837 | basket.threadId = Dbg::GetThreadSelfId(); |
| 838 | basket.className = Dbg::GetClassName(pLoc->class_id); |
| 839 | basket.field = fieldId; |
| 840 | |
| 841 | if (InvokeInProgress()) { |
| 842 | VLOG(jdwp) << "Not posting field event during invoke"; |
| 843 | return false; |
| 844 | } |
| 845 | |
| 846 | // Get field's reference type tag. |
| 847 | JDWP::JdwpTypeTag type_tag; |
| 848 | uint32_t class_status; // unused here. |
| 849 | JdwpError error = Dbg::GetClassInfo(typeId, &type_tag, &class_status, NULL); |
| 850 | if (error != ERR_NONE) { |
| 851 | return false; |
| 852 | } |
| 853 | |
| 854 | // Get instance type tag. |
| 855 | uint8_t tag; |
| 856 | error = Dbg::GetObjectTag(thisPtr, tag); |
| 857 | if (error != ERR_NONE) { |
| 858 | return false; |
| 859 | } |
| 860 | |
| 861 | int match_count = 0; |
| 862 | ExpandBuf* pReq = NULL; |
| 863 | JdwpSuspendPolicy suspend_policy = SP_NONE; |
| 864 | { |
| 865 | MutexLock mu(Thread::Current(), event_list_lock_); |
| 866 | JdwpEvent** match_list = AllocMatchList(event_list_size_); |
| 867 | |
| 868 | if (is_modification) { |
| 869 | FindMatchingEvents(EK_FIELD_MODIFICATION, &basket, match_list, &match_count); |
| 870 | } else { |
| 871 | FindMatchingEvents(EK_FIELD_ACCESS, &basket, match_list, &match_count); |
| 872 | } |
| 873 | if (match_count != 0) { |
| 874 | VLOG(jdwp) << "EVENT: " << match_list[0]->eventKind << "(" << match_count << " total) " |
| 875 | << basket.className << "." << Dbg::GetMethodName(pLoc->method_id) |
| 876 | << StringPrintf(" thread=%#" PRIx64 " dex_pc=%#" PRIx64 ")", |
| 877 | basket.threadId, pLoc->dex_pc); |
| 878 | |
| 879 | suspend_policy = scanSuspendPolicy(match_list, match_count); |
| 880 | VLOG(jdwp) << " suspend_policy=" << suspend_policy; |
| 881 | |
| 882 | pReq = eventPrep(); |
| 883 | expandBufAdd1(pReq, suspend_policy); |
| 884 | expandBufAdd4BE(pReq, match_count); |
| 885 | |
| 886 | for (int i = 0; i < match_count; i++) { |
| 887 | expandBufAdd1(pReq, match_list[i]->eventKind); |
| 888 | expandBufAdd4BE(pReq, match_list[i]->requestId); |
| 889 | expandBufAdd8BE(pReq, basket.threadId); |
| 890 | expandBufAddLocation(pReq, *pLoc); |
| 891 | expandBufAdd1(pReq, type_tag); |
| 892 | expandBufAddRefTypeId(pReq, typeId); |
| 893 | expandBufAddFieldId(pReq, fieldId); |
| 894 | expandBufAdd1(pReq, tag); |
| 895 | expandBufAddObjectId(pReq, thisPtr); |
| 896 | if (is_modification) { |
| 897 | Dbg::OutputFieldValue(fieldId, fieldValue, pReq); |
| 898 | } |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | CleanupMatchList(match_list, match_count); |
| 903 | } |
| 904 | |
| 905 | Dbg::ManageDeoptimization(); |
| 906 | |
| 907 | SendRequestAndPossiblySuspend(pReq, suspend_policy, basket.threadId); |
| 908 | return match_count != 0; |
| 909 | } |
| 910 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 911 | /* |
| 912 | * A thread is starting or stopping. |
| 913 | * |
| 914 | * Valid mods: |
| 915 | * Count, ThreadOnly |
| 916 | */ |
Elliott Hughes | 234ab15 | 2011-10-26 14:02:26 -0700 | [diff] [blame] | 917 | bool JdwpState::PostThreadChange(ObjectId threadId, bool start) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 918 | CHECK_EQ(threadId, Dbg::GetThreadSelfId()); |
| 919 | |
| 920 | /* |
| 921 | * I don't think this can happen. |
| 922 | */ |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 923 | if (InvokeInProgress()) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 924 | LOG(WARNING) << "Not posting thread change during invoke"; |
| 925 | return false; |
| 926 | } |
| 927 | |
| 928 | ModBasket basket; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 929 | basket.threadId = threadId; |
| 930 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 931 | ExpandBuf* pReq = NULL; |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 932 | JdwpSuspendPolicy suspend_policy = SP_NONE; |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 933 | int match_count = 0; |
Elliott Hughes | 234ab15 | 2011-10-26 14:02:26 -0700 | [diff] [blame] | 934 | { |
| 935 | // Don't allow the list to be updated while we scan it. |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 936 | MutexLock mu(Thread::Current(), event_list_lock_); |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 937 | JdwpEvent** match_list = AllocMatchList(event_list_size_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 938 | |
Elliott Hughes | 234ab15 | 2011-10-26 14:02:26 -0700 | [diff] [blame] | 939 | if (start) { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 940 | FindMatchingEvents(EK_THREAD_START, &basket, match_list, &match_count); |
Elliott Hughes | 234ab15 | 2011-10-26 14:02:26 -0700 | [diff] [blame] | 941 | } else { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 942 | FindMatchingEvents(EK_THREAD_DEATH, &basket, match_list, &match_count); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 943 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 944 | |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 945 | if (match_count != 0) { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 946 | VLOG(jdwp) << "EVENT: " << match_list[0]->eventKind << "(" << match_count << " total) " |
Ian Rogers | d9e4e0c | 2014-01-23 20:11:40 -0800 | [diff] [blame] | 947 | << StringPrintf("thread=%#" PRIx64, basket.threadId) << ")"; |
Elliott Hughes | 234ab15 | 2011-10-26 14:02:26 -0700 | [diff] [blame] | 948 | |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 949 | suspend_policy = scanSuspendPolicy(match_list, match_count); |
| 950 | VLOG(jdwp) << " suspend_policy=" << suspend_policy; |
Elliott Hughes | 234ab15 | 2011-10-26 14:02:26 -0700 | [diff] [blame] | 951 | |
| 952 | pReq = eventPrep(); |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 953 | expandBufAdd1(pReq, suspend_policy); |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 954 | expandBufAdd4BE(pReq, match_count); |
Elliott Hughes | 234ab15 | 2011-10-26 14:02:26 -0700 | [diff] [blame] | 955 | |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 956 | for (int i = 0; i < match_count; i++) { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 957 | expandBufAdd1(pReq, match_list[i]->eventKind); |
| 958 | expandBufAdd4BE(pReq, match_list[i]->requestId); |
Elliott Hughes | 234ab15 | 2011-10-26 14:02:26 -0700 | [diff] [blame] | 959 | expandBufAdd8BE(pReq, basket.threadId); |
| 960 | } |
| 961 | } |
| 962 | |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 963 | CleanupMatchList(match_list, match_count); |
Elliott Hughes | 234ab15 | 2011-10-26 14:02:26 -0700 | [diff] [blame] | 964 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 965 | |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 966 | Dbg::ManageDeoptimization(); |
| 967 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 968 | SendRequestAndPossiblySuspend(pReq, suspend_policy, basket.threadId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 969 | |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 970 | return match_count != 0; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | /* |
| 974 | * Send a polite "VM is dying" message to the debugger. |
| 975 | * |
| 976 | * Skips the usual "event token" stuff. |
| 977 | */ |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 978 | bool JdwpState::PostVMDeath() { |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 979 | VLOG(jdwp) << "EVENT: " << EK_VM_DEATH; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 980 | |
| 981 | ExpandBuf* pReq = eventPrep(); |
| 982 | expandBufAdd1(pReq, SP_NONE); |
| 983 | expandBufAdd4BE(pReq, 1); |
| 984 | |
| 985 | expandBufAdd1(pReq, EK_VM_DEATH); |
| 986 | expandBufAdd4BE(pReq, 0); |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 987 | EventFinish(pReq); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 988 | return true; |
| 989 | } |
| 990 | |
| 991 | /* |
| 992 | * An exception has been thrown. It may or may not have been caught. |
| 993 | * |
| 994 | * Valid mods: |
| 995 | * Count, ThreadOnly, ClassOnly, ClassMatch, ClassExclude, LocationOnly, |
| 996 | * ExceptionOnly, InstanceOnly |
| 997 | * |
| 998 | * The "exceptionId" has not been added to the GC-visible object registry, |
| 999 | * because there's a pretty good chance that we're not going to send it |
| 1000 | * up the debugger. |
| 1001 | */ |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 1002 | bool JdwpState::PostException(const JdwpLocation* pThrowLoc, |
Elliott Hughes | 7484741 | 2012-06-20 18:10:21 -0700 | [diff] [blame] | 1003 | ObjectId exceptionId, RefTypeId exceptionClassId, |
| 1004 | const JdwpLocation* pCatchLoc, ObjectId thisPtr) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1005 | ModBasket basket; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1006 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1007 | basket.pLoc = pThrowLoc; |
Elliott Hughes | 7484741 | 2012-06-20 18:10:21 -0700 | [diff] [blame] | 1008 | basket.classId = pThrowLoc->class_id; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1009 | basket.threadId = Dbg::GetThreadSelfId(); |
Elliott Hughes | c308a5d | 2012-02-16 17:12:06 -0800 | [diff] [blame] | 1010 | basket.className = Dbg::GetClassName(basket.classId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1011 | basket.excepClassId = exceptionClassId; |
Elliott Hughes | 7484741 | 2012-06-20 18:10:21 -0700 | [diff] [blame] | 1012 | basket.caught = (pCatchLoc->class_id != 0); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1013 | basket.thisPtr = thisPtr; |
| 1014 | |
| 1015 | /* don't try to post an exception caused by the debugger */ |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 1016 | if (InvokeInProgress()) { |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1017 | VLOG(jdwp) << "Not posting exception hit during invoke (" << basket.className << ")"; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1018 | return false; |
| 1019 | } |
| 1020 | |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 1021 | int match_count = 0; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1022 | ExpandBuf* pReq = NULL; |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 1023 | JdwpSuspendPolicy suspend_policy = SP_NONE; |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 1024 | { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 1025 | MutexLock mu(Thread::Current(), event_list_lock_); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 1026 | JdwpEvent** match_list = AllocMatchList(event_list_size_); |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 1027 | FindMatchingEvents(EK_EXCEPTION, &basket, match_list, &match_count); |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 1028 | if (match_count != 0) { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 1029 | VLOG(jdwp) << "EVENT: " << match_list[0]->eventKind << "(" << match_count << " total)" |
Ian Rogers | d9e4e0c | 2014-01-23 20:11:40 -0800 | [diff] [blame] | 1030 | << StringPrintf(" thread=%#" PRIx64, basket.threadId) |
| 1031 | << StringPrintf(" exceptId=%#" PRIx64, exceptionId) |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame] | 1032 | << " caught=" << basket.caught << ")" |
| 1033 | << " throw: " << *pThrowLoc; |
Elliott Hughes | 7484741 | 2012-06-20 18:10:21 -0700 | [diff] [blame] | 1034 | if (pCatchLoc->class_id == 0) { |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1035 | VLOG(jdwp) << " catch: (not caught)"; |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 1036 | } else { |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1037 | VLOG(jdwp) << " catch: " << *pCatchLoc; |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 1038 | } |
| 1039 | |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 1040 | suspend_policy = scanSuspendPolicy(match_list, match_count); |
| 1041 | VLOG(jdwp) << " suspend_policy=" << suspend_policy; |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 1042 | |
| 1043 | pReq = eventPrep(); |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 1044 | expandBufAdd1(pReq, suspend_policy); |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 1045 | expandBufAdd4BE(pReq, match_count); |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 1046 | |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 1047 | for (int i = 0; i < match_count; i++) { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 1048 | expandBufAdd1(pReq, match_list[i]->eventKind); |
| 1049 | expandBufAdd4BE(pReq, match_list[i]->requestId); |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 1050 | expandBufAdd8BE(pReq, basket.threadId); |
| 1051 | |
Elliott Hughes | 6e9d22c | 2012-06-22 15:02:37 -0700 | [diff] [blame] | 1052 | expandBufAddLocation(pReq, *pThrowLoc); |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 1053 | expandBufAdd1(pReq, JT_OBJECT); |
| 1054 | expandBufAdd8BE(pReq, exceptionId); |
Elliott Hughes | 6e9d22c | 2012-06-22 15:02:37 -0700 | [diff] [blame] | 1055 | expandBufAddLocation(pReq, *pCatchLoc); |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 1056 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 1059 | CleanupMatchList(match_list, match_count); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1060 | } |
| 1061 | |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 1062 | Dbg::ManageDeoptimization(); |
| 1063 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1064 | SendRequestAndPossiblySuspend(pReq, suspend_policy, basket.threadId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1065 | |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 1066 | return match_count != 0; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | /* |
| 1070 | * Announce that a class has been loaded. |
| 1071 | * |
| 1072 | * Valid mods: |
| 1073 | * Count, ThreadOnly, ClassOnly, ClassMatch, ClassExclude |
| 1074 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1075 | bool JdwpState::PostClassPrepare(JdwpTypeTag tag, RefTypeId refTypeId, const std::string& signature, |
| 1076 | int status) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1077 | ModBasket basket; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1078 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1079 | basket.classId = refTypeId; |
| 1080 | basket.threadId = Dbg::GetThreadSelfId(); |
Elliott Hughes | c308a5d | 2012-02-16 17:12:06 -0800 | [diff] [blame] | 1081 | basket.className = Dbg::GetClassName(basket.classId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1082 | |
| 1083 | /* suppress class prep caused by debugger */ |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 1084 | if (InvokeInProgress()) { |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1085 | VLOG(jdwp) << "Not posting class prep caused by invoke (" << basket.className << ")"; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1086 | return false; |
| 1087 | } |
| 1088 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1089 | ExpandBuf* pReq = NULL; |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 1090 | JdwpSuspendPolicy suspend_policy = SP_NONE; |
| 1091 | int match_count = 0; |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 1092 | { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 1093 | MutexLock mu(Thread::Current(), event_list_lock_); |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 1094 | JdwpEvent** match_list = AllocMatchList(event_list_size_); |
| 1095 | FindMatchingEvents(EK_CLASS_PREPARE, &basket, match_list, &match_count); |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 1096 | if (match_count != 0) { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 1097 | VLOG(jdwp) << "EVENT: " << match_list[0]->eventKind << "(" << match_count << " total) " |
Ian Rogers | d9e4e0c | 2014-01-23 20:11:40 -0800 | [diff] [blame] | 1098 | << StringPrintf("thread=%#" PRIx64, basket.threadId) << ") " << signature; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1099 | |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 1100 | suspend_policy = scanSuspendPolicy(match_list, match_count); |
| 1101 | VLOG(jdwp) << " suspend_policy=" << suspend_policy; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1102 | |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 1103 | if (basket.threadId == debug_thread_id_) { |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 1104 | /* |
| 1105 | * JDWP says that, for a class prep in the debugger thread, we |
| 1106 | * should set threadId to null and if any threads were supposed |
| 1107 | * to be suspended then we suspend all other threads. |
| 1108 | */ |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1109 | VLOG(jdwp) << " NOTE: class prepare in debugger thread!"; |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 1110 | basket.threadId = 0; |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 1111 | if (suspend_policy == SP_EVENT_THREAD) { |
| 1112 | suspend_policy = SP_ALL; |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 1113 | } |
| 1114 | } |
| 1115 | |
| 1116 | pReq = eventPrep(); |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 1117 | expandBufAdd1(pReq, suspend_policy); |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 1118 | expandBufAdd4BE(pReq, match_count); |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 1119 | |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 1120 | for (int i = 0; i < match_count; i++) { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 1121 | expandBufAdd1(pReq, match_list[i]->eventKind); |
| 1122 | expandBufAdd4BE(pReq, match_list[i]->requestId); |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 1123 | expandBufAdd8BE(pReq, basket.threadId); |
| 1124 | |
| 1125 | expandBufAdd1(pReq, tag); |
| 1126 | expandBufAdd8BE(pReq, refTypeId); |
| 1127 | expandBufAddUtf8String(pReq, signature); |
| 1128 | expandBufAdd4BE(pReq, status); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1129 | } |
| 1130 | } |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 1131 | CleanupMatchList(match_list, match_count); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 1134 | Dbg::ManageDeoptimization(); |
| 1135 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1136 | SendRequestAndPossiblySuspend(pReq, suspend_policy, basket.threadId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1137 | |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 1138 | return match_count != 0; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1141 | /* |
| 1142 | * Send up a chunk of DDM data. |
| 1143 | * |
| 1144 | * While this takes the form of a JDWP "event", it doesn't interact with |
| 1145 | * other debugger traffic, and can't suspend the VM, so we skip all of |
| 1146 | * the fun event token gymnastics. |
| 1147 | */ |
Elliott Hughes | cccd84f | 2011-12-05 16:51:54 -0800 | [diff] [blame] | 1148 | void JdwpState::DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1149 | uint8_t header[kJDWPHeaderLen + 8]; |
| 1150 | size_t dataLen = 0; |
| 1151 | |
| 1152 | CHECK(iov != NULL); |
Elliott Hughes | cccd84f | 2011-12-05 16:51:54 -0800 | [diff] [blame] | 1153 | CHECK_GT(iov_count, 0); |
| 1154 | CHECK_LT(iov_count, 10); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1155 | |
| 1156 | /* |
| 1157 | * "Wrap" the contents of the iovec with a JDWP/DDMS header. We do |
| 1158 | * this by creating a new copy of the vector with space for the header. |
| 1159 | */ |
Brian Carlstrom | f529352 | 2013-07-19 00:24:00 -0700 | [diff] [blame] | 1160 | std::vector<iovec> wrapiov; |
| 1161 | wrapiov.push_back(iovec()); |
Elliott Hughes | cccd84f | 2011-12-05 16:51:54 -0800 | [diff] [blame] | 1162 | for (int i = 0; i < iov_count; i++) { |
Brian Carlstrom | f529352 | 2013-07-19 00:24:00 -0700 | [diff] [blame] | 1163 | wrapiov.push_back(iov[i]); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1164 | dataLen += iov[i].iov_len; |
| 1165 | } |
| 1166 | |
| 1167 | /* form the header (JDWP plus DDMS) */ |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 1168 | Set4BE(header, sizeof(header) + dataLen); |
| 1169 | Set4BE(header+4, NextRequestSerial()); |
| 1170 | Set1(header+8, 0); /* flags */ |
| 1171 | Set1(header+9, kJDWPDdmCmdSet); |
| 1172 | Set1(header+10, kJDWPDdmCmd); |
| 1173 | Set4BE(header+11, type); |
| 1174 | Set4BE(header+15, dataLen); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1175 | |
| 1176 | wrapiov[0].iov_base = header; |
| 1177 | wrapiov[0].iov_len = sizeof(header); |
| 1178 | |
Ian Rogers | 15bf2d3 | 2012-08-28 17:33:04 -0700 | [diff] [blame] | 1179 | // Try to avoid blocking GC during a send, but only safe when not using mutexes at a lower-level |
| 1180 | // than mutator for lock ordering reasons. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1181 | Thread* self = Thread::Current(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1182 | bool safe_to_release_mutator_lock_over_send = !Locks::mutator_lock_->IsExclusiveHeld(self); |
| 1183 | if (safe_to_release_mutator_lock_over_send) { |
Brian Carlstrom | 38f85e4 | 2013-07-18 14:45:22 -0700 | [diff] [blame] | 1184 | for (size_t i = 0; i < kMutatorLock; ++i) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1185 | if (self->GetHeldMutex(static_cast<LockLevel>(i)) != NULL) { |
| 1186 | safe_to_release_mutator_lock_over_send = false; |
| 1187 | break; |
| 1188 | } |
Ian Rogers | 15bf2d3 | 2012-08-28 17:33:04 -0700 | [diff] [blame] | 1189 | } |
| 1190 | } |
| 1191 | if (safe_to_release_mutator_lock_over_send) { |
| 1192 | // Change state to waiting to allow GC, ... while we're sending. |
| 1193 | self->TransitionFromRunnableToSuspended(kWaitingForDebuggerSend); |
Brian Carlstrom | f529352 | 2013-07-19 00:24:00 -0700 | [diff] [blame] | 1194 | SendBufferedRequest(type, wrapiov); |
Ian Rogers | 15bf2d3 | 2012-08-28 17:33:04 -0700 | [diff] [blame] | 1195 | self->TransitionFromSuspendedToRunnable(); |
| 1196 | } else { |
| 1197 | // Send and possibly block GC... |
Brian Carlstrom | f529352 | 2013-07-19 00:24:00 -0700 | [diff] [blame] | 1198 | SendBufferedRequest(type, wrapiov); |
Ian Rogers | 15bf2d3 | 2012-08-28 17:33:04 -0700 | [diff] [blame] | 1199 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | } // namespace JDWP |
| 1203 | |
| 1204 | } // namespace art |