1402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// Copyright 2010 the V8 project authors. All rights reserved. 2b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Use of this source code is governed by a BSD-style license that can be 3b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// found in the LICENSE file. 4402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 56ded16be15dd865a9b21ea304d5273c8be299c87Steve Block#ifndef V8_VM_STATE_H_ 66ded16be15dd865a9b21ea304d5273c8be299c87Steve Block#define V8_VM_STATE_H_ 7402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 8b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/allocation.h" 9109988c7ccb6f3fd1a58574fa3dfb88beaef6632Ben Murdoch#include "src/counters.h" 10b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/isolate.h" 11f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch 12402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescunamespace v8 { 13402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescunamespace internal { 14402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 15958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Logging and profiling. A StateTag represents a possible state of 16958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// the VM. The logger maintains a stack of these. Creating a VMState 17958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// object enters a state by pushing on the stack, and destroying a 18958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// VMState object leaves a state by popping the current state from the 19958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// stack. 20b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtemplate <StateTag Tag> 216ded16be15dd865a9b21ea304d5273c8be299c87Steve Blockclass VMState BASE_EMBEDDED { 22402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu public: 23b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch explicit inline VMState(Isolate* isolate); 246ded16be15dd865a9b21ea304d5273c8be299c87Steve Block inline ~VMState(); 25402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 26b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch private: 2744f0eee88ff00398ff7f715fab053374d808c90dSteve Block Isolate* isolate_; 28b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch StateTag previous_tag_; 29b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch}; 306ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 316ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 32b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdochclass ExternalCallbackScope BASE_EMBEDDED { 33b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch public: 3444f0eee88ff00398ff7f715fab053374d808c90dSteve Block inline ExternalCallbackScope(Isolate* isolate, Address callback); 35b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch inline ~ExternalCallbackScope(); 36b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Address callback() { return callback_; } 37014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch Address* callback_entrypoint_address() { 38014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch if (callback_ == nullptr) return nullptr; 39014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch#if USES_FUNCTION_DESCRIPTORS 40014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch return FUNCTION_ENTRYPOINT_ADDRESS(callback_); 41014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch#else 42014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch return &callback_; 43014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch#endif 44014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch } 45b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch ExternalCallbackScope* previous() { return previous_scope_; } 46b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch inline Address scope_address(); 47b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 486ded16be15dd865a9b21ea304d5273c8be299c87Steve Block private: 4944f0eee88ff00398ff7f715fab053374d808c90dSteve Block Isolate* isolate_; 50b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Address callback_; 51b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch ExternalCallbackScope* previous_scope_; 52b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#ifdef USE_SIMULATOR 53b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Address scope_address_; 54b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#endif 55402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu}; 56402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 57014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch} // namespace internal 58014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch} // namespace v8 59402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 606ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 616ded16be15dd865a9b21ea304d5273c8be299c87Steve Block#endif // V8_VM_STATE_H_ 62