blob: 7e723a5282b426c16360984900b8feecee7ddc51 [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"
9#include "src/isolate.h"
Ben Murdochf87a2032010-10-22 12:50:53 +010010
Andrei Popescu402d9372010-02-26 13:31:12 +000011namespace v8 {
12namespace internal {
13
Emily Bernierd0a1eb72015-03-24 16:35:39 -040014// Logging and profiling. A StateTag represents a possible state of
15// the VM. The logger maintains a stack of these. Creating a VMState
16// object enters a state by pushing on the stack, and destroying a
17// VMState object leaves a state by popping the current state from the
18// stack.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000019template <StateTag Tag>
Steve Block6ded16b2010-05-10 14:33:55 +010020class VMState BASE_EMBEDDED {
Andrei Popescu402d9372010-02-26 13:31:12 +000021 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +000022 explicit inline VMState(Isolate* isolate);
Steve Block6ded16b2010-05-10 14:33:55 +010023 inline ~VMState();
Andrei Popescu402d9372010-02-26 13:31:12 +000024
Steve Block6ded16b2010-05-10 14:33:55 +010025 private:
Steve Block44f0eee2011-05-26 01:26:41 +010026 Isolate* isolate_;
Ben Murdochb0fe1622011-05-05 13:52:32 +010027 StateTag previous_tag_;
Andrei Popescu402d9372010-02-26 13:31:12 +000028};
29
Ben Murdochb0fe1622011-05-05 13:52:32 +010030
31class ExternalCallbackScope BASE_EMBEDDED {
Ben Murdochb0fe1622011-05-05 13:52:32 +010032 public:
Steve Block44f0eee2011-05-26 01:26:41 +010033 inline ExternalCallbackScope(Isolate* isolate, Address callback);
Ben Murdochb0fe1622011-05-05 13:52:32 +010034 inline ~ExternalCallbackScope();
Ben Murdochb8a8cc12014-11-26 15:28:44 +000035 Address callback() { return callback_; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000036 Address* callback_entrypoint_address() {
37 if (callback_ == nullptr) return nullptr;
38#if USES_FUNCTION_DESCRIPTORS
39 return FUNCTION_ENTRYPOINT_ADDRESS(callback_);
40#else
41 return &callback_;
42#endif
43 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000044 ExternalCallbackScope* previous() { return previous_scope_; }
45 inline Address scope_address();
46
Ben Murdochb0fe1622011-05-05 13:52:32 +010047 private:
Steve Block44f0eee2011-05-26 01:26:41 +010048 Isolate* isolate_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000049 Address callback_;
50 ExternalCallbackScope* previous_scope_;
51#ifdef USE_SIMULATOR
52 Address scope_address_;
53#endif
Ben Murdochb0fe1622011-05-05 13:52:32 +010054};
55
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000056} // namespace internal
57} // namespace v8
Andrei Popescu402d9372010-02-26 13:31:12 +000058
Steve Block6ded16b2010-05-10 14:33:55 +010059
60#endif // V8_VM_STATE_H_