JNI_CreateJavaVM returns JNI_ENOMEM (-4) from different versions of the jre

I have created a JNI dll, invoked from a VBA Excel add-in to execute Java code. This works fine until I introduce the -Xmx parameter as a vm option.
Before creating the VM, I use a VirtualAlloc/Free loop to make sure the -Xmx parameter is not too large, decrementing it by 2MB each time until an allocable amount is found (thanks to [jurberg's post|http://forums.sun.com/thread.jspa?forumID=37&threadID=5220601]; my version, slightly modified, is posted below). I then pass that value to the VM via the -Xmx option.
This works great when I am using a JRE 1.6 installed in the "C:\Program Files\Java\*jre1.6.0_xx"* directory. When the same* JRE version is installed in the "C:\Program Files\Java\*jre6*" directory, JNI_CreateJavaVM fails with JNI_ENOMEM. Calling GetLastError returns 0 ("operation completed successfully"). Using a *1.5 JRE*, this also fails, returning JNI_ENOMEM, but GetLastError returns error code 6 ("the handle is invalid").
A little about my platform:
     Windows XP Pro
     Building JNI dll using Microsoft Visual C++ 2008 and 1.5 JDK
I have multiple JREs and JDKs installed on my system as this is a dev machine, but I have the same problem on a non-dev machine running XP Home.
Here is a snippet of my code used to create the vm:
     // create the JNI structures
     const int numOptions = args.size();
     JavaVMInitArgs vm_args;
     JavaVMOption* options = new JavaVMOption[numOptions];
        log("Creating JVM with parameters:");
        int i = 0;
        char * nextArg;
        for (itr=args.begin(); itr != args.end(); itr++) {
            nextArg = new char[(*itr).length() + 1];
            strcpy(nextArg, (*itr).c_str());
            options.extraInfo = NULL;
options[i++].optionString = nextArg;
log("\t" + string(nextArg));
     vm_args.version = CRUSH_JNI_VERSION;
     vm_args.options = options;
     vm_args.nOptions = numOptions;
     vm_args.ignoreUnrecognized = JNI_FALSE;
// load and initialize the Java VM, and return a JNI interface pointer
JNIEnv* env = NULL;
     err = (*createVM)(&jvm, (void**)&env, &vm_args);
     // err is -4 (JNI_ENOMEM) in the cases described above
Does anyone have any suggestions on what is going on here and how I might make this code stable for all 1.5 and 1.6 JREs, regardless of where they are installed?
Thanks in advance,
Sarah
Code to determine max -Xmx value:static const DWORD NUM_BYTES_PER_MB = 1024 * 1024;
bool canAllocate(DWORD bytes)
LPVOID lpvBase;
lpvBase = VirtualAlloc(NULL, bytes, MEM_RESERVE, PAGE_READWRITE);
if (lpvBase == NULL) return false;
VirtualFree(lpvBase, 0, MEM_RELEASE);
return true;
int getMaxHeapAvailable(int permGenMB, int maxHeapMB)
DWORD          originalMaxHeapBytes = 0;
DWORD          maxHeapBytes = 0;
int               numMemChunks = 0;
SYSTEM_INFO          sSysInfo;
DWORD          maxPermBytes = permGenMB * NUM_BYTES_PER_MB;     // Perm space is in addition to the heap size
DWORD          numBytesNeeded = 0;
GetSystemInfo(&sSysInfo);
// jvm aligns as follows:
// quoted from size_t GenCollectorPolicy::compute_max_alignment() of jdk 7 hotspot code:
// The card marking array and the offset arrays for old generations are
// committed in os pages as well. Make sure they are entirely full (to
// avoid partial page problems), e.g. if 512 bytes heap corresponds to 1
// byte entry and the os page size is 4096, the maximum heap size should
// be 512*4096 = 2MB aligned.
// card_size computation from CardTableModRefBS::SomePublicConstants of jdk 7 hotspot code
int card_shift = 9;
int card_size = 1 << card_shift;
DWORD alignmentBytes = sSysInfo.dwPageSize * card_size;
maxHeapBytes = maxHeapMB * NUM_BYTES_PER_MB;
// make it fit in the alignment structure
maxHeapBytes = maxHeapBytes + (maxHeapBytes % alignmentBytes);
numMemChunks = maxHeapBytes / alignmentBytes;
originalMaxHeapBytes = maxHeapBytes;
// loop and decrement requested amount by one chunk
// until the available amount is found
numBytesNeeded = maxHeapBytes + maxPermBytes;
while (!canAllocate(numBytesNeeded) && numMemChunks > 0)
numMemChunks --;
maxHeapBytes = numMemChunks * alignmentBytes;
numBytesNeeded = maxHeapBytes + maxPermBytes;
if (numMemChunks == 0) return 0;
// we can allocate the requested size, return it now
if (maxHeapBytes == originalMaxHeapBytes) return maxHeapMB;
// calculate the new MaxHeapSize in megabytes
return maxHeapBytes / NUM_BYTES_PER_MB;

I have a similar, but I think much simpler problem. Namely, I get ENOMEM's when as far as I can tell there's plenty of memory available. It seems to have something to do with how Windows is configured, although I've never been able to determine what it could be.FWIW, in my case, I found that if I loaded my JNI dll into a console process, the max heap requested was always allocated. But when loading into Excel, the same amount would be too much. This was partly due to the fact that Excel has its own memory management, limiting the amount of memory workbooks can use. Also, it could be due to the vm not being able to reserve a contiguous chunk of memory for the max heap space.
Why (and how) separate the permanent generation space from the rest of the max heap? It seems you'll fail if you can't get that much space (which is the why) but how did you determine what it is?The VM uses the perm gen space plus the requested max heap space when attempting the VirtualAlloc call to verify that it can allocate the specified amount. The default perm gen is 64MB, but that can be changed via the -XX:MaxPermSize vm parameter, so I allow for any requested value.
What's CRUSH_JNI_VERSION? It's not in any .h file I have.That's just my own constant defined to be either JNI_VERSION_1_4 or JNI_VERSION_1_6.
Why are you messing with the bootclasspath? (I suspect you're adding something to it. Generally the VM can find it's own damn classpath).Yep, I'm adding the 2.1 JAXB jar to the bootclasspath because earlier 1.6 distributions included JAXB 2.0 and I needed 2.1.
-sarah

Similar Messages

  • Can't download a song from different version of the same group/album

    Well, I'll try to be as specific as I can. Here it goes: There are two versions of Muse's album "The 2nd Law" - Normal and Deluxe. I've bought Madness song from Normal version, then I previewed the whole album, liked it and decided to "Complete the album". But I did that with Deluxe version - not Normal.
    As a  result I have incomplete Deluxe album (without Madness song) and just lone song in Normal album... There's no way to download Deluxe version of Madness now. It says "Purchased" but doesn't allow me to download it. Hiding/deleting Normal song doesn't help either.
    Is there any way to complete Deluxe album now? Or replace Normal version of Madness song with Deluxe one?
    And before you asked - there's slightly (but audible) better quality of the recording in the Deluxe version.

    You can try contacting support thru this link http://www.apple.com/support/itunes/contact/
    so they can assist you with this.

  • Registry.lookup() return Remote object from different ip address

    I've got this error using
    Registry reg = LocateRegistry.getRegistry(serverName, Registry.REGISTRY_PORT);
    service = (ILogin) reg.lookup("service");and when I use debugger I've got this
    RegistryImpl_Stub[UnicastRef [liveRef: [endpoint:[10.240.161.66:1099](remote),objID:[0:0:0, 0]]]]
    Proxy[ILogin,RemoteObjectInvocationHandler[UnicastRef [liveRef: [endpoint:[10.240.161.54:2074](remote),objID:[-4308ea07:116adade605:-7fff, 9133145996543447416]]]]]Why the Registry return a service from different IP address ?
    I've run this code for several times and it works. But today it cannot connect to the RMIServer.
    Any idea ?

    Thanks, i found my missing prppertis is
    // optional. Defaults to localhost. Only needed if web server is running
    // on a different host than the appserver
    props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
    // optional. Defaults to 3700. Only needed if target orb port is not 3700.
    props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
    to set the port and host back

  • Accessing an itunes library from different version of itunes

    I recently installed yosemite and with that came iTunes 12 since I have an iPhone 6 with 8.1 I will keep iTunes 12. But I have been having major issues with syncing video files to my iphone 4S(ipod touch now) 7.1.2JB. The files never sync or appear to sync and then when I go to view them on the iphone the size shows up as zero. So I feel like if I go back to an older version iTunes all will be right in the world. I just wonder will I have any issues if I have different versions accessing the itunes library files? Planning on using iTunes 11.4 and iTunes 12.
    TIA

    Open the iTunes preferences, click on the Advanced tab, turn off the option to automatically copy the music to the iTunes Music folder, and then drag the library on the Windows partition to the open iTunes window. This will not transfer playlists and other metadata and will not keep the Mac version of the library in sync.
    (33924)

  • Different versions of the same app on the app store

    Is it possible to let users download the different versions of the same app from the App store,( even though I have not seen it but just wonder whether it is possible) ?
    If not then can we have different releases of the same product with different feature set.
    This question is applicable for iPhone as well.
    Thanks

    Wouldn't do you any good, as you need to be a registered developer to use the forum. Just contact one of the developer's of an app you're interested in and ask the developer directly.

  • EJB was compiled by a different version of the Weblogic Server

    I got the following error message when attempt to startup weblogic server to deploy my ejb.
    <The EJB deployment named: ejb_test was compiled by a different version of the WebLogic Server.>
    <... cannot be redeployed while the server is running ...>
    Anybody has any clue about this? TIA.
    Cheers. KokHwa.

    See inline:
    KokHwa wrote:
    I got the following error message when attempt to startup weblogic server to deploy my ejb.
    <The EJB deployment named: ejb_test was compiled by a different version of the WebLogic Server.>
    Exactly what is says. You are deploying an EJB that was compiled with a
    different Weblogic version (might be a different SP or a previous
    version) that the one you are deploying on. Recompile with the same
    version as the deployment and it should be fixed.
    <... cannot be redeployed while the server is running ...>
    This message is the same. Because you have some of the classes of the EJB
    in your server classpath you will not be able to redeploy that EJB but apart
    from that it's harmless. To redeploy after changing the EJB you'll have to
    restart the server.
    >
    Anybody has any clue about this? TIA.
    Cheers. KokHwa.
    --dejan

  • Updated pages on 11/25 but it in application it is saying there is an new version for $19.99.  Is this a different version or the same?

    updated pages on 11/25 but it in application it is saying there is an new version for $19.99.  Is this a different version or the same?

    Launch Pages.
    From the Pages menu bar click Pages > About Pages
    The latest version available is 5.0.1
    If it's 5.0.1, your currently installed copy of Pages is up to date.

  • Versioned deployments: how to deploy different version of the same app ?

    I 'd like to deploy on a server (single instance) different versions of the same web application, say:
    webapp1.war
    webapp2.war
    webapp3.war
    The wars have the same ContextRoot.
    It is possible to version them with an attribute in MANIFEST.MF, but is it possible to have the N applications ACTIVE and running ? I'd like that one IP will be served from webapp1, another IP from webapp2, another IP from webapp3, etc.

    It may your 'requirement' but I have serious doubts that the app review team will approve it. Save yourself the waste of time and follow my original suggestion of one app. That's the only correct 'method' (w/IAP of course) that will have a chance of success.
    See the iOS Human Interface Guidelines and the App Review Guidelines before you go any further. In the case where you need 'official' guidance, consider using support event w/DTS

  • The upgrade patch cannot be installed by the windows installer service because the program to be upgraded may be missing, or the upgrade patch may update a different version of the program

    trying to install an update patch for Citrix xendesktop 7.5 and the error when I click on the msi patch is "the upgrade patch cannot be installed by the windows installer service because the program to be upgraded may be missing, or the upgrade patch
    may update a different version of the program"
    The application was installed 2 days prior and works fine but the patch will not install.
    Any ideas?
    Wendy2014

    Yes let's see if there is any error occurs in installation log.
    Meanwhile from the error message, the possible cause is that a part of the application is missing such as a registry key with app version. In this situation you can first test to reinstall/repair the application though it is still working fine - see if issue
    persists after reinstall the app.
    Meanwhile you could also contact Citrix about this issue. It may be a common issue and Citrix may provide a quick fix for it. 
    If you have any feedback on our support, please send to [email protected]

  • Hi can someone tell me if it is possible to have two accounts (from different countries) in the same laptop?

    Hi can someone tell me if it is possible to have two accounts (from different countries) in the same laptop?

    Hi...
    The issue is that your credit or debit card credentials must be associated with the same country where you reside to make purchases.
    "Although you can browse the iTunes Store in any country without being signed in, you can only purchase content from the iTunes Store for your own country. This is enforced via the billing address associated with your credit card or other payment method that you use with the iTunes Store, rather than your actual geographic location."
    From here >  The Complete Guide to Using the iTunes Store | iLounge Article
    Billing policy is the same for both the iTunes as well as Mac App Stores.

  • Data from different databases in the same report.

    Hi Everyone,
    I am trying to build a reconciliation report in which I need to show the data from the source and target, side by side.
    Source and target are both different databases, although being oracle only
    Whenever a new data model is created, it gets attached to a data source and in the report we need to choose a specific data model.
    Can we have data from different databases in the same report ?

    Yes, it is possible.
    One way Is to use dataTemplates. There you can make queries from any number of different databases (The max I have done is 5).
    It looks something like that:
    <dataTemplate name="NameOfTemplate">
    <dataQuery>
         <sqlStatement name="Q1" dataSourceRef="Connection1">
              <![CDATA[     select * from table1]]>
         </sqlStatement>
         <sqlStatement name="Q2" dataSourceRef="Connection2">
              <![CDATA[     select * from table2]]>
         </sqlStatement>
      </dataQuery>
      <dataStructure>
         <group name="RESULT1" source="Q1">
              <element name="P_FIRST_NAME" value="P_FIRST_NAME"/>
         </group>
         <group name="RESULT2" source="Q2">
              <element name="P_DATE" value="P_DATE"/>     
         </group>
      </dataStructure>
    </dataTemplate>dataStructure is very important when you get data from different places, if you don't define those elements, then only the result from Q1 is shown.
    The second possible way is to make as two different data models, each containing their own query and then set Main Data Set as concatenated SQL Data Source.
    Best of luck,
    Evelyn

  • How to update data in database from different region of the same page

    Hi,
    I have pepared two regions of tabular form based on the same table,each region is selecting different columns of the same table.
    I want to update the values from different regions in the database using single submit button.
    Regards
    Shashi

    I presume that the two regions are working fine with their individual buttons and your issue is how to make them both save with one button.
    Here is how
    a. You will have 2 ApplyMRU and 1 ApplyMRD processes for each of the regions. Right? Lets say you have 2 "Save" (i.e. label=Save) buttons, one has name SUBMIT and the other SAVE ( SUBMIT and SAVE being the requests that will be sent when they are clicked , respectively)
    b. Make the Display condition on one of the buttons 'Never'. Now it won't show when you run the page. Lets say you made SAVE's conditional Display 'Never'
    c. Go and change the condition on all ApplyMRU and ApplyMRD processes from "When Button Pressed" to "Request is contains in Expression1". In Expression1 enter SUBMIT,SAVERegards

  • Mail sorting messages from different people in the same thread?

    I have this weird issue. It's happened before but I figured I might be able to figure this out.
    I got a response from somebody this morning and whats happening is, when I click on his response, the email shows up on the right like it should. However, ths email is from "Floyd" and shows as email "2". It shows another email below it in the "thread" from "Taryn" and has absolutely nothing to do with this email. The only similarities are the subject line which says "Poster". The "First" email from Taryn is from April. It seams as if it's sorting the emails by subject line. I don't want emails from different people in the same thread. Any thoughts on how to fix this issue? Image attached.
    OSX 10.8.4

    This question is about the same as mine.  I migrated all my data from old mac mini to new mac mini.  System screwed up and permission and owners were not setup.  Now I'm trying to salvage this mess.  I'm also trying to import mail, which I think should be on the computer but I don't know where.
    Same question where does the computer store Mail mail?
    Chuck

  • Good afternoon! We purchased the product Adobe master collection 5.5 AOO Litsense RU. Distribyutiv program has been lost, and now we can not find it on the site. There we find different versions of the program other than Russian. Please tell me where to d

    Good afternoon! We purchased the product Adobe master collection 5.5 AOO Litsense RU. Distribyutiv program has been lost, and now we can not find it on the site. There we find different versions of the program other than Russian. Please tell me where to download it?

    Voronello volume license installation files are available under the end user or deploy to account at https://licensing.adobe.com/.

  • Warning a client is using a different version of the ormi protocol 1.3 != 1

    Hi All,
    I am trying to access a bpel process deployed on 10.1.2.0.2 bpel process manager via java client. I am getting the below error on the bpel process manager as,
    Warning a client is using a different version of the ormi protocol 1.3 != 1.1
    I am using the following jars at client side,
    ejb.jar
    oc4jclient.jar
    oc4j-internal.jar
    optic.jar
    orabpel.jar
    orabpel-common.jar
    xmlparserv2.jar
    Can you please help me to solve this issue.
    Appreciate your help!.
    Thanks,
    Levey

    I believe there is a patch available, which allows cross version ORMI compatibility, which needs to be applied to the 10.1.2 release:
    http://download-west.oracle.com/docs/cd/B25221_04/web.1013/b14427/rmi.htm#JISVC6301
    -steve-

Maybe you are looking for

  • SWF player with controls

    am to making a SWF player on Flash CS3 (AS2 & AS3) for web with controls like Play, Pause, Forward, Rewind, Time, Seek bar etc. This player will load external SWF and user can play them as other movie file play. My Player screen size is 300X300Px. I

  • IPad - Unable to complete cellular data setup, cannot input phone number.

    Hi, I purchased my iPad two days ago, it's been brilliant excluding the fact I can't activate my 02 micro-sim. When I'm obliged to input my details e.g. name, telephone and registration details, I can do so, excluding my telephone number as such I ca

  • Procurement Planning in BPC

    Hey Guys, Can we do Procurement Planning (Material Planning) in BPC System? This is something new for me... I know we do Income/expense planning, Headcount plnning and CAPEX planning as these all r financial planning (Account based).  but doing the p

  • Dvd drive missing

    I am using HP pavilion dv6000 PC notebook and operating sytem is widows vista (32 bit) . After upgrading to service pack 2 my dvd drive got disappeared and i tried all possible solutions but could not resolve the issue. Please help in this matter sou

  • Jeg har overført en pdf fil til word, men kan ikke arbejde videre med fodnoter ... nogen der ved noget om det?

    Jeg har overført en pdf fil til word, men kan ikke arbejde videre med fodnoter ... nogen der ved noget om det?