# 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
"V8_I18N_SUPPORT",
]
}
- if (v8_compress_startup_data == "bz2") {
- defines += [
- "COMPRESS_STARTUP_DATA_BZ2",
- ]
- }
if (v8_enable_extra_checks == true) {
defines += [
"ENABLE_EXTRA_CHECKS",
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) {
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) {
# 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" ]
":v8_nosnapshot",
"//build/config/sanitizers:deps",
]
-
- if (v8_compress_startup_data == "bz2") {
- libs = [ "bz2" ]
- }
}
}
{
'variables': {
- 'v8_compress_startup_data%': 'off',
-
'v8_enable_disassembler%': 0,
'v8_enable_gdbjit%': 0,
['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',],
}],
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.
*/
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.
*
#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;
#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,
}
-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);
#define V8_SHARED
#endif
-#ifdef COMPRESS_STARTUP_DATA_BZ2
-#include <bzlib.h>
-#endif
-
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#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"),
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
'../tools/js2c.py',
'<@(_outputs)',
'D8',
- 'off', # compress startup data
'<@(js_files)'
],
},
// 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"
};
-#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());
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;
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);
}
// 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_;
'../../tools/js2c.py',
'<@(_outputs)',
'TEST', # type
- 'off', # compression
'<@(file_list)',
],
}
'../../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)',
'../../tools/js2c.py',
'<(SHARED_INTERMEDIATE_DIR)/libraries.cc',
'CORE',
- '<(v8_compress_startup_data)',
'<@(library_files)',
'<@(i18n_library_files)',
],
'../../tools/js2c.py',
'<(SHARED_INTERMEDIATE_DIR)/experimental-libraries.cc',
'EXPERIMENTAL',
- '<(v8_compress_startup_data)',
'<@(experimental_library_files)'
],
'conditions': [
}, {
'toolsets': ['target'],
}],
- ['v8_compress_startup_data=="bz2"', {
- 'libraries': [
- '-lbz2',
- ]
- }],
],
},
],
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):
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.
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__":