Commit e99f0393 authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[torque][wasm] generate C++ class and BodyDescriptor for WasmCapiFunctionData

Drive-by fixes:
 - Use constexpr types to determine C++ type names.
 - Fix factory constructors to not skip write barriers in old generation.

Change-Id: I0ebbfd56c06ad41d02836fb48531ae7eded166bf
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2400994Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70921}
parent 8c3f81be
......@@ -28,7 +28,7 @@ type never;
type Tagged generates 'TNode<MaybeObject>' constexpr 'MaybeObject';
type StrongTagged extends Tagged
generates 'TNode<Object>' constexpr 'ObjectPtr';
generates 'TNode<Object>' constexpr 'Object';
type Smi extends StrongTagged generates 'TNode<Smi>' constexpr 'Smi';
type TaggedIndex extends StrongTagged
generates 'TNode<TaggedIndex>' constexpr 'TaggedIndex';
......@@ -150,7 +150,7 @@ type ObjectHashTable extends HashTable
generates 'TNode<ObjectHashTable>';
extern class NumberDictionary extends HashTable;
type RawPtr generates 'TNode<RawPtrT>' constexpr 'void*';
type RawPtr generates 'TNode<RawPtrT>' constexpr 'Address';
type ExternalPointer
generates 'TNode<ExternalPointerT>' constexpr 'ExternalPointer_t';
extern class Code extends HeapObject;
......
......@@ -242,24 +242,6 @@ using Numeric = UnionT<Number, BigInt>;
// A pointer to a builtin function, used by Torque's function pointers.
using BuiltinPtr = Smi;
class int31_t {
public:
int31_t() : value_(0) {}
int31_t(int value) : value_(value) { // NOLINT(runtime/explicit)
DCHECK_EQ((value & 0x80000000) != 0, (value & 0x40000000) != 0);
}
int31_t& operator=(int value) {
DCHECK_EQ((value & 0x80000000) != 0, (value & 0x40000000) != 0);
value_ = value;
return *this;
}
int32_t value() const { return value_; }
operator int32_t() const { return value_; }
private:
int32_t value_;
};
template <class T, class U>
struct is_subtype {
static const bool value =
......
......@@ -1740,6 +1740,24 @@ class IsolateRoot {
};
#endif
class int31_t {
public:
constexpr int31_t() : value_(0) {}
constexpr int31_t(int value) : value_(value) { // NOLINT(runtime/explicit)
DCHECK_EQ((value & 0x80000000) != 0, (value & 0x40000000) != 0);
}
int31_t& operator=(int value) {
DCHECK_EQ((value & 0x80000000) != 0, (value & 0x40000000) != 0);
value_ = value;
return *this;
}
int32_t value() const { return value_; }
operator int32_t() const { return value_; }
private:
int32_t value_;
};
} // namespace internal
// Tag dispatching support for acquire loads and release stores.
......
......@@ -357,7 +357,6 @@ Type::bitset BitsetType::Lub(const MapRefLike& map) {
case WASM_VALUE_TYPE:
case CACHED_TEMPLATE_OBJECT_TYPE:
case ENUM_CACHE_TYPE:
case WASM_CAPI_FUNCTION_DATA_TYPE:
case WASM_INDIRECT_FUNCTION_TABLE_TYPE:
case WASM_EXCEPTION_TAG_TYPE:
case WASM_EXPORTED_FUNCTION_DATA_TYPE:
......
......@@ -1555,8 +1555,6 @@ void CallHandlerInfo::CallHandlerInfoVerify(Isolate* isolate) {
.next_call_side_effect_free_call_handler_info_map());
}
USE_TORQUE_VERIFIER(WasmCapiFunctionData)
USE_TORQUE_VERIFIER(WasmJSFunctionData)
USE_TORQUE_VERIFIER(WasmIndirectFunctionTable)
......
......@@ -1878,16 +1878,6 @@ void FunctionTemplateInfo::FunctionTemplateInfoPrint(
os << "\n";
}
void WasmCapiFunctionData::WasmCapiFunctionDataPrint(
std::ostream& os) { // NOLINT
PrintHeader(os, "WasmCapiFunctionData");
os << "\n - call_target: " << call_target();
os << "\n - embedder_data: " << Brief(embedder_data());
os << "\n - wrapper_code: " << Brief(wrapper_code());
os << "\n - serialized_signature: " << Brief(serialized_signature());
os << "\n";
}
void WasmIndirectFunctionTable::WasmIndirectFunctionTablePrint(
std::ostream& os) {
PrintHeader(os, "WasmIndirectFunctionTable");
......
......@@ -72,6 +72,10 @@ class WasmExportedFunctionData;
class WasmJSFunctionData;
class WeakCell;
namespace wasm {
class ValueType;
} // namespace wasm
enum class SharedFlag : uint8_t;
enum class InitializedFlag : uint8_t;
......
......@@ -57,7 +57,6 @@ namespace internal {
V(UncompiledDataWithoutPreparseData) \
V(UncompiledDataWithPreparseData) \
V(WasmArray) \
V(WasmCapiFunctionData) \
V(WasmIndirectFunctionTable) \
V(WasmInstanceObject) \
V(WasmStruct) \
......
......@@ -73,7 +73,6 @@ enum InstanceType : uint16_t;
V(TransitionArray) \
V(UncompiledDataWithoutPreparseData) \
V(UncompiledDataWithPreparseData) \
V(WasmCapiFunctionData) \
V(WasmIndirectFunctionTable) \
V(WasmInstanceObject) \
V(WasmArray) \
......
......@@ -148,8 +148,6 @@ namespace internal {
V(_, TEMPLATE_OBJECT_DESCRIPTION_TYPE, TemplateObjectDescription, \
template_object_description) \
V(_, TUPLE2_TYPE, Tuple2, tuple2) \
V(_, WASM_CAPI_FUNCTION_DATA_TYPE, WasmCapiFunctionData, \
wasm_capi_function_data) \
V(_, WASM_EXCEPTION_TAG_TYPE, WasmExceptionTag, wasm_exception_tag) \
V(_, WASM_EXPORTED_FUNCTION_DATA_TYPE, WasmExportedFunctionData, \
wasm_exported_function_data) \
......
......@@ -4077,7 +4077,7 @@ void CppClassGenerator::GenerateFieldAccessorForTagged(const Field& f) {
std::string offset = "k" + CamelifyString(name) + "Offset";
bool strong_pointer = field_type->IsSubtypeOf(TypeOracle::GetObjectType());
std::string type = field_type->GetRuntimeType();
std::string type = field_type->UnhandlifiedCppTypeName();
// Generate declarations in header.
if (!field_type->IsClassType() && field_type != TypeOracle::GetObjectType()) {
hdr_ << " // Torque type: " << field_type->ToString() << "\n";
......@@ -4264,9 +4264,12 @@ void ImplementationVisitor::GenerateClassDefinitions(
factory_impl << " "
"isolate()->heap()->AllocateRawWith<Heap::kRetryOrFail>"
"(size, allocation_type);\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(), SKIP_WRITE_BARRIER);\n";
<< "_map(), write_barrier_mode);\n";
factory_impl << " " << type->HandlifiedCppTypeName()
<< " result_handle(" << type->name()
<< "::cast(result), isolate());\n";
......@@ -4280,7 +4283,7 @@ void ImplementationVisitor::GenerateClassDefinitions(
TypeOracle::GetTaggedType()) &&
!f.name_and_type.type->IsSubtypeOf(TypeOracle::GetSmiType())) {
factory_impl << "*" << f.name_and_type.name
<< ", SKIP_WRITE_BARRIER";
<< ", write_barrier_mode";
} else {
factory_impl << f.name_and_type.name;
}
......@@ -4318,7 +4321,7 @@ void GeneratePrintDefinitionsForClass(std::ostream& impl, const ClassType* type,
impl << template_params << "\n";
impl << "void " << gen_name_T << "::" << type->name()
<< "Print(std::ostream& os) {\n";
impl << " this->PrintHeader(os, \"" << gen_name << "\");\n";
impl << " this->PrintHeader(os, \"" << type->name() << "\");\n";
auto hierarchy = type->GetHierarchy();
std::map<std::string, const AggregateType*> field_names;
for (const AggregateType* aggregate_type : hierarchy) {
......
......@@ -75,12 +75,18 @@ std::string Type::SimpleName() const {
std::string Type::HandlifiedCppTypeName() const {
if (IsSubtypeOf(TypeOracle::GetSmiType())) return "int";
if (IsSubtypeOf(TypeOracle::GetTaggedType())) {
return "Handle<" + ConstexprVersion()->GetGeneratedTypeName() + ">";
return "Handle<" + UnhandlifiedCppTypeName() + ">";
} else {
return ConstexprVersion()->GetGeneratedTypeName();
return UnhandlifiedCppTypeName();
}
}
std::string Type::UnhandlifiedCppTypeName() const {
if (IsSubtypeOf(TypeOracle::GetSmiType())) return "int";
if (this == TypeOracle::GetObjectType()) return "Object";
return GetConstexprGeneratedTypeName();
}
bool Type::IsSubtypeOf(const Type* supertype) const {
if (supertype->IsTopType()) return true;
if (IsNever()) return true;
......
......@@ -117,6 +117,7 @@ class V8_EXPORT_PRIVATE Type : public TypeBase {
// Used for naming generated code.
virtual std::string SimpleName() const;
std::string UnhandlifiedCppTypeName() const;
std::string HandlifiedCppTypeName() const;
const Type* parent() const { return parent_; }
......@@ -159,6 +160,7 @@ class V8_EXPORT_PRIVATE Type : public TypeBase {
virtual const Type* ConstexprVersion() const {
if (constexpr_version_) return constexpr_version_;
if (IsConstexpr()) return this;
if (parent()) return parent()->ConstexprVersion();
return nullptr;
}
......
......@@ -365,16 +365,6 @@ WasmCapiFunction::WasmCapiFunction(Address ptr) : JSFunction(ptr) {
}
CAST_ACCESSOR(WasmCapiFunction)
// WasmCapiFunctionData
OBJECT_CONSTRUCTORS_IMPL(WasmCapiFunctionData, Struct)
CAST_ACCESSOR(WasmCapiFunctionData)
PRIMITIVE_ACCESSORS(WasmCapiFunctionData, call_target, Address,
kCallTargetOffset)
ACCESSORS(WasmCapiFunctionData, embedder_data, Foreign, kEmbedderDataOffset)
ACCESSORS(WasmCapiFunctionData, wrapper_code, Code, kWrapperCodeOffset)
ACCESSORS(WasmCapiFunctionData, serialized_signature, PodArray<wasm::ValueType>,
kSerializedSignatureOffset)
// WasmExternalFunction
WasmExternalFunction::WasmExternalFunction(Address ptr) : JSFunction(ptr) {
SLOW_DCHECK(IsWasmExternalFunction(*this));
......
......@@ -1840,16 +1840,14 @@ bool WasmCapiFunction::IsWasmCapiFunction(Object object) {
Handle<WasmCapiFunction> WasmCapiFunction::New(
Isolate* isolate, Address call_target, Handle<Foreign> embedder_data,
Handle<PodArray<wasm::ValueType>> serialized_signature) {
Handle<WasmCapiFunctionData> fun_data =
Handle<WasmCapiFunctionData>::cast(isolate->factory()->NewStruct(
WASM_CAPI_FUNCTION_DATA_TYPE, AllocationType::kOld));
fun_data->set_call_target(call_target);
fun_data->set_embedder_data(*embedder_data);
fun_data->set_serialized_signature(*serialized_signature);
// TODO(jkummerow): Install a JavaScript wrapper. For now, calling
// these functions directly is unsupported; they can only be called
// from Wasm code.
fun_data->set_wrapper_code(isolate->builtins()->builtin(Builtins::kIllegal));
Handle<WasmCapiFunctionData> fun_data =
isolate->factory()->NewWasmCapiFunctionData(
call_target, embedder_data,
isolate->builtins()->builtin_handle(Builtins::kIllegal),
serialized_signature, AllocationType::kOld);
Handle<SharedFunctionInfo> shared =
isolate->factory()->NewSharedFunctionInfoForWasmCapiFunction(fun_data);
return Handle<WasmCapiFunction>::cast(
......
......@@ -753,27 +753,6 @@ class WasmIndirectFunctionTable : public Struct {
OBJECT_CONSTRUCTORS(WasmIndirectFunctionTable, Struct);
};
class WasmCapiFunctionData : public Struct {
public:
DECL_PRIMITIVE_ACCESSORS(call_target, Address)
DECL_ACCESSORS(embedder_data, Foreign)
DECL_ACCESSORS(wrapper_code, Code)
DECL_ACCESSORS(serialized_signature, PodArray<wasm::ValueType>)
DECL_CAST(WasmCapiFunctionData)
DECL_PRINTER(WasmCapiFunctionData)
DECL_VERIFIER(WasmCapiFunctionData)
DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
TORQUE_GENERATED_WASM_CAPI_FUNCTION_DATA_FIELDS)
STATIC_ASSERT(kStartOfStrongFieldsOffset == kEmbedderDataOffset);
using BodyDescriptor = FlexibleBodyDescriptor<kStartOfStrongFieldsOffset>;
OBJECT_CONSTRUCTORS(WasmCapiFunctionData, Struct);
};
// Information for a WasmExportedFunction which is referenced as the function
// data of the SharedFunctionInfo underlying the function. For details please
// see the {SharedFunctionInfo::HasWasmExportedFunctionData} predicate.
......
......@@ -35,7 +35,8 @@ extern class WasmJSFunctionData extends Struct {
serialized_signature: PodArrayOfWasmValueType;
}
extern class WasmCapiFunctionData extends Struct {
@export
class WasmCapiFunctionData extends HeapObject {
call_target: RawPtr;
embedder_data: Foreign; // Managed<wasm::FuncData>
wrapper_code: Code;
......
This diff is collapsed.
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