Flutter Engine
The Flutter Engine
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
13namespace dart {
14
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
@ kNew
Definition: heap.h:38
@ kOld
Definition: heap.h:39
void ResetObjectIdTable()
Definition: heap.cc:899
intptr_t GetObjectId(ObjectPtr raw_obj) const
Definition: heap.h:197
void SetObjectId(ObjectPtr raw_obj, intptr_t object_id)
Definition: heap.h:193
ObjectPtr ptr() const
Definition: object.h:332
static Object & Handle()
Definition: object.h:407
static SmiPtr New(intptr_t value)
Definition: object.h:10006
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
Definition: object.cc:23698
static constexpr intptr_t kNoValue
Definition: weak_table.h:18
Definition: dart_vm.cc:33
ISOLATE_UNIT_TEST_CASE(StackAllocatedDestruction)