Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0d75724

Browse files
alexmarkovCommit Queue
authored and
Commit Queue
committed
[vm,dyn_modules] Support compound pointers in FFI call arguments
TEST=ci (ffi/address_of_test) Change-Id: If87231c5c9dabb49a904dedd0cc8ef034c16dfe3 Cq-Include-Trybots: luci.dart.try:vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-linux-debug-x64-try,vm-dyn-mac-debug-arm64-try,vm-ffi-dyn-mac-debug-simarm64_arm64-try,vm-ffi-dyn-mac-release-simarm64_arm64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449069 Reviewed-by: Tess Strickland <sstrickl@google.com> Commit-Queue: Alexander Markov <alexmarkov@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com>
1 parent dbab989 commit 0d75724

File tree

10 files changed

+612
-586
lines changed

10 files changed

+612
-586
lines changed

‎runtime/vm/compiler/compiler_state.cc‎

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -141,41 +141,11 @@ DEFINE_TYPED_LIST_NATIVE_FUNCTION_GETTER(Float64x2, float64x2)
141141
return *Lower##_class_; \
142142
}
143143

144-
DEFINE_CLASS_GETTER(Ffi, Array, array, Array)
145-
DEFINE_CLASS_GETTER(Ffi, Compound, compound, Compound)
146-
DEFINE_CLASS_GETTER(Ffi, Struct, struct, Struct)
147-
DEFINE_CLASS_GETTER(Ffi, Union, union, Union)
148144
DEFINE_CLASS_GETTER(TypedData, TypedData, typed_data, TypedData)
149145
DEFINE_CLASS_GETTER(TypedData, TypedList, typed_list, _TypedList)
150146

151147
#undef DEFINE_CLASS_GETTER
152148

153-
const Field& CompilerState::CompoundOffsetInBytesField() {
154-
if (compound_offset_in_bytes_field_ == nullptr) {
155-
Thread* thread = Thread::Current();
156-
Zone* zone = thread->zone();
157-
const auto& field =
158-
Field::ZoneHandle(zone, CompoundClass().LookupInstanceFieldAllowPrivate(
159-
Symbols::_offsetInBytes()));
160-
ASSERT(!field.IsNull());
161-
compound_offset_in_bytes_field_ = &field;
162-
}
163-
return *compound_offset_in_bytes_field_;
164-
}
165-
166-
const Field& CompilerState::CompoundTypedDataBaseField() {
167-
if (compound_typed_data_base_field_ == nullptr) {
168-
Thread* thread = Thread::Current();
169-
Zone* zone = thread->zone();
170-
const auto& field =
171-
Field::ZoneHandle(zone, CompoundClass().LookupInstanceFieldAllowPrivate(
172-
Symbols::_typedDataBase()));
173-
ASSERT(!field.IsNull());
174-
compound_typed_data_base_field_ = &field;
175-
}
176-
return *compound_typed_data_base_field_;
177-
}
178-
179149
const Field& CompilerState::ErrorStackTraceField() {
180150
if (error_stack_trace_field_ == nullptr) {
181151
Thread* thread = Thread::Current();

‎runtime/vm/compiler/compiler_state.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,9 @@ class CompilerState : public ThreadStackResource {
126126
const Function& TypedListGetFloat64x2();
127127
const Function& TypedListSetFloat64x2();
128128

129-
const Class& ArrayClass();
130-
const Class& CompoundClass();
131129
const Class& ErrorClass();
132-
const Class& StructClass();
133130
const Class& TypedDataClass();
134-
const Class& UnionClass();
135131

136-
const Field& CompoundOffsetInBytesField();
137-
const Field& CompoundTypedDataBaseField();
138132
const Field& ErrorStackTraceField();
139133

140134
const Function* function() const { return function_; }

‎runtime/vm/compiler/ffi/marshaller.cc‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ const NativeFunctionType* NativeFunctionTypeFromFunctionType(
4747
intptr_t variadic_arguments_index = NativeFunctionType::kNoVariadicArguments;
4848
for (intptr_t i = 0; i < num_arguments; i++) {
4949
arg_type = c_signature.ParameterTypeAt(i + kNativeParamsStartAt);
50-
const bool varargs = arg_type.type_class() == object_store->varargs_class();
50+
const bool varargs =
51+
arg_type.type_class() == object_store->ffi_varargs_class();
5152
if (varargs) {
5253
arg_type = TypeArguments::Handle(zone, Type::Cast(arg_type).arguments())
5354
.TypeAt(0);
@@ -119,7 +120,7 @@ AbstractTypePtr BaseMarshaller::CType(intptr_t arg_index) const {
119120
zone, c_signature_.ParameterTypeAt(last_param_index));
120121
ObjectStore* object_store = IsolateGroup::Current()->object_store();
121122
const bool has_varargs =
122-
last_arg_type.type_class() == object_store->varargs_class();
123+
last_arg_type.type_class() == object_store->ffi_varargs_class();
123124

124125
// Skip #0 argument, the function pointer.
125126
const intptr_t real_arg_index = arg_index + kNativeParamsStartAt;
@@ -198,15 +199,16 @@ bool BaseMarshaller::IsTypedDataPointer(intptr_t arg_index) const {
198199
}
199200

200201
static bool IsCompound(Zone* zone, const AbstractType& type) {
201-
auto& compiler_state = Thread::Current()->compiler_state();
202+
ObjectStore* object_store =
203+
Thread::Current()->isolate_group()->object_store();
202204
auto& cls = Class::Handle(zone, type.type_class());
203-
if (cls.id() == compiler_state.CompoundClass().id() ||
204-
cls.id() == compiler_state.ArrayClass().id()) {
205+
if ((object_store->ffi_compound_class() == cls.ptr()) ||
206+
(object_store->ffi_array_class() == cls.ptr())) {
205207
return true;
206208
}
207209
cls ^= cls.SuperClass();
208-
if (cls.id() == compiler_state.StructClass().id() ||
209-
cls.id() == compiler_state.UnionClass().id()) {
210+
if ((object_store->ffi_struct_class() == cls.ptr()) ||
211+
(object_store->ffi_union_class() == cls.ptr())) {
210212
return true;
211213
}
212214
return false;

‎runtime/vm/compiler/frontend/kernel_to_il.cc‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4792,37 +4792,39 @@ Fragment FlowGraphBuilder::WrapTypedDataBaseInCompound(
47924792
Class::ZoneHandle(Z, compound_type.type_class());
47934793
compound_sub_class.EnsureIsFinalized(thread_);
47944794

4795-
auto& state = thread_->compiler_state();
4795+
ObjectStore* object_store = IG->object_store();
47964796

47974797
Fragment body;
47984798
LocalVariable* typed_data = MakeTemporary("typed_data_base");
47994799
body += AllocateObject(TokenPosition::kNoSource, compound_sub_class, 0);
48004800
LocalVariable* compound = MakeTemporary("compound");
48014801
body += LoadLocal(compound);
48024802
body += LoadLocal(typed_data);
4803-
body += StoreField(state.CompoundTypedDataBaseField(),
4804-
StoreFieldInstr::Kind::kInitializing);
4803+
body += StoreField(
4804+
Field::ZoneHandle(Z, object_store->compound_typed_data_base_field()),
4805+
StoreFieldInstr::Kind::kInitializing);
48054806
body += LoadLocal(compound);
48064807
body += IntConstant(0);
4807-
body += StoreField(state.CompoundOffsetInBytesField(),
4808-
StoreFieldInstr::Kind::kInitializing);
4808+
body += StoreField(
4809+
Field::ZoneHandle(Z, object_store->compound_offset_in_bytes_field()),
4810+
StoreFieldInstr::Kind::kInitializing);
48094811
body += DropTempsPreserveTop(1); // Drop TypedData.
48104812
return body;
48114813
}
48124814

48134815
Fragment FlowGraphBuilder::LoadTypedDataBaseFromCompound() {
48144816
Fragment body;
4815-
auto& state = thread_->compiler_state();
4816-
body += LoadField(state.CompoundTypedDataBaseField(),
4817-
/*calls_initializer=*/false);
4817+
constauto& field = Field::ZoneHandle(
4818+
Z, IG->object_store()->compound_typed_data_base_field());
4819+
body += LoadField(field, /*calls_initializer=*/false);
48184820
return body;
48194821
}
48204822

48214823
Fragment FlowGraphBuilder::LoadOffsetInBytesFromCompound() {
48224824
Fragment body;
4823-
auto& state = thread_->compiler_state();
4824-
body += LoadField(state.CompoundOffsetInBytesField(),
4825-
/*calls_initializer=*/false);
4825+
constauto& field = Field::ZoneHandle(
4826+
Z, IG->object_store()->compound_offset_in_bytes_field());
4827+
body += LoadField(field, /*calls_initializer=*/false);
48264828
return body;
48274829
}
48284830

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /