blob: c23b1b88f2f4892c29fe50b5985f0ec549a2ccc1 [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
Man Cao8c2ff642015-05-27 17:25:30 -070026#include <list>
Mathieu Chartier4345c462014-06-27 10:20:14 -070027#include <map>
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010028#include <set>
Elliott Hughes3bb81562011-10-21 18:52:59 -070029#include <string>
Sebastien Hertz4d25df32014-03-21 17:44:46 +010030#include <vector>
Elliott Hughes3bb81562011-10-21 18:52:59 -070031
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -080032#include "gc_root.h"
Elliott Hughes872d4ec2011-10-21 17:07:15 -070033#include "jdwp/jdwp.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080034#include "jni.h"
35#include "jvalue.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
Mathieu Chartierc7853442015-03-27 14:35:38 -070044class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070045class ArtMethod;
Sebastien Hertz6995c602014-09-09 12:10:13 +020046class ObjectRegistry;
47class ScopedObjectAccessUnchecked;
Sebastien Hertz8009f392014-09-01 17:07:11 +020048class StackVisitor;
Ian Rogers1b09b092012-08-20 15:35:52 -070049class Thread;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070050
51/*
52 * Invoke-during-breakpoint support.
53 */
54struct DebugInvokeReq {
Sebastien Hertz1558b572015-02-25 15:05:59 +010055 DebugInvokeReq(mirror::Object* invoke_receiver, mirror::Class* invoke_class,
Mathieu Chartiere401d142015-04-22 13:56:20 -070056 ArtMethod* invoke_method, uint32_t invoke_options,
Sebastien Hertz1558b572015-02-25 15:05:59 +010057 uint64_t* args, uint32_t args_count)
58 : receiver(invoke_receiver), klass(invoke_class), method(invoke_method),
59 arg_count(args_count), arg_values(args), options(invoke_options),
60 error(JDWP::ERR_NONE), result_tag(JDWP::JT_VOID), result_value(0), exception(0),
Sebastien Hertzd38667a2013-11-25 15:43:54 +010061 lock("a DebugInvokeReq lock", kBreakpointInvokeLock),
62 cond("a DebugInvokeReq condition variable", lock) {
Elliott Hughes475fc232011-10-25 15:00:35 -070063 }
64
Elliott Hughes872d4ec2011-10-21 17:07:15 -070065 /* request */
Sebastien Hertz1558b572015-02-25 15:05:59 +010066 GcRoot<mirror::Object> receiver; // not used for ClassType.InvokeMethod
67 GcRoot<mirror::Class> klass;
Mathieu Chartiere401d142015-04-22 13:56:20 -070068 ArtMethod* method;
Sebastien Hertz1558b572015-02-25 15:05:59 +010069 const uint32_t arg_count;
Mathieu Chartier2cebb242015-04-21 16:50:40 -070070 uint64_t* const arg_values; // will be null if arg_count_ == 0
Sebastien Hertz1558b572015-02-25 15:05:59 +010071 const uint32_t options;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070072
73 /* result */
Elliott Hughes475fc232011-10-25 15:00:35 -070074 JDWP::JdwpError error;
Elliott Hughesd07986f2011-12-06 18:27:45 -080075 JDWP::JdwpTag result_tag;
Sebastien Hertz1558b572015-02-25 15:05:59 +010076 uint64_t result_value; // either a primitive value or an ObjectId
Elliott Hughes475fc232011-10-25 15:00:35 -070077 JDWP::ObjectId exception;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070078
79 /* condition variable to wait on while the method executes */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010080 Mutex lock DEFAULT_MUTEX_ACQUIRED_AFTER;
81 ConditionVariable cond GUARDED_BY(lock);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010082
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -070083 void VisitRoots(RootVisitor* visitor, const RootInfo& root_info)
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -070084 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
85
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010086 private:
87 DISALLOW_COPY_AND_ASSIGN(DebugInvokeReq);
88};
89
90// Thread local data-structure that holds fields for controlling single-stepping.
Sebastien Hertz597c4f02015-01-26 17:37:14 +010091class SingleStepControl {
92 public:
93 SingleStepControl(JDWP::JdwpStepSize step_size, JDWP::JdwpStepDepth step_depth,
Mathieu Chartiere401d142015-04-22 13:56:20 -070094 int stack_depth, ArtMethod* method)
Sebastien Hertz597c4f02015-01-26 17:37:14 +010095 : step_size_(step_size), step_depth_(step_depth),
96 stack_depth_(stack_depth), method_(method) {
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010097 }
98
Sebastien Hertz597c4f02015-01-26 17:37:14 +010099 JDWP::JdwpStepSize GetStepSize() const {
100 return step_size_;
101 }
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100102
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100103 JDWP::JdwpStepDepth GetStepDepth() const {
104 return step_depth_;
105 }
106
107 int GetStackDepth() const {
108 return stack_depth_;
109 }
110
Mathieu Chartiere401d142015-04-22 13:56:20 -0700111 ArtMethod* GetMethod() const {
112 return method_;
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100113 }
114
115 const std::set<uint32_t>& GetDexPcs() const {
116 return dex_pcs_;
117 }
118
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100119 void AddDexPc(uint32_t dex_pc);
120
121 bool ContainsDexPc(uint32_t dex_pc) const;
122
123 private:
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100124 // See JdwpStepSize and JdwpStepDepth for details.
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100125 const JDWP::JdwpStepSize step_size_;
126 const JDWP::JdwpStepDepth step_depth_;
127
128 // The stack depth when this single-step was initiated. This is used to support SD_OVER and SD_OUT
129 // single-step depth.
130 const int stack_depth_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100131
132 // The location this single-step was initiated from.
133 // A single-step is initiated in a suspended thread. We save here the current method and the
134 // set of DEX pcs associated to the source line number where the suspension occurred.
135 // This is used to support SD_INTO and SD_OVER single-step depths so we detect when a single-step
136 // causes the execution of an instruction in a different method or at a different line number.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700137 ArtMethod* method_;
138
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100139 std::set<uint32_t> dex_pcs_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100140
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100141 DISALLOW_COPY_AND_ASSIGN(SingleStepControl);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700142};
143
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200144// TODO rename to InstrumentationRequest.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700145class DeoptimizationRequest {
146 public:
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100147 enum Kind {
148 kNothing, // no action.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200149 kRegisterForEvent, // start listening for instrumentation event.
150 kUnregisterForEvent, // stop listening for instrumentation event.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100151 kFullDeoptimization, // deoptimize everything.
152 kFullUndeoptimization, // undeoptimize everything.
153 kSelectiveDeoptimization, // deoptimize one method.
154 kSelectiveUndeoptimization // undeoptimize one method.
155 };
156
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700157 DeoptimizationRequest() : kind_(kNothing), instrumentation_event_(0), method_(nullptr) {}
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100158
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700159 DeoptimizationRequest(const DeoptimizationRequest& other)
160 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
161 : kind_(other.kind_), instrumentation_event_(other.instrumentation_event_) {
162 // Create a new JNI global reference for the method.
163 SetMethod(other.Method());
164 }
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100165
Mathieu Chartiere401d142015-04-22 13:56:20 -0700166 ArtMethod* Method() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700167
Mathieu Chartiere401d142015-04-22 13:56:20 -0700168 void SetMethod(ArtMethod* m) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700169
170 // Name 'Kind()' would collide with the above enum name.
171 Kind GetKind() const {
172 return kind_;
173 }
174
175 void SetKind(Kind kind) {
176 kind_ = kind;
177 }
178
179 uint32_t InstrumentationEvent() const {
180 return instrumentation_event_;
181 }
182
183 void SetInstrumentationEvent(uint32_t instrumentation_event) {
184 instrumentation_event_ = instrumentation_event;
185 }
186
187 private:
188 Kind kind_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100189
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200190 // TODO we could use a union to hold the instrumentation_event and the method since they
191 // respectively have sense only for kRegisterForEvent/kUnregisterForEvent and
192 // kSelectiveDeoptimization/kSelectiveUndeoptimization.
193
194 // Event to start or stop listening to. Only for kRegisterForEvent and kUnregisterForEvent.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700195 uint32_t instrumentation_event_;
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200196
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100197 // Method for selective deoptimization.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700198 jmethodID method_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100199};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700200std::ostream& operator<<(std::ostream& os, const DeoptimizationRequest::Kind& rhs);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100201
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700202class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800203 public:
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700204 static void SetJdwpAllowed(bool allowed);
205
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100206 static void StartJdwp();
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700207 static void StopJdwp();
208
Elliott Hughes767a1472011-10-26 18:49:02 -0700209 // Invoked by the GC in case we need to keep DDMS informed.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700210 static void GcDidFinish() LOCKS_EXCLUDED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700211
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700212 // Return the DebugInvokeReq for the current thread.
213 static DebugInvokeReq* GetInvokeReq();
214
Elliott Hughes475fc232011-10-25 15:00:35 -0700215 static Thread* GetDebugThread();
216 static void ClearWaitForEventThread();
217
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700218 /*
219 * Enable/disable breakpoints and step modes. Used to provide a heads-up
220 * when the debugger attaches.
221 */
222 static void Connected();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100223 static void GoActive()
Brian Carlstrom306db812014-09-05 13:01:41 -0700224 LOCKS_EXCLUDED(Locks::breakpoint_lock_, Locks::deoptimization_lock_, Locks::mutator_lock_);
225 static void Disconnected() LOCKS_EXCLUDED(Locks::deoptimization_lock_, Locks::mutator_lock_);
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100226 static void Dispose() {
227 gDisposed = true;
228 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700229
Elliott Hughesc0f09332012-03-26 13:27:06 -0700230 // Returns true if we're actually debugging with a real debugger, false if it's
231 // just DDMS (or nothing at all).
Daniel Mihalyieb076692014-08-22 17:33:31 +0200232 static bool IsDebuggerActive() {
233 return gDebuggerActive;
234 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700235
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100236 // Configures JDWP with parsed command-line options.
237 static void ConfigureJdwp(const JDWP::JdwpOptions& jdwp_options);
238
Elliott Hughesc0f09332012-03-26 13:27:06 -0700239 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
240 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700241
Mathieu Chartierd8565452015-03-26 09:41:50 -0700242 // Returns true if a method has any breakpoints.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700243 static bool MethodHasAnyBreakpoints(ArtMethod* method)
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100244 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
245 LOCKS_EXCLUDED(Locks::breakpoint_lock_);
Mathieu Chartierd8565452015-03-26 09:41:50 -0700246
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100247 static bool IsDisposed() {
248 return gDisposed;
249 }
Elliott Hughes86964332012-02-15 19:37:42 -0800250
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700251 /*
252 * Time, in milliseconds, since the last debugger activity. Does not
253 * include DDMS activity. Returns -1 if there has been no activity.
254 * Returns 0 if we're in the middle of handling a debugger request.
255 */
256 static int64_t LastDebuggerActivity();
257
Sebastien Hertz253fa552014-10-14 17:27:15 +0200258 static void UndoDebuggerSuspensions()
259 LOCKS_EXCLUDED(Locks::thread_list_lock_,
260 Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700261
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700262 /*
263 * Class, Object, Array
264 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700265 static std::string GetClassName(JDWP::RefTypeId id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700266 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200267 static std::string GetClassName(mirror::Class* klass)
268 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700269 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId* class_object_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700270 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700271 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId* superclass_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700272 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700273 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700274 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700275 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700276 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800277 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700278 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700279 static void GetClassList(std::vector<JDWP::RefTypeId>* classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700280 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800281 static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700282 uint32_t* pStatus, std::string* pDescriptor)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700283 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700284 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>* ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700285 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800286 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
287 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersfc0e94b2013-09-23 23:51:32 -0700288 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700289 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700290 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string* source_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700291 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700292 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t* tag)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700293 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800294 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700295
Ian Rogersc0542af2014-09-03 16:16:56 -0700296 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int32_t* length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700297 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800298 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700299 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700300 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800301 static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700302 JDWP::Request* request)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700303 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700304
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200305 static JDWP::JdwpError CreateString(const std::string& str, JDWP::ObjectId* new_string_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700306 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200307 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId* new_object_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700308 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800309 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200310 JDWP::ObjectId* new_array_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700311 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700312
Sebastien Hertz6995c602014-09-09 12:10:13 +0200313 //
314 // Event filtering.
315 //
316 static bool MatchThread(JDWP::ObjectId expected_thread_id, Thread* event_thread)
317 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
318
319 static bool MatchLocation(const JDWP::JdwpLocation& expected_location,
320 const JDWP::EventLocation& event_location)
321 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
322
323 static bool MatchType(mirror::Class* event_class, JDWP::RefTypeId class_id)
324 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
325
326 static bool MatchField(JDWP::RefTypeId expected_type_id, JDWP::FieldId expected_field_id,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700327 ArtField* event_field)
Sebastien Hertz6995c602014-09-09 12:10:13 +0200328 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
329
330 static bool MatchInstance(JDWP::ObjectId expected_instance_id, mirror::Object* event_instance)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700331 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700332
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800333 //
334 // Monitors.
335 //
336 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
337 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
338 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700339 std::vector<JDWP::ObjectId>* monitors,
340 std::vector<uint32_t>* stack_depths)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100341 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800342 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100343 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700344 JDWP::ObjectId* contended_monitor)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100345 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800346 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
347
348 //
349 // Heap.
350 //
351 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
Ian Rogersc0542af2014-09-03 16:16:56 -0700352 std::vector<uint64_t>* counts)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800353 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800354 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700355 std::vector<JDWP::ObjectId>* instances)
Elliott Hughes3b78c942013-01-15 17:35:41 -0800356 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800357 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700358 std::vector<JDWP::ObjectId>* referring_objects)
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800359 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800360 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
361 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
362 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
363 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700364 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool* is_collected)
Elliott Hughes64f574f2013-02-20 14:57:12 -0800365 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
366 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
367 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800368
Elliott Hughes9777ba22013-01-17 09:04:19 -0800369 //
370 // Methods and fields.
371 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800372 static std::string GetMethodName(JDWP::MethodId method_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700373 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800374 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700375 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700376 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800377 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700378 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700379 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800380 static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700381 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700382 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800383 static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700384 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700385 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800386 static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700387 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700388 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800389 static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value,
390 JDWP::ExpandBuf* pReply)
391 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200392 static void OutputFieldValue(JDWP::FieldId field_id, const JValue* field_value,
393 JDWP::ExpandBuf* pReply)
394 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800395 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700396 std::vector<uint8_t>* bytecodes)
Elliott Hughes9777ba22013-01-17 09:04:19 -0800397 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700398
Elliott Hughesa96836a2013-01-17 12:27:49 -0800399 static std::string GetFieldName(JDWP::FieldId field_id)
400 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800401 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700402 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800403 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Brian Carlstromf69863b2013-07-17 21:53:13 -0700404 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800405 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700406 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700407 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800408 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700409 uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700410 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800411 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700412 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700413 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800414 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700415 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700416
Sebastien Hertzb0b0b492014-09-15 11:27:27 +0200417 static JDWP::JdwpError StringToUtf8(JDWP::ObjectId string_id, std::string* str)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700418 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800419 static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply)
420 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700421
422 /*
423 * Thread, ThreadGroup, Frame
424 */
Ian Rogersc0542af2014-09-03 16:16:56 -0700425 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string* name)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700426 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
427 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100428 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply)
Sebastien Hertza06430c2014-09-15 19:21:30 +0200429 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100430 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200431 static JDWP::JdwpError GetThreadGroupName(JDWP::ObjectId thread_group_id,
432 JDWP::ExpandBuf* pReply)
433 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
434 static JDWP::JdwpError GetThreadGroupParent(JDWP::ObjectId thread_group_id,
435 JDWP::ExpandBuf* pReply)
436 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
437 static JDWP::JdwpError GetThreadGroupChildren(JDWP::ObjectId thread_group_id,
438 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700439 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700440 static JDWP::ObjectId GetSystemThreadGroupId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700441 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700442
Jeff Hao920af3e2013-08-28 15:46:38 -0700443 static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100444 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id,
445 JDWP::JdwpThreadStatus* pThreadStatus,
446 JDWP::JdwpSuspendStatus* pSuspendStatus)
447 LOCKS_EXCLUDED(Locks::thread_list_lock_);
448 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id,
449 JDWP::ExpandBuf* pReply)
450 LOCKS_EXCLUDED(Locks::thread_list_lock_,
451 Locks::thread_suspend_count_lock_);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700452 // static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700453
Elliott Hughes026b1462012-06-28 20:43:49 -0700454 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700455 // returns all threads.
Sebastien Hertza06430c2014-09-15 19:21:30 +0200456 static void GetThreads(mirror::Object* thread_group, std::vector<JDWP::ObjectId>* thread_ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700457 LOCKS_EXCLUDED(Locks::thread_list_lock_)
458 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700459
Ian Rogersc0542af2014-09-03 16:16:56 -0700460 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t* result)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100461 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700462 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
463 size_t frame_count, JDWP::ExpandBuf* buf)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100464 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700465 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700466
Sebastien Hertz6995c602014-09-09 12:10:13 +0200467 static JDWP::ObjectId GetThreadSelfId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
468 static JDWP::ObjectId GetThreadId(Thread* thread) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
469
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700470 static void SuspendVM()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700471 LOCKS_EXCLUDED(Locks::thread_list_lock_,
472 Locks::thread_suspend_count_lock_);
Sebastien Hertz253fa552014-10-14 17:27:15 +0200473 static void ResumeVM()
474 LOCKS_EXCLUDED(Locks::thread_list_lock_,
475 Locks::thread_suspend_count_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800476 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700477 LOCKS_EXCLUDED(Locks::mutator_lock_,
478 Locks::thread_list_lock_,
479 Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700480
Elliott Hughes88d63092013-01-09 09:55:54 -0800481 static void ResumeThread(JDWP::ObjectId thread_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700482 LOCKS_EXCLUDED(Locks::thread_list_lock_,
483 Locks::thread_suspend_count_lock_)
484 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700485 static void SuspendSelf();
486
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700487 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
488 JDWP::ObjectId* result)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700489 LOCKS_EXCLUDED(Locks::thread_list_lock_,
490 Locks::thread_suspend_count_lock_)
491 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200492 static JDWP::JdwpError GetLocalValues(JDWP::Request* request, JDWP::ExpandBuf* pReply)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100493 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700494 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200495 static JDWP::JdwpError SetLocalValues(JDWP::Request* request)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100496 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700497 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700498
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100499 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id)
500 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughesf9501702013-01-11 11:22:27 -0800501
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700502 /*
503 * Debugger notification
504 */
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700505 enum EventFlag {
Elliott Hughes86964332012-02-15 19:37:42 -0800506 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700507 kSingleStep = 0x02,
508 kMethodEntry = 0x04,
509 kMethodExit = 0x08,
510 };
Mathieu Chartiere401d142015-04-22 13:56:20 -0700511 static void PostFieldAccessEvent(ArtMethod* m, int dex_pc, mirror::Object* this_object,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700512 ArtField* f)
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200513 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700514 static void PostFieldModificationEvent(ArtMethod* m, int dex_pc,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700515 mirror::Object* this_object, ArtField* f,
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200516 const JValue* field_value)
517 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000518 static void PostException(mirror::Throwable* exception)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700519 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700520 static void PostThreadStart(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700521 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700522 static void PostThreadDeath(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700523 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800524 static void PostClassPrepare(mirror::Class* c)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700525 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700526
Ian Rogers62d6c772013-02-27 08:32:07 -0800527 static void UpdateDebugger(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700528 ArtMethod* method, uint32_t new_dex_pc,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100529 int event_flags, const JValue* return_value)
jeffhao09bfc6a2012-12-11 18:11:43 -0800530 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700531 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800532
Sebastien Hertzf3928792014-11-17 19:00:37 +0100533 // Indicates whether we need deoptimization for debugging.
534 static bool RequiresDeoptimization();
535
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100536 // Records deoptimization request in the queue.
537 static void RequestDeoptimization(const DeoptimizationRequest& req)
Brian Carlstrom306db812014-09-05 13:01:41 -0700538 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100539 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
540
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100541 // Manage deoptimization after updating JDWP events list. Suspends all threads, processes each
542 // request and finally resumes all threads.
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100543 static void ManageDeoptimization()
Brian Carlstrom306db812014-09-05 13:01:41 -0700544 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100545 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
546
547 // Breakpoints.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100548 static void WatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
549 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700550 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100551 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
552 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700553 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100554
Daniel Mihalyieb076692014-08-22 17:33:31 +0200555 /*
556 * Forced interpreter checkers for single-step and continue support.
557 */
558
559 // Indicates whether we need to force the use of interpreter to invoke a method.
560 // This allows to single-step or continue into the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700561 static bool IsForcedInterpreterNeededForCalling(Thread* thread, ArtMethod* m)
Daniel Mihalyieb076692014-08-22 17:33:31 +0200562 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
563 if (!IsDebuggerActive()) {
564 return false;
565 }
566 return IsForcedInterpreterNeededForCallingImpl(thread, m);
567 }
568
569 // Indicates whether we need to force the use of interpreter entrypoint when calling a
570 // method through the resolution trampoline. This allows to single-step or continue into
571 // the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700572 static bool IsForcedInterpreterNeededForResolution(Thread* thread, ArtMethod* m)
Daniel Mihalyieb076692014-08-22 17:33:31 +0200573 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
574 if (!IsDebuggerActive()) {
575 return false;
576 }
577 return IsForcedInterpreterNeededForResolutionImpl(thread, m);
578 }
579
580 // Indicates whether we need to force the use of instrumentation entrypoint when calling
581 // a method through the resolution trampoline. This allows to deoptimize the stack for
582 // debugging when we returned from the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700583 static bool IsForcedInstrumentationNeededForResolution(Thread* thread, ArtMethod* m)
Daniel Mihalyieb076692014-08-22 17:33:31 +0200584 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
585 if (!IsDebuggerActive()) {
586 return false;
587 }
588 return IsForcedInstrumentationNeededForResolutionImpl(thread, m);
589 }
590
591 // Indicates whether we need to force the use of interpreter when returning from the
592 // interpreter into the runtime. This allows to deoptimize the stack and continue
593 // execution with interpreter for debugging.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700594 static bool IsForcedInterpreterNeededForUpcall(Thread* thread, ArtMethod* m)
Daniel Mihalyieb076692014-08-22 17:33:31 +0200595 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
596 if (!IsDebuggerActive()) {
597 return false;
598 }
599 return IsForcedInterpreterNeededForUpcallImpl(thread, m);
600 }
601
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100602 // Single-stepping.
Elliott Hughes88d63092013-01-09 09:55:54 -0800603 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700604 JDWP::JdwpStepDepth depth)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700605 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100606 static void UnconfigureStep(JDWP::ObjectId thread_id)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100607 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100608 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700609
Sebastien Hertz1558b572015-02-25 15:05:59 +0100610 // Invoke support for commands ClassType.InvokeMethod, ClassType.NewInstance and
611 // ObjectReference.InvokeMethod.
Elliott Hughes88d63092013-01-09 09:55:54 -0800612 static JDWP::JdwpError InvokeMethod(JDWP::ObjectId thread_id, JDWP::ObjectId object_id,
613 JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700614 uint32_t arg_count, uint64_t* arg_values,
615 JDWP::JdwpTag* arg_types, uint32_t options,
616 JDWP::JdwpTag* pResultTag, uint64_t* pResultValue,
617 JDWP::ObjectId* pExceptObj)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700618 LOCKS_EXCLUDED(Locks::thread_list_lock_,
619 Locks::thread_suspend_count_lock_)
620 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700621 static void ExecuteMethod(DebugInvokeReq* pReq);
622
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700623 /*
624 * DDM support.
625 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700626 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700627 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100628 static void DdmSetThreadNotification(bool enable)
629 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700630 static bool DdmHandlePacket(JDWP::Request* request, uint8_t** pReplyBuf, int* pReplyLen);
Ian Rogersb726dcb2012-09-05 08:57:23 -0700631 static void DdmConnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
632 static void DdmDisconnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700633 static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700634 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700635 static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700636 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700637 static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700638 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700639
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700640 static void VisitRoots(RootVisitor* visitor)
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700641 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
642
Elliott Hughes545a0642011-11-08 19:10:03 -0800643 /*
Man Cao8c2ff642015-05-27 17:25:30 -0700644 * Allocation tracking support.
Elliott Hughes545a0642011-11-08 19:10:03 -0800645 */
Brian Carlstrom306db812014-09-05 13:01:41 -0700646 static void SetAllocTrackingEnabled(bool enabled) LOCKS_EXCLUDED(Locks::alloc_tracker_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100647 static jbyteArray GetRecentAllocations()
Brian Carlstrom306db812014-09-05 13:01:41 -0700648 LOCKS_EXCLUDED(Locks::alloc_tracker_lock_)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100649 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom306db812014-09-05 13:01:41 -0700650 static void DumpRecentAllocations() LOCKS_EXCLUDED(Locks::alloc_tracker_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800651
Elliott Hughes767a1472011-10-26 18:49:02 -0700652 enum HpifWhen {
653 HPIF_WHEN_NEVER = 0,
654 HPIF_WHEN_NOW = 1,
655 HPIF_WHEN_NEXT_GC = 2,
656 HPIF_WHEN_EVERY_GC = 3
657 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700658 static int DdmHandleHpifChunk(HpifWhen when)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700659 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700660
661 enum HpsgWhen {
662 HPSG_WHEN_NEVER = 0,
663 HPSG_WHEN_EVERY_GC = 1,
664 };
665 enum HpsgWhat {
666 HPSG_WHAT_MERGED_OBJECTS = 0,
667 HPSG_WHAT_DISTINCT_OBJECTS = 1,
668 };
669 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
670
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700671 static void DdmSendHeapInfo(HpifWhen reason)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700672 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700673 static void DdmSendHeapSegments(bool native)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700674 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800675
Sebastien Hertz6995c602014-09-09 12:10:13 +0200676 static ObjectRegistry* GetObjectRegistry() {
677 return gRegistry;
678 }
679
680 static JDWP::JdwpTag TagFromObject(const ScopedObjectAccessUnchecked& soa, mirror::Object* o)
681 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
682
683 static JDWP::JdwpTypeTag GetTypeTag(mirror::Class* klass)
684 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
685
Mathieu Chartierc7853442015-03-27 14:35:38 -0700686 static JDWP::FieldId ToFieldId(const ArtField* f)
Sebastien Hertz6995c602014-09-09 12:10:13 +0200687 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
688
Mathieu Chartiere401d142015-04-22 13:56:20 -0700689 static void SetJdwpLocation(JDWP::JdwpLocation* location, ArtMethod* m, uint32_t dex_pc)
Sebastien Hertz6995c602014-09-09 12:10:13 +0200690 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
691
Mathieu Chartierad466ad2015-01-08 16:28:08 -0800692 static JDWP::JdwpState* GetJdwpState();
693
Sebastien Hertz9d6bf692015-04-10 12:12:33 +0200694 static uint32_t GetInstrumentationEvents() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
695 return instrumentation_events_;
696 }
697
Elliott Hughes545a0642011-11-08 19:10:03 -0800698 private:
Sebastien Hertz8009f392014-09-01 17:07:11 +0200699 static JDWP::JdwpError GetLocalValue(const StackVisitor& visitor,
700 ScopedObjectAccessUnchecked& soa, int slot,
701 JDWP::JdwpTag tag, uint8_t* buf, size_t width)
702 LOCKS_EXCLUDED(Locks::thread_list_lock_)
703 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
704 static JDWP::JdwpError SetLocalValue(StackVisitor& visitor, int slot, JDWP::JdwpTag tag,
705 uint64_t value, size_t width)
706 LOCKS_EXCLUDED(Locks::thread_list_lock_)
707 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
708
Brian Carlstrom2d888622013-07-18 17:02:00 -0700709 static void DdmBroadcast(bool connect) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700710 static void PostThreadStartOrStop(Thread*, uint32_t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700711 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800712
Mathieu Chartiere401d142015-04-22 13:56:20 -0700713 static void PostLocationEvent(ArtMethod* method, int pcOffset,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100714 mirror::Object* thisPtr, int eventFlags,
715 const JValue* return_value)
716 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
717
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100718 static void ProcessDeoptimizationRequest(const DeoptimizationRequest& request)
719 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_);
720
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100721 static void RequestDeoptimizationLocked(const DeoptimizationRequest& req)
Brian Carlstrom306db812014-09-05 13:01:41 -0700722 EXCLUSIVE_LOCKS_REQUIRED(Locks::deoptimization_lock_)
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100723 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
724
Mathieu Chartiere401d142015-04-22 13:56:20 -0700725 static bool IsForcedInterpreterNeededForCallingImpl(Thread* thread, ArtMethod* m)
Daniel Mihalyieb076692014-08-22 17:33:31 +0200726 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
727
Mathieu Chartiere401d142015-04-22 13:56:20 -0700728 static bool IsForcedInterpreterNeededForResolutionImpl(Thread* thread, ArtMethod* m)
Daniel Mihalyieb076692014-08-22 17:33:31 +0200729 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
730
Mathieu Chartiere401d142015-04-22 13:56:20 -0700731 static bool IsForcedInstrumentationNeededForResolutionImpl(Thread* thread, ArtMethod* m)
Daniel Mihalyieb076692014-08-22 17:33:31 +0200732 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
733
Mathieu Chartiere401d142015-04-22 13:56:20 -0700734 static bool IsForcedInterpreterNeededForUpcallImpl(Thread* thread, ArtMethod* m)
Daniel Mihalyieb076692014-08-22 17:33:31 +0200735 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
736
Daniel Mihalyieb076692014-08-22 17:33:31 +0200737 // Indicates whether the debugger is making requests.
738 static bool gDebuggerActive;
739
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100740 // Indicates whether we should drop the JDWP connection because the runtime stops or the
741 // debugger called VirtualMachine.Dispose.
742 static bool gDisposed;
743
Daniel Mihalyieb076692014-08-22 17:33:31 +0200744 // The registry mapping objects to JDWP ids.
Sebastien Hertz6995c602014-09-09 12:10:13 +0200745 static ObjectRegistry* gRegistry;
746
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100747 // Deoptimization requests to be processed each time the event list is updated. This is used when
748 // registering and unregistering events so we do not deoptimize while holding the event list
749 // lock.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200750 // TODO rename to instrumentation_requests.
Brian Carlstrom306db812014-09-05 13:01:41 -0700751 static std::vector<DeoptimizationRequest> deoptimization_requests_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100752
753 // Count the number of events requiring full deoptimization. When the counter is > 0, everything
754 // is deoptimized, otherwise everything is undeoptimized.
755 // Note: we fully deoptimize on the first event only (when the counter is set to 1). We fully
756 // undeoptimize when the last event is unregistered (when the counter is set to 0).
Brian Carlstrom306db812014-09-05 13:01:41 -0700757 static size_t full_deoptimization_event_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100758
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200759 static size_t* GetReferenceCounterForEvent(uint32_t instrumentation_event);
760
761 // Instrumentation event reference counters.
762 // TODO we could use an array instead of having all these dedicated counters. Instrumentation
763 // events are bits of a mask so we could convert them to array index.
Brian Carlstrom306db812014-09-05 13:01:41 -0700764 static size_t dex_pc_change_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
765 static size_t method_enter_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
766 static size_t method_exit_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
767 static size_t field_read_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
768 static size_t field_write_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
769 static size_t exception_catch_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200770 static uint32_t instrumentation_events_ GUARDED_BY(Locks::mutator_lock_);
771
Ian Rogers719d1a32014-03-06 12:13:39 -0800772 DISALLOW_COPY_AND_ASSIGN(Dbg);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700773};
774
775#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800776 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700777
778} // namespace art
779
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700780#endif // ART_RUNTIME_DEBUGGER_H_