#JCConf
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
#JCConf
https://www.youtube.com/watch?v=450maTzSIvA
13
#JCConf
•
–
•
•
–
•
•
–
A B
C
D E
F G
H
A	and	B	are	garbage	collection	roots,	
(GC	roots)
Leading	Set Retained	Set
E E,	G
C C,	D,	E,	F,	G,	H
A,	B A,	B,	C,	D,	E,	F,	G,	H
A B
C
D E
F G
H
A B
C
D E
F G
H
A B
C
D E
F G
H
A B
C
D E
F G
H
#JCConf
Done
More Things…
List	objects	→	with	outgoing	references
oracle.jdbc.ScrollableResultSet →	scrollStmt
→	sqlObject →	sqlBytes →	Copy	→	Value
SELECT	*	FROM	POP.PRMASTER,POP.PRITEM	 WHERE	
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
…………………………………………………..…………………………………………………………………………
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
…………………………………………………………Order	 By	PRITEM.IDOCNUMBER	
DESC,PRITEM.ITEM
Merge	Shortes Paths	to	GCRoots
→	exclude	all	phantom/weak/soft	etc.	references
List	objects	→	with	outgoing	references
Sorting	by	Class	Name
java.lang.Thread →	org.apache.catlina.connector.Request
→	postData →	Copy	→	Value
sessionid=16F098C27D8DE1C8C7E58A15798C470A&applicantID=&hcreatorID=&
applicantName ………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
…………………………………………………………………………..…………………………………………………
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
…………………………………………………………………………………	 KOLON_prodhier=K0
HTTP	Request	Attributes
org.apache.catlina.connector.Request →	attributes	→	
table		→	java.util.HashMap$Entry
HTTP	Session	Data
org.apache.catlina.connector.Request →	session	→	attributes	
→	segments	→	java.util.concurrent.ConcurrentHashMap$Segment
Java	Basics	→	Thread	Overview	and	Stacks
•
•
•
•
•
•
•
•
#JCConf
•
–
•
–
•
Merge	Shortest	Paths	to	GC	Roots	
→	exclude	all	phantom/weak/soft	etc.	references
List	objects	→	with	outgoing	references
Expand	the	node
target	
org.apache.logging.log4j
.core.util.DefaultShutdownCallbackRegistry
Using Log4j 2 in Web Applications
You must take particular care when using Log4j or any other logging framework within a Java EE web application.
It's important for logging resources to be properly cleaned up (database connectionsclosed, files closed, etc.)
when the container shuts down or the web application is undeployed. Because of the nature of class loaders within web applications,
Log4j resources cannot be cleaned up through normalmeans. Log4j must be "started" when the web application deploys and "shut down"
when the web application undeploys. How this works varies depending on whether your application is
a Servlet 3.0 or newer or Servlet 2.5 web application.
In either case, you'll need to add the log4j-web module to your deployment as detailed in the Maven, Ivy, and Gradle Artifacts manualpage.
To avoid problems the Log4j shutdown
hook will automatically be disabled
when the log4j-web jar is included.
<classloader>
org.apache.logging.log4j.core.jmx.StatusLoggerAdminMBean
•
•
•
–
–
•
–
#JCConf
•
•
•
•
•
•
/* */ public abstract class ItemFactory
/* */ implements Constants
/* */ {
/* */ protected static Logger a;
/* 45 */ public Map b = null;
/* */ public static int c;
/* */ private static String[] A;
/* */
/* */ protected ItemFactory()
/* */ {
/* 51 */ this.b = Collections.synchronizedMap(new HashMap());
/* 52 */ if ((ItemBean.d) || (a == null)) {
/* 53 */ a = Logger.getLogger(A[2]);
/* */ }
/* */ }
Bad	news:	It	is	obfuscated	(混淆)
Can’t	decompile,	rewrite,	and	compile	…
•
public aspect ItemFactoryAop {
private final static int DEFAULT_CACHE_SIZE = 100000;
after() : execution(workflow.ItemFactory.new()) {
((ItemFactory)thisJoinPoint.getThis()).b =
Collections.synchronizedMap(
new cache.LruCache(DEFAULT_CACHE_SIZE));
}
}
•
–
•
–
•
•
#JCConf
•
•
•
•
•
•
•
•
–
#JCConf
•
•
•
•
#JCConf
MayYour JVM
Live Long and Prosper
生生不息、繁榮昌盛

自己的JVM自己救: 解救 OOM 實務經驗談 (JCConf 2015)