[Pharo-users] [ANN] JNIPort for Pharo 3.0 alpha

Tudor Girba tudor at tudorgirba.com
Thu Mar 27 08:07:22 EDT 2014


I also tested it on Windows 7 and it works just great.

Just a question: is there a way to communicate with an already running VM
that was started independently from Pharo?

Doru


On Tue, Mar 25, 2014 at 11:55 PM, Philippe Back <phil at highoctane.be> wrote:

> Works on Windows 8.1 x64 with a 32-bit JRE 1.7 on a freshly fetched Pharo30
>
>
>
> There is a Transcript flush that would help seeing the output to the
> Transcript...
>
>
>
> Snippet:
>
>
>
> | jvmSettings |
>
> "You can set the path to the Java VM library by editing the path as
>
> needed."
>
> "JNIPortJNIInterface libraryFile:
>
>
> '/System/Library/Java/JavaVirtualMachines/1..6.0.jdk/Contents/Libraries/libclient.dylib'"
>
> .
>
> JNIPortJNIInterface libraryFile: 'C:\Program Files
> (x86)\Java\jre7\bin\client\jvm.dll' ..
>
>
>
> jvmSettings := JVMSettings new.
>
> jvmSettings usesGhosts: true.
>
> jvmSettings supportsCallbacks: true.
>
> jvmSettings jniPortSettings  useJNIHelperLibrary: false.
>
> jvmSettings ghostClassSettings retainMethodSource: true.
>
>
>
> "On Mac OS X and Linux, class path entries are separated by colons."
>
> "On Windows, you have to use semicolons instead. Edit the following line as
>
> needed."
>
> "jvmSettings runtimeSettings classpath:
>
> '.:/Users/myname/JNIPort.jar:/Users/myname/JNIPort-Tests.jar'."
>
> jvmSettings runtimeSettings classpath:
> '.;.\JNIPort.jar;.\JNIPort-Tests.jar'.
>
>
>
> "Uncomment the following if you want the Java VM to emit verbose messages.
>
>   How to access these messages depends on your platform.
>
>   On Mac OS X, they are visible in the Console application."
>
> "jvmSettings runtimeSettings addOption: '-verbose:jni'; addOption:
>
> '-verbose:gc'; addOption: '-verbose:class'."
>
> Cursor execute showWhile: [JVM newWithSettings: jvmSettings].
>
> "----
>
>
>
> Then the fun starts:
>
>
>
> ----"
>
> zfClass := JVM current findClass: #'java.util.zip.ZipFile'.
>
> zipfile := zfClass new_String: 'JNIPort.jar'.
>
> zipfile size. "--> answers an Integer"
>
> entries := zipfile entries.
>
> entries asAnEnumeration do: [:each | Transcript cr; print: each].
>
> Transcript flush.
>
> "----"
>
>
>
> Cool to have a bridge.
>
>
>
> Phil
>
>
>
>
>
> *From:* Pharo-users [mailto:pharo-users-bounces at lists.pharo.org] *On
> Behalf Of *Tudor Girba
> *Sent:* mardi 25 mars 2014 21:26
> *To:* Any question about pharo is welcome
> *Subject:* Re: [Pharo-users] [ANN] JNIPort for Pharo 3.0 alpha
>
>
>
> Thanks a lot for this contribution!
>
>
>
> I will give it a try soon.
>
>
>
> Doru
>
>
>
> On Tue, Mar 25, 2014 at 7:59 PM, Joachim Geidel <
> joachim.geidel at onlinehome.de> wrote:
>
> Hi everybody,
>
> JNIPort for Pharo 3.0 alpha is now available at SmalltalkHub.
>
> JNIPort is a Smalltalk library which allows Java code to be invoked from
> Smalltalk. It acts as a bridge between the world of Smalltalk objects and a
> Java Virtual Machine (JVM) where Java code is executing.
>
> When I first ported JNIPort to Squeak and Pharo 1.x, I used Alien as the
> FFI
> library. As NativeBoost has superseded Alien, the interface to the Java
> Native Interface library had to be rewritten. There are still some
> undocumented and obscure parts in NativeBoost, so this has taken some time.
>
> If you want to try it, load it via the ConfigurationOfJNIPort. I hope this
> works. If it does not, load the packages individually in the order in which
> they appear in the ConfigurationOfJNIPort.
>         http://www.smalltalkhub.com/#!/~JNIPort/JNIPort
> The next step is to read the documentation at
>         http://jniport.wikispaces.com/
> Otherwise, you won't know what to do next. ;-)
> Download the extra files from the download page at Wikispaces, you will
> need
> two jar files from there.
>
> Start a Java VM attached to Pharo by adapting and executing the following
> code snippet:
>
> ----
> | jvmSettings |
>  "You can set the path to the Java VM library by editing the path as
> needed."
> JNIPortJNIInterface libraryFile:
>
> '/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries/libclient.dylib'
> .
> "JNIPortJNIInterface libraryFile:
> 'C:\Programme\Java\jre7\bin\client\jvm.dll' .."
>
>
>  jvmSettings := JVMSettings new.
>  jvmSettings usesGhosts: true.
>  jvmSettings supportsCallbacks: true.
>  jvmSettings jniPortSettings  useJNIHelperLibrary: false.
> jvmSettings ghostClassSettings retainMethodSource: true.
>
>  "On Mac OS X and Linux, class path entries are separated by colons."
>  "On Windows, you have to use semicolons instead. Edit the following line
> as
> needed."
> jvmSettings runtimeSettings classpath:
> '.:/Users/myname/JNIPort.jar:/Users/myname/JNIPort-Tests.jar'.
> " jvmSettings runtimeSettings classpath:
> '.;.\JNIPort.jar;.\JNIPort-Tests.jar'."
>
>  "Uncomment the following if you want the Java VM to emit verbose messages.
>   How to access these messages depends on your platform.
>   On Mac OS X, they are visible in the Console application."
> "jvmSettings runtimeSettings addOption: '-verbose:jni'; addOption:
> '-verbose:gc'; addOption: '-verbose:class'."
> Cursor execute showWhile: [JVM newWithSettings: jvmSettings].
> ----
>
> Then the fun starts:
>
> ----
> | zfClass zipfile entries |
> zfClass := JVM current findClass: #'java.util.zip.ZipFile'.
> zipfile := zfClass new_String: 'JNIPort.jar'.
> zipfile size. "--> answers an Integer"
> entries := zipfile entries.
> entries asAnEnumeration do: [:each | Transcript cr; print: each].
> ----
>
> And now to the ugly little secret reason why I call it an alpha version:
>
> While everything seems to work, it is *much* slower than it used to be in
> Pharo 1.2 with Alien. And when I compare it with VisualWorks, I wonder if
> the Pharo version secretly does some additional work for SETI:
> - Starting the JVM:
>         VisualWorks 0.7 seconds
>         Pharo 7 to 8 seconds
> - A benchmark using some methods of java.io.BufferedReader and
> java.util.StringTokenizer:
>         VisualWorks 114 milliseconds
>         Pharo 12 to 13 seconds
>
> I have not yet found the reason. The TimeProfiler is not very helpful, as
> its 1 millisecond resolution is too coarse. It would be nice if it had
> microsecond resolution. From the TimeProfiler results, it seems that
> calling
> a JNI method with NativeBoost is extremely slow, but I don't trust those
> profiles too much.
>
> So, give it a try, and if you find something useful concerning the bad
> performance, please send me a message.
>
> Best regards,
> Joachim Geidel
>
>
>
>
> --
> View this message in context:
> http://forum.world.st/ANN-JNIPort-for-Pharo-3-0-alpha-tp4750750.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>
>
>
>
>
> --
>
> www.tudorgirba.com
>
>
>
> "Every thing has its own flow"
>
>
> ------------------------------
>    <http://www.avast.com/>
>
> Ce courrier électronique ne contient aucun virus ou logiciel malveillant
> parce que la protection Antivirus avast! <http://www.avast.com/> est
> active.
>
>


-- 
www.tudorgirba.com

"Every thing has its own flow"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-users_lists.pharo.org/attachments/20140327/ae328820/attachment.html>


More information about the Pharo-users mailing list