Lines Matching defs:code
2 // Use of this source code is governed by a BSD-style license that can be
13 #include "src/snapshot/code-serializer.h"
17 #include "src/wasm/code-space-access.h"
21 #include "src/wasm/wasm-code-manager.h"
193 constexpr size_t kHeaderSize = sizeof(size_t); // total code size
195 constexpr size_t kCodeHeaderSize = sizeof(uint8_t) + // code kind
199 sizeof(int) + // offset of code comments
203 sizeof(int) + // code size
207 sizeof(WasmCode::Kind) + // code kind
308 size_t NativeModuleSerializer::MeasureCode(const WasmCode* code) const {
309 if (code == nullptr) return sizeof(uint8_t);
310 DCHECK_EQ(WasmCode::kWasmFunction, code->kind());
311 if (code->tier() != ExecutionTier::kTurbofan) {
314 return kCodeHeaderSize + code->instructions().size() +
315 code->reloc_info().size() + code->source_positions().size() +
316 code->protected_instructions_data().size();
321 for (WasmCode* code : code_table_) {
322 size += MeasureCode(code);
335 void NativeModuleSerializer::WriteCode(const WasmCode* code, Writer* writer) {
336 if (code == nullptr) {
341 DCHECK_EQ(WasmCode::kWasmFunction, code->kind());
342 // Only serialize TurboFan code, as Liftoff code can contain breakpoints or
344 if (code->tier() != ExecutionTier::kTurbofan) {
350 NativeModule* native_module = code->native_module();
353 native_module->module(), code->index())];
362 // Write the size of the entire code section, followed by the code header.
363 writer->Write(code->constant_pool_offset());
364 writer->Write(code->safepoint_table_offset());
365 writer->Write(code->handler_table_offset());
366 writer->Write(code->code_comments_offset());
367 writer->Write(code->unpadded_binary_size());
368 writer->Write(code->stack_slots());
369 writer->Write(code->raw_tagged_parameter_slots_for_serialization());
370 writer->Write(code->instructions().length());
371 writer->Write(code->reloc_info().length());
372 writer->Write(code->source_positions().length());
373 writer->Write(code->protected_instructions_data().length());
374 writer->Write(code->kind());
375 writer->Write(code->tier());
377 // Get a pointer to the destination buffer, to hold relocated code.
380 size_t code_size = code->instructions().size();
382 // Write the reloc info, source positions, and protected code.
383 writer->WriteVector(code->reloc_info());
384 writer->WriteVector(code->source_positions());
385 writer->WriteVector(code->protected_instructions_data());
390 // buffer if necessary so we can relocate the serialized code.
400 memcpy(code_start, code->instructions().begin(), code_size);
401 // Relocate the code.
407 RelocIterator orig_iter(code->instructions(), code->reloc_info(),
408 code->constant_pool(), mask);
410 {code_start, code->instructions().size()}, code->reloc_info(),
411 reinterpret_cast<Address>(code_start) + code->constant_pool_offset(),
437 Address offset = orig_target - code->instruction_start();
445 // If we copied to an aligned buffer, copy code into serialized buffer.
457 for (WasmCode* code : code_table_) {
458 if (code && code->tier() == ExecutionTier::kTurbofan) {
459 DCHECK(IsAligned(code->instructions().size(), kCodeAlignment));
460 total_code_size += code->instructions().size();
465 for (WasmCode* code : code_table_) {
466 WriteCode(code, writer);
471 // Make sure that the serialized total code size was correct.
503 std::unique_ptr<WasmCode> code;
665 // code bytes), but also not too many (<=100 batches).
675 if (!unit.code) continue;
676 batch_size += unit.code->instructions().size();
686 // We should have read the expected amount of code now, and should have fully
687 // utilized the allocated code space.
735 // Allocate the next code space. Don't allocate more than 90% of
758 unit.code = native_module_->AddDeserializedCode(
769 memcpy(unit.code->instructions().begin(), unit.src_code_buffer.begin(),
772 // Relocate the code.
778 for (RelocIterator iter(unit.code->instructions(), unit.code->reloc_info(),
779 unit.code->constant_pool(), mask);
807 Address target = unit.code->instruction_start() + offset;
817 // Finally, flush the icache for that code.
818 FlushInstructionCache(unit.code->instructions().begin(),
819 unit.code->instructions().size());
827 codes.emplace_back(std::move(unit).code);
913 // Log the code within the generated module for profiling.