J2V8 2.2 New and Noteworthy

J2V8 2.2 New and Noteworthy

I’m happy to announce the availability of J2V8 2.2 (2.2.1 actually). This release adds two important features: 1) Typed Arrays and 2) 64 Bit Windows support.

Typed Arrays

In Javascript, most arrays are untyped. That is, you can create an array and add anything to it.

<pre lang="javascript">
var myStuff = [];
myStuff[0] = 42;
myStuff[1] = true;
myStuff[2] = "Strings";
</pre>

A  few years ago, the Javascript community realized the need for a more efficient mechanism for working with binary data in WebGL. The result of this work were Typed Arrays. Typed Arrays are a continuous chunk of memory with a typed view onto it. The memory is managed by the underlying engine and they perform a lot better than regular Javascript arrays.

<pre lang="javascript">
var buffer = new ArrayBuffer(256);
var i32 = new Int32Array(buffer);
i32[0] = 1;
i32[1] = 3;
i32[2] = i32[0] + i32[1];
</pre>

In this example, an array buffer of 256 bytes is allocated. A view, rendering the data as an array of 32bit integers, is then projected onto that buffer. Because the memory is continuous and the types are known, the operations (such as add in this case) perform much faster.

J2V8 2.2 supports the creation of Typed Arrays. You can even access the contents of the arrays, in bulk, from Java using the getIntsMethod (getDoubles and getBoolean for doubles and booleans).

<pre lang="java">
V8 v8 = V8.createV8Runtime();
V8Array result = v8.executeArrayScript("var buffer = new ArrayBuffer(256);\n"
 + "var i32 = new Int32Array(buffer);\n"
 + "i32[0] = 1;\n"
 + "i32[1] = 3;\n"
 + "i32[2] = i32[0] + i32[1];\n"
 + "i32;");
int[] ints = result.getInts(0, 3);
System.out.println("Result: " + ints[0] + ", " + ints[1] + ", " + ints[2]);
result.release();
v8.release();
</pre>

64 Bit Windows Support

J2V8 now supports 64 bit Windows. The binaries have pushed to Maven Central and can be consumed using the following dependency.

<pre lang="xml">
<dependency>
  <groupId>com.eclipsesource.j2v8</groupId>
  <artifactId>j2v8_win32_x86_64</artifactId>
  <version>2.2.1</version>
  <scope>compile</scope>
</dependency>
</pre>

For more news about J2V8, follow me on Twitter.

No Comments

Sorry, the comment form is closed at this time.