5555 */
5656public class DataReaderSun1_6_0G1 extends AbstractDataReaderSun {
5757
58- private static final String INCOMPLETE_CONCURRENT_MARK_INDICATOR = "concurrent-mark " ;
58+ private static final String INCOMPLETE_CONCURRENT_EVENT_INDICATOR = "concurrent-" ;
5959
6060 private static final Logger LOG = Logger .getLogger (DataReaderSun1_6_0G1 .class .getName ());
6161
@@ -115,8 +115,12 @@ public class DataReaderSun1_6_0G1 extends AbstractDataReaderSun {
115115 HEAP_STRINGS .add ("Metaspace" ); // java 8
116116 HEAP_STRINGS .add ("class space" ); // java 8
117117 HEAP_STRINGS .add ("}" );
118+ HEAP_STRINGS .add ("[0x" ); // special case of line following one containing a concurrent event mixed with heap information
118119 }
119120
121+ /** is true, if "[Times ..." information is present in the gc log */
122+ private boolean hasTimes = false ;
123+
120124 public DataReaderSun1_6_0G1 (InputStream in , GcLogType gcLogType ) throws UnsupportedEncodingException {
121125 super (in , gcLogType );
122126 }
@@ -288,10 +292,10 @@ else if (line.indexOf(Type.FULL_GC.getName()) > 0) {
288292 }
289293 else if (line .indexOf (HEAP_SIZING_START ) >= 0 ) {
290294 // the next few lines will be the sizing of the heap
291- lineNumber = skipLines (in , parsePosition , lineNumber , HEAP_STRINGS );
295+ lineNumber = skipLinesRespectingConcurrentEvents (in , model , parsePosition , lineNumber , HEAP_STRINGS );
292296 continue ;
293297 }
294- else if (line . indexOf ( INCOMPLETE_CONCURRENT_MARK_INDICATOR ) >= 0 ) {
298+ else if (hasIncompleteConcurrentEvent ( line , parsePosition ) ) {
295299 parseIncompleteConcurrentEvent (model , model .getLastEventAdded (), line , parsePosition );
296300 }
297301 else {
@@ -313,6 +317,12 @@ else if (line.indexOf(INCOMPLETE_CONCURRENT_MARK_INDICATOR) >= 0) {
313317 }
314318 }
315319
320+ private boolean hasIncompleteConcurrentEvent (String line , ParseInformation paresPosition ) {
321+ return !nextIsTimestamp (line , paresPosition )
322+ && !nextIsDatestamp (line , paresPosition )
323+ && line .indexOf (INCOMPLETE_CONCURRENT_EVENT_INDICATOR ) >= 0 ;
324+ }
325+
316326 /**
317327 * Returns true, if <code>line</code> ends with one of the detailed event types.
318328 *
@@ -357,7 +367,11 @@ private int parseDetails(BufferedReader in,
357367 ++lineNumber ;
358368 pos .setLineNumber (lineNumber );
359369 pos .setIndex (0 );
360-
370+
371+ if (line .length () == 0 ) {
372+ continue ;
373+ }
374+
361375 // we might have had a mixed line before; then we just parsed the second part of the mixed line
362376 if (beginningOfLine != null ) {
363377 line = beginningOfLine + line ;
@@ -371,7 +385,13 @@ private int parseDetails(BufferedReader in,
371385 if (line .indexOf ("Eden" ) >= 0 ) {
372386 parseMemoryDetails (event , line , pos );
373387 }
374- else if (line .indexOf (INCOMPLETE_CONCURRENT_MARK_INDICATOR ) >= 0 ) {
388+ else if (line .charAt (0 ) != ' ' && !hasTimes && (nextIsDatestamp (line , pos ) || nextIsTimestamp (line , pos ))) {
389+ // special case for simple logs (marked by missing "[Times..." in the log)
390+ // since the line starts with a time / datestamp, the detailed event seems to be finished (unexpectedly)
391+ model .add (parseLine (line , pos ));
392+ isInDetailedEvent = false ;
393+ }
394+ else if (line .indexOf (INCOMPLETE_CONCURRENT_EVENT_INDICATOR ) >= 0 ) {
375395 parseIncompleteConcurrentEvent (model , event , line , pos );
376396 }
377397 else {
@@ -387,6 +407,7 @@ else if (line.indexOf(INCOMPLETE_CONCURRENT_MARK_INDICATOR) >= 0) {
387407 if (line .indexOf (TIMES ) >= 0 ) {
388408 // detailed gc description ends with " [Times: user=...]" -> stop reading lines
389409 isInDetailedEvent = false ;
410+ hasTimes = true ;
390411 }
391412 }
392413
@@ -462,7 +483,11 @@ private void parseIncompleteConcurrentEvent(GCModel model, AbstractGCEvent<?> pr
462483 // some concurrent event is mixed in -> extract it
463484 pos .setIndex (line .indexOf ("GC conc" ));
464485 ExtendedType type = parseType (line , pos );
465- model .add (parseConcurrentEvent (line , pos , previousEvent .getDatestamp (), previousEvent .getTimestamp (), type ));
486+ model .add (parseConcurrentEvent (line ,
487+ pos ,
488+ previousEvent != null ? previousEvent .getDatestamp () : null ,
489+ previousEvent != null ? previousEvent .getTimestamp () : 0 ,
490+ type ));
466491 }
467492
468493 @ Override
@@ -544,4 +569,58 @@ private AbstractGCEvent<?> parseConcurrentEvent(String line,
544569 return event ;
545570 }
546571
572+ /**
573+ * Skips a block of lines containing information like they are generated by
574+ * -XX:+PrintHeapAtGC or -XX:+PrintAdaptiveSizePolicy.
575+ *
576+ * @param in inputStream of the current log to be read
577+ * @param lineNumber current line number
578+ * @param lineStartStrings lines starting with these strings should be ignored
579+ * @return line number including lines read in this method
580+ * @throws IOException problem with reading from the file
581+ */
582+ private int skipLinesRespectingConcurrentEvents (BufferedReader in , GCModel model , ParseInformation pos , int lineNumber , List <String > lineStartStrings ) throws IOException {
583+ String line = "" ;
584+
585+ if (!in .markSupported ()) {
586+ LOG .warning ("input stream does not support marking!" );
587+ }
588+ else {
589+ in .mark (200 );
590+ }
591+
592+ boolean startsWithString = true ;
593+ while (startsWithString && (line = in .readLine ()) != null ) {
594+ ++lineNumber ;
595+ pos .setLineNumber (lineNumber );
596+
597+ if (line .indexOf (INCOMPLETE_CONCURRENT_EVENT_INDICATOR ) >= 0 ) {
598+ parseIncompleteConcurrentEvent (model , model .getLastEventAdded (), line , pos );
599+ }
600+ else {
601+ // for now just skip those lines
602+ startsWithString = startsWith (line , lineStartStrings , true );
603+ if (startsWithString ) {
604+ // don't mark any more if line didn't match -> it is the first line that
605+ // is of interest after the skipped block
606+ if (in .markSupported ()) {
607+ in .mark (200 );
608+ }
609+ }
610+ }
611+ }
612+
613+ // push last read line back into stream - it is the next event to be parsed
614+ if (in .markSupported ()) {
615+ try {
616+ in .reset ();
617+ }
618+ catch (IOException e ) {
619+ throw new ParseException ("problem resetting stream (" + e .toString () + ")" , line , pos );
620+ }
621+ }
622+
623+ return --lineNumber ;
624+ }
625+
547626}
0 commit comments