b1c09ecd8f
Currently we have things called XPtr which are not what you get from ptr().
Old world:
handle->raw() returns RawObject* (tagged)
raw_obj->ptr() returns RawObject* (untagged)
After 6fe15f6df9:
handle->raw() returns ObjectPtr
obj_ptr->ptr() returns ObjectLayout*
New world:
handle->ptr() returns ObjectPtr
obj_ptr->untag() returns UntaggedObject*
TEST=ci
Change-Id: I6c7f34014cf20737607caaf84979838300d12df2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/149367
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
63 lines
2.2 KiB
C++
63 lines
2.2 KiB
C++
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "platform/globals.h"
|
|
|
|
#include "platform/assert.h"
|
|
#include "vm/globals.h"
|
|
#include "vm/heap/heap.h"
|
|
#include "vm/heap/weak_table.h"
|
|
#include "vm/unit_test.h"
|
|
|
|
namespace dart {
|
|
|
|
ISOLATE_UNIT_TEST_CASE(WeakTables) {
|
|
const Object& old_obj = Object::Handle(String::New("old", Heap::kOld));
|
|
const Object& new_obj = Object::Handle(String::New("new", Heap::kNew));
|
|
const Object& imm_obj = Object::Handle(Smi::New(0));
|
|
|
|
// Initially absent.
|
|
Heap* heap = thread->heap();
|
|
const intptr_t kNoValue = WeakTable::kNoValue;
|
|
EXPECT_EQ(kNoValue, heap->GetObjectId(old_obj.ptr()));
|
|
EXPECT_EQ(kNoValue, heap->GetObjectId(new_obj.ptr()));
|
|
EXPECT_EQ(kNoValue, heap->GetObjectId(imm_obj.ptr()));
|
|
|
|
// Found after insert.
|
|
heap->SetObjectId(old_obj.ptr(), 100);
|
|
heap->SetObjectId(new_obj.ptr(), 200);
|
|
heap->SetObjectId(imm_obj.ptr(), 300);
|
|
EXPECT_EQ(100, heap->GetObjectId(old_obj.ptr()));
|
|
EXPECT_EQ(200, heap->GetObjectId(new_obj.ptr()));
|
|
EXPECT_EQ(300, heap->GetObjectId(imm_obj.ptr()));
|
|
|
|
// Found after update.
|
|
heap->SetObjectId(old_obj.ptr(), 400);
|
|
heap->SetObjectId(new_obj.ptr(), 500);
|
|
heap->SetObjectId(imm_obj.ptr(), 600);
|
|
EXPECT_EQ(400, heap->GetObjectId(old_obj.ptr()));
|
|
EXPECT_EQ(500, heap->GetObjectId(new_obj.ptr()));
|
|
EXPECT_EQ(600, heap->GetObjectId(imm_obj.ptr()));
|
|
|
|
// Found after GC.
|
|
GCTestHelper::CollectNewSpace();
|
|
EXPECT_EQ(400, heap->GetObjectId(old_obj.ptr()));
|
|
EXPECT_EQ(500, heap->GetObjectId(new_obj.ptr()));
|
|
EXPECT_EQ(600, heap->GetObjectId(imm_obj.ptr()));
|
|
|
|
// Found after GC.
|
|
GCTestHelper::CollectOldSpace();
|
|
EXPECT_EQ(400, heap->GetObjectId(old_obj.ptr()));
|
|
EXPECT_EQ(500, heap->GetObjectId(new_obj.ptr()));
|
|
EXPECT_EQ(600, heap->GetObjectId(imm_obj.ptr()));
|
|
|
|
// Absent after reset.
|
|
heap->ResetObjectIdTable();
|
|
EXPECT_EQ(kNoValue, heap->GetObjectId(old_obj.ptr()));
|
|
EXPECT_EQ(kNoValue, heap->GetObjectId(new_obj.ptr()));
|
|
EXPECT_EQ(kNoValue, heap->GetObjectId(imm_obj.ptr()));
|
|
}
|
|
|
|
} // namespace dart
|