/
jvmciCompilerToVM.cpp
2792 lines (2509 loc) · 131 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, 2021, 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 "precompiled.hpp"
#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/disassembler.hpp"
#include "interpreter/linkResolver.hpp"
#include "interpreter/bytecodeStream.hpp"
#include "jfr/jfrEvents.hpp"
#include "jvmci/jvmciCompilerToVM.hpp"
#include "jvmci/jvmciCodeInstaller.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/method.inline.hpp"
#include "oops/typeArrayOop.inline.hpp"
#include "prims/jvmtiExport.hpp"
#include "prims/methodHandles.hpp"
#include "prims/nativeLookup.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/reflectionUtils.hpp"
#include "runtime/timerTrace.hpp"
#include "runtime/vframe_hp.hpp"
JVMCIKlassHandle::JVMCIKlassHandle(Thread* thread, Klass* klass) {
_thread = thread;
_klass = klass;
if (klass != NULL) {
_holder = Handle(_thread, klass->klass_holder());
}
}
JVMCIKlassHandle& JVMCIKlassHandle::operator=(Klass* klass) {
_klass = klass;
if (klass != NULL) {
_holder = Handle(_thread, klass->klass_holder());
}
return *this;
}
static void requireInHotSpot(const char* caller, JVMCI_TRAPS) {
if (!JVMCIENV->is_hotspot()) {
JVMCI_THROW_MSG(IllegalStateException, err_msg("Cannot call %s from JVMCI shared library", caller));
}
}
void JNIHandleMark::push_jni_handle_block(JavaThread* thread) {
if (thread != NULL) {
// Allocate a new block for JNI handles.
// Inlined code from jni_PushLocalFrame()
JNIHandleBlock* java_handles = thread->active_handles();
JNIHandleBlock* compile_handles = JNIHandleBlock::allocate_block(thread);
assert(compile_handles != NULL && java_handles != NULL, "should not be NULL");
compile_handles->set_pop_frame_link(java_handles);
thread->set_active_handles(compile_handles);
}
}
void JNIHandleMark::pop_jni_handle_block(JavaThread* thread) {
if (thread != NULL) {
// Release our JNI handle block
JNIHandleBlock* compile_handles = thread->active_handles();
JNIHandleBlock* java_handles = compile_handles->pop_frame_link();
thread->set_active_handles(java_handles);
compile_handles->set_pop_frame_link(NULL);
JNIHandleBlock::release_block(compile_handles, thread); // may block
}
}
class JVMCITraceMark : public StackObj {
const char* _msg;
public:
JVMCITraceMark(const char* msg) {
_msg = msg;
JVMCI_event_2("Enter %s", _msg);
}
~JVMCITraceMark() {
JVMCI_event_2(" Exit %s", _msg);
}
};
Handle JavaArgumentUnboxer::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");
return Handle(Thread::current(), arg);
}
// Bring the JVMCI compiler thread into the VM state.
#define JVMCI_VM_ENTRY_MARK \
ThreadInVMfromNative __tiv(thread); \
HandleMarkCleaner __hm(thread); \
Thread* THREAD = thread; \
debug_only(VMNativeEntryWrapper __vew;)
// Native method block that transitions current thread to '_thread_in_vm'.
#define C2V_BLOCK(result_type, name, signature) \
JVMCI_VM_ENTRY_MARK; \
ResourceMark rm; \
JNI_JVMCIENV(JVMCI::compilation_tick(thread), env);
static JavaThread* get_current_thread(bool allow_null=true) {
Thread* thread = Thread::current_or_null_safe();
if (thread == NULL) {
assert(allow_null, "npe");
return NULL;
}
return thread->as_Java_thread();
}
// Entry to native method implementation that transitions
// current thread to '_thread_in_vm'.
#define C2V_VMENTRY(result_type, name, signature) \
JNIEXPORT result_type JNICALL c2v_ ## name signature { \
JavaThread* thread = get_current_thread(); \
if (thread == NULL) { \
env->ThrowNew(JNIJVMCI::InternalError::clazz(), \
err_msg("Cannot call into HotSpot from JVMCI shared library without attaching current thread")); \
return; \
} \
JVMCITraceMark jtm("CompilerToVM::" #name); \
C2V_BLOCK(result_type, name, signature)
#define C2V_VMENTRY_(result_type, name, signature, result) \
JNIEXPORT result_type JNICALL c2v_ ## name signature { \
JavaThread* thread = get_current_thread(); \
if (thread == NULL) { \
env->ThrowNew(JNIJVMCI::InternalError::clazz(), \
err_msg("Cannot call into HotSpot from JVMCI shared library without attaching current thread")); \
return result; \
} \
JVMCITraceMark jtm("CompilerToVM::" #name); \
C2V_BLOCK(result_type, name, signature)
#define C2V_VMENTRY_NULL(result_type, name, signature) C2V_VMENTRY_(result_type, name, signature, NULL)
#define C2V_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'.
#define C2V_VMENTRY_PREFIX(result_type, name, signature) \
JNIEXPORT result_type JNICALL c2v_ ## name signature { \
JavaThread* thread = get_current_thread();
#define C2V_END }
#define JNI_THROW(caller, name, msg) do { \
jint __throw_res = env->ThrowNew(JNIJVMCI::name::clazz(), msg); \
if (__throw_res != JNI_OK) { \
tty->print_cr("Throwing " #name " in " caller " returned %d", __throw_res); \
} \
return; \
} while (0);
#define JNI_THROW_(caller, name, msg, result) do { \
jint __throw_res = env->ThrowNew(JNIJVMCI::name::clazz(), msg); \
if (__throw_res != JNI_OK) { \
tty->print_cr("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))
#define RETURN_BOXED_LONG(value) jvalue p; p.j = (jlong) (value); JVMCIObject box = JVMCIENV->create_box(T_LONG, &p, JVMCI_CHECK_NULL); return box.as_jobject();
#define RETURN_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);
}
const char* cstring = JVMCIENV->as_utf8_string(name);
const JVMFlag* flag = JVMFlag::find_declared_flag(cstring);
if (flag == NULL) {
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);
} else if (flag->is_ccstr()) {
JVMCIObject value = JVMCIENV->create_string(flag->get_ccstr(), JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(value);
} else if (flag->is_intx()) {
RETURN_BOXED_LONG(flag->get_intx());
} else if (flag->is_int()) {
RETURN_BOXED_LONG(flag->get_int());
} else if (flag->is_uint()) {
RETURN_BOXED_LONG(flag->get_uint());
} else if (flag->is_uint64_t()) {
RETURN_BOXED_LONG(flag->get_uint64_t());
} else if (flag->is_size_t()) {
RETURN_BOXED_LONG(flag->get_size_t());
} else if (flag->is_uintx()) {
RETURN_BOXED_LONG(flag->get_uintx());
} else if (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
C2V_VMENTRY_NULL(jobject, getObjectAtAddress, (JNIEnv* env, jobject c2vm, jlong oop_address))
requireInHotSpot("getObjectAtAddress", JVMCI_CHECK_NULL);
if (oop_address == 0) {
JVMCI_THROW_MSG_NULL(InternalError, "Handle must be non-zero");
}
oop obj = *((oopDesc**) oop_address);
if (obj != NULL) {
oopDesc::verify(obj);
}
return JNIHandles::make_local(THREAD, obj);
C2V_END
C2V_VMENTRY_NULL(jbyteArray, getBytecode, (JNIEnv* env, jobject, jobject jvmci_method))
methodHandle method(THREAD, JVMCIENV->asMethod(jvmci_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, jobject jvmci_method))
Method* method = JVMCIENV->asMethod(jvmci_method);
return method->exception_table_length();
C2V_END
C2V_VMENTRY_0(jlong, getExceptionTableStart, (JNIEnv* env, jobject, jobject jvmci_method))
Method* method = JVMCIENV->asMethod(jvmci_method);
if (method->exception_table_length() == 0) {
return 0L;
}
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 = NULL;
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_NULL(jobject, getResolvedJavaMethod, (JNIEnv* env, jobject, jobject base, jlong offset))
Method* method;
JVMCIObject base_object = JVMCIENV->wrap(base);
if (base_object.is_null()) {
method = *((Method**)(offset));
} else if (JVMCIENV->isa_HotSpotObjectConstantImpl(base_object)) {
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()));
}
} else if (JVMCIENV->isa_HotSpotResolvedJavaMethodImpl(base_object)) {
method = JVMCIENV->asMethod(base_object);
}
if (method == NULL) {
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, jobject object_handle))
ConstantPool* cp = NULL;
JVMCIObject object = JVMCIENV->wrap(object_handle);
if (object.is_null()) {
JVMCI_THROW_NULL(NullPointerException);
}
if (JVMCIENV->isa_HotSpotResolvedJavaMethodImpl(object)) {
cp = JVMCIENV->asMethod(object)->constMethod()->constants();
} else if (JVMCIENV->isa_HotSpotResolvedObjectTypeImpl(object)) {
cp = InstanceKlass::cast(JVMCIENV->asKlass(object))->constants();
} else {
JVMCI_THROW_MSG_NULL(IllegalArgumentException,
err_msg("Unexpected type: %s", JVMCIENV->klass_name(object)));
}
assert(cp != NULL, "npe");
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))
JVMCIKlassHandle klass(THREAD);
JVMCIObject base_object = JVMCIENV->wrap(base);
jlong base_address = 0;
if (base_object.is_non_null() && offset == oopDesc::klass_offset_in_bytes()) {
// klass = JVMCIENV->unhandle(base_object)->klass();
if (JVMCIENV->isa_HotSpotObjectConstantImpl(base_object)) {
Handle base_oop = JVMCIENV->asConstant(base_object, JVMCI_CHECK_NULL);
klass = base_oop->klass();
} else {
assert(false, "What types are we actually expecting here?");
}
} else if (!compressed) {
if (base_object.is_non_null()) {
if (JVMCIENV->isa_HotSpotResolvedJavaMethodImpl(base_object)) {
base_address = (intptr_t) JVMCIENV->asMethod(base_object);
} else if (JVMCIENV->isa_HotSpotConstantPool(base_object)) {
base_address = (intptr_t) JVMCIENV->asConstantPool(base_object);
} else if (JVMCIENV->isa_HotSpotResolvedObjectTypeImpl(base_object)) {
base_address = (intptr_t) JVMCIENV->asKlass(base_object);
} else if (JVMCIENV->isa_HotSpotObjectConstantImpl(base_object)) {
Handle base_oop = JVMCIENV->asConstant(base_object, JVMCI_CHECK_NULL);
if (base_oop->is_a(vmClasses::Class_klass())) {
base_address = cast_from_oop<jlong>(base_oop());
}
}
if (base_address == 0) {
JVMCI_THROW_MSG_NULL(IllegalArgumentException,
err_msg("Unexpected arguments: %s " JLONG_FORMAT " %s", JVMCIENV->klass_name(base_object), offset, compressed ? "true" : "false"));
}
}
klass = *((Klass**) (intptr_t) (base_address + offset));
} else {
JVMCI_THROW_MSG_NULL(IllegalArgumentException,
err_msg("Unexpected arguments: %s " JLONG_FORMAT " %s",
base_object.is_non_null() ? JVMCIENV->klass_name(base_object) : "null",
offset, compressed ? "true" : "false"));
}
assert (klass == NULL || klass->is_klass(), "invalid read");
JVMCIObject result = JVMCIENV->get_jvmci_type(klass, JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(result);
}
C2V_VMENTRY_NULL(jobject, findUniqueConcreteMethod, (JNIEnv* env, jobject, jobject jvmci_type, jobject jvmci_method))
methodHandle method (THREAD, JVMCIENV->asMethod(jvmci_method));
Klass* holder = JVMCIENV->asKlass(jvmci_type);
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, jobject jvmci_type))
Klass* klass = JVMCIENV->asKlass(jvmci_type);
if (!klass->is_interface()) {
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
err_msg("Expected interface type, got %s", klass->external_name()));
}
InstanceKlass* iklass = InstanceKlass::cast(klass);
JVMCIKlassHandle handle(THREAD);
{
// Need Compile_lock around implementor()
MutexLocker locker(Compile_lock);
handle = 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, jobject jvmci_method))
Method* method = JVMCIENV->asMethod(jvmci_method);
return method->is_ignored_by_security_stack_walk();
C2V_END
C2V_VMENTRY_0(jboolean, isCompilable,(JNIEnv* env, jobject, jobject jvmci_method))
Method* method = JVMCIENV->asMethod(jvmci_method);
ConstantPool* cp = method->constMethod()->constants();
assert(cp != NULL, "npe");
// don't inline method when constant pool contains a CONSTANT_Dynamic
return !method->is_not_compilable(CompLevel_full_optimization) && !cp->has_dynamic_constant();
C2V_END
C2V_VMENTRY_0(jboolean, hasNeverInlineDirective,(JNIEnv* env, jobject, jobject jvmci_method))
methodHandle method (THREAD, JVMCIENV->asMethod(jvmci_method));
return !Inline || CompilerOracle::should_not_inline(method) || method->dont_inline();
C2V_END
C2V_VMENTRY_0(jboolean, shouldInlineMethod,(JNIEnv* env, jobject, jobject jvmci_method))
methodHandle method (THREAD, JVMCIENV->asMethod(jvmci_method));
return CompilerOracle::should_inline(method) || method->force_inline();
C2V_END
C2V_VMENTRY_NULL(jobject, lookupType, (JNIEnv* env, jobject, jstring jname, jclass accessing_class, jboolean resolve))
JVMCIObject name = JVMCIENV->wrap(jname);
const char* str = JVMCIENV->as_utf8_string(name);
TempNewSymbol class_name = SymbolTable::new_symbol(str);
if (class_name->utf8_length() <= 1) {
JVMCI_THROW_MSG_0(InternalError, err_msg("Primitive type %s should be handled in Java code", class_name->as_C_string()));
}
JVMCIKlassHandle resolved_klass(THREAD);
Klass* accessing_klass = NULL;
Handle class_loader;
Handle protection_domain;
if (accessing_class != NULL) {
accessing_klass = JVMCIENV->asKlass(accessing_class);
class_loader = Handle(THREAD, accessing_klass->class_loader());
protection_domain = Handle(THREAD, accessing_klass->protection_domain());
} else {
// Use the System class loader
class_loader = Handle(THREAD, SystemDictionary::java_system_loader());
JVMCIENV->runtime()->initialize(JVMCIENV);
}
if (resolve) {
resolved_klass = SystemDictionary::resolve_or_null(class_name, class_loader, protection_domain, CHECK_NULL);
if (resolved_klass == NULL) {
JVMCI_THROW_MSG_NULL(ClassNotFoundException, str);
}
} 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(strippedsym,
class_loader,
protection_domain);
} else if (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(strippedsym,
class_loader,
protection_domain);
if (!resolved_klass.is_null()) {
resolved_klass = resolved_klass->array_klass(ndim, CHECK_NULL);
}
} else {
resolved_klass = TypeArrayKlass::cast(Universe::typeArrayKlassObj(ss.type()))->array_klass(ndim, CHECK_NULL);
}
} else {
resolved_klass = SystemDictionary::find_instance_klass(class_name,
class_loader,
protection_domain);
}
}
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, jobject jvmci_type))
if (jvmci_type == NULL) {
JVMCI_THROW_0(NullPointerException);
}
JVMCIObject jvmci_type_object = JVMCIENV->wrap(jvmci_type);
JVMCIKlassHandle array_klass(THREAD);
if (JVMCIENV->isa_HotSpotResolvedPrimitiveType(jvmci_type_object)) {
BasicType type = JVMCIENV->kindToBasicType(JVMCIENV->get_HotSpotResolvedPrimitiveType_kind(jvmci_type_object), JVMCI_CHECK_0);
if (type == T_VOID) {
return NULL;
}
array_klass = Universe::typeArrayKlassObj(type);
if (array_klass == NULL) {
JVMCI_THROW_MSG_NULL(InternalError, err_msg("No array klass for primitive type %s", type2name(type)));
}
} else {
Klass* klass = JVMCIENV->asKlass(jvmci_type);
if (klass == NULL) {
JVMCI_THROW_0(NullPointerException);
}
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 == NULL) {
return NULL;
}
JVMCIKlassHandle klass(THREAD);
klass = java_lang_Class::as_Klass(JNIHandles::resolve(mirror));
if (klass == NULL) {
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_VMENTRY_NULL(jobject, resolvePossiblyCachedConstantInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
oop result = cp->resolve_possibly_cached_constant_at(index, CHECK_NULL);
return JVMCIENV->get_jobject(JVMCIENV->get_object_constant(result));
C2V_END
C2V_VMENTRY_0(jint, lookupNameAndTypeRefIndexInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
return cp->name_and_type_ref_index_at(index);
C2V_END
C2V_VMENTRY_NULL(jobject, lookupNameInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint which))
constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
JVMCIObject sym = JVMCIENV->create_string(cp->name_ref_at(which), JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(sym);
C2V_END
C2V_VMENTRY_NULL(jobject, lookupSignatureInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint which))
constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
JVMCIObject sym = JVMCIENV->create_string(cp->signature_ref_at(which), JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(sym);
C2V_END
C2V_VMENTRY_0(jint, lookupKlassRefIndexInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
return cp->klass_ref_index_at(index);
C2V_END
C2V_VMENTRY_NULL(jobject, resolveTypeInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
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, jobject jvmci_constant_pool, jint index, jbyte opcode))
constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
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 = NULL;
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);
} else if (tag.is_symbol()) {
symbol = cp->symbol_at(index);
} else {
assert(cp->tag_at(index).is_unresolved_klass(), "wrong tag");
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, jobject jvmci_constant_pool, jint index))
constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
oop appendix_oop = ConstantPool::appendix_at_if_loaded(cp, index);
return JVMCIENV->get_jobject(JVMCIENV->get_object_constant(appendix_oop));
C2V_END
C2V_VMENTRY_NULL(jobject, lookupMethodInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index, jbyte opcode))
constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
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));
JVMCIObject result = JVMCIENV->get_jvmci_method(method, JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(result);
C2V_END
C2V_VMENTRY_0(jint, constantPoolRemapInstructionOperandFromCache, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
return cp->remap_instruction_operand_from_cache(index);
C2V_END
C2V_VMENTRY_NULL(jobject, resolveFieldInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index, jobject jvmci_method, jbyte opcode, jintArray info_handle))
constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
Bytecodes::Code code = (Bytecodes::Code)(((int) opcode) & 0xFF);
fieldDescriptor fd;
methodHandle mh(THREAD, (jvmci_method != NULL) ? JVMCIENV->asMethod(jvmci_method) : NULL);
LinkInfo link_info(cp, index, mh, 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) != 3) {
JVMCI_ERROR_NULL("info must not be null and have a length of 3");
}
JVMCIENV->put_int_at(info, 0, fd.access_flags().as_int());
JVMCIENV->put_int_at(info, 1, fd.offset());
JVMCIENV->put_int_at(info, 2, fd.index());
JVMCIKlassHandle handle(THREAD, fd.field_holder());
JVMCIObject field_holder = JVMCIENV->get_jvmci_type(handle, JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(field_holder);
C2V_END
C2V_VMENTRY_0(jint, getVtableIndexForInterfaceMethod, (JNIEnv* env, jobject, jobject jvmci_type, jobject jvmci_method))
Klass* klass = JVMCIENV->asKlass(jvmci_type);
methodHandle method(THREAD, JVMCIENV->asMethod(jvmci_method));
if (klass->is_interface()) {
JVMCI_THROW_MSG_0(InternalError, err_msg("Interface %s should be handled in Java code", klass->external_name()));
}
if (!method->method_holder()->is_interface()) {
JVMCI_THROW_MSG_0(InternalError, err_msg("Method %s is not held by an interface, this case should be handled in Java code", method->name_and_sig_as_C_string()));
}
if (!klass->is_instance_klass()) {
JVMCI_THROW_MSG_0(InternalError, err_msg("Class %s must be instance klass", klass->external_name()));
}
if (!InstanceKlass::cast(klass)->is_linked()) {
JVMCI_THROW_MSG_0(InternalError, err_msg("Class %s must be linked", klass->external_name()));
}
return LinkResolver::vtable_index_of_interface_method(klass, method);
C2V_END
C2V_VMENTRY_NULL(jobject, resolveMethod, (JNIEnv* env, jobject, jobject receiver_jvmci_type, jobject jvmci_method, jobject caller_jvmci_type))
Klass* recv_klass = JVMCIENV->asKlass(receiver_jvmci_type);
Klass* caller_klass = JVMCIENV->asKlass(caller_jvmci_type);
methodHandle method(THREAD, JVMCIENV->asMethod(jvmci_method));
Klass* resolved = method->method_holder();
Symbol* h_name = method->name();
Symbol* h_signature = method->signature();
if (MethodHandles::is_signature_polymorphic_method(method())) {
// Signature polymorphic methods are already resolved, JVMCI just returns NULL in this case.
return NULL;
}
if (method->name() == vmSymbols::clone_name() &&
resolved == vmClasses::Object_klass() &&
recv_klass->is_array_klass()) {
// Resolution of the clone method on arrays always returns Object.clone even though that method
// has protected access. There's some trickery in the access checking to make this all work out
// so it's necessary to pass in the array class as the resolved class to properly trigger this.
// Otherwise it's impossible to resolve the array clone methods through JVMCI. See
// LinkResolver::check_method_accessability for the matching logic.
resolved = recv_klass;
}
LinkInfo link_info(resolved, h_name, h_signature, caller_klass);
Method* m = NULL;
// Only do exact lookup if receiver klass has been linked. Otherwise,
// the vtable has not been setup, and the LinkResolver will fail.
if (recv_klass->is_array_klass() ||
(InstanceKlass::cast(recv_klass)->is_linked() && !recv_klass->is_interface())) {
if (resolved->is_interface()) {
m = LinkResolver::resolve_interface_call_or_null(recv_klass, link_info);
} else {
m = LinkResolver::resolve_virtual_call_or_null(recv_klass, link_info);
}
}
if (m == NULL) {
// Return NULL if there was a problem with lookup (uninitialized class, etc.)
return NULL;
}
JVMCIObject result = JVMCIENV->get_jvmci_method(methodHandle(THREAD, m), JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(result);
C2V_END
C2V_VMENTRY_0(jboolean, hasFinalizableSubclass,(JNIEnv* env, jobject, jobject jvmci_type))
Klass* klass = JVMCIENV->asKlass(jvmci_type);
assert(klass != NULL, "method must not be called for primitive types");
return Dependencies::find_finalizable_subclass(klass) != NULL;
C2V_END
C2V_VMENTRY_NULL(jobject, getClassInitializer, (JNIEnv* env, jobject, jobject jvmci_type))
Klass* klass = JVMCIENV->asKlass(jvmci_type);
if (!klass->is_instance_klass()) {
return NULL;
}
InstanceKlass* iklass = InstanceKlass::cast(klass);
methodHandle clinit(THREAD, iklass->class_initializer());
JVMCIObject result = JVMCIENV->get_jvmci_method(clinit, JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(result);
C2V_END
C2V_VMENTRY_0(jlong, getMaxCallTargetOffset, (JNIEnv* env, jobject, jlong addr))
address target_addr = (address) addr;
if (target_addr != 0x0) {
int64_t off_low = (int64_t)target_addr - ((int64_t)CodeCache::low_bound() + sizeof(int));
int64_t off_high = (int64_t)target_addr - ((int64_t)CodeCache::high_bound() + sizeof(int));
return MAX2(ABS(off_low), ABS(off_high));
}
return -1;
C2V_END
C2V_VMENTRY(void, setNotInlinableOrCompilable,(JNIEnv* env, jobject, jobject jvmci_method))
methodHandle method(THREAD, JVMCIENV->asMethod(jvmci_method));
method->set_not_c1_compilable();
method->set_not_c2_compilable();
method->set_dont_inline(true);
C2V_END
C2V_VMENTRY_0(jint, installCode, (JNIEnv *env, jobject, jobject target, jobject compiled_code,
jobject installed_code, jlong failed_speculations_address, jbyteArray speculations_obj))
HandleMark hm(THREAD);
JNIHandleMark jni_hm(thread);
JVMCIObject target_handle = JVMCIENV->wrap(target);
JVMCIObject compiled_code_handle = JVMCIENV->wrap(compiled_code);
CodeBlob* cb = NULL;
JVMCIObject installed_code_handle = JVMCIENV->wrap(installed_code);
JVMCIPrimitiveArray speculations_handle = JVMCIENV->wrap(speculations_obj);
int speculations_len = JVMCIENV->get_length(speculations_handle);
char* speculations = NEW_RESOURCE_ARRAY(char, speculations_len);
JVMCIENV->copy_bytes_to(speculations_handle, (jbyte*) speculations, 0, speculations_len);
JVMCICompiler* compiler = JVMCICompiler::instance(true, CHECK_JNI_ERR);
TraceTime install_time("installCode", JVMCICompiler::codeInstallTimer(!thread->is_Compiler_thread()));
bool is_immutable_PIC = JVMCIENV->get_HotSpotCompiledCode_isImmutablePIC(compiled_code_handle) > 0;
CodeInstaller installer(JVMCIENV, is_immutable_PIC);
JVMCI::CodeInstallResult result = installer.install(compiler,
target_handle,
compiled_code_handle,
cb,
installed_code_handle,
(FailedSpeculation**)(address) failed_speculations_address,
speculations,
speculations_len,
JVMCI_CHECK_0);
if (PrintCodeCacheOnCompilation) {
stringStream s;
// Dump code cache into a buffer before locking the tty,
{
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
CodeCache::print_summary(&s, false);
}
ttyLocker ttyl;
tty->print_raw_cr(s.as_string());
}
if (result != JVMCI::ok) {
assert(cb == NULL, "should be");
} else {
if (installed_code_handle.is_non_null()) {
if (cb->is_nmethod()) {
assert(JVMCIENV->isa_HotSpotNmethod(installed_code_handle), "wrong type");
// Clear the link to an old nmethod first
JVMCIObject nmethod_mirror = installed_code_handle;
JVMCIENV->invalidate_nmethod_mirror(nmethod_mirror, JVMCI_CHECK_0);
} else {
assert(JVMCIENV->isa_InstalledCode(installed_code_handle), "wrong type");
}
// Initialize the link to the new code blob
JVMCIENV->initialize_installed_code(installed_code_handle, cb, JVMCI_CHECK_0);
}
}
return result;
C2V_END
C2V_VMENTRY_0(jint, getMetadata, (JNIEnv *env, jobject, jobject target, jobject compiled_code, jobject metadata))
#if INCLUDE_AOT
HandleMark hm(THREAD);
assert(JVMCIENV->is_hotspot(), "AOT code is executed only in HotSpot mode");
JVMCIObject target_handle = JVMCIENV->wrap(target);
JVMCIObject compiled_code_handle = JVMCIENV->wrap(compiled_code);
JVMCIObject metadata_handle = JVMCIENV->wrap(metadata);
CodeMetadata code_metadata;
CodeInstaller installer(JVMCIENV, true /* immutable PIC compilation */);
JVMCI::CodeInstallResult result = installer.gather_metadata(target_handle, compiled_code_handle, code_metadata, JVMCI_CHECK_0);
if (result != JVMCI::ok) {
return result;
}
if (code_metadata.get_nr_pc_desc() > 0) {
int size = sizeof(PcDesc) * code_metadata.get_nr_pc_desc();
JVMCIPrimitiveArray array = JVMCIENV->new_byteArray(size, JVMCI_CHECK_(JVMCI::cache_full));
JVMCIENV->copy_bytes_from((jbyte*) code_metadata.get_pc_desc(), array, 0, size);
HotSpotJVMCI::HotSpotMetaData::set_pcDescBytes(JVMCIENV, metadata_handle, array);
}
if (code_metadata.get_scopes_size() > 0) {
int size = code_metadata.get_scopes_size();
JVMCIPrimitiveArray array = JVMCIENV->new_byteArray(size, JVMCI_CHECK_(JVMCI::cache_full));
JVMCIENV->copy_bytes_from((jbyte*) code_metadata.get_scopes_desc(), array, 0, size);
HotSpotJVMCI::HotSpotMetaData::set_scopesDescBytes(JVMCIENV, metadata_handle, array);
}
RelocBuffer* reloc_buffer = code_metadata.get_reloc_buffer();
int size = (int) reloc_buffer->size();
JVMCIPrimitiveArray array = JVMCIENV->new_byteArray(size, JVMCI_CHECK_(JVMCI::cache_full));
JVMCIENV->copy_bytes_from((jbyte*) reloc_buffer->begin(), array, 0, size);
HotSpotJVMCI::HotSpotMetaData::set_relocBytes(JVMCIENV, metadata_handle, array);
const OopMapSet* oopMapSet = installer.oopMapSet();
{
ResourceMark mark;
ImmutableOopMapBuilder builder(oopMapSet);
int size = builder.heap_size();
JVMCIPrimitiveArray array = JVMCIENV->new_byteArray(size, JVMCI_CHECK_(JVMCI::cache_full));
builder.generate_into((address) HotSpotJVMCI::resolve(array)->byte_at_addr(0));
HotSpotJVMCI::HotSpotMetaData::set_oopMaps(JVMCIENV, metadata_handle, array);
}
AOTOopRecorder* recorder = code_metadata.get_oop_recorder();
int nr_meta_refs = recorder->nr_meta_refs();
JVMCIObjectArray metadataArray = JVMCIENV->new_Object_array(nr_meta_refs, JVMCI_CHECK_(JVMCI::cache_full));
for (int i = 0; i < nr_meta_refs; ++i) {
jobject element = recorder->meta_element(i);
if (element == NULL) {
return JVMCI::cache_full;
}
JVMCIENV->put_object_at(metadataArray, i, JVMCIENV->wrap(element));
}
HotSpotJVMCI::HotSpotMetaData::set_metadata(JVMCIENV, metadata_handle, metadataArray);
ExceptionHandlerTable* handler = code_metadata.get_exception_table();
int table_size = handler->size_in_bytes();
JVMCIPrimitiveArray exceptionArray = JVMCIENV->new_byteArray(table_size, JVMCI_CHECK_(JVMCI::cache_full));
if (table_size > 0) {
handler->copy_bytes_to((address) HotSpotJVMCI::resolve(exceptionArray)->byte_at_addr(0));
}
HotSpotJVMCI::HotSpotMetaData::set_exceptionBytes(JVMCIENV, metadata_handle, exceptionArray);
ImplicitExceptionTable* implicit = code_metadata.get_implicit_exception_table();
int implicit_table_size = implicit->size_in_bytes();
JVMCIPrimitiveArray implicitExceptionArray = JVMCIENV->new_byteArray(implicit_table_size, JVMCI_CHECK_(JVMCI::cache_full));
if (implicit_table_size > 0) {
implicit->copy_bytes_to((address) HotSpotJVMCI::resolve(implicitExceptionArray)->byte_at_addr(0), implicit_table_size);
}
HotSpotJVMCI::HotSpotMetaData::set_implicitExceptionBytes(JVMCIENV, metadata_handle, implicitExceptionArray);
return result;
#else
JVMCI_THROW_MSG_0(InternalError, "unimplemented");
#endif
C2V_END
C2V_VMENTRY(void, resetCompilationStatistics, (JNIEnv* env, jobject))
JVMCICompiler* compiler = JVMCICompiler::instance(true, CHECK);
CompilerStatistics* stats = compiler->stats();
stats->_standard.reset();
stats->_osr.reset();
C2V_END
C2V_VMENTRY_NULL(jobject, disassembleCodeBlob, (JNIEnv* env, jobject, jobject installedCode))
HandleMark hm(THREAD);
if (installedCode == NULL) {
JVMCI_THROW_MSG_NULL(NullPointerException, "installedCode is null");
}
JVMCIObject installedCodeObject = JVMCIENV->wrap(installedCode);
nmethodLocker locker;
CodeBlob* cb = JVMCIENV->get_code_blob(installedCodeObject, locker);
if (cb == NULL) {
return NULL;
}
// We don't want the stringStream buffer to resize during disassembly as it
// uses scoped resource memory. If a nested function called during disassembly uses
// a ResourceMark and the buffer expands within the scope of the mark,
// the buffer becomes garbage when that scope is exited. Experience shows that
// the disassembled code is typically about 10x the code size so a fixed buffer
// sized to 20x code size plus a fixed amount for header info should be sufficient.
int bufferSize = cb->code_size() * 20 + 1024;
char* buffer = NEW_RESOURCE_ARRAY(char, bufferSize);
stringStream st(buffer, bufferSize);
if (cb->is_nmethod()) {