Commit 1874c334 authored by Marina Sakai's avatar Marina Sakai Committed by Commit Bot

Make V8PrivateProperty::SymbolKey class is_trivially_constructible

A class which is not trivially constructible might bloat out code size.

The member variable |desc_| of class V8PrivateProperty::SymbolKey is used for just a description of a private property, so we can remove the variable.

This CL guarantees that V8PrivateProperty::SymbolKey is is_trivially_constructible.

Bug: 715418
Change-Id: I7f44e4e70430b66275b001c99974326556d38477
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1880778
Commit-Queue: Marina Sakai <marinasakai@google.com>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710246}
parent b13dc585
......@@ -41,8 +41,7 @@ const v8::FunctionCallbackInfo<v8::Value>& info
{% if attribute.is_save_same_object %}
// [SaveSameObject]
static const V8PrivateProperty::SymbolKey
save_same_object_key("{{cpp_class}}#{{attribute.camel_case_name}}");
static const V8PrivateProperty::SymbolKey save_same_object_key;
auto private_same_object =
V8PrivateProperty::GetSymbol(info.GetIsolate(), save_same_object_key);
{
......@@ -77,8 +76,7 @@ const v8::FunctionCallbackInfo<v8::Value>& info
V8PrivateProperty::GetHistoryStateSymbol(info.GetIsolate());
{% else %}
{% if not attribute.private_property_is_shared_between_getter_and_setter %}
static const V8PrivateProperty::SymbolKey
{{attribute.private_property_key_name}}("{{cpp_class}}#{{attribute.camel_case_name}}");
static const V8PrivateProperty::SymbolKey {{attribute.private_property_key_name}};
{% endif %}
V8PrivateProperty::Symbol property_symbol =
......
......@@ -92,8 +92,7 @@ static void (*{{method.name}}MethodForPartialInterface)(const v8::FunctionCallba
{% for world_suffix in attribute.world_suffixes %}
{% if attribute.private_property_is_shared_between_getter_and_setter %}
// Define a private property key shared between getter and setter.
static const V8PrivateProperty::SymbolKey
{{attribute.private_property_key_name}}("{{cpp_class}}#{{attribute.camel_case_name}}");
static const V8PrivateProperty::SymbolKey {{attribute.private_property_key_name}};
{% endif %}
{% if attribute.does_generate_getter %}
......
......@@ -1993,8 +1993,7 @@ static void ActivityLoggingSetterForAllWorldsLongAttributeAttributeSetter(
}
// Define a private property key shared between getter and setter.
static const V8PrivateProperty::SymbolKey
cached_attribute_any_attribute_key("TestObject#CachedAttributeAnyAttribute");
static const V8PrivateProperty::SymbolKey cached_attribute_any_attribute_key;
static void CachedAttributeAnyAttributeAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Local<v8::Object> holder = info.Holder();
......@@ -2046,8 +2045,7 @@ static void CachedAttributeAnyAttributeAttributeSetter(
}
// Define a private property key shared between getter and setter.
static const V8PrivateProperty::SymbolKey
cached_array_attribute_key("TestObject#CachedArrayAttribute");
static const V8PrivateProperty::SymbolKey cached_array_attribute_key;
static void CachedArrayAttributeAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Local<v8::Object> holder = info.Holder();
......@@ -2108,8 +2106,7 @@ static void ReadonlyCachedAttributeAttributeGetter(const v8::FunctionCallbackInf
TestObject* impl = V8TestObject::ToImpl(holder);
// [CachedAttribute]
static const V8PrivateProperty::SymbolKey
readonly_cached_attribute_key("TestObject#ReadonlyCachedAttribute");
static const V8PrivateProperty::SymbolKey readonly_cached_attribute_key;
V8PrivateProperty::Symbol property_symbol =
V8PrivateProperty::GetSymbol(info.GetIsolate(),
......@@ -2132,8 +2129,7 @@ static void ReadonlyCachedAttributeAttributeGetter(const v8::FunctionCallbackInf
}
// Define a private property key shared between getter and setter.
static const V8PrivateProperty::SymbolKey
cached_string_or_none_attribute_key("TestObject#CachedStringOrNoneAttribute");
static const V8PrivateProperty::SymbolKey cached_string_or_none_attribute_key;
static void CachedStringOrNoneAttributeAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Local<v8::Object> holder = info.Holder();
......@@ -3145,8 +3141,7 @@ static void RaisesExceptionTestInterfaceEmptyAttributeAttributeSetter(
}
// Define a private property key shared between getter and setter.
static const V8PrivateProperty::SymbolKey
cached_attribute_raises_exception_getter_any_attribute_key("TestObject#CachedAttributeRaisesExceptionGetterAnyAttribute");
static const V8PrivateProperty::SymbolKey cached_attribute_raises_exception_getter_any_attribute_key;
static void CachedAttributeRaisesExceptionGetterAnyAttributeAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Local<v8::Object> holder = info.Holder();
......@@ -4125,8 +4120,7 @@ static void SaveSameObjectAttributeAttributeGetter(const v8::FunctionCallbackInf
v8::Local<v8::Object> holder = info.Holder();
// [SaveSameObject]
static const V8PrivateProperty::SymbolKey
save_same_object_key("TestObject#SaveSameObjectAttribute");
static const V8PrivateProperty::SymbolKey save_same_object_key;
auto private_same_object =
V8PrivateProperty::GetSymbol(info.GetIsolate(), save_same_object_key);
{
......@@ -4161,8 +4155,7 @@ static void StaticSaveSameObjectAttributeAttributeGetter(const v8::FunctionCallb
v8::Local<v8::Object> holder = info.Holder();
// [SaveSameObject]
static const V8PrivateProperty::SymbolKey
save_same_object_key("TestObject#StaticSaveSameObjectAttribute");
static const V8PrivateProperty::SymbolKey save_same_object_key;
auto private_same_object =
V8PrivateProperty::GetSymbol(info.GetIsolate(), save_same_object_key);
{
......
......@@ -11,6 +11,18 @@
namespace blink {
// As SymbolKey is widely used, numerous instances of SymbolKey are created,
// plus all the instances have static storage duration (defined as static
// variables). Thus, it's important to make SymbolKey
// trivially-constructible/destructible so that compilers can remove all the
// constructor/destructor calls and reduce the code size.
static_assert(
std::is_trivially_constructible<V8PrivateProperty::SymbolKey>::value,
"SymbolKey is not trivially constructible");
static_assert(
std::is_trivially_destructible<V8PrivateProperty::SymbolKey>::value,
"SymbolKey is not trivially destructible");
v8::MaybeLocal<v8::Value> V8PrivateProperty::Symbol::GetFromMainWorld(
ScriptWrappable* script_wrappable) {
v8::Local<v8::Object> wrapper = script_wrappable->MainWorldWrapper(isolate_);
......@@ -27,7 +39,7 @@ V8PrivateProperty::Symbol V8PrivateProperty::GetSymbol(
auto iter = symbol_map.find(&key);
v8::Local<v8::Private> v8_private;
if (UNLIKELY(iter == symbol_map.end())) {
v8_private = CreateV8Private(isolate, key.GetDescription());
v8_private = CreateV8Private(isolate, nullptr);
symbol_map.insert(&key, v8::Eternal<v8::Private>(isolate, v8_private));
} else {
v8_private = iter->value.Get(isolate);
......
......@@ -54,17 +54,16 @@ class ScriptWrappable;
// Provides access to V8's private properties.
//
// Usage 1) Fast path to use a pre-registered symbol.
// Usage 1) Path to use a pre-registered symbol.
// auto private_property = V8PrivateProperty::GetDOMExceptionError(isolate);
// v8::Local<v8::Object> object = ...;
// v8::Local<v8::Value> value;
// if (!private_property.GetOrUndefined(object).ToLocal(&value)) return;
// value = ...;
// private_property.set(object, value);
// private_property.Set(object, value);
//
// Usage 2) Slow path to create a global private symbol.
// /* |desc| is a description of the private property. */
// static const SymbolKey key(desc);
// Usage 2) Access with a symbol key.
// static const SymbolKey key;
// auto private_property = V8PrivateProperty::GetSymbol(isolate, key);
// ...
class PLATFORM_EXPORT V8PrivateProperty {
......@@ -134,29 +133,21 @@ class PLATFORM_EXPORT V8PrivateProperty {
// This class is used for a key to get Symbol.
//
// We can improve ability of tracking private properties by using an instance
// of this class. |desc_| is a description of the private property.
// of this class.
class PLATFORM_EXPORT SymbolKey final {
public:
// Note that, unlike a string class, the lifetime of |desc| must be longer
// than this SymbolKey, i.e. this SymbolKey does not copy |desc| nor have
// |desc| alive enough long.
explicit SymbolKey(const char* desc) : desc_(desc) {}
const char* GetDescription() const { return desc_; }
SymbolKey() = default;
private:
SymbolKey(const SymbolKey&) = delete;
SymbolKey& operator=(const SymbolKey&) = delete;
const char* const desc_;
};
#define V8_PRIVATE_PROPERTY_DEFINE_GETTER(InterfaceName, KeyName) \
static Symbol V8_PRIVATE_PROPERTY_GETTER_NAME(/* // NOLINT */ \
InterfaceName, KeyName)( \
v8::Isolate * isolate) { \
static const SymbolKey private_property_key( \
V8_PRIVATE_PROPERTY_SYMBOL_STRING(InterfaceName, KeyName)); \
static const SymbolKey private_property_key; \
return GetSymbol(isolate, private_property_key); \
}
......@@ -195,7 +186,7 @@ class PLATFORM_EXPORT V8PrivateProperty {
// This is a hack for PopStateEvent to get the same private property of
// History, named State.
static Symbol GetHistoryStateSymbol(v8::Isolate* isolate) {
static const SymbolKey private_property_key("History#State");
static const SymbolKey private_property_key;
return GetSymbol(isolate, private_property_key);
}
......
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