Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8ValueCache.cpp

Issue 1583263002: Experimental CompressibleString UMA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adopt lazy-initializing way Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 { 47 {
48 V8PerIsolateData::from(data.GetIsolate())->stringCache()->InvalidateLastStri ng(); 48 V8PerIsolateData::from(data.GetIsolate())->stringCache()->InvalidateLastStri ng();
49 data.GetParameter()->deref(); 49 data.GetParameter()->deref();
50 } 50 }
51 51
52 void StringCacheMapTraits::OnWeakCallback(const v8::WeakCallbackInfo<WeakCallbac kDataType>& data) 52 void StringCacheMapTraits::OnWeakCallback(const v8::WeakCallbackInfo<WeakCallbac kDataType>& data)
53 { 53 {
54 V8PerIsolateData::from(data.GetIsolate())->stringCache()->InvalidateLastStri ng(); 54 V8PerIsolateData::from(data.GetIsolate())->stringCache()->InvalidateLastStri ng();
55 } 55 }
56 56
57
58 CompressibleStringCacheMapTraits::MapType* CompressibleStringCacheMapTraits::Map FromWeakCallbackInfo(
59 const v8::WeakCallbackInfo<WeakCallbackDataType>& data)
60 {
61 return &(V8PerIsolateData::from(data.GetIsolate())->stringCache()->m_compres sibleStringCache);
62 }
63
64 void CompressibleStringCacheMapTraits::Dispose(
65 v8::Isolate* isolate, v8::Global<v8::String> value, CompressibleStringImpl* key)
66 {
67 key->deref();
68 }
69
70 void CompressibleStringCacheMapTraits::DisposeWeak(const v8::WeakCallbackInfo<We akCallbackDataType>& data)
71 {
72 data.GetParameter()->deref();
73 }
74
75 void CompressibleStringCacheMapTraits::OnWeakCallback(const v8::WeakCallbackInfo <WeakCallbackDataType>& data)
76 {
77 }
78
79
57 void StringCache::dispose() 80 void StringCache::dispose()
58 { 81 {
59 // The MapType::Dispose callback calls StringCache::InvalidateLastString, 82 // The MapType::Dispose callback calls StringCache::InvalidateLastString,
60 // which will only work while the destructor has not yet finished. Thus, 83 // which will only work while the destructor has not yet finished. Thus,
61 // we need to clear the map before the destructor has completed. 84 // we need to clear the map before the destructor has completed.
62 m_stringCache.Clear(); 85 m_stringCache.Clear();
63 } 86 }
64 87
65 static v8::Local<v8::String> makeExternalString(v8::Isolate* isolate, const Stri ng& string) 88 static v8::Local<v8::String> makeExternalString(v8::Isolate* isolate, const Stri ng& string)
66 { 89 {
67 if (string.is8Bit()) { 90 if (string.is8Bit()) {
68 WebCoreStringResource8* stringResource = new WebCoreStringResource8(stri ng); 91 WebCoreStringResource8* stringResource = new WebCoreStringResource8(stri ng);
69 v8::Local<v8::String> newString; 92 v8::Local<v8::String> newString;
70 if (!v8::String::NewExternalOneByte(isolate, stringResource).ToLocal(&ne wString)) { 93 if (!v8::String::NewExternalOneByte(isolate, stringResource).ToLocal(&ne wString)) {
71 delete stringResource; 94 delete stringResource;
72 return v8::String::Empty(isolate); 95 return v8::String::Empty(isolate);
73 } 96 }
74 return newString; 97 return newString;
75 } 98 }
76 99
77 WebCoreStringResource16* stringResource = new WebCoreStringResource16(string ); 100 WebCoreStringResource16* stringResource = new WebCoreStringResource16(string );
78 v8::Local<v8::String> newString; 101 v8::Local<v8::String> newString;
79 if (!v8::String::NewExternalTwoByte(isolate, stringResource).ToLocal(&newStr ing)) { 102 if (!v8::String::NewExternalTwoByte(isolate, stringResource).ToLocal(&newStr ing)) {
80 delete stringResource; 103 delete stringResource;
81 return v8::String::Empty(isolate); 104 return v8::String::Empty(isolate);
82 } 105 }
83 return newString; 106 return newString;
84 } 107 }
85 108
109 static v8::Local<v8::String> makeExternalString(v8::Isolate* isolate, const Comp ressibleString& string)
110 {
111 if (string.is8Bit()) {
112 WebCoreCompressibleStringResource8* stringResource = new WebCoreCompress ibleStringResource8(string);
113 v8::Local<v8::String> newString;
114 if (!v8::String::NewExternalOneByte(isolate, stringResource).ToLocal(&ne wString)) {
115 delete stringResource;
116 return v8::String::Empty(isolate);
117 }
118 return newString;
119 }
120
121 WebCoreCompressibleStringResource16* stringResource = new WebCoreCompressibl eStringResource16(string);
122 v8::Local<v8::String> newString;
123 if (!v8::String::NewExternalTwoByte(isolate, stringResource).ToLocal(&newStr ing)) {
124 delete stringResource;
125 return v8::String::Empty(isolate);
126 }
127 return newString;
128 }
129
86 v8::Local<v8::String> StringCache::v8ExternalStringSlow(v8::Isolate* isolate, St ringImpl* stringImpl) 130 v8::Local<v8::String> StringCache::v8ExternalStringSlow(v8::Isolate* isolate, St ringImpl* stringImpl)
87 { 131 {
88 if (!stringImpl->length()) 132 if (!stringImpl->length())
89 return v8::String::Empty(isolate); 133 return v8::String::Empty(isolate);
90 134
91 StringCacheMapTraits::MapType::PersistentValueReference cachedV8String = m_s tringCache.GetReference(stringImpl); 135 StringCacheMapTraits::MapType::PersistentValueReference cachedV8String = m_s tringCache.GetReference(stringImpl);
92 if (!cachedV8String.IsEmpty()) { 136 if (!cachedV8String.IsEmpty()) {
93 m_lastStringImpl = stringImpl; 137 m_lastStringImpl = stringImpl;
94 m_lastV8String = cachedV8String; 138 m_lastV8String = cachedV8String;
95 return m_lastV8String.NewLocal(isolate); 139 return m_lastV8String.NewLocal(isolate);
96 } 140 }
97 141
98 return createStringAndInsertIntoCache(isolate, stringImpl); 142 return createStringAndInsertIntoCache(isolate, stringImpl);
99 } 143 }
100 144
145 v8::Local<v8::String> StringCache::v8ExternalStringSlow(v8::Isolate* isolate, co nst CompressibleString& string)
146 {
147 if (!string.length())
148 return v8::String::Empty(isolate);
149
150 CompressibleStringCacheMapTraits::MapType::PersistentValueReference cachedV8 String = m_compressibleStringCache.GetReference(string.impl());
151 if (!cachedV8String.IsEmpty())
152 return cachedV8String.NewLocal(isolate);
153
154 return createStringAndInsertIntoCache(isolate, string);
155 }
156
101 void StringCache::setReturnValueFromStringSlow(v8::ReturnValue<v8::Value> return Value, StringImpl* stringImpl) 157 void StringCache::setReturnValueFromStringSlow(v8::ReturnValue<v8::Value> return Value, StringImpl* stringImpl)
102 { 158 {
103 if (!stringImpl->length()) { 159 if (!stringImpl->length()) {
104 returnValue.SetEmptyString(); 160 returnValue.SetEmptyString();
105 return; 161 return;
106 } 162 }
107 163
108 StringCacheMapTraits::MapType::PersistentValueReference cachedV8String = m_s tringCache.GetReference(stringImpl); 164 StringCacheMapTraits::MapType::PersistentValueReference cachedV8String = m_s tringCache.GetReference(stringImpl);
109 if (!cachedV8String.IsEmpty()) { 165 if (!cachedV8String.IsEmpty()) {
110 m_lastStringImpl = stringImpl; 166 m_lastStringImpl = stringImpl;
(...skipping 17 matching lines...) Expand all
128 v8::UniquePersistent<v8::String> wrapper(isolate, newString); 184 v8::UniquePersistent<v8::String> wrapper(isolate, newString);
129 185
130 stringImpl->ref(); 186 stringImpl->ref();
131 wrapper.MarkIndependent(); 187 wrapper.MarkIndependent();
132 m_stringCache.Set(stringImpl, wrapper.Pass(), &m_lastV8String); 188 m_stringCache.Set(stringImpl, wrapper.Pass(), &m_lastV8String);
133 m_lastStringImpl = stringImpl; 189 m_lastStringImpl = stringImpl;
134 190
135 return newString; 191 return newString;
136 } 192 }
137 193
194 v8::Local<v8::String> StringCache::createStringAndInsertIntoCache(v8::Isolate* i solate, const CompressibleString& string)
195 {
196 CompressibleStringImpl* stringImpl = string.impl();
197
198 ASSERT(!m_compressibleStringCache.Contains(stringImpl));
199 ASSERT(stringImpl->originalLength());
200
201 v8::Local<v8::String> newString = makeExternalString(isolate, string);
202 ASSERT(!newString.IsEmpty());
203 ASSERT(newString->Length());
204
205 v8::UniquePersistent<v8::String> wrapper(isolate, newString);
206
207 stringImpl->ref();
208 wrapper.MarkIndependent();
209 // CompressibleStringImpl objects are NOT cached on |m_stringCache| or
210 // |m_lastStringImpl|. It's because if even one objects holds a StringImpl
211 // object in a CompressibleStringImpl, uncompressed string will exists even
212 // when compressing the string.
213 CompressibleStringCacheMapTraits::MapType::PersistentValueReference unused;
214 m_compressibleStringCache.Set(stringImpl, wrapper.Pass(), &unused);
215
216 return newString;
217 }
218
138 void StringCache::InvalidateLastString() 219 void StringCache::InvalidateLastString()
139 { 220 {
140 m_lastStringImpl = nullptr; 221 m_lastStringImpl = nullptr;
141 m_lastV8String.Reset(); 222 m_lastV8String.Reset();
142 } 223 }
143 224
144 } // namespace blink 225 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698