blob: e40f10fdf9a0b0f1ec818986d88fd2b3589be19a [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 {
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;
Mathieu Chartierc7853442015-03-27 14:35:38 -070045class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070046class ArtMethod;
Sebastien Hertz6995c602014-09-09 12:10:13 +020047class ObjectRegistry;
Sebastien Hertzcbc50642015-06-01 17:33:12 +020048class ScopedObjectAccess;
Sebastien Hertz6995c602014-09-09 12:10:13 +020049class ScopedObjectAccessUnchecked;
Sebastien Hertz8009f392014-09-01 17:07:11 +020050class StackVisitor;
Ian Rogers1b09b092012-08-20 15:35:52 -070051class Thread;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070052
53/*
54 * Invoke-during-breakpoint support.
55 */
56struct DebugInvokeReq {
Sebastien Hertzcbc50642015-06-01 17:33:12 +020057 DebugInvokeReq(uint32_t invoke_request_id, JDWP::ObjectId invoke_thread_id,
58 mirror::Object* invoke_receiver, mirror::Class* invoke_class,
Mathieu Chartiere401d142015-04-22 13:56:20 -070059 ArtMethod* invoke_method, uint32_t invoke_options,
Sebastien Hertzcbc50642015-06-01 17:33:12 +020060 uint64_t args[], uint32_t args_count)
61 : request_id(invoke_request_id), thread_id(invoke_thread_id), receiver(invoke_receiver),
62 klass(invoke_class), method(invoke_method), arg_count(args_count), arg_values(args),
63 options(invoke_options), reply(JDWP::expandBufAlloc()) {
Elliott Hughes475fc232011-10-25 15:00:35 -070064 }
65
Sebastien Hertzcbc50642015-06-01 17:33:12 +020066 ~DebugInvokeReq() {
67 JDWP::expandBufFree(reply);
68 }
69
70 // Request
71 const uint32_t request_id;
72 const JDWP::ObjectId thread_id;
73 GcRoot<mirror::Object> receiver; // not used for ClassType.InvokeMethod.
Sebastien Hertz1558b572015-02-25 15:05:59 +010074 GcRoot<mirror::Class> klass;
Sebastien Hertzcbc50642015-06-01 17:33:12 +020075 ArtMethod* const method;
Sebastien Hertz1558b572015-02-25 15:05:59 +010076 const uint32_t arg_count;
Sebastien Hertzcbc50642015-06-01 17:33:12 +020077 std::unique_ptr<uint64_t[]> arg_values; // will be null if arg_count_ == 0. We take ownership
78 // of this array so we must delete it upon destruction.
Sebastien Hertz1558b572015-02-25 15:05:59 +010079 const uint32_t options;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070080
Sebastien Hertzcbc50642015-06-01 17:33:12 +020081 // Reply
82 JDWP::ExpandBuf* const reply;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010083
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -070084 void VisitRoots(RootVisitor* visitor, const RootInfo& root_info)
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -070085 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
86
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010087 private:
88 DISALLOW_COPY_AND_ASSIGN(DebugInvokeReq);
89};
90
91// Thread local data-structure that holds fields for controlling single-stepping.
Sebastien Hertz597c4f02015-01-26 17:37:14 +010092class SingleStepControl {
93 public:
94 SingleStepControl(JDWP::JdwpStepSize step_size, JDWP::JdwpStepDepth step_depth,
Mathieu Chartiere401d142015-04-22 13:56:20 -070095 int stack_depth, ArtMethod* method)
Sebastien Hertz597c4f02015-01-26 17:37:14 +010096 : step_size_(step_size), step_depth_(step_depth),
97 stack_depth_(stack_depth), method_(method) {
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010098 }
99
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100100 JDWP::JdwpStepSize GetStepSize() const {
101 return step_size_;
102 }
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100103
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100104 JDWP::JdwpStepDepth GetStepDepth() const {
105 return step_depth_;
106 }
107
108 int GetStackDepth() const {
109 return stack_depth_;
110 }
111
Mathieu Chartiere401d142015-04-22 13:56:20 -0700112 ArtMethod* GetMethod() const {
113 return method_;
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100114 }
115
116 const std::set<uint32_t>& GetDexPcs() const {
117 return dex_pcs_;
118 }
119
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100120 void AddDexPc(uint32_t dex_pc);
121
122 bool ContainsDexPc(uint32_t dex_pc) const;
123
124 private:
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100125 // See JdwpStepSize and JdwpStepDepth for details.
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100126 const JDWP::JdwpStepSize step_size_;
127 const JDWP::JdwpStepDepth step_depth_;
128
129 // The stack depth when this single-step was initiated. This is used to support SD_OVER and SD_OUT
130 // single-step depth.
131 const int stack_depth_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100132
133 // The location this single-step was initiated from.
134 // A single-step is initiated in a suspended thread. We save here the current method and the
135 // set of DEX pcs associated to the source line number where the suspension occurred.
136 // This is used to support SD_INTO and SD_OVER single-step depths so we detect when a single-step
137 // causes the execution of an instruction in a different method or at a different line number.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700138 ArtMethod* method_;
139
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100140 std::set<uint32_t> dex_pcs_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100141
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100142 DISALLOW_COPY_AND_ASSIGN(SingleStepControl);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700143};
144
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200145// TODO rename to InstrumentationRequest.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700146class DeoptimizationRequest {
147 public:
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100148 enum Kind {
149 kNothing, // no action.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200150 kRegisterForEvent, // start listening for instrumentation event.
151 kUnregisterForEvent, // stop listening for instrumentation event.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100152 kFullDeoptimization, // deoptimize everything.
153 kFullUndeoptimization, // undeoptimize everything.
154 kSelectiveDeoptimization, // deoptimize one method.
155 kSelectiveUndeoptimization // undeoptimize one method.
156 };
157
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700158 DeoptimizationRequest() : kind_(kNothing), instrumentation_event_(0), method_(nullptr) {}
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100159
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700160 DeoptimizationRequest(const DeoptimizationRequest& other)
161 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
162 : kind_(other.kind_), instrumentation_event_(other.instrumentation_event_) {
163 // Create a new JNI global reference for the method.
164 SetMethod(other.Method());
165 }
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100166
Mathieu Chartiere401d142015-04-22 13:56:20 -0700167 ArtMethod* Method() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700168
Mathieu Chartiere401d142015-04-22 13:56:20 -0700169 void SetMethod(ArtMethod* m) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700170
171 // Name 'Kind()' would collide with the above enum name.
172 Kind GetKind() const {
173 return kind_;
174 }
175
176 void SetKind(Kind kind) {
177 kind_ = kind;
178 }
179
180 uint32_t InstrumentationEvent() const {
181 return instrumentation_event_;
182 }
183
184 void SetInstrumentationEvent(uint32_t instrumentation_event) {
185 instrumentation_event_ = instrumentation_event;
186 }
187
188 private:
189 Kind kind_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100190
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200191 // TODO we could use a union to hold the instrumentation_event and the method since they
192 // respectively have sense only for kRegisterForEvent/kUnregisterForEvent and
193 // kSelectiveDeoptimization/kSelectiveUndeoptimization.
194
195 // Event to start or stop listening to. Only for kRegisterForEvent and kUnregisterForEvent.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700196 uint32_t instrumentation_event_;
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200197
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100198 // Method for selective deoptimization.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700199 jmethodID method_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100200};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700201std::ostream& operator<<(std::ostream& os, const DeoptimizationRequest::Kind& rhs);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100202
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700203class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800204 public:
Mathieu Chartier4345c462014-06-27 10:20:14 -0700205 class TypeCache {
206 public:
207 // Returns a weak global for the input type. Deduplicates.
Brian Carlstrom306db812014-09-05 13:01:41 -0700208 jobject Add(mirror::Class* t) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_,
209 Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700210 // Clears the type cache and deletes all the weak global refs.
Brian Carlstrom306db812014-09-05 13:01:41 -0700211 void Clear() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_,
212 Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700213
214 private:
215 std::multimap<int32_t, jobject> objects_;
216 };
217
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700218 static void SetJdwpAllowed(bool allowed);
219
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100220 static void StartJdwp();
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700221 static void StopJdwp();
222
Elliott Hughes767a1472011-10-26 18:49:02 -0700223 // Invoked by the GC in case we need to keep DDMS informed.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700224 static void GcDidFinish() LOCKS_EXCLUDED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700225
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700226 // Return the DebugInvokeReq for the current thread.
227 static DebugInvokeReq* GetInvokeReq();
228
Elliott Hughes475fc232011-10-25 15:00:35 -0700229 static Thread* GetDebugThread();
230 static void ClearWaitForEventThread();
231
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700232 /*
233 * Enable/disable breakpoints and step modes. Used to provide a heads-up
234 * when the debugger attaches.
235 */
236 static void Connected();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100237 static void GoActive()
Brian Carlstrom306db812014-09-05 13:01:41 -0700238 LOCKS_EXCLUDED(Locks::breakpoint_lock_, Locks::deoptimization_lock_, Locks::mutator_lock_);
239 static void Disconnected() LOCKS_EXCLUDED(Locks::deoptimization_lock_, Locks::mutator_lock_);
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100240 static void Dispose() {
241 gDisposed = true;
242 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700243
Elliott Hughesc0f09332012-03-26 13:27:06 -0700244 // Returns true if we're actually debugging with a real debugger, false if it's
245 // just DDMS (or nothing at all).
Daniel Mihalyieb076692014-08-22 17:33:31 +0200246 static bool IsDebuggerActive() {
247 return gDebuggerActive;
248 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700249
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100250 // Configures JDWP with parsed command-line options.
251 static void ConfigureJdwp(const JDWP::JdwpOptions& jdwp_options);
252
Elliott Hughesc0f09332012-03-26 13:27:06 -0700253 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
254 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700255
Mathieu Chartierd8565452015-03-26 09:41:50 -0700256 // Returns true if a method has any breakpoints.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700257 static bool MethodHasAnyBreakpoints(ArtMethod* method)
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100258 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
259 LOCKS_EXCLUDED(Locks::breakpoint_lock_);
Mathieu Chartierd8565452015-03-26 09:41:50 -0700260
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100261 static bool IsDisposed() {
262 return gDisposed;
263 }
Elliott Hughes86964332012-02-15 19:37:42 -0800264
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700265 /*
266 * Time, in milliseconds, since the last debugger activity. Does not
267 * include DDMS activity. Returns -1 if there has been no activity.
268 * Returns 0 if we're in the middle of handling a debugger request.
269 */
270 static int64_t LastDebuggerActivity();
271
Sebastien Hertz253fa552014-10-14 17:27:15 +0200272 static void UndoDebuggerSuspensions()
273 LOCKS_EXCLUDED(Locks::thread_list_lock_,
274 Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700275
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700276 /*
277 * Class, Object, Array
278 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700279 static std::string GetClassName(JDWP::RefTypeId id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700280 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200281 static std::string GetClassName(mirror::Class* klass)
282 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700283 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId* class_object_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700284 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700285 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId* superclass_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700286 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700287 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700288 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700289 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700290 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800291 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700292 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700293 static void GetClassList(std::vector<JDWP::RefTypeId>* classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700294 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800295 static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700296 uint32_t* pStatus, std::string* pDescriptor)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700297 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700298 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>* ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700299 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800300 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
301 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersfc0e94b2013-09-23 23:51:32 -0700302 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700303 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700304 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string* source_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700305 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700306 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t* tag)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700307 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800308 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700309
Ian Rogersc0542af2014-09-03 16:16:56 -0700310 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int32_t* length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700311 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800312 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700313 JDWP::ExpandBuf* pReply)
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 SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700316 JDWP::Request* request)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700317 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700318
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200319 static JDWP::JdwpError CreateString(const std::string& str, JDWP::ObjectId* new_string_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700320 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200321 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId* new_object_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700322 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800323 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200324 JDWP::ObjectId* new_array_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700325 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700326
Sebastien Hertz6995c602014-09-09 12:10:13 +0200327 //
328 // Event filtering.
329 //
330 static bool MatchThread(JDWP::ObjectId expected_thread_id, Thread* event_thread)
331 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
332
333 static bool MatchLocation(const JDWP::JdwpLocation& expected_location,
334 const JDWP::EventLocation& event_location)
335 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
336
337 static bool MatchType(mirror::Class* event_class, JDWP::RefTypeId class_id)
338 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
339
340 static bool MatchField(JDWP::RefTypeId expected_type_id, JDWP::FieldId expected_field_id,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700341 ArtField* event_field)
Sebastien Hertz6995c602014-09-09 12:10:13 +0200342 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
343
344 static bool MatchInstance(JDWP::ObjectId expected_instance_id, mirror::Object* event_instance)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700345 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700346
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800347 //
348 // Monitors.
349 //
350 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
351 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
352 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700353 std::vector<JDWP::ObjectId>* monitors,
354 std::vector<uint32_t>* stack_depths)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100355 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800356 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100357 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700358 JDWP::ObjectId* contended_monitor)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100359 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800360 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
361
362 //
363 // Heap.
364 //
365 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
Ian Rogersc0542af2014-09-03 16:16:56 -0700366 std::vector<uint64_t>* counts)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800367 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800368 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700369 std::vector<JDWP::ObjectId>* instances)
Elliott Hughes3b78c942013-01-15 17:35:41 -0800370 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800371 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700372 std::vector<JDWP::ObjectId>* referring_objects)
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800373 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800374 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
375 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
376 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
377 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700378 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool* is_collected)
Elliott Hughes64f574f2013-02-20 14:57:12 -0800379 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
380 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
381 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800382
Elliott Hughes9777ba22013-01-17 09:04:19 -0800383 //
384 // Methods and fields.
385 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800386 static std::string GetMethodName(JDWP::MethodId method_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700387 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800388 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700389 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700390 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800391 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700392 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700393 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800394 static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700395 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700396 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800397 static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700398 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700399 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800400 static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700401 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700402 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800403 static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value,
404 JDWP::ExpandBuf* pReply)
405 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200406 static void OutputFieldValue(JDWP::FieldId field_id, const JValue* field_value,
407 JDWP::ExpandBuf* pReply)
408 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800409 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700410 std::vector<uint8_t>* bytecodes)
Elliott Hughes9777ba22013-01-17 09:04:19 -0800411 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700412
Elliott Hughesa96836a2013-01-17 12:27:49 -0800413 static std::string GetFieldName(JDWP::FieldId field_id)
414 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800415 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700416 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800417 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Brian Carlstromf69863b2013-07-17 21:53:13 -0700418 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800419 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700420 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700421 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800422 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700423 uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700424 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800425 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700426 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700427 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800428 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700429 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700430
Sebastien Hertzb0b0b492014-09-15 11:27:27 +0200431 static JDWP::JdwpError StringToUtf8(JDWP::ObjectId string_id, std::string* str)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700432 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800433 static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply)
434 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700435
436 /*
437 * Thread, ThreadGroup, Frame
438 */
Ian Rogersc0542af2014-09-03 16:16:56 -0700439 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string* name)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700440 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
441 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100442 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply)
Sebastien Hertza06430c2014-09-15 19:21:30 +0200443 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100444 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200445 static JDWP::JdwpError GetThreadGroupName(JDWP::ObjectId thread_group_id,
446 JDWP::ExpandBuf* pReply)
447 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
448 static JDWP::JdwpError GetThreadGroupParent(JDWP::ObjectId thread_group_id,
449 JDWP::ExpandBuf* pReply)
450 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
451 static JDWP::JdwpError GetThreadGroupChildren(JDWP::ObjectId thread_group_id,
452 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700453 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700454 static JDWP::ObjectId GetSystemThreadGroupId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700455 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700456
Jeff Hao920af3e2013-08-28 15:46:38 -0700457 static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100458 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id,
459 JDWP::JdwpThreadStatus* pThreadStatus,
460 JDWP::JdwpSuspendStatus* pSuspendStatus)
461 LOCKS_EXCLUDED(Locks::thread_list_lock_);
462 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id,
463 JDWP::ExpandBuf* pReply)
464 LOCKS_EXCLUDED(Locks::thread_list_lock_,
465 Locks::thread_suspend_count_lock_);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700466 // static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700467
Elliott Hughes026b1462012-06-28 20:43:49 -0700468 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700469 // returns all threads.
Sebastien Hertza06430c2014-09-15 19:21:30 +0200470 static void GetThreads(mirror::Object* thread_group, std::vector<JDWP::ObjectId>* thread_ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700471 LOCKS_EXCLUDED(Locks::thread_list_lock_)
472 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700473
Ian Rogersc0542af2014-09-03 16:16:56 -0700474 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t* result)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100475 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700476 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
477 size_t frame_count, JDWP::ExpandBuf* buf)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100478 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700479 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700480
Sebastien Hertz6995c602014-09-09 12:10:13 +0200481 static JDWP::ObjectId GetThreadSelfId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
482 static JDWP::ObjectId GetThreadId(Thread* thread) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
483
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700484 static void SuspendVM()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700485 LOCKS_EXCLUDED(Locks::thread_list_lock_,
486 Locks::thread_suspend_count_lock_);
Sebastien Hertz253fa552014-10-14 17:27:15 +0200487 static void ResumeVM()
488 LOCKS_EXCLUDED(Locks::thread_list_lock_,
489 Locks::thread_suspend_count_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800490 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700491 LOCKS_EXCLUDED(Locks::mutator_lock_,
492 Locks::thread_list_lock_,
493 Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700494
Elliott Hughes88d63092013-01-09 09:55:54 -0800495 static void ResumeThread(JDWP::ObjectId thread_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700496 LOCKS_EXCLUDED(Locks::thread_list_lock_,
497 Locks::thread_suspend_count_lock_)
498 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700499 static void SuspendSelf();
500
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700501 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
502 JDWP::ObjectId* result)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700503 LOCKS_EXCLUDED(Locks::thread_list_lock_,
504 Locks::thread_suspend_count_lock_)
505 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200506 static JDWP::JdwpError GetLocalValues(JDWP::Request* request, JDWP::ExpandBuf* pReply)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100507 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700508 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200509 static JDWP::JdwpError SetLocalValues(JDWP::Request* request)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100510 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700511 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700512
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100513 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id)
514 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughesf9501702013-01-11 11:22:27 -0800515
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700516 /*
517 * Debugger notification
518 */
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700519 enum EventFlag {
Elliott Hughes86964332012-02-15 19:37:42 -0800520 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700521 kSingleStep = 0x02,
522 kMethodEntry = 0x04,
523 kMethodExit = 0x08,
524 };
Mathieu Chartiere401d142015-04-22 13:56:20 -0700525 static void PostFieldAccessEvent(ArtMethod* m, int dex_pc, mirror::Object* this_object,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700526 ArtField* f)
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200527 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700528 static void PostFieldModificationEvent(ArtMethod* m, int dex_pc,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700529 mirror::Object* this_object, ArtField* f,
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200530 const JValue* field_value)
531 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000532 static void PostException(mirror::Throwable* exception)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700533 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700534 static void PostThreadStart(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700535 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700536 static void PostThreadDeath(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700537 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800538 static void PostClassPrepare(mirror::Class* c)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700539 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700540
Ian Rogers62d6c772013-02-27 08:32:07 -0800541 static void UpdateDebugger(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700542 ArtMethod* method, uint32_t new_dex_pc,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100543 int event_flags, const JValue* return_value)
jeffhao09bfc6a2012-12-11 18:11:43 -0800544 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700545 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800546
Sebastien Hertzf3928792014-11-17 19:00:37 +0100547 // Indicates whether we need deoptimization for debugging.
548 static bool RequiresDeoptimization();
549
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100550 // Records deoptimization request in the queue.
551 static void RequestDeoptimization(const DeoptimizationRequest& req)
Brian Carlstrom306db812014-09-05 13:01:41 -0700552 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100553 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
554
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100555 // Manage deoptimization after updating JDWP events list. Suspends all threads, processes each
556 // request and finally resumes all threads.
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100557 static void ManageDeoptimization()
Brian Carlstrom306db812014-09-05 13:01:41 -0700558 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100559 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
560
561 // Breakpoints.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100562 static void WatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
563 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700564 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100565 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
566 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700567 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100568
Daniel Mihalyieb076692014-08-22 17:33:31 +0200569 /*
570 * Forced interpreter checkers for single-step and continue support.
571 */
572
573 // Indicates whether we need to force the use of interpreter to invoke a method.
574 // This allows to single-step or continue into the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700575 static bool IsForcedInterpreterNeededForCalling(Thread* thread, ArtMethod* m)
Daniel Mihalyieb076692014-08-22 17:33:31 +0200576 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
577 if (!IsDebuggerActive()) {
578 return false;
579 }
580 return IsForcedInterpreterNeededForCallingImpl(thread, m);
581 }
582
583 // Indicates whether we need to force the use of interpreter entrypoint when calling a
584 // method through the resolution trampoline. This allows to single-step or continue into
585 // the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700586 static bool IsForcedInterpreterNeededForResolution(Thread* thread, ArtMethod* m)
Daniel Mihalyieb076692014-08-22 17:33:31 +0200587 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
588 if (!IsDebuggerActive()) {
589 return false;
590 }
591 return IsForcedInterpreterNeededForResolutionImpl(thread, m);
592 }
593
594 // Indicates whether we need to force the use of instrumentation entrypoint when calling
595 // a method through the resolution trampoline. This allows to deoptimize the stack for
596 // debugging when we returned from the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700597 static bool IsForcedInstrumentationNeededForResolution(Thread* thread, ArtMethod* m)
Daniel Mihalyieb076692014-08-22 17:33:31 +0200598 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
599 if (!IsDebuggerActive()) {
600 return false;
601 }
602 return IsForcedInstrumentationNeededForResolutionImpl(thread, m);
603 }
604
605 // Indicates whether we need to force the use of interpreter when returning from the
606 // interpreter into the runtime. This allows to deoptimize the stack and continue
607 // execution with interpreter for debugging.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700608 static bool IsForcedInterpreterNeededForUpcall(Thread* thread, ArtMethod* m)
Daniel Mihalyieb076692014-08-22 17:33:31 +0200609 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
610 if (!IsDebuggerActive()) {
611 return false;
612 }
613 return IsForcedInterpreterNeededForUpcallImpl(thread, m);
614 }
615
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100616 // Single-stepping.
Elliott Hughes88d63092013-01-09 09:55:54 -0800617 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700618 JDWP::JdwpStepDepth depth)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700619 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100620 static void UnconfigureStep(JDWP::ObjectId thread_id)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100621 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100622 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700623
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200624 /*
625 * Invoke support
626 */
627
628 // Called by the JDWP thread to prepare invocation in the event thread (suspended on an event).
629 // If the information sent by the debugger is incorrect, it will send a reply with the
630 // appropriate error code. Otherwise, it will attach a DebugInvokeReq object to the event thread
631 // and resume it (and possibly other threads depending on the invoke options).
632 // Unlike other commands, the JDWP thread will not send the reply to the debugger (see
633 // JdwpState::ProcessRequest). The reply will be sent by the event thread itself after method
634 // invocation completes (see FinishInvokeMethod). This is required to allow the JDWP thread to
635 // process incoming commands from the debugger while the invocation is still in progress in the
636 // event thread, especially if it gets suspended by a debug event occurring in another thread.
637 static JDWP::JdwpError PrepareInvokeMethod(uint32_t request_id, JDWP::ObjectId thread_id,
638 JDWP::ObjectId object_id, JDWP::RefTypeId class_id,
639 JDWP::MethodId method_id, uint32_t arg_count,
640 uint64_t arg_values[], JDWP::JdwpTag* arg_types,
641 uint32_t options)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700642 LOCKS_EXCLUDED(Locks::thread_list_lock_,
643 Locks::thread_suspend_count_lock_)
644 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200645
646 // Called by the event thread to execute a method prepared by the JDWP thread in the given
647 // DebugInvokeReq object. Once the invocation completes, the event thread attaches a reply
648 // to that DebugInvokeReq object so it can be sent to the debugger only when the event thread
649 // is ready to suspend (see FinishInvokeMethod).
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700650 static void ExecuteMethod(DebugInvokeReq* pReq);
651
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200652 // Called by the event thread to send the reply of the invoke (created in ExecuteMethod)
653 // before suspending itself. This is to ensure the thread is ready to suspend before the
654 // debugger receives the reply.
655 static void FinishInvokeMethod(DebugInvokeReq* pReq);
656
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700657 /*
658 * DDM support.
659 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700660 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700661 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100662 static void DdmSetThreadNotification(bool enable)
663 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700664 static bool DdmHandlePacket(JDWP::Request* request, uint8_t** pReplyBuf, int* pReplyLen);
Ian Rogersb726dcb2012-09-05 08:57:23 -0700665 static void DdmConnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
666 static void DdmDisconnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700667 static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700668 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700669 static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700670 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700671 static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700672 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700673
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700674 static void VisitRoots(RootVisitor* visitor)
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700675 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
676
Elliott Hughes545a0642011-11-08 19:10:03 -0800677 /*
678 * Recent allocation tracking support.
679 */
Ian Rogers844506b2014-09-12 19:59:33 -0700680 static void RecordAllocation(Thread* self, mirror::Class* type, size_t byte_count)
Brian Carlstrom306db812014-09-05 13:01:41 -0700681 LOCKS_EXCLUDED(Locks::alloc_tracker_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700682 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom306db812014-09-05 13:01:41 -0700683 static void SetAllocTrackingEnabled(bool enabled) LOCKS_EXCLUDED(Locks::alloc_tracker_lock_);
Ian Rogers719d1a32014-03-06 12:13:39 -0800684 static bool IsAllocTrackingEnabled() {
685 return recent_allocation_records_ != nullptr;
686 }
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100687 static jbyteArray GetRecentAllocations()
Brian Carlstrom306db812014-09-05 13:01:41 -0700688 LOCKS_EXCLUDED(Locks::alloc_tracker_lock_)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100689 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom306db812014-09-05 13:01:41 -0700690 static size_t HeadIndex() EXCLUSIVE_LOCKS_REQUIRED(Locks::alloc_tracker_lock_);
691 static void DumpRecentAllocations() LOCKS_EXCLUDED(Locks::alloc_tracker_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800692
Elliott Hughes767a1472011-10-26 18:49:02 -0700693 enum HpifWhen {
694 HPIF_WHEN_NEVER = 0,
695 HPIF_WHEN_NOW = 1,
696 HPIF_WHEN_NEXT_GC = 2,
697 HPIF_WHEN_EVERY_GC = 3
698 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700699 static int DdmHandleHpifChunk(HpifWhen when)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700700 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700701
702 enum HpsgWhen {
703 HPSG_WHEN_NEVER = 0,
704 HPSG_WHEN_EVERY_GC = 1,
705 };
706 enum HpsgWhat {
707 HPSG_WHAT_MERGED_OBJECTS = 0,
708 HPSG_WHAT_DISTINCT_OBJECTS = 1,
709 };
710 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
711
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700712 static void DdmSendHeapInfo(HpifWhen reason)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700713 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700714 static void DdmSendHeapSegments(bool native)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700715 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800716
Sebastien Hertz6995c602014-09-09 12:10:13 +0200717 static ObjectRegistry* GetObjectRegistry() {
718 return gRegistry;
719 }
720
721 static JDWP::JdwpTag TagFromObject(const ScopedObjectAccessUnchecked& soa, mirror::Object* o)
722 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
723
724 static JDWP::JdwpTypeTag GetTypeTag(mirror::Class* klass)
725 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
726
Mathieu Chartierc7853442015-03-27 14:35:38 -0700727 static JDWP::FieldId ToFieldId(const ArtField* f)
Sebastien Hertz6995c602014-09-09 12:10:13 +0200728 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
729
Mathieu Chartiere401d142015-04-22 13:56:20 -0700730 static void SetJdwpLocation(JDWP::JdwpLocation* location, ArtMethod* m, uint32_t dex_pc)
Sebastien Hertz6995c602014-09-09 12:10:13 +0200731 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
732
Mathieu Chartierad466ad2015-01-08 16:28:08 -0800733 static JDWP::JdwpState* GetJdwpState();
734
Sebastien Hertz9d6bf692015-04-10 12:12:33 +0200735 static uint32_t GetInstrumentationEvents() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
736 return instrumentation_events_;
737 }
738
Elliott Hughes545a0642011-11-08 19:10:03 -0800739 private:
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200740 static void ExecuteMethodWithoutPendingException(ScopedObjectAccess& soa, DebugInvokeReq* pReq)
741 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
742
743 static void BuildInvokeReply(JDWP::ExpandBuf* pReply, uint32_t request_id,
744 JDWP::JdwpTag result_tag, uint64_t result_value,
745 JDWP::ObjectId exception)
746 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
747
Sebastien Hertz8009f392014-09-01 17:07:11 +0200748 static JDWP::JdwpError GetLocalValue(const StackVisitor& visitor,
749 ScopedObjectAccessUnchecked& soa, int slot,
750 JDWP::JdwpTag tag, uint8_t* buf, size_t width)
751 LOCKS_EXCLUDED(Locks::thread_list_lock_)
752 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
753 static JDWP::JdwpError SetLocalValue(StackVisitor& visitor, int slot, JDWP::JdwpTag tag,
754 uint64_t value, size_t width)
755 LOCKS_EXCLUDED(Locks::thread_list_lock_)
756 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
757
Brian Carlstrom2d888622013-07-18 17:02:00 -0700758 static void DdmBroadcast(bool connect) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700759 static void PostThreadStartOrStop(Thread*, uint32_t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700760 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800761
Mathieu Chartiere401d142015-04-22 13:56:20 -0700762 static void PostLocationEvent(ArtMethod* method, int pcOffset,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100763 mirror::Object* thisPtr, int eventFlags,
764 const JValue* return_value)
765 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
766
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100767 static void ProcessDeoptimizationRequest(const DeoptimizationRequest& request)
768 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_);
769
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100770 static void RequestDeoptimizationLocked(const DeoptimizationRequest& req)
Brian Carlstrom306db812014-09-05 13:01:41 -0700771 EXCLUSIVE_LOCKS_REQUIRED(Locks::deoptimization_lock_)
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100772 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
773
Mathieu Chartiere401d142015-04-22 13:56:20 -0700774 static bool IsForcedInterpreterNeededForCallingImpl(Thread* thread, ArtMethod* m)
Daniel Mihalyieb076692014-08-22 17:33:31 +0200775 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
776
Mathieu Chartiere401d142015-04-22 13:56:20 -0700777 static bool IsForcedInterpreterNeededForResolutionImpl(Thread* thread, ArtMethod* m)
Daniel Mihalyieb076692014-08-22 17:33:31 +0200778 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
779
Mathieu Chartiere401d142015-04-22 13:56:20 -0700780 static bool IsForcedInstrumentationNeededForResolutionImpl(Thread* thread, ArtMethod* m)
Daniel Mihalyieb076692014-08-22 17:33:31 +0200781 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
782
Mathieu Chartiere401d142015-04-22 13:56:20 -0700783 static bool IsForcedInterpreterNeededForUpcallImpl(Thread* thread, ArtMethod* m)
Daniel Mihalyieb076692014-08-22 17:33:31 +0200784 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
785
Brian Carlstrom306db812014-09-05 13:01:41 -0700786 static AllocRecord* recent_allocation_records_ PT_GUARDED_BY(Locks::alloc_tracker_lock_);
787 static size_t alloc_record_max_ GUARDED_BY(Locks::alloc_tracker_lock_);
788 static size_t alloc_record_head_ GUARDED_BY(Locks::alloc_tracker_lock_);
789 static size_t alloc_record_count_ GUARDED_BY(Locks::alloc_tracker_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100790
Daniel Mihalyieb076692014-08-22 17:33:31 +0200791 // Indicates whether the debugger is making requests.
792 static bool gDebuggerActive;
793
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100794 // Indicates whether we should drop the JDWP connection because the runtime stops or the
795 // debugger called VirtualMachine.Dispose.
796 static bool gDisposed;
797
Daniel Mihalyieb076692014-08-22 17:33:31 +0200798 // The registry mapping objects to JDWP ids.
Sebastien Hertz6995c602014-09-09 12:10:13 +0200799 static ObjectRegistry* gRegistry;
800
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100801 // Deoptimization requests to be processed each time the event list is updated. This is used when
802 // registering and unregistering events so we do not deoptimize while holding the event list
803 // lock.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200804 // TODO rename to instrumentation_requests.
Brian Carlstrom306db812014-09-05 13:01:41 -0700805 static std::vector<DeoptimizationRequest> deoptimization_requests_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100806
807 // Count the number of events requiring full deoptimization. When the counter is > 0, everything
808 // is deoptimized, otherwise everything is undeoptimized.
809 // Note: we fully deoptimize on the first event only (when the counter is set to 1). We fully
810 // undeoptimize when the last event is unregistered (when the counter is set to 0).
Brian Carlstrom306db812014-09-05 13:01:41 -0700811 static size_t full_deoptimization_event_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100812
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200813 static size_t* GetReferenceCounterForEvent(uint32_t instrumentation_event);
814
Mathieu Chartier4345c462014-06-27 10:20:14 -0700815 // Weak global type cache, TODO improve this.
Brian Carlstrom306db812014-09-05 13:01:41 -0700816 static TypeCache type_cache_ GUARDED_BY(Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700817
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200818 // Instrumentation event reference counters.
819 // TODO we could use an array instead of having all these dedicated counters. Instrumentation
820 // events are bits of a mask so we could convert them to array index.
Brian Carlstrom306db812014-09-05 13:01:41 -0700821 static size_t dex_pc_change_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
822 static size_t method_enter_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
823 static size_t method_exit_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
824 static size_t field_read_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
825 static size_t field_write_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
826 static size_t exception_catch_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200827 static uint32_t instrumentation_events_ GUARDED_BY(Locks::mutator_lock_);
828
Brian Carlstrom306db812014-09-05 13:01:41 -0700829 friend class AllocRecord; // For type_cache_ with proper annotalysis.
Ian Rogers719d1a32014-03-06 12:13:39 -0800830 DISALLOW_COPY_AND_ASSIGN(Dbg);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700831};
832
833#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800834 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700835
836} // namespace art
837
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700838#endif // ART_RUNTIME_DEBUGGER_H_