Commit 5e45a19d authored by Junliang Yan's avatar Junliang Yan Committed by Commit Bot

PPC/s390: [builtins] Move builtins table to the Heap class

Port e3e3480b

Original Commit Message:

    The builtins table is an array of pointers to builtin code objects. It
    used to be located within the Builtins class, which itself was part of
    the Isolate.

    To enable faster isolate-independent access to builtin code objects,
    this CL moves the builtins table into the heap, at a constant known
    offset from the roots table. With this change, builtins can be accessed
    through the root pointer with a single instruction:

     mov reg, [kRootPointer, <offset to builtin>]

    TurboAssembler::LookupConstant is also extended in this CL to
    potentially shortcut the slow-ish constants table lookup: root
    constants are loaded through the root list, and builtin constants
    through the builtins table.

R=jgruber@chromium.org, joransiu@ca.ibm.com, michael_dawson@ca.ibm.com
BUG=
LOG=N

Change-Id: I1dac4ad30960d50f77aba7ec7da63b1f1259613d
Reviewed-on: https://chromium-review.googlesource.com/1087410Reviewed-by: 's avatarJoran Siu <joransiu@ca.ibm.com>
Commit-Queue: Junliang Yan <jyan@ca.ibm.com>
Cr-Commit-Position: refs/heads/master@{#53532}
parent 0b3e8e18
......@@ -136,20 +136,38 @@ void TurboAssembler::Jump(Register target) {
#ifdef V8_EMBEDDED_BUILTINS
void TurboAssembler::LookupConstant(Register destination,
Handle<Object> object) {
Handle<HeapObject> object) {
CHECK(isolate()->ShouldLoadConstantsFromRootList());
CHECK(root_array_available_);
// Before falling back to the (fairly slow) lookup from the constants table,
// check if any of the fast paths can be applied.
{
int builtin_index;
Heap::RootListIndex root_index;
if (isolate()->heap()->IsRootHandle(object, &root_index)) {
// Roots are loaded relative to the root register.
LoadRoot(destination, root_index);
return;
} else if (isolate()->builtins()->IsBuiltinHandle(object, &builtin_index)) {
// Similar to roots, builtins may be loaded from the builtins table.
LoadBuiltin(destination, builtin_index);
return;
} else if (object.is_identical_to(code_object_) &&
Builtins::IsBuiltinId(maybe_builtin_index_)) {
// The self-reference loaded through Codevalue() may also be a builtin
// and thus viable for a fast load.
LoadBuiltin(destination, maybe_builtin_index_);
return;
}
}
// Ensure the given object is in the builtins constants table and fetch its
// index.
BuiltinsConstantsTableBuilder* builder =
isolate()->builtins_constants_table_builder();
uint32_t index = builder->AddObject(object);
// TODO(jgruber): Load builtins from the builtins table.
// TODO(jgruber): Ensure that code generation can recognize constant targets
// in kArchCallCodeObject.
DCHECK(isolate()->heap()->RootCanBeTreatedAsConstant(
Heap::kBuiltinsConstantsTableRootIndex));
......@@ -185,6 +203,15 @@ void TurboAssembler::LookupExternalReference(Register destination,
LoadP(destination,
MemOperand(kRootRegister, roots_to_external_reference_offset), r0);
}
void TurboAssembler::LoadBuiltin(Register destination, int builtin_index) {
DCHECK(Builtins::IsBuiltinId(builtin_index));
int32_t roots_to_builtins_offset =
Heap::roots_to_builtins_offset() + builtin_index * kPointerSize;
LoadP(destination, MemOperand(kRootRegister, roots_to_builtins_offset), r0);
}
#endif // V8_EMBEDDED_BUILTINS
void MacroAssembler::JumpToJSEntry(Register target) {
......@@ -373,12 +400,7 @@ void TurboAssembler::Push(Smi* smi) {
void TurboAssembler::Move(Register dst, Handle<HeapObject> value) {
#ifdef V8_EMBEDDED_BUILTINS
if (root_array_available_ && isolate()->ShouldLoadConstantsFromRootList()) {
Heap::RootListIndex root_index;
if (!isolate()->heap()->IsRootHandle(value, &root_index)) {
LookupConstant(dst, value);
} else {
LoadRoot(dst, root_index);
}
LookupConstant(dst, value);
return;
}
#endif // V8_EMBEDDED_BUILTINS
......
......@@ -223,6 +223,10 @@ class TurboAssembler : public Assembler {
bool root_array_available() const { return root_array_available_; }
void set_root_array_available(bool v) { root_array_available_ = v; }
void set_builtin_index(int builtin_index) {
maybe_builtin_index_ = builtin_index;
}
void StoreDouble(DoubleRegister src, const MemOperand& mem,
Register scratch = no_reg);
void StoreDoubleU(DoubleRegister src, const MemOperand& mem,
......@@ -438,9 +442,10 @@ class TurboAssembler : public Assembler {
#endif
#ifdef V8_EMBEDDED_BUILTINS
void LookupConstant(Register destination, Handle<Object> object);
void LookupConstant(Register destination, Handle<HeapObject> object);
void LookupExternalReference(Register destination,
ExternalReference reference);
void LoadBuiltin(Register destination, int builtin_index);
#endif // V8_EMBEDDED_BUILTINS
// Returns the size of a call in instructions. Note, the value returned is
......@@ -682,6 +687,7 @@ class TurboAssembler : public Assembler {
Handle<HeapObject> code_object_;
private:
int maybe_builtin_index_ = -1; // May be set while generating builtins.
static const int kSmiShift = kSmiTagSize + kSmiShiftSize;
bool has_frame_ = false;
......
......@@ -131,20 +131,38 @@ int TurboAssembler::PopCallerSaved(SaveFPRegsMode fp_mode, Register exclusion1,
#ifdef V8_EMBEDDED_BUILTINS
void TurboAssembler::LookupConstant(Register destination,
Handle<Object> object) {
Handle<HeapObject> object) {
CHECK(isolate()->ShouldLoadConstantsFromRootList());
CHECK(root_array_available_);
// Before falling back to the (fairly slow) lookup from the constants table,
// check if any of the fast paths can be applied.
{
int builtin_index;
Heap::RootListIndex root_index;
if (isolate()->heap()->IsRootHandle(object, &root_index)) {
// Roots are loaded relative to the root register.
LoadRoot(destination, root_index);
return;
} else if (isolate()->builtins()->IsBuiltinHandle(object, &builtin_index)) {
// Similar to roots, builtins may be loaded from the builtins table.
LoadBuiltin(destination, builtin_index);
return;
} else if (object.is_identical_to(code_object_) &&
Builtins::IsBuiltinId(maybe_builtin_index_)) {
// The self-reference loaded through Codevalue() may also be a builtin
// and thus viable for a fast load.
LoadBuiltin(destination, maybe_builtin_index_);
return;
}
}
// Ensure the given object is in the builtins constants table and fetch its
// index.
BuiltinsConstantsTableBuilder* builder =
isolate()->builtins_constants_table_builder();
uint32_t index = builder->AddObject(object);
// TODO(jgruber): Load builtins from the builtins table.
// TODO(jgruber): Ensure that code generation can recognize constant targets
// in kArchCallCodeObject.
DCHECK(isolate()->heap()->RootCanBeTreatedAsConstant(
Heap::kBuiltinsConstantsTableRootIndex));
......@@ -180,6 +198,15 @@ void TurboAssembler::LookupExternalReference(Register destination,
LoadP(destination,
MemOperand(kRootRegister, roots_to_external_reference_offset));
}
void TurboAssembler::LoadBuiltin(Register destination, int builtin_index) {
DCHECK(Builtins::IsBuiltinId(builtin_index));
int32_t roots_to_builtins_offset =
Heap::roots_to_builtins_offset() + builtin_index * kPointerSize;
LoadP(destination, MemOperand(kRootRegister, roots_to_builtins_offset));
}
#endif // V8_EMBEDDED_BUILTINS
void TurboAssembler::Jump(Register target, Condition cond) { b(cond, target); }
......@@ -366,12 +393,7 @@ void TurboAssembler::Push(Smi* smi) {
void TurboAssembler::Move(Register dst, Handle<HeapObject> value) {
#ifdef V8_EMBEDDED_BUILTINS
if (root_array_available_ && isolate()->ShouldLoadConstantsFromRootList()) {
Heap::RootListIndex root_index;
if (!isolate()->heap()->IsRootHandle(value, &root_index)) {
LookupConstant(dst, value);
} else {
LoadRoot(dst, root_index);
}
LookupConstant(dst, value);
return;
}
#endif // V8_EMBEDDED_BUILTINS
......
......@@ -180,9 +180,10 @@ class TurboAssembler : public Assembler {
}
#ifdef V8_EMBEDDED_BUILTINS
void LookupConstant(Register destination, Handle<Object> object);
void LookupConstant(Register destination, Handle<HeapObject> object);
void LookupExternalReference(Register destination,
ExternalReference reference);
void LoadBuiltin(Register destination, int builtin_index);
#endif // V8_EMBEDDED_BUILTINS
// Returns the size of a call in instructions.
......@@ -1028,11 +1029,16 @@ class TurboAssembler : public Assembler {
bool root_array_available() const { return root_array_available_; }
void set_root_array_available(bool v) { root_array_available_ = v; }
void set_builtin_index(int builtin_index) {
maybe_builtin_index_ = builtin_index;
}
protected:
// This handle will be patched with the code object on installation.
Handle<HeapObject> code_object_;
private:
int maybe_builtin_index_ = -1; // May be set while generating builtins.
static const int kSmiShift = kSmiTagSize + kSmiShiftSize;
void CallCFunctionHelper(Register function, int num_reg_arguments,
......
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