Commit 45b622d9 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[explicit isolates] Add Handle getters to ReadOnlyRoots

Add <root>_handle getters to ReadOnlyRoots, so an Isolate isn't required
to get a handle of a root.

Also convert one GetIsolate()->factory()->accessor() to
GetReadOnlyRoots().accessor_handle() in FixedArray.

Bug: v8:7786
Change-Id: I1b72c58f90eacf64be95abb65df91cf993178a93
Reviewed-on: https://chromium-review.googlesource.com/1129225
Commit-Queue: Dan Elphick <delphick@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54334}
parent 16aa6d04
......@@ -10250,7 +10250,7 @@ bool FixedArray::ContainsSortedNumbers() {
Handle<FixedArray> FixedArray::ShrinkOrEmpty(Handle<FixedArray> array,
int new_length) {
if (new_length == 0) {
return array->GetIsolate()->factory()->empty_fixed_array();
return array->GetReadOnlyRoots().empty_fixed_array_handle();
} else {
array->Shrink(new_length);
return array;
......
......@@ -16,45 +16,69 @@ namespace internal {
ReadOnlyRoots::ReadOnlyRoots(Isolate* isolate) : heap_(isolate->heap()) {}
#define ROOT_ACCESSOR(type, name, camel_name) \
type* ReadOnlyRoots::name() { \
return type::cast(heap_->roots_[Heap::k##camel_name##RootIndex]); \
#define ROOT_ACCESSOR(type, name, camel_name) \
type* ReadOnlyRoots::name() { \
return type::cast(heap_->roots_[Heap::k##camel_name##RootIndex]); \
} \
Handle<type> ReadOnlyRoots::name##_handle() { \
return Handle<type>( \
bit_cast<type**>(&heap_->roots_[Heap::k##camel_name##RootIndex])); \
}
STRONG_READ_ONLY_ROOT_LIST(ROOT_ACCESSOR)
#undef ROOT_ACCESSOR
#define STRING_ACCESSOR(name, str) \
String* ReadOnlyRoots::name() { \
return String::cast(heap_->roots_[Heap::k##name##RootIndex]); \
#define STRING_ACCESSOR(name, str) \
String* ReadOnlyRoots::name() { \
return String::cast(heap_->roots_[Heap::k##name##RootIndex]); \
} \
Handle<String> ReadOnlyRoots::name##_handle() { \
return Handle<String>( \
bit_cast<String**>(&heap_->roots_[Heap::k##name##RootIndex])); \
}
INTERNALIZED_STRING_LIST(STRING_ACCESSOR)
#undef STRING_ACCESSOR
#define SYMBOL_ACCESSOR(name) \
Symbol* ReadOnlyRoots::name() { \
return Symbol::cast(heap_->roots_[Heap::k##name##RootIndex]); \
#define SYMBOL_ACCESSOR(name) \
Symbol* ReadOnlyRoots::name() { \
return Symbol::cast(heap_->roots_[Heap::k##name##RootIndex]); \
} \
Handle<Symbol> ReadOnlyRoots::name##_handle() { \
return Handle<Symbol>( \
bit_cast<Symbol**>(&heap_->roots_[Heap::k##name##RootIndex])); \
}
PRIVATE_SYMBOL_LIST(SYMBOL_ACCESSOR)
#undef SYMBOL_ACCESSOR
#define SYMBOL_ACCESSOR(name, description) \
Symbol* ReadOnlyRoots::name() { \
return Symbol::cast(heap_->roots_[Heap::k##name##RootIndex]); \
#define SYMBOL_ACCESSOR(name, description) \
Symbol* ReadOnlyRoots::name() { \
return Symbol::cast(heap_->roots_[Heap::k##name##RootIndex]); \
} \
Handle<Symbol> ReadOnlyRoots::name##_handle() { \
return Handle<Symbol>( \
bit_cast<Symbol**>(&heap_->roots_[Heap::k##name##RootIndex])); \
}
PUBLIC_SYMBOL_LIST(SYMBOL_ACCESSOR)
WELL_KNOWN_SYMBOL_LIST(SYMBOL_ACCESSOR)
#undef SYMBOL_ACCESSOR
#define STRUCT_MAP_ACCESSOR(NAME, Name, name) \
Map* ReadOnlyRoots::name##_map() { \
return Map::cast(heap_->roots_[Heap::k##Name##MapRootIndex]); \
#define STRUCT_MAP_ACCESSOR(NAME, Name, name) \
Map* ReadOnlyRoots::name##_map() { \
return Map::cast(heap_->roots_[Heap::k##Name##MapRootIndex]); \
} \
Handle<Map> ReadOnlyRoots::name##_map_handle() { \
return Handle<Map>( \
bit_cast<Map**>(&heap_->roots_[Heap::k##Name##MapRootIndex])); \
}
STRUCT_LIST(STRUCT_MAP_ACCESSOR)
#undef STRUCT_MAP_ACCESSOR
#define ALLOCATION_SITE_MAP_ACCESSOR(NAME, Name, Size, name) \
Map* ReadOnlyRoots::name##_map() { \
return Map::cast(heap_->roots_[Heap::k##Name##Size##MapRootIndex]); \
#define ALLOCATION_SITE_MAP_ACCESSOR(NAME, Name, Size, name) \
Map* ReadOnlyRoots::name##_map() { \
return Map::cast(heap_->roots_[Heap::k##Name##Size##MapRootIndex]); \
} \
Handle<Map> ReadOnlyRoots::name##_map_handle() { \
return Handle<Map>( \
bit_cast<Map**>(&heap_->roots_[Heap::k##Name##Size##MapRootIndex])); \
}
ALLOCATION_SITE_LIST(ALLOCATION_SITE_MAP_ACCESSOR)
#undef ALLOCATION_SITE_MAP_ACCESSOR
......
......@@ -5,6 +5,7 @@
#ifndef V8_ROOTS_H_
#define V8_ROOTS_H_
#include "src/handles.h"
#include "src/heap-symbols.h"
#include "src/objects-definitions.h"
......@@ -289,6 +290,7 @@ namespace internal {
class Heap;
class Isolate;
class Map;
class String;
class Symbol;
......@@ -297,30 +299,41 @@ class ReadOnlyRoots {
explicit ReadOnlyRoots(Heap* heap) : heap_(heap) {}
inline explicit ReadOnlyRoots(Isolate* isolate);
#define ROOT_ACCESSOR(type, name, camel_name) inline class type* name();
#define ROOT_ACCESSOR(type, name, camel_name) \
inline class type* name(); \
inline Handle<type> name##_handle();
STRONG_READ_ONLY_ROOT_LIST(ROOT_ACCESSOR)
#undef ROOT_ACCESSOR
#define STRING_ACCESSOR(name, str) inline String* name();
#define STRING_ACCESSOR(name, str) \
inline String* name(); \
inline Handle<String> name##_handle();
INTERNALIZED_STRING_LIST(STRING_ACCESSOR)
#undef STRING_ACCESSOR
#define SYMBOL_ACCESSOR(name) inline Symbol* name();
#define SYMBOL_ACCESSOR(name) \
inline Symbol* name(); \
inline Handle<Symbol> name##_handle();
PRIVATE_SYMBOL_LIST(SYMBOL_ACCESSOR)
#undef SYMBOL_ACCESSOR
#define SYMBOL_ACCESSOR(name, description) inline Symbol* name();
#define SYMBOL_ACCESSOR(name, description) \
inline Symbol* name(); \
inline Handle<Symbol> name##_handle();
PUBLIC_SYMBOL_LIST(SYMBOL_ACCESSOR)
WELL_KNOWN_SYMBOL_LIST(SYMBOL_ACCESSOR)
#undef SYMBOL_ACCESSOR
// Utility type maps.
#define STRUCT_MAP_ACCESSOR(NAME, Name, name) inline Map* name##_map();
#define STRUCT_MAP_ACCESSOR(NAME, Name, name) \
inline Map* name##_map(); \
inline class Handle<Map> name##_map_handle();
STRUCT_LIST(STRUCT_MAP_ACCESSOR)
#undef STRUCT_MAP_ACCESSOR
#define ALLOCATION_SITE_MAP_ACCESSOR(NAME, Name, Size, name) \
inline Map* name##_map();
inline Map* name##_map(); \
inline class Handle<Map> name##_map_handle();
ALLOCATION_SITE_LIST(ALLOCATION_SITE_MAP_ACCESSOR)
#undef ALLOCATION_SITE_MAP_ACCESSOR
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment