Skip to content

Commit

Permalink
Release 0.2.3-r67
Browse files Browse the repository at this point in the history
 * 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
  • Loading branch information
lh3 committed Jul 22, 2016
1 parent 6d8797c commit 9dae729
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down Expand Up @@ -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
23 changes: 16 additions & 7 deletions k8.cc
Original file line number Diff line number Diff line change
@@ -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 <stdlib.h>
#include <stdint.h>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -792,9 +792,19 @@ static v8::Persistent<v8::Context> 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] <src.js> [arguments]\n");
fprintf(stderr, "Usage: k8 [-v] [-e jsSrc] [-E jsSrc] [-M maxRSS] <src.js> [arguments]\n");
return 1;
}
{
Expand All @@ -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;
Expand All @@ -816,7 +825,7 @@ int main(int argc, char* argv[])
if (!ret && optind != argc) {
v8::HandleScope scope2;
v8::Local<v8::Array> 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;
Expand Down

0 comments on commit 9dae729

Please sign in to comment.