Commit 1691b1f6 authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[cleanup] Make InstructionStream::TryLookupCode() return builtin ID

... instead of Code. This is useful because usually the callers are
interested in having just a builtin ID but not the Code object.

This CL also makes Builtins::kNoBuiltinId a part of the Builtins::Name
enum.

Bug: v8:11527
Change-Id: I501e3e52dccc73cc7800f271939e0bf9fd00a975
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2749635Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73331}
parent 3353a7d0
......@@ -106,8 +106,8 @@ void Builtins::TearDown() { initialized_ = false; }
const char* Builtins::Lookup(Address pc) {
// Off-heap pc's can be looked up through binary search.
Code maybe_builtin = InstructionStream::TryLookupCode(isolate_, pc);
if (!maybe_builtin.is_null()) return name(maybe_builtin.builtin_index());
Builtins::Name builtin = InstructionStream::TryLookupCode(isolate_, pc);
if (Builtins::IsBuiltinId(builtin)) return name(builtin);
// May be called during initialization (disassembler).
if (initialized_) {
......
......@@ -49,6 +49,7 @@ class Builtins {
const char* Lookup(Address pc);
enum Name : int32_t {
kNoBuiltinId = -1,
#define DEF_ENUM(Name, ...) k##Name,
BUILTIN_LIST(DEF_ENUM, DEF_ENUM, DEF_ENUM, DEF_ENUM, DEF_ENUM, DEF_ENUM,
DEF_ENUM)
......@@ -62,8 +63,6 @@ class Builtins {
#undef EXTRACT_NAME
};
static const int32_t kNoBuiltinId = -1;
static constexpr int kFirstWideBytecodeHandler =
kFirstBytecodeHandler + kNumberOfBytecodeHandlers;
static constexpr int kFirstExtraWideBytecodeHandler =
......@@ -73,7 +72,9 @@ class Builtins {
STATIC_ASSERT(kLastBytecodeHandlerPlusOne == builtin_count);
static constexpr bool IsBuiltinId(int maybe_id) {
return 0 <= maybe_id && maybe_id < builtin_count;
STATIC_ASSERT(kNoBuiltinId == -1);
return static_cast<uint32_t>(maybe_id) <
static_cast<uint32_t>(builtin_count);
}
// The different builtin kinds are documented in builtins-definitions.h.
......
......@@ -526,7 +526,8 @@ void RelocInfo::Verify(Isolate* isolate) {
case OFF_HEAP_TARGET: {
Address addr = target_off_heap_target();
CHECK_NE(addr, kNullAddress);
CHECK(!InstructionStream::TryLookupCode(isolate, addr).is_null());
CHECK(Builtins::IsBuiltinId(
InstructionStream::TryLookupCode(isolate, addr)));
break;
}
case RUNTIME_ENTRY:
......
......@@ -662,11 +662,10 @@ Builtins::Name Deoptimizer::GetDeoptimizationEntry(DeoptimizeKind kind) {
bool Deoptimizer::IsDeoptimizationEntry(Isolate* isolate, Address addr,
DeoptimizeKind* type_out) {
Code maybe_code = InstructionStream::TryLookupCode(isolate, addr);
if (maybe_code.is_null()) return false;
Builtins::Name builtin = InstructionStream::TryLookupCode(isolate, addr);
if (!Builtins::IsBuiltinId(builtin)) return false;
Code code = maybe_code;
switch (code.builtin_index()) {
switch (builtin) {
case Builtins::kDeoptimizationEntry_Eager:
*type_out = DeoptimizeKind::kEager;
return true;
......
......@@ -6495,15 +6495,23 @@ Code Heap::GcSafeCastToCode(HeapObject object, Address inner_pointer) {
bool Heap::GcSafeCodeContains(Code code, Address addr) {
Map map = GcSafeMapOfCodeSpaceObject(code);
DCHECK(map == ReadOnlyRoots(this).code_map());
if (InstructionStream::TryLookupCode(isolate(), addr) == code) return true;
Builtins::Name maybe_builtin =
InstructionStream::TryLookupCode(isolate(), addr);
if (Builtins::IsBuiltinId(maybe_builtin) &&
code.builtin_index() == maybe_builtin) {
return true;
}
Address start = code.address();
Address end = code.address() + code.SizeFromMap(map);
return start <= addr && addr < end;
}
Code Heap::GcSafeFindCodeForInnerPointer(Address inner_pointer) {
Code code = InstructionStream::TryLookupCode(isolate(), inner_pointer);
if (!code.is_null()) return code;
Builtins::Name maybe_builtin =
InstructionStream::TryLookupCode(isolate(), inner_pointer);
if (Builtins::IsBuiltinId(maybe_builtin)) {
return builtin(maybe_builtin);
}
if (V8_ENABLE_THIRD_PARTY_HEAP_BOOL) {
Address start = tp_heap_->GetObjectFromInnerPointer(inner_pointer);
......
......@@ -21,11 +21,12 @@ bool InstructionStream::PcIsOffHeap(Isolate* isolate, Address pc) {
}
// static
Code InstructionStream::TryLookupCode(Isolate* isolate, Address address) {
if (!PcIsOffHeap(isolate, address)) return Code();
Builtins::Name InstructionStream::TryLookupCode(Isolate* isolate,
Address address) {
if (!PcIsOffHeap(isolate, address)) return Builtins::kNoBuiltinId;
EmbeddedData d = EmbeddedData::FromBlob();
if (address < d.InstructionStartOfBuiltin(0)) return Code();
if (address < d.InstructionStartOfBuiltin(0)) return Builtins::kNoBuiltinId;
// Note: Addresses within the padding section between builtins (i.e. within
// start + size <= address < start + padded_size) are interpreted as belonging
......@@ -42,7 +43,7 @@ Code InstructionStream::TryLookupCode(Isolate* isolate, Address address) {
} else if (address >= end) {
l = mid + 1;
} else {
return isolate->builtins()->builtin(mid);
return static_cast<Builtins::Name>(mid);
}
}
......
......@@ -23,8 +23,9 @@ class InstructionStream final : public AllStatic {
// Returns true, iff the given pc points into an off-heap instruction stream.
static bool PcIsOffHeap(Isolate* isolate, Address pc);
// Returns the corresponding Code object if it exists, and nullptr otherwise.
static Code TryLookupCode(Isolate* isolate, Address address);
// Returns the corresponding builtin ID if lookup succeeds, and kNoBuiltinId
// otherwise.
static Builtins::Name TryLookupCode(Isolate* isolate, Address address);
// During snapshot creation, we first create an executable off-heap area
// containing all off-heap code. The area is guaranteed to be contiguous.
......
......@@ -1003,11 +1003,12 @@ void Serializer::ObjectSerializer::VisitOffHeapTarget(Code host,
Address addr = rinfo->target_off_heap_target();
CHECK_NE(kNullAddress, addr);
Code target = InstructionStream::TryLookupCode(isolate(), addr);
CHECK(Builtins::IsIsolateIndependentBuiltin(target));
Builtins::Name builtin = InstructionStream::TryLookupCode(isolate(), addr);
CHECK(Builtins::IsBuiltinId(builtin));
CHECK(Builtins::IsIsolateIndependent(builtin));
sink_->Put(kOffHeapTarget, "OffHeapTarget");
sink_->PutInt(target.builtin_index(), "builtin index");
sink_->PutInt(builtin, "builtin index");
}
void Serializer::ObjectSerializer::VisitCodeTarget(Code host,
......
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