Skip to content

Commit b9c7fc2

Browse files
ngzhianV8 LUCI CQ
authored andcommitted
Revert "[wasm][diagnostics] Support WasmCode in gdb JIT integration"
This reverts commit a3b2c4e. Reason for revert: UBSan https://logs.chromium.org/logs/v8/buildbucket/cr-buildbucket/8839060153390139249/+/u/Check/gdbjit Original change's description: > [wasm][diagnostics] Support WasmCode in gdb JIT integration > > - Add new enum WASM_CODE to JitCodeEvent::CodeType > - Use AddressRegion instead of AddressRange (remove the latter) > - Change CodeDescription constructor to take an AddressRegion, > both JIT_CODE and WASM_CODE use this > - Add a simple mjsunit test that sets --gdbjit to check that > we don't crash. > - Add a api test for adding WASM_CODE > > Bug: v8:11908 > Change-Id: I6e87fadc2df67978144d78caf9800c3982bc3705 > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3067754 > Reviewed-by: Adam Klein <adamk@chromium.org> > Reviewed-by: Clemens Backes <clemensb@chromium.org> > Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> > Commit-Queue: Zhi An Ng <zhin@chromium.org> > Cr-Commit-Position: refs/heads/master@{#76271} Bug: v8:11908 Change-Id: Ic1a74a9239e8ef6107efd36f61c089ae6bfc5b6c No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3093365 Auto-Submit: Zhi An Ng <zhin@chromium.org> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Cr-Commit-Position: refs/heads/master@{#76274}
1 parent 457112f commit b9c7fc2

8 files changed

Lines changed: 80 additions & 182 deletions

File tree

include/v8.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7848,13 +7848,13 @@ struct JitCodeEvent {
78487848
// statement, and is used to indicate possible break locations.
78497849
enum PositionType { POSITION, STATEMENT_POSITION };
78507850

7851-
// There are three different kinds of CodeType, one for JIT code generated
7852-
// by the optimizing compiler, one for byte code generated for the
7853-
// interpreter, and one for code generated from Wasm. For JIT_CODE and
7854-
// WASM_CODE, |code_start| points to the beginning of jitted assembly code,
7855-
// while for BYTE_CODE events, |code_start| points to the first bytecode of
7856-
// the interpreted function.
7857-
enum CodeType { BYTE_CODE, JIT_CODE, WASM_CODE };
7851+
// There are two different kinds of JitCodeEvents, one for JIT code generated
7852+
// by the optimizing compiler, and one for byte code generated for the
7853+
// interpreter. For JIT_CODE events, the |code_start| member of the event
7854+
// points to the beginning of jitted assembly code, while for BYTE_CODE
7855+
// events, |code_start| points to the first bytecode of the interpreted
7856+
// function.
7857+
enum CodeType { BYTE_CODE, JIT_CODE };
78587858

78597859
// Type of event.
78607860
EventType type;

src/diagnostics/gdb-jit.cc

Lines changed: 57 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include "include/v8.h"
1212
#include "src/api/api-inl.h"
13-
#include "src/base/address-region.h"
1413
#include "src/base/bits.h"
1514
#include "src/base/hashmap.h"
1615
#include "src/base/platform/platform.h"
@@ -897,20 +896,17 @@ class CodeDescription {
897896
};
898897
#endif
899898

900-
CodeDescription(const char* name, base::AddressRegion region,
901-
SharedFunctionInfo shared, LineInfo* lineinfo,
902-
bool is_function)
903-
: name_(name),
904-
shared_info_(shared),
905-
lineinfo_(lineinfo),
906-
is_function_(is_function),
907-
code_region_(region) {}
899+
CodeDescription(const char* name, Code code, SharedFunctionInfo shared,
900+
LineInfo* lineinfo)
901+
: name_(name), code_(code), shared_info_(shared), lineinfo_(lineinfo) {}
908902

909903
const char* name() const { return name_; }
910904

911905
LineInfo* lineinfo() const { return lineinfo_; }
912906

913-
bool is_function() const { return is_function_; }
907+
bool is_function() const {
908+
return CodeKindIsOptimizedJSFunction(code_.kind());
909+
}
914910

915911
bool has_scope_info() const { return !shared_info_.is_null(); }
916912

@@ -919,11 +915,15 @@ class CodeDescription {
919915
return shared_info_.scope_info();
920916
}
921917

922-
uintptr_t CodeStart() const { return code_region_.begin(); }
918+
uintptr_t CodeStart() const {
919+
return static_cast<uintptr_t>(code_.InstructionStart());
920+
}
923921

924-
uintptr_t CodeEnd() const { return code_region_.end(); }
922+
uintptr_t CodeEnd() const {
923+
return static_cast<uintptr_t>(code_.InstructionEnd());
924+
}
925925

926-
uintptr_t CodeSize() const { return code_region_.size(); }
926+
uintptr_t CodeSize() const { return CodeEnd() - CodeStart(); }
927927

928928
bool has_script() {
929929
return !shared_info_.is_null() && shared_info_.script().IsScript();
@@ -933,8 +933,6 @@ class CodeDescription {
933933

934934
bool IsLineInfoAvailable() { return lineinfo_ != nullptr; }
935935

936-
base::AddressRegion region() { return code_region_; }
937-
938936
#if V8_TARGET_ARCH_X64
939937
uintptr_t GetStackStateStartAddress(StackState state) const {
940938
DCHECK(state < STACK_STATE_MAX);
@@ -967,10 +965,9 @@ class CodeDescription {
967965

968966
private:
969967
const char* name_;
968+
Code code_;
970969
SharedFunctionInfo shared_info_;
971970
LineInfo* lineinfo_;
972-
bool is_function_;
973-
base::AddressRegion code_region_;
974971
#if V8_TARGET_ARCH_X64
975972
uintptr_t stack_state_start_addresses_[STACK_STATE_MAX];
976973
#endif
@@ -1819,17 +1816,26 @@ static JITCodeEntry* CreateELFObject(CodeDescription* desc, Isolate* isolate) {
18191816
return CreateCodeEntry(reinterpret_cast<Address>(w.buffer()), w.position());
18201817
}
18211818

1822-
// Like base::AddressRegion::StartAddressLess but also compares |end| when
1823-
// |begin| is equal.
1824-
struct AddressRegionLess {
1825-
bool operator()(const base::AddressRegion& a,
1826-
const base::AddressRegion& b) const {
1827-
if (a.begin() == b.begin()) return a.end() < b.end();
1828-
return a.begin() < b.begin();
1819+
struct AddressRange {
1820+
Address start;
1821+
Address end;
1822+
};
1823+
1824+
struct AddressRangeLess {
1825+
bool operator()(const AddressRange& a, const AddressRange& b) const {
1826+
if (a.start == b.start) return a.end < b.end;
1827+
return a.start < b.start;
18291828
}
18301829
};
18311830

1832-
using CodeMap = std::map<base::AddressRegion, JITCodeEntry*, AddressRegionLess>;
1831+
struct CodeMapConfig {
1832+
using Key = AddressRange;
1833+
using Value = JITCodeEntry*;
1834+
using Less = AddressRangeLess;
1835+
};
1836+
1837+
using CodeMap =
1838+
std::map<CodeMapConfig::Key, CodeMapConfig::Value, CodeMapConfig::Less>;
18331839

18341840
static CodeMap* GetCodeMap() {
18351841
// TODO(jgruber): Don't leak.
@@ -1903,37 +1909,36 @@ static void AddUnwindInfo(CodeDescription* desc) {
19031909

19041910
static base::LazyMutex mutex = LAZY_MUTEX_INITIALIZER;
19051911

1906-
// Remove entries from the map that intersect the given address region,
1912+
// Remove entries from the map that intersect the given address range,
19071913
// and deregister them from GDB.
1908-
static void RemoveJITCodeEntries(CodeMap* map,
1909-
const base::AddressRegion region) {
1910-
DCHECK_LT(region.begin(), region.end());
1914+
static void RemoveJITCodeEntries(CodeMap* map, const AddressRange& range) {
1915+
DCHECK(range.start < range.end);
19111916

19121917
if (map->empty()) return;
19131918

19141919
// Find the first overlapping entry.
19151920

1916-
// If successful, points to the first element not less than `region`. The
1921+
// If successful, points to the first element not less than `range`. The
19171922
// returned iterator has the key in `first` and the value in `second`.
1918-
auto it = map->lower_bound(region);
1923+
auto it = map->lower_bound(range);
19191924
auto start_it = it;
19201925

19211926
if (it == map->end()) {
19221927
start_it = map->begin();
19231928
} else if (it != map->begin()) {
19241929
for (--it; it != map->begin(); --it) {
1925-
if ((*it).first.end() <= region.begin()) break;
1930+
if ((*it).first.end <= range.start) break;
19261931
start_it = it;
19271932
}
19281933
}
19291934

1930-
DCHECK_NE(start_it, map->end());
1935+
DCHECK(start_it != map->end());
19311936

1932-
// Find the first non-overlapping entry after `region`.
1937+
// Find the first non-overlapping entry after `range`.
19331938

1934-
const auto end_it = map->lower_bound({region.end(), 0});
1939+
const auto end_it = map->lower_bound({range.end, 0});
19351940

1936-
// Evict intersecting regions.
1941+
// Evict intersecting ranges.
19371942

19381943
if (std::distance(start_it, end_it) < 1) return; // No overlapping entries.
19391944

@@ -1947,7 +1952,7 @@ static void RemoveJITCodeEntries(CodeMap* map,
19471952
}
19481953

19491954
// Insert the entry into the map and register it with GDB.
1950-
static void AddJITCodeEntry(CodeMap* map, const base::AddressRegion region,
1955+
static void AddJITCodeEntry(CodeMap* map, const AddressRange& range,
19511956
JITCodeEntry* entry, bool dump_if_enabled,
19521957
const char* name_hint) {
19531958
#if defined(DEBUG) && !V8_OS_WIN
@@ -1964,28 +1969,32 @@ static void AddJITCodeEntry(CodeMap* map, const base::AddressRegion region,
19641969
}
19651970
#endif
19661971

1967-
auto result = map->emplace(region, entry);
1972+
auto result = map->emplace(range, entry);
19681973
DCHECK(result.second); // Insertion happened.
19691974
USE(result);
19701975

19711976
RegisterCodeEntry(entry);
19721977
}
19731978

1974-
static void AddCode(const char* name, base::AddressRegion region,
1975-
SharedFunctionInfo shared, LineInfo* lineinfo,
1976-
Isolate* isolate, bool is_function) {
1979+
static void AddCode(const char* name, Code code, SharedFunctionInfo shared,
1980+
LineInfo* lineinfo) {
19771981
DisallowGarbageCollection no_gc;
1978-
CodeDescription code_desc(name, region, shared, lineinfo, is_function);
19791982

19801983
CodeMap* code_map = GetCodeMap();
1981-
RemoveJITCodeEntries(code_map, region);
1984+
AddressRange range;
1985+
range.start = code.address();
1986+
range.end = code.address() + code.CodeSize();
1987+
RemoveJITCodeEntries(code_map, range);
1988+
1989+
CodeDescription code_desc(name, code, shared, lineinfo);
19821990

19831991
if (!FLAG_gdbjit_full && !code_desc.IsLineInfoAvailable()) {
19841992
delete lineinfo;
19851993
return;
19861994
}
19871995

19881996
AddUnwindInfo(&code_desc);
1997+
Isolate* isolate = code.GetIsolate();
19891998
JITCodeEntry* entry = CreateELFObject(&code_desc, isolate);
19901999

19912000
delete lineinfo;
@@ -2001,40 +2010,25 @@ static void AddCode(const char* name, base::AddressRegion region,
20012010
should_dump = (name_hint != nullptr);
20022011
}
20032012
}
2004-
AddJITCodeEntry(code_map, region, entry, should_dump, name_hint);
2013+
AddJITCodeEntry(code_map, range, entry, should_dump, name_hint);
20052014
}
20062015

20072016
void EventHandler(const v8::JitCodeEvent* event) {
20082017
if (!FLAG_gdbjit) return;
2009-
if ((event->code_type != v8::JitCodeEvent::JIT_CODE) &&
2010-
(event->code_type != v8::JitCodeEvent::WASM_CODE)) {
2011-
return;
2012-
}
2018+
if (event->code_type != v8::JitCodeEvent::JIT_CODE) return;
20132019
base::MutexGuard lock_guard(mutex.Pointer());
20142020
switch (event->type) {
20152021
case v8::JitCodeEvent::CODE_ADDED: {
20162022
Address addr = reinterpret_cast<Address>(event->code_start);
2023+
Isolate* isolate = reinterpret_cast<Isolate*>(event->isolate);
2024+
Code code = isolate->heap()->GcSafeFindCodeForInnerPointer(addr);
20172025
LineInfo* lineinfo = GetLineInfo(addr);
20182026
std::string event_name(event->name.str, event->name.len);
20192027
// It's called UnboundScript in the API but it's a SharedFunctionInfo.
20202028
SharedFunctionInfo shared = event->script.IsEmpty()
20212029
? SharedFunctionInfo()
20222030
: *Utils::OpenHandle(*event->script);
2023-
Isolate* isolate = reinterpret_cast<Isolate*>(event->isolate);
2024-
bool is_function = false;
2025-
// TODO(zhin): See if we can use event->code_type to determine
2026-
// is_function, the difference currently is that JIT_CODE is SparkPlug,
2027-
// TurboProp, TurboFan, whereas CodeKindIsOptimizedJSFunction is only
2028-
// TurboProp and TurboFan. is_function is used for AddUnwindInfo, and the
2029-
// prologue that SP generates probably matches that of TP/TF, so we can
2030-
// use event->code_type here instead of finding the Code.
2031-
// TODO(zhin): Rename is_function to be more accurate.
2032-
if (event->code_type == v8::JitCodeEvent::JIT_CODE) {
2033-
Code code = isolate->heap()->GcSafeFindCodeForInnerPointer(addr);
2034-
is_function = CodeKindIsOptimizedJSFunction(code.kind());
2035-
}
2036-
AddCode(event_name.c_str(), {addr, event->code_len}, shared, lineinfo,
2037-
isolate, is_function);
2031+
AddCode(event_name.c_str(), code, shared, lineinfo);
20382032
break;
20392033
}
20402034
case v8::JitCodeEvent::CODE_MOVED:

src/logging/log.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ void JitLogger::LogRecordedBuffer(const wasm::WasmCode* code, const char* name,
730730
int length) {
731731
JitCodeEvent event = {};
732732
event.type = JitCodeEvent::CODE_ADDED;
733-
event.code_type = JitCodeEvent::WASM_CODE;
733+
event.code_type = JitCodeEvent::JIT_CODE;
734734
event.code_start = code->instructions().begin();
735735
event.code_len = code->instructions().length();
736736
event.name.str = name;
@@ -1558,14 +1558,12 @@ void Logger::CodeLinePosInfoRecordEvent(Address code_start,
15581558
CodeLinePosEvent(*jit_logger_, code_start, iter, code_type);
15591559
}
15601560

1561-
#if V8_ENABLE_WEBASSEMBLY
1562-
void Logger::WasmCodeLinePosInfoRecordEvent(
1561+
void Logger::CodeLinePosInfoRecordEvent(
15631562
Address code_start, base::Vector<const byte> source_position_table) {
15641563
if (!jit_logger_) return;
15651564
SourcePositionTableIterator iter(source_position_table);
1566-
CodeLinePosEvent(*jit_logger_, code_start, iter, JitCodeEvent::WASM_CODE);
1565+
CodeLinePosEvent(*jit_logger_, code_start, iter, JitCodeEvent::JIT_CODE);
15671566
}
1568-
#endif // V8_ENABLE_WEBASSEMBLY
15691567

15701568
void Logger::CodeNameEvent(Address addr, int pos, const char* code_name) {
15711569
if (code_name == nullptr) return; // Not a code object.

src/logging/log.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,8 @@ class Logger : public CodeEventListener {
241241
void CodeLinePosInfoRecordEvent(Address code_start,
242242
ByteArray source_position_table,
243243
JitCodeEvent::CodeType code_type);
244-
#if V8_ENABLE_WEBASSEMBLY
245-
void WasmCodeLinePosInfoRecordEvent(
244+
void CodeLinePosInfoRecordEvent(
246245
Address code_start, base::Vector<const byte> source_position_table);
247-
#endif // V8_ENABLE_WEBASSEMBLY
248246

249247
void CodeNameEvent(Address addr, int pos, const char* code_name);
250248

src/wasm/wasm-code-manager.cc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,17 +267,14 @@ void WasmCode::LogCode(Isolate* isolate, const char* source_url,
267267
"wasm-function[%d]", index()));
268268
name = base::VectorOf(name_buffer);
269269
}
270-
271-
// Record source positions before adding code, otherwise when code is added,
272-
// there are no source positions to associate with the added code.
273-
if (!source_positions().empty()) {
274-
LOG_CODE_EVENT(isolate, WasmCodeLinePosInfoRecordEvent(instruction_start(),
275-
source_positions()));
276-
}
277-
278270
int code_offset = module->functions[index_].code.offset();
279271
PROFILE(isolate, CodeCreateEvent(CodeEventListener::FUNCTION_TAG, this, name,
280272
source_url, code_offset, script_id));
273+
274+
if (!source_positions().empty()) {
275+
LOG_CODE_EVENT(isolate, CodeLinePosInfoRecordEvent(instruction_start(),
276+
source_positions()));
277+
}
281278
}
282279

283280
void WasmCode::Validate() const {

test/cctest/cctest.status

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,6 @@
580580
'test-api/TurboAsmDisablesDetach': [SKIP],
581581
'test-api/WasmI32AtomicWaitCallback': [SKIP],
582582
'test-api/WasmI64AtomicWaitCallback': [SKIP],
583-
'test-api/WasmSetJitCodeEventHandler': [SKIP],
584583
'test-api-wasm/WasmStreaming*': [SKIP],
585584
'test-backing-store/Run_WasmModule_Buffer_Externalized_Regression_UseAfterFree': [SKIP],
586585
'test-c-wasm-entry/*': [SKIP],

0 commit comments

Comments
 (0)