Java/C++ integration made easy

Technical Introduction

JunC++ion is a development tool that solves complex Java/C++ or Java/C integration problems. At a high level, it consists of the following components:

  • a code generator, both GUI and command line version.
    The code generator takes Java bytecode as input and generates platform- and compiler-portable C++ source files, makefiles, and project files. The code generator represents our expert knowledge of the design-time aspects of Java/C++ interoperability. Unless you're an OEM customer, you usually only use the code generator in-house.

    Code Generator GUI
  • a runtime library.
    The runtime library is typically platform- and compiler-specific and provides an abstraction layer around the generic aspects of Java and C++ integration. The runtime library represents our expert knowledge of the runtime aspects of Java/C++ interoperability. You ship the runtime library as part of your finished integration solution.
  • an ANT abstraction for various C++ compilers.
    ANT is a poular build system in Java. The C++ compiler abstraction allows you to generate C++ bindings and compile them as part of an automated build without having to be an expert in a specific C++ compiler.
  • a Shared JVM server.
    The Shared JVM server provides you with an alternate deployment option that does not require the presence of a Java Runtime Environment on the host that is running your C++ code.
  • lots of examples.
    Some of the examples can be immediately useful to you because you just have to build them or customize them slightly to solve your particular integration problem.

Typical Workflow (C++ calling Java)

You start out with some Java API that you wish to publish to C++ so that C++ developers can use it. The Java API in question could be your own product's API, or it could be a third-party API that you "inherited" from a different group.

You start the code generator GUI, drag and drop the jar file containing the Java API onto it, set the target directory for the generated files, and press the "Generate" button, done!

Well, in real life it's not usually quite that simple because

  • you have to familiarize yourself with the code generator and its usually understandable peculiarities, and
  • your jar file might depend on other jar files that you don't have or didn't think about at first, and
  • the imported jar file might be too big and requires you to adjust the heap memory for the code generator, and
  • the imported jar file contains 7000 types and you only want 20 of them, and ...

you get the picture.

All of these obstacles are easily overcome by using standard code generator features. After the first or second day of playing with the tool and your Java classes, you will typically have a pretty good understanding of how things work and you're 90% done with creating the set of C++ types that will solve your integration problem.

What's next, now that you have some generated C++ source files? You can use the generated makefiles, batch files, or project files to compile the C++ sources into an integration library and then start using the library from your own projects.

The entire process involving the code generator is usually completed within the first week of usage, with the majority of the time spent on fine-tuning the class set and the conversion options to facilitate easy integration into an overnightly build.

Distinguishing Factors

JunC++ion is a mature integration solution. It has been ported successfully to many platforms and compilers and is being used in many business- and mission-critical applications. We don't like getting into feature comparison contests with the competition and we don't believe in Enterprise, Pro, Standard, Lite, Extra Lite, and Almost Not There feature matrices, so we will just present a table of features/decision making factors that will hopefully help you decide that the one and only version of JunC++ion is worth your consideration.

We broke the table up into sub-tables for code generation, generated code, and runtime features.

Code Generator feature matrix

Feature Explanation
"Smart" Code generator The code generator understands the relationships between Java types. When you import a Java type, it automatically enables other Java types that are required on the C++ side to make that type useful (for example method argument types of enabled methods). When you instruct the code generator to disable a particular type, it automatically disables all dependent elements (methods, fields) that rely on the presence of that type.
Good Heuristics If you make no modifications to the default generation settings, you will probably end up with something that is right for you or at least almost right for you.
High customizability You can disable (almost) any type, any method, any field from becoming available in C++.
Automation features The code generator can persist the state of a project and then allow you to reopen it in the GUI or use it as part of an automated, command line-based build.
ANT integration ANT is a very powerful, portableJava-based build system and the custom tasks for code generation and compilation allow you to create portable, automated, end-to-end integration builds.
Build support generator The code generator can optionally generate makefiles, build batch files, and Visual Studio project files.
API Documentation generator The code generator can optionally generate API documentation. It can generate a complete API reference manual even without access to the Java sources, but the results are even better if you can make the Java sourcefiles available to the code generator.
Special native method support The code generator can optionally generate method stubs and default implementations for Java native methods. The generated methods are exception-safe and can be implemented in terms of C++ proxy types.

Generated code feature matrix

Feature Explanation
Platform- and compiler-portable The generated code is as portable as we can possibly make it. This includes workarounds for compiler bugs that you have probably never run into in your hand-written code. Having us encounter and work around these issues is invaluable.
As lightweight as possible The generated code delegates as quickly as possible to the runtime library to keep the proxy classes as small as possible.
Exception-safe The generated code can be used in the presence of C++ exceptions without leaking objects on the Java side.
Multithread-ready The generated code can safely and easily be used in multithreaded runtime environments. We do not claim total thread safety because we intentionally did not synchronize write access to the proxy instances for performance reasons.
That being said and assuming you take care of write synchronization, you can safely use proxy objects on multiple threads.
Callback support A Java interface can be flagged as a callback interface, causing the generation of callback support. This means that you can implement the Java interface in C++ and have the Java side call your C++ implementation asynchronously (EventListeners, etc.)
Highly usable types The generated code is just about as usable as the underlying Java types and we just keep adding C++ features like STL iterator support for Java collections.
Fewest possible surprises It is impossible to generate code that is totally without surprises. For example, C++ has more reserved names than Java, so sometimes a valid Java name needs to be changed on the C++ side to ensure a successful compilation. The generated code has extremely few such surprises.

Runtime feature matrix

Feature Explanation
Works with virtually any Java2 JRE In JNI mode, JunC++ion-enabled C++ applications have been tested with a multitude of JVMs, starting with Sun JRE 1.2.2.
Extremely high performance in in-process (JNI) mode Even though JNI has a bad reputation, it is really quite fast. There is inevitable overhead, but you will be very positively surprised by the performance of your integrated application.
Out-of-process (Shared JVM) deployment option This is a much slower mode of operation, but you can avoid having to deploy Java with your C++ application; just one more deployment option for you.
Mature configuration framework You need to tell your C++ application where to find the Java parts of the application and how to initialize the JVM or connect to the shared JVM server.
You have extreme flexibility, from hardcoding the settings, over using XML config files, all the way to self-configuring DLLs via configuration callbacks.
No server necessary Your finished integrated solution can be totally self-contained without any additional "moving pieces" required.
"xcopy" deployable Just copy or move the integrated solution and double-click the executable. If you configured things correctly, it will still work, no registration steps necessary.

 


Copyright 2006-2011 by Codemesh, Inc., ALL RIGHTS RESERVED

:
junc++ion home
home products support customers partners newsroom about us contact us