/
githubmirror
/
node
Обзор
Документация
Войти
/
githubmirror
/
node
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
deps/v8/src/dumpling/dumpling-manager.h
181 строка
5 KB
Michaël Zasso
deps: update V8 to 14.6.202.33
24 апр 2026, 19:01
Не верифицирован
24 апр 2026, 19:01
f1e0b83
Код
Авторство
О чём код?
// Copyright 2025 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_DUMPLING_DUMPLING_MANAGER_H_ #define V8_DUMPLING_DUMPLING_MANAGER_H_ #include <ostream> #include "src/deoptimizer/deoptimizer.h" #include "src/execution/frames.h" #include "src/interpreter/bytecodes.h" namespace v8::internal { typedef enum DumpFrameType { kInterpreterFrame = 0, kSparkplugFrame = 1, kMaglevFrame = 2, kTurbofanFrame = 3 } DumpFrameType; // Wrapper around UnoptimizedJSFunction or FrameDescription. We can't // convert FrameDescription to UnoptimizedJSFunction without invasive // constructor hacking in the deoptimizer. Therefore we choose to wrap. class DumplingJSFrame { public: virtual Tagged<Object> GetRegisterValue(int reg_idx) = 0; virtual Tagged<Object> GetParameter(int param_idx) = 0; virtual Tagged<JSFunction> function() = 0; }; class DumplingUnoptimizedJSFrame : public DumplingJSFrame { public: explicit DumplingUnoptimizedJSFrame(UnoptimizedJSFrame* frame) : frame_(frame) {} Tagged<Object> GetRegisterValue(int reg_idx) override { return frame_->ReadInterpreterRegister(reg_idx); } Tagged<Object> GetParameter(int param_idx) override { return frame_->GetParameter(param_idx); } Tagged<JSFunction> function() override; private: UnoptimizedJSFrame* frame_; }; class DumplingFrameDescriptionFrame : public DumplingJSFrame { public: explicit DumplingFrameDescriptionFrame(FrameDescription* frame, Isolate* isolate) : frame_(frame), isolate_(isolate) {} Tagged<Object> GetRegisterValue(int reg_idx) override { int offset_from_fp = UnoptimizedFrameConstants::kExpressionsOffset - (reg_idx * kSystemPointerSize); return GetValueFromDescription(offset_from_fp); } Tagged<Object> GetParameter(int param_idx) override { int offset_from_fp = CommonFrameConstants::kCallerSPOffset + ((param_idx + 1) * kSystemPointerSize); return GetValueFromDescription(offset_from_fp); } Tagged<JSFunction> function() override; private: Tagged<Object> GetValueFromDescription(int offset_from_fp); Tagged<Object> function_slot_object() { int offset_from_fp = StandardFrameConstants::kFunctionOffset; return GetValueFromDescription(offset_from_fp); } FrameDescription* frame_; Isolate* isolate_; }; class DumplingManager { public: DumplingManager(); ~DumplingManager(); void SetIsolateDumpDisabled() { isolate_dumping_disabled_ = true; } bool IsIsolateDumpDisabled() const { return isolate_dumping_disabled_; } bool IsDumpingEnabled() const { return !IsIsolateDumpDisabled() && AnyDumplingFlagsSet(); } void DoPrint(DumplingJSFrame* frame, Tagged<JSFunction> function, int bytecode_offset, DumpFrameType frame_dump_type, Handle<BytecodeArray> bytecode_array, Handle<Object> accumulator); // Need to make sure that dumps were flushed to the dump file. void FinishCurrentREPRLCycle(); // We need to clean files and caches. void PrepareForNextREPRLCycle(); void PrintDumpedFrame(DumplingJSFrame* frame, Tagged<JSFunction> function, Isolate* isolate, int bytecode_offset, DumpFrameType frame_dump_type); void set_print_into_string(bool print_into_string) { print_into_string_ = print_into_string; } std::string GetOutput() { DCHECK(print_into_string_); DCHECK(dumpling_stream_); return static_cast<std::ostringstream*>(dumpling_stream_.get())->str(); } private: bool AnyDumplingFlagsSet() const; std::string GetDumpOutFilename() const; std::string GetDumpPositionsFilename() const; template <typename T> std::optional<std::string> DumpValuePlain(T value, T& last_value); template <typename T> std::optional<std::string> DumpValue(T value, T& last_value); std::optional<std::string> DumpBytecodeOffset(int bytecode_offset); std::optional<std::string> DumpFunctionId(int function_id); std::optional<std::string> DumpArgCount(int arg_count); std::optional<std::string> DumpRegCount(int reg_count); std::optional<std::string> DumpArg(unsigned int index, std::string arg); std::optional<std::string> DumpReg(unsigned int index, std::string reg); std::optional<std::string> DumpAcc(std::string acc); void RecordDumpPosition(int function_id, int bytecode_offset); // We write dump positions to file on dumpling manager destruction because we // deduplicate dump positions in a map to not spam the file contents with // many dupes. void WriteDumpPositionsToFile(); void LoadDumpPositionsFromFile(); void ResetLastFrame(); bool isolate_dumping_disabled_ = false; struct DumplingLastFrame { int bytecode_offset; std::string acc; int arg_count; std::vector<std::string> args; int reg_count; std::vector<std::string> regs; int function_id; }; DumplingLastFrame dumpling_last_frame_; // Gather the output into a string instead of printing out to a file. bool print_into_string_ = false; std::unique_ptr<std::ostream> dumpling_stream_; std::unordered_map<int, std::unordered_set<int> > dump_positions_; }; } // namespace v8::internal #endif // V8_DUMPLING_DUMPLING_MANAGER_H_