Skip to content

Commit b10d23a

Browse files
author
Dart CI
committed
Version 2.19.0-316.0.dev
Merge 30de549 into dev
2 parents 4d40ff6 + 30de549 commit b10d23a

File tree

11 files changed

+223
-23
lines changed

11 files changed

+223
-23
lines changed

runtime/include/dart_api.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,7 @@ DART_EXPORT void Dart_NotifyIdle(int64_t deadline);
12771277
*
12781278
* Requires there to be a current isolate.
12791279
*/
1280-
DART_EXPORT void Dart_NotifyDetach(void);
1280+
DART_EXPORT void Dart_NotifyDestroyed(void);
12811281

12821282
/**
12831283
* Notifies the VM that the system is running low on memory.

runtime/vm/dart_api_impl.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1818,12 +1818,12 @@ DART_EXPORT void Dart_NotifyIdle(int64_t deadline) {
18181818
T->isolate()->group()->idle_time_handler()->NotifyIdle(deadline);
18191819
}
18201820

1821-
DART_EXPORT void Dart_NotifyDetach() {
1821+
DART_EXPORT void Dart_NotifyDestroyed() {
18221822
Thread* T = Thread::Current();
18231823
CHECK_ISOLATE(T->isolate());
18241824
API_TIMELINE_BEGIN_END(T);
18251825
TransitionNativeToVM transition(T);
1826-
T->heap()->NotifyDetach();
1826+
T->heap()->NotifyDestroyed();
18271827
}
18281828

18291829
DART_EXPORT void Dart_NotifyLowMemory() {

runtime/vm/dart_api_impl_test.cc

+9-8
Original file line numberDiff line numberDiff line change
@@ -10008,17 +10008,18 @@ void main() {
1000810008
EXPECT_VALID(result);
1000910009
}
1001010010

10011-
static void NotifyDetachNative(Dart_NativeArguments args) {
10012-
Dart_NotifyDetach();
10011+
static void NotifyDestroyedNative(Dart_NativeArguments args) {
10012+
Dart_NotifyDestroyed();
1001310013
}
1001410014

10015-
static Dart_NativeFunction NotifyDetach_native_lookup(Dart_Handle name,
10016-
int argument_count,
10017-
bool* auto_setup_scope) {
10018-
return NotifyDetachNative;
10015+
static Dart_NativeFunction NotifyDestroyed_native_lookup(
10016+
Dart_Handle name,
10017+
int argument_count,
10018+
bool* auto_setup_scope) {
10019+
return NotifyDestroyedNative;
1001910020
}
1002010021

10021-
TEST_CASE(DartAPI_NotifyDetach) {
10022+
TEST_CASE(DartAPI_NotifyDestroyed) {
1002210023
const char* kScriptChars = R"(
1002310024
import 'dart:isolate';
1002410025
@pragma("vm:external-name", "Test_nativeFunc")
@@ -10035,7 +10036,7 @@ void main() {
1003510036
}
1003610037
})";
1003710038
Dart_Handle lib =
10038-
TestCase::LoadTestScript(kScriptChars, &NotifyDetach_native_lookup);
10039+
TestCase::LoadTestScript(kScriptChars, &NotifyDestroyed_native_lookup);
1003910040
Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
1004010041
EXPECT_VALID(result);
1004110042
}

runtime/vm/heap/heap.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,9 @@ void Heap::NotifyIdle(int64_t deadline) {
436436
}
437437
}
438438

439-
void Heap::NotifyDetach() {
440-
TIMELINE_FUNCTION_GC_DURATION(Thread::Current(), "NotifyDetach");
441-
CollectAllGarbage(GCReason::kDetach, /*compact=*/true);
439+
void Heap::NotifyDestroyed() {
440+
TIMELINE_FUNCTION_GC_DURATION(Thread::Current(), "NotifyDestroyed");
441+
CollectAllGarbage(GCReason::kDestroyed, /*compact=*/true);
442442
Page::ClearCache();
443443
}
444444

@@ -878,8 +878,8 @@ const char* Heap::GCReasonToString(GCReason gc_reason) {
878878
return "external";
879879
case GCReason::kIdle:
880880
return "idle";
881-
case GCReason::kDetach:
882-
return "detach";
881+
case GCReason::kDestroyed:
882+
return "destroyed";
883883
case GCReason::kDebugging:
884884
return "debugging";
885885
case GCReason::kCatchUp:

runtime/vm/heap/heap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class Heap {
108108
ObjectPtr FindObject(FindObjectVisitor* visitor);
109109

110110
void NotifyIdle(int64_t deadline);
111-
void NotifyDetach();
111+
void NotifyDestroyed();
112112

113113
Dart_PerformanceMode mode() const { return mode_; }
114114
Dart_PerformanceMode SetMode(Dart_PerformanceMode mode);

runtime/vm/heap/spaces.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ enum class GCReason {
4646
kFull, // Heap::CollectAllGarbage
4747
kExternal, // Dart_NewFinalizableHandle Dart_NewWeakPersistentHandle
4848
kIdle, // Dart_NotifyIdle
49-
kDetach, // Dart_NotifyDetach
49+
kDestroyed, // Dart_NotifyDestroyed
5050
kDebugging, // service request, etc.
5151
kCatchUp, // End of ForceGrowthScope or Dart_PerformanceMode_Latency.
5252
};

runtime/vm/message_snapshot.cc

+14
Original file line numberDiff line numberDiff line change
@@ -2140,45 +2140,59 @@ class TypedDataViewMessageDeserializationCluster
21402140
Dart_TypedData_Type type;
21412141
switch (cid_) {
21422142
case kTypedDataInt8ArrayViewCid:
2143+
case kUnmodifiableTypedDataInt8ArrayViewCid:
21432144
type = Dart_TypedData_kInt8;
21442145
break;
21452146
case kTypedDataUint8ArrayViewCid:
2147+
case kUnmodifiableTypedDataUint8ArrayViewCid:
21462148
type = Dart_TypedData_kUint8;
21472149
break;
21482150
case kTypedDataUint8ClampedArrayViewCid:
2151+
case kUnmodifiableTypedDataUint8ClampedArrayViewCid:
21492152
type = Dart_TypedData_kUint8Clamped;
21502153
break;
21512154
case kTypedDataInt16ArrayViewCid:
2155+
case kUnmodifiableTypedDataInt16ArrayViewCid:
21522156
type = Dart_TypedData_kInt16;
21532157
break;
21542158
case kTypedDataUint16ArrayViewCid:
2159+
case kUnmodifiableTypedDataUint16ArrayViewCid:
21552160
type = Dart_TypedData_kUint16;
21562161
break;
21572162
case kTypedDataInt32ArrayViewCid:
2163+
case kUnmodifiableTypedDataInt32ArrayViewCid:
21582164
type = Dart_TypedData_kInt32;
21592165
break;
21602166
case kTypedDataUint32ArrayViewCid:
2167+
case kUnmodifiableTypedDataUint32ArrayViewCid:
21612168
type = Dart_TypedData_kUint32;
21622169
break;
21632170
case kTypedDataInt64ArrayViewCid:
2171+
case kUnmodifiableTypedDataInt64ArrayViewCid:
21642172
type = Dart_TypedData_kInt64;
21652173
break;
21662174
case kTypedDataUint64ArrayViewCid:
2175+
case kUnmodifiableTypedDataUint64ArrayViewCid:
21672176
type = Dart_TypedData_kUint64;
21682177
break;
21692178
case kTypedDataFloat32ArrayViewCid:
2179+
case kUnmodifiableTypedDataFloat32ArrayViewCid:
21702180
type = Dart_TypedData_kFloat32;
21712181
break;
21722182
case kTypedDataFloat64ArrayViewCid:
2183+
case kUnmodifiableTypedDataFloat64ArrayViewCid:
21732184
type = Dart_TypedData_kFloat64;
21742185
break;
21752186
case kTypedDataInt32x4ArrayViewCid:
2187+
case kUnmodifiableTypedDataInt32x4ArrayViewCid:
21762188
type = Dart_TypedData_kInt32x4;
21772189
break;
21782190
case kTypedDataFloat32x4ArrayViewCid:
2191+
case kUnmodifiableTypedDataFloat32x4ArrayViewCid:
21792192
type = Dart_TypedData_kFloat32x4;
21802193
break;
21812194
case kTypedDataFloat64x2ArrayViewCid:
2195+
case kUnmodifiableTypedDataFloat64x2ArrayViewCid:
21822196
type = Dart_TypedData_kFloat64x2;
21832197
break;
21842198
default:

sdk/lib/io/common.dart

+5-4
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,13 @@ class _BufferAndStart {
8383
}
8484

8585
// Ensure that the input List can be serialized through a native port.
86-
// Only Int8List and Uint8List Lists are serialized directly.
87-
// All other lists are first copied into a Uint8List. This has the added
88-
// benefit that it is faster to access from the C code as well.
8986
_BufferAndStart _ensureFastAndSerializableByteData(
9087
List<int> buffer, int start, int end) {
91-
if (buffer is Uint8List) {
88+
if ((buffer is Uint8List) &&
89+
(buffer.buffer.lengthInBytes == buffer.length)) {
90+
// Send typed data directly, unless it is a partial view, in which case we
91+
// would rather copy than drag in the potentially much large backing store.
92+
// See issue 50206.
9293
return new _BufferAndStart(buffer, start);
9394
}
9495
int length = end - start;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import "dart:async";
6+
import "dart:io";
7+
import "dart:typed_data";
8+
9+
import "package:expect/expect.dart";
10+
import "test_utils.dart" show withTempDir;
11+
12+
const chunkCount = 8192;
13+
const chunkSize = 8192;
14+
15+
Future<int> timeWrite(File file, chunks) async {
16+
final sink = file.openWrite();
17+
18+
final Stopwatch stopwatch = new Stopwatch()..start();
19+
for (var chunk in chunks) {
20+
sink.add(chunk);
21+
}
22+
await sink.close();
23+
stopwatch.stop();
24+
25+
Expect.equals(chunkCount * chunkSize, await file.length());
26+
27+
await file.delete();
28+
29+
return stopwatch.elapsedMilliseconds;
30+
}
31+
32+
main() async {
33+
await withTempDir("regress50206", (Directory tempDir) async {
34+
File file = new File("${tempDir.path}/file.tmp");
35+
36+
int arrayTime = 0;
37+
{
38+
var chunks = [];
39+
for (var i = 0; i < chunkCount; i++) {
40+
var chunk = new Uint8List(chunkSize);
41+
chunks.add(chunk);
42+
}
43+
arrayTime = await timeWrite(file, chunks);
44+
print("arrays: $arrayTime ms");
45+
}
46+
47+
int unmodifiableArrayTime = 0;
48+
{
49+
var chunks = [];
50+
for (var i = 0; i < chunkCount; i++) {
51+
var chunk = new UnmodifiableUint8ListView(new Uint8List(chunkSize));
52+
chunks.add(chunk);
53+
}
54+
unmodifiableArrayTime = await timeWrite(file, chunks);
55+
print("unmodifiable arrays: $unmodifiableArrayTime ms");
56+
}
57+
58+
int viewTime = 0;
59+
{
60+
var chunks = [];
61+
var backing = new Uint8List(chunkSize * chunkCount);
62+
for (var i = 0; i < chunkCount; i++) {
63+
var chunk =
64+
new Uint8List.view(backing.buffer, i * chunkSize, chunkSize);
65+
chunks.add(chunk);
66+
}
67+
viewTime = await timeWrite(file, chunks);
68+
print("views: $viewTime ms");
69+
}
70+
71+
int unmodifiableViewTime = 0;
72+
{
73+
var chunks = [];
74+
var backing = new Uint8List(chunkSize * chunkCount);
75+
for (var i = 0; i < chunkCount; i++) {
76+
var chunk = new UnmodifiableUint8ListView(
77+
new Uint8List.view(backing.buffer, i * chunkSize, chunkSize));
78+
chunks.add(chunk);
79+
}
80+
unmodifiableViewTime = await timeWrite(file, chunks);
81+
print("unmodifiable views: $unmodifiableViewTime ms");
82+
}
83+
84+
// Assert with factor a 1000 to avoid the test being flaky from I/O
85+
// variance. If we copy the whole backing store for each view chunk, things
86+
// will be quadratically slower, i.e. more than a factor of 1000.
87+
Expect.isTrue(unmodifiableArrayTime / arrayTime < 1000);
88+
Expect.isTrue(viewTime / arrayTime < 1000);
89+
Expect.isTrue(unmodifiableViewTime / arrayTime < 1000);
90+
});
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// @dart = 2.9
6+
7+
import "dart:async";
8+
import "dart:io";
9+
import "dart:typed_data";
10+
11+
import "package:expect/expect.dart";
12+
import "test_utils.dart" show withTempDir;
13+
14+
const chunkCount = 8192;
15+
const chunkSize = 8192;
16+
17+
Future<int> timeWrite(File file, chunks) async {
18+
final sink = file.openWrite();
19+
20+
final Stopwatch stopwatch = new Stopwatch()..start();
21+
for (var chunk in chunks) {
22+
sink.add(chunk);
23+
}
24+
await sink.close();
25+
stopwatch.stop();
26+
27+
Expect.equals(chunkCount * chunkSize, await file.length());
28+
29+
await file.delete();
30+
31+
return stopwatch.elapsedMilliseconds;
32+
}
33+
34+
main() async {
35+
await withTempDir("regress50206", (Directory tempDir) async {
36+
File file = new File("${tempDir.path}/file.tmp");
37+
38+
int arrayTime = 0;
39+
{
40+
var chunks = [];
41+
for (var i = 0; i < chunkCount; i++) {
42+
var chunk = new Uint8List(chunkSize);
43+
chunks.add(chunk);
44+
}
45+
arrayTime = await timeWrite(file, chunks);
46+
print("arrays: $arrayTime ms");
47+
}
48+
49+
int unmodifiableArrayTime = 0;
50+
{
51+
var chunks = [];
52+
for (var i = 0; i < chunkCount; i++) {
53+
var chunk = new UnmodifiableUint8ListView(new Uint8List(chunkSize));
54+
chunks.add(chunk);
55+
}
56+
unmodifiableArrayTime = await timeWrite(file, chunks);
57+
print("unmodifiable arrays: $unmodifiableArrayTime ms");
58+
}
59+
60+
int viewTime = 0;
61+
{
62+
var chunks = [];
63+
var backing = new Uint8List(chunkSize * chunkCount);
64+
for (var i = 0; i < chunkCount; i++) {
65+
var chunk =
66+
new Uint8List.view(backing.buffer, i * chunkSize, chunkSize);
67+
chunks.add(chunk);
68+
}
69+
viewTime = await timeWrite(file, chunks);
70+
print("views: $viewTime ms");
71+
}
72+
73+
int unmodifiableViewTime = 0;
74+
{
75+
var chunks = [];
76+
var backing = new Uint8List(chunkSize * chunkCount);
77+
for (var i = 0; i < chunkCount; i++) {
78+
var chunk = new UnmodifiableUint8ListView(
79+
new Uint8List.view(backing.buffer, i * chunkSize, chunkSize));
80+
chunks.add(chunk);
81+
}
82+
unmodifiableViewTime = await timeWrite(file, chunks);
83+
print("unmodifiable views: $unmodifiableViewTime ms");
84+
}
85+
86+
// Assert with factor a 1000 to avoid the test being flaky from I/O
87+
// variance. If we copy the whole backing store for each view chunk, things
88+
// will be quadratically slower, i.e. more than a factor of 1000.
89+
Expect.isTrue(unmodifiableArrayTime / arrayTime < 1000);
90+
Expect.isTrue(viewTime / arrayTime < 1000);
91+
Expect.isTrue(unmodifiableViewTime / arrayTime < 1000);
92+
});
93+
}

tools/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ CHANNEL dev
2727
MAJOR 2
2828
MINOR 19
2929
PATCH 0
30-
PRERELEASE 315
30+
PRERELEASE 316
3131
PRERELEASE_PATCH 0

0 commit comments

Comments
 (0)