-
Notifications
You must be signed in to change notification settings - Fork 728
/
jvmtiHelpers.c
2084 lines (1752 loc) · 68.1 KB
/
jvmtiHelpers.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* Copyright IBM Corp. and others 1991
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] https://openjdk.org/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
*******************************************************************************/
#include "jvmtiHelpers.h"
#include "jvmti_internal.h"
#include "j9cp.h"
extern jvmtiNativeInterface jvmtiFunctionTable;
/* Jazz 99339: Map JVMTI event number to the reason code for zAAP switching on zOS.
* Note: refer to jvmtiEventCallbacks (/runtime/include/jvmti.h) for reserved JVMTI events.
*/
#if defined(J9VM_OPT_JAVA_OFFLOAD_SUPPORT)
static const UDATA reasonCodeFromJVMTIEvent[] = {
J9_JNI_OFFLOAD_SWITCH_JVMTI_VM_INIT, /* JVMTI_EVENT_VM_INIT */
J9_JNI_OFFLOAD_SWITCH_JVMTI_VM_DEATH, /* JVMTI_EVENT_VM_DEATH */
J9_JNI_OFFLOAD_SWITCH_JVMTI_THREAD_START, /* JVMTI_EVENT_THREAD_START */
J9_JNI_OFFLOAD_SWITCH_JVMTI_THREAD_END, /* JVMTI_EVENT_THREAD_END */
J9_JNI_OFFLOAD_SWITCH_JVMTI_CLASS_FILE_LOAD_HOOK, /* JVMTI_EVENT_CLASS_FILE_LOAD_HOOK */
J9_JNI_OFFLOAD_SWITCH_JVMTI_CLASS_LOAD, /* JVMTI_EVENT_CLASS_LOAD */
J9_JNI_OFFLOAD_SWITCH_JVMTI_CLASS_PREPARE, /* JVMTI_EVENT_CLASS_PREPARE */
J9_JNI_OFFLOAD_SWITCH_JVMTI_VM_START, /* JVMTI_EVENT_VM_START */
J9_JNI_OFFLOAD_SWITCH_JVMTI_EXCEPTION, /* JVMTI_EVENT_EXCEPTION */
J9_JNI_OFFLOAD_SWITCH_JVMTI_EXCEPTION_CATCH, /* JVMTI_EVENT_EXCEPTION_CATCH */
J9_JNI_OFFLOAD_SWITCH_JVMTI_SINGLE_STEP, /* JVMTI_EVENT_SINGLE_STEP */
J9_JNI_OFFLOAD_SWITCH_JVMTI_FRAME_POP, /* JVMTI_EVENT_FRAME_POP */
J9_JNI_OFFLOAD_SWITCH_JVMTI_BREAKPOINT, /* JVMTI_EVENT_BREAKPOINT */
J9_JNI_OFFLOAD_SWITCH_JVMTI_FIELD_ACCESS, /* JVMTI_EVENT_FIELD_ACCESS */
J9_JNI_OFFLOAD_SWITCH_JVMTI_FIELD_MODIFICATION, /* JVMTI_EVENT_FIELD_MODIFICATION */
J9_JNI_OFFLOAD_SWITCH_JVMTI_METHOD_ENTRY, /* JVMTI_EVENT_METHOD_ENTRY */
J9_JNI_OFFLOAD_SWITCH_JVMTI_METHOD_EXIT, /* JVMTI_EVENT_METHOD_EXIT */
J9_JNI_OFFLOAD_SWITCH_JVMTI_NATIVE_METHOD_BIND, /* JVMTI_EVENT_NATIVE_METHOD_BIND */
J9_JNI_OFFLOAD_SWITCH_JVMTI_COMPILED_METHOD_LOAD, /* JVMTI_EVENT_COMPILED_METHOD_LOAD */
J9_JNI_OFFLOAD_SWITCH_JVMTI_COMPILED_METHOD_UNLOAD, /* JVMTI_EVENT_COMPILED_METHOD_UNLOAD */
J9_JNI_OFFLOAD_SWITCH_JVMTI_DYNAMIC_CODE_GENERATED, /* JVMTI_EVENT_DYNAMIC_CODE_GENERATED */
J9_JNI_OFFLOAD_SWITCH_JVMTI_DATA_DUMP_REQUEST, /* JVMTI_EVENT_DATA_DUMP_REQUEST */
0, /* Reserved for JVMTI event */
J9_JNI_OFFLOAD_SWITCH_JVMTI_MONITOR_WAIT, /* JVMTI_EVENT_MONITOR_WAIT */
J9_JNI_OFFLOAD_SWITCH_JVMTI_MONITOR_WAITED, /* JVMTI_EVENT_MONITOR_WAITED */
J9_JNI_OFFLOAD_SWITCH_JVMTI_MONITOR_CONTENDED_ENTER, /* JVMTI_EVENT_MONITOR_CONTENDED_ENTER */
J9_JNI_OFFLOAD_SWITCH_JVMTI_MONITOR_CONTENDED_ENTERED, /* JVMTI_EVENT_MONITOR_CONTENDED_ENTERED */
0, /* Reserved for JVMTI event */
0, /* Reserved for JVMTI event */
0, /* Reserved for JVMTI event */
J9_JNI_OFFLOAD_SWITCH_JVMTI_RESOURCE_EXHAUSTED, /* JVMTI_EVENT_RESOURCE_EXHAUSTED */
J9_JNI_OFFLOAD_SWITCH_JVMTI_GC_START, /* JVMTI_EVENT_GARBAGE_COLLECTION_START */
J9_JNI_OFFLOAD_SWITCH_JVMTI_GC_FINISH, /* JVMTI_EVENT_GARBAGE_COLLECTION_FINISH */
J9_JNI_OFFLOAD_SWITCH_JVMTI_OBJECT_FREE, /* JVMTI_EVENT_OBJECT_FREE */
J9_JNI_OFFLOAD_SWITCH_JVMTI_VM_OBJECT_ALLOC, /* JVMTI_EVENT_VM_OBJECT_ALLOC */
0, /* Reserved for JVMTI event */
J9_JNI_OFFLOAD_SWITCH_JVMTI_SAMPLED_OBJECT_ALLOC, /* JVMTI_EVENT_SAMPLED_OBJECT_ALLOC */
J9_JNI_OFFLOAD_SWITCH_J9JVMTI_COMPILING_START, /* J9JVMTI_EVENT_COM_IBM_COMPILING_START */
J9_JNI_OFFLOAD_SWITCH_J9JVMTI_COMPILING_END, /* J9JVMTI_EVENT_COM_IBM_COMPILING_END */
J9_JNI_OFFLOAD_SWITCH_J9JVMTI_INSTRUMENTABLE_OBJECT_ALLOC, /* J9JVMTI_EVENT_COM_IBM_INSTRUMENTABLE_OBJECT_ALLOC */
J9_JNI_OFFLOAD_SWITCH_J9JVMTI_VM_DUMP_START, /* J9JVMTI_EVENT_COM_IBM_VM_DUMP_START */
J9_JNI_OFFLOAD_SWITCH_J9JVMTI_VM_DUMP_END, /* J9JVMTI_EVENT_COM_IBM_VM_DUMP_END */
J9_JNI_OFFLOAD_SWITCH_J9JVMTI_GC_CYCLE_START, /* J9JVMTI_EVENT_COM_IBM_GARBAGE_COLLECTION_CYCLE_START */
J9_JNI_OFFLOAD_SWITCH_J9JVMTI_GC_CYCLE_FINISH, /* J9JVMTI_EVENT_COM_IBM_GARBAGE_COLLECTION_CYCLE_FINISH */
J9_JNI_OFFLOAD_SWITCH_J9JVMTI_VIRTUAL_THREAD_MOUNT, /* J9JVMTI_EVENT_COM_SUN_HOTSPOT_EVENTS_VIRTUAL_THREAD_MOUNT */
J9_JNI_OFFLOAD_SWITCH_J9JVMTI_VIRTUAL_THREAD_UNMOUNT, /* J9JVMTI_EVENT_COM_SUN_HOTSPOT_EVENTS_VIRTUAL_THREAD_UNMOUNT */
};
#endif /* J9VM_OPT_JAVA_OFFLOAD_SUPPORT */
static void clearGlobalBreakpoint (J9VMThread * currentThread, J9JVMTIGlobalBreakpoint * globalBreakpoint);
static jvmtiError setGlobalBreakpoint (J9VMThread * currentThread, J9Method * ramMethod, IDATA location, J9JVMTIGlobalBreakpoint ** globalBreakpointPtr);
static jvmtiError createSingleBreakpoint (J9VMThread * currentThread, J9Method * ramMethod, IDATA location, J9JVMTIGlobalBreakpoint ** globalBreakpointPtr);
static UDATA hashObjectTag (void *entry, void *userData);
static void deleteBreakpointedMethodReference (J9VMThread * currentThread, J9JVMTIBreakpointedMethod * breakpointedMethod);
static UDATA fixBytecodesFrameIterator (J9VMThread * currentThread, J9StackWalkState * walkState);
static void fixBytecodesInAllStacks (J9JavaVM * vm, J9Method * method, UDATA delta);
static void clearSingleBreakpoint (J9VMThread * currentThread, J9JVMTIGlobalBreakpoint * globalBreakpoint);
static J9JVMTIGlobalBreakpoint * findGlobalBreakpoint (J9JVMTIData * jvmtiData, J9Method * ramMethod, IDATA location);
static J9JVMTIBreakpointedMethod * createBreakpointedMethod (J9VMThread * currentThread, J9Method * ramMethod);
static UDATA hashEqualObjectTag (void *lhsEntry, void *rhsEntry, void *userData);
static UDATA findDecompileInfoFrameIterator(J9VMThread *currentThread, J9StackWalkState *walkState);
static UDATA watchedClassHash (void *entry, void *userData);
static UDATA watchedClassEqual (void *lhsEntry, void *rhsEntry, void *userData);
static jint getThreadStateHelper(J9VMThread *currentThread, j9object_t threadObject, J9VMThread *vmThread);
jvmtiError
getVMThread(J9VMThread *currentThread, jthread thread, J9VMThread **vmThreadPtr, jvmtiError vThreadError, UDATA flags)
{
J9JavaVM *vm = currentThread->javaVM;
j9object_t threadObject = NULL;
J9VMThread *targetThread = NULL;
BOOLEAN isThreadAlive = FALSE;
#if JAVA_SPEC_VERSION >= 19
BOOLEAN isVirtualThread = FALSE;
#endif /* JAVA_SPEC_VERSION >= 19 */
if (NULL == thread) {
if (OMR_ARE_ANY_BITS_SET(flags, J9JVMTI_GETVMTHREAD_ERROR_ON_NULL_JTHREAD)) {
return JVMTI_ERROR_INVALID_THREAD;
}
#if JAVA_SPEC_VERSION >= 19
if (OMR_ARE_ANY_BITS_SET(flags, J9JVMTI_GETVMTHREAD_ERROR_ON_VIRTUALTHREAD)
&& IS_JAVA_LANG_VIRTUALTHREAD(currentThread, currentThread->threadObject)
) {
return vThreadError;
}
#endif /* JAVA_SPEC_VERSION >= 19 */
*vmThreadPtr = currentThread;
return JVMTI_ERROR_NONE;
} else {
threadObject = J9_JNI_UNWRAP_REFERENCE(thread);
if (!IS_JAVA_LANG_THREAD(currentThread, threadObject)) {
return JVMTI_ERROR_INVALID_THREAD;
}
#if JAVA_SPEC_VERSION >= 19
if (OMR_ARE_ANY_BITS_SET(flags, J9JVMTI_GETVMTHREAD_ERROR_ON_VIRTUALTHREAD)
&& IS_JAVA_LANG_VIRTUALTHREAD(currentThread, threadObject)
) {
return vThreadError;
}
#endif /* JAVA_SPEC_VERSION >= 19 */
if (currentThread->threadObject == threadObject) {
*vmThreadPtr = currentThread;
return JVMTI_ERROR_NONE;
}
}
/* Make sure the vmThread stays alive while it is being used. */
omrthread_monitor_enter(vm->vmThreadListMutex);
#if JAVA_SPEC_VERSION >= 19
isVirtualThread = IS_JAVA_LANG_VIRTUALTHREAD(currentThread, threadObject);
if (isVirtualThread) {
vm->internalVMFunctions->acquireVThreadInspector(currentThread, thread, TRUE);
jint vthreadState = J9VMJAVALANGVIRTUALTHREAD_STATE(currentThread, threadObject);
j9object_t carrierThread = (j9object_t)J9VMJAVALANGVIRTUALTHREAD_CARRIERTHREAD(currentThread, threadObject);
if (NULL != carrierThread) {
targetThread = J9VMJAVALANGTHREAD_THREADREF(currentThread, carrierThread);
}
isThreadAlive = (JVMTI_VTHREAD_STATE_NEW != vthreadState) && (JVMTI_VTHREAD_STATE_TERMINATED != vthreadState);
} else
#endif /* JAVA_SPEC_VERSION >= 19 */
{
targetThread = J9VMJAVALANGTHREAD_THREADREF(currentThread, threadObject);
isThreadAlive = J9VMJAVALANGTHREAD_STARTED(currentThread, threadObject) && (NULL != targetThread);
}
if (!isThreadAlive) {
if (OMR_ARE_ANY_BITS_SET(flags, J9JVMTI_GETVMTHREAD_ERROR_ON_DEAD_THREAD)) {
#if JAVA_SPEC_VERSION >= 19
if (isVirtualThread) {
vm->internalVMFunctions->releaseVThreadInspector(currentThread, thread);
}
#endif /* JAVA_SPEC_VERSION >= 19 */
omrthread_monitor_exit(vm->vmThreadListMutex);
return JVMTI_ERROR_THREAD_NOT_ALIVE;
}
}
*vmThreadPtr = targetThread;
if (NULL != targetThread) {
targetThread->inspectorCount += 1;
}
omrthread_monitor_exit(vm->vmThreadListMutex);
#if JAVA_SPEC_VERSION >= 19
if (isThreadAlive && !isVirtualThread) {
/* targetThread should not be NULL for alive non-virtual threads. */
Assert_JVMTI_true(NULL != targetThread);
}
#endif /* JAVA_SPEC_VERSION >= 19 */
return JVMTI_ERROR_NONE;
}
void
releaseVMThread(J9VMThread *currentThread, J9VMThread *targetThread, jthread thread)
{
#if JAVA_SPEC_VERSION >= 19
if (NULL != thread) {
j9object_t threadObject = J9_JNI_UNWRAP_REFERENCE(thread);
if ((currentThread->threadObject != threadObject) && IS_JAVA_LANG_VIRTUALTHREAD(currentThread, threadObject)) {
currentThread->javaVM->internalVMFunctions->releaseVThreadInspector(currentThread, thread);
}
}
#endif /* JAVA_SPEC_VERSION >= 19 */
if ((NULL != targetThread) && (currentThread != targetThread)) {
J9JavaVM *vm = targetThread->javaVM;
/* Release the J9VMThread (allow it to die) now that we are no longer inspecting it. */
omrthread_monitor_enter(vm->vmThreadListMutex);
if (0 == --(targetThread->inspectorCount)) {
omrthread_monitor_notify_all(vm->vmThreadListMutex);
}
omrthread_monitor_exit(vm->vmThreadListMutex);
}
}
/* Assumes that exclusive VM access and jvmtiData->mutex is held, or that execution is single-threaded (at shutdown) */
void
disposeEnvironment(J9JVMTIEnv * j9env, UDATA freeData)
{
J9JavaVM * vm = j9env->vm;
/* Mark this env as disposed - this prevents any further events being reported */
if (J9_ARE_NO_BITS_SET(j9env->flags, J9JVMTIENV_FLAG_DISPOSED)) {
J9HookInterface ** vmHook = j9env->vmHook.hookInterface;
J9HookInterface ** gcHook = j9env->gcHook.hookInterface;
J9HookInterface ** gcOmrHook = j9env->gcOmrHook.hookInterface;
#if defined (J9VM_INTERP_NATIVE_SUPPORT)
J9HookInterface** jitHook = j9env->jitHook.hookInterface;
#endif
j9env->flags |= J9JVMTIENV_FLAG_DISPOSED;
#if JAVA_SPEC_VERSION >= 11
if (j9env->capabilities.can_generate_sampled_object_alloc_events) {
J9JVMTI_DATA_FROM_VM(vm)->flags &= ~J9JVMTI_FLAG_SAMPLED_OBJECT_ALLOC_ENABLED;
/* Set sampling interval to UDATA_MAX to inform GC that sampling is not required */
vm->memoryManagerFunctions->j9gc_set_allocation_sampling_interval(vm, UDATA_MAX);
}
#endif /* JAVA_SPEC_VERSION >= 11 */
/* Remove all breakpoints */
if (j9env->breakpoints != NULL) {
J9VMThread * currentThread = vm->internalVMFunctions->currentVMThread(vm);
pool_state poolState;
J9JVMTIAgentBreakpoint * agentBreakpoint = NULL;
agentBreakpoint = pool_startDo(j9env->breakpoints, &poolState);
while (agentBreakpoint != NULL) {
deleteAgentBreakpoint(currentThread, j9env, agentBreakpoint);
agentBreakpoint = pool_nextDo(&poolState);
}
}
/* Unhook all the events - note this does not guarantee that no further events will be received - some may be in progress already */
unhookAllEvents(j9env);
/* Discard the agent IDs */
(*vmHook)->J9HookDeallocateAgentID(vmHook, j9env->vmHook.agentID);
(*gcHook)->J9HookDeallocateAgentID(gcHook, j9env->gcHook.agentID);
(*gcOmrHook)->J9HookDeallocateAgentID(gcOmrHook, j9env->gcOmrHook.agentID);
#if defined (J9VM_INTERP_NATIVE_SUPPORT)
if (jitHook != NULL) {
(*jitHook)->J9HookDeallocateAgentID(vmHook, j9env->jitHook.agentID);
}
#endif
}
/* Free the data if requested */
if (freeData) {
PORT_ACCESS_FROM_JAVAVM(vm);
j9mem_free_memory(j9env->prefixes);
if (NULL != j9env->mutex) {
omrthread_monitor_destroy(j9env->mutex);
j9env->mutex = NULL;
}
if (NULL != j9env->threadDataPoolMutex) {
omrthread_monitor_destroy(j9env->threadDataPoolMutex);
j9env->threadDataPoolMutex = NULL;
}
if (NULL != j9env->threadDataPool) {
pool_kill(j9env->threadDataPool);
j9env->threadDataPool = NULL;
}
if (NULL != j9env->objectTagTable) {
hashTableFree(j9env->objectTagTable);
j9env->objectTagTable = NULL;
}
if (NULL != j9env->watchedClasses) {
J9HashTableState walkState;
J9JVMTIWatchedClass *watchedClass = hashTableStartDo(j9env->watchedClasses, &walkState);
while (NULL != watchedClass) {
if (J9JVMTI_CLASS_REQUIRES_ALLOCATED_J9JVMTI_WATCHED_FIELD_ACCESS_BITS(watchedClass->clazz)) {
j9mem_free_memory(watchedClass->watchBits);
}
watchedClass = hashTableNextDo(&walkState);
}
hashTableFree(j9env->watchedClasses);
j9env->watchedClasses = NULL;
}
if (NULL != j9env->breakpoints) {
pool_kill(j9env->breakpoints);
j9env->breakpoints = NULL;
}
if (0 != j9env->tlsKey) {
jvmtiTLSFree(vm, j9env->tlsKey);
j9env->tlsKey = 0;
}
}
}
jint
allocateEnvironment(J9InvocationJavaVM * invocationJavaVM, jint version, void ** penv)
{
J9JavaVM * vm = NULL;
J9JVMTIData * jvmtiData = NULL;
J9JVMTIEnv * j9env;
jint rc = JNI_EDETACHED;
J9VMThread * currentThread;
Assert_JVMTI_true(NULL != invocationJavaVM);
vm = invocationJavaVM->j9vm;
jvmtiData = J9JVMTI_DATA_FROM_VM(vm);
if (getCurrentVMThread(vm, ¤tThread) == JVMTI_ERROR_NONE) {
vm->internalVMFunctions->internalEnterVMFromJNI(currentThread);
vm->internalVMFunctions->acquireExclusiveVMAccess(currentThread);
omrthread_monitor_enter(jvmtiData->mutex);
rc = JNI_ENOMEM;
j9env = pool_newElement(jvmtiData->environments);
if (j9env != NULL) {
J9HookInterface ** vmHook = vm->internalVMFunctions->getVMHookInterface(vm);
J9HookInterface ** gcHook = vm->memoryManagerFunctions->j9gc_get_hook_interface(vm);
J9HookInterface ** gcOmrHook = vm->memoryManagerFunctions->j9gc_get_omr_hook_interface(vm->omrVM);
#if defined (J9VM_INTERP_NATIVE_SUPPORT)
J9HookInterface** jitHook = vm->internalVMFunctions->getJITHookInterface(vm);
#endif
memset(j9env, 0, sizeof(J9JVMTIEnv));
j9env->functions = &jvmtiFunctionTable;
j9env->vm = vm;
#if defined(J9VM_OPT_JAVA_OFFLOAD_SUPPORT)
/* Jazz 99339: store J9NativeLibrary in J9JVMTIEnv so as to check the zAAP switching flag in the JVMTI event callbacks */
j9env->library = invocationJavaVM->reserved2_library;
#endif /* J9VM_OPT_JAVA_OFFLOAD_SUPPORT */
j9env->vmHook.hookInterface = vmHook;
j9env->gcHook.hookInterface = gcHook;
j9env->gcOmrHook.hookInterface = gcOmrHook;
#if defined (J9VM_INTERP_NATIVE_SUPPORT)
j9env->jitHook.hookInterface = jitHook;
#endif
if ((j9env->vmHook.agentID = (*vmHook)->J9HookAllocateAgentID(vmHook)) == 0) {
goto fail;
}
if ((j9env->gcHook.agentID = (*gcHook)->J9HookAllocateAgentID(gcHook)) == 0) {
goto fail;
}
if ((j9env->gcOmrHook.agentID = (*gcOmrHook)->J9HookAllocateAgentID(gcOmrHook)) == 0) {
goto fail;
}
#if defined (J9VM_INTERP_NATIVE_SUPPORT)
if (jitHook != NULL) {
if ((j9env->jitHook.agentID = (*jitHook)->J9HookAllocateAgentID(jitHook)) == 0) {
goto fail;
}
}
#endif
if (omrthread_monitor_init(&(j9env->mutex), 0) != 0) {
goto fail;
}
if (omrthread_monitor_init(&(j9env->threadDataPoolMutex), 0) != 0) {
goto fail;
}
j9env->threadDataPool = pool_new(sizeof(J9JVMTIThreadData), 0, 0, 0, J9_GET_CALLSITE(), J9MEM_CATEGORY_JVMTI, POOL_FOR_PORT(vm->portLibrary));
if (j9env->threadDataPool == NULL) {
goto fail;
}
j9env->objectTagTable = hashTableNew(OMRPORT_FROM_J9PORT(vm->portLibrary), J9_GET_CALLSITE(), 0, sizeof(J9JVMTIObjectTag), sizeof(jlong), 0, J9MEM_CATEGORY_JVMTI, hashObjectTag, hashEqualObjectTag, NULL, NULL);
if (j9env->objectTagTable == NULL) {
goto fail;
}
j9env->watchedClasses = hashTableNew(OMRPORT_FROM_J9PORT(vm->portLibrary), J9_GET_CALLSITE(), 0, sizeof(J9JVMTIWatchedClass), sizeof(UDATA), 0, J9MEM_CATEGORY_JVMTI, watchedClassHash, watchedClassEqual, NULL, NULL);
if (j9env->watchedClasses == NULL) {
goto fail;
}
j9env->breakpoints = pool_new(sizeof(J9JVMTIAgentBreakpoint), 0, 0, POOL_ALWAYS_KEEP_SORTED, J9_GET_CALLSITE(), J9MEM_CATEGORY_JVMTI, POOL_FOR_PORT(vm->portLibrary));
if (j9env->breakpoints == NULL) {
goto fail;
}
j9env->tlsKey = 0;
/* Hook the thread and virtual thread destroy events to clean up any allocated TLS structs. */
if (hookRequiredEvents(j9env) != 0) {
goto fail;
}
if (jvmtiData->environmentsHead == NULL) {
issueWriteBarrier();
jvmtiData->environmentsHead = jvmtiData->environmentsTail = j9env;
} else {
j9env->linkPrevious = jvmtiData->environmentsTail;
issueWriteBarrier();
jvmtiData->environmentsTail->linkNext = j9env;
jvmtiData->environmentsTail = j9env;
}
rc = JNI_OK;
*penv = j9env;
fail:
if (rc != JNI_OK) {
disposeEnvironment(j9env, TRUE);
}
}
omrthread_monitor_exit(jvmtiData->mutex);
vm->internalVMFunctions->releaseExclusiveVMAccess(currentThread);
vm->internalVMFunctions->internalExitVMToJNI(currentThread);
}
return rc;
}
UDATA
prepareForEvent(J9JVMTIEnv * j9env, J9VMThread * currentThread, J9VMThread * eventThread, UDATA eventNumber, jthread * threadRefPtr, UDATA * hadVMAccessPtr, UDATA wantVMAccess, UDATA jniRefSlots, UDATA * javaOffloadOldState)
{
J9JVMTIThreadData *threadData = NULL;
#if JAVA_SPEC_VERSION >= 19
j9object_t threadObj = currentThread->threadObject;
/* threadObj can be null early in J9VMThread initialization. */
if (NULL != threadObj) {
void *tlsArray = J9OBJECT_ADDRESS_LOAD(currentThread, threadObj, currentThread->javaVM->tlsOffset);
if (NULL != tlsArray) {
threadData = jvmtiTLSGet(currentThread, threadObj, j9env->tlsKey);
}
}
#else
threadData = jvmtiTLSGet(currentThread, currentThread->threadObject, j9env->tlsKey);
#endif /* JAVA_SPEC_VERSION >= 19 */
/* If this environment has been disposed, do not report any events */
if (j9env->flags & J9JVMTIENV_FLAG_DISPOSED) {
return FALSE;
}
/* Allow the VM_DEATH and THREAD_END event to be sent on a dead thread, but no others */
if (currentThread->publicFlags & J9_PUBLIC_FLAGS_STOPPED) {
if ((eventNumber != JVMTI_EVENT_VM_DEATH)
&& (eventNumber != JVMTI_EVENT_THREAD_END)
) {
return FALSE;
}
}
/* Do not issue events on threads that do not have a threadObject. We ignore this check
* when in Primordial phase since the threadObject is not initialized until sometime after
* j.l.Thread is loaded. This is done to correctly fire the Class File Load events on classes
* loaded prior to j.l.Thread. See CMVC 127730 */
if ((NULL == eventThread->threadObject) && (J9JVMTI_PHASE(j9env) != JVMTI_PHASE_PRIMORDIAL)) {
return FALSE;
}
/* See if the event is enabled either globally or for the current thread */
if (EVENT_IS_ENABLED(eventNumber, &(j9env->globalEventEnable))
|| ((NULL != threadData) && EVENT_IS_ENABLED(eventNumber, &(threadData->threadEventEnable)))
) {
j9object_t * refs;
++jniRefSlots; /* for saving the current exception */
if (threadRefPtr != NULL) {
++jniRefSlots;
}
*hadVMAccessPtr = pushEventFrame(currentThread, TRUE, jniRefSlots);
/* Preserve and clear any pending exception in the current thread */
refs = (j9object_t*) (((J9SFJNINativeMethodFrame *) currentThread->sp) + 1);
refs[0] = currentThread->currentException;
currentThread->currentException = NULL;
if (threadRefPtr != NULL) {
jthread threadRef = (jthread) (refs + 1);
*((j9object_t*) threadRef) = eventThread->threadObject;
*threadRefPtr = threadRef;
}
if (!wantVMAccess) {
currentThread->javaVM->internalVMFunctions->internalExitVMToJNI(currentThread);
}
#if defined(J9VM_OPT_JAVA_OFFLOAD_SUPPORT)
/* Jazz 99339: Switch away from the zAAP processor if running there */
if (J9_ARE_ALL_BITS_SET(currentThread->javaVM->extendedRuntimeFlags, J9_EXTENDED_RUNTIME_RESTRICT_IFA)) {
javaOffloadSwitchOff(j9env, currentThread, eventNumber, javaOffloadOldState);
}
#endif /* J9VM_OPT_JAVA_OFFLOAD_SUPPORT */
return TRUE;
}
return FALSE;
}
#if defined(J9VM_OPT_JAVA_OFFLOAD_SUPPORT)
void
javaOffloadSwitchOff(J9JVMTIEnv * j9env, J9VMThread * currentThread, UDATA eventNumber, UDATA * javaOffloadOldState)
{
J9JavaVM * vm = NULL;
BOOLEAN zAAPSwitchingFlag = FALSE;
J9NativeLibrary * nativeLibrary = j9env->library;
Assert_JVMTI_true(NULL != currentThread);
vm = currentThread->javaVM;
/* There are two cases for zAAP switching:
* 1) The agent library (most likely created by customer) calls GetEnv() at any time when required
* but doesn't need to call GetEnv() in Agent_OnLoad. Thus, it may be possible for j9env->library
* to be NULL if JVMTI is used directly by the VM.
* 2) The flag in J9NativeLibrary->doSwitching requires it to do zAAP switching.
*/
if (NULL == nativeLibrary) {
zAAPSwitchingFlag = TRUE;
} else if (J9_ARE_ALL_BITS_SET(nativeLibrary->doSwitching, J9_NATIVE_LIBRARY_SWITCH_REQUIRED)) {
zAAPSwitchingFlag = TRUE;
}
if ((NULL != vm->javaOffloadSwitchOffWithReasonFunc) && (TRUE == zAAPSwitchingFlag)) {
/* Save the old state */
*javaOffloadOldState = currentThread->javaOffloadState;
/* Zero the state and switch java offload mode OFF */
currentThread->javaOffloadState = 0;
vm->javaOffloadSwitchOffWithReasonFunc(currentThread, reasonCodeFromJVMTIEvent[eventNumber - J9JVMTI_LOWEST_EVENT]);
}
}
#endif /* J9VM_OPT_JAVA_OFFLOAD_SUPPORT */
jvmtiError
getCurrentVMThread(J9JavaVM * vm, J9VMThread ** currentThread)
{
*currentThread = vm->internalVMFunctions->currentVMThread(vm);
if (*currentThread == NULL) {
return JVMTI_ERROR_UNATTACHED_THREAD;
}
return JVMTI_ERROR_NONE;
}
jvmtiError
cStringFromUTF(jvmtiEnv * env, J9UTF8 * utf, char ** cString)
{
return cStringFromUTFChars(env, J9UTF8_DATA(utf), J9UTF8_LENGTH(utf), cString);
}
jvmtiError
cStringFromUTFChars(jvmtiEnv * env, U_8 * data, UDATA length, char ** cString)
{
jvmtiError rc = JVMTI_ERROR_NONE;
PORT_ACCESS_FROM_JVMTI(env);
*cString = j9mem_allocate_memory(length + 1, J9MEM_CATEGORY_JVMTI_ALLOCATE);
if (*cString == NULL) {
rc = JVMTI_ERROR_OUT_OF_MEMORY;
} else {
memcpy(*cString, data, length);
(*cString)[length] = '\0';
}
return rc;
}
U_16
nextUTFChar(U_8 ** pUtfData)
{
U_8 * utfData = *pUtfData;
U_16 utfChar;
utfChar = *(utfData++);
if (utfChar & 0x80) {
if (utfChar & 0x20) {
utfChar = (utfChar & 0x0F) << 12;
utfChar |= ((((U_16) *(utfData++)) & 0x3F) << 6);
utfChar |= (((U_16) *(utfData++)) & 0x3F);
} else {
utfChar = (utfChar & 0x1F) << 6;
utfChar |= (((U_16) *(utfData++)) & 0x3F);
}
}
*pUtfData = utfData;
return utfChar;
}
void
skipSignature(U_8 ** pUtfData)
{
U_16 utfChar;
/* Skip array prefixes */
do {
utfChar = nextUTFChar(pUtfData);
} while (utfChar == '[');
/* Skip to the end of Object type signatures */
if (IS_REF_OR_VAL_SIGNATURE(utfChar)) {
do {
utfChar = nextUTFChar(pUtfData);
} while (utfChar != ';');
}
}
void
finishedEvent(J9VMThread * currentThread, UDATA eventNumber, UDATA hadVMAccess, UDATA javaOffloadOldState)
{
J9SFJNINativeMethodFrame * frame = ((J9SFJNINativeMethodFrame *) (((U_8 *) currentThread->sp) + (UDATA) currentThread->literals));
/* Acquire VM access if the current thread does not already have it */
#if defined(J9VM_INTERP_ATOMIC_FREE_JNI)
if (currentThread->inNative) {
currentThread->javaVM->internalVMFunctions->internalEnterVMFromJNI(currentThread);
}
#else /* J9VM_INTERP_ATOMIC_FREE_JNI */
if (!(currentThread->publicFlags & J9_PUBLIC_FLAGS_VM_ACCESS)) {
currentThread->javaVM->internalVMFunctions->internalAcquireVMAccess(currentThread);
}
#endif /* J9VM_INTERP_ATOMIC_FREE_JNI */
/* Restore the pending exception in the current thread */
currentThread->currentException = getObjectFromRef((j9object_t*) (frame + 1));
/* Pop the frame */
popEventFrame(currentThread, hadVMAccess);
#if defined(J9VM_OPT_JAVA_OFFLOAD_SUPPORT)
/* Jazz 99339: Switch onto the zAAP processor if not running there after native finishes running on GP */
if (J9_ARE_ALL_BITS_SET(currentThread->javaVM->extendedRuntimeFlags, J9_EXTENDED_RUNTIME_RESTRICT_IFA)) {
javaOffloadSwitchOn(currentThread, eventNumber, javaOffloadOldState);
}
#endif /* J9VM_OPT_JAVA_OFFLOAD_SUPPORT */
}
#if defined(J9VM_OPT_JAVA_OFFLOAD_SUPPORT)
void
javaOffloadSwitchOn(J9VMThread * currentThread, UDATA eventNumber, UDATA javaOffloadOldState)
{
J9JavaVM *vm = NULL;
Assert_JVMTI_true(NULL != currentThread);
vm = currentThread->javaVM;
/* Check if java offload mode is enabled */
if (NULL != vm->javaOffloadSwitchOnWithReasonFunc) {
if (0 == currentThread->javaOffloadState) {
/* Call the offload switch ON */
vm->javaOffloadSwitchOnWithReasonFunc(currentThread, reasonCodeFromJVMTIEvent[eventNumber - J9JVMTI_LOWEST_EVENT]);
/* Restore the old state */
currentThread->javaOffloadState = javaOffloadOldState;
}
}
}
#endif /* J9VM_OPT_JAVA_OFFLOAD_SUPPORT */
static jint
getThreadStateHelper(J9VMThread *currentThread, j9object_t threadObject, J9VMThread *vmThread)
{
jint state = 0;
UDATA vmstate = getVMThreadObjectStatesAll(vmThread, NULL, NULL, NULL);
/* Assumes that the current thread has VM access, and the thread is locked (will not die) */
if (vmThread == NULL || (vmstate & J9VMTHREAD_STATE_UNKNOWN)) {
if (J9VMJAVALANGTHREAD_STARTED(currentThread, threadObject)) {
state |= JVMTI_THREAD_STATE_TERMINATED;
} else {
/* new thread */
}
} else if (vmstate & J9VMTHREAD_STATE_DEAD) {
state |= JVMTI_THREAD_STATE_TERMINATED;
} else {
state |= JVMTI_THREAD_STATE_ALIVE;
if (vmstate & J9VMTHREAD_STATE_SUSPENDED) {
state |= JVMTI_THREAD_STATE_SUSPENDED;
}
#if JAVA_SPEC_VERSION >= 19
/* Based on the isSuspendedInternal field, set the JVMTI
* thread state to suspended for the corresponding thread.
*/
if (0 != J9OBJECT_U32_LOAD(currentThread, threadObject, currentThread->javaVM->isSuspendedInternalOffset)) {
state |= JVMTI_THREAD_STATE_SUSPENDED;
} else {
state &= ~JVMTI_THREAD_STATE_SUSPENDED;
}
#endif /* JAVA_SPEC_VERSION >= 19 */
if (vmstate & J9VMTHREAD_STATE_INTERRUPTED) {
state |= JVMTI_THREAD_STATE_INTERRUPTED;
}
#if defined(J9VM_INTERP_ATOMIC_FREE_JNI)
if (vmThread->inNative) {
state |= JVMTI_THREAD_STATE_IN_NATIVE;
}
#else /* J9VM_INTERP_ATOMIC_FREE_JNI */
if ( (vmThread->omrVMThread->vmState & J9VMSTATE_MAJOR) == J9VMSTATE_JNI ) {
if (!(vmThread->publicFlags & J9_PUBLIC_FLAGS_VM_ACCESS)) {
state |= JVMTI_THREAD_STATE_IN_NATIVE;
}
}
#endif /* J9VM_INTERP_ATOMIC_FREE_JNI */
if (vmstate & J9VMTHREAD_STATE_BLOCKED) {
state |= JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
/* Object.wait() */
} else if (vmstate & J9VMTHREAD_STATE_WAITING) {
state |= JVMTI_THREAD_STATE_IN_OBJECT_WAIT;
state |= JVMTI_THREAD_STATE_WAITING_INDEFINITELY;
state |= JVMTI_THREAD_STATE_WAITING;
/* Object.wait(...) */
} else if (vmstate & J9VMTHREAD_STATE_WAITING_TIMED) {
state |= JVMTI_THREAD_STATE_IN_OBJECT_WAIT;
state |= JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT;
state |= JVMTI_THREAD_STATE_WAITING;
/* Lock.park() */
} else if (vmstate & J9VMTHREAD_STATE_PARKED) {
state |= JVMTI_THREAD_STATE_PARKED;
state |= JVMTI_THREAD_STATE_WAITING_INDEFINITELY;
state |= JVMTI_THREAD_STATE_WAITING;
/* Lock.park(...) */
} else if (vmstate & J9VMTHREAD_STATE_PARKED_TIMED) {
state |= JVMTI_THREAD_STATE_PARKED;
state |= JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT;
state |= JVMTI_THREAD_STATE_WAITING;
/* Thread.sleep(...) */
} else if (vmstate & J9VMTHREAD_STATE_SLEEPING) {
state |= JVMTI_THREAD_STATE_SLEEPING;
state |= JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT;
state |= JVMTI_THREAD_STATE_WAITING;
} else {
state |= JVMTI_THREAD_STATE_RUNNABLE;
}
}
return state;
}
jint
getThreadState(J9VMThread *currentThread, j9object_t threadObject)
{
J9VMThread *vmThread = J9VMJAVALANGTHREAD_THREADREF(currentThread, threadObject);
jint state = getThreadStateHelper(currentThread, threadObject, vmThread);
#if JAVA_SPEC_VERSION >= 19
if (J9_ARE_ANY_BITS_SET(state, JVMTI_THREAD_STATE_RUNNABLE)) {
if ((NULL != vmThread->currentContinuation)
&& (vmThread->threadObject != vmThread->carrierThreadObject)
) {
/* If a virtual thread is mounted on a carrier thread, then the carrier thread
* is considered implicitly parked.
*/
state &= ~JVMTI_THREAD_STATE_RUNNABLE;
state |= JVMTI_THREAD_STATE_WAITING_INDEFINITELY;
state |= JVMTI_THREAD_STATE_WAITING;
}
}
#endif /* JAVA_SPEC_VERSION >= 19 */
return state;
}
#if JAVA_SPEC_VERSION >= 19
jint
getVirtualThreadState(J9VMThread *currentThread, jthread thread)
{
J9JavaVM* vm = currentThread->javaVM;
jint rc = 0;
J9VMThread *targetThread = NULL;
Assert_JVMTI_notNull(thread);
Assert_JVMTI_mustHaveVMAccess(currentThread);
rc = getVMThread(
currentThread, thread, &targetThread, JVMTI_ERROR_NONE,
J9JVMTI_GETVMTHREAD_ERROR_ON_NULL_JTHREAD);
if (JVMTI_ERROR_NONE == rc) {
j9object_t vThreadObject = J9_JNI_UNWRAP_REFERENCE(thread);
if (NULL != targetThread) {
vm->internalVMFunctions->haltThreadForInspection(currentThread, targetThread);
rc = getThreadStateHelper(currentThread, targetThread->carrierThreadObject, targetThread);
vm->internalVMFunctions->resumeThreadForInspection(currentThread, targetThread);
} else {
jint vThreadState = (jint) J9VMJAVALANGVIRTUALTHREAD_STATE(currentThread, vThreadObject);
/* The mapping from JVMTI_VTHREAD_STATE_XXX to JVMTI_JAVA_LANG_THREAD_STATE_XXX is based
* on j.l.VirtualThread.threadState().
*/
switch (vThreadState) {
case JVMTI_VTHREAD_STATE_NEW:
rc = JVMTI_JAVA_LANG_THREAD_STATE_NEW;
break;
case JVMTI_VTHREAD_STATE_STARTED:
{
JNIEnv *env = (JNIEnv *)currentThread;
jfieldID fid = NULL;
jclass jlThread = NULL;
vm->internalVMFunctions->internalExitVMToJNI(currentThread);
jlThread = (*env)->FindClass(env, "java/lang/Thread");
if (NULL != jlThread) {
fid = (*env)->GetFieldID(env, jlThread, "container", "Ljdk/internal/vm/ThreadContainer;");
}
if ((NULL != fid)
&& (NULL == (*env)->GetObjectField(env, thread, fid))
) {
rc = JVMTI_JAVA_LANG_THREAD_STATE_NEW;
} else {
rc = JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE;
}
vm->internalVMFunctions->internalEnterVMFromJNI(currentThread);
/* Re-fetch object to correctly set the isSuspendedInternal field. */
vThreadObject = J9_JNI_UNWRAP_REFERENCE(thread);
break;
}
case JVMTI_VTHREAD_STATE_RUNNABLE:
rc = JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE;
break;
case JVMTI_VTHREAD_STATE_RUNNABLE_SUSPENDED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE | JVMTI_THREAD_STATE_SUSPENDED;
break;
case JVMTI_VTHREAD_STATE_RUNNING:
rc = JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE;
break;
case JVMTI_VTHREAD_STATE_PARKING:
/* Fall Through */
case JVMTI_VTHREAD_STATE_YIELDING:
rc = JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE;
break;
case JVMTI_VTHREAD_STATE_PARKED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_WAITING | JVMTI_THREAD_STATE_PARKED;
break;
case JVMTI_VTHREAD_STATE_PARKED_SUSPENDED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_WAITING | JVMTI_THREAD_STATE_PARKED | JVMTI_THREAD_STATE_SUSPENDED;
break;
case JVMTI_VTHREAD_STATE_PINNED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_WAITING;
break;
case JVMTI_VTHREAD_STATE_TERMINATED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_TERMINATED;
break;
default:
Assert_JVMTI_unreachable();
rc = JVMTI_ERROR_INTERNAL;
}
}
/* Re-fetch object to correctly set the isSuspendedInternal field. */
vThreadObject = J9_JNI_UNWRAP_REFERENCE(thread);
if (0 != J9OBJECT_U32_LOAD(currentThread, vThreadObject, vm->isSuspendedInternalOffset)) {
rc |= JVMTI_THREAD_STATE_SUSPENDED;
} else {
rc &= ~JVMTI_THREAD_STATE_SUSPENDED;
}
releaseVMThread(currentThread, targetThread, thread);
} else {
/* This is unreachable. */
Assert_JVMTI_unreachable();
rc = JVMTI_ERROR_INTERNAL;
}
return rc;
}
#endif /* JAVA_SPEC_VERSION >= 19 */
void
fillInJValue(char signatureType, jvalue * jvaluePtr, void * valueAddress, j9object_t * objectStorage)
{
j9object_t object;
switch (signatureType) {
case 'Z':
jvaluePtr->z = (jboolean) *((I_32 *) valueAddress);
break;
case 'B':
jvaluePtr->b = (jbyte) *((I_32 *) valueAddress);
break;
case 'C':
jvaluePtr->c = (jchar) *((I_32 *) valueAddress);
break;
case 'S':
jvaluePtr->s = (jshort) *((I_32 *) valueAddress);
break;
case 'I':
jvaluePtr->i = (jint) *((I_32 *) valueAddress);
break;
case 'J':
memcpy(&(jvaluePtr->j), valueAddress, 8);
break;
case 'F':
jvaluePtr->f = *((jfloat *) valueAddress);
break;
case 'D':
memcpy(&(jvaluePtr->d), valueAddress, 8);
break;
case 'L':
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
case 'Q':
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
object = *((j9object_t*) valueAddress);
if (object == NULL) {
jvaluePtr->l = NULL;
} else {
*objectStorage = object;
jvaluePtr->l = (jobject) objectStorage;
}
break;
}
}
j9object_t
getObjectFromRef(j9object_t * ref)
{
j9object_t result = *ref;
#ifdef J9VM_INTERP_GROWABLE_STACKS
/* See if the ref was redirected */
if (((UDATA) result) & J9_REDIRECTED_REFERENCE) {
result = *((j9object_t*) (((UDATA) result) - J9_REDIRECTED_REFERENCE));
}
#endif
return result;
}
J9Class *
getCurrentClass(J9Class * clazz)
{
return J9_CURRENT_CLASS(clazz);
}
static UDATA
hashObjectTag(void *entry, void *userData)
{
return ((UDATA) ((J9JVMTIObjectTag *) entry)->ref) / sizeof(UDATA);
}
static UDATA
hashEqualObjectTag(void *lhsEntry, void *rhsEntry, void *userData)
{
return (((J9JVMTIObjectTag *) lhsEntry)->ref == ((J9JVMTIObjectTag *) rhsEntry)->ref);
}
static UDATA
watchedClassHash(void *entry, void *userData)
{
return ((UDATA) ((J9JVMTIWatchedClass *) entry)->clazz) / J9_REQUIRED_CLASS_ALIGNMENT;
}
static UDATA
watchedClassEqual(void *lhsEntry, void *rhsEntry, void *userData)