blob: 0ac83f687c4975aa30f4d0dc0e9060935373b34d [file] [log] [blame]
Elliott Hughes872d4ec2011-10-21 17:07:15 -07001/*
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 */
16
17/*
18 * Dalvik-specific side of debugger support. (The JDWP code is intended to
19 * be relatively generic.)
20 */
Brian Carlstromfc0e3212013-07-17 14:40:12 -070021#ifndef ART_RUNTIME_DEBUGGER_H_
22#define ART_RUNTIME_DEBUGGER_H_
Elliott Hughes872d4ec2011-10-21 17:07:15 -070023
24#include <pthread.h>
25
Mathieu Chartier4345c462014-06-27 10:20:14 -070026#include <map>
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010027#include <set>
Elliott Hughes3bb81562011-10-21 18:52:59 -070028#include <string>
Sebastien Hertz4d25df32014-03-21 17:44:46 +010029#include <vector>
Elliott Hughes3bb81562011-10-21 18:52:59 -070030
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -080031#include "gc_root.h"
Elliott Hughes872d4ec2011-10-21 17:07:15 -070032#include "jdwp/jdwp.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080033#include "jni.h"
34#include "jvalue.h"
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080035#include "object_callbacks.h"
Jeff Hao920af3e2013-08-28 15:46:38 -070036#include "thread_state.h"
Elliott Hughes872d4ec2011-10-21 17:07:15 -070037
38namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080039namespace mirror {
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +020040class ArtField;
Brian Carlstromea46f952013-07-30 01:26:50 -070041class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080042class Class;
43class Object;
44class Throwable;
45} // namespace mirror
Hiroshi Yamauchib5a9e3d2014-06-09 12:11:20 -070046class AllocRecord;
Sebastien Hertz6995c602014-09-09 12:10:13 +020047class ObjectRegistry;
48class ScopedObjectAccessUnchecked;
Sebastien Hertz8009f392014-09-01 17:07:11 +020049class StackVisitor;
Ian Rogers1b09b092012-08-20 15:35:52 -070050class Thread;
Ian Rogers62d6c772013-02-27 08:32:07 -080051class ThrowLocation;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070052
53/*
54 * Invoke-during-breakpoint support.
55 */
56struct DebugInvokeReq {
Sebastien Hertz1558b572015-02-25 15:05:59 +010057 DebugInvokeReq(mirror::Object* invoke_receiver, mirror::Class* invoke_class,
58 mirror::ArtMethod* invoke_method, uint32_t invoke_options,
59 uint64_t* args, uint32_t args_count)
60 : receiver(invoke_receiver), klass(invoke_class), method(invoke_method),
61 arg_count(args_count), arg_values(args), options(invoke_options),
62 error(JDWP::ERR_NONE), result_tag(JDWP::JT_VOID), result_value(0), exception(0),
Sebastien Hertzd38667a2013-11-25 15:43:54 +010063 lock("a DebugInvokeReq lock", kBreakpointInvokeLock),
64 cond("a DebugInvokeReq condition variable", lock) {
Elliott Hughes475fc232011-10-25 15:00:35 -070065 }
66
Elliott Hughes872d4ec2011-10-21 17:07:15 -070067 /* request */
Sebastien Hertz1558b572015-02-25 15:05:59 +010068 GcRoot<mirror::Object> receiver; // not used for ClassType.InvokeMethod
69 GcRoot<mirror::Class> klass;
70 GcRoot<mirror::ArtMethod> method;
71 const uint32_t arg_count;
72 uint64_t* const arg_values; // will be NULL if arg_count_ == 0
73 const uint32_t options;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070074
75 /* result */
Elliott Hughes475fc232011-10-25 15:00:35 -070076 JDWP::JdwpError error;
Elliott Hughesd07986f2011-12-06 18:27:45 -080077 JDWP::JdwpTag result_tag;
Sebastien Hertz1558b572015-02-25 15:05:59 +010078 uint64_t result_value; // either a primitive value or an ObjectId
Elliott Hughes475fc232011-10-25 15:00:35 -070079 JDWP::ObjectId exception;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070080
81 /* condition variable to wait on while the method executes */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010082 Mutex lock DEFAULT_MUTEX_ACQUIRED_AFTER;
83 ConditionVariable cond GUARDED_BY(lock);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010084
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -080085 void VisitRoots(RootCallback* callback, void* arg, const RootInfo& root_info)
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -070086 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
87
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010088 private:
89 DISALLOW_COPY_AND_ASSIGN(DebugInvokeReq);
90};
91
92// Thread local data-structure that holds fields for controlling single-stepping.
Sebastien Hertz597c4f02015-01-26 17:37:14 +010093class SingleStepControl {
94 public:
95 SingleStepControl(JDWP::JdwpStepSize step_size, JDWP::JdwpStepDepth step_depth,
96 int stack_depth, mirror::ArtMethod* method)
97 : step_size_(step_size), step_depth_(step_depth),
98 stack_depth_(stack_depth), method_(method) {
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010099 }
100
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100101 JDWP::JdwpStepSize GetStepSize() const {
102 return step_size_;
103 }
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100104
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100105 JDWP::JdwpStepDepth GetStepDepth() const {
106 return step_depth_;
107 }
108
109 int GetStackDepth() const {
110 return stack_depth_;
111 }
112
113 mirror::ArtMethod* GetMethod() const {
114 return method_;
115 }
116
117 const std::set<uint32_t>& GetDexPcs() const {
118 return dex_pcs_;
119 }
120
121 void VisitRoots(RootCallback* callback, void* arg, const RootInfo& root_info)
122 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
123
124 void AddDexPc(uint32_t dex_pc);
125
126 bool ContainsDexPc(uint32_t dex_pc) const;
127
128 private:
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100129 // See JdwpStepSize and JdwpStepDepth for details.
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100130 const JDWP::JdwpStepSize step_size_;
131 const JDWP::JdwpStepDepth step_depth_;
132
133 // The stack depth when this single-step was initiated. This is used to support SD_OVER and SD_OUT
134 // single-step depth.
135 const int stack_depth_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100136
137 // The location this single-step was initiated from.
138 // A single-step is initiated in a suspended thread. We save here the current method and the
139 // set of DEX pcs associated to the source line number where the suspension occurred.
140 // This is used to support SD_INTO and SD_OVER single-step depths so we detect when a single-step
141 // causes the execution of an instruction in a different method or at a different line number.
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100142 mirror::ArtMethod* method_;
143 std::set<uint32_t> dex_pcs_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100144
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100145 DISALLOW_COPY_AND_ASSIGN(SingleStepControl);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700146};
147
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200148// TODO rename to InstrumentationRequest.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700149class DeoptimizationRequest {
150 public:
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100151 enum Kind {
152 kNothing, // no action.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200153 kRegisterForEvent, // start listening for instrumentation event.
154 kUnregisterForEvent, // stop listening for instrumentation event.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100155 kFullDeoptimization, // deoptimize everything.
156 kFullUndeoptimization, // undeoptimize everything.
157 kSelectiveDeoptimization, // deoptimize one method.
158 kSelectiveUndeoptimization // undeoptimize one method.
159 };
160
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700161 DeoptimizationRequest() : kind_(kNothing), instrumentation_event_(0), method_(nullptr) {}
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100162
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700163 DeoptimizationRequest(const DeoptimizationRequest& other)
164 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
165 : kind_(other.kind_), instrumentation_event_(other.instrumentation_event_) {
166 // Create a new JNI global reference for the method.
167 SetMethod(other.Method());
168 }
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100169
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700170 mirror::ArtMethod* Method() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
171
172 void SetMethod(mirror::ArtMethod* m) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
173
174 // Name 'Kind()' would collide with the above enum name.
175 Kind GetKind() const {
176 return kind_;
177 }
178
179 void SetKind(Kind kind) {
180 kind_ = kind;
181 }
182
183 uint32_t InstrumentationEvent() const {
184 return instrumentation_event_;
185 }
186
187 void SetInstrumentationEvent(uint32_t instrumentation_event) {
188 instrumentation_event_ = instrumentation_event;
189 }
190
191 private:
192 Kind kind_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100193
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200194 // TODO we could use a union to hold the instrumentation_event and the method since they
195 // respectively have sense only for kRegisterForEvent/kUnregisterForEvent and
196 // kSelectiveDeoptimization/kSelectiveUndeoptimization.
197
198 // Event to start or stop listening to. Only for kRegisterForEvent and kUnregisterForEvent.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700199 uint32_t instrumentation_event_;
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200200
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100201 // Method for selective deoptimization.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700202 jmethodID method_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100203};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700204std::ostream& operator<<(std::ostream& os, const DeoptimizationRequest::Kind& rhs);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100205
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700206class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800207 public:
Mathieu Chartier4345c462014-06-27 10:20:14 -0700208 class TypeCache {
209 public:
210 // Returns a weak global for the input type. Deduplicates.
Brian Carlstrom306db812014-09-05 13:01:41 -0700211 jobject Add(mirror::Class* t) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_,
212 Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700213 // Clears the type cache and deletes all the weak global refs.
Brian Carlstrom306db812014-09-05 13:01:41 -0700214 void Clear() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_,
215 Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700216
217 private:
218 std::multimap<int32_t, jobject> objects_;
219 };
220
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700221 static void SetJdwpAllowed(bool allowed);
222
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100223 static void StartJdwp();
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700224 static void StopJdwp();
225
Elliott Hughes767a1472011-10-26 18:49:02 -0700226 // Invoked by the GC in case we need to keep DDMS informed.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700227 static void GcDidFinish() LOCKS_EXCLUDED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700228
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700229 // Return the DebugInvokeReq for the current thread.
230 static DebugInvokeReq* GetInvokeReq();
231
Elliott Hughes475fc232011-10-25 15:00:35 -0700232 static Thread* GetDebugThread();
233 static void ClearWaitForEventThread();
234
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700235 /*
236 * Enable/disable breakpoints and step modes. Used to provide a heads-up
237 * when the debugger attaches.
238 */
239 static void Connected();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100240 static void GoActive()
Brian Carlstrom306db812014-09-05 13:01:41 -0700241 LOCKS_EXCLUDED(Locks::breakpoint_lock_, Locks::deoptimization_lock_, Locks::mutator_lock_);
242 static void Disconnected() LOCKS_EXCLUDED(Locks::deoptimization_lock_, Locks::mutator_lock_);
Elliott Hughes86964332012-02-15 19:37:42 -0800243 static void Disposed();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700244
Elliott Hughesc0f09332012-03-26 13:27:06 -0700245 // Returns true if we're actually debugging with a real debugger, false if it's
246 // just DDMS (or nothing at all).
247 static bool IsDebuggerActive();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700248
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100249 // Configures JDWP with parsed command-line options.
250 static void ConfigureJdwp(const JDWP::JdwpOptions& jdwp_options);
251
Elliott Hughesc0f09332012-03-26 13:27:06 -0700252 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
253 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700254
Elliott Hughes86964332012-02-15 19:37:42 -0800255 static bool IsDisposed();
256
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700257 /*
258 * Time, in milliseconds, since the last debugger activity. Does not
259 * include DDMS activity. Returns -1 if there has been no activity.
260 * Returns 0 if we're in the middle of handling a debugger request.
261 */
262 static int64_t LastDebuggerActivity();
263
Sebastien Hertz253fa552014-10-14 17:27:15 +0200264 static void UndoDebuggerSuspensions()
265 LOCKS_EXCLUDED(Locks::thread_list_lock_,
266 Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700267
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700268 /*
269 * Class, Object, Array
270 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700271 static std::string GetClassName(JDWP::RefTypeId id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700272 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200273 static std::string GetClassName(mirror::Class* klass)
274 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700275 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId* class_object_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700276 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700277 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId* superclass_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700278 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700279 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700280 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700281 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700282 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800283 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700284 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700285 static void GetClassList(std::vector<JDWP::RefTypeId>* classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700286 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800287 static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700288 uint32_t* pStatus, std::string* pDescriptor)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700289 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700290 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>* ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700291 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800292 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
293 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersfc0e94b2013-09-23 23:51:32 -0700294 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700295 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700296 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string* source_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700297 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700298 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t* tag)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700299 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800300 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700301
Ian Rogersc0542af2014-09-03 16:16:56 -0700302 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int32_t* length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700303 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800304 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700305 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700306 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800307 static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700308 JDWP::Request* request)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700309 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700310
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700311 static JDWP::ObjectId CreateString(const std::string& str)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700312 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700313 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId* new_object)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700314 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800315 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Ian Rogersc0542af2014-09-03 16:16:56 -0700316 JDWP::ObjectId* new_array)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700317 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700318
Sebastien Hertz6995c602014-09-09 12:10:13 +0200319 //
320 // Event filtering.
321 //
322 static bool MatchThread(JDWP::ObjectId expected_thread_id, Thread* event_thread)
323 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
324
325 static bool MatchLocation(const JDWP::JdwpLocation& expected_location,
326 const JDWP::EventLocation& event_location)
327 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
328
329 static bool MatchType(mirror::Class* event_class, JDWP::RefTypeId class_id)
330 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
331
332 static bool MatchField(JDWP::RefTypeId expected_type_id, JDWP::FieldId expected_field_id,
333 mirror::ArtField* event_field)
334 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
335
336 static bool MatchInstance(JDWP::ObjectId expected_instance_id, mirror::Object* event_instance)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700337 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700338
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800339 //
340 // Monitors.
341 //
342 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
343 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
344 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700345 std::vector<JDWP::ObjectId>* monitors,
346 std::vector<uint32_t>* stack_depths)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100347 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800348 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100349 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700350 JDWP::ObjectId* contended_monitor)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100351 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800352 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
353
354 //
355 // Heap.
356 //
357 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
Ian Rogersc0542af2014-09-03 16:16:56 -0700358 std::vector<uint64_t>* counts)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800359 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800360 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700361 std::vector<JDWP::ObjectId>* instances)
Elliott Hughes3b78c942013-01-15 17:35:41 -0800362 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800363 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700364 std::vector<JDWP::ObjectId>* referring_objects)
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800365 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800366 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
367 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
368 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
369 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700370 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool* is_collected)
Elliott Hughes64f574f2013-02-20 14:57:12 -0800371 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
372 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
373 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800374
Elliott Hughes9777ba22013-01-17 09:04:19 -0800375 //
376 // Methods and fields.
377 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800378 static std::string GetMethodName(JDWP::MethodId method_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700379 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800380 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700381 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700382 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800383 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700384 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700385 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800386 static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700387 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700388 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800389 static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700390 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700391 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800392 static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700393 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700394 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800395 static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value,
396 JDWP::ExpandBuf* pReply)
397 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200398 static void OutputFieldValue(JDWP::FieldId field_id, const JValue* field_value,
399 JDWP::ExpandBuf* pReply)
400 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800401 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700402 std::vector<uint8_t>* bytecodes)
Elliott Hughes9777ba22013-01-17 09:04:19 -0800403 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700404
Elliott Hughesa96836a2013-01-17 12:27:49 -0800405 static std::string GetFieldName(JDWP::FieldId field_id)
406 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800407 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700408 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800409 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Brian Carlstromf69863b2013-07-17 21:53:13 -0700410 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800411 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700412 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700413 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800414 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700415 uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700416 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800417 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700418 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700419 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800420 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700421 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700422
Sebastien Hertzb0b0b492014-09-15 11:27:27 +0200423 static JDWP::JdwpError StringToUtf8(JDWP::ObjectId string_id, std::string* str)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700424 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800425 static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply)
426 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700427
428 /*
429 * Thread, ThreadGroup, Frame
430 */
Ian Rogersc0542af2014-09-03 16:16:56 -0700431 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string* name)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700432 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
433 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100434 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply)
Sebastien Hertza06430c2014-09-15 19:21:30 +0200435 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100436 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200437 static JDWP::JdwpError GetThreadGroupName(JDWP::ObjectId thread_group_id,
438 JDWP::ExpandBuf* pReply)
439 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
440 static JDWP::JdwpError GetThreadGroupParent(JDWP::ObjectId thread_group_id,
441 JDWP::ExpandBuf* pReply)
442 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
443 static JDWP::JdwpError GetThreadGroupChildren(JDWP::ObjectId thread_group_id,
444 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700445 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700446 static JDWP::ObjectId GetSystemThreadGroupId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700447 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700448
Jeff Hao920af3e2013-08-28 15:46:38 -0700449 static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100450 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id,
451 JDWP::JdwpThreadStatus* pThreadStatus,
452 JDWP::JdwpSuspendStatus* pSuspendStatus)
453 LOCKS_EXCLUDED(Locks::thread_list_lock_);
454 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id,
455 JDWP::ExpandBuf* pReply)
456 LOCKS_EXCLUDED(Locks::thread_list_lock_,
457 Locks::thread_suspend_count_lock_);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700458 // static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700459
Elliott Hughes026b1462012-06-28 20:43:49 -0700460 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700461 // returns all threads.
Sebastien Hertza06430c2014-09-15 19:21:30 +0200462 static void GetThreads(mirror::Object* thread_group, std::vector<JDWP::ObjectId>* thread_ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700463 LOCKS_EXCLUDED(Locks::thread_list_lock_)
464 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700465
Ian Rogersc0542af2014-09-03 16:16:56 -0700466 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t* result)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100467 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700468 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
469 size_t frame_count, JDWP::ExpandBuf* buf)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100470 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700471 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700472
Sebastien Hertz6995c602014-09-09 12:10:13 +0200473 static JDWP::ObjectId GetThreadSelfId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
474 static JDWP::ObjectId GetThreadId(Thread* thread) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
475
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700476 static void SuspendVM()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700477 LOCKS_EXCLUDED(Locks::thread_list_lock_,
478 Locks::thread_suspend_count_lock_);
Sebastien Hertz253fa552014-10-14 17:27:15 +0200479 static void ResumeVM()
480 LOCKS_EXCLUDED(Locks::thread_list_lock_,
481 Locks::thread_suspend_count_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800482 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700483 LOCKS_EXCLUDED(Locks::mutator_lock_,
484 Locks::thread_list_lock_,
485 Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700486
Elliott Hughes88d63092013-01-09 09:55:54 -0800487 static void ResumeThread(JDWP::ObjectId thread_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700488 LOCKS_EXCLUDED(Locks::thread_list_lock_,
489 Locks::thread_suspend_count_lock_)
490 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700491 static void SuspendSelf();
492
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700493 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
494 JDWP::ObjectId* result)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700495 LOCKS_EXCLUDED(Locks::thread_list_lock_,
496 Locks::thread_suspend_count_lock_)
497 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200498 static JDWP::JdwpError GetLocalValues(JDWP::Request* request, JDWP::ExpandBuf* pReply)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100499 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700500 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200501 static JDWP::JdwpError SetLocalValues(JDWP::Request* request)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100502 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700503 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700504
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100505 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id)
506 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughesf9501702013-01-11 11:22:27 -0800507
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700508 /*
509 * Debugger notification
510 */
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700511 enum EventFlag {
Elliott Hughes86964332012-02-15 19:37:42 -0800512 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700513 kSingleStep = 0x02,
514 kMethodEntry = 0x04,
515 kMethodExit = 0x08,
516 };
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200517 static void PostFieldAccessEvent(mirror::ArtMethod* m, int dex_pc, mirror::Object* this_object,
518 mirror::ArtField* f)
519 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
520 static void PostFieldModificationEvent(mirror::ArtMethod* m, int dex_pc,
521 mirror::Object* this_object, mirror::ArtField* f,
522 const JValue* field_value)
523 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000524 static void PostException(mirror::Throwable* exception)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700525 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700526 static void PostThreadStart(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700527 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700528 static void PostThreadDeath(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700529 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800530 static void PostClassPrepare(mirror::Class* c)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700531 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700532
Ian Rogers62d6c772013-02-27 08:32:07 -0800533 static void UpdateDebugger(Thread* thread, mirror::Object* this_object,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100534 mirror::ArtMethod* method, uint32_t new_dex_pc,
535 int event_flags, const JValue* return_value)
jeffhao09bfc6a2012-12-11 18:11:43 -0800536 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700537 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800538
Sebastien Hertzf3928792014-11-17 19:00:37 +0100539 // Indicates whether we need deoptimization for debugging.
540 static bool RequiresDeoptimization();
541
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100542 // Records deoptimization request in the queue.
543 static void RequestDeoptimization(const DeoptimizationRequest& req)
Brian Carlstrom306db812014-09-05 13:01:41 -0700544 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100545 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
546
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100547 // Support delayed full undeoptimization requests. This is currently only used for single-step
548 // events.
Brian Carlstrom306db812014-09-05 13:01:41 -0700549 static void DelayFullUndeoptimization() LOCKS_EXCLUDED(Locks::deoptimization_lock_);
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100550 static void ProcessDelayedFullUndeoptimizations()
Brian Carlstrom306db812014-09-05 13:01:41 -0700551 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100552 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
553
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100554 // Manage deoptimization after updating JDWP events list. Suspends all threads, processes each
555 // request and finally resumes all threads.
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100556 static void ManageDeoptimization()
Brian Carlstrom306db812014-09-05 13:01:41 -0700557 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100558 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
559
560 // Breakpoints.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100561 static void WatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
562 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700563 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100564 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
565 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700566 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100567
568 // Single-stepping.
Elliott Hughes88d63092013-01-09 09:55:54 -0800569 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700570 JDWP::JdwpStepDepth depth)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700571 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100572 static void UnconfigureStep(JDWP::ObjectId thread_id)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100573 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100574 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700575
Sebastien Hertz1558b572015-02-25 15:05:59 +0100576 // Invoke support for commands ClassType.InvokeMethod, ClassType.NewInstance and
577 // ObjectReference.InvokeMethod.
Elliott Hughes88d63092013-01-09 09:55:54 -0800578 static JDWP::JdwpError InvokeMethod(JDWP::ObjectId thread_id, JDWP::ObjectId object_id,
579 JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700580 uint32_t arg_count, uint64_t* arg_values,
581 JDWP::JdwpTag* arg_types, uint32_t options,
582 JDWP::JdwpTag* pResultTag, uint64_t* pResultValue,
583 JDWP::ObjectId* pExceptObj)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700584 LOCKS_EXCLUDED(Locks::thread_list_lock_,
585 Locks::thread_suspend_count_lock_)
586 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700587 static void ExecuteMethod(DebugInvokeReq* pReq);
588
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700589 /*
590 * DDM support.
591 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700592 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700593 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100594 static void DdmSetThreadNotification(bool enable)
595 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700596 static bool DdmHandlePacket(JDWP::Request* request, uint8_t** pReplyBuf, int* pReplyLen);
Ian Rogersb726dcb2012-09-05 08:57:23 -0700597 static void DdmConnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
598 static void DdmDisconnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700599 static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700600 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700601 static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700602 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700603 static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700604 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700605
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700606 static void VisitRoots(RootCallback* callback, void* arg)
607 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
608
Elliott Hughes545a0642011-11-08 19:10:03 -0800609 /*
610 * Recent allocation tracking support.
611 */
Ian Rogers844506b2014-09-12 19:59:33 -0700612 static void RecordAllocation(Thread* self, mirror::Class* type, size_t byte_count)
Brian Carlstrom306db812014-09-05 13:01:41 -0700613 LOCKS_EXCLUDED(Locks::alloc_tracker_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700614 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom306db812014-09-05 13:01:41 -0700615 static void SetAllocTrackingEnabled(bool enabled) LOCKS_EXCLUDED(Locks::alloc_tracker_lock_);
Ian Rogers719d1a32014-03-06 12:13:39 -0800616 static bool IsAllocTrackingEnabled() {
617 return recent_allocation_records_ != nullptr;
618 }
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100619 static jbyteArray GetRecentAllocations()
Brian Carlstrom306db812014-09-05 13:01:41 -0700620 LOCKS_EXCLUDED(Locks::alloc_tracker_lock_)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100621 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom306db812014-09-05 13:01:41 -0700622 static size_t HeadIndex() EXCLUSIVE_LOCKS_REQUIRED(Locks::alloc_tracker_lock_);
623 static void DumpRecentAllocations() LOCKS_EXCLUDED(Locks::alloc_tracker_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800624
Elliott Hughes767a1472011-10-26 18:49:02 -0700625 enum HpifWhen {
626 HPIF_WHEN_NEVER = 0,
627 HPIF_WHEN_NOW = 1,
628 HPIF_WHEN_NEXT_GC = 2,
629 HPIF_WHEN_EVERY_GC = 3
630 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700631 static int DdmHandleHpifChunk(HpifWhen when)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700632 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700633
634 enum HpsgWhen {
635 HPSG_WHEN_NEVER = 0,
636 HPSG_WHEN_EVERY_GC = 1,
637 };
638 enum HpsgWhat {
639 HPSG_WHAT_MERGED_OBJECTS = 0,
640 HPSG_WHAT_DISTINCT_OBJECTS = 1,
641 };
642 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
643
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700644 static void DdmSendHeapInfo(HpifWhen reason)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700645 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700646 static void DdmSendHeapSegments(bool native)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700647 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800648
Sebastien Hertz6995c602014-09-09 12:10:13 +0200649 static ObjectRegistry* GetObjectRegistry() {
650 return gRegistry;
651 }
652
653 static JDWP::JdwpTag TagFromObject(const ScopedObjectAccessUnchecked& soa, mirror::Object* o)
654 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
655
656 static JDWP::JdwpTypeTag GetTypeTag(mirror::Class* klass)
657 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
658
659 static JDWP::FieldId ToFieldId(const mirror::ArtField* f)
660 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
661
662 static void SetJdwpLocation(JDWP::JdwpLocation* location, mirror::ArtMethod* m, uint32_t dex_pc)
663 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
664
Mathieu Chartierad466ad2015-01-08 16:28:08 -0800665 static JDWP::JdwpState* GetJdwpState();
666
Elliott Hughes545a0642011-11-08 19:10:03 -0800667 private:
Sebastien Hertz8009f392014-09-01 17:07:11 +0200668 static JDWP::JdwpError GetLocalValue(const StackVisitor& visitor,
669 ScopedObjectAccessUnchecked& soa, int slot,
670 JDWP::JdwpTag tag, uint8_t* buf, size_t width)
671 LOCKS_EXCLUDED(Locks::thread_list_lock_)
672 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
673 static JDWP::JdwpError SetLocalValue(StackVisitor& visitor, int slot, JDWP::JdwpTag tag,
674 uint64_t value, size_t width)
675 LOCKS_EXCLUDED(Locks::thread_list_lock_)
676 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
677
Brian Carlstrom2d888622013-07-18 17:02:00 -0700678 static void DdmBroadcast(bool connect) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700679 static void PostThreadStartOrStop(Thread*, uint32_t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700680 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800681
Sebastien Hertz8379b222014-02-24 17:38:15 +0100682 static void PostLocationEvent(mirror::ArtMethod* method, int pcOffset,
683 mirror::Object* thisPtr, int eventFlags,
684 const JValue* return_value)
685 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
686
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100687 static void ProcessDeoptimizationRequest(const DeoptimizationRequest& request)
688 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_);
689
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100690 static void RequestDeoptimizationLocked(const DeoptimizationRequest& req)
Brian Carlstrom306db812014-09-05 13:01:41 -0700691 EXCLUSIVE_LOCKS_REQUIRED(Locks::deoptimization_lock_)
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100692 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
693
Brian Carlstrom306db812014-09-05 13:01:41 -0700694 static AllocRecord* recent_allocation_records_ PT_GUARDED_BY(Locks::alloc_tracker_lock_);
695 static size_t alloc_record_max_ GUARDED_BY(Locks::alloc_tracker_lock_);
696 static size_t alloc_record_head_ GUARDED_BY(Locks::alloc_tracker_lock_);
697 static size_t alloc_record_count_ GUARDED_BY(Locks::alloc_tracker_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100698
Sebastien Hertz6995c602014-09-09 12:10:13 +0200699 static ObjectRegistry* gRegistry;
700
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100701 // Deoptimization requests to be processed each time the event list is updated. This is used when
702 // registering and unregistering events so we do not deoptimize while holding the event list
703 // lock.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200704 // TODO rename to instrumentation_requests.
Brian Carlstrom306db812014-09-05 13:01:41 -0700705 static std::vector<DeoptimizationRequest> deoptimization_requests_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100706
707 // Count the number of events requiring full deoptimization. When the counter is > 0, everything
708 // is deoptimized, otherwise everything is undeoptimized.
709 // Note: we fully deoptimize on the first event only (when the counter is set to 1). We fully
710 // undeoptimize when the last event is unregistered (when the counter is set to 0).
Brian Carlstrom306db812014-09-05 13:01:41 -0700711 static size_t full_deoptimization_event_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100712
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100713 // Count the number of full undeoptimization requests delayed to next resume or end of debug
714 // session.
Brian Carlstrom306db812014-09-05 13:01:41 -0700715 static size_t delayed_full_undeoptimization_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100716
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200717 static size_t* GetReferenceCounterForEvent(uint32_t instrumentation_event);
718
Mathieu Chartier4345c462014-06-27 10:20:14 -0700719 // Weak global type cache, TODO improve this.
Brian Carlstrom306db812014-09-05 13:01:41 -0700720 static TypeCache type_cache_ GUARDED_BY(Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700721
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200722 // Instrumentation event reference counters.
723 // TODO we could use an array instead of having all these dedicated counters. Instrumentation
724 // events are bits of a mask so we could convert them to array index.
Brian Carlstrom306db812014-09-05 13:01:41 -0700725 static size_t dex_pc_change_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
726 static size_t method_enter_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
727 static size_t method_exit_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
728 static size_t field_read_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
729 static size_t field_write_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
730 static size_t exception_catch_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200731 static uint32_t instrumentation_events_ GUARDED_BY(Locks::mutator_lock_);
732
Brian Carlstrom306db812014-09-05 13:01:41 -0700733 friend class AllocRecord; // For type_cache_ with proper annotalysis.
Ian Rogers719d1a32014-03-06 12:13:39 -0800734 DISALLOW_COPY_AND_ASSIGN(Dbg);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700735};
736
737#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800738 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700739
740} // namespace art
741
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700742#endif // ART_RUNTIME_DEBUGGER_H_