23 static_cast<uint32_t
>(address -
reinterpret_cast<Address>(
RawCode()));
31 return o < desc.end_offset;
43 if (isolate->embedded_blob_code() ==
nullptr)
return false;
47 return isolate->is_short_builtin_calls_enabled() &&
55 if (isolate->embedded_blob_code() ==
nullptr)
return false;
59 if (d.IsInCodeRange(address)) {
60 *hashable_address = d.AddressForHashing(address);
64 if (isolate->is_short_builtin_calls_enabled()) {
66 if (d.IsInCodeRange(address)) {
67 *hashable_address = d.AddressForHashing(address);
83 if (isolate->is_short_builtin_calls_enabled() &&
88#ifdef V8_COMPRESS_POINTERS_IN_SHARED_CAGE
106 Isolate* isolate, uint8_t** code, uint32_t* code_size, uint8_t** data,
107 uint32_t* data_size) {
115 const uint32_t alignment =
118 void*
const requested_allocation_code_address =
120 const uint32_t allocation_code_size =
RoundUp(d.code_size(), alignment);
121 uint8_t* allocated_code_bytes =
static_cast<uint8_t*
>(
AllocatePages(
122 page_allocator, requested_allocation_code_address, allocation_code_size,
126 void*
const requested_allocation_data_address =
128 const uint32_t allocation_data_size =
RoundUp(d.data_size(), alignment);
129 uint8_t* allocated_data_bytes =
static_cast<uint8_t*
>(
AllocatePages(
130 page_allocator, requested_allocation_data_address, allocation_data_size,
142 std::memcpy(allocated_code_bytes, d.code(), d.code_size());
143 if (
v8_flags.experimental_flush_embedded_blob_icache) {
149 std::memcpy(allocated_data_bytes, d.data(), d.data_size());
153 *code = allocated_code_bytes;
154 *code_size = d.code_size();
155 *data = allocated_data_bytes;
156 *data_size = d.data_size();
163 uint8_t* code, uint32_t code_size, uint8_t* data, uint32_t data_size) {
165 const uint32_t page_size =
174 static const int kRelocMask =
175 RelocInfo::ModeMask(RelocInfo::CODE_TARGET) |
176 RelocInfo::ModeMask(RelocInfo::RELATIVE_CODE_TARGET);
178 static_assert(Builtins::kAllBuiltinsAreIsolateIndependent);
179 for (
Builtin builtin = Builtins::kFirst; builtin <= Builtins::kLast;
185#if defined(V8_TARGET_ARCH_X64) || defined(V8_TARGET_ARCH_ARM64) || \
186 defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_IA32) || \
187 defined(V8_TARGET_ARCH_S390X) || defined(V8_TARGET_ARCH_RISCV64) || \
188 defined(V8_TARGET_ARCH_LOONG64) || defined(V8_TARGET_ARCH_RISCV32)
193 while (!on_heap_it.done()) {
194 DCHECK(!off_heap_it.done());
200 CHECK(Builtins::IsIsolateIndependentBuiltin(target_code));
203 off_heap_it.rinfo()->set_off_heap_target_address(
204 blob->InstructionStartOf(target_code->builtin_id()));
209 DCHECK(off_heap_it.done());
214 CHECK(on_heap_it.done());
215 CHECK(off_heap_it.done());
220void EnsureRelocatable(Tagged<Code> code) {
221 if (code->relocation_size() == 0)
return;
228 for (RelocIterator it(code); !it.done(); it.next()) {
229 CHECK_EQ(it.rinfo()->rmode(), RelocInfo::CONST_POOL);
237 Builtins* builtins = isolate->builtins();
240 std::vector<struct LayoutDescription> layout_descriptions(
kTableSize);
241 std::vector<struct BuiltinLookupEntry> offset_descriptions(
kTableSize);
243 bool saw_unsafe_builtin =
false;
244 uint32_t raw_code_size = 0;
245 uint32_t raw_data_size = 0;
248 std::vector<Builtin> reordered_builtins;
255 std::vector<uint32_t> builtin_sizes;
258 uint32_t instruction_size =
259 static_cast<uint32_t
>(code->instruction_size());
261 builtin_sizes.push_back(padding_size);
264 v8_flags.turbo_profiling_input.value(), builtin_sizes);
271 if (reordered_builtins.empty()) {
272 builtin =
static_cast<Builtin>(embedded_index);
274 builtin = reordered_builtins[embedded_index];
279 if (!code->IsIsolateIndependent(isolate)) {
280 saw_unsafe_builtin =
true;
281 fprintf(stderr,
"%s is not isolate-independent.\n",
285 uint32_t instruction_size =
static_cast<uint32_t
>(code->instruction_size());
289 const int builtin_id =
static_cast<int>(
builtin);
302 offset_descriptions[embedded_index];
303 offset_desc.end_offset = raw_code_size;
304 offset_desc.builtin_id =
static_cast<uint32_t
>(
builtin);
309 "One or more builtins marked as isolate-independent either contains "
310 "isolate-dependent code or aliases the off-heap trampoline register. "
311 "If in doubt, ask jgruber@");
315 const uint32_t blob_code_size =
RawCodeOffset() + raw_code_size;
316 uint8_t*
const blob_code =
new uint8_t[blob_code_size]();
321 const uint32_t blob_data_size =
FixedDataSize() + raw_data_size;
322 uint8_t*
const blob_data =
new uint8_t[blob_data_size]();
331 const size_t hash = isolate->HashIsolateForEmbeddedBlob();
337 sizeof(layout_descriptions[0]) * layout_descriptions.size());
343 sizeof(offset_descriptions[0]) * offset_descriptions.size());
354 layout_descriptions[
static_cast<int>(
builtin)].metadata_offset;
355 uint8_t* dst = raw_metadata_start +
offset;
358 std::memcpy(dst,
reinterpret_cast<uint8_t*
>(code->metadata_start()),
359 code->metadata_size());
372 layout_descriptions[
static_cast<int>(
builtin)].instruction_offset;
373 uint8_t* dst = raw_code_start +
offset;
376 std::memcpy(dst,
reinterpret_cast<uint8_t*
>(code->instruction_start()),
377 code->instruction_size());
380 EmbeddedData d(blob_code, blob_code_size, blob_data, blob_data_size);
383 FinalizeEmbeddedCodeTargets(isolate, &d);
388 const size_t data_hash = d.CreateEmbeddedBlobDataHash();
393 const size_t code_hash = d.CreateEmbeddedBlobCodeHash();
397 DCHECK_EQ(data_hash, d.CreateEmbeddedBlobDataHash());
398 DCHECK_EQ(data_hash, d.EmbeddedBlobDataHash());
399 DCHECK_EQ(code_hash, d.CreateEmbeddedBlobCodeHash());
400 DCHECK_EQ(code_hash, d.EmbeddedBlobCodeHash());
407 CHECK_EQ(d.InstructionSizeOf(builtin), code->instruction_size());
414 builtins->code(Builtin::kInterpreterEntryTrampolineForProfiling));
416 if (
v8_flags.serialization_statistics) d.PrintStatistics();
452 for (
int i = 0;
i < kCount;
i++) {
457 std::sort(&sizes[0], &sizes[kCount]);
459 const int k50th = kCount * 0.5;
460 const int k75th = kCount * 0.75;
461 const int k90th = kCount * 0.90;
462 const int k99th = kCount * 0.99;
464 PrintF(
"EmbeddedData:\n");
465 PrintF(
" Total size: %d\n",
469 PrintF(
" Instruction size (50th percentile): %d\n", sizes[k50th]);
470 PrintF(
" Instruction size (75th percentile): %d\n", sizes[k75th]);
471 PrintF(
" Instruction size (90th percentile): %d\n", sizes[k90th]);
472 PrintF(
" Instruction size (99th percentile): %d\n", sizes[k99th]);
virtual size_t AllocatePageSize()=0
V8_INLINE bool all_hash_matched() const
static BuiltinsCallGraph * Get()
std::vector< Builtin > SortBuiltins(const char *profiling_file, const std::vector< uint32_t > &builtin_size)
static constexpr int kBuiltinCount
static constexpr Builtin kFirst
static constexpr bool kAllBuiltinsAreIsolateIndependent
static constexpr bool IsBuiltinId(Builtin builtin)
static constexpr Builtin FromInt(int id)
static constexpr Builtin kLast
static V8_EXPORT_PRIVATE const char * name(Builtin builtin)
uint8_t * embedded_blob_code_copy() const
void PrintStatistics() const
static constexpr uint32_t FixedDataSize()
static EmbeddedData NewFromIsolate(Isolate *isolate)
bool IsInCodeRange(Address pc) const
const BuiltinLookupEntry * BuiltinLookupEntry(ReorderedBuiltinIndex index) const
Address InstructionStartOf(Builtin builtin) const
static constexpr uint32_t BuiltinLookupEntryTableOffset()
uint32_t InstructionSizeOf(Builtin builtin) const
uint32_t PaddedInstructionSizeOf(Builtin builtin) const
static EmbeddedData FromBlob()
static constexpr uint32_t LayoutDescriptionTableSize()
static constexpr uint32_t EmbeddedBlobDataHashOffset()
static constexpr uint32_t EmbeddedBlobCodeHashOffset()
size_t CreateEmbeddedBlobDataHash() const
static constexpr uint32_t IsolateHashOffset()
static constexpr uint32_t LayoutDescriptionTableOffset()
size_t CreateEmbeddedBlobCodeHash() const
static constexpr uint32_t RawMetadataOffset()
static constexpr int PadAndAlignCode(int size)
static constexpr uint32_t BuiltinLookupEntryTableSize()
const uint8_t * RawCode() const
Builtin TryLookupCode(Address address) const
uint32_t data_size() const
uint32_t code_size() const
Builtin GetBuiltinId(ReorderedBuiltinIndex embedded_index) const
static constexpr uint32_t kTableSize
static constexpr uint32_t IsolateHashSize()
static constexpr uint32_t EmbeddedBlobCodeHashSize()
static constexpr uint32_t EmbeddedBlobDataHashSize()
static constexpr int PadAndAlignData(int size)
static constexpr uint32_t RawCodeOffset()
static constexpr int kMetadataAlignment
static IsolateGroup * current()
CodeRange * GetCodeRange() const
static const uint8_t * CurrentEmbeddedBlobCode()
static void FreeOffHeapOffHeapInstructionStream(uint8_t *code, uint32_t code_size, uint8_t *data, uint32_t data_size)
static bool TryGetAddressForHashing(Isolate *isolate, Address address, uint32_t *hashable_address)
static void CreateOffHeapOffHeapInstructionStream(Isolate *isolate, uint8_t **code, uint32_t *code_size, uint8_t **data, uint32_t *data_size)
static Builtin TryLookupCode(Isolate *isolate, Address address)
static bool PcIsOffHeap(Isolate *isolate, Address pc)
V8_INLINE Address target_address()
#define V8_SHORT_BUILTIN_CALLS_BOOL
bool SetPermissions(v8::PageAllocator *page_allocator, void *address, size_t size, PageAllocator::Permission access)
v8::PageAllocator * GetPlatformPageAllocator()
V8_INLINE void ZapCode(Address addr, size_t size_in_bytes)
void PrintF(const char *format,...)
void * AllocatePages(v8::PageAllocator *page_allocator, void *hint, size_t size, size_t alignment, PageAllocator::Permission access)
void FlushInstructionCache(void *start, size_t size)
constexpr intptr_t kCodeAlignment
uint32_t ReorderedBuiltinIndex
constexpr size_t kMaxPCRelativeCodeRangeInMB
V8_EXPORT_PRIVATE FlagValues v8_flags
void FreePages(v8::PageAllocator *page_allocator, void *address, const size_t size)
uint32_t Checksum(base::Vector< const uint8_t > payload)
#define DCHECK_LE(v1, v2)
#define CHECK_IMPLIES(lhs, rhs)
#define CHECK_WITH_MSG(condition, message)
#define DCHECK_NOT_NULL(val)
#define CHECK_NOT_NULL(val)
#define DCHECK_GE(v1, v2)
#define CHECK_EQ(lhs, rhs)
#define DCHECK(condition)
#define DCHECK_LT(v1, v2)
#define DCHECK_EQ(v1, v2)
constexpr T RoundUp(T x, intptr_t m)
void * AlignedAddress(void *address, size_t alignment)
constexpr bool IsAligned(T value, U alignment)
uint32_t instruction_offset
uint32_t instruction_length