Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
dart-lang
sdk
runtime
vm
heap
weak_table_test.cc
Go to the documentation of this file.
1
// Copyright (c) 2020, 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
#include "
platform/globals.h
"
6
7
#include "
platform/assert.h
"
8
#include "
vm/globals.h
"
9
#include "
vm/heap/heap.h
"
10
#include "
vm/heap/weak_table.h
"
11
#include "
vm/unit_test.h
"
12
13
namespace
dart
{
14
15
ISOLATE_UNIT_TEST_CASE
(WeakTables) {
16
const
Object
& old_obj =
Object::Handle
(
String::New
(
"old"
,
Heap::kOld
));
17
const
Object
& new_obj =
Object::Handle
(
String::New
(
"new"
,
Heap::kNew
));
18
const
Object
& imm_obj =
Object::Handle
(
Smi::New
(0));
19
20
// Initially absent.
21
Heap
* heap = thread->heap();
22
const
intptr_t kNoValue =
WeakTable::kNoValue
;
23
EXPECT_EQ(kNoValue, heap->
GetObjectId
(old_obj.
ptr
()));
24
EXPECT_EQ(kNoValue, heap->
GetObjectId
(new_obj.
ptr
()));
25
EXPECT_EQ(kNoValue, heap->
GetObjectId
(imm_obj.
ptr
()));
26
27
// Found after insert.
28
heap->
SetObjectId
(old_obj.
ptr
(), 100);
29
heap->
SetObjectId
(new_obj.
ptr
(), 200);
30
heap->
SetObjectId
(imm_obj.
ptr
(), 300);
31
EXPECT_EQ(100, heap->
GetObjectId
(old_obj.
ptr
()));
32
EXPECT_EQ(200, heap->
GetObjectId
(new_obj.
ptr
()));
33
EXPECT_EQ(300, heap->
GetObjectId
(imm_obj.
ptr
()));
34
35
// Found after update.
36
heap->
SetObjectId
(old_obj.
ptr
(), 400);
37
heap->
SetObjectId
(new_obj.
ptr
(), 500);
38
heap->
SetObjectId
(imm_obj.
ptr
(), 600);
39
EXPECT_EQ(400, heap->
GetObjectId
(old_obj.
ptr
()));
40
EXPECT_EQ(500, heap->
GetObjectId
(new_obj.
ptr
()));
41
EXPECT_EQ(600, heap->
GetObjectId
(imm_obj.
ptr
()));
42
43
// Found after GC.
44
GCTestHelper::CollectNewSpace();
45
EXPECT_EQ(400, heap->
GetObjectId
(old_obj.
ptr
()));
46
EXPECT_EQ(500, heap->
GetObjectId
(new_obj.
ptr
()));
47
EXPECT_EQ(600, heap->
GetObjectId
(imm_obj.
ptr
()));
48
49
// Found after GC.
50
GCTestHelper::CollectOldSpace();
51
EXPECT_EQ(400, heap->
GetObjectId
(old_obj.
ptr
()));
52
EXPECT_EQ(500, heap->
GetObjectId
(new_obj.
ptr
()));
53
EXPECT_EQ(600, heap->
GetObjectId
(imm_obj.
ptr
()));
54
55
// Absent after reset.
56
heap->
ResetObjectIdTable
();
57
EXPECT_EQ(kNoValue, heap->
GetObjectId
(old_obj.
ptr
()));
58
EXPECT_EQ(kNoValue, heap->
GetObjectId
(new_obj.
ptr
()));
59
EXPECT_EQ(kNoValue, heap->
GetObjectId
(imm_obj.
ptr
()));
60
}
61
62
}
// namespace dart
assert.h
dart::Heap
Definition
heap.h:35
dart::Heap::kNew
@ kNew
Definition
heap.h:38
dart::Heap::kOld
@ kOld
Definition
heap.h:39
dart::Heap::ResetObjectIdTable
void ResetObjectIdTable()
Definition
heap.cc:888
dart::Heap::GetObjectId
intptr_t GetObjectId(ObjectPtr raw_obj) const
Definition
heap.h:197
dart::Heap::SetObjectId
void SetObjectId(ObjectPtr raw_obj, intptr_t object_id)
Definition
heap.h:193
dart::Object
Definition
object.h:315
dart::Object::ptr
ObjectPtr ptr() const
Definition
object.h:332
dart::Object::Handle
static Object & Handle()
Definition
object.h:407
dart::Smi::New
static SmiPtr New(intptr_t value)
Definition
object.h:9985
dart::String::New
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
Definition
object.cc:23777
dart::WeakTable::kNoValue
static constexpr intptr_t kNoValue
Definition
weak_table.h:18
heap.h
dart
Definition
dart_vm.cc:33
globals.h
unit_test.h
ISOLATE_UNIT_TEST_CASE
#define ISOLATE_UNIT_TEST_CASE(name)
Definition
unit_test.h:64
globals.h
weak_table.h
Generated on Fri Apr 26 2024 06:15:08 for Flutter Engine by
1.9.8