JNI MMX and Java long arithmetic

I am having trouble with a JNI call to a C program which contains assembler which uses an MMX operation as follows:
static inline int diffPixels(int rgb1, int rgb2) {
register int temp;
__asm__ __volatile__ (
"movd %1, %%mm1\n\t"
"movd %2, %%mm2\n\t"
"psadbw %%mm1, %%mm2\n\t"
"movd %%mm2, %0\n\t"
: "=r" (temp)
: "r" (rgb1), "r" (rgb2)
: "mm1", "mm2", "cc"
return temp;
After the JNI call returns, the first Java long arithmetic fails. I believe the failure is that when a method on a Java object returns a long the result is 0x8000000000000000 rather than the correct value.
To use pure Java means my response to a user action is 9 seconds rather than 3 seconds with the JNI call which is why I want to persist with it. At present I am doing an arbitrary long multiply after the JNI call to "fix" long arithmetic but I am afraid this won't work if there is a context switch to another java thread in the middle of the JNI call.
The test environment is a 3 Gigahertz Pentium 4 running Linux kernel 2.6.9 and Java version 1.4.2_06-b03.
Can anyone explain this behaviour ? It took me days to isolate the problem.

Hi,
Is it absolutely necessary to declare temp as register ?
How about adding a lock directive at the beginning of your asm ?
--Marc (http://jnative.sf.net)                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Set Java Object with Java Long Object from JNI

    Hi,
    i am getting crazy with the jni...
    in Java i have the follwoing:
    public class blabla{
    Object myObject;
    i chose Object cause the return value from native is not known
    in case for a long value i handle it like this :
    //get the Long class
    jclass LongCls = env->FindClass("Ljava/lang/Long;");
    jmethodID jmid = env->GetMethodID(LongCls, "<init>","(J)V");
    //create an Long Object with the long return value
    jobject LongObj = env->NewObject(LongCls,jmid,longreturnvalue);
    //set Long Objekt - doesnt work!(jclazz is the class of the return Object of the blabla class)
    jfid = env->GetFieldID(jclazz, "myObject", "Ljava/lang/Object;");
    env->SetObjectField( returnobjectofblabla,jfid,LongObj );
    the long value is set fine in the Long Object but i cant set the Long Object with the SetObjectField method into the Object myObject.
    Java is shown that the myObject contains a Long Object but the long value of the Long Object is totally wrong and doesnt equal to the long value which has been set.But setting the value works fine- any ideas or solutions?
    Thank you!

    charliess wrote:
    sometimes i really wonder about the answers in this forum - until now i got not one answer that helps me, even i tried to write down the problem very detailed...
    Sometimes I wonder about people who jump onto a site and immediately assume that
    1. They are the most important person in the world
    2. That they deserved the absolute undivided attention of absolute everyone.
    3. That everyone should be absolutely polite to them and provide them with perfect answers.
    4. Feel free to denigrate and posit their own opinion on everything while ignoring anything else that anyone else says.
    5. Expect that everyone else should understand their poorly worded questions.
    Myself I find such individuals extremely amusing. Although they seldom stick around long here. At least not under their original alias.
    plaz tel me how to realise your error checking?example plz
    You start by having at least a basic understanding of C/C++ and java.
    Then you read the JNI documents, all of them, for each method that you are using.
    Then you write code such that it actually reflects the documents. For example you check return types. And probably deal with the possibility that JNI methods might throw exceptions.
    as far as i know the jni methods like getfieldids and so on throw exceptions other like stObject dont do that the just return nothing
    i can see all exceptions in my Java console thats not the Problem, setting the Long Object does not throwing a exception btw->
    Myself I wouldn't expect that a JNI exception would show in the java console. Could I suppose though.
    However nothing so far would suggest that an exception is being thrown. That however doesn't alter the fact that you must still write the code such that it could happen.
    is it possible in general to set an java Long Object created in C(native) into a Object type (Object) overgiven as parameter in my JNI function with the setObject method?
    Is it possible that you could actually follow my previous request and create some code that actually runs instead of cut and pasting whatever you feel like?
    plz answer also with code and examples i did the same for you...No you didn't. You posted something which would not compile and quite possibly doesn't represent your actual code at all.
    And please note that we do not get paid to do this. If you want to pay someone to solve your problem then there are sites for that.
    Paying someone allows you to make all sorts of demands. The more you pay the more people will put up with.
    If you don't want to pay and do in fact want free answers then it will probably be in your interest to
    1. Be polite
    2. Answer the questions that have been asked of you.

  • I have been getting java.lang.ClassNotFoundException: ZeroApplet.class and java.lang.ClassNotFoundException: JavaToJS.class crashes with JRE version 1.6.0_26-b03-384-10M3425 VM executing a Java Applet. Is Apple aware of this problem? No longer supported?

    My web page uses a Java Applet to allow my visitors to replay chess games; the Chess Viewer Deluxe applet was written by Nikolai Pilafov some time ago and has been working properly for some time (until recently). I don't monitor this part of my site regularly so I am not sure when it began to fail. On his web site [http://chesstuff.blogspot.com/2008/11/chess-viewer-deluxe.html] he has a link to check LiveConnect object functionality (which fails for OBJECT tags). His recommendation is to "seek platform specific support which might be available from the JRE developers for your platform".
    I have been getting java.lang.ClassNotFoundException: ZeroApplet.class and java.lang.ClassNotFoundException: JavaToJS.class crashes with JRE version 1.6.0_26-b03-384-10M3425 VM executing a Java Applet. Until I checked the LiveConnect object functionality, I was unable to identify the source of the console error messages. This does seem to be the smoking gun.
    Is Apple aware of this problem? Are these classes no longer supported? Has anyone else had this problem? You can attempt to recreate the problem locally by going to my web page: http://donsmallidge.com/DonSmallidgeChess.html
    Thanks in advance for any help you can provide!
    Abbreviated Java Console output:
    Java Plug-in 1.6.0_26
    Using JRE version 1.6.0_26-b03-384-10M3425 Java HotSpot(TM) 64-Bit Server VM
    load: class ZeroApplet.class not found.
    java.lang.ClassNotFoundException: ZeroApplet.class
        at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:211)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:144)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:662)
        at sun.applet.AppletPanel.createApplet(AppletPanel.java:807)
        at sun.plugin.AppletViewer.createApplet(AppletViewer.java:2389)
        at sun.applet.AppletPanel.runLoader(AppletPanel.java:714)
        at sun.applet.AppletPanel.run(AppletPanel.java:368)
        at java.lang.Thread.run(Thread.java:680)
    load: class JavaToJS.class not found.
    java.lang.ClassNotFoundException: JavaToJS.class
        at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:211)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:144)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:662)
        at sun.applet.AppletPanel.createApplet(AppletPanel.java:807)
        at sun.plugin.AppletViewer.createApplet(AppletViewer.java:2389)
        at sun.applet.AppletPanel.runLoader(AppletPanel.java:714)
        at sun.applet.AppletPanel.run(AppletPanel.java:368)
        at java.lang.Thread.run(Thread.java:680)

    I just went up to check the LiveConnect object functionality page AND IT WORKED THIS TIME! I must confess, this is very mysterious. I will do some more checking and reply here if I can determine why it is working now (and more importantly, why it didn't work before).

  • HT1338 OSX 10.4.11 update quicktime. Browser says out of date. Updater says up-to-date. Is this version no longer supported. How to update QuickTime and Java then?

    OSX 10.4.11 Updates to QuickTime and Java.
    Browser says out of date. Updater says up-to-date. Is this version no longer supported?
    How can I update QuickTime and Java then without upgarding? I wish to keep a back channel to OS9

    Mac OS X Tiger was discontinued years ago, and if Software Update doesn't detect any new update, it's because you are running the latest Java and QuickTime version for Tiger.
    Apart from that, I see that you have a G5, so the most recent Mac OS X version you can use is Mac OS X Leopard, another version that it's (or it's going to be) discontinued soon. PowerPC support is completely dead now, and if you want the most recent QuickTime and Java versions, you will need a Intel-based Mac with OS X Lion or Mountain Lion, that have got the latest Java 6 versions and they are compatible with Java 7

  • J2me and java card, need help to communicate

    we are trying to put together a reader to read smartcards using j2me and we figure that it would be easiest if we could develop it to work with java cards rather than standard smart cards, the problem is we get garbage when we communicate to it, the chip sends us crap, any suggestions what might be wrong, any calls we might be missing, has anyone worked with j2me and java cards or smart cards, any help would be appreciated.
    einar

    .... reader app and the ME behind it .... smells like mobile ....
    First of all - if you want to have one mobile application running on this just make sure that whatever is written in ME can use drivers from the reader chip ....
    Workin on the PC is something completely different. There was one good example how to develop one host application in Java provided with the JCOP tools long ago ... I don't know if this is now in the new Eclipse tools.
    But - there was a small API provided that can give you good hints what to do - and - once you have it on the reader side - you can easily integrate ME methods with this ...

  • Why not Deprecate java.util.Date and java.util.Calendar

    With the introduction of java.time, why did you not flag java.util.Date and java.util.Calendar. These classes have been a bane to every Java developer and should never be used again with the introduction of Java 1.8.

    Adding the @Deprecated annotation would only just provide a warning about an old API and recommendation to the developer(s) to no longer use it. Doing so would not break any existing library out there; in fact quite a number of constructors and methods on the Date class have already been flagged deprecated.
    The new java.time package is far superior to Date/Calendar.

  • Short dump Error during VM container communication between ABAP and JAVA.

    Hello All,
    Can anybody please help with resolving the following issue:
    Short dump is displayed, when I try to insert CRM product (type: material) in the document (opportunity). This CRM product was created in CRM directly.
    When I try to insert ECC migrated material, everything works fine.
    Here is the details of dump:
    Short text
        Error during VM container communication between ABAP and JAVA
    Information on where terminated
        Termination occurred in the ABAP program "SAPLPRC_INT" - in "GET_PRICING_PROCEDURE_INFO".
        The main program was "SAPMHTTP ". In the source code you have the termination point in line 100 of the (Include) program "LPRC_INTF35".
    Thank you!

    hi Willie,
         this is the dump, and i have used the t-code sm52 . the VMC is not active.
    |Short Text                                                                                        |
    |    Error during VM Container communication between ABAP and JAVA.                                |
    |What happened?                                                                                    |
    |    The current program had to be terminated because of an                                        |
    |    error when installing the R/3 System.                                                         |
    |    Error in the RFC layer.                                                                       |
    |What can you do?                                                                                  |
    |    Note which actions and entries caused the error to occur.                                     |
    |                                                                                                  |
    |    Consult your SAP administrator.                                                               |
    |                                                                                                  |
    |    Using transaction ST22 for ABAP dump analysis, you can view, manage,                          |
    |    and retain termination messages for longer periods.                                           |
    |Error analysis                                                                                    |
    |    An error has occurred in the RFC layer during communication between                           |
    |    JAVA and the ABAP stack. This prevents data from being passed correctly                       |
    |    between the two stacks.                                                                       |
    |                                                                                                  |
    |    Message    = TH_VMC_SERV_NOT_ACTIVE                                                           |
    |    Return code = -1007                                                                           |
    |    Pointer    = "000007DD348F6138"                                                               |
    |How to correct the error                                                                          |
    |    Check whether the VMC is active on your application server. To do this,                       |
    |    run transaction SM52. If the VMC is not active, contact your SAP                              |
    |    administrator.                                                                                |
    Regards
    Charles

  • UDP DatagramPacket sent between C (client) and Java (server)

    Hi,
    I have a problem sending a struct from C to Java UDP server.
    In the C (client) program, the struct is defined as
    typedef strurct dataType_s {
    char name[52];
    char add[52];
    long x;
    long y;
    } dataType;
    dataType data;
    strcpy(data.name, "sun");
    strcpy(data.add, "com");
    data.x = 100;
    data.y = 50;
    sendto(sock, (struct dataType*)&dataType, sizeof(dataType), (struct sockaddr*)&dest, sizeof(dest))
    In the Java server side, I have the following code.
    byte[] buffer = new Byte[1024];
    DatagramPacket packet = new DatagramPacket(buffer, 1024);
    udpSock.receive(buffer);
    byte[] data = buffer.getData();
    String name = new String(data, 0, 52);
    String add = new String(data, 52, 52);
    String _xx = new String(data, 104, 4);
    String _yy = new String(data, 108, 4);
    Byte x = new Byte(xx.getBytes());
    long x = _x.longValue();
    Byte y = new Byte(yy.getBytes());
    long y = _y.longValue();
    I am having problem to read the contents of x and y above. The string name and add received by the server
    are correct. However, I receive garbage value
    for x (long) and y (long). In fact, I get expection
    that I cannot create Byte x and Byte y as shown
    above. Any idea of how to send a mixture of types
    from C/C++ to Java server?
    Thanks a lot.
    Kelvin ([email protected])

    sendto(sock, (struct dataType*)&dataType,
    sizeof(dataType), (struct sockaddr*)&dest,
    sizeof(dest))You have to check the alignment of your structs. You can't be sure that a long takes up four bytes. It can very well be 8 bytes or something else depending on your settings at compilation.
    udpSock.receive(buffer);
    byte[] data = buffer.getData();I suppose this is a typo, but of course you should use packet not buffer here.
    >
    Byte x = new Byte(xx.getBytes());
    long x = _x.longValue();
    Byte y = new Byte(yy.getBytes());
    long y = _y.longValue();
    in my opinion its easier to use a DataInputStream instead:
    DataInputStream in = new DataInputStream(new ByteArrayInputStream(data));
    int y = in.readInt();
    Notice that a long in Java is 8 bytes. A C long corresponds to a Java int.
    /Per-Arne

  • 9IAS and Java 1.4.2_06

    Hi all,
    I have installed 9IAS and Java 1.4.2 on Solaris 8, as per Oracle's own documentation I have changed the JDK to point to my Java installation in /usr/j2se in order for out Java based application to work, however the EM process will now not start it time's out and aborts. This means I am unable to access the website I just recive an Internal Server error.
    Any ideas on how to get Oracle to use the new Java?
    Thanks.

    Hi,
    I had this same issue when upgrading from 9.0.4 to 10.1.2.2. Someone else in the forum had a solution. You could probably search for it. However, here are the details:
    The fillowing are the notes from Oracle:
    Applies to:
    Oracle Discoverer - Version: 10.1.2.2 to 10.1.2.3 This problem can occur on any platform.
    Symptoms
    The user interaction performance using Discoverer Plus 10g (10.1.2) when configured with Sun java plug-in (JRE/JVM) 1.6.0_03 or higher.
    Every action in Discoverer takes longer. For example:
    displaying the Create/Open Workbook wizard
    displaying the Help > About window.
    The problem does not exist with JInitiator or with Sun plugin 1.4 or 1.5 and earlier versions of 1.6
    JRE 1.6.0 - works correctly, runs with 1.5.0-like speed JRE 1.6.0_01 - works correctly JRE 1.6.0_02 - works correctly JRE 1.6.0_03 - here the problem is observed for the first time. The issue is then observed in all subsequent versions (e.g., _04, _05, _06, _07 and the new_10)
    The problem does not exist when an entry for the Discoverer server exists in the local hosts file on the client PC (C:\WINDOWS\system32\drivers\etc\hosts).
    Cause
    Sun's Java plug-in performs reverse DNS lookups when connecting to the Application Server. This can be observed with a network sniffer trace (Wire Shark).
    There is a change in the DNS handling in Sun plug-in 1.6.0_03 and higher.
    This issue may be more prevalent if you are accessing Discoverer Plus via a firewall, proxy server
    Solution
    To implement the solution, please execute the following steps:
    Ensure the external facing IP address of the Discoverer server has a reverse DNS entry in the DNS server.
    For example:
    nslookup <IP address> must resolve to the <machinename.domainname>
    and
    nslookup <machinename.domainname> must resolve to <IP address>
    An alternative or temporary solution would be to add an entry to the local PC host file as described above.
    Hope this helps,
    Nancy

  • Java Web Start and Java Preferences

    I am having trouble with Java Web Start and Java Preferences. I have tried reinstalling the update with the link http://www.apple.com/downloads/macosx/apple/application_updates/javaformacosx105 update6.html but to no avail. What else can be done ? Moreover the file /System/Library/Frameworks/JavaVM.framework/Versions/A/ seems to be in place, but Java Web Start wont open and Java Preferences can't access cache files. Any ideas about how to resolve this? I have been having issues with Java for a long time and have already done a clean Leopard reinstall and all the Combo updates. Java Web Start and Java Preferences worked correctly for a while after that but seem to have gone haywire again.

    bump

  • How can I do to share the array elements between "C" and "Java"

    Hi,all
    I want to implement the function about this: c and java between JNI can share the same data area. For example, when change the value of the array in java, i can get the same value in c.
    I use the function:Xxx* GetXxxArrayElements(JNIEnv env, jarray array, jboolean isCopy)
    But i find that the "isCopy" is JNI_TRUE which means that i get the pointer which point to a copy,so i can't get the change
    in Java later.
    How can I do?Can i set "isCopy" with JNI_FALSE??
    Thank u.

    No, you can't. isCopy is of type jboolean*, and the value is just set by the call to inform you whether the data was copied or not, but you cannot infulence that.
    In fact, the VM might store an array of primitives in a different way as C, and this routine has to convert between the two representations. In this case copying is always required.

  • XMLsocket and java server

    Hi
    I would like to developp a client which connects on a java
    server.
    When i run my program on my developement computer, it works
    (maybe because the server and the flex application are on the same
    machine.)
    But when i want to run the flex application from another
    computer I can't manage to get connected...
    First question : is it possible to connect flex appli to java
    server through internet or network
    Example
    123.2.2.2:18000 this is the (false) ip on my javaserver (the
    port 18000 is open)
    and I want to connect to it with a flex application from
    another computer.
    Thank you for you help
    Nicolas

    Hi,
    I discovered your topic too late so I made a duplicate topic
    about socket and java server.
    I spend quite a long time trying to solve this problem and I
    don't have the solution !
    It should be a common question so I guess the answer is so
    easy than I can't see it !!
    TechNote seams to say that you have to put the
    crossdomain.xml file on the root of the (html) server and not on
    the server where the flash file is.
    The problem is that I don't have or need a web server as my
    java server is doing the job. So I don't think it is the answer.
    Did you find the answer ?
    THX
    Jean-Yves

  • I am using a Application in c dll calling from jni jar by java applet in firefox version 19.0 , the problem is click event message box will not working correct

    I am using a Application in c dll calling from jni jar by java applet in firefox version 19.0 , the problem is button click event message box or popup window will not working correctly. Please any one suggest me the steps to overcome this not responding or slowness in the responding problem of Button click event.

    Hello,
    In Firefox 23, as part of an effort to simplify the Firefox options set and protect users from unintentially damaging their Firefox, the option to disable JavaScript was removed from the Firefox Options window.
    However, the option to disable JavaScript was not removed from Firefox entirely. You can still access it from about:config or by installing an add-on.
    '''about:config'''
    # In the address bar, type "about:config" (with no quotes), and press Enter.
    # Click "I'll be careful, I promise"
    # In the search bar, search for "javascript.enabled" (with no quotes).
    # Right click the result named "javascript.enabled" and click "Toggle". JavaScript is now disabled.
    To Re-enable JavaScript, repeat these steps.
    '''Add-ons'''
    You can alternatively install an add-on that lets you disable JavaScript, such as
    *[https://addons.mozilla.org/firefox/addon/noscript/ No-Script] (to disable JavaScript on a per page basis, as required)
    *[https://addons.mozilla.org/firefox/addon/quickjava/ QuickJava] (to easily disable and enable JavaScript, automatic loading of images, and other content)
    Thank you and I hope this helps!

  • OpenSSL and java interaction

    Hi
    I am working on a project which requires me to use crypto library of OpenSSL. The calling program is Java. Does anyone have examples of OpenSSL interaction and java ?
    Thanks
    p

    In order of worst to best ideas for doing cryptography that is (or at least should be) compatible with
    OpenSSL:
    System.exec to call openssl binaries
    JNI to wrap calls to OpenSSL methods
    Not-Yet-Commons-SSL has some OpenSSL compatible stuff: http://juliusdavies.ca/commons-ssl/
    Just use the Java Cryptographic API using algorithms/params that are compatible with OpenSSL.
    It seems odd to have a requirement for a project that is written in Java to have to use a C library. If you want open source (free $$) and Java, go with BouncyCastle or Mozilla's JSS (which is FIPS approved, BTW).
    It's not too hard to find a common middle ground between such crypto toolkits as Microsoft CAPI, NSS, and OpenSSL.

  • Make native code and Java VM interact

    Hi all,
    I am building a native components (Delphi and C++) using JNI.
    Currently my components involve a Java GUI.
    It loads the JVM, then request for that Java Object GUI.
    When the interface is created, I need to get back information
    from what the user can type in.
    However, the native code doesn't wait. It runs and continues right after
    the creation of the GUI, thus causing me trouble (trying to get
    null objects).
    Is there a way to make the native code wait for a java command from
    the interface, or is there a way to make both part of the component
    (java / native) to communicate and interact ?
    Any help would be appreciated.
    Thanks
    Regards,
    Florent

    There are quite a few options here, and this may not
    be the best, per se, but you could make a blocking
    call from the JNI to a Java method. That Java method
    will only return after whatever you want done in the
    interface has completed.Thanks for your reply. Is there other solution in the JNI itself,
    using the JNIEnv Object ?
    Else, I'll try to use that solution.
    Regards,
    Florent

Maybe you are looking for

  • :hover not working in Firefox. Help!

    Hi everyone, I created a rollover menu using :hover in CSS. The menu sits in a one-row six-column table on the page. The menu displays and works perfectly in IE6 and IE7. However, it falls apart in Firefox. The site is at http://www.labellacenter.com

  • Cumulative KF

    Can someone give examples for a cumulative and non cumulative KF pls.

  • Help connecting my VCR/DVD combo and my Wii

    I have a TV with a built in VCR (that doesn't work), so I have VCR/DVD combo. I would like to hook up my VCR/DVD combo and my Wii but I am not sure how with my HD DVR box. The HD DVR uses the only audio/video plugs that are on the TV. Any help would

  • CORBA - Oracle DBMS acting as Client in a relation Client - Server

    Hi, I'de like to invoke some services in an Transaction Server from my Oracle 8i Database (8.1.6) wich is in another machine. Is this possible in Oracle, and if so, are there any resources explaining how can i achieve this? Note that the transaction

  • Code change management in JDeveloper & BPEL Process Manager

    Hi, I am finding that when we make any changes such as adding more parameters to a database adapter query, internally generated variable / message type names change, and you have to re-do most of the work downstream of the database adapter. It seems