[BUILD] Add v8_use_zlib flag
This allows V8 to be compiled without zlib. Currently we use zlib for 3 features: 1. Snapshot compression. The cl asserts v8_snapshot_compression implies v8_use_zlib. 2. Compression of translation arrays (experimental flag). The runtime flag is only enabled if v8_use_zlib. 3. Snapshot checksums. We fallback to a simple Fletcher algorithm if v8_use_zlib is false. Change-Id: If043c3c21bba4d734573d7e1199d3ddf17b84f41 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3833817 Commit-Queue: Victor Gomes <victorgomes@chromium.org> Reviewed-by: Jakob Linke <jgruber@chromium.org> Reviewed-by: Camillo Bruni <cbruni@chromium.org> Cr-Commit-Position: refs/heads/main@{#82527}
This commit is contained in:
parent
0c9083b59e
commit
980b623494
30
BUILD.gn
30
BUILD.gn
@ -377,6 +377,10 @@ declare_args() {
|
|||||||
# Enables pointer compression for 8GB heaps.
|
# Enables pointer compression for 8GB heaps.
|
||||||
# Sets -DV8_COMPRESS_POINTERS_8GB.
|
# Sets -DV8_COMPRESS_POINTERS_8GB.
|
||||||
v8_enable_pointer_compression_8gb = ""
|
v8_enable_pointer_compression_8gb = ""
|
||||||
|
|
||||||
|
# Compile V8 using zlib as dependency.
|
||||||
|
# Sets -DV8_USE_ZLIB
|
||||||
|
v8_use_zlib = true
|
||||||
}
|
}
|
||||||
|
|
||||||
# Derived defaults.
|
# Derived defaults.
|
||||||
@ -622,6 +626,9 @@ if (v8_fuchsia_use_vmex_resource) {
|
|||||||
assert(target_os == "fuchsia", "VMEX resource only available on Fuchsia")
|
assert(target_os == "fuchsia", "VMEX resource only available on Fuchsia")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(!v8_enable_snapshot_compression || v8_use_zlib,
|
||||||
|
"Snapshot compression requires zlib")
|
||||||
|
|
||||||
v8_random_seed = "314159265"
|
v8_random_seed = "314159265"
|
||||||
v8_toolset_for_shell = "host"
|
v8_toolset_for_shell = "host"
|
||||||
|
|
||||||
@ -1080,6 +1087,9 @@ config("features") {
|
|||||||
if (v8_enable_pointer_compression_8gb) {
|
if (v8_enable_pointer_compression_8gb) {
|
||||||
defines += [ "V8_COMPRESS_POINTERS_8GB" ]
|
defines += [ "V8_COMPRESS_POINTERS_8GB" ]
|
||||||
}
|
}
|
||||||
|
if (v8_use_zlib) {
|
||||||
|
defines += [ "V8_USE_ZLIB" ]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
config("toolchain") {
|
config("toolchain") {
|
||||||
@ -3544,7 +3554,6 @@ v8_header_set("v8_internal_headers") {
|
|||||||
"src/snapshot/serializer.h",
|
"src/snapshot/serializer.h",
|
||||||
"src/snapshot/shared-heap-deserializer.h",
|
"src/snapshot/shared-heap-deserializer.h",
|
||||||
"src/snapshot/shared-heap-serializer.h",
|
"src/snapshot/shared-heap-serializer.h",
|
||||||
"src/snapshot/snapshot-compression.h",
|
|
||||||
"src/snapshot/snapshot-data.h",
|
"src/snapshot/snapshot-data.h",
|
||||||
"src/snapshot/snapshot-source-sink.h",
|
"src/snapshot/snapshot-source-sink.h",
|
||||||
"src/snapshot/snapshot-utils.h",
|
"src/snapshot/snapshot-utils.h",
|
||||||
@ -3607,6 +3616,10 @@ v8_header_set("v8_internal_headers") {
|
|||||||
"src/zone/zone.h",
|
"src/zone/zone.h",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if (v8_enable_snapshot_compression) {
|
||||||
|
sources += [ "src/snapshot/snapshot-compression.h" ]
|
||||||
|
}
|
||||||
|
|
||||||
if (v8_use_perfetto) {
|
if (v8_use_perfetto) {
|
||||||
sources -= [ "//base/trace_event/common/trace_event_common.h" ]
|
sources -= [ "//base/trace_event/common/trace_event_common.h" ]
|
||||||
}
|
}
|
||||||
@ -4751,7 +4764,6 @@ v8_source_set("v8_base_without_compiler") {
|
|||||||
"src/snapshot/serializer.cc",
|
"src/snapshot/serializer.cc",
|
||||||
"src/snapshot/shared-heap-deserializer.cc",
|
"src/snapshot/shared-heap-deserializer.cc",
|
||||||
"src/snapshot/shared-heap-serializer.cc",
|
"src/snapshot/shared-heap-serializer.cc",
|
||||||
"src/snapshot/snapshot-compression.cc",
|
|
||||||
"src/snapshot/snapshot-data.cc",
|
"src/snapshot/snapshot-data.cc",
|
||||||
"src/snapshot/snapshot-source-sink.cc",
|
"src/snapshot/snapshot-source-sink.cc",
|
||||||
"src/snapshot/snapshot-utils.cc",
|
"src/snapshot/snapshot-utils.cc",
|
||||||
@ -4790,6 +4802,10 @@ v8_source_set("v8_base_without_compiler") {
|
|||||||
"src/zone/zone.cc",
|
"src/zone/zone.cc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if (v8_enable_snapshot_compression) {
|
||||||
|
sources += [ "src/snapshot/snapshot-compression.cc" ]
|
||||||
|
}
|
||||||
|
|
||||||
if (v8_enable_maglev) {
|
if (v8_enable_maglev) {
|
||||||
sources += [
|
sources += [
|
||||||
"src/maglev/maglev-code-generator.cc",
|
"src/maglev/maglev-code-generator.cc",
|
||||||
@ -5226,10 +5242,12 @@ v8_source_set("v8_base_without_compiler") {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
deps += [
|
if (v8_use_zlib) {
|
||||||
"//third_party/zlib",
|
deps += [
|
||||||
"//third_party/zlib/google:compression_utils_portable",
|
"//third_party/zlib",
|
||||||
]
|
"//third_party/zlib/google:compression_utils_portable",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
if (v8_postmortem_support) {
|
if (v8_postmortem_support) {
|
||||||
sources += [ "$target_gen_dir/debug-support.cc" ]
|
sources += [ "$target_gen_dir/debug-support.cc" ]
|
||||||
|
@ -7,13 +7,17 @@
|
|||||||
#include "src/base/vlq.h"
|
#include "src/base/vlq.h"
|
||||||
#include "src/deoptimizer/translated-state.h"
|
#include "src/deoptimizer/translated-state.h"
|
||||||
#include "src/objects/fixed-array-inl.h"
|
#include "src/objects/fixed-array-inl.h"
|
||||||
|
|
||||||
|
#ifdef V8_USE_ZLIB
|
||||||
#include "third_party/zlib/google/compression_utils_portable.h"
|
#include "third_party/zlib/google/compression_utils_portable.h"
|
||||||
|
#endif // V8_USE_ZLIB
|
||||||
|
|
||||||
namespace v8 {
|
namespace v8 {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
#ifdef V8_USE_ZLIB
|
||||||
// Constants describing compressed TranslationArray layout. Only relevant if
|
// Constants describing compressed TranslationArray layout. Only relevant if
|
||||||
// --turbo-compress-translation-arrays is enabled.
|
// --turbo-compress-translation-arrays is enabled.
|
||||||
constexpr int kUncompressedSizeOffset = 0;
|
constexpr int kUncompressedSizeOffset = 0;
|
||||||
@ -21,12 +25,14 @@ constexpr int kUncompressedSizeSize = kInt32Size;
|
|||||||
constexpr int kCompressedDataOffset =
|
constexpr int kCompressedDataOffset =
|
||||||
kUncompressedSizeOffset + kUncompressedSizeSize;
|
kUncompressedSizeOffset + kUncompressedSizeSize;
|
||||||
constexpr int kTranslationArrayElementSize = kInt32Size;
|
constexpr int kTranslationArrayElementSize = kInt32Size;
|
||||||
|
#endif // V8_USE_ZLIB
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
TranslationArrayIterator::TranslationArrayIterator(TranslationArray buffer,
|
TranslationArrayIterator::TranslationArrayIterator(TranslationArray buffer,
|
||||||
int index)
|
int index)
|
||||||
: buffer_(buffer), index_(index) {
|
: buffer_(buffer), index_(index) {
|
||||||
|
#ifdef V8_USE_ZLIB
|
||||||
if (V8_UNLIKELY(FLAG_turbo_compress_translation_arrays)) {
|
if (V8_UNLIKELY(FLAG_turbo_compress_translation_arrays)) {
|
||||||
const int size = buffer_.get_int(kUncompressedSizeOffset);
|
const int size = buffer_.get_int(kUncompressedSizeOffset);
|
||||||
uncompressed_contents_.insert(uncompressed_contents_.begin(), size, 0);
|
uncompressed_contents_.insert(uncompressed_contents_.begin(), size, 0);
|
||||||
@ -41,9 +47,11 @@ TranslationArrayIterator::TranslationArrayIterator(TranslationArray buffer,
|
|||||||
buffer_.DataSize()),
|
buffer_.DataSize()),
|
||||||
Z_OK);
|
Z_OK);
|
||||||
DCHECK(index >= 0 && index < size);
|
DCHECK(index >= 0 && index < size);
|
||||||
} else {
|
return;
|
||||||
DCHECK(index >= 0 && index < buffer.length());
|
|
||||||
}
|
}
|
||||||
|
#endif // V8_USE_ZLIB
|
||||||
|
DCHECK(!FLAG_turbo_compress_translation_arrays);
|
||||||
|
DCHECK(index >= 0 && index < buffer.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t TranslationArrayIterator::Next() {
|
int32_t TranslationArrayIterator::Next() {
|
||||||
@ -121,6 +129,7 @@ void TranslationArrayBuilder::AddDoubleRegister(DoubleRegister reg) {
|
|||||||
|
|
||||||
Handle<TranslationArray> TranslationArrayBuilder::ToTranslationArray(
|
Handle<TranslationArray> TranslationArrayBuilder::ToTranslationArray(
|
||||||
Factory* factory) {
|
Factory* factory) {
|
||||||
|
#ifdef V8_USE_ZLIB
|
||||||
if (V8_UNLIKELY(FLAG_turbo_compress_translation_arrays)) {
|
if (V8_UNLIKELY(FLAG_turbo_compress_translation_arrays)) {
|
||||||
const int input_size = SizeInBytes();
|
const int input_size = SizeInBytes();
|
||||||
uLongf compressed_data_size = compressBound(input_size);
|
uLongf compressed_data_size = compressBound(input_size);
|
||||||
@ -144,13 +153,14 @@ Handle<TranslationArray> TranslationArrayBuilder::ToTranslationArray(
|
|||||||
compressed_data.data(), compressed_data_size);
|
compressed_data.data(), compressed_data_size);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} else {
|
|
||||||
Handle<TranslationArray> result =
|
|
||||||
factory->NewByteArray(SizeInBytes(), AllocationType::kOld);
|
|
||||||
memcpy(result->GetDataStartAddress(), contents_.data(),
|
|
||||||
contents_.size() * sizeof(uint8_t));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
DCHECK(!FLAG_turbo_compress_translation_arrays);
|
||||||
|
Handle<TranslationArray> result =
|
||||||
|
factory->NewByteArray(SizeInBytes(), AllocationType::kOld);
|
||||||
|
memcpy(result->GetDataStartAddress(), contents_.data(),
|
||||||
|
contents_.size() * sizeof(uint8_t));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TranslationArrayBuilder::BeginBuiltinContinuationFrame(
|
void TranslationArrayBuilder::BeginBuiltinContinuationFrame(
|
||||||
|
@ -957,8 +957,13 @@ DEFINE_BOOL(
|
|||||||
stress_gc_during_compilation, false,
|
stress_gc_during_compilation, false,
|
||||||
"simulate GC/compiler thread race related to https://crbug.com/v8/8520")
|
"simulate GC/compiler thread race related to https://crbug.com/v8/8520")
|
||||||
DEFINE_BOOL(turbo_fast_api_calls, true, "enable fast API calls from TurboFan")
|
DEFINE_BOOL(turbo_fast_api_calls, true, "enable fast API calls from TurboFan")
|
||||||
|
#ifdef V8_USE_ZLIB
|
||||||
DEFINE_BOOL(turbo_compress_translation_arrays, false,
|
DEFINE_BOOL(turbo_compress_translation_arrays, false,
|
||||||
"compress translation arrays (experimental)")
|
"compress translation arrays (experimental)")
|
||||||
|
#else
|
||||||
|
DEFINE_BOOL_READONLY(turbo_compress_translation_arrays, false,
|
||||||
|
"compress translation arrays (experimental)")
|
||||||
|
#endif // V8_USE_ZLIB
|
||||||
DEFINE_BOOL(turbo_inline_js_wasm_calls, true, "inline JS->Wasm calls")
|
DEFINE_BOOL(turbo_inline_js_wasm_calls, true, "inline JS->Wasm calls")
|
||||||
DEFINE_BOOL(turbo_use_mid_tier_regalloc_for_huge_functions, true,
|
DEFINE_BOOL(turbo_use_mid_tier_regalloc_for_huge_functions, true,
|
||||||
"fall back to the mid-tier register allocator for huge functions")
|
"fall back to the mid-tier register allocator for huge functions")
|
||||||
|
@ -5,7 +5,10 @@
|
|||||||
#include "src/snapshot/snapshot-utils.h"
|
#include "src/snapshot/snapshot-utils.h"
|
||||||
|
|
||||||
#include "src/base/sanitizer/msan.h"
|
#include "src/base/sanitizer/msan.h"
|
||||||
|
|
||||||
|
#ifdef V8_USE_ZLIB
|
||||||
#include "third_party/zlib/zlib.h"
|
#include "third_party/zlib/zlib.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace v8 {
|
namespace v8 {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
@ -16,9 +19,20 @@ uint32_t Checksum(base::Vector<const byte> payload) {
|
|||||||
// Mark every object as initialized in the code serializer.
|
// Mark every object as initialized in the code serializer.
|
||||||
MSAN_MEMORY_IS_INITIALIZED(payload.begin(), payload.length());
|
MSAN_MEMORY_IS_INITIALIZED(payload.begin(), payload.length());
|
||||||
#endif // MEMORY_SANITIZER
|
#endif // MEMORY_SANITIZER
|
||||||
|
|
||||||
|
#ifdef V8_USE_ZLIB
|
||||||
// Priming the adler32 call so it can see what CPU features are available.
|
// Priming the adler32 call so it can see what CPU features are available.
|
||||||
adler32(0, nullptr, 0);
|
adler32(0, nullptr, 0);
|
||||||
return static_cast<uint32_t>(adler32(0, payload.begin(), payload.length()));
|
return static_cast<uint32_t>(adler32(0, payload.begin(), payload.length()));
|
||||||
|
#else
|
||||||
|
// Simple Fletcher-32.
|
||||||
|
uint32_t sum1 = 0, sum2 = 0;
|
||||||
|
for (auto data : payload) {
|
||||||
|
sum1 = (sum1 + data) % 65535;
|
||||||
|
sum2 = (sum2 + sum1) % 65535;
|
||||||
|
}
|
||||||
|
return (sum2 << 16 | sum1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
@ -437,6 +437,7 @@ static void SerializeContext(base::Vector<const byte>* startup_blob_out,
|
|||||||
v8_isolate->Dispose();
|
v8_isolate->Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SNAPSHOT_COMPRESSION
|
||||||
UNINITIALIZED_TEST(SnapshotCompression) {
|
UNINITIALIZED_TEST(SnapshotCompression) {
|
||||||
DisableAlwaysOpt();
|
DisableAlwaysOpt();
|
||||||
base::Vector<const byte> startup_blob;
|
base::Vector<const byte> startup_blob;
|
||||||
@ -457,6 +458,7 @@ UNINITIALIZED_TEST(SnapshotCompression) {
|
|||||||
shared_space_blob.Dispose();
|
shared_space_blob.Dispose();
|
||||||
context_blob.Dispose();
|
context_blob.Dispose();
|
||||||
}
|
}
|
||||||
|
#endif // SNAPSHOT_COMPRESSION
|
||||||
|
|
||||||
UNINITIALIZED_TEST(ContextSerializerContext) {
|
UNINITIALIZED_TEST(ContextSerializerContext) {
|
||||||
DisableAlwaysOpt();
|
DisableAlwaysOpt();
|
||||||
|
Loading…
Reference in New Issue
Block a user