695 {
696 const bool bare_instruction_payloads = FLAG_precompiled_mode;
697
698
699 intptr_t alignment_padding = 0;
701 &alignment_padding)) {
702 return;
703 }
704
705 intptr_t text_offset = 0;
706#if defined(DART_PRECOMPILER)
707
708
709
710 V8SnapshotProfileWriter::ObjectId parent_id(
offset_space_, text_offset);
711#endif
712
713
714
718
719
720 text_offset +=
722 : Image::kNoInstructionsSection);
723
724 text_offset +=
Align(Image::kHeaderSize, 0, text_offset);
726
727#if defined(DART_PRECOMPILER)
729 ASSERT(instructions_symbol !=
nullptr);
731 ASSERT(instructions_label > 0);
733 ASSERT(bss_symbol !=
nullptr);
736
739 instructions_symbol);
743 }
744
745 if (FLAG_precompiled_mode) {
746 const intptr_t section_header_length =
748
749
750
751 const intptr_t section_payload_length =
752 bare_instruction_payloads
754 : 0;
755 const intptr_t section_size =
757 section_payload_length);
758
759 const V8SnapshotProfileWriter::ObjectId
id(
offset_space_, text_offset);
762 instructions_symbol);
764 section_size - section_payload_length);
765 const intptr_t element_offset = id.nonce() - parent_id.nonce();
767 parent_id,
769
770
771 if (bare_instruction_payloads) {
773 }
774 }
775
776
777 text_offset +=
779
780
782
783 text_offset += Relocation(text_offset, instructions_label, bss_label);
784
785 text_offset += RelocatedAddress(text_offset, instructions_label);
786
787 text_offset += Relocation(text_offset, instructions_label,
789
790 const intptr_t section_contents_alignment =
791 bare_instruction_payloads
794 const intptr_t alignment_offset =
796 const intptr_t expected_size =
797 bare_instruction_payloads
800 text_offset +=
801 Align(section_contents_alignment, alignment_offset, text_offset);
803 }
804#endif
805
806#if !defined(EMIT_UNWIND_DIRECTIVES_PER_FUNCTION)
808#endif
809
810#if defined(DART_PRECOMPILER)
812#endif
813
814
815 uint8_t padding_bytes[64];
816 memset(&padding_bytes[0], 0, sizeof(padding_bytes));
817
821 const bool is_trampoline =
data.trampoline_bytes !=
nullptr;
822 const bool is_padding =
823 data.trampoline_bytes ==
nullptr &&
data.trampoline_length != 0;
825
826#if defined(DART_PRECOMPILER)
827 const char* object_name = namer_.SnapshotNameFor(
data);
828
830 const V8SnapshotProfileWriter::ObjectId
id(
offset_space_, text_offset);
834 const intptr_t
size = (is_trampoline || is_padding)
835 ?
data.trampoline_length
839 const intptr_t element_offset = id.nonce() - parent_id.nonce();
841 parent_id,
843 }
844#endif
845
846 if (is_trampoline) {
848 delete[]
data.trampoline_bytes;
849 data.trampoline_bytes =
nullptr;
850 continue;
851 }
852
853 if (is_padding) {
855 continue;
856 }
857
858 const intptr_t instr_start = text_offset;
859 const auto& insns = *
data.insns_;
860
861
862
863
864 if (!bare_instruction_payloads) {
865 NoSafepointScope no_safepoint;
866
867
869 text_offset +=
WriteFixed(insns.untag()->size_and_flags_);
870 text_offset +=
873 text_offset);
874 }
875
878
879#if defined(DART_PRECOMPILER)
881
882
883 AddCodeSymbol(
code, object_name, text_offset);
884#endif
885
886#if defined(EMIT_UNWIND_DIRECTIVES_PER_FUNCTION)
888#endif
889
890 {
891 NoSafepointScope no_safepoint;
892
893
894
895
896 auto const payload_start =
897 reinterpret_cast<const uint8_t*>(insns.PayloadStart());
898
899
901 const uword payload_size = insns.Size();
902 auto const payload_end = payload_start + payload_size;
903 auto cursor = payload_start;
904#if defined(DART_PRECOMPILER)
905 descriptors =
code.pc_descriptors();
906 PcDescriptors::Iterator iterator(
907 descriptors, UntaggedPcDescriptors::kBSSRelocation);
908 while (iterator.MoveNext()) {
909
910 ASSERT(FLAG_precompiled_mode);
911 auto const next_reloc_offset = iterator.PcOffset();
912 auto const next_reloc_address = payload_start + next_reloc_offset;
913
914
917 text_offset +=
WriteBytes(cursor, next_reloc_address - cursor);
918
919
920
921 const auto target_offset =
923 next_reloc_address);
924 text_offset += Relocation(text_offset, instructions_label, text_offset,
925 bss_label, target_offset);
927 }
928#endif
929 text_offset +=
WriteBytes(cursor, payload_end - cursor);
930 }
931
932
933
934
935 const intptr_t alignment =
936 bare_instruction_payloads
940
942#if defined(EMIT_UNWIND_DIRECTIVES_PER_FUNCTION)
944#endif
945 }
946
947
948
949
950 ASSERT(bare_instruction_payloads ||
955
957
958#if !defined(EMIT_UNWIND_DIRECTIVES_PER_FUNCTION)
960#endif
961
963}
virtual void FrameUnwindEpilogue()=0
intptr_t WriteFixed(T value)
virtual intptr_t Align(intptr_t alignment, intptr_t offset, intptr_t position)=0
virtual void FrameUnwindPrologue()=0
intptr_t AlignWithBreakInstructions(intptr_t alignment, intptr_t offset)
virtual void ExitSection(ProgramSection name, bool vm, intptr_t size)=0
static constexpr intptr_t kTextAlignment
virtual bool EnterSection(ProgramSection name, bool vm, intptr_t alignment, intptr_t *alignment_padding=nullptr)=0
static const char * SectionSymbol(ProgramSection section, bool vm)
static constexpr intptr_t kPayloadAlignment
void AttributeReferenceTo(const ObjectId &from_object_id, const Reference &reference, const ObjectId &to_object_id)
void SetObjectTypeAndName(const ObjectId &object_id, const char *type, const char *name)
void AddRoot(const ObjectId &object_id, const char *name=nullptr)
static word InstanceSize()
static const word kNonBarePayloadAlignment
static const word kBarePayloadAlignment
static constexpr intptr_t kOldObjectAlignmentOffset
static Reference Element(intptr_t offset)