Git Product home page Git Product logo

j2v8's Introduction

J2V8

Build Status Maven Central

J2V8 is a set of Java bindings for V8. J2V8 focuses on performance and tight integration with V8. It also takes a 'primitive first' approach, meaning that if a value can be accessed as a primitive, then it should be. This forces a more static type system between the JS and Java code, but it also improves the performance since intermediate Objects are not created.

We developed J2V8 as a high performance engine for our multi-platform mobile toolkit tabris.js and it is a great choice for executing JavaScript on Android devices.

Building J2V8

Building J2V8 requires building both the native parts and the Java library (.jar/.aar file). To build the native parts we first build V8 as a monolithic library and then statically link J2V8 to that. The Java parts are built with maven/gradle.

J2V8 uses a cross-platform, cross-compiling build-system written in Python.

For any further build instructions & details please read BUILDING.md

Tutorials

Articles

Presentations

Other Resources

Here is a list of articles I've written on J2V8 http://eclipsesource.com/blogs/tag/j2v8/.

Who is using J2V8?

Here are some projects that use J2V8:

License

The code is published under the terms of the Eclipse Public License, version 1.0.

j2v8's People

Contributors

95ulisse avatar ahmadov avatar angelozerr avatar caer avatar drywolf avatar fwaibel avatar geowarin avatar gorkem avatar grahamborland avatar irbull avatar jessholle avatar jknack avatar matiwinnetou avatar muthu90ec avatar mvladev avatar piotrtomiak avatar rracariu avatar tarioch avatar tnytown avatar tonyrice avatar tverbeke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

j2v8's Issues

Provide a twin operation for V8Value

V8Values should be twin-able. This means we should be able to create a second V8Value that points to same underlying JavaScript object but through a different handle. In particular .equals, hashcode, sameValue, and strictEquals should all return true, but == may not return true in Java.

Changes to one twin can be seen in the other.

This is needed so one twin can be released, but the other can live on.

Call to V8.release(boolean) does not shut down the engine

When calling V8.release(boolean) i would expect to shut down the engine completely. Instead the entire internal state is preserved and the engine can be used as before.

A dedicated "dispose" method that frees operating system resources should be available.

[3.0] Suppport locker for multi thread.

Instead of checking that all interactions come from the same thread J2V8 should create a locker, and
then we'll check that all interactions come from the thread with the locker.

The locker can be acquired and released. With this approach you can release the locker after you create the JavaScript variable, and then acquire it in the new thread before you use it.

Crashes (will isolate further)

# Fatal error in ../src/runtime.cc, line 807
#
# A fatal error has been detected by the Java Runtime Environment:
#
# CHECK(V8::ArrayBufferAllocator() != NULL) failed
#

==== C stack trace ===============================

 1: ??
 2: ??
 3: ??
 4: ??
#  SIGILL (0x4) at pc=0x000000012bcb59a5, pid=65015, tid=4867
#
# JRE version: Java(TM) SE Runtime Environment (7.0_51-b13) (build 1.7.0_51-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.51-b03 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# C  [libj2v8_macosx_x86_64.dylib+0x3819a5]  v8::internal::OS::Abort()+0x15
#

Add support for getting arrays of values

In order to fully fetch an array, we need to fetch each element. We have some evidence that getting multiple primitives at once (through an array) is faster. We should add methods like

getDoubles[]
getInts[]
getBooleans[]
getStrings[]

Consider making V8Array extend V8Object

In JS and in V8, the Array extends Objects (Arrays 'are' Objects). We currently don't do this in J2V8, but it may make sense. However, we keep a registry of Arrays and Objects in C++. This registry will need to be merged if we create this hierarchy.

Create a README.md file

We need a readme file that describes
[] the purpose of the project
[] how to build the project
[] how to use the project

Docker build android jar?

I see the docker build builds the v8 stuff, but could we do similar to build the actual jar? Right now it's not clear how I can just get a jar with the current status of the repo.

Remove calls to Isolate::GetCurrent

When we first started, Isolate::GetCurrent was good enough. But this fails if you have multiple isolates. We need to lookup the correct isolate from our RuntimeMap.

Support 64 bit Windows

When I run in Windows 7. I am getting the following error. While debugging around this, found the following error.
"Can't load IA 32-bit .dll on a AMD 64-bit platform"

vm_info: Java HotSpot(TM) 64-Bit Server VM (24.75-b04) for windows-amd64 JRE (1.7.0_75-b13), built on Dec 18 2014 17:15:01 by "java_re" with unknown MS VC++:1600

Exception in thread "main" java.lang.IllegalStateException: J2V8 native library not loaded.
    at com.eclipsesource.v8.V8.checkNativeLibraryLoaded(V8.java:86)
    at com.eclipsesource.v8.V8.createV8Runtime(V8.java:74)
    at com.eclipsesource.v8.V8.createV8Runtime(V8.java:63)
    at Main.start(Main.java:10)
    at Main.main(Main.java:16)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.UnsatisfiedLinkError: Could not load J2V8 library. Reasons: 
    no j2v8_win32_amd64 in java.library.path

    at com.eclipsesource.v8.LibraryLoader.loadLibrary(LibraryLoader.java:71)
    at com.eclipsesource.v8.V8.load(V8.java:49)
    at com.eclipsesource.v8.V8.createV8Runtime(V8.java:72)
    ... 8 more

Process finished with exit code 1

I am not sure this library is tested on all the platform.

Thanks,
Mani

JSON support

I create this issue because I would like to implement tern server with J2V8.

The tern server works with JSON for request/response. In tern.java the JSON object is created by using https://github.com/ralfstx/minimal-json.

How to do that :

  • transform com.eclipsesource.json.JsonObject to a com.eclipsesource.v8.V8 instance?
  • or call JsonObject .toString() and call V8 engine with this string?

Perhaps I need to create a V8 <-> JsonObject binding?

Sorry for my naive question, I don't know how to V8 works.

Add equals methods to V8Object

The V8 Object (C++ side) has three equality methods. It has a strictEquals(===), same(==) and equals (not sure?). We should determine what we want to expose in J2V8 and how to best do this. If we override .equals, we will need to add a hashcode method too.

Multithread support

I know that javascript isn't support multiple threads, and what I need is creating multiple V8 engine instances on different threads and access this engine instances parallel.

At this time, i can create multiple V8 engine instances, all the instances can be accessed from one single thread, because the V8 class stores the thread which created the first instance in a static field called thread, and later every method call the checkThread() method.

I want to use V8 in a server environment where every request creates a new V8 instance and execute some script in it and after kill it. And every request has a separated thread. But now I can't do this.

Linux support

I can't find the 32 and 64 bit linux versions. Is there any plan to support these os versions?

Why J2V8 requires Java7?

It seems that J2V8 is build with Java 1.7.0_71. Why?

Do you think it's possible to provide a JAR which requires Java 6? Or perhaps Java 5 is enough?

Provide Eclipse Update site for J2V8

It should be very good if you could provide an update site for J2V8 which install the well J2V8 plugins according the OS.

tern.java provides this feature for node.js install. See https://github.com/angelozerr/tern.java/tree/master/eclipse/embed

It install the well node.js according the OS by using Eclipse-PlatformFilter. See https://github.com/angelozerr/tern.java/blob/master/eclipse/embed/tern.eclipse.ide.server.nodejs.embed.win32.win32.x86_64/META-INF/MANIFEST.MF#L12

See https://github.com/angelozerr/tern.java/blob/master/thirdparties/j2v8/j2v8_win32_x86_64/META-INF/MANIFEST.MF#L12 for my custom J2V8

Calling a JavaScript function in script

I'm sorry for opening an issue on this, but I can't seem to find any documentation on this.

I have a Javascript library that I'd like to keep in memory and run functions on it from time to time. It also might make callbacks to my methods I register.

I am assuming that I don't release the v8 runtime until I'm done with my libraries. But how do I call "someFunction(args)" in my Javascript code from Java?

Using Rhino, it looks like this:

Context rhino = Context.enter(); // Rhino context
rhino.setOptimizationLevel(-1);

scope = rhino.initStandardObjects();
obj = scope.get("someFunction", scope);
if (obj instanceof Function) {
    Function jsFunction = (Function) obj;
    // Set params
    Object [] params = new Object [] {arg1, arg2};
    // Call the function with params
    Object jsResult = jsFunction.call(rhino, scope, scope, params);
}

Hoping to find the J2V8 equivalent. Thank you for the library.

Getting Started or Hello-world Example required

J2V8 project looks very interesting. We have faced with problem, that Rhino on Android works very slow.

But in order to start it would be nice to have any kind of example or how-to documentation.

For example:

  1. Simple example referring standard API :
    https://code.google.com/p/jav8/
  2. Simple example of using not standard API:
    https://github.com/nostra13/Android-Universal-Image-Loader
  3. More sophisticated documentation
    https://developers.google.com/v8/embed?csw=1
    https://developers.google.com/v8/get_started

Add the ability to register a functional interface as a callback

Currently we implement the callbacks via reflection. For performance reasons we should also allow the registration of functional interfaces. We will need two:

JavaVoidCallback {
public void voidCallback(V8Array parameters);
}

JavaObjectCallback {
public Object objectCallback(V8Array parameters);
}

Add a universal 'get' method

Since we allow executing scripts / functions with unknown return values, we should also add a 'get(key)' that returns an Object.

Add an executeFunction method

We should have an executeFunction method that returns an Object. It should inspect the return type from JS and return the correct Java type.

java.lang.IllegalStateException: When two different JVMs use J2V8

Perhaps this issue looks like #33, but I have a strange problem.

I'm on Windows OS 64 bits. I can start the Hello sample http://eclipsesource.com/blogs/2015/02/25/announcing-j2v8-2-0/

Now take the same sample add a loop at the end of the main (in order to that the main doesn't finish) :

import com.eclipsesource.v8.V8;

public class Hello {

    public void print(String s) {
        System.out.println(s);
    }
    public void start() {
        V8 v8 = V8.createV8Runtime();
        v8.registerJavaMethod(this, "print", "print", 
                                      new Class<?>[] { String.class });
        v8.executeVoidScript("print('Hello, World!');");

                // HERE THE MAIN DOESN'T STOP
        while(true) {

        }
    }
    public static void main(String[] args) {
        new Hello().start();
    }
}
  • Run the Hello with Eclipse (it works)
  • Run a second Hello with Eclipse, I have the foolowing problem :
Exception in thread "main" java.lang.IllegalStateException: J2V8 native library not loaded.
    at com.eclipsesource.v8.V8.checkNativeLibraryLoaded(V8.java:86)
    at com.eclipsesource.v8.V8.createV8Runtime(V8.java:74)
    at com.eclipsesource.v8.V8.createV8Runtime(V8.java:63)
    at Hello.start(Hello.java:10)
    at Hello.main(Hello.java:20)
Caused by: java.lang.UnsatisfiedLinkError: Could not load J2V8 library. Reasons: 
    no j2v8_win32_x86_64 in java.library.path

    at com.eclipsesource.v8.LibraryLoader.loadLibrary(LibraryLoader.java:71)
    at com.eclipsesource.v8.V8.load(V8.java:49)
    at com.eclipsesource.v8.V8.createV8Runtime(V8.java:72)
    ... 3 more

V8 causes crash when shutting down

As experienced on the pizza day on the Samsung Galaxy Nexus (Andrdoi 4.3).

10-24 10:03:58.975  17795-17795/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.IncompatibleClassChangeError: interface not implemented
            at com.eclipsesource.v8.utils.DebugTunnel.close(DebugTunnel.java:38)
            at com.eclipsesource.v8.utils.DebugTunnel.stop(DebugTunnel.java:30)
            at com.eclipsesource.tabris.android.internal.javascript.V8JavaScriptBridge.shutDown(V8JavaScriptBridge.java:209)
            at com.eclipsesource.tabris.android.internal.javascript.JavaScriptMessageSender.shutdown(JavaScriptMessageSender.java:48)
            at com.eclipsesource.tabris.android.TabrisActivity.onDestroy(TabrisActivity.java:205)

Add support for creating V8Objects without native resources

When V8Objects (or V8Arrays) are used as a return value, there is no need to first allocate native resources. This is because these resources will be freed, and the return result will be used. This creating / releasing takes time.

We need the ability to create V8Object that simply have a handle number, but no native resource attached.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.