Commit d83e4999 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[interpreter] Fix LookupNameOfBytecodeHandler

Fixes LookupNameOfBytecodeHandler so it actually returns non-nullptr
values with embedded builtins enabled. Also now correctly handles wide
and extra-wide bytecodes and always works regardless of whether
ENABLE_DISASSEMBLER is set.

Bug: v8:9215
Change-Id: I787134f2145d02daaf5b50ecb6c174dfc129a4fe
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1635890Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61929}
parent d64f582a
...@@ -290,14 +290,9 @@ bool Interpreter::IsDispatchTableInitialized() const { ...@@ -290,14 +290,9 @@ bool Interpreter::IsDispatchTableInitialized() const {
} }
const char* Interpreter::LookupNameOfBytecodeHandler(const Code code) { const char* Interpreter::LookupNameOfBytecodeHandler(const Code code) {
#ifdef ENABLE_DISASSEMBLER if (code.kind() == Code::BYTECODE_HANDLER) {
#define RETURN_NAME(Name, ...) \ return Builtins::name(code.builtin_index());
if (dispatch_table_[Bytecodes::ToByte(Bytecode::k##Name)] == code.entry()) { \
return #Name; \
} }
BYTECODE_LIST(RETURN_NAME)
#undef RETURN_NAME
#endif // ENABLE_DISASSEMBLER
return nullptr; return nullptr;
} }
......
...@@ -60,8 +60,8 @@ class Interpreter { ...@@ -60,8 +60,8 @@ class Interpreter {
// GC support. // GC support.
void IterateDispatchTable(RootVisitor* v); void IterateDispatchTable(RootVisitor* v);
// Disassembler support (only useful with ENABLE_DISASSEMBLER defined). // Disassembler support.
const char* LookupNameOfBytecodeHandler(const Code code); V8_EXPORT_PRIVATE const char* LookupNameOfBytecodeHandler(const Code code);
V8_EXPORT_PRIVATE Local<v8::Object> GetDispatchCountersObject(); V8_EXPORT_PRIVATE Local<v8::Object> GetDispatchCountersObject();
......
...@@ -5197,13 +5197,19 @@ TEST(InterpreterCollectSourcePositions_ThrowFrom2ndFrame) { ...@@ -5197,13 +5197,19 @@ TEST(InterpreterCollectSourcePositions_ThrowFrom2ndFrame) {
namespace { namespace {
void CheckStringEqual(const char* expected_ptr, const char* actual_ptr) {
CHECK_NOT_NULL(expected_ptr);
CHECK_NOT_NULL(actual_ptr);
std::string expected(expected_ptr);
std::string actual(actual_ptr);
CHECK_EQ(expected, actual);
}
void CheckStringEqual(const char* expected_ptr, Handle<Object> actual_handle) { void CheckStringEqual(const char* expected_ptr, Handle<Object> actual_handle) {
v8::String::Utf8Value utf8( v8::String::Utf8Value utf8(
v8::Isolate::GetCurrent(), v8::Isolate::GetCurrent(),
v8::Utils::ToLocal(Handle<String>::cast(actual_handle))); v8::Utils::ToLocal(Handle<String>::cast(actual_handle)));
std::string expected(expected_ptr); CheckStringEqual(expected_ptr, *utf8);
std::string actual(*utf8);
CHECK_EQ(expected, actual);
} }
} // namespace } // namespace
...@@ -5246,6 +5252,23 @@ TEST(InterpreterCollectSourcePositions_GenerateStackTrace) { ...@@ -5246,6 +5252,23 @@ TEST(InterpreterCollectSourcePositions_GenerateStackTrace) {
CHECK_GT(source_position_table.length(), 0); CHECK_GT(source_position_table.length(), 0);
} }
TEST(InterpreterLookupNameOfBytecodeHandler) {
Interpreter* interpreter = CcTest::i_isolate()->interpreter();
Code ldaLookupSlot = interpreter->GetBytecodeHandler(Bytecode::kLdaLookupSlot,
OperandScale::kSingle);
CheckStringEqual("LdaLookupSlotHandler",
interpreter->LookupNameOfBytecodeHandler(ldaLookupSlot));
Code wideLdaLookupSlot = interpreter->GetBytecodeHandler(
Bytecode::kLdaLookupSlot, OperandScale::kDouble);
CheckStringEqual("LdaLookupSlotWideHandler",
interpreter->LookupNameOfBytecodeHandler(wideLdaLookupSlot));
Code extraWideLdaLookupSlot = interpreter->GetBytecodeHandler(
Bytecode::kLdaLookupSlot, OperandScale::kQuadruple);
CheckStringEqual(
"LdaLookupSlotExtraWideHandler",
interpreter->LookupNameOfBytecodeHandler(extraWideLdaLookupSlot));
}
} // namespace interpreter } // namespace interpreter
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment