• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_COMMON_PTR_COMPR_INL_H_
6 #define V8_COMMON_PTR_COMPR_INL_H_
7 
8 #include "include/v8-internal.h"
9 #include "src/common/ptr-compr.h"
10 #include "src/execution/isolate.h"
11 #include "src/execution/local-isolate-inl.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 #ifdef V8_COMPRESS_POINTERS
17 
IsolateRoot(const Isolate * isolate)18 IsolateRoot::IsolateRoot(const Isolate* isolate)
19     : address_(isolate->isolate_root()) {}
IsolateRoot(const LocalIsolate * isolate)20 IsolateRoot::IsolateRoot(const LocalIsolate* isolate)
21     : address_(isolate->isolate_root()) {}
22 
address()23 Address IsolateRoot::address() const {
24   Address ret = address_;
25   ret = reinterpret_cast<Address>(V8_ASSUME_ALIGNED(
26       reinterpret_cast<void*>(ret), kPtrComprIsolateRootAlignment));
27   return ret;
28 }
29 
30 // Compresses full-pointer representation of a tagged value to on-heap
31 // representation.
CompressTagged(Address tagged)32 V8_INLINE Tagged_t CompressTagged(Address tagged) {
33   return static_cast<Tagged_t>(static_cast<uint32_t>(tagged));
34 }
35 
GetIsolateRootAddress(Address on_heap_addr)36 V8_INLINE constexpr Address GetIsolateRootAddress(Address on_heap_addr) {
37   return RoundDown<kPtrComprIsolateRootAlignment>(on_heap_addr);
38 }
39 
GetIsolateRootAddress(IsolateRoot isolate)40 V8_INLINE Address GetIsolateRootAddress(IsolateRoot isolate) {
41   return isolate.address();
42 }
43 
44 // Decompresses smi value.
DecompressTaggedSigned(Tagged_t raw_value)45 V8_INLINE Address DecompressTaggedSigned(Tagged_t raw_value) {
46   // For runtime code the upper 32-bits of the Smi value do not matter.
47   return static_cast<Address>(raw_value);
48 }
49 
50 // Decompresses weak or strong heap object pointer or forwarding pointer,
51 // preserving both weak- and smi- tags.
52 template <typename TOnHeapAddress>
DecompressTaggedPointer(TOnHeapAddress on_heap_addr,Tagged_t raw_value)53 V8_INLINE Address DecompressTaggedPointer(TOnHeapAddress on_heap_addr,
54                                           Tagged_t raw_value) {
55   return GetIsolateRootAddress(on_heap_addr) + static_cast<Address>(raw_value);
56 }
57 
58 // Decompresses any tagged value, preserving both weak- and smi- tags.
59 template <typename TOnHeapAddress>
DecompressTaggedAny(TOnHeapAddress on_heap_addr,Tagged_t raw_value)60 V8_INLINE Address DecompressTaggedAny(TOnHeapAddress on_heap_addr,
61                                       Tagged_t raw_value) {
62   return DecompressTaggedPointer(on_heap_addr, raw_value);
63 }
64 
65 STATIC_ASSERT(kPtrComprHeapReservationSize ==
66               Internals::kPtrComprHeapReservationSize);
67 STATIC_ASSERT(kPtrComprIsolateRootAlignment ==
68               Internals::kPtrComprIsolateRootAlignment);
69 
70 #else
71 
72 V8_INLINE Tagged_t CompressTagged(Address tagged) { UNREACHABLE(); }
73 
74 V8_INLINE Address GetIsolateRootAddress(Address on_heap_addr) { UNREACHABLE(); }
75 
76 V8_INLINE Address GetIsolateRootAddress(IsolateRoot isolate) { UNREACHABLE(); }
77 
78 V8_INLINE Address DecompressTaggedSigned(Tagged_t raw_value) { UNREACHABLE(); }
79 
80 template <typename TOnHeapAddress>
81 V8_INLINE Address DecompressTaggedPointer(TOnHeapAddress on_heap_addr,
82                                           Tagged_t raw_value) {
83   UNREACHABLE();
84 }
85 
86 template <typename TOnHeapAddress>
87 V8_INLINE Address DecompressTaggedAny(TOnHeapAddress on_heap_addr,
88                                       Tagged_t raw_value) {
89   UNREACHABLE();
90 }
91 
92 #endif  // V8_COMPRESS_POINTERS
93 }  // namespace internal
94 }  // namespace v8
95 
96 #endif  // V8_COMMON_PTR_COMPR_INL_H_
97