-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Expand file tree
/
Copy pathframe.cpp
More file actions
1714 lines (1524 loc) · 61.2 KB
/
frame.cpp
File metadata and controls
1714 lines (1524 loc) · 61.2 KB
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, 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/moduleEntry.hpp"
#include "code/codeCache.hpp"
#include "code/scopeDesc.hpp"
#include "code/vmreg.inline.hpp"
#include "compiler/abstractCompiler.hpp"
#include "compiler/disassembler.hpp"
#include "compiler/oopMap.hpp"
#include "gc/shared/collectedHeap.inline.hpp"
#include "interpreter/interpreter.hpp"
#include "interpreter/oopMapCache.hpp"
#include "logging/log.hpp"
#include "memory/resourceArea.hpp"
#include "memory/universe.hpp"
#include "oops/markWord.hpp"
#include "oops/method.inline.hpp"
#include "oops/methodData.hpp"
#include "oops/oop.inline.hpp"
#include "oops/stackChunkOop.inline.hpp"
#include "oops/verifyOopClosure.hpp"
#include "prims/methodHandles.hpp"
#include "runtime/continuation.hpp"
#include "runtime/continuationEntry.inline.hpp"
#include "runtime/frame.inline.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/javaCalls.hpp"
#include "runtime/javaThread.hpp"
#include "runtime/monitorChunk.hpp"
#include "runtime/os.hpp"
#include "runtime/safefetch.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/signature.hpp"
#include "runtime/stackValue.hpp"
#include "runtime/stubCodeGenerator.hpp"
#include "runtime/stubRoutines.hpp"
#include "utilities/debug.hpp"
#include "utilities/decoder.hpp"
#include "utilities/formatBuffer.hpp"
RegisterMap::RegisterMap(JavaThread *thread, UpdateMap update_map, ProcessFrames process_frames, WalkContinuation walk_cont) {
_thread = thread;
_update_map = update_map == UpdateMap::include;
_process_frames = process_frames == ProcessFrames::include;
_walk_cont = walk_cont == WalkContinuation::include;
clear();
DEBUG_ONLY (_update_for_id = nullptr;)
NOT_PRODUCT(_skip_missing = false;)
NOT_PRODUCT(_async = false;)
if (walk_cont == WalkContinuation::include && thread != nullptr && thread->last_continuation() != nullptr) {
_chunk = stackChunkHandle(Thread::current()->handle_area()->allocate_null_handle(), true /* dummy */);
}
_chunk_index = -1;
#ifndef PRODUCT
for (int i = 0; i < reg_count ; i++ ) _location[i] = nullptr;
#endif /* PRODUCT */
}
RegisterMap::RegisterMap(oop continuation, UpdateMap update_map) {
_thread = nullptr;
_update_map = update_map == UpdateMap::include;
_process_frames = false;
_walk_cont = true;
clear();
DEBUG_ONLY (_update_for_id = nullptr;)
NOT_PRODUCT(_skip_missing = false;)
NOT_PRODUCT(_async = false;)
_chunk = stackChunkHandle(Thread::current()->handle_area()->allocate_null_handle(), true /* dummy */);
_chunk_index = -1;
#ifndef PRODUCT
for (int i = 0; i < reg_count ; i++ ) _location[i] = nullptr;
#endif /* PRODUCT */
}
RegisterMap::RegisterMap(const RegisterMap* map) {
assert(map != this, "bad initialization parameter");
assert(map != nullptr, "RegisterMap must be present");
_thread = map->thread();
_update_map = map->update_map();
_process_frames = map->process_frames();
_walk_cont = map->_walk_cont;
_include_argument_oops = map->include_argument_oops();
DEBUG_ONLY (_update_for_id = map->_update_for_id;)
NOT_PRODUCT(_skip_missing = map->_skip_missing;)
NOT_PRODUCT(_async = map->_async;)
// only the original RegisterMap's handle lives long enough for StackWalker; this is bound to cause trouble with nested continuations.
_chunk = map->_chunk;
_chunk_index = map->_chunk_index;
pd_initialize_from(map);
if (update_map()) {
for(int i = 0; i < location_valid_size; i++) {
LocationValidType bits = map->_location_valid[i];
_location_valid[i] = bits;
// for whichever bits are set, pull in the corresponding map->_location
int j = i*location_valid_type_size;
while (bits != 0) {
if ((bits & 1) != 0) {
assert(0 <= j && j < reg_count, "range check");
_location[j] = map->_location[j];
}
bits >>= 1;
j += 1;
}
}
}
}
oop RegisterMap::cont() const {
return _chunk() != nullptr ? _chunk()->cont() : (oop)nullptr;
}
void RegisterMap::set_stack_chunk(stackChunkOop chunk) {
assert(chunk == nullptr || _walk_cont, "");
assert(chunk == nullptr || _chunk.not_null(), "");
if (_chunk.is_null()) return;
log_trace(continuations)("set_stack_chunk: " INTPTR_FORMAT " this: " INTPTR_FORMAT, p2i((oopDesc*)chunk), p2i(this));
_chunk.replace(chunk); // reuse handle. see comment above in the constructor
if (chunk == nullptr) {
_chunk_index = -1;
} else {
_chunk_index++;
}
}
void RegisterMap::clear() {
set_include_argument_oops(true);
if (update_map()) {
for(int i = 0; i < location_valid_size; i++) {
_location_valid[i] = 0;
}
pd_clear();
} else {
pd_initialize();
}
}
#ifndef PRODUCT
VMReg RegisterMap::find_register_spilled_here(void* p, intptr_t* sp) {
for(int i = 0; i < RegisterMap::reg_count; i++) {
VMReg r = VMRegImpl::as_VMReg(i);
if (p == location(r, sp)) return r;
}
return nullptr;
}
void RegisterMap::print_on(outputStream* st) const {
st->print_cr("Register map");
for(int i = 0; i < reg_count; i++) {
VMReg r = VMRegImpl::as_VMReg(i);
intptr_t* src = (intptr_t*) location(r, nullptr);
if (src != nullptr) {
r->print_on(st);
st->print(" [" INTPTR_FORMAT "] = ", p2i(src));
if (((uintptr_t)src & (sizeof(*src)-1)) != 0) {
st->print_cr("<misaligned>");
} else {
st->print_cr(INTPTR_FORMAT, *src);
}
}
}
}
void RegisterMap::print() const {
print_on(tty);
}
#endif
// This returns the pc that if you were in the debugger you'd see. Not
// the idealized value in the frame object. This undoes the magic conversion
// that happens for deoptimized frames. In addition it makes the value the
// hardware would want to see in the native frame. The only user (at this point)
// is deoptimization. It likely no one else should ever use it.
address frame::raw_pc() const {
if (is_deoptimized_frame()) {
nmethod* nm = cb()->as_nmethod_or_null();
assert(nm != nullptr, "only nmethod is expected here");
return nm->deopt_handler_entry() - pc_return_offset;
} else {
return (pc() - pc_return_offset);
}
}
// Change the pc in a frame object. This does not change the actual pc in
// actual frame. To do that use patch_pc.
//
void frame::set_pc(address newpc) {
#ifdef ASSERT
if (_cb != nullptr && _cb->is_nmethod()) {
assert(!((nmethod*)_cb)->is_deopt_pc(_pc), "invariant violation");
}
#endif // ASSERT
// Unsafe to use the is_deoptimized tester after changing pc
_deopt_state = unknown;
_pc = newpc;
_cb = CodeCache::find_blob(_pc);
}
// This is optimized for intra-blob pc adjustments only.
void frame::adjust_pc(address newpc) {
assert(_cb != nullptr, "invariant");
assert(_cb == CodeCache::find_blob(newpc), "invariant");
// Unsafe to use the is_deoptimized tester after changing pc
_deopt_state = unknown;
_pc = newpc;
}
// type testers
bool frame::is_ignored_frame() const {
return false; // FIXME: some LambdaForm frames should be ignored
}
bool frame::is_native_frame() const {
return (_cb != nullptr &&
_cb->is_nmethod() &&
((nmethod*)_cb)->is_native_method());
}
bool frame::is_java_frame() const {
if (is_interpreted_frame()) return true;
if (is_compiled_frame()) return true;
return false;
}
bool frame::is_runtime_frame() const {
return (_cb != nullptr && _cb->is_runtime_stub());
}
bool frame::is_safepoint_blob_frame() const {
return (_cb != nullptr && _cb->is_safepoint_stub());
}
// testers
bool frame::is_first_java_frame() const {
RegisterMap map(JavaThread::current(),
RegisterMap::UpdateMap::skip,
RegisterMap::ProcessFrames::include,
RegisterMap::WalkContinuation::skip); // No update
frame s;
for (s = sender(&map); !(s.is_java_frame() || s.is_first_frame()); s = s.sender(&map));
return s.is_first_frame();
}
bool frame::is_first_vthread_frame(JavaThread* thread) const {
return Continuation::is_continuation_enterSpecial(*this)
&& Continuation::get_continuation_entry_for_entry_frame(thread, *this)->is_virtual_thread();
}
bool frame::entry_frame_is_first() const {
return entry_frame_call_wrapper()->is_first_frame();
}
JavaCallWrapper* frame::entry_frame_call_wrapper_if_safe(JavaThread* thread) const {
JavaCallWrapper** jcw = entry_frame_call_wrapper_addr();
address addr = (address) jcw;
// addr must be within the usable part of the stack
if (thread->is_in_usable_stack(addr)) {
return *jcw;
}
return nullptr;
}
bool frame::is_entry_frame_valid(JavaThread* thread) const {
// Validate the JavaCallWrapper an entry frame must have
address jcw = (address)entry_frame_call_wrapper();
if (!thread->is_in_stack_range_excl(jcw, (address)fp())) {
return false;
}
// Validate sp saved in the java frame anchor
JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();
return (jfa->last_Java_sp() > sp());
}
Method* frame::safe_interpreter_frame_method() const {
Method** m_addr = interpreter_frame_method_addr();
if (m_addr == nullptr) {
return nullptr;
}
return (Method*) SafeFetchN((intptr_t*) m_addr, 0);
}
bool frame::should_be_deoptimized() const {
if (_deopt_state == is_deoptimized ||
!is_compiled_frame() ) return false;
assert(_cb != nullptr && _cb->is_nmethod(), "must be an nmethod");
nmethod* nm = _cb->as_nmethod();
LogTarget(Debug, dependencies) lt;
if (lt.is_enabled()) {
LogStream ls(<);
ls.print("checking (%s) ", nm->is_marked_for_deoptimization() ? "true" : "false");
nm->print_value_on(&ls);
ls.cr();
}
if( !nm->is_marked_for_deoptimization() )
return false;
// If at the return point, then the frame has already been popped, and
// only the return needs to be executed. Don't deoptimize here.
return !nm->is_at_poll_return(pc());
}
bool frame::can_be_deoptimized() const {
if (!is_compiled_frame()) return false;
nmethod* nm = _cb->as_nmethod();
if(!nm->can_be_deoptimized())
return false;
return !nm->is_at_poll_return(pc());
}
void frame::deoptimize(JavaThread* thread) {
assert(thread == nullptr
|| (thread->frame_anchor()->has_last_Java_frame() &&
thread->frame_anchor()->walkable()), "must be");
// Schedule deoptimization of an nmethod activation with this frame.
assert(_cb != nullptr && _cb->is_nmethod(), "must be");
// If the call site is a MethodHandle call site use the MH deopt handler.
nmethod* nm = _cb->as_nmethod();
address deopt = nm->deopt_handler_entry();
NativePostCallNop* inst = nativePostCallNop_at(pc());
// Save the original pc before we patch in the new one
nm->set_original_pc(this, pc());
patch_pc(thread, deopt);
assert(is_deoptimized_frame(), "must be");
#ifdef ASSERT
if (thread != nullptr) {
frame check = thread->last_frame();
if (is_older(check.id())) {
RegisterMap map(thread,
RegisterMap::UpdateMap::skip,
RegisterMap::ProcessFrames::include,
RegisterMap::WalkContinuation::skip);
while (id() != check.id()) {
check = check.sender(&map);
}
assert(check.is_deoptimized_frame(), "missed deopt");
}
}
#endif // ASSERT
}
frame frame::java_sender() const {
RegisterMap map(JavaThread::current(),
RegisterMap::UpdateMap::skip,
RegisterMap::ProcessFrames::include,
RegisterMap::WalkContinuation::skip);
frame s;
for (s = sender(&map); !(s.is_java_frame() || s.is_first_frame()); s = s.sender(&map)) ;
guarantee(s.is_java_frame(), "tried to get caller of first java frame");
return s;
}
frame frame::real_sender(RegisterMap* map) const {
frame result = sender(map);
while (result.is_runtime_frame() ||
result.is_ignored_frame()) {
result = result.sender(map);
}
return result;
}
// Interpreter frames
Method* frame::interpreter_frame_method() const {
assert(is_interpreted_frame(), "interpreted frame expected");
Method* m = *interpreter_frame_method_addr();
assert(m->is_method(), "not a Method*");
return m;
}
void frame::interpreter_frame_set_method(Method* method) {
assert(is_interpreted_frame(), "interpreted frame expected");
*interpreter_frame_method_addr() = method;
}
void frame::interpreter_frame_set_mirror(oop mirror) {
assert(is_interpreted_frame(), "interpreted frame expected");
*interpreter_frame_mirror_addr() = mirror;
}
jint frame::interpreter_frame_bci() const {
assert(is_interpreted_frame(), "interpreted frame expected");
address bcp = interpreter_frame_bcp();
return interpreter_frame_method()->bci_from(bcp);
}
address frame::interpreter_frame_bcp() const {
assert(is_interpreted_frame(), "interpreted frame expected");
address bcp = (address)*interpreter_frame_bcp_addr();
return interpreter_frame_method()->bcp_from(bcp);
}
void frame::interpreter_frame_set_bcp(address bcp) {
assert(is_interpreted_frame(), "interpreted frame expected");
*interpreter_frame_bcp_addr() = (intptr_t)bcp;
}
address frame::interpreter_frame_mdp() const {
assert(ProfileInterpreter, "must be profiling interpreter");
assert(is_interpreted_frame(), "interpreted frame expected");
return (address)*interpreter_frame_mdp_addr();
}
void frame::interpreter_frame_set_mdp(address mdp) {
assert(is_interpreted_frame(), "interpreted frame expected");
assert(ProfileInterpreter, "must be profiling interpreter");
*interpreter_frame_mdp_addr() = (intptr_t)mdp;
}
BasicObjectLock* frame::next_monitor_in_interpreter_frame(BasicObjectLock* current) const {
assert(is_interpreted_frame(), "Not an interpreted frame");
#ifdef ASSERT
interpreter_frame_verify_monitor(current);
#endif
BasicObjectLock* next = (BasicObjectLock*) (((intptr_t*) current) + interpreter_frame_monitor_size());
return next;
}
BasicObjectLock* frame::previous_monitor_in_interpreter_frame(BasicObjectLock* current) const {
assert(is_interpreted_frame(), "Not an interpreted frame");
#ifdef ASSERT
// // This verification needs to be checked before being enabled
// interpreter_frame_verify_monitor(current);
#endif
BasicObjectLock* previous = (BasicObjectLock*) (((intptr_t*) current) - interpreter_frame_monitor_size());
return previous;
}
// Interpreter locals and expression stack locations.
intptr_t* frame::interpreter_frame_local_at(int index) const {
const int n = Interpreter::local_offset_in_bytes(index)/wordSize;
intptr_t* first = interpreter_frame_locals();
return &(first[n]);
}
intptr_t* frame::interpreter_frame_expression_stack_at(jint offset) const {
const int i = offset * interpreter_frame_expression_stack_direction();
const int n = i * Interpreter::stackElementWords;
return &(interpreter_frame_expression_stack()[n]);
}
jint frame::interpreter_frame_expression_stack_size() const {
// Number of elements on the interpreter expression stack
// Callers should span by stackElementWords
int element_size = Interpreter::stackElementWords;
size_t stack_size = 0;
if (frame::interpreter_frame_expression_stack_direction() < 0) {
stack_size = (interpreter_frame_expression_stack() -
interpreter_frame_tos_address() + 1)/element_size;
} else {
stack_size = (interpreter_frame_tos_address() -
interpreter_frame_expression_stack() + 1)/element_size;
}
assert(stack_size <= (size_t)max_jint, "stack size too big");
return (jint)stack_size;
}
// (frame::interpreter_frame_sender_sp accessor is in frame_<arch>.cpp)
const char* frame::print_name() const {
if (is_native_frame()) return "Native";
if (is_interpreted_frame()) return "Interpreted";
if (is_compiled_frame()) {
if (is_deoptimized_frame()) return "Deoptimized";
return "Compiled";
}
if (sp() == nullptr) return "Empty";
return "C";
}
void frame::print_value_on(outputStream* st) const {
NOT_PRODUCT(address begin = pc()-40;)
NOT_PRODUCT(address end = nullptr;)
st->print("%s frame (sp=" INTPTR_FORMAT " unextended sp=" INTPTR_FORMAT, print_name(), p2i(sp()), p2i(unextended_sp()));
if (sp() != nullptr)
st->print(", fp=" INTPTR_FORMAT ", real_fp=" INTPTR_FORMAT ", pc=" INTPTR_FORMAT,
p2i(fp()), p2i(real_fp()), p2i(pc()));
st->print_cr(")");
if (StubRoutines::contains(pc())) {
StubCodeDesc* desc = StubCodeDesc::desc_for(pc());
st->print("~Stub::%s", desc->name());
NOT_PRODUCT(begin = desc->begin(); end = desc->end();)
} else if (Interpreter::contains(pc())) {
InterpreterCodelet* desc = Interpreter::codelet_containing(pc());
if (desc != nullptr) {
st->print("~");
desc->print_on(st);
NOT_PRODUCT(begin = desc->code_begin(); end = desc->code_end();)
} else {
st->print("~interpreter");
}
}
#ifndef PRODUCT
if (_cb != nullptr) {
st->print(" ");
_cb->print_value_on(st);
if (end == nullptr) {
begin = _cb->code_begin();
end = _cb->code_end();
}
}
if (WizardMode && Verbose) Disassembler::decode(begin, end);
#endif
}
void frame::print_on(outputStream* st) const {
print_value_on(st);
if (is_interpreted_frame()) {
interpreter_frame_print_on(st);
}
}
void frame::interpreter_frame_print_on(outputStream* st) const {
#ifndef PRODUCT
assert(is_interpreted_frame(), "Not an interpreted frame");
jint i;
for (i = 0; i < interpreter_frame_method()->max_locals(); i++ ) {
intptr_t x = *interpreter_frame_local_at(i);
st->print(" - local [" INTPTR_FORMAT "]", x);
st->fill_to(23);
st->print_cr("; #%d", i);
}
for (i = interpreter_frame_expression_stack_size() - 1; i >= 0; --i ) {
intptr_t x = *interpreter_frame_expression_stack_at(i);
st->print(" - stack [" INTPTR_FORMAT "]", x);
st->fill_to(23);
st->print_cr("; #%d", i);
}
// locks for synchronization
for (BasicObjectLock* current = interpreter_frame_monitor_end();
current < interpreter_frame_monitor_begin();
current = next_monitor_in_interpreter_frame(current)) {
st->print(" - obj [%s", current->obj() == nullptr ? "null" : "");
oop obj = current->obj();
if (obj != nullptr) {
if (!is_heap_frame()) {
obj->print_value_on(st);
} else {
// Might be an invalid oop. We don't have the
// stackChunk to correct it so just print address.
st->print(INTPTR_FORMAT, p2i(obj));
}
}
st->print_cr("]");
st->print(" - lock [");
if (!is_heap_frame()) {
current->lock()->print_on(st, obj);
}
st->print_cr("]");
}
// monitor
st->print_cr(" - monitor[" INTPTR_FORMAT "]", p2i(interpreter_frame_monitor_begin()));
// bcp
st->print(" - bcp [" INTPTR_FORMAT "]", p2i(interpreter_frame_bcp()));
st->fill_to(23);
st->print_cr("; @%d", interpreter_frame_bci());
// locals
st->print_cr(" - locals [" INTPTR_FORMAT "]", p2i(interpreter_frame_local_at(0)));
// method
st->print(" - method [" INTPTR_FORMAT "]", p2i(interpreter_frame_method()));
st->fill_to(23);
st->print("; ");
interpreter_frame_method()->print_name(st);
st->cr();
#endif
}
// Print whether the frame is in the VM or OS indicating a HotSpot problem.
// Otherwise, it's likely a bug in the native library that the Java code calls,
// hopefully indicating where to submit bugs.
void frame::print_C_frame(outputStream* st, char* buf, int buflen, address pc) {
// C/C++ frame
bool in_vm = os::address_is_in_vm(pc);
st->print(in_vm ? "V" : "C");
int offset;
bool found;
if (buf == nullptr || buflen < 1) return;
// libname
buf[0] = '\0';
found = os::dll_address_to_library_name(pc, buf, buflen, &offset);
if (found && buf[0] != '\0') {
// skip directory names
const char *p1, *p2;
p1 = buf;
int len = (int)strlen(os::file_separator());
while ((p2 = strstr(p1, os::file_separator())) != nullptr) p1 = p2 + len;
st->print(" [%s+0x%x]", p1, offset);
} else {
st->print(" " PTR_FORMAT, p2i(pc));
}
found = os::dll_address_to_function_name(pc, buf, buflen, &offset);
if (found) {
st->print(" %s+0x%x", buf, offset);
}
}
// frame::print_on_error() is called by fatal error handler. Notice that we may
// crash inside this function if stack frame is corrupted. The fatal error
// handler can catch and handle the crash. Here we assume the frame is valid.
//
// First letter indicates type of the frame:
// J: Java frame (compiled)
// j: Java frame (interpreted)
// V: VM frame (C/C++)
// v: Other frames running VM generated code (e.g. stubs, adapters, etc.)
// C: C/C++ frame
//
// We don't need detailed frame type as that in frame::print_name(). "C"
// suggests the problem is in user lib; everything else is likely a VM bug.
void frame::print_on_error(outputStream* st, char* buf, int buflen, bool verbose) const {
if (_cb != nullptr) {
if (Interpreter::contains(pc())) {
Method* m = this->interpreter_frame_method();
if (m != nullptr) {
m->name_and_sig_as_C_string(buf, buflen);
st->print("j %s", buf);
st->print("+%d", this->interpreter_frame_bci());
ModuleEntry* module = m->method_holder()->module();
if (module->is_named()) {
module->name()->as_C_string(buf, buflen);
st->print(" %s", buf);
if (module->version() != nullptr) {
module->version()->as_C_string(buf, buflen);
st->print("@%s", buf);
}
}
} else {
st->print("j " PTR_FORMAT, p2i(pc()));
}
} else if (StubRoutines::contains(pc())) {
StubCodeDesc* desc = StubCodeDesc::desc_for(pc());
if (desc != nullptr) {
st->print("v ~StubRoutines::%s " PTR_FORMAT, desc->name(), p2i(pc()));
} else {
st->print("v ~StubRoutines::" PTR_FORMAT, p2i(pc()));
}
} else if (_cb->is_buffer_blob()) {
st->print("v ~BufferBlob::%s " PTR_FORMAT, ((BufferBlob *)_cb)->name(), p2i(pc()));
} else if (_cb->is_nmethod()) {
nmethod* nm = _cb->as_nmethod();
Method* m = nm->method();
if (m != nullptr) {
st->print("J %d%s", nm->compile_id(), (nm->is_osr_method() ? "%" : ""));
st->print(" %s", nm->compiler_name());
m->name_and_sig_as_C_string(buf, buflen);
st->print(" %s", buf);
ModuleEntry* module = m->method_holder()->module();
if (module->is_named()) {
module->name()->as_C_string(buf, buflen);
st->print(" %s", buf);
if (module->version() != nullptr) {
module->version()->as_C_string(buf, buflen);
st->print("@%s", buf);
}
}
st->print(" (%d bytes) @ " PTR_FORMAT " [" PTR_FORMAT "+" INTPTR_FORMAT "]",
m->code_size(), p2i(_pc), p2i(_cb->code_begin()), _pc - _cb->code_begin());
#if INCLUDE_JVMCI
const char* jvmciName = nm->jvmci_name();
if (jvmciName != nullptr) {
st->print(" (%s)", jvmciName);
}
#endif
} else {
st->print("J " PTR_FORMAT, p2i(pc()));
}
} else if (_cb->is_runtime_stub()) {
st->print("v ~RuntimeStub::%s " PTR_FORMAT, ((RuntimeStub *)_cb)->name(), p2i(pc()));
} else if (_cb->is_deoptimization_stub()) {
st->print("v ~DeoptimizationBlob " PTR_FORMAT, p2i(pc()));
} else if (_cb->is_exception_stub()) {
st->print("v ~ExceptionBlob " PTR_FORMAT, p2i(pc()));
} else if (_cb->is_safepoint_stub()) {
st->print("v ~SafepointBlob " PTR_FORMAT, p2i(pc()));
} else if (_cb->is_adapter_blob()) {
st->print("v ~AdapterBlob " PTR_FORMAT, p2i(pc()));
} else if (_cb->is_vtable_blob()) {
st->print("v ~VtableBlob " PTR_FORMAT, p2i(pc()));
} else if (_cb->is_method_handles_adapter_blob()) {
st->print("v ~MethodHandlesAdapterBlob " PTR_FORMAT, p2i(pc()));
} else if (_cb->is_uncommon_trap_stub()) {
st->print("v ~UncommonTrapBlob " PTR_FORMAT, p2i(pc()));
} else if (_cb->is_upcall_stub()) {
st->print("v ~UpcallStub::%s " PTR_FORMAT, _cb->name(), p2i(pc()));
} else {
st->print("v blob " PTR_FORMAT, p2i(pc()));
}
} else {
print_C_frame(st, buf, buflen, pc());
}
}
/*
The interpreter_frame_expression_stack_at method in the case of SPARC needs the
max_stack value of the method in order to compute the expression stack address.
It uses the Method* in order to get the max_stack value but during GC this
Method* value saved on the frame is changed by reverse_and_push and hence cannot
be used. So we save the max_stack value in the FrameClosure object and pass it
down to the interpreter_frame_expression_stack_at method
*/
class InterpreterFrameClosure : public OffsetClosure {
private:
const frame* _fr;
OopClosure* _f;
int _max_locals;
int _max_stack;
public:
InterpreterFrameClosure(const frame* fr, int max_locals, int max_stack,
OopClosure* f) {
_fr = fr;
_max_locals = max_locals;
_max_stack = max_stack;
_f = f;
}
void offset_do(int offset) {
oop* addr;
if (offset < _max_locals) {
addr = (oop*) _fr->interpreter_frame_local_at(offset);
assert((intptr_t*)addr >= _fr->sp(), "must be inside the frame");
_f->do_oop(addr);
} else {
addr = (oop*) _fr->interpreter_frame_expression_stack_at((offset - _max_locals));
// In case of exceptions, the expression stack is invalid and the esp will be reset to express
// this condition. Therefore, we call f only if addr is 'inside' the stack (i.e., addr >= esp for Intel).
bool in_stack;
if (frame::interpreter_frame_expression_stack_direction() > 0) {
in_stack = (intptr_t*)addr <= _fr->interpreter_frame_tos_address();
} else {
in_stack = (intptr_t*)addr >= _fr->interpreter_frame_tos_address();
}
if (in_stack) {
_f->do_oop(addr);
}
}
}
};
class InterpretedArgumentOopFinder: public SignatureIterator {
private:
OopClosure* _f; // Closure to invoke
int _offset; // TOS-relative offset, decremented with each argument
bool _has_receiver; // true if the callee has a receiver
const frame* _fr;
friend class SignatureIterator; // so do_parameters_on can call do_type
void do_type(BasicType type) {
_offset -= parameter_type_word_count(type);
if (is_reference_type(type)) oop_offset_do();
}
void oop_offset_do() {
oop* addr;
addr = (oop*)_fr->interpreter_frame_tos_at(_offset);
_f->do_oop(addr);
}
public:
InterpretedArgumentOopFinder(Symbol* signature, bool has_receiver, const frame* fr, OopClosure* f) : SignatureIterator(signature), _has_receiver(has_receiver) {
// compute size of arguments
int args_size = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0);
assert(!fr->is_interpreted_frame() ||
args_size <= fr->interpreter_frame_expression_stack_size(),
"args cannot be on stack anymore");
// initialize InterpretedArgumentOopFinder
_f = f;
_fr = fr;
_offset = args_size;
}
void oops_do() {
if (_has_receiver) {
--_offset;
oop_offset_do();
}
do_parameters_on(this);
}
};
// Entry frame has following form (n arguments)
// +-----------+
// sp -> | last arg |
// +-----------+
// : ::: :
// +-----------+
// (sp+n)->| first arg|
// +-----------+
// visits and GC's all the arguments in entry frame
class EntryFrameOopFinder: public SignatureIterator {
private:
bool _is_static;
int _offset;
const frame* _fr;
OopClosure* _f;
friend class SignatureIterator; // so do_parameters_on can call do_type
void do_type(BasicType type) {
// decrement offset before processing the type
_offset -= parameter_type_word_count(type);
assert (_offset >= 0, "illegal offset");
if (is_reference_type(type)) oop_at_offset_do(_offset);
}
void oop_at_offset_do(int offset) {
assert (offset >= 0, "illegal offset");
oop* addr = (oop*) _fr->entry_frame_argument_at(offset);
_f->do_oop(addr);
}
public:
EntryFrameOopFinder(const frame* frame, Symbol* signature, bool is_static) : SignatureIterator(signature) {
_f = nullptr; // will be set later
_fr = frame;
_is_static = is_static;
_offset = ArgumentSizeComputer(signature).size(); // pre-decremented down to zero
}
void arguments_do(OopClosure* f) {
_f = f;
if (!_is_static) oop_at_offset_do(_offset); // do the receiver
do_parameters_on(this);
}
};
oop* frame::interpreter_callee_receiver_addr(Symbol* signature) {
ArgumentSizeComputer asc(signature);
int size = asc.size();
return (oop *)interpreter_frame_tos_at(size);
}
oop frame::interpreter_callee_receiver(Symbol* signature) {
return *interpreter_callee_receiver_addr(signature);
}
template <typename RegisterMapT>
void frame::oops_interpreted_do(OopClosure* f, const RegisterMapT* map, bool query_oop_map_cache) const {
assert(is_interpreted_frame(), "Not an interpreted frame");
Thread *thread = Thread::current();
methodHandle m (thread, interpreter_frame_method());
jint bci = interpreter_frame_bci();
assert(!Universe::heap()->is_in(m()),
"must be valid oop");
assert(m->is_method(), "checking frame value");
assert((m->is_native() && bci == 0) ||
(!m->is_native() && bci >= 0 && bci < m->code_size()),
"invalid bci value");
// Handle the monitor elements in the activation
for (
BasicObjectLock* current = interpreter_frame_monitor_end();
current < interpreter_frame_monitor_begin();
current = next_monitor_in_interpreter_frame(current)
) {
#ifdef ASSERT
interpreter_frame_verify_monitor(current);
#endif
current->oops_do(f);
}
if (m->is_native()) {
f->do_oop(interpreter_frame_temp_oop_addr());
}
// The method pointer in the frame might be the only path to the method's
// klass, and the klass needs to be kept alive while executing. The GCs
// don't trace through method pointers, so the mirror of the method's klass
// is installed as a GC root.
f->do_oop(interpreter_frame_mirror_addr());
int max_locals = m->is_native() ? m->size_of_parameters() : m->max_locals();
// Process a callee's arguments if we are at a call site
// (i.e., if we are at an invoke bytecode)
// This is used sometimes for calling into the VM, not for another
// interpreted or compiled frame.
if (!m->is_native() && map != nullptr && map->include_argument_oops()) {
Bytecode_invoke call = Bytecode_invoke_check(m, bci);
if (call.is_valid() && interpreter_frame_expression_stack_size() > 0) {
ResourceMark rm(thread); // is this right ???
Symbol* signature = call.signature();
bool has_receiver = call.has_receiver();
// We are at a call site & the expression stack is not empty
// so we might have callee arguments we need to process.
oops_interpreted_arguments_do(signature, has_receiver, f);
}
}
InterpreterFrameClosure blk(this, max_locals, m->max_stack(), f);
// process locals & expression stack
InterpreterOopMap mask;
if (query_oop_map_cache) {
m->mask_for(m, bci, &mask);
} else {
OopMapCache::compute_one_oop_map(m, bci, &mask);
}
mask.iterate_oop(&blk);
}
template void frame::oops_interpreted_do(OopClosure* f, const RegisterMap* map, bool query_oop_map_cache) const;
template void frame::oops_interpreted_do(OopClosure* f, const SmallRegisterMapNoArgs* map, bool query_oop_map_cache) const;
template void frame::oops_interpreted_do(OopClosure* f, const SmallRegisterMapWithArgs* map, bool query_oop_map_cache) const;
void frame::oops_interpreted_arguments_do(Symbol* signature, bool has_receiver, OopClosure* f) const {
InterpretedArgumentOopFinder finder(signature, has_receiver, this, f);
finder.oops_do();
}
void frame::oops_nmethod_do(OopClosure* f, NMethodClosure* cf, DerivedOopClosure* df, DerivedPointerIterationMode derived_mode, const RegisterMap* reg_map) const {
assert(_cb != nullptr, "sanity check");
assert((oop_map() == nullptr) == (_cb->oop_maps() == nullptr), "frame and _cb must agree that oopmap is set or not");
if (oop_map() != nullptr) {
if (df != nullptr) {
_oop_map->oops_do(this, reg_map, f, df);
} else {
_oop_map->oops_do(this, reg_map, f, derived_mode);
}
// Preserve potential arguments for a callee. We handle this by dispatching
// on the codeblob. For c2i, we do
if (reg_map->include_argument_oops() && _cb->is_nmethod()) {
// Only nmethod preserves outgoing arguments at call.
_cb->as_nmethod()->preserve_callee_argument_oops(*this, reg_map, f);
}
}
// In cases where perm gen is collected, GC will want to mark
// oops referenced from nmethods active on thread stacks so as to
// prevent them from being collected. However, this visit should be
// restricted to certain phases of the collection only. The
// closure decides how it wants nmethods to be traced.
if (cf != nullptr && _cb->is_nmethod())
cf->do_nmethod(_cb->as_nmethod());
}
class CompiledArgumentOopFinder: public SignatureIterator {
protected:
OopClosure* _f;
int _offset; // the current offset, incremented with each argument
bool _has_receiver; // true if the callee has a receiver
bool _has_appendix; // true if the call has an appendix