- Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathjvmciCompilerToVM.cpp
3403 lines (3065 loc) · 159 KB
/
jvmciCompilerToVM.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 (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include"classfile/classLoaderData.inline.hpp"
#include"classfile/javaClasses.inline.hpp"
#include"classfile/stringTable.hpp"
#include"classfile/symbolTable.hpp"
#include"classfile/systemDictionary.hpp"
#include"classfile/vmClasses.hpp"
#include"code/scopeDesc.hpp"
#include"compiler/compileBroker.hpp"
#include"compiler/compilerEvent.hpp"
#include"compiler/compilerOracle.hpp"
#include"compiler/disassembler.hpp"
#include"compiler/oopMap.hpp"
#include"interpreter/bytecodeStream.hpp"
#include"interpreter/linkResolver.hpp"
#include"interpreter/oopMapCache.hpp"
#include"jfr/jfrEvents.hpp"
#include"jvmci/jvmciCodeInstaller.hpp"
#include"jvmci/jvmciCompilerToVM.hpp"
#include"jvmci/jvmciRuntime.hpp"
#include"logging/log.hpp"
#include"logging/logTag.hpp"
#include"memory/oopFactory.hpp"
#include"memory/universe.hpp"
#include"oops/constantPool.inline.hpp"
#include"oops/instanceKlass.inline.hpp"
#include"oops/instanceMirrorKlass.hpp"
#include"oops/method.inline.hpp"
#include"oops/objArrayKlass.inline.hpp"
#include"oops/typeArrayOop.inline.hpp"
#include"prims/jvmtiExport.hpp"
#include"prims/methodHandles.hpp"
#include"prims/nativeLookup.hpp"
#include"runtime/arguments.hpp"
#include"runtime/atomic.hpp"
#include"runtime/deoptimization.hpp"
#include"runtime/fieldDescriptor.inline.hpp"
#include"runtime/frame.inline.hpp"
#include"runtime/globals_extension.hpp"
#include"runtime/interfaceSupport.inline.hpp"
#include"runtime/jniHandles.inline.hpp"
#include"runtime/keepStackGCProcessed.hpp"
#include"runtime/reflection.hpp"
#include"runtime/stackFrameStream.inline.hpp"
#include"runtime/timerTrace.hpp"
#include"runtime/vframe.inline.hpp"
#include"runtime/vframe_hp.hpp"
#if INCLUDE_JFR
#include"jfr/jfr.hpp"
#endif
JVMCIKlassHandle::JVMCIKlassHandle(Thread* thread, Klass* klass) {
_thread = thread;
_klass = klass;
if (klass != nullptr) {
_holder = Handle(_thread, klass->klass_holder());
}
}
JVMCIKlassHandle& JVMCIKlassHandle::operator=(Klass* klass) {
_klass = klass;
if (klass != nullptr) {
_holder = Handle(_thread, klass->klass_holder());
}
return *this;
}
staticvoidrequireInHotSpot(constchar* caller, JVMCI_TRAPS) {
if (!JVMCIENV->is_hotspot()) {
JVMCI_THROW_MSG(IllegalStateException, err_msg("Cannot call %s from JVMCI shared library", caller));
}
}
staticvoidrequireNotInHotSpot(constchar* caller, JVMCI_TRAPS) {
if (JVMCIENV->is_hotspot()) {
JVMCI_THROW_MSG(IllegalStateException, err_msg("Cannot call %s from HotSpot", caller));
}
}
classJVMCITraceMark : publicStackObj {
constchar* _msg;
public:
JVMCITraceMark(constchar* msg) {
_msg = msg;
JVMCI_event_2("Enter %s", _msg);
}
~JVMCITraceMark() {
JVMCI_event_2(" Exit %s", _msg);
}
};
classJavaArgumentUnboxer : publicSignatureIterator {
protected:
JavaCallArguments* _jca;
arrayOop _args;
int _index;
Handlenext_arg(BasicType expectedType);
public:
JavaArgumentUnboxer(Symbol* signature,
JavaCallArguments* jca,
arrayOop args,
bool is_static)
: SignatureIterator(signature)
{
this->_return_type = T_ILLEGAL;
_jca = jca;
_index = 0;
_args = args;
if (!is_static) {
_jca->push_oop(next_arg(T_OBJECT));
}
do_parameters_on(this);
assert(_index == args->length(), "arg count mismatch with signature");
}
private:
friendclassSignatureIterator; // so do_parameters_on can call do_type
voiddo_type(BasicType type) {
if (is_reference_type(type)) {
_jca->push_oop(next_arg(T_OBJECT));
return;
}
Handle arg = next_arg(type);
int box_offset = java_lang_boxing_object::value_offset(type);
switch (type) {
case T_BOOLEAN: _jca->push_int(arg->bool_field(box_offset)); break;
case T_CHAR: _jca->push_int(arg->char_field(box_offset)); break;
case T_SHORT: _jca->push_int(arg->short_field(box_offset)); break;
case T_BYTE: _jca->push_int(arg->byte_field(box_offset)); break;
case T_INT: _jca->push_int(arg->int_field(box_offset)); break;
case T_LONG: _jca->push_long(arg->long_field(box_offset)); break;
case T_FLOAT: _jca->push_float(arg->float_field(box_offset)); break;
case T_DOUBLE: _jca->push_double(arg->double_field(box_offset)); break;
default: ShouldNotReachHere();
}
}
};
HandleJavaArgumentUnboxer::next_arg(BasicType expectedType) {
assert(_index < _args->length(), "out of bounds");
oop arg=((objArrayOop) (_args))->obj_at(_index++);
assert(expectedType == T_OBJECT || java_lang_boxing_object::is_instance(arg, expectedType), "arg type mismatch");
returnHandle(Thread::current(), arg);
}
// Bring the JVMCI compiler thread into the VM state.
#defineJVMCI_VM_ENTRY_MARK \
MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, thread)); \
ThreadInVMfromNative __tiv(thread); \
HandleMarkCleaner __hm(thread); \
JavaThread* THREAD = thread; \
DEBUG_ONLY(VMNativeEntryWrapper __vew;)
// Native method block that transitions current thread to '_thread_in_vm'.
// Note: CompilerThreadCanCallJava must precede JVMCIENV_FROM_JNI so that
// the translation of an uncaught exception in the JVMCIEnv does not make
// a Java call when __is_hotspot == false.
#defineC2V_BLOCK(result_type, name, signature) \
JVMCI_VM_ENTRY_MARK; \
ResourceMark rm; \
bool __is_hotspot = env == thread->jni_environment(); \
bool __block_can_call_java = __is_hotspot || !thread->is_Compiler_thread() || CompilerThread::cast(thread)->can_call_java(); \
CompilerThreadCanCallJava ccj(thread, __block_can_call_java); \
JVMCIENV_FROM_JNI(JVMCI::compilation_tick(thread), env); \
// Entry to native method implementation that transitions
// current thread to '_thread_in_vm'.
#defineC2V_VMENTRY(result_type, name, signature) \
result_type JNICALL c2v_ ## name signature { \
JavaThread* thread = JavaThread::current_or_null(); \
if (thread == nullptr) { \
env->ThrowNew(JNIJVMCI::InternalError::clazz(), \
err_msg("Cannot call into HotSpot from JVMCI shared library without attaching current thread")); \
return; \
} \
C2V_BLOCK(result_type, name, signature) \
JVMCITraceMark jtm("CompilerToVM::" #name);
#defineC2V_VMENTRY_(result_type, name, signature, result) \
result_type JNICALL c2v_ ## name signature { \
JavaThread* thread = JavaThread::current_or_null(); \
if (thread == nullptr) { \
env->ThrowNew(JNIJVMCI::InternalError::clazz(), \
err_msg("Cannot call into HotSpot from JVMCI shared library without attaching current thread")); \
return result; \
} \
C2V_BLOCK(result_type, name, signature) \
JVMCITraceMark jtm("CompilerToVM::" #name);
#defineC2V_VMENTRY_NULL(result_type, name, signature) C2V_VMENTRY_(result_type, name, signature, nullptr)
#defineC2V_VMENTRY_0(result_type, name, signature) C2V_VMENTRY_(result_type, name, signature, 0)
// Entry to native method implementation that does not transition
// current thread to '_thread_in_vm'.
#defineC2V_VMENTRY_PREFIX(result_type, name, signature) \
result_type JNICALL c2v_ ## name signature { \
JavaThread* thread = JavaThread::current_or_null();
#defineC2V_END }
#defineJNI_THROW(caller, name, msg) do { \
jint __throw_res = env->ThrowNew(JNIJVMCI::name::clazz(), msg); \
if (__throw_res != JNI_OK) { \
JVMCI_event_1("Throwing " #name " in " caller " returned %d", __throw_res); \
} \
return; \
} while (0);
#defineJNI_THROW_(caller, name, msg, result) do { \
jint __throw_res = env->ThrowNew(JNIJVMCI::name::clazz(), msg); \
if (__throw_res != JNI_OK) { \
JVMCI_event_1("Throwing " #name " in " caller " returned %d", __throw_res); \
} \
return result; \
} while (0)
jobjectArray readConfiguration0(JNIEnv *env, JVMCI_TRAPS);
C2V_VMENTRY_NULL(jobjectArray, readConfiguration, (JNIEnv* env))
jobjectArray config = readConfiguration0(env, JVMCI_CHECK_NULL);
return config;
}
C2V_VMENTRY_NULL(jobject, getFlagValue, (JNIEnv* env, jobject c2vm, jobject name_handle))
#defineRETURN_BOXED_LONG(value) jvalue p; p.j = (jlong) (value); JVMCIObject box = JVMCIENV->create_box(T_LONG, &p, JVMCI_CHECK_NULL); return box.as_jobject();
#defineRETURN_BOXED_DOUBLE(value) jvalue p; p.d = (jdouble) (value); JVMCIObject box = JVMCIENV->create_box(T_DOUBLE, &p, JVMCI_CHECK_NULL); return box.as_jobject();
JVMCIObject name = JVMCIENV->wrap(name_handle);
if (name.is_null()) {
JVMCI_THROW_NULL(NullPointerException);
}
constchar* cstring = JVMCIENV->as_utf8_string(name);
const JVMFlag* flag = JVMFlag::find_declared_flag(cstring);
if (flag == nullptr) {
return c2vm;
}
if (flag->is_bool()) {
jvalue prim;
prim.z = flag->get_bool();
JVMCIObject box = JVMCIENV->create_box(T_BOOLEAN, &prim, JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(box);
} elseif (flag->is_ccstr()) {
JVMCIObject value = JVMCIENV->create_string(flag->get_ccstr(), JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(value);
} elseif (flag->is_intx()) {
RETURN_BOXED_LONG(flag->get_intx());
} elseif (flag->is_int()) {
RETURN_BOXED_LONG(flag->get_int());
} elseif (flag->is_uint()) {
RETURN_BOXED_LONG(flag->get_uint());
} elseif (flag->is_uint64_t()) {
RETURN_BOXED_LONG(flag->get_uint64_t());
} elseif (flag->is_size_t()) {
RETURN_BOXED_LONG(flag->get_size_t());
} elseif (flag->is_uintx()) {
RETURN_BOXED_LONG(flag->get_uintx());
} elseif (flag->is_double()) {
RETURN_BOXED_DOUBLE(flag->get_double());
} else {
JVMCI_ERROR_NULL("VM flag %s has unsupported type %s", flag->name(), flag->type_string());
}
#undef RETURN_BOXED_LONG
#undef RETURN_BOXED_DOUBLE
C2V_END
// Macros for argument pairs representing a wrapper object and its wrapped VM pointer
#defineARGUMENT_PAIR(name) jobject name ## _obj, jlong name ## _pointer
#defineUNPACK_PAIR(type, name) ((type*) name ## _pointer)
C2V_VMENTRY_NULL(jbyteArray, getBytecode, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
methodHandle method(THREAD, UNPACK_PAIR(Method, method));
int code_size = method->code_size();
jbyte* reconstituted_code = NEW_RESOURCE_ARRAY(jbyte, code_size);
guarantee(method->method_holder()->is_rewritten(), "Method's holder should be rewritten");
// iterate over all bytecodes and replace non-Java bytecodes
for (BytecodeStream s(method); s.next() != Bytecodes::_illegal; ) {
Bytecodes::Code code = s.code();
Bytecodes::Code raw_code = s.raw_code();
int bci = s.bci();
int len = s.instruction_size();
// Restore original byte code.
reconstituted_code[bci] = (jbyte) (s.is_wide()? Bytecodes::_wide : code);
if (len > 1) {
memcpy(reconstituted_code + (bci + 1), s.bcp()+1, len-1);
}
if (len > 1) {
// Restore the big-endian constant pool indexes.
// Cf. Rewriter::scan_method
switch (code) {
case Bytecodes::_getstatic:
case Bytecodes::_putstatic:
case Bytecodes::_getfield:
case Bytecodes::_putfield:
case Bytecodes::_invokevirtual:
case Bytecodes::_invokespecial:
case Bytecodes::_invokestatic:
case Bytecodes::_invokeinterface:
case Bytecodes::_invokehandle: {
int cp_index = Bytes::get_native_u2((address) reconstituted_code + (bci + 1));
Bytes::put_Java_u2((address) reconstituted_code + (bci + 1), (u2) cp_index);
break;
}
case Bytecodes::_invokedynamic: {
int cp_index = Bytes::get_native_u4((address) reconstituted_code + (bci + 1));
Bytes::put_Java_u4((address) reconstituted_code + (bci + 1), (u4) cp_index);
break;
}
default:
break;
}
// Not all ldc byte code are rewritten.
switch (raw_code) {
case Bytecodes::_fast_aldc: {
int cpc_index = reconstituted_code[bci + 1] & 0xff;
int cp_index = method->constants()->object_to_cp_index(cpc_index);
assert(cp_index < method->constants()->length(), "sanity check");
reconstituted_code[bci + 1] = (jbyte) cp_index;
break;
}
case Bytecodes::_fast_aldc_w: {
int cpc_index = Bytes::get_native_u2((address) reconstituted_code + (bci + 1));
int cp_index = method->constants()->object_to_cp_index(cpc_index);
assert(cp_index < method->constants()->length(), "sanity check");
Bytes::put_Java_u2((address) reconstituted_code + (bci + 1), (u2) cp_index);
break;
}
default:
break;
}
}
}
JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
JVMCIENV->copy_bytes_from(reconstituted_code, result, 0, code_size);
return JVMCIENV->get_jbyteArray(result);
C2V_END
C2V_VMENTRY_0(jint, getExceptionTableLength, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
Method* method = UNPACK_PAIR(Method, method);
return method->exception_table_length();
C2V_END
C2V_VMENTRY_0(jlong, getExceptionTableStart, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
Method* method = UNPACK_PAIR(Method, method);
if (method->exception_table_length() == 0) {
return0L;
}
return (jlong) (address) method->exception_table_start();
C2V_END
C2V_VMENTRY_NULL(jobject, asResolvedJavaMethod, (JNIEnv* env, jobject, jobject executable_handle))
requireInHotSpot("asResolvedJavaMethod", JVMCI_CHECK_NULL);
oop executable = JNIHandles::resolve(executable_handle);
oop mirror = nullptr;
int slot = 0;
if (executable->klass() == vmClasses::reflect_Constructor_klass()) {
mirror = java_lang_reflect_Constructor::clazz(executable);
slot = java_lang_reflect_Constructor::slot(executable);
} else {
assert(executable->klass() == vmClasses::reflect_Method_klass(), "wrong type");
mirror = java_lang_reflect_Method::clazz(executable);
slot = java_lang_reflect_Method::slot(executable);
}
Klass* holder = java_lang_Class::as_Klass(mirror);
methodHandle method (THREAD, InstanceKlass::cast(holder)->method_with_idnum(slot));
JVMCIObject result = JVMCIENV->get_jvmci_method(method, JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(result);
}
C2V_VMENTRY_PREFIX(jboolean, updateCompilerThreadCanCallJava, (JNIEnv* env, jobject, jboolean newState))
returnCompilerThreadCanCallJava::update(thread, newState) != nullptr;
C2V_END
C2V_VMENTRY_NULL(jobject, getResolvedJavaMethod, (JNIEnv* env, jobject, jobject base, jlong offset))
Method* method = nullptr;
JVMCIObject base_object = JVMCIENV->wrap(base);
if (base_object.is_null()) {
method = *((Method**)(offset));
} else {
Handle obj = JVMCIENV->asConstant(base_object, JVMCI_CHECK_NULL);
if (obj->is_a(vmClasses::ResolvedMethodName_klass())) {
method = (Method*) (intptr_t) obj->long_field(offset);
} else {
JVMCI_THROW_MSG_NULL(IllegalArgumentException, err_msg("Unexpected type: %s", obj->klass()->external_name()));
}
}
if (method == nullptr) {
JVMCI_THROW_MSG_NULL(IllegalArgumentException, err_msg("Unexpected type: %s", JVMCIENV->klass_name(base_object)));
}
assert (method->is_method(), "invalid read");
JVMCIObject result = JVMCIENV->get_jvmci_method(methodHandle(THREAD, method), JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(result);
}
C2V_VMENTRY_NULL(jobject, getConstantPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass_or_method), jboolean is_klass))
ConstantPool* cp = nullptr;
if (UNPACK_PAIR(address, klass_or_method) == nullptr) {
JVMCI_THROW_NULL(NullPointerException);
}
if (!is_klass) {
cp = (UNPACK_PAIR(Method, klass_or_method))->constMethod()->constants();
} else {
cp = InstanceKlass::cast(UNPACK_PAIR(Klass, klass_or_method))->constants();
}
JVMCIObject result = JVMCIENV->get_jvmci_constant_pool(constantPoolHandle(THREAD, cp), JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(result);
}
C2V_VMENTRY_NULL(jobject, getResolvedJavaType0, (JNIEnv* env, jobject, jobject base, jlong offset, jboolean compressed))
JVMCIObject base_object = JVMCIENV->wrap(base);
if (base_object.is_null()) {
JVMCI_THROW_MSG_NULL(NullPointerException, "base object is null");
}
constchar* base_desc = nullptr;
JVMCIKlassHandle klass(THREAD);
if (offset == oopDesc::klass_offset_in_bytes()) {
if (JVMCIENV->isa_HotSpotObjectConstantImpl(base_object)) {
Handle base_oop = JVMCIENV->asConstant(base_object, JVMCI_CHECK_NULL);
klass = base_oop->klass();
} else {
goto unexpected;
}
} elseif (!compressed) {
if (JVMCIENV->isa_HotSpotConstantPool(base_object)) {
ConstantPool* cp = JVMCIENV->asConstantPool(base_object);
if (offset == in_bytes(ConstantPool::pool_holder_offset())) {
klass = cp->pool_holder();
} else {
base_desc = FormatBufferResource("[constant pool for %s]", cp->pool_holder()->signature_name());
goto unexpected;
}
} elseif (JVMCIENV->isa_HotSpotResolvedObjectTypeImpl(base_object)) {
Klass* base_klass = JVMCIENV->asKlass(base_object);
if (offset == in_bytes(Klass::subklass_offset())) {
klass = base_klass->subklass();
} elseif (offset == in_bytes(Klass::super_offset())) {
klass = base_klass->super();
} elseif (offset == in_bytes(Klass::next_sibling_offset())) {
klass = base_klass->next_sibling();
} elseif (offset == in_bytes(ObjArrayKlass::element_klass_offset()) && base_klass->is_objArray_klass()) {
klass = ObjArrayKlass::cast(base_klass)->element_klass();
} elseif (offset >= in_bytes(Klass::primary_supers_offset()) &&
offset < in_bytes(Klass::primary_supers_offset()) + (int) (sizeof(Klass*) * Klass::primary_super_limit()) &&
offset % sizeof(Klass*) == 0) {
// Offset is within the primary supers array
intindex = (int) ((offset - in_bytes(Klass::primary_supers_offset())) / sizeof(Klass*));
klass = base_klass->primary_super_of_depth(index);
} else {
base_desc = FormatBufferResource("[%s]", base_klass->signature_name());
goto unexpected;
}
} elseif (JVMCIENV->isa_HotSpotObjectConstantImpl(base_object)) {
Handle base_oop = JVMCIENV->asConstant(base_object, JVMCI_CHECK_NULL);
if (base_oop->is_a(vmClasses::Class_klass())) {
if (offset == java_lang_Class::klass_offset()) {
klass = java_lang_Class::as_Klass(base_oop());
} elseif (offset == java_lang_Class::array_klass_offset()) {
klass = java_lang_Class::array_klass_acquire(base_oop());
} else {
base_desc = FormatBufferResource("[Class=%s]", java_lang_Class::as_Klass(base_oop())->signature_name());
goto unexpected;
}
} else {
if (!base_oop.is_null()) {
base_desc = FormatBufferResource("[%s]", base_oop()->klass()->signature_name());
}
goto unexpected;
}
} elseif (JVMCIENV->isa_HotSpotMethodData(base_object)) {
jlong base_address = (intptr_t) JVMCIENV->asMethodData(base_object);
klass = *((Klass**) (intptr_t) (base_address + offset));
if (klass == nullptr || !klass->is_loader_alive()) {
// Klasses in methodData might be concurrently unloading so return null in that case.
returnnullptr;
}
} else {
goto unexpected;
}
} else {
goto unexpected;
}
{
if (klass == nullptr) {
returnnullptr;
}
JVMCIObject result = JVMCIENV->get_jvmci_type(klass, JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(result);
}
unexpected:
JVMCI_THROW_MSG_NULL(IllegalArgumentException,
err_msg("Unexpected arguments: %s%s " JLONG_FORMAT " %s",
JVMCIENV->klass_name(base_object), base_desc == nullptr ? "" : base_desc,
offset, compressed ? "true" : "false"));
}
C2V_VMENTRY_NULL(jobject, findUniqueConcreteMethod, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), ARGUMENT_PAIR(method)))
methodHandle method (THREAD, UNPACK_PAIR(Method, method));
InstanceKlass* holder = InstanceKlass::cast(UNPACK_PAIR(Klass, klass));
if (holder->is_interface()) {
JVMCI_THROW_MSG_NULL(InternalError, err_msg("Interface %s should be handled in Java code", holder->external_name()));
}
if (method->can_be_statically_bound()) {
JVMCI_THROW_MSG_NULL(InternalError, err_msg("Effectively static method %s.%s should be handled in Java code", method->method_holder()->external_name(), method->external_name()));
}
methodHandle ucm;
{
MutexLocker locker(Compile_lock);
ucm = methodHandle(THREAD, Dependencies::find_unique_concrete_method(holder, method()));
}
JVMCIObject result = JVMCIENV->get_jvmci_method(ucm, JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(result);
C2V_END
C2V_VMENTRY_NULL(jobject, getImplementor, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
Klass* klass = UNPACK_PAIR(Klass, klass);
if (!klass->is_interface()) {
THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
err_msg("Expected interface type, got %s", klass->external_name()));
}
InstanceKlass* iklass = InstanceKlass::cast(klass);
JVMCIKlassHandle handle(THREAD, iklass->implementor());
JVMCIObject implementor = JVMCIENV->get_jvmci_type(handle, JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(implementor);
C2V_END
C2V_VMENTRY_0(jboolean, methodIsIgnoredBySecurityStackWalk,(JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
Method* method = UNPACK_PAIR(Method, method);
return method->is_ignored_by_security_stack_walk();
C2V_END
C2V_VMENTRY_0(jboolean, isCompilable,(JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
Method* method = UNPACK_PAIR(Method, method);
// Skip redefined methods
if (method->is_old()) {
returnfalse;
}
return !method->is_not_compilable(CompLevel_full_optimization);
C2V_END
C2V_VMENTRY_0(jboolean, hasNeverInlineDirective,(JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
methodHandle method (THREAD, UNPACK_PAIR(Method, method));
return !Inline || CompilerOracle::should_not_inline(method) || method->dont_inline();
C2V_END
C2V_VMENTRY_0(jboolean, shouldInlineMethod,(JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
methodHandle method (THREAD, UNPACK_PAIR(Method, method));
return CompilerOracle::should_inline(method) || method->force_inline();
C2V_END
C2V_VMENTRY_NULL(jobject, lookupType, (JNIEnv* env, jobject, jstring jname, ARGUMENT_PAIR(accessing_klass), jint accessing_klass_loader, jboolean resolve))
CompilerThreadCanCallJava canCallJava(thread, resolve); // Resolution requires Java calls
JVMCIObject name = JVMCIENV->wrap(jname);
constchar* str = JVMCIENV->as_utf8_string(name);
TempNewSymbol class_name = SymbolTable::new_symbol(str);
if (class_name->utf8_length() <= 1) {
JVMCI_THROW_MSG_NULL(InternalError, err_msg("Primitive type %s should be handled in Java code", str));
}
#ifdef ASSERT
constchar* val = Arguments::PropertyList_get_value(Arguments::system_properties(), "test.jvmci.lookupTypeException");
if (val != nullptr) {
if (strstr(val, "<trace>") != nullptr) {
tty->print_cr("CompilerToVM.lookupType: %s", str);
} elseif (strstr(str, val) != nullptr) {
THROW_MSG_NULL(vmSymbols::java_lang_Exception(),
err_msg("lookupTypeException: %s", str));
}
}
#endif
JVMCIKlassHandle resolved_klass(THREAD);
Klass* accessing_klass = UNPACK_PAIR(Klass, accessing_klass);
Handle class_loader;
if (accessing_klass != nullptr) {
class_loader = Handle(THREAD, accessing_klass->class_loader());
} else {
switch (accessing_klass_loader) {
case0: break; // class_loader is already null, the boot loader
case1: class_loader = Handle(THREAD, SystemDictionary::java_platform_loader()); break;
case2: class_loader = Handle(THREAD, SystemDictionary::java_system_loader()); break;
default:
JVMCI_THROW_MSG_NULL(InternalError, err_msg("Illegal class loader value: %d", accessing_klass_loader));
}
JVMCIENV->runtime()->initialize(JVMCI_CHECK_NULL);
}
if (resolve) {
resolved_klass = SystemDictionary::resolve_or_fail(class_name, class_loader, true, CHECK_NULL);
} else {
if (Signature::has_envelope(class_name)) {
// This is a name from a signature. Strip off the trimmings.
// Call recursive to keep scope of strippedsym.
TempNewSymbol strippedsym = Signature::strip_envelope(class_name);
resolved_klass = SystemDictionary::find_instance_klass(THREAD, strippedsym,
class_loader);
} elseif (Signature::is_array(class_name)) {
SignatureStream ss(class_name, false);
int ndim = ss.skip_array_prefix();
if (ss.type() == T_OBJECT) {
Symbol* strippedsym = ss.as_symbol();
resolved_klass = SystemDictionary::find_instance_klass(THREAD, strippedsym,
class_loader);
if (!resolved_klass.is_null()) {
resolved_klass = resolved_klass->array_klass(ndim, CHECK_NULL);
}
} else {
resolved_klass = Universe::typeArrayKlass(ss.type())->array_klass(ndim, CHECK_NULL);
}
} else {
resolved_klass = SystemDictionary::find_instance_klass(THREAD, class_name,
class_loader);
}
}
JVMCIObject result = JVMCIENV->get_jvmci_type(resolved_klass, JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(result);
C2V_END
C2V_VMENTRY_NULL(jobject, getArrayType, (JNIEnv* env, jobject, jchar type_char, ARGUMENT_PAIR(klass)))
JVMCIKlassHandle array_klass(THREAD);
Klass* klass = UNPACK_PAIR(Klass, klass);
if (klass == nullptr) {
BasicType type = JVMCIENV->typeCharToBasicType(type_char, JVMCI_CHECK_NULL);
if (type == T_VOID) {
returnnullptr;
}
array_klass = Universe::typeArrayKlass(type);
if (array_klass == nullptr) {
JVMCI_THROW_MSG_NULL(InternalError, err_msg("No array klass for primitive type %s", type2name(type)));
}
} else {
array_klass = klass->array_klass(CHECK_NULL);
}
JVMCIObject result = JVMCIENV->get_jvmci_type(array_klass, JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(result);
C2V_END
C2V_VMENTRY_NULL(jobject, lookupClass, (JNIEnv* env, jobject, jclass mirror))
requireInHotSpot("lookupClass", JVMCI_CHECK_NULL);
if (mirror == nullptr) {
returnnullptr;
}
JVMCIKlassHandle klass(THREAD);
klass = java_lang_Class::as_Klass(JNIHandles::resolve(mirror));
if (klass == nullptr) {
JVMCI_THROW_MSG_NULL(IllegalArgumentException, "Primitive classes are unsupported");
}
JVMCIObject result = JVMCIENV->get_jvmci_type(klass, JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(result);
C2V_END
C2V_VMENTRY_NULL(jobject, lookupJClass, (JNIEnv* env, jobject, jlong jclass_value))
if (jclass_value == 0L) {
JVMCI_THROW_MSG_NULL(IllegalArgumentException, "jclass must not be zero");
}
jclass mirror = reinterpret_cast<jclass>(jclass_value);
// Since the jclass_value is passed as a jlong, we perform additional checks to prevent the caller from accidentally
// sending a value that is not a JNI handle.
if (JNIHandles::handle_type(thread, mirror) == JNIInvalidRefType) {
JVMCI_THROW_MSG_NULL(IllegalArgumentException, "jclass is not a valid JNI reference");
}
oop obj = JNIHandles::resolve(mirror);
if (!java_lang_Class::is_instance(obj)) {
JVMCI_THROW_MSG_NULL(IllegalArgumentException, "jclass must be a reference to the Class object");
}
JVMCIKlassHandle klass(THREAD, java_lang_Class::as_Klass(obj));
JVMCIObject result = JVMCIENV->get_jvmci_type(klass, JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(result);
C2V_END
C2V_VMENTRY_0(jlong, getJObjectValue, (JNIEnv* env, jobject, jobject constant_jobject))
requireNotInHotSpot("getJObjectValue", JVMCI_CHECK_0);
// Ensure that current JNI handle scope is not the top-most JNIHandleBlock as handles
// in that scope are only released when the thread exits.
if (!THREAD->has_last_Java_frame() && THREAD->active_handles()->pop_frame_link() == nullptr) {
JVMCI_THROW_MSG_0(IllegalStateException, err_msg("Cannot call getJObjectValue without Java frame anchor or a pushed JNI handle block"));
}
JVMCIObject constant = JVMCIENV->wrap(constant_jobject);
Handle constant_value = JVMCIENV->asConstant(constant, JVMCI_CHECK_0);
jobject jni_handle = JNIHandles::make_local(THREAD, constant_value());
returnreinterpret_cast<jlong>(jni_handle);
C2V_END
C2V_VMENTRY_NULL(jobject, getUncachedStringInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index))
constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp));
constantTag tag = cp->tag_at(index);
if (!tag.is_string()) {
JVMCI_THROW_MSG_NULL(IllegalArgumentException, err_msg("Unexpected constant pool tag at index %d: %d", index, tag.value()));
}
oop obj = cp->uncached_string_at(index, CHECK_NULL);
return JVMCIENV->get_jobject(JVMCIENV->get_object_constant(obj));
C2V_END
C2V_VMENTRY_NULL(jobject, lookupConstantInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint cp_index, bool resolve))
constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp));
oop obj;
if (!resolve) {
bool found_it;
obj = cp->find_cached_constant_at(cp_index, found_it, CHECK_NULL);
if (!found_it) {
returnnullptr;
}
} else {
obj = cp->resolve_possibly_cached_constant_at(cp_index, CHECK_NULL);
}
constantTag tag = cp->tag_at(cp_index);
if (tag.is_dynamic_constant()) {
if (obj == nullptr) {
return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_NULL_POINTER());
}
BasicType bt = Signature::basic_type(cp->uncached_signature_ref_at(cp_index));
if (!is_reference_type(bt)) {
if (!is_java_primitive(bt)) {
return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_ILLEGAL());
}
// Convert standard box (e.g. java.lang.Integer) to JVMCI box (e.g. jdk.vm.ci.meta.PrimitiveConstant)
jvalue value;
jlong raw_value;
jchar type_char;
BasicType bt2 = java_lang_boxing_object::get_value(obj, &value);
assert(bt2 == bt, "");
switch (bt2) {
case T_LONG: type_char = 'J'; raw_value = value.j; break;
case T_DOUBLE: type_char = 'D'; raw_value = value.j; break;
case T_FLOAT: type_char = 'F'; raw_value = value.i; break;
case T_INT: type_char = 'I'; raw_value = value.i; break;
case T_SHORT: type_char = 'S'; raw_value = value.s; break;
case T_BYTE: type_char = 'B'; raw_value = value.b; break;
case T_CHAR: type_char = 'C'; raw_value = value.c; break;
case T_BOOLEAN: type_char = 'Z'; raw_value = value.z; break;
default: return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_ILLEGAL());
}
JVMCIObject result = JVMCIENV->call_JavaConstant_forPrimitive(type_char, raw_value, JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(result);
}
}
#ifdef ASSERT
// Support for testing an OOME raised in a context where the current thread cannot call Java
// 1. Put -Dtest.jvmci.oome_in_lookupConstantInPool=<trace> on the command line to
// discover possible values for step 2.
// Example output:
//
// CompilerToVM.lookupConstantInPool: "Overflow: String length out of range"{0x00000007ffeb2960}
// CompilerToVM.lookupConstantInPool: "null"{0x00000007ffebdfe8}
// CompilerToVM.lookupConstantInPool: "Maximum lock count exceeded"{0x00000007ffec4f90}
// CompilerToVM.lookupConstantInPool: "Negative length"{0x00000007ffec4468}
//
// 2. Choose a value shown in step 1.
// Example: -Dtest.jvmci.oome_in_lookupConstantInPool=Negative
constchar* val = Arguments::PropertyList_get_value(Arguments::system_properties(), "test.jvmci.oome_in_lookupConstantInPool");
if (val != nullptr) {
constchar* str = obj->print_value_string();
if (strstr(val, "<trace>") != nullptr) {
tty->print_cr("CompilerToVM.lookupConstantInPool: %s", str);
} elseif (strstr(str, val) != nullptr) {
Handle garbage;
while (true) {
// Trigger an OutOfMemoryError
objArrayOop next = oopFactory::new_objectArray(0x7FFFFFFF, CHECK_NULL);
next->obj_at_put(0, garbage());
garbage = Handle(THREAD, next);
}
}
}
#endif
return JVMCIENV->get_jobject(JVMCIENV->get_object_constant(obj));
C2V_END
C2V_VMENTRY_NULL(jobjectArray, resolveBootstrapMethod, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index))
constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp));
constantTag tag = cp->tag_at(index);
bool is_indy = tag.is_invoke_dynamic();
bool is_condy = tag.is_dynamic_constant();
if (!(is_condy || is_indy)) {
JVMCI_THROW_MSG_NULL(IllegalArgumentException, err_msg("Unexpected constant pool tag at index %d: %d", index, tag.value()));
}
// Get the indy entry based on CP index
int indy_index = -1;
if (is_indy) {
for (int i = 0; i < cp->resolved_indy_entries_length(); i++) {
if (cp->resolved_indy_entry_at(i)->constant_pool_index() == index) {
indy_index = i;
}
}
}
// Resolve the bootstrap specifier, its name, type, and static arguments
BootstrapInfo bootstrap_specifier(cp, index, indy_index);
Handle bsm = bootstrap_specifier.resolve_bsm(CHECK_NULL);
// call java.lang.invoke.MethodHandle::asFixedArity() -> MethodHandle
// to get a DirectMethodHandle from which we can then extract a Method*
JavaValue result(T_OBJECT);
JavaCalls::call_virtual(&result,
bsm,
vmClasses::MethodHandle_klass(),
vmSymbols::asFixedArity_name(),
vmSymbols::asFixedArity_signature(),
CHECK_NULL);
bsm = Handle(THREAD, result.get_oop());
// Check assumption about getting a DirectMethodHandle
if (!java_lang_invoke_DirectMethodHandle::is_instance(bsm())) {
JVMCI_THROW_MSG_NULL(InternalError, err_msg("Unexpected MethodHandle subclass: %s", bsm->klass()->external_name()));
}
// Create return array describing the bootstrap method invocation (BSMI)
JVMCIObjectArray bsmi = JVMCIENV->new_Object_array(4, JVMCI_CHECK_NULL);
// Extract Method* and wrap it in a ResolvedJavaMethod
Handle member = Handle(THREAD, java_lang_invoke_DirectMethodHandle::member(bsm()));
JVMCIObject bsmi_method = JVMCIENV->get_jvmci_method(methodHandle(THREAD, java_lang_invoke_MemberName::vmtarget(member())), JVMCI_CHECK_NULL);
JVMCIENV->put_object_at(bsmi, 0, bsmi_method);
JVMCIObject bsmi_name = JVMCIENV->create_string(bootstrap_specifier.name(), JVMCI_CHECK_NULL);
JVMCIENV->put_object_at(bsmi, 1, bsmi_name);
Handle type_arg = bootstrap_specifier.type_arg();
JVMCIObject bsmi_type = JVMCIENV->get_object_constant(type_arg());
JVMCIENV->put_object_at(bsmi, 2, bsmi_type);
Handle arg_values = bootstrap_specifier.arg_values();
if (arg_values.not_null()) {
if (!arg_values->is_array()) {
JVMCIENV->put_object_at(bsmi, 3, JVMCIENV->get_object_constant(arg_values()));
} elseif (arg_values->is_objArray()) {
objArrayHandle args_array = objArrayHandle(THREAD, (objArrayOop) arg_values());
int len = args_array->length();
JVMCIObjectArray arguments = JVMCIENV->new_JavaConstant_array(len, JVMCI_CHECK_NULL);
JVMCIENV->put_object_at(bsmi, 3, arguments);
for (int i = 0; i < len; i++) {
oop x = args_array->obj_at(i);
if (x != nullptr) {
JVMCIENV->put_object_at(arguments, i, JVMCIENV->get_object_constant(x));
} else {
JVMCIENV->put_object_at(arguments, i, JVMCIENV->get_JavaConstant_NULL_POINTER());
}
}
} elseif (arg_values->is_typeArray()) {
typeArrayHandle bsci = typeArrayHandle(THREAD, (typeArrayOop) arg_values());
JVMCIPrimitiveArray arguments = JVMCIENV->new_intArray(bsci->length(), JVMCI_CHECK_NULL);
JVMCIENV->put_object_at(bsmi, 3, arguments);
for (int i = 0; i < bsci->length(); i++) {
JVMCIENV->put_int_at(arguments, i, bsci->int_at(i));
}
}
}
return JVMCIENV->get_jobjectArray(bsmi);
C2V_END
C2V_VMENTRY_0(jint, bootstrapArgumentIndexAt, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint cpi, jint index))
constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp));
return cp->bootstrap_argument_index_at(cpi, index);
C2V_END
C2V_VMENTRY_0(jint, lookupNameAndTypeRefIndexInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index, jint opcode))
constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp));
return cp->name_and_type_ref_index_at(index, (Bytecodes::Code)opcode);
C2V_END
C2V_VMENTRY_NULL(jobject, lookupNameInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint which, jint opcode))
constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp));
JVMCIObject sym = JVMCIENV->create_string(cp->name_ref_at(which, (Bytecodes::Code)opcode), JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(sym);
C2V_END
C2V_VMENTRY_NULL(jobject, lookupSignatureInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint which, jint opcode))
constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp));
JVMCIObject sym = JVMCIENV->create_string(cp->signature_ref_at(which, (Bytecodes::Code)opcode), JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(sym);
C2V_END
C2V_VMENTRY_0(jint, lookupKlassRefIndexInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index, jint opcode))
constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp));
return cp->klass_ref_index_at(index, (Bytecodes::Code)opcode);
C2V_END
C2V_VMENTRY_NULL(jobject, resolveTypeInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index))
constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp));
Klass* klass = cp->klass_at(index, CHECK_NULL);
JVMCIKlassHandle resolved_klass(THREAD, klass);
if (resolved_klass->is_instance_klass()) {
InstanceKlass::cast(resolved_klass())->link_class(CHECK_NULL);
if (!InstanceKlass::cast(resolved_klass())->is_linked()) {
// link_class() should not return here if there is an issue.
JVMCI_THROW_MSG_NULL(InternalError, err_msg("Class %s must be linked", resolved_klass()->external_name()));
}
}
JVMCIObject klassObject = JVMCIENV->get_jvmci_type(resolved_klass, JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(klassObject);
C2V_END
C2V_VMENTRY_NULL(jobject, lookupKlassInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index))
constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp));
Klass* loading_klass = cp->pool_holder();
bool is_accessible = false;
JVMCIKlassHandle klass(THREAD, JVMCIRuntime::get_klass_by_index(cp, index, is_accessible, loading_klass));
Symbol* symbol = nullptr;
if (klass.is_null()) {
constantTag tag = cp->tag_at(index);
if (tag.is_klass()) {
// The klass has been inserted into the constant pool
// very recently.
klass = cp->resolved_klass_at(index);
} elseif (tag.is_symbol()) {
symbol = cp->symbol_at(index);
} else {
if (!tag.is_unresolved_klass()) {
JVMCI_THROW_MSG_NULL(InternalError, err_msg("Expected %d at index %d, got %d", JVM_CONSTANT_UnresolvedClassInError, index, tag.value()));
}
symbol = cp->klass_name_at(index);
}
}
JVMCIObject result;
if (!klass.is_null()) {
result = JVMCIENV->get_jvmci_type(klass, JVMCI_CHECK_NULL);
} else {
result = JVMCIENV->create_string(symbol, JVMCI_CHECK_NULL);
}
return JVMCIENV->get_jobject(result);
C2V_END
C2V_VMENTRY_NULL(jobject, lookupAppendixInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint which, jint opcode))
constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp));
oop appendix_oop = ConstantPool::appendix_at_if_loaded(cp, which, Bytecodes::Code(opcode));
return JVMCIENV->get_jobject(JVMCIENV->get_object_constant(appendix_oop));
C2V_END
C2V_VMENTRY_NULL(jobject, lookupMethodInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index, jbyte opcode, ARGUMENT_PAIR(caller)))
constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp));
methodHandle caller(THREAD, UNPACK_PAIR(Method, caller));
InstanceKlass* pool_holder = cp->pool_holder();
Bytecodes::Code bc = (Bytecodes::Code) (((int) opcode) & 0xFF);
methodHandle method(THREAD, JVMCIRuntime::get_method_by_index(cp, index, bc, pool_holder));
JFR_ONLY(if (method.not_null()) Jfr::on_resolution(caller(), method(), CHECK_NULL);)
JVMCIObject result = JVMCIENV->get_jvmci_method(method, JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(result);
C2V_END
C2V_VMENTRY_NULL(jobject, resolveFieldInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index, ARGUMENT_PAIR(method), jbyte opcode, jintArray info_handle))
constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp));
Bytecodes::Code code = (Bytecodes::Code)(((int) opcode) & 0xFF);
fieldDescriptor fd;
methodHandle mh(THREAD, UNPACK_PAIR(Method, method));
Bytecodes::Code bc = (Bytecodes::Code) (((int) opcode) & 0xFF);
int holder_index = cp->klass_ref_index_at(index, bc);
if (!cp->tag_at(holder_index).is_klass() && !THREAD->can_call_java()) {
// If the holder is not resolved in the constant pool and the current
// thread cannot call Java, return null. This avoids a Java call
// in LinkInfo to load the holder.
Symbol* klass_name = cp->klass_ref_at_noresolve(index, bc);
returnnullptr;
}
LinkInfo link_info(cp, index, mh, code, CHECK_NULL);
LinkResolver::resolve_field(fd, link_info, Bytecodes::java_code(code), false, CHECK_NULL);
JVMCIPrimitiveArray info = JVMCIENV->wrap(info_handle);
if (info.is_null() || JVMCIENV->get_length(info) != 4) {
JVMCI_ERROR_NULL("info must not be null and have a length of 4");