Operating System - HP-UX
1747984 Members
4823 Online
108756 Solutions
New Discussion юеВ

Re: Dynamic memory allocation problem ( VMError14report_and_dieEv .........libjvm.so)

 
nallamolu
Advisor

Dynamic memory allocation problem ( VMError14report_and_dieEv .........libjvm.so)

Hi World,

JVM : 1.6.0.02 ( i use in 64 bit mode IA64W )

I am using Using JNI .
compiled the jni code using the
Compiling options:

cc +z -c +DD64 -Ae +u4 -mt -I/opt/java6/include -I/opt/java6/include/hp-ux cImpl.c

Linker Options:

ld -b -o libcImpl.so cImpl.o



All the 3 senarious are called using jni

This is some what interesting problem which i found. There are 3 senarious..

1.)
int arr[5];
arr[0]=0;
printf(" sucessfull executed ");

This Got executed properly. sucessfull executed was printed

2.)
int count = 0,*arrIndex = NULL;
arrIndex= (int*)malloc(sizeof(int)*4);
for(count=0;count<4;count++)
arrIndex[count]=count;

This senario is failling for the first iteration it self. ( dynamic memory allocation )

3.)
int count = 0,*arrIndex = NULL,*tempIndex = NULL;
arrIndex= (int*)malloc(sizeof(int)*4);
tempIndex = arrIndex;
for(count=0;count<4;count++)
{
printf("count value :%d\n", count);

*tempIndex=count;
tempIndex++;
}

This also got failed just by printing
count value :0


2nd & 3rd senarious are giving the error messg as

Error message:

0xc0000000091d6b00 VMError::report_and_die{_ZN7VMError14report_and_dieEv} + 0x110 [/opt/java6/jre/lib/IA64W/server/libjvm.so]

##########################

Here u can see the VMError14report_and_dieEv ...libjvm.so.

What may be the cause for this..Is it a JVM problem ? If yes then what is the resolution for this.



Plz share u r thoughts on this.

Any help is appreciable.

Thanks in advance,
Gopi











5 REPLIES 5
Don Morris_1
Honored Contributor

Re: Dynamic memory allocation problem ( VMError14report_and_dieEv .........libjvm.so)

Well, one thing that screams out at me -- never cast the result of malloc() [it returns a void * -- which is compatible with all other pointers by definition].

That makes me strongly suspect that you aren't including the appropriate header (#include ), such that the compiler has to assume such an undeclared function returns an int -- and that means the void * is converted to an int [32-bit value] and then re-cast to int * from your directive... losing the upper 32-bits for your 64-bit pointer. Boom.
Dennis Handly
Acclaimed Contributor

Re: Dynamic memory allocation problem ( VMError14report_and_dieEv .........libjvm.so)

This is a continuation of your other thread:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1302344

Instead of calling this from java, you should call your JNI routines from C to make sure they work.

>2nd & 3rd scenarios are giving the error message as

This isn't the real error message. It is the signal here in frame 4:
(3) 0xe0000001120028e0 ---- Signal 11 (SIGSEGV) delivered ----
(4) 0xc0000000083e5d71 Java_TestJava2CallingNative_getCPUIndexMap + 0x191 at cImpl.c:63 [/home/nalgo01/Test/libcImpl.so]

Then you just fire up your debugger and debug:
$ gdb /opt/java1.5/bin/IA64W/java
(gdb) r -d64 TestJava2CallingNative cImpl
Program received signal SIGSEGV, Segmentation fault
si_code: 2 - SEGV_ACCERR - Invalid Permissions for object.
0x9fffffffbded6d10:0 in os::Hpux::generate_page_zero_trap ()

(ignore this bogus signal)
(gdb) c
Continuing.
Library cImpl successfully loaded
Calling sayHelloWorld
C says HelloWorld via stdio
Process ID :7203
All done

Program received signal SIGSEGV, Segmentation fault
si_code: 1 - SEGV_MAPERR - Address not mapped to object.
0x9fffffffbcd02d60:0 in Java_TestJava2CallingNative_getCPUIndexMaptype
(env=0x60000000000508a0, obj=0x9fffffffbefff688) at cImpl.c:64
64 arrIndex[count]=count;
(gdb) p arrIndex
$1 = (int *) 0x3a44d0

And this address has been truncated as Don said.

>Don: one thing that screams out at me - never cast the result of malloc() [it returns a void * -- which is compatible with all other pointers by definition].

This isn't valid for C++. You must cast the result of malloc.

>such that the compiler has to assume such an undeclared function returns an int

A newer compiler assumes it is an error and gives:
error #4313-D: no prototype or definition in scope for call to memory allocation routine "malloc"
arrIndex= (int*)malloc(sizeof(int)*numOfProc);
nallamolu
Advisor

Re: Dynamic memory allocation problem ( VMError14report_and_dieEv .........libjvm.so)

Hi Don / Dennis,

Thanxs alot for taking some of your valuable time and replying back.

Will be doing the nessasary changes what u have mentioned and replying back.

Thanks a lot,
Gopi
nallamolu
Advisor

Re: Dynamic memory allocation problem ( VMError14report_and_dieEv .........libjvm.so)

Hi Don / Dennis

included #include It worked fine for me.

But when i tried it on my application it is giving the

Error as :
java.lang.UnsatisfiedLinkError: Can't load library:/home/nalgo01/Probeing/libHPUXItanium64Stats.so )

Plz refer the following link below for the detail info:

http://forums11.itrc.hp.com/service/forums/questionanswer.do?admit=109447626+1231904747519+28353475&threadId=1302344

Any help is appreceated

Thanking in advance,
Gopi
Dennis Handly
Acclaimed Contributor

Re: Dynamic memory allocation problem ( VMError14report_and_dieEv .........libjvm.so)

>Thanxs alot for taking some of your valuable time and replying back.

If our answers were helpful, please read the following about assigning points:
http://forums.itrc.hp.com/service/forums/helptips.do?#33