blob: ab758caf69e17612cb3f506817ebad83ec4092dd [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
Elliott Hughes872d4ec2011-10-21 17:07:15 -070031#include "jdwp/jdwp.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032#include "jni.h"
33#include "jvalue.h"
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080034#include "object_callbacks.h"
Jeff Hao920af3e2013-08-28 15:46:38 -070035#include "thread_state.h"
Elliott Hughes872d4ec2011-10-21 17:07:15 -070036
37namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038namespace mirror {
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +020039class ArtField;
Brian Carlstromea46f952013-07-30 01:26:50 -070040class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080041class Class;
42class Object;
43class Throwable;
44} // namespace mirror
Hiroshi Yamauchib5a9e3d2014-06-09 12:11:20 -070045class AllocRecord;
Ian Rogers1b09b092012-08-20 15:35:52 -070046class Thread;
Ian Rogers62d6c772013-02-27 08:32:07 -080047class ThrowLocation;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070048
49/*
50 * Invoke-during-breakpoint support.
51 */
52struct DebugInvokeReq {
Elliott Hughes7b3cdfc2011-12-08 21:28:17 -080053 DebugInvokeReq()
Sebastien Hertzd38667a2013-11-25 15:43:54 +010054 : ready(false), invoke_needed(false),
55 receiver(NULL), thread(NULL), klass(NULL), method(NULL),
56 arg_count(0), arg_values(NULL), options(0), error(JDWP::ERR_NONE),
Ian Rogers00f7d0e2012-07-19 15:28:27 -070057 result_tag(JDWP::JT_VOID), exception(0),
Sebastien Hertzd38667a2013-11-25 15:43:54 +010058 lock("a DebugInvokeReq lock", kBreakpointInvokeLock),
59 cond("a DebugInvokeReq condition variable", lock) {
Elliott Hughes475fc232011-10-25 15:00:35 -070060 }
61
Elliott Hughes872d4ec2011-10-21 17:07:15 -070062 /* boolean; only set when we're in the tail end of an event handler */
63 bool ready;
64
65 /* boolean; set if the JDWP thread wants this thread to do work */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010066 bool invoke_needed;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070067
68 /* request */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010069 mirror::Object* receiver; /* not used for ClassType.InvokeMethod */
70 mirror::Object* thread;
71 mirror::Class* klass;
72 mirror::ArtMethod* method;
73 uint32_t arg_count;
74 uint64_t* arg_values; /* will be NULL if arg_count_ == 0 */
75 uint32_t options;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070076
77 /* result */
Elliott Hughes475fc232011-10-25 15:00:35 -070078 JDWP::JdwpError error;
Elliott Hughesd07986f2011-12-06 18:27:45 -080079 JDWP::JdwpTag result_tag;
Elliott Hughes475fc232011-10-25 15:00:35 -070080 JValue result_value;
81 JDWP::ObjectId exception;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070082
83 /* condition variable to wait on while the method executes */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010084 Mutex lock DEFAULT_MUTEX_ACQUIRED_AFTER;
85 ConditionVariable cond GUARDED_BY(lock);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010086
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -070087 void VisitRoots(RootCallback* callback, void* arg, uint32_t tid, RootType root_type)
88 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
89
Sebastien Hertzbb43b432014-04-14 11:59:08 +020090 void Clear();
91
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010092 private:
93 DISALLOW_COPY_AND_ASSIGN(DebugInvokeReq);
94};
95
96// Thread local data-structure that holds fields for controlling single-stepping.
97struct SingleStepControl {
98 SingleStepControl()
99 : is_active(false), step_size(JDWP::SS_MIN), step_depth(JDWP::SD_INTO),
100 method(nullptr), stack_depth(0) {
101 }
102
103 // Are we single-stepping right now?
104 bool is_active;
105
106 // See JdwpStepSize and JdwpStepDepth for details.
107 JDWP::JdwpStepSize step_size;
108 JDWP::JdwpStepDepth step_depth;
109
110 // The location this single-step was initiated from.
111 // A single-step is initiated in a suspended thread. We save here the current method and the
112 // set of DEX pcs associated to the source line number where the suspension occurred.
113 // This is used to support SD_INTO and SD_OVER single-step depths so we detect when a single-step
114 // causes the execution of an instruction in a different method or at a different line number.
115 mirror::ArtMethod* method;
116 std::set<uint32_t> dex_pcs;
117
118 // The stack depth when this single-step was initiated. This is used to support SD_OVER and SD_OUT
119 // single-step depth.
120 int stack_depth;
121
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700122 void VisitRoots(RootCallback* callback, void* arg, uint32_t tid, RootType root_type)
123 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
124
Sebastien Hertzbb43b432014-04-14 11:59:08 +0200125 bool ContainsDexPc(uint32_t dex_pc) const;
126
127 void Clear();
128
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100129 private:
130 DISALLOW_COPY_AND_ASSIGN(SingleStepControl);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700131};
132
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200133// TODO rename to InstrumentationRequest.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700134class DeoptimizationRequest {
135 public:
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100136 enum Kind {
137 kNothing, // no action.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200138 kRegisterForEvent, // start listening for instrumentation event.
139 kUnregisterForEvent, // stop listening for instrumentation event.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100140 kFullDeoptimization, // deoptimize everything.
141 kFullUndeoptimization, // undeoptimize everything.
142 kSelectiveDeoptimization, // deoptimize one method.
143 kSelectiveUndeoptimization // undeoptimize one method.
144 };
145
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700146 DeoptimizationRequest() : kind_(kNothing), instrumentation_event_(0), method_(nullptr) {}
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100147
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700148 DeoptimizationRequest(const DeoptimizationRequest& other)
149 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
150 : kind_(other.kind_), instrumentation_event_(other.instrumentation_event_) {
151 // Create a new JNI global reference for the method.
152 SetMethod(other.Method());
153 }
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100154
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700155 mirror::ArtMethod* Method() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
156
157 void SetMethod(mirror::ArtMethod* m) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
158
159 // Name 'Kind()' would collide with the above enum name.
160 Kind GetKind() const {
161 return kind_;
162 }
163
164 void SetKind(Kind kind) {
165 kind_ = kind;
166 }
167
168 uint32_t InstrumentationEvent() const {
169 return instrumentation_event_;
170 }
171
172 void SetInstrumentationEvent(uint32_t instrumentation_event) {
173 instrumentation_event_ = instrumentation_event;
174 }
175
176 private:
177 Kind kind_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100178
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200179 // TODO we could use a union to hold the instrumentation_event and the method since they
180 // respectively have sense only for kRegisterForEvent/kUnregisterForEvent and
181 // kSelectiveDeoptimization/kSelectiveUndeoptimization.
182
183 // Event to start or stop listening to. Only for kRegisterForEvent and kUnregisterForEvent.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700184 uint32_t instrumentation_event_;
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200185
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100186 // Method for selective deoptimization.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700187 jmethodID method_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100188};
189
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700190class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800191 public:
Mathieu Chartier4345c462014-06-27 10:20:14 -0700192 class TypeCache {
193 public:
194 // Returns a weak global for the input type. Deduplicates.
Brian Carlstrom306db812014-09-05 13:01:41 -0700195 jobject Add(mirror::Class* t) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_,
196 Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700197 // Clears the type cache and deletes all the weak global refs.
Brian Carlstrom306db812014-09-05 13:01:41 -0700198 void Clear() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_,
199 Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700200
201 private:
202 std::multimap<int32_t, jobject> objects_;
203 };
204
Elliott Hughes3bb81562011-10-21 18:52:59 -0700205 static bool ParseJdwpOptions(const std::string& options);
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700206 static void SetJdwpAllowed(bool allowed);
207
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700208 static void StartJdwp();
209 static void StopJdwp();
210
Elliott Hughes767a1472011-10-26 18:49:02 -0700211 // Invoked by the GC in case we need to keep DDMS informed.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700212 static void GcDidFinish() LOCKS_EXCLUDED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700213
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700214 // Return the DebugInvokeReq for the current thread.
215 static DebugInvokeReq* GetInvokeReq();
216
Elliott Hughes475fc232011-10-25 15:00:35 -0700217 static Thread* GetDebugThread();
218 static void ClearWaitForEventThread();
219
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700220 /*
221 * Enable/disable breakpoints and step modes. Used to provide a heads-up
222 * when the debugger attaches.
223 */
224 static void Connected();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100225 static void GoActive()
Brian Carlstrom306db812014-09-05 13:01:41 -0700226 LOCKS_EXCLUDED(Locks::breakpoint_lock_, Locks::deoptimization_lock_, Locks::mutator_lock_);
227 static void Disconnected() LOCKS_EXCLUDED(Locks::deoptimization_lock_, Locks::mutator_lock_);
Elliott Hughes86964332012-02-15 19:37:42 -0800228 static void Disposed();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700229
Elliott Hughesc0f09332012-03-26 13:27:06 -0700230 // Returns true if we're actually debugging with a real debugger, false if it's
231 // just DDMS (or nothing at all).
232 static bool IsDebuggerActive();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700233
Elliott Hughesc0f09332012-03-26 13:27:06 -0700234 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
235 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700236
Elliott Hughes86964332012-02-15 19:37:42 -0800237 static bool IsDisposed();
238
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700239 /*
240 * Time, in milliseconds, since the last debugger activity. Does not
241 * include DDMS activity. Returns -1 if there has been no activity.
242 * Returns 0 if we're in the middle of handling a debugger request.
243 */
244 static int64_t LastDebuggerActivity();
245
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700246 static void UndoDebuggerSuspensions();
247
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700248 /*
249 * Class, Object, Array
250 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700251 static std::string GetClassName(JDWP::RefTypeId id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700252 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700253 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId* class_object_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700254 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700255 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId* superclass_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700256 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700257 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700258 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700259 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700260 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800261 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700262 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700263 static void GetClassList(std::vector<JDWP::RefTypeId>* classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700264 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800265 static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700266 uint32_t* pStatus, std::string* pDescriptor)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700267 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700268 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>* ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700269 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800270 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
271 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersfc0e94b2013-09-23 23:51:32 -0700272 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700273 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700274 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string* source_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700275 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700276 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t* tag)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700277 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800278 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700279
Ian Rogersc0542af2014-09-03 16:16:56 -0700280 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int32_t* length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700281 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800282 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700283 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700284 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800285 static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700286 JDWP::Request* request)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700287 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700288
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700289 static JDWP::ObjectId CreateString(const std::string& str)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700290 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700291 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId* new_object)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700292 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800293 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Ian Rogersc0542af2014-09-03 16:16:56 -0700294 JDWP::ObjectId* new_array)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700295 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700296
Elliott Hughes88d63092013-01-09 09:55:54 -0800297 static bool MatchType(JDWP::RefTypeId instance_class_id, JDWP::RefTypeId class_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700298 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700299
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800300 //
301 // Monitors.
302 //
303 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
304 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
305 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700306 std::vector<JDWP::ObjectId>* monitors,
307 std::vector<uint32_t>* stack_depths)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100308 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800309 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100310 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700311 JDWP::ObjectId* contended_monitor)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100312 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800313 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
314
315 //
316 // Heap.
317 //
318 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
Ian Rogersc0542af2014-09-03 16:16:56 -0700319 std::vector<uint64_t>* counts)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800320 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800321 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700322 std::vector<JDWP::ObjectId>* instances)
Elliott Hughes3b78c942013-01-15 17:35:41 -0800323 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800324 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700325 std::vector<JDWP::ObjectId>* referring_objects)
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800326 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800327 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
328 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
329 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
330 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700331 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool* is_collected)
Elliott Hughes64f574f2013-02-20 14:57:12 -0800332 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
333 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
334 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800335
Elliott Hughes9777ba22013-01-17 09:04:19 -0800336 //
337 // Methods and fields.
338 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800339 static std::string GetMethodName(JDWP::MethodId method_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700340 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800341 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700342 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700343 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800344 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700345 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700346 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800347 static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700348 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700349 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800350 static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700351 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700352 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800353 static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700354 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700355 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800356 static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value,
357 JDWP::ExpandBuf* pReply)
358 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200359 static void OutputFieldValue(JDWP::FieldId field_id, const JValue* field_value,
360 JDWP::ExpandBuf* pReply)
361 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800362 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700363 std::vector<uint8_t>* bytecodes)
Elliott Hughes9777ba22013-01-17 09:04:19 -0800364 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700365
Elliott Hughesa96836a2013-01-17 12:27:49 -0800366 static std::string GetFieldName(JDWP::FieldId field_id)
367 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800368 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700369 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800370 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Brian Carlstromf69863b2013-07-17 21:53:13 -0700371 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800372 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700373 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700374 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800375 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700376 uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700377 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800378 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700379 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700380 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800381 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700382 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700383
Elliott Hughes88d63092013-01-09 09:55:54 -0800384 static std::string StringToUtf8(JDWP::ObjectId string_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700385 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800386 static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply)
387 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700388
389 /*
390 * Thread, ThreadGroup, Frame
391 */
Ian Rogersc0542af2014-09-03 16:16:56 -0700392 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string* name)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700393 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
394 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100395 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply)
Sebastien Hertza06430c2014-09-15 19:21:30 +0200396 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100397 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200398 static JDWP::JdwpError GetThreadGroupName(JDWP::ObjectId thread_group_id,
399 JDWP::ExpandBuf* pReply)
400 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
401 static JDWP::JdwpError GetThreadGroupParent(JDWP::ObjectId thread_group_id,
402 JDWP::ExpandBuf* pReply)
403 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
404 static JDWP::JdwpError GetThreadGroupChildren(JDWP::ObjectId thread_group_id,
405 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700406 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700407 static JDWP::ObjectId GetSystemThreadGroupId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700408 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700409
Jeff Hao920af3e2013-08-28 15:46:38 -0700410 static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100411 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id,
412 JDWP::JdwpThreadStatus* pThreadStatus,
413 JDWP::JdwpSuspendStatus* pSuspendStatus)
414 LOCKS_EXCLUDED(Locks::thread_list_lock_);
415 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id,
416 JDWP::ExpandBuf* pReply)
417 LOCKS_EXCLUDED(Locks::thread_list_lock_,
418 Locks::thread_suspend_count_lock_);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700419 // static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700420
Elliott Hughes026b1462012-06-28 20:43:49 -0700421 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700422 // returns all threads.
Sebastien Hertza06430c2014-09-15 19:21:30 +0200423 static void GetThreads(mirror::Object* thread_group, std::vector<JDWP::ObjectId>* thread_ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700424 LOCKS_EXCLUDED(Locks::thread_list_lock_)
425 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700426
Ian Rogersc0542af2014-09-03 16:16:56 -0700427 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t* result)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100428 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700429 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
430 size_t frame_count, JDWP::ExpandBuf* buf)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100431 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700432 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700433
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700434 static JDWP::ObjectId GetThreadSelfId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700435 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700436 static void SuspendVM()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700437 LOCKS_EXCLUDED(Locks::thread_list_lock_,
438 Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700439 static void ResumeVM();
Elliott Hughes88d63092013-01-09 09:55:54 -0800440 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700441 LOCKS_EXCLUDED(Locks::mutator_lock_,
442 Locks::thread_list_lock_,
443 Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700444
Elliott Hughes88d63092013-01-09 09:55:54 -0800445 static void ResumeThread(JDWP::ObjectId thread_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700446 LOCKS_EXCLUDED(Locks::thread_list_lock_,
447 Locks::thread_suspend_count_lock_)
448 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700449 static void SuspendSelf();
450
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700451 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
452 JDWP::ObjectId* result)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700453 LOCKS_EXCLUDED(Locks::thread_list_lock_,
454 Locks::thread_suspend_count_lock_)
455 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertzcb19ebf2014-03-11 15:26:35 +0100456 static JDWP::JdwpError GetLocalValue(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, int slot,
457 JDWP::JdwpTag tag, uint8_t* buf, size_t expectedLen)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100458 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700459 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertzcb19ebf2014-03-11 15:26:35 +0100460 static JDWP::JdwpError SetLocalValue(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, int slot,
461 JDWP::JdwpTag tag, uint64_t value, size_t width)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100462 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700463 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700464
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100465 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id)
466 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughesf9501702013-01-11 11:22:27 -0800467
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700468 /*
469 * Debugger notification
470 */
471 enum {
Elliott Hughes86964332012-02-15 19:37:42 -0800472 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700473 kSingleStep = 0x02,
474 kMethodEntry = 0x04,
475 kMethodExit = 0x08,
476 };
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200477 static void PostFieldAccessEvent(mirror::ArtMethod* m, int dex_pc, mirror::Object* this_object,
478 mirror::ArtField* f)
479 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
480 static void PostFieldModificationEvent(mirror::ArtMethod* m, int dex_pc,
481 mirror::Object* this_object, mirror::ArtField* f,
482 const JValue* field_value)
483 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
484 static void PostException(const ThrowLocation& throw_location, mirror::ArtMethod* catch_method,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800485 uint32_t catch_dex_pc, mirror::Throwable* exception)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700486 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700487 static void PostThreadStart(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700488 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700489 static void PostThreadDeath(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700490 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800491 static void PostClassPrepare(mirror::Class* c)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700492 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700493
Ian Rogers62d6c772013-02-27 08:32:07 -0800494 static void UpdateDebugger(Thread* thread, mirror::Object* this_object,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100495 mirror::ArtMethod* method, uint32_t new_dex_pc,
496 int event_flags, const JValue* return_value)
jeffhao09bfc6a2012-12-11 18:11:43 -0800497 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700498 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800499
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100500 // Records deoptimization request in the queue.
501 static void RequestDeoptimization(const DeoptimizationRequest& req)
Brian Carlstrom306db812014-09-05 13:01:41 -0700502 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100503 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
504
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100505 // Support delayed full undeoptimization requests. This is currently only used for single-step
506 // events.
Brian Carlstrom306db812014-09-05 13:01:41 -0700507 static void DelayFullUndeoptimization() LOCKS_EXCLUDED(Locks::deoptimization_lock_);
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100508 static void ProcessDelayedFullUndeoptimizations()
Brian Carlstrom306db812014-09-05 13:01:41 -0700509 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100510 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
511
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100512 // Manage deoptimization after updating JDWP events list. Suspends all threads, processes each
513 // request and finally resumes all threads.
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100514 static void ManageDeoptimization()
Brian Carlstrom306db812014-09-05 13:01:41 -0700515 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100516 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
517
518 // Breakpoints.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100519 static void WatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
520 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700521 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100522 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
523 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700524 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100525
526 // Single-stepping.
Elliott Hughes88d63092013-01-09 09:55:54 -0800527 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700528 JDWP::JdwpStepDepth depth)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700529 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100530 static void UnconfigureStep(JDWP::ObjectId thread_id)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100531 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100532 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700533
Elliott Hughes88d63092013-01-09 09:55:54 -0800534 static JDWP::JdwpError InvokeMethod(JDWP::ObjectId thread_id, JDWP::ObjectId object_id,
535 JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700536 uint32_t arg_count, uint64_t* arg_values,
537 JDWP::JdwpTag* arg_types, uint32_t options,
538 JDWP::JdwpTag* pResultTag, uint64_t* pResultValue,
539 JDWP::ObjectId* pExceptObj)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700540 LOCKS_EXCLUDED(Locks::thread_list_lock_,
541 Locks::thread_suspend_count_lock_)
542 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700543 static void ExecuteMethod(DebugInvokeReq* pReq);
544
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700545 /*
546 * DDM support.
547 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700548 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700549 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100550 static void DdmSetThreadNotification(bool enable)
551 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700552 static bool DdmHandlePacket(JDWP::Request* request, uint8_t** pReplyBuf, int* pReplyLen);
Ian Rogersb726dcb2012-09-05 08:57:23 -0700553 static void DdmConnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
554 static void DdmDisconnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700555 static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700556 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700557 static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700558 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700559 static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700560 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700561
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700562 static void VisitRoots(RootCallback* callback, void* arg)
563 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
564
Elliott Hughes545a0642011-11-08 19:10:03 -0800565 /*
566 * Recent allocation tracking support.
567 */
Ian Rogers844506b2014-09-12 19:59:33 -0700568 static void RecordAllocation(Thread* self, mirror::Class* type, size_t byte_count)
Brian Carlstrom306db812014-09-05 13:01:41 -0700569 LOCKS_EXCLUDED(Locks::alloc_tracker_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700570 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom306db812014-09-05 13:01:41 -0700571 static void SetAllocTrackingEnabled(bool enabled) LOCKS_EXCLUDED(Locks::alloc_tracker_lock_);
Ian Rogers719d1a32014-03-06 12:13:39 -0800572 static bool IsAllocTrackingEnabled() {
573 return recent_allocation_records_ != nullptr;
574 }
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100575 static jbyteArray GetRecentAllocations()
Brian Carlstrom306db812014-09-05 13:01:41 -0700576 LOCKS_EXCLUDED(Locks::alloc_tracker_lock_)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100577 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom306db812014-09-05 13:01:41 -0700578 static size_t HeadIndex() EXCLUSIVE_LOCKS_REQUIRED(Locks::alloc_tracker_lock_);
579 static void DumpRecentAllocations() LOCKS_EXCLUDED(Locks::alloc_tracker_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800580
Elliott Hughes767a1472011-10-26 18:49:02 -0700581 enum HpifWhen {
582 HPIF_WHEN_NEVER = 0,
583 HPIF_WHEN_NOW = 1,
584 HPIF_WHEN_NEXT_GC = 2,
585 HPIF_WHEN_EVERY_GC = 3
586 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700587 static int DdmHandleHpifChunk(HpifWhen when)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700588 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700589
590 enum HpsgWhen {
591 HPSG_WHEN_NEVER = 0,
592 HPSG_WHEN_EVERY_GC = 1,
593 };
594 enum HpsgWhat {
595 HPSG_WHAT_MERGED_OBJECTS = 0,
596 HPSG_WHAT_DISTINCT_OBJECTS = 1,
597 };
598 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
599
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700600 static void DdmSendHeapInfo(HpifWhen reason)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700601 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700602 static void DdmSendHeapSegments(bool native)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700603 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800604
605 private:
Brian Carlstrom2d888622013-07-18 17:02:00 -0700606 static void DdmBroadcast(bool connect) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700607 static void PostThreadStartOrStop(Thread*, uint32_t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700608 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800609
Sebastien Hertz8379b222014-02-24 17:38:15 +0100610 static void PostLocationEvent(mirror::ArtMethod* method, int pcOffset,
611 mirror::Object* thisPtr, int eventFlags,
612 const JValue* return_value)
613 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
614
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200615 static JDWP::ObjectId GetThisObjectIdForEvent(mirror::Object* this_object)
616 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
617
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100618 static void ProcessDeoptimizationRequest(const DeoptimizationRequest& request)
619 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_);
620
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100621 static void RequestDeoptimizationLocked(const DeoptimizationRequest& req)
Brian Carlstrom306db812014-09-05 13:01:41 -0700622 EXCLUSIVE_LOCKS_REQUIRED(Locks::deoptimization_lock_)
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100623 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
624
Brian Carlstrom306db812014-09-05 13:01:41 -0700625 static AllocRecord* recent_allocation_records_ PT_GUARDED_BY(Locks::alloc_tracker_lock_);
626 static size_t alloc_record_max_ GUARDED_BY(Locks::alloc_tracker_lock_);
627 static size_t alloc_record_head_ GUARDED_BY(Locks::alloc_tracker_lock_);
628 static size_t alloc_record_count_ GUARDED_BY(Locks::alloc_tracker_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100629
630 // Deoptimization requests to be processed each time the event list is updated. This is used when
631 // registering and unregistering events so we do not deoptimize while holding the event list
632 // lock.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200633 // TODO rename to instrumentation_requests.
Brian Carlstrom306db812014-09-05 13:01:41 -0700634 static std::vector<DeoptimizationRequest> deoptimization_requests_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100635
636 // Count the number of events requiring full deoptimization. When the counter is > 0, everything
637 // is deoptimized, otherwise everything is undeoptimized.
638 // Note: we fully deoptimize on the first event only (when the counter is set to 1). We fully
639 // undeoptimize when the last event is unregistered (when the counter is set to 0).
Brian Carlstrom306db812014-09-05 13:01:41 -0700640 static size_t full_deoptimization_event_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100641
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100642 // Count the number of full undeoptimization requests delayed to next resume or end of debug
643 // session.
Brian Carlstrom306db812014-09-05 13:01:41 -0700644 static size_t delayed_full_undeoptimization_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100645
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200646 static size_t* GetReferenceCounterForEvent(uint32_t instrumentation_event);
647
Mathieu Chartier4345c462014-06-27 10:20:14 -0700648 // Weak global type cache, TODO improve this.
Brian Carlstrom306db812014-09-05 13:01:41 -0700649 static TypeCache type_cache_ GUARDED_BY(Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700650
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200651 // Instrumentation event reference counters.
652 // TODO we could use an array instead of having all these dedicated counters. Instrumentation
653 // events are bits of a mask so we could convert them to array index.
Brian Carlstrom306db812014-09-05 13:01:41 -0700654 static size_t dex_pc_change_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
655 static size_t method_enter_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
656 static size_t method_exit_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
657 static size_t field_read_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
658 static size_t field_write_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
659 static size_t exception_catch_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200660 static uint32_t instrumentation_events_ GUARDED_BY(Locks::mutator_lock_);
661
Brian Carlstrom306db812014-09-05 13:01:41 -0700662 friend class AllocRecord; // For type_cache_ with proper annotalysis.
Ian Rogers719d1a32014-03-06 12:13:39 -0800663 DISALLOW_COPY_AND_ASSIGN(Dbg);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700664};
665
666#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800667 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700668
669} // namespace art
670
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700671#endif // ART_RUNTIME_DEBUGGER_H_