This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Java Nashorn Deprecated

 
Bartender
Posts: 1679
17
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has anyone moved to Graal from Nashorn yet?

In JDK 11 you now get the deprecation warning for Nashorn (JavaScript library).

I have some code that does a JS "eval()" which of course needs to keep working in future JDK versions.

Will Graal still support the JS "eval()" logic once I "install" it?

(Wishing Java had an "eval()" capability...)

Thanks,

-- mike
 
Bartender
Posts: 1164
38
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Mike, but with "Graal" do you  mean a new JScript interpreter embedded in latest java runtimes or do you refer to Graal VM?
 
Mike London
Bartender
Posts: 1679
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Claude Moore wrote:Sorry Mike, but with "Graal" do you  mean a new JScript interpreter embedded in latest java runtimes or do you refer to Graal VM?



Yep.

I actually did a lot of research yesterday and found that Graal is pretty cool Especially since you can now have polyglot apps and even compile Java code to machine code (finally).

I then refactored my Java code that uses an "eval()" using Nashorn to an "eval()" using Graal and it's all good!

Thanks.

- mike
 
Saloon Keeper
Posts: 5700
144
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oracle has endorsed the GraalVM as an alternative to Nashorn. My favorite would be the time-tested Rhino library, which is now a standalone library. I understand that Nashorn can have better performance, though, so that may not be an option.
 
Mike London
Bartender
Posts: 1679
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:Oracle has endorsed the GraalVM as an alternative to Nashorn. My favorite would be the time-tested Rhino library, which is now a standalone library. I understand that Nashorn can have better performance, though, so that may not be an option.



To use the CE edition of Graal is easy also.

In a Maven project, I just used these two dependencies:



Then, you can write code, like this:

public static void main(String[] args)
   {
       System.out.println("Hello World!");
       System.out.println("Hello polyglot world Java!");

       Context context = Context.newBuilder().allowAllAccess(true).build();

       context.eval("python", "\nprint('Hello polyglot world Python!');");
       context.eval("R", "'/Users/jim/Desktop/Test.R'");
       context.eval("js", "print(eval('1+3'));");      
.
.
.


- mike
 
Claude Moore
Bartender
Posts: 1164
38
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GraalVM looks really interesting, I hope it will get some momentum someday.
 
Tim Moores
Saloon Keeper
Posts: 5700
144
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Incidentally, a final version of GraalVM just just released: https://www.infoq.com/news/2019/06/oracle-releases-graalvm-19.0
 
Mike London
Bartender
Posts: 1679
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:Incidentally, a final version of GraalVM just just released: https://www.infoq.com/news/2019/06/oracle-releases-graalvm-19.0



Interesting.

Since my posting, I figured out how to call a python or R program (not just execute a single line), pass parameters, and get results.

---

Creating a native executable doesn't seem to be much faster than a regular Java program, however.

For example, I have a sample benchmark program that does 2 billion loop iterations. In each iteration, it calls a function to compute a sin(), cos(), and a couple other functions just so the loop is actually doing something.

On an 8-core 2019 iMac (i9), this program (using .parallel()) takes 23 seconds.

Creating a Graal "native-image" that sacrifices byte-code portability for speed, it still takes 22 seconds.

Not much of an improvement.

I'm not motivated at the moment to port this sample program to C, but I bet it would be faster.

- mike

 
Claude Moore
Bartender
Posts: 1164
38
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IMHO one of the major problem with GraalVM is that at the moment there's no official porting for Windows.
This may reduce potential audience of users.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!