Saturday, October 3, 2009

Running eRCP with Phoneme Advanced on your mobile phone

Running eRCP with Phoneme Advanced on your mobile phone

Originally, I don't think this is a problem. Because I have run the eRCP with J9 VM successfullly 4 years ago. However, when I revisit this topic recently, I found that this thought was not true. You google some posts about this problem, like here or here recently, or old post here at 2007. 

Now the status of JVM on mobile phone is that J9 CDC VM is not available to non-linux platform mobile users for free any more.(maybe binded with some IBM products like IBM JRE6? If I am not right, you correct me^_^). And some benchmark show that the phoneme advanced is faster thant the J9 embed.

Now, I think I should fix this problem for our community. I take out my old HP 1940, and try to find some clues. And yes, I get the crash as well. One convenient thing for Equinox(or other OSGI RI) is that you can find some logs at the %eRCP_ROOT%/configuration/ directory. I find one thing like,

...
!MESSAGE 
!STACK 0
org.osgi.framework.BundleException: The bundle could not be resolved. Reason: Missing Constraint: Bundle-RequiredExecutionEnvironment: CDC-1.0/Foundation-1.0,J2SE-1.3
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(Unknown Source)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(Unknown Source)
at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Unknown Source)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(Unknown 
...

Yeah, "Missing Constraint: Bundle-RequiredExecutionEnvironment" error. So, we know that the Equinox OSGI framework can not recognize the phoneme advanced execution environment. After quickly sourcing, the best fixing solution appears. Using the follow .ink file to lanuch the eRCP,

37#"\phoneme\bin\cvm.exe" -Djava.specification.name="J2ME Foundation Specification" -cp \eRCP\startup.jar org.eclipse.core.launcher.Main -application org.eclipse.ercp.swt.demo.eSWTDemoApp -console

The reason is that the Equinox osgi use "java.specification.name" property to recognize the cdc execution environment, and they just accept the "J2ME Foundation Specification" as the value of property java.specification.name. However, in the Phoneme Advanced, this value is set to the "Foundation Profile Specification" in default. There are many ways to fix this problem, such as modifying the makefile of phoneme, modifying the config.ini to include this property, or modifying the source of osgi. However, the best way now is as my suggestion. I will open a bug to Equinox to see if they want to do something:)

Now you will see the exciting screen on your mobile phone.

eRCP HelloWorld

eRCP Canvas

eRCP eWorkbench

OSGI(Equinox) console


The feeling of eRCP has still been awesome from my last try several years ago. The fact eRCP can run on mobile has demonstrated the success of Eclipse RT project. (Surely, OSGi Minimum Execution Environment is JavaME Foundation).

One interesting for me is that the eSWT widgets can work with Phoneme Advanced without any modification. As I have pointed out at the previous post, the JNI application should be compiled with CVM's JNI headers. In win32/x86 platform, this re-compilation is a "must". However, direct eSWT supporting for CVM is not perfect. The screenshots, like "eRCP eWorkbench", has shown some appended unreadable characters on the menu item. That is a eSWT bug (seemly just for CVM) as I mentioned at the previous post as well. It needs times to fix this problem. Stay tuned...


Let's do a summary as follows:

1. full eRCP can be run with Phoneme Advanced
2. full OSGI 4.x RI can be run with Phoneme Advanced
3. if you run the native(JNI) codes and meet some errors, please do not forget to re-compile your JNI codes against CVM's JNI headers.


6 comments:

Jeff McAffer said...

Cool. Check out Equinox's execution environment files (.ee files) at http://wiki.eclipse.org/Execution_Environment_Descriptions for information on how to describe different JREs.

Jin Mingjian said...

Jeff, thanks for pointing out this way to add other execution environments non-invasively. I forget to mention this great way here:) But in fact, I use .ee file to make CVM become one of my running and debugging JRE without any programming last week. Cool too:) maybe I can blog it some time recently.

stardot said...

I was able to resolve the issue with stray characters in the widget texts (menu, button, etc.) by fixing one method in the eSWT C code. It seems CVM does not handle Strings the same way J9 does. J9 will automatically terminate the string with null values when passing to/from JNI. CVM doesn't seem to do this. The fix was pretty simple, since the length of the string was provided already. I'll post the fix once I can get back to the source code (it's on an external drive I don't have access to right now!)

Interesting post. I had to do the same digging into the eRCP startup code to find the J2ME properties to get this going. eRCP is a GREAT development environment for mobile devices, and it's nice to not require a licensed runtime (J9) to use it on Windows CE devices.

I did find other oddities with CVM and eRCP, particularly with the networking in the update.core plugin. (sometimes an operation timed out error would occur at the start of plugin download)

Also, DLL load order seems more sensitive in CVM as opposed to J9. Usually putting the plugin that loads the DLL in the config.ini file and loading it in the activator will resolve this.

Jin Mingjian said...

Hi, Jerome. Useful comments.

I understand your "pretty simple" method. Because there is a long time I re-pick up C/C++ tools. So I just choose one widget to fix as an example for myself. Recently, I played with CVM more or less. You thought is right. The CVM failed in terminating jchar* as null. But one thing is that jchar* seemly don't need to be a kind of string, although some forced cast can do this. So I am not sure whether this is a CVM bug.

The UM in eRCP could be changed with p2 in some near future from some discussions. And there some lightweight p2 discussions recently. So, there may be a better solution in the future.

As the dll order problems, I have not met. However, if someone met with it, your comment will be much useful for him, I think;)

moovida said...

This post has been of incredible help, even if 2 years old. I got it working with the open phoneme, while I wasn't able with a J9 I bought for the pure testing purpose.
Many thanks for what seems to me the most updated doc on how to get eRCP running.

moovida said...

@Jerome: is there a chance to get your fix into the eRCP codebase? I am having the same issue you describe but don't have the environment (knowledge?) to produce the fix.
Would you be willing to supply the patch to the fix you implemented?

@Jin, sorry to pollute your great post with this, I had no other way to get in touch with Jerome.