Commit be91c6c5 authored by Santiago Aboy Solanes's avatar Santiago Aboy Solanes Committed by Commit Bot

[compiler][cleanup] Move Make(String|Name) helper methods to cctest.h

Several tests were using them and we can dedup code.

Change-Id: I4ef5ae5772856d1f36e965b6b62ff5895b4e04fb
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2215173Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67974}
parent a79a9185
......@@ -150,6 +150,18 @@ void CcTest::PreciseCollectAllGarbage(i::Isolate* isolate) {
i::GarbageCollectionReason::kTesting);
}
i::Handle<i::String> CcTest::MakeString(const char* str) {
i::Isolate* isolate = CcTest::i_isolate();
i::Factory* factory = isolate->factory();
return factory->InternalizeUtf8String(str);
}
i::Handle<i::String> CcTest::MakeName(const char* str, int suffix) {
i::EmbeddedVector<char, 128> buffer;
SNPrintF(buffer, "%s%d", str, suffix);
return CcTest::MakeString(buffer.begin());
}
v8::base::RandomNumberGenerator* CcTest::random_number_generator() {
return InitIsolateOnce()->random_number_generator();
}
......
......@@ -141,6 +141,9 @@ class CcTest {
static void CollectAllAvailableGarbage(i::Isolate* isolate = nullptr);
static void PreciseCollectAllGarbage(i::Isolate* isolate = nullptr);
static i::Handle<i::String> MakeString(const char* str);
static i::Handle<i::String> MakeName(const char* str, int suffix);
static v8::base::RandomNumberGenerator* random_number_generator();
static v8::Local<v8::Object> global();
......
......@@ -42,18 +42,6 @@ template <class T>
using TVariable = TypedCodeAssemblerVariable<T>;
using PromiseResolvingFunctions = TorqueStructPromiseResolvingFunctions;
Handle<String> MakeString(const char* str) {
Isolate* isolate = CcTest::i_isolate();
Factory* factory = isolate->factory();
return factory->InternalizeUtf8String(str);
}
Handle<String> MakeName(const char* str, int suffix) {
EmbeddedVector<char, 128> buffer;
SNPrintF(buffer, "%s%d", str, suffix);
return MakeString(buffer.begin());
}
int sum10(int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7,
int a8, int a9) {
return a0 + a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9;
......@@ -1090,7 +1078,7 @@ TEST(TransitionLookup) {
name = factory->NewSymbol();
} else {
int random_key = rand_gen.NextInt(Smi::kMaxValue);
name = MakeName("p", random_key);
name = CcTest::MakeName("p", random_key);
}
keys[i] = name;
......@@ -3572,8 +3560,8 @@ TEST(TestCallBuiltinInlineTrampoline) {
options.use_pc_relative_calls_and_jumps = false;
options.isolate_independent_code = false;
FunctionTester ft(asm_tester.GenerateCode(options), kNumParams);
MaybeHandle<Object> result = ft.Call(MakeString("abcdef"));
CHECK(String::Equals(isolate, MakeString("abcdefabcdef"),
MaybeHandle<Object> result = ft.Call(CcTest::MakeString("abcdef"));
CHECK(String::Equals(isolate, CcTest::MakeString("abcdefabcdef"),
Handle<String>::cast(result.ToHandleChecked())));
}
......@@ -3598,8 +3586,8 @@ DISABLED_TEST(TestCallBuiltinIndirectLoad) {
options.use_pc_relative_calls_and_jumps = false;
options.isolate_independent_code = true;
FunctionTester ft(asm_tester.GenerateCode(options), kNumParams);
MaybeHandle<Object> result = ft.Call(MakeString("abcdef"));
CHECK(String::Equals(isolate, MakeString("abcdefabcdef"),
MaybeHandle<Object> result = ft.Call(CcTest::MakeString("abcdef"));
CHECK(String::Equals(isolate, CcTest::MakeString("abcdefabcdef"),
Handle<String>::cast(result.ToHandleChecked())));
}
......
This diff is collapsed.
......@@ -43,20 +43,6 @@ const int kPropCount = 7;
// Helper functions.
//
static Handle<String> MakeString(const char* str) {
Isolate* isolate = CcTest::i_isolate();
Factory* factory = isolate->factory();
return factory->InternalizeUtf8String(str);
}
static Handle<String> MakeName(const char* str, int suffix) {
EmbeddedVector<char, 128> buffer;
SNPrintF(buffer, "%s%d", str, suffix);
return MakeString(buffer.begin());
}
static Handle<AccessorPair> CreateAccessorPair(bool with_getter,
bool with_setter) {
Isolate* isolate = CcTest::i_isolate();
......@@ -339,7 +325,7 @@ class Expectations {
SetDataField(property_index, attributes, constness, representation,
field_type);
Handle<String> name = MakeName("prop", property_index);
Handle<String> name = CcTest::MakeName("prop", property_index);
return Map::CopyWithField(isolate_, map, name, field_type, attributes,
constness, representation, INSERT_TRANSITION)
.ToHandleChecked();
......@@ -351,7 +337,7 @@ class Expectations {
int property_index = number_of_properties_++;
SetDataConstant(property_index, attributes, value);
Handle<String> name = MakeName("prop", property_index);
Handle<String> name = CcTest::MakeName("prop", property_index);
return Map::CopyWithConstant(isolate_, map, name, value, attributes,
INSERT_TRANSITION)
.ToHandleChecked();
......@@ -368,7 +354,7 @@ class Expectations {
SetDataField(property_index, attributes, constness, representation,
heap_type);
Handle<String> name = MakeName("prop", property_index);
Handle<String> name = CcTest::MakeName("prop", property_index);
return Map::TransitionToDataProperty(isolate_, map, name, value, attributes,
constness, StoreOrigin::kNamed);
}
......@@ -380,7 +366,7 @@ class Expectations {
int property_index = number_of_properties_++;
SetDataConstant(property_index, attributes, value);
Handle<String> name = MakeName("prop", property_index);
Handle<String> name = CcTest::MakeName("prop", property_index);
return Map::TransitionToDataProperty(isolate_, map, name, value, attributes,
PropertyConstness::kConst,
StoreOrigin::kNamed);
......@@ -396,7 +382,7 @@ class Expectations {
SetDataField(property_index, attributes, constness, representation,
heap_type);
Handle<String> name = MakeName("prop", property_index);
Handle<String> name = CcTest::MakeName("prop", property_index);
Map target = TransitionsAccessor(isolate_, map)
.SearchTransition(*name, kData, attributes);
CHECK(!target.is_null());
......@@ -410,7 +396,7 @@ class Expectations {
int property_index = number_of_properties_++;
SetAccessorConstant(property_index, attributes, pair);
Handle<String> name = MakeName("prop", property_index);
Handle<String> name = CcTest::MakeName("prop", property_index);
Descriptor d = Descriptor::AccessorConstant(name, pair, attributes);
return Map::CopyInsertDescriptor(isolate_, map, &d, INSERT_TRANSITION);
......@@ -424,7 +410,7 @@ class Expectations {
int property_index = number_of_properties_++;
SetAccessorConstant(property_index, attributes, getter, setter);
Handle<String> name = MakeName("prop", property_index);
Handle<String> name = CcTest::MakeName("prop", property_index);
CHECK(!getter->IsNull(isolate_) || !setter->IsNull(isolate_));
Factory* factory = isolate_->factory();
......@@ -451,7 +437,7 @@ class Expectations {
int property_index = number_of_properties_++;
SetAccessorConstant(property_index, attributes, pair);
Handle<String> name = MakeName("prop", property_index);
Handle<String> name = CcTest::MakeName("prop", property_index);
Isolate* isolate = CcTest::i_isolate();
Handle<Object> getter(pair->getter(), isolate);
......@@ -2121,7 +2107,7 @@ TEST(ReconfigurePropertySplitMapTransitionsOverflow) {
split_map = map2;
}
Handle<String> name = MakeName("prop", i);
Handle<String> name = CcTest::MakeName("prop", i);
Map target = TransitionsAccessor(isolate, map2)
.SearchTransition(*name, kData, NONE);
CHECK(!target.is_null());
......@@ -2148,7 +2134,7 @@ TEST(ReconfigurePropertySplitMapTransitionsOverflow) {
// Fill in transition tree of |map2| so that it can't have more transitions.
for (int i = 0; i < TransitionsAccessor::kMaxNumberOfTransitions; i++) {
CHECK(TransitionsAccessor(isolate, map2).CanHaveMoreTransitions());
Handle<String> name = MakeName("foo", i);
Handle<String> name = CcTest::MakeName("foo", i);
Map::CopyWithField(isolate, map2, name, any_type, NONE,
PropertyConstness::kMutable, Representation::Smi(),
INSERT_TRANSITION)
......@@ -2367,9 +2353,9 @@ TEST(ElementsKindTransitionFromMapNotOwningDescriptor) {
// Add one more transition to |map| in order to prevent descriptors
// ownership.
CHECK(map->owns_descriptors());
Map::CopyWithField(isolate, map, MakeString("foo"), any_type, NONE,
PropertyConstness::kMutable, Representation::Smi(),
INSERT_TRANSITION)
Map::CopyWithField(isolate, map, CcTest::MakeString("foo"), any_type,
NONE, PropertyConstness::kMutable,
Representation::Smi(), INSERT_TRANSITION)
.ToHandleChecked();
CHECK(!map->owns_descriptors());
......@@ -2480,9 +2466,9 @@ TEST(PrototypeTransitionFromMapNotOwningDescriptor) {
// Add one more transition to |map| in order to prevent descriptors
// ownership.
CHECK(map->owns_descriptors());
Map::CopyWithField(isolate, map, MakeString("foo"), any_type, NONE,
PropertyConstness::kMutable, Representation::Smi(),
INSERT_TRANSITION)
Map::CopyWithField(isolate, map, CcTest::MakeString("foo"), any_type,
NONE, PropertyConstness::kMutable,
Representation::Smi(), INSERT_TRANSITION)
.ToHandleChecked();
CHECK(!map->owns_descriptors());
......
......@@ -45,20 +45,6 @@ static void InitializeVerifiedMapDescriptors(
CHECK(layout_descriptor.IsConsistentWithMap(map, true));
}
static Handle<String> MakeString(const char* str) {
Isolate* isolate = CcTest::i_isolate();
Factory* factory = isolate->factory();
return factory->InternalizeUtf8String(str);
}
static Handle<String> MakeName(const char* str, int suffix) {
EmbeddedVector<char, 128> buffer;
SNPrintF(buffer, "%s%d", str, suffix);
return MakeString(buffer.begin());
}
Handle<JSObject> GetObject(const char* name) {
return Handle<JSObject>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(
......@@ -995,13 +981,14 @@ TEST(DescriptorArrayTrimming) {
Handle<FieldType> any_type = FieldType::Any(isolate);
Handle<Map> map = Map::Create(isolate, kFieldCount);
for (int i = 0; i < kSplitFieldIndex; i++) {
map = Map::CopyWithField(isolate, map, MakeName("prop", i), any_type, NONE,
PropertyConstness::kMutable, Representation::Smi(),
INSERT_TRANSITION)
map = Map::CopyWithField(isolate, map, CcTest::MakeName("prop", i),
any_type, NONE, PropertyConstness::kMutable,
Representation::Smi(), INSERT_TRANSITION)
.ToHandleChecked();
}
map = Map::CopyWithField(isolate, map, MakeName("dbl", kSplitFieldIndex),
any_type, NONE, PropertyConstness::kMutable,
map = Map::CopyWithField(isolate, map,
CcTest::MakeName("dbl", kSplitFieldIndex), any_type,
NONE, PropertyConstness::kMutable,
Representation::Double(), INSERT_TRANSITION)
.ToHandleChecked();
CHECK(map->layout_descriptor().IsConsistentWithMap(*map, true));
......@@ -1015,7 +1002,7 @@ TEST(DescriptorArrayTrimming) {
Handle<Map> tmp_map = map;
for (int i = kSplitFieldIndex + 1; i < kFieldCount; i++) {
tmp_map = Map::CopyWithField(isolate, tmp_map, MakeName("dbl", i),
tmp_map = Map::CopyWithField(isolate, tmp_map, CcTest::MakeName("dbl", i),
any_type, NONE, PropertyConstness::kMutable,
Representation::Double(), INSERT_TRANSITION)
.ToHandleChecked();
......@@ -1055,14 +1042,15 @@ TEST(DescriptorArrayTrimming) {
Handle<Map> tmp_map = map;
for (int i = kSplitFieldIndex + 1; i < kFieldCount - 1; i++) {
tmp_map = Map::CopyWithField(isolate, tmp_map, MakeName("tagged", i),
any_type, NONE, PropertyConstness::kMutable,
Representation::Tagged(), INSERT_TRANSITION)
.ToHandleChecked();
tmp_map =
Map::CopyWithField(isolate, tmp_map, CcTest::MakeName("tagged", i),
any_type, NONE, PropertyConstness::kMutable,
Representation::Tagged(), INSERT_TRANSITION)
.ToHandleChecked();
CHECK(tmp_map->layout_descriptor().IsConsistentWithMap(*tmp_map, true));
}
tmp_map = Map::CopyWithField(isolate, tmp_map, MakeString("dbl"), any_type,
NONE, PropertyConstness::kMutable,
tmp_map = Map::CopyWithField(isolate, tmp_map, CcTest::MakeString("dbl"),
any_type, NONE, PropertyConstness::kMutable,
Representation::Double(), INSERT_TRANSITION)
.ToHandleChecked();
CHECK(tmp_map->layout_descriptor().IsConsistentWithMap(*tmp_map, true));
......@@ -1087,8 +1075,8 @@ TEST(DoScavenge) {
Handle<FieldType> any_type = FieldType::Any(isolate);
Handle<Map> map = Map::Create(isolate, 10);
map = Map::CopyWithField(isolate, map, MakeName("prop", 0), any_type, NONE,
PropertyConstness::kMutable,
map = Map::CopyWithField(isolate, map, CcTest::MakeName("prop", 0), any_type,
NONE, PropertyConstness::kMutable,
Representation::Double(), INSERT_TRANSITION)
.ToHandleChecked();
......@@ -1153,12 +1141,12 @@ TEST(DoScavengeWithIncrementalWriteBarrier) {
Handle<FieldType> any_type = FieldType::Any(isolate);
Handle<Map> map = Map::Create(isolate, 10);
map = Map::CopyWithField(isolate, map, MakeName("prop", 0), any_type, NONE,
PropertyConstness::kMutable,
map = Map::CopyWithField(isolate, map, CcTest::MakeName("prop", 0), any_type,
NONE, PropertyConstness::kMutable,
Representation::Double(), INSERT_TRANSITION)
.ToHandleChecked();
map = Map::CopyWithField(isolate, map, MakeName("prop", 1), any_type, NONE,
PropertyConstness::kMutable,
map = Map::CopyWithField(isolate, map, CcTest::MakeName("prop", 1), any_type,
NONE, PropertyConstness::kMutable,
Representation::Tagged(), INSERT_TRANSITION)
.ToHandleChecked();
......@@ -1390,14 +1378,14 @@ TEST(LayoutDescriptorSharing) {
{
Handle<Map> map = Map::Create(isolate, 64);
for (int i = 0; i < 32; i++) {
Handle<String> name = MakeName("prop", i);
Handle<String> name = CcTest::MakeName("prop", i);
map = Map::CopyWithField(isolate, map, name, any_type, NONE,
PropertyConstness::kMutable,
Representation::Smi(), INSERT_TRANSITION)
.ToHandleChecked();
}
split_map = Map::CopyWithField(isolate, map, MakeString("dbl"), any_type,
NONE, PropertyConstness::kMutable,
split_map = Map::CopyWithField(isolate, map, CcTest::MakeString("dbl"),
any_type, NONE, PropertyConstness::kMutable,
Representation::Double(), INSERT_TRANSITION)
.ToHandleChecked();
}
......@@ -1408,9 +1396,9 @@ TEST(LayoutDescriptorSharing) {
CHECK(split_map->owns_descriptors());
Handle<Map> map1 =
Map::CopyWithField(isolate, split_map, MakeString("foo"), any_type, NONE,
PropertyConstness::kMutable, Representation::Double(),
INSERT_TRANSITION)
Map::CopyWithField(isolate, split_map, CcTest::MakeString("foo"),
any_type, NONE, PropertyConstness::kMutable,
Representation::Double(), INSERT_TRANSITION)
.ToHandleChecked();
CHECK(!split_map->owns_descriptors());
CHECK_EQ(*split_layout_descriptor, split_map->layout_descriptor());
......@@ -1421,9 +1409,9 @@ TEST(LayoutDescriptorSharing) {
CHECK(map1->layout_descriptor().IsConsistentWithMap(*map1, true));
Handle<Map> map2 =
Map::CopyWithField(isolate, split_map, MakeString("bar"), any_type, NONE,
PropertyConstness::kMutable, Representation::Tagged(),
INSERT_TRANSITION)
Map::CopyWithField(isolate, split_map, CcTest::MakeString("bar"),
any_type, NONE, PropertyConstness::kMutable,
Representation::Tagged(), INSERT_TRANSITION)
.ToHandleChecked();
// Layout descriptors should not be shared with |split_map|.
......@@ -1595,15 +1583,15 @@ static void TestWriteBarrierObjectShiftFieldsRight(
Handle<JSObject> func = GetObject("func");
Handle<Map> map = Map::Create(isolate, 10);
map = Map::CopyWithConstant(isolate, map, MakeName("prop", 0), func, NONE,
INSERT_TRANSITION)
map = Map::CopyWithConstant(isolate, map, CcTest::MakeName("prop", 0), func,
NONE, INSERT_TRANSITION)
.ToHandleChecked();
map = Map::CopyWithField(isolate, map, MakeName("prop", 1), any_type, NONE,
PropertyConstness::kMutable,
map = Map::CopyWithField(isolate, map, CcTest::MakeName("prop", 1), any_type,
NONE, PropertyConstness::kMutable,
Representation::Double(), INSERT_TRANSITION)
.ToHandleChecked();
map = Map::CopyWithField(isolate, map, MakeName("prop", 2), any_type, NONE,
PropertyConstness::kMutable,
map = Map::CopyWithField(isolate, map, CcTest::MakeName("prop", 2), any_type,
NONE, PropertyConstness::kMutable,
Representation::Tagged(), INSERT_TRANSITION)
.ToHandleChecked();
......
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