[go: up one dir, main page]

Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Memory Analyzer (MAT) » Classes from rt.jar loaded by different loaders ?
Classes from rt.jar loaded by different loaders ? [message #11331] Fri, 17 July 2009 10:06 Go to next message
Satish Burnwal is currently offline Satish BurnwalFriend
Messages: 5
Registered: July 2009
Junior Member
This is one doubt I got into while analyzing a heap dump. I was trying to
view the classes loaded by the different class loaders, I see that system
class loader has loaded classes like java.util.HashMap etc. Then I
observed another class loader sun.misc.Launcher$AppClassLoader and there
also I see that it has references to classes java.util.HashMap. This has
led me to confusion, I always thought that if system CL is loading classes
like java.util.HashMap, it will not be loaded by any other class loader
since it is the parent CL and a class loaded by a loader can not be loaded
by its child loaders. Can you pls clarify on this please ?
Re: Classes from rt.jar loaded by different loaders ? [message #11444 is a reply to message #11331] Sun, 19 July 2009 16:05 Go to previous messageGo to next message
Andreas Buchen is currently offline Andreas BuchenFriend
Messages: 123
Registered: July 2009
Senior Member
Satish Burnwal wrote:

> Then I
> observed another class loader sun.misc.Launcher$AppClassLoader and there
> also I see that it has references to classes java.util.HashMap. This has
> led me to confusion, I always thought that if system CL is loading classes
> like java.util.HashMap, it will not be loaded by any other class loader
> since it is the parent CL and a class loaded by a loader can not be loaded
> by its child loaders.

You are right - all classes from the rt.jar should be loaded using the
system class loader. What's confusing me is that you say "it has
references to classes" - of course, the another class loader can have
references to those classes, but it should not define them.

Check out the "Java Basics" -> "Class Loader Explorer". It shows all class
loaders, the classes the define and their parent class loader. I just ran
this query on two dumps and could not find any problems. Do not hesitate
to copy and paste the view to this forum to discuss.

Andreas.
Re: Classes from rt.jar loaded by different loaders ? [message #11482 is a reply to message #11444] Tue, 21 July 2009 08:26 Go to previous messageGo to next message
Satish Burnwal is currently offline Satish BurnwalFriend
Messages: 5
Registered: July 2009
Junior Member
Andreas,
You may be right that different class loaders might reference the same
classes but I just tried to convince myself on this. Can someone tell me
when can a non-system classloader refer to a system class ? For example, I
tried to run these 2 examples and take a heap dump while the thread is
sleeping but I do not see TestCL referring to java.net.ServerSocket or
java.util.concurrent.ConcurrentLinkedQueue:

//example1
import java.net.*;
import java.util.concurrent.*;
import java.util.*;

public class TestCL extends java.lang.ClassLoader {

public static void main(String[] args) {
TestCL loader = new TestCL();
loader.load();
}

public void load() {
try {
String s = new String("satish");
Vector v = new Vector(10);
ServerSocket ss = new ServerSocket();
ConcurrentLinkedQueue list = new ConcurrentLinkedQueue();
System.out.println("TestCL...");
Thread.sleep(100000000);
} catch (Exception e) {
e.printStackTrace();
}
}

}

//example2
import java.net.*;
import java.util.concurrent.*;
import java.util.*;

public class TestCL extends java.lang.ClassLoader {

public static void main(String[] args) {
TestCL loader = new TestCL();
Thread t = new Thread(
new Runnable() {
public void run() {
try {
String s = new String("satish");
Vector v = new Vector(10);
ServerSocket ss = new ServerSocket();
ConcurrentLinkedQueue list = new ConcurrentLinkedQueue();
System.out.println("TestCL executed!!");
Thread.sleep(100000000);
} catch (Exception e) {
e.printStackTrace();
}
}
}, "TestThread");
t.setContextClassLoader(loader);
t.start();
try {
t.join();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Re: Classes from rt.jar loaded by different loaders ? [message #11519 is a reply to message #11482] Tue, 21 July 2009 17:51 Go to previous message
Andreas Buchen is currently offline Andreas BuchenFriend
Messages: 123
Registered: July 2009
Senior Member
Hi Satish,

your example will not work this way - the VM knows that your are not
referencing s, v, ss, or the list after the Thread.sleep(). It will
garbage collect those items.

> String s = new String("satish");
> Vector v = new Vector(10);
> ServerSocket ss = new ServerSocket();
> ConcurrentLinkedQueue list = new ConcurrentLinkedQueue();
> System.out.println("TestCL...");
> Thread.sleep(100000000);


Probably all class loaders reference the Vector from the system class
loader.

Take this example: the class loader (not loaded by the system class loader
itself) references a hash table.

Class Name

------------------------------------------------------------ ---------
com.foo.loader.ResourceMultiParentClassLoader @ 0xa8d6338
|- <class> class com.foo.loader.ResourceMultiParentClassLoader @ 0xe38e780
|- parent sun.misc.Launcher$AppClassLoader @ 0xa8c3710

|- package2certs java.util.Hashtable @ 0xa8d63d8

|- classes java.util.Vector @ 0xa8d6400

------------------------------------------------------------ ---------

If you have a question how to interpret a particular view of the Memory
Analyzer, just go ahead and Ctrl-C the selected lines and copy and paste
it to the forum.

Andreas.
Previous Topic:Could not parse big heap file
Next Topic:Request for comments: MAT next steps
Goto Forum:
  


Current Time: Thu Dec 12 17:04:16 GMT 2024

Powered by FUDForum. Page generated in 0.03452 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top