Profile cover photo
Profile photo
Arpi Vezer
51 followers
51 followers
About
Arpi's posts

Post has shared content
+Raoul-Gabriel Urma  +Jim Gough  and I have teamed up to produce a #Java 8 & #Lambdas training course:

http://java8training.com

(Please +1)

JNI Overloaded Method Signatures

tl;dr Avoid them! :)

I've never really written any JNI code before, so here are some quick notes on potential gotchas that lead to an UnsatisfiedLinkError when exposing overloaded C++ functions to Java classes.

Overview

Overloaded method names are appended with a double underscore "__" followed by the Java method signature, so for a java.lang.String this would be Ljava_lang_String_2, or Lyour_namespace_Classname_2 for an arbitrary object. multiple arguments are appended to the name without any separator, so the "L..." follows immediately after the "..._2".

The signature convention is detailed here: http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/design.html

Note the bits about escaping underscores with "_1" if you have them in any names, like in the example_namespace below. Also important to keep in mind is that mangling is in the JNI sense of the word, not C++ symbol mangling!

Here's a simple, hopefully correct example.

C++ class to wrap

//foo.hpp
namespace example_namespace {
class ArgA;
class ArgB;

class Foo {
  //...
  void func(const ArgA &a);
  void func(const ArgA &a, const ArgB &b);
};
}

Java counterpart
//Foo.java
package example_namespace;
public class Foo {
  //...
  public native func(ArgA a);
  public native func(ArgA a, ArgB b);
}

JNI wrapper
(I'm not sure of the correct terminology for these wrapping layers.)

//example_namespace_Foo.cpp
JNIEXPORT void JNICALL
Java_example_1namespace_Foo_func_Lexample_1namespace_ArgA_2(JNIEnv* env, jobject obj, jobject a) { /* ... */ }
Java_example_1namespace_Foo_func_Lexample_1namespace_ArgA_2Lexample_1namespace_ArgB_2(JNIEnv* env, jobject obj, jobject a, jobject b) { /* ... */ }

Post has attachment
Free Caltech online machine learning course starts again on 2 April http://work.caltech.edu/telecourse. I really enjoyed the course, worth checking out if you're interested in the subject.

Post has shared content
The best dynamic memory/cheese metaphors I've seen all week

Hope Google Now soon learns that while my office overlooks a bus stop, I don't need to be kept informed of its timetable
London

Post has attachment
The Nokia 808 camera in this video looks great. I wonder how much the footage was improved during post production.

The new stream in g+ for android looks awesome!
London

Post has attachment
My new calendar, with a different font for every day. I'm cool.
Photo

Thanks Apple, now it feels wrong no matter which way I set the scrolling on my laptop

Post has attachment
500 kg shark jumps onto boat - crazy.
Wait while more posts are being loaded