This repository has been archived by the owner on Aug 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathsharedRuntime.cpp
3151 lines (2741 loc) · 121 KB
/
sharedRuntime.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) 1997, 2018, 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 "jvm.h"
#include "aot/aotLoader.hpp"
#include "code/compiledMethod.inline.hpp"
#include "classfile/stringTable.hpp"
#include "classfile/systemDictionary.hpp"
#include "classfile/vmSymbols.hpp"
#include "code/codeCache.hpp"
#include "code/compiledIC.hpp"
#include "code/scopeDesc.hpp"
#include "code/vtableStubs.hpp"
#include "compiler/abstractCompiler.hpp"
#include "compiler/compileBroker.hpp"
#include "compiler/disassembler.hpp"
#include "gc/shared/barrierSet.hpp"
#include "gc/shared/gcLocker.inline.hpp"
#include "interpreter/interpreter.hpp"
#include "interpreter/interpreterRuntime.hpp"
#include "jfr/jfrEvents.hpp"
#include "logging/log.hpp"
#include "memory/metaspaceShared.hpp"
#include "memory/resourceArea.hpp"
#include "memory/universe.hpp"
#include "oops/klass.hpp"
#include "oops/method.inline.hpp"
#include "oops/objArrayKlass.hpp"
#include "oops/oop.inline.hpp"
#include "prims/forte.hpp"
#include "prims/jvmtiExport.hpp"
#include "prims/methodHandles.hpp"
#include "prims/nativeLookup.hpp"
#include "runtime/arguments.hpp"
#include "runtime/atomic.hpp"
#include "runtime/biasedLocking.hpp"
#include "runtime/compilationPolicy.hpp"
#include "runtime/frame.inline.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/init.hpp"
#include "runtime/interfaceSupport.inline.hpp"
#include "runtime/java.hpp"
#include "runtime/javaCalls.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/stubRoutines.hpp"
#include "runtime/vframe.inline.hpp"
#include "runtime/vframeArray.hpp"
#include "utilities/copy.hpp"
#include "utilities/dtrace.hpp"
#include "utilities/events.hpp"
#include "utilities/hashtable.inline.hpp"
#include "utilities/macros.hpp"
#include "utilities/xmlstream.hpp"
#ifdef COMPILER1
#include "c1/c1_Runtime1.hpp"
#endif
// Shared stub locations
RuntimeStub* SharedRuntime::_wrong_method_blob;
RuntimeStub* SharedRuntime::_wrong_method_abstract_blob;
RuntimeStub* SharedRuntime::_ic_miss_blob;
RuntimeStub* SharedRuntime::_resolve_opt_virtual_call_blob;
RuntimeStub* SharedRuntime::_resolve_virtual_call_blob;
RuntimeStub* SharedRuntime::_resolve_static_call_blob;
address SharedRuntime::_resolve_static_call_entry;
DeoptimizationBlob* SharedRuntime::_deopt_blob;
SafepointBlob* SharedRuntime::_polling_page_vectors_safepoint_handler_blob;
SafepointBlob* SharedRuntime::_polling_page_safepoint_handler_blob;
SafepointBlob* SharedRuntime::_polling_page_return_handler_blob;
#ifdef COMPILER2
UncommonTrapBlob* SharedRuntime::_uncommon_trap_blob;
#endif // COMPILER2
//----------------------------generate_stubs-----------------------------------
void SharedRuntime::generate_stubs() {
_wrong_method_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::handle_wrong_method), "wrong_method_stub");
_wrong_method_abstract_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::handle_wrong_method_abstract), "wrong_method_abstract_stub");
_ic_miss_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::handle_wrong_method_ic_miss), "ic_miss_stub");
_resolve_opt_virtual_call_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::resolve_opt_virtual_call_C), "resolve_opt_virtual_call");
_resolve_virtual_call_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::resolve_virtual_call_C), "resolve_virtual_call");
_resolve_static_call_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::resolve_static_call_C), "resolve_static_call");
_resolve_static_call_entry = _resolve_static_call_blob->entry_point();
#if COMPILER2_OR_JVMCI
// Vectors are generated only by C2 and JVMCI.
bool support_wide = is_wide_vector(MaxVectorSize);
if (support_wide) {
_polling_page_vectors_safepoint_handler_blob = generate_handler_blob(CAST_FROM_FN_PTR(address, SafepointSynchronize::handle_polling_page_exception), POLL_AT_VECTOR_LOOP);
}
#endif // COMPILER2_OR_JVMCI
_polling_page_safepoint_handler_blob = generate_handler_blob(CAST_FROM_FN_PTR(address, SafepointSynchronize::handle_polling_page_exception), POLL_AT_LOOP);
_polling_page_return_handler_blob = generate_handler_blob(CAST_FROM_FN_PTR(address, SafepointSynchronize::handle_polling_page_exception), POLL_AT_RETURN);
generate_deopt_blob();
#ifdef COMPILER2
generate_uncommon_trap_blob();
#endif // COMPILER2
}
#include <math.h>
// Implementation of SharedRuntime
#ifndef PRODUCT
// For statistics
int SharedRuntime::_ic_miss_ctr = 0;
int SharedRuntime::_wrong_method_ctr = 0;
int SharedRuntime::_resolve_static_ctr = 0;
int SharedRuntime::_resolve_virtual_ctr = 0;
int SharedRuntime::_resolve_opt_virtual_ctr = 0;
int SharedRuntime::_implicit_null_throws = 0;
int SharedRuntime::_implicit_div0_throws = 0;
int SharedRuntime::_throw_null_ctr = 0;
int SharedRuntime::_nof_normal_calls = 0;
int SharedRuntime::_nof_optimized_calls = 0;
int SharedRuntime::_nof_inlined_calls = 0;
int SharedRuntime::_nof_megamorphic_calls = 0;
int SharedRuntime::_nof_static_calls = 0;
int SharedRuntime::_nof_inlined_static_calls = 0;
int SharedRuntime::_nof_interface_calls = 0;
int SharedRuntime::_nof_optimized_interface_calls = 0;
int SharedRuntime::_nof_inlined_interface_calls = 0;
int SharedRuntime::_nof_megamorphic_interface_calls = 0;
int SharedRuntime::_nof_removable_exceptions = 0;
int SharedRuntime::_new_instance_ctr=0;
int SharedRuntime::_new_array_ctr=0;
int SharedRuntime::_multi1_ctr=0;
int SharedRuntime::_multi2_ctr=0;
int SharedRuntime::_multi3_ctr=0;
int SharedRuntime::_multi4_ctr=0;
int SharedRuntime::_multi5_ctr=0;
int SharedRuntime::_mon_enter_stub_ctr=0;
int SharedRuntime::_mon_exit_stub_ctr=0;
int SharedRuntime::_mon_enter_ctr=0;
int SharedRuntime::_mon_exit_ctr=0;
int SharedRuntime::_partial_subtype_ctr=0;
int SharedRuntime::_jbyte_array_copy_ctr=0;
int SharedRuntime::_jshort_array_copy_ctr=0;
int SharedRuntime::_jint_array_copy_ctr=0;
int SharedRuntime::_jlong_array_copy_ctr=0;
int SharedRuntime::_oop_array_copy_ctr=0;
int SharedRuntime::_checkcast_array_copy_ctr=0;
int SharedRuntime::_unsafe_array_copy_ctr=0;
int SharedRuntime::_generic_array_copy_ctr=0;
int SharedRuntime::_slow_array_copy_ctr=0;
int SharedRuntime::_find_handler_ctr=0;
int SharedRuntime::_rethrow_ctr=0;
int SharedRuntime::_ICmiss_index = 0;
int SharedRuntime::_ICmiss_count[SharedRuntime::maxICmiss_count];
address SharedRuntime::_ICmiss_at[SharedRuntime::maxICmiss_count];
void SharedRuntime::trace_ic_miss(address at) {
for (int i = 0; i < _ICmiss_index; i++) {
if (_ICmiss_at[i] == at) {
_ICmiss_count[i]++;
return;
}
}
int index = _ICmiss_index++;
if (_ICmiss_index >= maxICmiss_count) _ICmiss_index = maxICmiss_count - 1;
_ICmiss_at[index] = at;
_ICmiss_count[index] = 1;
}
void SharedRuntime::print_ic_miss_histogram() {
if (ICMissHistogram) {
tty->print_cr("IC Miss Histogram:");
int tot_misses = 0;
for (int i = 0; i < _ICmiss_index; i++) {
tty->print_cr(" at: " INTPTR_FORMAT " nof: %d", p2i(_ICmiss_at[i]), _ICmiss_count[i]);
tot_misses += _ICmiss_count[i];
}
tty->print_cr("Total IC misses: %7d", tot_misses);
}
}
#endif // PRODUCT
JRT_LEAF(jlong, SharedRuntime::lmul(jlong y, jlong x))
return x * y;
JRT_END
JRT_LEAF(jlong, SharedRuntime::ldiv(jlong y, jlong x))
if (x == min_jlong && y == CONST64(-1)) {
return x;
} else {
return x / y;
}
JRT_END
JRT_LEAF(jlong, SharedRuntime::lrem(jlong y, jlong x))
if (x == min_jlong && y == CONST64(-1)) {
return 0;
} else {
return x % y;
}
JRT_END
const juint float_sign_mask = 0x7FFFFFFF;
const juint float_infinity = 0x7F800000;
const julong double_sign_mask = CONST64(0x7FFFFFFFFFFFFFFF);
const julong double_infinity = CONST64(0x7FF0000000000000);
JRT_LEAF(jfloat, SharedRuntime::frem(jfloat x, jfloat y))
#ifdef _WIN64
// 64-bit Windows on amd64 returns the wrong values for
// infinity operands.
union { jfloat f; juint i; } xbits, ybits;
xbits.f = x;
ybits.f = y;
// x Mod Infinity == x unless x is infinity
if (((xbits.i & float_sign_mask) != float_infinity) &&
((ybits.i & float_sign_mask) == float_infinity) ) {
return x;
}
return ((jfloat)fmod_winx64((double)x, (double)y));
#else
return ((jfloat)fmod((double)x,(double)y));
#endif
JRT_END
JRT_LEAF(jdouble, SharedRuntime::drem(jdouble x, jdouble y))
#ifdef _WIN64
union { jdouble d; julong l; } xbits, ybits;
xbits.d = x;
ybits.d = y;
// x Mod Infinity == x unless x is infinity
if (((xbits.l & double_sign_mask) != double_infinity) &&
((ybits.l & double_sign_mask) == double_infinity) ) {
return x;
}
return ((jdouble)fmod_winx64((double)x, (double)y));
#else
return ((jdouble)fmod((double)x,(double)y));
#endif
JRT_END
#ifdef __SOFTFP__
JRT_LEAF(jfloat, SharedRuntime::fadd(jfloat x, jfloat y))
return x + y;
JRT_END
JRT_LEAF(jfloat, SharedRuntime::fsub(jfloat x, jfloat y))
return x - y;
JRT_END
JRT_LEAF(jfloat, SharedRuntime::fmul(jfloat x, jfloat y))
return x * y;
JRT_END
JRT_LEAF(jfloat, SharedRuntime::fdiv(jfloat x, jfloat y))
return x / y;
JRT_END
JRT_LEAF(jdouble, SharedRuntime::dadd(jdouble x, jdouble y))
return x + y;
JRT_END
JRT_LEAF(jdouble, SharedRuntime::dsub(jdouble x, jdouble y))
return x - y;
JRT_END
JRT_LEAF(jdouble, SharedRuntime::dmul(jdouble x, jdouble y))
return x * y;
JRT_END
JRT_LEAF(jdouble, SharedRuntime::ddiv(jdouble x, jdouble y))
return x / y;
JRT_END
JRT_LEAF(jfloat, SharedRuntime::i2f(jint x))
return (jfloat)x;
JRT_END
JRT_LEAF(jdouble, SharedRuntime::i2d(jint x))
return (jdouble)x;
JRT_END
JRT_LEAF(jdouble, SharedRuntime::f2d(jfloat x))
return (jdouble)x;
JRT_END
JRT_LEAF(int, SharedRuntime::fcmpl(float x, float y))
return x>y ? 1 : (x==y ? 0 : -1); /* x<y or is_nan*/
JRT_END
JRT_LEAF(int, SharedRuntime::fcmpg(float x, float y))
return x<y ? -1 : (x==y ? 0 : 1); /* x>y or is_nan */
JRT_END
JRT_LEAF(int, SharedRuntime::dcmpl(double x, double y))
return x>y ? 1 : (x==y ? 0 : -1); /* x<y or is_nan */
JRT_END
JRT_LEAF(int, SharedRuntime::dcmpg(double x, double y))
return x<y ? -1 : (x==y ? 0 : 1); /* x>y or is_nan */
JRT_END
// Functions to return the opposite of the aeabi functions for nan.
JRT_LEAF(int, SharedRuntime::unordered_fcmplt(float x, float y))
return (x < y) ? 1 : ((g_isnan(x) || g_isnan(y)) ? 1 : 0);
JRT_END
JRT_LEAF(int, SharedRuntime::unordered_dcmplt(double x, double y))
return (x < y) ? 1 : ((g_isnan(x) || g_isnan(y)) ? 1 : 0);
JRT_END
JRT_LEAF(int, SharedRuntime::unordered_fcmple(float x, float y))
return (x <= y) ? 1 : ((g_isnan(x) || g_isnan(y)) ? 1 : 0);
JRT_END
JRT_LEAF(int, SharedRuntime::unordered_dcmple(double x, double y))
return (x <= y) ? 1 : ((g_isnan(x) || g_isnan(y)) ? 1 : 0);
JRT_END
JRT_LEAF(int, SharedRuntime::unordered_fcmpge(float x, float y))
return (x >= y) ? 1 : ((g_isnan(x) || g_isnan(y)) ? 1 : 0);
JRT_END
JRT_LEAF(int, SharedRuntime::unordered_dcmpge(double x, double y))
return (x >= y) ? 1 : ((g_isnan(x) || g_isnan(y)) ? 1 : 0);
JRT_END
JRT_LEAF(int, SharedRuntime::unordered_fcmpgt(float x, float y))
return (x > y) ? 1 : ((g_isnan(x) || g_isnan(y)) ? 1 : 0);
JRT_END
JRT_LEAF(int, SharedRuntime::unordered_dcmpgt(double x, double y))
return (x > y) ? 1 : ((g_isnan(x) || g_isnan(y)) ? 1 : 0);
JRT_END
// Intrinsics make gcc generate code for these.
float SharedRuntime::fneg(float f) {
return -f;
}
double SharedRuntime::dneg(double f) {
return -f;
}
#endif // __SOFTFP__
#if defined(__SOFTFP__) || defined(E500V2)
// Intrinsics make gcc generate code for these.
double SharedRuntime::dabs(double f) {
return (f <= (double)0.0) ? (double)0.0 - f : f;
}
#endif
#if defined(__SOFTFP__) || defined(PPC)
double SharedRuntime::dsqrt(double f) {
return sqrt(f);
}
#endif
JRT_LEAF(jint, SharedRuntime::f2i(jfloat x))
if (g_isnan(x))
return 0;
if (x >= (jfloat) max_jint)
return max_jint;
if (x <= (jfloat) min_jint)
return min_jint;
return (jint) x;
JRT_END
JRT_LEAF(jlong, SharedRuntime::f2l(jfloat x))
if (g_isnan(x))
return 0;
if (x >= (jfloat) max_jlong)
return max_jlong;
if (x <= (jfloat) min_jlong)
return min_jlong;
return (jlong) x;
JRT_END
JRT_LEAF(jint, SharedRuntime::d2i(jdouble x))
if (g_isnan(x))
return 0;
if (x >= (jdouble) max_jint)
return max_jint;
if (x <= (jdouble) min_jint)
return min_jint;
return (jint) x;
JRT_END
JRT_LEAF(jlong, SharedRuntime::d2l(jdouble x))
if (g_isnan(x))
return 0;
if (x >= (jdouble) max_jlong)
return max_jlong;
if (x <= (jdouble) min_jlong)
return min_jlong;
return (jlong) x;
JRT_END
JRT_LEAF(jfloat, SharedRuntime::d2f(jdouble x))
return (jfloat)x;
JRT_END
JRT_LEAF(jfloat, SharedRuntime::l2f(jlong x))
return (jfloat)x;
JRT_END
JRT_LEAF(jdouble, SharedRuntime::l2d(jlong x))
return (jdouble)x;
JRT_END
// Exception handling across interpreter/compiler boundaries
//
// exception_handler_for_return_address(...) returns the continuation address.
// The continuation address is the entry point of the exception handler of the
// previous frame depending on the return address.
address SharedRuntime::raw_exception_handler_for_return_address(JavaThread* thread, address return_address) {
assert(frame::verify_return_pc(return_address), "must be a return address: " INTPTR_FORMAT, p2i(return_address));
assert(thread->frames_to_pop_failed_realloc() == 0 || Interpreter::contains(return_address), "missed frames to pop?");
// Reset method handle flag.
thread->set_is_method_handle_return(false);
#if INCLUDE_JVMCI
// JVMCI's ExceptionHandlerStub expects the thread local exception PC to be clear
// and other exception handler continuations do not read it
thread->set_exception_pc(NULL);
#endif // INCLUDE_JVMCI
// The fastest case first
CodeBlob* blob = CodeCache::find_blob(return_address);
CompiledMethod* nm = (blob != NULL) ? blob->as_compiled_method_or_null() : NULL;
if (nm != NULL) {
// Set flag if return address is a method handle call site.
thread->set_is_method_handle_return(nm->is_method_handle_return(return_address));
// native nmethods don't have exception handlers
assert(!nm->is_native_method(), "no exception handler");
assert(nm->header_begin() != nm->exception_begin(), "no exception handler");
if (nm->is_deopt_pc(return_address)) {
// If we come here because of a stack overflow, the stack may be
// unguarded. Reguard the stack otherwise if we return to the
// deopt blob and the stack bang causes a stack overflow we
// crash.
bool guard_pages_enabled = thread->stack_guards_enabled();
if (!guard_pages_enabled) guard_pages_enabled = thread->reguard_stack();
if (thread->reserved_stack_activation() != thread->stack_base()) {
thread->set_reserved_stack_activation(thread->stack_base());
}
assert(guard_pages_enabled, "stack banging in deopt blob may cause crash");
return SharedRuntime::deopt_blob()->unpack_with_exception();
} else {
return nm->exception_begin();
}
}
// Entry code
if (StubRoutines::returns_to_call_stub(return_address)) {
return StubRoutines::catch_exception_entry();
}
// Interpreted code
if (Interpreter::contains(return_address)) {
return Interpreter::rethrow_exception_entry();
}
guarantee(blob == NULL || !blob->is_runtime_stub(), "caller should have skipped stub");
guarantee(!VtableStubs::contains(return_address), "NULL exceptions in vtables should have been handled already!");
#ifndef PRODUCT
{ ResourceMark rm;
tty->print_cr("No exception handler found for exception at " INTPTR_FORMAT " - potential problems:", p2i(return_address));
tty->print_cr("a) exception happened in (new?) code stubs/buffers that is not handled here");
tty->print_cr("b) other problem");
}
#endif // PRODUCT
ShouldNotReachHere();
return NULL;
}
JRT_LEAF(address, SharedRuntime::exception_handler_for_return_address(JavaThread* thread, address return_address))
return raw_exception_handler_for_return_address(thread, return_address);
JRT_END
address SharedRuntime::get_poll_stub(address pc) {
address stub;
// Look up the code blob
CodeBlob *cb = CodeCache::find_blob(pc);
// Should be an nmethod
guarantee(cb != NULL && cb->is_compiled(), "safepoint polling: pc must refer to an nmethod");
// Look up the relocation information
assert(((CompiledMethod*)cb)->is_at_poll_or_poll_return(pc),
"safepoint polling: type must be poll");
#ifdef ASSERT
if (!((NativeInstruction*)pc)->is_safepoint_poll()) {
tty->print_cr("bad pc: " PTR_FORMAT, p2i(pc));
Disassembler::decode(cb);
fatal("Only polling locations are used for safepoint");
}
#endif
bool at_poll_return = ((CompiledMethod*)cb)->is_at_poll_return(pc);
bool has_wide_vectors = ((CompiledMethod*)cb)->has_wide_vectors();
if (at_poll_return) {
assert(SharedRuntime::polling_page_return_handler_blob() != NULL,
"polling page return stub not created yet");
stub = SharedRuntime::polling_page_return_handler_blob()->entry_point();
} else if (has_wide_vectors) {
assert(SharedRuntime::polling_page_vectors_safepoint_handler_blob() != NULL,
"polling page vectors safepoint stub not created yet");
stub = SharedRuntime::polling_page_vectors_safepoint_handler_blob()->entry_point();
} else {
assert(SharedRuntime::polling_page_safepoint_handler_blob() != NULL,
"polling page safepoint stub not created yet");
stub = SharedRuntime::polling_page_safepoint_handler_blob()->entry_point();
}
log_debug(safepoint)("... found polling page %s exception at pc = "
INTPTR_FORMAT ", stub =" INTPTR_FORMAT,
at_poll_return ? "return" : "loop",
(intptr_t)pc, (intptr_t)stub);
return stub;
}
oop SharedRuntime::retrieve_receiver( Symbol* sig, frame caller ) {
assert(caller.is_interpreted_frame(), "");
int args_size = ArgumentSizeComputer(sig).size() + 1;
assert(args_size <= caller.interpreter_frame_expression_stack_size(), "receiver must be on interpreter stack");
oop result = cast_to_oop(*caller.interpreter_frame_tos_at(args_size - 1));
assert(Universe::heap()->is_in(result) && oopDesc::is_oop(result), "receiver must be an oop");
return result;
}
void SharedRuntime::throw_and_post_jvmti_exception(JavaThread *thread, Handle h_exception) {
if (JvmtiExport::can_post_on_exceptions()) {
vframeStream vfst(thread, true);
methodHandle method = methodHandle(thread, vfst.method());
address bcp = method()->bcp_from(vfst.bci());
JvmtiExport::post_exception_throw(thread, method(), bcp, h_exception());
}
Exceptions::_throw(thread, __FILE__, __LINE__, h_exception);
}
void SharedRuntime::throw_and_post_jvmti_exception(JavaThread *thread, Symbol* name, const char *message) {
Handle h_exception = Exceptions::new_exception(thread, name, message);
throw_and_post_jvmti_exception(thread, h_exception);
}
// The interpreter code to call this tracing function is only
// called/generated when UL is on for redefine, class and has the right level
// and tags. Since obsolete methods are never compiled, we don't have
// to modify the compilers to generate calls to this function.
//
JRT_LEAF(int, SharedRuntime::rc_trace_method_entry(
JavaThread* thread, Method* method))
if (method->is_obsolete()) {
// We are calling an obsolete method, but this is not necessarily
// an error. Our method could have been redefined just after we
// fetched the Method* from the constant pool.
ResourceMark rm;
log_trace(redefine, class, obsolete)("calling obsolete method '%s'", method->name_and_sig_as_C_string());
}
return 0;
JRT_END
// ret_pc points into caller; we are returning caller's exception handler
// for given exception
address SharedRuntime::compute_compiled_exc_handler(CompiledMethod* cm, address ret_pc, Handle& exception,
bool force_unwind, bool top_frame_only, bool& recursive_exception_occurred) {
assert(cm != NULL, "must exist");
ResourceMark rm;
#if INCLUDE_JVMCI
if (cm->is_compiled_by_jvmci()) {
// lookup exception handler for this pc
int catch_pco = ret_pc - cm->code_begin();
ExceptionHandlerTable table(cm);
HandlerTableEntry *t = table.entry_for(catch_pco, -1, 0);
if (t != NULL) {
return cm->code_begin() + t->pco();
} else {
return Deoptimization::deoptimize_for_missing_exception_handler(cm);
}
}
#endif // INCLUDE_JVMCI
nmethod* nm = cm->as_nmethod();
ScopeDesc* sd = nm->scope_desc_at(ret_pc);
// determine handler bci, if any
EXCEPTION_MARK;
int handler_bci = -1;
int scope_depth = 0;
if (!force_unwind) {
int bci = sd->bci();
bool recursive_exception = false;
do {
bool skip_scope_increment = false;
// exception handler lookup
Klass* ek = exception->klass();
methodHandle mh(THREAD, sd->method());
handler_bci = Method::fast_exception_handler_bci_for(mh, ek, bci, THREAD);
if (HAS_PENDING_EXCEPTION) {
recursive_exception = true;
// We threw an exception while trying to find the exception handler.
// Transfer the new exception to the exception handle which will
// be set into thread local storage, and do another lookup for an
// exception handler for this exception, this time starting at the
// BCI of the exception handler which caused the exception to be
// thrown (bugs 4307310 and 4546590). Set "exception" reference
// argument to ensure that the correct exception is thrown (4870175).
recursive_exception_occurred = true;
exception = Handle(THREAD, PENDING_EXCEPTION);
CLEAR_PENDING_EXCEPTION;
if (handler_bci >= 0) {
bci = handler_bci;
handler_bci = -1;
skip_scope_increment = true;
}
}
else {
recursive_exception = false;
}
if (!top_frame_only && handler_bci < 0 && !skip_scope_increment) {
sd = sd->sender();
if (sd != NULL) {
bci = sd->bci();
}
++scope_depth;
}
} while (recursive_exception || (!top_frame_only && handler_bci < 0 && sd != NULL));
}
// found handling method => lookup exception handler
int catch_pco = ret_pc - nm->code_begin();
ExceptionHandlerTable table(nm);
HandlerTableEntry *t = table.entry_for(catch_pco, handler_bci, scope_depth);
if (t == NULL && (nm->is_compiled_by_c1() || handler_bci != -1)) {
// Allow abbreviated catch tables. The idea is to allow a method
// to materialize its exceptions without committing to the exact
// routing of exceptions. In particular this is needed for adding
// a synthetic handler to unlock monitors when inlining
// synchronized methods since the unlock path isn't represented in
// the bytecodes.
t = table.entry_for(catch_pco, -1, 0);
}
#ifdef COMPILER1
if (t == NULL && nm->is_compiled_by_c1()) {
assert(nm->unwind_handler_begin() != NULL, "");
return nm->unwind_handler_begin();
}
#endif
if (t == NULL) {
ttyLocker ttyl;
tty->print_cr("MISSING EXCEPTION HANDLER for pc " INTPTR_FORMAT " and handler bci %d", p2i(ret_pc), handler_bci);
tty->print_cr(" Exception:");
exception->print();
tty->cr();
tty->print_cr(" Compiled exception table :");
table.print();
nm->print_code();
guarantee(false, "missing exception handler");
return NULL;
}
return nm->code_begin() + t->pco();
}
JRT_ENTRY(void, SharedRuntime::throw_AbstractMethodError(JavaThread* thread))
// These errors occur only at call sites
throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_AbstractMethodError());
JRT_END
JRT_ENTRY(void, SharedRuntime::throw_IncompatibleClassChangeError(JavaThread* thread))
// These errors occur only at call sites
throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_IncompatibleClassChangeError(), "vtable stub");
JRT_END
JRT_ENTRY(void, SharedRuntime::throw_ArithmeticException(JavaThread* thread))
throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_ArithmeticException(), "/ by zero");
JRT_END
JRT_ENTRY(void, SharedRuntime::throw_NullPointerException(JavaThread* thread))
throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_NullPointerException());
JRT_END
JRT_ENTRY(void, SharedRuntime::throw_NullPointerException_at_call(JavaThread* thread))
// This entry point is effectively only used for NullPointerExceptions which occur at inline
// cache sites (when the callee activation is not yet set up) so we are at a call site
throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_NullPointerException());
JRT_END
JRT_ENTRY(void, SharedRuntime::throw_StackOverflowError(JavaThread* thread))
throw_StackOverflowError_common(thread, false);
JRT_END
JRT_ENTRY(void, SharedRuntime::throw_delayed_StackOverflowError(JavaThread* thread))
throw_StackOverflowError_common(thread, true);
JRT_END
void SharedRuntime::throw_StackOverflowError_common(JavaThread* thread, bool delayed) {
// We avoid using the normal exception construction in this case because
// it performs an upcall to Java, and we're already out of stack space.
Thread* THREAD = thread;
Klass* k = SystemDictionary::StackOverflowError_klass();
oop exception_oop = InstanceKlass::cast(k)->allocate_instance(CHECK);
if (delayed) {
java_lang_Throwable::set_message(exception_oop,
Universe::delayed_stack_overflow_error_message());
}
Handle exception (thread, exception_oop);
if (StackTraceInThrowable) {
java_lang_Throwable::fill_in_stack_trace(exception);
}
// Increment counter for hs_err file reporting
Atomic::inc(&Exceptions::_stack_overflow_errors);
throw_and_post_jvmti_exception(thread, exception);
}
#if INCLUDE_JVMCI
address SharedRuntime::deoptimize_for_implicit_exception(JavaThread* thread, address pc, CompiledMethod* nm, int deopt_reason) {
assert(deopt_reason > Deoptimization::Reason_none && deopt_reason < Deoptimization::Reason_LIMIT, "invalid deopt reason");
thread->set_jvmci_implicit_exception_pc(pc);
thread->set_pending_deoptimization(Deoptimization::make_trap_request((Deoptimization::DeoptReason)deopt_reason, Deoptimization::Action_reinterpret));
return (SharedRuntime::deopt_blob()->implicit_exception_uncommon_trap());
}
#endif // INCLUDE_JVMCI
address SharedRuntime::continuation_for_implicit_exception(JavaThread* thread,
address pc,
SharedRuntime::ImplicitExceptionKind exception_kind)
{
address target_pc = NULL;
if (Interpreter::contains(pc)) {
#ifdef CC_INTERP
// C++ interpreter doesn't throw implicit exceptions
ShouldNotReachHere();
#else
switch (exception_kind) {
case IMPLICIT_NULL: return Interpreter::throw_NullPointerException_entry();
case IMPLICIT_DIVIDE_BY_ZERO: return Interpreter::throw_ArithmeticException_entry();
case STACK_OVERFLOW: return Interpreter::throw_StackOverflowError_entry();
default: ShouldNotReachHere();
}
#endif // !CC_INTERP
} else {
switch (exception_kind) {
case STACK_OVERFLOW: {
// Stack overflow only occurs upon frame setup; the callee is
// going to be unwound. Dispatch to a shared runtime stub
// which will cause the StackOverflowError to be fabricated
// and processed.
// Stack overflow should never occur during deoptimization:
// the compiled method bangs the stack by as much as the
// interpreter would need in case of a deoptimization. The
// deoptimization blob and uncommon trap blob bang the stack
// in a debug VM to verify the correctness of the compiled
// method stack banging.
assert(thread->deopt_mark() == NULL, "no stack overflow from deopt blob/uncommon trap");
Events::log_exception(thread, "StackOverflowError at " INTPTR_FORMAT, p2i(pc));
return StubRoutines::throw_StackOverflowError_entry();
}
case IMPLICIT_NULL: {
if (VtableStubs::contains(pc)) {
// We haven't yet entered the callee frame. Fabricate an
// exception and begin dispatching it in the caller. Since
// the caller was at a call site, it's safe to destroy all
// caller-saved registers, as these entry points do.
VtableStub* vt_stub = VtableStubs::stub_containing(pc);
// If vt_stub is NULL, then return NULL to signal handler to report the SEGV error.
if (vt_stub == NULL) return NULL;
if (vt_stub->is_abstract_method_error(pc)) {
assert(!vt_stub->is_vtable_stub(), "should never see AbstractMethodErrors from vtable-type VtableStubs");
Events::log_exception(thread, "AbstractMethodError at " INTPTR_FORMAT, p2i(pc));
// Instead of throwing the abstract method error here directly, we re-resolve
// and will throw the AbstractMethodError during resolve. As a result, we'll
// get a more detailed error message.
return SharedRuntime::get_handle_wrong_method_stub();
} else {
Events::log_exception(thread, "NullPointerException at vtable entry " INTPTR_FORMAT, p2i(pc));
// Assert that the signal comes from the expected location in stub code.
assert(vt_stub->is_null_pointer_exception(pc),
"obtained signal from unexpected location in stub code");
return StubRoutines::throw_NullPointerException_at_call_entry();
}
} else {
CodeBlob* cb = CodeCache::find_blob(pc);
// If code blob is NULL, then return NULL to signal handler to report the SEGV error.
if (cb == NULL) return NULL;
// Exception happened in CodeCache. Must be either:
// 1. Inline-cache check in C2I handler blob,
// 2. Inline-cache check in nmethod, or
// 3. Implicit null exception in nmethod
if (!cb->is_compiled()) {
bool is_in_blob = cb->is_adapter_blob() || cb->is_method_handles_adapter_blob();
if (!is_in_blob) {
// Allow normal crash reporting to handle this
return NULL;
}
Events::log_exception(thread, "NullPointerException in code blob at " INTPTR_FORMAT, p2i(pc));
// There is no handler here, so we will simply unwind.
return StubRoutines::throw_NullPointerException_at_call_entry();
}
// Otherwise, it's a compiled method. Consult its exception handlers.
CompiledMethod* cm = (CompiledMethod*)cb;
if (cm->inlinecache_check_contains(pc)) {
// exception happened inside inline-cache check code
// => the nmethod is not yet active (i.e., the frame
// is not set up yet) => use return address pushed by
// caller => don't push another return address
Events::log_exception(thread, "NullPointerException in IC check " INTPTR_FORMAT, p2i(pc));
return StubRoutines::throw_NullPointerException_at_call_entry();
}
if (cm->method()->is_method_handle_intrinsic()) {
// exception happened inside MH dispatch code, similar to a vtable stub
Events::log_exception(thread, "NullPointerException in MH adapter " INTPTR_FORMAT, p2i(pc));
return StubRoutines::throw_NullPointerException_at_call_entry();
}
#ifndef PRODUCT
_implicit_null_throws++;
#endif
#if INCLUDE_JVMCI
if (cm->is_compiled_by_jvmci() && cm->pc_desc_at(pc) != NULL) {
// If there's no PcDesc then we'll die way down inside of
// deopt instead of just getting normal error reporting,
// so only go there if it will succeed.
return deoptimize_for_implicit_exception(thread, pc, cm, Deoptimization::Reason_null_check);
} else {
#endif // INCLUDE_JVMCI
assert (cm->is_nmethod(), "Expect nmethod");
target_pc = ((nmethod*)cm)->continuation_for_implicit_exception(pc);
#if INCLUDE_JVMCI
}
#endif // INCLUDE_JVMCI
// If there's an unexpected fault, target_pc might be NULL,
// in which case we want to fall through into the normal
// error handling code.
}
break; // fall through
}
case IMPLICIT_DIVIDE_BY_ZERO: {
CompiledMethod* cm = CodeCache::find_compiled(pc);
guarantee(cm != NULL, "must have containing compiled method for implicit division-by-zero exceptions");
#ifndef PRODUCT
_implicit_div0_throws++;
#endif
#if INCLUDE_JVMCI
if (cm->is_compiled_by_jvmci() && cm->pc_desc_at(pc) != NULL) {
return deoptimize_for_implicit_exception(thread, pc, cm, Deoptimization::Reason_div0_check);
} else {
#endif // INCLUDE_JVMCI
target_pc = cm->continuation_for_implicit_exception(pc);
#if INCLUDE_JVMCI
}
#endif // INCLUDE_JVMCI
// If there's an unexpected fault, target_pc might be NULL,
// in which case we want to fall through into the normal
// error handling code.
break; // fall through
}
default: ShouldNotReachHere();
}
assert(exception_kind == IMPLICIT_NULL || exception_kind == IMPLICIT_DIVIDE_BY_ZERO, "wrong implicit exception kind");
if (exception_kind == IMPLICIT_NULL) {
#ifndef PRODUCT
// for AbortVMOnException flag
Exceptions::debug_check_abort("java.lang.NullPointerException");
#endif //PRODUCT
Events::log_exception(thread, "Implicit null exception at " INTPTR_FORMAT " to " INTPTR_FORMAT, p2i(pc), p2i(target_pc));
} else {
#ifndef PRODUCT
// for AbortVMOnException flag
Exceptions::debug_check_abort("java.lang.ArithmeticException");
#endif //PRODUCT
Events::log_exception(thread, "Implicit division by zero exception at " INTPTR_FORMAT " to " INTPTR_FORMAT, p2i(pc), p2i(target_pc));
}
return target_pc;
}
ShouldNotReachHere();
return NULL;
}
/**
* Throws an java/lang/UnsatisfiedLinkError. The address of this method is
* installed in the native function entry of all native Java methods before
* they get linked to their actual native methods.
*
* \note
* This method actually never gets called! The reason is because
* the interpreter's native entries call NativeLookup::lookup() which
* throws the exception when the lookup fails. The exception is then
* caught and forwarded on the return from NativeLookup::lookup() call
* before the call to the native function. This might change in the future.
*/
JNI_ENTRY(void*, throw_unsatisfied_link_error(JNIEnv* env, ...))
{
// We return a bad value here to make sure that the exception is
// forwarded before we look at the return value.
THROW_(vmSymbols::java_lang_UnsatisfiedLinkError(), (void*)badAddress);
}
JNI_END
address SharedRuntime::native_method_throw_unsatisfied_link_error_entry() {
return CAST_FROM_FN_PTR(address, &throw_unsatisfied_link_error);
}
JRT_ENTRY_NO_ASYNC(void, SharedRuntime::register_finalizer(JavaThread* thread, oopDesc* obj))
#if INCLUDE_JVMCI
if (!obj->klass()->has_finalizer()) {
return;
}
#endif // INCLUDE_JVMCI
assert(oopDesc::is_oop(obj), "must be a valid oop");
assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
JRT_END
jlong SharedRuntime::get_java_tid(Thread* thread) {
if (thread != NULL) {
if (thread->is_Java_thread()) {
oop obj = ((JavaThread*)thread)->threadObj();
return (obj == NULL) ? 0 : java_lang_Thread::thread_id(obj);
}
}
return 0;
}
/**
* This function ought to be a void function, but cannot be because
* it gets turned into a tail-call on sparc, which runs into dtrace bug
* 6254741. Once that is fixed we can remove the dummy return value.
*/
int SharedRuntime::dtrace_object_alloc(oopDesc* o, int size) {
return dtrace_object_alloc_base(Thread::current(), o, size);
}