v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
literal-buffer.h
Go to the documentation of this file.
1// Copyright 2019 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_PARSING_LITERAL_BUFFER_H_
6#define V8_PARSING_LITERAL_BUFFER_H_
7
8#include "include/v8config.h"
9#include "src/base/strings.h"
10#include "src/base/vector.h"
12
13namespace v8 {
14namespace internal {
15
16// LiteralBuffer - Collector of chars of literals.
17class LiteralBuffer final {
18 public:
19 LiteralBuffer() = default;
21
22 LiteralBuffer(const LiteralBuffer&) = delete;
24
25 V8_INLINE void AddChar(char code_unit) {
26 DCHECK(IsValidAscii(code_unit));
27 AddOneByteChar(static_cast<uint8_t>(code_unit));
28 }
29
30 V8_INLINE void AddChar(base::uc32 code_unit) {
31 if (is_one_byte()) {
32 if (code_unit <= static_cast<base::uc32>(unibrow::Latin1::kMaxChar)) {
33 AddOneByteChar(static_cast<uint8_t>(code_unit));
34 return;
35 }
37 }
38 AddTwoByteChar(code_unit);
39 }
40
41 bool is_one_byte() const { return is_one_byte_; }
42
43 bool Equals(base::Vector<const char> keyword) const {
44 return is_one_byte() && keyword.length() == position_ &&
45 (memcmp(keyword.begin(), backing_store_.begin(), position_) == 0);
46 }
47
51
55
56 template <typename Char>
58 DCHECK_EQ(is_one_byte_, sizeof(Char) == 1);
59 DCHECK_EQ(position_ & (sizeof(Char) - 1), 0);
61 reinterpret_cast<const Char*>(backing_store_.begin()),
62 position_ >> (sizeof(Char) - 1));
63 }
64
65 int length() const { return is_one_byte() ? position_ : (position_ >> 1); }
66
67 void Start() {
68 position_ = 0;
69 is_one_byte_ = true;
70 }
71
72 template <typename IsolateT>
73 DirectHandle<String> Internalize(IsolateT* isolate) const;
74
75 private:
76 static constexpr int kInitialCapacity = 256;
77 static constexpr int kGrowthFactor = 4;
78 static constexpr int kMaxGrowth = 1 * MB;
79
80 inline bool IsValidAscii(char code_unit) {
81 // Control characters and printable characters span the range of
82 // valid ASCII characters (0-127). Chars are unsigned on some
83 // platforms which causes compiler warnings if the validity check
84 // tests the lower bound >= 0 as it's always true.
85 return iscntrl(code_unit) || isprint(code_unit);
86 }
87
88 V8_INLINE void AddOneByteChar(uint8_t one_byte_char) {
91 backing_store_[position_] = one_byte_char;
93 }
94
95 void AddTwoByteChar(base::uc32 code_unit);
96 int NewCapacity(int min_capacity);
98 void ConvertToTwoByte();
99
101 int position_ = 0;
102 bool is_one_byte_ = true;
103};
104
105} // namespace internal
106} // namespace v8
107
108#endif // V8_PARSING_LITERAL_BUFFER_H_
static const uint16_t kMaxChar
Definition unicode.h:142
int length() const
Definition vector.h:64
void Dispose()
Definition vector.h:127
constexpr T * begin() const
Definition vector.h:96
bool IsValidAscii(char code_unit)
V8_INLINE void AddOneByteChar(uint8_t one_byte_char)
base::Vector< const Char > literal() const
base::Vector< uint8_t > backing_store_
V8_INLINE void AddChar(char code_unit)
static constexpr int kGrowthFactor
V8_NOINLINE V8_PRESERVE_MOST void ExpandBuffer()
static constexpr int kMaxGrowth
base::Vector< const uint16_t > two_byte_literal() const
V8_INLINE void AddChar(base::uc32 code_unit)
LiteralBuffer(const LiteralBuffer &)=delete
DirectHandle< String > Internalize(IsolateT *isolate) const
static constexpr int kInitialCapacity
void AddTwoByteChar(base::uc32 code_unit)
base::Vector< const uint8_t > one_byte_literal() const
bool Equals(base::Vector< const char > keyword) const
int NewCapacity(int min_capacity)
LiteralBuffer & operator=(const LiteralBuffer &)=delete
uint32_t uc32
Definition strings.h:19
constexpr int kOneByteSize
Definition globals.h:703
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in allocation gc speed threshold for starting incremental marking via a task in percent of available threshold for starting incremental marking immediately in percent of available Use a single schedule for determining a marking schedule between JS and C objects schedules the minor GC task with kUserVisible priority max worker number of concurrent for NumberOfWorkerThreads start background threads that allocate memory concurrent_array_buffer_sweeping use parallel threads to clear weak refs in the atomic pause trace progress of the incremental marking trace object counts and memory usage * MB
Definition flags.cc:2197
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
#define V8_INLINE
Definition v8config.h:500
#define V8_NOINLINE
Definition v8config.h:586
#define V8_PRESERVE_MOST
Definition v8config.h:598