The following code causes a segv during runtime. The command to execute the code
is given following the code.
--------------
class Compute_Seconds {
public static double Compute( long milliseconds ) {
return (double) milliseconds / 1000.0;
}
}
class MyObject {
public long creation_time;
MyObject() {
creation_time = System.currentTimeMillis();
}
}
class createObjects {
public static void main( String args[] ) {
MyObject myArray[];
Long Number_Of_Objects = Long.valueOf( args[0] );
long elapsed_time = 0;
double time_in_seconds = 0.0;
double time_per_object = 0.0;
System.out.println("About to create objects.");
myArray = new MyObject[Number_Of_Objects.intValue()];
for (int i = 0; i < myArray.length; i++) {
myArray[i] = new MyObject();
}
System.out.println("Finished creating objects.");
elapsed_time = myArray[myArray.length-1].creation_time -
myArray[0].creation_time;
System.out.println("Elapsed time = " + elapsed_time + "milliseconds.");
time_in_seconds = Compute_Seconds.Compute( elapsed_time );
System.out.println("Which is " + time_in_seconds + " seconds.");
time_per_object = (double) elapsed_time /
Number_Of_Objects.doubleValue();
System.out.println("Time per object = " + time_per_object +
"milliseconds.");
}
}
-----------------------
Command: java createObjects 400000
--------
Output:
------
[216][wspace] ? java createObjects 400000
About to create objects.
SIGSEGV 11* segmentation violation
si_signo [11]: SIGSEGV 11* segmentation violation
si_errno [0]: Error 0
si_code [1]: SEGV_ACCERR [addr: 0xedf66734]
stackbase=EFFFF63C, stackpointer=EFFFF320
Full thread dump:
"Finalizer thread" (TID:0xee300358, sys_thread_t:0xef490de8) prio=1
"Async Garbage Collector" (TID:0xee300308, sys_thread_t:0xef4c0de8) prio=1
"Idle thread" (TID:0xee300290, sys_thread_t:0xef4f0de8) prio=0
"clock handler" (TID:0xee300098, sys_thread_t:0xef5b0de8) prio=11
"main" (TID:0xee300048, sys_thread_t:0x63dc0) prio=5 *current thread*
createObjects.main(createObjects.java:27)
Monitor Cache Dump:
Registered Monitor Dump:
Finalize me queue lock: unowned
Thread queue lock: unowned
Class lock: unowned
Java stack lock: unowned
Code rewrite lock: unowned
Heap lock: monitor owner: "main"
Has finalization queue lock: unowned
Monitor IO lock: unowned
Child death monitor: unowned
Event monitor: unowned
I/O monitor: unowned
Alarm monitor: unowned
Waiting to be notified:
"clock handler"
Sbrk lock: unowned
Monitor cache lock: unowned
Monitor registry: monitor owner: "main"
Thread Alarm Q:
Segmentation fault
- duplicates
-
JDK-1238397 Garbage Collector segment faults instead of erroring gracefully
-
- Closed
-