Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1 | /* 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 Light | 9c20a14 | 2016-08-23 15:05:12 -0700 | [diff] [blame] | 32 | #include <string> |
| 33 | #include <vector> |
| 34 | |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 35 | #include <jni.h> |
Alex Light | 9c20a14 | 2016-08-23 15:05:12 -0700 | [diff] [blame] | 36 | |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 37 | #include "openjdkjvmti/jvmti.h" |
| 38 | |
Andreas Gampe | db6dcb6 | 2016-09-13 09:05:59 -0700 | [diff] [blame] | 39 | #include "art_jvmti.h" |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 40 | #include "base/mutex.h" |
| 41 | #include "events-inl.h" |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 42 | #include "jni_env_ext-inl.h" |
Andreas Gampe | 6dee92e | 2016-09-12 19:58:13 -0700 | [diff] [blame] | 43 | #include "obj_ptr-inl.h" |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 44 | #include "object_tagging.h" |
Alex Light | 9c20a14 | 2016-08-23 15:05:12 -0700 | [diff] [blame] | 45 | #include "runtime.h" |
Andreas Gampe | 6dee92e | 2016-09-12 19:58:13 -0700 | [diff] [blame] | 46 | #include "scoped_thread_state_change-inl.h" |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 47 | #include "thread-inl.h" |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 48 | #include "thread_list.h" |
Andreas Gampe | e492ae3 | 2016-10-28 19:34:57 -0700 | [diff] [blame] | 49 | #include "ti_class.h" |
Andreas Gampe | ab2f0d0 | 2017-01-05 17:23:45 -0800 | [diff] [blame] | 50 | #include "ti_field.h" |
Andreas Gampe | ba8df69 | 2016-11-01 10:30:44 -0700 | [diff] [blame] | 51 | #include "ti_heap.h" |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 52 | #include "ti_method.h" |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 53 | #include "ti_redefine.h" |
Andreas Gampe | b5eb94a | 2016-10-27 19:23:09 -0700 | [diff] [blame] | 54 | #include "ti_stack.h" |
Alex Light | 9c20a14 | 2016-08-23 15:05:12 -0700 | [diff] [blame] | 55 | #include "transform.h" |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 56 | |
| 57 | // TODO Remove this at some point by annotating all the methods. It was put in to make the skeleton |
| 58 | // easier to create. |
| 59 | #pragma GCC diagnostic ignored "-Wunused-parameter" |
| 60 | |
| 61 | namespace openjdkjvmti { |
| 62 | |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 63 | EventHandler gEventHandler; |
Andreas Gampe | cc13b22 | 2016-10-10 19:09:09 -0700 | [diff] [blame] | 64 | ObjectTagTable gObjectTagTable(&gEventHandler); |
Andreas Gampe | 6dee92e | 2016-09-12 19:58:13 -0700 | [diff] [blame] | 65 | |
Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 66 | #define ENSURE_NON_NULL(n) \ |
| 67 | do { \ |
| 68 | if ((n) == nullptr) { \ |
| 69 | return ERR(NULL_POINTER); \ |
| 70 | } \ |
| 71 | } while (false) |
| 72 | |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 73 | class JvmtiFunctions { |
| 74 | private: |
| 75 | static bool IsValidEnv(jvmtiEnv* env) { |
| 76 | return env != nullptr; |
| 77 | } |
| 78 | |
Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 79 | #define ENSURE_VALID_ENV(env) \ |
| 80 | do { \ |
| 81 | if (!IsValidEnv(env)) { \ |
| 82 | return ERR(INVALID_ENVIRONMENT); \ |
| 83 | } \ |
| 84 | } while (false) |
| 85 | |
| 86 | #define ENSURE_HAS_CAP(env, cap) \ |
| 87 | do { \ |
| 88 | ENSURE_VALID_ENV(env); \ |
| 89 | if (ArtJvmTiEnv::AsArtJvmTiEnv(env)->capabilities.cap != 1) { \ |
| 90 | return ERR(MUST_POSSESS_CAPABILITY); \ |
| 91 | } \ |
| 92 | } while (false) |
| 93 | |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 94 | public: |
| 95 | static jvmtiError Allocate(jvmtiEnv* env, jlong size, unsigned char** mem_ptr) { |
Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 96 | ENSURE_VALID_ENV(env); |
| 97 | ENSURE_NON_NULL(mem_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 98 | if (size < 0) { |
| 99 | return ERR(ILLEGAL_ARGUMENT); |
| 100 | } else if (size == 0) { |
| 101 | *mem_ptr = nullptr; |
| 102 | return OK; |
| 103 | } |
| 104 | *mem_ptr = static_cast<unsigned char*>(malloc(size)); |
| 105 | return (*mem_ptr != nullptr) ? OK : ERR(OUT_OF_MEMORY); |
| 106 | } |
| 107 | |
| 108 | static jvmtiError Deallocate(jvmtiEnv* env, unsigned char* mem) { |
Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 109 | ENSURE_VALID_ENV(env); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 110 | if (mem != nullptr) { |
| 111 | free(mem); |
| 112 | } |
| 113 | return OK; |
| 114 | } |
| 115 | |
| 116 | static jvmtiError GetThreadState(jvmtiEnv* env, jthread thread, jint* thread_state_ptr) { |
| 117 | return ERR(NOT_IMPLEMENTED); |
| 118 | } |
| 119 | |
| 120 | static jvmtiError GetCurrentThread(jvmtiEnv* env, jthread* thread_ptr) { |
| 121 | return ERR(NOT_IMPLEMENTED); |
| 122 | } |
| 123 | |
| 124 | static jvmtiError GetAllThreads(jvmtiEnv* env, jint* threads_count_ptr, jthread** threads_ptr) { |
| 125 | return ERR(NOT_IMPLEMENTED); |
| 126 | } |
| 127 | |
| 128 | static jvmtiError SuspendThread(jvmtiEnv* env, jthread thread) { |
| 129 | return ERR(NOT_IMPLEMENTED); |
| 130 | } |
| 131 | |
| 132 | static jvmtiError SuspendThreadList(jvmtiEnv* env, |
| 133 | jint request_count, |
| 134 | const jthread* request_list, |
| 135 | jvmtiError* results) { |
| 136 | return ERR(NOT_IMPLEMENTED); |
| 137 | } |
| 138 | |
| 139 | static jvmtiError ResumeThread(jvmtiEnv* env, jthread thread) { |
| 140 | return ERR(NOT_IMPLEMENTED); |
| 141 | } |
| 142 | |
| 143 | static jvmtiError ResumeThreadList(jvmtiEnv* env, |
| 144 | jint request_count, |
| 145 | const jthread* request_list, |
| 146 | jvmtiError* results) { |
| 147 | return ERR(NOT_IMPLEMENTED); |
| 148 | } |
| 149 | |
| 150 | static jvmtiError StopThread(jvmtiEnv* env, jthread thread, jobject exception) { |
| 151 | return ERR(NOT_IMPLEMENTED); |
| 152 | } |
| 153 | |
| 154 | static jvmtiError InterruptThread(jvmtiEnv* env, jthread thread) { |
| 155 | return ERR(NOT_IMPLEMENTED); |
| 156 | } |
| 157 | |
| 158 | static jvmtiError GetThreadInfo(jvmtiEnv* env, jthread thread, jvmtiThreadInfo* info_ptr) { |
| 159 | return ERR(NOT_IMPLEMENTED); |
| 160 | } |
| 161 | |
| 162 | static jvmtiError GetOwnedMonitorInfo(jvmtiEnv* env, |
| 163 | jthread thread, |
| 164 | jint* owned_monitor_count_ptr, |
| 165 | jobject** owned_monitors_ptr) { |
| 166 | return ERR(NOT_IMPLEMENTED); |
| 167 | } |
| 168 | |
| 169 | static jvmtiError GetOwnedMonitorStackDepthInfo(jvmtiEnv* env, |
| 170 | jthread thread, |
| 171 | jint* monitor_info_count_ptr, |
| 172 | jvmtiMonitorStackDepthInfo** monitor_info_ptr) { |
| 173 | return ERR(NOT_IMPLEMENTED); |
| 174 | } |
| 175 | |
| 176 | static jvmtiError GetCurrentContendedMonitor(jvmtiEnv* env, |
| 177 | jthread thread, |
| 178 | jobject* monitor_ptr) { |
Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 179 | return ERR(NOT_IMPLEMENTED); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | static jvmtiError RunAgentThread(jvmtiEnv* env, |
| 183 | jthread thread, |
| 184 | jvmtiStartFunction proc, |
| 185 | const void* arg, |
| 186 | jint priority) { |
| 187 | return ERR(NOT_IMPLEMENTED); |
| 188 | } |
| 189 | |
| 190 | static jvmtiError SetThreadLocalStorage(jvmtiEnv* env, jthread thread, const void* data) { |
| 191 | return ERR(NOT_IMPLEMENTED); |
| 192 | } |
| 193 | |
| 194 | static jvmtiError GetThreadLocalStorage(jvmtiEnv* env, jthread thread, void** data_ptr) { |
| 195 | return ERR(NOT_IMPLEMENTED); |
| 196 | } |
| 197 | |
| 198 | static jvmtiError GetTopThreadGroups(jvmtiEnv* env, |
| 199 | jint* group_count_ptr, |
| 200 | jthreadGroup** groups_ptr) { |
| 201 | return ERR(NOT_IMPLEMENTED); |
| 202 | } |
| 203 | |
| 204 | static jvmtiError GetThreadGroupInfo(jvmtiEnv* env, |
| 205 | jthreadGroup group, |
| 206 | jvmtiThreadGroupInfo* info_ptr) { |
| 207 | return ERR(NOT_IMPLEMENTED); |
| 208 | } |
| 209 | |
| 210 | static jvmtiError GetThreadGroupChildren(jvmtiEnv* env, |
| 211 | jthreadGroup group, |
| 212 | jint* thread_count_ptr, |
| 213 | jthread** threads_ptr, |
| 214 | jint* group_count_ptr, |
| 215 | jthreadGroup** groups_ptr) { |
| 216 | return ERR(NOT_IMPLEMENTED); |
| 217 | } |
| 218 | |
| 219 | static jvmtiError GetStackTrace(jvmtiEnv* env, |
| 220 | jthread thread, |
| 221 | jint start_depth, |
| 222 | jint max_frame_count, |
| 223 | jvmtiFrameInfo* frame_buffer, |
| 224 | jint* count_ptr) { |
Andreas Gampe | b5eb94a | 2016-10-27 19:23:09 -0700 | [diff] [blame] | 225 | return StackUtil::GetStackTrace(env, |
| 226 | thread, |
| 227 | start_depth, |
| 228 | max_frame_count, |
| 229 | frame_buffer, |
| 230 | count_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | static jvmtiError GetAllStackTraces(jvmtiEnv* env, |
| 234 | jint max_frame_count, |
| 235 | jvmtiStackInfo** stack_info_ptr, |
| 236 | jint* thread_count_ptr) { |
| 237 | return ERR(NOT_IMPLEMENTED); |
| 238 | } |
| 239 | |
| 240 | static jvmtiError GetThreadListStackTraces(jvmtiEnv* env, |
| 241 | jint thread_count, |
| 242 | const jthread* thread_list, |
| 243 | jint max_frame_count, |
| 244 | jvmtiStackInfo** stack_info_ptr) { |
| 245 | return ERR(NOT_IMPLEMENTED); |
| 246 | } |
| 247 | |
| 248 | static jvmtiError GetFrameCount(jvmtiEnv* env, jthread thread, jint* count_ptr) { |
| 249 | return ERR(NOT_IMPLEMENTED); |
| 250 | } |
| 251 | |
| 252 | static jvmtiError PopFrame(jvmtiEnv* env, jthread thread) { |
| 253 | return ERR(NOT_IMPLEMENTED); |
| 254 | } |
| 255 | |
| 256 | static jvmtiError GetFrameLocation(jvmtiEnv* env, |
| 257 | jthread thread, |
| 258 | jint depth, |
| 259 | jmethodID* method_ptr, |
| 260 | jlocation* location_ptr) { |
| 261 | return ERR(NOT_IMPLEMENTED); |
| 262 | } |
| 263 | |
| 264 | static jvmtiError NotifyFramePop(jvmtiEnv* env, jthread thread, jint depth) { |
| 265 | return ERR(NOT_IMPLEMENTED); |
| 266 | } |
| 267 | |
| 268 | static jvmtiError ForceEarlyReturnObject(jvmtiEnv* env, jthread thread, jobject value) { |
| 269 | return ERR(NOT_IMPLEMENTED); |
| 270 | } |
| 271 | |
| 272 | static jvmtiError ForceEarlyReturnInt(jvmtiEnv* env, jthread thread, jint value) { |
| 273 | return ERR(NOT_IMPLEMENTED); |
| 274 | } |
| 275 | |
| 276 | static jvmtiError ForceEarlyReturnLong(jvmtiEnv* env, jthread thread, jlong value) { |
| 277 | return ERR(NOT_IMPLEMENTED); |
| 278 | } |
| 279 | |
| 280 | static jvmtiError ForceEarlyReturnFloat(jvmtiEnv* env, jthread thread, jfloat value) { |
| 281 | return ERR(NOT_IMPLEMENTED); |
| 282 | } |
| 283 | |
| 284 | static jvmtiError ForceEarlyReturnDouble(jvmtiEnv* env, jthread thread, jdouble value) { |
| 285 | return ERR(NOT_IMPLEMENTED); |
| 286 | } |
| 287 | |
| 288 | static jvmtiError ForceEarlyReturnVoid(jvmtiEnv* env, jthread thread) { |
| 289 | return ERR(NOT_IMPLEMENTED); |
| 290 | } |
| 291 | |
| 292 | static jvmtiError FollowReferences(jvmtiEnv* env, |
| 293 | jint heap_filter, |
| 294 | jclass klass, |
| 295 | jobject initial_object, |
| 296 | const jvmtiHeapCallbacks* callbacks, |
| 297 | const void* user_data) { |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 298 | HeapUtil heap_util(&gObjectTagTable); |
| 299 | return heap_util.FollowReferences(env, |
| 300 | heap_filter, |
| 301 | klass, |
| 302 | initial_object, |
| 303 | callbacks, |
| 304 | user_data); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | static jvmtiError IterateThroughHeap(jvmtiEnv* env, |
| 308 | jint heap_filter, |
| 309 | jclass klass, |
| 310 | const jvmtiHeapCallbacks* callbacks, |
| 311 | const void* user_data) { |
Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 312 | ENSURE_HAS_CAP(env, can_tag_objects); |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 313 | HeapUtil heap_util(&gObjectTagTable); |
| 314 | return heap_util.IterateThroughHeap(env, heap_filter, klass, callbacks, user_data); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | static jvmtiError GetTag(jvmtiEnv* env, jobject object, jlong* tag_ptr) { |
Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 318 | ENSURE_HAS_CAP(env, can_tag_objects); |
Andreas Gampe | 6dee92e | 2016-09-12 19:58:13 -0700 | [diff] [blame] | 319 | |
| 320 | JNIEnv* jni_env = GetJniEnv(env); |
| 321 | if (jni_env == nullptr) { |
| 322 | return ERR(INTERNAL); |
| 323 | } |
| 324 | |
| 325 | art::ScopedObjectAccess soa(jni_env); |
| 326 | art::ObjPtr<art::mirror::Object> obj = soa.Decode<art::mirror::Object>(object); |
| 327 | if (!gObjectTagTable.GetTag(obj.Ptr(), tag_ptr)) { |
| 328 | *tag_ptr = 0; |
| 329 | } |
| 330 | |
| 331 | return ERR(NONE); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | static jvmtiError SetTag(jvmtiEnv* env, jobject object, jlong tag) { |
Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 335 | ENSURE_HAS_CAP(env, can_tag_objects); |
| 336 | |
Andreas Gampe | 6dee92e | 2016-09-12 19:58:13 -0700 | [diff] [blame] | 337 | if (object == nullptr) { |
| 338 | return ERR(NULL_POINTER); |
| 339 | } |
| 340 | |
| 341 | JNIEnv* jni_env = GetJniEnv(env); |
| 342 | if (jni_env == nullptr) { |
| 343 | return ERR(INTERNAL); |
| 344 | } |
| 345 | |
| 346 | art::ScopedObjectAccess soa(jni_env); |
| 347 | art::ObjPtr<art::mirror::Object> obj = soa.Decode<art::mirror::Object>(object); |
Andreas Gampe | e54eee1 | 2016-10-20 19:03:58 -0700 | [diff] [blame] | 348 | gObjectTagTable.Set(obj.Ptr(), tag); |
Andreas Gampe | 6dee92e | 2016-09-12 19:58:13 -0700 | [diff] [blame] | 349 | |
| 350 | return ERR(NONE); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | static jvmtiError GetObjectsWithTags(jvmtiEnv* env, |
| 354 | jint tag_count, |
| 355 | const jlong* tags, |
| 356 | jint* count_ptr, |
| 357 | jobject** object_result_ptr, |
| 358 | jlong** tag_result_ptr) { |
Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 359 | ENSURE_HAS_CAP(env, can_tag_objects); |
| 360 | |
Andreas Gampe | 5e6046b | 2016-10-25 12:05:53 -0700 | [diff] [blame] | 361 | JNIEnv* jni_env = GetJniEnv(env); |
| 362 | if (jni_env == nullptr) { |
| 363 | return ERR(INTERNAL); |
| 364 | } |
| 365 | |
| 366 | art::ScopedObjectAccess soa(jni_env); |
| 367 | return gObjectTagTable.GetTaggedObjects(env, |
| 368 | tag_count, |
| 369 | tags, |
| 370 | count_ptr, |
| 371 | object_result_ptr, |
| 372 | tag_result_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | static jvmtiError ForceGarbageCollection(jvmtiEnv* env) { |
Andreas Gampe | 8da6d03 | 2016-10-31 19:31:03 -0700 | [diff] [blame] | 376 | return HeapUtil::ForceGarbageCollection(env); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | static jvmtiError IterateOverObjectsReachableFromObject( |
| 380 | jvmtiEnv* env, |
| 381 | jobject object, |
| 382 | jvmtiObjectReferenceCallback object_reference_callback, |
| 383 | const void* user_data) { |
| 384 | return ERR(NOT_IMPLEMENTED); |
| 385 | } |
| 386 | |
| 387 | static jvmtiError IterateOverReachableObjects(jvmtiEnv* env, |
| 388 | jvmtiHeapRootCallback heap_root_callback, |
| 389 | jvmtiStackReferenceCallback stack_ref_callback, |
| 390 | jvmtiObjectReferenceCallback object_ref_callback, |
| 391 | const void* user_data) { |
| 392 | return ERR(NOT_IMPLEMENTED); |
| 393 | } |
| 394 | |
| 395 | static jvmtiError IterateOverHeap(jvmtiEnv* env, |
| 396 | jvmtiHeapObjectFilter object_filter, |
| 397 | jvmtiHeapObjectCallback heap_object_callback, |
| 398 | const void* user_data) { |
| 399 | return ERR(NOT_IMPLEMENTED); |
| 400 | } |
| 401 | |
| 402 | static jvmtiError IterateOverInstancesOfClass(jvmtiEnv* env, |
| 403 | jclass klass, |
| 404 | jvmtiHeapObjectFilter object_filter, |
| 405 | jvmtiHeapObjectCallback heap_object_callback, |
| 406 | const void* user_data) { |
| 407 | return ERR(NOT_IMPLEMENTED); |
| 408 | } |
| 409 | |
| 410 | static jvmtiError GetLocalObject(jvmtiEnv* env, |
| 411 | jthread thread, |
| 412 | jint depth, |
| 413 | jint slot, |
| 414 | jobject* value_ptr) { |
| 415 | return ERR(NOT_IMPLEMENTED); |
| 416 | } |
| 417 | |
| 418 | static jvmtiError GetLocalInstance(jvmtiEnv* env, |
| 419 | jthread thread, |
| 420 | jint depth, |
| 421 | jobject* value_ptr) { |
| 422 | return ERR(NOT_IMPLEMENTED); |
| 423 | } |
| 424 | |
| 425 | static jvmtiError GetLocalInt(jvmtiEnv* env, |
| 426 | jthread thread, |
| 427 | jint depth, |
| 428 | jint slot, |
| 429 | jint* value_ptr) { |
| 430 | return ERR(NOT_IMPLEMENTED); |
| 431 | } |
| 432 | |
| 433 | static jvmtiError GetLocalLong(jvmtiEnv* env, |
| 434 | jthread thread, |
| 435 | jint depth, |
| 436 | jint slot, |
| 437 | jlong* value_ptr) { |
| 438 | return ERR(NOT_IMPLEMENTED); |
| 439 | } |
| 440 | |
| 441 | static jvmtiError GetLocalFloat(jvmtiEnv* env, |
| 442 | jthread thread, |
| 443 | jint depth, |
| 444 | jint slot, |
| 445 | jfloat* value_ptr) { |
| 446 | return ERR(NOT_IMPLEMENTED); |
| 447 | } |
| 448 | |
| 449 | static jvmtiError GetLocalDouble(jvmtiEnv* env, |
| 450 | jthread thread, |
| 451 | jint depth, |
| 452 | jint slot, |
| 453 | jdouble* value_ptr) { |
| 454 | return ERR(NOT_IMPLEMENTED); |
| 455 | } |
| 456 | |
| 457 | static jvmtiError SetLocalObject(jvmtiEnv* env, |
| 458 | jthread thread, |
| 459 | jint depth, |
| 460 | jint slot, |
| 461 | jobject value) { |
| 462 | return ERR(NOT_IMPLEMENTED); |
| 463 | } |
| 464 | |
| 465 | static jvmtiError SetLocalInt(jvmtiEnv* env, |
| 466 | jthread thread, |
| 467 | jint depth, |
| 468 | jint slot, |
| 469 | jint value) { |
| 470 | return ERR(NOT_IMPLEMENTED); |
| 471 | } |
| 472 | |
| 473 | static jvmtiError SetLocalLong(jvmtiEnv* env, |
| 474 | jthread thread, |
| 475 | jint depth, |
| 476 | jint slot, |
| 477 | jlong value) { |
| 478 | return ERR(NOT_IMPLEMENTED); |
| 479 | } |
| 480 | |
| 481 | static jvmtiError SetLocalFloat(jvmtiEnv* env, |
| 482 | jthread thread, |
| 483 | jint depth, |
| 484 | jint slot, |
| 485 | jfloat value) { |
| 486 | return ERR(NOT_IMPLEMENTED); |
| 487 | } |
| 488 | |
| 489 | static jvmtiError SetLocalDouble(jvmtiEnv* env, |
| 490 | jthread thread, |
| 491 | jint depth, |
| 492 | jint slot, |
| 493 | jdouble value) { |
| 494 | return ERR(NOT_IMPLEMENTED); |
| 495 | } |
| 496 | |
| 497 | static jvmtiError SetBreakpoint(jvmtiEnv* env, jmethodID method, jlocation location) { |
| 498 | return ERR(NOT_IMPLEMENTED); |
| 499 | } |
| 500 | |
| 501 | static jvmtiError ClearBreakpoint(jvmtiEnv* env, jmethodID method, jlocation location) { |
| 502 | return ERR(NOT_IMPLEMENTED); |
| 503 | } |
| 504 | |
| 505 | static jvmtiError SetFieldAccessWatch(jvmtiEnv* env, jclass klass, jfieldID field) { |
| 506 | return ERR(NOT_IMPLEMENTED); |
| 507 | } |
| 508 | |
| 509 | static jvmtiError ClearFieldAccessWatch(jvmtiEnv* env, jclass klass, jfieldID field) { |
| 510 | return ERR(NOT_IMPLEMENTED); |
| 511 | } |
| 512 | |
| 513 | static jvmtiError SetFieldModificationWatch(jvmtiEnv* env, jclass klass, jfieldID field) { |
| 514 | return ERR(NOT_IMPLEMENTED); |
| 515 | } |
| 516 | |
| 517 | static jvmtiError ClearFieldModificationWatch(jvmtiEnv* env, jclass klass, jfieldID field) { |
| 518 | return ERR(NOT_IMPLEMENTED); |
| 519 | } |
| 520 | |
| 521 | static jvmtiError GetLoadedClasses(jvmtiEnv* env, jint* class_count_ptr, jclass** classes_ptr) { |
Andreas Gampe | aa8b60c | 2016-10-12 12:51:25 -0700 | [diff] [blame] | 522 | HeapUtil heap_util(&gObjectTagTable); |
| 523 | return heap_util.GetLoadedClasses(env, class_count_ptr, classes_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | static jvmtiError GetClassLoaderClasses(jvmtiEnv* env, |
| 527 | jobject initiating_loader, |
| 528 | jint* class_count_ptr, |
| 529 | jclass** classes_ptr) { |
| 530 | return ERR(NOT_IMPLEMENTED); |
| 531 | } |
| 532 | |
| 533 | static jvmtiError GetClassSignature(jvmtiEnv* env, |
| 534 | jclass klass, |
| 535 | char** signature_ptr, |
| 536 | char** generic_ptr) { |
Andreas Gampe | e492ae3 | 2016-10-28 19:34:57 -0700 | [diff] [blame] | 537 | return ClassUtil::GetClassSignature(env, klass, signature_ptr, generic_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | static jvmtiError GetClassStatus(jvmtiEnv* env, jclass klass, jint* status_ptr) { |
Andreas Gampe | ff9d209 | 2017-01-06 09:12:49 -0800 | [diff] [blame] | 541 | return ClassUtil::GetClassStatus(env, klass, status_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | static jvmtiError GetSourceFileName(jvmtiEnv* env, jclass klass, char** source_name_ptr) { |
| 545 | return ERR(NOT_IMPLEMENTED); |
| 546 | } |
| 547 | |
| 548 | static jvmtiError GetClassModifiers(jvmtiEnv* env, jclass klass, jint* modifiers_ptr) { |
Andreas Gampe | 64013e5 | 2017-01-06 13:07:19 -0800 | [diff] [blame] | 549 | return ClassUtil::GetClassModifiers(env, klass, modifiers_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | static jvmtiError GetClassMethods(jvmtiEnv* env, |
| 553 | jclass klass, |
| 554 | jint* method_count_ptr, |
| 555 | jmethodID** methods_ptr) { |
Andreas Gampe | 18fee4d | 2017-01-06 11:36:35 -0800 | [diff] [blame] | 556 | return ClassUtil::GetClassMethods(env, klass, method_count_ptr, methods_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | static jvmtiError GetClassFields(jvmtiEnv* env, |
| 560 | jclass klass, |
| 561 | jint* field_count_ptr, |
| 562 | jfieldID** fields_ptr) { |
Andreas Gampe | ac58727 | 2017-01-05 15:21:34 -0800 | [diff] [blame] | 563 | return ClassUtil::GetClassFields(env, klass, field_count_ptr, fields_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | static jvmtiError GetImplementedInterfaces(jvmtiEnv* env, |
| 567 | jclass klass, |
| 568 | jint* interface_count_ptr, |
| 569 | jclass** interfaces_ptr) { |
Andreas Gampe | 8b07e47 | 2017-01-06 14:20:39 -0800 | [diff] [blame] | 570 | return ClassUtil::GetImplementedInterfaces(env, klass, interface_count_ptr, interfaces_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | static jvmtiError GetClassVersionNumbers(jvmtiEnv* env, |
| 574 | jclass klass, |
| 575 | jint* minor_version_ptr, |
| 576 | jint* major_version_ptr) { |
| 577 | return ERR(NOT_IMPLEMENTED); |
| 578 | } |
| 579 | |
| 580 | static jvmtiError GetConstantPool(jvmtiEnv* env, |
| 581 | jclass klass, |
| 582 | jint* constant_pool_count_ptr, |
| 583 | jint* constant_pool_byte_count_ptr, |
| 584 | unsigned char** constant_pool_bytes_ptr) { |
| 585 | return ERR(NOT_IMPLEMENTED); |
| 586 | } |
| 587 | |
| 588 | static jvmtiError IsInterface(jvmtiEnv* env, jclass klass, jboolean* is_interface_ptr) { |
Andreas Gampe | 4fd66ec | 2017-01-05 14:42:13 -0800 | [diff] [blame] | 589 | return ClassUtil::IsInterface(env, klass, is_interface_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | static jvmtiError IsArrayClass(jvmtiEnv* env, |
| 593 | jclass klass, |
| 594 | jboolean* is_array_class_ptr) { |
Andreas Gampe | 4fd66ec | 2017-01-05 14:42:13 -0800 | [diff] [blame] | 595 | return ClassUtil::IsArrayClass(env, klass, is_array_class_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | static jvmtiError IsModifiableClass(jvmtiEnv* env, |
| 599 | jclass klass, |
| 600 | jboolean* is_modifiable_class_ptr) { |
| 601 | return ERR(NOT_IMPLEMENTED); |
| 602 | } |
| 603 | |
| 604 | static jvmtiError GetClassLoader(jvmtiEnv* env, jclass klass, jobject* classloader_ptr) { |
Andreas Gampe | 8f5b603 | 2017-01-06 15:50:55 -0800 | [diff] [blame] | 605 | return ClassUtil::GetClassLoader(env, klass, classloader_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | static jvmtiError GetSourceDebugExtension(jvmtiEnv* env, |
| 609 | jclass klass, |
| 610 | char** source_debug_extension_ptr) { |
| 611 | return ERR(NOT_IMPLEMENTED); |
| 612 | } |
| 613 | |
| 614 | static jvmtiError RetransformClasses(jvmtiEnv* env, jint class_count, const jclass* classes) { |
| 615 | return ERR(NOT_IMPLEMENTED); |
| 616 | } |
| 617 | |
| 618 | static jvmtiError RedefineClasses(jvmtiEnv* env, |
| 619 | jint class_count, |
| 620 | const jvmtiClassDefinition* class_definitions) { |
| 621 | return ERR(NOT_IMPLEMENTED); |
| 622 | } |
| 623 | |
| 624 | static jvmtiError GetObjectSize(jvmtiEnv* env, jobject object, jlong* size_ptr) { |
| 625 | return ERR(NOT_IMPLEMENTED); |
| 626 | } |
| 627 | |
| 628 | static jvmtiError GetObjectHashCode(jvmtiEnv* env, jobject object, jint* hash_code_ptr) { |
| 629 | return ERR(NOT_IMPLEMENTED); |
| 630 | } |
| 631 | |
| 632 | static jvmtiError GetObjectMonitorUsage(jvmtiEnv* env, |
| 633 | jobject object, |
| 634 | jvmtiMonitorUsage* info_ptr) { |
| 635 | return ERR(NOT_IMPLEMENTED); |
| 636 | } |
| 637 | |
| 638 | static jvmtiError GetFieldName(jvmtiEnv* env, |
| 639 | jclass klass, |
| 640 | jfieldID field, |
| 641 | char** name_ptr, |
| 642 | char** signature_ptr, |
| 643 | char** generic_ptr) { |
Andreas Gampe | ab2f0d0 | 2017-01-05 17:23:45 -0800 | [diff] [blame] | 644 | return FieldUtil::GetFieldName(env, klass, field, name_ptr, signature_ptr, generic_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | static jvmtiError GetFieldDeclaringClass(jvmtiEnv* env, |
| 648 | jclass klass, |
| 649 | jfieldID field, |
| 650 | jclass* declaring_class_ptr) { |
Andreas Gampe | ab2f0d0 | 2017-01-05 17:23:45 -0800 | [diff] [blame] | 651 | return FieldUtil::GetFieldDeclaringClass(env, klass, field, declaring_class_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | static jvmtiError GetFieldModifiers(jvmtiEnv* env, |
| 655 | jclass klass, |
| 656 | jfieldID field, |
| 657 | jint* modifiers_ptr) { |
Andreas Gampe | ab2f0d0 | 2017-01-05 17:23:45 -0800 | [diff] [blame] | 658 | return FieldUtil::GetFieldModifiers(env, klass, field, modifiers_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | static jvmtiError IsFieldSynthetic(jvmtiEnv* env, |
| 662 | jclass klass, |
| 663 | jfieldID field, |
| 664 | jboolean* is_synthetic_ptr) { |
Andreas Gampe | ab2f0d0 | 2017-01-05 17:23:45 -0800 | [diff] [blame] | 665 | return FieldUtil::IsFieldSynthetic(env, klass, field, is_synthetic_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | static jvmtiError GetMethodName(jvmtiEnv* env, |
| 669 | jmethodID method, |
| 670 | char** name_ptr, |
| 671 | char** signature_ptr, |
| 672 | char** generic_ptr) { |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 673 | return MethodUtil::GetMethodName(env, method, name_ptr, signature_ptr, generic_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | static jvmtiError GetMethodDeclaringClass(jvmtiEnv* env, |
| 677 | jmethodID method, |
| 678 | jclass* declaring_class_ptr) { |
Andreas Gampe | 368a208 | 2016-10-28 17:33:13 -0700 | [diff] [blame] | 679 | return MethodUtil::GetMethodDeclaringClass(env, method, declaring_class_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | static jvmtiError GetMethodModifiers(jvmtiEnv* env, |
| 683 | jmethodID method, |
| 684 | jint* modifiers_ptr) { |
Andreas Gampe | 36bcd4f | 2016-10-28 18:07:18 -0700 | [diff] [blame] | 685 | return MethodUtil::GetMethodModifiers(env, method, modifiers_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | static jvmtiError GetMaxLocals(jvmtiEnv* env, |
| 689 | jmethodID method, |
| 690 | jint* max_ptr) { |
| 691 | return ERR(NOT_IMPLEMENTED); |
| 692 | } |
| 693 | |
| 694 | static jvmtiError GetArgumentsSize(jvmtiEnv* env, |
| 695 | jmethodID method, |
| 696 | jint* size_ptr) { |
| 697 | return ERR(NOT_IMPLEMENTED); |
| 698 | } |
| 699 | |
| 700 | static jvmtiError GetLineNumberTable(jvmtiEnv* env, |
| 701 | jmethodID method, |
| 702 | jint* entry_count_ptr, |
| 703 | jvmtiLineNumberEntry** table_ptr) { |
Andreas Gampe | da3e561 | 2016-12-13 19:00:53 -0800 | [diff] [blame] | 704 | return MethodUtil::GetLineNumberTable(env, method, entry_count_ptr, table_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | static jvmtiError GetMethodLocation(jvmtiEnv* env, |
| 708 | jmethodID method, |
| 709 | jlocation* start_location_ptr, |
| 710 | jlocation* end_location_ptr) { |
| 711 | return ERR(NOT_IMPLEMENTED); |
| 712 | } |
| 713 | |
| 714 | static jvmtiError GetLocalVariableTable(jvmtiEnv* env, |
| 715 | jmethodID method, |
| 716 | jint* entry_count_ptr, |
| 717 | jvmtiLocalVariableEntry** table_ptr) { |
| 718 | return ERR(NOT_IMPLEMENTED); |
| 719 | } |
| 720 | |
| 721 | static jvmtiError GetBytecodes(jvmtiEnv* env, |
| 722 | jmethodID method, |
| 723 | jint* bytecode_count_ptr, |
| 724 | unsigned char** bytecodes_ptr) { |
| 725 | return ERR(NOT_IMPLEMENTED); |
| 726 | } |
| 727 | |
| 728 | static jvmtiError IsMethodNative(jvmtiEnv* env, jmethodID method, jboolean* is_native_ptr) { |
| 729 | return ERR(NOT_IMPLEMENTED); |
| 730 | } |
| 731 | |
| 732 | static jvmtiError IsMethodSynthetic(jvmtiEnv* env, jmethodID method, jboolean* is_synthetic_ptr) { |
| 733 | return ERR(NOT_IMPLEMENTED); |
| 734 | } |
| 735 | |
| 736 | static jvmtiError IsMethodObsolete(jvmtiEnv* env, jmethodID method, jboolean* is_obsolete_ptr) { |
| 737 | return ERR(NOT_IMPLEMENTED); |
| 738 | } |
| 739 | |
| 740 | static jvmtiError SetNativeMethodPrefix(jvmtiEnv* env, const char* prefix) { |
| 741 | return ERR(NOT_IMPLEMENTED); |
| 742 | } |
| 743 | |
| 744 | static jvmtiError SetNativeMethodPrefixes(jvmtiEnv* env, jint prefix_count, char** prefixes) { |
| 745 | return ERR(NOT_IMPLEMENTED); |
| 746 | } |
| 747 | |
| 748 | static jvmtiError CreateRawMonitor(jvmtiEnv* env, const char* name, jrawMonitorID* monitor_ptr) { |
| 749 | return ERR(NOT_IMPLEMENTED); |
| 750 | } |
| 751 | |
| 752 | static jvmtiError DestroyRawMonitor(jvmtiEnv* env, jrawMonitorID monitor) { |
| 753 | return ERR(NOT_IMPLEMENTED); |
| 754 | } |
| 755 | |
| 756 | static jvmtiError RawMonitorEnter(jvmtiEnv* env, jrawMonitorID monitor) { |
| 757 | return ERR(NOT_IMPLEMENTED); |
| 758 | } |
| 759 | |
| 760 | static jvmtiError RawMonitorExit(jvmtiEnv* env, jrawMonitorID monitor) { |
| 761 | return ERR(NOT_IMPLEMENTED); |
| 762 | } |
| 763 | |
| 764 | static jvmtiError RawMonitorWait(jvmtiEnv* env, jrawMonitorID monitor, jlong millis) { |
| 765 | return ERR(NOT_IMPLEMENTED); |
| 766 | } |
| 767 | |
| 768 | static jvmtiError RawMonitorNotify(jvmtiEnv* env, jrawMonitorID monitor) { |
| 769 | return ERR(NOT_IMPLEMENTED); |
| 770 | } |
| 771 | |
| 772 | static jvmtiError RawMonitorNotifyAll(jvmtiEnv* env, jrawMonitorID monitor) { |
| 773 | return ERR(NOT_IMPLEMENTED); |
| 774 | } |
| 775 | |
| 776 | static jvmtiError SetJNIFunctionTable(jvmtiEnv* env, const jniNativeInterface* function_table) { |
| 777 | return ERR(NOT_IMPLEMENTED); |
| 778 | } |
| 779 | |
| 780 | static jvmtiError GetJNIFunctionTable(jvmtiEnv* env, jniNativeInterface** function_table) { |
| 781 | return ERR(NOT_IMPLEMENTED); |
| 782 | } |
| 783 | |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 784 | // TODO: This will require locking, so that an agent can't remove callbacks when we're dispatching |
| 785 | // an event. |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 786 | static jvmtiError SetEventCallbacks(jvmtiEnv* env, |
| 787 | const jvmtiEventCallbacks* callbacks, |
| 788 | jint size_of_callbacks) { |
Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 789 | ENSURE_VALID_ENV(env); |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 790 | if (size_of_callbacks < 0) { |
| 791 | return ERR(ILLEGAL_ARGUMENT); |
| 792 | } |
| 793 | |
| 794 | if (callbacks == nullptr) { |
| 795 | ArtJvmTiEnv::AsArtJvmTiEnv(env)->event_callbacks.reset(); |
| 796 | return ERR(NONE); |
| 797 | } |
| 798 | |
| 799 | std::unique_ptr<jvmtiEventCallbacks> tmp(new jvmtiEventCallbacks()); |
| 800 | memset(tmp.get(), 0, sizeof(jvmtiEventCallbacks)); |
| 801 | size_t copy_size = std::min(sizeof(jvmtiEventCallbacks), |
| 802 | static_cast<size_t>(size_of_callbacks)); |
| 803 | copy_size = art::RoundDown(copy_size, sizeof(void*)); |
| 804 | memcpy(tmp.get(), callbacks, copy_size); |
| 805 | |
| 806 | ArtJvmTiEnv::AsArtJvmTiEnv(env)->event_callbacks = std::move(tmp); |
| 807 | |
| 808 | return ERR(NONE); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | static jvmtiError SetEventNotificationMode(jvmtiEnv* env, |
| 812 | jvmtiEventMode mode, |
| 813 | jvmtiEvent event_type, |
| 814 | jthread event_thread, |
| 815 | ...) { |
Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 816 | ENSURE_VALID_ENV(env); |
| 817 | // TODO: Check for capabilities. |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 818 | art::Thread* art_thread = nullptr; |
| 819 | if (event_thread != nullptr) { |
| 820 | // TODO: Need non-aborting call here, to return JVMTI_ERROR_INVALID_THREAD. |
| 821 | art::ScopedObjectAccess soa(art::Thread::Current()); |
| 822 | art::MutexLock mu(soa.Self(), *art::Locks::thread_list_lock_); |
| 823 | art_thread = art::Thread::FromManagedThread(soa, event_thread); |
| 824 | |
| 825 | if (art_thread == nullptr || // The thread hasn't been started or is already dead. |
| 826 | art_thread->IsStillStarting()) { |
| 827 | // TODO: We may want to let the EventHandler know, so it could clean up masks, potentially. |
| 828 | return ERR(THREAD_NOT_ALIVE); |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | return gEventHandler.SetEvent(ArtJvmTiEnv::AsArtJvmTiEnv(env), art_thread, event_type, mode); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | static jvmtiError GenerateEvents(jvmtiEnv* env, jvmtiEvent event_type) { |
| 836 | return ERR(NOT_IMPLEMENTED); |
| 837 | } |
| 838 | |
| 839 | static jvmtiError GetExtensionFunctions(jvmtiEnv* env, |
| 840 | jint* extension_count_ptr, |
| 841 | jvmtiExtensionFunctionInfo** extensions) { |
| 842 | return ERR(NOT_IMPLEMENTED); |
| 843 | } |
| 844 | |
| 845 | static jvmtiError GetExtensionEvents(jvmtiEnv* env, |
| 846 | jint* extension_count_ptr, |
| 847 | jvmtiExtensionEventInfo** extensions) { |
| 848 | return ERR(NOT_IMPLEMENTED); |
| 849 | } |
| 850 | |
| 851 | static jvmtiError SetExtensionEventCallback(jvmtiEnv* env, |
| 852 | jint extension_event_index, |
| 853 | jvmtiExtensionEvent callback) { |
| 854 | return ERR(NOT_IMPLEMENTED); |
| 855 | } |
| 856 | |
| 857 | static jvmtiError GetPotentialCapabilities(jvmtiEnv* env, jvmtiCapabilities* capabilities_ptr) { |
Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 858 | ENSURE_VALID_ENV(env); |
| 859 | ENSURE_NON_NULL(capabilities_ptr); |
| 860 | *capabilities_ptr = kPotentialCapabilities; |
| 861 | return OK; |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | static jvmtiError AddCapabilities(jvmtiEnv* env, const jvmtiCapabilities* capabilities_ptr) { |
Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 865 | ENSURE_VALID_ENV(env); |
| 866 | ENSURE_NON_NULL(capabilities_ptr); |
| 867 | ArtJvmTiEnv* art_env = static_cast<ArtJvmTiEnv*>(env); |
| 868 | jvmtiError ret = OK; |
| 869 | #define ADD_CAPABILITY(e) \ |
| 870 | do { \ |
| 871 | if (capabilities_ptr->e == 1) { \ |
| 872 | if (kPotentialCapabilities.e == 1) { \ |
| 873 | art_env->capabilities.e = 1;\ |
| 874 | } else { \ |
| 875 | ret = ERR(NOT_AVAILABLE); \ |
| 876 | } \ |
| 877 | } \ |
| 878 | } while (false) |
| 879 | |
| 880 | ADD_CAPABILITY(can_tag_objects); |
| 881 | ADD_CAPABILITY(can_generate_field_modification_events); |
| 882 | ADD_CAPABILITY(can_generate_field_access_events); |
| 883 | ADD_CAPABILITY(can_get_bytecodes); |
| 884 | ADD_CAPABILITY(can_get_synthetic_attribute); |
| 885 | ADD_CAPABILITY(can_get_owned_monitor_info); |
| 886 | ADD_CAPABILITY(can_get_current_contended_monitor); |
| 887 | ADD_CAPABILITY(can_get_monitor_info); |
| 888 | ADD_CAPABILITY(can_pop_frame); |
| 889 | ADD_CAPABILITY(can_redefine_classes); |
| 890 | ADD_CAPABILITY(can_signal_thread); |
| 891 | ADD_CAPABILITY(can_get_source_file_name); |
| 892 | ADD_CAPABILITY(can_get_line_numbers); |
| 893 | ADD_CAPABILITY(can_get_source_debug_extension); |
| 894 | ADD_CAPABILITY(can_access_local_variables); |
| 895 | ADD_CAPABILITY(can_maintain_original_method_order); |
| 896 | ADD_CAPABILITY(can_generate_single_step_events); |
| 897 | ADD_CAPABILITY(can_generate_exception_events); |
| 898 | ADD_CAPABILITY(can_generate_frame_pop_events); |
| 899 | ADD_CAPABILITY(can_generate_breakpoint_events); |
| 900 | ADD_CAPABILITY(can_suspend); |
| 901 | ADD_CAPABILITY(can_redefine_any_class); |
| 902 | ADD_CAPABILITY(can_get_current_thread_cpu_time); |
| 903 | ADD_CAPABILITY(can_get_thread_cpu_time); |
| 904 | ADD_CAPABILITY(can_generate_method_entry_events); |
| 905 | ADD_CAPABILITY(can_generate_method_exit_events); |
| 906 | ADD_CAPABILITY(can_generate_all_class_hook_events); |
| 907 | ADD_CAPABILITY(can_generate_compiled_method_load_events); |
| 908 | ADD_CAPABILITY(can_generate_monitor_events); |
| 909 | ADD_CAPABILITY(can_generate_vm_object_alloc_events); |
| 910 | ADD_CAPABILITY(can_generate_native_method_bind_events); |
| 911 | ADD_CAPABILITY(can_generate_garbage_collection_events); |
| 912 | ADD_CAPABILITY(can_generate_object_free_events); |
| 913 | ADD_CAPABILITY(can_force_early_return); |
| 914 | ADD_CAPABILITY(can_get_owned_monitor_stack_depth_info); |
| 915 | ADD_CAPABILITY(can_get_constant_pool); |
| 916 | ADD_CAPABILITY(can_set_native_method_prefix); |
| 917 | ADD_CAPABILITY(can_retransform_classes); |
| 918 | ADD_CAPABILITY(can_retransform_any_class); |
| 919 | ADD_CAPABILITY(can_generate_resource_exhaustion_heap_events); |
| 920 | ADD_CAPABILITY(can_generate_resource_exhaustion_threads_events); |
| 921 | #undef ADD_CAPABILITY |
| 922 | return ret; |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | static jvmtiError RelinquishCapabilities(jvmtiEnv* env, |
| 926 | const jvmtiCapabilities* capabilities_ptr) { |
Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 927 | ENSURE_VALID_ENV(env); |
| 928 | ENSURE_NON_NULL(capabilities_ptr); |
| 929 | ArtJvmTiEnv* art_env = reinterpret_cast<ArtJvmTiEnv*>(env); |
| 930 | #define DEL_CAPABILITY(e) \ |
| 931 | do { \ |
| 932 | if (capabilities_ptr->e == 1) { \ |
| 933 | art_env->capabilities.e = 0;\ |
| 934 | } \ |
| 935 | } while (false) |
| 936 | |
| 937 | DEL_CAPABILITY(can_tag_objects); |
| 938 | DEL_CAPABILITY(can_generate_field_modification_events); |
| 939 | DEL_CAPABILITY(can_generate_field_access_events); |
| 940 | DEL_CAPABILITY(can_get_bytecodes); |
| 941 | DEL_CAPABILITY(can_get_synthetic_attribute); |
| 942 | DEL_CAPABILITY(can_get_owned_monitor_info); |
| 943 | DEL_CAPABILITY(can_get_current_contended_monitor); |
| 944 | DEL_CAPABILITY(can_get_monitor_info); |
| 945 | DEL_CAPABILITY(can_pop_frame); |
| 946 | DEL_CAPABILITY(can_redefine_classes); |
| 947 | DEL_CAPABILITY(can_signal_thread); |
| 948 | DEL_CAPABILITY(can_get_source_file_name); |
| 949 | DEL_CAPABILITY(can_get_line_numbers); |
| 950 | DEL_CAPABILITY(can_get_source_debug_extension); |
| 951 | DEL_CAPABILITY(can_access_local_variables); |
| 952 | DEL_CAPABILITY(can_maintain_original_method_order); |
| 953 | DEL_CAPABILITY(can_generate_single_step_events); |
| 954 | DEL_CAPABILITY(can_generate_exception_events); |
| 955 | DEL_CAPABILITY(can_generate_frame_pop_events); |
| 956 | DEL_CAPABILITY(can_generate_breakpoint_events); |
| 957 | DEL_CAPABILITY(can_suspend); |
| 958 | DEL_CAPABILITY(can_redefine_any_class); |
| 959 | DEL_CAPABILITY(can_get_current_thread_cpu_time); |
| 960 | DEL_CAPABILITY(can_get_thread_cpu_time); |
| 961 | DEL_CAPABILITY(can_generate_method_entry_events); |
| 962 | DEL_CAPABILITY(can_generate_method_exit_events); |
| 963 | DEL_CAPABILITY(can_generate_all_class_hook_events); |
| 964 | DEL_CAPABILITY(can_generate_compiled_method_load_events); |
| 965 | DEL_CAPABILITY(can_generate_monitor_events); |
| 966 | DEL_CAPABILITY(can_generate_vm_object_alloc_events); |
| 967 | DEL_CAPABILITY(can_generate_native_method_bind_events); |
| 968 | DEL_CAPABILITY(can_generate_garbage_collection_events); |
| 969 | DEL_CAPABILITY(can_generate_object_free_events); |
| 970 | DEL_CAPABILITY(can_force_early_return); |
| 971 | DEL_CAPABILITY(can_get_owned_monitor_stack_depth_info); |
| 972 | DEL_CAPABILITY(can_get_constant_pool); |
| 973 | DEL_CAPABILITY(can_set_native_method_prefix); |
| 974 | DEL_CAPABILITY(can_retransform_classes); |
| 975 | DEL_CAPABILITY(can_retransform_any_class); |
| 976 | DEL_CAPABILITY(can_generate_resource_exhaustion_heap_events); |
| 977 | DEL_CAPABILITY(can_generate_resource_exhaustion_threads_events); |
| 978 | #undef DEL_CAPABILITY |
| 979 | return OK; |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | static jvmtiError GetCapabilities(jvmtiEnv* env, jvmtiCapabilities* capabilities_ptr) { |
Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 983 | ENSURE_VALID_ENV(env); |
| 984 | ENSURE_NON_NULL(capabilities_ptr); |
| 985 | ArtJvmTiEnv* artenv = reinterpret_cast<ArtJvmTiEnv*>(env); |
| 986 | *capabilities_ptr = artenv->capabilities; |
| 987 | return OK; |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | static jvmtiError GetCurrentThreadCpuTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr) { |
| 991 | return ERR(NOT_IMPLEMENTED); |
| 992 | } |
| 993 | |
| 994 | static jvmtiError GetCurrentThreadCpuTime(jvmtiEnv* env, jlong* nanos_ptr) { |
| 995 | return ERR(NOT_IMPLEMENTED); |
| 996 | } |
| 997 | |
| 998 | static jvmtiError GetThreadCpuTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr) { |
| 999 | return ERR(NOT_IMPLEMENTED); |
| 1000 | } |
| 1001 | |
| 1002 | static jvmtiError GetThreadCpuTime(jvmtiEnv* env, jthread thread, jlong* nanos_ptr) { |
| 1003 | return ERR(NOT_IMPLEMENTED); |
| 1004 | } |
| 1005 | |
| 1006 | static jvmtiError GetTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr) { |
| 1007 | return ERR(NOT_IMPLEMENTED); |
| 1008 | } |
| 1009 | |
| 1010 | static jvmtiError GetTime(jvmtiEnv* env, jlong* nanos_ptr) { |
| 1011 | return ERR(NOT_IMPLEMENTED); |
| 1012 | } |
| 1013 | |
| 1014 | static jvmtiError GetAvailableProcessors(jvmtiEnv* env, jint* processor_count_ptr) { |
| 1015 | return ERR(NOT_IMPLEMENTED); |
| 1016 | } |
| 1017 | |
| 1018 | static jvmtiError AddToBootstrapClassLoaderSearch(jvmtiEnv* env, const char* segment) { |
| 1019 | return ERR(NOT_IMPLEMENTED); |
| 1020 | } |
| 1021 | |
| 1022 | static jvmtiError AddToSystemClassLoaderSearch(jvmtiEnv* env, const char* segment) { |
| 1023 | return ERR(NOT_IMPLEMENTED); |
| 1024 | } |
| 1025 | |
| 1026 | static jvmtiError GetSystemProperties(jvmtiEnv* env, jint* count_ptr, char*** property_ptr) { |
| 1027 | return ERR(NOT_IMPLEMENTED); |
| 1028 | } |
| 1029 | |
| 1030 | static jvmtiError GetSystemProperty(jvmtiEnv* env, const char* property, char** value_ptr) { |
| 1031 | return ERR(NOT_IMPLEMENTED); |
| 1032 | } |
| 1033 | |
| 1034 | static jvmtiError SetSystemProperty(jvmtiEnv* env, const char* property, const char* value) { |
| 1035 | return ERR(NOT_IMPLEMENTED); |
| 1036 | } |
| 1037 | |
| 1038 | static jvmtiError GetPhase(jvmtiEnv* env, jvmtiPhase* phase_ptr) { |
| 1039 | return ERR(NOT_IMPLEMENTED); |
| 1040 | } |
| 1041 | |
| 1042 | static jvmtiError DisposeEnvironment(jvmtiEnv* env) { |
Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1043 | ENSURE_VALID_ENV(env); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1044 | delete env; |
| 1045 | return OK; |
| 1046 | } |
| 1047 | |
| 1048 | static jvmtiError SetEnvironmentLocalStorage(jvmtiEnv* env, const void* data) { |
Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1049 | ENSURE_VALID_ENV(env); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1050 | reinterpret_cast<ArtJvmTiEnv*>(env)->local_data = const_cast<void*>(data); |
| 1051 | return OK; |
| 1052 | } |
| 1053 | |
| 1054 | static jvmtiError GetEnvironmentLocalStorage(jvmtiEnv* env, void** data_ptr) { |
Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1055 | ENSURE_VALID_ENV(env); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1056 | *data_ptr = reinterpret_cast<ArtJvmTiEnv*>(env)->local_data; |
| 1057 | return OK; |
| 1058 | } |
| 1059 | |
| 1060 | static jvmtiError GetVersionNumber(jvmtiEnv* env, jint* version_ptr) { |
Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1061 | ENSURE_VALID_ENV(env); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1062 | *version_ptr = JVMTI_VERSION; |
| 1063 | return OK; |
| 1064 | } |
| 1065 | |
| 1066 | static jvmtiError GetErrorName(jvmtiEnv* env, jvmtiError error, char** name_ptr) { |
Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1067 | ENSURE_NON_NULL(name_ptr); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1068 | switch (error) { |
| 1069 | #define ERROR_CASE(e) case (JVMTI_ERROR_ ## e) : do { \ |
Alex Light | 4196071 | 2017-01-06 14:44:23 -0800 | [diff] [blame] | 1070 | jvmtiError res = CopyString(env, \ |
| 1071 | "JVMTI_ERROR_"#e, \ |
| 1072 | reinterpret_cast<unsigned char**>(name_ptr)); \ |
| 1073 | if (res != OK) { \ |
| 1074 | *name_ptr = nullptr; \ |
| 1075 | return res; \ |
| 1076 | } else { \ |
| 1077 | return OK; \ |
| 1078 | } \ |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1079 | } while (false) |
| 1080 | ERROR_CASE(NONE); |
| 1081 | ERROR_CASE(INVALID_THREAD); |
| 1082 | ERROR_CASE(INVALID_THREAD_GROUP); |
| 1083 | ERROR_CASE(INVALID_PRIORITY); |
| 1084 | ERROR_CASE(THREAD_NOT_SUSPENDED); |
| 1085 | ERROR_CASE(THREAD_NOT_ALIVE); |
| 1086 | ERROR_CASE(INVALID_OBJECT); |
| 1087 | ERROR_CASE(INVALID_CLASS); |
| 1088 | ERROR_CASE(CLASS_NOT_PREPARED); |
| 1089 | ERROR_CASE(INVALID_METHODID); |
| 1090 | ERROR_CASE(INVALID_LOCATION); |
| 1091 | ERROR_CASE(INVALID_FIELDID); |
| 1092 | ERROR_CASE(NO_MORE_FRAMES); |
| 1093 | ERROR_CASE(OPAQUE_FRAME); |
| 1094 | ERROR_CASE(TYPE_MISMATCH); |
| 1095 | ERROR_CASE(INVALID_SLOT); |
| 1096 | ERROR_CASE(DUPLICATE); |
| 1097 | ERROR_CASE(NOT_FOUND); |
| 1098 | ERROR_CASE(INVALID_MONITOR); |
| 1099 | ERROR_CASE(NOT_MONITOR_OWNER); |
| 1100 | ERROR_CASE(INTERRUPT); |
| 1101 | ERROR_CASE(INVALID_CLASS_FORMAT); |
| 1102 | ERROR_CASE(CIRCULAR_CLASS_DEFINITION); |
| 1103 | ERROR_CASE(FAILS_VERIFICATION); |
| 1104 | ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_ADDED); |
| 1105 | ERROR_CASE(UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED); |
| 1106 | ERROR_CASE(INVALID_TYPESTATE); |
| 1107 | ERROR_CASE(UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED); |
| 1108 | ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_DELETED); |
| 1109 | ERROR_CASE(UNSUPPORTED_VERSION); |
| 1110 | ERROR_CASE(NAMES_DONT_MATCH); |
| 1111 | ERROR_CASE(UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED); |
| 1112 | ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED); |
| 1113 | ERROR_CASE(UNMODIFIABLE_CLASS); |
| 1114 | ERROR_CASE(NOT_AVAILABLE); |
| 1115 | ERROR_CASE(MUST_POSSESS_CAPABILITY); |
| 1116 | ERROR_CASE(NULL_POINTER); |
| 1117 | ERROR_CASE(ABSENT_INFORMATION); |
| 1118 | ERROR_CASE(INVALID_EVENT_TYPE); |
| 1119 | ERROR_CASE(ILLEGAL_ARGUMENT); |
| 1120 | ERROR_CASE(NATIVE_METHOD); |
| 1121 | ERROR_CASE(CLASS_LOADER_UNSUPPORTED); |
| 1122 | ERROR_CASE(OUT_OF_MEMORY); |
| 1123 | ERROR_CASE(ACCESS_DENIED); |
| 1124 | ERROR_CASE(WRONG_PHASE); |
| 1125 | ERROR_CASE(INTERNAL); |
| 1126 | ERROR_CASE(UNATTACHED_THREAD); |
| 1127 | ERROR_CASE(INVALID_ENVIRONMENT); |
| 1128 | #undef ERROR_CASE |
| 1129 | default: { |
Alex Light | 4196071 | 2017-01-06 14:44:23 -0800 | [diff] [blame] | 1130 | jvmtiError res = CopyString(env, |
| 1131 | "JVMTI_ERROR_UNKNOWN", |
| 1132 | reinterpret_cast<unsigned char**>(name_ptr)); |
| 1133 | if (res != OK) { |
| 1134 | *name_ptr = nullptr; |
| 1135 | return res; |
| 1136 | } else { |
| 1137 | return ERR(ILLEGAL_ARGUMENT); |
| 1138 | } |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1139 | } |
| 1140 | } |
| 1141 | } |
| 1142 | |
| 1143 | static jvmtiError SetVerboseFlag(jvmtiEnv* env, jvmtiVerboseFlag flag, jboolean value) { |
| 1144 | return ERR(NOT_IMPLEMENTED); |
| 1145 | } |
| 1146 | |
| 1147 | static jvmtiError GetJLocationFormat(jvmtiEnv* env, jvmtiJlocationFormat* format_ptr) { |
| 1148 | return ERR(NOT_IMPLEMENTED); |
| 1149 | } |
Alex Light | 9c20a14 | 2016-08-23 15:05:12 -0700 | [diff] [blame] | 1150 | |
| 1151 | // TODO Remove this once events are working. |
| 1152 | static jvmtiError RetransformClassWithHook(jvmtiEnv* env, |
| 1153 | jclass klass, |
| 1154 | jvmtiEventClassFileLoadHook hook) { |
| 1155 | std::vector<jclass> classes; |
| 1156 | classes.push_back(klass); |
| 1157 | return RetransformClassesWithHook(reinterpret_cast<ArtJvmTiEnv*>(env), classes, hook); |
| 1158 | } |
| 1159 | |
Alex Light | 1e07ca6 | 2016-12-02 11:40:56 -0800 | [diff] [blame] | 1160 | static jvmtiError RedefineClassDirect(ArtJvmTiEnv* env, |
| 1161 | jclass klass, |
| 1162 | jint dex_size, |
| 1163 | unsigned char* dex_file) { |
| 1164 | if (!IsValidEnv(env)) { |
| 1165 | return ERR(INVALID_ENVIRONMENT); |
| 1166 | } |
| 1167 | jvmtiError ret = OK; |
| 1168 | std::string location; |
| 1169 | if ((ret = GetClassLocation(env, klass, &location)) != OK) { |
| 1170 | // TODO Do something more here? Maybe give log statements? |
| 1171 | return ret; |
| 1172 | } |
| 1173 | std::string error; |
| 1174 | ret = Redefiner::RedefineClass(env, |
| 1175 | art::Runtime::Current(), |
| 1176 | art::Thread::Current(), |
| 1177 | klass, |
| 1178 | location, |
| 1179 | dex_size, |
| 1180 | reinterpret_cast<uint8_t*>(dex_file), |
| 1181 | &error); |
| 1182 | if (ret != OK) { |
| 1183 | LOG(ERROR) << "FAILURE TO REDEFINE " << error; |
| 1184 | } |
| 1185 | return ret; |
| 1186 | } |
| 1187 | |
Alex Light | 9c20a14 | 2016-08-23 15:05:12 -0700 | [diff] [blame] | 1188 | // TODO This will be called by the event handler for the art::ti Event Load Event |
| 1189 | static jvmtiError RetransformClassesWithHook(ArtJvmTiEnv* env, |
| 1190 | const std::vector<jclass>& classes, |
| 1191 | jvmtiEventClassFileLoadHook hook) { |
| 1192 | if (!IsValidEnv(env)) { |
| 1193 | return ERR(INVALID_ENVIRONMENT); |
| 1194 | } |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 1195 | jvmtiError res = OK; |
| 1196 | std::string error; |
Alex Light | 9c20a14 | 2016-08-23 15:05:12 -0700 | [diff] [blame] | 1197 | for (jclass klass : classes) { |
| 1198 | JNIEnv* jni_env = nullptr; |
| 1199 | jobject loader = nullptr; |
| 1200 | std::string name; |
| 1201 | jobject protection_domain = nullptr; |
| 1202 | jint data_len = 0; |
| 1203 | unsigned char* dex_data = nullptr; |
| 1204 | jvmtiError ret = OK; |
| 1205 | std::string location; |
| 1206 | if ((ret = GetTransformationData(env, |
| 1207 | klass, |
| 1208 | /*out*/&location, |
| 1209 | /*out*/&jni_env, |
| 1210 | /*out*/&loader, |
| 1211 | /*out*/&name, |
| 1212 | /*out*/&protection_domain, |
| 1213 | /*out*/&data_len, |
| 1214 | /*out*/&dex_data)) != OK) { |
| 1215 | // TODO Do something more here? Maybe give log statements? |
| 1216 | return ret; |
| 1217 | } |
| 1218 | jint new_data_len = 0; |
| 1219 | unsigned char* new_dex_data = nullptr; |
| 1220 | hook(env, |
| 1221 | jni_env, |
| 1222 | klass, |
| 1223 | loader, |
| 1224 | name.c_str(), |
| 1225 | protection_domain, |
| 1226 | data_len, |
| 1227 | dex_data, |
| 1228 | /*out*/&new_data_len, |
| 1229 | /*out*/&new_dex_data); |
| 1230 | // Check if anything actually changed. |
| 1231 | if ((new_data_len != 0 || new_dex_data != nullptr) && new_dex_data != dex_data) { |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 1232 | res = Redefiner::RedefineClass(env, |
| 1233 | art::Runtime::Current(), |
| 1234 | art::Thread::Current(), |
| 1235 | klass, |
| 1236 | location, |
| 1237 | new_data_len, |
| 1238 | new_dex_data, |
| 1239 | &error); |
Alex Light | 9c20a14 | 2016-08-23 15:05:12 -0700 | [diff] [blame] | 1240 | env->Deallocate(new_dex_data); |
| 1241 | } |
| 1242 | // Deallocate the old dex data. |
| 1243 | env->Deallocate(dex_data); |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 1244 | if (res != OK) { |
| 1245 | LOG(ERROR) << "FAILURE TO REDEFINE " << error; |
| 1246 | return res; |
| 1247 | } |
Alex Light | 9c20a14 | 2016-08-23 15:05:12 -0700 | [diff] [blame] | 1248 | } |
| 1249 | return OK; |
| 1250 | } |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1251 | }; |
| 1252 | |
| 1253 | static bool IsJvmtiVersion(jint version) { |
| 1254 | return version == JVMTI_VERSION_1 || |
| 1255 | version == JVMTI_VERSION_1_0 || |
| 1256 | version == JVMTI_VERSION_1_1 || |
| 1257 | version == JVMTI_VERSION_1_2 || |
| 1258 | version == JVMTI_VERSION; |
| 1259 | } |
| 1260 | |
| 1261 | // Creates a jvmtiEnv and returns it with the art::ti::Env that is associated with it. new_art_ti |
| 1262 | // is a pointer to the uninitialized memory for an art::ti::Env. |
| 1263 | static void CreateArtJvmTiEnv(art::JavaVMExt* vm, /*out*/void** new_jvmtiEnv) { |
| 1264 | struct ArtJvmTiEnv* env = new ArtJvmTiEnv(vm); |
| 1265 | *new_jvmtiEnv = env; |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 1266 | |
| 1267 | gEventHandler.RegisterArtJvmTiEnv(env); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | // A hook that the runtime uses to allow plugins to handle GetEnv calls. It returns true and |
| 1271 | // places the return value in 'env' if this library can handle the GetEnv request. Otherwise |
| 1272 | // returns false and does not modify the 'env' pointer. |
| 1273 | static jint GetEnvHandler(art::JavaVMExt* vm, /*out*/void** env, jint version) { |
| 1274 | if (IsJvmtiVersion(version)) { |
| 1275 | CreateArtJvmTiEnv(vm, env); |
| 1276 | return JNI_OK; |
| 1277 | } else { |
| 1278 | printf("version 0x%x is not valid!", version); |
| 1279 | return JNI_EVERSION; |
| 1280 | } |
| 1281 | } |
| 1282 | |
| 1283 | // The plugin initialization function. This adds the jvmti environment. |
| 1284 | extern "C" bool ArtPlugin_Initialize() { |
Andreas Gampe | e08a2be | 2016-10-06 13:13:30 -0700 | [diff] [blame] | 1285 | art::Runtime* runtime = art::Runtime::Current(); |
| 1286 | runtime->GetJavaVM()->AddEnvironmentHook(GetEnvHandler); |
| 1287 | runtime->AddSystemWeakHolder(&gObjectTagTable); |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1288 | return true; |
| 1289 | } |
| 1290 | |
| 1291 | // The actual struct holding all of the entrypoints into the jvmti interface. |
| 1292 | const jvmtiInterface_1 gJvmtiInterface = { |
Alex Light | 9c20a14 | 2016-08-23 15:05:12 -0700 | [diff] [blame] | 1293 | // SPECIAL FUNCTION: RetransformClassWithHook Is normally reserved1 |
| 1294 | // TODO Remove once we have events working. |
| 1295 | reinterpret_cast<void*>(JvmtiFunctions::RetransformClassWithHook), |
| 1296 | // nullptr, // reserved1 |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1297 | JvmtiFunctions::SetEventNotificationMode, |
Alex Light | 1e07ca6 | 2016-12-02 11:40:56 -0800 | [diff] [blame] | 1298 | // SPECIAL FUNCTION: RedefineClassDirect Is normally reserved3 |
| 1299 | // TODO Remove once we have events working. |
| 1300 | reinterpret_cast<void*>(JvmtiFunctions::RedefineClassDirect), |
| 1301 | // nullptr, // reserved3 |
Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1302 | JvmtiFunctions::GetAllThreads, |
| 1303 | JvmtiFunctions::SuspendThread, |
| 1304 | JvmtiFunctions::ResumeThread, |
| 1305 | JvmtiFunctions::StopThread, |
| 1306 | JvmtiFunctions::InterruptThread, |
| 1307 | JvmtiFunctions::GetThreadInfo, |
| 1308 | JvmtiFunctions::GetOwnedMonitorInfo, // 10 |
| 1309 | JvmtiFunctions::GetCurrentContendedMonitor, |
| 1310 | JvmtiFunctions::RunAgentThread, |
| 1311 | JvmtiFunctions::GetTopThreadGroups, |
| 1312 | JvmtiFunctions::GetThreadGroupInfo, |
| 1313 | JvmtiFunctions::GetThreadGroupChildren, |
| 1314 | JvmtiFunctions::GetFrameCount, |
| 1315 | JvmtiFunctions::GetThreadState, |
| 1316 | JvmtiFunctions::GetCurrentThread, |
| 1317 | JvmtiFunctions::GetFrameLocation, |
| 1318 | JvmtiFunctions::NotifyFramePop, // 20 |
| 1319 | JvmtiFunctions::GetLocalObject, |
| 1320 | JvmtiFunctions::GetLocalInt, |
| 1321 | JvmtiFunctions::GetLocalLong, |
| 1322 | JvmtiFunctions::GetLocalFloat, |
| 1323 | JvmtiFunctions::GetLocalDouble, |
| 1324 | JvmtiFunctions::SetLocalObject, |
| 1325 | JvmtiFunctions::SetLocalInt, |
| 1326 | JvmtiFunctions::SetLocalLong, |
| 1327 | JvmtiFunctions::SetLocalFloat, |
| 1328 | JvmtiFunctions::SetLocalDouble, // 30 |
| 1329 | JvmtiFunctions::CreateRawMonitor, |
| 1330 | JvmtiFunctions::DestroyRawMonitor, |
| 1331 | JvmtiFunctions::RawMonitorEnter, |
| 1332 | JvmtiFunctions::RawMonitorExit, |
| 1333 | JvmtiFunctions::RawMonitorWait, |
| 1334 | JvmtiFunctions::RawMonitorNotify, |
| 1335 | JvmtiFunctions::RawMonitorNotifyAll, |
| 1336 | JvmtiFunctions::SetBreakpoint, |
| 1337 | JvmtiFunctions::ClearBreakpoint, |
| 1338 | nullptr, // reserved40 |
| 1339 | JvmtiFunctions::SetFieldAccessWatch, |
| 1340 | JvmtiFunctions::ClearFieldAccessWatch, |
| 1341 | JvmtiFunctions::SetFieldModificationWatch, |
| 1342 | JvmtiFunctions::ClearFieldModificationWatch, |
| 1343 | JvmtiFunctions::IsModifiableClass, |
| 1344 | JvmtiFunctions::Allocate, |
| 1345 | JvmtiFunctions::Deallocate, |
| 1346 | JvmtiFunctions::GetClassSignature, |
| 1347 | JvmtiFunctions::GetClassStatus, |
| 1348 | JvmtiFunctions::GetSourceFileName, // 50 |
| 1349 | JvmtiFunctions::GetClassModifiers, |
| 1350 | JvmtiFunctions::GetClassMethods, |
| 1351 | JvmtiFunctions::GetClassFields, |
| 1352 | JvmtiFunctions::GetImplementedInterfaces, |
| 1353 | JvmtiFunctions::IsInterface, |
| 1354 | JvmtiFunctions::IsArrayClass, |
| 1355 | JvmtiFunctions::GetClassLoader, |
| 1356 | JvmtiFunctions::GetObjectHashCode, |
| 1357 | JvmtiFunctions::GetObjectMonitorUsage, |
| 1358 | JvmtiFunctions::GetFieldName, // 60 |
| 1359 | JvmtiFunctions::GetFieldDeclaringClass, |
| 1360 | JvmtiFunctions::GetFieldModifiers, |
| 1361 | JvmtiFunctions::IsFieldSynthetic, |
| 1362 | JvmtiFunctions::GetMethodName, |
| 1363 | JvmtiFunctions::GetMethodDeclaringClass, |
| 1364 | JvmtiFunctions::GetMethodModifiers, |
| 1365 | nullptr, // reserved67 |
| 1366 | JvmtiFunctions::GetMaxLocals, |
| 1367 | JvmtiFunctions::GetArgumentsSize, |
| 1368 | JvmtiFunctions::GetLineNumberTable, // 70 |
| 1369 | JvmtiFunctions::GetMethodLocation, |
| 1370 | JvmtiFunctions::GetLocalVariableTable, |
| 1371 | JvmtiFunctions::SetNativeMethodPrefix, |
| 1372 | JvmtiFunctions::SetNativeMethodPrefixes, |
| 1373 | JvmtiFunctions::GetBytecodes, |
| 1374 | JvmtiFunctions::IsMethodNative, |
| 1375 | JvmtiFunctions::IsMethodSynthetic, |
| 1376 | JvmtiFunctions::GetLoadedClasses, |
| 1377 | JvmtiFunctions::GetClassLoaderClasses, |
| 1378 | JvmtiFunctions::PopFrame, // 80 |
| 1379 | JvmtiFunctions::ForceEarlyReturnObject, |
| 1380 | JvmtiFunctions::ForceEarlyReturnInt, |
| 1381 | JvmtiFunctions::ForceEarlyReturnLong, |
| 1382 | JvmtiFunctions::ForceEarlyReturnFloat, |
| 1383 | JvmtiFunctions::ForceEarlyReturnDouble, |
| 1384 | JvmtiFunctions::ForceEarlyReturnVoid, |
| 1385 | JvmtiFunctions::RedefineClasses, |
| 1386 | JvmtiFunctions::GetVersionNumber, |
| 1387 | JvmtiFunctions::GetCapabilities, |
| 1388 | JvmtiFunctions::GetSourceDebugExtension, // 90 |
| 1389 | JvmtiFunctions::IsMethodObsolete, |
| 1390 | JvmtiFunctions::SuspendThreadList, |
| 1391 | JvmtiFunctions::ResumeThreadList, |
| 1392 | nullptr, // reserved94 |
| 1393 | nullptr, // reserved95 |
| 1394 | nullptr, // reserved96 |
| 1395 | nullptr, // reserved97 |
| 1396 | nullptr, // reserved98 |
| 1397 | nullptr, // reserved99 |
| 1398 | JvmtiFunctions::GetAllStackTraces, // 100 |
| 1399 | JvmtiFunctions::GetThreadListStackTraces, |
| 1400 | JvmtiFunctions::GetThreadLocalStorage, |
| 1401 | JvmtiFunctions::SetThreadLocalStorage, |
| 1402 | JvmtiFunctions::GetStackTrace, |
| 1403 | nullptr, // reserved105 |
| 1404 | JvmtiFunctions::GetTag, |
| 1405 | JvmtiFunctions::SetTag, |
| 1406 | JvmtiFunctions::ForceGarbageCollection, |
| 1407 | JvmtiFunctions::IterateOverObjectsReachableFromObject, |
| 1408 | JvmtiFunctions::IterateOverReachableObjects, // 110 |
| 1409 | JvmtiFunctions::IterateOverHeap, |
| 1410 | JvmtiFunctions::IterateOverInstancesOfClass, |
| 1411 | nullptr, // reserved113 |
| 1412 | JvmtiFunctions::GetObjectsWithTags, |
| 1413 | JvmtiFunctions::FollowReferences, |
| 1414 | JvmtiFunctions::IterateThroughHeap, |
| 1415 | nullptr, // reserved117 |
| 1416 | nullptr, // reserved118 |
| 1417 | nullptr, // reserved119 |
| 1418 | JvmtiFunctions::SetJNIFunctionTable, // 120 |
| 1419 | JvmtiFunctions::GetJNIFunctionTable, |
| 1420 | JvmtiFunctions::SetEventCallbacks, |
| 1421 | JvmtiFunctions::GenerateEvents, |
| 1422 | JvmtiFunctions::GetExtensionFunctions, |
| 1423 | JvmtiFunctions::GetExtensionEvents, |
| 1424 | JvmtiFunctions::SetExtensionEventCallback, |
| 1425 | JvmtiFunctions::DisposeEnvironment, |
| 1426 | JvmtiFunctions::GetErrorName, |
| 1427 | JvmtiFunctions::GetJLocationFormat, |
| 1428 | JvmtiFunctions::GetSystemProperties, // 130 |
| 1429 | JvmtiFunctions::GetSystemProperty, |
| 1430 | JvmtiFunctions::SetSystemProperty, |
| 1431 | JvmtiFunctions::GetPhase, |
| 1432 | JvmtiFunctions::GetCurrentThreadCpuTimerInfo, |
| 1433 | JvmtiFunctions::GetCurrentThreadCpuTime, |
| 1434 | JvmtiFunctions::GetThreadCpuTimerInfo, |
| 1435 | JvmtiFunctions::GetThreadCpuTime, |
| 1436 | JvmtiFunctions::GetTimerInfo, |
| 1437 | JvmtiFunctions::GetTime, |
| 1438 | JvmtiFunctions::GetPotentialCapabilities, // 140 |
| 1439 | nullptr, // reserved141 |
| 1440 | JvmtiFunctions::AddCapabilities, |
| 1441 | JvmtiFunctions::RelinquishCapabilities, |
| 1442 | JvmtiFunctions::GetAvailableProcessors, |
| 1443 | JvmtiFunctions::GetClassVersionNumbers, |
| 1444 | JvmtiFunctions::GetConstantPool, |
| 1445 | JvmtiFunctions::GetEnvironmentLocalStorage, |
| 1446 | JvmtiFunctions::SetEnvironmentLocalStorage, |
| 1447 | JvmtiFunctions::AddToBootstrapClassLoaderSearch, |
| 1448 | JvmtiFunctions::SetVerboseFlag, // 150 |
| 1449 | JvmtiFunctions::AddToSystemClassLoaderSearch, |
| 1450 | JvmtiFunctions::RetransformClasses, |
| 1451 | JvmtiFunctions::GetOwnedMonitorStackDepthInfo, |
| 1452 | JvmtiFunctions::GetObjectSize, |
| 1453 | JvmtiFunctions::GetLocalInstance, |
| 1454 | }; |
| 1455 | |
| 1456 | }; // namespace openjdkjvmti |