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