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}
This commit is contained in:
yangguo 2014-11-21 04:45:10 -08:00 committed by Commit bot
parent 5414c39974
commit 9b8d40594a
13 changed files with 6 additions and 386 deletions

View File

@ -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" ]
}
}
}

View File

@ -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',],
}],

View File

@ -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.

View File

@ -32,10 +32,6 @@
#include <map>
#include <string>
#ifdef COMPRESS_STARTUP_DATA_BZ2
#error Using compressed startup data is not supported for this sample
#endif
using namespace std;
using namespace v8;

View File

@ -35,10 +35,6 @@
#include <stdlib.h>
#include <string.h>
#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,

View File

@ -196,134 +196,6 @@ static inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) {
}
StartupDataDecompressor::StartupDataDecompressor()
: raw_data(i::NewArray<char*>(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<StartupData>(compressed_data_count);
V8::GetCompressedStartupData(compressed_data);
for (int i = 0; i < compressed_data_count; ++i) {
char* decompressed = raw_data[i] =
i::NewArray<char>(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<const char*>(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<const char*>(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<const i::byte> libraries_source = i::Natives::GetScriptsSource();
compressed_data[kLibraries].data =
reinterpret_cast<const char*>(libraries_source.start());
compressed_data[kLibraries].compressed_size = libraries_source.length();
compressed_data[kLibraries].raw_size = i::Natives::GetRawScriptsSize();
i::Vector<const i::byte> exp_libraries_source =
i::ExperimentalNatives::GetScriptsSource();
compressed_data[kExperimentalLibraries].data =
reinterpret_cast<const char*>(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<const i::byte*>(decompressed_data[kSnapshot].data));
DCHECK_EQ(i::Snapshot::context_raw_size(),
decompressed_data[kSnapshotContext].raw_size);
i::Snapshot::set_context_raw_data(
reinterpret_cast<const i::byte*>(
decompressed_data[kSnapshotContext].data));
DCHECK_EQ(i::Natives::GetRawScriptsSize(),
decompressed_data[kLibraries].raw_size);
i::Vector<const char> 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<const char> 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);

View File

@ -8,10 +8,6 @@
#define V8_SHARED
#endif
#ifdef COMPRESS_STARTUP_DATA_BZ2
#include <bzlib.h>
#endif
#include <errno.h>
#include <stdlib.h>
#include <string.h>
@ -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<char*>(compressed_data),
compressed_data_size,
0, 1);
if (result == BZ_OK) {
*raw_data_size = decompressed_size;
}
return result;
}
};
#endif
Handle<ObjectTemplate> Shell::CreateGlobalTemplate(Isolate* isolate) {
Handle<ObjectTemplate> global_template = ObjectTemplate::New(isolate);
global_template->Set(String::NewFromUtf8(isolate, "print"),
@ -967,15 +935,6 @@ Handle<ObjectTemplate> 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

View File

@ -129,7 +129,6 @@
'../tools/js2c.py',
'<@(_outputs)',
'D8',
'off', # compress startup data
'<@(js_files)'
],
},

View File

@ -3,11 +3,8 @@
// found in the LICENSE file.
#include <errno.h>
#include <stdio.h>
#ifdef COMPRESS_STARTUP_DATA_BZ2
#include <bzlib.h>
#endif
#include <signal.h>
#include <stdio.h>
#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<char> input) {
delete output_;
output_ = new i::ScopedVector<char>((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<char>* output() { return output_; }
private:
i::ScopedVector<char>* 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<char*>(compressed_data),
compressed_data_size,
0, 1);
if (result == BZ_OK) {
*raw_data_size = decompressed_size;
}
return result;
}
};
#endif
void DumpException(Handle<Message> 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);
}

View File

@ -21,21 +21,6 @@ class Snapshot {
// Create a new context using the internal partial snapshot.
static Handle<Context> 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_;

View File

@ -301,7 +301,6 @@
'../../tools/js2c.py',
'<@(_outputs)',
'TEST', # type
'off', # compression
'<@(file_list)',
],
}

View File

@ -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': '<!(echo $GYP_GENERATORS)',
@ -1653,7 +1641,6 @@
'../../tools/js2c.py',
'<(SHARED_INTERMEDIATE_DIR)/libraries.cc',
'CORE',
'<(v8_compress_startup_data)',
'<@(library_files)',
'<@(i18n_library_files)',
],
@ -1680,7 +1667,6 @@
'../../tools/js2c.py',
'<(SHARED_INTERMEDIATE_DIR)/experimental-libraries.cc',
'EXPERIMENTAL',
'<(v8_compress_startup_data)',
'<@(experimental_library_files)'
],
'conditions': [
@ -1744,11 +1730,6 @@
}, {
'toolsets': ['target'],
}],
['v8_compress_startup_data=="bz2"', {
'libraries': [
'-lbz2',
]
}],
],
},
],

View File

@ -478,25 +478,6 @@ def BuildMetadata(sources, source_bytes, native_type):
return metadata
def CompressMaybe(sources, compression_type):
"""Take the prepared sources and generate a sequence of bytes.
Args:
sources: A Sources instance with the prepared sourced.
compression_type: string, describing the desired compression.
Returns:
A sequence of bytes.
"""
sources_bytes = "".join(sources.modules)
if compression_type == "off":
return sources_bytes
elif compression_type == "bz2":
return bz2.compress(sources_bytes)
else:
raise Error("Unknown compression type %s." % compression_type)
def PutInt(blob_file, value):
assert(value >= 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__":