[vm/ffi] Fix instantiation and garbage collection of NativeType objects
Fixes: https://github.com/dart-lang/sdk/issues/37780 Change-Id: I04f5788ab2dbce13fd6bd906acb91b8acf6d7fb3 Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try, app-kernel-linux-debug-x64-try, vm-kernel-linux-debug-simdbc64-try,vm-kernel-linux-debug-ia32-try,vm-dartkb-linux-debug-simarm64-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-dartkb-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-ffi-android-product-arm-try,vm-dartkb-linux-release-x64-abi-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112390 Commit-Queue: Daco Harkes <dacoharkes@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com> Auto-Submit: Daco Harkes <dacoharkes@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
b0d079a96b
commit
77f545bbc4
@@ -7,9 +7,12 @@
|
||||
import "dart:_internal" show patch;
|
||||
import 'dart:typed_data' show TypedData;
|
||||
|
||||
// NativeType is not private, because it is used in type arguments.
|
||||
// NativeType is abstract because it not used with const constructors in
|
||||
// annotations directly, so it should never be instantiated at runtime.
|
||||
@patch
|
||||
@pragma("vm:entry-point")
|
||||
class NativeType {}
|
||||
abstract class NativeType {}
|
||||
|
||||
@patch
|
||||
@pragma("vm:entry-point")
|
||||
|
||||
@@ -330,6 +330,10 @@ static uword GetInstanceSizeImpl(const dart::Class& handle) {
|
||||
case kByteBufferCid:
|
||||
case kByteDataViewCid:
|
||||
case kFfiPointerCid:
|
||||
case kFfiDynamicLibraryCid:
|
||||
#define HANDLE_CASE(clazz) case kFfi##clazz##Cid:
|
||||
CLASS_LIST_FFI_TYPE_MARKER(HANDLE_CASE)
|
||||
#undef HANDLE_CASE
|
||||
#define HANDLE_CASE(clazz) \
|
||||
case kTypedData##clazz##Cid: \
|
||||
case kTypedData##clazz##ViewCid: \
|
||||
|
||||
@@ -302,6 +302,13 @@ intptr_t RawObject::VisitPointersPredefined(ObjectPointerVisitor* visitor,
|
||||
size = RawDynamicLibrary::VisitDynamicLibraryPointers(raw_obj, visitor);
|
||||
break;
|
||||
}
|
||||
#define RAW_VISITPOINTERS(clazz) case kFfi##clazz##Cid:
|
||||
CLASS_LIST_FFI_TYPE_MARKER(RAW_VISITPOINTERS) {
|
||||
// NativeType do not have any fields or type arguments.
|
||||
size = HeapSize();
|
||||
break;
|
||||
}
|
||||
#undef RAW_VISITPOINTERS
|
||||
case kFreeListElement: {
|
||||
uword addr = RawObject::ToAddr(this);
|
||||
FreeListElement* element = reinterpret_cast<FreeListElement*>(addr);
|
||||
|
||||
@@ -8,7 +8,7 @@ part of dart.ffi;
|
||||
///
|
||||
/// [NativeType]'s subtypes are not constructible in the Dart code and serve
|
||||
/// purely as markers in type signatures.
|
||||
class NativeType {
|
||||
abstract class NativeType {
|
||||
const NativeType();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
//
|
||||
// SharedObjects=ffi_test_functions
|
||||
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'dylib_utils.dart';
|
||||
|
||||
DynamicLibrary ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
|
||||
|
||||
final triggerGc = ffiTestFunctions
|
||||
.lookupFunction<Void Function(), void Function()>("TriggerGC");
|
||||
|
||||
main(List<String> args) {
|
||||
final foo = [Float(), Double(), Uint8()];
|
||||
triggerGc();
|
||||
print(foo);
|
||||
}
|
||||
Reference in New Issue
Block a user