Commit bfce6778 authored by ben's avatar ben Committed by Commit bot

Pretenure builtin typed arrays.

Typed arrays from the snapshot start out in the young space but they
all seem to end up in the old space sooner or later anyway.  Let's
expedite that by allocating them in the old space right away.

Review URL: https://codereview.chromium.org/1347263003

Cr-Commit-Position: refs/heads/master@{#30804}
parent 61fef768
......@@ -1730,18 +1730,21 @@ static Handle<JSObject> ResolveBuiltinIdHolder(Handle<Context> native_context,
template <typename Data>
Data* SetBuiltinTypedArray(Isolate* isolate, Handle<JSBuiltinsObject> builtins,
ExternalArrayType type, Data* data,
size_t num_elements, const char* name) {
size_t num_elements, const char* name,
const SharedFlag shared = SharedFlag::kNotShared,
const PretenureFlag pretenure = TENURED) {
size_t byte_length = num_elements * sizeof(*data);
Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer();
Handle<JSArrayBuffer> buffer =
isolate->factory()->NewJSArrayBuffer(shared, pretenure);
bool is_external = data != nullptr;
if (!is_external) {
data = reinterpret_cast<Data*>(
isolate->array_buffer_allocator()->Allocate(byte_length));
}
JSArrayBuffer::Setup(buffer, isolate, is_external, data, byte_length);
JSArrayBuffer::Setup(buffer, isolate, is_external, data, byte_length, shared);
Handle<JSTypedArray> typed_array =
isolate->factory()->NewJSTypedArray(type, buffer, 0, num_elements);
Handle<JSTypedArray> typed_array = isolate->factory()->NewJSTypedArray(
type, buffer, 0, num_elements, pretenure);
Handle<String> name_string = isolate->factory()->InternalizeUtf8String(name);
// Reset property cell type before (re)initializing.
JSBuiltinsObject::InvalidatePropertyCell(builtins, name_string);
......
......@@ -1626,15 +1626,15 @@ Handle<JSGeneratorObject> Factory::NewJSGeneratorObject(
}
Handle<JSArrayBuffer> Factory::NewJSArrayBuffer(SharedFlag shared) {
Handle<JSArrayBuffer> Factory::NewJSArrayBuffer(SharedFlag shared,
PretenureFlag pretenure) {
Handle<JSFunction> array_buffer_fun(
shared == SharedFlag::kShared
? isolate()->native_context()->shared_array_buffer_fun()
: isolate()->native_context()->array_buffer_fun());
CALL_HEAP_FUNCTION(
isolate(),
isolate()->heap()->AllocateJSObject(*array_buffer_fun),
JSArrayBuffer);
CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->AllocateJSObject(
*array_buffer_fun, pretenure),
JSArrayBuffer);
}
......@@ -1784,18 +1784,19 @@ JSFunction* GetTypedArrayFun(ElementsKind elements_kind, Isolate* isolate) {
void SetupArrayBufferView(i::Isolate* isolate,
i::Handle<i::JSArrayBufferView> obj,
i::Handle<i::JSArrayBuffer> buffer,
size_t byte_offset, size_t byte_length) {
size_t byte_offset, size_t byte_length,
PretenureFlag pretenure = NOT_TENURED) {
DCHECK(byte_offset + byte_length <=
static_cast<size_t>(buffer->byte_length()->Number()));
obj->set_buffer(*buffer);
i::Handle<i::Object> byte_offset_object =
isolate->factory()->NewNumberFromSize(byte_offset);
isolate->factory()->NewNumberFromSize(byte_offset, pretenure);
obj->set_byte_offset(*byte_offset_object);
i::Handle<i::Object> byte_length_object =
isolate->factory()->NewNumberFromSize(byte_length);
isolate->factory()->NewNumberFromSize(byte_length, pretenure);
obj->set_byte_length(*byte_length_object);
}
......@@ -1803,31 +1804,32 @@ void SetupArrayBufferView(i::Isolate* isolate,
} // namespace
Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) {
Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type,
PretenureFlag pretenure) {
Handle<JSFunction> typed_array_fun_handle(GetTypedArrayFun(type, isolate()));
CALL_HEAP_FUNCTION(
isolate(),
isolate()->heap()->AllocateJSObject(*typed_array_fun_handle),
JSTypedArray);
CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->AllocateJSObject(
*typed_array_fun_handle, pretenure),
JSTypedArray);
}
Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind) {
Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind,
PretenureFlag pretenure) {
Handle<JSFunction> typed_array_fun_handle(
GetTypedArrayFun(elements_kind, isolate()));
CALL_HEAP_FUNCTION(
isolate(), isolate()->heap()->AllocateJSObject(*typed_array_fun_handle),
JSTypedArray);
CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->AllocateJSObject(
*typed_array_fun_handle, pretenure),
JSTypedArray);
}
Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type,
Handle<JSArrayBuffer> buffer,
size_t byte_offset,
size_t length) {
Handle<JSTypedArray> obj = NewJSTypedArray(type);
size_t byte_offset, size_t length,
PretenureFlag pretenure) {
Handle<JSTypedArray> obj = NewJSTypedArray(type, pretenure);
size_t element_size = GetExternalArrayElementSize(type);
ElementsKind elements_kind = GetExternalArrayElementsKind(type);
......@@ -1837,14 +1839,15 @@ Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type,
CHECK(length <= (std::numeric_limits<size_t>::max() / element_size));
CHECK(length <= static_cast<size_t>(Smi::kMaxValue));
size_t byte_length = length * element_size;
SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length);
SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length,
pretenure);
Handle<Object> length_object = NewNumberFromSize(length);
Handle<Object> length_object = NewNumberFromSize(length, pretenure);
obj->set_length(*length_object);
Handle<FixedTypedArrayBase> elements = NewFixedTypedArrayWithExternalPointer(
static_cast<int>(length), type,
static_cast<uint8_t*>(buffer->backing_store()) + byte_offset);
static_cast<uint8_t*>(buffer->backing_store()) + byte_offset, pretenure);
Handle<Map> map = JSObject::GetElementsTransitionMap(obj, elements_kind);
JSObject::SetMapAndElements(obj, map, elements);
return obj;
......@@ -1852,8 +1855,9 @@ Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type,
Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind,
size_t number_of_elements) {
Handle<JSTypedArray> obj = NewJSTypedArray(elements_kind);
size_t number_of_elements,
PretenureFlag pretenure) {
Handle<JSTypedArray> obj = NewJSTypedArray(elements_kind, pretenure);
size_t element_size = GetFixedTypedArraysElementSize(elements_kind);
ExternalArrayType array_type = GetArrayTypeFromElementsKind(elements_kind);
......@@ -1865,18 +1869,19 @@ Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind,
obj->set_byte_offset(Smi::FromInt(0));
i::Handle<i::Object> byte_length_object =
isolate()->factory()->NewNumberFromSize(byte_length);
NewNumberFromSize(byte_length, pretenure);
obj->set_byte_length(*byte_length_object);
Handle<Object> length_object = NewNumberFromSize(number_of_elements);
Handle<Object> length_object =
NewNumberFromSize(number_of_elements, pretenure);
obj->set_length(*length_object);
Handle<JSArrayBuffer> buffer = isolate()->factory()->NewJSArrayBuffer();
Handle<JSArrayBuffer> buffer =
NewJSArrayBuffer(SharedFlag::kNotShared, pretenure);
JSArrayBuffer::Setup(buffer, isolate(), true, NULL, byte_length,
SharedFlag::kNotShared);
obj->set_buffer(*buffer);
Handle<FixedTypedArrayBase> elements =
isolate()->factory()->NewFixedTypedArray(
static_cast<int>(number_of_elements), array_type, true);
Handle<FixedTypedArrayBase> elements = NewFixedTypedArray(
static_cast<int>(number_of_elements), array_type, true, pretenure);
obj->set_elements(*elements);
return obj;
}
......
......@@ -449,20 +449,25 @@ class Factory final {
Handle<JSGeneratorObject> NewJSGeneratorObject(Handle<JSFunction> function);
Handle<JSArrayBuffer> NewJSArrayBuffer(
SharedFlag shared = SharedFlag::kNotShared);
SharedFlag shared = SharedFlag::kNotShared,
PretenureFlag pretenure = NOT_TENURED);
Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type);
Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type,
PretenureFlag pretenure = NOT_TENURED);
Handle<JSTypedArray> NewJSTypedArray(ElementsKind elements_kind);
Handle<JSTypedArray> NewJSTypedArray(ElementsKind elements_kind,
PretenureFlag pretenure = NOT_TENURED);
// Creates a new JSTypedArray with the specified buffer.
Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type,
Handle<JSArrayBuffer> buffer,
size_t byte_offset, size_t length);
size_t byte_offset, size_t length,
PretenureFlag pretenure = NOT_TENURED);
// Creates a new on-heap JSTypedArray.
Handle<JSTypedArray> NewJSTypedArray(ElementsKind elements_kind,
size_t number_of_elements);
size_t number_of_elements,
PretenureFlag pretenure = NOT_TENURED);
Handle<JSDataView> NewJSDataView();
Handle<JSDataView> NewJSDataView(Handle<JSArrayBuffer> buffer,
......
......@@ -467,6 +467,14 @@ RUNTIME_FUNCTION(Runtime_HaveSameMap) {
}
RUNTIME_FUNCTION(Runtime_InNewSpace) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 1);
CONVERT_ARG_CHECKED(Object, obj, 0);
return isolate->heap()->ToBoolean(isolate->heap()->InNewSpace(obj));
}
#define ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(Name) \
RUNTIME_FUNCTION(Runtime_Has##Name) { \
CONVERT_ARG_CHECKED(JSObject, obj, 0); \
......
......@@ -960,6 +960,7 @@ namespace internal {
F(TraceEnter, 0, 1) \
F(TraceExit, 1, 1) \
F(HaveSameMap, 2, 1) \
F(InNewSpace, 1, 1) \
F(HasFastSmiElements, 1, 1) \
F(HasFastObjectElements, 1, 1) \
F(HasFastSmiOrObjectElements, 1, 1) \
......
......@@ -25,7 +25,12 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-natives-as=builtins
// Flags: --allow-natives-syntax --expose-natives-as=builtins
// Verify that the builtin typed arrays have been pretenured.
assertFalse(%InNewSpace(builtins.kMath));
assertFalse(%InNewSpace(builtins.rempio2result));
assertFalse(%InNewSpace(builtins.rngstate));
// Checks that all function properties of the builtin object that are actually
// constructors (recognized by having properties on their .prototype object),
......
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