Skip to content

Commit 3605630

Browse files
vsmenoncommit-bot@chromium.org
authored andcommitted
[dartdevc] don't clear generic type caches on a hot restart
The combination of type expression hoisting, hot restart, and generic cache reset triggers occasional breakage (see #37259). Not clearing the generic cache should be safe, but will some leak memory: unloaded types will pollute the cache. References to those unloaded types in user code, however, should be cleared. Bug: #37259 Change-Id: Ia15115a41556db7a19109f0178baa63ec0cfcb9c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109100 Reviewed-by: Leaf Petersen <[email protected]> Commit-Queue: Vijay Menon <[email protected]>
1 parent 7fa49a2 commit 3605630

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/classes.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,14 @@ generic(typeConstructor, setBaseClass) => JS('', '''(() => {
127127
$throwInternalError('must have at least one generic type argument');
128128
}
129129
let resultMap = new Map();
130-
$_cacheMaps.push(resultMap);
130+
// TODO(vsm): Rethink how to clear the resultMap on hot restart.
131+
// A simple clear via:
132+
// _cacheMaps.push(resultMap);
133+
// will break (a) we hoist type expressions in generated code and
134+
// (b) we don't clear those type expressions in the presence of a
135+
// hot restart. Not clearing this map (as we're doing now) should
136+
// not affect correctness, but can result in a memory leak across
137+
// multiple restarts.
131138
function makeGenericType(...args) {
132139
if (args.length != length && args.length != 0) {
133140
$throwInternalError('requires ' + length + ' or 0 type arguments');
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) 2019, 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 'package:expect/expect.dart';
6+
import 'dart:_foreign_helper' show JS;
7+
import 'dart:_runtime' as dart;
8+
9+
class Foo<T> {
10+
Type type() => typeOf<Foo<T>>();
11+
}
12+
13+
class Bar {}
14+
15+
Type typeOf<T>() => T;
16+
17+
Type fooOf<T>() => typeOf<Foo<T>>();
18+
19+
void main() {
20+
var f1 = Foo<Bar>();
21+
var t1 = typeOf<Foo<Bar>>();
22+
Expect.equals(f1.type(), t1);
23+
var s1 = fooOf<Bar>();
24+
Expect.equals(t1, s1);
25+
26+
dart.hotRestart();
27+
28+
var f2 = Foo<Bar>();
29+
Expect.isTrue(f2 is Foo<Bar>);
30+
var t2 = typeOf<Foo<Bar>>();
31+
Expect.equals(f2.type(), t2);
32+
var s2 = fooOf<Bar>();
33+
Expect.equals(t2, s2);
34+
}

0 commit comments

Comments
 (0)