Produced by Araxis Merge on 9/25/2018 2:13:06 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\com\sun\tools\hat\internal\parser | HprofReader.java | Mon Jan 22 14:46:52 2018 UTC |
2 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\com\sun\tools\hat\internal\parser | HprofReader.java | Wed Sep 12 16:45:41 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 1796 |
Changed | 1 | 2 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | /* | |
2 | * Copyrig ht (c) 199 7, 2008, O racle and/ or its aff iliates. A ll rights reserved. | |
3 | * DO NOT ALTER OR R EMOVE COPY RIGHT NOTI CES OR THI S FILE HEA DER. | |
4 | * | |
5 | * This co de is free software; you can r edistribut e it and/o r modify i t | |
6 | * under t he terms o f the GNU General Pu blic Licen se version 2 only, a s | |
7 | * publish ed by the Free Softw are Founda tion. Ora cle design ates this | |
8 | * particu lar file a s subject to the "Cl asspath" e xception a s provided | |
9 | * by Orac le in the LICENSE fi le that ac companied this code. | |
10 | * | |
11 | * This co de is dist ributed in the hope that it wi ll be usef ul, but WI THOUT | |
12 | * ANY WAR RANTY; wit hout even the implie d warranty of MERCHA NTABILITY or | |
13 | * FITNESS FOR A PAR TICULAR PU RPOSE. Se e the GNU General Pu blic Licen se | |
14 | * version 2 for mor e details (a copy is included in the LIC ENSE file that | |
15 | * accompa nied this code). | |
16 | * | |
17 | * You sho uld have r eceived a copy of th e GNU Gene ral Public License v ersion | |
18 | * 2 along with this work; if not, write to the Fr ee Softwar e Foundati on, | |
19 | * Inc., 5 1 Franklin St, Fifth Floor, Bo ston, MA 0 2110-1301 USA. | |
20 | * | |
21 | * Please contact Or acle, 500 Oracle Par kway, Redw ood Shores , CA 94065 USA | |
22 | * or visi t www.orac le.com if you need a dditional informatio n or have any | |
23 | * questio ns. | |
24 | */ | |
25 | ||
26 | ||
27 | /* | |
28 | * The Ori ginal Code is HAT. T he Initial Developer of the | |
29 | * Origina l Code is Bill Foote , with con tributions from othe rs | |
30 | * at Java Soft/Sun. | |
31 | */ | |
32 | ||
33 | package co m.sun.tool s.hat.inte rnal.parse r; | |
34 | ||
35 | import jav a.io.*; | |
36 | import jav a.util.Dat e; | |
37 | import jav a.util.Has htable; | |
38 | import com .sun.tools .hat.inter nal.model. ArrayTypeC odes; | |
39 | import com .sun.tools .hat.inter nal.model. *; | |
40 | ||
41 | /** | |
42 | * Object that's use d to read a hprof fi le. | |
43 | * | |
44 | * @author Bill Foote | |
45 | */ | |
46 | ||
47 | public cla ss HprofRe ader exten ds Reader /* imports */ implem ents Array TypeCodes { | |
48 | ||
49 | final static int MAGIC_NUM BER = 0x4a 415641; | |
50 | // That's "JAVA", th e first pa rt of "JA D A N P S O I E ..." | |
51 | privat e final st atic Strin g[] VERSIO NS = { | |
52 | " PROFIL E 1.0\0", | |
53 | " PROFIL E 1.0.1\0" , | |
54 | " PROFIL E 1.0.2\0" , | |
55 | }; | |
56 | ||
57 | privat e final st atic int V ERSION_JDK 12BETA3 = 0; | |
58 | privat e final st atic int V ERSION_JDK 12BETA4 = 1; | |
59 | privat e final st atic int V ERSION_JDK 6 = 2; | |
60 | // The se version numbers a re indices into VERS IONS. The instance data | |
61 | // mem ber versio n is set t o one of t hese, and it drives decisions when | |
62 | // rea ding the f ile. | |
63 | // | |
64 | // Ver sion 1.0.1 added HPR OF_GC_PRIM _ARRAY_DUM P, which r equires no | |
65 | // ver sion-sensi tive parsi ng. | |
66 | // | |
67 | // Ver sion 1.0.1 changed t he type of a constan t pool ent ry from a signature | |
68 | // to a typecode . | |
69 | // | |
70 | // Ver sion 1.0.2 added HPR OF_HEAP_DU MP_SEGMENT and HPROF _HEAP_DUMP _END | |
71 | // to allow a la rge heap t o be dumpe d as a seq uence of h eap dump s egments. | |
72 | // | |
73 | // The HPROF age nt in J2SE 1.2 throu gh to 5.0 generate a version 1 .0.1 | |
74 | // fil e. In Java SE 6.0 th e version is either 1.0.1 or 1 .0.2 depen ding on | |
75 | // the size of t he heap (n ormally it will be 1 .0.1 but f or multi-G B | |
76 | // hea ps the hea p dump wil l not fit in a HPROF _HEAP_DUMP record so the | |
77 | // dum p is gener ated as ve rsion 1.0. 2). | |
78 | ||
79 | // | |
80 | // Rec ord types: | |
81 | // | |
82 | static final int HPROF_UTF 8 = 0x01; | |
83 | static final int HPROF_LOA D_CLASS = 0x02; | |
84 | static final int HPROF_UNL OAD_CLASS = 0x03; | |
85 | static final int HPROF_FRA ME = 0x04; | |
86 | static final int HPROF_TRA CE = 0x05; | |
87 | static final int HPROF_ALL OC_SITES = 0x06; | |
88 | static final int HPROF_HEA P_SUMMARY = 0x07; | |
89 | ||
90 | static final int HPROF_STA RT_THREAD = 0x0a; | |
91 | static final int HPROF_END _THREAD = 0x0b; | |
92 | ||
93 | static final int HPROF_HEA P_DUMP = 0x0c; | |
94 | ||
95 | static final int HPROF_CPU _SAMPLES = 0x0d; | |
96 | static final int HPROF_CON TROL_SETTI NGS = 0x0e ; | |
97 | static final int HPROF_LOC KSTATS_WAI T_TIME = 0 x10; | |
98 | static final int HPROF_LOC KSTATS_HOL D_TIME = 0 x11; | |
99 | ||
100 | static final int HPROF_GC_ ROOT_UNKNO WN = 0xff; | |
101 | static final int HPROF_GC_ ROOT_JNI_G LOBAL = 0x01; | |
102 | static final int HPROF_GC_ ROOT_JNI_L OCAL = 0x02; | |
103 | static final int HPROF_GC_ ROOT_JAVA_ FRAME = 0x03; | |
104 | static final int HPROF_GC_ ROOT_NATIV E_STACK = 0x04; | |
105 | static final int HPROF_GC_ ROOT_STICK Y_CLASS = 0x05; | |
106 | static final int HPROF_GC_ ROOT_THREA D_BLOCK = 0x06; | |
107 | static final int HPROF_GC_ ROOT_MONIT OR_USED = 0x07; | |
108 | static final int HPROF_GC_ ROOT_THREA D_OBJ = 0x08; | |
109 | ||
110 | static final int HPROF_GC_ CLASS_DUMP = 0x20; | |
111 | static final int HPROF_GC_ INSTANCE_D UMP = 0x21; | |
112 | static final int HPROF_GC_ OBJ_ARRAY_ DUMP = 0x22; | |
113 | static final int HPROF_GC_ PRIM_ARRAY _DUMP = 0x23 ; | |
114 | ||
115 | static final int HPROF_HEA P_DUMP_SEG MENT = 0x1c; | |
116 | static final int HPROF_HEA P_DUMP_END = 0x2c; | |
117 | ||
118 | privat e final st atic int T _CLASS = 2 ; | |
119 | ||
120 | privat e int vers ion; // The v ersion of .hprof bei ng read | |
121 | ||
122 | privat e int debu gLevel; | |
123 | privat e long cur rPos; // Curr ent positi on in the file | |
124 | ||
125 | privat e int dump sToSkip; | |
126 | privat e boolean callStack; // If tr ue, read t he call st ack of obj ects | |
127 | ||
128 | privat e int iden tifierSize ; // Size, i n bytes, o f identifi ers. | |
129 | privat e Hashtabl e<Long, St ring> name s; | |
130 | ||
131 | // Has htable<Int eger, Thre adObject>, used to m ap the thr ead sequen ce number | |
132 | // (ak a "serial number") t o the thre ad object ID for | |
133 | // HPR OF_GC_ROOT _THREAD_OB J. Thread Object is a trivial inner clas s, | |
134 | // at the end of this file . | |
135 | privat e Hashtabl e<Integer, ThreadObj ect> threa dObjects; | |
136 | ||
137 | // Has htable<Lon g, String> , maps cla ss object ID to clas s name | |
138 | // (wi th / conve rted to .) | |
139 | privat e Hashtabl e<Long, St ring> clas sNameFromO bjectID; | |
140 | ||
141 | // Has htable<Int eger, Inte ger>, maps class ser ial # to c lass objec t ID | |
142 | privat e Hashtabl e<Integer, String> c lassNameFr omSerialNo ; | |
143 | ||
144 | // Has htable<Lon g, StackFr ame> maps stack fram e ID to St ackFrame. | |
145 | // Nul l if we're not track ing them. | |
146 | privat e Hashtabl e<Long, St ackFrame> stackFrame s; | |
147 | ||
148 | // Has htable<Int eger, Stac kTrace> ma ps stack f rame ID to StackTrac e | |
149 | // Nul l if we're not track ing them. | |
150 | privat e Hashtabl e<Integer, StackTrac e> stackTr aces; | |
151 | ||
152 | privat e Snapshot snapshot; | |
153 | ||
154 | public HprofRead er(String fileName, PositionDa taInputStr eam in, | |
155 | int dum pNumber, b oolean cal lStack, in t debugLev el) | |
156 | throws IOExceptio n { | |
157 | su per(in); | |
158 | Ra ndomAccess File file = new Rand omAccessFi le(fileNam e, "r"); | |
159 | th is.snapsho t = new Sn apshot(Map pedReadBuf fer.create (file)); | |
160 | th is.dumpsTo Skip = dum pNumber - 1; | |
161 | th is.callSta ck = callS tack; | |
162 | th is.debugLe vel = debu gLevel; | |
163 | na mes = new Hashtable< Long, Stri ng>(); | |
164 | th readObject s = new Ha shtable<In teger, Thr eadObject> (43); | |
165 | cl assNameFro mObjectID = new Hash table<Long , String>( ); | |
166 | if (callStac k) { | |
167 | stackFra mes = new Hashtable< Long, Stac kFrame>(43 ); | |
168 | stackTra ces = new Hashtable< Integer, S tackTrace> (43); | |
169 | classNam eFromSeria lNo = new Hashtable< Integer, S tring>(); | |
170 | } | |
171 | } | |
172 | ||
173 | public Snapshot read() thr ows IOExce ption { | |
174 | cu rrPos = 4; // 4 b ecause of the magic number | |
175 | ve rsion = re adVersionH eader(); | |
176 | id entifierSi ze = in.re adInt(); | |
177 | sn apshot.set Identifier Size(ident ifierSize) ; | |
178 | if (version >= VERSION _JDK12BETA 4) { | |
179 | snapshot .setNewSty leArrayCla ss(true); | |
180 | } else { | |
181 | snapshot .setNewSty leArrayCla ss(false); | |
182 | } | |
183 | ||
184 | cu rrPos += 4 ; | |
185 | if (identifi erSize != 4 && ident ifierSize != 8) { | |
186 | throw ne w IOExcept ion("I'm s orry, but I can't de al with an identifie r size of " + identi fierSize + ". I can only deal with 4 or 8."); | |
187 | } | |
188 | Sy stem.out.p rintln("Du mp file cr eated " + (new Date( in.readLon g()))); | |
189 | cu rrPos += 8 ; | |
190 | ||
191 | fo r (;;) { | |
192 | int type ; | |
193 | try { | |
194 | type = in.read UnsignedBy te(); | |
195 | } catch (EOFExcept ion ignore d) { | |
196 | brea k; | |
197 | } | |
198 | in.readI nt(); // Times tamp of th is record | |
199 | // Lengt h of recor d: readInt () will re turn negat ive value for record | |
200 | // lengt h >2GB. s o store 32 bit value in long to keep it u nsigned. | |
201 | long len gth = in.r eadInt() & 0xfffffff fL; | |
202 | if (debu gLevel > 0 ) { | |
203 | Syst em.out.pri ntln("Read record ty pe " + typ e | |
204 | + ", length " + length | |
205 | + " a t position " + toHex (currPos)) ; | |
206 | } | |
207 | if (leng th < 0) { | |
208 | thro w new IOEx ception("B ad record length of " + length | |
209 | + " at byte " + toHex( currPos+5) | |
210 | + " of file. "); | |
211 | } | |
212 | currPos += 9 + len gth; | |
213 | switch ( type) { | |
214 | case HPROF_UTF 8: { | |
215 | long id = readID(); | |
216 | byte[] cha rs = new b yte[(int)l ength - id entifierSi ze]; | |
217 | in.readFul ly(chars); | |
218 | names.put( new Long(i d), new St ring(chars )); | |
219 | break; | |
220 | } | |
221 | case HPROF_LOA D_CLASS: { | |
222 | int serial No = in.re adInt(); // N ot used | |
223 | long class ID = readI D(); | |
224 | int stackT raceSerial No = in.re adInt(); | |
225 | long class NameID = r eadID(); | |
226 | Long class IdI = new Long(class ID); | |
227 | String nm = getNameF romID(clas sNameID).r eplace('/' , '.'); | |
228 | classNameF romObjectI D.put(clas sIdI, nm); | |
229 | if (classN ameFromSer ialNo != n ull) { | |
230 | classN ameFromSer ialNo.put( new Intege r(serialNo ), nm); | |
231 | } | |
232 | break; | |
233 | } | |
234 | ||
235 | case HPROF_HEA P_DUMP: { | |
236 | if (dumpsT oSkip <= 0 ) { | |
237 | try { | |
238 | re adHeapDump (length, c urrPos); | |
239 | } catc h (EOFExce ption exp) { | |
240 | ha ndleEOF(ex p, snapsho t); | |
241 | } | |
242 | if (de bugLevel > 0) { | |
243 | Sy stem.out.p rintln(" Finished processin g instance s in heap dump."); | |
244 | } | |
245 | return snapshot; | |
246 | } else { | |
247 | dumpsT oSkip--; | |
248 | skipBy tes(length ); | |
249 | } | |
250 | break; | |
251 | } | |
252 | ||
253 | case HPROF_HEA P_DUMP_END : { | |
254 | if (versio n >= VERSI ON_JDK6) { | |
255 | if (du mpsToSkip <= 0) { | |
256 | sk ipBytes(le ngth); // should be no-op | |
257 | re turn snaps hot; | |
258 | } else { | |
259 | // skip this dump (of the end re cord for a sequence of dump se gments) | |
260 | du mpsToSkip- -; | |
261 | } | |
262 | } else { | |
263 | // HPR OF_HEAP_DU MP_END onl y recogniz ed in >= 1 .0.2 | |
264 | warn(" Ignoring u nrecognize d record t ype " + ty pe); | |
265 | } | |
266 | skipBytes( length); // should be no-op | |
267 | break; | |
268 | } | |
269 | ||
270 | case HPROF_HEA P_DUMP_SEG MENT: { | |
271 | if (versio n >= VERSI ON_JDK6) { | |
272 | if (du mpsToSkip <= 0) { | |
273 | tr y { | |
274 | // read the dump s egment | |
275 | readHeap Dump(lengt h, currPos ); | |
276 | } catch (EOF Exception exp) { | |
277 | handleEO F(exp, sna pshot); | |
278 | } | |
279 | } else { | |
280 | // all segme nts compri sing the h eap dump w ill be ski pped | |
281 | sk ipBytes(le ngth); | |
282 | } | |
283 | } else { | |
284 | // HPR OF_HEAP_DU MP_SEGMENT only reco gnized in >= 1.0.2 | |
285 | warn(" Ignoring u nrecognize d record t ype " + ty pe); | |
286 | skipBy tes(length ); | |
287 | } | |
288 | break; | |
289 | } | |
290 | ||
291 | case HPROF_FRA ME: { | |
292 | if (stackF rames == n ull) { | |
293 | skipBy tes(length ); | |
294 | } else { | |
295 | long i d = readID (); | |
296 | String methodNam e = getNam eFromID(re adID()); | |
297 | String methodSig = getName FromID(rea dID()); | |
298 | String sourceFil e = getNam eFromID(re adID()); | |
299 | int cl assSer = i n.readInt( ); | |
300 | String className = classNa meFromSeri alNo.get(n ew Integer (classSer) ); | |
301 | int li neNumber = in.readIn t(); | |
302 | if (li neNumber < StackFram e.LINE_NUM BER_NATIVE ) { | |
303 | wa rn("Weird stack fram e line num ber: " + lineNumber ); | |
304 | li neNumber = StackFram e.LINE_NUM BER_UNKNOW N; | |
305 | } | |
306 | stackF rames.put( new Long(i d), | |
307 | new StackF rame(metho dName, met hodSig, | |
308 | class Name, sour ceFile, | |
309 | lineN umber)); | |
310 | } | |
311 | break; | |
312 | } | |
313 | case HPROF_TRA CE: { | |
314 | if (stackT races == n ull) { | |
315 | skipBy tes(length ); | |
316 | } else { | |
317 | int se rialNo = i n.readInt( ); | |
318 | int th readSeq = in.readInt (); // N ot used | |
319 | StackF rame[] fra mes = new StackFrame [in.readIn t()]; | |
320 | for (i nt i = 0; i < frames .length; i ++) { | |
321 | lo ng fid = r eadID(); | |
322 | fr ames[i] = stackFrame s.get(new Long(fid)) ; | |
323 | if (frames[i ] == null) { | |
324 | throw ne w IOExcept ion("Stack frame " + toHex(fid ) + " not found"); | |
325 | } | |
326 | } | |
327 | stackT races.put( new Intege r(serialNo ), | |
328 | new StackT race(frame s)); | |
329 | } | |
330 | break; | |
331 | } | |
332 | case HPROF_UNL OAD_CLASS: | |
333 | case HPROF_ALL OC_SITES: | |
334 | case HPROF_STA RT_THREAD: | |
335 | case HPROF_END _THREAD: | |
336 | case HPROF_HEA P_SUMMARY: | |
337 | case HPROF_CPU _SAMPLES: | |
338 | case HPROF_CON TROL_SETTI NGS: | |
339 | case HPROF_LOC KSTATS_WAI T_TIME: | |
340 | case HPROF_LOC KSTATS_HOL D_TIME: | |
341 | { | |
342 | // Ignore these reco rd types | |
343 | skipBytes( length); | |
344 | break; | |
345 | } | |
346 | defa ult: { | |
347 | skipBytes( length); | |
348 | warn("Igno ring unrec ognized re cord type " + type); | |
349 | } | |
350 | } | |
351 | } | |
352 | ||
353 | re turn snaps hot; | |
354 | } | |
355 | ||
356 | privat e void ski pBytes(lon g length) throws IOE xception { | |
357 | wh ile (lengt h > 0) { | |
358 | long ski pped = in. skip(lengt h); | |
359 | length - = skipped; | |
360 | if (skip ped == 0) { | |
361 | // E OF or othe r problem, throw exc eption | |
362 | thro w new EOFE xception(" Couldn't s kip enough bytes"); | |
363 | } | |
364 | } | |
365 | } | |
366 | ||
367 | privat e int read VersionHea der() thro ws IOExcep tion { | |
368 | in t candidat esLeft = V ERSIONS.le ngth; | |
369 | bo olean[] ma tched = ne w boolean[ VERSIONS.l ength]; | |
370 | fo r (int i = 0; i < ca ndidatesLe ft; i++) { | |
371 | matched[ i] = true; | |
372 | } | |
373 | ||
374 | in t pos = 0; | |
375 | wh ile (candi datesLeft > 0) { | |
376 | char c = (char) in .readByte( ); | |
377 | currPos+ +; | |
378 | for (int i = 0; i < VERSIONS .length; i ++) { | |
379 | if ( matched[i] ) { | |
380 | if (c != V ERSIONS[i] .charAt(po s)) { // Not match ed | |
381 | matche d[i] = fal se; | |
382 | --cand idatesLeft ; | |
383 | } else if (pos == VE RSIONS[i]. length() - 1) { // Full match | |
384 | return i; | |
385 | } | |
386 | } | |
387 | } | |
388 | ++pos; | |
389 | } | |
390 | th row new IO Exception( "Version s tring not recognized at byte " + (pos+3) ); | |
391 | } | |
392 | ||
393 | privat e void rea dHeapDump( long bytes Left, long posAtEnd) throws IO Exception { | |
394 | wh ile (bytes Left > 0) { | |
395 | int type = in.read UnsignedBy te(); | |
396 | if (debu gLevel > 0 ) { | |
397 | Syst em.out.pri ntln(" Read heap sub-record type " + type | |
398 | + " a t position " | |
399 | + toH ex(posAtEn d - bytesL eft)); | |
400 | } | |
401 | bytesLef t--; | |
402 | switch(t ype) { | |
403 | case HPROF_GC_ ROOT_UNKNO WN: { | |
404 | long id = readID(); | |
405 | bytesLeft -= identif ierSize; | |
406 | snapshot.a ddRoot(new Root(id, 0, Root.UN KNOWN, "") ); | |
407 | break; | |
408 | } | |
409 | case HPROF_GC_ ROOT_THREA D_OBJ: { | |
410 | long id = readID(); | |
411 | int thread Seq = in.r eadInt(); | |
412 | int stackS eq = in.re adInt(); | |
413 | bytesLeft -= identif ierSize + 8; | |
414 | threadObje cts.put(ne w Integer( threadSeq) , | |
415 | ne w ThreadOb ject(id, s tackSeq)); | |
416 | break; | |
417 | } | |
418 | case HPROF_GC_ ROOT_JNI_G LOBAL: { | |
419 | long id = readID(); | |
420 | long globa lRefId = r eadID(); // I gnored, fo r now | |
421 | bytesLeft -= 2*ident ifierSize; | |
422 | snapshot.a ddRoot(new Root(id, 0, Root.NA TIVE_STATI C, "")); | |
423 | break; | |
424 | } | |
425 | case HPROF_GC_ ROOT_JNI_L OCAL: { | |
426 | long id = readID(); | |
427 | int thread Seq = in.r eadInt(); | |
428 | int depth = in.readI nt(); | |
429 | bytesLeft -= identif ierSize + 8; | |
430 | ThreadObje ct to = ge tThreadObj ectFromSeq uence(thre adSeq); | |
431 | StackTrace st = getS tackTraceF romSerial( to.stackSe q); | |
432 | if (st != null) { | |
433 | st = s t.traceFor Depth(dept h+1); | |
434 | } | |
435 | snapshot.a ddRoot(new Root(id, to.threadI d, | |
436 | Root .NATIVE_LO CAL, "", s t)); | |
437 | break; | |
438 | } | |
439 | case HPROF_GC_ ROOT_JAVA_ FRAME: { | |
440 | long id = readID(); | |
441 | int thread Seq = in.r eadInt(); | |
442 | int depth = in.readI nt(); | |
443 | bytesLeft -= identif ierSize + 8; | |
444 | ThreadObje ct to = ge tThreadObj ectFromSeq uence(thre adSeq); | |
445 | StackTrace st = getS tackTraceF romSerial( to.stackSe q); | |
446 | if (st != null) { | |
447 | st = s t.traceFor Depth(dept h+1); | |
448 | } | |
449 | snapshot.a ddRoot(new Root(id, to.threadI d, | |
450 | Root .JAVA_LOCA L, "", st) ); | |
451 | break; | |
452 | } | |
453 | case HPROF_GC_ ROOT_NATIV E_STACK: { | |
454 | long id = readID(); | |
455 | int thread Seq = in.r eadInt(); | |
456 | bytesLeft -= identif ierSize + 4; | |
457 | ThreadObje ct to = ge tThreadObj ectFromSeq uence(thre adSeq); | |
458 | StackTrace st = getS tackTraceF romSerial( to.stackSe q); | |
459 | snapshot.a ddRoot(new Root(id, to.threadI d, | |
460 | Root .NATIVE_ST ACK, "", s t)); | |
461 | break; | |
462 | } | |
463 | case HPROF_GC_ ROOT_STICK Y_CLASS: { | |
464 | long id = readID(); | |
465 | bytesLeft -= identif ierSize; | |
466 | snapshot.a ddRoot(new Root(id, 0, Root.SY STEM_CLASS , "")); | |
467 | break; | |
468 | } | |
469 | case HPROF_GC_ ROOT_THREA D_BLOCK: { | |
470 | long id = readID(); | |
471 | int thread Seq = in.r eadInt(); | |
472 | bytesLeft -= identif ierSize + 4; | |
473 | ThreadObje ct to = ge tThreadObj ectFromSeq uence(thre adSeq); | |
474 | StackTrace st = getS tackTraceF romSerial( to.stackSe q); | |
475 | snapshot.a ddRoot(new Root(id, to.threadI d, | |
476 | Roo t.THREAD_B LOCK, "", st)); | |
477 | break; | |
478 | } | |
479 | case HPROF_GC_ ROOT_MONIT OR_USED: { | |
480 | long id = readID(); | |
481 | bytesLeft -= identif ierSize; | |
482 | snapshot.a ddRoot(new Root(id, 0, Root.BU SY_MONITOR , "")); | |
483 | break; | |
484 | } | |
485 | case HPROF_GC_ CLASS_DUMP : { | |
486 | int bytesR ead = read Class(); | |
487 | bytesLeft -= bytesRe ad; | |
488 | break; | |
489 | } | |
490 | case HPROF_GC_ INSTANCE_D UMP: { | |
491 | int bytesR ead = read Instance() ; | |
492 | bytesLeft -= bytesRe ad; | |
493 | break; | |
494 | } | |
495 | case HPROF_GC_ OBJ_ARRAY_ DUMP: { | |
496 | long bytes Read = rea dArray(fal se); | |
497 | bytesLeft -= bytesRe ad; | |
498 | break; | |
499 | } | |
500 | case HPROF_GC_ PRIM_ARRAY _DUMP: { | |
501 | long bytes Read = rea dArray(tru e); | |
502 | bytesLeft -= bytesRe ad; | |
503 | break; | |
504 | } | |
505 | defa ult: { | |
506 | throw new IOExceptio n("Unrecog nized heap dump sub- record typ e: " + ty pe); | |
507 | } | |
508 | } | |
509 | } | |
510 | if (bytesLef t != 0) { | |
511 | warn("Er ror readin g heap dum p or heap dump segme nt: Byte count is " + bytesLe ft + " ins tead of 0" ); | |
512 | skipByte s(bytesLef t); | |
513 | } | |
514 | if (debugLev el > 0) { | |
515 | System.o ut.println (" Fini shed heap sub-record s."); | |
516 | } | |
517 | } | |
518 | ||
519 | privat e long rea dID() thro ws IOExcep tion { | |
520 | re turn (iden tifierSize == 4)? | |
521 | (Snapsho t.SMALL_ID _MASK & (l ong)in.rea dInt()) : in.readLon g(); | |
522 | } | |
523 | ||
524 | // | |
525 | // Rea d a java v alue. If result is non-null, it's expec ted to be an | |
526 | // arr ay of one element. We use it to fake mu ltiple ret urn values . | |
527 | // @re turns the number of bytes read | |
528 | // | |
529 | privat e int read Value(Java Thing[] re sultArr) t hrows IOEx ception { | |
530 | by te type = in.readByt e(); | |
531 | re turn 1 + r eadValueFo rType(type , resultAr r); | |
532 | } | |
533 | ||
534 | privat e int read ValueForTy pe(byte ty pe, JavaTh ing[] resu ltArr) | |
535 | throws I OException { | |
536 | if (version >= VERSION _JDK12BETA 4) { | |
537 | type = s ignatureFr omTypeId(t ype); | |
538 | } | |
539 | re turn readV alueForTyp eSignature (type, res ultArr); | |
540 | } | |
541 | ||
542 | privat e int read ValueForTy peSignatur e(byte typ e, JavaThi ng[] resul tArr) | |
543 | throws I OException { | |
544 | sw itch (type ) { | |
545 | case '[' : | |
546 | case 'L' : { | |
547 | long id = read ID(); | |
548 | if ( resultArr != null) { | |
549 | resultArr[ 0] = new J avaObjectR ef(id); | |
550 | } | |
551 | retu rn identif ierSize; | |
552 | } | |
553 | case 'Z' : { | |
554 | int b = in.rea dByte(); | |
555 | if ( b != 0 && b != 1) { | |
556 | warn("Ille gal boolea n value re ad"); | |
557 | } | |
558 | if ( resultArr != null) { | |
559 | resultArr[ 0] = new J avaBoolean (b != 0); | |
560 | } | |
561 | retu rn 1; | |
562 | } | |
563 | case 'B' : { | |
564 | byte b = in.re adByte(); | |
565 | if ( resultArr != null) { | |
566 | resultArr[ 0] = new J avaByte(b) ; | |
567 | } | |
568 | retu rn 1; | |
569 | } | |
570 | case 'S' : { | |
571 | shor t s = in.r eadShort() ; | |
572 | if ( resultArr != null) { | |
573 | resultArr[ 0] = new J avaShort(s ); | |
574 | } | |
575 | retu rn 2; | |
576 | } | |
577 | case 'C' : { | |
578 | char ch = in.r eadChar(); | |
579 | if ( resultArr != null) { | |
580 | resultArr[ 0] = new J avaChar(ch ); | |
581 | } | |
582 | retu rn 2; | |
583 | } | |
584 | case 'I' : { | |
585 | int val = in.r eadInt(); | |
586 | if ( resultArr != null) { | |
587 | resultArr[ 0] = new J avaInt(val ); | |
588 | } | |
589 | retu rn 4; | |
590 | } | |
591 | case 'J' : { | |
592 | long val = in. readLong() ; | |
593 | if ( resultArr != null) { | |
594 | resultArr[ 0] = new J avaLong(va l); | |
595 | } | |
596 | retu rn 8; | |
597 | } | |
598 | case 'F' : { | |
599 | floa t val = in .readFloat (); | |
600 | if ( resultArr != null) { | |
601 | resultArr[ 0] = new J avaFloat(v al); | |
602 | } | |
603 | retu rn 4; | |
604 | } | |
605 | case 'D' : { | |
606 | doub le val = i n.readDoub le(); | |
607 | if ( resultArr != null) { | |
608 | resultArr[ 0] = new J avaDouble( val); | |
609 | } | |
610 | retu rn 8; | |
611 | } | |
612 | default: { | |
613 | thro w new IOEx ception("B ad value s ignature: " + type) ; | |
614 | } | |
615 | } | |
616 | } | |
617 | ||
618 | privat e ThreadOb ject getTh readObject FromSequen ce(int thr eadSeq) | |
619 | throws I OException { | |
620 | Th readObject to = thre adObjects. get(new In teger(thre adSeq)); | |
621 | if (to == nu ll) { | |
622 | throw ne w IOExcept ion("Threa d " + thre adSeq + | |
623 | " not found for JNI local ref"); | |
624 | } | |
625 | re turn to; | |
626 | } | |
627 | ||
628 | privat e String g etNameFrom ID(long id ) throws I OException { | |
629 | re turn getNa meFromID(n ew Long(id )); | |
630 | } | |
631 | ||
632 | privat e String g etNameFrom ID(Long id ) throws I OException { | |
633 | if (id.longV alue() == 0L) { | |
634 | return " "; | |
635 | } | |
636 | St ring resul t = names. get(id); | |
637 | if (result = = null) { | |
638 | warn("Na me not fou nd at " + toHex(id.l ongValue() )); | |
639 | return " unresolved name " + toHex(id.l ongValue() ); | |
640 | } | |
641 | re turn resul t; | |
642 | } | |
643 | ||
644 | privat e StackTra ce getStac kTraceFrom Serial(int ser) thro ws IOExcep tion { | |
645 | if (stackTra ces == nul l) { | |
646 | return n ull; | |
647 | } | |
648 | St ackTrace r esult = st ackTraces. get(new In teger(ser) ); | |
649 | if (result = = null) { | |
650 | warn("St ack trace not found for serial # " + ser ); | |
651 | } | |
652 | re turn resul t; | |
653 | } | |
654 | ||
655 | // | |
656 | // Han dle a HPRO F_GC_CLASS _DUMP | |
657 | // Ret urn number of bytes read | |
658 | // | |
659 | privat e int read Class() th rows IOExc eption { | |
660 | lo ng id = re adID(); | |
661 | St ackTrace s tackTrace = getStack TraceFromS erial(in.r eadInt()); | |
662 | lo ng superId = readID( ); | |
663 | lo ng classLo aderId = r eadID(); | |
664 | lo ng signers Id = readI D(); | |
665 | lo ng protDom ainId = re adID(); | |
666 | lo ng reserve d1 = readI D(); | |
667 | lo ng reserve d2 = readI D(); | |
668 | in t instance Size = in. readInt(); | |
669 | in t bytesRea d = 7 * id entifierSi ze + 8; | |
670 | ||
671 | in t numConst PoolEntrie s = in.rea dUnsignedS hort(); | |
672 | by tesRead += 2; | |
673 | fo r (int i = 0; i < nu mConstPool Entries; i ++) { | |
674 | int inde x = in.rea dUnsignedS hort(); // unused | |
675 | bytesRea d += 2; | |
676 | bytesRea d += readV alue(null) ; // We ignore the value s | |
677 | } | |
678 | ||
679 | in t numStati cs = in.re adUnsigned Short(); | |
680 | by tesRead += 2; | |
681 | Ja vaThing[] valueBin = new JavaT hing[1]; | |
682 | Ja vaStatic[] statics = new JavaS tatic[numS tatics]; | |
683 | fo r (int i = 0; i < nu mStatics; i++) { | |
684 | long nam eId = read ID(); | |
685 | bytesRea d += ident ifierSize; | |
686 | byte typ e = in.rea dByte(); | |
687 | bytesRea d++; | |
688 | bytesRea d += readV alueForTyp e(type, va lueBin); | |
689 | String f ieldName = getNameFr omID(nameI d); | |
690 | if (vers ion >= VER SION_JDK12 BETA4) { | |
691 | type = signatu reFromType Id(type); | |
692 | } | |
693 | String s ignature = "" + ((ch ar) type); | |
694 | JavaFiel d f = new JavaField( fieldName, signature ); | |
695 | statics[ i] = new J avaStatic( f, valueBi n[0]); | |
696 | } | |
697 | ||
698 | in t numField s = in.rea dUnsignedS hort(); | |
699 | by tesRead += 2; | |
700 | Ja vaField[] fields = n ew JavaFie ld[numFiel ds]; | |
701 | fo r (int i = 0; i < nu mFields; i ++) { | |
702 | long nam eId = read ID(); | |
703 | bytesRea d += ident ifierSize; | |
704 | byte typ e = in.rea dByte(); | |
705 | bytesRea d++; | |
706 | String f ieldName = getNameFr omID(nameI d); | |
707 | if (vers ion >= VER SION_JDK12 BETA4) { | |
708 | type = signatu reFromType Id(type); | |
709 | } | |
710 | String s ignature = "" + ((ch ar) type); | |
711 | fields[i ] = new Ja vaField(fi eldName, s ignature); | |
712 | } | |
713 | St ring name = classNam eFromObjec tID.get(ne w Long(id) ); | |
714 | if (name == null) { | |
715 | warn("Cl ass name n ot found f or " + toH ex(id)); | |
716 | name = " unknown-na me@" + toH ex(id); | |
717 | } | |
718 | Ja vaClass c = new Java Class(id, name, supe rId, class LoaderId, signersId, | |
719 | prot DomainId, fields, st atics, | |
720 | inst anceSize); | |
721 | sn apshot.add Class(id, c); | |
722 | sn apshot.set SiteTrace( c, stackTr ace); | |
723 | ||
724 | re turn bytes Read; | |
725 | } | |
726 | ||
727 | privat e String t oHex(long addr) { | |
728 | re turn com.s un.tools.h at.interna l.util.Mis c.toHex(ad dr); | |
729 | } | |
730 | ||
731 | // | |
732 | // Han dle a HPRO F_GC_INSTA NCE_DUMP | |
733 | // Ret urn number of bytes read | |
734 | // | |
735 | privat e int read Instance() throws IO Exception { | |
736 | lo ng start = in.positi on(); | |
737 | lo ng id = re adID(); | |
738 | St ackTrace s tackTrace = getStack TraceFromS erial(in.r eadInt()); | |
739 | lo ng classID = readID( ); | |
740 | in t bytesFol lowing = i n.readInt( ); | |
741 | in t bytesRea d = (2 * i dentifierS ize) + 8 + bytesFoll owing; | |
742 | Ja vaObject j obj = new JavaObject (classID, start); | |
743 | sk ipBytes(by tesFollowi ng); | |
744 | sn apshot.add HeapObject (id, jobj) ; | |
745 | sn apshot.set SiteTrace( jobj, stac kTrace); | |
746 | re turn bytes Read; | |
747 | } | |
748 | ||
749 | // | |
750 | // Han dle a HPRO F_GC_OBJ_A RRAY_DUMP or HPROF_G C_PRIM_ARR AY_DUMP | |
751 | // Ret urn number of bytes read | |
752 | // | |
753 | privat e long rea dArray(boo lean isPri mitive) th rows IOExc eption { | |
754 | lo ng start = in.positi on(); | |
755 | lo ng id = re adID(); | |
756 | St ackTrace s tackTrace = getStack TraceFromS erial(in.r eadInt()); | |
757 | in t num = in .readInt() ; | |
758 | lo ng bytesRe ad = ident ifierSize + 8; | |
759 | lo ng element ClassID; | |
760 | if (isPrimit ive) { | |
761 | elementC lassID = i n.readByte (); | |
762 | bytesRea d++; | |
763 | } else { | |
764 | elementC lassID = r eadID(); | |
765 | bytesRea d += ident ifierSize; | |
766 | } | |
767 | ||
768 | // Check for primitive arrays: | |
769 | by te primiti veSignatur e = 0x00; | |
770 | in t elSize = 0; | |
771 | if (isPrimit ive || ver sion < VER SION_JDK12 BETA4) { | |
772 | switch ( (int)eleme ntClassID) { | |
773 | case T_BOOLEAN : { | |
774 | primitiveS ignature = (byte) 'Z '; | |
775 | elSize = 1 ; | |
776 | break; | |
777 | } | |
778 | case T_CHAR: { | |
779 | primitiveS ignature = (byte) 'C '; | |
780 | elSize = 2 ; | |
781 | break; | |
782 | } | |
783 | case T_FLOAT: { | |
784 | primitiveS ignature = (byte) 'F '; | |
785 | elSize = 4 ; | |
786 | break; | |
787 | } | |
788 | case T_DOUBLE: { | |
789 | primitiveS ignature = (byte) 'D '; | |
790 | elSize = 8 ; | |
791 | break; | |
792 | } | |
793 | case T_BYTE: { | |
794 | primitiveS ignature = (byte) 'B '; | |
795 | elSize = 1 ; | |
796 | break; | |
797 | } | |
798 | case T_SHORT: { | |
799 | primitiveS ignature = (byte) 'S '; | |
800 | elSize = 2 ; | |
801 | break; | |
802 | } | |
803 | case T_INT: { | |
804 | primitiveS ignature = (byte) 'I '; | |
805 | elSize = 4 ; | |
806 | break; | |
807 | } | |
808 | case T_LONG: { | |
809 | primitiveS ignature = (byte) 'J '; | |
810 | elSize = 8 ; | |
811 | break; | |
812 | } | |
813 | } | |
814 | if (vers ion >= VER SION_JDK12 BETA4 && p rimitiveSi gnature == 0x00) { | |
815 | thro w new IOEx ception("U nrecognize d typecode : " | |
816 | + elementC lassID); | |
817 | } | |
818 | } | |
819 | if (primitiv eSignature != 0x00) { | |
820 | long siz e = elSize * (long)n um; | |
821 | bytesRea d += size; | |
822 | JavaValu eArray va = new Java ValueArray (primitive Signature, start); | |
823 | skipByte s(size); | |
824 | snapshot .addHeapOb ject(id, v a); | |
825 | snapshot .setSiteTr ace(va, st ackTrace); | |
826 | } else { | |
827 | long sz = (long)nu m * identi fierSize; | |
828 | bytesRea d += sz; | |
829 | JavaObje ctArray ar r = new Ja vaObjectAr ray(elemen tClassID, start); | |
830 | skipByte s(sz); | |
831 | snapshot .addHeapOb ject(id, a rr); | |
832 | snapshot .setSiteTr ace(arr, s tackTrace) ; | |
833 | } | |
834 | re turn bytes Read; | |
835 | } | |
836 | ||
837 | privat e byte sig natureFrom TypeId(byt e typeId) throws IOE xception { | |
838 | sw itch (type Id) { | |
839 | case T_C LASS: { | |
840 | retu rn (byte) 'L'; | |
841 | } | |
842 | case T_B OOLEAN: { | |
843 | retu rn (byte) 'Z'; | |
844 | } | |
845 | case T_C HAR: { | |
846 | retu rn (byte) 'C'; | |
847 | } | |
848 | case T_F LOAT: { | |
849 | retu rn (byte) 'F'; | |
850 | } | |
851 | case T_D OUBLE: { | |
852 | retu rn (byte) 'D'; | |
853 | } | |
854 | case T_B YTE: { | |
855 | retu rn (byte) 'B'; | |
856 | } | |
857 | case T_S HORT: { | |
858 | retu rn (byte) 'S'; | |
859 | } | |
860 | case T_I NT: { | |
861 | retu rn (byte) 'I'; | |
862 | } | |
863 | case T_L ONG: { | |
864 | retu rn (byte) 'J'; | |
865 | } | |
866 | default: { | |
867 | thro w new IOEx ception("I nvalid typ e id of " + typeId); | |
868 | } | |
869 | } | |
870 | } | |
871 | ||
872 | privat e void han dleEOF(EOF Exception exp, Snaps hot snapsh ot) { | |
873 | if (debugLev el > 0) { | |
874 | exp.prin tStackTrac e(); | |
875 | } | |
876 | wa rn("Unexpe cted EOF. Will miss informatio n..."); | |
877 | // we have E OF, we hav e to toler ate missin g referenc es | |
878 | sn apshot.set Unresolved ObjectsOK( true); | |
879 | } | |
880 | ||
881 | privat e void war n(String m sg) { | |
882 | Sy stem.out.p rintln("WA RNING: " + msg); | |
883 | } | |
884 | ||
885 | // | |
886 | // A t rivial dat a-holder c lass for H PROF_GC_RO OT_THREAD_ OBJ. | |
887 | // | |
888 | privat e class Th readObject { | |
889 | ||
890 | lo ng threadI d; | |
891 | in t stackSeq ; | |
892 | ||
893 | Th readObject (long thre adId, int stackSeq) { | |
894 | this.thr eadId = th readId; | |
895 | this.sta ckSeq = st ackSeq; | |
896 | } | |
897 | } | |
898 | ||
899 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.