2019-06-24 09:49:45 +00:00
|
|
|
// Copyright 2019 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef V8_EXECUTION_ISOLATE_UTILS_INL_H_
|
|
|
|
#define V8_EXECUTION_ISOLATE_UTILS_INL_H_
|
|
|
|
|
|
|
|
#include "src/execution/isolate-utils.h"
|
|
|
|
|
|
|
|
#include "src/common/ptr-compr-inl.h"
|
|
|
|
#include "src/execution/isolate.h"
|
|
|
|
#include "src/heap/heap-write-barrier-inl.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2019-11-27 11:00:05 +00:00
|
|
|
inline const Isolate* GetIsolateForPtrCompr(HeapObject object) {
|
2019-06-24 10:57:35 +00:00
|
|
|
#ifdef V8_COMPRESS_POINTERS
|
|
|
|
return Isolate::FromRoot(GetIsolateRoot(object.ptr()));
|
|
|
|
#else
|
|
|
|
return nullptr;
|
|
|
|
#endif // V8_COMPRESS_POINTERS
|
|
|
|
}
|
|
|
|
|
2019-06-24 09:49:45 +00:00
|
|
|
V8_INLINE Heap* GetHeapFromWritableObject(HeapObject object) {
|
2020-02-10 09:23:49 +00:00
|
|
|
// Avoid using the below GetIsolateFromWritableObject because we want to be
|
|
|
|
// able to get the heap, but not the isolate, for off-thread objects.
|
|
|
|
|
|
|
|
#if defined V8_ENABLE_THIRD_PARTY_HEAP
|
2020-02-10 14:55:39 +00:00
|
|
|
return Heap::GetIsolateFromWritableObject(object)->heap();
|
2020-02-10 09:23:49 +00:00
|
|
|
#elif defined V8_COMPRESS_POINTERS
|
|
|
|
Isolate* isolate = Isolate::FromRoot(GetIsolateRoot(object.ptr()));
|
|
|
|
DCHECK_NOT_NULL(isolate);
|
|
|
|
return isolate->heap();
|
2019-06-24 09:49:45 +00:00
|
|
|
#else
|
|
|
|
heap_internals::MemoryChunk* chunk =
|
|
|
|
heap_internals::MemoryChunk::FromHeapObject(object);
|
|
|
|
return chunk->GetHeap();
|
2019-11-22 10:31:02 +00:00
|
|
|
#endif // V8_COMPRESS_POINTERS || V8_ENABLE_THIRD_PARTY_HEAP
|
2019-06-24 09:49:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
V8_INLINE Isolate* GetIsolateFromWritableObject(HeapObject object) {
|
2020-02-10 09:23:49 +00:00
|
|
|
// We don't want to allow accessing the isolate off-thread.
|
|
|
|
DCHECK(!Heap::InOffThreadSpace(object));
|
|
|
|
|
2019-11-22 10:31:02 +00:00
|
|
|
#ifdef V8_ENABLE_THIRD_PARTY_HEAP
|
|
|
|
return Heap::GetIsolateFromWritableObject(object);
|
|
|
|
#elif defined V8_COMPRESS_POINTERS
|
2019-06-24 09:49:45 +00:00
|
|
|
Isolate* isolate = Isolate::FromRoot(GetIsolateRoot(object.ptr()));
|
|
|
|
DCHECK_NOT_NULL(isolate);
|
|
|
|
return isolate;
|
|
|
|
#else
|
|
|
|
return Isolate::FromHeap(GetHeapFromWritableObject(object));
|
2019-11-22 10:31:02 +00:00
|
|
|
#endif // V8_COMPRESS_POINTERS, V8_ENABLE_THIRD_PARTY_HEAP
|
2019-06-24 09:49:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
V8_INLINE bool GetIsolateFromHeapObject(HeapObject object, Isolate** isolate) {
|
2019-11-22 10:31:02 +00:00
|
|
|
#ifdef V8_ENABLE_THIRD_PARTY_HEAP
|
|
|
|
*isolate = Heap::GetIsolateFromWritableObject(object);
|
|
|
|
return true;
|
|
|
|
#elif defined V8_COMPRESS_POINTERS
|
2019-06-24 09:49:45 +00:00
|
|
|
*isolate = GetIsolateFromWritableObject(object);
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
heap_internals::MemoryChunk* chunk =
|
|
|
|
heap_internals::MemoryChunk::FromHeapObject(object);
|
|
|
|
if (chunk->InReadOnlySpace()) {
|
|
|
|
*isolate = nullptr;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*isolate = Isolate::FromHeap(chunk->GetHeap());
|
|
|
|
return true;
|
2019-11-22 10:31:02 +00:00
|
|
|
#endif // V8_COMPRESS_POINTERS, V8_ENABLE_THIRD_PARTY_HEAP
|
2019-06-24 09:49:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
#endif // V8_EXECUTION_ISOLATE_UTILS_INL_H_
|