v8/test/unittests/test-helpers.h
Leszek Swirski b3e1eb0c0d [compiler] Introduce ReusableUnoptimizedCompileState
Introduce a ReusableUnoptimizedCompileState class, passed to ParseInfo,
which stores a couple of pointers and most importantly the Zone and
AstValueFactory of the parse. This allows the Zone and AstValueFactory
to be reused across multiple parses, rather than re-initialising
per-Parse.

With this, we can amend the LazyCompileDispatcher to initialise one
LocalIsolate, Zone and AstValueFactory per background thread loop,
rather than one per compile task, which allows us to reduce per-task
costs and re-use the AstValueFactory's string table and previous String
internalizations.

Change-Id: Ia0e29c4e31fbe29af57674ebb10916865d38b2ce
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3313106
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78289}
2021-12-08 11:14:27 +00:00

58 lines
1.4 KiB
C++

// Copyright 2016 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_UNITTESTS_TEST_HELPERS_H_
#define V8_UNITTESTS_TEST_HELPERS_H_
#include <memory>
#include "include/v8-primitive.h"
namespace v8 {
class Isolate;
namespace internal {
class Object;
template <typename T>
class Handle;
class Isolate;
class SharedFunctionInfo;
class String;
class Utf16CharacterStream;
namespace test {
class ScriptResource : public v8::String::ExternalOneByteStringResource {
public:
ScriptResource(const char* data, size_t length)
: data_(data), length_(length) {}
~ScriptResource() override = default;
ScriptResource(const ScriptResource&) = delete;
ScriptResource& operator=(const ScriptResource&) = delete;
const char* data() const override { return data_; }
size_t length() const override { return length_; }
private:
const char* data_;
size_t length_;
};
Handle<String> CreateSource(
Isolate* isolate,
v8::String::ExternalOneByteStringResource* maybe_resource);
Handle<SharedFunctionInfo> CreateSharedFunctionInfo(
Isolate* isolate,
v8::String::ExternalOneByteStringResource* maybe_resource);
std::unique_ptr<Utf16CharacterStream> SourceCharacterStreamForShared(
Isolate* isolate, Handle<SharedFunctionInfo> shared);
} // namespace test
} // namespace internal
} // namespace v8
#endif // V8_UNITTESTS_TEST_HELPERS_H_