blob: 339c457c66d05474c6e5b2f0686238b0a45d1e98 [file] [log] [blame]
Alex Light49948e92016-08-11 15:35:28 -07001/* Copyright (C) 2016 The Android Open Source Project
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * This file implements interfaces from the file jvmti.h. This implementation
5 * is licensed under the same terms as the file jvmti.h. The
6 * copyright and license information for the file jvmti.h follows.
7 *
8 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
9 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
10 *
11 * This code is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 2 only, as
13 * published by the Free Software Foundation. Oracle designates this
14 * particular file as subject to the "Classpath" exception as provided
15 * by Oracle in the LICENSE file that accompanied this code.
16 *
17 * This code is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * version 2 for more details (a copy is included in the LICENSE file that
21 * accompanied this code).
22 *
23 * You should have received a copy of the GNU General Public License version
24 * 2 along with this work; if not, write to the Free Software Foundation,
25 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26 *
27 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
28 * or visit www.oracle.com if you need additional information or have any
29 * questions.
30 */
31
32#include <jni.h>
33#include "openjdkjvmti/jvmti.h"
34
35#include "gc_root-inl.h"
36#include "globals.h"
37#include "jni_env_ext-inl.h"
38#include "scoped_thread_state_change.h"
39#include "thread_list.h"
40
41// TODO Remove this at some point by annotating all the methods. It was put in to make the skeleton
42// easier to create.
43#pragma GCC diagnostic ignored "-Wunused-parameter"
44
45namespace openjdkjvmti {
46
47extern const jvmtiInterface_1 gJvmtiInterface;
48
49// A structure that is a jvmtiEnv with additional information for the runtime.
50struct ArtJvmTiEnv : public jvmtiEnv {
51 art::JavaVMExt* art_vm;
52 void* local_data;
53
54 explicit ArtJvmTiEnv(art::JavaVMExt* runtime) : art_vm(runtime), local_data(nullptr) {
55 functions = &gJvmtiInterface;
56 }
57};
58
59// Macro and constexpr to make error values less annoying to write.
60#define ERR(e) JVMTI_ERROR_ ## e
61static constexpr jvmtiError OK = JVMTI_ERROR_NONE;
62
63// Special error code for unimplemented functions in JVMTI
64static constexpr jvmtiError ERR(NOT_IMPLEMENTED) = JVMTI_ERROR_NOT_AVAILABLE;
65
66class JvmtiFunctions {
67 private:
68 static bool IsValidEnv(jvmtiEnv* env) {
69 return env != nullptr;
70 }
71
72 public:
73 static jvmtiError Allocate(jvmtiEnv* env, jlong size, unsigned char** mem_ptr) {
74 if (!IsValidEnv(env)) {
75 return ERR(INVALID_ENVIRONMENT);
76 }
77 if (mem_ptr == nullptr) {
78 return ERR(NULL_POINTER);
79 }
80 if (size < 0) {
81 return ERR(ILLEGAL_ARGUMENT);
82 } else if (size == 0) {
83 *mem_ptr = nullptr;
84 return OK;
85 }
86 *mem_ptr = static_cast<unsigned char*>(malloc(size));
87 return (*mem_ptr != nullptr) ? OK : ERR(OUT_OF_MEMORY);
88 }
89
90 static jvmtiError Deallocate(jvmtiEnv* env, unsigned char* mem) {
91 if (!IsValidEnv(env)) {
92 return ERR(INVALID_ENVIRONMENT);
93 }
94 if (mem != nullptr) {
95 free(mem);
96 }
97 return OK;
98 }
99
100 static jvmtiError GetThreadState(jvmtiEnv* env, jthread thread, jint* thread_state_ptr) {
101 return ERR(NOT_IMPLEMENTED);
102 }
103
104 static jvmtiError GetCurrentThread(jvmtiEnv* env, jthread* thread_ptr) {
105 return ERR(NOT_IMPLEMENTED);
106 }
107
108 static jvmtiError GetAllThreads(jvmtiEnv* env, jint* threads_count_ptr, jthread** threads_ptr) {
109 return ERR(NOT_IMPLEMENTED);
110 }
111
112 static jvmtiError SuspendThread(jvmtiEnv* env, jthread thread) {
113 return ERR(NOT_IMPLEMENTED);
114 }
115
116 static jvmtiError SuspendThreadList(jvmtiEnv* env,
117 jint request_count,
118 const jthread* request_list,
119 jvmtiError* results) {
120 return ERR(NOT_IMPLEMENTED);
121 }
122
123 static jvmtiError ResumeThread(jvmtiEnv* env, jthread thread) {
124 return ERR(NOT_IMPLEMENTED);
125 }
126
127 static jvmtiError ResumeThreadList(jvmtiEnv* env,
128 jint request_count,
129 const jthread* request_list,
130 jvmtiError* results) {
131 return ERR(NOT_IMPLEMENTED);
132 }
133
134 static jvmtiError StopThread(jvmtiEnv* env, jthread thread, jobject exception) {
135 return ERR(NOT_IMPLEMENTED);
136 }
137
138 static jvmtiError InterruptThread(jvmtiEnv* env, jthread thread) {
139 return ERR(NOT_IMPLEMENTED);
140 }
141
142 static jvmtiError GetThreadInfo(jvmtiEnv* env, jthread thread, jvmtiThreadInfo* info_ptr) {
143 return ERR(NOT_IMPLEMENTED);
144 }
145
146 static jvmtiError GetOwnedMonitorInfo(jvmtiEnv* env,
147 jthread thread,
148 jint* owned_monitor_count_ptr,
149 jobject** owned_monitors_ptr) {
150 return ERR(NOT_IMPLEMENTED);
151 }
152
153 static jvmtiError GetOwnedMonitorStackDepthInfo(jvmtiEnv* env,
154 jthread thread,
155 jint* monitor_info_count_ptr,
156 jvmtiMonitorStackDepthInfo** monitor_info_ptr) {
157 return ERR(NOT_IMPLEMENTED);
158 }
159
160 static jvmtiError GetCurrentContendedMonitor(jvmtiEnv* env,
161 jthread thread,
162 jobject* monitor_ptr) {
163 return ERR(NOT_IMPLEMENTED);
164 }
165
166 static jvmtiError RunAgentThread(jvmtiEnv* env,
167 jthread thread,
168 jvmtiStartFunction proc,
169 const void* arg,
170 jint priority) {
171 return ERR(NOT_IMPLEMENTED);
172 }
173
174 static jvmtiError SetThreadLocalStorage(jvmtiEnv* env, jthread thread, const void* data) {
175 return ERR(NOT_IMPLEMENTED);
176 }
177
178 static jvmtiError GetThreadLocalStorage(jvmtiEnv* env, jthread thread, void** data_ptr) {
179 return ERR(NOT_IMPLEMENTED);
180 }
181
182 static jvmtiError GetTopThreadGroups(jvmtiEnv* env,
183 jint* group_count_ptr,
184 jthreadGroup** groups_ptr) {
185 return ERR(NOT_IMPLEMENTED);
186 }
187
188 static jvmtiError GetThreadGroupInfo(jvmtiEnv* env,
189 jthreadGroup group,
190 jvmtiThreadGroupInfo* info_ptr) {
191 return ERR(NOT_IMPLEMENTED);
192 }
193
194 static jvmtiError GetThreadGroupChildren(jvmtiEnv* env,
195 jthreadGroup group,
196 jint* thread_count_ptr,
197 jthread** threads_ptr,
198 jint* group_count_ptr,
199 jthreadGroup** groups_ptr) {
200 return ERR(NOT_IMPLEMENTED);
201 }
202
203 static jvmtiError GetStackTrace(jvmtiEnv* env,
204 jthread thread,
205 jint start_depth,
206 jint max_frame_count,
207 jvmtiFrameInfo* frame_buffer,
208 jint* count_ptr) {
209 return ERR(NOT_IMPLEMENTED);
210 }
211
212 static jvmtiError GetAllStackTraces(jvmtiEnv* env,
213 jint max_frame_count,
214 jvmtiStackInfo** stack_info_ptr,
215 jint* thread_count_ptr) {
216 return ERR(NOT_IMPLEMENTED);
217 }
218
219 static jvmtiError GetThreadListStackTraces(jvmtiEnv* env,
220 jint thread_count,
221 const jthread* thread_list,
222 jint max_frame_count,
223 jvmtiStackInfo** stack_info_ptr) {
224 return ERR(NOT_IMPLEMENTED);
225 }
226
227 static jvmtiError GetFrameCount(jvmtiEnv* env, jthread thread, jint* count_ptr) {
228 return ERR(NOT_IMPLEMENTED);
229 }
230
231 static jvmtiError PopFrame(jvmtiEnv* env, jthread thread) {
232 return ERR(NOT_IMPLEMENTED);
233 }
234
235 static jvmtiError GetFrameLocation(jvmtiEnv* env,
236 jthread thread,
237 jint depth,
238 jmethodID* method_ptr,
239 jlocation* location_ptr) {
240 return ERR(NOT_IMPLEMENTED);
241 }
242
243 static jvmtiError NotifyFramePop(jvmtiEnv* env, jthread thread, jint depth) {
244 return ERR(NOT_IMPLEMENTED);
245 }
246
247 static jvmtiError ForceEarlyReturnObject(jvmtiEnv* env, jthread thread, jobject value) {
248 return ERR(NOT_IMPLEMENTED);
249 }
250
251 static jvmtiError ForceEarlyReturnInt(jvmtiEnv* env, jthread thread, jint value) {
252 return ERR(NOT_IMPLEMENTED);
253 }
254
255 static jvmtiError ForceEarlyReturnLong(jvmtiEnv* env, jthread thread, jlong value) {
256 return ERR(NOT_IMPLEMENTED);
257 }
258
259 static jvmtiError ForceEarlyReturnFloat(jvmtiEnv* env, jthread thread, jfloat value) {
260 return ERR(NOT_IMPLEMENTED);
261 }
262
263 static jvmtiError ForceEarlyReturnDouble(jvmtiEnv* env, jthread thread, jdouble value) {
264 return ERR(NOT_IMPLEMENTED);
265 }
266
267 static jvmtiError ForceEarlyReturnVoid(jvmtiEnv* env, jthread thread) {
268 return ERR(NOT_IMPLEMENTED);
269 }
270
271 static jvmtiError FollowReferences(jvmtiEnv* env,
272 jint heap_filter,
273 jclass klass,
274 jobject initial_object,
275 const jvmtiHeapCallbacks* callbacks,
276 const void* user_data) {
277 return ERR(NOT_IMPLEMENTED);
278 }
279
280 static jvmtiError IterateThroughHeap(jvmtiEnv* env,
281 jint heap_filter,
282 jclass klass,
283 const jvmtiHeapCallbacks* callbacks,
284 const void* user_data) {
285 return ERR(NOT_IMPLEMENTED);
286 }
287
288 static jvmtiError GetTag(jvmtiEnv* env, jobject object, jlong* tag_ptr) {
289 return ERR(NOT_IMPLEMENTED);
290 }
291
292 static jvmtiError SetTag(jvmtiEnv* env, jobject object, jlong tag) {
293 return ERR(NOT_IMPLEMENTED);
294 }
295
296 static jvmtiError GetObjectsWithTags(jvmtiEnv* env,
297 jint tag_count,
298 const jlong* tags,
299 jint* count_ptr,
300 jobject** object_result_ptr,
301 jlong** tag_result_ptr) {
302 return ERR(NOT_IMPLEMENTED);
303 }
304
305 static jvmtiError ForceGarbageCollection(jvmtiEnv* env) {
306 return ERR(NOT_IMPLEMENTED);
307 }
308
309 static jvmtiError IterateOverObjectsReachableFromObject(
310 jvmtiEnv* env,
311 jobject object,
312 jvmtiObjectReferenceCallback object_reference_callback,
313 const void* user_data) {
314 return ERR(NOT_IMPLEMENTED);
315 }
316
317 static jvmtiError IterateOverReachableObjects(jvmtiEnv* env,
318 jvmtiHeapRootCallback heap_root_callback,
319 jvmtiStackReferenceCallback stack_ref_callback,
320 jvmtiObjectReferenceCallback object_ref_callback,
321 const void* user_data) {
322 return ERR(NOT_IMPLEMENTED);
323 }
324
325 static jvmtiError IterateOverHeap(jvmtiEnv* env,
326 jvmtiHeapObjectFilter object_filter,
327 jvmtiHeapObjectCallback heap_object_callback,
328 const void* user_data) {
329 return ERR(NOT_IMPLEMENTED);
330 }
331
332 static jvmtiError IterateOverInstancesOfClass(jvmtiEnv* env,
333 jclass klass,
334 jvmtiHeapObjectFilter object_filter,
335 jvmtiHeapObjectCallback heap_object_callback,
336 const void* user_data) {
337 return ERR(NOT_IMPLEMENTED);
338 }
339
340 static jvmtiError GetLocalObject(jvmtiEnv* env,
341 jthread thread,
342 jint depth,
343 jint slot,
344 jobject* value_ptr) {
345 return ERR(NOT_IMPLEMENTED);
346 }
347
348 static jvmtiError GetLocalInstance(jvmtiEnv* env,
349 jthread thread,
350 jint depth,
351 jobject* value_ptr) {
352 return ERR(NOT_IMPLEMENTED);
353 }
354
355 static jvmtiError GetLocalInt(jvmtiEnv* env,
356 jthread thread,
357 jint depth,
358 jint slot,
359 jint* value_ptr) {
360 return ERR(NOT_IMPLEMENTED);
361 }
362
363 static jvmtiError GetLocalLong(jvmtiEnv* env,
364 jthread thread,
365 jint depth,
366 jint slot,
367 jlong* value_ptr) {
368 return ERR(NOT_IMPLEMENTED);
369 }
370
371 static jvmtiError GetLocalFloat(jvmtiEnv* env,
372 jthread thread,
373 jint depth,
374 jint slot,
375 jfloat* value_ptr) {
376 return ERR(NOT_IMPLEMENTED);
377 }
378
379 static jvmtiError GetLocalDouble(jvmtiEnv* env,
380 jthread thread,
381 jint depth,
382 jint slot,
383 jdouble* value_ptr) {
384 return ERR(NOT_IMPLEMENTED);
385 }
386
387 static jvmtiError SetLocalObject(jvmtiEnv* env,
388 jthread thread,
389 jint depth,
390 jint slot,
391 jobject value) {
392 return ERR(NOT_IMPLEMENTED);
393 }
394
395 static jvmtiError SetLocalInt(jvmtiEnv* env,
396 jthread thread,
397 jint depth,
398 jint slot,
399 jint value) {
400 return ERR(NOT_IMPLEMENTED);
401 }
402
403 static jvmtiError SetLocalLong(jvmtiEnv* env,
404 jthread thread,
405 jint depth,
406 jint slot,
407 jlong value) {
408 return ERR(NOT_IMPLEMENTED);
409 }
410
411 static jvmtiError SetLocalFloat(jvmtiEnv* env,
412 jthread thread,
413 jint depth,
414 jint slot,
415 jfloat value) {
416 return ERR(NOT_IMPLEMENTED);
417 }
418
419 static jvmtiError SetLocalDouble(jvmtiEnv* env,
420 jthread thread,
421 jint depth,
422 jint slot,
423 jdouble value) {
424 return ERR(NOT_IMPLEMENTED);
425 }
426
427 static jvmtiError SetBreakpoint(jvmtiEnv* env, jmethodID method, jlocation location) {
428 return ERR(NOT_IMPLEMENTED);
429 }
430
431 static jvmtiError ClearBreakpoint(jvmtiEnv* env, jmethodID method, jlocation location) {
432 return ERR(NOT_IMPLEMENTED);
433 }
434
435 static jvmtiError SetFieldAccessWatch(jvmtiEnv* env, jclass klass, jfieldID field) {
436 return ERR(NOT_IMPLEMENTED);
437 }
438
439 static jvmtiError ClearFieldAccessWatch(jvmtiEnv* env, jclass klass, jfieldID field) {
440 return ERR(NOT_IMPLEMENTED);
441 }
442
443 static jvmtiError SetFieldModificationWatch(jvmtiEnv* env, jclass klass, jfieldID field) {
444 return ERR(NOT_IMPLEMENTED);
445 }
446
447 static jvmtiError ClearFieldModificationWatch(jvmtiEnv* env, jclass klass, jfieldID field) {
448 return ERR(NOT_IMPLEMENTED);
449 }
450
451 static jvmtiError GetLoadedClasses(jvmtiEnv* env, jint* class_count_ptr, jclass** classes_ptr) {
452 return ERR(NOT_IMPLEMENTED);
453 }
454
455 static jvmtiError GetClassLoaderClasses(jvmtiEnv* env,
456 jobject initiating_loader,
457 jint* class_count_ptr,
458 jclass** classes_ptr) {
459 return ERR(NOT_IMPLEMENTED);
460 }
461
462 static jvmtiError GetClassSignature(jvmtiEnv* env,
463 jclass klass,
464 char** signature_ptr,
465 char** generic_ptr) {
466 return ERR(NOT_IMPLEMENTED);
467 }
468
469 static jvmtiError GetClassStatus(jvmtiEnv* env, jclass klass, jint* status_ptr) {
470 return ERR(NOT_IMPLEMENTED);
471 }
472
473 static jvmtiError GetSourceFileName(jvmtiEnv* env, jclass klass, char** source_name_ptr) {
474 return ERR(NOT_IMPLEMENTED);
475 }
476
477 static jvmtiError GetClassModifiers(jvmtiEnv* env, jclass klass, jint* modifiers_ptr) {
478 return ERR(NOT_IMPLEMENTED);
479 }
480
481 static jvmtiError GetClassMethods(jvmtiEnv* env,
482 jclass klass,
483 jint* method_count_ptr,
484 jmethodID** methods_ptr) {
485 return ERR(NOT_IMPLEMENTED);
486 }
487
488 static jvmtiError GetClassFields(jvmtiEnv* env,
489 jclass klass,
490 jint* field_count_ptr,
491 jfieldID** fields_ptr) {
492 return ERR(NOT_IMPLEMENTED);
493 }
494
495 static jvmtiError GetImplementedInterfaces(jvmtiEnv* env,
496 jclass klass,
497 jint* interface_count_ptr,
498 jclass** interfaces_ptr) {
499 return ERR(NOT_IMPLEMENTED);
500 }
501
502 static jvmtiError GetClassVersionNumbers(jvmtiEnv* env,
503 jclass klass,
504 jint* minor_version_ptr,
505 jint* major_version_ptr) {
506 return ERR(NOT_IMPLEMENTED);
507 }
508
509 static jvmtiError GetConstantPool(jvmtiEnv* env,
510 jclass klass,
511 jint* constant_pool_count_ptr,
512 jint* constant_pool_byte_count_ptr,
513 unsigned char** constant_pool_bytes_ptr) {
514 return ERR(NOT_IMPLEMENTED);
515 }
516
517 static jvmtiError IsInterface(jvmtiEnv* env, jclass klass, jboolean* is_interface_ptr) {
518 return ERR(NOT_IMPLEMENTED);
519 }
520
521 static jvmtiError IsArrayClass(jvmtiEnv* env,
522 jclass klass,
523 jboolean* is_array_class_ptr) {
524 return ERR(NOT_IMPLEMENTED);
525 }
526
527 static jvmtiError IsModifiableClass(jvmtiEnv* env,
528 jclass klass,
529 jboolean* is_modifiable_class_ptr) {
530 return ERR(NOT_IMPLEMENTED);
531 }
532
533 static jvmtiError GetClassLoader(jvmtiEnv* env, jclass klass, jobject* classloader_ptr) {
534 return ERR(NOT_IMPLEMENTED);
535 }
536
537 static jvmtiError GetSourceDebugExtension(jvmtiEnv* env,
538 jclass klass,
539 char** source_debug_extension_ptr) {
540 return ERR(NOT_IMPLEMENTED);
541 }
542
543 static jvmtiError RetransformClasses(jvmtiEnv* env, jint class_count, const jclass* classes) {
544 return ERR(NOT_IMPLEMENTED);
545 }
546
547 static jvmtiError RedefineClasses(jvmtiEnv* env,
548 jint class_count,
549 const jvmtiClassDefinition* class_definitions) {
550 return ERR(NOT_IMPLEMENTED);
551 }
552
553 static jvmtiError GetObjectSize(jvmtiEnv* env, jobject object, jlong* size_ptr) {
554 return ERR(NOT_IMPLEMENTED);
555 }
556
557 static jvmtiError GetObjectHashCode(jvmtiEnv* env, jobject object, jint* hash_code_ptr) {
558 return ERR(NOT_IMPLEMENTED);
559 }
560
561 static jvmtiError GetObjectMonitorUsage(jvmtiEnv* env,
562 jobject object,
563 jvmtiMonitorUsage* info_ptr) {
564 return ERR(NOT_IMPLEMENTED);
565 }
566
567 static jvmtiError GetFieldName(jvmtiEnv* env,
568 jclass klass,
569 jfieldID field,
570 char** name_ptr,
571 char** signature_ptr,
572 char** generic_ptr) {
573 return ERR(NOT_IMPLEMENTED);
574 }
575
576 static jvmtiError GetFieldDeclaringClass(jvmtiEnv* env,
577 jclass klass,
578 jfieldID field,
579 jclass* declaring_class_ptr) {
580 return ERR(NOT_IMPLEMENTED);
581 }
582
583 static jvmtiError GetFieldModifiers(jvmtiEnv* env,
584 jclass klass,
585 jfieldID field,
586 jint* modifiers_ptr) {
587 return ERR(NOT_IMPLEMENTED);
588 }
589
590 static jvmtiError IsFieldSynthetic(jvmtiEnv* env,
591 jclass klass,
592 jfieldID field,
593 jboolean* is_synthetic_ptr) {
594 return ERR(NOT_IMPLEMENTED);
595 }
596
597 static jvmtiError GetMethodName(jvmtiEnv* env,
598 jmethodID method,
599 char** name_ptr,
600 char** signature_ptr,
601 char** generic_ptr) {
602 return ERR(NOT_IMPLEMENTED);
603 }
604
605 static jvmtiError GetMethodDeclaringClass(jvmtiEnv* env,
606 jmethodID method,
607 jclass* declaring_class_ptr) {
608 return ERR(NOT_IMPLEMENTED);
609 }
610
611 static jvmtiError GetMethodModifiers(jvmtiEnv* env,
612 jmethodID method,
613 jint* modifiers_ptr) {
614 return ERR(NOT_IMPLEMENTED);
615 }
616
617 static jvmtiError GetMaxLocals(jvmtiEnv* env,
618 jmethodID method,
619 jint* max_ptr) {
620 return ERR(NOT_IMPLEMENTED);
621 }
622
623 static jvmtiError GetArgumentsSize(jvmtiEnv* env,
624 jmethodID method,
625 jint* size_ptr) {
626 return ERR(NOT_IMPLEMENTED);
627 }
628
629 static jvmtiError GetLineNumberTable(jvmtiEnv* env,
630 jmethodID method,
631 jint* entry_count_ptr,
632 jvmtiLineNumberEntry** table_ptr) {
633 return ERR(NOT_IMPLEMENTED);
634 }
635
636 static jvmtiError GetMethodLocation(jvmtiEnv* env,
637 jmethodID method,
638 jlocation* start_location_ptr,
639 jlocation* end_location_ptr) {
640 return ERR(NOT_IMPLEMENTED);
641 }
642
643 static jvmtiError GetLocalVariableTable(jvmtiEnv* env,
644 jmethodID method,
645 jint* entry_count_ptr,
646 jvmtiLocalVariableEntry** table_ptr) {
647 return ERR(NOT_IMPLEMENTED);
648 }
649
650 static jvmtiError GetBytecodes(jvmtiEnv* env,
651 jmethodID method,
652 jint* bytecode_count_ptr,
653 unsigned char** bytecodes_ptr) {
654 return ERR(NOT_IMPLEMENTED);
655 }
656
657 static jvmtiError IsMethodNative(jvmtiEnv* env, jmethodID method, jboolean* is_native_ptr) {
658 return ERR(NOT_IMPLEMENTED);
659 }
660
661 static jvmtiError IsMethodSynthetic(jvmtiEnv* env, jmethodID method, jboolean* is_synthetic_ptr) {
662 return ERR(NOT_IMPLEMENTED);
663 }
664
665 static jvmtiError IsMethodObsolete(jvmtiEnv* env, jmethodID method, jboolean* is_obsolete_ptr) {
666 return ERR(NOT_IMPLEMENTED);
667 }
668
669 static jvmtiError SetNativeMethodPrefix(jvmtiEnv* env, const char* prefix) {
670 return ERR(NOT_IMPLEMENTED);
671 }
672
673 static jvmtiError SetNativeMethodPrefixes(jvmtiEnv* env, jint prefix_count, char** prefixes) {
674 return ERR(NOT_IMPLEMENTED);
675 }
676
677 static jvmtiError CreateRawMonitor(jvmtiEnv* env, const char* name, jrawMonitorID* monitor_ptr) {
678 return ERR(NOT_IMPLEMENTED);
679 }
680
681 static jvmtiError DestroyRawMonitor(jvmtiEnv* env, jrawMonitorID monitor) {
682 return ERR(NOT_IMPLEMENTED);
683 }
684
685 static jvmtiError RawMonitorEnter(jvmtiEnv* env, jrawMonitorID monitor) {
686 return ERR(NOT_IMPLEMENTED);
687 }
688
689 static jvmtiError RawMonitorExit(jvmtiEnv* env, jrawMonitorID monitor) {
690 return ERR(NOT_IMPLEMENTED);
691 }
692
693 static jvmtiError RawMonitorWait(jvmtiEnv* env, jrawMonitorID monitor, jlong millis) {
694 return ERR(NOT_IMPLEMENTED);
695 }
696
697 static jvmtiError RawMonitorNotify(jvmtiEnv* env, jrawMonitorID monitor) {
698 return ERR(NOT_IMPLEMENTED);
699 }
700
701 static jvmtiError RawMonitorNotifyAll(jvmtiEnv* env, jrawMonitorID monitor) {
702 return ERR(NOT_IMPLEMENTED);
703 }
704
705 static jvmtiError SetJNIFunctionTable(jvmtiEnv* env, const jniNativeInterface* function_table) {
706 return ERR(NOT_IMPLEMENTED);
707 }
708
709 static jvmtiError GetJNIFunctionTable(jvmtiEnv* env, jniNativeInterface** function_table) {
710 return ERR(NOT_IMPLEMENTED);
711 }
712
713 static jvmtiError SetEventCallbacks(jvmtiEnv* env,
714 const jvmtiEventCallbacks* callbacks,
715 jint size_of_callbacks) {
716 return ERR(NOT_IMPLEMENTED);
717 }
718
719 static jvmtiError SetEventNotificationMode(jvmtiEnv* env,
720 jvmtiEventMode mode,
721 jvmtiEvent event_type,
722 jthread event_thread,
723 ...) {
724 return ERR(NOT_IMPLEMENTED);
725 }
726
727 static jvmtiError GenerateEvents(jvmtiEnv* env, jvmtiEvent event_type) {
728 return ERR(NOT_IMPLEMENTED);
729 }
730
731 static jvmtiError GetExtensionFunctions(jvmtiEnv* env,
732 jint* extension_count_ptr,
733 jvmtiExtensionFunctionInfo** extensions) {
734 return ERR(NOT_IMPLEMENTED);
735 }
736
737 static jvmtiError GetExtensionEvents(jvmtiEnv* env,
738 jint* extension_count_ptr,
739 jvmtiExtensionEventInfo** extensions) {
740 return ERR(NOT_IMPLEMENTED);
741 }
742
743 static jvmtiError SetExtensionEventCallback(jvmtiEnv* env,
744 jint extension_event_index,
745 jvmtiExtensionEvent callback) {
746 return ERR(NOT_IMPLEMENTED);
747 }
748
749 static jvmtiError GetPotentialCapabilities(jvmtiEnv* env, jvmtiCapabilities* capabilities_ptr) {
750 return ERR(NOT_IMPLEMENTED);
751 }
752
753 static jvmtiError AddCapabilities(jvmtiEnv* env, const jvmtiCapabilities* capabilities_ptr) {
754 return ERR(NOT_IMPLEMENTED);
755 }
756
757 static jvmtiError RelinquishCapabilities(jvmtiEnv* env,
758 const jvmtiCapabilities* capabilities_ptr) {
759 return ERR(NOT_IMPLEMENTED);
760 }
761
762 static jvmtiError GetCapabilities(jvmtiEnv* env, jvmtiCapabilities* capabilities_ptr) {
763 return ERR(NOT_IMPLEMENTED);
764 }
765
766 static jvmtiError GetCurrentThreadCpuTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr) {
767 return ERR(NOT_IMPLEMENTED);
768 }
769
770 static jvmtiError GetCurrentThreadCpuTime(jvmtiEnv* env, jlong* nanos_ptr) {
771 return ERR(NOT_IMPLEMENTED);
772 }
773
774 static jvmtiError GetThreadCpuTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr) {
775 return ERR(NOT_IMPLEMENTED);
776 }
777
778 static jvmtiError GetThreadCpuTime(jvmtiEnv* env, jthread thread, jlong* nanos_ptr) {
779 return ERR(NOT_IMPLEMENTED);
780 }
781
782 static jvmtiError GetTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr) {
783 return ERR(NOT_IMPLEMENTED);
784 }
785
786 static jvmtiError GetTime(jvmtiEnv* env, jlong* nanos_ptr) {
787 return ERR(NOT_IMPLEMENTED);
788 }
789
790 static jvmtiError GetAvailableProcessors(jvmtiEnv* env, jint* processor_count_ptr) {
791 return ERR(NOT_IMPLEMENTED);
792 }
793
794 static jvmtiError AddToBootstrapClassLoaderSearch(jvmtiEnv* env, const char* segment) {
795 return ERR(NOT_IMPLEMENTED);
796 }
797
798 static jvmtiError AddToSystemClassLoaderSearch(jvmtiEnv* env, const char* segment) {
799 return ERR(NOT_IMPLEMENTED);
800 }
801
802 static jvmtiError GetSystemProperties(jvmtiEnv* env, jint* count_ptr, char*** property_ptr) {
803 return ERR(NOT_IMPLEMENTED);
804 }
805
806 static jvmtiError GetSystemProperty(jvmtiEnv* env, const char* property, char** value_ptr) {
807 return ERR(NOT_IMPLEMENTED);
808 }
809
810 static jvmtiError SetSystemProperty(jvmtiEnv* env, const char* property, const char* value) {
811 return ERR(NOT_IMPLEMENTED);
812 }
813
814 static jvmtiError GetPhase(jvmtiEnv* env, jvmtiPhase* phase_ptr) {
815 return ERR(NOT_IMPLEMENTED);
816 }
817
818 static jvmtiError DisposeEnvironment(jvmtiEnv* env) {
819 if (!IsValidEnv(env)) {
820 return ERR(INVALID_ENVIRONMENT);
821 }
822 delete env;
823 return OK;
824 }
825
826 static jvmtiError SetEnvironmentLocalStorage(jvmtiEnv* env, const void* data) {
827 if (!IsValidEnv(env)) {
828 return ERR(INVALID_ENVIRONMENT);
829 }
830 reinterpret_cast<ArtJvmTiEnv*>(env)->local_data = const_cast<void*>(data);
831 return OK;
832 }
833
834 static jvmtiError GetEnvironmentLocalStorage(jvmtiEnv* env, void** data_ptr) {
835 if (!IsValidEnv(env)) {
836 return ERR(INVALID_ENVIRONMENT);
837 }
838 *data_ptr = reinterpret_cast<ArtJvmTiEnv*>(env)->local_data;
839 return OK;
840 }
841
842 static jvmtiError GetVersionNumber(jvmtiEnv* env, jint* version_ptr) {
843 if (!IsValidEnv(env)) {
844 return ERR(INVALID_ENVIRONMENT);
845 }
846 *version_ptr = JVMTI_VERSION;
847 return OK;
848 }
849
850 static jvmtiError GetErrorName(jvmtiEnv* env, jvmtiError error, char** name_ptr) {
851 if (!IsValidEnv(env)) {
852 return ERR(INVALID_ENVIRONMENT);
853 }
854 if (name_ptr == nullptr) {
855 return ERR(NULL_POINTER);
856 }
857 switch (error) {
858#define ERROR_CASE(e) case (JVMTI_ERROR_ ## e) : do { \
859 *name_ptr = const_cast<char*>("JVMTI_ERROR_"#e); \
860 return OK; \
861 } while (false)
862 ERROR_CASE(NONE);
863 ERROR_CASE(INVALID_THREAD);
864 ERROR_CASE(INVALID_THREAD_GROUP);
865 ERROR_CASE(INVALID_PRIORITY);
866 ERROR_CASE(THREAD_NOT_SUSPENDED);
867 ERROR_CASE(THREAD_NOT_ALIVE);
868 ERROR_CASE(INVALID_OBJECT);
869 ERROR_CASE(INVALID_CLASS);
870 ERROR_CASE(CLASS_NOT_PREPARED);
871 ERROR_CASE(INVALID_METHODID);
872 ERROR_CASE(INVALID_LOCATION);
873 ERROR_CASE(INVALID_FIELDID);
874 ERROR_CASE(NO_MORE_FRAMES);
875 ERROR_CASE(OPAQUE_FRAME);
876 ERROR_CASE(TYPE_MISMATCH);
877 ERROR_CASE(INVALID_SLOT);
878 ERROR_CASE(DUPLICATE);
879 ERROR_CASE(NOT_FOUND);
880 ERROR_CASE(INVALID_MONITOR);
881 ERROR_CASE(NOT_MONITOR_OWNER);
882 ERROR_CASE(INTERRUPT);
883 ERROR_CASE(INVALID_CLASS_FORMAT);
884 ERROR_CASE(CIRCULAR_CLASS_DEFINITION);
885 ERROR_CASE(FAILS_VERIFICATION);
886 ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_ADDED);
887 ERROR_CASE(UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED);
888 ERROR_CASE(INVALID_TYPESTATE);
889 ERROR_CASE(UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED);
890 ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_DELETED);
891 ERROR_CASE(UNSUPPORTED_VERSION);
892 ERROR_CASE(NAMES_DONT_MATCH);
893 ERROR_CASE(UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED);
894 ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED);
895 ERROR_CASE(UNMODIFIABLE_CLASS);
896 ERROR_CASE(NOT_AVAILABLE);
897 ERROR_CASE(MUST_POSSESS_CAPABILITY);
898 ERROR_CASE(NULL_POINTER);
899 ERROR_CASE(ABSENT_INFORMATION);
900 ERROR_CASE(INVALID_EVENT_TYPE);
901 ERROR_CASE(ILLEGAL_ARGUMENT);
902 ERROR_CASE(NATIVE_METHOD);
903 ERROR_CASE(CLASS_LOADER_UNSUPPORTED);
904 ERROR_CASE(OUT_OF_MEMORY);
905 ERROR_CASE(ACCESS_DENIED);
906 ERROR_CASE(WRONG_PHASE);
907 ERROR_CASE(INTERNAL);
908 ERROR_CASE(UNATTACHED_THREAD);
909 ERROR_CASE(INVALID_ENVIRONMENT);
910#undef ERROR_CASE
911 default: {
912 *name_ptr = const_cast<char*>("JVMTI_ERROR_UNKNOWN");
913 return ERR(ILLEGAL_ARGUMENT);
914 }
915 }
916 }
917
918 static jvmtiError SetVerboseFlag(jvmtiEnv* env, jvmtiVerboseFlag flag, jboolean value) {
919 return ERR(NOT_IMPLEMENTED);
920 }
921
922 static jvmtiError GetJLocationFormat(jvmtiEnv* env, jvmtiJlocationFormat* format_ptr) {
923 return ERR(NOT_IMPLEMENTED);
924 }
925};
926
927static bool IsJvmtiVersion(jint version) {
928 return version == JVMTI_VERSION_1 ||
929 version == JVMTI_VERSION_1_0 ||
930 version == JVMTI_VERSION_1_1 ||
931 version == JVMTI_VERSION_1_2 ||
932 version == JVMTI_VERSION;
933}
934
935// Creates a jvmtiEnv and returns it with the art::ti::Env that is associated with it. new_art_ti
936// is a pointer to the uninitialized memory for an art::ti::Env.
937static void CreateArtJvmTiEnv(art::JavaVMExt* vm, /*out*/void** new_jvmtiEnv) {
938 struct ArtJvmTiEnv* env = new ArtJvmTiEnv(vm);
939 *new_jvmtiEnv = env;
940}
941
942// A hook that the runtime uses to allow plugins to handle GetEnv calls. It returns true and
943// places the return value in 'env' if this library can handle the GetEnv request. Otherwise
944// returns false and does not modify the 'env' pointer.
945static jint GetEnvHandler(art::JavaVMExt* vm, /*out*/void** env, jint version) {
946 if (IsJvmtiVersion(version)) {
947 CreateArtJvmTiEnv(vm, env);
948 return JNI_OK;
949 } else {
950 printf("version 0x%x is not valid!", version);
951 return JNI_EVERSION;
952 }
953}
954
955// The plugin initialization function. This adds the jvmti environment.
956extern "C" bool ArtPlugin_Initialize() {
957 art::Runtime::Current()->GetJavaVM()->AddEnvironmentHook(GetEnvHandler);
958 return true;
959}
960
961// The actual struct holding all of the entrypoints into the jvmti interface.
962const jvmtiInterface_1 gJvmtiInterface = {
963 nullptr, // reserved1
964 JvmtiFunctions::SetEventNotificationMode,
965 nullptr, // reserved3
966 JvmtiFunctions::GetAllThreads,
967 JvmtiFunctions::SuspendThread,
968 JvmtiFunctions::ResumeThread,
969 JvmtiFunctions::StopThread,
970 JvmtiFunctions::InterruptThread,
971 JvmtiFunctions::GetThreadInfo,
972 JvmtiFunctions::GetOwnedMonitorInfo, // 10
973 JvmtiFunctions::GetCurrentContendedMonitor,
974 JvmtiFunctions::RunAgentThread,
975 JvmtiFunctions::GetTopThreadGroups,
976 JvmtiFunctions::GetThreadGroupInfo,
977 JvmtiFunctions::GetThreadGroupChildren,
978 JvmtiFunctions::GetFrameCount,
979 JvmtiFunctions::GetThreadState,
980 JvmtiFunctions::GetCurrentThread,
981 JvmtiFunctions::GetFrameLocation,
982 JvmtiFunctions::NotifyFramePop, // 20
983 JvmtiFunctions::GetLocalObject,
984 JvmtiFunctions::GetLocalInt,
985 JvmtiFunctions::GetLocalLong,
986 JvmtiFunctions::GetLocalFloat,
987 JvmtiFunctions::GetLocalDouble,
988 JvmtiFunctions::SetLocalObject,
989 JvmtiFunctions::SetLocalInt,
990 JvmtiFunctions::SetLocalLong,
991 JvmtiFunctions::SetLocalFloat,
992 JvmtiFunctions::SetLocalDouble, // 30
993 JvmtiFunctions::CreateRawMonitor,
994 JvmtiFunctions::DestroyRawMonitor,
995 JvmtiFunctions::RawMonitorEnter,
996 JvmtiFunctions::RawMonitorExit,
997 JvmtiFunctions::RawMonitorWait,
998 JvmtiFunctions::RawMonitorNotify,
999 JvmtiFunctions::RawMonitorNotifyAll,
1000 JvmtiFunctions::SetBreakpoint,
1001 JvmtiFunctions::ClearBreakpoint,
1002 nullptr, // reserved40
1003 JvmtiFunctions::SetFieldAccessWatch,
1004 JvmtiFunctions::ClearFieldAccessWatch,
1005 JvmtiFunctions::SetFieldModificationWatch,
1006 JvmtiFunctions::ClearFieldModificationWatch,
1007 JvmtiFunctions::IsModifiableClass,
1008 JvmtiFunctions::Allocate,
1009 JvmtiFunctions::Deallocate,
1010 JvmtiFunctions::GetClassSignature,
1011 JvmtiFunctions::GetClassStatus,
1012 JvmtiFunctions::GetSourceFileName, // 50
1013 JvmtiFunctions::GetClassModifiers,
1014 JvmtiFunctions::GetClassMethods,
1015 JvmtiFunctions::GetClassFields,
1016 JvmtiFunctions::GetImplementedInterfaces,
1017 JvmtiFunctions::IsInterface,
1018 JvmtiFunctions::IsArrayClass,
1019 JvmtiFunctions::GetClassLoader,
1020 JvmtiFunctions::GetObjectHashCode,
1021 JvmtiFunctions::GetObjectMonitorUsage,
1022 JvmtiFunctions::GetFieldName, // 60
1023 JvmtiFunctions::GetFieldDeclaringClass,
1024 JvmtiFunctions::GetFieldModifiers,
1025 JvmtiFunctions::IsFieldSynthetic,
1026 JvmtiFunctions::GetMethodName,
1027 JvmtiFunctions::GetMethodDeclaringClass,
1028 JvmtiFunctions::GetMethodModifiers,
1029 nullptr, // reserved67
1030 JvmtiFunctions::GetMaxLocals,
1031 JvmtiFunctions::GetArgumentsSize,
1032 JvmtiFunctions::GetLineNumberTable, // 70
1033 JvmtiFunctions::GetMethodLocation,
1034 JvmtiFunctions::GetLocalVariableTable,
1035 JvmtiFunctions::SetNativeMethodPrefix,
1036 JvmtiFunctions::SetNativeMethodPrefixes,
1037 JvmtiFunctions::GetBytecodes,
1038 JvmtiFunctions::IsMethodNative,
1039 JvmtiFunctions::IsMethodSynthetic,
1040 JvmtiFunctions::GetLoadedClasses,
1041 JvmtiFunctions::GetClassLoaderClasses,
1042 JvmtiFunctions::PopFrame, // 80
1043 JvmtiFunctions::ForceEarlyReturnObject,
1044 JvmtiFunctions::ForceEarlyReturnInt,
1045 JvmtiFunctions::ForceEarlyReturnLong,
1046 JvmtiFunctions::ForceEarlyReturnFloat,
1047 JvmtiFunctions::ForceEarlyReturnDouble,
1048 JvmtiFunctions::ForceEarlyReturnVoid,
1049 JvmtiFunctions::RedefineClasses,
1050 JvmtiFunctions::GetVersionNumber,
1051 JvmtiFunctions::GetCapabilities,
1052 JvmtiFunctions::GetSourceDebugExtension, // 90
1053 JvmtiFunctions::IsMethodObsolete,
1054 JvmtiFunctions::SuspendThreadList,
1055 JvmtiFunctions::ResumeThreadList,
1056 nullptr, // reserved94
1057 nullptr, // reserved95
1058 nullptr, // reserved96
1059 nullptr, // reserved97
1060 nullptr, // reserved98
1061 nullptr, // reserved99
1062 JvmtiFunctions::GetAllStackTraces, // 100
1063 JvmtiFunctions::GetThreadListStackTraces,
1064 JvmtiFunctions::GetThreadLocalStorage,
1065 JvmtiFunctions::SetThreadLocalStorage,
1066 JvmtiFunctions::GetStackTrace,
1067 nullptr, // reserved105
1068 JvmtiFunctions::GetTag,
1069 JvmtiFunctions::SetTag,
1070 JvmtiFunctions::ForceGarbageCollection,
1071 JvmtiFunctions::IterateOverObjectsReachableFromObject,
1072 JvmtiFunctions::IterateOverReachableObjects, // 110
1073 JvmtiFunctions::IterateOverHeap,
1074 JvmtiFunctions::IterateOverInstancesOfClass,
1075 nullptr, // reserved113
1076 JvmtiFunctions::GetObjectsWithTags,
1077 JvmtiFunctions::FollowReferences,
1078 JvmtiFunctions::IterateThroughHeap,
1079 nullptr, // reserved117
1080 nullptr, // reserved118
1081 nullptr, // reserved119
1082 JvmtiFunctions::SetJNIFunctionTable, // 120
1083 JvmtiFunctions::GetJNIFunctionTable,
1084 JvmtiFunctions::SetEventCallbacks,
1085 JvmtiFunctions::GenerateEvents,
1086 JvmtiFunctions::GetExtensionFunctions,
1087 JvmtiFunctions::GetExtensionEvents,
1088 JvmtiFunctions::SetExtensionEventCallback,
1089 JvmtiFunctions::DisposeEnvironment,
1090 JvmtiFunctions::GetErrorName,
1091 JvmtiFunctions::GetJLocationFormat,
1092 JvmtiFunctions::GetSystemProperties, // 130
1093 JvmtiFunctions::GetSystemProperty,
1094 JvmtiFunctions::SetSystemProperty,
1095 JvmtiFunctions::GetPhase,
1096 JvmtiFunctions::GetCurrentThreadCpuTimerInfo,
1097 JvmtiFunctions::GetCurrentThreadCpuTime,
1098 JvmtiFunctions::GetThreadCpuTimerInfo,
1099 JvmtiFunctions::GetThreadCpuTime,
1100 JvmtiFunctions::GetTimerInfo,
1101 JvmtiFunctions::GetTime,
1102 JvmtiFunctions::GetPotentialCapabilities, // 140
1103 nullptr, // reserved141
1104 JvmtiFunctions::AddCapabilities,
1105 JvmtiFunctions::RelinquishCapabilities,
1106 JvmtiFunctions::GetAvailableProcessors,
1107 JvmtiFunctions::GetClassVersionNumbers,
1108 JvmtiFunctions::GetConstantPool,
1109 JvmtiFunctions::GetEnvironmentLocalStorage,
1110 JvmtiFunctions::SetEnvironmentLocalStorage,
1111 JvmtiFunctions::AddToBootstrapClassLoaderSearch,
1112 JvmtiFunctions::SetVerboseFlag, // 150
1113 JvmtiFunctions::AddToSystemClassLoaderSearch,
1114 JvmtiFunctions::RetransformClasses,
1115 JvmtiFunctions::GetOwnedMonitorStackDepthInfo,
1116 JvmtiFunctions::GetObjectSize,
1117 JvmtiFunctions::GetLocalInstance,
1118};
1119
1120}; // namespace openjdkjvmti