summaryrefslogtreecommitdiff
path: root/deps/v8/src/v8.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/v8.cc')
-rw-r--r--deps/v8/src/v8.cc136
1 files changed, 62 insertions, 74 deletions
diff --git a/deps/v8/src/v8.cc b/deps/v8/src/v8.cc
index 62330c32d4..28454b437e 100644
--- a/deps/v8/src/v8.cc
+++ b/deps/v8/src/v8.cc
@@ -36,6 +36,9 @@
#include "frames.h"
#include "heap-profiler.h"
#include "hydrogen.h"
+#ifdef V8_USE_DEFAULT_PLATFORM
+#include "libplatform/default-platform.h"
+#endif
#include "lithium-allocator.h"
#include "objects.h"
#include "once.h"
@@ -52,6 +55,7 @@ V8_DECLARE_ONCE(init_once);
List<CallCompletedCallback>* V8::call_completed_callbacks_ = NULL;
v8::ArrayBuffer::Allocator* V8::array_buffer_allocator_ = NULL;
+v8::Platform* V8::platform_ = NULL;
bool V8::Initialize(Deserializer* des) {
@@ -75,6 +79,11 @@ bool V8::Initialize(Deserializer* des) {
if (isolate->IsDead()) return false;
if (isolate->IsInitialized()) return true;
+#ifdef V8_USE_DEFAULT_PLATFORM
+ DefaultPlatform* platform = static_cast<DefaultPlatform*>(platform_);
+ platform->SetThreadPoolSize(isolate->max_available_threads());
+#endif
+
return isolate->Init(des);
}
@@ -90,6 +99,7 @@ void V8::TearDown() {
isolate->TearDown();
delete isolate;
+ Bootstrapper::TearDownExtensions();
ElementsAccessor::TearDown();
LOperand::TearDownCaches();
ExternalReference::TearDownMathExpData();
@@ -100,6 +110,12 @@ void V8::TearDown() {
call_completed_callbacks_ = NULL;
Sampler::TearDown();
+
+#ifdef V8_USE_DEFAULT_PLATFORM
+ DefaultPlatform* platform = static_cast<DefaultPlatform*>(platform_);
+ platform_ = NULL;
+ delete platform;
+#endif
}
@@ -109,25 +125,6 @@ void V8::SetReturnAddressLocationResolver(
}
-// Used by JavaScript APIs
-uint32_t V8::Random(Context* context) {
- ASSERT(context->IsNativeContext());
- ByteArray* seed = context->random_seed();
- uint32_t* state = reinterpret_cast<uint32_t*>(seed->GetDataStartAddress());
-
- // When we get here, the RNG must have been initialized,
- // see the Genesis constructor in file bootstrapper.cc.
- ASSERT_NE(0, state[0]);
- ASSERT_NE(0, state[1]);
-
- // Mix the bits. Never replaces state[i] with 0 if it is nonzero.
- state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16);
- state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16);
-
- return (state[0] << 14) + (state[1] & 0x3FFFF);
-}
-
-
void V8::AddCallCompletedCallback(CallCompletedCallback callback) {
if (call_completed_callbacks_ == NULL) { // Lazy init.
call_completed_callbacks_ = new List<CallCompletedCallback>();
@@ -151,17 +148,16 @@ void V8::RemoveCallCompletedCallback(CallCompletedCallback callback) {
void V8::FireCallCompletedCallback(Isolate* isolate) {
bool has_call_completed_callbacks = call_completed_callbacks_ != NULL;
- bool observer_delivery_pending =
- FLAG_harmony_observation && isolate->observer_delivery_pending();
- if (!has_call_completed_callbacks && !observer_delivery_pending) return;
+ bool run_microtasks = isolate->autorun_microtasks() &&
+ isolate->microtask_pending();
+ if (!has_call_completed_callbacks && !run_microtasks) return;
+
HandleScopeImplementer* handle_scope_implementer =
isolate->handle_scope_implementer();
if (!handle_scope_implementer->CallDepthIsZero()) return;
// Fire callbacks. Increase call depth to prevent recursive callbacks.
handle_scope_implementer->IncrementCallDepth();
- if (observer_delivery_pending) {
- JSObject::DeliverChangeRecords(isolate);
- }
+ if (run_microtasks) Execution::RunMicrotasks(isolate);
if (has_call_completed_callbacks) {
for (int i = 0; i < call_completed_callbacks_->length(); i++) {
call_completed_callbacks_->at(i)();
@@ -171,68 +167,41 @@ void V8::FireCallCompletedCallback(Isolate* isolate) {
}
-// Use a union type to avoid type-aliasing optimizations in GCC.
-typedef union {
- double double_value;
- uint64_t uint64_t_value;
-} double_int_union;
-
+void V8::RunMicrotasks(Isolate* isolate) {
+ if (!isolate->microtask_pending())
+ return;
-Object* V8::FillHeapNumberWithRandom(Object* heap_number,
- Context* context) {
- double_int_union r;
- uint64_t random_bits = Random(context);
- // Convert 32 random bits to 0.(32 random bits) in a double
- // by computing:
- // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
- static const double binary_million = 1048576.0;
- r.double_value = binary_million;
- r.uint64_t_value |= random_bits;
- r.double_value -= binary_million;
+ HandleScopeImplementer* handle_scope_implementer =
+ isolate->handle_scope_implementer();
+ ASSERT(handle_scope_implementer->CallDepthIsZero());
- HeapNumber::cast(heap_number)->set_value(r.double_value);
- return heap_number;
+ // Increase call depth to prevent recursive callbacks.
+ handle_scope_implementer->IncrementCallDepth();
+ Execution::RunMicrotasks(isolate);
+ handle_scope_implementer->DecrementCallDepth();
}
void V8::InitializeOncePerProcessImpl() {
FlagList::EnforceFlagImplications();
- if (FLAG_stress_compaction) {
- FLAG_force_marking_deque_overflows = true;
- FLAG_gc_global = true;
- FLAG_max_new_space_size = (1 << (kPageSizeBits - 10)) * 2;
- }
- if (FLAG_concurrent_recompilation &&
- (FLAG_trace_hydrogen || FLAG_trace_hydrogen_stubs)) {
- FLAG_concurrent_recompilation = false;
- PrintF("Concurrent recompilation has been disabled for tracing.\n");
- }
-
- if (FLAG_sweeper_threads <= 0) {
- if (FLAG_concurrent_sweeping) {
- FLAG_sweeper_threads = SystemThreadManager::
- NumberOfParallelSystemThreads(
- SystemThreadManager::CONCURRENT_SWEEPING);
- } else if (FLAG_parallel_sweeping) {
- FLAG_sweeper_threads = SystemThreadManager::
- NumberOfParallelSystemThreads(
- SystemThreadManager::PARALLEL_SWEEPING);
- }
- if (FLAG_sweeper_threads == 0) {
- FLAG_concurrent_sweeping = false;
- FLAG_parallel_sweeping = false;
+ if (FLAG_predictable) {
+ if (FLAG_random_seed == 0) {
+ // Avoid random seeds in predictable mode.
+ FLAG_random_seed = 12347;
}
- } else if (!FLAG_concurrent_sweeping && !FLAG_parallel_sweeping) {
- FLAG_sweeper_threads = 0;
+ FLAG_hash_seed = 0;
}
- if (FLAG_concurrent_recompilation &&
- SystemThreadManager::NumberOfParallelSystemThreads(
- SystemThreadManager::PARALLEL_RECOMPILATION) == 0) {
- FLAG_concurrent_recompilation = false;
+ if (FLAG_stress_compaction) {
+ FLAG_force_marking_deque_overflows = true;
+ FLAG_gc_global = true;
+ FLAG_max_new_space_size = (1 << (kPageSizeBits - 10)) * 2;
}
+#ifdef V8_USE_DEFAULT_PLATFORM
+ platform_ = new DefaultPlatform;
+#endif
Sampler::SetUp();
CPU::SetUp();
OS::PostSetUp();
@@ -248,4 +217,23 @@ void V8::InitializeOncePerProcess() {
CallOnce(&init_once, &InitializeOncePerProcessImpl);
}
+
+void V8::InitializePlatform(v8::Platform* platform) {
+ ASSERT(!platform_);
+ ASSERT(platform);
+ platform_ = platform;
+}
+
+
+void V8::ShutdownPlatform() {
+ ASSERT(platform_);
+ platform_ = NULL;
+}
+
+
+v8::Platform* V8::GetCurrentPlatform() {
+ ASSERT(platform_);
+ return platform_;
+}
+
} } // namespace v8::internal