Commit 5fee3636 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Avoid allocating a zone for processing protected instructions

By reusing a single vector instead of allocating one per code object,
we can save lots of heap allocations.

R=eholk@chromium.org

Bug: v8:5277
Change-Id: Ia462c97293cd00607d9f2faf29e265ea78d49394
Reviewed-on: https://chromium-review.googlesource.com/686819Reviewed-by: 's avatarEric Holk <eholk@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48187}
parent f180d9fb
...@@ -312,12 +312,14 @@ Handle<JSArrayBuffer> NewArrayBuffer(Isolate* isolate, size_t size, ...@@ -312,12 +312,14 @@ Handle<JSArrayBuffer> NewArrayBuffer(Isolate* isolate, size_t size,
void UnpackAndRegisterProtectedInstructions(Isolate* isolate, void UnpackAndRegisterProtectedInstructions(Isolate* isolate,
Handle<FixedArray> code_table) { Handle<FixedArray> code_table) {
DisallowHeapAllocation no_gc;
std::vector<trap_handler::ProtectedInstructionData> unpacked;
for (int i = 0; i < code_table->length(); ++i) { for (int i = 0; i < code_table->length(); ++i) {
Handle<Code> code; Object* maybe_code = code_table->get(i);
// This is sometimes undefined when we're called from cctests. // This is sometimes undefined when we're called from cctests.
if (!code_table->GetValue<Code>(isolate, i).ToHandle(&code)) { if (maybe_code->IsUndefined(isolate)) continue;
continue; Code* code = Code::cast(maybe_code);
}
if (code->kind() != Code::WASM_FUNCTION) { if (code->kind() != Code::WASM_FUNCTION) {
continue; continue;
...@@ -330,25 +332,24 @@ void UnpackAndRegisterProtectedInstructions(Isolate* isolate, ...@@ -330,25 +332,24 @@ void UnpackAndRegisterProtectedInstructions(Isolate* isolate,
const intptr_t base = reinterpret_cast<intptr_t>(code->entry()); const intptr_t base = reinterpret_cast<intptr_t>(code->entry());
Zone zone(isolate->allocator(), "Wasm Module");
ZoneVector<trap_handler::ProtectedInstructionData> unpacked(&zone);
const int mode_mask = const int mode_mask =
RelocInfo::ModeMask(RelocInfo::WASM_PROTECTED_INSTRUCTION_LANDING); RelocInfo::ModeMask(RelocInfo::WASM_PROTECTED_INSTRUCTION_LANDING);
for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { for (RelocIterator it(code, mode_mask); !it.done(); it.next()) {
trap_handler::ProtectedInstructionData data; trap_handler::ProtectedInstructionData data;
data.instr_offset = it.rinfo()->data(); data.instr_offset = it.rinfo()->data();
data.landing_offset = reinterpret_cast<intptr_t>(it.rinfo()->pc()) - base; data.landing_offset = reinterpret_cast<intptr_t>(it.rinfo()->pc()) - base;
unpacked.emplace_back(data); unpacked.emplace_back(data);
} }
if (unpacked.size() > 0) { if (unpacked.empty()) continue;
int size = code->CodeSize(); int size = code->CodeSize();
const int index = RegisterHandlerData(reinterpret_cast<void*>(base), size, const int index = RegisterHandlerData(reinterpret_cast<void*>(base), size,
unpacked.size(), &unpacked[0]); unpacked.size(), &unpacked[0]);
unpacked.clear();
// TODO(eholk): if index is negative, fail. // TODO(eholk): if index is negative, fail.
DCHECK_LE(0, index); DCHECK_LE(0, index);
code->set_trap_handler_index(Smi::FromInt(index)); code->set_trap_handler_index(Smi::FromInt(index));
} }
}
} }
std::ostream& operator<<(std::ostream& os, const WasmFunctionName& name) { std::ostream& operator<<(std::ostream& os, const WasmFunctionName& name) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment