Commit 2f3ebfa9 authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[sparkplug] Use sorted vector for handlers

Rather than doing a set lookup for each bytecode offset during
iteration, rely on the fact that bytecode offsets are monotonically
increasing, and store the handler offsets in a sorted array with a
"next offset" cursor that the iteration can increment when a handler
is found.

Bug: v8:11420
Change-Id: I50e40043540d37e6c6ecb3e39a9a92c28b65e3d1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2742621
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73272}
parent c15a7c97
......@@ -8,8 +8,8 @@
#include "src/baseline/baseline-compiler.h"
#include <algorithm>
#include <type_traits>
#include <unordered_map>
#include "src/baseline/baseline-assembler-inl.h"
#include "src/builtins/builtins-constructor.h"
......@@ -221,7 +221,6 @@ void MoveArgumentsForDescriptor(BaselineAssembler* masm,
} // namespace detail
BaselineCompiler::BaselineCompiler(
Isolate* isolate, Handle<SharedFunctionInfo> shared_function_info,
Handle<BytecodeArray> bytecode)
......@@ -234,7 +233,7 @@ BaselineCompiler::BaselineCompiler(
iterator_(bytecode_),
zone_(isolate->allocator(), ZONE_NAME),
labels_(zone_.NewArray<BaselineLabels*>(bytecode_->length())),
handler_offsets_(&zone_) {
next_handler_offset_(nullptr) {
MemsetPointer(labels_, nullptr, bytecode_->length());
}
......@@ -243,12 +242,20 @@ BaselineCompiler::BaselineCompiler(
void BaselineCompiler::GenerateCode() {
HandlerTable table(*bytecode_);
{
// Handler offsets are stored in a sorted array, terminated with kMaxInt.
// This allows the bytecode visitor to keep a cursor into this array, moving
// the cursor forward each time the handler offset matches the current
// cursor's value.
int num_handlers = table.NumberOfRangeEntries();
next_handler_offset_ = zone_.NewArray<int>(num_handlers + 1);
RuntimeCallTimerScope runtimeTimer(
stats_, RuntimeCallCounterId::kCompileBaselinePrepareHandlerOffsets);
for (int i = 0; i < table.NumberOfRangeEntries(); ++i) {
for (int i = 0; i < num_handlers; ++i) {
int handler_offset = table.GetRangeHandler(i);
handler_offsets_.insert(handler_offset);
next_handler_offset_[i] = handler_offset;
}
std::sort(next_handler_offset_, &next_handler_offset_[num_handlers]);
next_handler_offset_[num_handlers] = kMaxInt;
}
{
......@@ -400,11 +407,12 @@ void BaselineCompiler::VisitSingleBytecode() {
}
// Record positions of exception handlers.
if (handler_offsets_.find(iterator().current_offset()) !=
handler_offsets_.end()) {
if (iterator().current_offset() == *next_handler_offset_) {
AddPosition();
__ ExceptionHandler();
next_handler_offset_++;
}
DCHECK_LT(iterator().current_offset(), *next_handler_offset_);
if (FLAG_code_comments) {
std::ostringstream str;
......
......@@ -9,8 +9,6 @@
// architectures.
#if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_ARM64
#include <unordered_map>
#include "src/base/logging.h"
#include "src/base/threaded-list.h"
#include "src/base/vlq.h"
......@@ -22,7 +20,6 @@
#include "src/logging/counters.h"
#include "src/objects/map.h"
#include "src/objects/tagged-index.h"
#include "src/zone/zone-containers.h"
namespace v8 {
namespace internal {
......@@ -197,7 +194,7 @@ class BaselineCompiler {
}
BaselineLabels** labels_;
ZoneSet<int> handler_offsets_;
int* next_handler_offset_;
};
} // namespace baseline
......
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