-
Bug
-
Resolution: Fixed
-
P2
-
1.4.0
-
beta
-
generic
-
generic
-
Verified
Name: elR10090 Date: 03/02/2001
When I fixed the bug:
4419859 TEST_BUG: Some tests work with allocated memory after it was freed
in the test:
nsk/serial/Unsafe/reallocateMemory/reallocmem001
I found that now it crashes Merlin's java_g for both Sevrer and Client VM's
at all platforms - Win, Lynx, and both 32-bits Solarises, and Sol for SPARC-V9.
While crashing, HS complains either:
"An unexpected exception has been detected in native code outside the VM."
or:
# SafepointSynchronize::begin: Timed out while attempting to reach a safepoint.
The exception in native code is detected inside "reallocateMemory(address,size)"
invocation found in the following cycle attempting to allocate huge amount of
memory:
long size = 1;
for (int i = 0; i < 64; i++) {
==> address = unsafe.reallocateMemory(address, size);
size <<= 1;
}
This kind of log looks like:
>>>> java_g -showversion serial.Unsafe.reallocateMemory.reallocmem001 ; echo $status
java version "1.4.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b54)
Java HotSpot(TM) Client VM (build 1.4beta-B54-debug, mixed mode)
An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : 11 occurred at PC=0xFF271138
Function=memcpy+0xB48
Library=/usr/platform/SUNW,Ultra-60/lib/libc_psr.so.1
Current Java thread:
at sun.misc.Unsafe.reallocateMemory(Native Method)
at serial.Unsafe.reallocateMemory.reallocmem001.run(reallocmem001.java:114)
at serial.Unsafe.reallocateMemory.reallocmem001.main(reallocmem001.java:14)
Dynamic libraries:
0x10000 /export/ld50/java/dest/jdk1.4.0beta-b54/solsparc/bin/../bin/sparc/native_threads/java_g
0xff360000 /usr/lib/libthread.so.1
0xff3a0000 /usr/lib/libdl.so.1
0xff280000 /usr/lib/libc.so.1
0xff270000 /usr/platform/SUNW,Ultra-60/lib/libc_psr.so.1
0xfd800000 /export/ld50/java/dest/jdk1.4.0beta-b54/solsparc/jre/lib/sparc/client/libjvm_g.so
0xff210000 /usr/lib/libCrun.so.1
0xff1f0000 /usr/lib/libsocket.so.1
0xff100000 /usr/lib/libnsl.so.1
0xff0d0000 /opt/SUNWspro/lib/libm.so.1
0xff240000 /usr/lib/libw.so.1
0xff0b0000 /usr/lib/libmp.so.2
0xff080000 /export/ld50/java/dest/jdk1.4.0beta-b54/solsparc/jre/lib/sparc/native_threads/libhpi_g.so
0xff050000 /export/ld50/java/dest/jdk1.4.0beta-b54/solsparc/jre/lib/sparc/libverify_g.so
0xfe7c0000 /export/ld50/java/dest/jdk1.4.0beta-b54/solsparc/jre/lib/sparc/libjava_g.so
0xff020000 /export/ld50/java/dest/jdk1.4.0beta-b54/solsparc/jre/lib/sparc/libzip_g.so
Local Time = Fri Mar 2 16:02:13 2001
Elapsed Time = 63
#
# The exception above was detected in native code outside the VM
#
# Java VM: Java HotSpot(TM) Client VM (1.4beta-B54-debug mixed mode)
#
# An error report file has been saved as hs_err_pid14655.log.
# Please refer to the file for further information.
#
Dumping core....
Abort
134
Another kind of crash log is observed only for SolX86; it look like:
>>>>java_g -showversion serial.Unsafe.reallocateMemory.reallocmem001 ; echo $status
java version "1.4.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b52)
Java HotSpot(TM) Client VM (build 1.4beta-B52-debug, mixed mode)
# SafepointSynchronize::begin: Fatal error:
# SafepointSynchronize::begin: Timed out while attempting to reach a safepoint.
# SafepointSynchronize::begin: Threads which did not reach the safepoint:
# nid=0x1 runnable
# SafepointSynchronize::begin: (End of list)
^C
(HS hangs while trying to crash here.)
Following is the fixed test source, which reveals this new bug:
/* @(#)reallocmem001.java 1.3 01/03/02
* Copyright 03/02/01 Sun Microsystems, Inc.
*/
package serial.Unsafe.reallocateMemory;
import java.io.*;
import sun.misc.*;
import java.security.*;
class reallocmem001 {
public static void main (String args[]) {
System.exit(95 + run(args, System.out));
}
public static int run (String args[], PrintStream out) {
boolean testFailed = false;
long address;
Unsafe unsafe = (Unsafe)
AccessController.doPrivileged(new Unsafe.GetUnsafeAction());
// Allocate memory
try {
address = unsafe.allocateMemory(1);
} catch(Throwable t) {
out.println("# FAILURE 1.");
out.println(" Cannot allocate memory.");
out.println(" Exception: " + t);
return ( (t instanceof OutOfMemoryError) ||
(t instanceof IllegalArgumentException)
) ? 0 : 2;
}
unsafe.putByte(address, Byte.MAX_VALUE);
// Reallocate memory
try {
address = unsafe.reallocateMemory(address, 2);
if (address == 0) {
out.println("# FAILURE 2.");
out.println(" Address of reallocated memory is 0.");
testFailed = true;
}
} catch(Exception e) {
out.println("# FAILURE 3.");
out.println(" Cannot reallocate memory");
return 2; // Not possibe to continue
}
// Check value put in the memory before reallocation
byte b = unsafe.getByte(address);
if (b != Byte.MAX_VALUE) {
out.println("# FAILURE 4.");
out.println(" " + Byte.MAX_VALUE + " was put in the "
+ "memory before reallocation and " + b
+ " was read.");
testFailed = true;
}
// Try to reallocate memory with size 0
try {
address = unsafe.reallocateMemory(address, 0);
if (address != 0) {
out.println("# FAILURE 5.");
out.println(" Memory was reallocated with size 0, "
+ "but address is " + address + " (should be 0).");
testFailed = true;
}
} catch(Exception e) {
out.println("# FAILURE 6.");
out.println(" Unexpected exception " + e);
testFailed = true;
}
// Try to reallocate memory with address 0
// (an allocation should be performed) and then
// check if memory was allocated
try {
address = unsafe.reallocateMemory(0, 1);
if (address == 0) {
out.println("# FAILURE 7.");
out.println(" Memory was reallocated with address 0 "
+ "and size 1 (byte), but reallocated "
+ "address is " + address + ".");
testFailed = true;
}
} catch(Exception e) {
out.println("# FAILURE 8.");
out.println(" Unexpected exception " + e);
testFailed = true;
}
// Check if memory allocated
try {
unsafe.putByte(address, Byte.MAX_VALUE);
b = unsafe.getByte(address);
if (b != Byte.MAX_VALUE) {
out.println("# FAILURE 9.");
out.println(" " + Byte.MAX_VALUE + " was put in the "
+ "memory and " + b + " was read.");
testFailed = true;
}
} catch (Exception e) {
out.println("# FAILURE 10.");
out.println(" Unexpected exception " + e);
testFailed = true;
}
// Check if VM throws OutOfMemoryError if the
// reallocation is refused by the system
long size = 1;
try {
for (int i = 0; i < 64; i++) {
address = unsafe.reallocateMemory(address, size);
if (address == 0) {
out.println("# FAILURE 11.");
out.println(" Address of reallocated memory is 0 "
+ "when size = " + size);
testFailed = true;
}
size <<= 1;
}
unsafe.freeMemory(address);
} catch (Throwable t) {
if (!((t instanceof OutOfMemoryError) ||
(t instanceof IllegalArgumentException)
)
) {
out.println("# Unexpected exception: " + t);
testFailed = true;
}
}
if (testFailed)
out.println("# TEST FAILED.");
return (testFailed ? 2 : 0);
}
}
======================================================================
- relates to
-
JDK-4419993 Unsafe API: Three failures in Unsafe.allocateMemory(long)
-
- Closed
-