Commit 8da9dbbb authored by Ross McIlroy's avatar Ross McIlroy Committed by Commit Bot

[Parser] Add support for Zone allocated ConsumedPreParsingScopeData.

Adds support for zone allocated (off-heap) ConsumedPreParsingScopeData to
enable worker-thread access to PreParsingScopeData during parallel IIFE
compile tasks.

In order to avoid code-duplication, a templated
BaseConsumedPreParsingScopeData is added which implements the logic for
decoding the bytestream into scope data. Two implementations of this
base class are instantiated for each of the underlying serialized scope date:
  - ZoneConsumedPreParsedScopeData for exposing ZonePreParsedScopeData
  - OnHeapConsumedPreParsedScopeData for exposing on-heap PreParsedScopeData
The interface for each of these classes is the ConsumedPreParsingScopeData,
which exposes the methods required by the parser to deserialize the required
data.

As a side-cleanup, moved Ucs2CharLength and Utf8LengthHelper implementations
to cc file so that we don't get a linker error if one of them are unused by
the cc file including the header.


BUG=v8:8041

Change-Id: Id502312d32fe4a9ddb6f5d2d9d3e3a9d30b9b27d
Reviewed-on: https://chromium-review.googlesource.com/1199462
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55711}
parent 60d3f89d
...@@ -2278,6 +2278,7 @@ v8_source_set("v8_base") { ...@@ -2278,6 +2278,7 @@ v8_source_set("v8_base") {
"src/parsing/parsing.cc", "src/parsing/parsing.cc",
"src/parsing/parsing.h", "src/parsing/parsing.h",
"src/parsing/pattern-rewriter.cc", "src/parsing/pattern-rewriter.cc",
"src/parsing/preparsed-scope-data-impl.h",
"src/parsing/preparsed-scope-data.cc", "src/parsing/preparsed-scope-data.cc",
"src/parsing/preparsed-scope-data.h", "src/parsing/preparsed-scope-data.h",
"src/parsing/preparser-logger.h", "src/parsing/preparser-logger.h",
......
...@@ -933,7 +933,7 @@ std::unique_ptr<UnoptimizedCompilationJob> CompileTopLevelOnBackgroundThread( ...@@ -933,7 +933,7 @@ std::unique_ptr<UnoptimizedCompilationJob> CompileTopLevelOnBackgroundThread(
stricter_language_mode(parse_info->language_mode(), language_mode)); stricter_language_mode(parse_info->language_mode(), language_mode));
// Can't access scope info data off-main-thread. // Can't access scope info data off-main-thread.
DCHECK(!parse_info->consumed_preparsed_scope_data()->HasData()); DCHECK(!parse_info->consumed_preparsed_scope_data());
// Generate the unoptimized bytecode or asm-js data. // Generate the unoptimized bytecode or asm-js data.
std::unique_ptr<UnoptimizedCompilationJob> outer_function_job( std::unique_ptr<UnoptimizedCompilationJob> outer_function_job(
...@@ -1086,10 +1086,12 @@ bool Compiler::Compile(Handle<SharedFunctionInfo> shared_info, ...@@ -1086,10 +1086,12 @@ bool Compiler::Compile(Handle<SharedFunctionInfo> shared_info,
if (FLAG_preparser_scope_analysis) { if (FLAG_preparser_scope_analysis) {
if (shared_info->HasUncompiledDataWithPreParsedScope()) { if (shared_info->HasUncompiledDataWithPreParsedScope()) {
parse_info.consumed_preparsed_scope_data()->SetData( parse_info.set_consumed_preparsed_scope_data(
isolate, handle(shared_info->uncompiled_data_with_pre_parsed_scope() ConsumedPreParsedScopeData::For(
->pre_parsed_scope_data(), isolate,
isolate)); handle(shared_info->uncompiled_data_with_pre_parsed_scope()
->pre_parsed_scope_data(),
isolate)));
} }
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "include/v8.h" #include "include/v8.h"
#include "src/globals.h" #include "src/globals.h"
#include "src/handles.h" #include "src/handles.h"
#include "src/objects/script.h"
#include "src/parsing/preparsed-scope-data.h" #include "src/parsing/preparsed-scope-data.h"
#include "src/pending-compilation-error-handler.h" #include "src/pending-compilation-error-handler.h"
...@@ -105,9 +106,12 @@ class V8_EXPORT_PRIVATE ParseInfo { ...@@ -105,9 +106,12 @@ class V8_EXPORT_PRIVATE ParseInfo {
v8::Extension* extension() const { return extension_; } v8::Extension* extension() const { return extension_; }
void set_extension(v8::Extension* extension) { extension_ = extension; } void set_extension(v8::Extension* extension) { extension_ = extension; }
void set_consumed_preparsed_scope_data(
std::unique_ptr<ConsumedPreParsedScopeData> data) {
consumed_preparsed_scope_data_.swap(data);
}
ConsumedPreParsedScopeData* consumed_preparsed_scope_data() { ConsumedPreParsedScopeData* consumed_preparsed_scope_data() {
return &consumed_preparsed_scope_data_; return consumed_preparsed_scope_data_.get();
} }
DeclarationScope* script_scope() const { return script_scope_; } DeclarationScope* script_scope() const { return script_scope_; }
...@@ -266,7 +270,7 @@ class V8_EXPORT_PRIVATE ParseInfo { ...@@ -266,7 +270,7 @@ class V8_EXPORT_PRIVATE ParseInfo {
//----------- Inputs+Outputs of parsing and scope analysis ----------------- //----------- Inputs+Outputs of parsing and scope analysis -----------------
std::unique_ptr<Utf16CharacterStream> character_stream_; std::unique_ptr<Utf16CharacterStream> character_stream_;
ConsumedPreParsedScopeData consumed_preparsed_scope_data_; std::unique_ptr<ConsumedPreParsedScopeData> consumed_preparsed_scope_data_;
std::unique_ptr<AstValueFactory> ast_value_factory_; std::unique_ptr<AstValueFactory> ast_value_factory_;
const class AstStringConstants* ast_string_constants_; const class AstStringConstants* ast_string_constants_;
const AstRawString* function_name_; const AstRawString* function_name_;
......
...@@ -2731,8 +2731,7 @@ Parser::LazyParsingResult Parser::SkipFunction( ...@@ -2731,8 +2731,7 @@ Parser::LazyParsingResult Parser::SkipFunction(
scanner()->current_token() == Token::ARROW); scanner()->current_token() == Token::ARROW);
// FIXME(marja): There are 2 ways to skip functions now. Unify them. // FIXME(marja): There are 2 ways to skip functions now. Unify them.
DCHECK_NOT_NULL(consumed_preparsed_scope_data_); if (consumed_preparsed_scope_data_) {
if (consumed_preparsed_scope_data_->HasData()) {
DCHECK(FLAG_preparser_scope_analysis); DCHECK(FLAG_preparser_scope_analysis);
int end_position; int end_position;
LanguageMode language_mode; LanguageMode language_mode;
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_PARSING_PREPARSED_SCOPE_DATA_IMPL_H_
#define V8_PARSING_PREPARSED_SCOPE_DATA_IMPL_H_
#include "src/parsing/preparsed-scope-data.h"
#include "src/assert-scope.h"
namespace v8 {
namespace internal {
// Classes which are internal to prepared-scope-data.cc, but are exposed in
// a header for tests.
struct PreParsedScopeByteDataConstants {
#ifdef DEBUG
static constexpr int kMagicValue = 0xC0DE0DE;
static constexpr size_t kUint32Size = 5;
static constexpr size_t kUint8Size = 2;
static constexpr size_t kQuarterMarker = 0;
static constexpr size_t kPlaceholderSize = kUint32Size;
#else
static constexpr size_t kUint32Size = 4;
static constexpr size_t kUint8Size = 1;
static constexpr size_t kPlaceholderSize = 0;
#endif
static const size_t kSkippableFunctionDataSize =
4 * kUint32Size + 1 * kUint8Size;
};
class ProducedPreParsedScopeData::ByteData
: public ZoneObject,
public PreParsedScopeByteDataConstants {
public:
explicit ByteData(Zone* zone)
: backing_store_(zone), free_quarters_in_last_byte_(0) {}
void WriteUint32(uint32_t data);
void WriteUint8(uint8_t data);
void WriteQuarter(uint8_t data);
#ifdef DEBUG
// For overwriting previously written data at position 0.
void OverwriteFirstUint32(uint32_t data);
#endif
Handle<PodArray<uint8_t>> Serialize(Isolate* isolate);
size_t size() const { return backing_store_.size(); }
ZoneChunkList<uint8_t>::iterator begin() { return backing_store_.begin(); }
ZoneChunkList<uint8_t>::iterator end() { return backing_store_.end(); }
private:
ZoneChunkList<uint8_t> backing_store_;
uint8_t free_quarters_in_last_byte_;
};
template <class Data>
class BaseConsumedPreParsedScopeData : public ConsumedPreParsedScopeData {
public:
class ByteData : public PreParsedScopeByteDataConstants {
public:
ByteData()
: data_(nullptr), index_(0), stored_quarters_(0), stored_byte_(0) {}
// Reading from the ByteData is only allowed when a ReadingScope is on the
// stack. This ensures that we have a DisallowHeapAllocation in place
// whenever ByteData holds a raw pointer into the heap.
class ReadingScope {
public:
ReadingScope(ByteData* consumed_data, Data* data)
: consumed_data_(consumed_data) {
consumed_data->data_ = data;
}
explicit ReadingScope(BaseConsumedPreParsedScopeData<Data>* parent)
: ReadingScope(parent->scope_data_.get(), parent->GetScopeData()) {}
~ReadingScope() { consumed_data_->data_ = nullptr; }
private:
ByteData* consumed_data_;
DisallowHeapAllocation no_gc;
};
void SetPosition(int position) { index_ = position; }
size_t RemainingBytes() const {
DCHECK_NOT_NULL(data_);
return data_->length() - index_;
}
int32_t ReadUint32() {
DCHECK_NOT_NULL(data_);
DCHECK_GE(RemainingBytes(), kUint32Size);
#ifdef DEBUG
// Check that there indeed is an integer following.
DCHECK_EQ(data_->get(index_++), kUint32Size);
#endif
int32_t result = 0;
byte* p = reinterpret_cast<byte*>(&result);
for (int i = 0; i < 4; ++i) {
*p++ = data_->get(index_++);
}
stored_quarters_ = 0;
return result;
}
uint8_t ReadUint8() {
DCHECK_NOT_NULL(data_);
DCHECK_GE(RemainingBytes(), kUint8Size);
#ifdef DEBUG
// Check that there indeed is a byte following.
DCHECK_EQ(data_->get(index_++), kUint8Size);
#endif
stored_quarters_ = 0;
return data_->get(index_++);
}
uint8_t ReadQuarter() {
DCHECK_NOT_NULL(data_);
if (stored_quarters_ == 0) {
DCHECK_GE(RemainingBytes(), kUint8Size);
#ifdef DEBUG
// Check that there indeed are quarters following.
DCHECK_EQ(data_->get(index_++), kQuarterMarker);
#endif
stored_byte_ = data_->get(index_++);
stored_quarters_ = 4;
}
// Read the first 2 bits from stored_byte_.
uint8_t result = (stored_byte_ >> 6) & 3;
DCHECK_LE(result, 3);
--stored_quarters_;
stored_byte_ <<= 2;
return result;
}
private:
Data* data_;
int index_;
uint8_t stored_quarters_;
uint8_t stored_byte_;
};
BaseConsumedPreParsedScopeData()
: scope_data_(new ByteData()), child_index_(0) {}
virtual Data* GetScopeData() = 0;
virtual ProducedPreParsedScopeData* GetChildData(Zone* zone,
int child_index) = 0;
ProducedPreParsedScopeData* GetDataForSkippableFunction(
Zone* zone, int start_position, int* end_position, int* num_parameters,
int* num_inner_functions, bool* uses_super_property,
LanguageMode* language_mode) final;
void RestoreScopeAllocationData(DeclarationScope* scope) final;
#ifdef DEBUG
void VerifyDataStart();
#endif
private:
void RestoreData(Scope* scope);
void RestoreDataForVariable(Variable* var);
void RestoreDataForInnerScopes(Scope* scope);
std::unique_ptr<ByteData> scope_data_;
// When consuming the data, these indexes point to the data we're going to
// consume next.
int child_index_;
DISALLOW_COPY_AND_ASSIGN(BaseConsumedPreParsedScopeData);
};
// Implementation of ConsumedPreParsedScopeData for on-heap data.
class OnHeapConsumedPreParsedScopeData final
: public BaseConsumedPreParsedScopeData<PodArray<uint8_t>> {
public:
OnHeapConsumedPreParsedScopeData(Isolate* isolate,
Handle<PreParsedScopeData> data);
PodArray<uint8_t>* GetScopeData() final;
ProducedPreParsedScopeData* GetChildData(Zone* zone, int child_index) final;
private:
Isolate* isolate_;
Handle<PreParsedScopeData> data_;
};
// Wraps a ZoneVector<uint8_t> to have with functions named the same as
// PodArray<uint8_t>.
class ZoneVectorWrapper {
public:
explicit ZoneVectorWrapper(ZoneVector<uint8_t>* data) : data_(data) {}
int length() const { return static_cast<int>(data_->size()); }
uint8_t get(int index) const { return data_->at(index); }
private:
ZoneVector<uint8_t>* data_;
DISALLOW_COPY_AND_ASSIGN(ZoneVectorWrapper);
};
// A serialized PreParsedScopeData in zone memory (as apposed to being on-heap).
class ZonePreParsedScopeData : public ZoneObject {
public:
ZonePreParsedScopeData(Zone* zone,
ZoneChunkList<uint8_t>::iterator byte_data_begin,
ZoneChunkList<uint8_t>::iterator byte_data_end,
int child_length);
Handle<PreParsedScopeData> Serialize(Isolate* isolate);
int child_length() const { return static_cast<int>(children_.size()); }
ZonePreParsedScopeData* get_child(int index) { return children_[index]; }
void set_child(int index, ZonePreParsedScopeData* child) {
children_[index] = child;
}
ZoneVector<uint8_t>* byte_data() { return &byte_data_; }
private:
ZoneVector<uint8_t> byte_data_;
ZoneVector<ZonePreParsedScopeData*> children_;
DISALLOW_COPY_AND_ASSIGN(ZonePreParsedScopeData);
};
// Implementation of ConsumedPreParsedScopeData for PreParsedScopeData
// serialized into zone memory.
class ZoneConsumedPreParsedScopeData final
: public BaseConsumedPreParsedScopeData<ZoneVectorWrapper> {
public:
ZoneConsumedPreParsedScopeData(Zone* zone, ZonePreParsedScopeData* data);
ZoneVectorWrapper* GetScopeData() final;
ProducedPreParsedScopeData* GetChildData(Zone* zone, int child_index) final;
private:
ZonePreParsedScopeData* data_;
ZoneVectorWrapper scope_data_wrapper_;
};
} // namespace internal
} // namespace v8
#endif // V8_PARSING_PREPARSED_SCOPE_DATA_IMPL_H_
This diff is collapsed.
...@@ -5,23 +5,21 @@ ...@@ -5,23 +5,21 @@
#ifndef V8_PARSING_PREPARSED_SCOPE_DATA_H_ #ifndef V8_PARSING_PREPARSED_SCOPE_DATA_H_
#define V8_PARSING_PREPARSED_SCOPE_DATA_H_ #define V8_PARSING_PREPARSED_SCOPE_DATA_H_
#include <set>
#include <unordered_map>
#include <vector>
#include "src/globals.h" #include "src/globals.h"
#include "src/handles.h" #include "src/handles.h"
#include "src/objects/shared-function-info.h" #include "src/maybe-handles.h"
#include "src/zone/zone-chunk-list.h" #include "src/zone/zone-chunk-list.h"
#include "src/zone/zone-containers.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
template <typename T> template <typename T>
class Handle; class PodArray;
class PreParser; class PreParser;
class PreParsedScopeData; class PreParsedScopeData;
class ZonePreParsedScopeData;
/* /*
...@@ -66,37 +64,20 @@ class PreParsedScopeData; ...@@ -66,37 +64,20 @@ class PreParsedScopeData;
class ProducedPreParsedScopeData : public ZoneObject { class ProducedPreParsedScopeData : public ZoneObject {
public: public:
class ByteData : public ZoneObject { class ByteData;
public:
explicit ByteData(Zone* zone)
: backing_store_(zone), free_quarters_in_last_byte_(0) {}
void WriteUint32(uint32_t data);
void WriteUint8(uint8_t data);
void WriteQuarter(uint8_t data);
#ifdef DEBUG
// For overwriting previously written data at position 0.
void OverwriteFirstUint32(uint32_t data);
#endif
Handle<PodArray<uint8_t>> Serialize(Isolate* isolate);
size_t size() const { return backing_store_.size(); }
private:
ZoneChunkList<uint8_t> backing_store_;
uint8_t free_quarters_in_last_byte_;
};
// Create a ProducedPreParsedScopeData object which will collect data as we // Create a ProducedPreParsedScopeData object which will collect data as we
// parse. // parse.
ProducedPreParsedScopeData(Zone* zone, ProducedPreParsedScopeData* parent); ProducedPreParsedScopeData(Zone* zone, ProducedPreParsedScopeData* parent);
// Create a ProducedPreParsedScopeData which is just a proxy for a previous // Create a ProducedPreParsedScopeData which is just a proxy for a previous
// produced PreParsedScopeData. // produced PreParsedScopeData on the heap.
ProducedPreParsedScopeData(Handle<PreParsedScopeData> data, Zone* zone); ProducedPreParsedScopeData(Handle<PreParsedScopeData> data, Zone* zone);
// Create a ProducedPreParsedScopeData which is just a proxy for a previous
// produced PreParsedScopeData in zone.
ProducedPreParsedScopeData(ZonePreParsedScopeData* data, Zone* zone);
ProducedPreParsedScopeData* parent() const { return parent_; } ProducedPreParsedScopeData* parent() const { return parent_; }
// For gathering the inner function data and splitting it up according to the // For gathering the inner function data and splitting it up according to the
...@@ -153,6 +134,11 @@ class ProducedPreParsedScopeData : public ZoneObject { ...@@ -153,6 +134,11 @@ class ProducedPreParsedScopeData : public ZoneObject {
// MaybeHandle. // MaybeHandle.
MaybeHandle<PreParsedScopeData> Serialize(Isolate* isolate); MaybeHandle<PreParsedScopeData> Serialize(Isolate* isolate);
// If there is data (if the Scope contains skippable inner functions), return
// an off-heap ZonePreParsedScopeData representing the data; otherwise
// return nullptr.
ZonePreParsedScopeData* Serialize(Zone* zone);
static bool ScopeNeedsData(Scope* scope); static bool ScopeNeedsData(Scope* scope);
static bool ScopeIsSkippableFunctionScope(Scope* scope); static bool ScopeIsSkippableFunctionScope(Scope* scope);
...@@ -174,80 +160,48 @@ class ProducedPreParsedScopeData : public ZoneObject { ...@@ -174,80 +160,48 @@ class ProducedPreParsedScopeData : public ZoneObject {
// Whether we've given up producing the data for this function. // Whether we've given up producing the data for this function.
bool bailed_out_; bool bailed_out_;
// ProducedPreParsedScopeData can also mask a Handle<PreParsedScopeData> // ProducedPreParsedScopeData can also hold a Handle<PreParsedScopeData>
// which was produced already earlier. This happens for deeper lazy functions. // which was produced already earlier. This happens for deeper lazy functions.
Handle<PreParsedScopeData> previously_produced_preparsed_scope_data_; // TODO(rmcilroy): Split apart ProducedPreParsedScopeData into different
// classes for situations where it has already been produced.
Handle<PreParsedScopeData> previously_produced_on_heap_preparsed_scope_data_;
// ProducedPreParsedScopeData can also hold a ZonePreParsedScopeData*
// which was produced already earlier. This happens for deeper lazy functions.
// TODO(rmcilroy): Split apart ProducedPreParsedScopeData into different
// classes for situations where it has already been produced.
ZonePreParsedScopeData* previously_produced_zone_preparsed_scope_data_;
DISALLOW_COPY_AND_ASSIGN(ProducedPreParsedScopeData); DISALLOW_COPY_AND_ASSIGN(ProducedPreParsedScopeData);
}; };
class ConsumedPreParsedScopeData { class ConsumedPreParsedScopeData {
public: public:
class ByteData { // Creates a ConsumedPreParsedScopeData representing the data of an on-heap
public: // PreParsedScopeData |data|.
ByteData() static std::unique_ptr<ConsumedPreParsedScopeData> For(
: data_(nullptr), index_(0), stored_quarters_(0), stored_byte_(0) {} Isolate* isolate, Handle<PreParsedScopeData> data);
// Reading from the ByteData is only allowed when a ReadingScope is on the
// stack. This ensures that we have a DisallowHeapAllocation in place
// whenever ByteData holds a raw pointer into the heap.
class ReadingScope {
public:
ReadingScope(ByteData* consumed_data, PodArray<uint8_t>* data)
: consumed_data_(consumed_data) {
consumed_data->data_ = data;
}
explicit ReadingScope(ConsumedPreParsedScopeData* parent);
~ReadingScope() { consumed_data_->data_ = nullptr; }
private:
ByteData* consumed_data_;
DisallowHeapAllocation no_gc;
};
void SetPosition(int position) { index_ = position; }
int32_t ReadUint32();
uint8_t ReadUint8();
uint8_t ReadQuarter();
size_t RemainingBytes() const;
// private:
PodArray<uint8_t>* data_;
int index_;
uint8_t stored_quarters_;
uint8_t stored_byte_;
};
ConsumedPreParsedScopeData();
~ConsumedPreParsedScopeData();
void SetData(Isolate* isolate, Handle<PreParsedScopeData> data); // Creates a ConsumedPreParsedScopeData representing the data of an off-heap
// ZonePreParsedScopeData |data|.
static std::unique_ptr<ConsumedPreParsedScopeData> For(
Zone* zone, ZonePreParsedScopeData* data);
bool HasData() const { return !data_.is_null(); } virtual ~ConsumedPreParsedScopeData() {}
ProducedPreParsedScopeData* GetDataForSkippableFunction( virtual ProducedPreParsedScopeData* GetDataForSkippableFunction(
Zone* zone, int start_position, int* end_position, int* num_parameters, Zone* zone, int start_position, int* end_position, int* num_parameters,
int* num_inner_functions, bool* uses_super_property, int* num_inner_functions, bool* uses_super_property,
LanguageMode* language_mode); LanguageMode* language_mode) = 0;
// Restores the information needed for allocating the Scope's (and its // Restores the information needed for allocating the Scope's (and its
// subscopes') variables. // subscopes') variables.
void RestoreScopeAllocationData(DeclarationScope* scope); virtual void RestoreScopeAllocationData(DeclarationScope* scope) = 0;
private: protected:
void RestoreData(Scope* scope); ConsumedPreParsedScopeData() {}
void RestoreDataForVariable(Variable* var);
void RestoreDataForInnerScopes(Scope* scope);
Isolate* isolate_;
Handle<PreParsedScopeData> data_;
std::unique_ptr<ByteData> scope_data_;
// When consuming the data, these indexes point to the data we're going to
// consume next.
int child_index_;
private:
DISALLOW_COPY_AND_ASSIGN(ConsumedPreParsedScopeData); DISALLOW_COPY_AND_ASSIGN(ConsumedPreParsedScopeData);
}; };
......
...@@ -155,8 +155,8 @@ class ZoneChunkListIterator ...@@ -155,8 +155,8 @@ class ZoneChunkListIterator
using ChunkList = maybe_const<ZoneChunkList<T>>; using ChunkList = maybe_const<ZoneChunkList<T>>;
public: public:
maybe_const<T>& operator*() { return current_->items()[position_]; } maybe_const<T>& operator*() const { return current_->items()[position_]; }
maybe_const<T>* operator->() { return &current_->items()[position_]; } maybe_const<T>* operator->() const { return &current_->items()[position_]; }
bool operator==(const ZoneChunkListIterator& other) const { bool operator==(const ZoneChunkListIterator& other) const {
return other.current_ == current_ && other.position_ == position_; return other.current_ == current_ && other.position_ == position_;
} }
......
...@@ -239,6 +239,7 @@ v8_source_set("cctest_sources") { ...@@ -239,6 +239,7 @@ v8_source_set("cctest_sources") {
"trace-extension.cc", "trace-extension.cc",
"trace-extension.h", "trace-extension.h",
"types-fuzz.h", "types-fuzz.h",
"unicode-helpers.cc",
"unicode-helpers.h", "unicode-helpers.h",
"wasm/test-c-wasm-entry.cc", "wasm/test-c-wasm-entry.cc",
"wasm/test-jump-table-assembler.cc", "wasm/test-jump-table-assembler.cc",
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "src/objects-inl.h" #include "src/objects-inl.h"
#include "src/parsing/parse-info.h" #include "src/parsing/parse-info.h"
#include "src/parsing/parsing.h" #include "src/parsing/parsing.h"
#include "src/parsing/preparsed-scope-data-impl.h"
#include "src/parsing/preparsed-scope-data.h" #include "src/parsing/preparsed-scope-data.h"
#include "test/cctest/cctest.h" #include "test/cctest/cctest.h"
...@@ -747,8 +748,8 @@ TEST(PreParserScopeAnalysis) { ...@@ -747,8 +748,8 @@ TEST(PreParserScopeAnalysis) {
// Parse the lazy function using the scope data. // Parse the lazy function using the scope data.
i::ParseInfo using_scope_data(isolate, shared); i::ParseInfo using_scope_data(isolate, shared);
using_scope_data.set_lazy_compile(); using_scope_data.set_lazy_compile();
using_scope_data.consumed_preparsed_scope_data()->SetData( using_scope_data.set_consumed_preparsed_scope_data(
isolate, produced_data_on_heap); i::ConsumedPreParsedScopeData::For(isolate, produced_data_on_heap));
CHECK(i::parsing::ParseFunction(&using_scope_data, shared, isolate)); CHECK(i::parsing::ParseFunction(&using_scope_data, shared, isolate));
// Verify that we skipped at least one function inside that scope. // Verify that we skipped at least one function inside that scope.
...@@ -841,32 +842,67 @@ TEST(ProducingAndConsumingByteData) { ...@@ -841,32 +842,67 @@ TEST(ProducingAndConsumingByteData) {
// End with a lonely quarter. // End with a lonely quarter.
bytes.WriteQuarter(2); bytes.WriteQuarter(2);
i::Handle<i::PodArray<uint8_t>> data_on_heap = bytes.Serialize(isolate); {
i::ConsumedPreParsedScopeData::ByteData bytes_for_reading; // Serialize as a ZoneConsumedPreParsedScopeData, and read back data.
i::ConsumedPreParsedScopeData::ByteData::ReadingScope reading_scope( i::ZonePreParsedScopeData zone_serialized(&zone, bytes.begin(), bytes.end(),
&bytes_for_reading, *data_on_heap); 0);
i::ZoneConsumedPreParsedScopeData::ByteData bytes_for_reading;
i::ZoneVectorWrapper wrapper(zone_serialized.byte_data());
i::ZoneConsumedPreParsedScopeData::ByteData::ReadingScope reading_scope(
&bytes_for_reading, &wrapper);
// Read the data back.
#ifdef DEBUG #ifdef DEBUG
CHECK_EQ(bytes_for_reading.ReadUint32(), 2017); CHECK_EQ(bytes_for_reading.ReadUint32(), 2017);
#else #else
CHECK_EQ(bytes_for_reading.ReadUint32(), 1983); CHECK_EQ(bytes_for_reading.ReadUint32(), 1983);
#endif #endif
CHECK_EQ(bytes_for_reading.ReadUint32(), 2147483647); CHECK_EQ(bytes_for_reading.ReadUint32(), 2147483647);
CHECK_EQ(bytes_for_reading.ReadUint8(), 4); CHECK_EQ(bytes_for_reading.ReadUint8(), 4);
CHECK_EQ(bytes_for_reading.ReadUint8(), 255); CHECK_EQ(bytes_for_reading.ReadUint8(), 255);
CHECK_EQ(bytes_for_reading.ReadUint32(), 0); CHECK_EQ(bytes_for_reading.ReadUint32(), 0);
CHECK_EQ(bytes_for_reading.ReadUint8(), 0); CHECK_EQ(bytes_for_reading.ReadUint8(), 0);
CHECK_EQ(bytes_for_reading.ReadUint8(), 100); CHECK_EQ(bytes_for_reading.ReadUint8(), 100);
CHECK_EQ(bytes_for_reading.ReadQuarter(), 3); CHECK_EQ(bytes_for_reading.ReadQuarter(), 3);
CHECK_EQ(bytes_for_reading.ReadQuarter(), 0); CHECK_EQ(bytes_for_reading.ReadQuarter(), 0);
CHECK_EQ(bytes_for_reading.ReadQuarter(), 2); CHECK_EQ(bytes_for_reading.ReadQuarter(), 2);
CHECK_EQ(bytes_for_reading.ReadQuarter(), 1); CHECK_EQ(bytes_for_reading.ReadQuarter(), 1);
CHECK_EQ(bytes_for_reading.ReadQuarter(), 0); CHECK_EQ(bytes_for_reading.ReadQuarter(), 0);
CHECK_EQ(bytes_for_reading.ReadUint8(), 50); CHECK_EQ(bytes_for_reading.ReadUint8(), 50);
CHECK_EQ(bytes_for_reading.ReadQuarter(), 0); CHECK_EQ(bytes_for_reading.ReadQuarter(), 0);
CHECK_EQ(bytes_for_reading.ReadQuarter(), 1); CHECK_EQ(bytes_for_reading.ReadQuarter(), 1);
CHECK_EQ(bytes_for_reading.ReadQuarter(), 2); CHECK_EQ(bytes_for_reading.ReadQuarter(), 2);
CHECK_EQ(bytes_for_reading.ReadUint32(), 50); CHECK_EQ(bytes_for_reading.ReadUint32(), 50);
CHECK_EQ(bytes_for_reading.ReadQuarter(), 2); CHECK_EQ(bytes_for_reading.ReadQuarter(), 2);
}
{
// Serialize as an OnHeapConsumedPreParsedScopeData, and read back data.
i::Handle<i::PodArray<uint8_t>> data_on_heap = bytes.Serialize(isolate);
i::OnHeapConsumedPreParsedScopeData::ByteData bytes_for_reading;
i::OnHeapConsumedPreParsedScopeData::ByteData::ReadingScope reading_scope(
&bytes_for_reading, *data_on_heap);
#ifdef DEBUG
CHECK_EQ(bytes_for_reading.ReadUint32(), 2017);
#else
CHECK_EQ(bytes_for_reading.ReadUint32(), 1983);
#endif
CHECK_EQ(bytes_for_reading.ReadUint32(), 2147483647);
CHECK_EQ(bytes_for_reading.ReadUint8(), 4);
CHECK_EQ(bytes_for_reading.ReadUint8(), 255);
CHECK_EQ(bytes_for_reading.ReadUint32(), 0);
CHECK_EQ(bytes_for_reading.ReadUint8(), 0);
CHECK_EQ(bytes_for_reading.ReadUint8(), 100);
CHECK_EQ(bytes_for_reading.ReadQuarter(), 3);
CHECK_EQ(bytes_for_reading.ReadQuarter(), 0);
CHECK_EQ(bytes_for_reading.ReadQuarter(), 2);
CHECK_EQ(bytes_for_reading.ReadQuarter(), 1);
CHECK_EQ(bytes_for_reading.ReadQuarter(), 0);
CHECK_EQ(bytes_for_reading.ReadUint8(), 50);
CHECK_EQ(bytes_for_reading.ReadQuarter(), 0);
CHECK_EQ(bytes_for_reading.ReadQuarter(), 1);
CHECK_EQ(bytes_for_reading.ReadQuarter(), 2);
CHECK_EQ(bytes_for_reading.ReadUint32(), 50);
CHECK_EQ(bytes_for_reading.ReadQuarter(), 2);
}
} }
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "test/cctest/unicode-helpers.h"
int Ucs2CharLength(unibrow::uchar c) {
if (c == unibrow::Utf8::kIncomplete || c == unibrow::Utf8::kBufferEmpty) {
return 0;
} else if (c < 0xFFFF) {
return 1;
} else {
return 2;
}
}
int Utf8LengthHelper(const char* s) {
unibrow::Utf8::Utf8IncrementalBuffer buffer(unibrow::Utf8::kBufferEmpty);
unibrow::Utf8::State state = unibrow::Utf8::State::kAccept;
int length = 0;
size_t i = 0;
while (s[i] != '\0') {
unibrow::uchar tmp =
unibrow::Utf8::ValueOfIncremental(s[i], &i, &state, &buffer);
length += Ucs2CharLength(tmp);
}
unibrow::uchar tmp = unibrow::Utf8::ValueOfIncrementalFinish(&state);
length += Ucs2CharLength(tmp);
return length;
}
...@@ -7,30 +7,7 @@ ...@@ -7,30 +7,7 @@
#include "src/unicode.h" #include "src/unicode.h"
static int Ucs2CharLength(unibrow::uchar c) { int Ucs2CharLength(unibrow::uchar c);
if (c == unibrow::Utf8::kIncomplete || c == unibrow::Utf8::kBufferEmpty) { int Utf8LengthHelper(const char* s);
return 0;
} else if (c < 0xFFFF) {
return 1;
} else {
return 2;
}
}
static int Utf8LengthHelper(const char* s) {
unibrow::Utf8::Utf8IncrementalBuffer buffer(unibrow::Utf8::kBufferEmpty);
unibrow::Utf8::State state = unibrow::Utf8::State::kAccept;
int length = 0;
size_t i = 0;
while (s[i] != '\0') {
unibrow::uchar tmp =
unibrow::Utf8::ValueOfIncremental(s[i], &i, &state, &buffer);
length += Ucs2CharLength(tmp);
}
unibrow::uchar tmp = unibrow::Utf8::ValueOfIncrementalFinish(&state);
length += Ucs2CharLength(tmp);
return length;
}
#endif // V8_CCTEST_UNICODE_HELPERS_H_ #endif // V8_CCTEST_UNICODE_HELPERS_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment