2016-01-05 19:08:11 +00:00
|
|
|
// Copyright 2014 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.
|
|
|
|
|
2019-05-24 13:51:59 +00:00
|
|
|
#include "src/init/v8.h"
|
2016-01-05 19:08:11 +00:00
|
|
|
|
2017-02-10 17:22:45 +00:00
|
|
|
#include "src/ast/ast-value-factory.h"
|
2019-05-22 07:55:37 +00:00
|
|
|
#include "src/execution/isolate.h"
|
2019-05-22 12:44:24 +00:00
|
|
|
#include "src/handles/handles-inl.h"
|
2018-04-09 19:11:22 +00:00
|
|
|
#include "src/heap/factory.h"
|
2016-01-05 19:08:11 +00:00
|
|
|
#include "src/interpreter/constant-array-builder.h"
|
2019-05-24 13:51:59 +00:00
|
|
|
#include "src/numbers/hash-seed-inl.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
2016-01-05 19:08:11 +00:00
|
|
|
#include "test/unittests/test-utils.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace interpreter {
|
|
|
|
|
|
|
|
class ConstantArrayBuilderTest : public TestWithIsolateAndZone {
|
|
|
|
public:
|
2018-09-13 09:22:50 +00:00
|
|
|
ConstantArrayBuilderTest() = default;
|
|
|
|
~ConstantArrayBuilderTest() override = default;
|
2016-01-05 19:08:11 +00:00
|
|
|
|
2016-02-26 10:14:49 +00:00
|
|
|
static const size_t k8BitCapacity = ConstantArrayBuilder::k8BitCapacity;
|
|
|
|
static const size_t k16BitCapacity = ConstantArrayBuilder::k16BitCapacity;
|
2016-01-05 19:08:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
STATIC_CONST_MEMBER_DEFINITION const size_t
|
2016-02-26 10:14:49 +00:00
|
|
|
ConstantArrayBuilderTest::k16BitCapacity;
|
2016-01-05 19:08:11 +00:00
|
|
|
STATIC_CONST_MEMBER_DEFINITION const size_t
|
2016-02-26 10:14:49 +00:00
|
|
|
ConstantArrayBuilderTest::k8BitCapacity;
|
2016-01-05 19:08:11 +00:00
|
|
|
|
|
|
|
TEST_F(ConstantArrayBuilderTest, AllocateAllEntries) {
|
2016-08-05 10:09:50 +00:00
|
|
|
CanonicalHandleScope canonical(isolate());
|
2017-02-10 17:22:45 +00:00
|
|
|
ConstantArrayBuilder builder(zone());
|
|
|
|
AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(),
|
2019-02-14 21:10:30 +00:00
|
|
|
HashSeed(isolate()));
|
2016-02-26 10:14:49 +00:00
|
|
|
for (size_t i = 0; i < k16BitCapacity; i++) {
|
2017-10-27 19:53:15 +00:00
|
|
|
builder.Insert(i + 0.5);
|
2016-01-05 19:08:11 +00:00
|
|
|
}
|
2016-02-26 10:14:49 +00:00
|
|
|
CHECK_EQ(builder.size(), k16BitCapacity);
|
[offthread] Add an OffThreadIsolate
The Factory/OffThreadFactory allows us to cleanly separate object
construction behaviour between main-thread and off-thread in a
syntactically consistent way (so that methods templated on the factory
type can be made to work on both).
However, there are cases where we also have to access the Isolate, for
handle creation or exception throwing. So far we have been pushing more
and more "customization points" into the factories to allow these
factory-templated methods to dispatch on this isolate behaviour via
these factory methods. Unfortunately, this is an increasing layering
violation between Factory and Isolate, particularly around exception
handling.
Now, we introduce an OffThreadIsolate, analogous to Isolate in the same
way as OffThreadFactory is analogous to Factory. All methods which were
templated on Factory are now templated on Isolate, and methods which
used to take an Isolate, and which were recently changed to take a
templated Factory, are changed/reverted to take a templated Isolate.
OffThreadFactory gets an isolate() method to match Factory's.
Notably, FactoryHandle is changed to "HandleFor", where the template
argument can be either of the Isolate type or the Factory type (allowing
us to dispatch on both depending on what is available).
Bug: chromium:1011762
Change-Id: Id144176f7da534dd76f3d535ab2ade008b6845e3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2030909
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66101}
2020-02-04 10:50:53 +00:00
|
|
|
ast_factory.Internalize(isolate());
|
2016-02-26 10:14:49 +00:00
|
|
|
for (size_t i = 0; i < k16BitCapacity; i++) {
|
2017-02-10 17:22:45 +00:00
|
|
|
CHECK_EQ(
|
|
|
|
Handle<HeapNumber>::cast(builder.At(i, isolate()).ToHandleChecked())
|
|
|
|
->value(),
|
|
|
|
i + 0.5);
|
2016-01-05 19:08:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-10 16:41:43 +00:00
|
|
|
TEST_F(ConstantArrayBuilderTest, ToFixedArray) {
|
|
|
|
CanonicalHandleScope canonical(isolate());
|
2017-02-10 17:22:45 +00:00
|
|
|
ConstantArrayBuilder builder(zone());
|
2017-10-27 19:53:15 +00:00
|
|
|
static const int kNumberOfElements = 37;
|
|
|
|
for (int i = 0; i < kNumberOfElements; i++) {
|
|
|
|
builder.Insert(i + 0.5);
|
2016-08-10 16:41:43 +00:00
|
|
|
}
|
2016-08-18 13:42:05 +00:00
|
|
|
Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
|
2017-10-27 19:53:15 +00:00
|
|
|
ASSERT_EQ(kNumberOfElements, constant_array->length());
|
|
|
|
for (int i = 0; i < kNumberOfElements; i++) {
|
|
|
|
Handle<Object> actual(constant_array->get(i), isolate());
|
|
|
|
Handle<Object> expected = builder.At(i, isolate()).ToHandleChecked();
|
|
|
|
ASSERT_EQ(expected->Number(), actual->Number()) << "Failure at index " << i;
|
2016-08-10 16:41:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ConstantArrayBuilderTest, ToLargeFixedArray) {
|
|
|
|
CanonicalHandleScope canonical(isolate());
|
2017-02-10 17:22:45 +00:00
|
|
|
ConstantArrayBuilder builder(zone());
|
2017-10-27 19:53:15 +00:00
|
|
|
static const int kNumberOfElements = 37373;
|
|
|
|
for (int i = 0; i < kNumberOfElements; i++) {
|
|
|
|
builder.Insert(i + 0.5);
|
2016-08-10 16:41:43 +00:00
|
|
|
}
|
2016-08-18 13:42:05 +00:00
|
|
|
Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
|
2017-10-27 19:53:15 +00:00
|
|
|
ASSERT_EQ(kNumberOfElements, constant_array->length());
|
|
|
|
for (int i = 0; i < kNumberOfElements; i++) {
|
|
|
|
Handle<Object> actual(constant_array->get(i), isolate());
|
|
|
|
Handle<Object> expected = builder.At(i, isolate()).ToHandleChecked();
|
|
|
|
ASSERT_EQ(expected->Number(), actual->Number()) << "Failure at index " << i;
|
2016-08-10 16:41:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ConstantArrayBuilderTest, ToLargeFixedArrayWithReservations) {
|
|
|
|
CanonicalHandleScope canonical(isolate());
|
2017-02-10 17:22:45 +00:00
|
|
|
ConstantArrayBuilder builder(zone());
|
|
|
|
AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(),
|
2019-02-14 21:10:30 +00:00
|
|
|
HashSeed(isolate()));
|
2017-10-27 19:53:15 +00:00
|
|
|
static const int kNumberOfElements = 37373;
|
|
|
|
for (int i = 0; i < kNumberOfElements; i++) {
|
|
|
|
builder.CommitReservedEntry(builder.CreateReservedEntry(), Smi::FromInt(i));
|
2016-08-10 16:41:43 +00:00
|
|
|
}
|
[offthread] Add an OffThreadIsolate
The Factory/OffThreadFactory allows us to cleanly separate object
construction behaviour between main-thread and off-thread in a
syntactically consistent way (so that methods templated on the factory
type can be made to work on both).
However, there are cases where we also have to access the Isolate, for
handle creation or exception throwing. So far we have been pushing more
and more "customization points" into the factories to allow these
factory-templated methods to dispatch on this isolate behaviour via
these factory methods. Unfortunately, this is an increasing layering
violation between Factory and Isolate, particularly around exception
handling.
Now, we introduce an OffThreadIsolate, analogous to Isolate in the same
way as OffThreadFactory is analogous to Factory. All methods which were
templated on Factory are now templated on Isolate, and methods which
used to take an Isolate, and which were recently changed to take a
templated Factory, are changed/reverted to take a templated Isolate.
OffThreadFactory gets an isolate() method to match Factory's.
Notably, FactoryHandle is changed to "HandleFor", where the template
argument can be either of the Isolate type or the Factory type (allowing
us to dispatch on both depending on what is available).
Bug: chromium:1011762
Change-Id: Id144176f7da534dd76f3d535ab2ade008b6845e3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2030909
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66101}
2020-02-04 10:50:53 +00:00
|
|
|
ast_factory.Internalize(isolate());
|
2016-08-18 13:42:05 +00:00
|
|
|
Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
|
2017-10-27 19:53:15 +00:00
|
|
|
ASSERT_EQ(kNumberOfElements, constant_array->length());
|
|
|
|
for (int i = 0; i < kNumberOfElements; i++) {
|
|
|
|
Handle<Object> actual(constant_array->get(i), isolate());
|
|
|
|
Handle<Object> expected = builder.At(i, isolate()).ToHandleChecked();
|
|
|
|
ASSERT_EQ(expected->Number(), actual->Number()) << "Failure at index " << i;
|
2016-08-10 16:41:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-05 19:08:11 +00:00
|
|
|
TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithIdx8Reservations) {
|
2016-08-05 10:09:50 +00:00
|
|
|
CanonicalHandleScope canonical(isolate());
|
2016-02-26 10:14:49 +00:00
|
|
|
for (size_t reserved = 1; reserved < k8BitCapacity; reserved *= 3) {
|
2017-02-10 17:22:45 +00:00
|
|
|
ConstantArrayBuilder builder(zone());
|
|
|
|
AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(),
|
2019-02-14 21:10:30 +00:00
|
|
|
HashSeed(isolate()));
|
2016-01-05 19:08:11 +00:00
|
|
|
for (size_t i = 0; i < reserved; i++) {
|
|
|
|
OperandSize operand_size = builder.CreateReservedEntry();
|
2017-10-18 09:06:55 +00:00
|
|
|
CHECK_EQ(operand_size, OperandSize::kByte);
|
2016-01-05 19:08:11 +00:00
|
|
|
}
|
2016-02-26 10:14:49 +00:00
|
|
|
for (size_t i = 0; i < 2 * k8BitCapacity; i++) {
|
2016-08-10 16:41:43 +00:00
|
|
|
builder.CommitReservedEntry(builder.CreateReservedEntry(),
|
|
|
|
Smi::FromInt(static_cast<int>(i)));
|
2016-02-26 10:14:49 +00:00
|
|
|
if (i + reserved < k8BitCapacity) {
|
|
|
|
CHECK_LE(builder.size(), k8BitCapacity);
|
2016-01-05 19:08:11 +00:00
|
|
|
CHECK_EQ(builder.size(), i + 1);
|
|
|
|
} else {
|
2016-02-26 10:14:49 +00:00
|
|
|
CHECK_GE(builder.size(), k8BitCapacity);
|
2016-01-05 19:08:11 +00:00
|
|
|
CHECK_EQ(builder.size(), i + reserved + 1);
|
|
|
|
}
|
|
|
|
}
|
2016-02-26 10:14:49 +00:00
|
|
|
CHECK_EQ(builder.size(), 2 * k8BitCapacity + reserved);
|
2016-01-05 19:08:11 +00:00
|
|
|
|
2016-08-10 16:41:43 +00:00
|
|
|
// Commit reserved entries with duplicates and check size does not change.
|
2016-02-26 10:14:49 +00:00
|
|
|
DCHECK_EQ(reserved + 2 * k8BitCapacity, builder.size());
|
2016-01-05 19:08:11 +00:00
|
|
|
size_t duplicates_in_idx8_space =
|
2016-02-26 10:14:49 +00:00
|
|
|
std::min(reserved, k8BitCapacity - reserved);
|
2016-01-05 19:08:11 +00:00
|
|
|
for (size_t i = 0; i < duplicates_in_idx8_space; i++) {
|
|
|
|
builder.CommitReservedEntry(OperandSize::kByte,
|
2016-08-10 16:41:43 +00:00
|
|
|
Smi::FromInt(static_cast<int>(i)));
|
2016-02-26 10:14:49 +00:00
|
|
|
DCHECK_EQ(reserved + 2 * k8BitCapacity, builder.size());
|
2016-01-05 19:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now make reservations, and commit them with unique entries.
|
|
|
|
for (size_t i = 0; i < duplicates_in_idx8_space; i++) {
|
|
|
|
OperandSize operand_size = builder.CreateReservedEntry();
|
2017-10-18 09:06:55 +00:00
|
|
|
CHECK_EQ(operand_size, OperandSize::kByte);
|
2016-01-05 19:08:11 +00:00
|
|
|
}
|
|
|
|
for (size_t i = 0; i < duplicates_in_idx8_space; i++) {
|
2018-11-03 00:13:22 +00:00
|
|
|
Smi value = Smi::FromInt(static_cast<int>(2 * k8BitCapacity + i));
|
2016-08-10 16:41:43 +00:00
|
|
|
size_t index = builder.CommitReservedEntry(OperandSize::kByte, value);
|
2016-11-10 11:25:17 +00:00
|
|
|
CHECK_EQ(index, k8BitCapacity - reserved + i);
|
2016-01-05 19:08:11 +00:00
|
|
|
}
|
2016-08-10 16:41:43 +00:00
|
|
|
|
2017-02-10 17:22:45 +00:00
|
|
|
// Clear any remaining uncommited reservations.
|
|
|
|
for (size_t i = 0; i < reserved - duplicates_in_idx8_space; i++) {
|
|
|
|
builder.DiscardReservedEntry(OperandSize::kByte);
|
|
|
|
}
|
|
|
|
|
[offthread] Add an OffThreadIsolate
The Factory/OffThreadFactory allows us to cleanly separate object
construction behaviour between main-thread and off-thread in a
syntactically consistent way (so that methods templated on the factory
type can be made to work on both).
However, there are cases where we also have to access the Isolate, for
handle creation or exception throwing. So far we have been pushing more
and more "customization points" into the factories to allow these
factory-templated methods to dispatch on this isolate behaviour via
these factory methods. Unfortunately, this is an increasing layering
violation between Factory and Isolate, particularly around exception
handling.
Now, we introduce an OffThreadIsolate, analogous to Isolate in the same
way as OffThreadFactory is analogous to Factory. All methods which were
templated on Factory are now templated on Isolate, and methods which
used to take an Isolate, and which were recently changed to take a
templated Factory, are changed/reverted to take a templated Isolate.
OffThreadFactory gets an isolate() method to match Factory's.
Notably, FactoryHandle is changed to "HandleFor", where the template
argument can be either of the Isolate type or the Factory type (allowing
us to dispatch on both depending on what is available).
Bug: chromium:1011762
Change-Id: Id144176f7da534dd76f3d535ab2ade008b6845e3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2030909
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66101}
2020-02-04 10:50:53 +00:00
|
|
|
ast_factory.Internalize(isolate());
|
2016-08-18 13:42:05 +00:00
|
|
|
Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
|
2016-11-10 11:25:17 +00:00
|
|
|
CHECK_EQ(constant_array->length(),
|
|
|
|
static_cast<int>(2 * k8BitCapacity + reserved));
|
2016-08-10 16:41:43 +00:00
|
|
|
|
|
|
|
// Check all committed values match expected
|
|
|
|
for (size_t i = 0; i < k8BitCapacity - reserved; i++) {
|
2018-12-25 00:19:47 +00:00
|
|
|
Object value = constant_array->get(static_cast<int>(i));
|
2018-11-03 00:13:22 +00:00
|
|
|
Smi smi = Smi::FromInt(static_cast<int>(i));
|
2016-08-10 16:41:43 +00:00
|
|
|
CHECK(value.SameValue(smi));
|
|
|
|
}
|
|
|
|
for (size_t i = k8BitCapacity; i < 2 * k8BitCapacity + reserved; i++) {
|
2018-12-25 00:19:47 +00:00
|
|
|
Object value = constant_array->get(static_cast<int>(i));
|
2018-11-03 00:13:22 +00:00
|
|
|
Smi smi = Smi::FromInt(static_cast<int>(i - reserved));
|
2016-08-10 16:41:43 +00:00
|
|
|
CHECK(value.SameValue(smi));
|
|
|
|
}
|
2016-01-05 19:08:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-21 17:08:21 +00:00
|
|
|
TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithWideReservations) {
|
2016-08-05 10:09:50 +00:00
|
|
|
CanonicalHandleScope canonical(isolate());
|
2016-02-26 10:14:49 +00:00
|
|
|
for (size_t reserved = 1; reserved < k8BitCapacity; reserved *= 3) {
|
2017-02-10 17:22:45 +00:00
|
|
|
ConstantArrayBuilder builder(zone());
|
|
|
|
AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(),
|
2019-02-14 21:10:30 +00:00
|
|
|
HashSeed(isolate()));
|
2016-02-26 10:14:49 +00:00
|
|
|
for (size_t i = 0; i < k8BitCapacity; i++) {
|
2016-08-10 16:41:43 +00:00
|
|
|
builder.CommitReservedEntry(builder.CreateReservedEntry(),
|
|
|
|
Smi::FromInt(static_cast<int>(i)));
|
2016-01-05 19:08:11 +00:00
|
|
|
CHECK_EQ(builder.size(), i + 1);
|
|
|
|
}
|
|
|
|
for (size_t i = 0; i < reserved; i++) {
|
|
|
|
OperandSize operand_size = builder.CreateReservedEntry();
|
2017-10-18 09:06:55 +00:00
|
|
|
CHECK_EQ(operand_size, OperandSize::kShort);
|
2016-02-26 10:14:49 +00:00
|
|
|
CHECK_EQ(builder.size(), k8BitCapacity);
|
2016-01-05 19:08:11 +00:00
|
|
|
}
|
|
|
|
for (size_t i = 0; i < reserved; i++) {
|
|
|
|
builder.DiscardReservedEntry(OperandSize::kShort);
|
2016-02-26 10:14:49 +00:00
|
|
|
CHECK_EQ(builder.size(), k8BitCapacity);
|
2016-01-05 19:08:11 +00:00
|
|
|
}
|
|
|
|
for (size_t i = 0; i < reserved; i++) {
|
|
|
|
OperandSize operand_size = builder.CreateReservedEntry();
|
2017-10-18 09:06:55 +00:00
|
|
|
CHECK_EQ(operand_size, OperandSize::kShort);
|
2016-08-10 16:41:43 +00:00
|
|
|
builder.CommitReservedEntry(operand_size,
|
|
|
|
Smi::FromInt(static_cast<int>(i)));
|
2016-02-26 10:14:49 +00:00
|
|
|
CHECK_EQ(builder.size(), k8BitCapacity);
|
2016-01-05 19:08:11 +00:00
|
|
|
}
|
2016-02-26 10:14:49 +00:00
|
|
|
for (size_t i = k8BitCapacity; i < k8BitCapacity + reserved; i++) {
|
2016-01-05 19:08:11 +00:00
|
|
|
OperandSize operand_size = builder.CreateReservedEntry();
|
2017-10-18 09:06:55 +00:00
|
|
|
CHECK_EQ(operand_size, OperandSize::kShort);
|
2016-08-10 16:41:43 +00:00
|
|
|
builder.CommitReservedEntry(operand_size,
|
|
|
|
Smi::FromInt(static_cast<int>(i)));
|
2016-01-05 19:08:11 +00:00
|
|
|
CHECK_EQ(builder.size(), i + 1);
|
|
|
|
}
|
|
|
|
|
[offthread] Add an OffThreadIsolate
The Factory/OffThreadFactory allows us to cleanly separate object
construction behaviour between main-thread and off-thread in a
syntactically consistent way (so that methods templated on the factory
type can be made to work on both).
However, there are cases where we also have to access the Isolate, for
handle creation or exception throwing. So far we have been pushing more
and more "customization points" into the factories to allow these
factory-templated methods to dispatch on this isolate behaviour via
these factory methods. Unfortunately, this is an increasing layering
violation between Factory and Isolate, particularly around exception
handling.
Now, we introduce an OffThreadIsolate, analogous to Isolate in the same
way as OffThreadFactory is analogous to Factory. All methods which were
templated on Factory are now templated on Isolate, and methods which
used to take an Isolate, and which were recently changed to take a
templated Factory, are changed/reverted to take a templated Isolate.
OffThreadFactory gets an isolate() method to match Factory's.
Notably, FactoryHandle is changed to "HandleFor", where the template
argument can be either of the Isolate type or the Factory type (allowing
us to dispatch on both depending on what is available).
Bug: chromium:1011762
Change-Id: Id144176f7da534dd76f3d535ab2ade008b6845e3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2030909
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66101}
2020-02-04 10:50:53 +00:00
|
|
|
ast_factory.Internalize(isolate());
|
2016-08-18 13:42:05 +00:00
|
|
|
Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
|
2016-11-10 11:25:17 +00:00
|
|
|
CHECK_EQ(constant_array->length(),
|
|
|
|
static_cast<int>(k8BitCapacity + reserved));
|
2016-08-10 16:41:43 +00:00
|
|
|
for (size_t i = 0; i < k8BitCapacity + reserved; i++) {
|
2018-12-25 00:19:47 +00:00
|
|
|
Object value = constant_array->get(static_cast<int>(i));
|
2016-08-10 16:41:43 +00:00
|
|
|
CHECK(value.SameValue(*isolate()->factory()->NewNumberFromSize(i)));
|
|
|
|
}
|
2016-03-21 17:08:21 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-05 19:08:11 +00:00
|
|
|
|
|
|
|
TEST_F(ConstantArrayBuilderTest, GapFilledWhenLowReservationCommitted) {
|
2016-08-05 10:09:50 +00:00
|
|
|
CanonicalHandleScope canonical(isolate());
|
2017-02-10 17:22:45 +00:00
|
|
|
ConstantArrayBuilder builder(zone());
|
|
|
|
AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(),
|
2019-02-14 21:10:30 +00:00
|
|
|
HashSeed(isolate()));
|
2016-02-26 10:14:49 +00:00
|
|
|
for (size_t i = 0; i < k8BitCapacity; i++) {
|
2016-01-05 19:08:11 +00:00
|
|
|
OperandSize operand_size = builder.CreateReservedEntry();
|
2017-10-18 09:06:55 +00:00
|
|
|
CHECK_EQ(OperandSize::kByte, operand_size);
|
2016-11-14 10:48:26 +00:00
|
|
|
CHECK_EQ(builder.size(), 0u);
|
2016-01-05 19:08:11 +00:00
|
|
|
}
|
2016-02-26 10:14:49 +00:00
|
|
|
for (size_t i = 0; i < k8BitCapacity; i++) {
|
2016-08-10 16:41:43 +00:00
|
|
|
builder.CommitReservedEntry(builder.CreateReservedEntry(),
|
|
|
|
Smi::FromInt(static_cast<int>(i)));
|
2016-02-26 10:14:49 +00:00
|
|
|
CHECK_EQ(builder.size(), i + k8BitCapacity + 1);
|
2016-01-05 19:08:11 +00:00
|
|
|
}
|
2016-02-26 10:14:49 +00:00
|
|
|
for (size_t i = 0; i < k8BitCapacity; i++) {
|
2016-01-05 19:08:11 +00:00
|
|
|
builder.CommitReservedEntry(OperandSize::kByte,
|
2016-08-10 16:41:43 +00:00
|
|
|
Smi::FromInt(static_cast<int>(i)));
|
2016-02-26 10:14:49 +00:00
|
|
|
CHECK_EQ(builder.size(), 2 * k8BitCapacity);
|
2016-01-05 19:08:11 +00:00
|
|
|
}
|
[offthread] Add an OffThreadIsolate
The Factory/OffThreadFactory allows us to cleanly separate object
construction behaviour between main-thread and off-thread in a
syntactically consistent way (so that methods templated on the factory
type can be made to work on both).
However, there are cases where we also have to access the Isolate, for
handle creation or exception throwing. So far we have been pushing more
and more "customization points" into the factories to allow these
factory-templated methods to dispatch on this isolate behaviour via
these factory methods. Unfortunately, this is an increasing layering
violation between Factory and Isolate, particularly around exception
handling.
Now, we introduce an OffThreadIsolate, analogous to Isolate in the same
way as OffThreadFactory is analogous to Factory. All methods which were
templated on Factory are now templated on Isolate, and methods which
used to take an Isolate, and which were recently changed to take a
templated Factory, are changed/reverted to take a templated Isolate.
OffThreadFactory gets an isolate() method to match Factory's.
Notably, FactoryHandle is changed to "HandleFor", where the template
argument can be either of the Isolate type or the Factory type (allowing
us to dispatch on both depending on what is available).
Bug: chromium:1011762
Change-Id: Id144176f7da534dd76f3d535ab2ade008b6845e3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2030909
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66101}
2020-02-04 10:50:53 +00:00
|
|
|
ast_factory.Internalize(isolate());
|
2016-08-18 13:42:05 +00:00
|
|
|
Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
|
2016-11-14 10:48:26 +00:00
|
|
|
CHECK_EQ(constant_array->length(), static_cast<int>(2 * k8BitCapacity));
|
2016-02-26 10:14:49 +00:00
|
|
|
for (size_t i = 0; i < k8BitCapacity; i++) {
|
2018-12-25 00:19:47 +00:00
|
|
|
Object original = constant_array->get(static_cast<int>(k8BitCapacity + i));
|
|
|
|
Object duplicate = constant_array->get(static_cast<int>(i));
|
2016-08-10 16:41:43 +00:00
|
|
|
CHECK(original.SameValue(duplicate));
|
2016-01-05 19:08:11 +00:00
|
|
|
Handle<Object> reference = isolate()->factory()->NewNumberFromSize(i);
|
|
|
|
CHECK(original.SameValue(*reference));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ConstantArrayBuilderTest, GapNotFilledWhenLowReservationDiscarded) {
|
2016-08-05 10:09:50 +00:00
|
|
|
CanonicalHandleScope canonical(isolate());
|
2017-02-10 17:22:45 +00:00
|
|
|
ConstantArrayBuilder builder(zone());
|
2016-02-26 10:14:49 +00:00
|
|
|
for (size_t i = 0; i < k8BitCapacity; i++) {
|
2016-01-05 19:08:11 +00:00
|
|
|
OperandSize operand_size = builder.CreateReservedEntry();
|
2017-10-18 09:06:55 +00:00
|
|
|
CHECK_EQ(OperandSize::kByte, operand_size);
|
2016-11-14 10:48:26 +00:00
|
|
|
CHECK_EQ(builder.size(), 0u);
|
2016-01-05 19:08:11 +00:00
|
|
|
}
|
2017-10-27 19:53:15 +00:00
|
|
|
double values[k8BitCapacity];
|
2016-02-26 10:14:49 +00:00
|
|
|
for (size_t i = 0; i < k8BitCapacity; i++) {
|
2017-10-27 19:53:15 +00:00
|
|
|
values[i] = i + 0.5;
|
2017-02-10 17:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < k8BitCapacity; i++) {
|
2017-10-27 19:53:15 +00:00
|
|
|
builder.Insert(values[i]);
|
2016-02-26 10:14:49 +00:00
|
|
|
CHECK_EQ(builder.size(), i + k8BitCapacity + 1);
|
2016-01-05 19:08:11 +00:00
|
|
|
}
|
2016-02-26 10:14:49 +00:00
|
|
|
for (size_t i = 0; i < k8BitCapacity; i++) {
|
2016-01-05 19:08:11 +00:00
|
|
|
builder.DiscardReservedEntry(OperandSize::kByte);
|
2017-10-27 19:53:15 +00:00
|
|
|
builder.Insert(values[i]);
|
2016-02-26 10:14:49 +00:00
|
|
|
CHECK_EQ(builder.size(), 2 * k8BitCapacity);
|
2016-01-05 19:08:11 +00:00
|
|
|
}
|
2016-02-26 10:14:49 +00:00
|
|
|
for (size_t i = 0; i < k8BitCapacity; i++) {
|
2017-02-10 17:22:45 +00:00
|
|
|
Handle<Object> reference = isolate()->factory()->NewNumber(i + 0.5);
|
|
|
|
Handle<Object> original =
|
|
|
|
builder.At(k8BitCapacity + i, isolate()).ToHandleChecked();
|
2016-01-05 19:08:11 +00:00
|
|
|
CHECK(original->SameValue(*reference));
|
2017-02-10 17:22:45 +00:00
|
|
|
MaybeHandle<Object> duplicate = builder.At(i, isolate());
|
|
|
|
CHECK(duplicate.is_null());
|
2016-01-05 19:08:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-01 12:08:53 +00:00
|
|
|
TEST_F(ConstantArrayBuilderTest, HolesWithUnusedReservations) {
|
2016-08-05 10:09:50 +00:00
|
|
|
CanonicalHandleScope canonical(isolate());
|
2016-04-01 12:08:53 +00:00
|
|
|
static int kNumberOfHoles = 128;
|
2017-02-10 17:22:45 +00:00
|
|
|
static int k8BitCapacity = ConstantArrayBuilder::k8BitCapacity;
|
|
|
|
ConstantArrayBuilder builder(zone());
|
|
|
|
AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(),
|
2019-02-14 21:10:30 +00:00
|
|
|
HashSeed(isolate()));
|
2016-04-01 12:08:53 +00:00
|
|
|
for (int i = 0; i < kNumberOfHoles; ++i) {
|
|
|
|
CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kByte);
|
|
|
|
}
|
2017-02-10 17:22:45 +00:00
|
|
|
// Values are placed before the reserved entries in the same slice.
|
|
|
|
for (int i = 0; i < k8BitCapacity - kNumberOfHoles; ++i) {
|
2017-10-27 19:53:15 +00:00
|
|
|
CHECK_EQ(builder.Insert(i + 0.5), static_cast<size_t>(i));
|
2016-04-01 12:08:53 +00:00
|
|
|
}
|
2017-02-10 17:22:45 +00:00
|
|
|
// The next value is pushed into the next slice.
|
2017-10-27 19:53:15 +00:00
|
|
|
CHECK_EQ(builder.Insert(k8BitCapacity + 0.5), k8BitCapacity);
|
2016-04-01 12:08:53 +00:00
|
|
|
|
2017-02-10 17:22:45 +00:00
|
|
|
// Discard the reserved entries.
|
|
|
|
for (int i = 0; i < kNumberOfHoles; ++i) {
|
|
|
|
builder.DiscardReservedEntry(OperandSize::kByte);
|
|
|
|
}
|
|
|
|
|
[offthread] Add an OffThreadIsolate
The Factory/OffThreadFactory allows us to cleanly separate object
construction behaviour between main-thread and off-thread in a
syntactically consistent way (so that methods templated on the factory
type can be made to work on both).
However, there are cases where we also have to access the Isolate, for
handle creation or exception throwing. So far we have been pushing more
and more "customization points" into the factories to allow these
factory-templated methods to dispatch on this isolate behaviour via
these factory methods. Unfortunately, this is an increasing layering
violation between Factory and Isolate, particularly around exception
handling.
Now, we introduce an OffThreadIsolate, analogous to Isolate in the same
way as OffThreadFactory is analogous to Factory. All methods which were
templated on Factory are now templated on Isolate, and methods which
used to take an Isolate, and which were recently changed to take a
templated Factory, are changed/reverted to take a templated Isolate.
OffThreadFactory gets an isolate() method to match Factory's.
Notably, FactoryHandle is changed to "HandleFor", where the template
argument can be either of the Isolate type or the Factory type (allowing
us to dispatch on both depending on what is available).
Bug: chromium:1011762
Change-Id: Id144176f7da534dd76f3d535ab2ade008b6845e3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2030909
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66101}
2020-02-04 10:50:53 +00:00
|
|
|
ast_factory.Internalize(isolate());
|
2016-08-18 13:42:05 +00:00
|
|
|
Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
|
2017-02-10 17:22:45 +00:00
|
|
|
CHECK_EQ(constant_array->length(), k8BitCapacity + 1);
|
|
|
|
for (int i = kNumberOfHoles; i < k8BitCapacity; i++) {
|
2016-04-01 12:08:53 +00:00
|
|
|
CHECK(constant_array->get(i).SameValue(
|
|
|
|
*isolate()->factory()->the_hole_value()));
|
|
|
|
}
|
2017-02-10 17:22:45 +00:00
|
|
|
CHECK(!constant_array->get(kNumberOfHoles - 1)
|
|
|
|
.SameValue(*isolate()->factory()->the_hole_value()));
|
|
|
|
CHECK(!constant_array->get(k8BitCapacity)
|
|
|
|
.SameValue(*isolate()->factory()->the_hole_value()));
|
2016-04-01 12:08:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ConstantArrayBuilderTest, ReservationsAtAllScales) {
|
2016-08-05 10:09:50 +00:00
|
|
|
CanonicalHandleScope canonical(isolate());
|
2017-02-10 17:22:45 +00:00
|
|
|
ConstantArrayBuilder builder(zone());
|
|
|
|
AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(),
|
2019-02-14 21:10:30 +00:00
|
|
|
HashSeed(isolate()));
|
2016-04-01 12:08:53 +00:00
|
|
|
for (int i = 0; i < 256; i++) {
|
|
|
|
CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kByte);
|
|
|
|
}
|
|
|
|
for (int i = 256; i < 65536; ++i) {
|
|
|
|
CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kShort);
|
|
|
|
}
|
|
|
|
for (int i = 65536; i < 131072; ++i) {
|
|
|
|
CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kQuad);
|
|
|
|
}
|
2016-11-14 10:48:26 +00:00
|
|
|
CHECK_EQ(builder.CommitReservedEntry(OperandSize::kByte, Smi::FromInt(1)),
|
|
|
|
0u);
|
2016-08-10 16:41:43 +00:00
|
|
|
CHECK_EQ(builder.CommitReservedEntry(OperandSize::kShort, Smi::FromInt(2)),
|
2016-11-14 10:48:26 +00:00
|
|
|
256u);
|
2016-08-10 16:41:43 +00:00
|
|
|
CHECK_EQ(builder.CommitReservedEntry(OperandSize::kQuad, Smi::FromInt(3)),
|
2016-11-14 10:48:26 +00:00
|
|
|
65536u);
|
2017-02-10 17:22:45 +00:00
|
|
|
for (int i = 1; i < 256; i++) {
|
|
|
|
builder.DiscardReservedEntry(OperandSize::kByte);
|
|
|
|
}
|
|
|
|
for (int i = 257; i < 65536; ++i) {
|
|
|
|
builder.DiscardReservedEntry(OperandSize::kShort);
|
|
|
|
}
|
|
|
|
for (int i = 65537; i < 131072; ++i) {
|
|
|
|
builder.DiscardReservedEntry(OperandSize::kQuad);
|
|
|
|
}
|
|
|
|
|
[offthread] Add an OffThreadIsolate
The Factory/OffThreadFactory allows us to cleanly separate object
construction behaviour between main-thread and off-thread in a
syntactically consistent way (so that methods templated on the factory
type can be made to work on both).
However, there are cases where we also have to access the Isolate, for
handle creation or exception throwing. So far we have been pushing more
and more "customization points" into the factories to allow these
factory-templated methods to dispatch on this isolate behaviour via
these factory methods. Unfortunately, this is an increasing layering
violation between Factory and Isolate, particularly around exception
handling.
Now, we introduce an OffThreadIsolate, analogous to Isolate in the same
way as OffThreadFactory is analogous to Factory. All methods which were
templated on Factory are now templated on Isolate, and methods which
used to take an Isolate, and which were recently changed to take a
templated Factory, are changed/reverted to take a templated Isolate.
OffThreadFactory gets an isolate() method to match Factory's.
Notably, FactoryHandle is changed to "HandleFor", where the template
argument can be either of the Isolate type or the Factory type (allowing
us to dispatch on both depending on what is available).
Bug: chromium:1011762
Change-Id: Id144176f7da534dd76f3d535ab2ade008b6845e3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2030909
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66101}
2020-02-04 10:50:53 +00:00
|
|
|
ast_factory.Internalize(isolate());
|
2016-08-18 13:42:05 +00:00
|
|
|
Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
|
2016-04-01 12:08:53 +00:00
|
|
|
CHECK_EQ(constant_array->length(), 65537);
|
|
|
|
int count = 1;
|
|
|
|
for (int i = 0; i < constant_array->length(); ++i) {
|
|
|
|
Handle<Object> expected;
|
|
|
|
if (i == 0 || i == 256 || i == 65536) {
|
|
|
|
expected = isolate()->factory()->NewNumber(count++);
|
|
|
|
} else {
|
|
|
|
expected = isolate()->factory()->the_hole_value();
|
|
|
|
}
|
|
|
|
CHECK(constant_array->get(i).SameValue(*expected));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-25 11:30:36 +00:00
|
|
|
TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithFixedReservations) {
|
2016-08-05 10:09:50 +00:00
|
|
|
CanonicalHandleScope canonical(isolate());
|
2017-02-10 17:22:45 +00:00
|
|
|
ConstantArrayBuilder builder(zone());
|
2016-07-25 11:30:36 +00:00
|
|
|
for (size_t i = 0; i < k16BitCapacity; i++) {
|
|
|
|
if ((i % 2) == 0) {
|
2017-02-10 17:22:45 +00:00
|
|
|
CHECK_EQ(i, builder.InsertDeferred());
|
2016-07-25 11:30:36 +00:00
|
|
|
} else {
|
2017-02-10 17:22:45 +00:00
|
|
|
builder.Insert(Smi::FromInt(static_cast<int>(i)));
|
2016-07-25 11:30:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
CHECK_EQ(builder.size(), k16BitCapacity);
|
|
|
|
|
|
|
|
// Check values before reserved entries are inserted.
|
|
|
|
for (size_t i = 0; i < k16BitCapacity; i++) {
|
|
|
|
if ((i % 2) == 0) {
|
2017-02-10 17:22:45 +00:00
|
|
|
// Check reserved values are null.
|
|
|
|
MaybeHandle<Object> empty = builder.At(i, isolate());
|
|
|
|
CHECK(empty.is_null());
|
2016-07-25 11:30:36 +00:00
|
|
|
} else {
|
2017-02-10 17:22:45 +00:00
|
|
|
CHECK_EQ(Handle<Smi>::cast(builder.At(i, isolate()).ToHandleChecked())
|
|
|
|
->value(),
|
|
|
|
static_cast<int>(i));
|
2016-07-25 11:30:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert reserved entries.
|
|
|
|
for (size_t i = 0; i < k16BitCapacity; i += 2) {
|
2017-02-10 17:22:45 +00:00
|
|
|
builder.SetDeferredAt(i,
|
|
|
|
handle(Smi::FromInt(static_cast<int>(i)), isolate()));
|
2016-07-25 11:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check values after reserved entries are inserted.
|
|
|
|
for (size_t i = 0; i < k16BitCapacity; i++) {
|
2017-02-10 17:22:45 +00:00
|
|
|
CHECK_EQ(
|
|
|
|
Handle<Smi>::cast(builder.At(i, isolate()).ToHandleChecked())->value(),
|
|
|
|
static_cast<int>(i));
|
2016-07-25 11:30:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-05 19:08:11 +00:00
|
|
|
} // namespace interpreter
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|