PPC/s390: Reland: [builtins] Patch self-references in constants table

Port ab9e012426

Original Commit Message:

    Original CL: https://crrev.com/c/1018468

    During code generation, we generate self-references (i.e. references to
    the Code object currently being generated) as references to a temporary
    handle. When the final Code object has been allocated, the handle's
    location is fixed up and RelocInfo iteration fixes up all references
    embedded in the generated code.

    This adds support for this mechanism to the builtins constants table
    builder. CodeObject() is now a new handle pointing to a dedicated
    self-reference marker in order to distinguish between self-references
    and references to undefined. In Factory::NewCode, we patch up
    the constants table.

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

Change-Id: Iba0f4435125b9d6c3fda7fc3e9836494b6eb6f45
Reviewed-on: https://chromium-review.googlesource.com/1042216
Reviewed-by: Joran Siu <joransiu@ca.ibm.com>
Commit-Queue: Junliang Yan <jyan@ca.ibm.com>
Cr-Commit-Position: refs/heads/master@{#52969}
This commit is contained in:
Junliang Yan 2018-05-03 12:52:02 -04:00 committed by Commit Bot
parent efc92f0d4a
commit e0d2c6c2b3
4 changed files with 34 additions and 22 deletions

View File

@ -28,7 +28,17 @@ namespace internal {
MacroAssembler::MacroAssembler(Isolate* isolate, void* buffer, int size,
CodeObjectRequired create_code_object)
: TurboAssembler(isolate, buffer, size, create_code_object) {}
: TurboAssembler(isolate, buffer, size, create_code_object) {
if (create_code_object == CodeObjectRequired::kYes) {
// Unlike TurboAssembler, which can be used off the main thread and may not
// allocate, macro assembler creates its own copy of the self-reference
// marker in order to disambiguate between self-references during nested
// code generation (e.g.: codegen of the current object triggers stub
// compilation through CodeStub::GetCode()).
code_object_ = Handle<HeapObject>::New(
*isolate->factory()->NewSelfReferenceMarker(), isolate);
}
}
TurboAssembler::TurboAssembler(Isolate* isolate, void* buffer, int buffer_size,
CodeObjectRequired create_code_object)
@ -128,11 +138,6 @@ void TurboAssembler::LookupConstant(Register destination,
CHECK(isolate()->ShouldLoadConstantsFromRootList());
CHECK(root_array_available_);
// TODO(jgruber, v8:6666): Support self-references. Currently, we'd end up
// adding the temporary code object to the constants list, before creating the
// final object in Factory::CopyCode.
CHECK(code_object_.is_null() || !object.equals(code_object_));
// Ensure the given object is in the builtins constants table and fetch its
// index.
BuiltinsConstantsTableBuilder* builder =
@ -331,8 +336,7 @@ void TurboAssembler::Push(Smi* smi) {
void TurboAssembler::Move(Register dst, Handle<HeapObject> value) {
#ifdef V8_EMBEDDED_BUILTINS
if (root_array_available_ && isolate()->ShouldLoadConstantsFromRootList() &&
!value.equals(CodeObject())) {
if (root_array_available_ && isolate()->ShouldLoadConstantsFromRootList()) {
Heap::RootListIndex root_index;
if (!isolate()->heap()->IsRootHandle(value, &root_index)) {
LookupConstant(dst, value);

View File

@ -676,14 +676,16 @@ class TurboAssembler : public Assembler {
void ResetSpeculationPoisonRegister();
protected:
// This handle will be patched with the code object on installation.
Handle<HeapObject> code_object_;
private:
static const int kSmiShift = kSmiTagSize + kSmiShiftSize;
bool has_frame_ = false;
bool root_array_available_ = true;
Isolate* const isolate_;
// This handle will be patched with the code object on installation.
Handle<HeapObject> code_object_;
void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al,
CRegister cr = cr7);

View File

@ -28,14 +28,24 @@ namespace internal {
MacroAssembler::MacroAssembler(Isolate* isolate, void* buffer, int size,
CodeObjectRequired create_code_object)
: TurboAssembler(isolate, buffer, size, create_code_object) {}
: TurboAssembler(isolate, buffer, size, create_code_object) {
if (create_code_object == CodeObjectRequired::kYes) {
// Unlike TurboAssembler, which can be used off the main thread and may not
// allocate, macro assembler creates its own copy of the self-reference
// marker in order to disambiguate between self-references during nested
// code generation (e.g.: codegen of the current object triggers stub
// compilation through CodeStub::GetCode()).
code_object_ = Handle<HeapObject>::New(
*isolate->factory()->NewSelfReferenceMarker(), isolate);
}
}
TurboAssembler::TurboAssembler(Isolate* isolate, void* buffer, int buffer_size,
CodeObjectRequired create_code_object)
: Assembler(isolate, buffer, buffer_size), isolate_(isolate) {
if (create_code_object == CodeObjectRequired::kYes) {
code_object_ =
Handle<HeapObject>::New(isolate->heap()->undefined_value(), isolate);
code_object_ = Handle<HeapObject>::New(
isolate->heap()->self_reference_marker(), isolate);
}
}
@ -123,11 +133,6 @@ void TurboAssembler::LookupConstant(Register destination,
CHECK(isolate()->ShouldLoadConstantsFromRootList());
CHECK(root_array_available_);
// TODO(jgruber, v8:6666): Support self-references. Currently, we'd end up
// adding the temporary code object to the constants list, before creating the
// final object in Factory::CopyCode.
CHECK(code_object_.is_null() || !object.equals(code_object_));
// Ensure the given object is in the builtins constants table and fetch its
// index.
BuiltinsConstantsTableBuilder* builder =
@ -330,8 +335,7 @@ void TurboAssembler::Push(Smi* smi) {
void TurboAssembler::Move(Register dst, Handle<HeapObject> value) {
#ifdef V8_EMBEDDED_BUILTINS
if (root_array_available_ && isolate()->ShouldLoadConstantsFromRootList() &&
!value.equals(CodeObject())) {
if (root_array_available_ && isolate()->ShouldLoadConstantsFromRootList()) {
Heap::RootListIndex root_index;
if (!isolate()->heap()->IsRootHandle(value, &root_index)) {
LookupConstant(dst, value);

View File

@ -1024,6 +1024,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; }
protected:
// This handle will be patched with the code object on installation.
Handle<HeapObject> code_object_;
private:
static const int kSmiShift = kSmiTagSize + kSmiShiftSize;
@ -1038,8 +1042,6 @@ class TurboAssembler : public Assembler {
bool has_frame_ = false;
bool root_array_available_ = true;
Isolate* isolate_;
// This handle will be patched with the code object on installation.
Handle<HeapObject> code_object_;
};
// MacroAssembler implements a collection of frequently used macros.