2010-04-08 13:37:39 +00:00
|
|
|
// Copyright 2010 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.
|
2010-04-08 13:37:39 +00:00
|
|
|
|
|
|
|
#ifndef V8_VM_STATE_INL_H_
|
|
|
|
#define V8_VM_STATE_INL_H_
|
|
|
|
|
|
|
|
#include "vm-state.h"
|
2013-07-23 15:01:38 +00:00
|
|
|
#include "log.h"
|
|
|
|
#include "simulator.h"
|
2010-04-08 13:37:39 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
//
|
|
|
|
// VMState class implementation. A simple stack of VM states held by the
|
|
|
|
// logger and partially threaded through the call stack. States are pushed by
|
|
|
|
// VMState construction and popped by destruction.
|
|
|
|
//
|
|
|
|
inline const char* StateToString(StateTag state) {
|
|
|
|
switch (state) {
|
|
|
|
case JS:
|
|
|
|
return "JS";
|
|
|
|
case GC:
|
|
|
|
return "GC";
|
|
|
|
case COMPILER:
|
|
|
|
return "COMPILER";
|
|
|
|
case OTHER:
|
|
|
|
return "OTHER";
|
2010-12-07 11:31:57 +00:00
|
|
|
case EXTERNAL:
|
|
|
|
return "EXTERNAL";
|
2010-04-08 13:37:39 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2013-04-24 14:44:08 +00:00
|
|
|
template <StateTag Tag>
|
|
|
|
VMState<Tag>::VMState(Isolate* isolate)
|
2011-03-18 20:35:07 +00:00
|
|
|
: isolate_(isolate), previous_tag_(isolate->current_vm_state()) {
|
2013-04-24 14:44:08 +00:00
|
|
|
if (FLAG_log_timer_events && previous_tag_ != EXTERNAL && Tag == EXTERNAL) {
|
|
|
|
LOG(isolate_,
|
|
|
|
TimerEvent(Logger::START, Logger::TimerEventScope::v8_external));
|
2012-11-28 11:01:10 +00:00
|
|
|
}
|
2013-04-24 14:44:08 +00:00
|
|
|
isolate_->set_current_vm_state(Tag);
|
2010-04-08 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-24 14:44:08 +00:00
|
|
|
template <StateTag Tag>
|
|
|
|
VMState<Tag>::~VMState() {
|
|
|
|
if (FLAG_log_timer_events && previous_tag_ != EXTERNAL && Tag == EXTERNAL) {
|
2011-03-18 20:35:07 +00:00
|
|
|
LOG(isolate_,
|
2013-04-24 14:44:08 +00:00
|
|
|
TimerEvent(Logger::END, Logger::TimerEventScope::v8_external));
|
2012-11-28 11:01:10 +00:00
|
|
|
}
|
2013-04-24 14:44:08 +00:00
|
|
|
isolate_->set_current_vm_state(previous_tag_);
|
2010-04-08 13:37:39 +00:00
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
ExternalCallbackScope::ExternalCallbackScope(Isolate* isolate, Address callback)
|
2013-07-23 15:01:38 +00:00
|
|
|
: isolate_(isolate),
|
|
|
|
callback_(callback),
|
|
|
|
previous_scope_(isolate->external_callback_scope()) {
|
|
|
|
#ifdef USE_SIMULATOR
|
2014-02-12 09:19:30 +00:00
|
|
|
scope_address_ = Simulator::current(isolate)->get_sp();
|
2013-07-23 15:01:38 +00:00
|
|
|
#endif
|
|
|
|
isolate_->set_external_callback_scope(this);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ExternalCallbackScope::~ExternalCallbackScope() {
|
2013-07-23 15:01:38 +00:00
|
|
|
isolate_->set_external_callback_scope(previous_scope_);
|
|
|
|
}
|
|
|
|
|
|
|
|
Address ExternalCallbackScope::scope_address() {
|
|
|
|
#ifdef USE_SIMULATOR
|
|
|
|
return scope_address_;
|
|
|
|
#else
|
|
|
|
return reinterpret_cast<Address>(this);
|
|
|
|
#endif
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-08 13:37:39 +00:00
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_VM_STATE_INL_H_
|