[string] Add tests for uncached strings with cacheable resources
Add tests for internal external uncached strings with cacheable resources, for the cached_data functionality added in https://chromium-review.googlesource.com/c/v8/v8/+/2710440. Bug: v8:7790, v8:11463 Change-Id: I679c50995d315cc4289452a00838b3cafa4c93e4 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2715187 Reviewed-by: Leszek Swirski <leszeks@chromium.org> Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org> Cr-Commit-Position: refs/heads/master@{#73103}
This commit is contained in:
parent
475d47d703
commit
8e8c727ae2
@ -2096,6 +2096,84 @@ TEST(InternalizeExternalStringUncachedWithCopyTwoByte) {
|
||||
CHECK(internal->IsInternalizedString());
|
||||
}
|
||||
|
||||
// Show that we cache the data pointer for internal, external and uncached
|
||||
// strings with cacheable resources through MakeExternal. One byte version.
|
||||
TEST(CheckCachedDataInternalExternalUncachedString) {
|
||||
CcTest::InitializeVM();
|
||||
Factory* factory = CcTest::i_isolate()->factory();
|
||||
v8::HandleScope scope(CcTest::isolate());
|
||||
|
||||
// Due to different size restrictions the string needs to be small but not too
|
||||
// small. One of these restrictions is whether pointer compression is enabled.
|
||||
#ifdef V8_COMPRESS_POINTERS
|
||||
const char* raw_small = "small string";
|
||||
#elif V8_TARGET_ARCH_32_BIT
|
||||
const char* raw_small = "smol";
|
||||
#else
|
||||
const char* raw_small = "smalls";
|
||||
#endif // V8_COMPRESS_POINTERS
|
||||
|
||||
Handle<String> string =
|
||||
factory->InternalizeString(factory->NewStringFromAsciiChecked(raw_small));
|
||||
OneByteResource* resource =
|
||||
new OneByteResource(i::StrDup(raw_small), strlen(raw_small));
|
||||
|
||||
// Check it is external, internalized, and uncached with a cacheable resource.
|
||||
string->MakeExternal(resource);
|
||||
CHECK(string->IsOneByteRepresentation());
|
||||
CHECK(string->IsExternalString());
|
||||
CHECK(string->IsInternalizedString());
|
||||
|
||||
// Check that the external string is uncached, its resource is cacheable, and
|
||||
// that we indeed cached it.
|
||||
Handle<ExternalOneByteString> external_string =
|
||||
Handle<ExternalOneByteString>::cast(string);
|
||||
CHECK(external_string->is_uncached());
|
||||
CHECK(external_string->resource()->IsCacheable());
|
||||
CHECK_NOT_NULL(external_string->resource()->cached_data());
|
||||
CHECK_EQ(external_string->resource()->cached_data(),
|
||||
external_string->resource()->data());
|
||||
}
|
||||
|
||||
// Show that we cache the data pointer for internal, external and uncached
|
||||
// strings with cacheable resources through MakeExternal. One byte version.
|
||||
TEST(CheckCachedDataInternalExternalUncachedStringTwoByte) {
|
||||
CcTest::InitializeVM();
|
||||
Factory* factory = CcTest::i_isolate()->factory();
|
||||
v8::HandleScope scope(CcTest::isolate());
|
||||
|
||||
// Due to different size restrictions the string needs to be small but not too
|
||||
// small. One of these restrictions is whether pointer compression is enabled.
|
||||
#ifdef V8_COMPRESS_POINTERS
|
||||
const char* raw_small = "small string";
|
||||
#elif V8_TARGET_ARCH_32_BIT
|
||||
const char* raw_small = "smol";
|
||||
#else
|
||||
const char* raw_small = "smalls";
|
||||
#endif // V8_COMPRESS_POINTERS
|
||||
|
||||
Handle<String> string =
|
||||
factory->InternalizeString(factory->NewStringFromAsciiChecked(raw_small));
|
||||
Resource* resource =
|
||||
new Resource(AsciiToTwoByteString(raw_small), strlen(raw_small));
|
||||
|
||||
// Check it is external, internalized, and uncached with a cacheable resource.
|
||||
string->MakeExternal(resource);
|
||||
CHECK(string->IsTwoByteRepresentation());
|
||||
CHECK(string->IsExternalString());
|
||||
CHECK(string->IsInternalizedString());
|
||||
|
||||
// Check that the external string is uncached, its resource is cacheable, and
|
||||
// that we indeed cached it.
|
||||
Handle<ExternalTwoByteString> external_string =
|
||||
Handle<ExternalTwoByteString>::cast(string);
|
||||
CHECK(external_string->is_uncached());
|
||||
CHECK(external_string->resource()->IsCacheable());
|
||||
CHECK_NOT_NULL(external_string->resource()->cached_data());
|
||||
CHECK_EQ(external_string->resource()->cached_data(),
|
||||
external_string->resource()->data());
|
||||
}
|
||||
|
||||
} // namespace test_strings
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
Loading…
Reference in New Issue
Block a user