2012-01-18 16:16:11 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2011-03-18 20:35:07 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/v8.h"
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/ast.h"
|
2014-06-30 13:25:46 +00:00
|
|
|
#include "src/base/platform/platform.h"
|
|
|
|
#include "src/base/utils/random-number-generator.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/bootstrapper.h"
|
|
|
|
#include "src/codegen.h"
|
|
|
|
#include "src/compilation-cache.h"
|
|
|
|
#include "src/cpu-profiler.h"
|
|
|
|
#include "src/debug.h"
|
|
|
|
#include "src/deoptimizer.h"
|
|
|
|
#include "src/heap-profiler.h"
|
|
|
|
#include "src/hydrogen.h"
|
|
|
|
#include "src/isolate-inl.h"
|
|
|
|
#include "src/lithium-allocator.h"
|
|
|
|
#include "src/log.h"
|
|
|
|
#include "src/messages.h"
|
|
|
|
#include "src/regexp-stack.h"
|
|
|
|
#include "src/runtime-profiler.h"
|
|
|
|
#include "src/sampler.h"
|
|
|
|
#include "src/scopeinfo.h"
|
|
|
|
#include "src/serialize.h"
|
|
|
|
#include "src/simulator.h"
|
|
|
|
#include "src/spaces.h"
|
|
|
|
#include "src/stub-cache.h"
|
|
|
|
#include "src/sweeper-thread.h"
|
|
|
|
#include "src/version.h"
|
|
|
|
#include "src/vm-state-inl.h"
|
2011-03-18 20:35:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2014-06-05 12:14:47 +00:00
|
|
|
base::Atomic32 ThreadId::highest_thread_id_ = 0;
|
2011-04-11 23:46:22 +00:00
|
|
|
|
|
|
|
int ThreadId::AllocateThreadId() {
|
2014-06-05 12:14:47 +00:00
|
|
|
int new_id = base::NoBarrier_AtomicIncrement(&highest_thread_id_, 1);
|
2011-04-11 23:46:22 +00:00
|
|
|
return new_id;
|
|
|
|
}
|
|
|
|
|
2011-05-13 08:54:16 +00:00
|
|
|
|
2011-04-11 23:46:22 +00:00
|
|
|
int ThreadId::GetCurrentThreadId() {
|
2014-06-30 13:25:46 +00:00
|
|
|
int thread_id = base::Thread::GetThreadLocalInt(Isolate::thread_id_key_);
|
2011-04-11 23:46:22 +00:00
|
|
|
if (thread_id == 0) {
|
|
|
|
thread_id = AllocateThreadId();
|
2014-06-30 13:25:46 +00:00
|
|
|
base::Thread::SetThreadLocalInt(Isolate::thread_id_key_, thread_id);
|
2011-04-11 23:46:22 +00:00
|
|
|
}
|
|
|
|
return thread_id;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2011-05-13 08:54:16 +00:00
|
|
|
|
|
|
|
ThreadLocalTop::ThreadLocalTop() {
|
|
|
|
InitializeInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ThreadLocalTop::InitializeInternal() {
|
|
|
|
c_entry_fp_ = 0;
|
|
|
|
handler_ = 0;
|
|
|
|
#ifdef USE_SIMULATOR
|
|
|
|
simulator_ = NULL;
|
|
|
|
#endif
|
|
|
|
js_entry_sp_ = NULL;
|
2013-07-23 15:01:38 +00:00
|
|
|
external_callback_scope_ = NULL;
|
2011-05-13 08:54:16 +00:00
|
|
|
current_vm_state_ = EXTERNAL;
|
2014-05-20 10:13:46 +00:00
|
|
|
try_catch_handler_ = NULL;
|
2011-05-13 08:54:16 +00:00
|
|
|
context_ = NULL;
|
|
|
|
thread_id_ = ThreadId::Invalid();
|
|
|
|
external_caught_exception_ = false;
|
|
|
|
failed_access_check_callback_ = NULL;
|
|
|
|
save_context_ = NULL;
|
|
|
|
catcher_ = NULL;
|
2011-10-18 11:18:55 +00:00
|
|
|
top_lookup_result_ = NULL;
|
2011-10-10 09:21:48 +00:00
|
|
|
|
|
|
|
// These members are re-initialized later after deserialization
|
|
|
|
// is complete.
|
|
|
|
pending_exception_ = NULL;
|
|
|
|
has_pending_message_ = false;
|
2013-07-01 10:54:39 +00:00
|
|
|
rethrowing_message_ = false;
|
2011-10-10 09:21:48 +00:00
|
|
|
pending_message_obj_ = NULL;
|
|
|
|
pending_message_script_ = NULL;
|
|
|
|
scheduled_exception_ = NULL;
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ThreadLocalTop::Initialize() {
|
|
|
|
InitializeInternal();
|
|
|
|
#ifdef USE_SIMULATOR
|
|
|
|
simulator_ = Simulator::current(isolate_);
|
|
|
|
#endif
|
|
|
|
thread_id_ = ThreadId::Current();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-30 13:25:46 +00:00
|
|
|
base::Thread::LocalStorageKey Isolate::isolate_key_;
|
|
|
|
base::Thread::LocalStorageKey Isolate::thread_id_key_;
|
|
|
|
base::Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_;
|
2013-06-03 15:32:22 +00:00
|
|
|
#ifdef DEBUG
|
2014-06-30 13:25:46 +00:00
|
|
|
base::Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key;
|
2013-06-03 15:32:22 +00:00
|
|
|
#endif // DEBUG
|
2014-07-02 07:44:02 +00:00
|
|
|
base::Mutex Isolate::process_wide_mutex_;
|
|
|
|
// TODO(dcarney): Remove with default isolate.
|
|
|
|
enum DefaultIsolateStatus {
|
|
|
|
kDefaultIsolateUninitialized,
|
|
|
|
kDefaultIsolateInitialized,
|
|
|
|
kDefaultIsolateCrashIfInitialized
|
|
|
|
};
|
|
|
|
static DefaultIsolateStatus default_isolate_status_
|
|
|
|
= kDefaultIsolateUninitialized;
|
2012-03-30 14:30:46 +00:00
|
|
|
Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL;
|
2014-06-05 12:14:47 +00:00
|
|
|
base::Atomic32 Isolate::isolate_counter_ = 0;
|
2012-03-30 14:30:46 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate::PerIsolateThreadData*
|
|
|
|
Isolate::FindOrAllocatePerThreadDataForThisThread() {
|
2011-04-11 23:46:22 +00:00
|
|
|
ThreadId thread_id = ThreadId::Current();
|
2011-03-18 20:35:07 +00:00
|
|
|
PerIsolateThreadData* per_thread = NULL;
|
|
|
|
{
|
2014-07-02 07:44:02 +00:00
|
|
|
base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
|
2012-03-30 14:30:46 +00:00
|
|
|
per_thread = thread_data_table_->Lookup(this, thread_id);
|
2013-07-31 07:51:46 +00:00
|
|
|
if (per_thread == NULL) {
|
2013-09-06 13:18:26 +00:00
|
|
|
per_thread = new PerIsolateThreadData(this, thread_id);
|
|
|
|
thread_data_table_->Insert(per_thread);
|
2013-07-31 07:51:46 +00:00
|
|
|
}
|
2014-05-06 11:25:37 +00:00
|
|
|
ASSERT(thread_data_table_->Lookup(this, thread_id) == per_thread);
|
2011-03-18 20:35:07 +00:00
|
|
|
}
|
|
|
|
return per_thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-05 18:55:31 +00:00
|
|
|
Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() {
|
|
|
|
ThreadId thread_id = ThreadId::Current();
|
2013-04-11 14:22:04 +00:00
|
|
|
return FindPerThreadDataForThread(thread_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread(
|
|
|
|
ThreadId thread_id) {
|
2011-05-05 18:55:31 +00:00
|
|
|
PerIsolateThreadData* per_thread = NULL;
|
|
|
|
{
|
2014-07-02 07:44:02 +00:00
|
|
|
base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
|
2012-03-30 14:30:46 +00:00
|
|
|
per_thread = thread_data_table_->Lookup(this, thread_id);
|
2011-05-05 18:55:31 +00:00
|
|
|
}
|
|
|
|
return per_thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-02 07:44:02 +00:00
|
|
|
void Isolate::SetCrashIfDefaultIsolateInitialized() {
|
|
|
|
base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
|
|
|
|
CHECK(default_isolate_status_ != kDefaultIsolateInitialized);
|
|
|
|
default_isolate_status_ = kDefaultIsolateCrashIfInitialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::EnsureDefaultIsolate() {
|
|
|
|
base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
|
|
|
|
CHECK(default_isolate_status_ != kDefaultIsolateCrashIfInitialized);
|
2014-05-09 08:40:18 +00:00
|
|
|
if (thread_data_table_ == NULL) {
|
2014-06-30 13:25:46 +00:00
|
|
|
isolate_key_ = base::Thread::CreateThreadLocalKey();
|
|
|
|
thread_id_key_ = base::Thread::CreateThreadLocalKey();
|
|
|
|
per_isolate_thread_data_key_ = base::Thread::CreateThreadLocalKey();
|
2013-10-02 09:01:40 +00:00
|
|
|
#ifdef DEBUG
|
2014-06-30 13:25:46 +00:00
|
|
|
PerThreadAssertScopeBase::thread_local_key =
|
|
|
|
base::Thread::CreateThreadLocalKey();
|
2013-10-02 09:01:40 +00:00
|
|
|
#endif // DEBUG
|
|
|
|
thread_data_table_ = new Isolate::ThreadDataTable();
|
2011-05-05 18:55:31 +00:00
|
|
|
}
|
2013-10-01 14:26:53 +00:00
|
|
|
}
|
|
|
|
|
2014-07-02 07:44:02 +00:00
|
|
|
struct StaticInitializer {
|
|
|
|
StaticInitializer() {
|
|
|
|
Isolate::EnsureDefaultIsolate();
|
|
|
|
}
|
|
|
|
} static_initializer;
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2011-05-13 08:54:16 +00:00
|
|
|
Address Isolate::get_address_from_id(Isolate::AddressId id) {
|
|
|
|
return isolate_addresses_[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char* Isolate::Iterate(ObjectVisitor* v, char* thread_storage) {
|
|
|
|
ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(thread_storage);
|
|
|
|
Iterate(v, thread);
|
|
|
|
return thread_storage + sizeof(ThreadLocalTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::IterateThread(ThreadVisitor* v, char* t) {
|
|
|
|
ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(t);
|
|
|
|
v->VisitThread(this, thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::Iterate(ObjectVisitor* v, ThreadLocalTop* thread) {
|
|
|
|
// Visit the roots from the top for a given thread.
|
2014-04-08 09:44:24 +00:00
|
|
|
v->VisitPointer(&thread->pending_exception_);
|
2011-05-13 08:54:16 +00:00
|
|
|
v->VisitPointer(&(thread->pending_message_obj_));
|
|
|
|
v->VisitPointer(BitCast<Object**>(&(thread->pending_message_script_)));
|
|
|
|
v->VisitPointer(BitCast<Object**>(&(thread->context_)));
|
2014-04-08 09:44:24 +00:00
|
|
|
v->VisitPointer(&thread->scheduled_exception_);
|
2011-05-13 08:54:16 +00:00
|
|
|
|
2014-05-20 10:13:46 +00:00
|
|
|
for (v8::TryCatch* block = thread->try_catch_handler();
|
2011-05-13 08:54:16 +00:00
|
|
|
block != NULL;
|
2014-05-20 10:13:46 +00:00
|
|
|
block = block->next_) {
|
2011-05-13 08:54:16 +00:00
|
|
|
v->VisitPointer(BitCast<Object**>(&(block->exception_)));
|
2013-07-01 10:54:39 +00:00
|
|
|
v->VisitPointer(BitCast<Object**>(&(block->message_obj_)));
|
|
|
|
v->VisitPointer(BitCast<Object**>(&(block->message_script_)));
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate over pointers on native execution stack.
|
|
|
|
for (StackFrameIterator it(this, thread); !it.done(); it.Advance()) {
|
|
|
|
it.frame()->Iterate(v);
|
|
|
|
}
|
2011-10-18 11:18:55 +00:00
|
|
|
|
|
|
|
// Iterate pointers in live lookup results.
|
|
|
|
thread->top_lookup_result_->Iterate(v);
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::Iterate(ObjectVisitor* v) {
|
|
|
|
ThreadLocalTop* current_t = thread_local_top();
|
|
|
|
Iterate(v, current_t);
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2012-07-18 14:15:02 +00:00
|
|
|
void Isolate::IterateDeferredHandles(ObjectVisitor* visitor) {
|
|
|
|
for (DeferredHandles* deferred = deferred_handles_head_;
|
|
|
|
deferred != NULL;
|
|
|
|
deferred = deferred->next_) {
|
|
|
|
deferred->Iterate(visitor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-13 08:54:16 +00:00
|
|
|
|
2013-04-23 09:23:07 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool Isolate::IsDeferredHandle(Object** handle) {
|
|
|
|
// Each DeferredHandles instance keeps the handles to one job in the
|
2013-08-22 16:14:37 +00:00
|
|
|
// concurrent recompilation queue, containing a list of blocks. Each block
|
2013-04-23 09:23:07 +00:00
|
|
|
// contains kHandleBlockSize handles except for the first block, which may
|
|
|
|
// not be fully filled.
|
|
|
|
// We iterate through all the blocks to see whether the argument handle
|
|
|
|
// belongs to one of the blocks. If so, it is deferred.
|
|
|
|
for (DeferredHandles* deferred = deferred_handles_head_;
|
|
|
|
deferred != NULL;
|
|
|
|
deferred = deferred->next_) {
|
|
|
|
List<Object**>* blocks = &deferred->blocks_;
|
|
|
|
for (int i = 0; i < blocks->length(); i++) {
|
|
|
|
Object** block_limit = (i == 0) ? deferred->first_block_limit_
|
|
|
|
: blocks->at(i) + kHandleBlockSize;
|
|
|
|
if (blocks->at(i) <= handle && handle < block_limit) return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
|
2011-05-13 08:54:16 +00:00
|
|
|
void Isolate::RegisterTryCatchHandler(v8::TryCatch* that) {
|
2014-05-20 10:13:46 +00:00
|
|
|
thread_local_top()->set_try_catch_handler(that);
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::UnregisterTryCatchHandler(v8::TryCatch* that) {
|
2014-05-20 10:13:46 +00:00
|
|
|
ASSERT(thread_local_top()->try_catch_handler() == that);
|
|
|
|
thread_local_top()->set_try_catch_handler(that->next_);
|
2011-05-13 08:54:16 +00:00
|
|
|
thread_local_top()->catcher_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<String> Isolate::StackTraceString() {
|
|
|
|
if (stack_trace_nesting_level_ == 0) {
|
|
|
|
stack_trace_nesting_level_++;
|
|
|
|
HeapStringAllocator allocator;
|
2013-09-03 11:54:08 +00:00
|
|
|
StringStream::ClearMentionedObjectCache(this);
|
2011-05-13 08:54:16 +00:00
|
|
|
StringStream accumulator(&allocator);
|
|
|
|
incomplete_message_ = &accumulator;
|
|
|
|
PrintStack(&accumulator);
|
2013-09-03 11:54:08 +00:00
|
|
|
Handle<String> stack_trace = accumulator.ToString(this);
|
2011-05-13 08:54:16 +00:00
|
|
|
incomplete_message_ = NULL;
|
|
|
|
stack_trace_nesting_level_ = 0;
|
|
|
|
return stack_trace;
|
|
|
|
} else if (stack_trace_nesting_level_ == 1) {
|
|
|
|
stack_trace_nesting_level_++;
|
2014-06-30 13:25:46 +00:00
|
|
|
base::OS::PrintError(
|
2011-05-13 08:54:16 +00:00
|
|
|
"\n\nAttempt to print stack while printing stack (double fault)\n");
|
2014-06-30 13:25:46 +00:00
|
|
|
base::OS::PrintError(
|
2011-05-13 08:54:16 +00:00
|
|
|
"If you are lucky you may find a partial stack dump on stdout.\n\n");
|
|
|
|
incomplete_message_->OutputToStdOut();
|
2013-02-28 17:03:34 +00:00
|
|
|
return factory()->empty_string();
|
2011-05-13 08:54:16 +00:00
|
|
|
} else {
|
2014-06-30 13:25:46 +00:00
|
|
|
base::OS::Abort();
|
2011-05-13 08:54:16 +00:00
|
|
|
// Unreachable
|
2013-02-28 17:03:34 +00:00
|
|
|
return factory()->empty_string();
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-05 12:30:49 +00:00
|
|
|
void Isolate::PushStackTraceAndDie(unsigned int magic,
|
|
|
|
Object* object,
|
|
|
|
Map* map,
|
|
|
|
unsigned int magic2) {
|
|
|
|
const int kMaxStackTraceSize = 8192;
|
|
|
|
Handle<String> trace = StackTraceString();
|
2013-01-09 15:47:53 +00:00
|
|
|
uint8_t buffer[kMaxStackTraceSize];
|
2012-09-05 12:30:49 +00:00
|
|
|
int length = Min(kMaxStackTraceSize - 1, trace->length());
|
|
|
|
String::WriteToFlat(*trace, buffer, 0, length);
|
|
|
|
buffer[length] = '\0';
|
2013-01-09 15:47:53 +00:00
|
|
|
// TODO(dcarney): convert buffer to utf8?
|
2014-06-30 13:25:46 +00:00
|
|
|
base::OS::PrintError("Stacktrace (%x-%x) %p %p: %s\n", magic, magic2,
|
|
|
|
static_cast<void*>(object), static_cast<void*>(map),
|
|
|
|
reinterpret_cast<char*>(buffer));
|
|
|
|
base::OS::Abort();
|
2012-09-05 12:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-12 14:54:29 +00:00
|
|
|
// Determines whether the given stack frame should be displayed in
|
|
|
|
// a stack trace. The caller is the error constructor that asked
|
|
|
|
// for the stack trace to be collected. The first time a construct
|
|
|
|
// call to this function is encountered it is skipped. The seen_caller
|
|
|
|
// in/out parameter is used to remember if the caller has been seen
|
|
|
|
// yet.
|
|
|
|
static bool IsVisibleInStackTrace(StackFrame* raw_frame,
|
|
|
|
Object* caller,
|
|
|
|
bool* seen_caller) {
|
|
|
|
// Only display JS frames.
|
|
|
|
if (!raw_frame->is_java_script()) return false;
|
|
|
|
JavaScriptFrame* frame = JavaScriptFrame::cast(raw_frame);
|
2013-07-11 16:45:58 +00:00
|
|
|
JSFunction* fun = frame->function();
|
|
|
|
if ((fun == caller) && !(*seen_caller)) {
|
2012-11-12 14:54:29 +00:00
|
|
|
*seen_caller = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Skip all frames until we've seen the caller.
|
|
|
|
if (!(*seen_caller)) return false;
|
|
|
|
// Also, skip non-visible built-in functions and any call with the builtins
|
|
|
|
// object as receiver, so as to not reveal either the builtins object or
|
|
|
|
// an internal function.
|
|
|
|
// The --builtins-in-stack-traces command line flag allows including
|
|
|
|
// internal call sites in the stack trace for debugging purposes.
|
|
|
|
if (!FLAG_builtins_in_stack_traces) {
|
|
|
|
if (frame->receiver()->IsJSBuiltinsObject() ||
|
|
|
|
(fun->IsBuiltin() && !fun->shared()->native())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-30 13:16:42 +00:00
|
|
|
Handle<JSArray> Isolate::CaptureSimpleStackTrace(Handle<JSObject> error_object,
|
|
|
|
Handle<Object> caller,
|
|
|
|
int limit) {
|
2012-11-12 14:54:29 +00:00
|
|
|
limit = Max(limit, 0); // Ensure that limit is not negative.
|
|
|
|
int initial_size = Min(limit, 10);
|
|
|
|
Handle<FixedArray> elements =
|
2013-03-28 10:40:07 +00:00
|
|
|
factory()->NewFixedArrayWithHoles(initial_size * 4 + 1);
|
2012-11-12 14:54:29 +00:00
|
|
|
|
|
|
|
// If the caller parameter is a function we skip frames until we're
|
|
|
|
// under it before starting to collect.
|
|
|
|
bool seen_caller = !caller->IsJSFunction();
|
2014-03-11 14:39:08 +00:00
|
|
|
// First element is reserved to store the number of sloppy frames.
|
2013-03-28 10:40:07 +00:00
|
|
|
int cursor = 1;
|
2012-11-12 14:54:29 +00:00
|
|
|
int frames_seen = 0;
|
2014-03-11 14:39:08 +00:00
|
|
|
int sloppy_frames = 0;
|
2013-03-28 10:40:07 +00:00
|
|
|
bool encountered_strict_function = false;
|
2012-11-12 14:54:29 +00:00
|
|
|
for (StackFrameIterator iter(this);
|
|
|
|
!iter.done() && frames_seen < limit;
|
|
|
|
iter.Advance()) {
|
|
|
|
StackFrame* raw_frame = iter.frame();
|
|
|
|
if (IsVisibleInStackTrace(raw_frame, *caller, &seen_caller)) {
|
|
|
|
JavaScriptFrame* frame = JavaScriptFrame::cast(raw_frame);
|
|
|
|
// Set initial size to the maximum inlining level + 1 for the outermost
|
|
|
|
// function.
|
2013-07-17 08:44:10 +00:00
|
|
|
List<FrameSummary> frames(FLAG_max_inlining_levels + 1);
|
2012-11-12 14:54:29 +00:00
|
|
|
frame->Summarize(&frames);
|
|
|
|
for (int i = frames.length() - 1; i >= 0; i--) {
|
2014-05-19 13:45:45 +00:00
|
|
|
Handle<JSFunction> fun = frames[i].function();
|
|
|
|
// Filter out frames from other security contexts.
|
|
|
|
if (!this->context()->HasSameSecurityTokenAs(fun->context())) continue;
|
2012-11-12 14:54:29 +00:00
|
|
|
if (cursor + 4 > elements->length()) {
|
|
|
|
int new_capacity = JSObject::NewElementsCapacity(elements->length());
|
|
|
|
Handle<FixedArray> new_elements =
|
|
|
|
factory()->NewFixedArrayWithHoles(new_capacity);
|
|
|
|
for (int i = 0; i < cursor; i++) {
|
|
|
|
new_elements->set(i, elements->get(i));
|
|
|
|
}
|
|
|
|
elements = new_elements;
|
|
|
|
}
|
|
|
|
ASSERT(cursor + 4 <= elements->length());
|
|
|
|
|
|
|
|
Handle<Object> recv = frames[i].receiver();
|
|
|
|
Handle<Code> code = frames[i].code();
|
2013-02-25 14:46:09 +00:00
|
|
|
Handle<Smi> offset(Smi::FromInt(frames[i].offset()), this);
|
2013-03-28 10:40:07 +00:00
|
|
|
// The stack trace API should not expose receivers and function
|
|
|
|
// objects on frames deeper than the top-most one with a strict
|
2014-03-11 14:39:08 +00:00
|
|
|
// mode function. The number of sloppy frames is stored as
|
2013-03-28 10:40:07 +00:00
|
|
|
// first element in the result array.
|
|
|
|
if (!encountered_strict_function) {
|
2014-03-11 14:41:22 +00:00
|
|
|
if (fun->shared()->strict_mode() == STRICT) {
|
2013-03-28 10:40:07 +00:00
|
|
|
encountered_strict_function = true;
|
|
|
|
} else {
|
2014-03-11 14:39:08 +00:00
|
|
|
sloppy_frames++;
|
2013-03-28 10:40:07 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-12 14:54:29 +00:00
|
|
|
elements->set(cursor++, *recv);
|
|
|
|
elements->set(cursor++, *fun);
|
|
|
|
elements->set(cursor++, *code);
|
|
|
|
elements->set(cursor++, *offset);
|
|
|
|
}
|
2014-05-19 13:45:45 +00:00
|
|
|
frames_seen++;
|
2012-11-12 14:54:29 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-11 14:39:08 +00:00
|
|
|
elements->set(0, Smi::FromInt(sloppy_frames));
|
2012-11-12 14:54:29 +00:00
|
|
|
Handle<JSArray> result = factory()->NewJSArrayWithElements(elements);
|
|
|
|
result->set_length(Smi::FromInt(cursor));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::CaptureAndSetDetailedStackTrace(Handle<JSObject> error_object) {
|
2012-02-07 09:31:06 +00:00
|
|
|
if (capture_stack_trace_for_uncaught_exceptions_) {
|
|
|
|
// Capture stack trace for a detailed exception message.
|
2014-06-30 13:16:42 +00:00
|
|
|
Handle<String> key = factory()->hidden_stack_trace_string();
|
2012-02-07 09:31:06 +00:00
|
|
|
Handle<JSArray> stack_trace = CaptureCurrentStackTrace(
|
|
|
|
stack_trace_for_uncaught_exceptions_frame_limit_,
|
|
|
|
stack_trace_for_uncaught_exceptions_options_);
|
2014-06-30 13:16:42 +00:00
|
|
|
JSObject::SetHiddenProperty(error_object, key, stack_trace);
|
2012-02-07 09:31:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-13 08:54:16 +00:00
|
|
|
Handle<JSArray> Isolate::CaptureCurrentStackTrace(
|
|
|
|
int frame_limit, StackTrace::StackTraceOptions options) {
|
|
|
|
// Ensure no negative values.
|
|
|
|
int limit = Max(frame_limit, 0);
|
|
|
|
Handle<JSArray> stack_trace = factory()->NewJSArray(frame_limit);
|
|
|
|
|
2012-12-17 15:56:16 +00:00
|
|
|
Handle<String> column_key =
|
2013-02-28 17:03:34 +00:00
|
|
|
factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("column"));
|
2012-12-17 15:56:16 +00:00
|
|
|
Handle<String> line_key =
|
2013-02-28 17:03:34 +00:00
|
|
|
factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("lineNumber"));
|
2013-08-30 14:54:59 +00:00
|
|
|
Handle<String> script_id_key =
|
|
|
|
factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("scriptId"));
|
|
|
|
Handle<String> script_name_key =
|
2013-02-28 17:03:34 +00:00
|
|
|
factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("scriptName"));
|
2011-05-13 08:54:16 +00:00
|
|
|
Handle<String> script_name_or_source_url_key =
|
2013-02-28 17:03:34 +00:00
|
|
|
factory()->InternalizeOneByteString(
|
2012-12-17 15:56:16 +00:00
|
|
|
STATIC_ASCII_VECTOR("scriptNameOrSourceURL"));
|
|
|
|
Handle<String> function_key =
|
2013-02-28 17:03:34 +00:00
|
|
|
factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("functionName"));
|
2012-12-17 15:56:16 +00:00
|
|
|
Handle<String> eval_key =
|
2013-02-28 17:03:34 +00:00
|
|
|
factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("isEval"));
|
2011-05-13 08:54:16 +00:00
|
|
|
Handle<String> constructor_key =
|
2013-02-28 17:03:34 +00:00
|
|
|
factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("isConstructor"));
|
2011-05-13 08:54:16 +00:00
|
|
|
|
|
|
|
StackTraceFrameIterator it(this);
|
|
|
|
int frames_seen = 0;
|
|
|
|
while (!it.done() && (frames_seen < limit)) {
|
|
|
|
JavaScriptFrame* frame = it.frame();
|
|
|
|
// Set initial size to the maximum inlining level + 1 for the outermost
|
|
|
|
// function.
|
2013-07-17 08:44:10 +00:00
|
|
|
List<FrameSummary> frames(FLAG_max_inlining_levels + 1);
|
2011-05-13 08:54:16 +00:00
|
|
|
frame->Summarize(&frames);
|
|
|
|
for (int i = frames.length() - 1; i >= 0 && frames_seen < limit; i--) {
|
2014-05-19 13:45:45 +00:00
|
|
|
Handle<JSFunction> fun = frames[i].function();
|
|
|
|
// Filter frames from other security contexts.
|
|
|
|
if (!(options & StackTrace::kExposeFramesAcrossSecurityOrigins) &&
|
|
|
|
!this->context()->HasSameSecurityTokenAs(fun->context())) continue;
|
|
|
|
|
2011-05-13 08:54:16 +00:00
|
|
|
// Create a JSObject to hold the information for the StackFrame.
|
2012-01-05 17:16:19 +00:00
|
|
|
Handle<JSObject> stack_frame = factory()->NewJSObject(object_function());
|
2011-05-13 08:54:16 +00:00
|
|
|
|
|
|
|
Handle<Script> script(Script::cast(fun->shared()->script()));
|
|
|
|
|
|
|
|
if (options & StackTrace::kLineNumber) {
|
|
|
|
int script_line_offset = script->line_offset()->value();
|
|
|
|
int position = frames[i].code()->SourcePosition(frames[i].pc());
|
2014-04-16 13:28:11 +00:00
|
|
|
int line_number = Script::GetLineNumber(script, position);
|
2011-05-13 08:54:16 +00:00
|
|
|
// line_number is already shifted by the script_line_offset.
|
|
|
|
int relative_line_number = line_number - script_line_offset;
|
|
|
|
if (options & StackTrace::kColumnOffset && relative_line_number >= 0) {
|
|
|
|
Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends()));
|
|
|
|
int start = (relative_line_number == 0) ? 0 :
|
|
|
|
Smi::cast(line_ends->get(relative_line_number - 1))->value() + 1;
|
|
|
|
int column_offset = position - start;
|
|
|
|
if (relative_line_number == 0) {
|
|
|
|
// For the case where the code is on the same line as the script
|
|
|
|
// tag.
|
|
|
|
column_offset += script->column_offset()->value();
|
|
|
|
}
|
2014-06-30 13:48:57 +00:00
|
|
|
JSObject::AddProperty(
|
2014-04-04 12:06:11 +00:00
|
|
|
stack_frame, column_key,
|
2014-06-30 13:48:57 +00:00
|
|
|
handle(Smi::FromInt(column_offset + 1), this), NONE);
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
2014-06-30 13:48:57 +00:00
|
|
|
JSObject::AddProperty(
|
2014-04-04 12:06:11 +00:00
|
|
|
stack_frame, line_key,
|
2014-06-30 13:48:57 +00:00
|
|
|
handle(Smi::FromInt(line_number + 1), this), NONE);
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
2013-08-30 14:54:59 +00:00
|
|
|
if (options & StackTrace::kScriptId) {
|
2014-06-30 13:48:57 +00:00
|
|
|
JSObject::AddProperty(
|
|
|
|
stack_frame, script_id_key, handle(script->id(), this), NONE);
|
2013-08-30 14:54:59 +00:00
|
|
|
}
|
|
|
|
|
2011-05-13 08:54:16 +00:00
|
|
|
if (options & StackTrace::kScriptName) {
|
2014-06-30 13:48:57 +00:00
|
|
|
JSObject::AddProperty(
|
|
|
|
stack_frame, script_name_key, handle(script->name(), this), NONE);
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options & StackTrace::kScriptNameOrSourceURL) {
|
2014-04-16 13:28:11 +00:00
|
|
|
Handle<Object> result = Script::GetNameOrSourceURL(script);
|
2014-06-30 13:48:57 +00:00
|
|
|
JSObject::AddProperty(
|
|
|
|
stack_frame, script_name_or_source_url_key, result, NONE);
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options & StackTrace::kFunctionName) {
|
|
|
|
Handle<Object> fun_name(fun->shared()->name(), this);
|
2013-03-07 16:22:19 +00:00
|
|
|
if (!fun_name->BooleanValue()) {
|
2011-05-13 08:54:16 +00:00
|
|
|
fun_name = Handle<Object>(fun->shared()->inferred_name(), this);
|
|
|
|
}
|
2014-06-30 13:48:57 +00:00
|
|
|
JSObject::AddProperty(stack_frame, function_key, fun_name, NONE);
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options & StackTrace::kIsEval) {
|
2013-07-30 17:00:05 +00:00
|
|
|
Handle<Object> is_eval =
|
|
|
|
script->compilation_type() == Script::COMPILATION_TYPE_EVAL ?
|
|
|
|
factory()->true_value() : factory()->false_value();
|
2014-06-30 13:48:57 +00:00
|
|
|
JSObject::AddProperty(stack_frame, eval_key, is_eval, NONE);
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options & StackTrace::kIsConstructor) {
|
|
|
|
Handle<Object> is_constructor = (frames[i].is_constructor()) ?
|
|
|
|
factory()->true_value() : factory()->false_value();
|
2014-06-30 13:48:57 +00:00
|
|
|
JSObject::AddProperty(
|
|
|
|
stack_frame, constructor_key, is_constructor, NONE);
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
2012-01-05 17:16:19 +00:00
|
|
|
FixedArray::cast(stack_trace->elements())->set(frames_seen, *stack_frame);
|
2011-05-13 08:54:16 +00:00
|
|
|
frames_seen++;
|
|
|
|
}
|
|
|
|
it.Advance();
|
|
|
|
}
|
|
|
|
|
|
|
|
stack_trace->set_length(Smi::FromInt(frames_seen));
|
|
|
|
return stack_trace;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-21 09:25:57 +00:00
|
|
|
void Isolate::PrintStack(FILE* out) {
|
2011-05-13 08:54:16 +00:00
|
|
|
if (stack_trace_nesting_level_ == 0) {
|
|
|
|
stack_trace_nesting_level_++;
|
2013-09-03 11:54:08 +00:00
|
|
|
StringStream::ClearMentionedObjectCache(this);
|
2013-11-20 12:35:58 +00:00
|
|
|
HeapStringAllocator allocator;
|
|
|
|
StringStream accumulator(&allocator);
|
2011-05-13 08:54:16 +00:00
|
|
|
incomplete_message_ = &accumulator;
|
|
|
|
PrintStack(&accumulator);
|
2013-05-21 09:25:57 +00:00
|
|
|
accumulator.OutputToFile(out);
|
2011-08-04 15:18:18 +00:00
|
|
|
InitializeLoggingAndCounters();
|
2013-09-11 10:59:39 +00:00
|
|
|
accumulator.Log(this);
|
2011-05-13 08:54:16 +00:00
|
|
|
incomplete_message_ = NULL;
|
|
|
|
stack_trace_nesting_level_ = 0;
|
|
|
|
} else if (stack_trace_nesting_level_ == 1) {
|
|
|
|
stack_trace_nesting_level_++;
|
2014-06-30 13:25:46 +00:00
|
|
|
base::OS::PrintError(
|
2011-05-13 08:54:16 +00:00
|
|
|
"\n\nAttempt to print stack while printing stack (double fault)\n");
|
2014-06-30 13:25:46 +00:00
|
|
|
base::OS::PrintError(
|
2011-05-13 08:54:16 +00:00
|
|
|
"If you are lucky you may find a partial stack dump on stdout.\n\n");
|
2013-05-21 09:25:57 +00:00
|
|
|
incomplete_message_->OutputToFile(out);
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-15 09:27:10 +00:00
|
|
|
static void PrintFrames(Isolate* isolate,
|
|
|
|
StringStream* accumulator,
|
2011-05-13 08:54:16 +00:00
|
|
|
StackFrame::PrintMode mode) {
|
2013-02-15 09:27:10 +00:00
|
|
|
StackFrameIterator it(isolate);
|
2011-05-13 08:54:16 +00:00
|
|
|
for (int i = 0; !it.done(); it.Advance()) {
|
|
|
|
it.frame()->Print(accumulator, mode, i++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::PrintStack(StringStream* accumulator) {
|
|
|
|
if (!IsInitialized()) {
|
|
|
|
accumulator->Add(
|
2012-12-14 14:27:06 +00:00
|
|
|
"\n==== JS stack trace is not available =======================\n\n");
|
2011-05-13 08:54:16 +00:00
|
|
|
accumulator->Add(
|
|
|
|
"\n==== Isolate for the thread is not initialized =============\n\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// The MentionedObjectCache is not GC-proof at the moment.
|
2013-06-03 15:32:22 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
2013-09-03 11:54:08 +00:00
|
|
|
ASSERT(StringStream::IsMentionedObjectCacheClear(this));
|
2011-05-13 08:54:16 +00:00
|
|
|
|
|
|
|
// Avoid printing anything if there are no frames.
|
|
|
|
if (c_entry_fp(thread_local_top()) == 0) return;
|
|
|
|
|
|
|
|
accumulator->Add(
|
2012-12-14 14:27:06 +00:00
|
|
|
"\n==== JS stack trace =========================================\n\n");
|
2013-02-15 09:27:10 +00:00
|
|
|
PrintFrames(this, accumulator, StackFrame::OVERVIEW);
|
2011-05-13 08:54:16 +00:00
|
|
|
|
|
|
|
accumulator->Add(
|
|
|
|
"\n==== Details ================================================\n\n");
|
2013-02-15 09:27:10 +00:00
|
|
|
PrintFrames(this, accumulator, StackFrame::DETAILS);
|
2011-05-13 08:54:16 +00:00
|
|
|
|
2013-09-03 11:54:08 +00:00
|
|
|
accumulator->PrintMentionedObjectCache(this);
|
2011-05-13 08:54:16 +00:00
|
|
|
accumulator->Add("=====================\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::SetFailedAccessCheckCallback(
|
|
|
|
v8::FailedAccessCheckCallback callback) {
|
|
|
|
thread_local_top()->failed_access_check_callback_ = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-14 14:03:20 +00:00
|
|
|
static inline AccessCheckInfo* GetAccessCheckInfo(Isolate* isolate,
|
|
|
|
Handle<JSObject> receiver) {
|
|
|
|
JSFunction* constructor = JSFunction::cast(receiver->map()->constructor());
|
|
|
|
if (!constructor->shared()->IsApiFunction()) return NULL;
|
|
|
|
|
|
|
|
Object* data_obj =
|
|
|
|
constructor->shared()->get_api_func_data()->access_check_info();
|
|
|
|
if (data_obj == isolate->heap()->undefined_value()) return NULL;
|
|
|
|
|
|
|
|
return AccessCheckInfo::cast(data_obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::ReportFailedAccessCheck(Handle<JSObject> receiver,
|
|
|
|
v8::AccessType type) {
|
2011-05-13 08:54:16 +00:00
|
|
|
if (!thread_local_top()->failed_access_check_callback_) return;
|
|
|
|
|
|
|
|
ASSERT(receiver->IsAccessCheckNeeded());
|
|
|
|
ASSERT(context());
|
|
|
|
|
|
|
|
// Get the data object from access check info.
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(this);
|
2014-04-14 14:03:20 +00:00
|
|
|
Handle<Object> data;
|
|
|
|
{ DisallowHeapAllocation no_gc;
|
|
|
|
AccessCheckInfo* access_check_info = GetAccessCheckInfo(this, receiver);
|
|
|
|
if (!access_check_info) return;
|
|
|
|
data = handle(access_check_info->data(), this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Leaving JavaScript.
|
|
|
|
VMState<EXTERNAL> state(this);
|
|
|
|
thread_local_top()->failed_access_check_callback_(
|
|
|
|
v8::Utils::ToLocal(receiver),
|
2012-02-20 15:34:08 +00:00
|
|
|
type,
|
|
|
|
v8::Utils::ToLocal(data));
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum MayAccessDecision {
|
|
|
|
YES, NO, UNKNOWN
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static MayAccessDecision MayAccessPreCheck(Isolate* isolate,
|
2014-04-14 14:03:20 +00:00
|
|
|
Handle<JSObject> receiver,
|
2011-05-13 08:54:16 +00:00
|
|
|
v8::AccessType type) {
|
2014-04-14 14:03:20 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
2011-05-13 08:54:16 +00:00
|
|
|
// During bootstrapping, callback functions are not enabled yet.
|
|
|
|
if (isolate->bootstrapper()->IsActive()) return YES;
|
|
|
|
|
|
|
|
if (receiver->IsJSGlobalProxy()) {
|
2014-04-14 14:03:20 +00:00
|
|
|
Object* receiver_context = JSGlobalProxy::cast(*receiver)->native_context();
|
2011-05-13 08:54:16 +00:00
|
|
|
if (!receiver_context->IsContext()) return NO;
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
// Get the native context of current top context.
|
|
|
|
// avoid using Isolate::native_context() because it uses Handle.
|
2012-08-17 12:59:00 +00:00
|
|
|
Context* native_context =
|
|
|
|
isolate->context()->global_object()->native_context();
|
2012-08-17 09:03:08 +00:00
|
|
|
if (receiver_context == native_context) return YES;
|
2011-05-13 08:54:16 +00:00
|
|
|
|
|
|
|
if (Context::cast(receiver_context)->security_token() ==
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context->security_token())
|
2011-05-13 08:54:16 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
return UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-14 14:03:20 +00:00
|
|
|
bool Isolate::MayNamedAccess(Handle<JSObject> receiver,
|
|
|
|
Handle<Object> key,
|
2011-05-13 08:54:16 +00:00
|
|
|
v8::AccessType type) {
|
2014-03-10 12:23:05 +00:00
|
|
|
ASSERT(receiver->IsJSGlobalProxy() || receiver->IsAccessCheckNeeded());
|
2011-05-13 08:54:16 +00:00
|
|
|
|
|
|
|
// Skip checks for hidden properties access. Note, we do not
|
|
|
|
// require existence of a context in this case.
|
2014-04-14 14:03:20 +00:00
|
|
|
if (key.is_identical_to(factory()->hidden_string())) return true;
|
2011-05-13 08:54:16 +00:00
|
|
|
|
|
|
|
// Check for compatibility between the security tokens in the
|
|
|
|
// current lexical context and the accessed object.
|
|
|
|
ASSERT(context());
|
|
|
|
|
|
|
|
MayAccessDecision decision = MayAccessPreCheck(this, receiver, type);
|
|
|
|
if (decision != UNKNOWN) return decision == YES;
|
|
|
|
|
|
|
|
HandleScope scope(this);
|
2014-04-14 14:03:20 +00:00
|
|
|
Handle<Object> data;
|
|
|
|
v8::NamedSecurityCallback callback;
|
|
|
|
{ DisallowHeapAllocation no_gc;
|
|
|
|
AccessCheckInfo* access_check_info = GetAccessCheckInfo(this, receiver);
|
|
|
|
if (!access_check_info) return false;
|
|
|
|
Object* fun_obj = access_check_info->named_callback();
|
|
|
|
callback = v8::ToCData<v8::NamedSecurityCallback>(fun_obj);
|
|
|
|
if (!callback) return false;
|
|
|
|
data = handle(access_check_info->data(), this);
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
2014-04-14 14:03:20 +00:00
|
|
|
|
|
|
|
LOG(this, ApiNamedSecurityCheck(*key));
|
|
|
|
|
|
|
|
// Leaving JavaScript.
|
|
|
|
VMState<EXTERNAL> state(this);
|
|
|
|
return callback(v8::Utils::ToLocal(receiver),
|
|
|
|
v8::Utils::ToLocal(key),
|
|
|
|
type,
|
|
|
|
v8::Utils::ToLocal(data));
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-14 14:03:20 +00:00
|
|
|
bool Isolate::MayIndexedAccess(Handle<JSObject> receiver,
|
2011-05-13 08:54:16 +00:00
|
|
|
uint32_t index,
|
|
|
|
v8::AccessType type) {
|
2014-03-10 12:23:05 +00:00
|
|
|
ASSERT(receiver->IsJSGlobalProxy() || receiver->IsAccessCheckNeeded());
|
2011-05-13 08:54:16 +00:00
|
|
|
// Check for compatibility between the security tokens in the
|
|
|
|
// current lexical context and the accessed object.
|
|
|
|
ASSERT(context());
|
|
|
|
|
|
|
|
MayAccessDecision decision = MayAccessPreCheck(this, receiver, type);
|
|
|
|
if (decision != UNKNOWN) return decision == YES;
|
|
|
|
|
|
|
|
HandleScope scope(this);
|
2014-04-14 14:03:20 +00:00
|
|
|
Handle<Object> data;
|
|
|
|
v8::IndexedSecurityCallback callback;
|
|
|
|
{ DisallowHeapAllocation no_gc;
|
|
|
|
// Get named access check callback
|
|
|
|
AccessCheckInfo* access_check_info = GetAccessCheckInfo(this, receiver);
|
|
|
|
if (!access_check_info) return false;
|
|
|
|
Object* fun_obj = access_check_info->indexed_callback();
|
|
|
|
callback = v8::ToCData<v8::IndexedSecurityCallback>(fun_obj);
|
|
|
|
if (!callback) return false;
|
|
|
|
data = handle(access_check_info->data(), this);
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
2014-04-14 14:03:20 +00:00
|
|
|
|
|
|
|
LOG(this, ApiIndexedSecurityCheck(index));
|
|
|
|
|
|
|
|
// Leaving JavaScript.
|
|
|
|
VMState<EXTERNAL> state(this);
|
|
|
|
return callback(
|
|
|
|
v8::Utils::ToLocal(receiver), index, type, v8::Utils::ToLocal(data));
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char* const Isolate::kStackOverflowMessage =
|
|
|
|
"Uncaught RangeError: Maximum call stack size exceeded";
|
|
|
|
|
|
|
|
|
2014-04-22 12:50:58 +00:00
|
|
|
Object* Isolate::StackOverflow() {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(this);
|
2012-11-12 14:54:29 +00:00
|
|
|
// At this point we cannot create an Error object using its javascript
|
|
|
|
// constructor. Instead, we copy the pre-constructed boilerplate and
|
|
|
|
// attach the stack trace as a hidden property.
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> key = factory()->stack_overflow_string();
|
2014-04-11 12:47:34 +00:00
|
|
|
Handle<JSObject> boilerplate = Handle<JSObject>::cast(
|
|
|
|
Object::GetProperty(js_builtins_object(), key).ToHandleChecked());
|
2014-04-29 07:02:11 +00:00
|
|
|
Handle<JSObject> exception = factory()->CopyJSObject(boilerplate);
|
2011-05-13 08:54:16 +00:00
|
|
|
DoThrow(*exception, NULL);
|
2012-11-12 14:54:29 +00:00
|
|
|
|
2014-06-30 13:16:42 +00:00
|
|
|
// Get stack trace limit.
|
|
|
|
Handle<Object> error = Object::GetProperty(
|
|
|
|
this, js_builtins_object(), "$Error").ToHandleChecked();
|
|
|
|
if (!error->IsJSObject()) return heap()->exception();
|
|
|
|
|
|
|
|
Handle<String> stackTraceLimit =
|
|
|
|
factory()->InternalizeUtf8String("stackTraceLimit");
|
|
|
|
ASSERT(!stackTraceLimit.is_null());
|
|
|
|
Handle<Object> stack_trace_limit =
|
|
|
|
JSObject::GetDataProperty(Handle<JSObject>::cast(error),
|
|
|
|
stackTraceLimit);
|
|
|
|
if (!stack_trace_limit->IsNumber()) return heap()->exception();
|
|
|
|
int limit = FastD2IChecked(stack_trace_limit->Number());
|
|
|
|
if (limit < 0) limit = 0;
|
|
|
|
Handle<JSArray> stack_trace = CaptureSimpleStackTrace(
|
|
|
|
exception, factory()->undefined_value(), limit);
|
|
|
|
JSObject::SetHiddenProperty(exception,
|
|
|
|
factory()->hidden_stack_trace_string(),
|
|
|
|
stack_trace);
|
2014-04-22 12:50:58 +00:00
|
|
|
return heap()->exception();
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-22 12:50:58 +00:00
|
|
|
Object* Isolate::TerminateExecution() {
|
2011-05-13 08:54:16 +00:00
|
|
|
DoThrow(heap_.termination_exception(), NULL);
|
2014-04-22 12:50:58 +00:00
|
|
|
return heap()->exception();
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-22 15:01:45 +00:00
|
|
|
void Isolate::CancelTerminateExecution() {
|
|
|
|
if (try_catch_handler()) {
|
|
|
|
try_catch_handler()->has_terminated_ = false;
|
|
|
|
}
|
|
|
|
if (has_pending_exception() &&
|
|
|
|
pending_exception() == heap_.termination_exception()) {
|
|
|
|
thread_local_top()->external_caught_exception_ = false;
|
|
|
|
clear_pending_exception();
|
|
|
|
}
|
|
|
|
if (has_scheduled_exception() &&
|
|
|
|
scheduled_exception() == heap_.termination_exception()) {
|
|
|
|
thread_local_top()->external_caught_exception_ = false;
|
|
|
|
clear_scheduled_exception();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-09 09:13:12 +00:00
|
|
|
void Isolate::InvokeApiInterruptCallback() {
|
2014-05-20 08:24:51 +00:00
|
|
|
// Note: callback below should be called outside of execution access lock.
|
|
|
|
InterruptCallback callback = NULL;
|
|
|
|
void* data = NULL;
|
|
|
|
{
|
|
|
|
ExecutionAccess access(this);
|
|
|
|
callback = api_interrupt_callback_;
|
|
|
|
data = api_interrupt_callback_data_;
|
|
|
|
api_interrupt_callback_ = NULL;
|
|
|
|
api_interrupt_callback_data_ = NULL;
|
|
|
|
}
|
2014-05-09 09:13:12 +00:00
|
|
|
|
|
|
|
if (callback != NULL) {
|
|
|
|
VMState<EXTERNAL> state(this);
|
|
|
|
HandleScope handle_scope(this);
|
|
|
|
callback(reinterpret_cast<v8::Isolate*>(this), data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-22 12:50:58 +00:00
|
|
|
Object* Isolate::Throw(Object* exception, MessageLocation* location) {
|
2011-05-13 08:54:16 +00:00
|
|
|
DoThrow(exception, location);
|
2014-04-22 12:50:58 +00:00
|
|
|
return heap()->exception();
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-22 12:50:58 +00:00
|
|
|
Object* Isolate::ReThrow(Object* exception) {
|
2011-05-13 08:54:16 +00:00
|
|
|
bool can_be_caught_externally = false;
|
2011-05-18 12:22:19 +00:00
|
|
|
bool catchable_by_javascript = is_catchable_by_javascript(exception);
|
|
|
|
ShouldReportException(&can_be_caught_externally, catchable_by_javascript);
|
|
|
|
|
2011-05-13 08:54:16 +00:00
|
|
|
thread_local_top()->catcher_ = can_be_caught_externally ?
|
|
|
|
try_catch_handler() : NULL;
|
|
|
|
|
|
|
|
// Set the exception being re-thrown.
|
|
|
|
set_pending_exception(exception);
|
2014-04-22 12:50:58 +00:00
|
|
|
return heap()->exception();
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-22 12:50:58 +00:00
|
|
|
Object* Isolate::ThrowIllegalOperation() {
|
2014-02-11 07:28:05 +00:00
|
|
|
if (FLAG_stack_trace_on_illegal) PrintStack(stdout);
|
2013-02-28 17:03:34 +00:00
|
|
|
return Throw(heap_.illegal_access_string());
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-22 12:50:58 +00:00
|
|
|
Object* Isolate::ThrowInvalidStringLength() {
|
2014-03-20 12:27:36 +00:00
|
|
|
return Throw(*factory()->NewRangeError(
|
|
|
|
"invalid_string_length", HandleVector<Object>(NULL, 0)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-13 08:54:16 +00:00
|
|
|
void Isolate::ScheduleThrow(Object* exception) {
|
|
|
|
// When scheduling a throw we first throw the exception to get the
|
|
|
|
// error reporting if it is uncaught before rescheduling it.
|
|
|
|
Throw(exception);
|
2014-05-22 11:16:05 +00:00
|
|
|
PropagatePendingExceptionToExternalTryCatch();
|
2012-12-04 10:45:59 +00:00
|
|
|
if (has_pending_exception()) {
|
|
|
|
thread_local_top()->scheduled_exception_ = pending_exception();
|
|
|
|
thread_local_top()->external_caught_exception_ = false;
|
|
|
|
clear_pending_exception();
|
|
|
|
}
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-01 10:54:39 +00:00
|
|
|
void Isolate::RestorePendingMessageFromTryCatch(v8::TryCatch* handler) {
|
|
|
|
ASSERT(handler == try_catch_handler());
|
|
|
|
ASSERT(handler->HasCaught());
|
|
|
|
ASSERT(handler->rethrow_);
|
|
|
|
ASSERT(handler->capture_message_);
|
|
|
|
Object* message = reinterpret_cast<Object*>(handler->message_obj_);
|
|
|
|
Object* script = reinterpret_cast<Object*>(handler->message_script_);
|
|
|
|
ASSERT(message->IsJSMessageObject() || message->IsTheHole());
|
|
|
|
ASSERT(script->IsScript() || script->IsTheHole());
|
|
|
|
thread_local_top()->pending_message_obj_ = message;
|
|
|
|
thread_local_top()->pending_message_script_ = script;
|
|
|
|
thread_local_top()->pending_message_start_pos_ = handler->message_start_pos_;
|
|
|
|
thread_local_top()->pending_message_end_pos_ = handler->message_end_pos_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-22 12:50:58 +00:00
|
|
|
Object* Isolate::PromoteScheduledException() {
|
2014-04-08 09:44:24 +00:00
|
|
|
Object* thrown = scheduled_exception();
|
2011-05-13 08:54:16 +00:00
|
|
|
clear_scheduled_exception();
|
|
|
|
// Re-throw the exception to avoid getting repeated error reporting.
|
|
|
|
return ReThrow(thrown);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::PrintCurrentStackTrace(FILE* out) {
|
|
|
|
StackTraceFrameIterator it(this);
|
|
|
|
while (!it.done()) {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(this);
|
2011-05-13 08:54:16 +00:00
|
|
|
// Find code position if recorded in relocation info.
|
|
|
|
JavaScriptFrame* frame = it.frame();
|
|
|
|
int pos = frame->LookupCode()->SourcePosition(frame->pc());
|
2013-02-25 14:46:09 +00:00
|
|
|
Handle<Object> pos_obj(Smi::FromInt(pos), this);
|
2011-05-13 08:54:16 +00:00
|
|
|
// Fetch function and receiver.
|
2013-07-11 16:45:58 +00:00
|
|
|
Handle<JSFunction> fun(frame->function());
|
2013-02-25 14:46:09 +00:00
|
|
|
Handle<Object> recv(frame->receiver(), this);
|
2011-05-13 08:54:16 +00:00
|
|
|
// Advance to the next JavaScript frame and determine if the
|
|
|
|
// current frame is the top-level frame.
|
|
|
|
it.Advance();
|
|
|
|
Handle<Object> is_top_level = it.done()
|
|
|
|
? factory()->true_value()
|
|
|
|
: factory()->false_value();
|
|
|
|
// Generate and print stack trace line.
|
|
|
|
Handle<String> line =
|
|
|
|
Execution::GetStackTraceLine(recv, fun, pos_obj, is_top_level);
|
|
|
|
if (line->length() > 0) {
|
|
|
|
line->PrintOn(out);
|
2013-04-10 09:18:41 +00:00
|
|
|
PrintF(out, "\n");
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::ComputeLocation(MessageLocation* target) {
|
|
|
|
*target = MessageLocation(Handle<Script>(heap_.empty_script()), -1, -1);
|
|
|
|
StackTraceFrameIterator it(this);
|
|
|
|
if (!it.done()) {
|
|
|
|
JavaScriptFrame* frame = it.frame();
|
2013-07-11 16:45:58 +00:00
|
|
|
JSFunction* fun = frame->function();
|
2011-05-13 08:54:16 +00:00
|
|
|
Object* script = fun->shared()->script();
|
|
|
|
if (script->IsScript() &&
|
|
|
|
!(Script::cast(script)->source()->IsUndefined())) {
|
|
|
|
int pos = frame->LookupCode()->SourcePosition(frame->pc());
|
|
|
|
// Compute the location from the function and the reloc info.
|
|
|
|
Handle<Script> casted_script(Script::cast(script));
|
|
|
|
*target = MessageLocation(casted_script, pos, pos + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Isolate::ShouldReportException(bool* can_be_caught_externally,
|
|
|
|
bool catchable_by_javascript) {
|
|
|
|
// Find the top-most try-catch handler.
|
|
|
|
StackHandler* handler =
|
|
|
|
StackHandler::FromAddress(Isolate::handler(thread_local_top()));
|
2012-02-09 09:43:37 +00:00
|
|
|
while (handler != NULL && !handler->is_catch()) {
|
2011-05-13 08:54:16 +00:00
|
|
|
handler = handler->next();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the address of the external handler so we can compare the address to
|
|
|
|
// determine which one is closer to the top of the stack.
|
|
|
|
Address external_handler_address =
|
|
|
|
thread_local_top()->try_catch_handler_address();
|
|
|
|
|
|
|
|
// The exception has been externally caught if and only if there is
|
|
|
|
// an external handler which is on top of the top-most try-catch
|
|
|
|
// handler.
|
|
|
|
*can_be_caught_externally = external_handler_address != NULL &&
|
|
|
|
(handler == NULL || handler->address() > external_handler_address ||
|
|
|
|
!catchable_by_javascript);
|
|
|
|
|
|
|
|
if (*can_be_caught_externally) {
|
|
|
|
// Only report the exception if the external handler is verbose.
|
|
|
|
return try_catch_handler()->is_verbose_;
|
|
|
|
} else {
|
|
|
|
// Report the exception if it isn't caught by JavaScript code.
|
|
|
|
return handler == NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-07 09:31:06 +00:00
|
|
|
bool Isolate::IsErrorObject(Handle<Object> obj) {
|
|
|
|
if (!obj->IsJSObject()) return false;
|
|
|
|
|
2014-04-09 12:21:47 +00:00
|
|
|
Handle<String> error_key =
|
|
|
|
factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("$Error"));
|
2014-04-11 12:47:34 +00:00
|
|
|
Handle<Object> error_constructor = Object::GetProperty(
|
|
|
|
js_builtins_object(), error_key).ToHandleChecked();
|
2012-02-07 09:31:06 +00:00
|
|
|
|
2014-04-09 12:21:47 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
2012-02-07 09:31:06 +00:00
|
|
|
for (Object* prototype = *obj; !prototype->IsNull();
|
2013-02-27 13:22:29 +00:00
|
|
|
prototype = prototype->GetPrototype(this)) {
|
2012-02-07 09:31:06 +00:00
|
|
|
if (!prototype->IsJSObject()) return false;
|
2014-04-09 12:21:47 +00:00
|
|
|
if (JSObject::cast(prototype)->map()->constructor() ==
|
|
|
|
*error_constructor) {
|
2012-02-07 09:31:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-09 11:31:10 +00:00
|
|
|
static int fatal_exception_depth = 0;
|
2012-02-07 09:31:06 +00:00
|
|
|
|
|
|
|
void Isolate::DoThrow(Object* exception, MessageLocation* location) {
|
2011-05-13 08:54:16 +00:00
|
|
|
ASSERT(!has_pending_exception());
|
|
|
|
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(this);
|
2013-02-25 14:46:09 +00:00
|
|
|
Handle<Object> exception_handle(exception, this);
|
2011-05-13 08:54:16 +00:00
|
|
|
|
|
|
|
// Determine reporting and whether the exception is caught externally.
|
|
|
|
bool catchable_by_javascript = is_catchable_by_javascript(exception);
|
|
|
|
bool can_be_caught_externally = false;
|
|
|
|
bool should_report_exception =
|
|
|
|
ShouldReportException(&can_be_caught_externally, catchable_by_javascript);
|
|
|
|
bool report_exception = catchable_by_javascript && should_report_exception;
|
2012-02-07 09:31:06 +00:00
|
|
|
bool try_catch_needs_message =
|
2013-07-01 10:54:39 +00:00
|
|
|
can_be_caught_externally && try_catch_handler()->capture_message_ &&
|
|
|
|
!thread_local_top()->rethrowing_message_;
|
2012-02-07 09:31:06 +00:00
|
|
|
bool bootstrapping = bootstrapper()->IsActive();
|
2011-05-13 08:54:16 +00:00
|
|
|
|
2013-07-01 10:54:39 +00:00
|
|
|
thread_local_top()->rethrowing_message_ = false;
|
|
|
|
|
2011-05-13 08:54:16 +00:00
|
|
|
// Notify debugger of exception.
|
|
|
|
if (catchable_by_javascript) {
|
2014-05-27 13:20:58 +00:00
|
|
|
debug()->OnException(exception_handle, report_exception);
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
2012-02-07 09:31:06 +00:00
|
|
|
// Generate the message if required.
|
2011-05-13 08:54:16 +00:00
|
|
|
if (report_exception || try_catch_needs_message) {
|
2012-02-07 09:31:06 +00:00
|
|
|
MessageLocation potential_computed_location;
|
2011-05-13 08:54:16 +00:00
|
|
|
if (location == NULL) {
|
2012-02-07 09:31:06 +00:00
|
|
|
// If no location was specified we use a computed one instead.
|
2011-05-13 08:54:16 +00:00
|
|
|
ComputeLocation(&potential_computed_location);
|
|
|
|
location = &potential_computed_location;
|
|
|
|
}
|
2012-02-07 09:31:06 +00:00
|
|
|
// It's not safe to try to make message objects or collect stack traces
|
|
|
|
// while the bootstrapper is active since the infrastructure may not have
|
|
|
|
// been properly initialized.
|
|
|
|
if (!bootstrapping) {
|
2011-05-13 08:54:16 +00:00
|
|
|
Handle<JSArray> stack_trace_object;
|
2012-02-07 09:31:06 +00:00
|
|
|
if (capture_stack_trace_for_uncaught_exceptions_) {
|
|
|
|
if (IsErrorObject(exception_handle)) {
|
|
|
|
// We fetch the stack trace that corresponds to this error object.
|
2014-06-30 13:16:42 +00:00
|
|
|
Handle<String> key = factory()->hidden_stack_trace_string();
|
|
|
|
Object* stack_property =
|
|
|
|
JSObject::cast(*exception_handle)->GetHiddenProperty(key);
|
|
|
|
// Property lookup may have failed. In this case it's probably not
|
|
|
|
// a valid Error object.
|
|
|
|
if (stack_property->IsJSArray()) {
|
|
|
|
stack_trace_object = Handle<JSArray>(JSArray::cast(stack_property));
|
2012-02-07 09:31:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (stack_trace_object.is_null()) {
|
|
|
|
// Not an error object, we capture at throw site.
|
2011-05-13 08:54:16 +00:00
|
|
|
stack_trace_object = CaptureCurrentStackTrace(
|
|
|
|
stack_trace_for_uncaught_exceptions_frame_limit_,
|
|
|
|
stack_trace_for_uncaught_exceptions_options_);
|
2012-02-07 09:31:06 +00:00
|
|
|
}
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
2012-11-12 17:32:30 +00:00
|
|
|
|
|
|
|
Handle<Object> exception_arg = exception_handle;
|
|
|
|
// If the exception argument is a custom object, turn it into a string
|
|
|
|
// before throwing as uncaught exception. Note that the pending
|
|
|
|
// exception object to be set later must not be turned into a string.
|
|
|
|
if (exception_arg->IsJSObject() && !IsErrorObject(exception_arg)) {
|
2014-04-11 10:41:09 +00:00
|
|
|
MaybeHandle<Object> maybe_exception =
|
|
|
|
Execution::ToDetailString(this, exception_arg);
|
|
|
|
if (!maybe_exception.ToHandle(&exception_arg)) {
|
2013-02-28 17:03:34 +00:00
|
|
|
exception_arg = factory()->InternalizeOneByteString(
|
|
|
|
STATIC_ASCII_VECTOR("exception"));
|
2012-11-12 10:33:20 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 09:31:06 +00:00
|
|
|
Handle<Object> message_obj = MessageHandler::MakeMessageObject(
|
2013-06-04 10:30:05 +00:00
|
|
|
this,
|
2012-02-07 09:31:06 +00:00
|
|
|
"uncaught_exception",
|
|
|
|
location,
|
2012-11-12 17:32:30 +00:00
|
|
|
HandleVector<Object>(&exception_arg, 1),
|
2011-05-13 08:54:16 +00:00
|
|
|
stack_trace_object);
|
2012-02-07 09:31:06 +00:00
|
|
|
thread_local_top()->pending_message_obj_ = *message_obj;
|
|
|
|
if (location != NULL) {
|
|
|
|
thread_local_top()->pending_message_script_ = *location->script();
|
|
|
|
thread_local_top()->pending_message_start_pos_ = location->start_pos();
|
|
|
|
thread_local_top()->pending_message_end_pos_ = location->end_pos();
|
|
|
|
}
|
2013-04-09 11:31:10 +00:00
|
|
|
|
|
|
|
// If the abort-on-uncaught-exception flag is specified, abort on any
|
|
|
|
// exception not caught by JavaScript, even when an external handler is
|
|
|
|
// present. This flag is intended for use by JavaScript developers, so
|
|
|
|
// print a user-friendly stack trace (not an internal one).
|
|
|
|
if (fatal_exception_depth == 0 &&
|
|
|
|
FLAG_abort_on_uncaught_exception &&
|
|
|
|
(report_exception || can_be_caught_externally)) {
|
|
|
|
fatal_exception_depth++;
|
2013-04-10 09:18:41 +00:00
|
|
|
PrintF(stderr,
|
|
|
|
"%s\n\nFROM\n",
|
2013-12-09 07:41:20 +00:00
|
|
|
MessageHandler::GetLocalizedMessage(this, message_obj).get());
|
2013-04-09 11:31:10 +00:00
|
|
|
PrintCurrentStackTrace(stderr);
|
2014-06-30 13:25:46 +00:00
|
|
|
base::OS::Abort();
|
2013-04-09 11:31:10 +00:00
|
|
|
}
|
2011-10-25 13:43:19 +00:00
|
|
|
} else if (location != NULL && !location->script().is_null()) {
|
|
|
|
// We are bootstrapping and caught an error where the location is set
|
|
|
|
// and we have a script for the location.
|
|
|
|
// In this case we could have an extension (or an internal error
|
|
|
|
// somewhere) and we print out the line number at which the error occured
|
|
|
|
// to the console for easier debugging.
|
2014-04-16 13:28:11 +00:00
|
|
|
int line_number =
|
|
|
|
location->script()->GetLineNumber(location->start_pos()) + 1;
|
2013-08-20 08:06:48 +00:00
|
|
|
if (exception->IsString() && location->script()->name()->IsString()) {
|
2014-06-30 13:25:46 +00:00
|
|
|
base::OS::PrintError(
|
2012-05-31 12:26:36 +00:00
|
|
|
"Extension or internal compilation error: %s in %s at line %d.\n",
|
2013-12-09 07:41:20 +00:00
|
|
|
String::cast(exception)->ToCString().get(),
|
|
|
|
String::cast(location->script()->name())->ToCString().get(),
|
2014-04-16 13:28:11 +00:00
|
|
|
line_number);
|
2013-08-20 08:06:48 +00:00
|
|
|
} else if (location->script()->name()->IsString()) {
|
2014-06-30 13:25:46 +00:00
|
|
|
base::OS::PrintError(
|
2012-05-31 12:26:36 +00:00
|
|
|
"Extension or internal compilation error in %s at line %d.\n",
|
2013-12-09 07:41:20 +00:00
|
|
|
String::cast(location->script()->name())->ToCString().get(),
|
2014-04-16 13:28:11 +00:00
|
|
|
line_number);
|
2013-08-20 08:06:48 +00:00
|
|
|
} else {
|
2014-06-30 13:25:46 +00:00
|
|
|
base::OS::PrintError("Extension or internal compilation error.\n");
|
2012-05-31 12:26:36 +00:00
|
|
|
}
|
2014-05-22 13:59:37 +00:00
|
|
|
#ifdef OBJECT_PRINT
|
|
|
|
// Since comments and empty lines have been stripped from the source of
|
|
|
|
// builtins, print the actual source here so that line numbers match.
|
|
|
|
if (location->script()->source()->IsString()) {
|
|
|
|
Handle<String> src(String::cast(location->script()->source()));
|
|
|
|
PrintF("Failing script:\n");
|
|
|
|
int len = src->length();
|
|
|
|
int line_number = 1;
|
|
|
|
PrintF("%5d: ", line_number);
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
uint16_t character = src->Get(i);
|
|
|
|
PrintF("%c", character);
|
|
|
|
if (character == '\n' && i < len - 2) {
|
|
|
|
PrintF("%5d: ", ++line_number);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save the message for reporting if the the exception remains uncaught.
|
|
|
|
thread_local_top()->has_pending_message_ = report_exception;
|
|
|
|
|
|
|
|
// Do not forget to clean catcher_ if currently thrown exception cannot
|
|
|
|
// be caught. If necessary, ReThrow will update the catcher.
|
|
|
|
thread_local_top()->catcher_ = can_be_caught_externally ?
|
|
|
|
try_catch_handler() : NULL;
|
|
|
|
|
2012-02-07 09:31:06 +00:00
|
|
|
set_pending_exception(*exception_handle);
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-11 05:48:33 +00:00
|
|
|
bool Isolate::HasExternalTryCatch() {
|
2011-05-13 08:54:16 +00:00
|
|
|
ASSERT(has_pending_exception());
|
|
|
|
|
2014-06-11 05:48:33 +00:00
|
|
|
return (thread_local_top()->catcher_ != NULL) &&
|
|
|
|
(try_catch_handler() == thread_local_top()->catcher_);
|
|
|
|
}
|
2011-05-13 08:54:16 +00:00
|
|
|
|
|
|
|
|
2014-06-11 05:48:33 +00:00
|
|
|
bool Isolate::IsFinallyOnTop() {
|
2011-05-13 08:54:16 +00:00
|
|
|
// Get the address of the external handler so we can compare the address to
|
|
|
|
// determine which one is closer to the top of the stack.
|
|
|
|
Address external_handler_address =
|
|
|
|
thread_local_top()->try_catch_handler_address();
|
|
|
|
ASSERT(external_handler_address != NULL);
|
|
|
|
|
|
|
|
// The exception has been externally caught if and only if there is
|
|
|
|
// an external handler which is on top of the top-most try-finally
|
|
|
|
// handler.
|
|
|
|
// There should be no try-catch blocks as they would prohibit us from
|
|
|
|
// finding external catcher in the first place (see catcher_ check above).
|
|
|
|
//
|
|
|
|
// Note, that finally clause would rethrow an exception unless it's
|
|
|
|
// aborted by jumps in control flow like return, break, etc. and we'll
|
|
|
|
// have another chances to set proper v8::TryCatch.
|
|
|
|
StackHandler* handler =
|
|
|
|
StackHandler::FromAddress(Isolate::handler(thread_local_top()));
|
|
|
|
while (handler != NULL && handler->address() < external_handler_address) {
|
2012-02-09 09:43:37 +00:00
|
|
|
ASSERT(!handler->is_catch());
|
2014-06-11 05:48:33 +00:00
|
|
|
if (handler->is_finally()) return true;
|
2011-05-13 08:54:16 +00:00
|
|
|
|
|
|
|
handler = handler->next();
|
|
|
|
}
|
|
|
|
|
2014-06-11 05:48:33 +00:00
|
|
|
return false;
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::ReportPendingMessages() {
|
|
|
|
ASSERT(has_pending_exception());
|
2014-06-11 05:48:33 +00:00
|
|
|
bool can_clear_message = PropagatePendingExceptionToExternalTryCatch();
|
2011-05-13 08:54:16 +00:00
|
|
|
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(this);
|
2014-05-23 11:12:25 +00:00
|
|
|
if (thread_local_top_.pending_exception_ ==
|
|
|
|
heap()->termination_exception()) {
|
2011-05-13 08:54:16 +00:00
|
|
|
// Do nothing: if needed, the exception has been already propagated to
|
|
|
|
// v8::TryCatch.
|
|
|
|
} else {
|
|
|
|
if (thread_local_top_.has_pending_message_) {
|
|
|
|
thread_local_top_.has_pending_message_ = false;
|
|
|
|
if (!thread_local_top_.pending_message_obj_->IsTheHole()) {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(this);
|
2013-02-25 14:46:09 +00:00
|
|
|
Handle<Object> message_obj(thread_local_top_.pending_message_obj_,
|
|
|
|
this);
|
2013-07-01 10:54:39 +00:00
|
|
|
if (!thread_local_top_.pending_message_script_->IsTheHole()) {
|
|
|
|
Handle<Script> script(
|
|
|
|
Script::cast(thread_local_top_.pending_message_script_));
|
2011-05-13 08:54:16 +00:00
|
|
|
int start_pos = thread_local_top_.pending_message_start_pos_;
|
|
|
|
int end_pos = thread_local_top_.pending_message_end_pos_;
|
|
|
|
MessageLocation location(script, start_pos, end_pos);
|
|
|
|
MessageHandler::ReportMessage(this, &location, message_obj);
|
|
|
|
} else {
|
|
|
|
MessageHandler::ReportMessage(this, NULL, message_obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-11 05:48:33 +00:00
|
|
|
if (can_clear_message) clear_pending_message();
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-03 21:47:39 +00:00
|
|
|
MessageLocation Isolate::GetMessageLocation() {
|
|
|
|
ASSERT(has_pending_exception());
|
|
|
|
|
2014-03-24 10:07:15 +00:00
|
|
|
if (thread_local_top_.pending_exception_ != heap()->termination_exception() &&
|
2012-12-03 21:47:39 +00:00
|
|
|
thread_local_top_.has_pending_message_ &&
|
|
|
|
!thread_local_top_.pending_message_obj_->IsTheHole() &&
|
2013-07-01 10:54:39 +00:00
|
|
|
!thread_local_top_.pending_message_obj_->IsTheHole()) {
|
|
|
|
Handle<Script> script(
|
|
|
|
Script::cast(thread_local_top_.pending_message_script_));
|
2012-12-03 21:47:39 +00:00
|
|
|
int start_pos = thread_local_top_.pending_message_start_pos_;
|
|
|
|
int end_pos = thread_local_top_.pending_message_end_pos_;
|
|
|
|
return MessageLocation(script, start_pos, end_pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
return MessageLocation();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-13 08:54:16 +00:00
|
|
|
bool Isolate::OptionalRescheduleException(bool is_bottom_call) {
|
|
|
|
ASSERT(has_pending_exception());
|
|
|
|
PropagatePendingExceptionToExternalTryCatch();
|
|
|
|
|
2014-03-24 10:07:15 +00:00
|
|
|
bool is_termination_exception =
|
|
|
|
pending_exception() == heap_.termination_exception();
|
2011-05-13 08:54:16 +00:00
|
|
|
|
2014-03-24 10:07:15 +00:00
|
|
|
// Do not reschedule the exception if this is the bottom call.
|
|
|
|
bool clear_exception = is_bottom_call;
|
2011-05-13 08:54:16 +00:00
|
|
|
|
2014-03-24 10:07:15 +00:00
|
|
|
if (is_termination_exception) {
|
|
|
|
if (is_bottom_call) {
|
2011-05-13 08:54:16 +00:00
|
|
|
thread_local_top()->external_caught_exception_ = false;
|
|
|
|
clear_pending_exception();
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-24 10:07:15 +00:00
|
|
|
} else if (thread_local_top()->external_caught_exception_) {
|
|
|
|
// If the exception is externally caught, clear it if there are no
|
|
|
|
// JavaScript frames on the way to the C++ frame that has the
|
|
|
|
// external handler.
|
|
|
|
ASSERT(thread_local_top()->try_catch_handler_address() != NULL);
|
|
|
|
Address external_handler_address =
|
|
|
|
thread_local_top()->try_catch_handler_address();
|
|
|
|
JavaScriptFrameIterator it(this);
|
|
|
|
if (it.done() || (it.frame()->sp() > external_handler_address)) {
|
|
|
|
clear_exception = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the exception if needed.
|
|
|
|
if (clear_exception) {
|
|
|
|
thread_local_top()->external_caught_exception_ = false;
|
|
|
|
clear_pending_exception();
|
|
|
|
return false;
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reschedule the exception.
|
|
|
|
thread_local_top()->scheduled_exception_ = pending_exception();
|
|
|
|
clear_pending_exception();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::SetCaptureStackTraceForUncaughtExceptions(
|
|
|
|
bool capture,
|
|
|
|
int frame_limit,
|
|
|
|
StackTrace::StackTraceOptions options) {
|
|
|
|
capture_stack_trace_for_uncaught_exceptions_ = capture;
|
|
|
|
stack_trace_for_uncaught_exceptions_frame_limit_ = frame_limit;
|
|
|
|
stack_trace_for_uncaught_exceptions_options_ = options;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
Handle<Context> Isolate::native_context() {
|
2014-07-01 12:12:34 +00:00
|
|
|
return handle(context()->native_context());
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-28 11:25:08 +00:00
|
|
|
Handle<Context> Isolate::global_context() {
|
2014-07-01 12:12:34 +00:00
|
|
|
return handle(context()->global_object()->global_context());
|
2012-08-28 11:25:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
Handle<Context> Isolate::GetCallingNativeContext() {
|
2013-02-15 09:27:10 +00:00
|
|
|
JavaScriptFrameIterator it(this);
|
2014-06-03 14:39:55 +00:00
|
|
|
if (debug_->in_debug_scope()) {
|
2011-05-13 08:54:16 +00:00
|
|
|
while (!it.done()) {
|
|
|
|
JavaScriptFrame* frame = it.frame();
|
|
|
|
Context* context = Context::cast(frame->context());
|
2012-08-17 09:03:08 +00:00
|
|
|
if (context->native_context() == *debug_->debug_context()) {
|
2011-05-13 08:54:16 +00:00
|
|
|
it.Advance();
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (it.done()) return Handle<Context>::null();
|
|
|
|
JavaScriptFrame* frame = it.frame();
|
|
|
|
Context* context = Context::cast(frame->context());
|
2012-08-17 09:03:08 +00:00
|
|
|
return Handle<Context>(context->native_context());
|
2011-05-13 08:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char* Isolate::ArchiveThread(char* to) {
|
2014-05-27 07:57:22 +00:00
|
|
|
MemCopy(to, reinterpret_cast<char*>(thread_local_top()),
|
|
|
|
sizeof(ThreadLocalTop));
|
2011-05-13 08:54:16 +00:00
|
|
|
InitializeThreadLocal();
|
2011-10-10 09:21:48 +00:00
|
|
|
clear_pending_exception();
|
|
|
|
clear_pending_message();
|
|
|
|
clear_scheduled_exception();
|
2011-05-13 08:54:16 +00:00
|
|
|
return to + sizeof(ThreadLocalTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char* Isolate::RestoreThread(char* from) {
|
2014-05-27 07:57:22 +00:00
|
|
|
MemCopy(reinterpret_cast<char*>(thread_local_top()), from,
|
|
|
|
sizeof(ThreadLocalTop));
|
|
|
|
// This might be just paranoia, but it seems to be needed in case a
|
|
|
|
// thread_local_top_ is restored on a separate OS thread.
|
2011-05-13 08:54:16 +00:00
|
|
|
#ifdef USE_SIMULATOR
|
|
|
|
thread_local_top()->simulator_ = Simulator::current(this);
|
|
|
|
#endif
|
2011-06-07 18:33:03 +00:00
|
|
|
ASSERT(context() == NULL || context()->IsContext());
|
2011-05-13 08:54:16 +00:00
|
|
|
return from + sizeof(ThreadLocalTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate::ThreadDataTable::ThreadDataTable()
|
|
|
|
: list_(NULL) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-12 11:57:51 +00:00
|
|
|
Isolate::ThreadDataTable::~ThreadDataTable() {
|
|
|
|
// TODO(svenpanne) The assertion below would fire if an embedder does not
|
|
|
|
// cleanly dispose all Isolates before disposing v8, so we are conservative
|
|
|
|
// and leave it out for now.
|
|
|
|
// ASSERT_EQ(NULL, list_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-28 10:55:47 +00:00
|
|
|
Isolate::PerIsolateThreadData::~PerIsolateThreadData() {
|
|
|
|
#if defined(USE_SIMULATOR)
|
|
|
|
delete simulator_;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate::PerIsolateThreadData*
|
2011-04-11 23:46:22 +00:00
|
|
|
Isolate::ThreadDataTable::Lookup(Isolate* isolate,
|
|
|
|
ThreadId thread_id) {
|
2011-03-18 20:35:07 +00:00
|
|
|
for (PerIsolateThreadData* data = list_; data != NULL; data = data->next_) {
|
|
|
|
if (data->Matches(isolate, thread_id)) return data;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::ThreadDataTable::Insert(Isolate::PerIsolateThreadData* data) {
|
|
|
|
if (list_ != NULL) list_->prev_ = data;
|
|
|
|
data->next_ = list_;
|
|
|
|
list_ = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::ThreadDataTable::Remove(PerIsolateThreadData* data) {
|
|
|
|
if (list_ == data) list_ = data->next_;
|
|
|
|
if (data->next_ != NULL) data->next_->prev_ = data->prev_;
|
|
|
|
if (data->prev_ != NULL) data->prev_->next_ = data->next_;
|
2011-08-18 12:14:12 +00:00
|
|
|
delete data;
|
2011-03-18 20:35:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-07 18:33:03 +00:00
|
|
|
void Isolate::ThreadDataTable::RemoveAllThreads(Isolate* isolate) {
|
|
|
|
PerIsolateThreadData* data = list_;
|
|
|
|
while (data != NULL) {
|
|
|
|
PerIsolateThreadData* next = data->next_;
|
|
|
|
if (data->isolate() == isolate) Remove(data);
|
|
|
|
data = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
#define TRACE_ISOLATE(tag) \
|
|
|
|
do { \
|
|
|
|
if (FLAG_trace_isolates) { \
|
2013-03-06 07:25:46 +00:00
|
|
|
PrintF("Isolate %p (id %d)" #tag "\n", \
|
|
|
|
reinterpret_cast<void*>(this), id()); \
|
2011-03-18 20:35:07 +00:00
|
|
|
} \
|
|
|
|
} while (false)
|
|
|
|
#else
|
|
|
|
#define TRACE_ISOLATE(tag)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2013-10-02 09:01:40 +00:00
|
|
|
Isolate::Isolate()
|
2013-11-20 15:16:18 +00:00
|
|
|
: embedder_data_(),
|
|
|
|
state_(UNINITIALIZED),
|
2011-03-18 20:35:07 +00:00
|
|
|
entry_stack_(NULL),
|
|
|
|
stack_trace_nesting_level_(0),
|
|
|
|
incomplete_message_(NULL),
|
|
|
|
bootstrapper_(NULL),
|
|
|
|
runtime_profiler_(NULL),
|
|
|
|
compilation_cache_(NULL),
|
2011-08-04 15:18:18 +00:00
|
|
|
counters_(NULL),
|
2011-03-18 20:35:07 +00:00
|
|
|
code_range_(NULL),
|
2011-08-04 15:18:18 +00:00
|
|
|
logger_(NULL),
|
|
|
|
stats_table_(NULL),
|
2011-03-18 20:35:07 +00:00
|
|
|
stub_cache_(NULL),
|
2014-05-06 11:25:37 +00:00
|
|
|
code_aging_helper_(NULL),
|
2011-03-18 20:35:07 +00:00
|
|
|
deoptimizer_data_(NULL),
|
The current
version is passing all the existing test + a bunch of new tests
(packaged in the change list, too).
The patch extends the SlotRef object to describe captured and duplicated
objects. Since the SlotRefs are not independent of each other anymore,
there is a new SlotRefValueBuilder class that stores the SlotRefs and
later materializes the objects from the SlotRefs.
Note that unlike the previous implementation of SlotRefs, we now build
the SlotRef entries for the entire frame, not just the particular
function. This is because duplicate objects might refer to previous
captured objects (that might live inside other inlined function's part
of the frame).
We also need to store the materialized objects between other potential
invocations of the same arguments object so that we materialize each
captured object at most once. The materialized objects of frames live
in the new MaterielizedObjectStore object (contained in Isolate),
indexed by the frame's FP address. Each argument materialization (and
deoptimization) tries to lookup its captured objects in the store before
building new ones. Deoptimization also removes the materialized objects
from the store. We also schedule a lazy deopt to be sure that we always
get rid of the materialized objects and that the optmized function
adopts the materialized objects (instead of happily computing with its
captured representations).
Concerns:
- Is the FP address the right key for a frame? (Note that deoptimizer's
representation of frame is different from the argument object
materializer's one - it is not easy to find common ground.)
- Performance is suboptimal in several places, but a quick local run of
benchmarks does not seem to show a perf hit. Examples of possible
improvements: smarter generation of SlotRefs (build other functions'
SlotRefs only for captured objects and only if necessary), smarter
lookup of stored materialized objects.
- Ideally, we would like to share the code for argument materialization
with deoptimizer's materializer. However, the supporting data structures
(mainly the frame descriptor) are quite different in each case, so it
looks more like a separate project.
Thanks for any feedback.
R=danno@chromium.org, mstarzinger@chromium.org
LOG=N
BUG=
Committed: https://code.google.com/p/v8/source/detail?r=18918
Review URL: https://codereview.chromium.org/103243005
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18936 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-30 10:33:53 +00:00
|
|
|
materialized_object_store_(NULL),
|
2011-03-18 20:35:07 +00:00
|
|
|
capture_stack_trace_for_uncaught_exceptions_(false),
|
|
|
|
stack_trace_for_uncaught_exceptions_frame_limit_(0),
|
|
|
|
stack_trace_for_uncaught_exceptions_options_(StackTrace::kOverview),
|
|
|
|
memory_allocator_(NULL),
|
|
|
|
keyed_lookup_cache_(NULL),
|
|
|
|
context_slot_cache_(NULL),
|
|
|
|
descriptor_lookup_cache_(NULL),
|
|
|
|
handle_scope_implementer_(NULL),
|
2011-04-12 08:27:38 +00:00
|
|
|
unicode_cache_(NULL),
|
2013-07-03 11:40:30 +00:00
|
|
|
runtime_zone_(this),
|
2011-09-20 10:08:39 +00:00
|
|
|
inner_pointer_to_code_cache_(NULL),
|
2012-12-31 11:13:50 +00:00
|
|
|
write_iterator_(NULL),
|
2011-03-18 20:35:07 +00:00
|
|
|
global_handles_(NULL),
|
2013-08-05 09:46:23 +00:00
|
|
|
eternal_handles_(NULL),
|
2011-03-18 20:35:07 +00:00
|
|
|
thread_manager_(NULL),
|
2011-11-15 22:48:55 +00:00
|
|
|
has_installed_extensions_(false),
|
2011-03-18 20:35:07 +00:00
|
|
|
string_tracker_(NULL),
|
|
|
|
regexp_stack_(NULL),
|
2012-03-09 12:07:29 +00:00
|
|
|
date_cache_(NULL),
|
2012-12-18 16:25:45 +00:00
|
|
|
code_stub_interface_descriptors_(NULL),
|
This is a preview of a first step towards unification of the hydrogen
call machinery. The change replaces CallNamed, CallKeyed,
CallConstantFunction and CallKnownGlobal hydrogen instructions with two
new instructions with a more lower level semantics:
1. CallJSFunction for direct calls of JSFunction objects (no
argument adaptation)
2. CallWithDescriptor for calls of a given Code object according to
the supplied calling convention.
Details:
CallJSFunction should be straightforward, the main difference from the
existing InvokeFunction instruction is the absence of argument adaptor
handling. (As a next step, we will replace InvokeFunction with an
equivalent hydrogen code.)
For CallWithDescriptor, the calling conventions are represented by a
tweaked version of CallStubInterfaceDescriptor. In addition to the
parameter-register mapping, we also define parameter-representation
mapping there. The CallWithDescriptor instruction has variable number of
parameters now - this required some simple tweaks in Lithium, which
assumed fixed number of arguments in some places.
The calling conventions used in the calls are initialized in the
CallDescriptors class (code-stubs.h, <arch>/code-stubs-<arch>.cc), and
they live in a new table in the Isolate class. I should say I am not
quite sure about Representation::Integer32() representation for some of
the params of ArgumentAdaptorCall - it is not clear to me wether the
params could not end up on the stack and thus confuse the GC.
The change also includes an earlier small change to argument adaptor
(https://codereview.chromium.org/98463007) that avoids passing a naked
pointer to the code entry as a parameter. I am sorry for packaging that
with an already biggish change.
Performance implications:
Locally, I see a small regression (.2% or so). It is hard to say where
exactly it comes from, but I do see inefficient call sequences to the
adaptor trampoline. For example:
;;; <@78,#24> constant-t
bf85aa515a mov edi,0x5a51aa85 ;; debug: position 29
;;; <@72,#53> load-named-field
8b7717 mov esi,[edi+0x17] ;; debug: position 195
;;; <@80,#51> constant-s
b902000000 mov ecx,0x2 ;; debug: position 195
;;; <@81,#51> gap
894df0 mov [ebp+0xf0],ecx
;;; <@82,#103> constant-i
bb01000000 mov ebx,0x1
;;; <@84,#102> constant-i
b902000000 mov ecx,0x2
;;; <@85,#102> gap
89d8 mov eax,ebx
89cb mov ebx,ecx
8b4df0 mov ecx,[ebp+0xf0]
;;; <@86,#58> call-with-descriptor
e8ef57fcff call ArgumentsAdaptorTrampoline (0x2d80e6e0) ;; code: BUILTIN
Note the silly handling of ecx; the hydrogen for this code is:
0 4 s27 Constant 1 range:1_1 <|@
0 3 t30 Constant 0x5bc1aa85 <JS Function xyz (SharedFunctionInfo 0x5bc1a919)> type:object <|@
0 1 t36 LoadNamedField t30.[in-object]@24 <|@
0 1 t38 Constant 0x2300e6a1 <Code> <|@
0 1 i102 Constant 2 range:2_2 <|@
0 1 i103 Constant 1 range:1_1 <|@
0 2 t41 CallWithDescriptor t38 t30 t36 s27 i103 i102 #2 changes[*] <|@
BUG=
R=verwaest@chromium.org, danno@chromium.org
Review URL: https://codereview.chromium.org/104663004
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18626 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-15 17:00:35 +00:00
|
|
|
call_descriptors_(NULL),
|
2013-09-10 11:13:55 +00:00
|
|
|
// TODO(bmeurer) Initialized lazily because it depends on flags; can
|
|
|
|
// be fixed once the default isolate cleanup is done.
|
|
|
|
random_number_generator_(NULL),
|
2014-05-22 09:36:20 +00:00
|
|
|
serializer_enabled_(false),
|
2013-09-03 09:35:26 +00:00
|
|
|
has_fatal_error_(false),
|
2013-06-28 13:40:41 +00:00
|
|
|
initialized_from_snapshot_(false),
|
2013-04-02 07:53:50 +00:00
|
|
|
cpu_profiler_(NULL),
|
2013-04-02 08:03:01 +00:00
|
|
|
heap_profiler_(NULL),
|
2013-06-28 13:40:41 +00:00
|
|
|
function_entry_hook_(NULL),
|
2012-07-19 18:58:23 +00:00
|
|
|
deferred_handles_head_(NULL),
|
2013-09-25 15:14:12 +00:00
|
|
|
optimizing_compiler_thread_(NULL),
|
2013-05-21 06:36:24 +00:00
|
|
|
sweeper_thread_(NULL),
|
2013-11-19 11:52:47 +00:00
|
|
|
num_sweeper_threads_(0),
|
2014-02-13 16:09:28 +00:00
|
|
|
stress_deopt_count_(0),
|
2014-06-24 14:13:15 +00:00
|
|
|
next_optimization_id_(0),
|
|
|
|
use_counter_callback_(NULL) {
|
2014-06-05 12:14:47 +00:00
|
|
|
id_ = base::NoBarrier_AtomicIncrement(&isolate_counter_, 1);
|
2011-03-18 20:35:07 +00:00
|
|
|
TRACE_ISOLATE(constructor);
|
|
|
|
|
|
|
|
memset(isolate_addresses_, 0,
|
2011-09-08 16:29:57 +00:00
|
|
|
sizeof(isolate_addresses_[0]) * (kIsolateAddressCount + 1));
|
2011-03-18 20:35:07 +00:00
|
|
|
|
|
|
|
heap_.isolate_ = this;
|
|
|
|
stack_guard_.isolate_ = this;
|
|
|
|
|
2011-05-05 18:55:31 +00:00
|
|
|
// ThreadManager is initialized early to support locking an isolate
|
|
|
|
// before it is entered.
|
|
|
|
thread_manager_ = new ThreadManager();
|
|
|
|
thread_manager_->isolate_ = this;
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
// heap_histograms_ initializes itself.
|
|
|
|
memset(&js_spill_information_, 0, sizeof(js_spill_information_));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
handle_scope_data_.Initialize();
|
|
|
|
|
|
|
|
#define ISOLATE_INIT_EXECUTE(type, name, initial_value) \
|
|
|
|
name##_ = (initial_value);
|
|
|
|
ISOLATE_INIT_LIST(ISOLATE_INIT_EXECUTE)
|
|
|
|
#undef ISOLATE_INIT_EXECUTE
|
|
|
|
|
|
|
|
#define ISOLATE_INIT_ARRAY_EXECUTE(type, name, length) \
|
|
|
|
memset(name##_, 0, sizeof(type) * length);
|
|
|
|
ISOLATE_INIT_ARRAY_LIST(ISOLATE_INIT_ARRAY_EXECUTE)
|
|
|
|
#undef ISOLATE_INIT_ARRAY_EXECUTE
|
2014-05-05 07:10:38 +00:00
|
|
|
|
|
|
|
InitializeLoggingAndCounters();
|
|
|
|
debug_ = new Debug(this);
|
2011-03-18 20:35:07 +00:00
|
|
|
}
|
|
|
|
|
2013-01-30 12:19:32 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void Isolate::TearDown() {
|
|
|
|
TRACE_ISOLATE(tear_down);
|
|
|
|
|
|
|
|
// Temporarily set this isolate as current so that various parts of
|
|
|
|
// the isolate can access it in their destructors without having a
|
|
|
|
// direct pointer. We don't use Enter/Exit here to avoid
|
|
|
|
// initializing the thread data.
|
|
|
|
PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData();
|
|
|
|
Isolate* saved_isolate = UncheckedCurrent();
|
|
|
|
SetIsolateThreadLocals(this, NULL);
|
|
|
|
|
|
|
|
Deinit();
|
|
|
|
|
2014-07-02 07:44:02 +00:00
|
|
|
{ base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
|
2012-03-30 14:30:46 +00:00
|
|
|
thread_data_table_->RemoveAllThreads(this);
|
2011-06-07 18:33:03 +00:00
|
|
|
}
|
|
|
|
|
2012-06-19 18:38:03 +00:00
|
|
|
if (serialize_partial_snapshot_cache_ != NULL) {
|
|
|
|
delete[] serialize_partial_snapshot_cache_;
|
|
|
|
serialize_partial_snapshot_cache_ = NULL;
|
|
|
|
}
|
|
|
|
|
2014-05-09 08:40:18 +00:00
|
|
|
delete this;
|
2011-03-18 20:35:07 +00:00
|
|
|
|
|
|
|
// Restore the previous current isolate.
|
|
|
|
SetIsolateThreadLocals(saved_isolate, saved_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-12 11:57:51 +00:00
|
|
|
void Isolate::GlobalTearDown() {
|
|
|
|
delete thread_data_table_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void Isolate::Deinit() {
|
|
|
|
if (state_ == INITIALIZED) {
|
|
|
|
TRACE_ISOLATE(deinit);
|
|
|
|
|
2014-05-26 08:05:04 +00:00
|
|
|
debug()->Unload();
|
|
|
|
|
2013-11-19 11:52:47 +00:00
|
|
|
if (concurrent_recompilation_enabled()) {
|
2013-09-25 15:14:12 +00:00
|
|
|
optimizing_compiler_thread_->Stop();
|
|
|
|
delete optimizing_compiler_thread_;
|
2013-11-19 11:52:47 +00:00
|
|
|
optimizing_compiler_thread_ = NULL;
|
2013-09-25 15:14:12 +00:00
|
|
|
}
|
2013-03-05 16:22:08 +00:00
|
|
|
|
2013-11-19 11:52:47 +00:00
|
|
|
for (int i = 0; i < num_sweeper_threads_; i++) {
|
|
|
|
sweeper_thread_[i]->Stop();
|
|
|
|
delete sweeper_thread_[i];
|
|
|
|
sweeper_thread_[i] = NULL;
|
2013-01-30 12:19:32 +00:00
|
|
|
}
|
2013-11-19 11:52:47 +00:00
|
|
|
delete[] sweeper_thread_;
|
|
|
|
sweeper_thread_ = NULL;
|
|
|
|
|
2014-02-13 15:36:17 +00:00
|
|
|
if (FLAG_job_based_sweeping &&
|
|
|
|
heap_.mark_compact_collector()->IsConcurrentSweepingInProgress()) {
|
|
|
|
heap_.mark_compact_collector()->WaitUntilSweepingCompleted();
|
|
|
|
}
|
2013-01-30 12:19:32 +00:00
|
|
|
|
2013-03-06 10:49:34 +00:00
|
|
|
if (FLAG_hydrogen_stats) GetHStatistics()->Print();
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2013-07-18 08:12:01 +00:00
|
|
|
if (FLAG_print_deopt_stress) {
|
|
|
|
PrintF(stdout, "=== Stress deopt counter: %u\n", stress_deopt_count_);
|
|
|
|
}
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
// We must stop the logger before we tear down other components.
|
2013-04-08 15:09:03 +00:00
|
|
|
Sampler* sampler = logger_->sampler();
|
|
|
|
if (sampler && sampler->IsActive()) sampler->Stop();
|
2011-03-18 20:35:07 +00:00
|
|
|
|
|
|
|
delete deoptimizer_data_;
|
|
|
|
deoptimizer_data_ = NULL;
|
|
|
|
builtins_.TearDown();
|
|
|
|
bootstrapper_->TearDown();
|
|
|
|
|
|
|
|
if (runtime_profiler_ != NULL) {
|
|
|
|
delete runtime_profiler_;
|
|
|
|
runtime_profiler_ = NULL;
|
|
|
|
}
|
|
|
|
heap_.TearDown();
|
|
|
|
logger_->TearDown();
|
|
|
|
|
2013-04-16 08:54:33 +00:00
|
|
|
delete heap_profiler_;
|
|
|
|
heap_profiler_ = NULL;
|
|
|
|
delete cpu_profiler_;
|
|
|
|
cpu_profiler_ = NULL;
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
// The default isolate is re-initializable due to legacy API.
|
2011-08-04 15:18:18 +00:00
|
|
|
state_ = UNINITIALIZED;
|
2011-03-18 20:35:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-19 18:38:03 +00:00
|
|
|
void Isolate::PushToPartialSnapshotCache(Object* obj) {
|
|
|
|
int length = serialize_partial_snapshot_cache_length();
|
|
|
|
int capacity = serialize_partial_snapshot_cache_capacity();
|
|
|
|
|
|
|
|
if (length >= capacity) {
|
2012-06-19 19:37:33 +00:00
|
|
|
int new_capacity = static_cast<int>((capacity + 10) * 1.2);
|
2012-06-19 18:38:03 +00:00
|
|
|
Object** new_array = new Object*[new_capacity];
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
new_array[i] = serialize_partial_snapshot_cache()[i];
|
|
|
|
}
|
|
|
|
if (capacity != 0) delete[] serialize_partial_snapshot_cache();
|
|
|
|
set_serialize_partial_snapshot_cache(new_array);
|
|
|
|
set_serialize_partial_snapshot_cache_capacity(new_capacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
serialize_partial_snapshot_cache()[length] = obj;
|
|
|
|
set_serialize_partial_snapshot_cache_length(length + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void Isolate::SetIsolateThreadLocals(Isolate* isolate,
|
|
|
|
PerIsolateThreadData* data) {
|
2014-06-30 13:25:46 +00:00
|
|
|
base::Thread::SetThreadLocal(isolate_key_, isolate);
|
|
|
|
base::Thread::SetThreadLocal(per_isolate_thread_data_key_, data);
|
2011-03-18 20:35:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Isolate::~Isolate() {
|
|
|
|
TRACE_ISOLATE(destructor);
|
|
|
|
|
2013-07-03 11:40:30 +00:00
|
|
|
// Has to be called while counters_ are still alive
|
|
|
|
runtime_zone_.DeleteKeptSegment();
|
|
|
|
|
2014-04-15 10:45:34 +00:00
|
|
|
// The entry stack must be empty when we get here.
|
2013-07-02 07:21:07 +00:00
|
|
|
ASSERT(entry_stack_ == NULL || entry_stack_->previous_item == NULL);
|
|
|
|
|
|
|
|
delete entry_stack_;
|
|
|
|
entry_stack_ = NULL;
|
|
|
|
|
2011-08-18 12:14:12 +00:00
|
|
|
delete[] assembler_spare_buffer_;
|
|
|
|
assembler_spare_buffer_ = NULL;
|
|
|
|
|
2011-04-12 08:27:38 +00:00
|
|
|
delete unicode_cache_;
|
|
|
|
unicode_cache_ = NULL;
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2012-03-09 12:07:29 +00:00
|
|
|
delete date_cache_;
|
|
|
|
date_cache_ = NULL;
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
delete[] code_stub_interface_descriptors_;
|
|
|
|
code_stub_interface_descriptors_ = NULL;
|
|
|
|
|
This is a preview of a first step towards unification of the hydrogen
call machinery. The change replaces CallNamed, CallKeyed,
CallConstantFunction and CallKnownGlobal hydrogen instructions with two
new instructions with a more lower level semantics:
1. CallJSFunction for direct calls of JSFunction objects (no
argument adaptation)
2. CallWithDescriptor for calls of a given Code object according to
the supplied calling convention.
Details:
CallJSFunction should be straightforward, the main difference from the
existing InvokeFunction instruction is the absence of argument adaptor
handling. (As a next step, we will replace InvokeFunction with an
equivalent hydrogen code.)
For CallWithDescriptor, the calling conventions are represented by a
tweaked version of CallStubInterfaceDescriptor. In addition to the
parameter-register mapping, we also define parameter-representation
mapping there. The CallWithDescriptor instruction has variable number of
parameters now - this required some simple tweaks in Lithium, which
assumed fixed number of arguments in some places.
The calling conventions used in the calls are initialized in the
CallDescriptors class (code-stubs.h, <arch>/code-stubs-<arch>.cc), and
they live in a new table in the Isolate class. I should say I am not
quite sure about Representation::Integer32() representation for some of
the params of ArgumentAdaptorCall - it is not clear to me wether the
params could not end up on the stack and thus confuse the GC.
The change also includes an earlier small change to argument adaptor
(https://codereview.chromium.org/98463007) that avoids passing a naked
pointer to the code entry as a parameter. I am sorry for packaging that
with an already biggish change.
Performance implications:
Locally, I see a small regression (.2% or so). It is hard to say where
exactly it comes from, but I do see inefficient call sequences to the
adaptor trampoline. For example:
;;; <@78,#24> constant-t
bf85aa515a mov edi,0x5a51aa85 ;; debug: position 29
;;; <@72,#53> load-named-field
8b7717 mov esi,[edi+0x17] ;; debug: position 195
;;; <@80,#51> constant-s
b902000000 mov ecx,0x2 ;; debug: position 195
;;; <@81,#51> gap
894df0 mov [ebp+0xf0],ecx
;;; <@82,#103> constant-i
bb01000000 mov ebx,0x1
;;; <@84,#102> constant-i
b902000000 mov ecx,0x2
;;; <@85,#102> gap
89d8 mov eax,ebx
89cb mov ebx,ecx
8b4df0 mov ecx,[ebp+0xf0]
;;; <@86,#58> call-with-descriptor
e8ef57fcff call ArgumentsAdaptorTrampoline (0x2d80e6e0) ;; code: BUILTIN
Note the silly handling of ecx; the hydrogen for this code is:
0 4 s27 Constant 1 range:1_1 <|@
0 3 t30 Constant 0x5bc1aa85 <JS Function xyz (SharedFunctionInfo 0x5bc1a919)> type:object <|@
0 1 t36 LoadNamedField t30.[in-object]@24 <|@
0 1 t38 Constant 0x2300e6a1 <Code> <|@
0 1 i102 Constant 2 range:2_2 <|@
0 1 i103 Constant 1 range:1_1 <|@
0 2 t41 CallWithDescriptor t38 t30 t36 s27 i103 i102 #2 changes[*] <|@
BUG=
R=verwaest@chromium.org, danno@chromium.org
Review URL: https://codereview.chromium.org/104663004
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18626 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-15 17:00:35 +00:00
|
|
|
delete[] call_descriptors_;
|
|
|
|
call_descriptors_ = NULL;
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
delete regexp_stack_;
|
|
|
|
regexp_stack_ = NULL;
|
|
|
|
|
|
|
|
delete descriptor_lookup_cache_;
|
|
|
|
descriptor_lookup_cache_ = NULL;
|
|
|
|
delete context_slot_cache_;
|
|
|
|
context_slot_cache_ = NULL;
|
|
|
|
delete keyed_lookup_cache_;
|
|
|
|
keyed_lookup_cache_ = NULL;
|
|
|
|
|
|
|
|
delete stub_cache_;
|
|
|
|
stub_cache_ = NULL;
|
2014-05-06 11:25:37 +00:00
|
|
|
delete code_aging_helper_;
|
|
|
|
code_aging_helper_ = NULL;
|
2011-03-18 20:35:07 +00:00
|
|
|
delete stats_table_;
|
|
|
|
stats_table_ = NULL;
|
|
|
|
|
The current
version is passing all the existing test + a bunch of new tests
(packaged in the change list, too).
The patch extends the SlotRef object to describe captured and duplicated
objects. Since the SlotRefs are not independent of each other anymore,
there is a new SlotRefValueBuilder class that stores the SlotRefs and
later materializes the objects from the SlotRefs.
Note that unlike the previous implementation of SlotRefs, we now build
the SlotRef entries for the entire frame, not just the particular
function. This is because duplicate objects might refer to previous
captured objects (that might live inside other inlined function's part
of the frame).
We also need to store the materialized objects between other potential
invocations of the same arguments object so that we materialize each
captured object at most once. The materialized objects of frames live
in the new MaterielizedObjectStore object (contained in Isolate),
indexed by the frame's FP address. Each argument materialization (and
deoptimization) tries to lookup its captured objects in the store before
building new ones. Deoptimization also removes the materialized objects
from the store. We also schedule a lazy deopt to be sure that we always
get rid of the materialized objects and that the optmized function
adopts the materialized objects (instead of happily computing with its
captured representations).
Concerns:
- Is the FP address the right key for a frame? (Note that deoptimizer's
representation of frame is different from the argument object
materializer's one - it is not easy to find common ground.)
- Performance is suboptimal in several places, but a quick local run of
benchmarks does not seem to show a perf hit. Examples of possible
improvements: smarter generation of SlotRefs (build other functions'
SlotRefs only for captured objects and only if necessary), smarter
lookup of stored materialized objects.
- Ideally, we would like to share the code for argument materialization
with deoptimizer's materializer. However, the supporting data structures
(mainly the frame descriptor) are quite different in each case, so it
looks more like a separate project.
Thanks for any feedback.
R=danno@chromium.org, mstarzinger@chromium.org
LOG=N
BUG=
Committed: https://code.google.com/p/v8/source/detail?r=18918
Review URL: https://codereview.chromium.org/103243005
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18936 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-30 10:33:53 +00:00
|
|
|
delete materialized_object_store_;
|
|
|
|
materialized_object_store_ = NULL;
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
delete logger_;
|
|
|
|
logger_ = NULL;
|
|
|
|
|
|
|
|
delete counters_;
|
|
|
|
counters_ = NULL;
|
|
|
|
|
|
|
|
delete handle_scope_implementer_;
|
|
|
|
handle_scope_implementer_ = NULL;
|
|
|
|
|
|
|
|
delete compilation_cache_;
|
|
|
|
compilation_cache_ = NULL;
|
|
|
|
delete bootstrapper_;
|
|
|
|
bootstrapper_ = NULL;
|
2011-09-20 10:08:39 +00:00
|
|
|
delete inner_pointer_to_code_cache_;
|
|
|
|
inner_pointer_to_code_cache_ = NULL;
|
2012-12-31 11:13:50 +00:00
|
|
|
delete write_iterator_;
|
|
|
|
write_iterator_ = NULL;
|
2011-03-18 20:35:07 +00:00
|
|
|
|
|
|
|
delete thread_manager_;
|
|
|
|
thread_manager_ = NULL;
|
|
|
|
|
|
|
|
delete string_tracker_;
|
|
|
|
string_tracker_ = NULL;
|
|
|
|
|
|
|
|
delete memory_allocator_;
|
|
|
|
memory_allocator_ = NULL;
|
|
|
|
delete code_range_;
|
|
|
|
code_range_ = NULL;
|
|
|
|
delete global_handles_;
|
|
|
|
global_handles_ = NULL;
|
2013-08-05 09:46:23 +00:00
|
|
|
delete eternal_handles_;
|
|
|
|
eternal_handles_ = NULL;
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2013-09-02 11:39:23 +00:00
|
|
|
delete string_stream_debug_object_cache_;
|
2013-07-01 12:07:53 +00:00
|
|
|
string_stream_debug_object_cache_ = NULL;
|
|
|
|
|
2011-08-17 08:48:54 +00:00
|
|
|
delete external_reference_table_;
|
|
|
|
external_reference_table_ = NULL;
|
|
|
|
|
2013-09-10 11:13:55 +00:00
|
|
|
delete random_number_generator_;
|
|
|
|
random_number_generator_ = NULL;
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
delete debug_;
|
|
|
|
debug_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::InitializeThreadLocal() {
|
2011-05-05 18:55:31 +00:00
|
|
|
thread_local_top_.isolate_ = this;
|
2011-03-18 20:35:07 +00:00
|
|
|
thread_local_top_.Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-11 05:48:33 +00:00
|
|
|
bool Isolate::PropagatePendingExceptionToExternalTryCatch() {
|
2011-04-07 19:52:24 +00:00
|
|
|
ASSERT(has_pending_exception());
|
|
|
|
|
2014-06-11 05:48:33 +00:00
|
|
|
bool has_external_try_catch = HasExternalTryCatch();
|
|
|
|
if (!has_external_try_catch) {
|
|
|
|
thread_local_top_.external_caught_exception_ = false;
|
|
|
|
return true;
|
|
|
|
}
|
2011-04-07 19:52:24 +00:00
|
|
|
|
2014-06-11 05:48:33 +00:00
|
|
|
bool catchable_by_js = is_catchable_by_javascript(pending_exception());
|
|
|
|
if (catchable_by_js && IsFinallyOnTop()) {
|
|
|
|
thread_local_top_.external_caught_exception_ = false;
|
|
|
|
return false;
|
|
|
|
}
|
2011-04-07 19:52:24 +00:00
|
|
|
|
2014-06-11 05:48:33 +00:00
|
|
|
thread_local_top_.external_caught_exception_ = true;
|
2014-05-23 11:12:25 +00:00
|
|
|
if (thread_local_top_.pending_exception_ ==
|
|
|
|
heap()->termination_exception()) {
|
2011-04-07 19:52:24 +00:00
|
|
|
try_catch_handler()->can_continue_ = false;
|
2013-04-22 15:01:45 +00:00
|
|
|
try_catch_handler()->has_terminated_ = true;
|
2011-04-07 19:52:24 +00:00
|
|
|
try_catch_handler()->exception_ = heap()->null_value();
|
|
|
|
} else {
|
2013-07-01 10:54:39 +00:00
|
|
|
v8::TryCatch* handler = try_catch_handler();
|
|
|
|
ASSERT(thread_local_top_.pending_message_obj_->IsJSMessageObject() ||
|
|
|
|
thread_local_top_.pending_message_obj_->IsTheHole());
|
|
|
|
ASSERT(thread_local_top_.pending_message_script_->IsScript() ||
|
|
|
|
thread_local_top_.pending_message_script_->IsTheHole());
|
|
|
|
handler->can_continue_ = true;
|
|
|
|
handler->has_terminated_ = false;
|
|
|
|
handler->exception_ = pending_exception();
|
|
|
|
// Propagate to the external try-catch only if we got an actual message.
|
2014-06-11 05:48:33 +00:00
|
|
|
if (thread_local_top_.pending_message_obj_->IsTheHole()) return true;
|
2013-07-01 10:54:39 +00:00
|
|
|
|
|
|
|
handler->message_obj_ = thread_local_top_.pending_message_obj_;
|
|
|
|
handler->message_script_ = thread_local_top_.pending_message_script_;
|
|
|
|
handler->message_start_pos_ = thread_local_top_.pending_message_start_pos_;
|
|
|
|
handler->message_end_pos_ = thread_local_top_.pending_message_end_pos_;
|
2011-04-07 19:52:24 +00:00
|
|
|
}
|
2014-06-11 05:48:33 +00:00
|
|
|
return true;
|
2011-04-07 19:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-04 15:18:18 +00:00
|
|
|
void Isolate::InitializeLoggingAndCounters() {
|
|
|
|
if (logger_ == NULL) {
|
2013-02-15 09:27:10 +00:00
|
|
|
logger_ = new Logger(this);
|
2011-08-04 15:18:18 +00:00
|
|
|
}
|
|
|
|
if (counters_ == NULL) {
|
2013-04-24 13:52:26 +00:00
|
|
|
counters_ = new Counters(this);
|
2011-08-04 15:18:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
bool Isolate::Init(Deserializer* des) {
|
|
|
|
ASSERT(state_ != INITIALIZED);
|
|
|
|
TRACE_ISOLATE(init);
|
|
|
|
|
2013-07-18 08:12:01 +00:00
|
|
|
stress_deopt_count_ = FLAG_deopt_every_n_times;
|
|
|
|
|
2013-09-03 09:35:26 +00:00
|
|
|
has_fatal_error_ = false;
|
|
|
|
|
2013-06-28 13:40:41 +00:00
|
|
|
if (function_entry_hook() != NULL) {
|
|
|
|
// When function entry hooking is in effect, we have to create the code
|
|
|
|
// stubs from scratch to get entry hooks, rather than loading the previously
|
|
|
|
// generated stubs from disk.
|
|
|
|
// If this assert fires, the initialization path has regressed.
|
|
|
|
ASSERT(des == NULL);
|
|
|
|
}
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
// The initialization process does not handle memory exhaustion.
|
2014-03-19 11:31:43 +00:00
|
|
|
DisallowAllocationFailure disallow_allocation_failure(this);
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2011-08-04 15:18:18 +00:00
|
|
|
memory_allocator_ = new MemoryAllocator(this);
|
|
|
|
code_range_ = new CodeRange(this);
|
|
|
|
|
2013-09-05 11:27:22 +00:00
|
|
|
// Safe after setting Heap::isolate_, and initializing StackGuard
|
2011-08-04 15:18:18 +00:00
|
|
|
heap_.SetStackLimits();
|
|
|
|
|
2011-09-08 16:29:57 +00:00
|
|
|
#define ASSIGN_ELEMENT(CamelName, hacker_name) \
|
|
|
|
isolate_addresses_[Isolate::k##CamelName##Address] = \
|
|
|
|
reinterpret_cast<Address>(hacker_name##_address());
|
|
|
|
FOR_EACH_ISOLATE_ADDRESS_NAME(ASSIGN_ELEMENT)
|
2013-06-20 06:13:03 +00:00
|
|
|
#undef ASSIGN_ELEMENT
|
2011-08-04 15:18:18 +00:00
|
|
|
|
|
|
|
string_tracker_ = new StringTracker();
|
|
|
|
string_tracker_->isolate_ = this;
|
|
|
|
compilation_cache_ = new CompilationCache(this);
|
|
|
|
keyed_lookup_cache_ = new KeyedLookupCache();
|
|
|
|
context_slot_cache_ = new ContextSlotCache();
|
|
|
|
descriptor_lookup_cache_ = new DescriptorLookupCache();
|
|
|
|
unicode_cache_ = new UnicodeCache();
|
2011-09-20 10:08:39 +00:00
|
|
|
inner_pointer_to_code_cache_ = new InnerPointerToCodeCache(this);
|
2012-12-31 11:13:50 +00:00
|
|
|
write_iterator_ = new ConsStringIteratorOp();
|
2011-08-04 15:18:18 +00:00
|
|
|
global_handles_ = new GlobalHandles(this);
|
2013-08-05 09:46:23 +00:00
|
|
|
eternal_handles_ = new EternalHandles();
|
2013-02-15 09:27:10 +00:00
|
|
|
bootstrapper_ = new Bootstrapper(this);
|
2011-08-04 15:18:18 +00:00
|
|
|
handle_scope_implementer_ = new HandleScopeImplementer(this);
|
2013-06-26 13:36:16 +00:00
|
|
|
stub_cache_ = new StubCache(this);
|
The current
version is passing all the existing test + a bunch of new tests
(packaged in the change list, too).
The patch extends the SlotRef object to describe captured and duplicated
objects. Since the SlotRefs are not independent of each other anymore,
there is a new SlotRefValueBuilder class that stores the SlotRefs and
later materializes the objects from the SlotRefs.
Note that unlike the previous implementation of SlotRefs, we now build
the SlotRef entries for the entire frame, not just the particular
function. This is because duplicate objects might refer to previous
captured objects (that might live inside other inlined function's part
of the frame).
We also need to store the materialized objects between other potential
invocations of the same arguments object so that we materialize each
captured object at most once. The materialized objects of frames live
in the new MaterielizedObjectStore object (contained in Isolate),
indexed by the frame's FP address. Each argument materialization (and
deoptimization) tries to lookup its captured objects in the store before
building new ones. Deoptimization also removes the materialized objects
from the store. We also schedule a lazy deopt to be sure that we always
get rid of the materialized objects and that the optmized function
adopts the materialized objects (instead of happily computing with its
captured representations).
Concerns:
- Is the FP address the right key for a frame? (Note that deoptimizer's
representation of frame is different from the argument object
materializer's one - it is not easy to find common ground.)
- Performance is suboptimal in several places, but a quick local run of
benchmarks does not seem to show a perf hit. Examples of possible
improvements: smarter generation of SlotRefs (build other functions'
SlotRefs only for captured objects and only if necessary), smarter
lookup of stored materialized objects.
- Ideally, we would like to share the code for argument materialization
with deoptimizer's materializer. However, the supporting data structures
(mainly the frame descriptor) are quite different in each case, so it
looks more like a separate project.
Thanks for any feedback.
R=danno@chromium.org, mstarzinger@chromium.org
LOG=N
BUG=
Committed: https://code.google.com/p/v8/source/detail?r=18918
Review URL: https://codereview.chromium.org/103243005
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18936 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-30 10:33:53 +00:00
|
|
|
materialized_object_store_ = new MaterializedObjectStore(this);
|
2011-08-04 15:18:18 +00:00
|
|
|
regexp_stack_ = new RegExpStack();
|
|
|
|
regexp_stack_->isolate_ = this;
|
2012-03-09 12:07:29 +00:00
|
|
|
date_cache_ = new DateCache();
|
2012-12-18 16:25:45 +00:00
|
|
|
code_stub_interface_descriptors_ =
|
|
|
|
new CodeStubInterfaceDescriptor[CodeStub::NUMBER_OF_IDS];
|
This is a preview of a first step towards unification of the hydrogen
call machinery. The change replaces CallNamed, CallKeyed,
CallConstantFunction and CallKnownGlobal hydrogen instructions with two
new instructions with a more lower level semantics:
1. CallJSFunction for direct calls of JSFunction objects (no
argument adaptation)
2. CallWithDescriptor for calls of a given Code object according to
the supplied calling convention.
Details:
CallJSFunction should be straightforward, the main difference from the
existing InvokeFunction instruction is the absence of argument adaptor
handling. (As a next step, we will replace InvokeFunction with an
equivalent hydrogen code.)
For CallWithDescriptor, the calling conventions are represented by a
tweaked version of CallStubInterfaceDescriptor. In addition to the
parameter-register mapping, we also define parameter-representation
mapping there. The CallWithDescriptor instruction has variable number of
parameters now - this required some simple tweaks in Lithium, which
assumed fixed number of arguments in some places.
The calling conventions used in the calls are initialized in the
CallDescriptors class (code-stubs.h, <arch>/code-stubs-<arch>.cc), and
they live in a new table in the Isolate class. I should say I am not
quite sure about Representation::Integer32() representation for some of
the params of ArgumentAdaptorCall - it is not clear to me wether the
params could not end up on the stack and thus confuse the GC.
The change also includes an earlier small change to argument adaptor
(https://codereview.chromium.org/98463007) that avoids passing a naked
pointer to the code entry as a parameter. I am sorry for packaging that
with an already biggish change.
Performance implications:
Locally, I see a small regression (.2% or so). It is hard to say where
exactly it comes from, but I do see inefficient call sequences to the
adaptor trampoline. For example:
;;; <@78,#24> constant-t
bf85aa515a mov edi,0x5a51aa85 ;; debug: position 29
;;; <@72,#53> load-named-field
8b7717 mov esi,[edi+0x17] ;; debug: position 195
;;; <@80,#51> constant-s
b902000000 mov ecx,0x2 ;; debug: position 195
;;; <@81,#51> gap
894df0 mov [ebp+0xf0],ecx
;;; <@82,#103> constant-i
bb01000000 mov ebx,0x1
;;; <@84,#102> constant-i
b902000000 mov ecx,0x2
;;; <@85,#102> gap
89d8 mov eax,ebx
89cb mov ebx,ecx
8b4df0 mov ecx,[ebp+0xf0]
;;; <@86,#58> call-with-descriptor
e8ef57fcff call ArgumentsAdaptorTrampoline (0x2d80e6e0) ;; code: BUILTIN
Note the silly handling of ecx; the hydrogen for this code is:
0 4 s27 Constant 1 range:1_1 <|@
0 3 t30 Constant 0x5bc1aa85 <JS Function xyz (SharedFunctionInfo 0x5bc1a919)> type:object <|@
0 1 t36 LoadNamedField t30.[in-object]@24 <|@
0 1 t38 Constant 0x2300e6a1 <Code> <|@
0 1 i102 Constant 2 range:2_2 <|@
0 1 i103 Constant 1 range:1_1 <|@
0 2 t41 CallWithDescriptor t38 t30 t36 s27 i103 i102 #2 changes[*] <|@
BUG=
R=verwaest@chromium.org, danno@chromium.org
Review URL: https://codereview.chromium.org/104663004
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18626 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-15 17:00:35 +00:00
|
|
|
call_descriptors_ =
|
|
|
|
new CallInterfaceDescriptor[NUMBER_OF_CALL_DESCRIPTORS];
|
2013-04-16 08:54:33 +00:00
|
|
|
cpu_profiler_ = new CpuProfiler(this);
|
|
|
|
heap_profiler_ = new HeapProfiler(heap());
|
2011-03-18 20:35:07 +00:00
|
|
|
|
|
|
|
// Enable logging before setting up the heap
|
2013-04-24 14:44:08 +00:00
|
|
|
logger_->SetUp(this);
|
2011-03-18 20:35:07 +00:00
|
|
|
|
|
|
|
// Initialize other runtime facilities
|
|
|
|
#if defined(USE_SIMULATOR)
|
2014-03-21 09:28:26 +00:00
|
|
|
#if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_ARM64 || V8_TARGET_ARCH_MIPS
|
2011-05-05 18:55:31 +00:00
|
|
|
Simulator::Initialize(this);
|
2011-03-18 20:35:07 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2014-05-06 11:25:37 +00:00
|
|
|
code_aging_helper_ = new CodeAgingHelper();
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
{ // NOLINT
|
|
|
|
// Ensure that the thread has a valid stack guard. The v8::Locker object
|
|
|
|
// will ensure this too, but we don't have to use lockers if we are only
|
|
|
|
// using one thread.
|
|
|
|
ExecutionAccess lock(this);
|
|
|
|
stack_guard_.InitThread(lock);
|
|
|
|
}
|
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// SetUp the object heap.
|
|
|
|
ASSERT(!heap_.HasBeenSetUp());
|
2013-02-25 14:03:09 +00:00
|
|
|
if (!heap_.SetUp()) {
|
2013-01-10 15:53:11 +00:00
|
|
|
V8::FatalProcessOutOfMemory("heap setup");
|
2011-03-18 20:35:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-18 13:57:49 +00:00
|
|
|
deoptimizer_data_ = new DeoptimizerData(memory_allocator_);
|
2013-02-25 14:03:09 +00:00
|
|
|
|
|
|
|
const bool create_heap_objects = (des == NULL);
|
|
|
|
if (create_heap_objects && !heap_.CreateHeapObjects()) {
|
|
|
|
V8::FatalProcessOutOfMemory("heap object creation");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-19 18:38:03 +00:00
|
|
|
if (create_heap_objects) {
|
|
|
|
// Terminate the cache array with the sentinel so we can iterate.
|
|
|
|
PushToPartialSnapshotCache(heap_.undefined_value());
|
|
|
|
}
|
|
|
|
|
2011-07-05 15:49:39 +00:00
|
|
|
InitializeThreadLocal();
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
bootstrapper_->Initialize(create_heap_objects);
|
2013-09-03 06:57:16 +00:00
|
|
|
builtins_.SetUp(this, create_heap_objects);
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2014-03-10 08:56:48 +00:00
|
|
|
if (FLAG_log_internal_timer_events) {
|
|
|
|
set_event_logger(Logger::LogInternalEvents);
|
|
|
|
} else {
|
|
|
|
set_event_logger(Logger::EmptyLogInternalEvents);
|
|
|
|
}
|
|
|
|
|
2013-11-19 11:52:47 +00:00
|
|
|
// Set default value if not yet set.
|
|
|
|
// TODO(yangguo): move this to ResourceConstraints::ConfigureDefaults
|
|
|
|
// once ResourceConstraints becomes an argument to the Isolate constructor.
|
|
|
|
if (max_available_threads_ < 1) {
|
|
|
|
// Choose the default between 1 and 4.
|
2014-06-30 13:25:46 +00:00
|
|
|
max_available_threads_ =
|
|
|
|
Max(Min(base::OS::NumberOfProcessorsOnline(), 4), 1);
|
2013-11-19 11:52:47 +00:00
|
|
|
}
|
|
|
|
|
2014-02-13 15:36:17 +00:00
|
|
|
if (!FLAG_job_based_sweeping) {
|
|
|
|
num_sweeper_threads_ =
|
|
|
|
SweeperThread::NumberOfThreads(max_available_threads_);
|
|
|
|
}
|
2013-11-19 11:52:47 +00:00
|
|
|
|
|
|
|
if (FLAG_trace_hydrogen || FLAG_trace_hydrogen_stubs) {
|
|
|
|
PrintF("Concurrent recompilation has been disabled for tracing.\n");
|
|
|
|
} else if (OptimizingCompilerThread::Enabled(max_available_threads_)) {
|
|
|
|
optimizing_compiler_thread_ = new OptimizingCompilerThread(this);
|
|
|
|
optimizing_compiler_thread_->Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_sweeper_threads_ > 0) {
|
|
|
|
sweeper_thread_ = new SweeperThread*[num_sweeper_threads_];
|
|
|
|
for (int i = 0; i < num_sweeper_threads_; i++) {
|
|
|
|
sweeper_thread_[i] = new SweeperThread(this);
|
|
|
|
sweeper_thread_[i]->Start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
// If we are deserializing, read the state into the now-empty heap.
|
2012-06-19 18:38:03 +00:00
|
|
|
if (!create_heap_objects) {
|
2013-09-03 11:54:08 +00:00
|
|
|
des->Deserialize(this);
|
2011-03-18 20:35:07 +00:00
|
|
|
}
|
2012-02-28 18:26:04 +00:00
|
|
|
stub_cache_->Initialize();
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2011-10-10 09:21:48 +00:00
|
|
|
// Finish initialization of ThreadLocal after deserialization is done.
|
|
|
|
clear_pending_exception();
|
|
|
|
clear_pending_message();
|
|
|
|
clear_scheduled_exception();
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
// Deserializing may put strange things in the root array's copy of the
|
|
|
|
// stack guard.
|
|
|
|
heap_.SetStackLimits();
|
|
|
|
|
2012-04-20 14:12:49 +00:00
|
|
|
// Quiet the heap NaN if needed on target platform.
|
2012-07-13 07:22:11 +00:00
|
|
|
if (!create_heap_objects) Assembler::QuietNaN(heap_.nan_value());
|
2012-04-20 14:12:49 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
runtime_profiler_ = new RuntimeProfiler(this);
|
|
|
|
|
|
|
|
// If we are deserializing, log non-function code objects and compiled
|
|
|
|
// functions found in the snapshot.
|
2012-11-20 12:59:36 +00:00
|
|
|
if (!create_heap_objects &&
|
2013-11-25 06:44:23 +00:00
|
|
|
(FLAG_log_code ||
|
|
|
|
FLAG_ll_prof ||
|
|
|
|
FLAG_perf_jit_prof ||
|
|
|
|
FLAG_perf_basic_prof ||
|
|
|
|
logger_->is_logging_code_events())) {
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(this);
|
2011-03-18 20:35:07 +00:00
|
|
|
LOG(this, LogCodeObjects());
|
|
|
|
LOG(this, LogCompiledFunctions());
|
|
|
|
}
|
|
|
|
|
2014-07-02 10:19:35 +00:00
|
|
|
// If we are profiling with the Linux perf tool, we need to disable
|
|
|
|
// code relocation.
|
|
|
|
if (FLAG_perf_jit_prof || FLAG_perf_basic_prof) {
|
|
|
|
FLAG_compact_code_space = false;
|
|
|
|
}
|
|
|
|
|
2012-04-23 16:42:34 +00:00
|
|
|
CHECK_EQ(static_cast<int>(OFFSET_OF(Isolate, embedder_data_)),
|
|
|
|
Internals::kIsolateEmbedderDataOffset);
|
|
|
|
CHECK_EQ(static_cast<int>(OFFSET_OF(Isolate, heap_.roots_)),
|
|
|
|
Internals::kIsolateRootsOffset);
|
2014-06-05 08:44:42 +00:00
|
|
|
CHECK_EQ(static_cast<int>(
|
|
|
|
OFFSET_OF(Isolate, heap_.amount_of_external_allocated_memory_)),
|
|
|
|
Internals::kAmountOfExternalAllocatedMemoryOffset);
|
|
|
|
CHECK_EQ(static_cast<int>(OFFSET_OF(
|
|
|
|
Isolate,
|
|
|
|
heap_.amount_of_external_allocated_memory_at_last_global_gc_)),
|
|
|
|
Internals::kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset);
|
2012-04-23 15:09:59 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
state_ = INITIALIZED;
|
2014-06-30 13:25:46 +00:00
|
|
|
time_millis_at_init_ = base::OS::TimeCurrentMillis();
|
2012-12-18 16:25:45 +00:00
|
|
|
|
|
|
|
if (!create_heap_objects) {
|
|
|
|
// Now that the heap is consistent, it's OK to generate the code for the
|
|
|
|
// deopt entry table that might have been referred to by optimized code in
|
|
|
|
// the snapshot.
|
|
|
|
HandleScope scope(this);
|
|
|
|
Deoptimizer::EnsureCodeForDeoptimizationEntry(
|
2013-02-27 14:45:59 +00:00
|
|
|
this,
|
2012-12-18 16:25:45 +00:00
|
|
|
Deoptimizer::LAZY,
|
|
|
|
kDeoptTableSerializeEntryCount - 1);
|
2013-01-29 12:50:42 +00:00
|
|
|
}
|
2013-01-29 09:12:20 +00:00
|
|
|
|
2014-05-22 09:36:20 +00:00
|
|
|
if (!serializer_enabled()) {
|
2013-03-06 16:15:01 +00:00
|
|
|
// Ensure that all stubs which need to be generated ahead of time, but
|
|
|
|
// cannot be serialized into the snapshot have been generated.
|
2013-01-29 12:50:42 +00:00
|
|
|
HandleScope scope(this);
|
2013-02-27 12:33:24 +00:00
|
|
|
CodeStub::GenerateFPStubs(this);
|
2013-04-04 17:55:43 +00:00
|
|
|
StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(this);
|
2013-02-27 12:33:24 +00:00
|
|
|
StubFailureTrampolineStub::GenerateAheadOfTime(this);
|
2014-02-21 11:19:32 +00:00
|
|
|
// Ensure interface descriptors are initialized even when stubs have been
|
|
|
|
// deserialized out of the snapshot without using the graph builder.
|
|
|
|
FastCloneShallowArrayStub::InstallDescriptors(this);
|
2013-12-02 13:14:07 +00:00
|
|
|
BinaryOpICStub::InstallDescriptors(this);
|
2014-01-09 13:22:18 +00:00
|
|
|
BinaryOpWithAllocationSiteStub::InstallDescriptors(this);
|
2014-02-21 11:19:32 +00:00
|
|
|
CompareNilICStub::InstallDescriptors(this);
|
|
|
|
ToBooleanStub::InstallDescriptors(this);
|
|
|
|
ToNumberStub::InstallDescriptors(this);
|
2013-04-25 16:00:32 +00:00
|
|
|
ArrayConstructorStubBase::InstallDescriptors(this);
|
2013-06-05 10:43:18 +00:00
|
|
|
InternalArrayConstructorStubBase::InstallDescriptors(this);
|
2013-08-27 11:55:08 +00:00
|
|
|
FastNewClosureStub::InstallDescriptors(this);
|
2014-01-23 08:36:22 +00:00
|
|
|
FastNewContextStub::InstallDescriptors(this);
|
2013-10-21 12:42:08 +00:00
|
|
|
NumberToStringStub::InstallDescriptors(this);
|
2014-01-22 13:48:05 +00:00
|
|
|
StringAddStub::InstallDescriptors(this);
|
2014-01-29 13:10:35 +00:00
|
|
|
RegExpConstructResultStub::InstallDescriptors(this);
|
2014-06-12 09:58:10 +00:00
|
|
|
KeyedLoadGenericElementStub::InstallDescriptors(this);
|
2012-12-18 16:25:45 +00:00
|
|
|
}
|
|
|
|
|
This is a preview of a first step towards unification of the hydrogen
call machinery. The change replaces CallNamed, CallKeyed,
CallConstantFunction and CallKnownGlobal hydrogen instructions with two
new instructions with a more lower level semantics:
1. CallJSFunction for direct calls of JSFunction objects (no
argument adaptation)
2. CallWithDescriptor for calls of a given Code object according to
the supplied calling convention.
Details:
CallJSFunction should be straightforward, the main difference from the
existing InvokeFunction instruction is the absence of argument adaptor
handling. (As a next step, we will replace InvokeFunction with an
equivalent hydrogen code.)
For CallWithDescriptor, the calling conventions are represented by a
tweaked version of CallStubInterfaceDescriptor. In addition to the
parameter-register mapping, we also define parameter-representation
mapping there. The CallWithDescriptor instruction has variable number of
parameters now - this required some simple tweaks in Lithium, which
assumed fixed number of arguments in some places.
The calling conventions used in the calls are initialized in the
CallDescriptors class (code-stubs.h, <arch>/code-stubs-<arch>.cc), and
they live in a new table in the Isolate class. I should say I am not
quite sure about Representation::Integer32() representation for some of
the params of ArgumentAdaptorCall - it is not clear to me wether the
params could not end up on the stack and thus confuse the GC.
The change also includes an earlier small change to argument adaptor
(https://codereview.chromium.org/98463007) that avoids passing a naked
pointer to the code entry as a parameter. I am sorry for packaging that
with an already biggish change.
Performance implications:
Locally, I see a small regression (.2% or so). It is hard to say where
exactly it comes from, but I do see inefficient call sequences to the
adaptor trampoline. For example:
;;; <@78,#24> constant-t
bf85aa515a mov edi,0x5a51aa85 ;; debug: position 29
;;; <@72,#53> load-named-field
8b7717 mov esi,[edi+0x17] ;; debug: position 195
;;; <@80,#51> constant-s
b902000000 mov ecx,0x2 ;; debug: position 195
;;; <@81,#51> gap
894df0 mov [ebp+0xf0],ecx
;;; <@82,#103> constant-i
bb01000000 mov ebx,0x1
;;; <@84,#102> constant-i
b902000000 mov ecx,0x2
;;; <@85,#102> gap
89d8 mov eax,ebx
89cb mov ebx,ecx
8b4df0 mov ecx,[ebp+0xf0]
;;; <@86,#58> call-with-descriptor
e8ef57fcff call ArgumentsAdaptorTrampoline (0x2d80e6e0) ;; code: BUILTIN
Note the silly handling of ecx; the hydrogen for this code is:
0 4 s27 Constant 1 range:1_1 <|@
0 3 t30 Constant 0x5bc1aa85 <JS Function xyz (SharedFunctionInfo 0x5bc1a919)> type:object <|@
0 1 t36 LoadNamedField t30.[in-object]@24 <|@
0 1 t38 Constant 0x2300e6a1 <Code> <|@
0 1 i102 Constant 2 range:2_2 <|@
0 1 i103 Constant 1 range:1_1 <|@
0 2 t41 CallWithDescriptor t38 t30 t36 s27 i103 i102 #2 changes[*] <|@
BUG=
R=verwaest@chromium.org, danno@chromium.org
Review URL: https://codereview.chromium.org/104663004
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18626 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-15 17:00:35 +00:00
|
|
|
CallDescriptors::InitializeForIsolate(this);
|
|
|
|
|
2013-06-28 13:40:41 +00:00
|
|
|
initialized_from_snapshot_ = (des != NULL);
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-04 15:18:18 +00:00
|
|
|
// Initialized lazily to allow early
|
|
|
|
// v8::V8::SetAddHistogramSampleFunction calls.
|
|
|
|
StatsTable* Isolate::stats_table() {
|
|
|
|
if (stats_table_ == NULL) {
|
|
|
|
stats_table_ = new StatsTable;
|
|
|
|
}
|
|
|
|
return stats_table_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void Isolate::Enter() {
|
|
|
|
Isolate* current_isolate = NULL;
|
|
|
|
PerIsolateThreadData* current_data = CurrentPerIsolateThreadData();
|
|
|
|
if (current_data != NULL) {
|
|
|
|
current_isolate = current_data->isolate_;
|
|
|
|
ASSERT(current_isolate != NULL);
|
|
|
|
if (current_isolate == this) {
|
|
|
|
ASSERT(Current() == this);
|
|
|
|
ASSERT(entry_stack_ != NULL);
|
|
|
|
ASSERT(entry_stack_->previous_thread_data == NULL ||
|
2011-04-11 23:46:22 +00:00
|
|
|
entry_stack_->previous_thread_data->thread_id().Equals(
|
|
|
|
ThreadId::Current()));
|
2011-03-18 20:35:07 +00:00
|
|
|
// Same thread re-enters the isolate, no need to re-init anything.
|
|
|
|
entry_stack_->entry_count++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Threads can have default isolate set into TLS as Current but not yet have
|
|
|
|
// PerIsolateThreadData for it, as it requires more advanced phase of the
|
|
|
|
// initialization. For example, a thread might be the one that system used for
|
|
|
|
// static initializers - in this case the default isolate is set in TLS but
|
|
|
|
// the thread did not yet Enter the isolate. If PerisolateThreadData is not
|
|
|
|
// there, use the isolate set in TLS.
|
|
|
|
if (current_isolate == NULL) {
|
|
|
|
current_isolate = Isolate::UncheckedCurrent();
|
|
|
|
}
|
|
|
|
|
|
|
|
PerIsolateThreadData* data = FindOrAllocatePerThreadDataForThisThread();
|
|
|
|
ASSERT(data != NULL);
|
|
|
|
ASSERT(data->isolate_ == this);
|
|
|
|
|
|
|
|
EntryStackItem* item = new EntryStackItem(current_data,
|
|
|
|
current_isolate,
|
|
|
|
entry_stack_);
|
|
|
|
entry_stack_ = item;
|
|
|
|
|
|
|
|
SetIsolateThreadLocals(this, data);
|
|
|
|
|
|
|
|
// In case it's the first time some thread enters the isolate.
|
|
|
|
set_thread_id(data->thread_id());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::Exit() {
|
|
|
|
ASSERT(entry_stack_ != NULL);
|
|
|
|
ASSERT(entry_stack_->previous_thread_data == NULL ||
|
2011-04-11 23:46:22 +00:00
|
|
|
entry_stack_->previous_thread_data->thread_id().Equals(
|
|
|
|
ThreadId::Current()));
|
2011-03-18 20:35:07 +00:00
|
|
|
|
|
|
|
if (--entry_stack_->entry_count > 0) return;
|
|
|
|
|
|
|
|
ASSERT(CurrentPerIsolateThreadData() != NULL);
|
|
|
|
ASSERT(CurrentPerIsolateThreadData()->isolate_ == this);
|
|
|
|
|
|
|
|
// Pop the stack.
|
|
|
|
EntryStackItem* item = entry_stack_;
|
|
|
|
entry_stack_ = item->previous_item;
|
|
|
|
|
|
|
|
PerIsolateThreadData* previous_thread_data = item->previous_thread_data;
|
|
|
|
Isolate* previous_isolate = item->previous_isolate;
|
|
|
|
|
|
|
|
delete item;
|
|
|
|
|
|
|
|
// Reinit the current thread for the isolate it was running before this one.
|
|
|
|
SetIsolateThreadLocals(previous_isolate, previous_thread_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-18 14:15:02 +00:00
|
|
|
void Isolate::LinkDeferredHandles(DeferredHandles* deferred) {
|
|
|
|
deferred->next_ = deferred_handles_head_;
|
|
|
|
if (deferred_handles_head_ != NULL) {
|
|
|
|
deferred_handles_head_->previous_ = deferred;
|
|
|
|
}
|
|
|
|
deferred_handles_head_ = deferred;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::UnlinkDeferredHandles(DeferredHandles* deferred) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
// In debug mode assert that the linked list is well-formed.
|
|
|
|
DeferredHandles* deferred_iterator = deferred;
|
|
|
|
while (deferred_iterator->previous_ != NULL) {
|
|
|
|
deferred_iterator = deferred_iterator->previous_;
|
|
|
|
}
|
|
|
|
ASSERT(deferred_handles_head_ == deferred_iterator);
|
|
|
|
#endif
|
|
|
|
if (deferred_handles_head_ == deferred) {
|
|
|
|
deferred_handles_head_ = deferred_handles_head_->next_;
|
|
|
|
}
|
|
|
|
if (deferred->next_ != NULL) {
|
|
|
|
deferred->next_->previous_ = deferred->previous_;
|
|
|
|
}
|
|
|
|
if (deferred->previous_ != NULL) {
|
|
|
|
deferred->previous_->next_ = deferred->next_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-06 10:49:34 +00:00
|
|
|
HStatistics* Isolate::GetHStatistics() {
|
|
|
|
if (hstatistics() == NULL) set_hstatistics(new HStatistics());
|
|
|
|
return hstatistics();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-06 07:25:46 +00:00
|
|
|
HTracer* Isolate::GetHTracer() {
|
|
|
|
if (htracer() == NULL) set_htracer(new HTracer(id()));
|
|
|
|
return htracer();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-07 16:35:27 +00:00
|
|
|
CodeTracer* Isolate::GetCodeTracer() {
|
|
|
|
if (code_tracer() == NULL) set_code_tracer(new CodeTracer(id()));
|
|
|
|
return code_tracer();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-13 07:35:26 +00:00
|
|
|
Map* Isolate::get_initial_js_array_map(ElementsKind kind) {
|
|
|
|
Context* native_context = context()->native_context();
|
|
|
|
Object* maybe_map_array = native_context->js_array_maps();
|
|
|
|
if (!maybe_map_array->IsUndefined()) {
|
|
|
|
Object* maybe_transitioned_map =
|
|
|
|
FixedArray::cast(maybe_map_array)->get(kind);
|
|
|
|
if (!maybe_transitioned_map->IsUndefined()) {
|
|
|
|
return Map::cast(maybe_transitioned_map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-22 09:36:20 +00:00
|
|
|
bool Isolate::use_crankshaft() const {
|
|
|
|
return FLAG_crankshaft &&
|
|
|
|
!serializer_enabled_ &&
|
|
|
|
CpuFeatures::SupportsCrankshaft();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-13 07:35:26 +00:00
|
|
|
bool Isolate::IsFastArrayConstructorPrototypeChainIntact() {
|
|
|
|
Map* root_array_map =
|
|
|
|
get_initial_js_array_map(GetInitialFastElementsKind());
|
|
|
|
ASSERT(root_array_map != NULL);
|
|
|
|
JSObject* initial_array_proto = JSObject::cast(*initial_array_prototype());
|
|
|
|
|
|
|
|
// Check that the array prototype hasn't been altered WRT empty elements.
|
|
|
|
if (root_array_map->prototype() != initial_array_proto) return false;
|
|
|
|
if (initial_array_proto->elements() != heap()->empty_fixed_array()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the object prototype hasn't been altered WRT empty elements.
|
|
|
|
JSObject* initial_object_proto = JSObject::cast(*initial_object_prototype());
|
|
|
|
Object* root_array_map_proto = initial_array_proto->GetPrototype();
|
|
|
|
if (root_array_map_proto != initial_object_proto) return false;
|
|
|
|
if (initial_object_proto->elements() != heap()->empty_fixed_array()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return initial_object_proto->GetPrototype()->IsNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
CodeStubInterfaceDescriptor*
|
|
|
|
Isolate::code_stub_interface_descriptor(int index) {
|
|
|
|
return code_stub_interface_descriptors_ + index;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
This is a preview of a first step towards unification of the hydrogen
call machinery. The change replaces CallNamed, CallKeyed,
CallConstantFunction and CallKnownGlobal hydrogen instructions with two
new instructions with a more lower level semantics:
1. CallJSFunction for direct calls of JSFunction objects (no
argument adaptation)
2. CallWithDescriptor for calls of a given Code object according to
the supplied calling convention.
Details:
CallJSFunction should be straightforward, the main difference from the
existing InvokeFunction instruction is the absence of argument adaptor
handling. (As a next step, we will replace InvokeFunction with an
equivalent hydrogen code.)
For CallWithDescriptor, the calling conventions are represented by a
tweaked version of CallStubInterfaceDescriptor. In addition to the
parameter-register mapping, we also define parameter-representation
mapping there. The CallWithDescriptor instruction has variable number of
parameters now - this required some simple tweaks in Lithium, which
assumed fixed number of arguments in some places.
The calling conventions used in the calls are initialized in the
CallDescriptors class (code-stubs.h, <arch>/code-stubs-<arch>.cc), and
they live in a new table in the Isolate class. I should say I am not
quite sure about Representation::Integer32() representation for some of
the params of ArgumentAdaptorCall - it is not clear to me wether the
params could not end up on the stack and thus confuse the GC.
The change also includes an earlier small change to argument adaptor
(https://codereview.chromium.org/98463007) that avoids passing a naked
pointer to the code entry as a parameter. I am sorry for packaging that
with an already biggish change.
Performance implications:
Locally, I see a small regression (.2% or so). It is hard to say where
exactly it comes from, but I do see inefficient call sequences to the
adaptor trampoline. For example:
;;; <@78,#24> constant-t
bf85aa515a mov edi,0x5a51aa85 ;; debug: position 29
;;; <@72,#53> load-named-field
8b7717 mov esi,[edi+0x17] ;; debug: position 195
;;; <@80,#51> constant-s
b902000000 mov ecx,0x2 ;; debug: position 195
;;; <@81,#51> gap
894df0 mov [ebp+0xf0],ecx
;;; <@82,#103> constant-i
bb01000000 mov ebx,0x1
;;; <@84,#102> constant-i
b902000000 mov ecx,0x2
;;; <@85,#102> gap
89d8 mov eax,ebx
89cb mov ebx,ecx
8b4df0 mov ecx,[ebp+0xf0]
;;; <@86,#58> call-with-descriptor
e8ef57fcff call ArgumentsAdaptorTrampoline (0x2d80e6e0) ;; code: BUILTIN
Note the silly handling of ecx; the hydrogen for this code is:
0 4 s27 Constant 1 range:1_1 <|@
0 3 t30 Constant 0x5bc1aa85 <JS Function xyz (SharedFunctionInfo 0x5bc1a919)> type:object <|@
0 1 t36 LoadNamedField t30.[in-object]@24 <|@
0 1 t38 Constant 0x2300e6a1 <Code> <|@
0 1 i102 Constant 2 range:2_2 <|@
0 1 i103 Constant 1 range:1_1 <|@
0 2 t41 CallWithDescriptor t38 t30 t36 s27 i103 i102 #2 changes[*] <|@
BUG=
R=verwaest@chromium.org, danno@chromium.org
Review URL: https://codereview.chromium.org/104663004
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18626 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-15 17:00:35 +00:00
|
|
|
CallInterfaceDescriptor*
|
|
|
|
Isolate::call_descriptor(CallDescriptorKey index) {
|
|
|
|
ASSERT(0 <= index && index < NUMBER_OF_CALL_DESCRIPTORS);
|
|
|
|
return &call_descriptors_[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-19 09:39:01 +00:00
|
|
|
Object* Isolate::FindCodeObject(Address a) {
|
|
|
|
return inner_pointer_to_code_cache()->GcSafeFindCodeForInnerPointer(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
#define ISOLATE_FIELD_OFFSET(type, name, ignored) \
|
|
|
|
const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_);
|
|
|
|
ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET)
|
|
|
|
ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET)
|
|
|
|
#undef ISOLATE_FIELD_OFFSET
|
|
|
|
#endif
|
|
|
|
|
2014-03-24 16:34:06 +00:00
|
|
|
|
|
|
|
Handle<JSObject> Isolate::GetSymbolRegistry() {
|
|
|
|
if (heap()->symbol_registry()->IsUndefined()) {
|
|
|
|
Handle<Map> map = factory()->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
|
|
|
|
Handle<JSObject> registry = factory()->NewJSObjectFromMap(map);
|
|
|
|
heap()->set_symbol_registry(*registry);
|
|
|
|
|
|
|
|
static const char* nested[] = {
|
|
|
|
"for", "for_api", "for_intern", "keyFor", "private_api", "private_intern"
|
|
|
|
};
|
|
|
|
for (unsigned i = 0; i < ARRAY_SIZE(nested); ++i) {
|
|
|
|
Handle<String> name = factory()->InternalizeUtf8String(nested[i]);
|
|
|
|
Handle<JSObject> obj = factory()->NewJSObjectFromMap(map);
|
|
|
|
JSObject::NormalizeProperties(obj, KEEP_INOBJECT_PROPERTIES, 8);
|
2014-04-04 12:06:11 +00:00
|
|
|
JSObject::SetProperty(registry, name, obj, NONE, STRICT).Assert();
|
2014-03-24 16:34:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return Handle<JSObject>::cast(factory()->symbol_registry());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-25 13:49:22 +00:00
|
|
|
void Isolate::AddCallCompletedCallback(CallCompletedCallback callback) {
|
|
|
|
for (int i = 0; i < call_completed_callbacks_.length(); i++) {
|
|
|
|
if (callback == call_completed_callbacks_.at(i)) return;
|
|
|
|
}
|
|
|
|
call_completed_callbacks_.Add(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::RemoveCallCompletedCallback(CallCompletedCallback callback) {
|
|
|
|
for (int i = 0; i < call_completed_callbacks_.length(); i++) {
|
|
|
|
if (callback == call_completed_callbacks_.at(i)) {
|
|
|
|
call_completed_callbacks_.Remove(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::FireCallCompletedCallback() {
|
|
|
|
bool has_call_completed_callbacks = !call_completed_callbacks_.is_empty();
|
2014-05-19 07:57:04 +00:00
|
|
|
bool run_microtasks = autorun_microtasks() && pending_microtask_count();
|
2014-04-25 13:49:22 +00:00
|
|
|
if (!has_call_completed_callbacks && !run_microtasks) return;
|
|
|
|
|
|
|
|
if (!handle_scope_implementer()->CallDepthIsZero()) return;
|
2014-05-19 07:57:04 +00:00
|
|
|
if (run_microtasks) RunMicrotasks();
|
2014-04-25 13:49:22 +00:00
|
|
|
// Fire callbacks. Increase call depth to prevent recursive callbacks.
|
2014-05-28 18:40:04 +00:00
|
|
|
v8::Isolate::SuppressMicrotaskExecutionScope suppress(
|
|
|
|
reinterpret_cast<v8::Isolate*>(this));
|
2014-04-25 13:49:22 +00:00
|
|
|
for (int i = 0; i < call_completed_callbacks_.length(); i++) {
|
|
|
|
call_completed_callbacks_.at(i)();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-03 20:12:19 +00:00
|
|
|
void Isolate::EnqueueMicrotask(Handle<Object> microtask) {
|
|
|
|
ASSERT(microtask->IsJSFunction() || microtask->IsCallHandlerInfo());
|
2014-05-19 07:57:04 +00:00
|
|
|
Handle<FixedArray> queue(heap()->microtask_queue(), this);
|
|
|
|
int num_tasks = pending_microtask_count();
|
|
|
|
ASSERT(num_tasks <= queue->length());
|
|
|
|
if (num_tasks == 0) {
|
|
|
|
queue = factory()->NewFixedArray(8);
|
|
|
|
heap()->set_microtask_queue(*queue);
|
|
|
|
} else if (num_tasks == queue->length()) {
|
|
|
|
queue = FixedArray::CopySize(queue, num_tasks * 2);
|
|
|
|
heap()->set_microtask_queue(*queue);
|
|
|
|
}
|
|
|
|
ASSERT(queue->get(num_tasks)->IsUndefined());
|
|
|
|
queue->set(num_tasks, *microtask);
|
|
|
|
set_pending_microtask_count(num_tasks + 1);
|
|
|
|
}
|
|
|
|
|
2014-05-02 19:30:54 +00:00
|
|
|
|
2014-05-19 07:57:04 +00:00
|
|
|
void Isolate::RunMicrotasks() {
|
2014-06-24 13:58:56 +00:00
|
|
|
// %RunMicrotasks may be called in mjsunit tests, which violates
|
|
|
|
// this assertion, hence the check for --allow-natives-syntax.
|
|
|
|
// TODO(adamk): However, this also fails some layout tests.
|
|
|
|
//
|
|
|
|
// ASSERT(FLAG_allow_natives_syntax ||
|
|
|
|
// handle_scope_implementer()->CallDepthIsZero());
|
2014-05-02 19:30:54 +00:00
|
|
|
|
|
|
|
// Increase call depth to prevent recursive callbacks.
|
2014-05-28 18:40:04 +00:00
|
|
|
v8::Isolate::SuppressMicrotaskExecutionScope suppress(
|
|
|
|
reinterpret_cast<v8::Isolate*>(this));
|
2014-05-19 07:57:04 +00:00
|
|
|
|
|
|
|
while (pending_microtask_count() > 0) {
|
|
|
|
HandleScope scope(this);
|
|
|
|
int num_tasks = pending_microtask_count();
|
|
|
|
Handle<FixedArray> queue(heap()->microtask_queue(), this);
|
|
|
|
ASSERT(num_tasks <= queue->length());
|
|
|
|
set_pending_microtask_count(0);
|
|
|
|
heap()->set_microtask_queue(heap()->empty_fixed_array());
|
|
|
|
|
|
|
|
for (int i = 0; i < num_tasks; i++) {
|
|
|
|
HandleScope scope(this);
|
2014-06-03 20:12:19 +00:00
|
|
|
Handle<Object> microtask(queue->get(i), this);
|
|
|
|
if (microtask->IsJSFunction()) {
|
|
|
|
Handle<JSFunction> microtask_function =
|
|
|
|
Handle<JSFunction>::cast(microtask);
|
2014-06-23 11:47:20 +00:00
|
|
|
SaveContext save(this);
|
|
|
|
set_context(microtask_function->context()->native_context());
|
2014-06-03 20:12:19 +00:00
|
|
|
Handle<Object> exception;
|
|
|
|
MaybeHandle<Object> result = Execution::TryCall(
|
|
|
|
microtask_function, factory()->undefined_value(),
|
|
|
|
0, NULL, &exception);
|
|
|
|
// If execution is terminating, just bail out.
|
|
|
|
if (result.is_null() &&
|
|
|
|
!exception.is_null() &&
|
|
|
|
*exception == heap()->termination_exception()) {
|
|
|
|
// Clear out any remaining callbacks in the queue.
|
|
|
|
heap()->set_microtask_queue(heap()->empty_fixed_array());
|
|
|
|
set_pending_microtask_count(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Handle<CallHandlerInfo> callback_info =
|
|
|
|
Handle<CallHandlerInfo>::cast(microtask);
|
|
|
|
v8::MicrotaskCallback callback =
|
|
|
|
v8::ToCData<v8::MicrotaskCallback>(callback_info->callback());
|
|
|
|
void* data = v8::ToCData<void*>(callback_info->data());
|
|
|
|
callback(data);
|
2014-05-28 18:40:04 +00:00
|
|
|
}
|
2014-05-19 07:57:04 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-02 19:30:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-23 09:46:58 +00:00
|
|
|
void Isolate::SetUseCounterCallback(v8::Isolate::UseCounterCallback callback) {
|
|
|
|
ASSERT(!use_counter_callback_);
|
|
|
|
use_counter_callback_ = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Isolate::CountUsage(v8::Isolate::UseCounterFeature feature) {
|
|
|
|
if (use_counter_callback_) {
|
|
|
|
use_counter_callback_(reinterpret_cast<v8::Isolate*>(this), feature);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-17 13:54:49 +00:00
|
|
|
bool StackLimitCheck::JsHasOverflowed() const {
|
|
|
|
StackGuard* stack_guard = isolate_->stack_guard();
|
|
|
|
#ifdef USE_SIMULATOR
|
|
|
|
// The simulator uses a separate JS stack.
|
|
|
|
Address jssp_address = Simulator::current(isolate_)->get_sp();
|
|
|
|
uintptr_t jssp = reinterpret_cast<uintptr_t>(jssp_address);
|
|
|
|
if (jssp < stack_guard->real_jslimit()) return true;
|
|
|
|
#endif // USE_SIMULATOR
|
|
|
|
return reinterpret_cast<uintptr_t>(this) < stack_guard->real_climit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-02 08:05:40 +00:00
|
|
|
bool PostponeInterruptsScope::Intercept(StackGuard::InterruptFlag flag) {
|
|
|
|
// First check whether the previous scope intercepts.
|
|
|
|
if (prev_ && prev_->Intercept(flag)) return true;
|
|
|
|
// Then check whether this scope intercepts.
|
|
|
|
if ((flag & intercept_mask_)) {
|
|
|
|
intercepted_flags_ |= flag;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
} } // namespace v8::internal
|