- Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathnmethod.hpp
1002 lines (828 loc) · 41.4 KB
/
nmethod.hpp
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.
*
*/
#ifndef SHARE_CODE_NMETHOD_HPP
#defineSHARE_CODE_NMETHOD_HPP
#include"code/codeBlob.hpp"
#include"code/pcDesc.hpp"
#include"oops/metadata.hpp"
#include"oops/method.hpp"
classAbstractCompiler;
classCompiledDirectCall;
classCompiledIC;
classCompiledICData;
classCompileTask;
classDepChange;
classDependencies;
classDirectiveSet;
classDebugInformationRecorder;
classExceptionHandlerTable;
classImplicitExceptionTable;
classJvmtiThreadState;
classMetadataClosure;
classNativeCallWrapper;
classOopIterateClosure;
classScopeDesc;
classxmlStream;
// This class is used internally by nmethods, to cache
// exception/pc/handler information.
classExceptionCache : publicCHeapObj<mtCode> {
friendclassVMStructs;
private:
enum { cache_size = 16 };
Klass* _exception_type;
address _pc[cache_size];
address _handler[cache_size];
volatileint _count;
ExceptionCache* volatile _next;
ExceptionCache* _purge_list_next;
inline address pc_at(int index);
voidset_pc_at(int index, address a) { assert(index >= 0 && index < cache_size,""); _pc[index] = a; }
inline address handler_at(int index);
voidset_handler_at(int index, address a) { assert(index >= 0 && index < cache_size,""); _handler[index] = a; }
inlineintcount();
// increment_count is only called under lock, but there may be concurrent readers.
voidincrement_count();
public:
ExceptionCache(Handleexception, address pc, address handler);
Klass* exception_type() { return _exception_type; }
ExceptionCache* next();
voidset_next(ExceptionCache *ec);
ExceptionCache* purge_list_next() { return _purge_list_next; }
voidset_purge_list_next(ExceptionCache *ec) { _purge_list_next = ec; }
address match(Handleexception, address pc);
boolmatch_exception_with_space(Handleexception) ;
address test_address(address addr);
booladd_address_and_handler(address addr, address handler) ;
};
// cache pc descs found in earlier inquiries
classPcDescCache {
friendclassVMStructs;
private:
enum { cache_size = 4 };
// The array elements MUST be volatile! Several threads may modify
// and read from the cache concurrently. find_pc_desc_internal has
// returned wrong results. C++ compiler (namely xlC12) may duplicate
// C++ field accesses if the elements are not volatile.
typedef PcDesc* PcDescPtr;
volatile PcDescPtr _pc_descs[cache_size]; // last cache_size pc_descs found
public:
PcDescCache() { DEBUG_ONLY(_pc_descs[0] = nullptr); }
voidinit_to(PcDesc* initial_pc_desc);
PcDesc* find_pc_desc(int pc_offset, bool approximate);
voidadd_pc_desc(PcDesc* pc_desc);
PcDesc* last_pc_desc() { return _pc_descs[0]; }
};
classPcDescContainer : publicCHeapObj<mtCode> {
private:
PcDescCache _pc_desc_cache;
public:
PcDescContainer(PcDesc* initial_pc_desc) { _pc_desc_cache.init_to(initial_pc_desc); }
PcDesc* find_pc_desc_internal(address pc, bool approximate, address code_begin,
PcDesc* lower, PcDesc* upper);
PcDesc* find_pc_desc(address pc, bool approximate, address code_begin, PcDesc* lower, PcDesc* upper)
#ifdef PRODUCT
{
PcDesc* desc = _pc_desc_cache.last_pc_desc();
assert(desc != nullptr, "PcDesc cache should be initialized already");
if (desc->pc_offset() == (pc - code_begin)) {
// Cached value matched
return desc;
}
returnfind_pc_desc_internal(pc, approximate, code_begin, lower, upper);
}
#endif
;
};
// nmethods (native methods) are the compiled code versions of Java methods.
//
// An nmethod contains:
// - Header (the nmethod structure)
// - Constant part (doubles, longs and floats used in nmethod)
// - Code part:
// - Code body
// - Exception handler
// - Stub code
// - OOP table
//
// As a CodeBlob, an nmethod references [mutable data] allocated on the C heap:
// - CodeBlob relocation data
// - Metainfo
// - JVMCI data
//
// An nmethod references [immutable data] allocated on C heap:
// - Dependency assertions data
// - Implicit null table array
// - Handler entry point array
// - Debugging information:
// - Scopes data array
// - Scopes pcs array
// - JVMCI speculations array
#if INCLUDE_JVMCI
classFailedSpeculation;
classJVMCINMethodData;
#endif
classnmethod : publicCodeBlob {
friendclassVMStructs;
friendclassJVMCIVMStructs;
friendclassCodeCache; // scavengable oops
friendclassJVMCINMethodData;
friendclassDeoptimizationScope;
private:
// Used to track in which deoptimize handshake this method will be deoptimized.
uint64_t _deoptimization_generation;
uint64_t _gc_epoch;
Method* _method;
// To reduce header size union fields which usages do not overlap.
union {
// To support simple linked-list chaining of nmethods:
nmethod* _osr_link; // from InstanceKlass::osr_nmethods_head
struct {
// These are used for compiled synchronized native methods to
// locate the owner and stack slot for the BasicLock. They are
// needed because there is no debug information for compiled native
// wrappers and the oop maps are insufficient to allow
// frame::retrieve_receiver() to work. Currently they are expected
// to be byte offsets from the Java stack pointer for maximum code
// sharing between platforms. JVMTI's GetLocalInstance() uses these
// offsets to find the receiver for non-static native wrapper frames.
ByteSize _native_receiver_sp_offset;
ByteSize _native_basic_lock_sp_offset;
};
};
// nmethod's read-only data
address _immutable_data;
PcDescContainer* _pc_desc_container;
ExceptionCache* volatile _exception_cache;
void* _gc_data;
structoops_do_mark_link; // Opaque data type.
static nmethod* volatile _oops_do_mark_nmethods;
oops_do_mark_link* volatile _oops_do_mark_link;
CompiledICData* _compiled_ic_data;
// offsets for entry points
address _osr_entry_point; // entry point for on stack replacement
uint16_t _entry_offset; // entry point with class check
uint16_t _verified_entry_offset; // entry point without class check
int _entry_bci; // != InvocationEntryBci if this nmethod is an on-stack replacement method
int _immutable_data_size;
// _consts_offset == _content_offset because SECT_CONSTS is first in code buffer
int _skipped_instructions_size;
int _stub_offset;
// Offsets for different stubs section parts
int _exception_offset;
// All deoptee's will resume execution at this location described by
// this offset.
int _deopt_handler_offset;
// All deoptee's at a MethodHandle call site will resume execution
// at this location described by this offset.
int _deopt_mh_handler_offset;
// Offset (from insts_end) of the unwind handler if it exists
int16_t _unwind_handler_offset;
// Number of arguments passed on the stack
uint16_t _num_stack_arg_slots;
uint16_t _oops_size;
#if INCLUDE_JVMCI
uint16_t _jvmci_data_size;
#endif
// Offset in immutable data section
// _dependencies_offset == 0
uint16_t _nul_chk_table_offset;
uint16_t _handler_table_offset; // This table could be big in C1 code
int _scopes_pcs_offset;
int _scopes_data_offset;
#if INCLUDE_JVMCI
int _speculations_offset;
#endif
// location in frame (offset for sp) that deopt can store the original
// pc during a deopt.
int _orig_pc_offset;
int _compile_id; // which compilation made this nmethod
CompLevel _comp_level; // compilation level (s1)
CompilerType _compiler_type; // which compiler made this nmethod (u1)
// Local state used to keep track of whether unloading is happening or not
volatileuint8_t _is_unloading_state;
// Protected by NMethodState_lock
volatilesignedchar _state; // {not_installed, in_use, not_entrant}
// set during construction
uint8_t _has_unsafe_access:1, // May fault due to unsafe access.
_has_method_handle_invokes:1,// Has this method MethodHandle invokes?
_has_wide_vectors:1, // Preserve wide vectors at safepoints
_has_monitors:1, // Fastpath monitor detection for continuations
_has_scoped_access:1, // used by for shared scope closure (scopedMemoryAccess.cpp)
_has_flushed_dependencies:1, // Used for maintenance of dependencies (under CodeCache_lock)
_is_unlinked:1, // mark during class unloading
_load_reported:1; // used by jvmti to track if an event has been posted for this nmethod
enum DeoptimizationStatus : u1 {
not_marked,
deoptimize,
deoptimize_noupdate,
deoptimize_done
};
volatile DeoptimizationStatus _deoptimization_status; // Used for stack deoptimization
DeoptimizationStatus deoptimization_status() const {
returnAtomic::load(&_deoptimization_status);
}
// Initialize fields to their default values
voidinit_defaults(CodeBuffer *code_buffer, CodeOffsets* offsets);
// Post initialization
voidpost_init();
// For native wrappers
nmethod(Method* method,
CompilerType type,
int nmethod_size,
int compile_id,
CodeOffsets* offsets,
CodeBuffer *code_buffer,
int frame_size,
ByteSize basic_lock_owner_sp_offset, /* synchronized natives only */
ByteSize basic_lock_sp_offset, /* synchronized natives only */
OopMapSet* oop_maps,
int mutable_data_size);
// For normal JIT compiled code
nmethod(Method* method,
CompilerType type,
int nmethod_size,
int immutable_data_size,
int mutable_data_size,
int compile_id,
int entry_bci,
address immutable_data,
CodeOffsets* offsets,
int orig_pc_offset,
DebugInformationRecorder *recorder,
Dependencies* dependencies,
CodeBuffer *code_buffer,
int frame_size,
OopMapSet* oop_maps,
ExceptionHandlerTable* handler_table,
ImplicitExceptionTable* nul_chk_table,
AbstractCompiler* compiler,
CompLevel comp_level
#if INCLUDE_JVMCI
, char* speculations = nullptr,
int speculations_len = 0,
JVMCINMethodData* jvmci_data = nullptr
#endif
);
// helper methods
void* operatornew(size_t size, int nmethod_size, int comp_level) throw();
// For method handle intrinsics: Try MethodNonProfiled, MethodProfiled and NonNMethod.
// Attention: Only allow NonNMethod space for special nmethods which don't need to be
// findable by nmethod iterators! In particular, they must not contain oops!
void* operatornew(size_t size, int nmethod_size, bool allow_NonNMethod_space) throw();
constchar* reloc_string_for(u_char* begin, u_char* end);
booltry_transition(signedchar new_state);
// Returns true if this thread changed the state of the nmethod or
// false if another thread performed the transition.
boolmake_entrant() { Unimplemented(); returnfalse; }
voidinc_decompile_count();
// Inform external interfaces that a compiled method has been unloaded
voidpost_compiled_method_unload();
PcDesc* find_pc_desc(address pc, bool approximate) {
if (_pc_desc_container == nullptr) returnnullptr; // native method
return _pc_desc_container->find_pc_desc(pc, approximate, code_begin(), scopes_pcs_begin(), scopes_pcs_end());
}
// STW two-phase nmethod root processing helpers.
//
// When determining liveness of a given nmethod to do code cache unloading,
// some collectors need to do different things depending on whether the nmethods
// need to absolutely be kept alive during root processing; "strong"ly reachable
// nmethods are known to be kept alive at root processing, but the liveness of
// "weak"ly reachable ones is to be determined later.
//
// We want to allow strong and weak processing of nmethods by different threads
// at the same time without heavy synchronization. Additional constraints are
// to make sure that every nmethod is processed a minimal amount of time, and
// nmethods themselves are always iterated at most once at a particular time.
//
// Note that strong processing work must be a superset of weak processing work
// for this code to work.
//
// We store state and claim information in the _oops_do_mark_link member, using
// the two LSBs for the state and the remaining upper bits for linking together
// nmethods that were already visited.
// The last element is self-looped, i.e. points to itself to avoid some special
// "end-of-list" sentinel value.
//
// _oops_do_mark_link special values:
//
// _oops_do_mark_link == nullptr: the nmethod has not been visited at all yet, i.e.
// is Unclaimed.
//
// For other values, its lowest two bits indicate the following states of the nmethod:
//
// weak_request (WR): the nmethod has been claimed by a thread for weak processing
// weak_done (WD): weak processing has been completed for this nmethod.
// strong_request (SR): the nmethod has been found to need strong processing while
// being weak processed.
// strong_done (SD): strong processing has been completed for this nmethod .
//
// The following shows the _only_ possible progressions of the _oops_do_mark_link
// pointer.
//
// Given
// N as the nmethod
// X the current next value of _oops_do_mark_link
//
// Unclaimed (C)-> N|WR (C)-> X|WD: the nmethod has been processed weakly by
// a single thread.
// Unclaimed (C)-> N|WR (C)-> X|WD (O)-> X|SD: after weak processing has been
// completed (as above) another thread found that the nmethod needs strong
// processing after all.
// Unclaimed (C)-> N|WR (O)-> N|SR (C)-> X|SD: during weak processing another
// thread finds that the nmethod needs strong processing, marks it as such and
// terminates. The original thread completes strong processing.
// Unclaimed (C)-> N|SD (C)-> X|SD: the nmethod has been processed strongly from
// the beginning by a single thread.
//
// "|" describes the concatenation of bits in _oops_do_mark_link.
//
// The diagram also describes the threads responsible for changing the nmethod to
// the next state by marking the _transition_ with (C) and (O), which mean "current"
// and "other" thread respectively.
//
// States used for claiming nmethods during root processing.
staticconstuint claim_weak_request_tag = 0;
staticconstuint claim_weak_done_tag = 1;
staticconstuint claim_strong_request_tag = 2;
staticconstuint claim_strong_done_tag = 3;
static oops_do_mark_link* mark_link(nmethod* nm, uint tag) {
assert(tag <= claim_strong_done_tag, "invalid tag %u", tag);
assert(is_aligned(nm, 4), "nmethod pointer must have zero lower two LSB");
return (oops_do_mark_link*)(((uintptr_t)nm & ~0x3) | tag);
}
staticuintextract_state(oops_do_mark_link* link) {
return (uint)((uintptr_t)link & 0x3);
}
static nmethod* extract_nmethod(oops_do_mark_link* link) {
return (nmethod*)((uintptr_t)link & ~0x3);
}
voidoops_do_log_change(constchar* state);
staticbooloops_do_has_weak_request(oops_do_mark_link* next) {
returnextract_state(next) == claim_weak_request_tag;
}
staticbooloops_do_has_any_strong_state(oops_do_mark_link* next) {
returnextract_state(next) >= claim_strong_request_tag;
}
// Attempt Unclaimed -> N|WR transition. Returns true if successful.
booloops_do_try_claim_weak_request();
// Attempt Unclaimed -> N|SD transition. Returns the current link.
oops_do_mark_link* oops_do_try_claim_strong_done();
// Attempt N|WR -> X|WD transition. Returns nullptr if successful, X otherwise.
nmethod* oops_do_try_add_to_list_as_weak_done();
// Attempt X|WD -> N|SR transition. Returns the current link.
oops_do_mark_link* oops_do_try_add_strong_request(oops_do_mark_link* next);
// Attempt X|WD -> X|SD transition. Returns true if successful.
booloops_do_try_claim_weak_done_as_strong_done(oops_do_mark_link* next);
// Do the N|SD -> X|SD transition.
voidoops_do_add_to_list_as_strong_done();
// Sets this nmethod as strongly claimed (as part of N|SD -> X|SD and N|SR -> X|SD
// transitions).
voidoops_do_set_strong_done(nmethod* old_head);
public:
// create nmethod with entry_bci
static nmethod* new_nmethod(const methodHandle& method,
int compile_id,
int entry_bci,
CodeOffsets* offsets,
int orig_pc_offset,
DebugInformationRecorder* recorder,
Dependencies* dependencies,
CodeBuffer *code_buffer,
int frame_size,
OopMapSet* oop_maps,
ExceptionHandlerTable* handler_table,
ImplicitExceptionTable* nul_chk_table,
AbstractCompiler* compiler,
CompLevel comp_level
#if INCLUDE_JVMCI
, char* speculations = nullptr,
int speculations_len = 0,
JVMCINMethodData* jvmci_data = nullptr
#endif
);
static nmethod* new_native_nmethod(const methodHandle& method,
int compile_id,
CodeBuffer *code_buffer,
int vep_offset,
int frame_complete,
int frame_size,
ByteSize receiver_sp_offset,
ByteSize basic_lock_sp_offset,
OopMapSet* oop_maps,
int exception_handler = -1);
Method* method () const { return _method; }
boolis_native_method() const { return _method != nullptr && _method->is_native(); }
boolis_java_method () const { return _method != nullptr && !_method->is_native(); }
boolis_osr_method () const { return _entry_bci != InvocationEntryBci; }
// Compiler task identification. Note that all OSR methods
// are numbered in an independent sequence if CICountOSR is true,
// and native method wrappers are also numbered independently if
// CICountNative is true.
intcompile_id() const { return _compile_id; }
constchar* compile_kind() const;
inlineboolis_compiled_by_c1 () const { return _compiler_type == compiler_c1; }
inlineboolis_compiled_by_c2 () const { return _compiler_type == compiler_c2; }
inlineboolis_compiled_by_jvmci() const { return _compiler_type == compiler_jvmci; }
CompilerType compiler_type () const { return _compiler_type; }
constchar* compiler_name () const;
// boundaries for different parts
address consts_begin () const { returncontent_begin(); }
address consts_end () const { returncode_begin() ; }
address insts_begin () const { returncode_begin() ; }
address insts_end () const { returnheader_begin() + _stub_offset ; }
address stub_begin () const { returnheader_begin() + _stub_offset ; }
address stub_end () const { returncode_end() ; }
address exception_begin () const { returnheader_begin() + _exception_offset ; }
address deopt_handler_begin () const { returnheader_begin() + _deopt_handler_offset ; }
address deopt_mh_handler_begin() const { returnheader_begin() + _deopt_mh_handler_offset ; }
address unwind_handler_begin () const { return _unwind_handler_offset != -1 ? (insts_end() - _unwind_handler_offset) : nullptr; }
oop* oops_begin () const { return (oop*) data_begin(); }
oop* oops_end () const { return (oop*) data_end(); }
// mutable data
Metadata** metadata_begin () const { return (Metadata**) (mutable_data_begin() + _relocation_size); }
#if INCLUDE_JVMCI
Metadata** metadata_end () const { return (Metadata**) (mutable_data_end() - _jvmci_data_size); }
address jvmci_data_begin () const { returnmutable_data_end() - _jvmci_data_size; }
address jvmci_data_end () const { returnmutable_data_end(); }
#else
Metadata** metadata_end () const { return (Metadata**) mutable_data_end(); }
#endif
// immutable data
address immutable_data_begin () const { return _immutable_data; }
address immutable_data_end () const { return _immutable_data + _immutable_data_size ; }
address dependencies_begin () const { return _immutable_data; }
address dependencies_end () const { return _immutable_data + _nul_chk_table_offset; }
address nul_chk_table_begin () const { return _immutable_data + _nul_chk_table_offset; }
address nul_chk_table_end () const { return _immutable_data + _handler_table_offset; }
address handler_table_begin () const { return _immutable_data + _handler_table_offset; }
address handler_table_end () const { return _immutable_data + _scopes_pcs_offset ; }
PcDesc* scopes_pcs_begin () const { return (PcDesc*)(_immutable_data + _scopes_pcs_offset) ; }
PcDesc* scopes_pcs_end () const { return (PcDesc*)(_immutable_data + _scopes_data_offset) ; }
address scopes_data_begin () const { return _immutable_data + _scopes_data_offset ; }
#if INCLUDE_JVMCI
address scopes_data_end () const { return _immutable_data + _speculations_offset ; }
address speculations_begin () const { return _immutable_data + _speculations_offset ; }
address speculations_end () const { returnimmutable_data_end(); }
#else
address scopes_data_end () const { returnimmutable_data_end(); }
#endif
// Sizes
intimmutable_data_size() const { return _immutable_data_size; }
intconsts_size () const { returnint( consts_end () - consts_begin ()); }
intinsts_size () const { returnint( insts_end () - insts_begin ()); }
intstub_size () const { returnint( stub_end () - stub_begin ()); }
intoops_size () const { returnint((address) oops_end () - (address) oops_begin ()); }
intmetadata_size () const { returnint((address) metadata_end () - (address) metadata_begin ()); }
intscopes_data_size () const { returnint( scopes_data_end () - scopes_data_begin ()); }
intscopes_pcs_size () const { returnint((intptr_t)scopes_pcs_end () - (intptr_t)scopes_pcs_begin ()); }
intdependencies_size () const { returnint( dependencies_end () - dependencies_begin ()); }
inthandler_table_size () const { returnint( handler_table_end() - handler_table_begin()); }
intnul_chk_table_size () const { returnint( nul_chk_table_end() - nul_chk_table_begin()); }
#if INCLUDE_JVMCI
intspeculations_size () const { returnint( speculations_end () - speculations_begin ()); }
intjvmci_data_size () const { returnint( jvmci_data_end () - jvmci_data_begin ()); }
#endif
intoops_count() const { assert(oops_size() % oopSize == 0, ""); return (oops_size() / oopSize) + 1; }
intmetadata_count() const { assert(metadata_size() % wordSize == 0, ""); return (metadata_size() / wordSize) + 1; }
intskipped_instructions_size () const { return _skipped_instructions_size; }
inttotal_size() const;
// Containment
boolconsts_contains (address addr) const { returnconsts_begin () <= addr && addr < consts_end (); }
// Returns true if a given address is in the 'insts' section. The method
// insts_contains_inclusive() is end-inclusive.
boolinsts_contains (address addr) const { returninsts_begin () <= addr && addr < insts_end (); }
boolinsts_contains_inclusive(address addr) const { returninsts_begin () <= addr && addr <= insts_end (); }
boolstub_contains (address addr) const { returnstub_begin () <= addr && addr < stub_end (); }
booloops_contains (oop* addr) const { returnoops_begin () <= addr && addr < oops_end (); }
boolmetadata_contains (Metadata** addr) const { returnmetadata_begin () <= addr && addr < metadata_end (); }
boolscopes_data_contains (address addr) const { returnscopes_data_begin () <= addr && addr < scopes_data_end (); }
boolscopes_pcs_contains (PcDesc* addr) const { returnscopes_pcs_begin () <= addr && addr < scopes_pcs_end (); }
boolhandler_table_contains (address addr) const { returnhandler_table_begin() <= addr && addr < handler_table_end(); }
boolnul_chk_table_contains (address addr) const { returnnul_chk_table_begin() <= addr && addr < nul_chk_table_end(); }
// entry points
address entry_point() const { returncode_begin() + _entry_offset; } // normal entry point
address verified_entry_point() const { returncode_begin() + _verified_entry_offset; } // if klass is correct
enum : signedchar { not_installed = -1, // in construction, only the owner doing the construction is
// allowed to advance state
in_use = 0, // executable nmethod
not_entrant = 1// marked for deoptimization but activations may still exist
};
// flag accessing and manipulation
boolis_not_installed() const { return _state == not_installed; }
boolis_in_use() const { return _state <= in_use; }
boolis_not_entrant() const { return _state == not_entrant; }
intget_state() const { return _state; }
voidclear_unloading_state();
// Heuristically deduce an nmethod isn't worth keeping around
boolis_cold();
boolis_unloading();
voiddo_unloading(bool unloading_occurred);
boolmake_in_use() {
returntry_transition(in_use);
}
// Make the nmethod non entrant. The nmethod will continue to be
// alive. It is used when an uncommon trap happens. Returns true
// if this thread changed the state of the nmethod or false if
// another thread performed the transition.
boolmake_not_entrant(constchar* reason);
boolmake_not_used() { returnmake_not_entrant("not used"); }
boolis_marked_for_deoptimization() const { returndeoptimization_status() != not_marked; }
boolhas_been_deoptimized() const { returndeoptimization_status() == deoptimize_done; }
voidset_deoptimized_done();
boolupdate_recompile_counts() const {
// Update recompile counts when either the update is explicitly requested (deoptimize)
// or the nmethod is not marked for deoptimization at all (not_marked).
// The latter happens during uncommon traps when deoptimized nmethod is made not entrant.
DeoptimizationStatus status = deoptimization_status();
return status != deoptimize_noupdate && status != deoptimize_done;
}
// tells whether frames described by this nmethod can be deoptimized
// note: native wrappers cannot be deoptimized.
boolcan_be_deoptimized() const { returnis_java_method(); }
boolhas_dependencies() { returndependencies_size() != 0; }
voidprint_dependencies_on(outputStream* out) PRODUCT_RETURN;
voidflush_dependencies();
template<typename T>
T* gc_data() const { returnreinterpret_cast<T*>(_gc_data); }
template<typename T>
voidset_gc_data(T* gc_data) { _gc_data = reinterpret_cast<void*>(gc_data); }
boolhas_unsafe_access() const { return _has_unsafe_access; }
voidset_has_unsafe_access(bool z) { _has_unsafe_access = z; }
boolhas_monitors() const { return _has_monitors; }
voidset_has_monitors(bool z) { _has_monitors = z; }
boolhas_scoped_access() const { return _has_scoped_access; }
voidset_has_scoped_access(bool z) { _has_scoped_access = z; }
boolhas_method_handle_invokes() const { return _has_method_handle_invokes; }
voidset_has_method_handle_invokes(bool z) { _has_method_handle_invokes = z; }
boolhas_wide_vectors() const { return _has_wide_vectors; }
voidset_has_wide_vectors(bool z) { _has_wide_vectors = z; }
boolhas_flushed_dependencies() const { return _has_flushed_dependencies; }
voidset_has_flushed_dependencies(bool z) {
assert(!has_flushed_dependencies(), "should only happen once");
_has_flushed_dependencies = z;
}
boolis_unlinked() const { return _is_unlinked; }
voidset_is_unlinked() {
assert(!_is_unlinked, "already unlinked");
_is_unlinked = true;
}
intcomp_level() const { return _comp_level; }
// Support for oops in scopes and relocs:
// Note: index 0 is reserved for null.
oop oop_at(int index) const;
oop oop_at_phantom(int index) const; // phantom reference
oop* oop_addr_at(int index) const { // for GC
// relocation indexes are biased by 1 (because 0 is reserved)
assert(index > 0 && index <= oops_count(), "must be a valid non-zero index");
return &oops_begin()[index - 1];
}
// Support for meta data in scopes and relocs:
// Note: index 0 is reserved for null.
Metadata* metadata_at(int index) const { returnindex == 0 ? nullptr: *metadata_addr_at(index); }
Metadata** metadata_addr_at(int index) const { // for GC
// relocation indexes are biased by 1 (because 0 is reserved)
assert(index > 0 && index <= metadata_count(), "must be a valid non-zero index");
return &metadata_begin()[index - 1];
}
voidcopy_values(GrowableArray<jobject>* oops);
voidcopy_values(GrowableArray<Metadata*>* metadata);
voidcopy_values(GrowableArray<address>* metadata) {} // Nothing to do
// Relocation support
private:
voidfix_oop_relocations(address begin, address end, bool initialize_immediates);
inlinevoidinitialize_immediate_oop(oop* dest, jobject handle);
protected:
address oops_reloc_begin() const;
public:
voidfix_oop_relocations(address begin, address end) { fix_oop_relocations(begin, end, false); }
voidfix_oop_relocations() { fix_oop_relocations(nullptr, nullptr, false); }
boolis_at_poll_return(address pc);
boolis_at_poll_or_poll_return(address pc);
protected:
// Exception cache support
// Note: _exception_cache may be read and cleaned concurrently.
ExceptionCache* exception_cache() const { return _exception_cache; }
ExceptionCache* exception_cache_acquire() const;
public:
address handler_for_exception_and_pc(Handleexception, address pc);
voidadd_handler_for_exception_and_pc(Handleexception, address pc, address handler);
voidclean_exception_cache();
voidadd_exception_cache_entry(ExceptionCache* new_entry);
ExceptionCache* exception_cache_entry_for_exception(Handleexception);
// MethodHandle
boolis_method_handle_return(address return_pc);
// Deopt
// Return true is the PC is one would expect if the frame is being deopted.
inlineboolis_deopt_pc(address pc);
inlineboolis_deopt_mh_entry(address pc);
inlineboolis_deopt_entry(address pc);
// Accessor/mutator for the original pc of a frame before a frame was deopted.
address get_original_pc(const frame* fr) { return *orig_pc_addr(fr); }
voidset_original_pc(const frame* fr, address pc) { *orig_pc_addr(fr) = pc; }
constchar* state() const;
boolinlinecache_check_contains(address addr) const {
return (addr >= code_begin() && addr < verified_entry_point());
}
voidpreserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f);
// implicit exceptions support
address continuation_for_implicit_div0_exception(address pc) { returncontinuation_for_implicit_exception(pc, true); }
address continuation_for_implicit_null_exception(address pc) { returncontinuation_for_implicit_exception(pc, false); }
// Inline cache support for class unloading and nmethod unloading
private:
voidcleanup_inline_caches_impl(bool unloading_occurred, bool clean_all);
address continuation_for_implicit_exception(address pc, bool for_div0_check);
public:
// Serial version used by whitebox test
voidcleanup_inline_caches_whitebox();
voidclear_inline_caches();
// Execute nmethod barrier code, as if entering through nmethod call.
voidrun_nmethod_entry_barrier();
voidverify_oop_relocations();
boolhas_evol_metadata();
Method* attached_method(address call_pc);
Method* attached_method_before_pc(address pc);
// GC unloading support
// Cleans unloaded klasses and unloaded nmethods in inline caches
voidunload_nmethod_caches(bool class_unloading_occurred);
voidunlink_from_method();
// On-stack replacement support
intosr_entry_bci() const { assert(is_osr_method(), "wrong kind of nmethod"); return _entry_bci; }
address osr_entry() const { assert(is_osr_method(), "wrong kind of nmethod"); return _osr_entry_point; }
nmethod* osr_link() const { return _osr_link; }
voidset_osr_link(nmethod *n) { _osr_link = n; }
voidinvalidate_osr_method();
intnum_stack_arg_slots(bool rounded = true) const {
return rounded ? align_up(_num_stack_arg_slots, 2) : _num_stack_arg_slots;
}
// Verify calls to dead methods have been cleaned.
voidverify_clean_inline_caches();
// Unlink this nmethod from the system
voidunlink();
// Deallocate this nmethod - called by the GC
voidpurge(bool unregister_nmethod);
// See comment at definition of _last_seen_on_stack
voidmark_as_maybe_on_stack();
boolis_maybe_on_stack();
// Evolution support. We make old (discarded) compiled methods point to new Method*s.
voidset_method(Method* method) { _method = method; }
#if INCLUDE_JVMCI
// Gets the JVMCI name of this nmethod.
constchar* jvmci_name();
// Records the pending failed speculation in the
// JVMCI speculation log associated with this nmethod.
voidupdate_speculation(JavaThread* thread);
// Gets the data specific to a JVMCI compiled method.
// This returns a non-nullptr value iff this nmethod was
// compiled by the JVMCI compiler.
JVMCINMethodData* jvmci_nmethod_data() const {
returnjvmci_data_size() == 0 ? nullptr : (JVMCINMethodData*) jvmci_data_begin();
}
#endif
voidoops_do(OopClosure* f) { oops_do(f, false); }
voidoops_do(OopClosure* f, bool allow_dead);
// All-in-one claiming of nmethods: returns true if the caller successfully claimed that
// nmethod.
booloops_do_try_claim();
// Loom support for following nmethods on the stack
voidfollow_nmethod(OopIterateClosure* cl);
// Class containing callbacks for the oops_do_process_weak/strong() methods
// below.
classOopsDoProcessor {
public:
// Process the oops of the given nmethod based on whether it has been called
// in a weak or strong processing context, i.e. apply either weak or strong
// work on it.
virtualvoiddo_regular_processing(nmethod* nm) = 0;
// Assuming that the oops of the given nmethod has already been its weak
// processing applied, apply the remaining strong processing part.
virtualvoiddo_remaining_strong_processing(nmethod* nm) = 0;
};
// The following two methods do the work corresponding to weak/strong nmethod
// processing.
voidoops_do_process_weak(OopsDoProcessor* p);
voidoops_do_process_strong(OopsDoProcessor* p);
staticvoidoops_do_marking_prologue();
staticvoidoops_do_marking_epilogue();
private:
ScopeDesc* scope_desc_in(address begin, address end);
address* orig_pc_addr(const frame* fr);
// used by jvmti to track if the load events has been reported
boolload_reported() const { return _load_reported; }
voidset_load_reported() { _load_reported = true; }
public:
// ScopeDesc retrieval operation
PcDesc* pc_desc_at(address pc) { returnfind_pc_desc(pc, false); }
// pc_desc_near returns the first PcDesc at or after the given pc.
PcDesc* pc_desc_near(address pc) { returnfind_pc_desc(pc, true); }
// ScopeDesc for an instruction
ScopeDesc* scope_desc_at(address pc);
ScopeDesc* scope_desc_near(address pc);
// copying of debugging information
voidcopy_scopes_pcs(PcDesc* pcs, int count);
voidcopy_scopes_data(address buffer, int size);
intorig_pc_offset() { return _orig_pc_offset; }
// Post successful compilation
voidpost_compiled_method(CompileTask* task);
// jvmti support:
voidpost_compiled_method_load_event(JvmtiThreadState* state = nullptr);
// verify operations
voidverify();
voidverify_scopes();
voidverify_interrupt_point(address interrupt_point, bool is_inline_cache);
// Disassemble this nmethod with additional debug information, e.g. information about blocks.
voiddecode2(outputStream* st) const;
voidprint_constant_pool(outputStream* st);
// Avoid hiding of parent's 'decode(outputStream*)' method.
voiddecode(outputStream* st) const { decode2(st); } // just delegate here.
// printing support
voidprint_on_impl(outputStream* st) const;
voidprint_code();
voidprint_value_on_impl(outputStream* st) const;
#if defined(SUPPORT_DATA_STRUCTS)
// print output in opt build for disassembler library
voidprint_relocations() PRODUCT_RETURN;
voidprint_pcs_on(outputStream* st);
voidprint_scopes() { print_scopes_on(tty); }
voidprint_scopes_on(outputStream* st) PRODUCT_RETURN;
voidprint_handler_table();
voidprint_nul_chk_table();
voidprint_recorded_oop(int log_n, int index);
voidprint_recorded_oops();
voidprint_recorded_metadata();
voidprint_oops(outputStream* st); // oops from the underlying CodeBlob.
voidprint_metadata(outputStream* st); // metadata in metadata pool.
#else
voidprint_pcs_on(outputStream* st) { return; }
#endif
voidprint_calls(outputStream* st) PRODUCT_RETURN;
staticvoidprint_statistics() PRODUCT_RETURN;
voidmaybe_print_nmethod(const DirectiveSet* directive);
voidprint_nmethod(bool print_code);
voidprint_on_with_msg(outputStream* st, constchar* msg) const;
// Logging
voidlog_identity(xmlStream* log) const;
voidlog_new_nmethod() const;
voidlog_state_change(constchar* reason) const;
// Prints block-level comments, including nmethod specific block labels:
voidprint_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels=true) const;
constchar* nmethod_section_label(address pos) const;
// returns whether this nmethod has code comments.
boolhas_code_comment(address begin, address end);
// Prints a comment for one native instruction (reloc info, pc desc)
voidprint_code_comment_on(outputStream* st, int column, address begin, address end);
// tells if this compiled method is dependent on the given changes,
// and the changes have invalidated it
boolcheck_dependency_on(DepChange& changes);
// Fast breakpoint support. Tells if this compiled method is
// dependent on the given method. Returns true if this nmethod
// corresponds to the given method as well.
boolis_dependent_on_method(Method* dependee);
// JVMTI's GetLocalInstance() support
ByteSize native_receiver_sp_offset() {
assert(is_native_method(), "sanity");
return _native_receiver_sp_offset;
}
ByteSize native_basic_lock_sp_offset() {
assert(is_native_method(), "sanity");
return _native_basic_lock_sp_offset;
}
// support for code generation
static ByteSize osr_entry_point_offset() { returnbyte_offset_of(nmethod, _osr_entry_point); }
static ByteSize state_offset() { returnbyte_offset_of(nmethod, _state); }
voidmetadata_do(MetadataClosure* f);
address call_instruction_address(address pc) const;
voidmake_deoptimized();
voidfinalize_relocations();
classVptr : publicCodeBlob::Vptr {
voidprint_on(const CodeBlob* instance, outputStream* st) constoverride {
ttyLocker ttyl;
instance->as_nmethod()->print_on_impl(st);
}
voidprint_value_on(const CodeBlob* instance, outputStream* st) constoverride {
instance->as_nmethod()->print_value_on_impl(st);
}
};
staticconst Vptr _vpntr;
};