Commit 148bfc81 authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[torque] generate Factory functions in FactoryBase

Bug: v8:7793
Change-Id: I7a34efcd4841a67d1e663f9e9b5f0c8fda09a8e3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2532307Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71179}
parent ea9ee866
......@@ -10,6 +10,7 @@
#include "src/objects/function-kind.h"
#include "src/objects/instance-type.h"
#include "src/roots/roots.h"
#include "torque-generated/class-forward-declarations.h"
namespace v8 {
namespace internal {
......@@ -25,6 +26,8 @@ class ArrayBoilerplateDescription;
class TemplateObjectDescription;
class SourceTextModuleInfo;
class PreparseData;
template <class T>
class PodArray;
class UncompiledDataWithoutPreparseData;
class UncompiledDataWithPreparseData;
class BytecodeArray;
......@@ -34,8 +37,28 @@ struct SourceRange;
template <typename T>
class ZoneVector;
namespace wasm {
class ValueType;
} // namespace wasm
template <typename Impl>
class FactoryBase;
// Putting Torque-generated definitions in a superclass allows to shadow them
// easily when they shouldn't be used and to reference them when they happen to
// have the same signature.
template <typename Impl>
class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) TorqueGeneratedFactory {
private:
FactoryBase<Impl>* factory() { return static_cast<FactoryBase<Impl>*>(this); }
public:
#include "torque-generated/factory.inc"
};
template <typename Impl>
class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) FactoryBase {
class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) FactoryBase
: public TorqueGeneratedFactory<Impl> {
public:
// Converts the given boolean condition to JavaScript boolean value.
inline Handle<Oddball> ToBoolean(bool value);
......@@ -223,6 +246,8 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) FactoryBase {
HeapObject AllocateRaw(int size, AllocationType allocation,
AllocationAlignment alignment = kWordAligned);
friend TorqueGeneratedFactory<Impl>;
};
} // namespace internal
......
......@@ -20,7 +20,6 @@
#include "src/objects/js-regexp.h"
#include "src/objects/shared-function-info.h"
#include "src/objects/string.h"
#include "torque-generated/class-forward-declarations.h"
namespace v8 {
namespace internal {
......@@ -71,10 +70,6 @@ class WasmExportedFunctionData;
class WasmJSFunctionData;
class WeakCell;
namespace wasm {
class ValueType;
} // namespace wasm
enum class SharedFlag : uint8_t;
enum class InitializedFlag : uint8_t;
......@@ -118,12 +113,6 @@ class V8_EXPORT_PRIVATE Factory : public FactoryBase<Factory> {
return handle(obj, isolate());
}
#include "torque-generated/factory.inc"
// Avoid the Torque-generated factory function to shadow the one from
// FactoryBase.
using FactoryBase::NewDescriptorArray;
Handle<Oddball> NewOddball(Handle<Map> map, const char* to_string,
Handle<Object> to_number, const char* type_of,
byte kind);
......
......@@ -4175,8 +4175,8 @@ void ImplementationVisitor::GenerateClassDefinitions(
std::string forward_declarations_filename = "class-forward-declarations.h";
{
factory_impl << "#include \"src/heap/factory.h\"\n";
factory_impl << "#include \"src/heap/factory-inl.h\"\n";
factory_impl << "#include \"src/heap/factory-base.h\"\n";
factory_impl << "#include \"src/heap/factory-base-inl.h\"\n";
factory_impl << "#include \"src/heap/heap.h\"\n";
factory_impl << "#include \"src/heap/heap-inl.h\"\n";
factory_impl << "#include \"src/execution/isolate.h\"\n";
......@@ -4219,24 +4219,25 @@ void ImplementationVisitor::GenerateClassDefinitions(
}
if (type->ShouldExport() && !type->IsAbstract() &&
!type->HasCustomMap()) {
factory_header << type->HandlifiedCppTypeName() << " New"
<< type->name() << "(";
factory_impl << type->HandlifiedCppTypeName() << " Factory::New"
<< type->name() << "(";
std::string return_type = type->HandlifiedCppTypeName();
std::string function_name = "New" + type->name();
std::stringstream parameters;
for (const Field& f : type->ComputeAllFields()) {
if (f.name_and_type.name == "map") continue;
if (!f.index) {
std::string type_string =
f.name_and_type.type->HandlifiedCppTypeName();
factory_header << type_string << " " << f.name_and_type.name
<< ", ";
factory_impl << type_string << " " << f.name_and_type.name << ", ";
parameters << type_string << " " << f.name_and_type.name << ", ";
}
}
parameters << "AllocationType allocation_type";
factory_header << "AllocationType allocation_type);\n";
factory_impl << "AllocationType allocation_type) {\n";
factory_header << return_type << " " << function_name << "("
<< parameters.str() << ");\n";
factory_impl << "template <typename Impl>\n";
factory_impl << return_type
<< " TorqueGeneratedFactory<Impl>::" << function_name
<< "(" << parameters.str() << ") {\n";
factory_impl << " int size = ";
const ClassType* super = type->GetSuperClass();
......@@ -4257,20 +4258,17 @@ void ImplementationVisitor::GenerateClassDefinitions(
}
factory_impl << ");\n";
factory_impl << " ReadOnlyRoots roots(isolate());\n";
factory_impl << " Map map = factory()->read_only_roots()."
<< SnakeifyString(type->name()) << "_map();";
factory_impl << " HeapObject result =\n";
factory_impl << " "
"isolate()->heap()->AllocateRawWith<Heap::kRetryOrFail>"
"(size, allocation_type);\n";
factory_impl << " factory()->AllocateRawWithImmortalMap(size, "
"allocation_type, map);\n";
factory_impl << " WriteBarrierMode write_barrier_mode =\n"
<< " allocation_type == AllocationType::kYoung\n"
<< " ? SKIP_WRITE_BARRIER : UPDATE_WRITE_BARRIER;\n";
factory_impl << " result.set_map_after_allocation(roots."
<< SnakeifyString(type->name())
<< "_map(), write_barrier_mode);\n";
factory_impl << " " << type->HandlifiedCppTypeName()
<< " result_handle(" << type->name()
<< "::cast(result), isolate());\n";
<< "::cast(result), factory()->isolate());\n";
for (const Field& f : type->ComputeAllFields()) {
if (f.name_and_type.name == "map") continue;
......@@ -4291,6 +4289,16 @@ void ImplementationVisitor::GenerateClassDefinitions(
factory_impl << " return result_handle;\n";
factory_impl << "}\n\n";
factory_impl << "template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) "
<< return_type
<< "TorqueGeneratedFactory<Factory>::" << function_name
<< "(" << parameters.str() << ");\n";
factory_impl << "template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) "
<< return_type << "TorqueGeneratedFactory<LocalFactory>::"
<< function_name << "(" << parameters.str() << ");\n";
factory_impl << "\n\n";
}
}
......
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