• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 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_EXECUTION_ISOLATE_UTILS_INL_H_
6 #define V8_EXECUTION_ISOLATE_UTILS_INL_H_
7 
8 #include "src/common/ptr-compr-inl.h"
9 #include "src/execution/isolate-utils.h"
10 #include "src/execution/isolate.h"
11 #include "src/heap/heap-write-barrier-inl.h"
12 
13 namespace v8 {
14 namespace internal {
15 
GetIsolateForPtrComprFromOnHeapAddress(Address address)16 inline constexpr IsolateRoot GetIsolateForPtrComprFromOnHeapAddress(
17     Address address) {
18 #ifdef V8_COMPRESS_POINTERS
19   return IsolateRoot(GetIsolateRootAddress(address));
20 #else
21   return IsolateRoot();
22 #endif  // V8_COMPRESS_POINTERS
23 }
24 
GetIsolateForPtrCompr(HeapObject object)25 inline IsolateRoot GetIsolateForPtrCompr(HeapObject object) {
26   return GetIsolateForPtrComprFromOnHeapAddress(object.ptr());
27 }
28 
GetHeapFromWritableObject(HeapObject object)29 V8_INLINE Heap* GetHeapFromWritableObject(HeapObject object) {
30   // Avoid using the below GetIsolateFromWritableObject because we want to be
31   // able to get the heap, but not the isolate, for off-thread objects.
32 
33 #if defined V8_ENABLE_THIRD_PARTY_HEAP
34   return Heap::GetIsolateFromWritableObject(object)->heap();
35 #elif defined V8_COMPRESS_POINTERS
36   Isolate* isolate =
37       Isolate::FromRootAddress(GetIsolateRootAddress(object.ptr()));
38   DCHECK_NOT_NULL(isolate);
39   return isolate->heap();
40 #else
41   heap_internals::MemoryChunk* chunk =
42       heap_internals::MemoryChunk::FromHeapObject(object);
43   return chunk->GetHeap();
44 #endif  // V8_COMPRESS_POINTERS || V8_ENABLE_THIRD_PARTY_HEAP
45 }
46 
GetIsolateFromWritableObject(HeapObject object)47 V8_INLINE Isolate* GetIsolateFromWritableObject(HeapObject object) {
48 #ifdef V8_ENABLE_THIRD_PARTY_HEAP
49   return Heap::GetIsolateFromWritableObject(object);
50 #elif defined V8_COMPRESS_POINTERS
51   Isolate* isolate =
52       Isolate::FromRootAddress(GetIsolateRootAddress(object.ptr()));
53   DCHECK_NOT_NULL(isolate);
54   return isolate;
55 #else
56   return Isolate::FromHeap(GetHeapFromWritableObject(object));
57 #endif  // V8_COMPRESS_POINTERS, V8_ENABLE_THIRD_PARTY_HEAP
58 }
59 
GetIsolateFromHeapObject(HeapObject object,Isolate ** isolate)60 V8_INLINE bool GetIsolateFromHeapObject(HeapObject object, Isolate** isolate) {
61 #ifdef V8_ENABLE_THIRD_PARTY_HEAP
62   *isolate = Heap::GetIsolateFromWritableObject(object);
63   return true;
64 #elif defined V8_COMPRESS_POINTERS
65   *isolate = GetIsolateFromWritableObject(object);
66   return true;
67 #else
68   heap_internals::MemoryChunk* chunk =
69       heap_internals::MemoryChunk::FromHeapObject(object);
70   if (chunk->InReadOnlySpace()) {
71     *isolate = nullptr;
72     return false;
73   }
74   *isolate = Isolate::FromHeap(chunk->GetHeap());
75   return true;
76 #endif  // V8_COMPRESS_POINTERS, V8_ENABLE_THIRD_PARTY_HEAP
77 }
78 
79 }  // namespace internal
80 }  // namespace v8
81 
82 #endif  // V8_EXECUTION_ISOLATE_UTILS_INL_H_
83