Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
pointer_tagging.h
Go to the documentation of this file.
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#ifndef RUNTIME_VM_POINTER_TAGGING_H_
6#define RUNTIME_VM_POINTER_TAGGING_H_
7
8#include "platform/assert.h"
9#include "platform/globals.h"
10
11// This header defines constants associated with pointer tagging:
12//
13// * which bits determine whether or not this is a Smi value or a heap
14// pointer;
15// * which bits determine whether this is a pointer into a new or an old
16// space.
17
18namespace dart {
19
20// Dart VM aligns all objects by 2 words in in the old space and misaligns them
21// in new space. This allows to distinguish new and old pointers by their bits.
22//
23// Note: these bits depend on the word size.
24template <intptr_t word_size, intptr_t word_size_log2>
26 // Alignment offsets are used to determine object age.
27 static constexpr intptr_t kNewObjectAlignmentOffset = word_size;
28 static constexpr intptr_t kOldObjectAlignmentOffset = 0;
29 static constexpr intptr_t kNewObjectBitPosition = word_size_log2;
30
31 // Object sizes are aligned to kObjectAlignment.
32 static constexpr intptr_t kObjectAlignment = 2 * word_size;
33 static constexpr intptr_t kObjectAlignmentLog2 = word_size_log2 + 1;
34 static constexpr intptr_t kObjectAlignmentMask = kObjectAlignment - 1;
35
36 // Discriminate between true and false based on the alignment bit.
37 static constexpr intptr_t kBoolValueBitPosition = kObjectAlignmentLog2;
38 static constexpr intptr_t kBoolValueMask = 1 << kBoolValueBitPosition;
39
40 // Discriminate between bool and null based on bit after the alignment bit.
41 static constexpr intptr_t kBoolVsNullBitPosition = kObjectAlignmentLog2 + 1;
42 static constexpr intptr_t kBoolVsNullMask = 1 << kBoolVsNullBitPosition;
43
44 static constexpr intptr_t kTrueOffsetFromNull = kObjectAlignment * 2;
45 static constexpr intptr_t kFalseOffsetFromNull = kObjectAlignment * 3;
46};
47
49
50static constexpr intptr_t kNewObjectAlignmentOffset =
52static constexpr intptr_t kOldObjectAlignmentOffset =
54static constexpr intptr_t kNewObjectBitPosition =
56static constexpr intptr_t kObjectAlignment =
58static constexpr intptr_t kObjectAlignmentLog2 =
60static constexpr intptr_t kObjectAlignmentMask =
62static constexpr intptr_t kBoolValueBitPosition =
65static constexpr intptr_t kBoolVsNullBitPosition =
67static constexpr intptr_t kBoolVsNullMask =
69static constexpr intptr_t kTrueOffsetFromNull =
71static constexpr intptr_t kFalseOffsetFromNull =
73
74static constexpr intptr_t kObjectStartAlignment = 64;
78
79// On all targets heap pointers are tagged by set least significant bit.
80//
81// To recover address of the actual heap object kHeapObjectTag needs to be
82// subtracted from the tagged pointer value.
83//
84// Smi-s (small integers) have least significant bit cleared.
85//
86// To recover the integer value tagged pointer value needs to be shifted
87// right by kSmiTagShift.
88enum {
94};
95
96#if !defined(DART_COMPRESSED_POINTERS)
97static constexpr uintptr_t kHeapBaseMask = 0;
98#else
99static constexpr uintptr_t kHeapBaseMask = ~(4LL * GB - 1);
100#endif
101
102} // namespace dart
103
104#endif // RUNTIME_VM_POINTER_TAGGING_H_
#define COMPILE_ASSERT(expr)
Definition assert.h:339
static constexpr uintptr_t kHeapBaseMask
static constexpr intptr_t kOldObjectAlignmentOffset
static constexpr intptr_t kObjectStartAlignment
static constexpr intptr_t kNewObjectAlignmentOffset
static constexpr intptr_t kBoolValueMask
static constexpr intptr_t kFalseOffsetFromNull
static constexpr intptr_t kBoolVsNullBitPosition
static constexpr intptr_t kBoolVsNullMask
static constexpr intptr_t kNewObjectBitPosition
static constexpr intptr_t kTrueOffsetFromNull
@ kHeapObjectTag
static constexpr intptr_t kBoolValueBitPosition
constexpr intptr_t GB
Definition globals.h:532
static constexpr intptr_t kObjectAlignmentMask
static constexpr intptr_t kObjectAlignment
static constexpr intptr_t kObjectAlignmentLog2
static constexpr intptr_t kNewObjectAlignmentOffset
static constexpr intptr_t kBoolVsNullBitPosition
static constexpr intptr_t kNewObjectBitPosition
static constexpr intptr_t kBoolValueBitPosition
static constexpr intptr_t kObjectAlignmentLog2
static constexpr intptr_t kFalseOffsetFromNull
static constexpr intptr_t kObjectAlignment
static constexpr intptr_t kObjectAlignmentMask
static constexpr intptr_t kBoolVsNullMask
static constexpr intptr_t kBoolValueMask
static constexpr intptr_t kOldObjectAlignmentOffset
static constexpr intptr_t kTrueOffsetFromNull