From 9b8d40594a1aa6451ae6c98d518174447face04b Mon Sep 17 00:00:00 2001 From: yangguo Date: Fri, 21 Nov 2014 04:45:10 -0800 Subject: [PATCH] Rip out bzip compression for native sources. R=vogelheim@chromium.org Review URL: https://codereview.chromium.org/750543002 Cr-Commit-Position: refs/heads/master@{#25464} --- BUILD.gn | 17 ------ build/features.gypi | 5 -- include/v8.h | 56 +----------------- samples/process.cc | 4 -- samples/shell.cc | 4 -- src/api.cc | 128 ----------------------------------------- src/d8.cc | 41 ------------- src/d8.gyp | 1 - src/mksnapshot.cc | 73 +---------------------- src/snapshot.h | 15 ----- test/cctest/cctest.gyp | 1 - tools/gyp/v8.gyp | 19 ------ tools/js2c.py | 28 ++------- 13 files changed, 6 insertions(+), 386 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 1c2c52a97e..b7bcb161d4 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -4,7 +4,6 @@ # TODO(jochen): These will need to be user-settable to support standalone V8 # builds. -v8_compress_startup_data = "off" v8_deprecation_warnings = false v8_enable_disassembler = false v8_enable_gdbjit = false @@ -95,11 +94,6 @@ config("features") { "V8_I18N_SUPPORT", ] } - if (v8_compress_startup_data == "bz2") { - defines += [ - "COMPRESS_STARTUP_DATA_BZ2", - ] - } if (v8_enable_extra_checks == true) { defines += [ "ENABLE_EXTRA_CHECKS", @@ -216,7 +210,6 @@ action("js2c") { args = [ rebase_path("$target_gen_dir/libraries.cc", root_build_dir), "CORE", - v8_compress_startup_data ] + rebase_path(sources, root_build_dir) if (v8_use_external_startup_data) { @@ -256,7 +249,6 @@ action("js2c_experimental") { args = [ rebase_path("$target_gen_dir/experimental-libraries.cc", root_build_dir), "EXPERIMENTAL", - v8_compress_startup_data ] + rebase_path(sources, root_build_dir) if (v8_use_external_startup_data) { @@ -1216,11 +1208,6 @@ source_set("v8_base") { # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. cflags = [ "/wd4267" ] } - if (is_linux) { - if (v8_compress_startup_data == "bz2") { - libs += [ "bz2" ] - } - } if (v8_enable_i18n_support) { deps += [ "//third_party/icu" ] @@ -1394,10 +1381,6 @@ if (current_toolchain == host_toolchain) { ":v8_nosnapshot", "//build/config/sanitizers:deps", ] - - if (v8_compress_startup_data == "bz2") { - libs = [ "bz2" ] - } } } diff --git a/build/features.gypi b/build/features.gypi index 612055a30c..6cb0c90cd8 100644 --- a/build/features.gypi +++ b/build/features.gypi @@ -29,8 +29,6 @@ { 'variables': { - 'v8_compress_startup_data%': 'off', - 'v8_enable_disassembler%': 0, 'v8_enable_gdbjit%': 0, @@ -94,9 +92,6 @@ ['v8_enable_i18n_support==1', { 'defines': ['V8_I18N_SUPPORT',], }], - ['v8_compress_startup_data=="bz2"', { - 'defines': ['COMPRESS_STARTUP_DATA_BZ2',], - }], ['v8_use_external_startup_data==1', { 'defines': ['V8_USE_EXTERNAL_STARTUP_DATA',], }], diff --git a/include/v8.h b/include/v8.h index af8426d7e6..21911b460d 100644 --- a/include/v8.h +++ b/include/v8.h @@ -5160,42 +5160,12 @@ class V8_EXPORT Isolate { class V8_EXPORT StartupData { public: - enum CompressionAlgorithm { - kUncompressed, - kBZip2 - }; - const char* data; - int compressed_size; + int compressed_size; // TODO(yangguo): remove this. int raw_size; }; -/** - * A helper class for driving V8 startup data decompression. It is based on - * "CompressedStartupData" API functions from the V8 class. It isn't mandatory - * for an embedder to use this class, instead, API functions can be used - * directly. - * - * For an example of the class usage, see the "shell.cc" sample application. - */ -class V8_EXPORT StartupDataDecompressor { // NOLINT - public: - StartupDataDecompressor(); - virtual ~StartupDataDecompressor(); - int Decompress(); - - protected: - virtual int DecompressData(char* raw_data, - int* raw_data_size, - const char* compressed_data, - int compressed_data_size) = 0; - - private: - char** raw_data; -}; - - /** * EntropySource is used as a callback function when v8 needs a source * of entropy. @@ -5252,30 +5222,6 @@ class V8_EXPORT V8 { // TODO(dcarney): deprecate this. V8_INLINE static bool IsDead(); - /** - * The following 4 functions are to be used when V8 is built with - * the 'compress_startup_data' flag enabled. In this case, the - * embedder must decompress startup data prior to initializing V8. - * - * This is how interaction with V8 should look like: - * int compressed_data_count = v8::V8::GetCompressedStartupDataCount(); - * v8::StartupData* compressed_data = - * new v8::StartupData[compressed_data_count]; - * v8::V8::GetCompressedStartupData(compressed_data); - * ... decompress data (compressed_data can be updated in-place) ... - * v8::V8::SetDecompressedStartupData(compressed_data); - * ... now V8 can be initialized - * ... make sure the decompressed data stays valid until V8 shutdown - * - * A helper class StartupDataDecompressor is provided. It implements - * the protocol of the interaction described above, and can be used in - * most cases instead of calling these API functions directly. - */ - static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm(); - static int GetCompressedStartupDataCount(); - static void GetCompressedStartupData(StartupData* compressed_data); - static void SetDecompressedStartupData(StartupData* decompressed_data); - /** * Hand startup data to V8, in case the embedder has chosen to build * V8 with external startup data. diff --git a/samples/process.cc b/samples/process.cc index e5c9b7a53c..fada73dcbd 100644 --- a/samples/process.cc +++ b/samples/process.cc @@ -32,10 +32,6 @@ #include #include -#ifdef COMPRESS_STARTUP_DATA_BZ2 -#error Using compressed startup data is not supported for this sample -#endif - using namespace std; using namespace v8; diff --git a/samples/shell.cc b/samples/shell.cc index b66e8f7453..1a08afffdc 100644 --- a/samples/shell.cc +++ b/samples/shell.cc @@ -35,10 +35,6 @@ #include #include -#ifdef COMPRESS_STARTUP_DATA_BZ2 -#error Using compressed startup data is not supported for this sample -#endif - /** * This sample program shows how to implement a simple javascript shell * based on V8. This includes initializing V8 with command line options, diff --git a/src/api.cc b/src/api.cc index 8f0dcf6bdd..3a2e822e85 100644 --- a/src/api.cc +++ b/src/api.cc @@ -196,134 +196,6 @@ static inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) { } -StartupDataDecompressor::StartupDataDecompressor() - : raw_data(i::NewArray(V8::GetCompressedStartupDataCount())) { - for (int i = 0; i < V8::GetCompressedStartupDataCount(); ++i) { - raw_data[i] = NULL; - } -} - - -StartupDataDecompressor::~StartupDataDecompressor() { - for (int i = 0; i < V8::GetCompressedStartupDataCount(); ++i) { - i::DeleteArray(raw_data[i]); - } - i::DeleteArray(raw_data); -} - - -int StartupDataDecompressor::Decompress() { - int compressed_data_count = V8::GetCompressedStartupDataCount(); - StartupData* compressed_data = - i::NewArray(compressed_data_count); - V8::GetCompressedStartupData(compressed_data); - for (int i = 0; i < compressed_data_count; ++i) { - char* decompressed = raw_data[i] = - i::NewArray(compressed_data[i].raw_size); - if (compressed_data[i].compressed_size != 0) { - int result = DecompressData(decompressed, - &compressed_data[i].raw_size, - compressed_data[i].data, - compressed_data[i].compressed_size); - if (result != 0) return result; - } else { - DCHECK_EQ(0, compressed_data[i].raw_size); - } - compressed_data[i].data = decompressed; - } - V8::SetDecompressedStartupData(compressed_data); - i::DeleteArray(compressed_data); - return 0; -} - - -StartupData::CompressionAlgorithm V8::GetCompressedStartupDataAlgorithm() { -#ifdef COMPRESS_STARTUP_DATA_BZ2 - return StartupData::kBZip2; -#else - return StartupData::kUncompressed; -#endif -} - - -enum CompressedStartupDataItems { - kSnapshot = 0, - kSnapshotContext, - kLibraries, - kExperimentalLibraries, - kCompressedStartupDataCount -}; - - -int V8::GetCompressedStartupDataCount() { -#ifdef COMPRESS_STARTUP_DATA_BZ2 - return kCompressedStartupDataCount; -#else - return 0; -#endif -} - - -void V8::GetCompressedStartupData(StartupData* compressed_data) { -#ifdef COMPRESS_STARTUP_DATA_BZ2 - compressed_data[kSnapshot].data = - reinterpret_cast(i::Snapshot::data()); - compressed_data[kSnapshot].compressed_size = i::Snapshot::size(); - compressed_data[kSnapshot].raw_size = i::Snapshot::raw_size(); - - compressed_data[kSnapshotContext].data = - reinterpret_cast(i::Snapshot::context_data()); - compressed_data[kSnapshotContext].compressed_size = - i::Snapshot::context_size(); - compressed_data[kSnapshotContext].raw_size = i::Snapshot::context_raw_size(); - - i::Vector libraries_source = i::Natives::GetScriptsSource(); - compressed_data[kLibraries].data = - reinterpret_cast(libraries_source.start()); - compressed_data[kLibraries].compressed_size = libraries_source.length(); - compressed_data[kLibraries].raw_size = i::Natives::GetRawScriptsSize(); - - i::Vector exp_libraries_source = - i::ExperimentalNatives::GetScriptsSource(); - compressed_data[kExperimentalLibraries].data = - reinterpret_cast(exp_libraries_source.start()); - compressed_data[kExperimentalLibraries].compressed_size = - exp_libraries_source.length(); - compressed_data[kExperimentalLibraries].raw_size = - i::ExperimentalNatives::GetRawScriptsSize(); -#endif -} - - -void V8::SetDecompressedStartupData(StartupData* decompressed_data) { -#ifdef COMPRESS_STARTUP_DATA_BZ2 - DCHECK_EQ(i::Snapshot::raw_size(), decompressed_data[kSnapshot].raw_size); - i::Snapshot::set_raw_data( - reinterpret_cast(decompressed_data[kSnapshot].data)); - - DCHECK_EQ(i::Snapshot::context_raw_size(), - decompressed_data[kSnapshotContext].raw_size); - i::Snapshot::set_context_raw_data( - reinterpret_cast( - decompressed_data[kSnapshotContext].data)); - - DCHECK_EQ(i::Natives::GetRawScriptsSize(), - decompressed_data[kLibraries].raw_size); - i::Vector libraries_source( - decompressed_data[kLibraries].data, - decompressed_data[kLibraries].raw_size); - i::Natives::SetRawScriptsSource(libraries_source); - - DCHECK_EQ(i::ExperimentalNatives::GetRawScriptsSize(), - decompressed_data[kExperimentalLibraries].raw_size); - i::Vector exp_libraries_source( - decompressed_data[kExperimentalLibraries].data, - decompressed_data[kExperimentalLibraries].raw_size); - i::ExperimentalNatives::SetRawScriptsSource(exp_libraries_source); -#endif -} - - void V8::SetNativesDataBlob(StartupData* natives_blob) { #ifdef V8_USE_EXTERNAL_STARTUP_DATA i::SetNativesFromFile(natives_blob); diff --git a/src/d8.cc b/src/d8.cc index 1c3ff8c405..bf1a74bdf8 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -8,10 +8,6 @@ #define V8_SHARED #endif -#ifdef COMPRESS_STARTUP_DATA_BZ2 -#include -#endif - #include #include #include @@ -883,34 +879,6 @@ void Shell::InstallUtilityScript(Isolate* isolate) { #endif // !V8_SHARED -#ifdef COMPRESS_STARTUP_DATA_BZ2 -class BZip2Decompressor : public v8::StartupDataDecompressor { - public: - virtual ~BZip2Decompressor() { } - - protected: - virtual int DecompressData(char* raw_data, - int* raw_data_size, - const char* compressed_data, - int compressed_data_size) { - DCHECK_EQ(v8::StartupData::kBZip2, - v8::V8::GetCompressedStartupDataAlgorithm()); - unsigned int decompressed_size = *raw_data_size; - int result = - BZ2_bzBuffToBuffDecompress(raw_data, - &decompressed_size, - const_cast(compressed_data), - compressed_data_size, - 0, 1); - if (result == BZ_OK) { - *raw_data_size = decompressed_size; - } - return result; - } -}; -#endif - - Handle Shell::CreateGlobalTemplate(Isolate* isolate) { Handle global_template = ObjectTemplate::New(isolate); global_template->Set(String::NewFromUtf8(isolate, "print"), @@ -967,15 +935,6 @@ Handle Shell::CreateGlobalTemplate(Isolate* isolate) { void Shell::Initialize(Isolate* isolate) { -#ifdef COMPRESS_STARTUP_DATA_BZ2 - BZip2Decompressor startup_data_decompressor; - int bz2_result = startup_data_decompressor.Decompress(); - if (bz2_result != BZ_OK) { - fprintf(stderr, "bzip error code: %d\n", bz2_result); - Exit(1); - } -#endif - #ifndef V8_SHARED Shell::counter_map_ = new CounterMap(); // Set up counters diff --git a/src/d8.gyp b/src/d8.gyp index a084979de2..e53658493a 100644 --- a/src/d8.gyp +++ b/src/d8.gyp @@ -129,7 +129,6 @@ '../tools/js2c.py', '<@(_outputs)', 'D8', - 'off', # compress startup data '<@(js_files)' ], }, diff --git a/src/mksnapshot.cc b/src/mksnapshot.cc index 740c30cfa8..3264f3743f 100644 --- a/src/mksnapshot.cc +++ b/src/mksnapshot.cc @@ -3,11 +3,8 @@ // found in the LICENSE file. #include -#include -#ifdef COMPRESS_STARTUP_DATA_BZ2 -#include -#endif #include +#include #include "src/v8.h" @@ -249,62 +246,6 @@ class SnapshotWriter { }; -#ifdef COMPRESS_STARTUP_DATA_BZ2 -class BZip2Compressor : public Compressor { - public: - BZip2Compressor() : output_(NULL) {} - virtual ~BZip2Compressor() { - delete output_; - } - virtual bool Compress(i::Vector input) { - delete output_; - output_ = new i::ScopedVector((input.length() * 101) / 100 + 1000); - unsigned int output_length_ = output_->length(); - int result = BZ2_bzBuffToBuffCompress(output_->start(), &output_length_, - input.start(), input.length(), - 9, 1, 0); - if (result == BZ_OK) { - output_->Truncate(output_length_); - return true; - } else { - fprintf(stderr, "bzlib error code: %d\n", result); - return false; - } - } - virtual i::Vector* output() { return output_; } - - private: - i::ScopedVector* output_; -}; - - -class BZip2Decompressor : public StartupDataDecompressor { - public: - virtual ~BZip2Decompressor() { } - - protected: - virtual int DecompressData(char* raw_data, - int* raw_data_size, - const char* compressed_data, - int compressed_data_size) { - DCHECK_EQ(StartupData::kBZip2, - V8::GetCompressedStartupDataAlgorithm()); - unsigned int decompressed_size = *raw_data_size; - int result = - BZ2_bzBuffToBuffDecompress(raw_data, - &decompressed_size, - const_cast(compressed_data), - compressed_data_size, - 0, 1); - if (result == BZ_OK) { - *raw_data_size = decompressed_size; - } - return result; - } -}; -#endif - - void DumpException(Handle message) { String::Utf8Value message_string(message->Get()); String::Utf8Value message_line(message->GetSourceLine()); @@ -336,14 +277,6 @@ int main(int argc, char** argv) { v8::V8::InitializePlatform(platform); v8::V8::Initialize(); -#ifdef COMPRESS_STARTUP_DATA_BZ2 - BZip2Decompressor natives_decompressor; - int bz2_result = natives_decompressor.Decompress(); - if (bz2_result != BZ_OK) { - fprintf(stderr, "bzip error code: %d\n", bz2_result); - exit(1); - } -#endif i::FLAG_logfile_per_isolate = false; Isolate::CreateParams params; @@ -437,10 +370,6 @@ int main(int argc, char** argv) { writer.SetRawFiles(i::FLAG_raw_file, i::FLAG_raw_context_file); if (i::FLAG_startup_blob) writer.SetStartupBlobFile(i::FLAG_startup_blob); - #ifdef COMPRESS_STARTUP_DATA_BZ2 - BZip2Compressor bzip2; - writer.SetCompressor(&bzip2); - #endif writer.WriteSnapshot(snapshot_sink.data(), ser, context_sink.data(), context_ser); } diff --git a/src/snapshot.h b/src/snapshot.h index 590ecf1718..6d4bf95391 100644 --- a/src/snapshot.h +++ b/src/snapshot.h @@ -21,21 +21,6 @@ class Snapshot { // Create a new context using the internal partial snapshot. static Handle NewContextFromSnapshot(Isolate* isolate); - // These methods support COMPRESS_STARTUP_DATA_BZ2. - static const byte* data() { return data_; } - static int size() { return size_; } - static int raw_size() { return raw_size_; } - static void set_raw_data(const byte* raw_data) { - raw_data_ = raw_data; - } - static const byte* context_data() { return context_data_; } - static int context_size() { return context_size_; } - static int context_raw_size() { return context_raw_size_; } - static void set_context_raw_data( - const byte* context_raw_data) { - context_raw_data_ = context_raw_data; - } - private: static const byte data_[]; static const byte* raw_data_; diff --git a/test/cctest/cctest.gyp b/test/cctest/cctest.gyp index 3b821a3d17..bae0607f7f 100644 --- a/test/cctest/cctest.gyp +++ b/test/cctest/cctest.gyp @@ -301,7 +301,6 @@ '../../tools/js2c.py', '<@(_outputs)', 'TEST', # type - 'off', # compression '<@(file_list)', ], } diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp index 06751cc364..5658608397 100644 --- a/tools/gyp/v8.gyp +++ b/tools/gyp/v8.gyp @@ -1170,18 +1170,6 @@ '../../src/compiler/x64/linkage-x64.cc', ], }], - ['OS=="linux"', { - 'link_settings': { - 'conditions': [ - ['v8_compress_startup_data=="bz2"', { - 'libraries': [ - '-lbz2', - ] - }], - ], - }, - } - ], ['OS=="win"', { 'variables': { 'gyp_generators': '= 0 and value < (1 << 28)) if (value < 1 << 6): @@ -545,9 +526,9 @@ def WriteStartupBlob(sources, startup_blob): output.close() -def JS2C(source, target, native_type, compression_type, raw_file, startup_blob): +def JS2C(source, target, native_type, raw_file, startup_blob): sources = PrepareSources(source) - sources_bytes = CompressMaybe(sources, compression_type) + sources_bytes = "".join(sources.modules) metadata = BuildMetadata(sources, sources_bytes, native_type) # Optionally emit raw file. @@ -571,14 +552,13 @@ def main(): help="file to write the processed sources array to.") parser.add_option("--startup_blob", action="store", help="file to write the startup blob to.") - parser.set_usage("""js2c out.cc type compression sources.js ... + parser.set_usage("""js2c out.cc type sources.js ... out.cc: C code to be generated. type: type parameter for NativesCollection template. - compression: type of compression used. [off|bz2] sources.js: JS internal sources or macros.py.""") (options, args) = parser.parse_args() - JS2C(args[3:], args[0], args[1], args[2], options.raw, options.startup_blob) + JS2C(args[2:], args[0], args[1], options.raw, options.startup_blob) if __name__ == "__main__":