[deoptimizer] Continue extracting classes
deoptimized-frame-info: Used only by the debugger. translated-state: Combines translations and current frame states to describe in- and output frames. translation-array: Utils for accessing the on-heap TranslationArray object. Bug: v8:11332 Change-Id: I86757bed370d6d9e493862eb24a9e92533f80933 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2640414 Commit-Queue: Jakob Gruber <jgruber@chromium.org> Reviewed-by: Nico Hartmann <nicohartmann@chromium.org> Cr-Commit-Position: refs/heads/master@{#72229}
This commit is contained in:
parent
7eb88e4216
commit
96b8ec759e
9
BUILD.gn
9
BUILD.gn
@ -2633,8 +2633,17 @@ v8_source_set("v8_base_without_compiler") {
|
||||
"src/debug/liveedit.h",
|
||||
"src/deoptimizer/deoptimize-reason.cc",
|
||||
"src/deoptimizer/deoptimize-reason.h",
|
||||
"src/deoptimizer/deoptimized-frame-info.cc",
|
||||
"src/deoptimizer/deoptimized-frame-info.h",
|
||||
"src/deoptimizer/deoptimizer.cc",
|
||||
"src/deoptimizer/deoptimizer.h",
|
||||
"src/deoptimizer/frame-description.h",
|
||||
"src/deoptimizer/materialized-object-store.cc",
|
||||
"src/deoptimizer/materialized-object-store.h",
|
||||
"src/deoptimizer/translated-state.cc",
|
||||
"src/deoptimizer/translated-state.h",
|
||||
"src/deoptimizer/translation-array.cc",
|
||||
"src/deoptimizer/translation-array.h",
|
||||
"src/deoptimizer/translations.cc",
|
||||
"src/deoptimizer/translations.h",
|
||||
"src/diagnostics/basic-block-profiler.cc",
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "src/deoptimizer/deoptimizer.h"
|
||||
#include "src/deoptimizer/deoptimized-frame-info.h"
|
||||
#include "src/execution/isolate.h"
|
||||
#include "src/execution/v8threads.h"
|
||||
#include "src/objects/objects.h"
|
||||
|
74
src/deoptimizer/deoptimized-frame-info.cc
Normal file
74
src/deoptimizer/deoptimized-frame-info.cc
Normal file
@ -0,0 +1,74 @@
|
||||
// Copyright 2021 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "src/deoptimizer/deoptimized-frame-info.h"
|
||||
|
||||
#include "src/execution/isolate.h"
|
||||
#include "src/objects/js-function-inl.h"
|
||||
#include "src/objects/oddball.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
namespace {
|
||||
|
||||
Handle<Object> GetValueForDebugger(TranslatedFrame::iterator it,
|
||||
Isolate* isolate) {
|
||||
if (it->GetRawValue() == ReadOnlyRoots(isolate).arguments_marker() &&
|
||||
!it->IsMaterializableByDebugger()) {
|
||||
return isolate->factory()->optimized_out();
|
||||
}
|
||||
return it->GetValue();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
DeoptimizedFrameInfo::DeoptimizedFrameInfo(TranslatedState* state,
|
||||
TranslatedState::iterator frame_it,
|
||||
Isolate* isolate) {
|
||||
int parameter_count =
|
||||
frame_it->shared_info()->internal_formal_parameter_count();
|
||||
TranslatedFrame::iterator stack_it = frame_it->begin();
|
||||
|
||||
// Get the function. Note that this might materialize the function.
|
||||
// In case the debugger mutates this value, we should deoptimize
|
||||
// the function and remember the value in the materialized value store.
|
||||
DCHECK_EQ(parameter_count, Handle<JSFunction>::cast(stack_it->GetValue())
|
||||
->shared()
|
||||
.internal_formal_parameter_count());
|
||||
|
||||
stack_it++; // Skip the function.
|
||||
stack_it++; // Skip the receiver.
|
||||
|
||||
DCHECK_EQ(TranslatedFrame::kInterpretedFunction, frame_it->kind());
|
||||
|
||||
parameters_.resize(static_cast<size_t>(parameter_count));
|
||||
for (int i = 0; i < parameter_count; i++) {
|
||||
Handle<Object> parameter = GetValueForDebugger(stack_it, isolate);
|
||||
SetParameter(i, parameter);
|
||||
stack_it++;
|
||||
}
|
||||
|
||||
// Get the context.
|
||||
context_ = GetValueForDebugger(stack_it, isolate);
|
||||
stack_it++;
|
||||
|
||||
// Get the expression stack.
|
||||
DCHECK_EQ(TranslatedFrame::kInterpretedFunction, frame_it->kind());
|
||||
const int stack_height = frame_it->height(); // Accumulator *not* included.
|
||||
|
||||
expression_stack_.resize(static_cast<size_t>(stack_height));
|
||||
for (int i = 0; i < stack_height; i++) {
|
||||
Handle<Object> expression = GetValueForDebugger(stack_it, isolate);
|
||||
SetExpression(i, expression);
|
||||
stack_it++;
|
||||
}
|
||||
|
||||
DCHECK_EQ(TranslatedFrame::kInterpretedFunction, frame_it->kind());
|
||||
stack_it++; // Skip the accumulator.
|
||||
|
||||
CHECK(stack_it == frame_it->end());
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
70
src/deoptimizer/deoptimized-frame-info.h
Normal file
70
src/deoptimizer/deoptimized-frame-info.h
Normal file
@ -0,0 +1,70 @@
|
||||
// Copyright 2021 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef V8_DEOPTIMIZER_DEOPTIMIZED_FRAME_INFO_H_
|
||||
#define V8_DEOPTIMIZER_DEOPTIMIZED_FRAME_INFO_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "src/deoptimizer/translations.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
// Class used to represent an unoptimized frame when the debugger
|
||||
// needs to inspect a frame that is part of an optimized frame. The
|
||||
// internally used FrameDescription objects are not GC safe so for use
|
||||
// by the debugger frame information is copied to an object of this type.
|
||||
// Represents parameters in unadapted form so their number might mismatch
|
||||
// formal parameter count.
|
||||
class DeoptimizedFrameInfo : public Malloced {
|
||||
public:
|
||||
DeoptimizedFrameInfo(TranslatedState* state,
|
||||
TranslatedState::iterator frame_it, Isolate* isolate);
|
||||
|
||||
// Get the frame context.
|
||||
Handle<Object> GetContext() { return context_; }
|
||||
|
||||
// Get an incoming argument.
|
||||
Handle<Object> GetParameter(int index) {
|
||||
DCHECK(0 <= index && index < parameters_count());
|
||||
return parameters_[index];
|
||||
}
|
||||
|
||||
// Get an expression from the expression stack.
|
||||
Handle<Object> GetExpression(int index) {
|
||||
DCHECK(0 <= index && index < expression_count());
|
||||
return expression_stack_[index];
|
||||
}
|
||||
|
||||
private:
|
||||
// Return the number of incoming arguments.
|
||||
int parameters_count() { return static_cast<int>(parameters_.size()); }
|
||||
|
||||
// Return the height of the expression stack.
|
||||
int expression_count() { return static_cast<int>(expression_stack_.size()); }
|
||||
|
||||
// Set an incoming argument.
|
||||
void SetParameter(int index, Handle<Object> obj) {
|
||||
DCHECK(0 <= index && index < parameters_count());
|
||||
parameters_[index] = obj;
|
||||
}
|
||||
|
||||
// Set an expression on the expression stack.
|
||||
void SetExpression(int index, Handle<Object> obj) {
|
||||
DCHECK(0 <= index && index < expression_count());
|
||||
expression_stack_[index] = obj;
|
||||
}
|
||||
|
||||
Handle<Object> context_;
|
||||
std::vector<Handle<Object>> parameters_;
|
||||
std::vector<Handle<Object>> expression_stack_;
|
||||
|
||||
friend class Deoptimizer;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
||||
#endif // V8_DEOPTIMIZER_DEOPTIMIZED_FRAME_INFO_H_
|
@ -7,6 +7,8 @@
|
||||
#include "src/base/memory.h"
|
||||
#include "src/codegen/interface-descriptors.h"
|
||||
#include "src/codegen/register-configuration.h"
|
||||
#include "src/deoptimizer/deoptimized-frame-info.h"
|
||||
#include "src/deoptimizer/materialized-object-store.h"
|
||||
#include "src/execution/frames-inl.h"
|
||||
#include "src/execution/isolate.h"
|
||||
#include "src/execution/pointer-authentication.h"
|
||||
@ -881,7 +883,7 @@ void Deoptimizer::DoComputeOutputFrames() {
|
||||
|
||||
FILE* trace_file =
|
||||
verbose_tracing_enabled() ? trace_scope()->file() : nullptr;
|
||||
TranslationIterator state_iterator(translations, translation_index);
|
||||
TranslationArrayIterator state_iterator(translations, translation_index);
|
||||
translated_state_.Init(
|
||||
isolate_, input_->GetFramePointerAddress(), stack_fp_, &state_iterator,
|
||||
input_data.LiteralArray(), input_->GetRegisterValues(), trace_file,
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "src/codegen/source-position.h"
|
||||
#include "src/deoptimizer/deoptimize-reason.h"
|
||||
#include "src/deoptimizer/frame-description.h"
|
||||
#include "src/deoptimizer/translations.h"
|
||||
#include "src/diagnostics/code-tracer.h"
|
||||
#include "src/objects/js-function.h"
|
||||
@ -18,6 +19,7 @@ namespace internal {
|
||||
|
||||
enum class BuiltinContinuationMode;
|
||||
|
||||
class DeoptimizedFrameInfo;
|
||||
class Isolate;
|
||||
|
||||
class Deoptimizer : public Malloced {
|
||||
|
230
src/deoptimizer/frame-description.h
Normal file
230
src/deoptimizer/frame-description.h
Normal file
@ -0,0 +1,230 @@
|
||||
// Copyright 2021 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef V8_DEOPTIMIZER_FRAME_DESCRIPTION_H_
|
||||
#define V8_DEOPTIMIZER_FRAME_DESCRIPTION_H_
|
||||
|
||||
#include "src/codegen/register-arch.h"
|
||||
#include "src/execution/frame-constants.h"
|
||||
#include "src/utils/boxed-float.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
// Classes in this file describe the physical stack frame state.
|
||||
//
|
||||
// RegisterValues: stores gp and fp register values. Can be filled in either by
|
||||
// the DeoptimizationEntry builtin (which fills in the input state of the
|
||||
// optimized frame); or by the FrameWriter (fills in the output state of the
|
||||
// interpreted frame).
|
||||
//
|
||||
// - FrameDescription: contains RegisterValues and other things.
|
||||
|
||||
class RegisterValues {
|
||||
public:
|
||||
intptr_t GetRegister(unsigned n) const {
|
||||
#if DEBUG
|
||||
// This convoluted DCHECK is needed to work around a gcc problem that
|
||||
// improperly detects an array bounds overflow in optimized debug builds
|
||||
// when using a plain DCHECK.
|
||||
if (n >= arraysize(registers_)) {
|
||||
DCHECK(false);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return registers_[n];
|
||||
}
|
||||
|
||||
Float32 GetFloatRegister(unsigned n) const;
|
||||
|
||||
Float64 GetDoubleRegister(unsigned n) const {
|
||||
DCHECK(n < arraysize(double_registers_));
|
||||
return double_registers_[n];
|
||||
}
|
||||
|
||||
void SetRegister(unsigned n, intptr_t value) {
|
||||
DCHECK(n < arraysize(registers_));
|
||||
registers_[n] = value;
|
||||
}
|
||||
|
||||
intptr_t registers_[Register::kNumRegisters];
|
||||
// Generated code writes directly into the following array, make sure the
|
||||
// element size matches what the machine instructions expect.
|
||||
static_assert(sizeof(Float64) == kDoubleSize, "size mismatch");
|
||||
Float64 double_registers_[DoubleRegister::kNumRegisters];
|
||||
};
|
||||
|
||||
class FrameDescription {
|
||||
public:
|
||||
FrameDescription(uint32_t frame_size, int parameter_count)
|
||||
: frame_size_(frame_size),
|
||||
parameter_count_(parameter_count),
|
||||
top_(kZapUint32),
|
||||
pc_(kZapUint32),
|
||||
fp_(kZapUint32),
|
||||
context_(kZapUint32),
|
||||
constant_pool_(kZapUint32) {
|
||||
// Zap all the registers.
|
||||
for (int r = 0; r < Register::kNumRegisters; r++) {
|
||||
// TODO(jbramley): It isn't safe to use kZapUint32 here. If the register
|
||||
// isn't used before the next safepoint, the GC will try to scan it as a
|
||||
// tagged value. kZapUint32 looks like a valid tagged pointer, but it
|
||||
// isn't.
|
||||
#if defined(V8_OS_WIN) && defined(V8_TARGET_ARCH_ARM64)
|
||||
// x18 is reserved as platform register on Windows arm64 platform
|
||||
const int kPlatformRegister = 18;
|
||||
if (r != kPlatformRegister) {
|
||||
SetRegister(r, kZapUint32);
|
||||
}
|
||||
#else
|
||||
SetRegister(r, kZapUint32);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Zap all the slots.
|
||||
for (unsigned o = 0; o < frame_size; o += kSystemPointerSize) {
|
||||
SetFrameSlot(o, kZapUint32);
|
||||
}
|
||||
}
|
||||
|
||||
void* operator new(size_t size, uint32_t frame_size) {
|
||||
// Subtracts kSystemPointerSize, as the member frame_content_ already
|
||||
// supplies the first element of the area to store the frame.
|
||||
return base::Malloc(size + frame_size - kSystemPointerSize);
|
||||
}
|
||||
|
||||
void operator delete(void* pointer, uint32_t frame_size) {
|
||||
base::Free(pointer);
|
||||
}
|
||||
|
||||
void operator delete(void* description) { base::Free(description); }
|
||||
|
||||
uint32_t GetFrameSize() const {
|
||||
USE(frame_content_);
|
||||
DCHECK(static_cast<uint32_t>(frame_size_) == frame_size_);
|
||||
return static_cast<uint32_t>(frame_size_);
|
||||
}
|
||||
|
||||
intptr_t GetFrameSlot(unsigned offset) {
|
||||
return *GetFrameSlotPointer(offset);
|
||||
}
|
||||
|
||||
unsigned GetLastArgumentSlotOffset(bool pad_arguments = true) {
|
||||
int parameter_slots = parameter_count();
|
||||
if (pad_arguments && ShouldPadArguments(parameter_slots)) parameter_slots++;
|
||||
return GetFrameSize() - parameter_slots * kSystemPointerSize;
|
||||
}
|
||||
|
||||
Address GetFramePointerAddress() {
|
||||
// We should not pad arguments in the bottom frame, since this
|
||||
// already contain a padding if necessary and it might contain
|
||||
// extra arguments (actual argument count > parameter count).
|
||||
const bool pad_arguments_bottom_frame = false;
|
||||
int fp_offset = GetLastArgumentSlotOffset(pad_arguments_bottom_frame) -
|
||||
StandardFrameConstants::kCallerSPOffset;
|
||||
return reinterpret_cast<Address>(GetFrameSlotPointer(fp_offset));
|
||||
}
|
||||
|
||||
RegisterValues* GetRegisterValues() { return ®ister_values_; }
|
||||
|
||||
void SetFrameSlot(unsigned offset, intptr_t value) {
|
||||
*GetFrameSlotPointer(offset) = value;
|
||||
}
|
||||
|
||||
void SetCallerPc(unsigned offset, intptr_t value);
|
||||
|
||||
void SetCallerFp(unsigned offset, intptr_t value);
|
||||
|
||||
void SetCallerConstantPool(unsigned offset, intptr_t value);
|
||||
|
||||
intptr_t GetRegister(unsigned n) const {
|
||||
return register_values_.GetRegister(n);
|
||||
}
|
||||
|
||||
Float64 GetDoubleRegister(unsigned n) const {
|
||||
return register_values_.GetDoubleRegister(n);
|
||||
}
|
||||
|
||||
void SetRegister(unsigned n, intptr_t value) {
|
||||
register_values_.SetRegister(n, value);
|
||||
}
|
||||
|
||||
intptr_t GetTop() const { return top_; }
|
||||
void SetTop(intptr_t top) { top_ = top; }
|
||||
|
||||
intptr_t GetPc() const { return pc_; }
|
||||
void SetPc(intptr_t pc);
|
||||
|
||||
intptr_t GetFp() const { return fp_; }
|
||||
void SetFp(intptr_t fp) { fp_ = fp; }
|
||||
|
||||
intptr_t GetContext() const { return context_; }
|
||||
void SetContext(intptr_t context) { context_ = context; }
|
||||
|
||||
intptr_t GetConstantPool() const { return constant_pool_; }
|
||||
void SetConstantPool(intptr_t constant_pool) {
|
||||
constant_pool_ = constant_pool;
|
||||
}
|
||||
|
||||
void SetContinuation(intptr_t pc) { continuation_ = pc; }
|
||||
|
||||
// Argument count, including receiver.
|
||||
int parameter_count() { return parameter_count_; }
|
||||
|
||||
static int registers_offset() {
|
||||
return offsetof(FrameDescription, register_values_.registers_);
|
||||
}
|
||||
|
||||
static constexpr int double_registers_offset() {
|
||||
return offsetof(FrameDescription, register_values_.double_registers_);
|
||||
}
|
||||
|
||||
static int frame_size_offset() {
|
||||
return offsetof(FrameDescription, frame_size_);
|
||||
}
|
||||
|
||||
static int pc_offset() { return offsetof(FrameDescription, pc_); }
|
||||
|
||||
static int continuation_offset() {
|
||||
return offsetof(FrameDescription, continuation_);
|
||||
}
|
||||
|
||||
static int frame_content_offset() {
|
||||
return offsetof(FrameDescription, frame_content_);
|
||||
}
|
||||
|
||||
private:
|
||||
static const uint32_t kZapUint32 = 0xbeeddead;
|
||||
|
||||
// Frame_size_ must hold a uint32_t value. It is only a uintptr_t to
|
||||
// keep the variable-size array frame_content_ of type intptr_t at
|
||||
// the end of the structure aligned.
|
||||
uintptr_t frame_size_; // Number of bytes.
|
||||
int parameter_count_;
|
||||
RegisterValues register_values_;
|
||||
intptr_t top_;
|
||||
intptr_t pc_;
|
||||
intptr_t fp_;
|
||||
intptr_t context_;
|
||||
intptr_t constant_pool_;
|
||||
|
||||
// Continuation is the PC where the execution continues after
|
||||
// deoptimizing.
|
||||
intptr_t continuation_;
|
||||
|
||||
// This must be at the end of the object as the object is allocated larger
|
||||
// than its definition indicates to extend this array.
|
||||
intptr_t frame_content_[1];
|
||||
|
||||
intptr_t* GetFrameSlotPointer(unsigned offset) {
|
||||
DCHECK(offset < frame_size_);
|
||||
return reinterpret_cast<intptr_t*>(reinterpret_cast<Address>(this) +
|
||||
frame_content_offset() + offset);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
||||
#endif // V8_DEOPTIMIZER_FRAME_DESCRIPTION_H_
|
90
src/deoptimizer/materialized-object-store.cc
Normal file
90
src/deoptimizer/materialized-object-store.cc
Normal file
@ -0,0 +1,90 @@
|
||||
// Copyright 2021 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "src/deoptimizer/materialized-object-store.h"
|
||||
|
||||
#include "src/execution/isolate.h"
|
||||
#include "src/objects/fixed-array-inl.h"
|
||||
#include "src/objects/oddball.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
Handle<FixedArray> MaterializedObjectStore::Get(Address fp) {
|
||||
int index = StackIdToIndex(fp);
|
||||
if (index == -1) {
|
||||
return Handle<FixedArray>::null();
|
||||
}
|
||||
Handle<FixedArray> array = GetStackEntries();
|
||||
CHECK_GT(array->length(), index);
|
||||
return Handle<FixedArray>::cast(Handle<Object>(array->get(index), isolate()));
|
||||
}
|
||||
|
||||
void MaterializedObjectStore::Set(Address fp,
|
||||
Handle<FixedArray> materialized_objects) {
|
||||
int index = StackIdToIndex(fp);
|
||||
if (index == -1) {
|
||||
index = static_cast<int>(frame_fps_.size());
|
||||
frame_fps_.push_back(fp);
|
||||
}
|
||||
|
||||
Handle<FixedArray> array = EnsureStackEntries(index + 1);
|
||||
array->set(index, *materialized_objects);
|
||||
}
|
||||
|
||||
bool MaterializedObjectStore::Remove(Address fp) {
|
||||
auto it = std::find(frame_fps_.begin(), frame_fps_.end(), fp);
|
||||
if (it == frame_fps_.end()) return false;
|
||||
int index = static_cast<int>(std::distance(frame_fps_.begin(), it));
|
||||
|
||||
frame_fps_.erase(it);
|
||||
FixedArray array = isolate()->heap()->materialized_objects();
|
||||
|
||||
CHECK_LT(index, array.length());
|
||||
int fps_size = static_cast<int>(frame_fps_.size());
|
||||
for (int i = index; i < fps_size; i++) {
|
||||
array.set(i, array.get(i + 1));
|
||||
}
|
||||
array.set(fps_size, ReadOnlyRoots(isolate()).undefined_value());
|
||||
return true;
|
||||
}
|
||||
|
||||
int MaterializedObjectStore::StackIdToIndex(Address fp) {
|
||||
auto it = std::find(frame_fps_.begin(), frame_fps_.end(), fp);
|
||||
return it == frame_fps_.end()
|
||||
? -1
|
||||
: static_cast<int>(std::distance(frame_fps_.begin(), it));
|
||||
}
|
||||
|
||||
Handle<FixedArray> MaterializedObjectStore::GetStackEntries() {
|
||||
return Handle<FixedArray>(isolate()->heap()->materialized_objects(),
|
||||
isolate());
|
||||
}
|
||||
|
||||
Handle<FixedArray> MaterializedObjectStore::EnsureStackEntries(int length) {
|
||||
Handle<FixedArray> array = GetStackEntries();
|
||||
if (array->length() >= length) {
|
||||
return array;
|
||||
}
|
||||
|
||||
int new_length = length > 10 ? length : 10;
|
||||
if (new_length < 2 * array->length()) {
|
||||
new_length = 2 * array->length();
|
||||
}
|
||||
|
||||
Handle<FixedArray> new_array =
|
||||
isolate()->factory()->NewFixedArray(new_length, AllocationType::kOld);
|
||||
for (int i = 0; i < array->length(); i++) {
|
||||
new_array->set(i, array->get(i));
|
||||
}
|
||||
HeapObject undefined_value = ReadOnlyRoots(isolate()).undefined_value();
|
||||
for (int i = array->length(); i < length; i++) {
|
||||
new_array->set(i, undefined_value);
|
||||
}
|
||||
isolate()->heap()->SetRootMaterializedObjects(*new_array);
|
||||
return new_array;
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
40
src/deoptimizer/materialized-object-store.h
Normal file
40
src/deoptimizer/materialized-object-store.h
Normal file
@ -0,0 +1,40 @@
|
||||
// Copyright 2021 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef V8_DEOPTIMIZER_MATERIALIZED_OBJECT_STORE_H_
|
||||
#define V8_DEOPTIMIZER_MATERIALIZED_OBJECT_STORE_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "src/handles/handles.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
class FixedArray;
|
||||
class Isolate;
|
||||
|
||||
class MaterializedObjectStore {
|
||||
public:
|
||||
explicit MaterializedObjectStore(Isolate* isolate) : isolate_(isolate) {}
|
||||
|
||||
Handle<FixedArray> Get(Address fp);
|
||||
void Set(Address fp, Handle<FixedArray> materialized_objects);
|
||||
bool Remove(Address fp);
|
||||
|
||||
private:
|
||||
Isolate* isolate() const { return isolate_; }
|
||||
Handle<FixedArray> GetStackEntries();
|
||||
Handle<FixedArray> EnsureStackEntries(int size);
|
||||
|
||||
int StackIdToIndex(Address fp);
|
||||
|
||||
Isolate* isolate_;
|
||||
std::vector<Address> frame_fps_;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
||||
#endif // V8_DEOPTIMIZER_MATERIALIZED_OBJECT_STORE_H_
|
1871
src/deoptimizer/translated-state.cc
Normal file
1871
src/deoptimizer/translated-state.cc
Normal file
File diff suppressed because it is too large
Load Diff
440
src/deoptimizer/translated-state.h
Normal file
440
src/deoptimizer/translated-state.h
Normal file
@ -0,0 +1,440 @@
|
||||
// Copyright 2021 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef V8_DEOPTIMIZER_TRANSLATED_STATE_H_
|
||||
#define V8_DEOPTIMIZER_TRANSLATED_STATE_H_
|
||||
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
|
||||
#include "src/objects/feedback-vector.h"
|
||||
#include "src/objects/heap-object.h"
|
||||
#include "src/objects/shared-function-info.h"
|
||||
#include "src/utils/boxed-float.h"
|
||||
#include "src/wasm/value-type.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
class RegisterValues;
|
||||
class TranslatedState;
|
||||
class TranslationArrayIterator;
|
||||
|
||||
// The Translated{Value,Frame,State} class hierarchy are a set of utility
|
||||
// functions to work with the combination of translations (built from a
|
||||
// TranslationArray) and the actual current CPU state (represented by
|
||||
// RegisterValues).
|
||||
//
|
||||
// TranslatedState: describes the entire stack state of the current optimized
|
||||
// frame, contains:
|
||||
//
|
||||
// TranslatedFrame: describes a single unoptimized frame, contains:
|
||||
//
|
||||
// TranslatedValue: the actual value of some location.
|
||||
|
||||
class TranslatedValue {
|
||||
public:
|
||||
// Allocation-free getter of the value.
|
||||
// Returns ReadOnlyRoots::arguments_marker() if allocation would be necessary
|
||||
// to get the value. In the case of numbers, returns a Smi if possible.
|
||||
Object GetRawValue() const;
|
||||
|
||||
// Convenience wrapper around GetRawValue (checked).
|
||||
int GetSmiValue() const;
|
||||
|
||||
// Returns the value, possibly materializing it first (and the whole subgraph
|
||||
// reachable from this value). In the case of numbers, returns a Smi if
|
||||
// possible.
|
||||
Handle<Object> GetValue();
|
||||
|
||||
bool IsMaterializedObject() const;
|
||||
bool IsMaterializableByDebugger() const;
|
||||
|
||||
private:
|
||||
friend class TranslatedState;
|
||||
friend class TranslatedFrame;
|
||||
friend class Deoptimizer;
|
||||
|
||||
enum Kind : uint8_t {
|
||||
kInvalid,
|
||||
kTagged,
|
||||
kInt32,
|
||||
kInt64,
|
||||
kInt64ToBigInt,
|
||||
kUInt32,
|
||||
kBoolBit,
|
||||
kFloat,
|
||||
kDouble,
|
||||
kCapturedObject, // Object captured by the escape analysis.
|
||||
// The number of nested objects can be obtained
|
||||
// with the DeferredObjectLength() method
|
||||
// (the values of the nested objects follow
|
||||
// this value in the depth-first order.)
|
||||
kDuplicatedObject // Duplicated object of a deferred object.
|
||||
};
|
||||
|
||||
enum MaterializationState : uint8_t {
|
||||
kUninitialized,
|
||||
kAllocated, // Storage for the object has been allocated (or
|
||||
// enqueued for allocation).
|
||||
kFinished, // The object has been initialized (or enqueued for
|
||||
// initialization).
|
||||
};
|
||||
|
||||
TranslatedValue(TranslatedState* container, Kind kind)
|
||||
: kind_(kind), container_(container) {}
|
||||
Kind kind() const { return kind_; }
|
||||
MaterializationState materialization_state() const {
|
||||
return materialization_state_;
|
||||
}
|
||||
void Handlify();
|
||||
int GetChildrenCount() const;
|
||||
|
||||
static TranslatedValue NewDeferredObject(TranslatedState* container,
|
||||
int length, int object_index);
|
||||
static TranslatedValue NewDuplicateObject(TranslatedState* container, int id);
|
||||
static TranslatedValue NewFloat(TranslatedState* container, Float32 value);
|
||||
static TranslatedValue NewDouble(TranslatedState* container, Float64 value);
|
||||
static TranslatedValue NewInt32(TranslatedState* container, int32_t value);
|
||||
static TranslatedValue NewInt64(TranslatedState* container, int64_t value);
|
||||
static TranslatedValue NewInt64ToBigInt(TranslatedState* container,
|
||||
int64_t value);
|
||||
static TranslatedValue NewUInt32(TranslatedState* container, uint32_t value);
|
||||
static TranslatedValue NewBool(TranslatedState* container, uint32_t value);
|
||||
static TranslatedValue NewTagged(TranslatedState* container, Object literal);
|
||||
static TranslatedValue NewInvalid(TranslatedState* container);
|
||||
|
||||
Isolate* isolate() const;
|
||||
|
||||
void set_storage(Handle<HeapObject> storage) { storage_ = storage; }
|
||||
void set_initialized_storage(Handle<HeapObject> storage);
|
||||
void mark_finished() { materialization_state_ = kFinished; }
|
||||
void mark_allocated() { materialization_state_ = kAllocated; }
|
||||
|
||||
Handle<HeapObject> storage() {
|
||||
DCHECK_NE(materialization_state(), kUninitialized);
|
||||
return storage_;
|
||||
}
|
||||
|
||||
Kind kind_;
|
||||
MaterializationState materialization_state_ = kUninitialized;
|
||||
TranslatedState* container_; // This is only needed for materialization of
|
||||
// objects and constructing handles (to get
|
||||
// to the isolate).
|
||||
|
||||
Handle<HeapObject> storage_; // Contains the materialized value or the
|
||||
// byte-array that will be later morphed into
|
||||
// the materialized object.
|
||||
|
||||
struct MaterializedObjectInfo {
|
||||
int id_;
|
||||
int length_; // Applies only to kCapturedObject kinds.
|
||||
};
|
||||
|
||||
union {
|
||||
// kind kTagged. After handlification it is always nullptr.
|
||||
Object raw_literal_;
|
||||
// kind is kUInt32 or kBoolBit.
|
||||
uint32_t uint32_value_;
|
||||
// kind is kInt32.
|
||||
int32_t int32_value_;
|
||||
// kind is kInt64.
|
||||
int64_t int64_value_;
|
||||
// kind is kFloat
|
||||
Float32 float_value_;
|
||||
// kind is kDouble
|
||||
Float64 double_value_;
|
||||
// kind is kDuplicatedObject or kCapturedObject.
|
||||
MaterializedObjectInfo materialization_info_;
|
||||
};
|
||||
|
||||
// Checked accessors for the union members.
|
||||
Object raw_literal() const;
|
||||
int32_t int32_value() const;
|
||||
int64_t int64_value() const;
|
||||
uint32_t uint32_value() const;
|
||||
Float32 float_value() const;
|
||||
Float64 double_value() const;
|
||||
int object_length() const;
|
||||
int object_index() const;
|
||||
};
|
||||
|
||||
class TranslatedFrame {
|
||||
public:
|
||||
enum Kind {
|
||||
kInterpretedFunction,
|
||||
kArgumentsAdaptor,
|
||||
kConstructStub,
|
||||
kBuiltinContinuation,
|
||||
kJSToWasmBuiltinContinuation,
|
||||
kJavaScriptBuiltinContinuation,
|
||||
kJavaScriptBuiltinContinuationWithCatch,
|
||||
kInvalid
|
||||
};
|
||||
|
||||
int GetValueCount();
|
||||
|
||||
Kind kind() const { return kind_; }
|
||||
BytecodeOffset bytecode_offset() const { return bytecode_offset_; }
|
||||
Handle<SharedFunctionInfo> shared_info() const { return shared_info_; }
|
||||
|
||||
// TODO(jgruber): Simplify/clarify the semantics of this field. The name
|
||||
// `height` is slightly misleading. Yes, this value is related to stack frame
|
||||
// height, but must undergo additional mutations to arrive at the real stack
|
||||
// frame height (e.g.: addition/subtraction of context, accumulator, fixed
|
||||
// frame sizes, padding).
|
||||
int height() const { return height_; }
|
||||
|
||||
int return_value_offset() const { return return_value_offset_; }
|
||||
int return_value_count() const { return return_value_count_; }
|
||||
|
||||
SharedFunctionInfo raw_shared_info() const {
|
||||
CHECK(!raw_shared_info_.is_null());
|
||||
return raw_shared_info_;
|
||||
}
|
||||
|
||||
class iterator {
|
||||
public:
|
||||
iterator& operator++() {
|
||||
++input_index_;
|
||||
AdvanceIterator(&position_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
iterator operator++(int) {
|
||||
iterator original(position_, input_index_);
|
||||
++input_index_;
|
||||
AdvanceIterator(&position_);
|
||||
return original;
|
||||
}
|
||||
|
||||
bool operator==(const iterator& other) const {
|
||||
// Ignore {input_index_} for equality.
|
||||
return position_ == other.position_;
|
||||
}
|
||||
bool operator!=(const iterator& other) const { return !(*this == other); }
|
||||
|
||||
TranslatedValue& operator*() { return (*position_); }
|
||||
TranslatedValue* operator->() { return &(*position_); }
|
||||
const TranslatedValue& operator*() const { return (*position_); }
|
||||
const TranslatedValue* operator->() const { return &(*position_); }
|
||||
|
||||
int input_index() const { return input_index_; }
|
||||
|
||||
private:
|
||||
friend TranslatedFrame;
|
||||
|
||||
explicit iterator(std::deque<TranslatedValue>::iterator position,
|
||||
int input_index = 0)
|
||||
: position_(position), input_index_(input_index) {}
|
||||
|
||||
std::deque<TranslatedValue>::iterator position_;
|
||||
int input_index_;
|
||||
};
|
||||
|
||||
using reference = TranslatedValue&;
|
||||
using const_reference = TranslatedValue const&;
|
||||
|
||||
iterator begin() { return iterator(values_.begin()); }
|
||||
iterator end() { return iterator(values_.end()); }
|
||||
|
||||
reference front() { return values_.front(); }
|
||||
const_reference front() const { return values_.front(); }
|
||||
|
||||
// Only for Kind == kJSToWasmBuiltinContinuation
|
||||
base::Optional<wasm::ValueType::Kind> wasm_call_return_type() const {
|
||||
DCHECK_EQ(kind(), kJSToWasmBuiltinContinuation);
|
||||
return return_type_;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class TranslatedState;
|
||||
friend class Deoptimizer;
|
||||
|
||||
// Constructor static methods.
|
||||
static TranslatedFrame InterpretedFrame(BytecodeOffset bytecode_offset,
|
||||
SharedFunctionInfo shared_info,
|
||||
int height, int return_value_offset,
|
||||
int return_value_count);
|
||||
static TranslatedFrame AccessorFrame(Kind kind,
|
||||
SharedFunctionInfo shared_info);
|
||||
static TranslatedFrame ArgumentsAdaptorFrame(SharedFunctionInfo shared_info,
|
||||
int height);
|
||||
static TranslatedFrame ConstructStubFrame(BytecodeOffset bailout_id,
|
||||
SharedFunctionInfo shared_info,
|
||||
int height);
|
||||
static TranslatedFrame BuiltinContinuationFrame(
|
||||
BytecodeOffset bailout_id, SharedFunctionInfo shared_info, int height);
|
||||
static TranslatedFrame JSToWasmBuiltinContinuationFrame(
|
||||
BytecodeOffset bailout_id, SharedFunctionInfo shared_info, int height,
|
||||
base::Optional<wasm::ValueType::Kind> return_type);
|
||||
static TranslatedFrame JavaScriptBuiltinContinuationFrame(
|
||||
BytecodeOffset bailout_id, SharedFunctionInfo shared_info, int height);
|
||||
static TranslatedFrame JavaScriptBuiltinContinuationWithCatchFrame(
|
||||
BytecodeOffset bailout_id, SharedFunctionInfo shared_info, int height);
|
||||
static TranslatedFrame InvalidFrame() {
|
||||
return TranslatedFrame(kInvalid, SharedFunctionInfo());
|
||||
}
|
||||
|
||||
static void AdvanceIterator(std::deque<TranslatedValue>::iterator* iter);
|
||||
|
||||
TranslatedFrame(Kind kind,
|
||||
SharedFunctionInfo shared_info = SharedFunctionInfo(),
|
||||
int height = 0, int return_value_offset = 0,
|
||||
int return_value_count = 0)
|
||||
: kind_(kind),
|
||||
bytecode_offset_(BytecodeOffset::None()),
|
||||
raw_shared_info_(shared_info),
|
||||
height_(height),
|
||||
return_value_offset_(return_value_offset),
|
||||
return_value_count_(return_value_count) {}
|
||||
|
||||
void Add(const TranslatedValue& value) { values_.push_back(value); }
|
||||
TranslatedValue* ValueAt(int index) { return &(values_[index]); }
|
||||
void Handlify();
|
||||
|
||||
Kind kind_;
|
||||
BytecodeOffset bytecode_offset_;
|
||||
SharedFunctionInfo raw_shared_info_;
|
||||
Handle<SharedFunctionInfo> shared_info_;
|
||||
int height_;
|
||||
int return_value_offset_;
|
||||
int return_value_count_;
|
||||
|
||||
using ValuesContainer = std::deque<TranslatedValue>;
|
||||
|
||||
ValuesContainer values_;
|
||||
|
||||
// Only for Kind == kJSToWasmBuiltinContinuation
|
||||
base::Optional<wasm::ValueType::Kind> return_type_;
|
||||
};
|
||||
|
||||
// Auxiliary class for translating deoptimization values.
|
||||
// Typical usage sequence:
|
||||
//
|
||||
// 1. Construct the instance. This will involve reading out the translations
|
||||
// and resolving them to values using the supplied frame pointer and
|
||||
// machine state (registers). This phase is guaranteed not to allocate
|
||||
// and not to use any HandleScope. Any object pointers will be stored raw.
|
||||
//
|
||||
// 2. Handlify pointers. This will convert all the raw pointers to handles.
|
||||
//
|
||||
// 3. Reading out the frame values.
|
||||
//
|
||||
// Note: After the instance is constructed, it is possible to iterate over
|
||||
// the values eagerly.
|
||||
|
||||
class TranslatedState {
|
||||
public:
|
||||
TranslatedState() = default;
|
||||
explicit TranslatedState(const JavaScriptFrame* frame);
|
||||
|
||||
void Prepare(Address stack_frame_pointer);
|
||||
|
||||
// Store newly materialized values into the isolate.
|
||||
void StoreMaterializedValuesAndDeopt(JavaScriptFrame* frame);
|
||||
|
||||
using iterator = std::vector<TranslatedFrame>::iterator;
|
||||
iterator begin() { return frames_.begin(); }
|
||||
iterator end() { return frames_.end(); }
|
||||
|
||||
using const_iterator = std::vector<TranslatedFrame>::const_iterator;
|
||||
const_iterator begin() const { return frames_.begin(); }
|
||||
const_iterator end() const { return frames_.end(); }
|
||||
|
||||
std::vector<TranslatedFrame>& frames() { return frames_; }
|
||||
|
||||
TranslatedFrame* GetFrameFromJSFrameIndex(int jsframe_index);
|
||||
TranslatedFrame* GetArgumentsInfoFromJSFrameIndex(int jsframe_index,
|
||||
int* arguments_count);
|
||||
|
||||
Isolate* isolate() { return isolate_; }
|
||||
|
||||
void Init(Isolate* isolate, Address input_frame_pointer,
|
||||
Address stack_frame_pointer, TranslationArrayIterator* iterator,
|
||||
FixedArray literal_array, RegisterValues* registers,
|
||||
FILE* trace_file, int parameter_count, int actual_argument_count);
|
||||
|
||||
void VerifyMaterializedObjects();
|
||||
bool DoUpdateFeedback();
|
||||
|
||||
private:
|
||||
friend TranslatedValue;
|
||||
|
||||
TranslatedFrame CreateNextTranslatedFrame(TranslationArrayIterator* iterator,
|
||||
FixedArray literal_array,
|
||||
Address fp, FILE* trace_file);
|
||||
int CreateNextTranslatedValue(int frame_index,
|
||||
TranslationArrayIterator* iterator,
|
||||
FixedArray literal_array, Address fp,
|
||||
RegisterValues* registers, FILE* trace_file);
|
||||
Address DecompressIfNeeded(intptr_t value);
|
||||
void CreateArgumentsElementsTranslatedValues(int frame_index,
|
||||
Address input_frame_pointer,
|
||||
CreateArgumentsType type,
|
||||
FILE* trace_file);
|
||||
|
||||
void UpdateFromPreviouslyMaterializedObjects();
|
||||
void MaterializeFixedDoubleArray(TranslatedFrame* frame, int* value_index,
|
||||
TranslatedValue* slot, Handle<Map> map);
|
||||
void MaterializeHeapNumber(TranslatedFrame* frame, int* value_index,
|
||||
TranslatedValue* slot);
|
||||
|
||||
void EnsureObjectAllocatedAt(TranslatedValue* slot);
|
||||
|
||||
void SkipSlots(int slots_to_skip, TranslatedFrame* frame, int* value_index);
|
||||
|
||||
Handle<ByteArray> AllocateStorageFor(TranslatedValue* slot);
|
||||
void EnsureJSObjectAllocated(TranslatedValue* slot, Handle<Map> map);
|
||||
void EnsurePropertiesAllocatedAndMarked(TranslatedValue* properties_slot,
|
||||
Handle<Map> map);
|
||||
void EnsureChildrenAllocated(int count, TranslatedFrame* frame,
|
||||
int* value_index, std::stack<int>* worklist);
|
||||
void EnsureCapturedObjectAllocatedAt(int object_index,
|
||||
std::stack<int>* worklist);
|
||||
Handle<HeapObject> InitializeObjectAt(TranslatedValue* slot);
|
||||
void InitializeCapturedObjectAt(int object_index, std::stack<int>* worklist,
|
||||
const DisallowGarbageCollection& no_gc);
|
||||
void InitializeJSObjectAt(TranslatedFrame* frame, int* value_index,
|
||||
TranslatedValue* slot, Handle<Map> map,
|
||||
const DisallowGarbageCollection& no_gc);
|
||||
void InitializeObjectWithTaggedFieldsAt(
|
||||
TranslatedFrame* frame, int* value_index, TranslatedValue* slot,
|
||||
Handle<Map> map, const DisallowGarbageCollection& no_gc);
|
||||
|
||||
void ReadUpdateFeedback(TranslationArrayIterator* iterator,
|
||||
FixedArray literal_array, FILE* trace_file);
|
||||
|
||||
TranslatedValue* ResolveCapturedObject(TranslatedValue* slot);
|
||||
TranslatedValue* GetValueByObjectIndex(int object_index);
|
||||
Handle<Object> GetValueAndAdvance(TranslatedFrame* frame, int* value_index);
|
||||
TranslatedValue* GetResolvedSlot(TranslatedFrame* frame, int value_index);
|
||||
TranslatedValue* GetResolvedSlotAndAdvance(TranslatedFrame* frame,
|
||||
int* value_index);
|
||||
|
||||
static uint32_t GetUInt32Slot(Address fp, int slot_index);
|
||||
static uint64_t GetUInt64Slot(Address fp, int slot_index);
|
||||
static Float32 GetFloatSlot(Address fp, int slot_index);
|
||||
static Float64 GetDoubleSlot(Address fp, int slot_index);
|
||||
|
||||
std::vector<TranslatedFrame> frames_;
|
||||
Isolate* isolate_ = nullptr;
|
||||
Address stack_frame_pointer_ = kNullAddress;
|
||||
int formal_parameter_count_;
|
||||
int actual_argument_count_;
|
||||
|
||||
struct ObjectPosition {
|
||||
int frame_index_;
|
||||
int value_index_;
|
||||
};
|
||||
std::deque<ObjectPosition> object_positions_;
|
||||
Handle<FeedbackVector> feedback_vector_handle_;
|
||||
FeedbackVector feedback_vector_;
|
||||
FeedbackSlot feedback_slot_;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
||||
#endif // V8_DEOPTIMIZER_TRANSLATED_STATE_H_
|
39
src/deoptimizer/translation-array.cc
Normal file
39
src/deoptimizer/translation-array.cc
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright 2021 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "src/deoptimizer/translation-array.h"
|
||||
|
||||
#include "src/objects/fixed-array-inl.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
TranslationArrayIterator::TranslationArrayIterator(TranslationArray buffer,
|
||||
int index)
|
||||
: buffer_(buffer), index_(index) {
|
||||
DCHECK(index >= 0 && index < buffer.length());
|
||||
}
|
||||
|
||||
int32_t TranslationArrayIterator::Next() {
|
||||
// Run through the bytes until we reach one with a least significant
|
||||
// bit of zero (marks the end).
|
||||
uint32_t bits = 0;
|
||||
for (int i = 0; true; i += 7) {
|
||||
DCHECK(HasNext());
|
||||
uint8_t next = buffer_.get(index_++);
|
||||
bits |= (next >> 1) << i;
|
||||
if ((next & 1) == 0) break;
|
||||
}
|
||||
// The bits encode the sign in the least significant bit.
|
||||
bool is_negative = (bits & 1) == 1;
|
||||
int32_t result = bits >> 1;
|
||||
return is_negative ? -result : result;
|
||||
}
|
||||
|
||||
bool TranslationArrayIterator::HasNext() const {
|
||||
return index_ < buffer_.length();
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
40
src/deoptimizer/translation-array.h
Normal file
40
src/deoptimizer/translation-array.h
Normal file
@ -0,0 +1,40 @@
|
||||
// Copyright 2021 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef V8_DEOPTIMIZER_TRANSLATION_ARRAY_H_
|
||||
#define V8_DEOPTIMIZER_TRANSLATION_ARRAY_H_
|
||||
|
||||
#include "src/objects/fixed-array.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
// The TranslationArray is the on-heap representation of translations created
|
||||
// during code generation in a (zone-allocated) TranslationBuffer. The
|
||||
// translation array specifies how to transform an optimized frame back into
|
||||
// one or more unoptimized frames.
|
||||
// TODO(jgruber): Consider a real type instead of this type alias.
|
||||
using TranslationArray = ByteArray;
|
||||
|
||||
class TranslationArrayIterator {
|
||||
public:
|
||||
TranslationArrayIterator(TranslationArray buffer, int index);
|
||||
|
||||
int32_t Next();
|
||||
|
||||
bool HasNext() const;
|
||||
|
||||
void Skip(int n) {
|
||||
for (int i = 0; i < n; i++) Next();
|
||||
}
|
||||
|
||||
private:
|
||||
TranslationArray buffer_;
|
||||
int index_;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
||||
#endif // V8_DEOPTIMIZER_TRANSLATION_ARRAY_H_
|
File diff suppressed because it is too large
Load Diff
@ -8,594 +8,17 @@
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
|
||||
#include "src/builtins/builtins.h"
|
||||
#include "src/codegen/register-arch.h"
|
||||
#include "src/execution/frame-constants.h"
|
||||
#include "src/heap/factory.h"
|
||||
#include "src/objects/feedback-vector.h"
|
||||
#include "src/objects/shared-function-info.h"
|
||||
#include "src/utils/boxed-float.h"
|
||||
#include "src/deoptimizer/translated-state.h"
|
||||
#include "src/objects/fixed-array.h"
|
||||
#include "src/wasm/value-type.h"
|
||||
#include "src/zone/zone-chunk-list.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
class RegisterValues;
|
||||
class TranslatedState;
|
||||
class TranslationIterator;
|
||||
|
||||
class TranslatedValue {
|
||||
public:
|
||||
// Allocation-free getter of the value.
|
||||
// Returns ReadOnlyRoots::arguments_marker() if allocation would be necessary
|
||||
// to get the value. In the case of numbers, returns a Smi if possible.
|
||||
Object GetRawValue() const;
|
||||
|
||||
// Convenience wrapper around GetRawValue (checked).
|
||||
int GetSmiValue() const;
|
||||
|
||||
// Returns the value, possibly materializing it first (and the whole subgraph
|
||||
// reachable from this value). In the case of numbers, returns a Smi if
|
||||
// possible.
|
||||
Handle<Object> GetValue();
|
||||
|
||||
bool IsMaterializedObject() const;
|
||||
bool IsMaterializableByDebugger() const;
|
||||
|
||||
private:
|
||||
friend class TranslatedState;
|
||||
friend class TranslatedFrame;
|
||||
friend class Deoptimizer;
|
||||
|
||||
enum Kind : uint8_t {
|
||||
kInvalid,
|
||||
kTagged,
|
||||
kInt32,
|
||||
kInt64,
|
||||
kInt64ToBigInt,
|
||||
kUInt32,
|
||||
kBoolBit,
|
||||
kFloat,
|
||||
kDouble,
|
||||
kCapturedObject, // Object captured by the escape analysis.
|
||||
// The number of nested objects can be obtained
|
||||
// with the DeferredObjectLength() method
|
||||
// (the values of the nested objects follow
|
||||
// this value in the depth-first order.)
|
||||
kDuplicatedObject // Duplicated object of a deferred object.
|
||||
};
|
||||
|
||||
enum MaterializationState : uint8_t {
|
||||
kUninitialized,
|
||||
kAllocated, // Storage for the object has been allocated (or
|
||||
// enqueued for allocation).
|
||||
kFinished, // The object has been initialized (or enqueued for
|
||||
// initialization).
|
||||
};
|
||||
|
||||
TranslatedValue(TranslatedState* container, Kind kind)
|
||||
: kind_(kind), container_(container) {}
|
||||
Kind kind() const { return kind_; }
|
||||
MaterializationState materialization_state() const {
|
||||
return materialization_state_;
|
||||
}
|
||||
void Handlify();
|
||||
int GetChildrenCount() const;
|
||||
|
||||
static TranslatedValue NewDeferredObject(TranslatedState* container,
|
||||
int length, int object_index);
|
||||
static TranslatedValue NewDuplicateObject(TranslatedState* container, int id);
|
||||
static TranslatedValue NewFloat(TranslatedState* container, Float32 value);
|
||||
static TranslatedValue NewDouble(TranslatedState* container, Float64 value);
|
||||
static TranslatedValue NewInt32(TranslatedState* container, int32_t value);
|
||||
static TranslatedValue NewInt64(TranslatedState* container, int64_t value);
|
||||
static TranslatedValue NewInt64ToBigInt(TranslatedState* container,
|
||||
int64_t value);
|
||||
static TranslatedValue NewUInt32(TranslatedState* container, uint32_t value);
|
||||
static TranslatedValue NewBool(TranslatedState* container, uint32_t value);
|
||||
static TranslatedValue NewTagged(TranslatedState* container, Object literal);
|
||||
static TranslatedValue NewInvalid(TranslatedState* container);
|
||||
|
||||
Isolate* isolate() const;
|
||||
|
||||
void set_storage(Handle<HeapObject> storage) { storage_ = storage; }
|
||||
void set_initialized_storage(Handle<HeapObject> storage);
|
||||
void mark_finished() { materialization_state_ = kFinished; }
|
||||
void mark_allocated() { materialization_state_ = kAllocated; }
|
||||
|
||||
Handle<HeapObject> storage() {
|
||||
DCHECK_NE(materialization_state(), kUninitialized);
|
||||
return storage_;
|
||||
}
|
||||
|
||||
Kind kind_;
|
||||
MaterializationState materialization_state_ = kUninitialized;
|
||||
TranslatedState* container_; // This is only needed for materialization of
|
||||
// objects and constructing handles (to get
|
||||
// to the isolate).
|
||||
|
||||
Handle<HeapObject> storage_; // Contains the materialized value or the
|
||||
// byte-array that will be later morphed into
|
||||
// the materialized object.
|
||||
|
||||
struct MaterializedObjectInfo {
|
||||
int id_;
|
||||
int length_; // Applies only to kCapturedObject kinds.
|
||||
};
|
||||
|
||||
union {
|
||||
// kind kTagged. After handlification it is always nullptr.
|
||||
Object raw_literal_;
|
||||
// kind is kUInt32 or kBoolBit.
|
||||
uint32_t uint32_value_;
|
||||
// kind is kInt32.
|
||||
int32_t int32_value_;
|
||||
// kind is kInt64.
|
||||
int64_t int64_value_;
|
||||
// kind is kFloat
|
||||
Float32 float_value_;
|
||||
// kind is kDouble
|
||||
Float64 double_value_;
|
||||
// kind is kDuplicatedObject or kCapturedObject.
|
||||
MaterializedObjectInfo materialization_info_;
|
||||
};
|
||||
|
||||
// Checked accessors for the union members.
|
||||
Object raw_literal() const;
|
||||
int32_t int32_value() const;
|
||||
int64_t int64_value() const;
|
||||
uint32_t uint32_value() const;
|
||||
Float32 float_value() const;
|
||||
Float64 double_value() const;
|
||||
int object_length() const;
|
||||
int object_index() const;
|
||||
};
|
||||
|
||||
class TranslatedFrame {
|
||||
public:
|
||||
enum Kind {
|
||||
kInterpretedFunction,
|
||||
kArgumentsAdaptor,
|
||||
kConstructStub,
|
||||
kBuiltinContinuation,
|
||||
kJSToWasmBuiltinContinuation,
|
||||
kJavaScriptBuiltinContinuation,
|
||||
kJavaScriptBuiltinContinuationWithCatch,
|
||||
kInvalid
|
||||
};
|
||||
|
||||
int GetValueCount();
|
||||
|
||||
Kind kind() const { return kind_; }
|
||||
BytecodeOffset bytecode_offset() const { return bytecode_offset_; }
|
||||
Handle<SharedFunctionInfo> shared_info() const { return shared_info_; }
|
||||
|
||||
// TODO(jgruber): Simplify/clarify the semantics of this field. The name
|
||||
// `height` is slightly misleading. Yes, this value is related to stack frame
|
||||
// height, but must undergo additional mutations to arrive at the real stack
|
||||
// frame height (e.g.: addition/subtraction of context, accumulator, fixed
|
||||
// frame sizes, padding).
|
||||
int height() const { return height_; }
|
||||
|
||||
int return_value_offset() const { return return_value_offset_; }
|
||||
int return_value_count() const { return return_value_count_; }
|
||||
|
||||
SharedFunctionInfo raw_shared_info() const {
|
||||
CHECK(!raw_shared_info_.is_null());
|
||||
return raw_shared_info_;
|
||||
}
|
||||
|
||||
class iterator {
|
||||
public:
|
||||
iterator& operator++() {
|
||||
++input_index_;
|
||||
AdvanceIterator(&position_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
iterator operator++(int) {
|
||||
iterator original(position_, input_index_);
|
||||
++input_index_;
|
||||
AdvanceIterator(&position_);
|
||||
return original;
|
||||
}
|
||||
|
||||
bool operator==(const iterator& other) const {
|
||||
// Ignore {input_index_} for equality.
|
||||
return position_ == other.position_;
|
||||
}
|
||||
bool operator!=(const iterator& other) const { return !(*this == other); }
|
||||
|
||||
TranslatedValue& operator*() { return (*position_); }
|
||||
TranslatedValue* operator->() { return &(*position_); }
|
||||
const TranslatedValue& operator*() const { return (*position_); }
|
||||
const TranslatedValue* operator->() const { return &(*position_); }
|
||||
|
||||
int input_index() const { return input_index_; }
|
||||
|
||||
private:
|
||||
friend TranslatedFrame;
|
||||
|
||||
explicit iterator(std::deque<TranslatedValue>::iterator position,
|
||||
int input_index = 0)
|
||||
: position_(position), input_index_(input_index) {}
|
||||
|
||||
std::deque<TranslatedValue>::iterator position_;
|
||||
int input_index_;
|
||||
};
|
||||
|
||||
using reference = TranslatedValue&;
|
||||
using const_reference = TranslatedValue const&;
|
||||
|
||||
iterator begin() { return iterator(values_.begin()); }
|
||||
iterator end() { return iterator(values_.end()); }
|
||||
|
||||
reference front() { return values_.front(); }
|
||||
const_reference front() const { return values_.front(); }
|
||||
|
||||
// Only for Kind == kJSToWasmBuiltinContinuation
|
||||
base::Optional<wasm::ValueType::Kind> wasm_call_return_type() const {
|
||||
DCHECK_EQ(kind(), kJSToWasmBuiltinContinuation);
|
||||
return return_type_;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class TranslatedState;
|
||||
friend class Deoptimizer;
|
||||
|
||||
// Constructor static methods.
|
||||
static TranslatedFrame InterpretedFrame(BytecodeOffset bytecode_offset,
|
||||
SharedFunctionInfo shared_info,
|
||||
int height, int return_value_offset,
|
||||
int return_value_count);
|
||||
static TranslatedFrame AccessorFrame(Kind kind,
|
||||
SharedFunctionInfo shared_info);
|
||||
static TranslatedFrame ArgumentsAdaptorFrame(SharedFunctionInfo shared_info,
|
||||
int height);
|
||||
static TranslatedFrame ConstructStubFrame(BytecodeOffset bailout_id,
|
||||
SharedFunctionInfo shared_info,
|
||||
int height);
|
||||
static TranslatedFrame BuiltinContinuationFrame(
|
||||
BytecodeOffset bailout_id, SharedFunctionInfo shared_info, int height);
|
||||
static TranslatedFrame JSToWasmBuiltinContinuationFrame(
|
||||
BytecodeOffset bailout_id, SharedFunctionInfo shared_info, int height,
|
||||
base::Optional<wasm::ValueType::Kind> return_type);
|
||||
static TranslatedFrame JavaScriptBuiltinContinuationFrame(
|
||||
BytecodeOffset bailout_id, SharedFunctionInfo shared_info, int height);
|
||||
static TranslatedFrame JavaScriptBuiltinContinuationWithCatchFrame(
|
||||
BytecodeOffset bailout_id, SharedFunctionInfo shared_info, int height);
|
||||
static TranslatedFrame InvalidFrame() {
|
||||
return TranslatedFrame(kInvalid, SharedFunctionInfo());
|
||||
}
|
||||
|
||||
static void AdvanceIterator(std::deque<TranslatedValue>::iterator* iter);
|
||||
|
||||
TranslatedFrame(Kind kind,
|
||||
SharedFunctionInfo shared_info = SharedFunctionInfo(),
|
||||
int height = 0, int return_value_offset = 0,
|
||||
int return_value_count = 0)
|
||||
: kind_(kind),
|
||||
bytecode_offset_(BytecodeOffset::None()),
|
||||
raw_shared_info_(shared_info),
|
||||
height_(height),
|
||||
return_value_offset_(return_value_offset),
|
||||
return_value_count_(return_value_count) {}
|
||||
|
||||
void Add(const TranslatedValue& value) { values_.push_back(value); }
|
||||
TranslatedValue* ValueAt(int index) { return &(values_[index]); }
|
||||
void Handlify();
|
||||
|
||||
Kind kind_;
|
||||
BytecodeOffset bytecode_offset_;
|
||||
SharedFunctionInfo raw_shared_info_;
|
||||
Handle<SharedFunctionInfo> shared_info_;
|
||||
int height_;
|
||||
int return_value_offset_;
|
||||
int return_value_count_;
|
||||
|
||||
using ValuesContainer = std::deque<TranslatedValue>;
|
||||
|
||||
ValuesContainer values_;
|
||||
|
||||
// Only for Kind == kJSToWasmBuiltinContinuation
|
||||
base::Optional<wasm::ValueType::Kind> return_type_;
|
||||
};
|
||||
|
||||
// Auxiliary class for translating deoptimization values.
|
||||
// Typical usage sequence:
|
||||
//
|
||||
// 1. Construct the instance. This will involve reading out the translations
|
||||
// and resolving them to values using the supplied frame pointer and
|
||||
// machine state (registers). This phase is guaranteed not to allocate
|
||||
// and not to use any HandleScope. Any object pointers will be stored raw.
|
||||
//
|
||||
// 2. Handlify pointers. This will convert all the raw pointers to handles.
|
||||
//
|
||||
// 3. Reading out the frame values.
|
||||
//
|
||||
// Note: After the instance is constructed, it is possible to iterate over
|
||||
// the values eagerly.
|
||||
|
||||
class TranslatedState {
|
||||
public:
|
||||
TranslatedState() = default;
|
||||
explicit TranslatedState(const JavaScriptFrame* frame);
|
||||
|
||||
void Prepare(Address stack_frame_pointer);
|
||||
|
||||
// Store newly materialized values into the isolate.
|
||||
void StoreMaterializedValuesAndDeopt(JavaScriptFrame* frame);
|
||||
|
||||
using iterator = std::vector<TranslatedFrame>::iterator;
|
||||
iterator begin() { return frames_.begin(); }
|
||||
iterator end() { return frames_.end(); }
|
||||
|
||||
using const_iterator = std::vector<TranslatedFrame>::const_iterator;
|
||||
const_iterator begin() const { return frames_.begin(); }
|
||||
const_iterator end() const { return frames_.end(); }
|
||||
|
||||
std::vector<TranslatedFrame>& frames() { return frames_; }
|
||||
|
||||
TranslatedFrame* GetFrameFromJSFrameIndex(int jsframe_index);
|
||||
TranslatedFrame* GetArgumentsInfoFromJSFrameIndex(int jsframe_index,
|
||||
int* arguments_count);
|
||||
|
||||
Isolate* isolate() { return isolate_; }
|
||||
|
||||
void Init(Isolate* isolate, Address input_frame_pointer,
|
||||
Address stack_frame_pointer, TranslationIterator* iterator,
|
||||
FixedArray literal_array, RegisterValues* registers,
|
||||
FILE* trace_file, int parameter_count, int actual_argument_count);
|
||||
|
||||
void VerifyMaterializedObjects();
|
||||
bool DoUpdateFeedback();
|
||||
|
||||
private:
|
||||
friend TranslatedValue;
|
||||
|
||||
TranslatedFrame CreateNextTranslatedFrame(TranslationIterator* iterator,
|
||||
FixedArray literal_array,
|
||||
Address fp, FILE* trace_file);
|
||||
int CreateNextTranslatedValue(int frame_index, TranslationIterator* iterator,
|
||||
FixedArray literal_array, Address fp,
|
||||
RegisterValues* registers, FILE* trace_file);
|
||||
Address DecompressIfNeeded(intptr_t value);
|
||||
void CreateArgumentsElementsTranslatedValues(int frame_index,
|
||||
Address input_frame_pointer,
|
||||
CreateArgumentsType type,
|
||||
FILE* trace_file);
|
||||
|
||||
void UpdateFromPreviouslyMaterializedObjects();
|
||||
void MaterializeFixedDoubleArray(TranslatedFrame* frame, int* value_index,
|
||||
TranslatedValue* slot, Handle<Map> map);
|
||||
void MaterializeHeapNumber(TranslatedFrame* frame, int* value_index,
|
||||
TranslatedValue* slot);
|
||||
|
||||
void EnsureObjectAllocatedAt(TranslatedValue* slot);
|
||||
|
||||
void SkipSlots(int slots_to_skip, TranslatedFrame* frame, int* value_index);
|
||||
|
||||
Handle<ByteArray> AllocateStorageFor(TranslatedValue* slot);
|
||||
void EnsureJSObjectAllocated(TranslatedValue* slot, Handle<Map> map);
|
||||
void EnsurePropertiesAllocatedAndMarked(TranslatedValue* properties_slot,
|
||||
Handle<Map> map);
|
||||
void EnsureChildrenAllocated(int count, TranslatedFrame* frame,
|
||||
int* value_index, std::stack<int>* worklist);
|
||||
void EnsureCapturedObjectAllocatedAt(int object_index,
|
||||
std::stack<int>* worklist);
|
||||
Handle<HeapObject> InitializeObjectAt(TranslatedValue* slot);
|
||||
void InitializeCapturedObjectAt(int object_index, std::stack<int>* worklist,
|
||||
const DisallowGarbageCollection& no_gc);
|
||||
void InitializeJSObjectAt(TranslatedFrame* frame, int* value_index,
|
||||
TranslatedValue* slot, Handle<Map> map,
|
||||
const DisallowGarbageCollection& no_gc);
|
||||
void InitializeObjectWithTaggedFieldsAt(
|
||||
TranslatedFrame* frame, int* value_index, TranslatedValue* slot,
|
||||
Handle<Map> map, const DisallowGarbageCollection& no_gc);
|
||||
|
||||
void ReadUpdateFeedback(TranslationIterator* iterator,
|
||||
FixedArray literal_array, FILE* trace_file);
|
||||
|
||||
TranslatedValue* ResolveCapturedObject(TranslatedValue* slot);
|
||||
TranslatedValue* GetValueByObjectIndex(int object_index);
|
||||
Handle<Object> GetValueAndAdvance(TranslatedFrame* frame, int* value_index);
|
||||
TranslatedValue* GetResolvedSlot(TranslatedFrame* frame, int value_index);
|
||||
TranslatedValue* GetResolvedSlotAndAdvance(TranslatedFrame* frame,
|
||||
int* value_index);
|
||||
|
||||
static uint32_t GetUInt32Slot(Address fp, int slot_index);
|
||||
static uint64_t GetUInt64Slot(Address fp, int slot_index);
|
||||
static Float32 GetFloatSlot(Address fp, int slot_index);
|
||||
static Float64 GetDoubleSlot(Address fp, int slot_index);
|
||||
|
||||
std::vector<TranslatedFrame> frames_;
|
||||
Isolate* isolate_ = nullptr;
|
||||
Address stack_frame_pointer_ = kNullAddress;
|
||||
int formal_parameter_count_;
|
||||
int actual_argument_count_;
|
||||
|
||||
struct ObjectPosition {
|
||||
int frame_index_;
|
||||
int value_index_;
|
||||
};
|
||||
std::deque<ObjectPosition> object_positions_;
|
||||
Handle<FeedbackVector> feedback_vector_handle_;
|
||||
FeedbackVector feedback_vector_;
|
||||
FeedbackSlot feedback_slot_;
|
||||
};
|
||||
|
||||
class RegisterValues {
|
||||
public:
|
||||
intptr_t GetRegister(unsigned n) const {
|
||||
#if DEBUG
|
||||
// This convoluted DCHECK is needed to work around a gcc problem that
|
||||
// improperly detects an array bounds overflow in optimized debug builds
|
||||
// when using a plain DCHECK.
|
||||
if (n >= arraysize(registers_)) {
|
||||
DCHECK(false);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return registers_[n];
|
||||
}
|
||||
|
||||
Float32 GetFloatRegister(unsigned n) const;
|
||||
|
||||
Float64 GetDoubleRegister(unsigned n) const {
|
||||
DCHECK(n < arraysize(double_registers_));
|
||||
return double_registers_[n];
|
||||
}
|
||||
|
||||
void SetRegister(unsigned n, intptr_t value) {
|
||||
DCHECK(n < arraysize(registers_));
|
||||
registers_[n] = value;
|
||||
}
|
||||
|
||||
intptr_t registers_[Register::kNumRegisters];
|
||||
// Generated code writes directly into the following array, make sure the
|
||||
// element size matches what the machine instructions expect.
|
||||
static_assert(sizeof(Float64) == kDoubleSize, "size mismatch");
|
||||
Float64 double_registers_[DoubleRegister::kNumRegisters];
|
||||
};
|
||||
|
||||
class FrameDescription {
|
||||
public:
|
||||
explicit FrameDescription(uint32_t frame_size, int parameter_count = 0);
|
||||
|
||||
void* operator new(size_t size, uint32_t frame_size) {
|
||||
// Subtracts kSystemPointerSize, as the member frame_content_ already
|
||||
// supplies the first element of the area to store the frame.
|
||||
return base::Malloc(size + frame_size - kSystemPointerSize);
|
||||
}
|
||||
|
||||
void operator delete(void* pointer, uint32_t frame_size) {
|
||||
base::Free(pointer);
|
||||
}
|
||||
|
||||
void operator delete(void* description) { base::Free(description); }
|
||||
|
||||
uint32_t GetFrameSize() const {
|
||||
USE(frame_content_);
|
||||
DCHECK(static_cast<uint32_t>(frame_size_) == frame_size_);
|
||||
return static_cast<uint32_t>(frame_size_);
|
||||
}
|
||||
|
||||
intptr_t GetFrameSlot(unsigned offset) {
|
||||
return *GetFrameSlotPointer(offset);
|
||||
}
|
||||
|
||||
unsigned GetLastArgumentSlotOffset(bool pad_arguments = true) {
|
||||
int parameter_slots = parameter_count();
|
||||
if (pad_arguments && ShouldPadArguments(parameter_slots)) parameter_slots++;
|
||||
return GetFrameSize() - parameter_slots * kSystemPointerSize;
|
||||
}
|
||||
|
||||
Address GetFramePointerAddress() {
|
||||
// We should not pad arguments in the bottom frame, since this
|
||||
// already contain a padding if necessary and it might contain
|
||||
// extra arguments (actual argument count > parameter count).
|
||||
const bool pad_arguments_bottom_frame = false;
|
||||
int fp_offset = GetLastArgumentSlotOffset(pad_arguments_bottom_frame) -
|
||||
StandardFrameConstants::kCallerSPOffset;
|
||||
return reinterpret_cast<Address>(GetFrameSlotPointer(fp_offset));
|
||||
}
|
||||
|
||||
RegisterValues* GetRegisterValues() { return ®ister_values_; }
|
||||
|
||||
void SetFrameSlot(unsigned offset, intptr_t value) {
|
||||
*GetFrameSlotPointer(offset) = value;
|
||||
}
|
||||
|
||||
void SetCallerPc(unsigned offset, intptr_t value);
|
||||
|
||||
void SetCallerFp(unsigned offset, intptr_t value);
|
||||
|
||||
void SetCallerConstantPool(unsigned offset, intptr_t value);
|
||||
|
||||
intptr_t GetRegister(unsigned n) const {
|
||||
return register_values_.GetRegister(n);
|
||||
}
|
||||
|
||||
Float64 GetDoubleRegister(unsigned n) const {
|
||||
return register_values_.GetDoubleRegister(n);
|
||||
}
|
||||
|
||||
void SetRegister(unsigned n, intptr_t value) {
|
||||
register_values_.SetRegister(n, value);
|
||||
}
|
||||
|
||||
intptr_t GetTop() const { return top_; }
|
||||
void SetTop(intptr_t top) { top_ = top; }
|
||||
|
||||
intptr_t GetPc() const { return pc_; }
|
||||
void SetPc(intptr_t pc);
|
||||
|
||||
intptr_t GetFp() const { return fp_; }
|
||||
void SetFp(intptr_t fp) { fp_ = fp; }
|
||||
|
||||
intptr_t GetContext() const { return context_; }
|
||||
void SetContext(intptr_t context) { context_ = context; }
|
||||
|
||||
intptr_t GetConstantPool() const { return constant_pool_; }
|
||||
void SetConstantPool(intptr_t constant_pool) {
|
||||
constant_pool_ = constant_pool;
|
||||
}
|
||||
|
||||
void SetContinuation(intptr_t pc) { continuation_ = pc; }
|
||||
|
||||
// Argument count, including receiver.
|
||||
int parameter_count() { return parameter_count_; }
|
||||
|
||||
static int registers_offset() {
|
||||
return offsetof(FrameDescription, register_values_.registers_);
|
||||
}
|
||||
|
||||
static constexpr int double_registers_offset() {
|
||||
return offsetof(FrameDescription, register_values_.double_registers_);
|
||||
}
|
||||
|
||||
static int frame_size_offset() {
|
||||
return offsetof(FrameDescription, frame_size_);
|
||||
}
|
||||
|
||||
static int pc_offset() { return offsetof(FrameDescription, pc_); }
|
||||
|
||||
static int continuation_offset() {
|
||||
return offsetof(FrameDescription, continuation_);
|
||||
}
|
||||
|
||||
static int frame_content_offset() {
|
||||
return offsetof(FrameDescription, frame_content_);
|
||||
}
|
||||
|
||||
private:
|
||||
static const uint32_t kZapUint32 = 0xbeeddead;
|
||||
|
||||
// Frame_size_ must hold a uint32_t value. It is only a uintptr_t to
|
||||
// keep the variable-size array frame_content_ of type intptr_t at
|
||||
// the end of the structure aligned.
|
||||
uintptr_t frame_size_; // Number of bytes.
|
||||
int parameter_count_;
|
||||
RegisterValues register_values_;
|
||||
intptr_t top_;
|
||||
intptr_t pc_;
|
||||
intptr_t fp_;
|
||||
intptr_t context_;
|
||||
intptr_t constant_pool_;
|
||||
|
||||
// Continuation is the PC where the execution continues after
|
||||
// deoptimizing.
|
||||
intptr_t continuation_;
|
||||
|
||||
// This must be at the end of the object as the object is allocated larger
|
||||
// than its definition indicates to extend this array.
|
||||
intptr_t frame_content_[1];
|
||||
|
||||
intptr_t* GetFrameSlotPointer(unsigned offset) {
|
||||
DCHECK(offset < frame_size_);
|
||||
return reinterpret_cast<intptr_t*>(reinterpret_cast<Address>(this) +
|
||||
frame_content_offset() + offset);
|
||||
}
|
||||
};
|
||||
class Factory;
|
||||
|
||||
class TranslationBuffer {
|
||||
public:
|
||||
@ -610,23 +33,6 @@ class TranslationBuffer {
|
||||
ZoneChunkList<uint8_t> contents_;
|
||||
};
|
||||
|
||||
class TranslationIterator {
|
||||
public:
|
||||
TranslationIterator(ByteArray buffer, int index);
|
||||
|
||||
int32_t Next();
|
||||
|
||||
bool HasNext() const;
|
||||
|
||||
void Skip(int n) {
|
||||
for (int i = 0; i < n; i++) Next();
|
||||
}
|
||||
|
||||
private:
|
||||
ByteArray buffer_;
|
||||
int index_;
|
||||
};
|
||||
|
||||
#define TRANSLATION_OPCODE_LIST(V) \
|
||||
V(BEGIN) \
|
||||
V(INTERPRETED_FRAME) \
|
||||
@ -728,84 +134,6 @@ class Translation {
|
||||
Zone* zone_;
|
||||
};
|
||||
|
||||
class MaterializedObjectStore {
|
||||
public:
|
||||
explicit MaterializedObjectStore(Isolate* isolate) : isolate_(isolate) {}
|
||||
|
||||
Handle<FixedArray> Get(Address fp);
|
||||
void Set(Address fp, Handle<FixedArray> materialized_objects);
|
||||
bool Remove(Address fp);
|
||||
|
||||
private:
|
||||
Isolate* isolate() const { return isolate_; }
|
||||
Handle<FixedArray> GetStackEntries();
|
||||
Handle<FixedArray> EnsureStackEntries(int size);
|
||||
|
||||
int StackIdToIndex(Address fp);
|
||||
|
||||
Isolate* isolate_;
|
||||
std::vector<Address> frame_fps_;
|
||||
};
|
||||
|
||||
// Class used to represent an unoptimized frame when the debugger
|
||||
// needs to inspect a frame that is part of an optimized frame. The
|
||||
// internally used FrameDescription objects are not GC safe so for use
|
||||
// by the debugger frame information is copied to an object of this type.
|
||||
// Represents parameters in unadapted form so their number might mismatch
|
||||
// formal parameter count.
|
||||
class DeoptimizedFrameInfo : public Malloced {
|
||||
public:
|
||||
DeoptimizedFrameInfo(TranslatedState* state,
|
||||
TranslatedState::iterator frame_it, Isolate* isolate);
|
||||
|
||||
// Return the number of incoming arguments.
|
||||
int parameters_count() { return static_cast<int>(parameters_.size()); }
|
||||
|
||||
// Return the height of the expression stack.
|
||||
int expression_count() { return static_cast<int>(expression_stack_.size()); }
|
||||
|
||||
// Get the frame function.
|
||||
Handle<JSFunction> GetFunction() { return function_; }
|
||||
|
||||
// Get the frame context.
|
||||
Handle<Object> GetContext() { return context_; }
|
||||
|
||||
// Get an incoming argument.
|
||||
Handle<Object> GetParameter(int index) {
|
||||
DCHECK(0 <= index && index < parameters_count());
|
||||
return parameters_[index];
|
||||
}
|
||||
|
||||
// Get an expression from the expression stack.
|
||||
Handle<Object> GetExpression(int index) {
|
||||
DCHECK(0 <= index && index < expression_count());
|
||||
return expression_stack_[index];
|
||||
}
|
||||
|
||||
int GetSourcePosition() { return source_position_; }
|
||||
|
||||
private:
|
||||
// Set an incoming argument.
|
||||
void SetParameter(int index, Handle<Object> obj) {
|
||||
DCHECK(0 <= index && index < parameters_count());
|
||||
parameters_[index] = obj;
|
||||
}
|
||||
|
||||
// Set an expression on the expression stack.
|
||||
void SetExpression(int index, Handle<Object> obj) {
|
||||
DCHECK(0 <= index && index < expression_count());
|
||||
expression_stack_[index] = obj;
|
||||
}
|
||||
|
||||
Handle<JSFunction> function_;
|
||||
Handle<Object> context_;
|
||||
std::vector<Handle<Object> > parameters_;
|
||||
std::vector<Handle<Object> > expression_stack_;
|
||||
int source_position_;
|
||||
|
||||
friend class Deoptimizer;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
||||
|
@ -1642,8 +1642,8 @@ void OptimizedFrame::GetFunctions(
|
||||
DCHECK_NE(Safepoint::kNoDeoptimizationIndex, deopt_index);
|
||||
FixedArray const literal_array = data.LiteralArray();
|
||||
|
||||
TranslationIterator it(data.TranslationByteArray(),
|
||||
data.TranslationIndex(deopt_index).value());
|
||||
TranslationArrayIterator it(data.TranslationByteArray(),
|
||||
data.TranslationIndex(deopt_index).value());
|
||||
Translation::Opcode opcode = static_cast<Translation::Opcode>(it.Next());
|
||||
DCHECK_EQ(Translation::BEGIN, opcode);
|
||||
it.Next(); // Skip frame count.
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "src/debug/debug-frames.h"
|
||||
#include "src/debug/debug.h"
|
||||
#include "src/deoptimizer/deoptimizer.h"
|
||||
#include "src/deoptimizer/materialized-object-store.h"
|
||||
#include "src/diagnostics/basic-block-profiler.h"
|
||||
#include "src/diagnostics/compilation-statistics.h"
|
||||
#include "src/execution/frames-inl.h"
|
||||
|
@ -762,7 +762,7 @@ int BytecodeArray::SizeIncludingMetadata() {
|
||||
return size;
|
||||
}
|
||||
|
||||
DEFINE_DEOPT_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray)
|
||||
DEFINE_DEOPT_ELEMENT_ACCESSORS(TranslationByteArray, TranslationArray)
|
||||
DEFINE_DEOPT_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi)
|
||||
DEFINE_DEOPT_ELEMENT_ACCESSORS(LiteralArray, FixedArray)
|
||||
DEFINE_DEOPT_ELEMENT_ACCESSORS(OsrBytecodeOffset, Smi)
|
||||
|
@ -469,7 +469,8 @@ void DeoptimizationData::DeoptimizationDataPrint(std::ostream& os) { // NOLINT
|
||||
|
||||
// Print details of the frame translation.
|
||||
int translation_index = TranslationIndex(i).value();
|
||||
TranslationIterator iterator(TranslationByteArray(), translation_index);
|
||||
TranslationArrayIterator iterator(TranslationByteArray(),
|
||||
translation_index);
|
||||
Translation::Opcode opcode =
|
||||
static_cast<Translation::Opcode>(iterator.Next());
|
||||
DCHECK(Translation::BEGIN == opcode);
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/codegen/handler-table.h"
|
||||
#include "src/deoptimizer/translation-array.h"
|
||||
#include "src/objects/code-kind.h"
|
||||
#include "src/objects/contexts.h"
|
||||
#include "src/objects/fixed-array.h"
|
||||
@ -865,7 +866,7 @@ class DeoptimizationData : public FixedArray {
|
||||
inline type name() const; \
|
||||
inline void Set##name(type value);
|
||||
|
||||
DECL_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray)
|
||||
DECL_ELEMENT_ACCESSORS(TranslationByteArray, TranslationArray)
|
||||
DECL_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi)
|
||||
DECL_ELEMENT_ACCESSORS(LiteralArray, FixedArray)
|
||||
DECL_ELEMENT_ACCESSORS(OsrBytecodeOffset, Smi)
|
||||
|
Loading…
Reference in New Issue
Block a user