-
Notifications
You must be signed in to change notification settings - Fork 740
/
Copy pathjava_lang_invoke_MethodHandleNatives.cpp
2096 lines (1894 loc) · 82.9 KB
/
java_lang_invoke_MethodHandleNatives.cpp
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 2021
*
* 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 "j9.h"
#include "jclprots.h"
#include "j9cp.h"
#include "j9protos.h"
#include "ut_j9jcl.h"
#include "j9port.h"
#include "jclglob.h"
#include "jcl_internal.h"
#include "util_api.h"
#include "j9vmconstantpool.h"
#include "ObjectAccessBarrierAPI.hpp"
#include "objhelp.h"
#include <string.h>
#include <assert.h>
#include "VMHelpers.hpp"
extern "C" {
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
/* Constants mapped from java.lang.invoke.MethodHandleNatives$Constants
* These constants are validated by the MethodHandleNatives$Constants.verifyConstants()
* method when Java assertions are enabled
*/
#define MN_SEARCH_SUPERCLASSES 0x00100000
#define MN_SEARCH_INTERFACES 0x00200000
#if JAVA_SPEC_VERSION >= 16
#define MN_MODULE_MODE 0x00000010
#define MN_UNCONDITIONAL_MODE 0x00000020
#define MN_TRUSTED_MODE -1
#endif /* JAVA_SPEC_VERSION >= 16 */
/* PlaceHolder value used for MN.vmindex that has default method conflict */
#define J9VM_RESOLVED_VMINDEX_FOR_DEFAULT_THROW 1
J9_DECLARE_CONSTANT_UTF8(mutableCallSite, "java/lang/invoke/MutableCallSite");
static bool
isPolymorphicMHMethod(J9JavaVM *vm, J9Class *declaringClass, J9UTF8 *methodName)
{
if (declaringClass == J9VMJAVALANGINVOKEMETHODHANDLE(vm)) {
U_8 *nameData = J9UTF8_DATA(methodName);
U_16 nameLength = J9UTF8_LENGTH(methodName);
if (J9UTF8_LITERAL_EQUALS(nameData, nameLength, "invoke")
|| J9UTF8_LITERAL_EQUALS(nameData, nameLength, "invokeBasic")
|| J9UTF8_LITERAL_EQUALS(nameData, nameLength, "linkToVirtual")
|| J9UTF8_LITERAL_EQUALS(nameData, nameLength, "linkToStatic")
|| J9UTF8_LITERAL_EQUALS(nameData, nameLength, "linkToSpecial")
|| J9UTF8_LITERAL_EQUALS(nameData, nameLength, "linkToInterface")
|| J9UTF8_LITERAL_EQUALS(nameData, nameLength, "linkToNative")
) {
return true;
}
}
return false;
}
/**
* @brief Add a MemberName to the list of MemberNames for the J9Class that will
* correspond to its clazz field.
*
* This must be done immediately prior to initializing vmtarget.
*
* clazzObject must be the value of the MemberName's clazz field, or the value
* that will be assigned to clazz immediately upon success.
*
* On error, the current exception will be set:
* - to OutOfMemoryError for allocation failure.
*
* The caller must have VM access.
*
* @param[in] currentThread the J9VMThread of the current thread
* @param[in] memberNameObject the MemberName object to add to the list
* @param[in] clazzObject the value of memberNameObject.clazz
* @return true for success, or false on error
*/
static bool
addMemberNameToClass(J9VMThread *currentThread, j9object_t memberNameObject, j9object_t clazzObject)
{
J9JavaVM *vm = currentThread->javaVM;
J9InternalVMFunctions *vmFuncs = vm->internalVMFunctions;
J9Class *j9clazz = J9VM_J9CLASS_FROM_HEAPCLASS(currentThread, clazzObject);
jobject weakRef = vmFuncs->j9jni_createGlobalRef((JNIEnv*)currentThread, memberNameObject, JNI_TRUE);
omrthread_monitor_enter(vm->memberNameListsMutex);
if (J9_ARE_ALL_BITS_SET(j9clazz->classFlags, J9ClassNeedToPruneMemberNames)) {
VM_AtomicSupport::bitAndU32((volatile uint32_t*)&j9clazz->classFlags, ~(uint32_t)J9ClassNeedToPruneMemberNames);
/* Remove all entries of memberNames for which the JNI weak ref has been cleared. */
J9MemberNameListNode **cur = &j9clazz->memberNames;
while (NULL != *cur) {
j9object_t obj = J9_JNI_UNWRAP_REFERENCE((*cur)->memberName);
if (NULL == obj) {
/* The MemberName has been collected. Remove this entry. */
J9MemberNameListNode *next = (*cur)->next;
vmFuncs->j9jni_deleteGlobalRef((JNIEnv*)currentThread, (*cur)->memberName, JNI_TRUE);
pool_removeElement(vm->memberNameListNodePool, *cur);
*cur = next;
} else {
cur = &(*cur)->next;
}
}
}
J9MemberNameListNode *node = (J9MemberNameListNode *)pool_newElement(vm->memberNameListNodePool);
bool success = false;
if ((NULL != weakRef) && (NULL != node)) {
/* Initialize node and push it onto the front of the list. */
node->memberName = weakRef;
node->next = j9clazz->memberNames;
j9clazz->memberNames = node;
success = true;
} else {
/* Failed to allocate either weakRef or node. */
if (NULL != node) {
pool_removeElement(vm->memberNameListNodePool, node);
}
if (NULL != weakRef) {
vmFuncs->j9jni_deleteGlobalRef((JNIEnv*)currentThread, weakRef, JNI_TRUE);
}
vmFuncs->setNativeOutOfMemoryError(currentThread, 0, 0);
}
omrthread_monitor_exit(vm->memberNameListsMutex);
return success;
}
/* Private MemberName object init helper
*
* Set the MemberName fields based on the refObject given:
* For j.l.reflect.Field:
* find JNIFieldID for refObject, create j.l.String for name and signature and store in MN.name/type fields.
* set vmindex to the fieldID pointer and target to the field offset.
* set MN.clazz to declaring class in the fieldID struct.
* For j.l.reflect.Method or j.l.reflect.Constructor:
* find JNIMethodID, set target to the J9Method and vmindex as appropriate for dispatch.
* set MN.clazz to the refObject's declaring class.
*
* Then for both, compute the MN.flags using access flags and invocation type based on the JNI-id.
*
* Throw an IllegalArgumentException if the refObject is not a Field/Method/Constructor
*
* Note: caller must have vmaccess before invoking this helper
*/
static void
initImpl(J9VMThread *currentThread, j9object_t membernameObject, j9object_t refObject)
{
J9JavaVM *vm = currentThread->javaVM;
const J9InternalVMFunctions *vmFuncs = vm->internalVMFunctions;
J9Class* refClass = J9OBJECT_CLAZZ(currentThread, refObject);
jint flags = 0;
jlong vmindex = 0;
jlong target = 0;
j9object_t clazzObject = NULL;
j9object_t nameObject = NULL;
j9object_t typeObject = NULL;
if (refClass == J9VMJAVALANGREFLECTFIELD(vm)) {
J9JNIFieldID *fieldID = vm->reflectFunctions.idFromFieldObject(currentThread, NULL, refObject);
J9ROMFieldShape *romField = fieldID->field;
UDATA offset = fieldID->offset;
if (J9_ARE_ANY_BITS_SET(romField->modifiers, J9AccStatic)) {
offset |= J9_SUN_STATIC_FIELD_OFFSET_TAG;
if (J9_ARE_ANY_BITS_SET(romField->modifiers, J9AccFinal)) {
offset |= J9_SUN_FINAL_FIELD_OFFSET_TAG;
}
}
vmindex = (jlong)fieldID;
target = (jlong)offset;
flags = fieldID->field->modifiers & CFR_FIELD_ACCESS_MASK;
flags |= MN_IS_FIELD;
flags |= (J9_ARE_ANY_BITS_SET(flags, J9AccStatic) ? MH_REF_GETSTATIC : MH_REF_GETFIELD) << MN_REFERENCE_KIND_SHIFT;
if (VM_VMHelpers::isTrustedFinalField(fieldID->field, fieldID->declaringClass->romClass)) {
flags |= MN_TRUSTED_FINAL;
}
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
if (J9ROMFIELD_IS_NULL_RESTRICTED(romField)) {
if (vmFuncs->isFlattenableFieldFlattened(fieldID->declaringClass, fieldID->field)) {
flags |= MN_FLAT_FIELD;
}
}
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
nameObject = J9VMJAVALANGREFLECTFIELD_NAME(currentThread, refObject);
typeObject = J9VMJAVALANGREFLECTFIELD_TYPE(currentThread, refObject);
clazzObject = J9VM_J9CLASS_TO_HEAPCLASS(fieldID->declaringClass);
} else if (refClass == J9VMJAVALANGREFLECTMETHOD(vm)) {
J9JNIMethodID *methodID = vm->reflectFunctions.idFromMethodObject(currentThread, refObject);
target = (jlong)methodID->method;
J9ROMMethod *romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(methodID->method);
J9Class *declaringClass = J9_CLASS_FROM_METHOD(methodID->method);
J9UTF8 *methodName = J9ROMMETHOD_NAME(romMethod);
if (isPolymorphicMHMethod(vm, declaringClass, methodName)
#if JAVA_SPEC_VERSION >= 9
|| ((declaringClass == J9VMJAVALANGINVOKEVARHANDLE(vm))
&& VM_VMHelpers::isPolymorphicVarHandleMethod(J9UTF8_DATA(methodName), J9UTF8_LENGTH(methodName)))
#endif
) {
/* Do not initialize polymorphic MH/VH methods as the Java code handles the "MemberName.clazz == null" case for them. */
return;
}
flags = romMethod->modifiers & CFR_METHOD_ACCESS_MASK;
if (J9_ARE_ANY_BITS_SET(romMethod->modifiers, J9AccMethodCallerSensitive)) {
flags |= MN_CALLER_SENSITIVE;
}
flags |= MN_IS_METHOD;
if (J9_ARE_ANY_BITS_SET(methodID->vTableIndex, J9_JNI_MID_INTERFACE)) {
flags |= MH_REF_INVOKEINTERFACE << MN_REFERENCE_KIND_SHIFT;
} else if (J9_ARE_ANY_BITS_SET(romMethod->modifiers , J9AccStatic)) {
flags |= MH_REF_INVOKESTATIC << MN_REFERENCE_KIND_SHIFT;
} else if (J9_ARE_ANY_BITS_SET(romMethod->modifiers , J9AccFinal) || !J9ROMMETHOD_HAS_VTABLE(romMethod)) {
flags |= MH_REF_INVOKESPECIAL << MN_REFERENCE_KIND_SHIFT;
} else {
flags |= MH_REF_INVOKEVIRTUAL << MN_REFERENCE_KIND_SHIFT;
}
nameObject = J9VMJAVALANGREFLECTMETHOD_NAME(currentThread, refObject);
clazzObject = J9VMJAVALANGREFLECTMETHOD_CLAZZ(currentThread, refObject);
J9Class *clazz = J9VM_J9CLASS_FROM_HEAPCLASS(currentThread, clazzObject);
vmindex = vmindexValueForMethodMemberName(methodID, clazz, flags);
} else if (refClass == J9VMJAVALANGREFLECTCONSTRUCTOR(vm)) {
J9JNIMethodID *methodID = vm->reflectFunctions.idFromConstructorObject(currentThread, refObject);
vmindex = -1;
target = (jlong)methodID->method;
J9ROMMethod *romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(methodID->method);
flags = romMethod->modifiers & CFR_METHOD_ACCESS_MASK;
if (J9_ARE_ANY_BITS_SET(romMethod->modifiers, J9AccMethodCallerSensitive)) {
flags |= MN_CALLER_SENSITIVE;
}
flags |= MN_IS_CONSTRUCTOR | (MH_REF_INVOKESPECIAL << MN_REFERENCE_KIND_SHIFT);
clazzObject = J9VMJAVALANGREFLECTMETHOD_CLAZZ(currentThread, refObject);
} else {
vmFuncs->setCurrentExceptionUTF(currentThread, J9VMCONSTANTPOOL_JAVALANGILLEGALARGUMENTEXCEPTION, NULL);
}
if (!VM_VMHelpers::exceptionPending(currentThread)) {
if (addMemberNameToClass(currentThread, membernameObject, clazzObject)) {
J9VMJAVALANGINVOKEMEMBERNAME_SET_FLAGS(currentThread, membernameObject, flags);
J9VMJAVALANGINVOKEMEMBERNAME_SET_NAME(currentThread, membernameObject, nameObject);
if (NULL != typeObject) {
Assert_JCL_true(OMR_ARE_ALL_BITS_SET(flags, MN_IS_FIELD));
J9VMJAVALANGINVOKEMEMBERNAME_SET_TYPE(currentThread, membernameObject, typeObject);
}
J9VMJAVALANGINVOKEMEMBERNAME_SET_CLAZZ(currentThread, membernameObject, clazzObject);
J9OBJECT_U64_STORE(currentThread, membernameObject, vm->vmindexOffset, (U_64)vmindex);
J9OBJECT_U64_STORE(currentThread, membernameObject, vm->vmtargetOffset, (U_64)target);
Trc_JCL_java_lang_invoke_MethodHandleNatives_initImpl_setData(currentThread, flags, nameObject, typeObject, clazzObject, vmindex, target);
}
}
}
struct LocalJ9UTF8Buffer {
/**
* Constructs an empty LocalJ9UTF8Buffer.
*/
LocalJ9UTF8Buffer()
: utf8(nullptr)
, capacity(0)
, cursor(nullptr)
{
}
/**
* Constructs a LocalJ9UTF8Buffer object from a J9UTF8 object pointer
* and its size.
* @param[in] buffer Pointer to the J9UTF8 buffer
* @param[in] length Length of the entire J9UTF8 buffer in bytes
*/
LocalJ9UTF8Buffer(J9UTF8 *buffer, size_t length)
: utf8(buffer)
, capacity(length - offsetof(J9UTF8, data))
, cursor(J9UTF8_DATA(buffer))
{
}
/**
* Calculate the remaining slots in the buffer.
* @return number of remaining slots in the buffer
*/
size_t remaining()
{
return capacity - static_cast<size_t>(cursor - J9UTF8_DATA(utf8));
}
/**
* Put a character into the buffer at the cursor, then advance the cursor.
* @param[in] c The character to put into the buffer
*/
void putCharAtCursor(char c)
{
*cursor = c;
cursor += 1;
}
/**
* Advance the cursor n slots.
* @param[in] n The number of slots to advance the cursor by
*/
void advanceN(size_t n)
{
cursor += n;
}
/**
* Null-terminates the data, and sets the J9UTF8 length from a cursor-position calculation.
*/
void commitLength()
{
*cursor = '\0';
J9UTF8_SET_LENGTH(utf8, static_cast<U_16>(cursor - J9UTF8_DATA(utf8)));
}
J9UTF8 *utf8; /**< Pointer to the J9UTF8 struct */
size_t capacity; /**< Capacity of the J9UTF8 data buffer */
U_8 *cursor; /**< Pointer to current position in J9UTF8 data buffer */
};
/**
* Returns a character corresponding to a primitive-type class.
* @param[in] vm J9JavaVM instance for current thread
* @param[in] clazz The class of signature character of interest
* @return character to newly allocated and filled-in signature buffer
* @return the character corresponding to a primitive type
*/
static VMINLINE char
sigForPrimitiveOrVoid(J9JavaVM *vm, J9Class *clazz)
{
char c = '\0';
if (clazz == vm->booleanReflectClass) {
c = 'Z';
} else if (clazz == vm->byteReflectClass) {
c = 'B';
} else if (clazz == vm->charReflectClass) {
c = 'C';
} else if (clazz == vm->shortReflectClass) {
c = 'S';
} else if (clazz == vm->intReflectClass) {
c = 'I';
} else if (clazz == vm->longReflectClass) {
c = 'J';
} else if (clazz == vm->floatReflectClass) {
c = 'F';
} else if (clazz == vm->doubleReflectClass) {
c = 'D';
} else if (clazz == vm->voidReflectClass) {
c = 'V';
}
return c;
}
/**
* Gets a class signature's string length.
* @param[in] currentThread The J9VMThread of the current thread
* @param[in] clazz The class whose signature is being queried
* @return length of a class' signature without null-termination
*/
static UDATA
getClassSignatureLength(J9VMThread *currentThread, J9Class *clazz)
{
J9JavaVM *vm = currentThread->javaVM;
UDATA signatureLength = 0;
if (J9ROMCLASS_IS_PRIMITIVE_TYPE(clazz->romClass)) {
signatureLength = 1;
} else {
j9object_t sigString = J9VMJAVALANGCLASS_CLASSNAMESTRING(currentThread, J9VM_J9CLASS_TO_HEAPCLASS(clazz));
if (NULL != sigString) {
/* +2 so that we can fit 'L' and ';' around the class name. */
signatureLength = vm->internalVMFunctions->getStringUTF8Length(currentThread, sigString) + 2;
} else {
J9Class *myClass = clazz;
UDATA numDims = 0;
bool isPrimitive = false;
if (J9CLASS_IS_ARRAY(myClass)) {
J9ArrayClass *arrayClazz = reinterpret_cast<J9ArrayClass *>(myClass);
numDims = arrayClazz->arity;
J9Class *leafComponentType = arrayClazz->leafComponentType;
isPrimitive = J9ROMCLASS_IS_PRIMITIVE_TYPE(leafComponentType->romClass);
if (isPrimitive) {
/* -1 to account for the '[' already prepended to the primitive array class' name.
* Result guaranteed to be >= 0 because the minimum arity for a J9ArrayClass is 1.
*/
numDims -= 1;
myClass = leafComponentType->arrayClass;
} else {
myClass = leafComponentType;
}
}
if (!isPrimitive) {
/* +2 so that we can fit 'L' and ';' around the class name. */
signatureLength += 2;
}
J9UTF8 *romName = J9ROMCLASS_CLASSNAME(myClass->romClass);
U_32 nameLength = J9UTF8_LENGTH(romName);
signatureLength += nameLength + numDims;
}
}
return signatureLength;
}
/**
* Fills in a class signature into a signature buffer.
* @param[in] currentThread The J9VMThread of the current thread
* @param[in] clazz The class whose signature is being queried
* @param[in,out] stringBuffer The signature buffer to place the signature into
* @return true if the signature fits into stringBuffer, false otherwise
*/
static bool
getClassSignatureInout(J9VMThread *currentThread, J9Class *clazz, LocalJ9UTF8Buffer *stringBuffer)
{
J9JavaVM *vm = currentThread->javaVM;
bool result = false;
if (J9ROMCLASS_IS_PRIMITIVE_TYPE(clazz->romClass)) {
/* 2 to ensure that a null-termination can be appended if this primitive type is
* the final type in the signature.
*/
if (2 <= stringBuffer->remaining()) {
const char c = sigForPrimitiveOrVoid(vm, clazz);
stringBuffer->putCharAtCursor(c);
result = true;
}
} else {
j9object_t sigString = J9VMJAVALANGCLASS_CLASSNAMESTRING(currentThread, J9VM_J9CLASS_TO_HEAPCLASS(clazz));
if (NULL != sigString) {
/* +3 so that we can fit 'L' and ';' around the class name and add null-terminator. */
UDATA utfLength = vm->internalVMFunctions->getStringUTF8Length(currentThread, sigString) + 3;
if (utfLength <= stringBuffer->remaining()) {
if (J9ROMCLASS_IS_ARRAY(clazz->romClass)) {
vm->internalVMFunctions->copyStringToUTF8Helper(
currentThread, sigString, J9_STR_XLAT, 0, J9VMJAVALANGSTRING_LENGTH(currentThread, sigString),
stringBuffer->cursor, utfLength - 3);
/* Adjust cursor to account for the call to copyStringToUTF8Helper. */
stringBuffer->advanceN(utfLength - 3);
} else {
stringBuffer->putCharAtCursor('L');
vm->internalVMFunctions->copyStringToUTF8Helper(
currentThread, sigString, J9_STR_XLAT, 0, J9VMJAVALANGSTRING_LENGTH(currentThread, sigString),
stringBuffer->cursor, utfLength - 3);
/* Adjust cursor to account for the call to copyStringToUTF8Helper. */
stringBuffer->advanceN(utfLength - 3);
stringBuffer->putCharAtCursor(';');
}
result = true;
}
} else {
J9Class *myClass = clazz;
UDATA numDims = 0;
bool isPrimitive = false;
if (J9CLASS_IS_ARRAY(myClass)) {
J9ArrayClass *arrayClazz = reinterpret_cast<J9ArrayClass *>(myClass);
numDims = arrayClazz->arity;
J9Class *leafComponentType = arrayClazz->leafComponentType;
isPrimitive = J9ROMCLASS_IS_PRIMITIVE_TYPE(leafComponentType->romClass);
if (isPrimitive) {
/* -1 to account for the '[' already prepended to the primitive array class' name.
* Result guaranteed to be >= 0 because the minimum arity for a J9ArrayClass is 1.
*/
numDims -= 1;
myClass = leafComponentType->arrayClass;
} else {
myClass = leafComponentType;
}
}
/* +1 to ensure we can add a null-terminator. */
UDATA sigLength = 1;
if (!isPrimitive) {
/* +2 so that we can fit 'L' and ';' around the class name. */
sigLength += 2;
}
J9UTF8 *romName = J9ROMCLASS_CLASSNAME(myClass->romClass);
U_32 nameLength = J9UTF8_LENGTH(romName);
const char *name = reinterpret_cast<const char *>(J9UTF8_DATA(romName));
sigLength += nameLength + numDims;
if (sigLength <= stringBuffer->remaining()) {
for (UDATA i = 0; i < numDims; i++) {
stringBuffer->putCharAtCursor('[');
}
if (!isPrimitive) {
stringBuffer->putCharAtCursor('L');
}
memcpy(stringBuffer->cursor, name, nameLength);
/* Adjust cursor to account for the memcpy. */
stringBuffer->advanceN(nameLength);
if (!isPrimitive) {
stringBuffer->putCharAtCursor(';');
}
result = true;
}
}
}
return result;
}
/**
* Allocates a J9UTF8 signature buffer and places a method signature constructed from a MethodType into it.
* @param[in] currentThread The J9VMThread of the current thread
* @param[in] typeObject A MethodType object that contains parameter and return type information
* @return pointer to newly allocated and filled-in JUTF8 signature buffer
*/
static J9UTF8 *
getJ9UTF8SignatureFromMethodTypeWithMemAlloc(J9VMThread *currentThread, j9object_t typeObject)
{
J9JavaVM *vm = currentThread->javaVM;
j9object_t ptypes = J9VMJAVALANGINVOKEMETHODTYPE_PTYPES(currentThread, typeObject);
U_32 numArgs = J9INDEXABLEOBJECT_SIZE(currentThread, ptypes);
UDATA signatureLength = 2; /* space for '(', ')' */
PORT_ACCESS_FROM_JAVAVM(vm);
/* Calculate total signature length, including all ptypes and rtype. */
for (U_32 i = 0; i < numArgs; i++) {
j9object_t pObject = J9JAVAARRAYOFOBJECT_LOAD(currentThread, ptypes, i);
J9Class *pclass = J9VM_J9CLASS_FROM_HEAPCLASS(currentThread, pObject);
signatureLength += getClassSignatureLength(currentThread, pclass);
}
j9object_t rtype = J9VMJAVALANGINVOKEMETHODTYPE_RTYPE(currentThread, typeObject);
J9Class *rclass = J9VM_J9CLASS_FROM_HEAPCLASS(currentThread, rtype);
signatureLength += getClassSignatureLength(currentThread, rclass);
UDATA signatureUtf8Size = signatureLength + sizeof(J9UTF8) + 1; /* +1 for a null-terminator */
J9UTF8 *result = reinterpret_cast<J9UTF8 *>(j9mem_allocate_memory(signatureUtf8Size, OMRMEM_CATEGORY_VM));
if (NULL != result) {
LocalJ9UTF8Buffer stringBuffer(result, signatureUtf8Size);
stringBuffer.putCharAtCursor('(');
for (U_32 i = 0; i < numArgs; i++) {
j9object_t pObject = J9JAVAARRAYOFOBJECT_LOAD(currentThread, ptypes, i);
J9Class *pclass = J9VM_J9CLASS_FROM_HEAPCLASS(currentThread, pObject);
getClassSignatureInout(currentThread, pclass, &stringBuffer);
}
stringBuffer.putCharAtCursor(')');
j9object_t rtype = J9VMJAVALANGINVOKEMETHODTYPE_RTYPE(currentThread, typeObject);
J9Class *rclass = J9VM_J9CLASS_FROM_HEAPCLASS(currentThread, rtype);
getClassSignatureInout(currentThread, rclass, &stringBuffer);
stringBuffer.commitLength();
}
return result;
}
/**
* Attempts to fill in a method signature constructed from a MethodType into a passed in signature buffer.
* Falls back to a dynamic buffer allocation if the statically allocated buffer's capacity is exceeded.
* @param[in] currentThread The J9VMThread of the current thread
* @param[in] typeObject A MethodType object that contains parameter and return type information
* @param[in,out] stringBuffer The signature buffer to place the signature into
* @return pointer to a filled-in JUTF8 signature buffer, either the dynamically or statically allocated buffer
*/
static J9UTF8 *
getJ9UTF8SignatureFromMethodType(J9VMThread *currentThread, j9object_t typeObject, LocalJ9UTF8Buffer *stringBuffer)
{
j9object_t ptypes = J9VMJAVALANGINVOKEMETHODTYPE_PTYPES(currentThread, typeObject);
U_32 numArgs = J9INDEXABLEOBJECT_SIZE(currentThread, ptypes);
stringBuffer->putCharAtCursor('(');
for (U_32 i = 0; i < numArgs; i++) {
j9object_t pObject = J9JAVAARRAYOFOBJECT_LOAD(currentThread, ptypes, i);
J9Class *pclass = J9VM_J9CLASS_FROM_HEAPCLASS(currentThread, pObject);
if (!getClassSignatureInout(currentThread, pclass, stringBuffer)) {
/* Failing getClassSignatureInout means stringBuffer exceeded capacity.
* Fall back to dynamic allocation.
*/
return getJ9UTF8SignatureFromMethodTypeWithMemAlloc(currentThread, typeObject);
}
}
if (1 >= stringBuffer->remaining()) {
/* Not enough space left in statically allocated buffer.
* Fall back to dynamic allocation.
*/
return getJ9UTF8SignatureFromMethodTypeWithMemAlloc(currentThread, typeObject);
}
stringBuffer->putCharAtCursor(')');
/* Return type */
j9object_t rtype = J9VMJAVALANGINVOKEMETHODTYPE_RTYPE(currentThread, typeObject);
J9Class *rclass = J9VM_J9CLASS_FROM_HEAPCLASS(currentThread, rtype);
if (!getClassSignatureInout(currentThread, rclass, stringBuffer)) {
/* Failing getClassSignatureInout means stringBuffer exceeded capacity.
* Fall back to dynamic allocation.
*/
return getJ9UTF8SignatureFromMethodTypeWithMemAlloc(currentThread, typeObject);
}
if (0 == stringBuffer->remaining()) {
/* Not enough space left in statically allocated buffer.
* Fall back to dynamic allocation.
*/
return getJ9UTF8SignatureFromMethodTypeWithMemAlloc(currentThread, typeObject);
}
stringBuffer->commitLength();
return stringBuffer->utf8;
}
j9object_t
resolveRefToObject(J9VMThread *currentThread, J9ConstantPool *ramConstantPool, U_16 cpIndex, bool resolve)
{
J9JavaVM *vm = currentThread->javaVM;
const J9InternalVMFunctions *vmFuncs = vm->internalVMFunctions;
j9object_t result = NULL;
J9RAMSingleSlotConstantRef *ramCP = (J9RAMSingleSlotConstantRef*)ramConstantPool + cpIndex;
U_32 *cpShapeDescription = J9ROMCLASS_CPSHAPEDESCRIPTION(J9_CLASS_FROM_CP(ramConstantPool)->romClass);
switch (J9_CP_TYPE(cpShapeDescription, cpIndex)) {
case J9CPTYPE_CLASS: {
J9Class *clazz = (J9Class*)ramCP->value;
if ((NULL == clazz) && resolve) {
clazz = vmFuncs->resolveClassRef(currentThread, ramConstantPool, cpIndex, J9_RESOLVE_FLAG_RUNTIME_RESOLVE);
}
if (NULL != clazz) {
result = J9VM_J9CLASS_TO_HEAPCLASS(clazz);
}
break;
}
case J9CPTYPE_STRING: {
result = (j9object_t)ramCP->value;
if ((NULL == result) && resolve) {
result = vmFuncs->resolveStringRef(currentThread, ramConstantPool, cpIndex, J9_RESOLVE_FLAG_RUNTIME_RESOLVE);
}
break;
}
case J9CPTYPE_INT: {
J9ROMSingleSlotConstantRef *romCP = (J9ROMSingleSlotConstantRef*)J9_ROM_CP_FROM_CP(ramConstantPool) + cpIndex;
result = vm->memoryManagerFunctions->J9AllocateObject(currentThread, J9VMJAVALANGINTEGER_OR_NULL(vm), J9_GC_ALLOCATE_OBJECT_NON_INSTRUMENTABLE);
if (NULL == result) {
vmFuncs->setHeapOutOfMemoryError(currentThread);
goto done;
}
J9VMJAVALANGINTEGER_SET_VALUE(currentThread, result, romCP->data);
break;
}
case J9CPTYPE_FLOAT: {
J9ROMSingleSlotConstantRef *romCP = (J9ROMSingleSlotConstantRef*)J9_ROM_CP_FROM_CP(ramConstantPool) + cpIndex;
result = vm->memoryManagerFunctions->J9AllocateObject(currentThread, J9VMJAVALANGFLOAT_OR_NULL(vm), J9_GC_ALLOCATE_OBJECT_NON_INSTRUMENTABLE);
if (NULL == result) {
vmFuncs->setHeapOutOfMemoryError(currentThread);
goto done;
}
J9VMJAVALANGFLOAT_SET_VALUE(currentThread, result, romCP->data);
break;
}
case J9CPTYPE_LONG: {
J9ROMConstantRef *romCP = (J9ROMConstantRef*)J9_ROM_CP_FROM_CP(ramConstantPool) + cpIndex;
#ifdef J9VM_ENV_LITTLE_ENDIAN
U_64 value = (((U_64)(romCP->slot2)) << 32) | ((U_64)(romCP->slot1));
#else
U_64 value = (((U_64)(romCP->slot1)) << 32) | ((U_64)(romCP->slot2));
#endif
result = vm->memoryManagerFunctions->J9AllocateObject(currentThread, J9VMJAVALANGLONG_OR_NULL(vm), J9_GC_ALLOCATE_OBJECT_NON_INSTRUMENTABLE);
if (NULL == result) {
vmFuncs->setHeapOutOfMemoryError(currentThread);
goto done;
}
J9VMJAVALANGLONG_SET_VALUE(currentThread, result, value);
break;
}
case J9CPTYPE_DOUBLE: {
J9ROMConstantRef *romCP = (J9ROMConstantRef*)J9_ROM_CP_FROM_CP(ramConstantPool) + cpIndex;
#ifdef J9VM_ENV_LITTLE_ENDIAN
U_64 value = (((U_64)(romCP->slot2)) << 32) | ((U_64)(romCP->slot1));
#else
U_64 value = (((U_64)(romCP->slot1)) << 32) | ((U_64)(romCP->slot2));
#endif
result = vm->memoryManagerFunctions->J9AllocateObject(currentThread, J9VMJAVALANGDOUBLE_OR_NULL(vm), J9_GC_ALLOCATE_OBJECT_NON_INSTRUMENTABLE);
if (NULL == result) {
vmFuncs->setHeapOutOfMemoryError(currentThread);
goto done;
}
J9VMJAVALANGDOUBLE_SET_VALUE(currentThread, result, value);
break;
}
case J9CPTYPE_METHOD_TYPE: {
result = (j9object_t)ramCP->value;
if ((NULL == result) && resolve) {
result = vmFuncs->resolveMethodTypeRef(currentThread, ramConstantPool, cpIndex, J9_RESOLVE_FLAG_RUNTIME_RESOLVE);
}
break;
}
case J9CPTYPE_METHODHANDLE: {
result = (j9object_t)ramCP->value;
if ((NULL == result) && resolve) {
result = vmFuncs->resolveMethodHandleRef(currentThread, ramConstantPool, cpIndex, J9_RESOLVE_FLAG_RUNTIME_RESOLVE | J9_RESOLVE_FLAG_NO_CLASS_INIT);
}
break;
}
case J9CPTYPE_CONSTANT_DYNAMIC: {
result = (j9object_t)ramCP->value;
if ((NULL == result) && resolve) {
result = vmFuncs->resolveConstantDynamic(currentThread, ramConstantPool, cpIndex, J9_RESOLVE_FLAG_RUNTIME_RESOLVE);
}
break;
}
} /* switch */
done:
return result;
}
J9Method *
lookupMethod(J9VMThread *currentThread, J9Class *resolvedClass, J9UTF8 *name, J9UTF8 *signature, J9Class *callerClass, UDATA lookupOptions)
{
J9Method *result = NULL;
J9NameAndSignature nas;
J9UTF8 nullSignature = {0};
nas.name = name;
nas.signature = signature;
lookupOptions |= J9_LOOK_DIRECT_NAS;
/* If looking for a MethodHandle polymorphic INL method, allow any caller signature. */
if (isPolymorphicMHMethod(currentThread->javaVM, resolvedClass, name)) {
nas.signature = &nullSignature;
/* Set flag for partial signature lookup. Signature length is already initialized to 0. */
lookupOptions |= J9_LOOK_PARTIAL_SIGNATURE;
}
result = (J9Method*)currentThread->javaVM->internalVMFunctions->javaLookupMethod(currentThread, resolvedClass, (J9ROMNameAndSignature*)&nas, callerClass, lookupOptions);
return result;
}
static void
setCallSiteTargetImpl(J9VMThread *currentThread, jobject callsite, jobject target, bool isVolatile)
{
J9JavaVM *javaVM = currentThread->javaVM;
const J9InternalVMFunctions *vmFuncs = javaVM->internalVMFunctions;
vmFuncs->internalEnterVMFromJNI(currentThread);
if ((NULL == callsite) || (NULL == target)) {
vmFuncs->setCurrentExceptionUTF(currentThread, J9VMCONSTANTPOOL_JAVALANGNULLPOINTEREXCEPTION, NULL);
} else {
j9object_t callsiteObject = J9_JNI_UNWRAP_REFERENCE(callsite);
j9object_t targetObject = J9_JNI_UNWRAP_REFERENCE(target);
J9Class *clazz = J9OBJECT_CLAZZ(currentThread, callsiteObject);
UDATA offset = (UDATA)vmFuncs->instanceFieldOffset(
currentThread,
clazz,
(U_8*)"target",
LITERAL_STRLEN("target"),
(U_8*)"Ljava/lang/invoke/MethodHandle;",
LITERAL_STRLEN("Ljava/lang/invoke/MethodHandle;"),
NULL, NULL, 0);
offset += J9VMTHREAD_OBJECT_HEADER_SIZE(currentThread);
MM_ObjectAccessBarrierAPI objectAccessBarrier = MM_ObjectAccessBarrierAPI(currentThread);
/* Check for MutableCallSite modification. */
J9JITConfig* jitConfig = javaVM->jitConfig;
J9Class *mcsClass = vmFuncs->peekClassHashTable(
currentThread,
javaVM->systemClassLoader,
J9UTF8_DATA(&mutableCallSite),
J9UTF8_LENGTH(&mutableCallSite));
if (!isVolatile /* MutableCallSite uses setTargetNormal(). */
&& (NULL != jitConfig)
&& (NULL != mcsClass)
&& VM_VMHelpers::inlineCheckCast(clazz, mcsClass)
) {
jitConfig->jitSetMutableCallSiteTarget(currentThread, callsiteObject, targetObject);
} else {
/* There are no runtime assumptions to invalidate (either because
* the call site is not a MutableCallSite, or because the JIT
* compiler is not loaded). */
objectAccessBarrier.inlineMixedObjectStoreObject(currentThread, callsiteObject, offset, targetObject, isVolatile);
}
}
vmFuncs->internalExitVMToJNI(currentThread);
}
/**
* static native void init(MemberName self, Object ref);
*
* Initializes a MemberName object using the given ref object.
* see initImpl for detail
* Throw NPE if self or ref is null
* Throw IllegalArgumentException if ref is not a field/method/constructor
*/
void JNICALL
Java_java_lang_invoke_MethodHandleNatives_init(JNIEnv *env, jclass clazz, jobject self, jobject ref)
{
J9VMThread *currentThread = (J9VMThread*)env;
J9JavaVM *vm = currentThread->javaVM;
J9InternalVMFunctions *vmFuncs = vm->internalVMFunctions;
vmFuncs->internalEnterVMFromJNI(currentThread);
Trc_JCL_java_lang_invoke_MethodHandleNatives_init_Entry(env, self, ref);
if ((NULL == self) || (NULL == ref)) {
vmFuncs->setCurrentExceptionUTF(currentThread, J9VMCONSTANTPOOL_JAVALANGNULLPOINTEREXCEPTION, NULL);
} else {
j9object_t membernameObject = J9_JNI_UNWRAP_REFERENCE(self);
j9object_t refObject = J9_JNI_UNWRAP_REFERENCE(ref);
initImpl(currentThread, membernameObject, refObject);
}
Trc_JCL_java_lang_invoke_MethodHandleNatives_init_Exit(env);
vmFuncs->internalExitVMToJNI(currentThread);
}
/**
* static native void expand(MemberName self);
*
* Given a MemberName object, try to set the uninitialized fields from existing VM metadata.
* Uses VM metadata (vmindex & vmtarget) to set symblic data fields (name & type & defc)
*
* Throws NullPointerException if MemberName object is null.
* Throws IllegalArgumentException if MemberName doesn't contain required data to expand.
* Throws InternalError if the MemberName object contains invalid data or completely uninitialized.
*/
void JNICALL
Java_java_lang_invoke_MethodHandleNatives_expand(JNIEnv *env, jclass clazz, jobject self)
{
J9VMThread *currentThread = (J9VMThread*)env;
J9JavaVM *vm = currentThread->javaVM;
const J9InternalVMFunctions *vmFuncs = vm->internalVMFunctions;
vmFuncs->internalEnterVMFromJNI(currentThread);
Trc_JCL_java_lang_invoke_MethodHandleNatives_expand_Entry(env, self);
if (NULL == self) {
vmFuncs->setCurrentExceptionUTF(currentThread, J9VMCONSTANTPOOL_JAVALANGNULLPOINTEREXCEPTION, NULL);
} else {
j9object_t membernameObject = J9_JNI_UNWRAP_REFERENCE(self);
jint flags = J9VMJAVALANGINVOKEMEMBERNAME_FLAGS(currentThread, membernameObject);
jlong vmindex = (jlong)J9OBJECT_ADDRESS_LOAD(currentThread, membernameObject, vm->vmindexOffset);
Trc_JCL_java_lang_invoke_MethodHandleNatives_expand_Data(env, membernameObject, flags, vmindex);
if (J9_ARE_ANY_BITS_SET(flags, MN_IS_FIELD)) {
/* For Field MemberName, the clazz and vmindex fields must be set. */
if ((NULL != J9VMJAVALANGINVOKEMEMBERNAME_CLAZZ(currentThread, membernameObject)) && (NULL != (void*)vmindex)) {
J9JNIFieldID *field = (J9JNIFieldID*)vmindex;
/* if name/type field is uninitialized, create j.l.String from ROM field name/sig and store in MN fields. */
if (NULL == J9VMJAVALANGINVOKEMEMBERNAME_NAME(currentThread, membernameObject)) {
J9UTF8 *name = J9ROMFIELDSHAPE_NAME(field->field);
j9object_t nameString = vm->memoryManagerFunctions->j9gc_createJavaLangStringWithUTFCache(currentThread, name);
if (NULL != nameString) {
/* Refetch reference after GC point */
membernameObject = J9_JNI_UNWRAP_REFERENCE(self);
J9VMJAVALANGINVOKEMEMBERNAME_SET_NAME(currentThread, membernameObject, nameString);
}
}
if (NULL == J9VMJAVALANGINVOKEMEMBERNAME_TYPE(currentThread, membernameObject)) {
J9UTF8 *signature = J9ROMFIELDSHAPE_SIGNATURE(field->field);
j9object_t signatureString = vm->memoryManagerFunctions->j9gc_createJavaLangStringWithUTFCache(currentThread, signature);
if (NULL != signatureString) {
/* Refetch reference after GC point */
membernameObject = J9_JNI_UNWRAP_REFERENCE(self);
J9VMJAVALANGINVOKEMEMBERNAME_SET_TYPE(currentThread, membernameObject, signatureString);
}
}
} else {
vmFuncs->setCurrentExceptionUTF(currentThread, J9VMCONSTANTPOOL_JAVALANGILLEGALARGUMENTEXCEPTION, NULL);
}
} else if (J9_ARE_ANY_BITS_SET(flags, MN_IS_METHOD | MN_IS_CONSTRUCTOR)) {
J9Method *method = (J9Method *)(UDATA)J9OBJECT_U64_LOAD(_currentThread, membernameObject, vm->vmtargetOffset);
if (NULL != method) {
/* Retrieve method info using the J9Method and store to MN fields. */
J9ROMMethod *romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(method);
if (NULL == J9VMJAVALANGINVOKEMEMBERNAME_CLAZZ(currentThread, membernameObject)) {
j9object_t newClassObject = J9VM_J9CLASS_TO_HEAPCLASS(J9_CLASS_FROM_METHOD(method));
J9VMJAVALANGINVOKEMEMBERNAME_SET_CLAZZ(currentThread, membernameObject, newClassObject);
}
if (NULL == J9VMJAVALANGINVOKEMEMBERNAME_NAME(currentThread, membernameObject)) {
J9UTF8 *name = J9ROMMETHOD_NAME(romMethod);
j9object_t nameString = vm->memoryManagerFunctions->j9gc_createJavaLangStringWithUTFCache(currentThread, name);
if (NULL != nameString) {
/* Refetch reference after GC point */
membernameObject = J9_JNI_UNWRAP_REFERENCE(self);
J9VMJAVALANGINVOKEMEMBERNAME_SET_NAME(currentThread, membernameObject, nameString);
}
}
if (NULL == J9VMJAVALANGINVOKEMEMBERNAME_TYPE(currentThread, membernameObject)) {
J9UTF8 *signature = J9ROMMETHOD_SIGNATURE(romMethod);
j9object_t signatureString = vm->memoryManagerFunctions->j9gc_createJavaLangStringWithUTFCache(currentThread, signature);
if (NULL != signatureString) {
/* Refetch reference after GC point */
membernameObject = J9_JNI_UNWRAP_REFERENCE(self);
J9VMJAVALANGINVOKEMEMBERNAME_SET_TYPE(currentThread, membernameObject, signatureString);
}
}
} else {
vmFuncs->setCurrentExceptionUTF(currentThread, J9VMCONSTANTPOOL_JAVALANGILLEGALARGUMENTEXCEPTION, NULL);
}
} else {
vmFuncs->setCurrentExceptionUTF(currentThread, J9VMCONSTANTPOOL_JAVALANGINTERNALERROR, NULL);
}
}
Trc_JCL_java_lang_invoke_MethodHandleNatives_expand_Exit(env);
vmFuncs->internalExitVMToJNI(currentThread);
}
/**
* [JDK8] static native MemberName resolve(MemberName self, Class<?> caller)
* throws LinkageError, ClassNotFoundException;
*
* [JDK11] static native MemberName resolve(MemberName self, Class<?> caller,
* boolean speculativeResolve) throws LinkageError, ClassNotFoundException;
*
* [JDK16+] static native MemberName resolve(MemberName self, Class<?> caller, int lookupMode,
* boolean speculativeResolve) throws LinkageError, ClassNotFoundException;
*
* Resolve the method/field represented by the MemberName's symbolic data (name & type & defc)
* with the supplied caller. Store the resolved Method/Field's JNI-id in vmindex, field offset
* or method pointer in vmtarget.
*
* If the speculativeResolve flag is not set, failed resolution will throw the corresponding exception.
*
* If the resolution failed with no exception,
* - Throw NoSuchFieldError for field MemberName issues.
* - Throw NoSuchMethodError for method/constructor MemberName issues.
* - Throw OutOfMemoryError for failure to allocate memory.
* - Throw LinkageError for other issues.
*/
jobject JNICALL
Java_java_lang_invoke_MethodHandleNatives_resolve(
#if JAVA_SPEC_VERSION == 8
JNIEnv *env, jclass clazz, jobject self, jclass caller
#elif JAVA_SPEC_VERSION == 11 /* JAVA_SPEC_VERSION == 8 */
JNIEnv *env, jclass clazz, jobject self, jclass caller,
jboolean speculativeResolve
#elif JAVA_SPEC_VERSION >= 16 /* JAVA_SPEC_VERSION == 11 */
JNIEnv *env, jclass clazz, jobject self, jclass caller,
jint lookupMode, jboolean speculativeResolve
#endif /* JAVA_SPEC_VERSION == 8 */
) {
J9VMThread *currentThread = (J9VMThread*)env;
J9JavaVM *vm = currentThread->javaVM;
const J9InternalVMFunctions *vmFuncs = vm->internalVMFunctions;
jobject result = NULL;
J9UTF8 *name = NULL;
char nameBuffer[256];
nameBuffer[0] = 0;
J9UTF8 *signature = NULL;
char signatureBuffer[256];
signatureBuffer[0] = 0;
PORT_ACCESS_FROM_JAVAVM(vm);
vmFuncs->internalEnterVMFromJNI(currentThread);
#if JAVA_SPEC_VERSION >= 11
Trc_JCL_java_lang_invoke_MethodHandleNatives_resolve_Entry(env, self, caller, (speculativeResolve ? "true" : "false"));
#else /* JAVA_SPEC_VERSION >= 11 */
Trc_JCL_java_lang_invoke_MethodHandleNatives_resolve_Entry(env, self, caller, "false");
#endif /* JAVA_SPEC_VERSION >= 11 */