v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
bytecode-offset-iterator.h
Go to the documentation of this file.
1// Copyright 2021 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_BASELINE_BYTECODE_OFFSET_ITERATOR_H_
6#define V8_BASELINE_BYTECODE_OFFSET_ITERATOR_H_
7
8#include <optional>
9
10#include "src/base/vlq.h"
11#include "src/common/globals.h"
14
15namespace v8 {
16namespace internal {
17
18class BytecodeArray;
19
20namespace baseline {
21
23 public:
25 Handle<BytecodeArray> bytecodes);
26 // Non-handlified version for use when no GC can happen.
28 Tagged<BytecodeArray> bytecodes);
30
31 inline void Advance() {
32 DCHECK(!done());
33 current_pc_start_offset_ = current_pc_end_offset_;
34 current_pc_end_offset_ += ReadPosition();
35 current_bytecode_offset_ = bytecode_iterator_.current_offset();
36 bytecode_iterator_.Advance();
37 }
38
39 inline void AdvanceToBytecodeOffset(int bytecode_offset) {
40 while (current_bytecode_offset() < bytecode_offset) {
41 Advance();
42 }
43 DCHECK_EQ(bytecode_offset, current_bytecode_offset());
44 }
45
46 inline void AdvanceToPCOffset(Address pc_offset) {
47 while (current_pc_end_offset() < pc_offset) {
48 Advance();
49 }
50 DCHECK_GT(pc_offset, current_pc_start_offset());
51 DCHECK_LE(pc_offset, current_pc_end_offset());
52 }
53
54 // For this iterator, done() means that it is not safe to Advance().
55 // Values are cached, so reads are always allowed.
56 inline bool done() const { return current_index_ >= data_length_; }
57
58 inline Address current_pc_start_offset() const {
59 return current_pc_start_offset_;
60 }
61
62 inline Address current_pc_end_offset() const {
63 return current_pc_end_offset_;
64 }
65
66 inline int current_bytecode_offset() const {
67 return current_bytecode_offset_;
68 }
69
70 static void UpdatePointersCallback(void* iterator) {
71 reinterpret_cast<BytecodeOffsetIterator*>(iterator)->UpdatePointers();
72 }
73
74 void UpdatePointers();
75
76 private:
77 void Initialize();
78 inline int ReadPosition() {
79 return base::VLQDecodeUnsigned(data_start_address_, &current_index_);
80 }
81
92 std::optional<DisallowGarbageCollection> no_gc_;
93};
94
95} // namespace baseline
96} // namespace internal
97} // namespace v8
98
99#endif // V8_BASELINE_BYTECODE_OFFSET_ITERATOR_H_
interpreter::BytecodeArrayIterator bytecode_iterator_
std::optional< DisallowGarbageCollection > no_gc_
int pc_offset
#define DCHECK_LE(v1, v2)
Definition logging.h:490
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
#define DCHECK_GT(v1, v2)
Definition logging.h:487
#define V8_EXPORT_PRIVATE
Definition macros.h:460