6
6
7
7
#include < iomanip>
8
8
9
+ #include " src/base/build_config.h"
9
10
#include " src/base/adapters.h"
10
11
#include " src/base/macros.h"
11
12
#include " src/base/platform/platform.h"
21
22
#include " src/snapshot/embedded/embedded-data.h"
22
23
#include " src/utils/ostreams.h"
23
24
#include " src/utils/vector.h"
25
+ #include " src/wasm/code-space-access.h"
24
26
#include " src/wasm/compilation-environment.h"
25
27
#include " src/wasm/function-compiler.h"
26
28
#include " src/wasm/jump-table-assembler.h"
@@ -45,6 +47,10 @@ namespace wasm {
45
47
46
48
using trap_handler::ProtectedInstructionData;
47
49
50
+ #if defined(V8_OS_MACOSX) && defined(V8_HOST_ARCH_ARM64)
51
+ thread_local int CodeSpaceWriteScope::code_space_write_nesting_level_ = 0 ;
52
+ #endif
53
+
48
54
base::AddressRegion DisjointAllocationPool::Merge (base::AddressRegion region) {
49
55
auto dest_it = regions_.begin ();
50
56
auto dest_end = regions_.end ();
@@ -626,6 +632,7 @@ void WasmCodeAllocator::FreeCode(Vector<WasmCode* const> codes) {
626
632
// Zap code area and collect freed code regions.
627
633
DisjointAllocationPool freed_regions;
628
634
size_t code_size = 0 ;
635
+ CODE_SPACE_WRITE_SCOPE
629
636
for (WasmCode* code : codes) {
630
637
ZapCode (code->instruction_start (), code->instructions ().size ());
631
638
FlushInstructionCache (code->instruction_start (),
@@ -731,6 +738,7 @@ CompilationEnv NativeModule::CreateCompilationEnv() const {
731
738
}
732
739
733
740
WasmCode* NativeModule::AddCodeForTesting (Handle <Code> code) {
741
+ CODE_SPACE_WRITE_SCOPE
734
742
return AddAndPublishAnonymousCode (code, WasmCode::kFunction );
735
743
}
736
744
@@ -742,6 +750,7 @@ void NativeModule::UseLazyStub(uint32_t func_index) {
742
750
if (!lazy_compile_table_) {
743
751
uint32_t num_slots = module_->num_declared_functions ;
744
752
WasmCodeRefScope code_ref_scope;
753
+ CODE_SPACE_WRITE_SCOPE
745
754
DCHECK_EQ (1 , code_space_data_.size ());
746
755
lazy_compile_table_ = CreateEmptyJumpTableInRegion (
747
756
JumpTableAssembler::SizeForNumberOfLazyFunctions (num_slots),
@@ -924,6 +933,7 @@ std::unique_ptr<WasmCode> NativeModule::AddCodeWithCodeSpace(
924
933
OwnedVector<byte> reloc_info;
925
934
if (desc.reloc_size > 0 ) {
926
935
reloc_info = OwnedVector<byte>::New (desc.reloc_size );
936
+ CODE_SPACE_WRITE_SCOPE
927
937
memcpy (reloc_info.start (), desc.buffer + desc.buffer_size - desc.reloc_size ,
928
938
desc.reloc_size );
929
939
}
@@ -1070,6 +1080,7 @@ WasmCode* NativeModule::AddDeserializedCode(
1070
1080
OwnedVector<const byte> reloc_info,
1071
1081
OwnedVector<const byte> source_position_table, WasmCode::Kind kind,
1072
1082
ExecutionTier tier) {
1083
+ // CodeSpaceWriteScope is provided by the caller.
1073
1084
Vector<uint8_t > dst_code_bytes =
1074
1085
code_allocator_.AllocateForCode (this , instructions.size ());
1075
1086
memcpy (dst_code_bytes.begin (), instructions.begin (), instructions.size ());
@@ -1126,6 +1137,7 @@ WasmCode* NativeModule::CreateEmptyJumpTableInRegion(
1126
1137
Vector<uint8_t > code_space =
1127
1138
code_allocator_.AllocateForCodeInRegion (this , jump_table_size, region);
1128
1139
DCHECK (!code_space.empty ());
1140
+ CODE_SPACE_WRITE_SCOPE
1129
1141
ZapCode (reinterpret_cast <Address>(code_space.begin ()), code_space.size ());
1130
1142
std::unique_ptr<WasmCode> code{new WasmCode{
1131
1143
this , // native_module
@@ -1171,6 +1183,7 @@ void NativeModule::AddCodeSpace(base::AddressRegion region) {
1171
1183
#endif // V8_OS_WIN64
1172
1184
1173
1185
WasmCodeRefScope code_ref_scope;
1186
+ CODE_SPACE_WRITE_SCOPE
1174
1187
WasmCode* jump_table = nullptr ;
1175
1188
const uint32_t num_wasm_functions = module_->num_declared_functions ;
1176
1189
const bool has_functions = num_wasm_functions > 0 ;
@@ -1353,7 +1366,11 @@ VirtualMemory WasmCodeManager::TryAllocate(size_t size, void* hint) {
1353
1366
if (!memory_tracker_->ReserveAddressSpace (size)) return {};
1354
1367
if (hint == nullptr ) hint = page_allocator->GetRandomMmapAddr ();
1355
1368
1356
- VirtualMemory mem (page_allocator, size, hint, allocate_page_size);
1369
+ // When we start exposing Wasm in jitless mode, then the jitless flag
1370
+ // will have to determine whether we set kMapAsJittable or not.
1371
+ DCHECK (!FLAG_jitless);
1372
+ VirtualMemory mem (page_allocator, size, hint, allocate_page_size,
1373
+ VirtualMemory::kMapAsJittable );
1357
1374
if (!mem.IsReserved ()) {
1358
1375
memory_tracker_->ReleaseReservation (size);
1359
1376
return {};
@@ -1513,6 +1530,7 @@ std::vector<WasmCode*> NativeModule::AddCompiledCode(
1513
1530
DCHECK (!results.empty ());
1514
1531
// First, allocate code space for all the results.
1515
1532
size_t total_code_space = 0 ;
1533
+ CODE_SPACE_WRITE_SCOPE
1516
1534
for (auto & result : results) {
1517
1535
DCHECK (result.succeeded ());
1518
1536
total_code_space += RoundUp<kCodeAlignment >(result.code_desc .instr_size );
0 commit comments