tips on complex types, BigDecimal, and general architecture recs

106 views
Skip to first unread message

Matt Walters

unread,
Jun 3, 2014, 11:42:17 AM6/3/14
to node...@googlegroups.com
Hi guys,

Thanks for making this module. I was hoping to get some pointers. 

I'm dealing with numerical data and need to instantiate some classes and use some methods in Java, from Node, that require parameters with complex types. When I instantiate complex types and use them in Node, things work great. If I attempt to instantiate a complex type for use as a parameter to a method back on the Java side, things blow up with the following segfault. This problem presents itself whether I'm attempting to instantiate and pass a custom type I've defined, or something as simple as a new BigDecimal:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x000000010fefa572, pid=17324, tid=1287
#
# JRE version: Java(TM) SE Runtime Environment (7.0_55-b13) (build 1.7.0_55-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.55-b03 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# C  [nodejavabridge_bindings.node+0x11572]  _Z20getSystemClassLoaderP7JNIEnv_+0x12
#
# Core dump written. Default location: /cores/core or core.17324
#
# An error report file with more information is saved as:
# /Users/matt/development/electronifie/fix-gateway/hs_err_pid17324.log
#
# If you would like to submit a bug report, please visit:
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

How should I be creating complex-typed objects to pass back to Java? My guess is the answer to this question will also suggest some best practices for working with BigDecimal objects, but I'd love some suggestions there as well (perhaps best to use bignumber.js, convert to string, then have helper methods convert back to BigDecimal on the Java side?

My intention is essentially to create a factory method, where the method creates a class and applies a number of set() operations on it. However, the set operations have different typed parameters - setInt, setString, setDecimal, etc. Is it best to pass a collection of operations to Java, which it can iterate on and then pass back the created object? Or, is there no real JNI penalty for doing these operations asynchronously straight from Node?

Thanks!

Matt 

Joe Ferner

unread,
Jun 3, 2014, 2:14:50 PM6/3/14
to node...@googlegroups.com
I just added a test for calling methods with BigDecimal args: see test/Test.java:staticBigDecimalToString and test/java-callStaticMethod-test.js

Try clone node-java and running npm test to see if the install is good or if it's your code.

Also can you try running...

gdb --args `which node` your-code.js

then at the prompt type run

Matt Walters

unread,
Jun 3, 2014, 4:15:42 PM6/3/14
to node...@googlegroups.com
Thanks, Joe.

Should that be in https://github.com/joeferner/node-java/blob/v0.3.4/test/Test.java? Looks like it may not have been committed. 
Reply all
Reply to author
Forward
0 new messages