blob: a815a603a7f51190f09748ad9b54d3a4c4c4376f [file] [log] [blame]
Alex Light49948e92016-08-11 15:35:28 -07001/* Copyright (C) 2016 The Android Open Source Project
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * This file implements interfaces from the file jvmti.h. This implementation
5 * is licensed under the same terms as the file jvmti.h. The
6 * copyright and license information for the file jvmti.h follows.
7 *
8 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
9 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
10 *
11 * This code is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 2 only, as
13 * published by the Free Software Foundation. Oracle designates this
14 * particular file as subject to the "Classpath" exception as provided
15 * by Oracle in the LICENSE file that accompanied this code.
16 *
17 * This code is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * version 2 for more details (a copy is included in the LICENSE file that
21 * accompanied this code).
22 *
23 * You should have received a copy of the GNU General Public License version
24 * 2 along with this work; if not, write to the Free Software Foundation,
25 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26 *
27 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
28 * or visit www.oracle.com if you need additional information or have any
29 * questions.
30 */
31
Alex Light9c20a142016-08-23 15:05:12 -070032#include <string>
Andreas Gampef37e3022017-01-13 17:54:46 -080033#include <type_traits>
Alex Light9c20a142016-08-23 15:05:12 -070034#include <vector>
35
Alex Light49948e92016-08-11 15:35:28 -070036#include <jni.h>
Alex Light9c20a142016-08-23 15:05:12 -070037
Alex Light49948e92016-08-11 15:35:28 -070038#include "openjdkjvmti/jvmti.h"
39
Andreas Gampedb6dcb62016-09-13 09:05:59 -070040#include "art_jvmti.h"
Andreas Gampef37e3022017-01-13 17:54:46 -080041#include "base/logging.h"
Andreas Gampe77708d92016-10-07 11:48:21 -070042#include "base/mutex.h"
43#include "events-inl.h"
Alex Light49948e92016-08-11 15:35:28 -070044#include "jni_env_ext-inl.h"
Andreas Gampe6dee92e2016-09-12 19:58:13 -070045#include "obj_ptr-inl.h"
Alex Lighta01de592016-11-15 10:43:06 -080046#include "object_tagging.h"
Alex Light9c20a142016-08-23 15:05:12 -070047#include "runtime.h"
Andreas Gampe6dee92e2016-09-12 19:58:13 -070048#include "scoped_thread_state_change-inl.h"
Andreas Gampe77708d92016-10-07 11:48:21 -070049#include "thread-inl.h"
Alex Lighta01de592016-11-15 10:43:06 -080050#include "thread_list.h"
Andreas Gampee492ae32016-10-28 19:34:57 -070051#include "ti_class.h"
Andreas Gampeeb0cea12017-01-23 08:50:04 -080052#include "ti_dump.h"
Andreas Gampeab2f0d02017-01-05 17:23:45 -080053#include "ti_field.h"
Andreas Gampeba8df692016-11-01 10:30:44 -070054#include "ti_heap.h"
Andreas Gampe6f8e4f02017-01-16 18:18:14 -080055#include "ti_jni.h"
Andreas Gampe3c252f02016-10-27 18:25:17 -070056#include "ti_method.h"
Andreas Gampe319dbe82017-01-09 16:42:21 -080057#include "ti_monitor.h"
Andreas Gampe50a4e492017-01-06 18:00:20 -080058#include "ti_object.h"
Andreas Gampe96eca782017-01-19 19:45:30 -080059#include "ti_phase.h"
Andreas Gampe1bdaf732017-01-09 19:21:06 -080060#include "ti_properties.h"
Alex Lighta01de592016-11-15 10:43:06 -080061#include "ti_redefine.h"
Andreas Gampece7732b2017-01-17 15:50:26 -080062#include "ti_search.h"
Andreas Gampeb5eb94a2016-10-27 19:23:09 -070063#include "ti_stack.h"
Andreas Gampeaf13ab92017-01-11 20:57:40 -080064#include "ti_thread.h"
Andreas Gamped18d9e22017-01-16 16:08:45 +000065#include "ti_threadgroup.h"
Andreas Gampe35bcf812017-01-13 16:24:17 -080066#include "ti_timers.h"
Alex Light9c20a142016-08-23 15:05:12 -070067#include "transform.h"
Alex Light49948e92016-08-11 15:35:28 -070068
69// TODO Remove this at some point by annotating all the methods. It was put in to make the skeleton
70// easier to create.
71#pragma GCC diagnostic ignored "-Wunused-parameter"
72
73namespace openjdkjvmti {
74
Andreas Gampe77708d92016-10-07 11:48:21 -070075EventHandler gEventHandler;
Andreas Gampecc13b222016-10-10 19:09:09 -070076ObjectTagTable gObjectTagTable(&gEventHandler);
Andreas Gampe6dee92e2016-09-12 19:58:13 -070077
Alex Lighte6574242016-08-17 09:56:24 -070078#define ENSURE_NON_NULL(n) \
79 do { \
80 if ((n) == nullptr) { \
81 return ERR(NULL_POINTER); \
82 } \
83 } while (false)
84
Alex Light49948e92016-08-11 15:35:28 -070085class JvmtiFunctions {
86 private:
87 static bool IsValidEnv(jvmtiEnv* env) {
88 return env != nullptr;
89 }
90
Alex Lighte6574242016-08-17 09:56:24 -070091#define ENSURE_VALID_ENV(env) \
92 do { \
93 if (!IsValidEnv(env)) { \
94 return ERR(INVALID_ENVIRONMENT); \
95 } \
96 } while (false)
97
98#define ENSURE_HAS_CAP(env, cap) \
99 do { \
100 ENSURE_VALID_ENV(env); \
101 if (ArtJvmTiEnv::AsArtJvmTiEnv(env)->capabilities.cap != 1) { \
102 return ERR(MUST_POSSESS_CAPABILITY); \
103 } \
104 } while (false)
105
Alex Light49948e92016-08-11 15:35:28 -0700106 public:
107 static jvmtiError Allocate(jvmtiEnv* env, jlong size, unsigned char** mem_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -0700108 ENSURE_VALID_ENV(env);
109 ENSURE_NON_NULL(mem_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700110 if (size < 0) {
111 return ERR(ILLEGAL_ARGUMENT);
112 } else if (size == 0) {
113 *mem_ptr = nullptr;
114 return OK;
115 }
116 *mem_ptr = static_cast<unsigned char*>(malloc(size));
117 return (*mem_ptr != nullptr) ? OK : ERR(OUT_OF_MEMORY);
118 }
119
120 static jvmtiError Deallocate(jvmtiEnv* env, unsigned char* mem) {
Alex Lighte6574242016-08-17 09:56:24 -0700121 ENSURE_VALID_ENV(env);
Alex Light49948e92016-08-11 15:35:28 -0700122 if (mem != nullptr) {
123 free(mem);
124 }
125 return OK;
126 }
127
128 static jvmtiError GetThreadState(jvmtiEnv* env, jthread thread, jint* thread_state_ptr) {
Andreas Gampe72c19832017-01-12 13:22:16 -0800129 return ThreadUtil::GetThreadState(env, thread, thread_state_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700130 }
131
132 static jvmtiError GetCurrentThread(jvmtiEnv* env, jthread* thread_ptr) {
Andreas Gampeaf13ab92017-01-11 20:57:40 -0800133 return ThreadUtil::GetCurrentThread(env, thread_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700134 }
135
136 static jvmtiError GetAllThreads(jvmtiEnv* env, jint* threads_count_ptr, jthread** threads_ptr) {
Andreas Gampe85807442017-01-13 14:40:58 -0800137 return ThreadUtil::GetAllThreads(env, threads_count_ptr, threads_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700138 }
139
140 static jvmtiError SuspendThread(jvmtiEnv* env, jthread thread) {
Alex Light9db679d2017-01-25 15:28:04 -0800141 ENSURE_HAS_CAP(env, can_suspend);
Alex Light49948e92016-08-11 15:35:28 -0700142 return ERR(NOT_IMPLEMENTED);
143 }
144
145 static jvmtiError SuspendThreadList(jvmtiEnv* env,
146 jint request_count,
147 const jthread* request_list,
148 jvmtiError* results) {
Alex Light9db679d2017-01-25 15:28:04 -0800149 ENSURE_HAS_CAP(env, can_suspend);
Alex Light49948e92016-08-11 15:35:28 -0700150 return ERR(NOT_IMPLEMENTED);
151 }
152
153 static jvmtiError ResumeThread(jvmtiEnv* env, jthread thread) {
Alex Light9db679d2017-01-25 15:28:04 -0800154 ENSURE_HAS_CAP(env, can_suspend);
Alex Light49948e92016-08-11 15:35:28 -0700155 return ERR(NOT_IMPLEMENTED);
156 }
157
158 static jvmtiError ResumeThreadList(jvmtiEnv* env,
159 jint request_count,
160 const jthread* request_list,
161 jvmtiError* results) {
Alex Light9db679d2017-01-25 15:28:04 -0800162 ENSURE_HAS_CAP(env, can_suspend);
Alex Light49948e92016-08-11 15:35:28 -0700163 return ERR(NOT_IMPLEMENTED);
164 }
165
166 static jvmtiError StopThread(jvmtiEnv* env, jthread thread, jobject exception) {
Alex Light9db679d2017-01-25 15:28:04 -0800167 ENSURE_HAS_CAP(env, can_signal_thread);
Alex Light49948e92016-08-11 15:35:28 -0700168 return ERR(NOT_IMPLEMENTED);
169 }
170
171 static jvmtiError InterruptThread(jvmtiEnv* env, jthread thread) {
Alex Light9db679d2017-01-25 15:28:04 -0800172 ENSURE_HAS_CAP(env, can_signal_thread);
Alex Light49948e92016-08-11 15:35:28 -0700173 return ERR(NOT_IMPLEMENTED);
174 }
175
176 static jvmtiError GetThreadInfo(jvmtiEnv* env, jthread thread, jvmtiThreadInfo* info_ptr) {
Andreas Gampeaf13ab92017-01-11 20:57:40 -0800177 return ThreadUtil::GetThreadInfo(env, thread, info_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700178 }
179
180 static jvmtiError GetOwnedMonitorInfo(jvmtiEnv* env,
181 jthread thread,
182 jint* owned_monitor_count_ptr,
183 jobject** owned_monitors_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800184 ENSURE_HAS_CAP(env, can_get_owned_monitor_info);
Alex Light49948e92016-08-11 15:35:28 -0700185 return ERR(NOT_IMPLEMENTED);
186 }
187
188 static jvmtiError GetOwnedMonitorStackDepthInfo(jvmtiEnv* env,
189 jthread thread,
190 jint* monitor_info_count_ptr,
191 jvmtiMonitorStackDepthInfo** monitor_info_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800192 ENSURE_HAS_CAP(env, can_get_owned_monitor_stack_depth_info);
Alex Light49948e92016-08-11 15:35:28 -0700193 return ERR(NOT_IMPLEMENTED);
194 }
195
196 static jvmtiError GetCurrentContendedMonitor(jvmtiEnv* env,
197 jthread thread,
198 jobject* monitor_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800199 ENSURE_HAS_CAP(env, can_get_current_contended_monitor);
Alex Lighte6574242016-08-17 09:56:24 -0700200 return ERR(NOT_IMPLEMENTED);
Alex Light49948e92016-08-11 15:35:28 -0700201 }
202
203 static jvmtiError RunAgentThread(jvmtiEnv* env,
204 jthread thread,
205 jvmtiStartFunction proc,
206 const void* arg,
207 jint priority) {
Andreas Gampe732b0ac2017-01-18 15:23:39 -0800208 return ThreadUtil::RunAgentThread(env, thread, proc, arg, priority);
Alex Light49948e92016-08-11 15:35:28 -0700209 }
210
211 static jvmtiError SetThreadLocalStorage(jvmtiEnv* env, jthread thread, const void* data) {
Andreas Gampe7b3b3262017-01-19 20:40:42 -0800212 return ThreadUtil::SetThreadLocalStorage(env, thread, data);
Alex Light49948e92016-08-11 15:35:28 -0700213 }
214
215 static jvmtiError GetThreadLocalStorage(jvmtiEnv* env, jthread thread, void** data_ptr) {
Andreas Gampe7b3b3262017-01-19 20:40:42 -0800216 return ThreadUtil::GetThreadLocalStorage(env, thread, data_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700217 }
218
219 static jvmtiError GetTopThreadGroups(jvmtiEnv* env,
220 jint* group_count_ptr,
221 jthreadGroup** groups_ptr) {
Andreas Gamped18d9e22017-01-16 16:08:45 +0000222 return ThreadGroupUtil::GetTopThreadGroups(env, group_count_ptr, groups_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700223 }
224
225 static jvmtiError GetThreadGroupInfo(jvmtiEnv* env,
226 jthreadGroup group,
227 jvmtiThreadGroupInfo* info_ptr) {
Andreas Gamped18d9e22017-01-16 16:08:45 +0000228 return ThreadGroupUtil::GetThreadGroupInfo(env, group, info_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700229 }
230
231 static jvmtiError GetThreadGroupChildren(jvmtiEnv* env,
232 jthreadGroup group,
233 jint* thread_count_ptr,
234 jthread** threads_ptr,
235 jint* group_count_ptr,
236 jthreadGroup** groups_ptr) {
Andreas Gamped18d9e22017-01-16 16:08:45 +0000237 return ThreadGroupUtil::GetThreadGroupChildren(env,
238 group,
239 thread_count_ptr,
240 threads_ptr,
241 group_count_ptr,
242 groups_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700243 }
244
245 static jvmtiError GetStackTrace(jvmtiEnv* env,
246 jthread thread,
247 jint start_depth,
248 jint max_frame_count,
249 jvmtiFrameInfo* frame_buffer,
250 jint* count_ptr) {
Andreas Gampeb5eb94a2016-10-27 19:23:09 -0700251 return StackUtil::GetStackTrace(env,
252 thread,
253 start_depth,
254 max_frame_count,
255 frame_buffer,
256 count_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700257 }
258
259 static jvmtiError GetAllStackTraces(jvmtiEnv* env,
260 jint max_frame_count,
261 jvmtiStackInfo** stack_info_ptr,
262 jint* thread_count_ptr) {
Andreas Gampea1a27c62017-01-11 16:37:16 -0800263 return StackUtil::GetAllStackTraces(env, max_frame_count, stack_info_ptr, thread_count_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700264 }
265
266 static jvmtiError GetThreadListStackTraces(jvmtiEnv* env,
267 jint thread_count,
268 const jthread* thread_list,
269 jint max_frame_count,
270 jvmtiStackInfo** stack_info_ptr) {
Andreas Gampeeba32fb2017-01-12 17:40:05 -0800271 return StackUtil::GetThreadListStackTraces(env,
272 thread_count,
273 thread_list,
274 max_frame_count,
275 stack_info_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700276 }
277
278 static jvmtiError GetFrameCount(jvmtiEnv* env, jthread thread, jint* count_ptr) {
Andreas Gampef6f3b5f2017-01-13 09:21:42 -0800279 return StackUtil::GetFrameCount(env, thread, count_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700280 }
281
282 static jvmtiError PopFrame(jvmtiEnv* env, jthread thread) {
Alex Light9db679d2017-01-25 15:28:04 -0800283 ENSURE_HAS_CAP(env, can_pop_frame);
Alex Light49948e92016-08-11 15:35:28 -0700284 return ERR(NOT_IMPLEMENTED);
285 }
286
287 static jvmtiError GetFrameLocation(jvmtiEnv* env,
288 jthread thread,
289 jint depth,
290 jmethodID* method_ptr,
291 jlocation* location_ptr) {
Andreas Gampef6f3b5f2017-01-13 09:21:42 -0800292 return StackUtil::GetFrameLocation(env, thread, depth, method_ptr, location_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700293 }
294
295 static jvmtiError NotifyFramePop(jvmtiEnv* env, jthread thread, jint depth) {
Alex Light9db679d2017-01-25 15:28:04 -0800296 ENSURE_HAS_CAP(env, can_generate_frame_pop_events);
Alex Light49948e92016-08-11 15:35:28 -0700297 return ERR(NOT_IMPLEMENTED);
298 }
299
300 static jvmtiError ForceEarlyReturnObject(jvmtiEnv* env, jthread thread, jobject value) {
Alex Light9db679d2017-01-25 15:28:04 -0800301 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Light49948e92016-08-11 15:35:28 -0700302 return ERR(NOT_IMPLEMENTED);
303 }
304
305 static jvmtiError ForceEarlyReturnInt(jvmtiEnv* env, jthread thread, jint value) {
Alex Light9db679d2017-01-25 15:28:04 -0800306 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Light49948e92016-08-11 15:35:28 -0700307 return ERR(NOT_IMPLEMENTED);
308 }
309
310 static jvmtiError ForceEarlyReturnLong(jvmtiEnv* env, jthread thread, jlong value) {
Alex Light9db679d2017-01-25 15:28:04 -0800311 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Light49948e92016-08-11 15:35:28 -0700312 return ERR(NOT_IMPLEMENTED);
313 }
314
315 static jvmtiError ForceEarlyReturnFloat(jvmtiEnv* env, jthread thread, jfloat value) {
Alex Light9db679d2017-01-25 15:28:04 -0800316 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Light49948e92016-08-11 15:35:28 -0700317 return ERR(NOT_IMPLEMENTED);
318 }
319
320 static jvmtiError ForceEarlyReturnDouble(jvmtiEnv* env, jthread thread, jdouble value) {
Alex Light9db679d2017-01-25 15:28:04 -0800321 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Light49948e92016-08-11 15:35:28 -0700322 return ERR(NOT_IMPLEMENTED);
323 }
324
325 static jvmtiError ForceEarlyReturnVoid(jvmtiEnv* env, jthread thread) {
Alex Light9db679d2017-01-25 15:28:04 -0800326 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Light49948e92016-08-11 15:35:28 -0700327 return ERR(NOT_IMPLEMENTED);
328 }
329
330 static jvmtiError FollowReferences(jvmtiEnv* env,
331 jint heap_filter,
332 jclass klass,
333 jobject initial_object,
334 const jvmtiHeapCallbacks* callbacks,
335 const void* user_data) {
Alex Light9db679d2017-01-25 15:28:04 -0800336 ENSURE_HAS_CAP(env, can_tag_objects);
Andreas Gampe70bfc8a2016-11-03 11:04:15 -0700337 HeapUtil heap_util(&gObjectTagTable);
338 return heap_util.FollowReferences(env,
339 heap_filter,
340 klass,
341 initial_object,
342 callbacks,
343 user_data);
Alex Light49948e92016-08-11 15:35:28 -0700344 }
345
346 static jvmtiError IterateThroughHeap(jvmtiEnv* env,
347 jint heap_filter,
348 jclass klass,
349 const jvmtiHeapCallbacks* callbacks,
350 const void* user_data) {
Alex Lighte6574242016-08-17 09:56:24 -0700351 ENSURE_HAS_CAP(env, can_tag_objects);
Andreas Gampee54d9922016-10-11 19:55:37 -0700352 HeapUtil heap_util(&gObjectTagTable);
353 return heap_util.IterateThroughHeap(env, heap_filter, klass, callbacks, user_data);
Alex Light49948e92016-08-11 15:35:28 -0700354 }
355
356 static jvmtiError GetTag(jvmtiEnv* env, jobject object, jlong* tag_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -0700357 ENSURE_HAS_CAP(env, can_tag_objects);
Andreas Gampe6dee92e2016-09-12 19:58:13 -0700358
359 JNIEnv* jni_env = GetJniEnv(env);
360 if (jni_env == nullptr) {
361 return ERR(INTERNAL);
362 }
363
364 art::ScopedObjectAccess soa(jni_env);
365 art::ObjPtr<art::mirror::Object> obj = soa.Decode<art::mirror::Object>(object);
366 if (!gObjectTagTable.GetTag(obj.Ptr(), tag_ptr)) {
367 *tag_ptr = 0;
368 }
369
370 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -0700371 }
372
373 static jvmtiError SetTag(jvmtiEnv* env, jobject object, jlong tag) {
Alex Lighte6574242016-08-17 09:56:24 -0700374 ENSURE_HAS_CAP(env, can_tag_objects);
375
Andreas Gampe6dee92e2016-09-12 19:58:13 -0700376 if (object == nullptr) {
377 return ERR(NULL_POINTER);
378 }
379
380 JNIEnv* jni_env = GetJniEnv(env);
381 if (jni_env == nullptr) {
382 return ERR(INTERNAL);
383 }
384
385 art::ScopedObjectAccess soa(jni_env);
386 art::ObjPtr<art::mirror::Object> obj = soa.Decode<art::mirror::Object>(object);
Andreas Gampee54eee12016-10-20 19:03:58 -0700387 gObjectTagTable.Set(obj.Ptr(), tag);
Andreas Gampe6dee92e2016-09-12 19:58:13 -0700388
389 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -0700390 }
391
392 static jvmtiError GetObjectsWithTags(jvmtiEnv* env,
393 jint tag_count,
394 const jlong* tags,
395 jint* count_ptr,
396 jobject** object_result_ptr,
397 jlong** tag_result_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -0700398 ENSURE_HAS_CAP(env, can_tag_objects);
399
Andreas Gampe5e6046b2016-10-25 12:05:53 -0700400 JNIEnv* jni_env = GetJniEnv(env);
401 if (jni_env == nullptr) {
402 return ERR(INTERNAL);
403 }
404
405 art::ScopedObjectAccess soa(jni_env);
406 return gObjectTagTable.GetTaggedObjects(env,
407 tag_count,
408 tags,
409 count_ptr,
410 object_result_ptr,
411 tag_result_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700412 }
413
414 static jvmtiError ForceGarbageCollection(jvmtiEnv* env) {
Andreas Gampe8da6d032016-10-31 19:31:03 -0700415 return HeapUtil::ForceGarbageCollection(env);
Alex Light49948e92016-08-11 15:35:28 -0700416 }
417
418 static jvmtiError IterateOverObjectsReachableFromObject(
419 jvmtiEnv* env,
420 jobject object,
421 jvmtiObjectReferenceCallback object_reference_callback,
422 const void* user_data) {
Alex Light9db679d2017-01-25 15:28:04 -0800423 ENSURE_HAS_CAP(env, can_tag_objects);
Alex Light49948e92016-08-11 15:35:28 -0700424 return ERR(NOT_IMPLEMENTED);
425 }
426
427 static jvmtiError IterateOverReachableObjects(jvmtiEnv* env,
428 jvmtiHeapRootCallback heap_root_callback,
429 jvmtiStackReferenceCallback stack_ref_callback,
430 jvmtiObjectReferenceCallback object_ref_callback,
431 const void* user_data) {
Alex Light9db679d2017-01-25 15:28:04 -0800432 ENSURE_HAS_CAP(env, can_tag_objects);
Alex Light49948e92016-08-11 15:35:28 -0700433 return ERR(NOT_IMPLEMENTED);
434 }
435
436 static jvmtiError IterateOverHeap(jvmtiEnv* env,
437 jvmtiHeapObjectFilter object_filter,
438 jvmtiHeapObjectCallback heap_object_callback,
439 const void* user_data) {
Alex Light9db679d2017-01-25 15:28:04 -0800440 ENSURE_HAS_CAP(env, can_tag_objects);
Alex Light49948e92016-08-11 15:35:28 -0700441 return ERR(NOT_IMPLEMENTED);
442 }
443
444 static jvmtiError IterateOverInstancesOfClass(jvmtiEnv* env,
445 jclass klass,
446 jvmtiHeapObjectFilter object_filter,
447 jvmtiHeapObjectCallback heap_object_callback,
448 const void* user_data) {
Alex Light9db679d2017-01-25 15:28:04 -0800449 ENSURE_HAS_CAP(env, can_tag_objects);
Alex Light49948e92016-08-11 15:35:28 -0700450 return ERR(NOT_IMPLEMENTED);
451 }
452
453 static jvmtiError GetLocalObject(jvmtiEnv* env,
454 jthread thread,
455 jint depth,
456 jint slot,
457 jobject* value_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800458 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700459 return ERR(NOT_IMPLEMENTED);
460 }
461
462 static jvmtiError GetLocalInstance(jvmtiEnv* env,
463 jthread thread,
464 jint depth,
465 jobject* value_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800466 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700467 return ERR(NOT_IMPLEMENTED);
468 }
469
470 static jvmtiError GetLocalInt(jvmtiEnv* env,
471 jthread thread,
472 jint depth,
473 jint slot,
474 jint* value_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800475 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700476 return ERR(NOT_IMPLEMENTED);
477 }
478
479 static jvmtiError GetLocalLong(jvmtiEnv* env,
480 jthread thread,
481 jint depth,
482 jint slot,
483 jlong* value_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800484 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700485 return ERR(NOT_IMPLEMENTED);
486 }
487
488 static jvmtiError GetLocalFloat(jvmtiEnv* env,
489 jthread thread,
490 jint depth,
491 jint slot,
492 jfloat* value_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800493 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700494 return ERR(NOT_IMPLEMENTED);
495 }
496
497 static jvmtiError GetLocalDouble(jvmtiEnv* env,
498 jthread thread,
499 jint depth,
500 jint slot,
501 jdouble* value_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800502 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700503 return ERR(NOT_IMPLEMENTED);
504 }
505
506 static jvmtiError SetLocalObject(jvmtiEnv* env,
507 jthread thread,
508 jint depth,
509 jint slot,
510 jobject value) {
Alex Light9db679d2017-01-25 15:28:04 -0800511 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700512 return ERR(NOT_IMPLEMENTED);
513 }
514
515 static jvmtiError SetLocalInt(jvmtiEnv* env,
516 jthread thread,
517 jint depth,
518 jint slot,
519 jint value) {
Alex Light9db679d2017-01-25 15:28:04 -0800520 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700521 return ERR(NOT_IMPLEMENTED);
522 }
523
524 static jvmtiError SetLocalLong(jvmtiEnv* env,
525 jthread thread,
526 jint depth,
527 jint slot,
528 jlong value) {
Alex Light9db679d2017-01-25 15:28:04 -0800529 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700530 return ERR(NOT_IMPLEMENTED);
531 }
532
533 static jvmtiError SetLocalFloat(jvmtiEnv* env,
534 jthread thread,
535 jint depth,
536 jint slot,
537 jfloat value) {
Alex Light9db679d2017-01-25 15:28:04 -0800538 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700539 return ERR(NOT_IMPLEMENTED);
540 }
541
542 static jvmtiError SetLocalDouble(jvmtiEnv* env,
543 jthread thread,
544 jint depth,
545 jint slot,
546 jdouble value) {
Alex Light9db679d2017-01-25 15:28:04 -0800547 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700548 return ERR(NOT_IMPLEMENTED);
549 }
550
551 static jvmtiError SetBreakpoint(jvmtiEnv* env, jmethodID method, jlocation location) {
Alex Light9db679d2017-01-25 15:28:04 -0800552 ENSURE_HAS_CAP(env, can_generate_breakpoint_events);
Alex Light49948e92016-08-11 15:35:28 -0700553 return ERR(NOT_IMPLEMENTED);
554 }
555
556 static jvmtiError ClearBreakpoint(jvmtiEnv* env, jmethodID method, jlocation location) {
Alex Light9db679d2017-01-25 15:28:04 -0800557 ENSURE_HAS_CAP(env, can_generate_breakpoint_events);
Alex Light49948e92016-08-11 15:35:28 -0700558 return ERR(NOT_IMPLEMENTED);
559 }
560
561 static jvmtiError SetFieldAccessWatch(jvmtiEnv* env, jclass klass, jfieldID field) {
Alex Light9db679d2017-01-25 15:28:04 -0800562 ENSURE_HAS_CAP(env, can_generate_field_access_events);
Alex Light49948e92016-08-11 15:35:28 -0700563 return ERR(NOT_IMPLEMENTED);
564 }
565
566 static jvmtiError ClearFieldAccessWatch(jvmtiEnv* env, jclass klass, jfieldID field) {
Alex Light9db679d2017-01-25 15:28:04 -0800567 ENSURE_HAS_CAP(env, can_generate_field_access_events);
Alex Light49948e92016-08-11 15:35:28 -0700568 return ERR(NOT_IMPLEMENTED);
569 }
570
571 static jvmtiError SetFieldModificationWatch(jvmtiEnv* env, jclass klass, jfieldID field) {
Alex Light9db679d2017-01-25 15:28:04 -0800572 ENSURE_HAS_CAP(env, can_generate_field_modification_events);
Alex Light49948e92016-08-11 15:35:28 -0700573 return ERR(NOT_IMPLEMENTED);
574 }
575
576 static jvmtiError ClearFieldModificationWatch(jvmtiEnv* env, jclass klass, jfieldID field) {
Alex Light9db679d2017-01-25 15:28:04 -0800577 ENSURE_HAS_CAP(env, can_generate_field_modification_events);
Alex Light49948e92016-08-11 15:35:28 -0700578 return ERR(NOT_IMPLEMENTED);
579 }
580
581 static jvmtiError GetLoadedClasses(jvmtiEnv* env, jint* class_count_ptr, jclass** classes_ptr) {
Andreas Gampeaa8b60c2016-10-12 12:51:25 -0700582 HeapUtil heap_util(&gObjectTagTable);
583 return heap_util.GetLoadedClasses(env, class_count_ptr, classes_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700584 }
585
586 static jvmtiError GetClassLoaderClasses(jvmtiEnv* env,
587 jobject initiating_loader,
588 jint* class_count_ptr,
589 jclass** classes_ptr) {
Andreas Gampe70f16392017-01-16 14:20:10 -0800590 return ClassUtil::GetClassLoaderClasses(env, initiating_loader, class_count_ptr, classes_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700591 }
592
593 static jvmtiError GetClassSignature(jvmtiEnv* env,
594 jclass klass,
595 char** signature_ptr,
596 char** generic_ptr) {
Andreas Gampee492ae32016-10-28 19:34:57 -0700597 return ClassUtil::GetClassSignature(env, klass, signature_ptr, generic_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700598 }
599
600 static jvmtiError GetClassStatus(jvmtiEnv* env, jclass klass, jint* status_ptr) {
Andreas Gampeff9d2092017-01-06 09:12:49 -0800601 return ClassUtil::GetClassStatus(env, klass, status_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700602 }
603
604 static jvmtiError GetSourceFileName(jvmtiEnv* env, jclass klass, char** source_name_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800605 ENSURE_HAS_CAP(env, can_get_source_file_name);
Alex Light49948e92016-08-11 15:35:28 -0700606 return ERR(NOT_IMPLEMENTED);
607 }
608
609 static jvmtiError GetClassModifiers(jvmtiEnv* env, jclass klass, jint* modifiers_ptr) {
Andreas Gampe64013e52017-01-06 13:07:19 -0800610 return ClassUtil::GetClassModifiers(env, klass, modifiers_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700611 }
612
613 static jvmtiError GetClassMethods(jvmtiEnv* env,
614 jclass klass,
615 jint* method_count_ptr,
616 jmethodID** methods_ptr) {
Andreas Gampe18fee4d2017-01-06 11:36:35 -0800617 return ClassUtil::GetClassMethods(env, klass, method_count_ptr, methods_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700618 }
619
620 static jvmtiError GetClassFields(jvmtiEnv* env,
621 jclass klass,
622 jint* field_count_ptr,
623 jfieldID** fields_ptr) {
Andreas Gampeac587272017-01-05 15:21:34 -0800624 return ClassUtil::GetClassFields(env, klass, field_count_ptr, fields_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700625 }
626
627 static jvmtiError GetImplementedInterfaces(jvmtiEnv* env,
628 jclass klass,
629 jint* interface_count_ptr,
630 jclass** interfaces_ptr) {
Andreas Gampe8b07e472017-01-06 14:20:39 -0800631 return ClassUtil::GetImplementedInterfaces(env, klass, interface_count_ptr, interfaces_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700632 }
633
634 static jvmtiError GetClassVersionNumbers(jvmtiEnv* env,
635 jclass klass,
636 jint* minor_version_ptr,
637 jint* major_version_ptr) {
Andreas Gampe812a2442017-01-19 22:04:46 -0800638 return ClassUtil::GetClassVersionNumbers(env, klass, minor_version_ptr, major_version_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700639 }
640
641 static jvmtiError GetConstantPool(jvmtiEnv* env,
642 jclass klass,
643 jint* constant_pool_count_ptr,
644 jint* constant_pool_byte_count_ptr,
645 unsigned char** constant_pool_bytes_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800646 ENSURE_HAS_CAP(env, can_get_constant_pool);
Alex Light49948e92016-08-11 15:35:28 -0700647 return ERR(NOT_IMPLEMENTED);
648 }
649
650 static jvmtiError IsInterface(jvmtiEnv* env, jclass klass, jboolean* is_interface_ptr) {
Andreas Gampe4fd66ec2017-01-05 14:42:13 -0800651 return ClassUtil::IsInterface(env, klass, is_interface_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700652 }
653
654 static jvmtiError IsArrayClass(jvmtiEnv* env,
655 jclass klass,
656 jboolean* is_array_class_ptr) {
Andreas Gampe4fd66ec2017-01-05 14:42:13 -0800657 return ClassUtil::IsArrayClass(env, klass, is_array_class_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700658 }
659
660 static jvmtiError IsModifiableClass(jvmtiEnv* env,
661 jclass klass,
662 jboolean* is_modifiable_class_ptr) {
Alex Lighte4a88632017-01-10 07:41:24 -0800663 return Redefiner::IsModifiableClass(env, klass, is_modifiable_class_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700664 }
665
666 static jvmtiError GetClassLoader(jvmtiEnv* env, jclass klass, jobject* classloader_ptr) {
Andreas Gampe8f5b6032017-01-06 15:50:55 -0800667 return ClassUtil::GetClassLoader(env, klass, classloader_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700668 }
669
670 static jvmtiError GetSourceDebugExtension(jvmtiEnv* env,
671 jclass klass,
672 char** source_debug_extension_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800673 ENSURE_HAS_CAP(env, can_get_source_debug_extension);
Alex Light49948e92016-08-11 15:35:28 -0700674 return ERR(NOT_IMPLEMENTED);
675 }
676
677 static jvmtiError RetransformClasses(jvmtiEnv* env, jint class_count, const jclass* classes) {
Alex Light9db679d2017-01-25 15:28:04 -0800678 ENSURE_HAS_CAP(env, can_retransform_classes);
Alex Light6ac57502017-01-19 15:05:06 -0800679 std::string error_msg;
680 jvmtiError res = Transformer::RetransformClasses(ArtJvmTiEnv::AsArtJvmTiEnv(env),
681 art::Runtime::Current(),
682 art::Thread::Current(),
683 class_count,
684 classes,
685 &error_msg);
686 if (res != OK) {
687 LOG(WARNING) << "FAILURE TO RETRANFORM " << error_msg;
688 }
689 return res;
Alex Light49948e92016-08-11 15:35:28 -0700690 }
691
692 static jvmtiError RedefineClasses(jvmtiEnv* env,
693 jint class_count,
694 const jvmtiClassDefinition* class_definitions) {
Alex Light9db679d2017-01-25 15:28:04 -0800695 ENSURE_HAS_CAP(env, can_redefine_classes);
Alex Light0e692732017-01-10 15:00:05 -0800696 std::string error_msg;
697 jvmtiError res = Redefiner::RedefineClasses(ArtJvmTiEnv::AsArtJvmTiEnv(env),
698 art::Runtime::Current(),
699 art::Thread::Current(),
700 class_count,
701 class_definitions,
702 &error_msg);
703 if (res != OK) {
704 LOG(WARNING) << "FAILURE TO REDEFINE " << error_msg;
705 }
706 return res;
Alex Light49948e92016-08-11 15:35:28 -0700707 }
708
709 static jvmtiError GetObjectSize(jvmtiEnv* env, jobject object, jlong* size_ptr) {
Andreas Gampe50a4e492017-01-06 18:00:20 -0800710 return ObjectUtil::GetObjectSize(env, object, size_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700711 }
712
713 static jvmtiError GetObjectHashCode(jvmtiEnv* env, jobject object, jint* hash_code_ptr) {
Andreas Gampe50a4e492017-01-06 18:00:20 -0800714 return ObjectUtil::GetObjectHashCode(env, object, hash_code_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700715 }
716
717 static jvmtiError GetObjectMonitorUsage(jvmtiEnv* env,
718 jobject object,
719 jvmtiMonitorUsage* info_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800720 ENSURE_HAS_CAP(env, can_get_monitor_info);
Alex Light49948e92016-08-11 15:35:28 -0700721 return ERR(NOT_IMPLEMENTED);
722 }
723
724 static jvmtiError GetFieldName(jvmtiEnv* env,
725 jclass klass,
726 jfieldID field,
727 char** name_ptr,
728 char** signature_ptr,
729 char** generic_ptr) {
Andreas Gampeab2f0d02017-01-05 17:23:45 -0800730 return FieldUtil::GetFieldName(env, klass, field, name_ptr, signature_ptr, generic_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700731 }
732
733 static jvmtiError GetFieldDeclaringClass(jvmtiEnv* env,
734 jclass klass,
735 jfieldID field,
736 jclass* declaring_class_ptr) {
Andreas Gampeab2f0d02017-01-05 17:23:45 -0800737 return FieldUtil::GetFieldDeclaringClass(env, klass, field, declaring_class_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700738 }
739
740 static jvmtiError GetFieldModifiers(jvmtiEnv* env,
741 jclass klass,
742 jfieldID field,
743 jint* modifiers_ptr) {
Andreas Gampeab2f0d02017-01-05 17:23:45 -0800744 return FieldUtil::GetFieldModifiers(env, klass, field, modifiers_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700745 }
746
747 static jvmtiError IsFieldSynthetic(jvmtiEnv* env,
748 jclass klass,
749 jfieldID field,
750 jboolean* is_synthetic_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800751 ENSURE_HAS_CAP(env, can_get_synthetic_attribute);
Andreas Gampeab2f0d02017-01-05 17:23:45 -0800752 return FieldUtil::IsFieldSynthetic(env, klass, field, is_synthetic_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700753 }
754
755 static jvmtiError GetMethodName(jvmtiEnv* env,
756 jmethodID method,
757 char** name_ptr,
758 char** signature_ptr,
759 char** generic_ptr) {
Andreas Gampe3c252f02016-10-27 18:25:17 -0700760 return MethodUtil::GetMethodName(env, method, name_ptr, signature_ptr, generic_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700761 }
762
763 static jvmtiError GetMethodDeclaringClass(jvmtiEnv* env,
764 jmethodID method,
765 jclass* declaring_class_ptr) {
Andreas Gampe368a2082016-10-28 17:33:13 -0700766 return MethodUtil::GetMethodDeclaringClass(env, method, declaring_class_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700767 }
768
769 static jvmtiError GetMethodModifiers(jvmtiEnv* env,
770 jmethodID method,
771 jint* modifiers_ptr) {
Andreas Gampe36bcd4f2016-10-28 18:07:18 -0700772 return MethodUtil::GetMethodModifiers(env, method, modifiers_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700773 }
774
775 static jvmtiError GetMaxLocals(jvmtiEnv* env,
776 jmethodID method,
777 jint* max_ptr) {
Andreas Gampef71832e2017-01-09 11:38:04 -0800778 return MethodUtil::GetMaxLocals(env, method, max_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700779 }
780
781 static jvmtiError GetArgumentsSize(jvmtiEnv* env,
782 jmethodID method,
783 jint* size_ptr) {
Andreas Gampef71832e2017-01-09 11:38:04 -0800784 return MethodUtil::GetArgumentsSize(env, method, size_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700785 }
786
787 static jvmtiError GetLineNumberTable(jvmtiEnv* env,
788 jmethodID method,
789 jint* entry_count_ptr,
790 jvmtiLineNumberEntry** table_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800791 ENSURE_HAS_CAP(env, can_get_line_numbers);
Andreas Gampeda3e5612016-12-13 19:00:53 -0800792 return MethodUtil::GetLineNumberTable(env, method, entry_count_ptr, table_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700793 }
794
795 static jvmtiError GetMethodLocation(jvmtiEnv* env,
796 jmethodID method,
797 jlocation* start_location_ptr,
798 jlocation* end_location_ptr) {
Andreas Gampef71832e2017-01-09 11:38:04 -0800799 return MethodUtil::GetMethodLocation(env, method, start_location_ptr, end_location_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700800 }
801
802 static jvmtiError GetLocalVariableTable(jvmtiEnv* env,
803 jmethodID method,
804 jint* entry_count_ptr,
805 jvmtiLocalVariableEntry** table_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800806 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700807 return ERR(NOT_IMPLEMENTED);
808 }
809
810 static jvmtiError GetBytecodes(jvmtiEnv* env,
811 jmethodID method,
812 jint* bytecode_count_ptr,
813 unsigned char** bytecodes_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800814 ENSURE_HAS_CAP(env, can_get_bytecodes);
Alex Light49948e92016-08-11 15:35:28 -0700815 return ERR(NOT_IMPLEMENTED);
816 }
817
818 static jvmtiError IsMethodNative(jvmtiEnv* env, jmethodID method, jboolean* is_native_ptr) {
Andreas Gampefdeef522017-01-09 14:40:25 -0800819 return MethodUtil::IsMethodNative(env, method, is_native_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700820 }
821
822 static jvmtiError IsMethodSynthetic(jvmtiEnv* env, jmethodID method, jboolean* is_synthetic_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800823 ENSURE_HAS_CAP(env, can_get_synthetic_attribute);
Andreas Gampefdeef522017-01-09 14:40:25 -0800824 return MethodUtil::IsMethodSynthetic(env, method, is_synthetic_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700825 }
826
827 static jvmtiError IsMethodObsolete(jvmtiEnv* env, jmethodID method, jboolean* is_obsolete_ptr) {
Andreas Gampefdeef522017-01-09 14:40:25 -0800828 return MethodUtil::IsMethodObsolete(env, method, is_obsolete_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700829 }
830
831 static jvmtiError SetNativeMethodPrefix(jvmtiEnv* env, const char* prefix) {
Alex Light9db679d2017-01-25 15:28:04 -0800832 ENSURE_HAS_CAP(env, can_set_native_method_prefix);
Alex Light49948e92016-08-11 15:35:28 -0700833 return ERR(NOT_IMPLEMENTED);
834 }
835
836 static jvmtiError SetNativeMethodPrefixes(jvmtiEnv* env, jint prefix_count, char** prefixes) {
Alex Light9db679d2017-01-25 15:28:04 -0800837 ENSURE_HAS_CAP(env, can_set_native_method_prefix);
Alex Light49948e92016-08-11 15:35:28 -0700838 return ERR(NOT_IMPLEMENTED);
839 }
840
841 static jvmtiError CreateRawMonitor(jvmtiEnv* env, const char* name, jrawMonitorID* monitor_ptr) {
Andreas Gampe319dbe82017-01-09 16:42:21 -0800842 return MonitorUtil::CreateRawMonitor(env, name, monitor_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700843 }
844
845 static jvmtiError DestroyRawMonitor(jvmtiEnv* env, jrawMonitorID monitor) {
Andreas Gampe319dbe82017-01-09 16:42:21 -0800846 return MonitorUtil::DestroyRawMonitor(env, monitor);
Alex Light49948e92016-08-11 15:35:28 -0700847 }
848
849 static jvmtiError RawMonitorEnter(jvmtiEnv* env, jrawMonitorID monitor) {
Andreas Gampe319dbe82017-01-09 16:42:21 -0800850 return MonitorUtil::RawMonitorEnter(env, monitor);
Alex Light49948e92016-08-11 15:35:28 -0700851 }
852
853 static jvmtiError RawMonitorExit(jvmtiEnv* env, jrawMonitorID monitor) {
Andreas Gampe319dbe82017-01-09 16:42:21 -0800854 return MonitorUtil::RawMonitorExit(env, monitor);
Alex Light49948e92016-08-11 15:35:28 -0700855 }
856
857 static jvmtiError RawMonitorWait(jvmtiEnv* env, jrawMonitorID monitor, jlong millis) {
Andreas Gampe319dbe82017-01-09 16:42:21 -0800858 return MonitorUtil::RawMonitorWait(env, monitor, millis);
Alex Light49948e92016-08-11 15:35:28 -0700859 }
860
861 static jvmtiError RawMonitorNotify(jvmtiEnv* env, jrawMonitorID monitor) {
Andreas Gampe319dbe82017-01-09 16:42:21 -0800862 return MonitorUtil::RawMonitorNotify(env, monitor);
Alex Light49948e92016-08-11 15:35:28 -0700863 }
864
865 static jvmtiError RawMonitorNotifyAll(jvmtiEnv* env, jrawMonitorID monitor) {
Andreas Gampe319dbe82017-01-09 16:42:21 -0800866 return MonitorUtil::RawMonitorNotifyAll(env, monitor);
Alex Light49948e92016-08-11 15:35:28 -0700867 }
868
869 static jvmtiError SetJNIFunctionTable(jvmtiEnv* env, const jniNativeInterface* function_table) {
Andreas Gampe6f8e4f02017-01-16 18:18:14 -0800870 return JNIUtil::SetJNIFunctionTable(env, function_table);
Alex Light49948e92016-08-11 15:35:28 -0700871 }
872
873 static jvmtiError GetJNIFunctionTable(jvmtiEnv* env, jniNativeInterface** function_table) {
Andreas Gampe6f8e4f02017-01-16 18:18:14 -0800874 return JNIUtil::GetJNIFunctionTable(env, function_table);
Alex Light49948e92016-08-11 15:35:28 -0700875 }
876
Andreas Gampe77708d92016-10-07 11:48:21 -0700877 // TODO: This will require locking, so that an agent can't remove callbacks when we're dispatching
878 // an event.
Alex Light49948e92016-08-11 15:35:28 -0700879 static jvmtiError SetEventCallbacks(jvmtiEnv* env,
880 const jvmtiEventCallbacks* callbacks,
881 jint size_of_callbacks) {
Alex Lighte6574242016-08-17 09:56:24 -0700882 ENSURE_VALID_ENV(env);
Andreas Gampe77708d92016-10-07 11:48:21 -0700883 if (size_of_callbacks < 0) {
884 return ERR(ILLEGAL_ARGUMENT);
885 }
886
887 if (callbacks == nullptr) {
888 ArtJvmTiEnv::AsArtJvmTiEnv(env)->event_callbacks.reset();
889 return ERR(NONE);
890 }
891
892 std::unique_ptr<jvmtiEventCallbacks> tmp(new jvmtiEventCallbacks());
893 memset(tmp.get(), 0, sizeof(jvmtiEventCallbacks));
894 size_t copy_size = std::min(sizeof(jvmtiEventCallbacks),
895 static_cast<size_t>(size_of_callbacks));
896 copy_size = art::RoundDown(copy_size, sizeof(void*));
897 memcpy(tmp.get(), callbacks, copy_size);
898
899 ArtJvmTiEnv::AsArtJvmTiEnv(env)->event_callbacks = std::move(tmp);
900
901 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -0700902 }
903
904 static jvmtiError SetEventNotificationMode(jvmtiEnv* env,
905 jvmtiEventMode mode,
906 jvmtiEvent event_type,
907 jthread event_thread,
908 ...) {
Alex Lighte6574242016-08-17 09:56:24 -0700909 ENSURE_VALID_ENV(env);
Andreas Gampe77708d92016-10-07 11:48:21 -0700910 art::Thread* art_thread = nullptr;
911 if (event_thread != nullptr) {
912 // TODO: Need non-aborting call here, to return JVMTI_ERROR_INVALID_THREAD.
913 art::ScopedObjectAccess soa(art::Thread::Current());
914 art::MutexLock mu(soa.Self(), *art::Locks::thread_list_lock_);
915 art_thread = art::Thread::FromManagedThread(soa, event_thread);
916
917 if (art_thread == nullptr || // The thread hasn't been started or is already dead.
918 art_thread->IsStillStarting()) {
919 // TODO: We may want to let the EventHandler know, so it could clean up masks, potentially.
920 return ERR(THREAD_NOT_ALIVE);
921 }
922 }
923
Alex Light40d87f42017-01-18 10:27:06 -0800924 ArtJvmTiEnv* art_env = ArtJvmTiEnv::AsArtJvmTiEnv(env);
925 return gEventHandler.SetEvent(art_env, art_thread, GetArtJvmtiEvent(art_env, event_type), mode);
Alex Light49948e92016-08-11 15:35:28 -0700926 }
927
928 static jvmtiError GenerateEvents(jvmtiEnv* env, jvmtiEvent event_type) {
929 return ERR(NOT_IMPLEMENTED);
930 }
931
932 static jvmtiError GetExtensionFunctions(jvmtiEnv* env,
933 jint* extension_count_ptr,
934 jvmtiExtensionFunctionInfo** extensions) {
Andreas Gampee4c33842017-01-09 10:50:17 -0800935 // We do not have any extension functions.
936 *extension_count_ptr = 0;
937 *extensions = nullptr;
938
939 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -0700940 }
941
942 static jvmtiError GetExtensionEvents(jvmtiEnv* env,
943 jint* extension_count_ptr,
944 jvmtiExtensionEventInfo** extensions) {
Andreas Gampee4c33842017-01-09 10:50:17 -0800945 // We do not have any extension events.
946 *extension_count_ptr = 0;
947 *extensions = nullptr;
948
949 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -0700950 }
951
952 static jvmtiError SetExtensionEventCallback(jvmtiEnv* env,
953 jint extension_event_index,
954 jvmtiExtensionEvent callback) {
Andreas Gampee4c33842017-01-09 10:50:17 -0800955 // We do not have any extension events, so any call is illegal.
956 return ERR(ILLEGAL_ARGUMENT);
Alex Light49948e92016-08-11 15:35:28 -0700957 }
958
959 static jvmtiError GetPotentialCapabilities(jvmtiEnv* env, jvmtiCapabilities* capabilities_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -0700960 ENSURE_VALID_ENV(env);
961 ENSURE_NON_NULL(capabilities_ptr);
962 *capabilities_ptr = kPotentialCapabilities;
963 return OK;
Alex Light49948e92016-08-11 15:35:28 -0700964 }
965
966 static jvmtiError AddCapabilities(jvmtiEnv* env, const jvmtiCapabilities* capabilities_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -0700967 ENSURE_VALID_ENV(env);
968 ENSURE_NON_NULL(capabilities_ptr);
969 ArtJvmTiEnv* art_env = static_cast<ArtJvmTiEnv*>(env);
970 jvmtiError ret = OK;
Alex Light73afd322017-01-18 11:17:47 -0800971 jvmtiCapabilities changed;
Alex Lighte6574242016-08-17 09:56:24 -0700972#define ADD_CAPABILITY(e) \
973 do { \
974 if (capabilities_ptr->e == 1) { \
975 if (kPotentialCapabilities.e == 1) { \
Alex Light73afd322017-01-18 11:17:47 -0800976 if (art_env->capabilities.e != 1) { \
977 art_env->capabilities.e = 1; \
978 changed.e = 1; \
979 }\
Alex Lighte6574242016-08-17 09:56:24 -0700980 } else { \
981 ret = ERR(NOT_AVAILABLE); \
982 } \
983 } \
984 } while (false)
985
986 ADD_CAPABILITY(can_tag_objects);
987 ADD_CAPABILITY(can_generate_field_modification_events);
988 ADD_CAPABILITY(can_generate_field_access_events);
989 ADD_CAPABILITY(can_get_bytecodes);
990 ADD_CAPABILITY(can_get_synthetic_attribute);
991 ADD_CAPABILITY(can_get_owned_monitor_info);
992 ADD_CAPABILITY(can_get_current_contended_monitor);
993 ADD_CAPABILITY(can_get_monitor_info);
994 ADD_CAPABILITY(can_pop_frame);
995 ADD_CAPABILITY(can_redefine_classes);
996 ADD_CAPABILITY(can_signal_thread);
997 ADD_CAPABILITY(can_get_source_file_name);
998 ADD_CAPABILITY(can_get_line_numbers);
999 ADD_CAPABILITY(can_get_source_debug_extension);
1000 ADD_CAPABILITY(can_access_local_variables);
1001 ADD_CAPABILITY(can_maintain_original_method_order);
1002 ADD_CAPABILITY(can_generate_single_step_events);
1003 ADD_CAPABILITY(can_generate_exception_events);
1004 ADD_CAPABILITY(can_generate_frame_pop_events);
1005 ADD_CAPABILITY(can_generate_breakpoint_events);
1006 ADD_CAPABILITY(can_suspend);
1007 ADD_CAPABILITY(can_redefine_any_class);
1008 ADD_CAPABILITY(can_get_current_thread_cpu_time);
1009 ADD_CAPABILITY(can_get_thread_cpu_time);
1010 ADD_CAPABILITY(can_generate_method_entry_events);
1011 ADD_CAPABILITY(can_generate_method_exit_events);
1012 ADD_CAPABILITY(can_generate_all_class_hook_events);
1013 ADD_CAPABILITY(can_generate_compiled_method_load_events);
1014 ADD_CAPABILITY(can_generate_monitor_events);
1015 ADD_CAPABILITY(can_generate_vm_object_alloc_events);
1016 ADD_CAPABILITY(can_generate_native_method_bind_events);
1017 ADD_CAPABILITY(can_generate_garbage_collection_events);
1018 ADD_CAPABILITY(can_generate_object_free_events);
1019 ADD_CAPABILITY(can_force_early_return);
1020 ADD_CAPABILITY(can_get_owned_monitor_stack_depth_info);
1021 ADD_CAPABILITY(can_get_constant_pool);
1022 ADD_CAPABILITY(can_set_native_method_prefix);
1023 ADD_CAPABILITY(can_retransform_classes);
1024 ADD_CAPABILITY(can_retransform_any_class);
1025 ADD_CAPABILITY(can_generate_resource_exhaustion_heap_events);
1026 ADD_CAPABILITY(can_generate_resource_exhaustion_threads_events);
1027#undef ADD_CAPABILITY
Alex Light73afd322017-01-18 11:17:47 -08001028 gEventHandler.HandleChangedCapabilities(ArtJvmTiEnv::AsArtJvmTiEnv(env),
1029 changed,
1030 /*added*/true);
Alex Lighte6574242016-08-17 09:56:24 -07001031 return ret;
Alex Light49948e92016-08-11 15:35:28 -07001032 }
1033
1034 static jvmtiError RelinquishCapabilities(jvmtiEnv* env,
1035 const jvmtiCapabilities* capabilities_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001036 ENSURE_VALID_ENV(env);
1037 ENSURE_NON_NULL(capabilities_ptr);
1038 ArtJvmTiEnv* art_env = reinterpret_cast<ArtJvmTiEnv*>(env);
Alex Light73afd322017-01-18 11:17:47 -08001039 jvmtiCapabilities changed;
Alex Lighte6574242016-08-17 09:56:24 -07001040#define DEL_CAPABILITY(e) \
1041 do { \
1042 if (capabilities_ptr->e == 1) { \
Alex Light73afd322017-01-18 11:17:47 -08001043 if (art_env->capabilities.e == 1) { \
1044 art_env->capabilities.e = 0;\
1045 changed.e = 1; \
1046 } \
Alex Lighte6574242016-08-17 09:56:24 -07001047 } \
1048 } while (false)
1049
1050 DEL_CAPABILITY(can_tag_objects);
1051 DEL_CAPABILITY(can_generate_field_modification_events);
1052 DEL_CAPABILITY(can_generate_field_access_events);
1053 DEL_CAPABILITY(can_get_bytecodes);
1054 DEL_CAPABILITY(can_get_synthetic_attribute);
1055 DEL_CAPABILITY(can_get_owned_monitor_info);
1056 DEL_CAPABILITY(can_get_current_contended_monitor);
1057 DEL_CAPABILITY(can_get_monitor_info);
1058 DEL_CAPABILITY(can_pop_frame);
1059 DEL_CAPABILITY(can_redefine_classes);
1060 DEL_CAPABILITY(can_signal_thread);
1061 DEL_CAPABILITY(can_get_source_file_name);
1062 DEL_CAPABILITY(can_get_line_numbers);
1063 DEL_CAPABILITY(can_get_source_debug_extension);
1064 DEL_CAPABILITY(can_access_local_variables);
1065 DEL_CAPABILITY(can_maintain_original_method_order);
1066 DEL_CAPABILITY(can_generate_single_step_events);
1067 DEL_CAPABILITY(can_generate_exception_events);
1068 DEL_CAPABILITY(can_generate_frame_pop_events);
1069 DEL_CAPABILITY(can_generate_breakpoint_events);
1070 DEL_CAPABILITY(can_suspend);
1071 DEL_CAPABILITY(can_redefine_any_class);
1072 DEL_CAPABILITY(can_get_current_thread_cpu_time);
1073 DEL_CAPABILITY(can_get_thread_cpu_time);
1074 DEL_CAPABILITY(can_generate_method_entry_events);
1075 DEL_CAPABILITY(can_generate_method_exit_events);
1076 DEL_CAPABILITY(can_generate_all_class_hook_events);
1077 DEL_CAPABILITY(can_generate_compiled_method_load_events);
1078 DEL_CAPABILITY(can_generate_monitor_events);
1079 DEL_CAPABILITY(can_generate_vm_object_alloc_events);
1080 DEL_CAPABILITY(can_generate_native_method_bind_events);
1081 DEL_CAPABILITY(can_generate_garbage_collection_events);
1082 DEL_CAPABILITY(can_generate_object_free_events);
1083 DEL_CAPABILITY(can_force_early_return);
1084 DEL_CAPABILITY(can_get_owned_monitor_stack_depth_info);
1085 DEL_CAPABILITY(can_get_constant_pool);
1086 DEL_CAPABILITY(can_set_native_method_prefix);
1087 DEL_CAPABILITY(can_retransform_classes);
1088 DEL_CAPABILITY(can_retransform_any_class);
1089 DEL_CAPABILITY(can_generate_resource_exhaustion_heap_events);
1090 DEL_CAPABILITY(can_generate_resource_exhaustion_threads_events);
1091#undef DEL_CAPABILITY
Alex Light73afd322017-01-18 11:17:47 -08001092 gEventHandler.HandleChangedCapabilities(ArtJvmTiEnv::AsArtJvmTiEnv(env),
1093 changed,
1094 /*added*/false);
Alex Lighte6574242016-08-17 09:56:24 -07001095 return OK;
Alex Light49948e92016-08-11 15:35:28 -07001096 }
1097
1098 static jvmtiError GetCapabilities(jvmtiEnv* env, jvmtiCapabilities* capabilities_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001099 ENSURE_VALID_ENV(env);
1100 ENSURE_NON_NULL(capabilities_ptr);
1101 ArtJvmTiEnv* artenv = reinterpret_cast<ArtJvmTiEnv*>(env);
1102 *capabilities_ptr = artenv->capabilities;
1103 return OK;
Alex Light49948e92016-08-11 15:35:28 -07001104 }
1105
1106 static jvmtiError GetCurrentThreadCpuTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -08001107 ENSURE_HAS_CAP(env, can_get_current_thread_cpu_time);
Alex Light49948e92016-08-11 15:35:28 -07001108 return ERR(NOT_IMPLEMENTED);
1109 }
1110
1111 static jvmtiError GetCurrentThreadCpuTime(jvmtiEnv* env, jlong* nanos_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -08001112 ENSURE_HAS_CAP(env, can_get_current_thread_cpu_time);
Alex Light49948e92016-08-11 15:35:28 -07001113 return ERR(NOT_IMPLEMENTED);
1114 }
1115
1116 static jvmtiError GetThreadCpuTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -08001117 ENSURE_HAS_CAP(env, can_get_thread_cpu_time);
Alex Light49948e92016-08-11 15:35:28 -07001118 return ERR(NOT_IMPLEMENTED);
1119 }
1120
1121 static jvmtiError GetThreadCpuTime(jvmtiEnv* env, jthread thread, jlong* nanos_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -08001122 ENSURE_HAS_CAP(env, can_get_thread_cpu_time);
Alex Light49948e92016-08-11 15:35:28 -07001123 return ERR(NOT_IMPLEMENTED);
1124 }
1125
1126 static jvmtiError GetTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr) {
Andreas Gampe35bcf812017-01-13 16:24:17 -08001127 return TimerUtil::GetTimerInfo(env, info_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001128 }
1129
1130 static jvmtiError GetTime(jvmtiEnv* env, jlong* nanos_ptr) {
Andreas Gampe35bcf812017-01-13 16:24:17 -08001131 return TimerUtil::GetTime(env, nanos_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001132 }
1133
1134 static jvmtiError GetAvailableProcessors(jvmtiEnv* env, jint* processor_count_ptr) {
Andreas Gampe35bcf812017-01-13 16:24:17 -08001135 return TimerUtil::GetAvailableProcessors(env, processor_count_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001136 }
1137
1138 static jvmtiError AddToBootstrapClassLoaderSearch(jvmtiEnv* env, const char* segment) {
Andreas Gampece7732b2017-01-17 15:50:26 -08001139 return SearchUtil::AddToBootstrapClassLoaderSearch(env, segment);
Alex Light49948e92016-08-11 15:35:28 -07001140 }
1141
1142 static jvmtiError AddToSystemClassLoaderSearch(jvmtiEnv* env, const char* segment) {
Andreas Gampece7732b2017-01-17 15:50:26 -08001143 return SearchUtil::AddToSystemClassLoaderSearch(env, segment);
Alex Light49948e92016-08-11 15:35:28 -07001144 }
1145
1146 static jvmtiError GetSystemProperties(jvmtiEnv* env, jint* count_ptr, char*** property_ptr) {
Andreas Gampe1bdaf732017-01-09 19:21:06 -08001147 return PropertiesUtil::GetSystemProperties(env, count_ptr, property_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001148 }
1149
1150 static jvmtiError GetSystemProperty(jvmtiEnv* env, const char* property, char** value_ptr) {
Andreas Gampe1bdaf732017-01-09 19:21:06 -08001151 return PropertiesUtil::GetSystemProperty(env, property, value_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001152 }
1153
1154 static jvmtiError SetSystemProperty(jvmtiEnv* env, const char* property, const char* value) {
Andreas Gampe1bdaf732017-01-09 19:21:06 -08001155 return PropertiesUtil::SetSystemProperty(env, property, value);
Alex Light49948e92016-08-11 15:35:28 -07001156 }
1157
1158 static jvmtiError GetPhase(jvmtiEnv* env, jvmtiPhase* phase_ptr) {
Andreas Gampe96eca782017-01-19 19:45:30 -08001159 return PhaseUtil::GetPhase(env, phase_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001160 }
1161
1162 static jvmtiError DisposeEnvironment(jvmtiEnv* env) {
Alex Lighte6574242016-08-17 09:56:24 -07001163 ENSURE_VALID_ENV(env);
Andreas Gampe3a7eb142017-01-19 21:59:22 -08001164 gEventHandler.RemoveArtJvmTiEnv(ArtJvmTiEnv::AsArtJvmTiEnv(env));
Alex Light49948e92016-08-11 15:35:28 -07001165 delete env;
1166 return OK;
1167 }
1168
1169 static jvmtiError SetEnvironmentLocalStorage(jvmtiEnv* env, const void* data) {
Alex Lighte6574242016-08-17 09:56:24 -07001170 ENSURE_VALID_ENV(env);
Alex Light49948e92016-08-11 15:35:28 -07001171 reinterpret_cast<ArtJvmTiEnv*>(env)->local_data = const_cast<void*>(data);
1172 return OK;
1173 }
1174
1175 static jvmtiError GetEnvironmentLocalStorage(jvmtiEnv* env, void** data_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001176 ENSURE_VALID_ENV(env);
Alex Light49948e92016-08-11 15:35:28 -07001177 *data_ptr = reinterpret_cast<ArtJvmTiEnv*>(env)->local_data;
1178 return OK;
1179 }
1180
1181 static jvmtiError GetVersionNumber(jvmtiEnv* env, jint* version_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001182 ENSURE_VALID_ENV(env);
Alex Light49948e92016-08-11 15:35:28 -07001183 *version_ptr = JVMTI_VERSION;
1184 return OK;
1185 }
1186
1187 static jvmtiError GetErrorName(jvmtiEnv* env, jvmtiError error, char** name_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001188 ENSURE_NON_NULL(name_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001189 switch (error) {
1190#define ERROR_CASE(e) case (JVMTI_ERROR_ ## e) : do { \
Alex Light41960712017-01-06 14:44:23 -08001191 jvmtiError res = CopyString(env, \
1192 "JVMTI_ERROR_"#e, \
1193 reinterpret_cast<unsigned char**>(name_ptr)); \
1194 if (res != OK) { \
1195 *name_ptr = nullptr; \
1196 return res; \
1197 } else { \
1198 return OK; \
1199 } \
Alex Light49948e92016-08-11 15:35:28 -07001200 } while (false)
1201 ERROR_CASE(NONE);
1202 ERROR_CASE(INVALID_THREAD);
1203 ERROR_CASE(INVALID_THREAD_GROUP);
1204 ERROR_CASE(INVALID_PRIORITY);
1205 ERROR_CASE(THREAD_NOT_SUSPENDED);
1206 ERROR_CASE(THREAD_NOT_ALIVE);
1207 ERROR_CASE(INVALID_OBJECT);
1208 ERROR_CASE(INVALID_CLASS);
1209 ERROR_CASE(CLASS_NOT_PREPARED);
1210 ERROR_CASE(INVALID_METHODID);
1211 ERROR_CASE(INVALID_LOCATION);
1212 ERROR_CASE(INVALID_FIELDID);
1213 ERROR_CASE(NO_MORE_FRAMES);
1214 ERROR_CASE(OPAQUE_FRAME);
1215 ERROR_CASE(TYPE_MISMATCH);
1216 ERROR_CASE(INVALID_SLOT);
1217 ERROR_CASE(DUPLICATE);
1218 ERROR_CASE(NOT_FOUND);
1219 ERROR_CASE(INVALID_MONITOR);
1220 ERROR_CASE(NOT_MONITOR_OWNER);
1221 ERROR_CASE(INTERRUPT);
1222 ERROR_CASE(INVALID_CLASS_FORMAT);
1223 ERROR_CASE(CIRCULAR_CLASS_DEFINITION);
1224 ERROR_CASE(FAILS_VERIFICATION);
1225 ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_ADDED);
1226 ERROR_CASE(UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED);
1227 ERROR_CASE(INVALID_TYPESTATE);
1228 ERROR_CASE(UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED);
1229 ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_DELETED);
1230 ERROR_CASE(UNSUPPORTED_VERSION);
1231 ERROR_CASE(NAMES_DONT_MATCH);
1232 ERROR_CASE(UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED);
1233 ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED);
1234 ERROR_CASE(UNMODIFIABLE_CLASS);
1235 ERROR_CASE(NOT_AVAILABLE);
1236 ERROR_CASE(MUST_POSSESS_CAPABILITY);
1237 ERROR_CASE(NULL_POINTER);
1238 ERROR_CASE(ABSENT_INFORMATION);
1239 ERROR_CASE(INVALID_EVENT_TYPE);
1240 ERROR_CASE(ILLEGAL_ARGUMENT);
1241 ERROR_CASE(NATIVE_METHOD);
1242 ERROR_CASE(CLASS_LOADER_UNSUPPORTED);
1243 ERROR_CASE(OUT_OF_MEMORY);
1244 ERROR_CASE(ACCESS_DENIED);
1245 ERROR_CASE(WRONG_PHASE);
1246 ERROR_CASE(INTERNAL);
1247 ERROR_CASE(UNATTACHED_THREAD);
1248 ERROR_CASE(INVALID_ENVIRONMENT);
1249#undef ERROR_CASE
1250 default: {
Alex Light41960712017-01-06 14:44:23 -08001251 jvmtiError res = CopyString(env,
1252 "JVMTI_ERROR_UNKNOWN",
1253 reinterpret_cast<unsigned char**>(name_ptr));
1254 if (res != OK) {
1255 *name_ptr = nullptr;
1256 return res;
1257 } else {
1258 return ERR(ILLEGAL_ARGUMENT);
1259 }
Alex Light49948e92016-08-11 15:35:28 -07001260 }
1261 }
1262 }
1263
1264 static jvmtiError SetVerboseFlag(jvmtiEnv* env, jvmtiVerboseFlag flag, jboolean value) {
Andreas Gampef37e3022017-01-13 17:54:46 -08001265 if (flag == jvmtiVerboseFlag::JVMTI_VERBOSE_OTHER) {
1266 // OTHER is special, as it's 0, so can't do a bit check.
1267 bool val = (value == JNI_TRUE) ? true : false;
1268
1269 art::gLogVerbosity.collector = val;
1270 art::gLogVerbosity.compiler = val;
1271 art::gLogVerbosity.deopt = val;
1272 art::gLogVerbosity.heap = val;
1273 art::gLogVerbosity.jdwp = val;
1274 art::gLogVerbosity.jit = val;
1275 art::gLogVerbosity.monitor = val;
1276 art::gLogVerbosity.oat = val;
1277 art::gLogVerbosity.profiler = val;
1278 art::gLogVerbosity.signals = val;
1279 art::gLogVerbosity.simulator = val;
1280 art::gLogVerbosity.startup = val;
1281 art::gLogVerbosity.third_party_jni = val;
1282 art::gLogVerbosity.threads = val;
1283 art::gLogVerbosity.verifier = val;
1284 art::gLogVerbosity.image = val;
1285
1286 // Note: can't switch systrace_lock_logging. That requires changing entrypoints.
1287
1288 art::gLogVerbosity.agents = val;
1289 } else {
1290 // Spec isn't clear whether "flag" is a mask or supposed to be single. We implement the mask
1291 // semantics.
1292 constexpr std::underlying_type<jvmtiVerboseFlag>::type kMask =
1293 jvmtiVerboseFlag::JVMTI_VERBOSE_GC |
1294 jvmtiVerboseFlag::JVMTI_VERBOSE_CLASS |
1295 jvmtiVerboseFlag::JVMTI_VERBOSE_JNI;
1296 if ((flag & ~kMask) != 0) {
1297 return ERR(ILLEGAL_ARGUMENT);
1298 }
1299
1300 bool val = (value == JNI_TRUE) ? true : false;
1301
1302 if ((flag & jvmtiVerboseFlag::JVMTI_VERBOSE_GC) != 0) {
1303 art::gLogVerbosity.gc = val;
1304 }
1305
1306 if ((flag & jvmtiVerboseFlag::JVMTI_VERBOSE_CLASS) != 0) {
1307 art::gLogVerbosity.class_linker = val;
1308 }
1309
1310 if ((flag & jvmtiVerboseFlag::JVMTI_VERBOSE_JNI) != 0) {
1311 art::gLogVerbosity.jni = val;
1312 }
1313 }
1314
1315 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -07001316 }
1317
1318 static jvmtiError GetJLocationFormat(jvmtiEnv* env, jvmtiJlocationFormat* format_ptr) {
Andreas Gampeacfc9572017-01-17 18:36:56 -08001319 // Report BCI as jlocation format. We report dex bytecode indices.
1320 if (format_ptr == nullptr) {
1321 return ERR(NULL_POINTER);
1322 }
1323 *format_ptr = jvmtiJlocationFormat::JVMTI_JLOCATION_JVMBCI;
1324 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -07001325 }
1326};
1327
1328static bool IsJvmtiVersion(jint version) {
1329 return version == JVMTI_VERSION_1 ||
1330 version == JVMTI_VERSION_1_0 ||
1331 version == JVMTI_VERSION_1_1 ||
1332 version == JVMTI_VERSION_1_2 ||
1333 version == JVMTI_VERSION;
1334}
1335
1336// Creates a jvmtiEnv and returns it with the art::ti::Env that is associated with it. new_art_ti
1337// is a pointer to the uninitialized memory for an art::ti::Env.
1338static void CreateArtJvmTiEnv(art::JavaVMExt* vm, /*out*/void** new_jvmtiEnv) {
1339 struct ArtJvmTiEnv* env = new ArtJvmTiEnv(vm);
1340 *new_jvmtiEnv = env;
Andreas Gampe77708d92016-10-07 11:48:21 -07001341
1342 gEventHandler.RegisterArtJvmTiEnv(env);
Alex Light49948e92016-08-11 15:35:28 -07001343}
1344
1345// A hook that the runtime uses to allow plugins to handle GetEnv calls. It returns true and
1346// places the return value in 'env' if this library can handle the GetEnv request. Otherwise
1347// returns false and does not modify the 'env' pointer.
1348static jint GetEnvHandler(art::JavaVMExt* vm, /*out*/void** env, jint version) {
1349 if (IsJvmtiVersion(version)) {
1350 CreateArtJvmTiEnv(vm, env);
1351 return JNI_OK;
1352 } else {
1353 printf("version 0x%x is not valid!", version);
1354 return JNI_EVERSION;
1355 }
1356}
1357
1358// The plugin initialization function. This adds the jvmti environment.
1359extern "C" bool ArtPlugin_Initialize() {
Andreas Gampee08a2be2016-10-06 13:13:30 -07001360 art::Runtime* runtime = art::Runtime::Current();
Andreas Gampe96eca782017-01-19 19:45:30 -08001361
1362 if (runtime->IsStarted()) {
1363 PhaseUtil::SetToLive();
1364 } else {
1365 PhaseUtil::SetToOnLoad();
1366 }
Andreas Gampe3a7eb142017-01-19 21:59:22 -08001367 PhaseUtil::Register(&gEventHandler);
Andreas Gampeeafaf572017-01-20 12:34:15 -08001368 ThreadUtil::Register(&gEventHandler);
Andreas Gampee6377462017-01-20 17:37:50 -08001369 ClassUtil::Register(&gEventHandler);
Andreas Gampeeb0cea12017-01-23 08:50:04 -08001370 DumpUtil::Register(&gEventHandler);
Andreas Gampecefaa142017-01-23 15:04:59 -08001371 SearchUtil::Register();
Andreas Gampe96eca782017-01-19 19:45:30 -08001372
Andreas Gampee08a2be2016-10-06 13:13:30 -07001373 runtime->GetJavaVM()->AddEnvironmentHook(GetEnvHandler);
1374 runtime->AddSystemWeakHolder(&gObjectTagTable);
Andreas Gampe96eca782017-01-19 19:45:30 -08001375
Alex Light49948e92016-08-11 15:35:28 -07001376 return true;
1377}
1378
Andreas Gampeeafaf572017-01-20 12:34:15 -08001379extern "C" bool ArtPlugin_Deinitialize() {
1380 PhaseUtil::Unregister();
1381 ThreadUtil::Unregister();
Andreas Gampee6377462017-01-20 17:37:50 -08001382 ClassUtil::Unregister();
Andreas Gampeeb0cea12017-01-23 08:50:04 -08001383 DumpUtil::Unregister();
Andreas Gampecefaa142017-01-23 15:04:59 -08001384 SearchUtil::Unregister();
Andreas Gampeeafaf572017-01-20 12:34:15 -08001385
1386 return true;
1387}
1388
Alex Light49948e92016-08-11 15:35:28 -07001389// The actual struct holding all of the entrypoints into the jvmti interface.
1390const jvmtiInterface_1 gJvmtiInterface = {
Alex Light6ac57502017-01-19 15:05:06 -08001391 nullptr, // reserved1
Alex Light49948e92016-08-11 15:35:28 -07001392 JvmtiFunctions::SetEventNotificationMode,
Alex Light0e692732017-01-10 15:00:05 -08001393 nullptr, // reserved3
Alex Light49948e92016-08-11 15:35:28 -07001394 JvmtiFunctions::GetAllThreads,
1395 JvmtiFunctions::SuspendThread,
1396 JvmtiFunctions::ResumeThread,
1397 JvmtiFunctions::StopThread,
1398 JvmtiFunctions::InterruptThread,
1399 JvmtiFunctions::GetThreadInfo,
1400 JvmtiFunctions::GetOwnedMonitorInfo, // 10
1401 JvmtiFunctions::GetCurrentContendedMonitor,
1402 JvmtiFunctions::RunAgentThread,
1403 JvmtiFunctions::GetTopThreadGroups,
1404 JvmtiFunctions::GetThreadGroupInfo,
1405 JvmtiFunctions::GetThreadGroupChildren,
1406 JvmtiFunctions::GetFrameCount,
1407 JvmtiFunctions::GetThreadState,
1408 JvmtiFunctions::GetCurrentThread,
1409 JvmtiFunctions::GetFrameLocation,
1410 JvmtiFunctions::NotifyFramePop, // 20
1411 JvmtiFunctions::GetLocalObject,
1412 JvmtiFunctions::GetLocalInt,
1413 JvmtiFunctions::GetLocalLong,
1414 JvmtiFunctions::GetLocalFloat,
1415 JvmtiFunctions::GetLocalDouble,
1416 JvmtiFunctions::SetLocalObject,
1417 JvmtiFunctions::SetLocalInt,
1418 JvmtiFunctions::SetLocalLong,
1419 JvmtiFunctions::SetLocalFloat,
1420 JvmtiFunctions::SetLocalDouble, // 30
1421 JvmtiFunctions::CreateRawMonitor,
1422 JvmtiFunctions::DestroyRawMonitor,
1423 JvmtiFunctions::RawMonitorEnter,
1424 JvmtiFunctions::RawMonitorExit,
1425 JvmtiFunctions::RawMonitorWait,
1426 JvmtiFunctions::RawMonitorNotify,
1427 JvmtiFunctions::RawMonitorNotifyAll,
1428 JvmtiFunctions::SetBreakpoint,
1429 JvmtiFunctions::ClearBreakpoint,
1430 nullptr, // reserved40
1431 JvmtiFunctions::SetFieldAccessWatch,
1432 JvmtiFunctions::ClearFieldAccessWatch,
1433 JvmtiFunctions::SetFieldModificationWatch,
1434 JvmtiFunctions::ClearFieldModificationWatch,
1435 JvmtiFunctions::IsModifiableClass,
1436 JvmtiFunctions::Allocate,
1437 JvmtiFunctions::Deallocate,
1438 JvmtiFunctions::GetClassSignature,
1439 JvmtiFunctions::GetClassStatus,
1440 JvmtiFunctions::GetSourceFileName, // 50
1441 JvmtiFunctions::GetClassModifiers,
1442 JvmtiFunctions::GetClassMethods,
1443 JvmtiFunctions::GetClassFields,
1444 JvmtiFunctions::GetImplementedInterfaces,
1445 JvmtiFunctions::IsInterface,
1446 JvmtiFunctions::IsArrayClass,
1447 JvmtiFunctions::GetClassLoader,
1448 JvmtiFunctions::GetObjectHashCode,
1449 JvmtiFunctions::GetObjectMonitorUsage,
1450 JvmtiFunctions::GetFieldName, // 60
1451 JvmtiFunctions::GetFieldDeclaringClass,
1452 JvmtiFunctions::GetFieldModifiers,
1453 JvmtiFunctions::IsFieldSynthetic,
1454 JvmtiFunctions::GetMethodName,
1455 JvmtiFunctions::GetMethodDeclaringClass,
1456 JvmtiFunctions::GetMethodModifiers,
1457 nullptr, // reserved67
1458 JvmtiFunctions::GetMaxLocals,
1459 JvmtiFunctions::GetArgumentsSize,
1460 JvmtiFunctions::GetLineNumberTable, // 70
1461 JvmtiFunctions::GetMethodLocation,
1462 JvmtiFunctions::GetLocalVariableTable,
1463 JvmtiFunctions::SetNativeMethodPrefix,
1464 JvmtiFunctions::SetNativeMethodPrefixes,
1465 JvmtiFunctions::GetBytecodes,
1466 JvmtiFunctions::IsMethodNative,
1467 JvmtiFunctions::IsMethodSynthetic,
1468 JvmtiFunctions::GetLoadedClasses,
1469 JvmtiFunctions::GetClassLoaderClasses,
1470 JvmtiFunctions::PopFrame, // 80
1471 JvmtiFunctions::ForceEarlyReturnObject,
1472 JvmtiFunctions::ForceEarlyReturnInt,
1473 JvmtiFunctions::ForceEarlyReturnLong,
1474 JvmtiFunctions::ForceEarlyReturnFloat,
1475 JvmtiFunctions::ForceEarlyReturnDouble,
1476 JvmtiFunctions::ForceEarlyReturnVoid,
1477 JvmtiFunctions::RedefineClasses,
1478 JvmtiFunctions::GetVersionNumber,
1479 JvmtiFunctions::GetCapabilities,
1480 JvmtiFunctions::GetSourceDebugExtension, // 90
1481 JvmtiFunctions::IsMethodObsolete,
1482 JvmtiFunctions::SuspendThreadList,
1483 JvmtiFunctions::ResumeThreadList,
1484 nullptr, // reserved94
1485 nullptr, // reserved95
1486 nullptr, // reserved96
1487 nullptr, // reserved97
1488 nullptr, // reserved98
1489 nullptr, // reserved99
1490 JvmtiFunctions::GetAllStackTraces, // 100
1491 JvmtiFunctions::GetThreadListStackTraces,
1492 JvmtiFunctions::GetThreadLocalStorage,
1493 JvmtiFunctions::SetThreadLocalStorage,
1494 JvmtiFunctions::GetStackTrace,
1495 nullptr, // reserved105
1496 JvmtiFunctions::GetTag,
1497 JvmtiFunctions::SetTag,
1498 JvmtiFunctions::ForceGarbageCollection,
1499 JvmtiFunctions::IterateOverObjectsReachableFromObject,
1500 JvmtiFunctions::IterateOverReachableObjects, // 110
1501 JvmtiFunctions::IterateOverHeap,
1502 JvmtiFunctions::IterateOverInstancesOfClass,
1503 nullptr, // reserved113
1504 JvmtiFunctions::GetObjectsWithTags,
1505 JvmtiFunctions::FollowReferences,
1506 JvmtiFunctions::IterateThroughHeap,
1507 nullptr, // reserved117
1508 nullptr, // reserved118
1509 nullptr, // reserved119
1510 JvmtiFunctions::SetJNIFunctionTable, // 120
1511 JvmtiFunctions::GetJNIFunctionTable,
1512 JvmtiFunctions::SetEventCallbacks,
1513 JvmtiFunctions::GenerateEvents,
1514 JvmtiFunctions::GetExtensionFunctions,
1515 JvmtiFunctions::GetExtensionEvents,
1516 JvmtiFunctions::SetExtensionEventCallback,
1517 JvmtiFunctions::DisposeEnvironment,
1518 JvmtiFunctions::GetErrorName,
1519 JvmtiFunctions::GetJLocationFormat,
1520 JvmtiFunctions::GetSystemProperties, // 130
1521 JvmtiFunctions::GetSystemProperty,
1522 JvmtiFunctions::SetSystemProperty,
1523 JvmtiFunctions::GetPhase,
1524 JvmtiFunctions::GetCurrentThreadCpuTimerInfo,
1525 JvmtiFunctions::GetCurrentThreadCpuTime,
1526 JvmtiFunctions::GetThreadCpuTimerInfo,
1527 JvmtiFunctions::GetThreadCpuTime,
1528 JvmtiFunctions::GetTimerInfo,
1529 JvmtiFunctions::GetTime,
1530 JvmtiFunctions::GetPotentialCapabilities, // 140
1531 nullptr, // reserved141
1532 JvmtiFunctions::AddCapabilities,
1533 JvmtiFunctions::RelinquishCapabilities,
1534 JvmtiFunctions::GetAvailableProcessors,
1535 JvmtiFunctions::GetClassVersionNumbers,
1536 JvmtiFunctions::GetConstantPool,
1537 JvmtiFunctions::GetEnvironmentLocalStorage,
1538 JvmtiFunctions::SetEnvironmentLocalStorage,
1539 JvmtiFunctions::AddToBootstrapClassLoaderSearch,
1540 JvmtiFunctions::SetVerboseFlag, // 150
1541 JvmtiFunctions::AddToSystemClassLoaderSearch,
1542 JvmtiFunctions::RetransformClasses,
1543 JvmtiFunctions::GetOwnedMonitorStackDepthInfo,
1544 JvmtiFunctions::GetObjectSize,
1545 JvmtiFunctions::GetLocalInstance,
1546};
1547
1548}; // namespace openjdkjvmti