| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 RELEASE_ASSERT(containsWrapper()); | 157 RELEASE_ASSERT(containsWrapper()); |
| 158 m_wrapper.Reset(); | 158 m_wrapper.Reset(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 static void firstWeakCallback(const v8::WeakCallbackInfo<ScriptWrappable>& d
ata) | 161 static void firstWeakCallback(const v8::WeakCallbackInfo<ScriptWrappable>& d
ata) |
| 162 { | 162 { |
| 163 auto scriptWrappable = data.GetParameter(); | 163 auto scriptWrappable = data.GetParameter(); |
| 164 scriptWrappable->disposeWrapper(data); | 164 scriptWrappable->disposeWrapper(data); |
| 165 | 165 |
| 166 auto wrapperTypeInfo = reinterpret_cast<WrapperTypeInfo*>(data.GetIntern
alField(v8DOMWrapperTypeIndex)); | 166 auto wrapperTypeInfo = reinterpret_cast<WrapperTypeInfo*>(data.GetIntern
alField(v8DOMWrapperTypeIndex)); |
| 167 if (wrapperTypeInfo->isGarbageCollected()) { | 167 // derefObject() for garbage collected objects is very cheap, so |
| 168 // derefObject() for garbage collected objects is very cheap, so | 168 // we don't delay derefObject to any second pass. |
| 169 // we don't delay derefObject to the second pass. | 169 // |
| 170 // | 170 // More importantly, we've already disposed the wrapper at this |
| 171 // More importantly, we've already disposed the wrapper at this | 171 // moment, so the ScriptWrappable may have already been collected |
| 172 // moment, so the ScriptWrappable may have already been collected | 172 // by GC by the second pass. |
| 173 // by GC by the second pass. We shouldn't use a pointer to the | 173 wrapperTypeInfo->derefObject(); |
| 174 // ScriptWrappable in secondWeakCallback in case of garbage | |
| 175 // collected objects. Thus calls derefObject right now. | |
| 176 wrapperTypeInfo->derefObject(scriptWrappable); | |
| 177 } else { | |
| 178 // For reference counted objects, let's delay the destruction of | |
| 179 // the object to the second pass. | |
| 180 data.SetSecondPassCallback(secondWeakCallback); | |
| 181 } | |
| 182 } | |
| 183 | |
| 184 static void secondWeakCallback(const v8::WeakCallbackInfo<ScriptWrappable>&
data) | |
| 185 { | |
| 186 // FIXME: I noticed that 50%~ of minor GC cycle times can be consumed | |
| 187 // inside data.GetParameter()->deref(), which causes Node destructions.
We should | |
| 188 // make Node destructions incremental. | |
| 189 auto scriptWrappable = reinterpret_cast<ScriptWrappable*>(data.GetIntern
alField(v8DOMWrapperObjectIndex)); | |
| 190 auto wrapperTypeInfo = reinterpret_cast<WrapperTypeInfo*>(data.GetIntern
alField(v8DOMWrapperTypeIndex)); | |
| 191 wrapperTypeInfo->derefObject(scriptWrappable); | |
| 192 } | 174 } |
| 193 | 175 |
| 194 v8::Persistent<v8::Object> m_wrapper; | 176 v8::Persistent<v8::Object> m_wrapper; |
| 195 }; | 177 }; |
| 196 | 178 |
| 197 // Defines 'wrapperTypeInfo' virtual method which returns the WrapperTypeInfo of | 179 // Defines 'wrapperTypeInfo' virtual method which returns the WrapperTypeInfo of |
| 198 // the instance. Also declares a static member of type WrapperTypeInfo, of which | 180 // the instance. Also declares a static member of type WrapperTypeInfo, of which |
| 199 // the definition is given by the IDL code generator. | 181 // the definition is given by the IDL code generator. |
| 200 // | 182 // |
| 201 // All the derived classes of ScriptWrappable, regardless of directly or | 183 // All the derived classes of ScriptWrappable, regardless of directly or |
| (...skipping 20 matching lines...) Expand all Loading... |
| 222 // in X's cpp code, and instantiate X, i.e. "template class X;". | 204 // in X's cpp code, and instantiate X, i.e. "template class X;". |
| 223 #define DECLARE_WRAPPERTYPEINFO() \ | 205 #define DECLARE_WRAPPERTYPEINFO() \ |
| 224 public: \ | 206 public: \ |
| 225 const WrapperTypeInfo* wrapperTypeInfo() const override; \ | 207 const WrapperTypeInfo* wrapperTypeInfo() const override; \ |
| 226 private: \ | 208 private: \ |
| 227 typedef void end_of_define_wrappertypeinfo_not_reached_t | 209 typedef void end_of_define_wrappertypeinfo_not_reached_t |
| 228 | 210 |
| 229 } // namespace blink | 211 } // namespace blink |
| 230 | 212 |
| 231 #endif // ScriptWrappable_h | 213 #endif // ScriptWrappable_h |
| OLD | NEW |