In my C++ application, I need to call some java functions inside a "jar" file through JNI.
Hovever after calling the JNI_CreateJavaVM function, My application memory increased by 3, 4 GBs. I suspect this is due to java VM loading into my application. However, but 3,4 GBs are not acceptable in my context. Can someone please let me know are the any parameters available to reduce the memory requirement.
My Sample Code:
#include <jni.h>
#include <iostream>
using namespace std;
int main(const int argc, const char** argv)
{
JNIEnv* p_JNIEnv = NULL;
JavaVM* jvm;
JavaVMInitArgs args;
JavaVMOption options[1];
args.version = JNI_VERSION_1_2;
args.nOptions = 1;
const char* zSystemLibs = "/x01/nptsapp/sujith/ds3api";
if (!zSystemLibs)
{
cout << "SYSTEM_LIBS environment variable not set" << endl;
return false;
}
// ClientAPI, Security and DS3Authenticator class made by us
char zPath[1024];
snprintf(zPath, 1024, "-Djava.class.path=%s/clientapi.jar:%s/security-1.2.jar:%s/RSAPasswordEncryptLib.jar:%s", zSystemLibs,
zSystemLibs, zSystemLibs, zSystemLibs);
cout << "Class Path=" << zPath << endl;
options[0].optionString = zPath;
args.options = options;
args.ignoreUnrecognized = JNI_FALSE;
p_JNIEnv = NULL;
JNI_CreateJavaVM(&jvm, (void**)&p_JNIEnv, &args);
if (!p_JNIEnv)
{
cout << "JNIEnv Not Created" << endl;
return false;
}
cout << "JNIEnv Created Successful:" << p_JNIEnv << endl;
cout << getpid() << " Enter:";
int iValue;
cin >> iValue;
return 0;
};
Compilation and Running
[sujith@nc-110 ~/ds3api]$ ./a.out
Class Path=-Djava.class.path=/x01/nptsapp/sujith/ds3api/clientapi.jar:/x01/nptsapp/sujith/ds3api/security-1.2.jar:/x01/nptsapp/sujith/ds3api/RSAPasswordEncryptLib.jar:/x01/nptsapp/sujith/ds3api
JNIEnv Created Successful:0x10869e8
21152 Enter:
pmap output before the application stops. I added cin for stop the application till I get the pmap output.
[sujith@nc-110 ~]$ pmap -d 21152
21152: ./a.out
Address Kbytes Mode Offset Device Mapping
0000000000400000 4 r-x-- 0000000000000000 000:00019 a.out
0000000000601000 4 rw--- 0000000000001000 000:00019 a.out
000000000107d000 684 rw--- 0000000000000000 000:00000 [ anon ]
0000000721200000 21504 rw--- 0000000000000000 000:00000 [ anon ]
0000000722700000 62464 rw--- 0000000000000000 000:00000 [ anon ]
0000000726400000 148480 rw--- 0000000000000000 000:00000 [ anon ]
000000072f500000 2229760 rw--- 0000000000000000 000:00000 [ anon ]
00000007b7680000 74752 rw--- 0000000000000000 000:00000 [ anon ]
00000007bbf80000 1114624 rw--- 0000000000000000 000:00000 [ anon ]
0000003f62000000 128 r-x-- 0000000000000000 068:00002 ld-2.12.so
0000003f6221f000 4 r---- 000000000001f000 068:00002 ld-2.12.so
0000003f62220000 4 rw--- 0000000000020000 068:00002 ld-2.12.so
0000003f62221000 4 rw--- 0000000000000000 000:00000 [ anon ]
0000003f62400000 524 r-x-- 0000000000000000 068:00002 libm-2.12.so
0000003f62483000 2044 ----- 0000000000083000 068:00002 libm-2.12.so
0000003f62682000 4 r---- 0000000000082000 068:00002 libm-2.12.so
0000003f62683000 4 rw--- 0000000000083000 068:00002 libm-2.12.so
0000003f62800000 1628 r-x-- 0000000000000000 068:00002 libc-2.12.so
0000003f62997000 2048 ----- 0000000000197000 068:00002 libc-2.12.so
0000003f62b97000 16 r---- 0000000000197000 068:00002 libc-2.12.so
0000003f62b9b000 4 rw--- 000000000019b000 068:00002 libc-2.12.so
0000003f62b9c000 20 rw--- 0000000000000000 000:00000 [ anon ]
0000003f62c00000 8 r-x-- 0000000000000000 068:00002 libdl-2.12.so
0000003f62c02000 2048 ----- 0000000000002000 068:00002 libdl-2.12.so
0000003f62e02000 4 r---- 0000000000002000 068:00002 libdl-2.12.so
0000003f62e03000 4 rw--- 0000000000003000 068:00002 libdl-2.12.so
0000003f63000000 92 r-x-- 0000000000000000 068:00002 libpthread-2.12.so
0000003f63017000 2044 ----- 0000000000017000 068:00002 libpthread-2.12.so
0000003f63216000 4 r---- 0000000000016000 068:00002 libpthread-2.12.so
0000003f63217000 4 rw--- 0000000000017000 068:00002 libpthread-2.12.so
0000003f63218000 16 rw--- 0000000000000000 000:00000 [ anon ]
0000003f63800000 28 r-x-- 0000000000000000 068:00002 librt-2.12.so
0000003f63807000 2044 ----- 0000000000007000 068:00002 librt-2.12.so
0000003f63a06000 4 r---- 0000000000006000 068:00002 librt-2.12.so
0000003f63a07000 4 rw--- 0000000000007000 068:00002 librt-2.12.so
0000003f6a800000 88 r-x-- 0000000000000000 068:00002 libgcc_s-4.4.6-20110824.so.1
0000003f6a816000 2044 ----- 0000000000016000 068:00002 libgcc_s-4.4.6-20110824.so.1
0000003f6aa15000 4 rw--- 0000000000015000 068:00002 libgcc_s-4.4.6-20110824.so.1
0000003f6e000000 928 r-x-- 0000000000000000 068:00002 libstdc++.so.6.0.13
0000003f6e0e8000 2048 ----- 00000000000e8000 068:00002 libstdc++.so.6.0.13
0000003f6e2e8000 28 r---- 00000000000e8000 068:00002 libstdc++.so.6.0.13
0000003f6e2ef000 8 rw--- 00000000000ef000 068:00002 libstdc++.so.6.0.13
0000003f6e2f1000 84 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f10000000 132 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f10021000 65404 ----- 0000000000000000 000:00000 [ anon ]
00007f1f14000000 132 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f14021000 65404 ----- 0000000000000000 000:00000 [ anon ]
00007f1f18000000 132 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f18021000 65404 ----- 0000000000000000 000:00000 [ anon ]
00007f1f1c000000 132 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f1c021000 65404 ----- 0000000000000000 000:00000 [ anon ]
00007f1f20000000 132 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f20021000 65404 ----- 0000000000000000 000:00000 [ anon ]
00007f1f2616f000 96836 r---- 0000000000000000 068:00002 locale-archive
00007f1f2c000000 132 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f2c021000 65404 ----- 0000000000000000 000:00000 [ anon ]
00007f1f30000000 132 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f30021000 65404 ----- 0000000000000000 000:00000 [ anon ]
00007f1f34000000 132 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f34021000 65404 ----- 0000000000000000 000:00000 [ anon ]
00007f1f39090000 114112 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f40000000 132 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f40021000 65404 ----- 0000000000000000 000:00000 [ anon ]
00007f1f470ae000 4 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f470af000 4 ----- 0000000000000000 000:00000 [ anon ]
00007f1f470b0000 1024 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f471b0000 12 ----- 0000000000000000 000:00000 [ anon ]
00007f1f471b3000 1016 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f472b1000 12 ----- 0000000000000000 000:00000 [ anon ]
00007f1f472b4000 1016 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f473b2000 12 ----- 0000000000000000 000:00000 [ anon ]
00007f1f473b5000 1016 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f474b3000 12 ----- 0000000000000000 000:00000 [ anon ]
00007f1f474b6000 1016 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f475b4000 12 ----- 0000000000000000 000:00000 [ anon ]
00007f1f475b7000 1016 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f476b5000 12 ----- 0000000000000000 000:00000 [ anon ]
00007f1f476b8000 1016 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f477b6000 4 ----- 0000000000000000 000:00000 [ anon ]
00007f1f477b7000 8484 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f48000000 132 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f48021000 65404 ----- 0000000000000000 000:00000 [ anon ]
00007f1f4c08d000 2488 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f4c2fb000 1788 r--s- 00000000039e5000 068:00002 rt.jar
00007f1f4c4ba000 8408 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f4ccf0000 4 ----- 0000000000000000 000:00000 [ anon ]
00007f1f4ccf1000 1024 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f4cdf1000 4 ----- 0000000000000000 000:00000 [ anon ]
00007f1f4cdf2000 1068 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f4cefd000 120 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f4cf1b000 292 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f4cf64000 4356 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f4d3a5000 44 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f4d3b0000 120 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f4d3ce000 292 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f4d417000 4352 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f4d857000 148 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f4d87c000 2176 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f4da9c000 44 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f4daa7000 728 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f4db5d000 2496 rwx-- 0000000000000000 000:00000 [ anon ]
00007f1f4ddcd000 46656 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f50b5d000 104 r-x-- 0000000000000000 068:00002 libzip.so
00007f1f50b77000 2048 ----- 000000000001a000 068:00002 libzip.so
00007f1f50d77000 4 rw--- 000000000001a000 068:00002 libzip.so
00007f1f50d78000 44 r-x-- 0000000000000000 068:00002 libnss_ldap.so.2
00007f1f50d83000 2044 ----- 000000000000b000 068:00002 libnss_ldap.so.2
00007f1f50f82000 4 rw--- 000000000000a000 068:00002 libnss_ldap.so.2
00007f1f50f83000 48 r-x-- 0000000000000000 068:00002 libnss_files-2.12.so
00007f1f50f8f000 2048 ----- 000000000000c000 068:00002 libnss_files-2.12.so
00007f1f5118f000 4 r---- 000000000000c000 068:00002 libnss_files-2.12.so
00007f1f51190000 4 rw--- 000000000000d000 068:00002 libnss_files-2.12.so
00007f1f511a8000 164 r-x-- 0000000000000000 068:00002 libjava.so
00007f1f511d1000 2048 ----- 0000000000029000 068:00002 libjava.so
00007f1f513d1000 8 rw--- 0000000000029000 068:00002 libjava.so
00007f1f513d3000 52 r-x-- 0000000000000000 068:00002 libverify.so
00007f1f513e0000 2044 ----- 000000000000d000 068:00002 libverify.so
00007f1f515df000 8 rw--- 000000000000c000 068:00002 libverify.so
00007f1f515e1000 28 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f515f4000 32 rw-s- 0000000000000000 068:00002 21152
00007f1f515fc000 4 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f515fd000 4 r---- 0000000000000000 000:00000 [ anon ]
00007f1f515fe000 4 rw--- 0000000000000000 000:00000 [ anon ]
00007f1f515ff000 11712 r-x-- 0000000000000000 068:00002 libjvm.so
00007f1f5216f000 2044 ----- 0000000000b70000 068:00002 libjvm.so
00007f1f5236e000 788 rw--- 0000000000b6f000 068:00002 libjvm.so
00007f1f52433000 260 rw--- 0000000000000000 000:00000 [ anon ]
00007fffac53e000 12 ----- 0000000000000000 000:00000 [ anon ]
00007fffac542000 1008 rw--- 0000000000000000 000:00000 [ stack ]
00007fffac7ff000 4 r-x-- 0000000000000000 000:00000 [ anon ]
ffffffffff600000 4 r-x-- 0000000000000000 000:00000 [ anon ]
mapped: 4655428K writeable/private: 3860404K shared: 1820K
[sujith@nc-110 ~]$