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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 } | 293 } |
294 | 294 |
295 | 295 |
296 static inline bool EmptyCheck(const char* location, const v8::Data* obj) { | 296 static inline bool EmptyCheck(const char* location, const v8::Data* obj) { |
297 return (obj == 0) ? ReportEmptyHandle(location) : false; | 297 return (obj == 0) ? ReportEmptyHandle(location) : false; |
298 } | 298 } |
299 | 299 |
300 // --- S t a t i c s --- | 300 // --- S t a t i c s --- |
301 | 301 |
302 | 302 |
303 static bool InitializeHelper() { | 303 static bool InitializeHelper(i::Isolate* isolate) { |
304 if (i::Snapshot::Initialize()) return true; | 304 // If the isolate has a function entry hook, it needs to re-build all its |
| 305 // code stubs with entry hooks embedded, so let's deserialize a snapshot. |
| 306 if (isolate == NULL || isolate->function_entry_hook() == NULL) { |
| 307 if (i::Snapshot::Initialize()) |
| 308 return true; |
| 309 } |
305 return i::V8::Initialize(NULL); | 310 return i::V8::Initialize(NULL); |
306 } | 311 } |
307 | 312 |
308 | 313 |
309 static inline bool EnsureInitializedForIsolate(i::Isolate* isolate, | 314 static inline bool EnsureInitializedForIsolate(i::Isolate* isolate, |
310 const char* location) { | 315 const char* location) { |
311 if (IsDeadCheck(isolate, location)) return false; | 316 if (IsDeadCheck(isolate, location)) return false; |
312 if (isolate != NULL) { | 317 if (isolate != NULL) { |
313 if (isolate->IsInitialized()) return true; | 318 if (isolate->IsInitialized()) return true; |
314 } | 319 } |
315 ASSERT(isolate == i::Isolate::Current()); | 320 ASSERT(isolate == i::Isolate::Current()); |
316 return ApiCheck(InitializeHelper(), location, "Error initializing V8"); | 321 return ApiCheck(InitializeHelper(isolate), location, "Error initializing V8"); |
317 } | 322 } |
318 | 323 |
319 // Some initializing API functions are called early and may be | 324 // Some initializing API functions are called early and may be |
320 // called on a thread different from static initializer thread. | 325 // called on a thread different from static initializer thread. |
321 // If Isolate API is used, Isolate::Enter() will initialize TLS so | 326 // If Isolate API is used, Isolate::Enter() will initialize TLS so |
322 // Isolate::Current() works. If it's a legacy case, then the thread | 327 // Isolate::Current() works. If it's a legacy case, then the thread |
323 // may not have TLS initialized yet. However, in initializing APIs it | 328 // may not have TLS initialized yet. However, in initializing APIs it |
324 // may be too early to call EnsureInitialized() - some pre-init | 329 // may be too early to call EnsureInitialized() - some pre-init |
325 // parameters still have to be configured. | 330 // parameters still have to be configured. |
326 static inline i::Isolate* EnterIsolateIfNeeded() { | 331 static inline i::Isolate* EnterIsolateIfNeeded() { |
(...skipping 4877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5204 | 5209 |
5205 | 5210 |
5206 // --- E n v i r o n m e n t --- | 5211 // --- E n v i r o n m e n t --- |
5207 | 5212 |
5208 | 5213 |
5209 bool v8::V8::Initialize() { | 5214 bool v8::V8::Initialize() { |
5210 i::Isolate* isolate = i::Isolate::UncheckedCurrent(); | 5215 i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
5211 if (isolate != NULL && isolate->IsInitialized()) { | 5216 if (isolate != NULL && isolate->IsInitialized()) { |
5212 return true; | 5217 return true; |
5213 } | 5218 } |
5214 return InitializeHelper(); | 5219 return InitializeHelper(isolate); |
5215 } | 5220 } |
5216 | 5221 |
5217 | 5222 |
5218 void v8::V8::SetEntropySource(EntropySource source) { | 5223 void v8::V8::SetEntropySource(EntropySource source) { |
5219 i::V8::SetEntropySource(source); | 5224 i::V8::SetEntropySource(source); |
5220 } | 5225 } |
5221 | 5226 |
5222 | 5227 |
5223 void v8::V8::SetReturnAddressLocationResolver( | 5228 void v8::V8::SetReturnAddressLocationResolver( |
5224 ReturnAddressLocationResolver return_address_resolver) { | 5229 ReturnAddressLocationResolver return_address_resolver) { |
5225 i::V8::SetReturnAddressLocationResolver(return_address_resolver); | 5230 i::V8::SetReturnAddressLocationResolver(return_address_resolver); |
5226 } | 5231 } |
5227 | 5232 |
5228 | 5233 |
5229 bool v8::V8::SetFunctionEntryHook(FunctionEntryHook entry_hook) { | 5234 bool v8::V8::SetFunctionEntryHook(FunctionEntryHook entry_hook) { |
5230 return i::ProfileEntryHookStub::SetFunctionEntryHook(entry_hook); | 5235 return SetFunctionEntryHook(Isolate::GetCurrent(), entry_hook); |
5231 } | 5236 } |
5232 | 5237 |
5233 | 5238 |
| 5239 bool v8::V8::SetFunctionEntryHook(Isolate* ext_isolate, |
| 5240 FunctionEntryHook entry_hook) { |
| 5241 ASSERT(ext_isolate != NULL); |
| 5242 ASSERT(entry_hook != NULL); |
| 5243 |
| 5244 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(ext_isolate); |
| 5245 |
| 5246 // The entry hook can only be set before the Isolate is initialized, as |
| 5247 // otherwise the Isolate's code stubs generated at initialization won't |
| 5248 // contain entry hooks. |
| 5249 if (isolate->IsInitialized()) |
| 5250 return false; |
| 5251 |
| 5252 // Setting an entry hook is a one-way operation, once set, it cannot be |
| 5253 // changed or unset. |
| 5254 if (isolate->function_entry_hook() != NULL) |
| 5255 return false; |
| 5256 |
| 5257 isolate->set_function_entry_hook(entry_hook); |
| 5258 return true; |
| 5259 } |
| 5260 |
| 5261 |
5234 void v8::V8::SetJitCodeEventHandler( | 5262 void v8::V8::SetJitCodeEventHandler( |
5235 JitCodeEventOptions options, JitCodeEventHandler event_handler) { | 5263 JitCodeEventOptions options, JitCodeEventHandler event_handler) { |
5236 i::Isolate* isolate = i::Isolate::Current(); | 5264 i::Isolate* isolate = i::Isolate::Current(); |
5237 // Ensure that logging is initialized for our isolate. | 5265 // Ensure that logging is initialized for our isolate. |
5238 isolate->InitializeLoggingAndCounters(); | 5266 isolate->InitializeLoggingAndCounters(); |
5239 isolate->logger()->SetCodeEventHandler(options, event_handler); | 5267 isolate->logger()->SetCodeEventHandler(options, event_handler); |
5240 } | 5268 } |
5241 | 5269 |
5242 void v8::V8::SetArrayBufferAllocator( | 5270 void v8::V8::SetArrayBufferAllocator( |
5243 ArrayBuffer::Allocator* allocator) { | 5271 ArrayBuffer::Allocator* allocator) { |
(...skipping 2747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7991 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 8019 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7992 Address callback_address = | 8020 Address callback_address = |
7993 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8021 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7994 VMState<EXTERNAL> state(isolate); | 8022 VMState<EXTERNAL> state(isolate); |
7995 ExternalCallbackScope call_scope(isolate, callback_address); | 8023 ExternalCallbackScope call_scope(isolate, callback_address); |
7996 return callback(info); | 8024 return callback(info); |
7997 } | 8025 } |
7998 | 8026 |
7999 | 8027 |
8000 } } // namespace v8::internal | 8028 } } // namespace v8::internal |
OLD | NEW |