blob: 1cf0b0c421954e3bb999d3e3c7fca78e0c4203b5 [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
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010026#include <set>
Elliott Hughes3bb81562011-10-21 18:52:59 -070027#include <string>
Sebastien Hertz4d25df32014-03-21 17:44:46 +010028#include <vector>
Elliott Hughes3bb81562011-10-21 18:52:59 -070029
Elliott Hughes872d4ec2011-10-21 17:07:15 -070030#include "jdwp/jdwp.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080031#include "jni.h"
32#include "jvalue.h"
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080033#include "object_callbacks.h"
Jeff Hao920af3e2013-08-28 15:46:38 -070034#include "thread_state.h"
Elliott Hughes872d4ec2011-10-21 17:07:15 -070035
36namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080037namespace mirror {
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +020038class ArtField;
Brian Carlstromea46f952013-07-30 01:26:50 -070039class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080040class Class;
41class Object;
42class Throwable;
43} // namespace mirror
Hiroshi Yamauchib5a9e3d2014-06-09 12:11:20 -070044class AllocRecord;
Ian Rogers1b09b092012-08-20 15:35:52 -070045class Thread;
Ian Rogers62d6c772013-02-27 08:32:07 -080046class ThrowLocation;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070047
48/*
49 * Invoke-during-breakpoint support.
50 */
51struct DebugInvokeReq {
Elliott Hughes7b3cdfc2011-12-08 21:28:17 -080052 DebugInvokeReq()
Sebastien Hertzd38667a2013-11-25 15:43:54 +010053 : ready(false), invoke_needed(false),
54 receiver(NULL), thread(NULL), klass(NULL), method(NULL),
55 arg_count(0), arg_values(NULL), options(0), error(JDWP::ERR_NONE),
Ian Rogers00f7d0e2012-07-19 15:28:27 -070056 result_tag(JDWP::JT_VOID), exception(0),
Sebastien Hertzd38667a2013-11-25 15:43:54 +010057 lock("a DebugInvokeReq lock", kBreakpointInvokeLock),
58 cond("a DebugInvokeReq condition variable", lock) {
Elliott Hughes475fc232011-10-25 15:00:35 -070059 }
60
Elliott Hughes872d4ec2011-10-21 17:07:15 -070061 /* boolean; only set when we're in the tail end of an event handler */
62 bool ready;
63
64 /* boolean; set if the JDWP thread wants this thread to do work */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010065 bool invoke_needed;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070066
67 /* request */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010068 mirror::Object* receiver; /* not used for ClassType.InvokeMethod */
69 mirror::Object* thread;
70 mirror::Class* klass;
71 mirror::ArtMethod* method;
72 uint32_t arg_count;
73 uint64_t* arg_values; /* will be NULL if arg_count_ == 0 */
74 uint32_t options;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070075
76 /* result */
Elliott Hughes475fc232011-10-25 15:00:35 -070077 JDWP::JdwpError error;
Elliott Hughesd07986f2011-12-06 18:27:45 -080078 JDWP::JdwpTag result_tag;
Elliott Hughes475fc232011-10-25 15:00:35 -070079 JValue result_value;
80 JDWP::ObjectId exception;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070081
82 /* condition variable to wait on while the method executes */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010083 Mutex lock DEFAULT_MUTEX_ACQUIRED_AFTER;
84 ConditionVariable cond GUARDED_BY(lock);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010085
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -070086 void VisitRoots(RootCallback* callback, void* arg, uint32_t tid, RootType root_type)
87 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
88
Sebastien Hertzbb43b432014-04-14 11:59:08 +020089 void Clear();
90
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010091 private:
92 DISALLOW_COPY_AND_ASSIGN(DebugInvokeReq);
93};
94
95// Thread local data-structure that holds fields for controlling single-stepping.
96struct SingleStepControl {
97 SingleStepControl()
98 : is_active(false), step_size(JDWP::SS_MIN), step_depth(JDWP::SD_INTO),
99 method(nullptr), stack_depth(0) {
100 }
101
102 // Are we single-stepping right now?
103 bool is_active;
104
105 // See JdwpStepSize and JdwpStepDepth for details.
106 JDWP::JdwpStepSize step_size;
107 JDWP::JdwpStepDepth step_depth;
108
109 // The location this single-step was initiated from.
110 // A single-step is initiated in a suspended thread. We save here the current method and the
111 // set of DEX pcs associated to the source line number where the suspension occurred.
112 // This is used to support SD_INTO and SD_OVER single-step depths so we detect when a single-step
113 // causes the execution of an instruction in a different method or at a different line number.
114 mirror::ArtMethod* method;
115 std::set<uint32_t> dex_pcs;
116
117 // The stack depth when this single-step was initiated. This is used to support SD_OVER and SD_OUT
118 // single-step depth.
119 int stack_depth;
120
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700121 void VisitRoots(RootCallback* callback, void* arg, uint32_t tid, RootType root_type)
122 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
123
Sebastien Hertzbb43b432014-04-14 11:59:08 +0200124 bool ContainsDexPc(uint32_t dex_pc) const;
125
126 void Clear();
127
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100128 private:
129 DISALLOW_COPY_AND_ASSIGN(SingleStepControl);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700130};
131
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200132// TODO rename to InstrumentationRequest.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100133struct DeoptimizationRequest {
134 enum Kind {
135 kNothing, // no action.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200136 kRegisterForEvent, // start listening for instrumentation event.
137 kUnregisterForEvent, // stop listening for instrumentation event.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100138 kFullDeoptimization, // deoptimize everything.
139 kFullUndeoptimization, // undeoptimize everything.
140 kSelectiveDeoptimization, // deoptimize one method.
141 kSelectiveUndeoptimization // undeoptimize one method.
142 };
143
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200144 DeoptimizationRequest() : kind(kNothing), instrumentation_event(0), method(nullptr) {}
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100145
146 void VisitRoots(RootCallback* callback, void* arg);
147
148 Kind kind;
149
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200150 // TODO we could use a union to hold the instrumentation_event and the method since they
151 // respectively have sense only for kRegisterForEvent/kUnregisterForEvent and
152 // kSelectiveDeoptimization/kSelectiveUndeoptimization.
153
154 // Event to start or stop listening to. Only for kRegisterForEvent and kUnregisterForEvent.
155 uint32_t instrumentation_event;
156
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100157 // Method for selective deoptimization.
158 mirror::ArtMethod* method;
159};
160
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700161class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800162 public:
Elliott Hughes3bb81562011-10-21 18:52:59 -0700163 static bool ParseJdwpOptions(const std::string& options);
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700164 static void SetJdwpAllowed(bool allowed);
165
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700166 static void StartJdwp();
167 static void StopJdwp();
168
Elliott Hughes767a1472011-10-26 18:49:02 -0700169 // Invoked by the GC in case we need to keep DDMS informed.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700170 static void GcDidFinish() LOCKS_EXCLUDED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700171
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700172 // Return the DebugInvokeReq for the current thread.
173 static DebugInvokeReq* GetInvokeReq();
174
Elliott Hughes475fc232011-10-25 15:00:35 -0700175 static Thread* GetDebugThread();
176 static void ClearWaitForEventThread();
177
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700178 /*
179 * Enable/disable breakpoints and step modes. Used to provide a heads-up
180 * when the debugger attaches.
181 */
182 static void Connected();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100183 static void GoActive()
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100184 LOCKS_EXCLUDED(Locks::breakpoint_lock_, deoptimization_lock_, Locks::mutator_lock_);
185 static void Disconnected() LOCKS_EXCLUDED(deoptimization_lock_, Locks::mutator_lock_);
Elliott Hughes86964332012-02-15 19:37:42 -0800186 static void Disposed();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700187
Elliott Hughesc0f09332012-03-26 13:27:06 -0700188 // Returns true if we're actually debugging with a real debugger, false if it's
189 // just DDMS (or nothing at all).
190 static bool IsDebuggerActive();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700191
Elliott Hughesc0f09332012-03-26 13:27:06 -0700192 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
193 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700194
Elliott Hughes86964332012-02-15 19:37:42 -0800195 static bool IsDisposed();
196
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700197 /*
198 * Time, in milliseconds, since the last debugger activity. Does not
199 * include DDMS activity. Returns -1 if there has been no activity.
200 * Returns 0 if we're in the middle of handling a debugger request.
201 */
202 static int64_t LastDebuggerActivity();
203
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700204 static void UndoDebuggerSuspensions();
205
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700206 /*
207 * Class, Object, Array
208 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700209 static std::string GetClassName(JDWP::RefTypeId id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700210 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800211 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId& class_object_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700212 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800213 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId& superclass_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700214 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700215 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700216 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700217 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700218 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800219 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700220 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700221 static void GetClassList(std::vector<JDWP::RefTypeId>& classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700222 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800223 static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700224 uint32_t* pStatus, std::string* pDescriptor)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700225 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700226 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>& ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700227 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800228 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
229 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersfc0e94b2013-09-23 23:51:32 -0700230 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700231 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800232 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string& source_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700233 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800234 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t& tag)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700235 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800236 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700237
Elliott Hughes88d63092013-01-09 09:55:54 -0800238 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int& length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700239 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800240 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700241 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700242 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800243 static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800244 JDWP::Request& request)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700245 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700246
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700247 static JDWP::ObjectId CreateString(const std::string& str)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700248 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800249 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId& new_object)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700250 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800251 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700252 JDWP::ObjectId& new_array)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700253 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700254
Elliott Hughes88d63092013-01-09 09:55:54 -0800255 static bool MatchType(JDWP::RefTypeId instance_class_id, JDWP::RefTypeId class_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700256 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700257
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800258 //
259 // Monitors.
260 //
261 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
262 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
263 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
264 std::vector<JDWP::ObjectId>& monitors,
265 std::vector<uint32_t>& stack_depths)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100266 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800267 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100268 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id,
269 JDWP::ObjectId& contended_monitor)
270 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800271 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
272
273 //
274 // Heap.
275 //
276 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
277 std::vector<uint64_t>& counts)
278 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800279 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
280 std::vector<JDWP::ObjectId>& instances)
281 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800282 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
283 std::vector<JDWP::ObjectId>& referring_objects)
284 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800285 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
286 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
287 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
288 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
289 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool& is_collected)
290 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
291 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
292 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800293
Elliott Hughes9777ba22013-01-17 09:04:19 -0800294 //
295 // Methods and fields.
296 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800297 static std::string GetMethodName(JDWP::MethodId method_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700298 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800299 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700300 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700301 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800302 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700303 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700304 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800305 static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700306 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700307 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800308 static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700309 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700310 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800311 static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700312 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700313 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800314 static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value,
315 JDWP::ExpandBuf* pReply)
316 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200317 static void OutputFieldValue(JDWP::FieldId field_id, const JValue* field_value,
318 JDWP::ExpandBuf* pReply)
319 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800320 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
321 std::vector<uint8_t>& bytecodes)
322 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700323
Elliott Hughesa96836a2013-01-17 12:27:49 -0800324 static std::string GetFieldName(JDWP::FieldId field_id)
325 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800326 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700327 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800328 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Brian Carlstromf69863b2013-07-17 21:53:13 -0700329 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800330 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700331 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700332 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800333 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700334 uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700335 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800336 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700337 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700338 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800339 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700340 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700341
Elliott Hughes88d63092013-01-09 09:55:54 -0800342 static std::string StringToUtf8(JDWP::ObjectId string_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700343 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800344 static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply)
345 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700346
347 /*
348 * Thread, ThreadGroup, Frame
349 */
Elliott Hughes88d63092013-01-09 09:55:54 -0800350 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string& name)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700351 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
352 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100353 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply)
354 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800355 static std::string GetThreadGroupName(JDWP::ObjectId thread_group_id);
356 static JDWP::ObjectId GetThreadGroupParent(JDWP::ObjectId thread_group_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700357 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700358 static JDWP::ObjectId GetSystemThreadGroupId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700359 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700360 static JDWP::ObjectId GetMainThreadGroupId();
361
Jeff Hao920af3e2013-08-28 15:46:38 -0700362 static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100363 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id,
364 JDWP::JdwpThreadStatus* pThreadStatus,
365 JDWP::JdwpSuspendStatus* pSuspendStatus)
366 LOCKS_EXCLUDED(Locks::thread_list_lock_);
367 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id,
368 JDWP::ExpandBuf* pReply)
369 LOCKS_EXCLUDED(Locks::thread_list_lock_,
370 Locks::thread_suspend_count_lock_);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700371 // static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700372
Elliott Hughes026b1462012-06-28 20:43:49 -0700373 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700374 // returns all threads.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700375 static void GetThreads(JDWP::ObjectId thread_group_id, std::vector<JDWP::ObjectId>& thread_ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700376 LOCKS_EXCLUDED(Locks::thread_list_lock_)
377 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700378 static void GetChildThreadGroups(JDWP::ObjectId thread_group_id, std::vector<JDWP::ObjectId>& child_thread_group_ids);
379
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100380 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t& result)
381 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700382 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
383 size_t frame_count, JDWP::ExpandBuf* buf)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100384 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700385 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700386
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700387 static JDWP::ObjectId GetThreadSelfId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700388 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700389 static void SuspendVM()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700390 LOCKS_EXCLUDED(Locks::thread_list_lock_,
391 Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700392 static void ResumeVM();
Elliott Hughes88d63092013-01-09 09:55:54 -0800393 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700394 LOCKS_EXCLUDED(Locks::mutator_lock_,
395 Locks::thread_list_lock_,
396 Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700397
Elliott Hughes88d63092013-01-09 09:55:54 -0800398 static void ResumeThread(JDWP::ObjectId thread_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700399 LOCKS_EXCLUDED(Locks::thread_list_lock_,
400 Locks::thread_suspend_count_lock_)
401 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700402 static void SuspendSelf();
403
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700404 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
405 JDWP::ObjectId* result)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700406 LOCKS_EXCLUDED(Locks::thread_list_lock_,
407 Locks::thread_suspend_count_lock_)
408 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertzcb19ebf2014-03-11 15:26:35 +0100409 static JDWP::JdwpError GetLocalValue(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, int slot,
410 JDWP::JdwpTag tag, uint8_t* buf, size_t expectedLen)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100411 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700412 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertzcb19ebf2014-03-11 15:26:35 +0100413 static JDWP::JdwpError SetLocalValue(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, int slot,
414 JDWP::JdwpTag tag, uint64_t value, size_t width)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100415 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700416 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700417
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100418 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id)
419 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughesf9501702013-01-11 11:22:27 -0800420
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700421 /*
422 * Debugger notification
423 */
424 enum {
Elliott Hughes86964332012-02-15 19:37:42 -0800425 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700426 kSingleStep = 0x02,
427 kMethodEntry = 0x04,
428 kMethodExit = 0x08,
429 };
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200430 static void PostFieldAccessEvent(mirror::ArtMethod* m, int dex_pc, mirror::Object* this_object,
431 mirror::ArtField* f)
432 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
433 static void PostFieldModificationEvent(mirror::ArtMethod* m, int dex_pc,
434 mirror::Object* this_object, mirror::ArtField* f,
435 const JValue* field_value)
436 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
437 static void PostException(const ThrowLocation& throw_location, mirror::ArtMethod* catch_method,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800438 uint32_t catch_dex_pc, mirror::Throwable* exception)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700439 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700440 static void PostThreadStart(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700441 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700442 static void PostThreadDeath(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700443 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800444 static void PostClassPrepare(mirror::Class* c)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700445 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700446
Ian Rogers62d6c772013-02-27 08:32:07 -0800447 static void UpdateDebugger(Thread* thread, mirror::Object* this_object,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100448 mirror::ArtMethod* method, uint32_t new_dex_pc,
449 int event_flags, const JValue* return_value)
jeffhao09bfc6a2012-12-11 18:11:43 -0800450 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700451 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800452
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100453 // Records deoptimization request in the queue.
454 static void RequestDeoptimization(const DeoptimizationRequest& req)
455 LOCKS_EXCLUDED(deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100456 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
457
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100458 // Support delayed full undeoptimization requests. This is currently only used for single-step
459 // events.
460 static void DelayFullUndeoptimization() LOCKS_EXCLUDED(deoptimization_lock_);
461 static void ProcessDelayedFullUndeoptimizations()
462 LOCKS_EXCLUDED(deoptimization_lock_)
463 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
464
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100465 // Manage deoptimization after updating JDWP events list. Suspends all threads, processes each
466 // request and finally resumes all threads.
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100467 static void ManageDeoptimization()
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100468 LOCKS_EXCLUDED(deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100469 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
470
471 // Breakpoints.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100472 static void WatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
473 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700474 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100475 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
476 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700477 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100478
479 // Single-stepping.
Elliott Hughes88d63092013-01-09 09:55:54 -0800480 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700481 JDWP::JdwpStepDepth depth)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700482 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100483 static void UnconfigureStep(JDWP::ObjectId thread_id)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100484 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100485 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700486
Elliott Hughes88d63092013-01-09 09:55:54 -0800487 static JDWP::JdwpError InvokeMethod(JDWP::ObjectId thread_id, JDWP::ObjectId object_id,
488 JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700489 uint32_t arg_count, uint64_t* arg_values,
490 JDWP::JdwpTag* arg_types, uint32_t options,
491 JDWP::JdwpTag* pResultTag, uint64_t* pResultValue,
492 JDWP::ObjectId* pExceptObj)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700493 LOCKS_EXCLUDED(Locks::thread_list_lock_,
494 Locks::thread_suspend_count_lock_)
495 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700496 static void ExecuteMethod(DebugInvokeReq* pReq);
497
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700498 /*
499 * DDM support.
500 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700501 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700502 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100503 static void DdmSetThreadNotification(bool enable)
504 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800505 static bool DdmHandlePacket(JDWP::Request& request, uint8_t** pReplyBuf, int* pReplyLen);
Ian Rogersb726dcb2012-09-05 08:57:23 -0700506 static void DdmConnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
507 static void DdmDisconnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700508 static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700509 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700510 static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700511 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700512 static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700513 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700514
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700515 static void VisitRoots(RootCallback* callback, void* arg)
516 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
517
Elliott Hughes545a0642011-11-08 19:10:03 -0800518 /*
519 * Recent allocation tracking support.
520 */
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800521 static void RecordAllocation(mirror::Class* type, size_t byte_count)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100522 LOCKS_EXCLUDED(alloc_tracker_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700523 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100524 static void SetAllocTrackingEnabled(bool enabled) LOCKS_EXCLUDED(alloc_tracker_lock_);
Ian Rogers719d1a32014-03-06 12:13:39 -0800525 static bool IsAllocTrackingEnabled() {
526 return recent_allocation_records_ != nullptr;
527 }
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100528 static jbyteArray GetRecentAllocations()
529 LOCKS_EXCLUDED(alloc_tracker_lock_)
530 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers719d1a32014-03-06 12:13:39 -0800531 static size_t HeadIndex() EXCLUSIVE_LOCKS_REQUIRED(alloc_tracker_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100532 static void DumpRecentAllocations() LOCKS_EXCLUDED(alloc_tracker_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800533
Elliott Hughes767a1472011-10-26 18:49:02 -0700534 enum HpifWhen {
535 HPIF_WHEN_NEVER = 0,
536 HPIF_WHEN_NOW = 1,
537 HPIF_WHEN_NEXT_GC = 2,
538 HPIF_WHEN_EVERY_GC = 3
539 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700540 static int DdmHandleHpifChunk(HpifWhen when)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700541 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700542
543 enum HpsgWhen {
544 HPSG_WHEN_NEVER = 0,
545 HPSG_WHEN_EVERY_GC = 1,
546 };
547 enum HpsgWhat {
548 HPSG_WHAT_MERGED_OBJECTS = 0,
549 HPSG_WHAT_DISTINCT_OBJECTS = 1,
550 };
551 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
552
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700553 static void DdmSendHeapInfo(HpifWhen reason)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700554 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700555 static void DdmSendHeapSegments(bool native)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700556 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800557
558 private:
Brian Carlstrom2d888622013-07-18 17:02:00 -0700559 static void DdmBroadcast(bool connect) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700560 static void PostThreadStartOrStop(Thread*, uint32_t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700561 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800562
Sebastien Hertz8379b222014-02-24 17:38:15 +0100563 static void PostLocationEvent(mirror::ArtMethod* method, int pcOffset,
564 mirror::Object* thisPtr, int eventFlags,
565 const JValue* return_value)
566 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
567
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200568 static JDWP::ObjectId GetThisObjectIdForEvent(mirror::Object* this_object)
569 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
570
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100571 static void ProcessDeoptimizationRequest(const DeoptimizationRequest& request)
572 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_);
573
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100574 static void RequestDeoptimizationLocked(const DeoptimizationRequest& req)
575 EXCLUSIVE_LOCKS_REQUIRED(deoptimization_lock_)
576 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
577
Ian Rogers719d1a32014-03-06 12:13:39 -0800578 static Mutex* alloc_tracker_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
579
580 static AllocRecord* recent_allocation_records_ PT_GUARDED_BY(alloc_tracker_lock_);
581 static size_t alloc_record_max_ GUARDED_BY(alloc_tracker_lock_);
582 static size_t alloc_record_head_ GUARDED_BY(alloc_tracker_lock_);
583 static size_t alloc_record_count_ GUARDED_BY(alloc_tracker_lock_);
584
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100585 // Guards deoptimization requests.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200586 // TODO rename to instrumentation_update_lock.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100587 static Mutex* deoptimization_lock_ ACQUIRED_AFTER(Locks::breakpoint_lock_);
588
589 // Deoptimization requests to be processed each time the event list is updated. This is used when
590 // registering and unregistering events so we do not deoptimize while holding the event list
591 // lock.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200592 // TODO rename to instrumentation_requests.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100593 static std::vector<DeoptimizationRequest> deoptimization_requests_ GUARDED_BY(deoptimization_lock_);
594
595 // Count the number of events requiring full deoptimization. When the counter is > 0, everything
596 // is deoptimized, otherwise everything is undeoptimized.
597 // Note: we fully deoptimize on the first event only (when the counter is set to 1). We fully
598 // undeoptimize when the last event is unregistered (when the counter is set to 0).
599 static size_t full_deoptimization_event_count_ GUARDED_BY(deoptimization_lock_);
600
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100601 // Count the number of full undeoptimization requests delayed to next resume or end of debug
602 // session.
603 static size_t delayed_full_undeoptimization_count_ GUARDED_BY(deoptimization_lock_);
604
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200605 static size_t* GetReferenceCounterForEvent(uint32_t instrumentation_event);
606
607 // Instrumentation event reference counters.
608 // TODO we could use an array instead of having all these dedicated counters. Instrumentation
609 // events are bits of a mask so we could convert them to array index.
610 static size_t dex_pc_change_event_ref_count_ GUARDED_BY(deoptimization_lock_);
611 static size_t method_enter_event_ref_count_ GUARDED_BY(deoptimization_lock_);
612 static size_t method_exit_event_ref_count_ GUARDED_BY(deoptimization_lock_);
613 static size_t field_read_event_ref_count_ GUARDED_BY(deoptimization_lock_);
614 static size_t field_write_event_ref_count_ GUARDED_BY(deoptimization_lock_);
615 static size_t exception_catch_event_ref_count_ GUARDED_BY(deoptimization_lock_);
616 static uint32_t instrumentation_events_ GUARDED_BY(Locks::mutator_lock_);
617
Ian Rogers719d1a32014-03-06 12:13:39 -0800618 DISALLOW_COPY_AND_ASSIGN(Dbg);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700619};
620
621#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800622 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700623
624} // namespace art
625
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700626#endif // ART_RUNTIME_DEBUGGER_H_