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 ...@@ -41,8 +41,7 @@ const v8::FunctionCallbackInfo<v8::Value>& info
{% if attribute.is_save_same_object %} {% if attribute.is_save_same_object %}
// [SaveSameObject] // [SaveSameObject]
static const V8PrivateProperty::SymbolKey static const V8PrivateProperty::SymbolKey save_same_object_key;
save_same_object_key("{{cpp_class}}#{{attribute.camel_case_name}}");
auto private_same_object = auto private_same_object =
V8PrivateProperty::GetSymbol(info.GetIsolate(), save_same_object_key); V8PrivateProperty::GetSymbol(info.GetIsolate(), save_same_object_key);
{ {
...@@ -77,8 +76,7 @@ const v8::FunctionCallbackInfo<v8::Value>& info ...@@ -77,8 +76,7 @@ const v8::FunctionCallbackInfo<v8::Value>& info
V8PrivateProperty::GetHistoryStateSymbol(info.GetIsolate()); V8PrivateProperty::GetHistoryStateSymbol(info.GetIsolate());
{% else %} {% else %}
{% if not attribute.private_property_is_shared_between_getter_and_setter %} {% if not attribute.private_property_is_shared_between_getter_and_setter %}
static const V8PrivateProperty::SymbolKey static const V8PrivateProperty::SymbolKey {{attribute.private_property_key_name}};
{{attribute.private_property_key_name}}("{{cpp_class}}#{{attribute.camel_case_name}}");
{% endif %} {% endif %}
V8PrivateProperty::Symbol property_symbol = V8PrivateProperty::Symbol property_symbol =
......
...@@ -92,8 +92,7 @@ static void (*{{method.name}}MethodForPartialInterface)(const v8::FunctionCallba ...@@ -92,8 +92,7 @@ static void (*{{method.name}}MethodForPartialInterface)(const v8::FunctionCallba
{% for world_suffix in attribute.world_suffixes %} {% for world_suffix in attribute.world_suffixes %}
{% if attribute.private_property_is_shared_between_getter_and_setter %} {% if attribute.private_property_is_shared_between_getter_and_setter %}
// Define a private property key shared between getter and setter. // Define a private property key shared between getter and setter.
static const V8PrivateProperty::SymbolKey static const V8PrivateProperty::SymbolKey {{attribute.private_property_key_name}};
{{attribute.private_property_key_name}}("{{cpp_class}}#{{attribute.camel_case_name}}");
{% endif %} {% endif %}
{% if attribute.does_generate_getter %} {% if attribute.does_generate_getter %}
......
...@@ -1993,8 +1993,7 @@ static void ActivityLoggingSetterForAllWorldsLongAttributeAttributeSetter( ...@@ -1993,8 +1993,7 @@ static void ActivityLoggingSetterForAllWorldsLongAttributeAttributeSetter(
} }
// Define a private property key shared between getter and setter. // Define a private property key shared between getter and setter.
static const V8PrivateProperty::SymbolKey static const V8PrivateProperty::SymbolKey cached_attribute_any_attribute_key;
cached_attribute_any_attribute_key("TestObject#CachedAttributeAnyAttribute");
static void CachedAttributeAnyAttributeAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info) { static void CachedAttributeAnyAttributeAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Local<v8::Object> holder = info.Holder(); v8::Local<v8::Object> holder = info.Holder();
...@@ -2046,8 +2045,7 @@ static void CachedAttributeAnyAttributeAttributeSetter( ...@@ -2046,8 +2045,7 @@ static void CachedAttributeAnyAttributeAttributeSetter(
} }
// Define a private property key shared between getter and setter. // Define a private property key shared between getter and setter.
static const V8PrivateProperty::SymbolKey static const V8PrivateProperty::SymbolKey cached_array_attribute_key;
cached_array_attribute_key("TestObject#CachedArrayAttribute");
static void CachedArrayAttributeAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info) { static void CachedArrayAttributeAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Local<v8::Object> holder = info.Holder(); v8::Local<v8::Object> holder = info.Holder();
...@@ -2108,8 +2106,7 @@ static void ReadonlyCachedAttributeAttributeGetter(const v8::FunctionCallbackInf ...@@ -2108,8 +2106,7 @@ static void ReadonlyCachedAttributeAttributeGetter(const v8::FunctionCallbackInf
TestObject* impl = V8TestObject::ToImpl(holder); TestObject* impl = V8TestObject::ToImpl(holder);
// [CachedAttribute] // [CachedAttribute]
static const V8PrivateProperty::SymbolKey static const V8PrivateProperty::SymbolKey readonly_cached_attribute_key;
readonly_cached_attribute_key("TestObject#ReadonlyCachedAttribute");
V8PrivateProperty::Symbol property_symbol = V8PrivateProperty::Symbol property_symbol =
V8PrivateProperty::GetSymbol(info.GetIsolate(), V8PrivateProperty::GetSymbol(info.GetIsolate(),
...@@ -2132,8 +2129,7 @@ static void ReadonlyCachedAttributeAttributeGetter(const v8::FunctionCallbackInf ...@@ -2132,8 +2129,7 @@ static void ReadonlyCachedAttributeAttributeGetter(const v8::FunctionCallbackInf
} }
// Define a private property key shared between getter and setter. // Define a private property key shared between getter and setter.
static const V8PrivateProperty::SymbolKey static const V8PrivateProperty::SymbolKey cached_string_or_none_attribute_key;
cached_string_or_none_attribute_key("TestObject#CachedStringOrNoneAttribute");
static void CachedStringOrNoneAttributeAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info) { static void CachedStringOrNoneAttributeAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Local<v8::Object> holder = info.Holder(); v8::Local<v8::Object> holder = info.Holder();
...@@ -3145,8 +3141,7 @@ static void RaisesExceptionTestInterfaceEmptyAttributeAttributeSetter( ...@@ -3145,8 +3141,7 @@ static void RaisesExceptionTestInterfaceEmptyAttributeAttributeSetter(
} }
// Define a private property key shared between getter and setter. // Define a private property key shared between getter and setter.
static const V8PrivateProperty::SymbolKey static const V8PrivateProperty::SymbolKey cached_attribute_raises_exception_getter_any_attribute_key;
cached_attribute_raises_exception_getter_any_attribute_key("TestObject#CachedAttributeRaisesExceptionGetterAnyAttribute");
static void CachedAttributeRaisesExceptionGetterAnyAttributeAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info) { static void CachedAttributeRaisesExceptionGetterAnyAttributeAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Local<v8::Object> holder = info.Holder(); v8::Local<v8::Object> holder = info.Holder();
...@@ -4125,8 +4120,7 @@ static void SaveSameObjectAttributeAttributeGetter(const v8::FunctionCallbackInf ...@@ -4125,8 +4120,7 @@ static void SaveSameObjectAttributeAttributeGetter(const v8::FunctionCallbackInf
v8::Local<v8::Object> holder = info.Holder(); v8::Local<v8::Object> holder = info.Holder();
// [SaveSameObject] // [SaveSameObject]
static const V8PrivateProperty::SymbolKey static const V8PrivateProperty::SymbolKey save_same_object_key;
save_same_object_key("TestObject#SaveSameObjectAttribute");
auto private_same_object = auto private_same_object =
V8PrivateProperty::GetSymbol(info.GetIsolate(), save_same_object_key); V8PrivateProperty::GetSymbol(info.GetIsolate(), save_same_object_key);
{ {
...@@ -4161,8 +4155,7 @@ static void StaticSaveSameObjectAttributeAttributeGetter(const v8::FunctionCallb ...@@ -4161,8 +4155,7 @@ static void StaticSaveSameObjectAttributeAttributeGetter(const v8::FunctionCallb
v8::Local<v8::Object> holder = info.Holder(); v8::Local<v8::Object> holder = info.Holder();
// [SaveSameObject] // [SaveSameObject]
static const V8PrivateProperty::SymbolKey static const V8PrivateProperty::SymbolKey save_same_object_key;
save_same_object_key("TestObject#StaticSaveSameObjectAttribute");
auto private_same_object = auto private_same_object =
V8PrivateProperty::GetSymbol(info.GetIsolate(), save_same_object_key); V8PrivateProperty::GetSymbol(info.GetIsolate(), save_same_object_key);
{ {
......
...@@ -11,6 +11,18 @@ ...@@ -11,6 +11,18 @@
namespace blink { 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( v8::MaybeLocal<v8::Value> V8PrivateProperty::Symbol::GetFromMainWorld(
ScriptWrappable* script_wrappable) { ScriptWrappable* script_wrappable) {
v8::Local<v8::Object> wrapper = script_wrappable->MainWorldWrapper(isolate_); v8::Local<v8::Object> wrapper = script_wrappable->MainWorldWrapper(isolate_);
...@@ -27,7 +39,7 @@ V8PrivateProperty::Symbol V8PrivateProperty::GetSymbol( ...@@ -27,7 +39,7 @@ V8PrivateProperty::Symbol V8PrivateProperty::GetSymbol(
auto iter = symbol_map.find(&key); auto iter = symbol_map.find(&key);
v8::Local<v8::Private> v8_private; v8::Local<v8::Private> v8_private;
if (UNLIKELY(iter == symbol_map.end())) { 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)); symbol_map.insert(&key, v8::Eternal<v8::Private>(isolate, v8_private));
} else { } else {
v8_private = iter->value.Get(isolate); v8_private = iter->value.Get(isolate);
......
...@@ -54,17 +54,16 @@ class ScriptWrappable; ...@@ -54,17 +54,16 @@ class ScriptWrappable;
// Provides access to V8's private properties. // 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); // auto private_property = V8PrivateProperty::GetDOMExceptionError(isolate);
// v8::Local<v8::Object> object = ...; // v8::Local<v8::Object> object = ...;
// v8::Local<v8::Value> value; // v8::Local<v8::Value> value;
// if (!private_property.GetOrUndefined(object).ToLocal(&value)) return; // if (!private_property.GetOrUndefined(object).ToLocal(&value)) return;
// value = ...; // value = ...;
// private_property.set(object, value); // private_property.Set(object, value);
// //
// Usage 2) Slow path to create a global private symbol. // Usage 2) Access with a symbol key.
// /* |desc| is a description of the private property. */ // static const SymbolKey key;
// static const SymbolKey key(desc);
// auto private_property = V8PrivateProperty::GetSymbol(isolate, key); // auto private_property = V8PrivateProperty::GetSymbol(isolate, key);
// ... // ...
class PLATFORM_EXPORT V8PrivateProperty { class PLATFORM_EXPORT V8PrivateProperty {
...@@ -134,29 +133,21 @@ class PLATFORM_EXPORT V8PrivateProperty { ...@@ -134,29 +133,21 @@ class PLATFORM_EXPORT V8PrivateProperty {
// This class is used for a key to get Symbol. // This class is used for a key to get Symbol.
// //
// We can improve ability of tracking private properties by using an instance // 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 { class PLATFORM_EXPORT SymbolKey final {
public: public:
// Note that, unlike a string class, the lifetime of |desc| must be longer SymbolKey() = default;
// 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_; }
private: private:
SymbolKey(const SymbolKey&) = delete; SymbolKey(const SymbolKey&) = delete;
SymbolKey& operator=(const SymbolKey&) = delete; SymbolKey& operator=(const SymbolKey&) = delete;
const char* const desc_;
}; };
#define V8_PRIVATE_PROPERTY_DEFINE_GETTER(InterfaceName, KeyName) \ #define V8_PRIVATE_PROPERTY_DEFINE_GETTER(InterfaceName, KeyName) \
static Symbol V8_PRIVATE_PROPERTY_GETTER_NAME(/* // NOLINT */ \ static Symbol V8_PRIVATE_PROPERTY_GETTER_NAME(/* // NOLINT */ \
InterfaceName, KeyName)( \ InterfaceName, KeyName)( \
v8::Isolate * isolate) { \ v8::Isolate * isolate) { \
static const SymbolKey private_property_key( \ static const SymbolKey private_property_key; \
V8_PRIVATE_PROPERTY_SYMBOL_STRING(InterfaceName, KeyName)); \
return GetSymbol(isolate, private_property_key); \ return GetSymbol(isolate, private_property_key); \
} }
...@@ -195,7 +186,7 @@ class PLATFORM_EXPORT V8PrivateProperty { ...@@ -195,7 +186,7 @@ class PLATFORM_EXPORT V8PrivateProperty {
// This is a hack for PopStateEvent to get the same private property of // This is a hack for PopStateEvent to get the same private property of
// History, named State. // History, named State.
static Symbol GetHistoryStateSymbol(v8::Isolate* isolate) { 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); 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