Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: src/compiler/wasm-compiler.cc

Issue 2500443004: [wasm] OOB traps: build protected instruction list during codegen (Closed)
Patch Set: Code review feedback Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler/wasm-compiler.h" 5 #include "src/compiler/wasm-compiler.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/isolate-inl.h" 9 #include "src/isolate-inl.h"
10 10
(...skipping 3372 matching lines...) Expand 10 before | Expand all | Expand 10 after
3383 graph_zone(), MachineType::PointerRepresentation(), 3383 graph_zone(), MachineType::PointerRepresentation(),
3384 InstructionSelector::SupportedMachineOperatorFlags(), 3384 InstructionSelector::SupportedMachineOperatorFlags(),
3385 InstructionSelector::AlignmentRequirements()))), 3385 InstructionSelector::AlignmentRequirements()))),
3386 compilation_zone_(isolate->allocator(), ZONE_NAME), 3386 compilation_zone_(isolate->allocator(), ZONE_NAME),
3387 info_(function->name_length != 0 ? module_env->GetNameOrNull(function) 3387 info_(function->name_length != 0 ? module_env->GetNameOrNull(function)
3388 : ArrayVector("wasm"), 3388 : ArrayVector("wasm"),
3389 isolate, &compilation_zone_, 3389 isolate, &compilation_zone_,
3390 Code::ComputeFlags(Code::WASM_FUNCTION)), 3390 Code::ComputeFlags(Code::WASM_FUNCTION)),
3391 job_(), 3391 job_(),
3392 index_(index), 3392 index_(index),
3393 ok_(true) { 3393 ok_(true),
3394 protected_instructions_(&compilation_zone_) {
3394 // Create and cache this node in the main thread. 3395 // Create and cache this node in the main thread.
3395 jsgraph_->CEntryStubConstant(1); 3396 jsgraph_->CEntryStubConstant(1);
3396 } 3397 }
3397 3398
3398 void WasmCompilationUnit::ExecuteCompilation() { 3399 void WasmCompilationUnit::ExecuteCompilation() {
3399 // TODO(ahaas): The counters are not thread-safe at the moment. 3400 // TODO(ahaas): The counters are not thread-safe at the moment.
3400 // HistogramTimerScope wasm_compile_function_time_scope( 3401 // HistogramTimerScope wasm_compile_function_time_scope(
3401 // isolate_->counters()->wasm_compile_function_time()); 3402 // isolate_->counters()->wasm_compile_function_time());
3402 if (FLAG_trace_wasm_compiler) { 3403 if (FLAG_trace_wasm_compiler) {
3403 OFStream os(stdout); 3404 OFStream os(stdout);
(...skipping 20 matching lines...) Expand all
3424 } 3425 }
3425 3426
3426 // Run the compiler pipeline to generate machine code. 3427 // Run the compiler pipeline to generate machine code.
3427 CallDescriptor* descriptor = wasm::ModuleEnv::GetWasmCallDescriptor( 3428 CallDescriptor* descriptor = wasm::ModuleEnv::GetWasmCallDescriptor(
3428 &compilation_zone_, function_->sig); 3429 &compilation_zone_, function_->sig);
3429 if (jsgraph_->machine()->Is32()) { 3430 if (jsgraph_->machine()->Is32()) {
3430 descriptor = 3431 descriptor =
3431 module_env_->GetI32WasmCallDescriptor(&compilation_zone_, descriptor); 3432 module_env_->GetI32WasmCallDescriptor(&compilation_zone_, descriptor);
3432 } 3433 }
3433 job_.reset(Pipeline::NewWasmCompilationJob(&info_, jsgraph_, descriptor, 3434 job_.reset(Pipeline::NewWasmCompilationJob(&info_, jsgraph_, descriptor,
3434 source_positions)); 3435 source_positions,
3436 &protected_instructions_));
3435 ok_ = job_->ExecuteJob() == CompilationJob::SUCCEEDED; 3437 ok_ = job_->ExecuteJob() == CompilationJob::SUCCEEDED;
3436 // TODO(bradnelson): Improve histogram handling of size_t. 3438 // TODO(bradnelson): Improve histogram handling of size_t.
3437 // TODO(ahaas): The counters are not thread-safe at the moment. 3439 // TODO(ahaas): The counters are not thread-safe at the moment.
3438 // isolate_->counters()->wasm_compile_function_peak_memory_bytes() 3440 // isolate_->counters()->wasm_compile_function_peak_memory_bytes()
3439 // ->AddSample( 3441 // ->AddSample(
3440 // static_cast<int>(jsgraph->graph()->zone()->allocation_size())); 3442 // static_cast<int>(jsgraph->graph()->zone()->allocation_size()));
3441 3443
3442 if (FLAG_trace_wasm_decode_time) { 3444 if (FLAG_trace_wasm_decode_time) {
3443 double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF(); 3445 double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF();
3444 PrintF( 3446 PrintF(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3482 } 3484 }
3483 3485
3484 if (FLAG_trace_wasm_decode_time) { 3486 if (FLAG_trace_wasm_decode_time) {
3485 double compile_ms = compile_timer.Elapsed().InMillisecondsF(); 3487 double compile_ms = compile_timer.Elapsed().InMillisecondsF();
3486 PrintF("wasm-code-generation ok: %d bytes, %0.3f ms code generation\n", 3488 PrintF("wasm-code-generation ok: %d bytes, %0.3f ms code generation\n",
3487 static_cast<int>(function_->code_end_offset - 3489 static_cast<int>(function_->code_end_offset -
3488 function_->code_start_offset), 3490 function_->code_start_offset),
3489 compile_ms); 3491 compile_ms);
3490 } 3492 }
3491 3493
3494 Handle<FixedArray> protected_instructions = PackProtectedInstructions();
3495 code->set_protected_instructions(*protected_instructions);
3496
3492 return code; 3497 return code;
3493 } 3498 }
3494 3499
3500 Handle<FixedArray> WasmCompilationUnit::PackProtectedInstructions() const {
3501 const int num_instructions = static_cast<int>(protected_instructions_.size());
3502 Handle<FixedArray> fn_protected = isolate_->factory()->NewFixedArray(
3503 num_instructions * Code::kTrapDataSize, TENURED);
3504 for (unsigned i = 0; i < protected_instructions_.size(); ++i) {
3505 const trap_handler::ProtectedInstructionData& instruction =
3506 protected_instructions_[i];
3507 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapCodeOffset,
3508 Smi::FromInt(instruction.instr_offset));
3509 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset,
3510 Smi::FromInt(instruction.landing_offset));
3511 }
3512 return fn_protected;
3513 }
3514
3495 } // namespace compiler 3515 } // namespace compiler
3496 } // namespace internal 3516 } // namespace internal
3497 } // namespace v8 3517 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698