blob: 450b6b6bcf224638c3404e4d6f884bcd6916ce22 [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 Gampe6dee92e2016-09-12 19:58:13 -070076
Alex Lighte6574242016-08-17 09:56:24 -070077#define ENSURE_NON_NULL(n) \
78 do { \
79 if ((n) == nullptr) { \
80 return ERR(NULL_POINTER); \
81 } \
82 } while (false)
83
Alex Light49948e92016-08-11 15:35:28 -070084class JvmtiFunctions {
85 private:
86 static bool IsValidEnv(jvmtiEnv* env) {
87 return env != nullptr;
88 }
89
Alex Lighte6574242016-08-17 09:56:24 -070090#define ENSURE_VALID_ENV(env) \
91 do { \
92 if (!IsValidEnv(env)) { \
93 return ERR(INVALID_ENVIRONMENT); \
94 } \
95 } while (false)
96
97#define ENSURE_HAS_CAP(env, cap) \
98 do { \
99 ENSURE_VALID_ENV(env); \
100 if (ArtJvmTiEnv::AsArtJvmTiEnv(env)->capabilities.cap != 1) { \
101 return ERR(MUST_POSSESS_CAPABILITY); \
102 } \
103 } while (false)
104
Alex Light49948e92016-08-11 15:35:28 -0700105 public:
106 static jvmtiError Allocate(jvmtiEnv* env, jlong size, unsigned char** mem_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -0700107 ENSURE_VALID_ENV(env);
108 ENSURE_NON_NULL(mem_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700109 if (size < 0) {
110 return ERR(ILLEGAL_ARGUMENT);
111 } else if (size == 0) {
112 *mem_ptr = nullptr;
113 return OK;
114 }
115 *mem_ptr = static_cast<unsigned char*>(malloc(size));
116 return (*mem_ptr != nullptr) ? OK : ERR(OUT_OF_MEMORY);
117 }
118
119 static jvmtiError Deallocate(jvmtiEnv* env, unsigned char* mem) {
Alex Lighte6574242016-08-17 09:56:24 -0700120 ENSURE_VALID_ENV(env);
Alex Light49948e92016-08-11 15:35:28 -0700121 if (mem != nullptr) {
122 free(mem);
123 }
124 return OK;
125 }
126
127 static jvmtiError GetThreadState(jvmtiEnv* env, jthread thread, jint* thread_state_ptr) {
Andreas Gampe72c19832017-01-12 13:22:16 -0800128 return ThreadUtil::GetThreadState(env, thread, thread_state_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700129 }
130
131 static jvmtiError GetCurrentThread(jvmtiEnv* env, jthread* thread_ptr) {
Andreas Gampeaf13ab92017-01-11 20:57:40 -0800132 return ThreadUtil::GetCurrentThread(env, thread_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700133 }
134
135 static jvmtiError GetAllThreads(jvmtiEnv* env, jint* threads_count_ptr, jthread** threads_ptr) {
Andreas Gampe85807442017-01-13 14:40:58 -0800136 return ThreadUtil::GetAllThreads(env, threads_count_ptr, threads_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700137 }
138
139 static jvmtiError SuspendThread(jvmtiEnv* env, jthread thread) {
Alex Light9db679d2017-01-25 15:28:04 -0800140 ENSURE_HAS_CAP(env, can_suspend);
Alex Light49948e92016-08-11 15:35:28 -0700141 return ERR(NOT_IMPLEMENTED);
142 }
143
144 static jvmtiError SuspendThreadList(jvmtiEnv* env,
145 jint request_count,
146 const jthread* request_list,
147 jvmtiError* results) {
Alex Light9db679d2017-01-25 15:28:04 -0800148 ENSURE_HAS_CAP(env, can_suspend);
Alex Light49948e92016-08-11 15:35:28 -0700149 return ERR(NOT_IMPLEMENTED);
150 }
151
152 static jvmtiError ResumeThread(jvmtiEnv* env, jthread thread) {
Alex Light9db679d2017-01-25 15:28:04 -0800153 ENSURE_HAS_CAP(env, can_suspend);
Alex Light49948e92016-08-11 15:35:28 -0700154 return ERR(NOT_IMPLEMENTED);
155 }
156
157 static jvmtiError ResumeThreadList(jvmtiEnv* env,
158 jint request_count,
159 const jthread* request_list,
160 jvmtiError* results) {
Alex Light9db679d2017-01-25 15:28:04 -0800161 ENSURE_HAS_CAP(env, can_suspend);
Alex Light49948e92016-08-11 15:35:28 -0700162 return ERR(NOT_IMPLEMENTED);
163 }
164
165 static jvmtiError StopThread(jvmtiEnv* env, jthread thread, jobject exception) {
Alex Light9db679d2017-01-25 15:28:04 -0800166 ENSURE_HAS_CAP(env, can_signal_thread);
Alex Light49948e92016-08-11 15:35:28 -0700167 return ERR(NOT_IMPLEMENTED);
168 }
169
170 static jvmtiError InterruptThread(jvmtiEnv* env, jthread thread) {
Alex Light9db679d2017-01-25 15:28:04 -0800171 ENSURE_HAS_CAP(env, can_signal_thread);
Alex Light49948e92016-08-11 15:35:28 -0700172 return ERR(NOT_IMPLEMENTED);
173 }
174
175 static jvmtiError GetThreadInfo(jvmtiEnv* env, jthread thread, jvmtiThreadInfo* info_ptr) {
Andreas Gampeaf13ab92017-01-11 20:57:40 -0800176 return ThreadUtil::GetThreadInfo(env, thread, info_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700177 }
178
179 static jvmtiError GetOwnedMonitorInfo(jvmtiEnv* env,
180 jthread thread,
181 jint* owned_monitor_count_ptr,
182 jobject** owned_monitors_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800183 ENSURE_HAS_CAP(env, can_get_owned_monitor_info);
Alex Light49948e92016-08-11 15:35:28 -0700184 return ERR(NOT_IMPLEMENTED);
185 }
186
187 static jvmtiError GetOwnedMonitorStackDepthInfo(jvmtiEnv* env,
188 jthread thread,
189 jint* monitor_info_count_ptr,
190 jvmtiMonitorStackDepthInfo** monitor_info_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800191 ENSURE_HAS_CAP(env, can_get_owned_monitor_stack_depth_info);
Alex Light49948e92016-08-11 15:35:28 -0700192 return ERR(NOT_IMPLEMENTED);
193 }
194
195 static jvmtiError GetCurrentContendedMonitor(jvmtiEnv* env,
196 jthread thread,
197 jobject* monitor_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800198 ENSURE_HAS_CAP(env, can_get_current_contended_monitor);
Alex Lighte6574242016-08-17 09:56:24 -0700199 return ERR(NOT_IMPLEMENTED);
Alex Light49948e92016-08-11 15:35:28 -0700200 }
201
202 static jvmtiError RunAgentThread(jvmtiEnv* env,
203 jthread thread,
204 jvmtiStartFunction proc,
205 const void* arg,
206 jint priority) {
Andreas Gampe732b0ac2017-01-18 15:23:39 -0800207 return ThreadUtil::RunAgentThread(env, thread, proc, arg, priority);
Alex Light49948e92016-08-11 15:35:28 -0700208 }
209
210 static jvmtiError SetThreadLocalStorage(jvmtiEnv* env, jthread thread, const void* data) {
Andreas Gampe7b3b3262017-01-19 20:40:42 -0800211 return ThreadUtil::SetThreadLocalStorage(env, thread, data);
Alex Light49948e92016-08-11 15:35:28 -0700212 }
213
214 static jvmtiError GetThreadLocalStorage(jvmtiEnv* env, jthread thread, void** data_ptr) {
Andreas Gampe7b3b3262017-01-19 20:40:42 -0800215 return ThreadUtil::GetThreadLocalStorage(env, thread, data_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700216 }
217
218 static jvmtiError GetTopThreadGroups(jvmtiEnv* env,
219 jint* group_count_ptr,
220 jthreadGroup** groups_ptr) {
Andreas Gamped18d9e22017-01-16 16:08:45 +0000221 return ThreadGroupUtil::GetTopThreadGroups(env, group_count_ptr, groups_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700222 }
223
224 static jvmtiError GetThreadGroupInfo(jvmtiEnv* env,
225 jthreadGroup group,
226 jvmtiThreadGroupInfo* info_ptr) {
Andreas Gamped18d9e22017-01-16 16:08:45 +0000227 return ThreadGroupUtil::GetThreadGroupInfo(env, group, info_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700228 }
229
230 static jvmtiError GetThreadGroupChildren(jvmtiEnv* env,
231 jthreadGroup group,
232 jint* thread_count_ptr,
233 jthread** threads_ptr,
234 jint* group_count_ptr,
235 jthreadGroup** groups_ptr) {
Andreas Gamped18d9e22017-01-16 16:08:45 +0000236 return ThreadGroupUtil::GetThreadGroupChildren(env,
237 group,
238 thread_count_ptr,
239 threads_ptr,
240 group_count_ptr,
241 groups_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700242 }
243
244 static jvmtiError GetStackTrace(jvmtiEnv* env,
245 jthread thread,
246 jint start_depth,
247 jint max_frame_count,
248 jvmtiFrameInfo* frame_buffer,
249 jint* count_ptr) {
Andreas Gampeb5eb94a2016-10-27 19:23:09 -0700250 return StackUtil::GetStackTrace(env,
251 thread,
252 start_depth,
253 max_frame_count,
254 frame_buffer,
255 count_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700256 }
257
258 static jvmtiError GetAllStackTraces(jvmtiEnv* env,
259 jint max_frame_count,
260 jvmtiStackInfo** stack_info_ptr,
261 jint* thread_count_ptr) {
Andreas Gampea1a27c62017-01-11 16:37:16 -0800262 return StackUtil::GetAllStackTraces(env, max_frame_count, stack_info_ptr, thread_count_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700263 }
264
265 static jvmtiError GetThreadListStackTraces(jvmtiEnv* env,
266 jint thread_count,
267 const jthread* thread_list,
268 jint max_frame_count,
269 jvmtiStackInfo** stack_info_ptr) {
Andreas Gampeeba32fb2017-01-12 17:40:05 -0800270 return StackUtil::GetThreadListStackTraces(env,
271 thread_count,
272 thread_list,
273 max_frame_count,
274 stack_info_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700275 }
276
277 static jvmtiError GetFrameCount(jvmtiEnv* env, jthread thread, jint* count_ptr) {
Andreas Gampef6f3b5f2017-01-13 09:21:42 -0800278 return StackUtil::GetFrameCount(env, thread, count_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700279 }
280
281 static jvmtiError PopFrame(jvmtiEnv* env, jthread thread) {
Alex Light9db679d2017-01-25 15:28:04 -0800282 ENSURE_HAS_CAP(env, can_pop_frame);
Alex Light49948e92016-08-11 15:35:28 -0700283 return ERR(NOT_IMPLEMENTED);
284 }
285
286 static jvmtiError GetFrameLocation(jvmtiEnv* env,
287 jthread thread,
288 jint depth,
289 jmethodID* method_ptr,
290 jlocation* location_ptr) {
Andreas Gampef6f3b5f2017-01-13 09:21:42 -0800291 return StackUtil::GetFrameLocation(env, thread, depth, method_ptr, location_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700292 }
293
294 static jvmtiError NotifyFramePop(jvmtiEnv* env, jthread thread, jint depth) {
Alex Light9db679d2017-01-25 15:28:04 -0800295 ENSURE_HAS_CAP(env, can_generate_frame_pop_events);
Alex Light49948e92016-08-11 15:35:28 -0700296 return ERR(NOT_IMPLEMENTED);
297 }
298
299 static jvmtiError ForceEarlyReturnObject(jvmtiEnv* env, jthread thread, jobject value) {
Alex Light9db679d2017-01-25 15:28:04 -0800300 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Light49948e92016-08-11 15:35:28 -0700301 return ERR(NOT_IMPLEMENTED);
302 }
303
304 static jvmtiError ForceEarlyReturnInt(jvmtiEnv* env, jthread thread, jint value) {
Alex Light9db679d2017-01-25 15:28:04 -0800305 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Light49948e92016-08-11 15:35:28 -0700306 return ERR(NOT_IMPLEMENTED);
307 }
308
309 static jvmtiError ForceEarlyReturnLong(jvmtiEnv* env, jthread thread, jlong value) {
Alex Light9db679d2017-01-25 15:28:04 -0800310 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Light49948e92016-08-11 15:35:28 -0700311 return ERR(NOT_IMPLEMENTED);
312 }
313
314 static jvmtiError ForceEarlyReturnFloat(jvmtiEnv* env, jthread thread, jfloat value) {
Alex Light9db679d2017-01-25 15:28:04 -0800315 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Light49948e92016-08-11 15:35:28 -0700316 return ERR(NOT_IMPLEMENTED);
317 }
318
319 static jvmtiError ForceEarlyReturnDouble(jvmtiEnv* env, jthread thread, jdouble value) {
Alex Light9db679d2017-01-25 15:28:04 -0800320 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Light49948e92016-08-11 15:35:28 -0700321 return ERR(NOT_IMPLEMENTED);
322 }
323
324 static jvmtiError ForceEarlyReturnVoid(jvmtiEnv* env, jthread thread) {
Alex Light9db679d2017-01-25 15:28:04 -0800325 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Light49948e92016-08-11 15:35:28 -0700326 return ERR(NOT_IMPLEMENTED);
327 }
328
329 static jvmtiError FollowReferences(jvmtiEnv* env,
330 jint heap_filter,
331 jclass klass,
332 jobject initial_object,
333 const jvmtiHeapCallbacks* callbacks,
334 const void* user_data) {
Alex Light9db679d2017-01-25 15:28:04 -0800335 ENSURE_HAS_CAP(env, can_tag_objects);
Andreas Gampede19eb92017-02-24 16:21:18 -0800336 HeapUtil heap_util(ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get());
Andreas Gampe70bfc8a2016-11-03 11:04:15 -0700337 return heap_util.FollowReferences(env,
338 heap_filter,
339 klass,
340 initial_object,
341 callbacks,
342 user_data);
Alex Light49948e92016-08-11 15:35:28 -0700343 }
344
345 static jvmtiError IterateThroughHeap(jvmtiEnv* env,
346 jint heap_filter,
347 jclass klass,
348 const jvmtiHeapCallbacks* callbacks,
349 const void* user_data) {
Alex Lighte6574242016-08-17 09:56:24 -0700350 ENSURE_HAS_CAP(env, can_tag_objects);
Andreas Gampede19eb92017-02-24 16:21:18 -0800351 HeapUtil heap_util(ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get());
Andreas Gampee54d9922016-10-11 19:55:37 -0700352 return heap_util.IterateThroughHeap(env, heap_filter, klass, callbacks, user_data);
Alex Light49948e92016-08-11 15:35:28 -0700353 }
354
355 static jvmtiError GetTag(jvmtiEnv* env, jobject object, jlong* tag_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -0700356 ENSURE_HAS_CAP(env, can_tag_objects);
Andreas Gampe6dee92e2016-09-12 19:58:13 -0700357
358 JNIEnv* jni_env = GetJniEnv(env);
359 if (jni_env == nullptr) {
360 return ERR(INTERNAL);
361 }
362
363 art::ScopedObjectAccess soa(jni_env);
364 art::ObjPtr<art::mirror::Object> obj = soa.Decode<art::mirror::Object>(object);
Andreas Gampede19eb92017-02-24 16:21:18 -0800365 if (!ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table->GetTag(obj.Ptr(), tag_ptr)) {
Andreas Gampe6dee92e2016-09-12 19:58:13 -0700366 *tag_ptr = 0;
367 }
368
369 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -0700370 }
371
372 static jvmtiError SetTag(jvmtiEnv* env, jobject object, jlong tag) {
Alex Lighte6574242016-08-17 09:56:24 -0700373 ENSURE_HAS_CAP(env, can_tag_objects);
374
Andreas Gampe6dee92e2016-09-12 19:58:13 -0700375 if (object == nullptr) {
376 return ERR(NULL_POINTER);
377 }
378
379 JNIEnv* jni_env = GetJniEnv(env);
380 if (jni_env == nullptr) {
381 return ERR(INTERNAL);
382 }
383
384 art::ScopedObjectAccess soa(jni_env);
385 art::ObjPtr<art::mirror::Object> obj = soa.Decode<art::mirror::Object>(object);
Andreas Gampede19eb92017-02-24 16:21:18 -0800386 ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table->Set(obj.Ptr(), tag);
Andreas Gampe6dee92e2016-09-12 19:58:13 -0700387
388 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -0700389 }
390
391 static jvmtiError GetObjectsWithTags(jvmtiEnv* env,
392 jint tag_count,
393 const jlong* tags,
394 jint* count_ptr,
395 jobject** object_result_ptr,
396 jlong** tag_result_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -0700397 ENSURE_HAS_CAP(env, can_tag_objects);
398
Andreas Gampe5e6046b2016-10-25 12:05:53 -0700399 JNIEnv* jni_env = GetJniEnv(env);
400 if (jni_env == nullptr) {
401 return ERR(INTERNAL);
402 }
403
404 art::ScopedObjectAccess soa(jni_env);
Andreas Gampede19eb92017-02-24 16:21:18 -0800405 return ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table->GetTaggedObjects(env,
406 tag_count,
407 tags,
408 count_ptr,
409 object_result_ptr,
410 tag_result_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700411 }
412
413 static jvmtiError ForceGarbageCollection(jvmtiEnv* env) {
Andreas Gampe8da6d032016-10-31 19:31:03 -0700414 return HeapUtil::ForceGarbageCollection(env);
Alex Light49948e92016-08-11 15:35:28 -0700415 }
416
417 static jvmtiError IterateOverObjectsReachableFromObject(
418 jvmtiEnv* env,
419 jobject object,
420 jvmtiObjectReferenceCallback object_reference_callback,
421 const void* user_data) {
Alex Light9db679d2017-01-25 15:28:04 -0800422 ENSURE_HAS_CAP(env, can_tag_objects);
Alex Light49948e92016-08-11 15:35:28 -0700423 return ERR(NOT_IMPLEMENTED);
424 }
425
426 static jvmtiError IterateOverReachableObjects(jvmtiEnv* env,
427 jvmtiHeapRootCallback heap_root_callback,
428 jvmtiStackReferenceCallback stack_ref_callback,
429 jvmtiObjectReferenceCallback object_ref_callback,
430 const void* user_data) {
Alex Light9db679d2017-01-25 15:28:04 -0800431 ENSURE_HAS_CAP(env, can_tag_objects);
Alex Light49948e92016-08-11 15:35:28 -0700432 return ERR(NOT_IMPLEMENTED);
433 }
434
435 static jvmtiError IterateOverHeap(jvmtiEnv* env,
436 jvmtiHeapObjectFilter object_filter,
437 jvmtiHeapObjectCallback heap_object_callback,
438 const void* user_data) {
Alex Light9db679d2017-01-25 15:28:04 -0800439 ENSURE_HAS_CAP(env, can_tag_objects);
Alex Light49948e92016-08-11 15:35:28 -0700440 return ERR(NOT_IMPLEMENTED);
441 }
442
443 static jvmtiError IterateOverInstancesOfClass(jvmtiEnv* env,
444 jclass klass,
445 jvmtiHeapObjectFilter object_filter,
446 jvmtiHeapObjectCallback heap_object_callback,
447 const void* user_data) {
Alex Light9db679d2017-01-25 15:28:04 -0800448 ENSURE_HAS_CAP(env, can_tag_objects);
Alex Light49948e92016-08-11 15:35:28 -0700449 return ERR(NOT_IMPLEMENTED);
450 }
451
452 static jvmtiError GetLocalObject(jvmtiEnv* env,
453 jthread thread,
454 jint depth,
455 jint slot,
456 jobject* value_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800457 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700458 return ERR(NOT_IMPLEMENTED);
459 }
460
461 static jvmtiError GetLocalInstance(jvmtiEnv* env,
462 jthread thread,
463 jint depth,
464 jobject* value_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800465 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700466 return ERR(NOT_IMPLEMENTED);
467 }
468
469 static jvmtiError GetLocalInt(jvmtiEnv* env,
470 jthread thread,
471 jint depth,
472 jint slot,
473 jint* value_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800474 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700475 return ERR(NOT_IMPLEMENTED);
476 }
477
478 static jvmtiError GetLocalLong(jvmtiEnv* env,
479 jthread thread,
480 jint depth,
481 jint slot,
482 jlong* value_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800483 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700484 return ERR(NOT_IMPLEMENTED);
485 }
486
487 static jvmtiError GetLocalFloat(jvmtiEnv* env,
488 jthread thread,
489 jint depth,
490 jint slot,
491 jfloat* value_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800492 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700493 return ERR(NOT_IMPLEMENTED);
494 }
495
496 static jvmtiError GetLocalDouble(jvmtiEnv* env,
497 jthread thread,
498 jint depth,
499 jint slot,
500 jdouble* value_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800501 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700502 return ERR(NOT_IMPLEMENTED);
503 }
504
505 static jvmtiError SetLocalObject(jvmtiEnv* env,
506 jthread thread,
507 jint depth,
508 jint slot,
509 jobject value) {
Alex Light9db679d2017-01-25 15:28:04 -0800510 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700511 return ERR(NOT_IMPLEMENTED);
512 }
513
514 static jvmtiError SetLocalInt(jvmtiEnv* env,
515 jthread thread,
516 jint depth,
517 jint slot,
518 jint value) {
Alex Light9db679d2017-01-25 15:28:04 -0800519 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700520 return ERR(NOT_IMPLEMENTED);
521 }
522
523 static jvmtiError SetLocalLong(jvmtiEnv* env,
524 jthread thread,
525 jint depth,
526 jint slot,
527 jlong value) {
Alex Light9db679d2017-01-25 15:28:04 -0800528 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700529 return ERR(NOT_IMPLEMENTED);
530 }
531
532 static jvmtiError SetLocalFloat(jvmtiEnv* env,
533 jthread thread,
534 jint depth,
535 jint slot,
536 jfloat value) {
Alex Light9db679d2017-01-25 15:28:04 -0800537 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700538 return ERR(NOT_IMPLEMENTED);
539 }
540
541 static jvmtiError SetLocalDouble(jvmtiEnv* env,
542 jthread thread,
543 jint depth,
544 jint slot,
545 jdouble value) {
Alex Light9db679d2017-01-25 15:28:04 -0800546 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700547 return ERR(NOT_IMPLEMENTED);
548 }
549
550 static jvmtiError SetBreakpoint(jvmtiEnv* env, jmethodID method, jlocation location) {
Alex Light9db679d2017-01-25 15:28:04 -0800551 ENSURE_HAS_CAP(env, can_generate_breakpoint_events);
Alex Light49948e92016-08-11 15:35:28 -0700552 return ERR(NOT_IMPLEMENTED);
553 }
554
555 static jvmtiError ClearBreakpoint(jvmtiEnv* env, jmethodID method, jlocation location) {
Alex Light9db679d2017-01-25 15:28:04 -0800556 ENSURE_HAS_CAP(env, can_generate_breakpoint_events);
Alex Light49948e92016-08-11 15:35:28 -0700557 return ERR(NOT_IMPLEMENTED);
558 }
559
560 static jvmtiError SetFieldAccessWatch(jvmtiEnv* env, jclass klass, jfieldID field) {
Alex Light9db679d2017-01-25 15:28:04 -0800561 ENSURE_HAS_CAP(env, can_generate_field_access_events);
Alex Light49948e92016-08-11 15:35:28 -0700562 return ERR(NOT_IMPLEMENTED);
563 }
564
565 static jvmtiError ClearFieldAccessWatch(jvmtiEnv* env, jclass klass, jfieldID field) {
Alex Light9db679d2017-01-25 15:28:04 -0800566 ENSURE_HAS_CAP(env, can_generate_field_access_events);
Alex Light49948e92016-08-11 15:35:28 -0700567 return ERR(NOT_IMPLEMENTED);
568 }
569
570 static jvmtiError SetFieldModificationWatch(jvmtiEnv* env, jclass klass, jfieldID field) {
Alex Light9db679d2017-01-25 15:28:04 -0800571 ENSURE_HAS_CAP(env, can_generate_field_modification_events);
Alex Light49948e92016-08-11 15:35:28 -0700572 return ERR(NOT_IMPLEMENTED);
573 }
574
575 static jvmtiError ClearFieldModificationWatch(jvmtiEnv* env, jclass klass, jfieldID field) {
Alex Light9db679d2017-01-25 15:28:04 -0800576 ENSURE_HAS_CAP(env, can_generate_field_modification_events);
Alex Light49948e92016-08-11 15:35:28 -0700577 return ERR(NOT_IMPLEMENTED);
578 }
579
580 static jvmtiError GetLoadedClasses(jvmtiEnv* env, jint* class_count_ptr, jclass** classes_ptr) {
Andreas Gampede19eb92017-02-24 16:21:18 -0800581 HeapUtil heap_util(ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get());
Andreas Gampeaa8b60c2016-10-12 12:51:25 -0700582 return heap_util.GetLoadedClasses(env, class_count_ptr, classes_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700583 }
584
585 static jvmtiError GetClassLoaderClasses(jvmtiEnv* env,
586 jobject initiating_loader,
587 jint* class_count_ptr,
588 jclass** classes_ptr) {
Andreas Gampe70f16392017-01-16 14:20:10 -0800589 return ClassUtil::GetClassLoaderClasses(env, initiating_loader, class_count_ptr, classes_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700590 }
591
592 static jvmtiError GetClassSignature(jvmtiEnv* env,
593 jclass klass,
594 char** signature_ptr,
595 char** generic_ptr) {
Andreas Gampee492ae32016-10-28 19:34:57 -0700596 return ClassUtil::GetClassSignature(env, klass, signature_ptr, generic_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700597 }
598
599 static jvmtiError GetClassStatus(jvmtiEnv* env, jclass klass, jint* status_ptr) {
Andreas Gampeff9d2092017-01-06 09:12:49 -0800600 return ClassUtil::GetClassStatus(env, klass, status_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700601 }
602
603 static jvmtiError GetSourceFileName(jvmtiEnv* env, jclass klass, char** source_name_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800604 ENSURE_HAS_CAP(env, can_get_source_file_name);
Alex Light49948e92016-08-11 15:35:28 -0700605 return ERR(NOT_IMPLEMENTED);
606 }
607
608 static jvmtiError GetClassModifiers(jvmtiEnv* env, jclass klass, jint* modifiers_ptr) {
Andreas Gampe64013e52017-01-06 13:07:19 -0800609 return ClassUtil::GetClassModifiers(env, klass, modifiers_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700610 }
611
612 static jvmtiError GetClassMethods(jvmtiEnv* env,
613 jclass klass,
614 jint* method_count_ptr,
615 jmethodID** methods_ptr) {
Andreas Gampe18fee4d2017-01-06 11:36:35 -0800616 return ClassUtil::GetClassMethods(env, klass, method_count_ptr, methods_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700617 }
618
619 static jvmtiError GetClassFields(jvmtiEnv* env,
620 jclass klass,
621 jint* field_count_ptr,
622 jfieldID** fields_ptr) {
Andreas Gampeac587272017-01-05 15:21:34 -0800623 return ClassUtil::GetClassFields(env, klass, field_count_ptr, fields_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700624 }
625
626 static jvmtiError GetImplementedInterfaces(jvmtiEnv* env,
627 jclass klass,
628 jint* interface_count_ptr,
629 jclass** interfaces_ptr) {
Andreas Gampe8b07e472017-01-06 14:20:39 -0800630 return ClassUtil::GetImplementedInterfaces(env, klass, interface_count_ptr, interfaces_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700631 }
632
633 static jvmtiError GetClassVersionNumbers(jvmtiEnv* env,
634 jclass klass,
635 jint* minor_version_ptr,
636 jint* major_version_ptr) {
Andreas Gampe812a2442017-01-19 22:04:46 -0800637 return ClassUtil::GetClassVersionNumbers(env, klass, minor_version_ptr, major_version_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700638 }
639
640 static jvmtiError GetConstantPool(jvmtiEnv* env,
641 jclass klass,
642 jint* constant_pool_count_ptr,
643 jint* constant_pool_byte_count_ptr,
644 unsigned char** constant_pool_bytes_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800645 ENSURE_HAS_CAP(env, can_get_constant_pool);
Alex Light49948e92016-08-11 15:35:28 -0700646 return ERR(NOT_IMPLEMENTED);
647 }
648
649 static jvmtiError IsInterface(jvmtiEnv* env, jclass klass, jboolean* is_interface_ptr) {
Andreas Gampe4fd66ec2017-01-05 14:42:13 -0800650 return ClassUtil::IsInterface(env, klass, is_interface_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700651 }
652
653 static jvmtiError IsArrayClass(jvmtiEnv* env,
654 jclass klass,
655 jboolean* is_array_class_ptr) {
Andreas Gampe4fd66ec2017-01-05 14:42:13 -0800656 return ClassUtil::IsArrayClass(env, klass, is_array_class_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700657 }
658
659 static jvmtiError IsModifiableClass(jvmtiEnv* env,
660 jclass klass,
661 jboolean* is_modifiable_class_ptr) {
Alex Lighte4a88632017-01-10 07:41:24 -0800662 return Redefiner::IsModifiableClass(env, klass, is_modifiable_class_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700663 }
664
665 static jvmtiError GetClassLoader(jvmtiEnv* env, jclass klass, jobject* classloader_ptr) {
Andreas Gampe8f5b6032017-01-06 15:50:55 -0800666 return ClassUtil::GetClassLoader(env, klass, classloader_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700667 }
668
669 static jvmtiError GetSourceDebugExtension(jvmtiEnv* env,
670 jclass klass,
671 char** source_debug_extension_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800672 ENSURE_HAS_CAP(env, can_get_source_debug_extension);
Alex Light49948e92016-08-11 15:35:28 -0700673 return ERR(NOT_IMPLEMENTED);
674 }
675
676 static jvmtiError RetransformClasses(jvmtiEnv* env, jint class_count, const jclass* classes) {
Alex Light9db679d2017-01-25 15:28:04 -0800677 ENSURE_HAS_CAP(env, can_retransform_classes);
Alex Light6ac57502017-01-19 15:05:06 -0800678 std::string error_msg;
679 jvmtiError res = Transformer::RetransformClasses(ArtJvmTiEnv::AsArtJvmTiEnv(env),
Andreas Gampede19eb92017-02-24 16:21:18 -0800680 &gEventHandler,
Alex Light6ac57502017-01-19 15:05:06 -0800681 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),
Andreas Gampede19eb92017-02-24 16:21:18 -0800698 &gEventHandler,
Alex Light0e692732017-01-10 15:00:05 -0800699 art::Runtime::Current(),
700 art::Thread::Current(),
701 class_count,
702 class_definitions,
703 &error_msg);
704 if (res != OK) {
705 LOG(WARNING) << "FAILURE TO REDEFINE " << error_msg;
706 }
707 return res;
Alex Light49948e92016-08-11 15:35:28 -0700708 }
709
710 static jvmtiError GetObjectSize(jvmtiEnv* env, jobject object, jlong* size_ptr) {
Andreas Gampe50a4e492017-01-06 18:00:20 -0800711 return ObjectUtil::GetObjectSize(env, object, size_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700712 }
713
714 static jvmtiError GetObjectHashCode(jvmtiEnv* env, jobject object, jint* hash_code_ptr) {
Andreas Gampe50a4e492017-01-06 18:00:20 -0800715 return ObjectUtil::GetObjectHashCode(env, object, hash_code_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700716 }
717
718 static jvmtiError GetObjectMonitorUsage(jvmtiEnv* env,
719 jobject object,
720 jvmtiMonitorUsage* info_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800721 ENSURE_HAS_CAP(env, can_get_monitor_info);
Alex Light49948e92016-08-11 15:35:28 -0700722 return ERR(NOT_IMPLEMENTED);
723 }
724
725 static jvmtiError GetFieldName(jvmtiEnv* env,
726 jclass klass,
727 jfieldID field,
728 char** name_ptr,
729 char** signature_ptr,
730 char** generic_ptr) {
Andreas Gampeab2f0d02017-01-05 17:23:45 -0800731 return FieldUtil::GetFieldName(env, klass, field, name_ptr, signature_ptr, generic_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700732 }
733
734 static jvmtiError GetFieldDeclaringClass(jvmtiEnv* env,
735 jclass klass,
736 jfieldID field,
737 jclass* declaring_class_ptr) {
Andreas Gampeab2f0d02017-01-05 17:23:45 -0800738 return FieldUtil::GetFieldDeclaringClass(env, klass, field, declaring_class_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700739 }
740
741 static jvmtiError GetFieldModifiers(jvmtiEnv* env,
742 jclass klass,
743 jfieldID field,
744 jint* modifiers_ptr) {
Andreas Gampeab2f0d02017-01-05 17:23:45 -0800745 return FieldUtil::GetFieldModifiers(env, klass, field, modifiers_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700746 }
747
748 static jvmtiError IsFieldSynthetic(jvmtiEnv* env,
749 jclass klass,
750 jfieldID field,
751 jboolean* is_synthetic_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800752 ENSURE_HAS_CAP(env, can_get_synthetic_attribute);
Andreas Gampeab2f0d02017-01-05 17:23:45 -0800753 return FieldUtil::IsFieldSynthetic(env, klass, field, is_synthetic_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700754 }
755
756 static jvmtiError GetMethodName(jvmtiEnv* env,
757 jmethodID method,
758 char** name_ptr,
759 char** signature_ptr,
760 char** generic_ptr) {
Andreas Gampe3c252f02016-10-27 18:25:17 -0700761 return MethodUtil::GetMethodName(env, method, name_ptr, signature_ptr, generic_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700762 }
763
764 static jvmtiError GetMethodDeclaringClass(jvmtiEnv* env,
765 jmethodID method,
766 jclass* declaring_class_ptr) {
Andreas Gampe368a2082016-10-28 17:33:13 -0700767 return MethodUtil::GetMethodDeclaringClass(env, method, declaring_class_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700768 }
769
770 static jvmtiError GetMethodModifiers(jvmtiEnv* env,
771 jmethodID method,
772 jint* modifiers_ptr) {
Andreas Gampe36bcd4f2016-10-28 18:07:18 -0700773 return MethodUtil::GetMethodModifiers(env, method, modifiers_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700774 }
775
776 static jvmtiError GetMaxLocals(jvmtiEnv* env,
777 jmethodID method,
778 jint* max_ptr) {
Andreas Gampef71832e2017-01-09 11:38:04 -0800779 return MethodUtil::GetMaxLocals(env, method, max_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700780 }
781
782 static jvmtiError GetArgumentsSize(jvmtiEnv* env,
783 jmethodID method,
784 jint* size_ptr) {
Andreas Gampef71832e2017-01-09 11:38:04 -0800785 return MethodUtil::GetArgumentsSize(env, method, size_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700786 }
787
788 static jvmtiError GetLineNumberTable(jvmtiEnv* env,
789 jmethodID method,
790 jint* entry_count_ptr,
791 jvmtiLineNumberEntry** table_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800792 ENSURE_HAS_CAP(env, can_get_line_numbers);
Andreas Gampeda3e5612016-12-13 19:00:53 -0800793 return MethodUtil::GetLineNumberTable(env, method, entry_count_ptr, table_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700794 }
795
796 static jvmtiError GetMethodLocation(jvmtiEnv* env,
797 jmethodID method,
798 jlocation* start_location_ptr,
799 jlocation* end_location_ptr) {
Andreas Gampef71832e2017-01-09 11:38:04 -0800800 return MethodUtil::GetMethodLocation(env, method, start_location_ptr, end_location_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700801 }
802
803 static jvmtiError GetLocalVariableTable(jvmtiEnv* env,
804 jmethodID method,
805 jint* entry_count_ptr,
806 jvmtiLocalVariableEntry** table_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800807 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Light49948e92016-08-11 15:35:28 -0700808 return ERR(NOT_IMPLEMENTED);
809 }
810
811 static jvmtiError GetBytecodes(jvmtiEnv* env,
812 jmethodID method,
813 jint* bytecode_count_ptr,
814 unsigned char** bytecodes_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800815 ENSURE_HAS_CAP(env, can_get_bytecodes);
Alex Light49948e92016-08-11 15:35:28 -0700816 return ERR(NOT_IMPLEMENTED);
817 }
818
819 static jvmtiError IsMethodNative(jvmtiEnv* env, jmethodID method, jboolean* is_native_ptr) {
Andreas Gampefdeef522017-01-09 14:40:25 -0800820 return MethodUtil::IsMethodNative(env, method, is_native_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700821 }
822
823 static jvmtiError IsMethodSynthetic(jvmtiEnv* env, jmethodID method, jboolean* is_synthetic_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -0800824 ENSURE_HAS_CAP(env, can_get_synthetic_attribute);
Andreas Gampefdeef522017-01-09 14:40:25 -0800825 return MethodUtil::IsMethodSynthetic(env, method, is_synthetic_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700826 }
827
828 static jvmtiError IsMethodObsolete(jvmtiEnv* env, jmethodID method, jboolean* is_obsolete_ptr) {
Andreas Gampefdeef522017-01-09 14:40:25 -0800829 return MethodUtil::IsMethodObsolete(env, method, is_obsolete_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700830 }
831
832 static jvmtiError SetNativeMethodPrefix(jvmtiEnv* env, const char* prefix) {
Alex Light9db679d2017-01-25 15:28:04 -0800833 ENSURE_HAS_CAP(env, can_set_native_method_prefix);
Alex Light49948e92016-08-11 15:35:28 -0700834 return ERR(NOT_IMPLEMENTED);
835 }
836
837 static jvmtiError SetNativeMethodPrefixes(jvmtiEnv* env, jint prefix_count, char** prefixes) {
Alex Light9db679d2017-01-25 15:28:04 -0800838 ENSURE_HAS_CAP(env, can_set_native_method_prefix);
Alex Light49948e92016-08-11 15:35:28 -0700839 return ERR(NOT_IMPLEMENTED);
840 }
841
842 static jvmtiError CreateRawMonitor(jvmtiEnv* env, const char* name, jrawMonitorID* monitor_ptr) {
Andreas Gampe319dbe82017-01-09 16:42:21 -0800843 return MonitorUtil::CreateRawMonitor(env, name, monitor_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700844 }
845
846 static jvmtiError DestroyRawMonitor(jvmtiEnv* env, jrawMonitorID monitor) {
Andreas Gampe319dbe82017-01-09 16:42:21 -0800847 return MonitorUtil::DestroyRawMonitor(env, monitor);
Alex Light49948e92016-08-11 15:35:28 -0700848 }
849
850 static jvmtiError RawMonitorEnter(jvmtiEnv* env, jrawMonitorID monitor) {
Andreas Gampe319dbe82017-01-09 16:42:21 -0800851 return MonitorUtil::RawMonitorEnter(env, monitor);
Alex Light49948e92016-08-11 15:35:28 -0700852 }
853
854 static jvmtiError RawMonitorExit(jvmtiEnv* env, jrawMonitorID monitor) {
Andreas Gampe319dbe82017-01-09 16:42:21 -0800855 return MonitorUtil::RawMonitorExit(env, monitor);
Alex Light49948e92016-08-11 15:35:28 -0700856 }
857
858 static jvmtiError RawMonitorWait(jvmtiEnv* env, jrawMonitorID monitor, jlong millis) {
Andreas Gampe319dbe82017-01-09 16:42:21 -0800859 return MonitorUtil::RawMonitorWait(env, monitor, millis);
Alex Light49948e92016-08-11 15:35:28 -0700860 }
861
862 static jvmtiError RawMonitorNotify(jvmtiEnv* env, jrawMonitorID monitor) {
Andreas Gampe319dbe82017-01-09 16:42:21 -0800863 return MonitorUtil::RawMonitorNotify(env, monitor);
Alex Light49948e92016-08-11 15:35:28 -0700864 }
865
866 static jvmtiError RawMonitorNotifyAll(jvmtiEnv* env, jrawMonitorID monitor) {
Andreas Gampe319dbe82017-01-09 16:42:21 -0800867 return MonitorUtil::RawMonitorNotifyAll(env, monitor);
Alex Light49948e92016-08-11 15:35:28 -0700868 }
869
870 static jvmtiError SetJNIFunctionTable(jvmtiEnv* env, const jniNativeInterface* function_table) {
Andreas Gampe6f8e4f02017-01-16 18:18:14 -0800871 return JNIUtil::SetJNIFunctionTable(env, function_table);
Alex Light49948e92016-08-11 15:35:28 -0700872 }
873
874 static jvmtiError GetJNIFunctionTable(jvmtiEnv* env, jniNativeInterface** function_table) {
Andreas Gampe6f8e4f02017-01-16 18:18:14 -0800875 return JNIUtil::GetJNIFunctionTable(env, function_table);
Alex Light49948e92016-08-11 15:35:28 -0700876 }
877
Andreas Gampe77708d92016-10-07 11:48:21 -0700878 // TODO: This will require locking, so that an agent can't remove callbacks when we're dispatching
879 // an event.
Alex Light49948e92016-08-11 15:35:28 -0700880 static jvmtiError SetEventCallbacks(jvmtiEnv* env,
881 const jvmtiEventCallbacks* callbacks,
882 jint size_of_callbacks) {
Alex Lighte6574242016-08-17 09:56:24 -0700883 ENSURE_VALID_ENV(env);
Andreas Gampe77708d92016-10-07 11:48:21 -0700884 if (size_of_callbacks < 0) {
885 return ERR(ILLEGAL_ARGUMENT);
886 }
887
888 if (callbacks == nullptr) {
889 ArtJvmTiEnv::AsArtJvmTiEnv(env)->event_callbacks.reset();
890 return ERR(NONE);
891 }
892
893 std::unique_ptr<jvmtiEventCallbacks> tmp(new jvmtiEventCallbacks());
894 memset(tmp.get(), 0, sizeof(jvmtiEventCallbacks));
895 size_t copy_size = std::min(sizeof(jvmtiEventCallbacks),
896 static_cast<size_t>(size_of_callbacks));
897 copy_size = art::RoundDown(copy_size, sizeof(void*));
898 memcpy(tmp.get(), callbacks, copy_size);
899
900 ArtJvmTiEnv::AsArtJvmTiEnv(env)->event_callbacks = std::move(tmp);
901
902 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -0700903 }
904
905 static jvmtiError SetEventNotificationMode(jvmtiEnv* env,
906 jvmtiEventMode mode,
907 jvmtiEvent event_type,
908 jthread event_thread,
909 ...) {
Alex Lighte6574242016-08-17 09:56:24 -0700910 ENSURE_VALID_ENV(env);
Andreas Gampe77708d92016-10-07 11:48:21 -0700911 art::Thread* art_thread = nullptr;
912 if (event_thread != nullptr) {
913 // TODO: Need non-aborting call here, to return JVMTI_ERROR_INVALID_THREAD.
914 art::ScopedObjectAccess soa(art::Thread::Current());
915 art::MutexLock mu(soa.Self(), *art::Locks::thread_list_lock_);
916 art_thread = art::Thread::FromManagedThread(soa, event_thread);
917
918 if (art_thread == nullptr || // The thread hasn't been started or is already dead.
919 art_thread->IsStillStarting()) {
920 // TODO: We may want to let the EventHandler know, so it could clean up masks, potentially.
921 return ERR(THREAD_NOT_ALIVE);
922 }
923 }
924
Alex Light40d87f42017-01-18 10:27:06 -0800925 ArtJvmTiEnv* art_env = ArtJvmTiEnv::AsArtJvmTiEnv(env);
926 return gEventHandler.SetEvent(art_env, art_thread, GetArtJvmtiEvent(art_env, event_type), mode);
Alex Light49948e92016-08-11 15:35:28 -0700927 }
928
929 static jvmtiError GenerateEvents(jvmtiEnv* env, jvmtiEvent event_type) {
930 return ERR(NOT_IMPLEMENTED);
931 }
932
933 static jvmtiError GetExtensionFunctions(jvmtiEnv* env,
934 jint* extension_count_ptr,
935 jvmtiExtensionFunctionInfo** extensions) {
Andreas Gampee4c33842017-01-09 10:50:17 -0800936 // We do not have any extension functions.
937 *extension_count_ptr = 0;
938 *extensions = nullptr;
939
940 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -0700941 }
942
943 static jvmtiError GetExtensionEvents(jvmtiEnv* env,
944 jint* extension_count_ptr,
945 jvmtiExtensionEventInfo** extensions) {
Andreas Gampee4c33842017-01-09 10:50:17 -0800946 // We do not have any extension events.
947 *extension_count_ptr = 0;
948 *extensions = nullptr;
949
950 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -0700951 }
952
953 static jvmtiError SetExtensionEventCallback(jvmtiEnv* env,
954 jint extension_event_index,
955 jvmtiExtensionEvent callback) {
Andreas Gampee4c33842017-01-09 10:50:17 -0800956 // We do not have any extension events, so any call is illegal.
957 return ERR(ILLEGAL_ARGUMENT);
Alex Light49948e92016-08-11 15:35:28 -0700958 }
959
960 static jvmtiError GetPotentialCapabilities(jvmtiEnv* env, jvmtiCapabilities* capabilities_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -0700961 ENSURE_VALID_ENV(env);
962 ENSURE_NON_NULL(capabilities_ptr);
963 *capabilities_ptr = kPotentialCapabilities;
964 return OK;
Alex Light49948e92016-08-11 15:35:28 -0700965 }
966
967 static jvmtiError AddCapabilities(jvmtiEnv* env, const jvmtiCapabilities* capabilities_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -0700968 ENSURE_VALID_ENV(env);
969 ENSURE_NON_NULL(capabilities_ptr);
970 ArtJvmTiEnv* art_env = static_cast<ArtJvmTiEnv*>(env);
971 jvmtiError ret = OK;
Alex Light73afd322017-01-18 11:17:47 -0800972 jvmtiCapabilities changed;
Alex Lighte6574242016-08-17 09:56:24 -0700973#define ADD_CAPABILITY(e) \
974 do { \
975 if (capabilities_ptr->e == 1) { \
976 if (kPotentialCapabilities.e == 1) { \
Alex Light73afd322017-01-18 11:17:47 -0800977 if (art_env->capabilities.e != 1) { \
978 art_env->capabilities.e = 1; \
979 changed.e = 1; \
980 }\
Alex Lighte6574242016-08-17 09:56:24 -0700981 } else { \
982 ret = ERR(NOT_AVAILABLE); \
983 } \
984 } \
985 } while (false)
986
987 ADD_CAPABILITY(can_tag_objects);
988 ADD_CAPABILITY(can_generate_field_modification_events);
989 ADD_CAPABILITY(can_generate_field_access_events);
990 ADD_CAPABILITY(can_get_bytecodes);
991 ADD_CAPABILITY(can_get_synthetic_attribute);
992 ADD_CAPABILITY(can_get_owned_monitor_info);
993 ADD_CAPABILITY(can_get_current_contended_monitor);
994 ADD_CAPABILITY(can_get_monitor_info);
995 ADD_CAPABILITY(can_pop_frame);
996 ADD_CAPABILITY(can_redefine_classes);
997 ADD_CAPABILITY(can_signal_thread);
998 ADD_CAPABILITY(can_get_source_file_name);
999 ADD_CAPABILITY(can_get_line_numbers);
1000 ADD_CAPABILITY(can_get_source_debug_extension);
1001 ADD_CAPABILITY(can_access_local_variables);
1002 ADD_CAPABILITY(can_maintain_original_method_order);
1003 ADD_CAPABILITY(can_generate_single_step_events);
1004 ADD_CAPABILITY(can_generate_exception_events);
1005 ADD_CAPABILITY(can_generate_frame_pop_events);
1006 ADD_CAPABILITY(can_generate_breakpoint_events);
1007 ADD_CAPABILITY(can_suspend);
1008 ADD_CAPABILITY(can_redefine_any_class);
1009 ADD_CAPABILITY(can_get_current_thread_cpu_time);
1010 ADD_CAPABILITY(can_get_thread_cpu_time);
1011 ADD_CAPABILITY(can_generate_method_entry_events);
1012 ADD_CAPABILITY(can_generate_method_exit_events);
1013 ADD_CAPABILITY(can_generate_all_class_hook_events);
1014 ADD_CAPABILITY(can_generate_compiled_method_load_events);
1015 ADD_CAPABILITY(can_generate_monitor_events);
1016 ADD_CAPABILITY(can_generate_vm_object_alloc_events);
1017 ADD_CAPABILITY(can_generate_native_method_bind_events);
1018 ADD_CAPABILITY(can_generate_garbage_collection_events);
1019 ADD_CAPABILITY(can_generate_object_free_events);
1020 ADD_CAPABILITY(can_force_early_return);
1021 ADD_CAPABILITY(can_get_owned_monitor_stack_depth_info);
1022 ADD_CAPABILITY(can_get_constant_pool);
1023 ADD_CAPABILITY(can_set_native_method_prefix);
1024 ADD_CAPABILITY(can_retransform_classes);
1025 ADD_CAPABILITY(can_retransform_any_class);
1026 ADD_CAPABILITY(can_generate_resource_exhaustion_heap_events);
1027 ADD_CAPABILITY(can_generate_resource_exhaustion_threads_events);
1028#undef ADD_CAPABILITY
Alex Light73afd322017-01-18 11:17:47 -08001029 gEventHandler.HandleChangedCapabilities(ArtJvmTiEnv::AsArtJvmTiEnv(env),
1030 changed,
1031 /*added*/true);
Alex Lighte6574242016-08-17 09:56:24 -07001032 return ret;
Alex Light49948e92016-08-11 15:35:28 -07001033 }
1034
1035 static jvmtiError RelinquishCapabilities(jvmtiEnv* env,
1036 const jvmtiCapabilities* capabilities_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001037 ENSURE_VALID_ENV(env);
1038 ENSURE_NON_NULL(capabilities_ptr);
1039 ArtJvmTiEnv* art_env = reinterpret_cast<ArtJvmTiEnv*>(env);
Alex Light73afd322017-01-18 11:17:47 -08001040 jvmtiCapabilities changed;
Alex Lighte6574242016-08-17 09:56:24 -07001041#define DEL_CAPABILITY(e) \
1042 do { \
1043 if (capabilities_ptr->e == 1) { \
Alex Light73afd322017-01-18 11:17:47 -08001044 if (art_env->capabilities.e == 1) { \
1045 art_env->capabilities.e = 0;\
1046 changed.e = 1; \
1047 } \
Alex Lighte6574242016-08-17 09:56:24 -07001048 } \
1049 } while (false)
1050
1051 DEL_CAPABILITY(can_tag_objects);
1052 DEL_CAPABILITY(can_generate_field_modification_events);
1053 DEL_CAPABILITY(can_generate_field_access_events);
1054 DEL_CAPABILITY(can_get_bytecodes);
1055 DEL_CAPABILITY(can_get_synthetic_attribute);
1056 DEL_CAPABILITY(can_get_owned_monitor_info);
1057 DEL_CAPABILITY(can_get_current_contended_monitor);
1058 DEL_CAPABILITY(can_get_monitor_info);
1059 DEL_CAPABILITY(can_pop_frame);
1060 DEL_CAPABILITY(can_redefine_classes);
1061 DEL_CAPABILITY(can_signal_thread);
1062 DEL_CAPABILITY(can_get_source_file_name);
1063 DEL_CAPABILITY(can_get_line_numbers);
1064 DEL_CAPABILITY(can_get_source_debug_extension);
1065 DEL_CAPABILITY(can_access_local_variables);
1066 DEL_CAPABILITY(can_maintain_original_method_order);
1067 DEL_CAPABILITY(can_generate_single_step_events);
1068 DEL_CAPABILITY(can_generate_exception_events);
1069 DEL_CAPABILITY(can_generate_frame_pop_events);
1070 DEL_CAPABILITY(can_generate_breakpoint_events);
1071 DEL_CAPABILITY(can_suspend);
1072 DEL_CAPABILITY(can_redefine_any_class);
1073 DEL_CAPABILITY(can_get_current_thread_cpu_time);
1074 DEL_CAPABILITY(can_get_thread_cpu_time);
1075 DEL_CAPABILITY(can_generate_method_entry_events);
1076 DEL_CAPABILITY(can_generate_method_exit_events);
1077 DEL_CAPABILITY(can_generate_all_class_hook_events);
1078 DEL_CAPABILITY(can_generate_compiled_method_load_events);
1079 DEL_CAPABILITY(can_generate_monitor_events);
1080 DEL_CAPABILITY(can_generate_vm_object_alloc_events);
1081 DEL_CAPABILITY(can_generate_native_method_bind_events);
1082 DEL_CAPABILITY(can_generate_garbage_collection_events);
1083 DEL_CAPABILITY(can_generate_object_free_events);
1084 DEL_CAPABILITY(can_force_early_return);
1085 DEL_CAPABILITY(can_get_owned_monitor_stack_depth_info);
1086 DEL_CAPABILITY(can_get_constant_pool);
1087 DEL_CAPABILITY(can_set_native_method_prefix);
1088 DEL_CAPABILITY(can_retransform_classes);
1089 DEL_CAPABILITY(can_retransform_any_class);
1090 DEL_CAPABILITY(can_generate_resource_exhaustion_heap_events);
1091 DEL_CAPABILITY(can_generate_resource_exhaustion_threads_events);
1092#undef DEL_CAPABILITY
Alex Light73afd322017-01-18 11:17:47 -08001093 gEventHandler.HandleChangedCapabilities(ArtJvmTiEnv::AsArtJvmTiEnv(env),
1094 changed,
1095 /*added*/false);
Alex Lighte6574242016-08-17 09:56:24 -07001096 return OK;
Alex Light49948e92016-08-11 15:35:28 -07001097 }
1098
1099 static jvmtiError GetCapabilities(jvmtiEnv* env, jvmtiCapabilities* capabilities_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001100 ENSURE_VALID_ENV(env);
1101 ENSURE_NON_NULL(capabilities_ptr);
1102 ArtJvmTiEnv* artenv = reinterpret_cast<ArtJvmTiEnv*>(env);
1103 *capabilities_ptr = artenv->capabilities;
1104 return OK;
Alex Light49948e92016-08-11 15:35:28 -07001105 }
1106
1107 static jvmtiError GetCurrentThreadCpuTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -08001108 ENSURE_HAS_CAP(env, can_get_current_thread_cpu_time);
Alex Light49948e92016-08-11 15:35:28 -07001109 return ERR(NOT_IMPLEMENTED);
1110 }
1111
1112 static jvmtiError GetCurrentThreadCpuTime(jvmtiEnv* env, jlong* nanos_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -08001113 ENSURE_HAS_CAP(env, can_get_current_thread_cpu_time);
Alex Light49948e92016-08-11 15:35:28 -07001114 return ERR(NOT_IMPLEMENTED);
1115 }
1116
1117 static jvmtiError GetThreadCpuTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -08001118 ENSURE_HAS_CAP(env, can_get_thread_cpu_time);
Alex Light49948e92016-08-11 15:35:28 -07001119 return ERR(NOT_IMPLEMENTED);
1120 }
1121
1122 static jvmtiError GetThreadCpuTime(jvmtiEnv* env, jthread thread, jlong* nanos_ptr) {
Alex Light9db679d2017-01-25 15:28:04 -08001123 ENSURE_HAS_CAP(env, can_get_thread_cpu_time);
Alex Light49948e92016-08-11 15:35:28 -07001124 return ERR(NOT_IMPLEMENTED);
1125 }
1126
1127 static jvmtiError GetTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr) {
Andreas Gampe35bcf812017-01-13 16:24:17 -08001128 return TimerUtil::GetTimerInfo(env, info_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001129 }
1130
1131 static jvmtiError GetTime(jvmtiEnv* env, jlong* nanos_ptr) {
Andreas Gampe35bcf812017-01-13 16:24:17 -08001132 return TimerUtil::GetTime(env, nanos_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001133 }
1134
1135 static jvmtiError GetAvailableProcessors(jvmtiEnv* env, jint* processor_count_ptr) {
Andreas Gampe35bcf812017-01-13 16:24:17 -08001136 return TimerUtil::GetAvailableProcessors(env, processor_count_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001137 }
1138
1139 static jvmtiError AddToBootstrapClassLoaderSearch(jvmtiEnv* env, const char* segment) {
Andreas Gampece7732b2017-01-17 15:50:26 -08001140 return SearchUtil::AddToBootstrapClassLoaderSearch(env, segment);
Alex Light49948e92016-08-11 15:35:28 -07001141 }
1142
1143 static jvmtiError AddToSystemClassLoaderSearch(jvmtiEnv* env, const char* segment) {
Andreas Gampece7732b2017-01-17 15:50:26 -08001144 return SearchUtil::AddToSystemClassLoaderSearch(env, segment);
Alex Light49948e92016-08-11 15:35:28 -07001145 }
1146
1147 static jvmtiError GetSystemProperties(jvmtiEnv* env, jint* count_ptr, char*** property_ptr) {
Andreas Gampe1bdaf732017-01-09 19:21:06 -08001148 return PropertiesUtil::GetSystemProperties(env, count_ptr, property_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001149 }
1150
1151 static jvmtiError GetSystemProperty(jvmtiEnv* env, const char* property, char** value_ptr) {
Andreas Gampe1bdaf732017-01-09 19:21:06 -08001152 return PropertiesUtil::GetSystemProperty(env, property, value_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001153 }
1154
1155 static jvmtiError SetSystemProperty(jvmtiEnv* env, const char* property, const char* value) {
Andreas Gampe1bdaf732017-01-09 19:21:06 -08001156 return PropertiesUtil::SetSystemProperty(env, property, value);
Alex Light49948e92016-08-11 15:35:28 -07001157 }
1158
1159 static jvmtiError GetPhase(jvmtiEnv* env, jvmtiPhase* phase_ptr) {
Andreas Gampe96eca782017-01-19 19:45:30 -08001160 return PhaseUtil::GetPhase(env, phase_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001161 }
1162
1163 static jvmtiError DisposeEnvironment(jvmtiEnv* env) {
Alex Lighte6574242016-08-17 09:56:24 -07001164 ENSURE_VALID_ENV(env);
Andreas Gampe3a7eb142017-01-19 21:59:22 -08001165 gEventHandler.RemoveArtJvmTiEnv(ArtJvmTiEnv::AsArtJvmTiEnv(env));
Andreas Gampede19eb92017-02-24 16:21:18 -08001166 art::Runtime::Current()->RemoveSystemWeakHolder(
1167 ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get());
Alex Light49948e92016-08-11 15:35:28 -07001168 delete env;
1169 return OK;
1170 }
1171
1172 static jvmtiError SetEnvironmentLocalStorage(jvmtiEnv* env, const void* data) {
Alex Lighte6574242016-08-17 09:56:24 -07001173 ENSURE_VALID_ENV(env);
Alex Light49948e92016-08-11 15:35:28 -07001174 reinterpret_cast<ArtJvmTiEnv*>(env)->local_data = const_cast<void*>(data);
1175 return OK;
1176 }
1177
1178 static jvmtiError GetEnvironmentLocalStorage(jvmtiEnv* env, void** data_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001179 ENSURE_VALID_ENV(env);
Alex Light49948e92016-08-11 15:35:28 -07001180 *data_ptr = reinterpret_cast<ArtJvmTiEnv*>(env)->local_data;
1181 return OK;
1182 }
1183
1184 static jvmtiError GetVersionNumber(jvmtiEnv* env, jint* version_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001185 ENSURE_VALID_ENV(env);
Alex Light49948e92016-08-11 15:35:28 -07001186 *version_ptr = JVMTI_VERSION;
1187 return OK;
1188 }
1189
1190 static jvmtiError GetErrorName(jvmtiEnv* env, jvmtiError error, char** name_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001191 ENSURE_NON_NULL(name_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001192 switch (error) {
1193#define ERROR_CASE(e) case (JVMTI_ERROR_ ## e) : do { \
Andreas Gampe54711412017-02-21 12:41:43 -08001194 jvmtiError res; \
1195 JvmtiUniquePtr<char[]> copy = CopyString(env, "JVMTI_ERROR_"#e, &res); \
1196 if (copy == nullptr) { \
Alex Light41960712017-01-06 14:44:23 -08001197 *name_ptr = nullptr; \
1198 return res; \
1199 } else { \
Andreas Gampe54711412017-02-21 12:41:43 -08001200 *name_ptr = copy.release(); \
Alex Light41960712017-01-06 14:44:23 -08001201 return OK; \
1202 } \
Alex Light49948e92016-08-11 15:35:28 -07001203 } while (false)
1204 ERROR_CASE(NONE);
1205 ERROR_CASE(INVALID_THREAD);
1206 ERROR_CASE(INVALID_THREAD_GROUP);
1207 ERROR_CASE(INVALID_PRIORITY);
1208 ERROR_CASE(THREAD_NOT_SUSPENDED);
1209 ERROR_CASE(THREAD_NOT_ALIVE);
1210 ERROR_CASE(INVALID_OBJECT);
1211 ERROR_CASE(INVALID_CLASS);
1212 ERROR_CASE(CLASS_NOT_PREPARED);
1213 ERROR_CASE(INVALID_METHODID);
1214 ERROR_CASE(INVALID_LOCATION);
1215 ERROR_CASE(INVALID_FIELDID);
1216 ERROR_CASE(NO_MORE_FRAMES);
1217 ERROR_CASE(OPAQUE_FRAME);
1218 ERROR_CASE(TYPE_MISMATCH);
1219 ERROR_CASE(INVALID_SLOT);
1220 ERROR_CASE(DUPLICATE);
1221 ERROR_CASE(NOT_FOUND);
1222 ERROR_CASE(INVALID_MONITOR);
1223 ERROR_CASE(NOT_MONITOR_OWNER);
1224 ERROR_CASE(INTERRUPT);
1225 ERROR_CASE(INVALID_CLASS_FORMAT);
1226 ERROR_CASE(CIRCULAR_CLASS_DEFINITION);
1227 ERROR_CASE(FAILS_VERIFICATION);
1228 ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_ADDED);
1229 ERROR_CASE(UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED);
1230 ERROR_CASE(INVALID_TYPESTATE);
1231 ERROR_CASE(UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED);
1232 ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_DELETED);
1233 ERROR_CASE(UNSUPPORTED_VERSION);
1234 ERROR_CASE(NAMES_DONT_MATCH);
1235 ERROR_CASE(UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED);
1236 ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED);
1237 ERROR_CASE(UNMODIFIABLE_CLASS);
1238 ERROR_CASE(NOT_AVAILABLE);
1239 ERROR_CASE(MUST_POSSESS_CAPABILITY);
1240 ERROR_CASE(NULL_POINTER);
1241 ERROR_CASE(ABSENT_INFORMATION);
1242 ERROR_CASE(INVALID_EVENT_TYPE);
1243 ERROR_CASE(ILLEGAL_ARGUMENT);
1244 ERROR_CASE(NATIVE_METHOD);
1245 ERROR_CASE(CLASS_LOADER_UNSUPPORTED);
1246 ERROR_CASE(OUT_OF_MEMORY);
1247 ERROR_CASE(ACCESS_DENIED);
1248 ERROR_CASE(WRONG_PHASE);
1249 ERROR_CASE(INTERNAL);
1250 ERROR_CASE(UNATTACHED_THREAD);
1251 ERROR_CASE(INVALID_ENVIRONMENT);
1252#undef ERROR_CASE
1253 default: {
Andreas Gampe54711412017-02-21 12:41:43 -08001254 jvmtiError res;
1255 JvmtiUniquePtr<char[]> copy = CopyString(env, "JVMTI_ERROR_UNKNOWN", &res);
1256 if (copy == nullptr) {
Alex Light41960712017-01-06 14:44:23 -08001257 *name_ptr = nullptr;
1258 return res;
1259 } else {
Andreas Gampe54711412017-02-21 12:41:43 -08001260 *name_ptr = copy.release();
Alex Light41960712017-01-06 14:44:23 -08001261 return ERR(ILLEGAL_ARGUMENT);
1262 }
Alex Light49948e92016-08-11 15:35:28 -07001263 }
1264 }
1265 }
1266
1267 static jvmtiError SetVerboseFlag(jvmtiEnv* env, jvmtiVerboseFlag flag, jboolean value) {
Andreas Gampef37e3022017-01-13 17:54:46 -08001268 if (flag == jvmtiVerboseFlag::JVMTI_VERBOSE_OTHER) {
1269 // OTHER is special, as it's 0, so can't do a bit check.
1270 bool val = (value == JNI_TRUE) ? true : false;
1271
1272 art::gLogVerbosity.collector = val;
1273 art::gLogVerbosity.compiler = val;
1274 art::gLogVerbosity.deopt = val;
1275 art::gLogVerbosity.heap = val;
1276 art::gLogVerbosity.jdwp = val;
1277 art::gLogVerbosity.jit = val;
1278 art::gLogVerbosity.monitor = val;
1279 art::gLogVerbosity.oat = val;
1280 art::gLogVerbosity.profiler = val;
1281 art::gLogVerbosity.signals = val;
1282 art::gLogVerbosity.simulator = val;
1283 art::gLogVerbosity.startup = val;
1284 art::gLogVerbosity.third_party_jni = val;
1285 art::gLogVerbosity.threads = val;
1286 art::gLogVerbosity.verifier = val;
1287 art::gLogVerbosity.image = val;
1288
1289 // Note: can't switch systrace_lock_logging. That requires changing entrypoints.
1290
1291 art::gLogVerbosity.agents = val;
1292 } else {
1293 // Spec isn't clear whether "flag" is a mask or supposed to be single. We implement the mask
1294 // semantics.
1295 constexpr std::underlying_type<jvmtiVerboseFlag>::type kMask =
1296 jvmtiVerboseFlag::JVMTI_VERBOSE_GC |
1297 jvmtiVerboseFlag::JVMTI_VERBOSE_CLASS |
1298 jvmtiVerboseFlag::JVMTI_VERBOSE_JNI;
1299 if ((flag & ~kMask) != 0) {
1300 return ERR(ILLEGAL_ARGUMENT);
1301 }
1302
1303 bool val = (value == JNI_TRUE) ? true : false;
1304
1305 if ((flag & jvmtiVerboseFlag::JVMTI_VERBOSE_GC) != 0) {
1306 art::gLogVerbosity.gc = val;
1307 }
1308
1309 if ((flag & jvmtiVerboseFlag::JVMTI_VERBOSE_CLASS) != 0) {
1310 art::gLogVerbosity.class_linker = val;
1311 }
1312
1313 if ((flag & jvmtiVerboseFlag::JVMTI_VERBOSE_JNI) != 0) {
1314 art::gLogVerbosity.jni = val;
1315 }
1316 }
1317
1318 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -07001319 }
1320
1321 static jvmtiError GetJLocationFormat(jvmtiEnv* env, jvmtiJlocationFormat* format_ptr) {
Andreas Gampeacfc9572017-01-17 18:36:56 -08001322 // Report BCI as jlocation format. We report dex bytecode indices.
1323 if (format_ptr == nullptr) {
1324 return ERR(NULL_POINTER);
1325 }
1326 *format_ptr = jvmtiJlocationFormat::JVMTI_JLOCATION_JVMBCI;
1327 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -07001328 }
1329};
1330
1331static bool IsJvmtiVersion(jint version) {
1332 return version == JVMTI_VERSION_1 ||
1333 version == JVMTI_VERSION_1_0 ||
1334 version == JVMTI_VERSION_1_1 ||
1335 version == JVMTI_VERSION_1_2 ||
1336 version == JVMTI_VERSION;
1337}
1338
Andreas Gampede19eb92017-02-24 16:21:18 -08001339extern const jvmtiInterface_1 gJvmtiInterface;
1340ArtJvmTiEnv::ArtJvmTiEnv(art::JavaVMExt* runtime, EventHandler* event_handler)
1341 : art_vm(runtime),
1342 local_data(nullptr),
1343 capabilities(),
1344 object_tag_table(new ObjectTagTable(event_handler)) {
1345 functions = &gJvmtiInterface;
1346}
1347
Alex Light49948e92016-08-11 15:35:28 -07001348// Creates a jvmtiEnv and returns it with the art::ti::Env that is associated with it. new_art_ti
1349// is a pointer to the uninitialized memory for an art::ti::Env.
1350static void CreateArtJvmTiEnv(art::JavaVMExt* vm, /*out*/void** new_jvmtiEnv) {
Andreas Gampede19eb92017-02-24 16:21:18 -08001351 struct ArtJvmTiEnv* env = new ArtJvmTiEnv(vm, &gEventHandler);
Alex Light49948e92016-08-11 15:35:28 -07001352 *new_jvmtiEnv = env;
Andreas Gampe77708d92016-10-07 11:48:21 -07001353
1354 gEventHandler.RegisterArtJvmTiEnv(env);
Andreas Gampede19eb92017-02-24 16:21:18 -08001355
1356 art::Runtime::Current()->AddSystemWeakHolder(
1357 ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get());
Alex Light49948e92016-08-11 15:35:28 -07001358}
1359
1360// A hook that the runtime uses to allow plugins to handle GetEnv calls. It returns true and
1361// places the return value in 'env' if this library can handle the GetEnv request. Otherwise
1362// returns false and does not modify the 'env' pointer.
1363static jint GetEnvHandler(art::JavaVMExt* vm, /*out*/void** env, jint version) {
1364 if (IsJvmtiVersion(version)) {
1365 CreateArtJvmTiEnv(vm, env);
1366 return JNI_OK;
1367 } else {
1368 printf("version 0x%x is not valid!", version);
1369 return JNI_EVERSION;
1370 }
1371}
1372
1373// The plugin initialization function. This adds the jvmti environment.
1374extern "C" bool ArtPlugin_Initialize() {
Andreas Gampee08a2be2016-10-06 13:13:30 -07001375 art::Runtime* runtime = art::Runtime::Current();
Andreas Gampe96eca782017-01-19 19:45:30 -08001376
1377 if (runtime->IsStarted()) {
1378 PhaseUtil::SetToLive();
1379 } else {
1380 PhaseUtil::SetToOnLoad();
1381 }
Andreas Gampe3a7eb142017-01-19 21:59:22 -08001382 PhaseUtil::Register(&gEventHandler);
Andreas Gampeeafaf572017-01-20 12:34:15 -08001383 ThreadUtil::Register(&gEventHandler);
Andreas Gampee6377462017-01-20 17:37:50 -08001384 ClassUtil::Register(&gEventHandler);
Andreas Gampeeb0cea12017-01-23 08:50:04 -08001385 DumpUtil::Register(&gEventHandler);
Andreas Gampecefaa142017-01-23 15:04:59 -08001386 SearchUtil::Register();
Andreas Gampe96eca782017-01-19 19:45:30 -08001387
Andreas Gampee08a2be2016-10-06 13:13:30 -07001388 runtime->GetJavaVM()->AddEnvironmentHook(GetEnvHandler);
Andreas Gampe96eca782017-01-19 19:45:30 -08001389
Alex Light49948e92016-08-11 15:35:28 -07001390 return true;
1391}
1392
Andreas Gampeeafaf572017-01-20 12:34:15 -08001393extern "C" bool ArtPlugin_Deinitialize() {
1394 PhaseUtil::Unregister();
1395 ThreadUtil::Unregister();
Andreas Gampee6377462017-01-20 17:37:50 -08001396 ClassUtil::Unregister();
Andreas Gampeeb0cea12017-01-23 08:50:04 -08001397 DumpUtil::Unregister();
Andreas Gampecefaa142017-01-23 15:04:59 -08001398 SearchUtil::Unregister();
Andreas Gampeeafaf572017-01-20 12:34:15 -08001399
1400 return true;
1401}
1402
Alex Light49948e92016-08-11 15:35:28 -07001403// The actual struct holding all of the entrypoints into the jvmti interface.
1404const jvmtiInterface_1 gJvmtiInterface = {
Alex Light6ac57502017-01-19 15:05:06 -08001405 nullptr, // reserved1
Alex Light49948e92016-08-11 15:35:28 -07001406 JvmtiFunctions::SetEventNotificationMode,
Alex Light0e692732017-01-10 15:00:05 -08001407 nullptr, // reserved3
Alex Light49948e92016-08-11 15:35:28 -07001408 JvmtiFunctions::GetAllThreads,
1409 JvmtiFunctions::SuspendThread,
1410 JvmtiFunctions::ResumeThread,
1411 JvmtiFunctions::StopThread,
1412 JvmtiFunctions::InterruptThread,
1413 JvmtiFunctions::GetThreadInfo,
1414 JvmtiFunctions::GetOwnedMonitorInfo, // 10
1415 JvmtiFunctions::GetCurrentContendedMonitor,
1416 JvmtiFunctions::RunAgentThread,
1417 JvmtiFunctions::GetTopThreadGroups,
1418 JvmtiFunctions::GetThreadGroupInfo,
1419 JvmtiFunctions::GetThreadGroupChildren,
1420 JvmtiFunctions::GetFrameCount,
1421 JvmtiFunctions::GetThreadState,
1422 JvmtiFunctions::GetCurrentThread,
1423 JvmtiFunctions::GetFrameLocation,
1424 JvmtiFunctions::NotifyFramePop, // 20
1425 JvmtiFunctions::GetLocalObject,
1426 JvmtiFunctions::GetLocalInt,
1427 JvmtiFunctions::GetLocalLong,
1428 JvmtiFunctions::GetLocalFloat,
1429 JvmtiFunctions::GetLocalDouble,
1430 JvmtiFunctions::SetLocalObject,
1431 JvmtiFunctions::SetLocalInt,
1432 JvmtiFunctions::SetLocalLong,
1433 JvmtiFunctions::SetLocalFloat,
1434 JvmtiFunctions::SetLocalDouble, // 30
1435 JvmtiFunctions::CreateRawMonitor,
1436 JvmtiFunctions::DestroyRawMonitor,
1437 JvmtiFunctions::RawMonitorEnter,
1438 JvmtiFunctions::RawMonitorExit,
1439 JvmtiFunctions::RawMonitorWait,
1440 JvmtiFunctions::RawMonitorNotify,
1441 JvmtiFunctions::RawMonitorNotifyAll,
1442 JvmtiFunctions::SetBreakpoint,
1443 JvmtiFunctions::ClearBreakpoint,
1444 nullptr, // reserved40
1445 JvmtiFunctions::SetFieldAccessWatch,
1446 JvmtiFunctions::ClearFieldAccessWatch,
1447 JvmtiFunctions::SetFieldModificationWatch,
1448 JvmtiFunctions::ClearFieldModificationWatch,
1449 JvmtiFunctions::IsModifiableClass,
1450 JvmtiFunctions::Allocate,
1451 JvmtiFunctions::Deallocate,
1452 JvmtiFunctions::GetClassSignature,
1453 JvmtiFunctions::GetClassStatus,
1454 JvmtiFunctions::GetSourceFileName, // 50
1455 JvmtiFunctions::GetClassModifiers,
1456 JvmtiFunctions::GetClassMethods,
1457 JvmtiFunctions::GetClassFields,
1458 JvmtiFunctions::GetImplementedInterfaces,
1459 JvmtiFunctions::IsInterface,
1460 JvmtiFunctions::IsArrayClass,
1461 JvmtiFunctions::GetClassLoader,
1462 JvmtiFunctions::GetObjectHashCode,
1463 JvmtiFunctions::GetObjectMonitorUsage,
1464 JvmtiFunctions::GetFieldName, // 60
1465 JvmtiFunctions::GetFieldDeclaringClass,
1466 JvmtiFunctions::GetFieldModifiers,
1467 JvmtiFunctions::IsFieldSynthetic,
1468 JvmtiFunctions::GetMethodName,
1469 JvmtiFunctions::GetMethodDeclaringClass,
1470 JvmtiFunctions::GetMethodModifiers,
1471 nullptr, // reserved67
1472 JvmtiFunctions::GetMaxLocals,
1473 JvmtiFunctions::GetArgumentsSize,
1474 JvmtiFunctions::GetLineNumberTable, // 70
1475 JvmtiFunctions::GetMethodLocation,
1476 JvmtiFunctions::GetLocalVariableTable,
1477 JvmtiFunctions::SetNativeMethodPrefix,
1478 JvmtiFunctions::SetNativeMethodPrefixes,
1479 JvmtiFunctions::GetBytecodes,
1480 JvmtiFunctions::IsMethodNative,
1481 JvmtiFunctions::IsMethodSynthetic,
1482 JvmtiFunctions::GetLoadedClasses,
1483 JvmtiFunctions::GetClassLoaderClasses,
1484 JvmtiFunctions::PopFrame, // 80
1485 JvmtiFunctions::ForceEarlyReturnObject,
1486 JvmtiFunctions::ForceEarlyReturnInt,
1487 JvmtiFunctions::ForceEarlyReturnLong,
1488 JvmtiFunctions::ForceEarlyReturnFloat,
1489 JvmtiFunctions::ForceEarlyReturnDouble,
1490 JvmtiFunctions::ForceEarlyReturnVoid,
1491 JvmtiFunctions::RedefineClasses,
1492 JvmtiFunctions::GetVersionNumber,
1493 JvmtiFunctions::GetCapabilities,
1494 JvmtiFunctions::GetSourceDebugExtension, // 90
1495 JvmtiFunctions::IsMethodObsolete,
1496 JvmtiFunctions::SuspendThreadList,
1497 JvmtiFunctions::ResumeThreadList,
1498 nullptr, // reserved94
1499 nullptr, // reserved95
1500 nullptr, // reserved96
1501 nullptr, // reserved97
1502 nullptr, // reserved98
1503 nullptr, // reserved99
1504 JvmtiFunctions::GetAllStackTraces, // 100
1505 JvmtiFunctions::GetThreadListStackTraces,
1506 JvmtiFunctions::GetThreadLocalStorage,
1507 JvmtiFunctions::SetThreadLocalStorage,
1508 JvmtiFunctions::GetStackTrace,
1509 nullptr, // reserved105
1510 JvmtiFunctions::GetTag,
1511 JvmtiFunctions::SetTag,
1512 JvmtiFunctions::ForceGarbageCollection,
1513 JvmtiFunctions::IterateOverObjectsReachableFromObject,
1514 JvmtiFunctions::IterateOverReachableObjects, // 110
1515 JvmtiFunctions::IterateOverHeap,
1516 JvmtiFunctions::IterateOverInstancesOfClass,
1517 nullptr, // reserved113
1518 JvmtiFunctions::GetObjectsWithTags,
1519 JvmtiFunctions::FollowReferences,
1520 JvmtiFunctions::IterateThroughHeap,
1521 nullptr, // reserved117
1522 nullptr, // reserved118
1523 nullptr, // reserved119
1524 JvmtiFunctions::SetJNIFunctionTable, // 120
1525 JvmtiFunctions::GetJNIFunctionTable,
1526 JvmtiFunctions::SetEventCallbacks,
1527 JvmtiFunctions::GenerateEvents,
1528 JvmtiFunctions::GetExtensionFunctions,
1529 JvmtiFunctions::GetExtensionEvents,
1530 JvmtiFunctions::SetExtensionEventCallback,
1531 JvmtiFunctions::DisposeEnvironment,
1532 JvmtiFunctions::GetErrorName,
1533 JvmtiFunctions::GetJLocationFormat,
1534 JvmtiFunctions::GetSystemProperties, // 130
1535 JvmtiFunctions::GetSystemProperty,
1536 JvmtiFunctions::SetSystemProperty,
1537 JvmtiFunctions::GetPhase,
1538 JvmtiFunctions::GetCurrentThreadCpuTimerInfo,
1539 JvmtiFunctions::GetCurrentThreadCpuTime,
1540 JvmtiFunctions::GetThreadCpuTimerInfo,
1541 JvmtiFunctions::GetThreadCpuTime,
1542 JvmtiFunctions::GetTimerInfo,
1543 JvmtiFunctions::GetTime,
1544 JvmtiFunctions::GetPotentialCapabilities, // 140
1545 nullptr, // reserved141
1546 JvmtiFunctions::AddCapabilities,
1547 JvmtiFunctions::RelinquishCapabilities,
1548 JvmtiFunctions::GetAvailableProcessors,
1549 JvmtiFunctions::GetClassVersionNumbers,
1550 JvmtiFunctions::GetConstantPool,
1551 JvmtiFunctions::GetEnvironmentLocalStorage,
1552 JvmtiFunctions::SetEnvironmentLocalStorage,
1553 JvmtiFunctions::AddToBootstrapClassLoaderSearch,
1554 JvmtiFunctions::SetVerboseFlag, // 150
1555 JvmtiFunctions::AddToSystemClassLoaderSearch,
1556 JvmtiFunctions::RetransformClasses,
1557 JvmtiFunctions::GetOwnedMonitorStackDepthInfo,
1558 JvmtiFunctions::GetObjectSize,
1559 JvmtiFunctions::GetLocalInstance,
1560};
1561
1562}; // namespace openjdkjvmti