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