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