blob: 18126b1eed13981f328d87b35bf1b2da8023a94f [file] [log] [blame]
Elliott Hughes872d4ec2011-10-21 17:07:15 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * Dalvik-specific side of debugger support. (The JDWP code is intended to
19 * be relatively generic.)
20 */
Brian Carlstromfc0e3212013-07-17 14:40:12 -070021#ifndef ART_RUNTIME_DEBUGGER_H_
22#define ART_RUNTIME_DEBUGGER_H_
Elliott Hughes872d4ec2011-10-21 17:07:15 -070023
24#include <pthread.h>
25
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010026#include <set>
Elliott Hughes3bb81562011-10-21 18:52:59 -070027#include <string>
Sebastien Hertz4d25df32014-03-21 17:44:46 +010028#include <vector>
Elliott Hughes3bb81562011-10-21 18:52:59 -070029
Andreas Gampe0f01b582017-01-18 15:22:37 -080030#include "class_linker.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070031#include "gc_root.h"
Andreas Gampe0f01b582017-01-18 15:22:37 -080032#include "handle.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"
Mathieu Chartier3398c782016-09-30 10:27:43 -070036#include "obj_ptr.h"
Alex Light21611932017-09-26 13:07:39 -070037#include "runtime_callbacks.h"
Mingyao Yang99170c62015-07-06 11:10:37 -070038#include "thread.h"
Jeff Hao920af3e2013-08-28 15:46:38 -070039#include "thread_state.h"
Elliott Hughes872d4ec2011-10-21 17:07:15 -070040
41namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080042namespace mirror {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080043class Class;
44class Object;
45class Throwable;
46} // namespace mirror
Mathieu Chartierc7853442015-03-27 14:35:38 -070047class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070048class ArtMethod;
Sebastien Hertz6995c602014-09-09 12:10:13 +020049class ObjectRegistry;
Sebastien Hertzcbc50642015-06-01 17:33:12 +020050class ScopedObjectAccess;
Sebastien Hertz6995c602014-09-09 12:10:13 +020051class ScopedObjectAccessUnchecked;
Sebastien Hertz8009f392014-09-01 17:07:11 +020052class StackVisitor;
Ian Rogers1b09b092012-08-20 15:35:52 -070053class Thread;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070054
Alex Light21611932017-09-26 13:07:39 -070055struct DebuggerActiveMethodInspectionCallback : public MethodInspectionCallback {
56 bool IsMethodBeingInspected(ArtMethod* m ATTRIBUTE_UNUSED)
57 OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
58};
59
60
Elliott Hughes872d4ec2011-10-21 17:07:15 -070061/*
62 * Invoke-during-breakpoint support.
63 */
64struct DebugInvokeReq {
Sebastien Hertzcbc50642015-06-01 17:33:12 +020065 DebugInvokeReq(uint32_t invoke_request_id, JDWP::ObjectId invoke_thread_id,
66 mirror::Object* invoke_receiver, mirror::Class* invoke_class,
Mathieu Chartiere401d142015-04-22 13:56:20 -070067 ArtMethod* invoke_method, uint32_t invoke_options,
Sebastien Hertzcbc50642015-06-01 17:33:12 +020068 uint64_t args[], uint32_t args_count)
69 : request_id(invoke_request_id), thread_id(invoke_thread_id), receiver(invoke_receiver),
70 klass(invoke_class), method(invoke_method), arg_count(args_count), arg_values(args),
71 options(invoke_options), reply(JDWP::expandBufAlloc()) {
Elliott Hughes475fc232011-10-25 15:00:35 -070072 }
73
Sebastien Hertzcbc50642015-06-01 17:33:12 +020074 ~DebugInvokeReq() {
75 JDWP::expandBufFree(reply);
76 }
77
78 // Request
79 const uint32_t request_id;
80 const JDWP::ObjectId thread_id;
81 GcRoot<mirror::Object> receiver; // not used for ClassType.InvokeMethod.
Sebastien Hertz1558b572015-02-25 15:05:59 +010082 GcRoot<mirror::Class> klass;
Sebastien Hertzcbc50642015-06-01 17:33:12 +020083 ArtMethod* const method;
Sebastien Hertz1558b572015-02-25 15:05:59 +010084 const uint32_t arg_count;
Sebastien Hertzcbc50642015-06-01 17:33:12 +020085 std::unique_ptr<uint64_t[]> arg_values; // will be null if arg_count_ == 0. We take ownership
86 // of this array so we must delete it upon destruction.
Sebastien Hertz1558b572015-02-25 15:05:59 +010087 const uint32_t options;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070088
Sebastien Hertzcbc50642015-06-01 17:33:12 +020089 // Reply
90 JDWP::ExpandBuf* const reply;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010091
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -070092 void VisitRoots(RootVisitor* visitor, const RootInfo& root_info)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070093 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -070094
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010095 private:
96 DISALLOW_COPY_AND_ASSIGN(DebugInvokeReq);
97};
98
99// Thread local data-structure that holds fields for controlling single-stepping.
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100100class SingleStepControl {
101 public:
102 SingleStepControl(JDWP::JdwpStepSize step_size, JDWP::JdwpStepDepth step_depth,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700103 int stack_depth, ArtMethod* method)
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100104 : step_size_(step_size), step_depth_(step_depth),
105 stack_depth_(stack_depth), method_(method) {
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100106 }
107
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100108 JDWP::JdwpStepSize GetStepSize() const {
109 return step_size_;
110 }
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100111
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100112 JDWP::JdwpStepDepth GetStepDepth() const {
113 return step_depth_;
114 }
115
116 int GetStackDepth() const {
117 return stack_depth_;
118 }
119
Mathieu Chartiere401d142015-04-22 13:56:20 -0700120 ArtMethod* GetMethod() const {
121 return method_;
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100122 }
123
124 const std::set<uint32_t>& GetDexPcs() const {
125 return dex_pcs_;
126 }
127
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100128 void AddDexPc(uint32_t dex_pc);
129
130 bool ContainsDexPc(uint32_t dex_pc) const;
131
132 private:
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100133 // See JdwpStepSize and JdwpStepDepth for details.
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100134 const JDWP::JdwpStepSize step_size_;
135 const JDWP::JdwpStepDepth step_depth_;
136
137 // The stack depth when this single-step was initiated. This is used to support SD_OVER and SD_OUT
138 // single-step depth.
139 const int stack_depth_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100140
141 // The location this single-step was initiated from.
142 // A single-step is initiated in a suspended thread. We save here the current method and the
143 // set of DEX pcs associated to the source line number where the suspension occurred.
144 // This is used to support SD_INTO and SD_OVER single-step depths so we detect when a single-step
145 // causes the execution of an instruction in a different method or at a different line number.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700146 ArtMethod* method_;
147
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100148 std::set<uint32_t> dex_pcs_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100149
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100150 DISALLOW_COPY_AND_ASSIGN(SingleStepControl);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700151};
152
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200153// TODO rename to InstrumentationRequest.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700154class DeoptimizationRequest {
155 public:
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100156 enum Kind {
157 kNothing, // no action.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200158 kRegisterForEvent, // start listening for instrumentation event.
159 kUnregisterForEvent, // stop listening for instrumentation event.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100160 kFullDeoptimization, // deoptimize everything.
161 kFullUndeoptimization, // undeoptimize everything.
162 kSelectiveDeoptimization, // deoptimize one method.
163 kSelectiveUndeoptimization // undeoptimize one method.
164 };
165
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700166 DeoptimizationRequest() : kind_(kNothing), instrumentation_event_(0), method_(nullptr) {}
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100167
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700168 DeoptimizationRequest(const DeoptimizationRequest& other)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700169 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700170 : kind_(other.kind_), instrumentation_event_(other.instrumentation_event_) {
171 // Create a new JNI global reference for the method.
172 SetMethod(other.Method());
173 }
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100174
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700175 ArtMethod* Method() const REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700176
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700177 void SetMethod(ArtMethod* m) REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700178
179 // Name 'Kind()' would collide with the above enum name.
180 Kind GetKind() const {
181 return kind_;
182 }
183
184 void SetKind(Kind kind) {
185 kind_ = kind;
186 }
187
188 uint32_t InstrumentationEvent() const {
189 return instrumentation_event_;
190 }
191
192 void SetInstrumentationEvent(uint32_t instrumentation_event) {
193 instrumentation_event_ = instrumentation_event;
194 }
195
196 private:
197 Kind kind_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100198
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200199 // TODO we could use a union to hold the instrumentation_event and the method since they
200 // respectively have sense only for kRegisterForEvent/kUnregisterForEvent and
201 // kSelectiveDeoptimization/kSelectiveUndeoptimization.
202
203 // Event to start or stop listening to. Only for kRegisterForEvent and kUnregisterForEvent.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700204 uint32_t instrumentation_event_;
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200205
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100206 // Method for selective deoptimization.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700207 jmethodID method_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100208};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700209std::ostream& operator<<(std::ostream& os, const DeoptimizationRequest::Kind& rhs);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100210
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700211class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800212 public:
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700213 static void SetJdwpAllowed(bool allowed);
Leonard Mosescueb842212016-10-06 17:26:36 -0700214 static bool IsJdwpAllowed();
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700215
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100216 static void StartJdwp();
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700217 static void StopJdwp();
218
Elliott Hughes767a1472011-10-26 18:49:02 -0700219 // Invoked by the GC in case we need to keep DDMS informed.
Mathieu Chartier90443472015-07-16 20:32:27 -0700220 static void GcDidFinish() REQUIRES(!Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700221
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700222 // Return the DebugInvokeReq for the current thread.
223 static DebugInvokeReq* GetInvokeReq();
224
Elliott Hughes475fc232011-10-25 15:00:35 -0700225 static Thread* GetDebugThread();
226 static void ClearWaitForEventThread();
227
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700228 /*
229 * Enable/disable breakpoints and step modes. Used to provide a heads-up
230 * when the debugger attaches.
231 */
232 static void Connected();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100233 static void GoActive()
Mathieu Chartier90443472015-07-16 20:32:27 -0700234 REQUIRES(!Locks::breakpoint_lock_, !Locks::deoptimization_lock_, !Locks::mutator_lock_);
235 static void Disconnected() REQUIRES(!Locks::deoptimization_lock_, !Locks::mutator_lock_);
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100236 static void Dispose() {
237 gDisposed = true;
238 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700239
Elliott Hughesc0f09332012-03-26 13:27:06 -0700240 // Returns true if we're actually debugging with a real debugger, false if it's
241 // just DDMS (or nothing at all).
Daniel Mihalyieb076692014-08-22 17:33:31 +0200242 static bool IsDebuggerActive() {
243 return gDebuggerActive;
244 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700245
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100246 // Configures JDWP with parsed command-line options.
247 static void ConfigureJdwp(const JDWP::JdwpOptions& jdwp_options);
248
Elliott Hughesc0f09332012-03-26 13:27:06 -0700249 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
250 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700251
Mathieu Chartierd8565452015-03-26 09:41:50 -0700252 // Returns true if a method has any breakpoints.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700253 static bool MethodHasAnyBreakpoints(ArtMethod* method)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700254 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::breakpoint_lock_);
Mathieu Chartierd8565452015-03-26 09:41:50 -0700255
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100256 static bool IsDisposed() {
257 return gDisposed;
258 }
Elliott Hughes86964332012-02-15 19:37:42 -0800259
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700260 /*
261 * Time, in milliseconds, since the last debugger activity. Does not
262 * include DDMS activity. Returns -1 if there has been no activity.
263 * Returns 0 if we're in the middle of handling a debugger request.
264 */
265 static int64_t LastDebuggerActivity();
266
Sebastien Hertz253fa552014-10-14 17:27:15 +0200267 static void UndoDebuggerSuspensions()
Mathieu Chartier90443472015-07-16 20:32:27 -0700268 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700269
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700270 /*
271 * Class, Object, Array
272 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700273 static std::string GetClassName(JDWP::RefTypeId id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700274 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200275 static std::string GetClassName(mirror::Class* klass)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700276 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700277 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId* class_object_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700278 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700279 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId* superclass_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700280 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700281 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700282 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700283 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700284 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800285 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700286 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700287 static void GetClassList(std::vector<JDWP::RefTypeId>* classes)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700288 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800289 static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700290 uint32_t* pStatus, std::string* pDescriptor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700291 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700292 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>* ids)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700293 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800294 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700295 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersfc0e94b2013-09-23 23:51:32 -0700296 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700297 REQUIRES_SHARED(Locks::mutator_lock_);
Orion Hodson77d8a1c2017-04-24 14:53:19 +0100298 static JDWP::JdwpError GetSourceDebugExtension(JDWP::RefTypeId ref_type_id,
299 std::string* extension_data)
300 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700301 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string* source_file)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700302 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700303 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t* tag)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700304 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800305 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700306
Ian Rogersc0542af2014-09-03 16:16:56 -0700307 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int32_t* length)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700308 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800309 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700310 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700311 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800312 static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700313 JDWP::Request* request)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700314 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700315
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200316 static JDWP::JdwpError CreateString(const std::string& str, JDWP::ObjectId* new_string_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700317 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200318 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId* new_object_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700319 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800320 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200321 JDWP::ObjectId* new_array_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700322 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700323
Sebastien Hertz6995c602014-09-09 12:10:13 +0200324 //
325 // Event filtering.
326 //
327 static bool MatchThread(JDWP::ObjectId expected_thread_id, Thread* event_thread)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700328 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200329
330 static bool MatchLocation(const JDWP::JdwpLocation& expected_location,
331 const JDWP::EventLocation& event_location)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700332 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200333
Mathieu Chartier3398c782016-09-30 10:27:43 -0700334 static bool MatchType(ObjPtr<mirror::Class> event_class, JDWP::RefTypeId class_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700335 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200336
337 static bool MatchField(JDWP::RefTypeId expected_type_id, JDWP::FieldId expected_field_id,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700338 ArtField* event_field)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700339 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200340
341 static bool MatchInstance(JDWP::ObjectId expected_instance_id, mirror::Object* event_instance)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700342 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700343
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800344 //
345 // Monitors.
346 //
347 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700348 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800349 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700350 std::vector<JDWP::ObjectId>* monitors,
351 std::vector<uint32_t>* stack_depths)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700352 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100353 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700354 JDWP::ObjectId* contended_monitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700355 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800356
357 //
358 // Heap.
359 //
360 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
Ian Rogersc0542af2014-09-03 16:16:56 -0700361 std::vector<uint64_t>* counts)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700362 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800363 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700364 std::vector<JDWP::ObjectId>* instances)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700365 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800366 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700367 std::vector<JDWP::ObjectId>* referring_objects)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700368 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800369 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700370 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800371 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700372 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700373 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool* is_collected)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700374 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800375 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700376 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800377
Elliott Hughes9777ba22013-01-17 09:04:19 -0800378 //
379 // Methods and fields.
380 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800381 static std::string GetMethodName(JDWP::MethodId method_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700382 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Light73376312017-04-06 10:10:51 -0700383 static bool IsMethodObsolete(JDWP::MethodId method_id)
384 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800385 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700386 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700387 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800388 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700389 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700390 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800391 static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700392 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700393 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800394 static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700395 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700396 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800397 static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700398 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700399 REQUIRES_SHARED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800400 static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value,
401 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700402 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200403 static void OutputFieldValue(JDWP::FieldId field_id, const JValue* field_value,
404 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700405 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800406 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700407 std::vector<uint8_t>* bytecodes)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700408 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700409
Elliott Hughesa96836a2013-01-17 12:27:49 -0800410 static std::string GetFieldName(JDWP::FieldId field_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700411 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800412 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700413 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800414 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700415 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800416 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700417 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700418 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800419 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700420 uint64_t value, int width)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700421 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800422 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700423 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700424 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800425 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700426 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700427
Sebastien Hertzb0b0b492014-09-15 11:27:27 +0200428 static JDWP::JdwpError StringToUtf8(JDWP::ObjectId string_id, std::string* str)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700429 REQUIRES_SHARED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800430 static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700431 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700432
433 /*
434 * Thread, ThreadGroup, Frame
435 */
Ian Rogersc0542af2014-09-03 16:16:56 -0700436 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string* name)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700437 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100438 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700439 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::thread_list_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200440 static JDWP::JdwpError GetThreadGroupName(JDWP::ObjectId thread_group_id,
441 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700442 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200443 static JDWP::JdwpError GetThreadGroupParent(JDWP::ObjectId thread_group_id,
444 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700445 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200446 static JDWP::JdwpError GetThreadGroupChildren(JDWP::ObjectId thread_group_id,
447 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700448 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700449 static JDWP::ObjectId GetSystemThreadGroupId()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700450 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700451
Jeff Hao920af3e2013-08-28 15:46:38 -0700452 static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100453 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id,
454 JDWP::JdwpThreadStatus* pThreadStatus,
455 JDWP::JdwpSuspendStatus* pSuspendStatus)
Mathieu Chartier90443472015-07-16 20:32:27 -0700456 REQUIRES(!Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100457 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id,
458 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700459 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700460 // static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700461
Elliott Hughes026b1462012-06-28 20:43:49 -0700462 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700463 // returns all threads.
Sebastien Hertza06430c2014-09-15 19:21:30 +0200464 static void GetThreads(mirror::Object* thread_group, std::vector<JDWP::ObjectId>* thread_ids)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700465 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700466
Ian Rogersc0542af2014-09-03 16:16:56 -0700467 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t* result)
Mathieu Chartier90443472015-07-16 20:32:27 -0700468 REQUIRES(!Locks::thread_list_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700469 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
470 size_t frame_count, JDWP::ExpandBuf* buf)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700471 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700472
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700473 static JDWP::ObjectId GetThreadSelfId() REQUIRES_SHARED(Locks::mutator_lock_);
474 static JDWP::ObjectId GetThreadId(Thread* thread) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200475
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700476 static void SuspendVM()
Mathieu Chartier90443472015-07-16 20:32:27 -0700477 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Sebastien Hertz253fa552014-10-14 17:27:15 +0200478 static void ResumeVM()
Mathieu Chartier90443472015-07-16 20:32:27 -0700479 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800480 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Mathieu Chartier90443472015-07-16 20:32:27 -0700481 REQUIRES(!Locks::mutator_lock_, !Locks::thread_list_lock_,
482 !Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700483
Elliott Hughes88d63092013-01-09 09:55:54 -0800484 static void ResumeThread(JDWP::ObjectId thread_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700485 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700486 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700487 static void SuspendSelf();
488
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700489 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
490 JDWP::ObjectId* result)
Mathieu Chartier90443472015-07-16 20:32:27 -0700491 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700492 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200493 static JDWP::JdwpError GetLocalValues(JDWP::Request* request, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700494 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200495 static JDWP::JdwpError SetLocalValues(JDWP::Request* request)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700496 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700497
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100498 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700499 REQUIRES(!Locks::thread_list_lock_);
Elliott Hughesf9501702013-01-11 11:22:27 -0800500
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700501 /*
502 * Debugger notification
503 */
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700504 enum EventFlag {
Elliott Hughes86964332012-02-15 19:37:42 -0800505 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700506 kSingleStep = 0x02,
507 kMethodEntry = 0x04,
508 kMethodExit = 0x08,
509 };
Mathieu Chartiere401d142015-04-22 13:56:20 -0700510 static void PostFieldAccessEvent(ArtMethod* m, int dex_pc, mirror::Object* this_object,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700511 ArtField* f)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700512 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700513 static void PostFieldModificationEvent(ArtMethod* m, int dex_pc,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700514 mirror::Object* this_object, ArtField* f,
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200515 const JValue* field_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700516 REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000517 static void PostException(mirror::Throwable* exception)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700518 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700519
Ian Rogers62d6c772013-02-27 08:32:07 -0800520 static void UpdateDebugger(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700521 ArtMethod* method, uint32_t new_dex_pc,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100522 int event_flags, const JValue* return_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700523 REQUIRES(!Locks::breakpoint_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800524
Sebastien Hertzf3928792014-11-17 19:00:37 +0100525 // Indicates whether we need deoptimization for debugging.
526 static bool RequiresDeoptimization();
527
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100528 // Records deoptimization request in the queue.
529 static void RequestDeoptimization(const DeoptimizationRequest& req)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700530 REQUIRES(!Locks::deoptimization_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100531
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100532 // Manage deoptimization after updating JDWP events list. Suspends all threads, processes each
533 // request and finally resumes all threads.
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100534 static void ManageDeoptimization()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700535 REQUIRES(!Locks::deoptimization_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100536
537 // Breakpoints.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100538 static void WatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700539 REQUIRES(!Locks::breakpoint_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100540 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700541 REQUIRES(!Locks::breakpoint_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100542
Daniel Mihalyieb076692014-08-22 17:33:31 +0200543 /*
544 * Forced interpreter checkers for single-step and continue support.
545 */
546
547 // Indicates whether we need to force the use of interpreter to invoke a method.
548 // This allows to single-step or continue into the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700549 static bool IsForcedInterpreterNeededForCalling(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700550 REQUIRES_SHARED(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200551 if (!IsDebuggerActive()) {
552 return false;
553 }
554 return IsForcedInterpreterNeededForCallingImpl(thread, m);
555 }
556
557 // Indicates whether we need to force the use of interpreter entrypoint when calling a
558 // method through the resolution trampoline. This allows to single-step or continue into
559 // the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700560 static bool IsForcedInterpreterNeededForResolution(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700561 REQUIRES_SHARED(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200562 if (!IsDebuggerActive()) {
563 return false;
564 }
565 return IsForcedInterpreterNeededForResolutionImpl(thread, m);
566 }
567
568 // Indicates whether we need to force the use of instrumentation entrypoint when calling
569 // a method through the resolution trampoline. This allows to deoptimize the stack for
570 // debugging when we returned from the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700571 static bool IsForcedInstrumentationNeededForResolution(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700572 REQUIRES_SHARED(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200573 if (!IsDebuggerActive()) {
574 return false;
575 }
576 return IsForcedInstrumentationNeededForResolutionImpl(thread, m);
577 }
578
579 // Indicates whether we need to force the use of interpreter when returning from the
580 // interpreter into the runtime. This allows to deoptimize the stack and continue
581 // execution with interpreter for debugging.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700582 static bool IsForcedInterpreterNeededForUpcall(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700583 REQUIRES_SHARED(Locks::mutator_lock_) {
Mingyao Yang99170c62015-07-06 11:10:37 -0700584 if (!IsDebuggerActive() && !thread->HasDebuggerShadowFrames()) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200585 return false;
586 }
587 return IsForcedInterpreterNeededForUpcallImpl(thread, m);
588 }
589
Sebastien Hertz520633b2015-09-08 17:03:36 +0200590 // Indicates whether we need to force the use of interpreter when handling an
591 // exception. This allows to deoptimize the stack and continue execution with
592 // the interpreter.
593 // Note: the interpreter will start by handling the exception when executing
594 // the deoptimized frames.
595 static bool IsForcedInterpreterNeededForException(Thread* thread)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700596 REQUIRES_SHARED(Locks::mutator_lock_) {
Mingyao Yang99170c62015-07-06 11:10:37 -0700597 if (!IsDebuggerActive() && !thread->HasDebuggerShadowFrames()) {
Sebastien Hertz520633b2015-09-08 17:03:36 +0200598 return false;
599 }
600 return IsForcedInterpreterNeededForExceptionImpl(thread);
601 }
602
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100603 // Single-stepping.
Elliott Hughes88d63092013-01-09 09:55:54 -0800604 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700605 JDWP::JdwpStepDepth depth)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700606 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100607 static void UnconfigureStep(JDWP::ObjectId thread_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700608 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700609
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200610 /*
611 * Invoke support
612 */
613
614 // Called by the JDWP thread to prepare invocation in the event thread (suspended on an event).
615 // If the information sent by the debugger is incorrect, it will send a reply with the
616 // appropriate error code. Otherwise, it will attach a DebugInvokeReq object to the event thread
617 // and resume it (and possibly other threads depending on the invoke options).
618 // Unlike other commands, the JDWP thread will not send the reply to the debugger (see
619 // JdwpState::ProcessRequest). The reply will be sent by the event thread itself after method
620 // invocation completes (see FinishInvokeMethod). This is required to allow the JDWP thread to
621 // process incoming commands from the debugger while the invocation is still in progress in the
622 // event thread, especially if it gets suspended by a debug event occurring in another thread.
623 static JDWP::JdwpError PrepareInvokeMethod(uint32_t request_id, JDWP::ObjectId thread_id,
624 JDWP::ObjectId object_id, JDWP::RefTypeId class_id,
625 JDWP::MethodId method_id, uint32_t arg_count,
626 uint64_t arg_values[], JDWP::JdwpTag* arg_types,
627 uint32_t options)
Mathieu Chartier90443472015-07-16 20:32:27 -0700628 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700629 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200630
631 // Called by the event thread to execute a method prepared by the JDWP thread in the given
632 // DebugInvokeReq object. Once the invocation completes, the event thread attaches a reply
633 // to that DebugInvokeReq object so it can be sent to the debugger only when the event thread
634 // is ready to suspend (see FinishInvokeMethod).
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700635 static void ExecuteMethod(DebugInvokeReq* pReq);
636
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200637 // Called by the event thread to send the reply of the invoke (created in ExecuteMethod)
638 // before suspending itself. This is to ensure the thread is ready to suspend before the
639 // debugger receives the reply.
640 static void FinishInvokeMethod(DebugInvokeReq* pReq);
641
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700642 /*
643 * DDM support.
644 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700645 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700646 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100647 static void DdmSetThreadNotification(bool enable)
Mathieu Chartier90443472015-07-16 20:32:27 -0700648 REQUIRES(!Locks::thread_list_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700649 static bool DdmHandlePacket(JDWP::Request* request, uint8_t** pReplyBuf, int* pReplyLen);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700650 static void DdmConnected() REQUIRES_SHARED(Locks::mutator_lock_);
651 static void DdmDisconnected() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700652 static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700653 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700654 static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700655 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700656 static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700657 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700658
Mathieu Chartiera6b1ead2015-10-06 10:32:38 -0700659 // Visit breakpoint roots, used to prevent unloading of methods with breakpoints.
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700660 static void VisitRoots(RootVisitor* visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700661 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700662
Elliott Hughes545a0642011-11-08 19:10:03 -0800663 /*
Man Cao8c2ff642015-05-27 17:25:30 -0700664 * Allocation tracking support.
Elliott Hughes545a0642011-11-08 19:10:03 -0800665 */
Mathieu Chartier90443472015-07-16 20:32:27 -0700666 static void SetAllocTrackingEnabled(bool enabled) REQUIRES(!Locks::alloc_tracker_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100667 static jbyteArray GetRecentAllocations()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700668 REQUIRES(!Locks::alloc_tracker_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier90443472015-07-16 20:32:27 -0700669 static void DumpRecentAllocations() REQUIRES(!Locks::alloc_tracker_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800670
Elliott Hughes767a1472011-10-26 18:49:02 -0700671 enum HpifWhen {
672 HPIF_WHEN_NEVER = 0,
673 HPIF_WHEN_NOW = 1,
674 HPIF_WHEN_NEXT_GC = 2,
675 HPIF_WHEN_EVERY_GC = 3
676 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700677 static int DdmHandleHpifChunk(HpifWhen when)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700678 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700679
680 enum HpsgWhen {
681 HPSG_WHEN_NEVER = 0,
682 HPSG_WHEN_EVERY_GC = 1,
683 };
684 enum HpsgWhat {
685 HPSG_WHAT_MERGED_OBJECTS = 0,
686 HPSG_WHAT_DISTINCT_OBJECTS = 1,
687 };
688 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
689
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700690 static void DdmSendHeapInfo(HpifWhen reason)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700691 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700692 static void DdmSendHeapSegments(bool native)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700693 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800694
Sebastien Hertz6995c602014-09-09 12:10:13 +0200695 static ObjectRegistry* GetObjectRegistry() {
696 return gRegistry;
697 }
698
699 static JDWP::JdwpTag TagFromObject(const ScopedObjectAccessUnchecked& soa, mirror::Object* o)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700700 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200701
Mathieu Chartier3398c782016-09-30 10:27:43 -0700702 static JDWP::JdwpTypeTag GetTypeTag(ObjPtr<mirror::Class> klass)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700703 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200704
Mathieu Chartierc7853442015-03-27 14:35:38 -0700705 static JDWP::FieldId ToFieldId(const ArtField* f)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700706 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200707
Mathieu Chartiere401d142015-04-22 13:56:20 -0700708 static void SetJdwpLocation(JDWP::JdwpLocation* location, ArtMethod* m, uint32_t dex_pc)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700709 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700710 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200711
Mathieu Chartierad466ad2015-01-08 16:28:08 -0800712 static JDWP::JdwpState* GetJdwpState();
713
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700714 static uint32_t GetInstrumentationEvents() REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz9d6bf692015-04-10 12:12:33 +0200715 return instrumentation_events_;
716 }
717
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000718 static ThreadLifecycleCallback* GetThreadLifecycleCallback() {
719 return &thread_lifecycle_callback_;
720 }
Andreas Gampe0f01b582017-01-18 15:22:37 -0800721 static ClassLoadCallback* GetClassLoadCallback() {
722 return &class_load_callback_;
723 }
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000724
Elliott Hughes545a0642011-11-08 19:10:03 -0800725 private:
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200726 static void ExecuteMethodWithoutPendingException(ScopedObjectAccess& soa, DebugInvokeReq* pReq)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700727 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200728
729 static void BuildInvokeReply(JDWP::ExpandBuf* pReply, uint32_t request_id,
730 JDWP::JdwpTag result_tag, uint64_t result_value,
731 JDWP::ObjectId exception)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700732 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200733
Sebastien Hertz8009f392014-09-01 17:07:11 +0200734 static JDWP::JdwpError GetLocalValue(const StackVisitor& visitor,
735 ScopedObjectAccessUnchecked& soa, int slot,
736 JDWP::JdwpTag tag, uint8_t* buf, size_t width)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700737 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang99170c62015-07-06 11:10:37 -0700738 static JDWP::JdwpError SetLocalValue(Thread* thread, StackVisitor& visitor, int slot,
739 JDWP::JdwpTag tag, uint64_t value, size_t width)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700740 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200741
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700742 static void DdmBroadcast(bool connect) REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000743
744 static void PostThreadStart(Thread* t)
745 REQUIRES_SHARED(Locks::mutator_lock_);
746 static void PostThreadDeath(Thread* t)
747 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700748 static void PostThreadStartOrStop(Thread*, uint32_t)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700749 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800750
Andreas Gampe0f01b582017-01-18 15:22:37 -0800751 static void PostClassPrepare(mirror::Class* c)
752 REQUIRES_SHARED(Locks::mutator_lock_);
753
Mathieu Chartiere401d142015-04-22 13:56:20 -0700754 static void PostLocationEvent(ArtMethod* method, int pcOffset,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100755 mirror::Object* thisPtr, int eventFlags,
756 const JValue* return_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700757 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz8379b222014-02-24 17:38:15 +0100758
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100759 static void ProcessDeoptimizationRequest(const DeoptimizationRequest& request)
Mathieu Chartieraa516822015-10-02 15:53:37 -0700760 REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100761
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100762 static void RequestDeoptimizationLocked(const DeoptimizationRequest& req)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700763 REQUIRES(Locks::deoptimization_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100764
Mathieu Chartiere401d142015-04-22 13:56:20 -0700765 static bool IsForcedInterpreterNeededForCallingImpl(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700766 REQUIRES_SHARED(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200767
Mathieu Chartiere401d142015-04-22 13:56:20 -0700768 static bool IsForcedInterpreterNeededForResolutionImpl(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700769 REQUIRES_SHARED(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200770
Mathieu Chartiere401d142015-04-22 13:56:20 -0700771 static bool IsForcedInstrumentationNeededForResolutionImpl(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700772 REQUIRES_SHARED(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200773
Mathieu Chartiere401d142015-04-22 13:56:20 -0700774 static bool IsForcedInterpreterNeededForUpcallImpl(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700775 REQUIRES_SHARED(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200776
Sebastien Hertz520633b2015-09-08 17:03:36 +0200777 static bool IsForcedInterpreterNeededForExceptionImpl(Thread* thread)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700778 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz520633b2015-09-08 17:03:36 +0200779
Daniel Mihalyieb076692014-08-22 17:33:31 +0200780 // Indicates whether the debugger is making requests.
781 static bool gDebuggerActive;
782
Alex Light21611932017-09-26 13:07:39 -0700783 static DebuggerActiveMethodInspectionCallback gDebugActiveCallback;
784
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100785 // Indicates whether we should drop the JDWP connection because the runtime stops or the
786 // debugger called VirtualMachine.Dispose.
787 static bool gDisposed;
788
Daniel Mihalyieb076692014-08-22 17:33:31 +0200789 // The registry mapping objects to JDWP ids.
Sebastien Hertz6995c602014-09-09 12:10:13 +0200790 static ObjectRegistry* gRegistry;
791
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100792 // Deoptimization requests to be processed each time the event list is updated. This is used when
793 // registering and unregistering events so we do not deoptimize while holding the event list
794 // lock.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200795 // TODO rename to instrumentation_requests.
Brian Carlstrom306db812014-09-05 13:01:41 -0700796 static std::vector<DeoptimizationRequest> deoptimization_requests_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100797
798 // Count the number of events requiring full deoptimization. When the counter is > 0, everything
799 // is deoptimized, otherwise everything is undeoptimized.
800 // Note: we fully deoptimize on the first event only (when the counter is set to 1). We fully
801 // undeoptimize when the last event is unregistered (when the counter is set to 0).
Brian Carlstrom306db812014-09-05 13:01:41 -0700802 static size_t full_deoptimization_event_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100803
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200804 static size_t* GetReferenceCounterForEvent(uint32_t instrumentation_event);
805
806 // Instrumentation event reference counters.
807 // TODO we could use an array instead of having all these dedicated counters. Instrumentation
808 // events are bits of a mask so we could convert them to array index.
Brian Carlstrom306db812014-09-05 13:01:41 -0700809 static size_t dex_pc_change_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
810 static size_t method_enter_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
811 static size_t method_exit_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
812 static size_t field_read_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
813 static size_t field_write_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
814 static size_t exception_catch_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200815 static uint32_t instrumentation_events_ GUARDED_BY(Locks::mutator_lock_);
816
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000817 class DbgThreadLifecycleCallback : public ThreadLifecycleCallback {
818 public:
819 void ThreadStart(Thread* self) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
820 void ThreadDeath(Thread* self) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
821 };
822
Andreas Gampe0f01b582017-01-18 15:22:37 -0800823 class DbgClassLoadCallback : public ClassLoadCallback {
824 public:
825 void ClassLoad(Handle<mirror::Class> klass) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
826 void ClassPrepare(Handle<mirror::Class> temp_klass,
827 Handle<mirror::Class> klass) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
828 };
829
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000830 static DbgThreadLifecycleCallback thread_lifecycle_callback_;
Andreas Gampe0f01b582017-01-18 15:22:37 -0800831 static DbgClassLoadCallback class_load_callback_;
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000832
Ian Rogers719d1a32014-03-06 12:13:39 -0800833 DISALLOW_COPY_AND_ASSIGN(Dbg);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700834};
835
836#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800837 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700838
839} // namespace art
840
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700841#endif // ART_RUNTIME_DEBUGGER_H_