SlideShare a Scribd company logo
J2V8
Running JavaScript Efficiently in a Java World
R. Ian Bull

EclipseSource

@irbull
Are You a JavaScript Developer?
• This talk is not for you. But you’ll want this information!
• Running JavaScript in Java environments
• Optimizing JavaScript for Java deployment
• Java concepts bleeding into JavaScript
• Can we unleash performant JavaScript in a Java System?
Example — Tabris.js
• Mobile framework
• Apps written in JavaScript
• Native iOS and Android Apps
• Bindings to native UI components
• JavaScript was fast, Java was slow
Tabris.js
• Tight integration between the mobile platform and JS
Android and JS
• Android bindings written in Java
• No decent Java / JavaScript integration on Android
• Nashorn is not available
• Rhino slooooow
What About V8?
• V8 is a highly performant Javascript runtime
• Written entirely in C++
• Workhorse behind node.js & Chrome
http://ariya.ofilabs.com/2014/03/nashorn-the-new-rhino-on-the-block.html
J2V8
• Can we leverage V8 for Android development?
• Create a thin JNI layer above V8
• Expose V8 API in Java
• Open Source
J2V8 Design
• C++ (JNI) Bindings between Java & JavaScript
• Two GCs and unmanaged memory model in the middle
V8
J2V8 — C++
Java I Live Here
J2V8 Design
• Make JavaScript shine in an enterprise Java World
• Standard Java APIs
• Efficient Java / JavaScript bindings
• No Java system knowledge in JavaScript
• Multithreaded Java & JavaScript integration
Script Execution Example (Java)
public static void main(String[] args) {

V8 v8 = V8.createV8Runtime();
Object result = v8.executeScript("1+1");
System.out.println("Result: " + result);
v8.release();

}
Script Execution Example (JavaScript)
JavaScript Objects
• Access JavaScript objects from Java
• No special JS required
• Object are lazily copied to Java
v8.executeScript("person = {name : {first : 'john', last:'smith'} };");
String name = v8.get(“person”).get(“name”).get(“first”);
Lists and Maps Utilities
• Working with V8Objects is highly performant but complex
• Access JSObjects using java.util
• JavaScript Object mapped to java.util.Map
• JavaScript Array mapped to java.util.List
• In short: It works with common Java API
Calling JS Functions
• JavaScript Functions can be called from Java
• Use the results directly in Java
• Java Methods can be called from JavaScript
• Pass JavaScript Objects to Java
Calling JavaScript
• Any Java Method can be registered as a Function
• Call the Function as you would any other Function
• Java Methods can be specified with ‘var args’
JavaCallback callback = new MyJavaCallback();
v8.registerJavaMethod(callback, “foo");
v8.executeScript(“foo(‘a’, false, undefined)”);
JavaScript Exceptions
• JavaScript errors / exceptions propagate to Java
Typed Arrays
V8Array result = (V8Array) v8.executeScript(""
+ "var buf = new ArrayBuffer(100);"
+ "var ints = new Int32Array(buf); "
+ "for(var i = 0; i < 25; i++) {"
+ " ints[i] = i;"
+ "}; "
+ “ints");
int[] ints = result.getIntegers(0, 25);
• Native support for JS Typed Arrays
• Access the values efficiently from Java
Workers
• Supports multi-threaded JavaScript execution
• Implemented as Java Threads
• Each JS Script runs in its own ‘Isolate’
• Can send messages between threads
Debugger Support
• J2V8 can listen on a port for debug events
Performance
var data = [];
for (var i = 0; i < 100000; i++) {
data[i] = i;
}
for ( var i = 0; i < data.length; i++) {
for ( var j = 0; j < data.length; j++ ) {
if ( data[i] < data[j] ) {
var tmp = data[i];
data[i] = data[j];
data[j] = tmp;
}
}
}
Performance
V8 Nashorn Rhino
Rhino: ???
Nashorn 2:30
J2V8 0:13
Performance Considerations
• Minimize callbacks from JavaScript to Java
• ~4000 Per Second on my MBP
• Use bulk array copy to move primitives from JS to Java
• 60fps in our animation demo
Tern
• Tern is a stand-alone code-analysis engine for JavaScript
• Moved to J2V8 for Java integration
Building V8
• Embeds V8 in the .jar file
• V8 built for each platform we support
• Build instructions encoded as a docker file
[%] git clone https://github.com/eclipsesource/J2V8.git

[%] docker build --rm=true --no-cache -t "eclipsesource/v8-build" .
Resources
• Getting started with J2V8
• Registering Java Callbacks with J2V8
• Implementing WebWorkers with J2V8
• Multithreaded JavaScript with J2V8
• Using J2V8 with Heroku
• All linked from our GitHub Page
Future Work
• Script API (JSR 223)
• Advanced exception handling between Java and JS
• Batch callbacks for better JNI performance
• Debugger integration with Chrome Dev Tools
Using J2V8
• J2V8 is available in Maven Central
• Currently 5 variants are available:
com.eclipsesource.j2v8.j2v8_win32_x86:2.2.1

com.eclipsesource.j2v8.j2v8_macosx_x86_64:2.2.1

com.eclipsesource.j2v8.j2v8_android:2.2.1

com.eclipsesource.j2v8.j2v8_android_armv7l:2.2.1

com.eclipsesource.j2v8.j2v8_android_x86:2.2.1
• j2v8_android:2.0 contains both x86 and armv7l, and the
correct library will be selected at runtime
J2V8
• Open Source Java bindings for V8
• Licensed under the EPL
• For J2V8 news, follow me on Twitter @irbull
https://github.com/eclipsesource/j2v8
Ad

More Related Content

What's hot (20)

ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
Shahed Chowdhuri
 
DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)
beom kyun choi
 
1-supportpoojavapremirepartie-140408132307-phpapp01.pptx
1-supportpoojavapremirepartie-140408132307-phpapp01.pptx1-supportpoojavapremirepartie-140408132307-phpapp01.pptx
1-supportpoojavapremirepartie-140408132307-phpapp01.pptx
RihabBENLAMINE
 
React Js Simplified
React Js SimplifiedReact Js Simplified
React Js Simplified
Sunil Yadav
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
Ravi Kant Sahu
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Language
jaimefrozr
 
webSocket通信を知らないiOSエンジニアが知っておいて損はしない(経験談的な)軽い話
webSocket通信を知らないiOSエンジニアが知っておいて損はしない(経験談的な)軽い話webSocket通信を知らないiOSエンジニアが知っておいて損はしない(経験談的な)軽い話
webSocket通信を知らないiOSエンジニアが知っておいて損はしない(経験談的な)軽い話
Yuhei Miyazato
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
Josué Neis
 
Reactive Java Microservices with Spring Boot and JHipster - Spring I/O 2022
Reactive Java Microservices with Spring Boot and JHipster - Spring I/O 2022Reactive Java Microservices with Spring Boot and JHipster - Spring I/O 2022
Reactive Java Microservices with Spring Boot and JHipster - Spring I/O 2022
Matt Raible
 
Expressjs
ExpressjsExpressjs
Expressjs
Yauheni Nikanovich
 
Unified JVM Logging
Unified JVM LoggingUnified JVM Logging
Unified JVM Logging
Yuji Kubota
 
Swagger / Quick Start Guide
Swagger / Quick Start GuideSwagger / Quick Start Guide
Swagger / Quick Start Guide
Andrii Gakhov
 
React workshop presentation
React workshop presentationReact workshop presentation
React workshop presentation
Bojan Golubović
 
Virtual machine and javascript engine
Virtual machine and javascript engineVirtual machine and javascript engine
Virtual machine and javascript engine
Duoyi Wu
 
Java programming course for beginners
Java programming course for beginnersJava programming course for beginners
Java programming course for beginners
Eduonix Learning Solutions
 
Fundamentals of JAVA
Fundamentals of JAVAFundamentals of JAVA
Fundamentals of JAVA
KUNAL GADHIA
 
クラスローダーについて
クラスローダーについてクラスローダーについて
クラスローダーについて
Suguru ARAKAWA
 
虎の穴ラボ エンジニア採用説明資料
虎の穴ラボ エンジニア採用説明資料虎の穴ラボ エンジニア採用説明資料
虎の穴ラボ エンジニア採用説明資料
虎の穴 開発室
 
Apache 핵심 프로젝트 camel 엿보기
Apache 핵심 프로젝트 camel 엿보기Apache 핵심 프로젝트 camel 엿보기
Apache 핵심 프로젝트 camel 엿보기
Hwang Sun Oh Kelly
 
WebLogic Scripting Tool Overview
WebLogic Scripting Tool OverviewWebLogic Scripting Tool Overview
WebLogic Scripting Tool Overview
James Bayer
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
Shahed Chowdhuri
 
DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)
beom kyun choi
 
1-supportpoojavapremirepartie-140408132307-phpapp01.pptx
1-supportpoojavapremirepartie-140408132307-phpapp01.pptx1-supportpoojavapremirepartie-140408132307-phpapp01.pptx
1-supportpoojavapremirepartie-140408132307-phpapp01.pptx
RihabBENLAMINE
 
React Js Simplified
React Js SimplifiedReact Js Simplified
React Js Simplified
Sunil Yadav
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
Ravi Kant Sahu
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Language
jaimefrozr
 
webSocket通信を知らないiOSエンジニアが知っておいて損はしない(経験談的な)軽い話
webSocket通信を知らないiOSエンジニアが知っておいて損はしない(経験談的な)軽い話webSocket通信を知らないiOSエンジニアが知っておいて損はしない(経験談的な)軽い話
webSocket通信を知らないiOSエンジニアが知っておいて損はしない(経験談的な)軽い話
Yuhei Miyazato
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
Josué Neis
 
Reactive Java Microservices with Spring Boot and JHipster - Spring I/O 2022
Reactive Java Microservices with Spring Boot and JHipster - Spring I/O 2022Reactive Java Microservices with Spring Boot and JHipster - Spring I/O 2022
Reactive Java Microservices with Spring Boot and JHipster - Spring I/O 2022
Matt Raible
 
Unified JVM Logging
Unified JVM LoggingUnified JVM Logging
Unified JVM Logging
Yuji Kubota
 
Swagger / Quick Start Guide
Swagger / Quick Start GuideSwagger / Quick Start Guide
Swagger / Quick Start Guide
Andrii Gakhov
 
React workshop presentation
React workshop presentationReact workshop presentation
React workshop presentation
Bojan Golubović
 
Virtual machine and javascript engine
Virtual machine and javascript engineVirtual machine and javascript engine
Virtual machine and javascript engine
Duoyi Wu
 
Fundamentals of JAVA
Fundamentals of JAVAFundamentals of JAVA
Fundamentals of JAVA
KUNAL GADHIA
 
クラスローダーについて
クラスローダーについてクラスローダーについて
クラスローダーについて
Suguru ARAKAWA
 
虎の穴ラボ エンジニア採用説明資料
虎の穴ラボ エンジニア採用説明資料虎の穴ラボ エンジニア採用説明資料
虎の穴ラボ エンジニア採用説明資料
虎の穴 開発室
 
Apache 핵심 프로젝트 camel 엿보기
Apache 핵심 프로젝트 camel 엿보기Apache 핵심 프로젝트 camel 엿보기
Apache 핵심 프로젝트 camel 엿보기
Hwang Sun Oh Kelly
 
WebLogic Scripting Tool Overview
WebLogic Scripting Tool OverviewWebLogic Scripting Tool Overview
WebLogic Scripting Tool Overview
James Bayer
 

Viewers also liked (9)

p2, your savior or your achilles heel? Everything an Eclipse team needs to kn...
p2, your savior or your achilles heel? Everything an Eclipse team needs to kn...p2, your savior or your achilles heel? Everything an Eclipse team needs to kn...
p2, your savior or your achilles heel? Everything an Eclipse team needs to kn...
irbull
 
Software Engineering 2014
Software Engineering 2014Software Engineering 2014
Software Engineering 2014
Shuichi Kurabayashi
 
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocket
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over WebsocketIntroduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocket
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocket
sametmax
 
javascript 1
javascript 1javascript 1
javascript 1
osman do
 
PgREST: Node.js in the Database
PgREST: Node.js in the DatabasePgREST: Node.js in the Database
PgREST: Node.js in the Database
Audrey Tang
 
A new execution model for Nashorn in Java 9
A new execution model for Nashorn in Java 9A new execution model for Nashorn in Java 9
A new execution model for Nashorn in Java 9
Marcus Lagergren
 
Java/Spring과 Node.js의 공존 시즌2
Java/Spring과 Node.js의 공존 시즌2Java/Spring과 Node.js의 공존 시즌2
Java/Spring과 Node.js의 공존 시즌2
동수 장
 
Que Es Java
Que Es JavaQue Es Java
Que Es Java
quesada_diego
 
Node.js and The Internet of Things
Node.js and The Internet of ThingsNode.js and The Internet of Things
Node.js and The Internet of Things
Losant
 
p2, your savior or your achilles heel? Everything an Eclipse team needs to kn...
p2, your savior or your achilles heel? Everything an Eclipse team needs to kn...p2, your savior or your achilles heel? Everything an Eclipse team needs to kn...
p2, your savior or your achilles heel? Everything an Eclipse team needs to kn...
irbull
 
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocket
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over WebsocketIntroduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocket
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocket
sametmax
 
javascript 1
javascript 1javascript 1
javascript 1
osman do
 
PgREST: Node.js in the Database
PgREST: Node.js in the DatabasePgREST: Node.js in the Database
PgREST: Node.js in the Database
Audrey Tang
 
A new execution model for Nashorn in Java 9
A new execution model for Nashorn in Java 9A new execution model for Nashorn in Java 9
A new execution model for Nashorn in Java 9
Marcus Lagergren
 
Java/Spring과 Node.js의 공존 시즌2
Java/Spring과 Node.js의 공존 시즌2Java/Spring과 Node.js의 공존 시즌2
Java/Spring과 Node.js의 공존 시즌2
동수 장
 
Node.js and The Internet of Things
Node.js and The Internet of ThingsNode.js and The Internet of Things
Node.js and The Internet of Things
Losant
 
Ad

Similar to Running JavaScript Efficiently in a Java World (20)

Node4J: Running Node.js in a JavaWorld
Node4J: Running Node.js in a JavaWorldNode4J: Running Node.js in a JavaWorld
Node4J: Running Node.js in a JavaWorld
Ian Bull
 
Java 8: Nashorn & avatar.js di Enrico Risa al JUG Roma
Java 8: Nashorn & avatar.js di Enrico Risa al JUG RomaJava 8: Nashorn & avatar.js di Enrico Risa al JUG Roma
Java 8: Nashorn & avatar.js di Enrico Risa al JUG Roma
Vitalij Zadneprovskij
 
The Ruby Racer: under the hood
The Ruby Racer: under the hoodThe Ruby Racer: under the hood
The Ruby Racer: under the hood
cowboyd
 
Nashorn
NashornNashorn
Nashorn
Rory Preddy
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript Everywhere
Pascal Rettig
 
Javantura 2014 - Java 8 JavaScript Nashorn
Javantura 2014 - Java 8 JavaScript NashornJavantura 2014 - Java 8 JavaScript Nashorn
Javantura 2014 - Java 8 JavaScript Nashorn
Miroslav Resetar
 
Javantura Zagreb 2014 - Nashorn - Miroslav Rešetar
Javantura Zagreb 2014 - Nashorn - Miroslav RešetarJavantura Zagreb 2014 - Nashorn - Miroslav Rešetar
Javantura Zagreb 2014 - Nashorn - Miroslav Rešetar
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
DataArt
 
Run-time of Node.js : V8 JavaScript Engine
Run-time of Node.js: V8 JavaScript EngineRun-time of Node.js: V8 JavaScript Engine
Run-time of Node.js : V8 JavaScript Engine
Gary Yeh
 
Lagergren jvmls-2014-final
Lagergren jvmls-2014-finalLagergren jvmls-2014-final
Lagergren jvmls-2014-final
Marcus Lagergren
 
jQuery Objects
jQuery ObjectsjQuery Objects
jQuery Objects
Steve Wells
 
Introduction to java and it's opportunities
Introduction to java and it's opportunities Introduction to java and it's opportunities
Introduction to java and it's opportunities
VigneshManikandan11
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele Rialdi
CodeFest
 
Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)
Ran Mizrahi
 
Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)
Ran Mizrahi
 
JHipster
JHipsterJHipster
JHipster
Yuen-Kuei Hsueh
 
Groovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentationGroovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentation
Stuart (Pid) Williams
 
How to Contribute to Apache Usergrid
How to Contribute to Apache UsergridHow to Contribute to Apache Usergrid
How to Contribute to Apache Usergrid
David M. Johnson
 
Json generation
Json generationJson generation
Json generation
Aravindharamanan S
 
Dropwizard
DropwizardDropwizard
Dropwizard
Andrew Panfilov
 
Node4J: Running Node.js in a JavaWorld
Node4J: Running Node.js in a JavaWorldNode4J: Running Node.js in a JavaWorld
Node4J: Running Node.js in a JavaWorld
Ian Bull
 
Java 8: Nashorn & avatar.js di Enrico Risa al JUG Roma
Java 8: Nashorn & avatar.js di Enrico Risa al JUG RomaJava 8: Nashorn & avatar.js di Enrico Risa al JUG Roma
Java 8: Nashorn & avatar.js di Enrico Risa al JUG Roma
Vitalij Zadneprovskij
 
The Ruby Racer: under the hood
The Ruby Racer: under the hoodThe Ruby Racer: under the hood
The Ruby Racer: under the hood
cowboyd
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript Everywhere
Pascal Rettig
 
Javantura 2014 - Java 8 JavaScript Nashorn
Javantura 2014 - Java 8 JavaScript NashornJavantura 2014 - Java 8 JavaScript Nashorn
Javantura 2014 - Java 8 JavaScript Nashorn
Miroslav Resetar
 
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
DataArt
 
Run-time of Node.js : V8 JavaScript Engine
Run-time of Node.js: V8 JavaScript EngineRun-time of Node.js: V8 JavaScript Engine
Run-time of Node.js : V8 JavaScript Engine
Gary Yeh
 
Lagergren jvmls-2014-final
Lagergren jvmls-2014-finalLagergren jvmls-2014-final
Lagergren jvmls-2014-final
Marcus Lagergren
 
Introduction to java and it's opportunities
Introduction to java and it's opportunities Introduction to java and it's opportunities
Introduction to java and it's opportunities
VigneshManikandan11
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele Rialdi
CodeFest
 
Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)
Ran Mizrahi
 
Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)
Ran Mizrahi
 
Groovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentationGroovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentation
Stuart (Pid) Williams
 
How to Contribute to Apache Usergrid
How to Contribute to Apache UsergridHow to Contribute to Apache Usergrid
How to Contribute to Apache Usergrid
David M. Johnson
 
Ad

Recently uploaded (20)

Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Maxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINKMaxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINK
younisnoman75
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New VersionPixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
saimabibi60507
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Maxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINKMaxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINK
younisnoman75
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New VersionPixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
saimabibi60507
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 

Running JavaScript Efficiently in a Java World

  • 1. J2V8 Running JavaScript Efficiently in a Java World R. Ian Bull EclipseSource @irbull
  • 2. Are You a JavaScript Developer? • This talk is not for you. But you’ll want this information! • Running JavaScript in Java environments • Optimizing JavaScript for Java deployment • Java concepts bleeding into JavaScript • Can we unleash performant JavaScript in a Java System?
  • 3. Example — Tabris.js • Mobile framework • Apps written in JavaScript • Native iOS and Android Apps • Bindings to native UI components • JavaScript was fast, Java was slow
  • 4. Tabris.js • Tight integration between the mobile platform and JS
  • 5. Android and JS • Android bindings written in Java • No decent Java / JavaScript integration on Android • Nashorn is not available • Rhino slooooow
  • 6. What About V8? • V8 is a highly performant Javascript runtime • Written entirely in C++ • Workhorse behind node.js & Chrome http://ariya.ofilabs.com/2014/03/nashorn-the-new-rhino-on-the-block.html
  • 7. J2V8 • Can we leverage V8 for Android development? • Create a thin JNI layer above V8 • Expose V8 API in Java • Open Source
  • 8. J2V8 Design • C++ (JNI) Bindings between Java & JavaScript • Two GCs and unmanaged memory model in the middle V8 J2V8 — C++ Java I Live Here
  • 9. J2V8 Design • Make JavaScript shine in an enterprise Java World • Standard Java APIs • Efficient Java / JavaScript bindings • No Java system knowledge in JavaScript • Multithreaded Java & JavaScript integration
  • 10. Script Execution Example (Java) public static void main(String[] args) {
 V8 v8 = V8.createV8Runtime(); Object result = v8.executeScript("1+1"); System.out.println("Result: " + result); v8.release();
 }
  • 11. Script Execution Example (JavaScript)
  • 12. JavaScript Objects • Access JavaScript objects from Java • No special JS required • Object are lazily copied to Java v8.executeScript("person = {name : {first : 'john', last:'smith'} };"); String name = v8.get(“person”).get(“name”).get(“first”);
  • 13. Lists and Maps Utilities • Working with V8Objects is highly performant but complex • Access JSObjects using java.util • JavaScript Object mapped to java.util.Map • JavaScript Array mapped to java.util.List • In short: It works with common Java API
  • 14. Calling JS Functions • JavaScript Functions can be called from Java • Use the results directly in Java • Java Methods can be called from JavaScript • Pass JavaScript Objects to Java
  • 15. Calling JavaScript • Any Java Method can be registered as a Function • Call the Function as you would any other Function • Java Methods can be specified with ‘var args’ JavaCallback callback = new MyJavaCallback(); v8.registerJavaMethod(callback, “foo"); v8.executeScript(“foo(‘a’, false, undefined)”);
  • 16. JavaScript Exceptions • JavaScript errors / exceptions propagate to Java
  • 17. Typed Arrays V8Array result = (V8Array) v8.executeScript("" + "var buf = new ArrayBuffer(100);" + "var ints = new Int32Array(buf); " + "for(var i = 0; i < 25; i++) {" + " ints[i] = i;" + "}; " + “ints"); int[] ints = result.getIntegers(0, 25); • Native support for JS Typed Arrays • Access the values efficiently from Java
  • 18. Workers • Supports multi-threaded JavaScript execution • Implemented as Java Threads • Each JS Script runs in its own ‘Isolate’ • Can send messages between threads
  • 19. Debugger Support • J2V8 can listen on a port for debug events
  • 20. Performance var data = []; for (var i = 0; i < 100000; i++) { data[i] = i; } for ( var i = 0; i < data.length; i++) { for ( var j = 0; j < data.length; j++ ) { if ( data[i] < data[j] ) { var tmp = data[i]; data[i] = data[j]; data[j] = tmp; } } }
  • 21. Performance V8 Nashorn Rhino Rhino: ??? Nashorn 2:30 J2V8 0:13
  • 22. Performance Considerations • Minimize callbacks from JavaScript to Java • ~4000 Per Second on my MBP • Use bulk array copy to move primitives from JS to Java • 60fps in our animation demo
  • 23. Tern • Tern is a stand-alone code-analysis engine for JavaScript • Moved to J2V8 for Java integration
  • 24. Building V8 • Embeds V8 in the .jar file • V8 built for each platform we support • Build instructions encoded as a docker file [%] git clone https://github.com/eclipsesource/J2V8.git
 [%] docker build --rm=true --no-cache -t "eclipsesource/v8-build" .
  • 25. Resources • Getting started with J2V8 • Registering Java Callbacks with J2V8 • Implementing WebWorkers with J2V8 • Multithreaded JavaScript with J2V8 • Using J2V8 with Heroku • All linked from our GitHub Page
  • 26. Future Work • Script API (JSR 223) • Advanced exception handling between Java and JS • Batch callbacks for better JNI performance • Debugger integration with Chrome Dev Tools
  • 27. Using J2V8 • J2V8 is available in Maven Central • Currently 5 variants are available: com.eclipsesource.j2v8.j2v8_win32_x86:2.2.1
 com.eclipsesource.j2v8.j2v8_macosx_x86_64:2.2.1
 com.eclipsesource.j2v8.j2v8_android:2.2.1
 com.eclipsesource.j2v8.j2v8_android_armv7l:2.2.1
 com.eclipsesource.j2v8.j2v8_android_x86:2.2.1 • j2v8_android:2.0 contains both x86 and armv7l, and the correct library will be selected at runtime
  • 28. J2V8 • Open Source Java bindings for V8 • Licensed under the EPL • For J2V8 news, follow me on Twitter @irbull https://github.com/eclipsesource/j2v8