Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade libv8 to latest stable version #85

Closed
seanmakesgames opened this issue May 3, 2018 · 12 comments · Fixed by rubyjs/libv8#258
Closed

Upgrade libv8 to latest stable version #85

seanmakesgames opened this issue May 3, 2018 · 12 comments · Fixed by rubyjs/libv8#258

Comments

@seanmakesgames
Copy link
Contributor

6.3 is released in libv8 -- is there a reason we haven't moved to it in mini_racer yet? (I don't remember)
@SamSaffron @ignisf

@SamSaffron
Copy link
Collaborator

I thought I already did...

@SamSaffron
Copy link
Collaborator

btw ... we got to get us up to 6.6 @ignisf if you have some time to do a new libv8

@seanmakesgames
Copy link
Contributor Author

Oh! look at that. Sorry.
Can close, or we can leave it open for moving to 6.6. Up to you!

@ignisf
Copy link
Contributor

ignisf commented May 4, 2018

will look into this :)

@ignisf
Copy link
Contributor

ignisf commented May 5, 2018

GYP has been retired since V8 6.5. Please use GN instead.

@SamSaffron SamSaffron changed the title bump mini_racer's libv8 version Upgrade libv8 to latest stable version May 13, 2018
@SamSaffron
Copy link
Collaborator

anything we can do to help move libv8 to 66 ?

@ignisf
Copy link
Contributor

ignisf commented May 14, 2018

Well, considering the complexity in the libv8 gem was mainly focused around wrestling with GYP, this release will certainly require more work than the previous ones. Have to research how to use gn to build v8 first as it even fails with the default options here...

@seanmakesgames
Copy link
Contributor Author

Yuck. That sucks. Wish I had time to dive in and go on a compiler adventure!

@ignisf
Copy link
Contributor

ignisf commented Jun 21, 2018

Hi,

I was able to get v8 to build with GN. Will be working on incorporating the changes that will automate the process in libv8.

Here are the changes needed to get mini_racer to compile against v8 6.7. The test_isolate_can_be_notified_of_idle_time fails though and I've not gotten around to debugging it.

diff --git a/ext/mini_racer_extension/mini_racer_extension.cc b/ext/mini_racer_extension/mini_racer_extension.cc
index 168785d..4dfdf97 100644
--- a/ext/mini_racer_extension/mini_racer_extension.cc
+++ b/ext/mini_racer_extension/mini_racer_extension.cc
@@ -202,7 +202,7 @@ static void gc_callback(Isolate *isolate, GCType type, GCCallbackFlags flags) {
 
     if(used > softlimit) {
         isolate->SetData(MEM_SOFTLIMIT_REACHED, (void*)true);
-        V8::TerminateExecution(isolate);
+        isolate->TerminateExecution();
     }
 }
 
@@ -626,11 +626,11 @@ static VALUE rb_isolate_init_with_snapshot(VALUE self, VALUE snapshot) {
     return Qnil;
 }
 
-static VALUE rb_isolate_idle_notification(VALUE self, VALUE idle_time_in_ms) {
+static VALUE rb_isolate_idle_notification_deadline(VALUE self, VALUE idle_time_in_s) {
     IsolateInfo* isolate_info;
     Data_Get_Struct(self, IsolateInfo, isolate_info);
 
-    return isolate_info->isolate->IdleNotification(NUM2INT(idle_time_in_ms)) ? Qtrue : Qfalse;
+    return isolate_info->isolate->IdleNotificationDeadline(NUM2DBL(idle_time_in_s)) ? Qtrue : Qfalse;
 }
 
 static VALUE rb_context_init_unsafe(VALUE self, VALUE isolate, VALUE snap) {
@@ -901,7 +901,7 @@ gvl_ruby_callback(void* data) {
 
     if ((bool)args->GetIsolate()->GetData(DO_TERMINATE) == true) {
        args->GetIsolate()->ThrowException(String::NewFromUtf8(args->GetIsolate(), "Terminated execution during transition from Ruby to JS"));
-       V8::TerminateExecution(args->GetIsolate());
+       args->GetIsolate()->TerminateExecution();
        return NULL;
     }
 
@@ -924,7 +924,7 @@ gvl_ruby_callback(void* data) {
 
     if ((bool)args->GetIsolate()->GetData(DO_TERMINATE) == true) {
       Isolate* isolate = args->GetIsolate();
-      V8::TerminateExecution(isolate);
+      isolate->TerminateExecution();
     }
 
     return NULL;
@@ -1180,7 +1180,7 @@ rb_context_stop(VALUE self) {
     // flag for termination
     isolate->SetData(DO_TERMINATE, (void*)true);
 
-    V8::TerminateExecution(isolate);
+    isolate->TerminateExecution();
     rb_funcall(self, rb_intern("stop_attached"), 0);
 
     return Qnil;
@@ -1361,7 +1361,7 @@ extern "C" {
        rb_define_method(rb_cSnapshot, "warmup!", (VALUE(*)(...))&rb_snapshot_warmup, 1);
        rb_define_private_method(rb_cSnapshot, "load", (VALUE(*)(...))&rb_snapshot_load, 1);
 
-       rb_define_method(rb_cIsolate, "idle_notification", (VALUE(*)(...))&rb_isolate_idle_notification, 1);
+       rb_define_method(rb_cIsolate, "idle_notification_deadline", (VALUE(*)(...))&rb_isolate_idle_notification_deadline, 1);
        rb_define_private_method(rb_cIsolate, "init_with_snapshot",(VALUE(*)(...))&rb_isolate_init_with_snapshot, 1);
 
        rb_define_singleton_method(rb_cPlatform, "set_flag_as_str!", (VALUE(*)(...))&rb_platform_set_flag_as_str, 1);
diff --git a/test/mini_racer_test.rb b/test/mini_racer_test.rb
index 517303d..a40470a 100644
--- a/test/mini_racer_test.rb
+++ b/test/mini_racer_test.rb
@@ -502,7 +502,7 @@ raise FooError, "I like foos"
   def test_isolate_can_be_notified_of_idle_time
     isolate = MiniRacer::Isolate.new
 
-    assert(isolate.idle_notification(1000))
+    assert(isolate.idle_notification_deadline(1))
   end
 
   def test_concurrent_access_over_the_same_isolate_1

@ignisf
Copy link
Contributor

ignisf commented Jun 21, 2018

Relevant review for the IdleNotification --> IdleNotificationDeadline change: https://chromium-review.googlesource.com/c/v8/v8/+/848782

@ignisf
Copy link
Contributor

ignisf commented Jun 21, 2018

[ignisf@clarity mini_racer]$ gem install ~/Projects/libv8/pkg/libv8-6.7.288.46.1beta0-x86_64-linux.gem
Successfully installed libv8-6.7.288.46.1beta0-x86_64-linux
Parsing documentation for libv8-6.7.288.46.1beta0-x86_64-linux
Done installing documentation for libv8 after 0 seconds
1 gem installed
[ignisf@clarity mini_racer]$ bundle exec rake
mkdir -p tmp/x86_64-linux/mini_racer_extension/2.5.1
cd tmp/x86_64-linux/mini_racer_extension/2.5.1
/home/ignisf/.rbenv/versions/2.5.1/bin/ruby -I. ../../../../ext/mini_racer_extension/extconf.rb
checking for -lpthread... yes
creating Makefile
cd -
cd tmp/x86_64-linux/mini_racer_extension/2.5.1
/usr/bin/make
compiling ../../../../ext/mini_racer_extension/mini_racer_extension.cc
cc1plus: warning: command line option ‘-Wimplicit-int’ is valid for C/ObjC but not for C++
cc1plus: warning: unrecognized command line option ‘-Wno-self-assign’
cc1plus: warning: unrecognized command line option ‘-Wno-constant-logical-operand’
cc1plus: warning: unrecognized command line option ‘-Wno-parentheses-equality’
linking shared-object mini_racer_extension.so
cd -
mkdir -p tmp/x86_64-linux/stage/lib
cp .gitignore tmp/x86_64-linux/stage/.gitignore
cp .travis.yml tmp/x86_64-linux/stage/.travis.yml
cp CHANGELOG tmp/x86_64-linux/stage/CHANGELOG
cp CODE_OF_CONDUCT.md tmp/x86_64-linux/stage/CODE_OF_CONDUCT.md
cp Gemfile tmp/x86_64-linux/stage/Gemfile
cp LICENSE.txt tmp/x86_64-linux/stage/LICENSE.txt
cp README.md tmp/x86_64-linux/stage/README.md
cp Rakefile tmp/x86_64-linux/stage/Rakefile
mkdir -p tmp/x86_64-linux/stage/bin
cp bin/console tmp/x86_64-linux/stage/bin/console
cp bin/setup tmp/x86_64-linux/stage/bin/setup
mkdir -p tmp/x86_64-linux/stage/ext/mini_racer_extension
cp ext/mini_racer_extension/extconf.rb tmp/x86_64-linux/stage/ext/mini_racer_extension/extconf.rb
cp ext/mini_racer_extension/mini_racer_extension.cc tmp/x86_64-linux/stage/ext/mini_racer_extension/mini_racer_extension.cc
cp lib/mini_racer.rb tmp/x86_64-linux/stage/lib/mini_racer.rb
mkdir -p tmp/x86_64-linux/stage/lib/mini_racer
cp lib/mini_racer/version.rb tmp/x86_64-linux/stage/lib/mini_racer/version.rb
cp mini_racer.gemspec tmp/x86_64-linux/stage/mini_racer.gemspec
install -c tmp/x86_64-linux/mini_racer_extension/2.5.1/mini_racer_extension.so lib/mini_racer_extension.so
cp tmp/x86_64-linux/mini_racer_extension/2.5.1/mini_racer_extension.so tmp/x86_64-linux/stage/lib/mini_racer_extension.so
Run options: --seed 17706

# Running:

....S.S...................................................F<unknown>:65: Uncaught TypeError: Cannot create property 'kevin' on number '2'
............

Fabulous run in 2.099619s, 33.8157 runs/s, 59.5346 assertions/s.

  1) Failure:
MiniRacerTest#test_isolate_can_be_notified_of_idle_time [/home/ignisf/Projects/mini_racer/test/mini_racer_test.rb:505]:
Expected false to be truthy.

71 runs, 125 assertions, 1 failures, 0 errors, 2 skips

You have skipped tests. Run with --verbose for details.
rake aborted!
Command failed with status (1): [ruby -I"lib:test:lib" -I"/home/ignisf/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-10.5.0/lib" "/home/ignisf/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-10.5.0/lib/rake/rake_test_loader.rb" "test/function_test.rb" "test/mini_racer_test.rb" ]
/home/ignisf/.rbenv/versions/2.5.1/bin/bundle:23:in `load'
/home/ignisf/.rbenv/versions/2.5.1/bin/bundle:23:in `<main>'
Tasks: TOP => default => test
(See full trace by running task with --trace)

[ignisf@clarity mini_racer]$ cd benchmark/babel/
[ignisf@clarity babel]$ bundle exec ruby bench.rb 
235.683456 load babel
mini racer 387.887614 transform
mini racer 209.37293300000002 transform
mini racer 193.90270700000002 transform
mini racer 157.03652000000002 transform
mini racer 169.673066 transform
mini racer 171.204993 transform
mini racer 149.80127 transform
mini racer 148.15504700000002 transform
mini racer 154.745834 transform
mini racer 138.345673 transform
mini racer 10x 1342.0522589999998 transform
mini racer 10x 1252.371447 transform
mini racer 10x 1007.71356 transform
mini racer 10x 956.56268 transform
mini racer 10x 950.773764 transform
mini racer 10x 926.577576 transform
mini racer 10x 926.18368 transform
mini racer 10x 909.327421 transform
mini racer 10x 949.6127690000001 transform
mini racer 10x 896.4094630000001 transform

[ignisf@clarity babel]$ bundle exec ruby bench.rb 
202.297411 load babel
mini racer 395.46331499999997 transform
mini racer 224.962691 transform
mini racer 203.037021 transform
mini racer 148.13652 transform
mini racer 175.858253 transform
mini racer 170.56891299999998 transform
mini racer 177.556209 transform
mini racer 165.506833 transform
mini racer 154.337413 transform
mini racer 152.433017 transform
mini racer 10x 1387.875483 transform
mini racer 10x 1262.661027 transform
mini racer 10x 967.235612 transform
mini racer 10x 961.99289 transform
mini racer 10x 945.040509 transform
mini racer 10x 945.703711 transform
mini racer 10x 923.7888800000001 transform
mini racer 10x 928.004817 transform
mini racer 10x 927.375828 transform
mini racer 10x 955.139841 transform

[ignisf@clarity babel]$ node bench_node.js 
Running V8 version 6.7.288.46-node.8
197 requiring babel
344 transpile
241 transpile
149 transpile
156 transpile
149 transpile
144 transpile
153 transpile
160 transpile
154 transpile
144 transpile
1308 transpile 10 times
1197 transpile 10 times
952 transpile 10 times
954 transpile 10 times
924 transpile 10 times
911 transpile 10 times
911 transpile 10 times
895 transpile 10 times
940 transpile 10 times
893 transpile 10 times

[ignisf@clarity babel]$ cd ../exec_js_uglify/

[ignisf@clarity exec_js_uglify]$ bundle exec ruby bench.rb mini_racer
Benching with mini_racer
mini_racer minify discourse_app.js 10696.161669000001ms
mini_racer minify discourse_app_minified.js 11931.020508ms
mini_racer minify discourse_app.js twice (2 threads) 14101.343083ms
[ignisf@clarity exec_js_uglify]$ bundle exec ruby bench.rb mini_racer
Benching with mini_racer
mini_racer minify discourse_app.js 10716.44347ms
mini_racer minify discourse_app_minified.js 11682.504576ms
mini_racer minify discourse_app.js twice (2 threads) 14209.070757ms
[ignisf@clarity exec_js_uglify]$ 

@SamSaffron
Copy link
Collaborator

wow this is awesome... once you have a libv8 version out I am perfectly happy changing mini_racer so it has a hard dependency on latest libv8 and we are not stuck with ugly #if blocks

Let me know as soon as you have a gem out cause I want to see if this resolves #90 which really worries me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants