Commit aab49f37 authored by Alexey Kozyatinskiy's avatar Alexey Kozyatinskiy Committed by Commit Bot

[inspector] do not allocate scope inside CallStackDepth

Allocation is super slow and produce big performance regression on
blink side.

Bug: chromium:839567,chromium:839809
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: I3e9989435515ecfaedaee60c1f0c6939b9053e95
Reviewed-on: https://chromium-review.googlesource.com/1053105
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53115}
parent 65f8a5c7
......@@ -234,20 +234,17 @@ class CallDepthScope {
: isolate_(isolate),
context_(context),
escaped_(false),
save_for_termination_(isolate->next_v8_call_is_safe_for_termination()) {
safe_for_termination_(isolate->next_v8_call_is_safe_for_termination()),
interrupts_scope_(isolate_, i::StackGuard::TERMINATE_EXECUTION,
isolate_->only_terminate_in_safe_scope()
? (safe_for_termination_
? i::InterruptsScope::kRunInterrupts
: i::InterruptsScope::kPostponeInterrupts)
: i::InterruptsScope::kNoop) {
// TODO(dcarney): remove this when blink stops crashing.
DCHECK(!isolate_->external_caught_exception());
isolate_->handle_scope_implementer()->IncrementCallDepth();
isolate_->set_next_v8_call_is_safe_for_termination(false);
if (isolate_->only_terminate_in_safe_scope()) {
if (save_for_termination_) {
interrupts_scope_.reset(new i::SafeForInterruptsScope(
isolate_, i::StackGuard::TERMINATE_EXECUTION));
} else {
interrupts_scope_.reset(new i::PostponeInterruptsScope(
isolate_, i::StackGuard::TERMINATE_EXECUTION));
}
}
if (!context.IsEmpty()) {
i::Handle<i::Context> env = Utils::OpenHandle(*context);
i::HandleScopeImplementer* impl = isolate->handle_scope_implementer();
......@@ -272,7 +269,7 @@ class CallDepthScope {
#ifdef V8_CHECK_MICROTASKS_SCOPES_CONSISTENCY
if (do_callback) CheckMicrotasksScopesConsistency(isolate_);
#endif
isolate_->set_next_v8_call_is_safe_for_termination(save_for_termination_);
isolate_->set_next_v8_call_is_safe_for_termination(safe_for_termination_);
}
void Escape() {
......@@ -289,8 +286,8 @@ class CallDepthScope {
Local<Context> context_;
bool escaped_;
bool do_callback_;
bool save_for_termination_;
std::unique_ptr<i::InterruptsScope> interrupts_scope_;
bool safe_for_termination_;
i::InterruptsScope interrupts_scope_;
};
} // namespace
......
......@@ -317,6 +317,7 @@ void StackGuard::DisableInterrupts() {
void StackGuard::PushInterruptsScope(InterruptsScope* scope) {
ExecutionAccess access(isolate_);
DCHECK_NE(scope->mode_, InterruptsScope::kNoop);
if (scope->mode_ == InterruptsScope::kPostponeInterrupts) {
// Intercept already requested interrupts.
int intercepted = thread_local_.interrupt_flags_ & scope->intercept_mask_;
......@@ -342,6 +343,7 @@ void StackGuard::PushInterruptsScope(InterruptsScope* scope) {
void StackGuard::PopInterruptsScope() {
ExecutionAccess access(isolate_);
InterruptsScope* top = thread_local_.interrupt_scopes_;
DCHECK_NE(top->mode_, InterruptsScope::kNoop);
if (top->mode_ == InterruptsScope::kPostponeInterrupts) {
// Make intercepted interrupts active.
DCHECK_EQ(thread_local_.interrupt_flags_ & top->intercept_mask_, 0);
......
......@@ -1819,9 +1819,11 @@ class StackLimitCheck BASE_EMBEDDED {
// not affect other interrupts.
class InterruptsScope {
public:
enum Mode { kPostponeInterrupts, kRunInterrupts };
enum Mode { kPostponeInterrupts, kRunInterrupts, kNoop };
virtual ~InterruptsScope() { stack_guard_->PopInterruptsScope(); }
virtual ~InterruptsScope() {
if (mode_ != kNoop) stack_guard_->PopInterruptsScope();
}
// Find the scope that intercepts this interrupt.
// It may be outermost PostponeInterruptsScope or innermost
......@@ -1829,13 +1831,12 @@ class InterruptsScope {
// Return whether the interrupt has been intercepted.
bool Intercept(StackGuard::InterruptFlag flag);
protected:
InterruptsScope(Isolate* isolate, int intercept_mask, Mode mode)
: stack_guard_(isolate->stack_guard()),
intercept_mask_(intercept_mask),
intercepted_flags_(0),
mode_(mode) {
stack_guard_->PushInterruptsScope(this);
if (mode_ != kNoop) stack_guard_->PushInterruptsScope(this);
}
private:
......
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