Skip to content

Commit 6cabe8d

Browse files
rmacnak-googleCommit Queue
authored andcommitted
---
yaml --- r: 361497 b: refs/heads/main c: 904c6fd h: refs/heads/main i: 361495: 959e2e1
1 parent 6b82cf7 commit 6cabe8d

File tree

7 files changed

+60
-1
lines changed

7 files changed

+60
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,7 @@ refs/tags/2.14.0-96.0.dev: 1eee24e50fc3028754d9a8e98852b949c04da4e4
19881988
refs/tags/2.14.0-97.0.dev: ba9c1636e87fbdcc02b8bc4a584455c32f8378b4
19891989
refs/tags/2.14.0-98.0.dev: f2d370c93582bbf4da42b5dd4c906d6145b01ea9
19901990
refs/tags/2.14.0-99.0.dev: e722f62b48fb382534efc1f20735def68848006f
1991-
refs/heads/main: b3e57bd2f7a63959d346d3de4357eec65476f761
1991+
refs/heads/main: 904c6fd6fa402f7f9586a1a5f156127357540d2f
19921992
refs/heads/TedSander-patch-1: 739563c962fea6f5e2883a8d84f8638c48f2aa40
19931993
refs/tags/2.13.1: 53a67a7b0650edb435535a50b5c430abbc68bc60
19941994
refs/tags/2.13.3: a77223333944631f8f48a76e7f4697a4877e29d7

trunk/runtime/include/dart_api.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,15 @@ DART_EXPORT void Dart_KillIsolate(Dart_Isolate isolate);
12701270
*/
12711271
DART_EXPORT void Dart_NotifyIdle(int64_t deadline);
12721272

1273+
/**
1274+
* Notifies the VM that the embedder expects the application's working set has
1275+
* recently shrunk significantly and is not expected to rise in the near future.
1276+
* The VM may spend O(heap-size) time performing clean up work.
1277+
*
1278+
* Requires there to be a current isolate.
1279+
*/
1280+
DART_EXPORT void Dart_NotifyDetach(void);
1281+
12731282
/**
12741283
* Notifies the VM that the system is running low on memory.
12751284
*

trunk/runtime/vm/dart_api_impl.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,14 @@ 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() {
1822+
Thread* T = Thread::Current();
1823+
CHECK_ISOLATE(T->isolate());
1824+
API_TIMELINE_BEGIN_END(T);
1825+
TransitionNativeToVM transition(T);
1826+
T->heap()->NotifyDetach();
1827+
}
1828+
18211829
DART_EXPORT void Dart_NotifyLowMemory() {
18221830
API_TIMELINE_BEGIN_END(Thread::Current());
18231831
Page::ClearCache();

trunk/runtime/vm/dart_api_impl_test.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10008,6 +10008,38 @@ void main() {
1000810008
EXPECT_VALID(result);
1000910009
}
1001010010

10011+
static void NotifyDetachNative(Dart_NativeArguments args) {
10012+
Dart_NotifyDetach();
10013+
}
10014+
10015+
static Dart_NativeFunction NotifyDetach_native_lookup(Dart_Handle name,
10016+
int argument_count,
10017+
bool* auto_setup_scope) {
10018+
return NotifyDetachNative;
10019+
}
10020+
10021+
TEST_CASE(DartAPI_NotifyDetach) {
10022+
const char* kScriptChars = R"(
10023+
import 'dart:isolate';
10024+
@pragma("vm:external-name", "Test_nativeFunc")
10025+
external void notifyDetach();
10026+
void main() {
10027+
var v;
10028+
for (var i = 0; i < 100; i++) {
10029+
var t = [];
10030+
for (var j = 0; j < 10000; j++) {
10031+
t.add(List.filled(100, null));
10032+
}
10033+
v = t;
10034+
notifyDetach();
10035+
}
10036+
})";
10037+
Dart_Handle lib =
10038+
TestCase::LoadTestScript(kScriptChars, &NotifyDetach_native_lookup);
10039+
Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
10040+
EXPECT_VALID(result);
10041+
}
10042+
1001110043
static void SetPerformanceModeDefault(Dart_NativeArguments args) {
1001210044
Dart_SetPerformanceMode(Dart_PerformanceMode_Default);
1001310045
}

trunk/runtime/vm/heap/heap.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,12 @@ 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);
442+
Page::ClearCache();
443+
}
444+
439445
Dart_PerformanceMode Heap::SetMode(Dart_PerformanceMode new_mode) {
440446
Dart_PerformanceMode old_mode = mode_.exchange(new_mode);
441447
if ((old_mode == Dart_PerformanceMode_Latency) &&
@@ -872,6 +878,8 @@ const char* Heap::GCReasonToString(GCReason gc_reason) {
872878
return "external";
873879
case GCReason::kIdle:
874880
return "idle";
881+
case GCReason::kDetach:
882+
return "detach";
875883
case GCReason::kDebugging:
876884
return "debugging";
877885
case GCReason::kCatchUp:

trunk/runtime/vm/heap/heap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class Heap {
108108
ObjectPtr FindObject(FindObjectVisitor* visitor);
109109

110110
void NotifyIdle(int64_t deadline);
111+
void NotifyDetach();
111112

112113
Dart_PerformanceMode mode() const { return mode_; }
113114
Dart_PerformanceMode SetMode(Dart_PerformanceMode mode);

trunk/runtime/vm/heap/spaces.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ enum class GCReason {
4646
kFull, // Heap::CollectAllGarbage
4747
kExternal, // Dart_NewFinalizableHandle Dart_NewWeakPersistentHandle
4848
kIdle, // Dart_NotifyIdle
49+
kDetach, // Dart_NotifyDetach
4950
kDebugging, // service request, etc.
5051
kCatchUp, // End of ForceGrowthScope or Dart_PerformanceMode_Latency.
5152
};

0 commit comments

Comments
 (0)