blob: 29cbf395935e22b01f94fda2da73ba5e01fa88f6 [file] [log] [blame]
Andrei Popescu402d9372010-02-26 13:31:12 +00001// Copyright 2010 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Andrei Popescu402d9372010-02-26 13:31:12 +00004
Steve Block6ded16b2010-05-10 14:33:55 +01005#ifndef V8_VM_STATE_H_
6#define V8_VM_STATE_H_
Andrei Popescu402d9372010-02-26 13:31:12 +00007
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/allocation.h"
Ben Murdoch097c5b22016-05-18 11:27:45 +01009#include "src/counters.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010#include "src/isolate.h"
Ben Murdochf87a2032010-10-22 12:50:53 +010011
Andrei Popescu402d9372010-02-26 13:31:12 +000012namespace v8 {
13namespace internal {
14
Emily Bernierd0a1eb72015-03-24 16:35:39 -040015// Logging and profiling. A StateTag represents a possible state of
16// the VM. The logger maintains a stack of these. Creating a VMState
17// object enters a state by pushing on the stack, and destroying a
18// VMState object leaves a state by popping the current state from the
19// stack.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000020template <StateTag Tag>
Steve Block6ded16b2010-05-10 14:33:55 +010021class VMState BASE_EMBEDDED {
Andrei Popescu402d9372010-02-26 13:31:12 +000022 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +000023 explicit inline VMState(Isolate* isolate);
Steve Block6ded16b2010-05-10 14:33:55 +010024 inline ~VMState();
Andrei Popescu402d9372010-02-26 13:31:12 +000025
Steve Block6ded16b2010-05-10 14:33:55 +010026 private:
Steve Block44f0eee2011-05-26 01:26:41 +010027 Isolate* isolate_;
Ben Murdochb0fe1622011-05-05 13:52:32 +010028 StateTag previous_tag_;
Andrei Popescu402d9372010-02-26 13:31:12 +000029};
30
Ben Murdochb0fe1622011-05-05 13:52:32 +010031
32class ExternalCallbackScope BASE_EMBEDDED {
Ben Murdochb0fe1622011-05-05 13:52:32 +010033 public:
Steve Block44f0eee2011-05-26 01:26:41 +010034 inline ExternalCallbackScope(Isolate* isolate, Address callback);
Ben Murdochb0fe1622011-05-05 13:52:32 +010035 inline ~ExternalCallbackScope();
Ben Murdochb8a8cc12014-11-26 15:28:44 +000036 Address callback() { return callback_; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000037 Address* callback_entrypoint_address() {
38 if (callback_ == nullptr) return nullptr;
39#if USES_FUNCTION_DESCRIPTORS
40 return FUNCTION_ENTRYPOINT_ADDRESS(callback_);
41#else
42 return &callback_;
43#endif
44 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000045 ExternalCallbackScope* previous() { return previous_scope_; }
46 inline Address scope_address();
47
Ben Murdochb0fe1622011-05-05 13:52:32 +010048 private:
Steve Block44f0eee2011-05-26 01:26:41 +010049 Isolate* isolate_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000050 Address callback_;
51 ExternalCallbackScope* previous_scope_;
52#ifdef USE_SIMULATOR
53 Address scope_address_;
54#endif
Ben Murdochb0fe1622011-05-05 13:52:32 +010055};
56
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000057} // namespace internal
58} // namespace v8
Andrei Popescu402d9372010-02-26 13:31:12 +000059
Steve Block6ded16b2010-05-10 14:33:55 +010060
61#endif // V8_VM_STATE_H_