5 #ifndef V8_OBJECTS_CODE_H_ 6 #define V8_OBJECTS_CODE_H_ 8 #include "src/contexts.h" 9 #include "src/handler-table.h" 10 #include "src/objects.h" 11 #include "src/objects/fixed-array.h" 12 #include "src/objects/heap-object.h" 15 #include "src/objects/object-macros.h" 22 class CodeDataContainer;
25 namespace interpreter {
37 #define CODE_KIND_LIST(V) \ 38 V(OPTIMIZED_FUNCTION) \ 44 V(WASM_TO_JS_FUNCTION) \ 45 V(JS_TO_WASM_FUNCTION) \ 46 V(WASM_INTERPRETER_ENTRY) \ 50 #define DEFINE_CODE_KIND_ENUM(name) name, 51 CODE_KIND_LIST(DEFINE_CODE_KIND_ENUM)
52 #undef DEFINE_CODE_KIND_ENUM 56 static const char* Kind2String(Kind kind);
58 #ifdef ENABLE_DISASSEMBLER 59 const char* GetName(
Isolate* isolate)
const;
60 void Disassemble(
const char* name, std::ostream& os,
61 Address current_pc = kNullAddress);
66 inline int raw_instruction_size()
const;
67 inline void set_raw_instruction_size(
int value);
74 inline int InstructionSize()
const;
75 int OffHeapInstructionSize()
const;
78 DECL_ACCESSORS2(relocation_info,
ByteArray)
81 void ClearEmbeddedObjects(
Heap* heap);
84 DECL_ACCESSORS2(deoptimization_data,
FixedArray)
88 DECL_ACCESSORS(source_position_table,
Object)
96 inline void set_stub_key(
uint32_t key);
100 inline Object* next_code_link()
const;
101 inline void set_next_code_link(
Object* value);
105 inline int constant_pool_offset()
const;
106 inline void set_constant_pool_offset(
int offset);
109 inline ByteArray unchecked_relocation_info()
const;
111 inline int relocation_size()
const;
114 inline Kind kind()
const;
116 inline bool is_stub()
const;
117 inline bool is_optimized_code()
const;
118 inline bool is_wasm_code()
const;
121 inline bool is_interpreter_trampoline_builtin()
const;
125 inline bool checks_optimization_marker()
const;
128 inline bool has_tagged_params()
const;
132 inline bool is_turbofanned()
const;
136 inline bool can_have_weak_objects()
const;
137 inline void set_can_have_weak_objects(
bool value);
142 inline bool is_construct_stub()
const;
143 inline void set_is_construct_stub(
bool value);
148 inline int builtin_index()
const;
149 inline void set_builtin_index(
int id);
150 inline bool is_builtin()
const;
152 inline bool has_safepoint_info()
const;
156 inline int stack_slots()
const;
160 inline int safepoint_table_offset()
const;
161 inline void set_safepoint_table_offset(
int offset);
165 inline int handler_table_offset()
const;
166 inline void set_handler_table_offset(
int offset);
170 inline bool marked_for_deoptimization()
const;
171 inline void set_marked_for_deoptimization(
bool flag);
176 inline bool embedded_objects_cleared()
const;
177 inline void set_embedded_objects_cleared(
bool flag);
181 inline bool deopt_already_counted()
const;
182 inline void set_deopt_already_counted(
bool flag);
188 inline void set_is_promise_rejection(
bool flag);
194 inline void set_is_exception_caught(
bool flag);
198 inline bool is_off_heap_trampoline()
const;
201 inline Address constant_pool()
const;
213 inline void WipeOutHeader();
217 inline void clear_padding();
220 inline void initialize_flags(Kind kind,
bool has_unwinding_info,
221 bool is_turbofanned,
int stack_slots,
222 bool is_off_heap_trampoline);
225 static inline Code GetCodeFromTargetAddress(
Address address);
228 static inline Object* GetObjectFromEntryAddress(
Address location_of_address);
231 static inline Object* GetObjectFromCodeEntry(
Address code_entry);
234 inline Address raw_instruction_start()
const;
239 inline Address InstructionStart()
const;
240 Address OffHeapInstructionStart()
const;
243 inline Address raw_instruction_end()
const;
248 inline Address InstructionEnd()
const;
249 Address OffHeapInstructionEnd()
const;
253 inline int body_size()
const;
257 inline int SizeIncludingMetadata()
const;
260 inline byte* relocation_start()
const;
263 inline byte* relocation_end()
const;
296 inline bool has_unwinding_info()
const;
299 inline int unwinding_info_size()
const;
300 inline void set_unwinding_info_size(
int value);
303 inline Address unwinding_info_start()
const;
306 inline Address unwinding_info_end()
const;
312 inline bool contains(
Address pc);
316 void Relocate(intptr_t delta);
323 static inline void CopyRelocInfoToByteArray(
ByteArray dest,
328 void FlushICache()
const;
331 static int SizeFor(
int body_size) {
332 DCHECK_SIZE_TAG_ALIGNED(body_size);
333 return RoundUp(kHeaderSize + body_size, kCodeAlignment);
338 inline int ExecutableSize()
const;
343 inline int CodeSize()
const;
348 void PrintDeoptLocation(FILE* out,
const char* str,
Address pc);
351 void SetMarkedForDeoptimization(
const char* reason);
353 inline HandlerTable::CatchPrediction GetBuiltinCatchPrediction();
356 enum VerifyMode { kNoContextSpecificPointers, kNoContextRetainingPointers };
357 void VerifyEmbeddedObjects(
Isolate* isolate,
358 VerifyMode mode = kNoContextRetainingPointers);
361 bool IsIsolateIndependent(
Isolate* isolate);
363 inline bool CanContainWeakObjects();
367 static inline bool IsWeakObjectInOptimizedCode(
HeapObject*
object);
375 #define CODE_FIELDS(V) \ 376 V(kRelocationInfoOffset, kTaggedSize) \ 377 V(kDeoptimizationDataOffset, kTaggedSize) \ 378 V(kSourcePositionTableOffset, kTaggedSize) \ 379 V(kCodeDataContainerOffset, kTaggedSize) \ 384 V(kInstructionSizeOffset, kIntSize) \ 385 V(kFlagsOffset, kIntSize) \ 386 V(kSafepointTableOffsetOffset, kIntSize) \ 387 V(kHandlerTableOffsetOffset, kIntSize) \ 388 V(kStubKeyOffset, kIntSize) \ 389 V(kConstantPoolOffset, FLAG_enable_embedded_constant_pool ? kIntSize : 0) \ 390 V(kBuiltinIndexOffset, kIntSize) \ 393 V(kHeaderPaddingStart, CODE_POINTER_PADDING(kHeaderPaddingStart)) \ 396 DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, CODE_FIELDS)
399 inline int GetUnwindingInfoSizeOffset()
const;
404 #define CODE_FLAGS_BIT_FIELDS(V, _) \ 405 V(HasUnwindingInfoField, bool, 1, _) \ 406 V(KindField, Kind, 5, _) \ 407 V(IsTurbofannedField, bool, 1, _) \ 408 V(StackSlotsField, int, 24, _) \ 409 V(IsOffHeapTrampoline, bool, 1, _) 410 DEFINE_BIT_FIELDS(CODE_FLAGS_BIT_FIELDS)
411 #undef CODE_FLAGS_BIT_FIELDS 412 static_assert(NUMBER_OF_KINDS <= KindField::kMax,
"Code::KindField size");
413 static_assert(IsOffHeapTrampoline::kNext <= 32,
414 "Code::flags field exhausted");
417 #define CODE_KIND_SPECIFIC_FLAGS_BIT_FIELDS(V, _) \ 418 V(MarkedForDeoptimizationField, bool, 1, _) \ 419 V(EmbeddedObjectsClearedField, bool, 1, _) \ 420 V(DeoptAlreadyCountedField, bool, 1, _) \ 421 V(CanHaveWeakObjectsField, bool, 1, _) \ 422 V(IsConstructStubField, bool, 1, _) \ 423 V(IsPromiseRejectionField, bool, 1, _) \ 424 V(IsExceptionCaughtField, bool, 1, _) 425 DEFINE_BIT_FIELDS(CODE_KIND_SPECIFIC_FLAGS_BIT_FIELDS)
426 #undef CODE_KIND_SPECIFIC_FLAGS_BIT_FIELDS 427 static_assert(IsExceptionCaughtField::kNext <= 32,
"KindSpecificFlags full");
430 static const int kMarkedForDeoptimizationBit =
431 MarkedForDeoptimizationField::kShift;
433 static const int kArgumentsBits = 16;
435 static const int kMaxArguments = (1 << kArgumentsBits) - 2;
440 bool is_promise_rejection()
const;
441 bool is_exception_caught()
const;
456 DISALLOW_HEAP_ALLOCATION(no_gc);
467 DECL_ACCESSORS(next_code_link,
Object)
468 DECL_INT_ACCESSORS(kind_specific_flags)
472 inline void clear_padding();
481 #define CODE_DATA_FIELDS(V) \ 483 V(kPointerFieldsStrongEndOffset, 0) \ 484 V(kNextCodeLinkOffset, kTaggedSize) \ 485 V(kPointerFieldsWeakEndOffset, 0) \ 487 V(kKindSpecificFlagsOffset, kIntSize) \ 488 V(kUnalignedSize, OBJECT_POINTER_PADDING(kUnalignedSize)) \ 492 DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, CODE_DATA_FIELDS)
493 #undef CODE_DATA_FIELDS 503 NEVER_READ_ONLY_SPACE
506 #define DEFINE_CODE_KIND_ENUM(name) name, 507 CODE_KIND_LIST(DEFINE_CODE_KIND_ENUM)
508 #undef DEFINE_CODE_KIND_ENUM 509 INTERPRETED_FUNCTION,
513 static const char* Kind2String(Kind kind);
516 int SourceStatementPosition(
int offset);
519 inline Address raw_instruction_start();
524 inline Address InstructionStart();
527 inline Address raw_instruction_end();
532 inline Address InstructionEnd();
535 inline int raw_instruction_size();
542 inline int InstructionSize();
545 inline ByteArray source_position_table();
547 inline Object* stack_frame_cache();
550 void DropStackFrameCache();
553 inline int SizeIncludingMetadata();
556 inline bool contains(
Address pc);
563 inline int ExecutableSize();
566 inline Code GetCode();
571 static const int kMaxLoopNestingMarker = 6;
599 enum DependencyGroup {
607 kPrototypeCheckGroup,
610 kPropertyCellChangedGroup,
616 kInitialMapChangedGroup,
619 kAllocationSiteTenuringChangedGroup,
622 kAllocationSiteTransitionChangedGroup
628 DependencyGroup group);
630 void DeoptimizeDependentCodeGroup(
Isolate* isolate, DependencyGroup group);
632 bool MarkCodeForDeoptimization(
Isolate* isolate, DependencyGroup group);
635 inline DependencyGroup group();
641 static const char* DependencyGroupName(DependencyGroup group);
655 DependencyGroup group,
662 static int Grow(
int number_of_entries) {
663 if (number_of_entries < 5)
return number_of_entries + 1;
664 return number_of_entries * 5 / 4;
667 static const int kGroupCount = kAllocationSiteTransitionChangedGroup + 1;
668 static const int kNextLinkIndex = 0;
669 static const int kFlagsIndex = 1;
670 static const int kCodesStartIndex = 2;
673 inline void set_count(
int value);
675 inline void clear_at(
int i);
676 inline void copy(
int from,
int to);
679 inline void set_flags(
int flags);
680 class GroupField :
public BitField<int, 0, 3> {};
681 class CountField :
public BitField<int, 3, 27> {};
682 STATIC_ASSERT(kGroupCount <= GroupField::kMax + 1);
689 kNoAgeBytecodeAge = 0,
690 kQuadragenarianBytecodeAge,
691 kQuinquagenarianBytecodeAge,
692 kSexagenarianBytecodeAge,
693 kSeptuagenarianBytecodeAge,
694 kOctogenarianBytecodeAge,
695 kAfterLastBytecodeAge,
696 kFirstBytecodeAge = kNoAgeBytecodeAge,
697 kLastBytecodeAge = kAfterLastBytecodeAge - 1,
698 kBytecodeAgeCount = kAfterLastBytecodeAge - kFirstBytecodeAge - 1,
699 kIsOldBytecodeAge = kSexagenarianBytecodeAge
702 static int SizeFor(
int length) {
703 return OBJECT_POINTER_ALIGN(kHeaderSize + length);
707 inline byte
get(
int index);
708 inline void set(
int index, byte value);
711 inline Address GetFirstBytecodeAddress();
714 inline int frame_size()
const;
715 inline void set_frame_size(
int frame_size);
718 inline int register_count()
const;
721 inline int parameter_count()
const;
722 inline void set_parameter_count(
int number_of_parameters);
728 inline void set_incoming_new_target_or_generator_register(
732 inline int interrupt_budget()
const;
733 inline void set_interrupt_budget(
int interrupt_budget);
736 inline int osr_loop_nesting_level()
const;
737 inline void set_osr_loop_nesting_level(
int depth);
740 inline Age bytecode_age()
const;
741 inline void set_bytecode_age(Age age);
747 DECL_ACCESSORS2(handler_table,
ByteArray)
751 DECL_ACCESSORS(source_position_table,
Object)
754 inline void ClearFrameCacheFromSourcePositionTable();
759 inline int BytecodeArraySize();
761 inline int raw_instruction_size();
765 inline int SizeIncludingMetadata();
768 int SourceStatementPosition(
int offset);
773 void Disassemble(std::ostream& os);
783 inline void clear_padding();
786 #define BYTECODE_ARRAY_FIELDS(V) \ 788 V(kConstantPoolOffset, kTaggedSize) \ 789 V(kHandlerTableOffset, kTaggedSize) \ 790 V(kSourcePositionTableOffset, kTaggedSize) \ 791 V(kFrameSizeOffset, kIntSize) \ 792 V(kParameterSizeOffset, kIntSize) \ 793 V(kIncomingNewTargetOrGeneratorRegisterOffset, kIntSize) \ 794 V(kInterruptBudgetOffset, kIntSize) \ 795 V(kOSRNestingLevelOffset, kCharSize) \ 796 V(kBytecodeAgeOffset, kCharSize) \ 800 DEFINE_FIELD_OFFSET_CONSTANTS(FixedArrayBase::kHeaderSize,
801 BYTECODE_ARRAY_FIELDS)
802 #undef BYTECODE_ARRAY_FIELDS 805 static const int kMaxSize = 512 * MB;
807 static const int kMaxLength = kMaxSize - kHeaderSize;
823 static const int kTranslationByteArrayIndex = 0;
824 static const int kInlinedFunctionCountIndex = 1;
825 static const int kLiteralArrayIndex = 2;
826 static const int kOsrBytecodeOffsetIndex = 3;
827 static const int kOsrPcOffsetIndex = 4;
828 static const int kOptimizationIdIndex = 5;
829 static const int kSharedFunctionInfoIndex = 6;
830 static const int kInliningPositionsIndex = 7;
831 static const int kFirstDeoptEntryIndex = 8;
834 static const int kBytecodeOffsetRawOffset = 0;
835 static const int kTranslationIndexOffset = 1;
836 static const int kPcOffset = 2;
837 static const int kDeoptEntrySize = 3;
840 #define DECL_ELEMENT_ACCESSORS(name, type) \ 841 inline type name() const; \ 842 inline void Set##name(type value); 844 DECL_ELEMENT_ACCESSORS(TranslationByteArray,
ByteArray)
845 DECL_ELEMENT_ACCESSORS(InlinedFunctionCount,
Smi)
846 DECL_ELEMENT_ACCESSORS(LiteralArray,
FixedArray)
847 DECL_ELEMENT_ACCESSORS(OsrBytecodeOffset,
Smi)
848 DECL_ELEMENT_ACCESSORS(OsrPcOffset,
Smi)
849 DECL_ELEMENT_ACCESSORS(OptimizationId,
Smi)
853 #undef DECL_ELEMENT_ACCESSORS 856 #define DECL_ENTRY_ACCESSORS(name, type) \ 857 inline type name(int i) const; \ 858 inline void Set##name(int i, type value); 860 DECL_ENTRY_ACCESSORS(BytecodeOffsetRaw,
Smi)
861 DECL_ENTRY_ACCESSORS(TranslationIndex,
Smi)
862 DECL_ENTRY_ACCESSORS(Pc,
Smi)
864 #undef DECL_ENTRY_ACCESSORS 868 inline void SetBytecodeOffset(
int i,
BailoutId value);
870 inline int DeoptCount();
872 static const int kNotInlinedIndex = -1;
880 PretenureFlag pretenure);
887 #ifdef ENABLE_DISASSEMBLER 888 void DeoptimizationDataPrint(std::ostream& os);
892 static int IndexForEntry(
int i) {
893 return kFirstDeoptEntryIndex + (
i * kDeoptEntrySize);
896 static int LengthFor(
int entry_count) {
return IndexForEntry(entry_count); }
903 DECL_ACCESSORS2(source_position_table,
ByteArray)
909 #define SOURCE_POSITION_TABLE_WITH_FRAME_FIELDS(V) \ 910 V(kSourcePositionTableIndex, kTaggedSize) \ 911 V(kStackFrameCacheIndex, kTaggedSize) \ 915 DEFINE_FIELD_OFFSET_CONSTANTS(Struct::kHeaderSize,
916 SOURCE_POSITION_TABLE_WITH_FRAME_FIELDS)
917 #undef SOURCE_POSITION_TABLE_WITH_FRAME_FIELDS 926 #include "src/objects/object-macros-undef.h" 928 #endif // V8_OBJECTS_CODE_H_