v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
bytecode-jump-table.h
Go to the documentation of this file.
1// Copyright 2017 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_INTERPRETER_BYTECODE_JUMP_TABLE_H_
6#define V8_INTERPRETER_BYTECODE_JUMP_TABLE_H_
7
9#include "src/zone/zone.h"
10
11namespace v8 {
12namespace internal {
13namespace interpreter {
14
15class ConstantArrayBuilder;
16
17// A jump table for a set of targets in a bytecode array. When an entry in the
18// table is bound, it represents a known position in the bytecode array. If no
19// entries match, the switch falls through.
21 public:
22 // Constructs a new BytecodeJumpTable starting at |constant_pool_index|, with
23 // the given |size|, where the case values of the table start at
24 // |case_value_base|.
25 BytecodeJumpTable(size_t constant_pool_index, int size, int case_value_base,
26 Zone* zone)
27 :
28#ifdef DEBUG
29 bound_(size, zone),
30#endif
31 constant_pool_index_(constant_pool_index),
32 switch_bytecode_offset_(kInvalidOffset),
33 size_(size),
34 case_value_base_(case_value_base) {
35 }
36
37 size_t constant_pool_index() const { return constant_pool_index_; }
38 size_t switch_bytecode_offset() const { return switch_bytecode_offset_; }
39 int case_value_base() const { return case_value_base_; }
40 int size() const { return size_; }
41#ifdef DEBUG
42 bool is_bound(int case_value) const {
43 DCHECK_GE(case_value, case_value_base_);
44 DCHECK_LT(case_value, case_value_base_ + size());
45 return bound_.Contains(case_value - case_value_base_);
46 }
47#endif
48
49 size_t ConstantPoolEntryFor(int case_value) {
50 DCHECK_GE(case_value, case_value_base_);
51 return constant_pool_index_ + case_value - case_value_base_;
52 }
53
54 private:
55 static const size_t kInvalidIndex = static_cast<size_t>(-1);
56 static const size_t kInvalidOffset = static_cast<size_t>(-1);
57
58 void mark_bound(int case_value) {
59#ifdef DEBUG
60 DCHECK_GE(case_value, case_value_base_);
61 DCHECK_LT(case_value, case_value_base_ + size());
62 bound_.Add(case_value - case_value_base_);
63#endif
64 }
65
67 DCHECK_EQ(switch_bytecode_offset_, kInvalidOffset);
68 switch_bytecode_offset_ = offset;
69 }
70
71#ifdef DEBUG
72 // This bit vector is only used for DCHECKS, so only store the field in debug
73 // builds.
74 BitVector bound_;
75#endif
78 int size_;
80
81 friend class BytecodeArrayWriter;
82};
83
84} // namespace interpreter
85} // namespace internal
86} // namespace v8
87
88#endif // V8_INTERPRETER_BYTECODE_JUMP_TABLE_H_
BytecodeJumpTable(size_t constant_pool_index, int size, int case_value_base, Zone *zone)
const int size_
Definition assembler.cc:132
int32_t offset
#define DCHECK_GE(v1, v2)
Definition logging.h:488
#define DCHECK_LT(v1, v2)
Definition logging.h:489
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
#define V8_EXPORT_PRIVATE
Definition macros.h:460