Reviewers: Søren Gjesse,
Description:
Add snapshot compression support into d8.
I'm not bothering with compressing d8.js, since it makes no sense,
but it is also possible.
[email protected]
Please review this at http://codereview.chromium.org/7046027/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M SConstruct
M src/d8.h
M src/d8.cc
Index: SConstruct
diff --git a/SConstruct b/SConstruct
index
4a7e182573060c1af4c7360ba3067092f00b8983..117510624804dcf4a8be18bdbdc313fd0e08a598
100644
--- a/SConstruct
+++ b/SConstruct
@@ -807,6 +807,12 @@ D8_FLAGS = {
'arch:arm': {
'LINKFLAGS': ARM_LINK_FLAGS
},
+ 'compress_startup_data:bz2': {
+ 'CPPDEFINES': ['COMPRESS_STARTUP_DATA_BZ2'],
+ 'os:linux': {
+ 'LIBS': ['bz2']
+ }
+ }
},
'msvc': {
'all': {
Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index
1d798b14bfa3ef3e059f117c1f44b916fdc821df..f4c7846f5273e6dc5106e047febf4814ad6693ae
100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -26,8 +26,11 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include <stdlib.h>
+#ifdef COMPRESS_STARTUP_DATA_BZ2
+#include <bzlib.h>
+#endif
#include <errno.h>
+#include <stdlib.h>
#include "v8.h"
@@ -483,7 +486,44 @@ void Shell::AddHistogramSample(void* histogram, int
sample) {
}
+#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) {
+ ASSERT_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
+
+
void Shell::Initialize() {
+#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
+
Shell::counter_map_ = new CounterMap();
// Set up counters
if (i::StrLength(i::FLAG_map_counters) != 0)
Index: src/d8.h
diff --git a/src/d8.h b/src/d8.h
index
fb5ab800daa2abb241f51eeccfd45445c6369344..540c9cac509c2349e45a35c8c7155dd61249ee15
100644
--- a/src/d8.h
+++ b/src/d8.h
@@ -32,10 +32,6 @@
#include "v8.h"
#include "hashmap.h"
-#ifdef COMPRESS_STARTUP_DATA_BZ2
-#error Using compressed startup data is not supported for D8
-#endif
-
namespace v8 {
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev