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_
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/vm-state.h"
|
|
|
|
#include "src/log.h"
|
|
|
|
#include "src/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) {
|
2014-07-16 08:14:50 +00:00
|
|
|
LOG(isolate_, TimerEvent(Logger::START, TimerEventExternal::name()));
|
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) {
|
2014-07-16 08:14:50 +00:00
|
|
|
LOG(isolate_, TimerEvent(Logger::END, TimerEventExternal::name()));
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-30 13:46:56 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
2010-04-08 13:37:39 +00:00
|
|
|
|
|
|
|
#endif // V8_VM_STATE_INL_H_
|