| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 204 |
| 205 | 205 |
| 206 Handle<Object> GetProperty(Isolate* isolate, | 206 Handle<Object> GetProperty(Isolate* isolate, |
| 207 Handle<Object> obj, | 207 Handle<Object> obj, |
| 208 Handle<Object> key) { | 208 Handle<Object> key) { |
| 209 CALL_HEAP_FUNCTION(isolate, | 209 CALL_HEAP_FUNCTION(isolate, |
| 210 Runtime::GetObjectProperty(isolate, obj, key), Object); | 210 Runtime::GetObjectProperty(isolate, obj, key), Object); |
| 211 } | 211 } |
| 212 | 212 |
| 213 | 213 |
| 214 Handle<Object> LookupSingleCharacterStringFromCode(Isolate* isolate, | 214 Handle<String> LookupSingleCharacterStringFromCode(Isolate* isolate, |
| 215 uint32_t index) { | 215 uint32_t index) { |
| 216 CALL_HEAP_FUNCTION( | 216 CALL_HEAP_FUNCTION( |
| 217 isolate, | 217 isolate, |
| 218 isolate->heap()->LookupSingleCharacterStringFromCode(index), Object); | 218 isolate->heap()->LookupSingleCharacterStringFromCode(index), |
| 219 String); |
| 219 } | 220 } |
| 220 | 221 |
| 221 | 222 |
| 222 // Wrappers for scripts are kept alive and cached in weak global | 223 // Wrappers for scripts are kept alive and cached in weak global |
| 223 // handles referred from foreign objects held by the scripts as long as | 224 // handles referred from foreign objects held by the scripts as long as |
| 224 // they are used. When they are not used anymore, the garbage | 225 // they are used. When they are not used anymore, the garbage |
| 225 // collector will call the weak callback on the global handle | 226 // collector will call the weak callback on the global handle |
| 226 // associated with the wrapper and get rid of both the wrapper and the | 227 // associated with the wrapper and get rid of both the wrapper and the |
| 227 // handle. | 228 // handle. |
| 228 static void ClearWrapperCache(v8::Isolate* v8_isolate, | 229 static void ClearWrapperCache( |
| 229 Persistent<v8::Value>* handle, | 230 const v8::WeakCallbackData<v8::Value, void>& data) { |
| 230 void*) { | 231 Object** location = reinterpret_cast<Object**>(data.GetParameter()); |
| 231 Handle<Object> cache = Utils::OpenPersistent(handle); | 232 JSValue* wrapper = JSValue::cast(*location); |
| 232 JSValue* wrapper = JSValue::cast(*cache); | |
| 233 Foreign* foreign = Script::cast(wrapper->value())->wrapper(); | 233 Foreign* foreign = Script::cast(wrapper->value())->wrapper(); |
| 234 ASSERT(foreign->foreign_address() == | 234 ASSERT_EQ(foreign->foreign_address(), reinterpret_cast<Address>(location)); |
| 235 reinterpret_cast<Address>(cache.location())); | |
| 236 foreign->set_foreign_address(0); | 235 foreign->set_foreign_address(0); |
| 237 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | 236 GlobalHandles::Destroy(location); |
| 238 isolate->global_handles()->Destroy(cache.location()); | 237 Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate()); |
| 239 isolate->counters()->script_wrappers()->Decrement(); | 238 isolate->counters()->script_wrappers()->Decrement(); |
| 240 } | 239 } |
| 241 | 240 |
| 242 | 241 |
| 243 Handle<JSValue> GetScriptWrapper(Handle<Script> script) { | 242 Handle<JSValue> GetScriptWrapper(Handle<Script> script) { |
| 244 if (script->wrapper()->foreign_address() != NULL) { | 243 if (script->wrapper()->foreign_address() != NULL) { |
| 245 // Return a handle for the existing script wrapper from the cache. | 244 // Return a handle for the existing script wrapper from the cache. |
| 246 return Handle<JSValue>( | 245 return Handle<JSValue>( |
| 247 *reinterpret_cast<JSValue**>(script->wrapper()->foreign_address())); | 246 *reinterpret_cast<JSValue**>(script->wrapper()->foreign_address())); |
| 248 } | 247 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 260 return Handle<JSValue>( | 259 return Handle<JSValue>( |
| 261 *reinterpret_cast<JSValue**>(script->wrapper()->foreign_address())); | 260 *reinterpret_cast<JSValue**>(script->wrapper()->foreign_address())); |
| 262 } | 261 } |
| 263 | 262 |
| 264 result->set_value(*script); | 263 result->set_value(*script); |
| 265 | 264 |
| 266 // Create a new weak global handle and use it to cache the wrapper | 265 // Create a new weak global handle and use it to cache the wrapper |
| 267 // for future use. The cache will automatically be cleared by the | 266 // for future use. The cache will automatically be cleared by the |
| 268 // garbage collector when it is not used anymore. | 267 // garbage collector when it is not used anymore. |
| 269 Handle<Object> handle = isolate->global_handles()->Create(*result); | 268 Handle<Object> handle = isolate->global_handles()->Create(*result); |
| 270 isolate->global_handles()->MakeWeak(handle.location(), | 269 GlobalHandles::MakeWeak(handle.location(), |
| 271 NULL, | 270 reinterpret_cast<void*>(handle.location()), |
| 272 &ClearWrapperCache); | 271 &ClearWrapperCache); |
| 273 script->wrapper()->set_foreign_address( | 272 script->wrapper()->set_foreign_address( |
| 274 reinterpret_cast<Address>(handle.location())); | 273 reinterpret_cast<Address>(handle.location())); |
| 275 return result; | 274 return result; |
| 276 } | 275 } |
| 277 | 276 |
| 278 | 277 |
| 279 // Init line_ends array with code positions of line ends inside script | 278 // Init line_ends array with code positions of line ends inside script |
| 280 // source. | 279 // source. |
| 281 void InitScriptLineEnds(Handle<Script> script) { | 280 void InitScriptLineEnds(Handle<Script> script) { |
| 282 if (!script->line_ends()->IsUndefined()) return; | 281 if (!script->line_ends()->IsUndefined()) return; |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 Handle<Code> code) { | 794 Handle<Code> code) { |
| 796 heap->EnsureWeakObjectToCodeTable(); | 795 heap->EnsureWeakObjectToCodeTable(); |
| 797 Handle<DependentCode> dep(heap->LookupWeakObjectToCodeDependency(*object)); | 796 Handle<DependentCode> dep(heap->LookupWeakObjectToCodeDependency(*object)); |
| 798 dep = DependentCode::Insert(dep, DependentCode::kWeaklyEmbeddedGroup, code); | 797 dep = DependentCode::Insert(dep, DependentCode::kWeaklyEmbeddedGroup, code); |
| 799 CALL_HEAP_FUNCTION_VOID(heap->isolate(), | 798 CALL_HEAP_FUNCTION_VOID(heap->isolate(), |
| 800 heap->AddWeakObjectToCodeDependency(*object, *dep)); | 799 heap->AddWeakObjectToCodeDependency(*object, *dep)); |
| 801 } | 800 } |
| 802 | 801 |
| 803 | 802 |
| 804 } } // namespace v8::internal | 803 } } // namespace v8::internal |
| OLD | NEW |