| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/api.h" | 5 #include "src/api.h" |
| 6 | 6 |
| 7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
| 8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
| 9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
| 10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 if (virtual_memory_limit > 0 && i::kRequiresCodeRange) { | 464 if (virtual_memory_limit > 0 && i::kRequiresCodeRange) { |
| 465 // Reserve no more than 1/8 of the memory for the code range, but at most | 465 // Reserve no more than 1/8 of the memory for the code range, but at most |
| 466 // kMaximalCodeRangeSize. | 466 // kMaximalCodeRangeSize. |
| 467 set_code_range_size( | 467 set_code_range_size( |
| 468 i::Min(i::kMaximalCodeRangeSize / i::MB, | 468 i::Min(i::kMaximalCodeRangeSize / i::MB, |
| 469 static_cast<size_t>((virtual_memory_limit >> 3) / i::MB))); | 469 static_cast<size_t>((virtual_memory_limit >> 3) / i::MB))); |
| 470 } | 470 } |
| 471 } | 471 } |
| 472 | 472 |
| 473 | 473 |
| 474 bool SetResourceConstraints(Isolate* v8_isolate, | 474 void SetResourceConstraints(i::Isolate* isolate, |
| 475 ResourceConstraints* constraints) { | 475 const ResourceConstraints& constraints) { |
| 476 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 476 int semi_space_size = constraints.max_semi_space_size(); |
| 477 int semi_space_size = constraints->max_semi_space_size(); | 477 int old_space_size = constraints.max_old_space_size(); |
| 478 int old_space_size = constraints->max_old_space_size(); | 478 int max_executable_size = constraints.max_executable_size(); |
| 479 int max_executable_size = constraints->max_executable_size(); | 479 size_t code_range_size = constraints.code_range_size(); |
| 480 size_t code_range_size = constraints->code_range_size(); | |
| 481 if (semi_space_size != 0 || old_space_size != 0 || | 480 if (semi_space_size != 0 || old_space_size != 0 || |
| 482 max_executable_size != 0 || code_range_size != 0) { | 481 max_executable_size != 0 || code_range_size != 0) { |
| 483 // After initialization it's too late to change Heap constraints. | 482 isolate->heap()->ConfigureHeap(semi_space_size, old_space_size, |
| 484 DCHECK(!isolate->IsInitialized()); | 483 max_executable_size, code_range_size); |
| 485 bool result = isolate->heap()->ConfigureHeap(semi_space_size, | |
| 486 old_space_size, | |
| 487 max_executable_size, | |
| 488 code_range_size); | |
| 489 if (!result) return false; | |
| 490 } | 484 } |
| 491 if (constraints->stack_limit() != NULL) { | 485 if (constraints.stack_limit() != NULL) { |
| 492 uintptr_t limit = reinterpret_cast<uintptr_t>(constraints->stack_limit()); | 486 uintptr_t limit = reinterpret_cast<uintptr_t>(constraints.stack_limit()); |
| 493 isolate->stack_guard()->SetStackLimit(limit); | 487 isolate->stack_guard()->SetStackLimit(limit); |
| 494 } | 488 } |
| 495 | 489 |
| 496 isolate->set_max_available_threads(constraints->max_available_threads()); | 490 isolate->set_max_available_threads(constraints.max_available_threads()); |
| 497 return true; | |
| 498 } | 491 } |
| 499 | 492 |
| 500 | 493 |
| 501 i::Object** V8::GlobalizeReference(i::Isolate* isolate, i::Object** obj) { | 494 i::Object** V8::GlobalizeReference(i::Isolate* isolate, i::Object** obj) { |
| 502 LOG_API(isolate, "Persistent::New"); | 495 LOG_API(isolate, "Persistent::New"); |
| 503 i::Handle<i::Object> result = isolate->global_handles()->Create(*obj); | 496 i::Handle<i::Object> result = isolate->global_handles()->Create(*obj); |
| 504 #ifdef DEBUG | 497 #ifdef DEBUG |
| 505 (*obj)->ObjectVerify(); | 498 (*obj)->ObjectVerify(); |
| 506 #endif // DEBUG | 499 #endif // DEBUG |
| 507 return result.location(); | 500 return result.location(); |
| (...skipping 4550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5058 void v8::V8::SetEntropySource(EntropySource entropy_source) { | 5051 void v8::V8::SetEntropySource(EntropySource entropy_source) { |
| 5059 base::RandomNumberGenerator::SetEntropySource(entropy_source); | 5052 base::RandomNumberGenerator::SetEntropySource(entropy_source); |
| 5060 } | 5053 } |
| 5061 | 5054 |
| 5062 | 5055 |
| 5063 void v8::V8::SetReturnAddressLocationResolver( | 5056 void v8::V8::SetReturnAddressLocationResolver( |
| 5064 ReturnAddressLocationResolver return_address_resolver) { | 5057 ReturnAddressLocationResolver return_address_resolver) { |
| 5065 i::V8::SetReturnAddressLocationResolver(return_address_resolver); | 5058 i::V8::SetReturnAddressLocationResolver(return_address_resolver); |
| 5066 } | 5059 } |
| 5067 | 5060 |
| 5068 | |
| 5069 bool v8::V8::SetFunctionEntryHook(Isolate* ext_isolate, | |
| 5070 FunctionEntryHook entry_hook) { | |
| 5071 DCHECK(ext_isolate != NULL); | |
| 5072 DCHECK(entry_hook != NULL); | |
| 5073 | |
| 5074 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(ext_isolate); | |
| 5075 | |
| 5076 // The entry hook can only be set before the Isolate is initialized, as | |
| 5077 // otherwise the Isolate's code stubs generated at initialization won't | |
| 5078 // contain entry hooks. | |
| 5079 if (isolate->IsInitialized()) | |
| 5080 return false; | |
| 5081 | |
| 5082 // Setting an entry hook is a one-way operation, once set, it cannot be | |
| 5083 // changed or unset. | |
| 5084 if (isolate->function_entry_hook() != NULL) | |
| 5085 return false; | |
| 5086 | |
| 5087 isolate->set_function_entry_hook(entry_hook); | |
| 5088 return true; | |
| 5089 } | |
| 5090 | |
| 5091 | |
| 5092 void v8::V8::SetJitCodeEventHandler( | |
| 5093 JitCodeEventOptions options, JitCodeEventHandler event_handler) { | |
| 5094 i::Isolate* isolate = i::Isolate::Current(); | |
| 5095 // Ensure that logging is initialized for our isolate. | |
| 5096 isolate->InitializeLoggingAndCounters(); | |
| 5097 isolate->logger()->SetCodeEventHandler(options, event_handler); | |
| 5098 } | |
| 5099 | |
| 5100 void v8::V8::SetArrayBufferAllocator( | 5061 void v8::V8::SetArrayBufferAllocator( |
| 5101 ArrayBuffer::Allocator* allocator) { | 5062 ArrayBuffer::Allocator* allocator) { |
| 5102 if (!Utils::ApiCheck(i::V8::ArrayBufferAllocator() == NULL, | 5063 if (!Utils::ApiCheck(i::V8::ArrayBufferAllocator() == NULL, |
| 5103 "v8::V8::SetArrayBufferAllocator", | 5064 "v8::V8::SetArrayBufferAllocator", |
| 5104 "ArrayBufferAllocator might only be set once")) | 5065 "ArrayBufferAllocator might only be set once")) |
| 5105 return; | 5066 return; |
| 5106 i::V8::SetArrayBufferAllocator(allocator); | 5067 i::V8::SetArrayBufferAllocator(allocator); |
| 5107 } | 5068 } |
| 5108 | 5069 |
| 5109 | 5070 |
| (...skipping 1499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6609 i::Isolate* isolate = new i::Isolate(); | 6570 i::Isolate* isolate = new i::Isolate(); |
| 6610 Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate); | 6571 Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate); |
| 6611 if (params.entry_hook) { | 6572 if (params.entry_hook) { |
| 6612 isolate->set_function_entry_hook(params.entry_hook); | 6573 isolate->set_function_entry_hook(params.entry_hook); |
| 6613 } | 6574 } |
| 6614 if (params.code_event_handler) { | 6575 if (params.code_event_handler) { |
| 6615 isolate->InitializeLoggingAndCounters(); | 6576 isolate->InitializeLoggingAndCounters(); |
| 6616 isolate->logger()->SetCodeEventHandler(kJitCodeEventDefault, | 6577 isolate->logger()->SetCodeEventHandler(kJitCodeEventDefault, |
| 6617 params.code_event_handler); | 6578 params.code_event_handler); |
| 6618 } | 6579 } |
| 6619 SetResourceConstraints(v8_isolate, | 6580 SetResourceConstraints(isolate, params.constraints); |
| 6620 const_cast<ResourceConstraints*>(¶ms.constraints)); | |
| 6621 if (params.enable_serializer) { | 6581 if (params.enable_serializer) { |
| 6622 isolate->enable_serializer(); | 6582 isolate->enable_serializer(); |
| 6623 } | 6583 } |
| 6624 // TODO(jochen): Once we got rid of Isolate::Current(), we can remove this. | 6584 // TODO(jochen): Once we got rid of Isolate::Current(), we can remove this. |
| 6625 Isolate::Scope isolate_scope(v8_isolate); | 6585 Isolate::Scope isolate_scope(v8_isolate); |
| 6626 if (params.entry_hook || !i::Snapshot::Initialize(isolate)) { | 6586 if (params.entry_hook || !i::Snapshot::Initialize(isolate)) { |
| 6627 // If the isolate has a function entry hook, it needs to re-build all its | 6587 // If the isolate has a function entry hook, it needs to re-build all its |
| 6628 // code stubs with entry hooks embedded, so don't deserialize a snapshot. | 6588 // code stubs with entry hooks embedded, so don't deserialize a snapshot. |
| 6629 isolate->Init(NULL); | 6589 isolate->Init(NULL); |
| 6630 } | 6590 } |
| (...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7695 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7655 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
| 7696 Address callback_address = | 7656 Address callback_address = |
| 7697 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7657 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 7698 VMState<EXTERNAL> state(isolate); | 7658 VMState<EXTERNAL> state(isolate); |
| 7699 ExternalCallbackScope call_scope(isolate, callback_address); | 7659 ExternalCallbackScope call_scope(isolate, callback_address); |
| 7700 callback(info); | 7660 callback(info); |
| 7701 } | 7661 } |
| 7702 | 7662 |
| 7703 | 7663 |
| 7704 } } // namespace v8::internal | 7664 } } // namespace v8::internal |
| OLD | NEW |