Name: kbR10066 Date: 01/30/2003
Intermittent core dumps are observed when running the JCov agent on Solaris-sparc
with complex apps under 'ec=on' or 'ci=...' options. For example, the app below, which
tries to load the same class with different class loaders in different threads, gets SIGSEGV:
> $JDK141/bin/javac -Xjcov a.java b.java
> $JDK141/bin/java -Xrunjcov:t=m,ec=on a
LOADING b
ClassLoader1@c78e57
b@8fe7c3
LOADING b
ClassLoader2@3e8d89
b@9664a1
An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : 11 occurred at PC=0xFF242974
Function=[Unknown. Nearest: free+0x70]
. . .
--- a.java ---
import java.io.*;
import java.security.*;
public class a {
public static void main(String[] args) {
Class c1 = null;
try {
c1 = new ClassLoader1().loadClass("b");
System.out.println(c1.newInstance());
} catch (Throwable e) {
e.printStackTrace();
}
Thread t = new Thread("test") {
public void run() {
try {
Class c2 = new ClassLoader2().loadClass("b");
System.out.println(c2.newInstance());
} catch (Throwable e) {
e.printStackTrace();
}
}
};
t.start();
try {
t.join();
System.out.println(c1.newInstance());
} catch (Throwable e) {
e.printStackTrace();
}
}
}
class CL extends ClassLoader {
final static int READ_CHUNK_SIZE = 1024;
public static byte[] read(String name) {
name = name.replace('.', '/') + ".class";
byte[] arr = null;
try {
InputStream is = ClassLoader.getSystemResourceAsStream(name);
int len = is.available();
int n = 0;
int res = 0;
arr = new byte[len];
do {
res += n;
int i = len - res;
if (i > READ_CHUNK_SIZE) {
i = READ_CHUNK_SIZE;
}
n = is.read(arr, res, i);
} while (n > 0);
is.close();
} catch (Throwable e) {
e.printStackTrace();
return null;
}
return arr;
}
}
class ClassLoader1 extends CL {
protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
Class res = null;
try {
byte[] arr = read(name);
res = defineClass(name, arr, 0, arr.length);
} catch (Throwable e) {
res = findSystemClass(name);
}
if (resolve) {
resolveClass(res);
}
return res;
}
}
class ClassLoader2 extends CL {
protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
Class res = null;
try {
byte[] arr = read(name);
res = defineClass(name, arr, 0, arr.length);
} catch (Throwable e) {
res = findSystemClass(name);
}
if (resolve) {
resolveClass(res);
}
return res;
}
}
--- end of a.java ---
--- b.java ---
public class b {
static {
System.out.println("LOADING b");
}
public b () {
System.out.println(getClass().getClassLoader());
}
}
--- end of b.java ---
======================================================================
- relates to
-
CODETOOLS-7900434 Incomplete coverage for classes loaded repeteadly
-
- Closed
-