From 9dae7293dbd05dfc806be6bf429e969c26e6242c Mon Sep 17 00:00:00 2001 From: Heng Li Date: Thu, 21 Jul 2016 21:41:53 -0400 Subject: [PATCH] Release 0.2.3-r67 * Set default --max_old_space_size to 16384 * Allow to change --max_old_space_size also with option -M, which is shorter * Updated instructions on compiling k8, as gyp svn is offline now --- README.md | 19 ++++++++++--------- k8.cc | 23 ++++++++++++++++------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 7d359c4..6e7b78b 100644 --- a/README.md +++ b/README.md @@ -32,16 +32,15 @@ for a hash map without hitting the memory limit of V8. You need to first compile V8 and then compile and link K8. Here is the full procedure: - git clone https://github.com/v8/v8 # download V8 - (cd v8; git checkout 3.16.4) # k8 only works with 3.16.x - (cd v8; make dependencies; make x64.release) # compile V8 - g++ -O2 -Wall -o k8 -Iv8/include k8.cc -lpthread -lz v8/out/*/libv8_{base,snapshot}.a + # download compilable V8 source code; K8 only works with v8-3.16 + wget -O- https://github.com/attractivechaos/k8/releases/download/v0.2.1/v8-3.16.4.tar.bz2 | tar jxf - + # compile V8 + cd v8-3.16.4 && make -j4 x64.release + # compile K8 + g++ -O2 -Wall -o k8 -Iinclude ../k8.cc -lpthread -lz `find out -name "libv8_*.a"|grep -v nosnap` -The two `libv8*.a` files should always be placed somewhere in `v8/out`, but -maybe in a deeper directory, depending on the OS. - -Alternatively, you may download the compiled binaries for Mac and Linux from -[SourceForge][11]. The source code is also included. +Alternatively, you may download the precompiled binaries for Mac and Linux from +the [release page][release]. #### 4. An earlier version of K8 implemented a generic buffered stream. Why has it been removed? @@ -191,3 +190,5 @@ when we want to stage a huge hash table in memory. `Map` has the following metho [8]: http://nodejs.org/api/stream.html [9]: http://www.commonjs.org/specs/ [11]: https://sourceforge.net/projects/lh3/files/ +[gyp]: https://gyp.gsrc.io/ +[release]: https://github.com/attractivechaos/k8/releases diff --git a/k8.cc b/k8.cc index 07398ab..a1a9323 100644 --- a/k8.cc +++ b/k8.cc @@ -1,4 +1,4 @@ -#define K8_VERSION "0.2.2-r65" // known to work with V8-3.16.14 +#define K8_VERSION "0.2.3-r67" // known to work with V8-3.16.14 #include #include @@ -596,9 +596,9 @@ JS_METHOD(k8_file_readline, args) // see iStream::readline(sep=line) for details return ret >= 0? scope.Close(v8::Integer::New(dret)) : scope.Close(v8::Integer::New(ret)); } -/********************** +/****************** *** Set object *** - **********************/ + ******************/ #include "khash.h" KHASH_MAP_INIT_STR(str, kh_cstr_t) @@ -792,9 +792,19 @@ static v8::Persistent CreateShellContext() // adapted from shell.cc int main(int argc, char* argv[]) { v8::V8::SetFlagsFromCommandLine(&argc, argv, true); + + // set --max_old_space_size. We have to do it before CreateShellContext(), I guess. + int c; + char flag_buf[256], *size = 0; + while ((c = getopt(argc, argv, "ve:E:M:")) >= 0) + if (c == 'M') size = optarg; + strcat(strcpy(flag_buf, "--max_old_space_size="), size? size : "16384"); + v8::V8::SetFlagsFromString(flag_buf, strlen(flag_buf)); + opterr = optind = 1; + int ret = 0; if (argc == 1) { - fprintf(stderr, "Usage: k8 [-v] [-e jsSrc] [-E jsSrc] [arguments]\n"); + fprintf(stderr, "Usage: k8 [-v] [-e jsSrc] [-E jsSrc] [-M maxRSS] [arguments]\n"); return 1; } { @@ -805,8 +815,7 @@ int main(int argc, char* argv[]) return 1; } context->Enter(); - int i, c; - while ((c = getopt(argc, argv, "ve:E:")) >= 0) // parse k8 related command line options + while ((c = getopt(argc, argv, "ve:E:M:")) >= 0) // parse k8 related command line options if (c == 'e' || c == 'E') { if (!k8_execute(JS_STR(optarg), JS_STR("CLI"), (c == 'E'))) { // note the difference between 'e' and 'E' ret = 1; @@ -816,7 +825,7 @@ int main(int argc, char* argv[]) if (!ret && optind != argc) { v8::HandleScope scope2; v8::Local args = v8::Array::New(argc - optind - 1); - for (i = optind + 1; i < argc; ++i) + for (int i = optind + 1; i < argc; ++i) args->Set(v8::Integer::New(i - optind - 1), JS_STR(argv[i])); context->Global()->Set(JS_STR("arguments"), args); if (!k8_execute(k8_readfile(argv[optind]), JS_STR(argv[optind]), false)) ret = 1;