Repository: microsoft/gctoolkit
File: parser/src/main/java/com/microsoft/gctoolkit/parser/ZGCParser.java (Java)

Code before:
                        trace.toKBytes(3),
                        trace.toKBytes(6)));

        if (trace.getGroup(9) != null) {
            ref.setGcDuration(trace.getSeconds(9));
        }

        publish(ref.getGCEVent(getClock()));
    }

    private void memorySummary(GCLogTrace trace, String s) {
        if (diary.isGenerationalZGC()) {
            long gcId = trace.getLongGroup(1);
            
            if (gcCauseMap.containsKey(gcId)) {
            	gcCauseMap.remove(gcId);
            } 
            
            // We use the lack of a MemorySummary in the forwardReference as a sign that this is the case and
            // that we need to publish a Generational no-details event.
       		ZGCCycleType type = ZGCCycleType.get(trace.getGroup(2));
           	ZGCForwardReference forwardReference = ZGCCycleType.MAJOR.equals(type) ? 
            			getForwardRefForPhase(ZGCPhase.MAJOR_YOUNG) :
            			getForwardRefForPhase(ZGCPhase.MINOR_YOUNG);
           	
           	if (forwardReference != null && !forwardReference.hasMemorySummary()) {
                forwardReference.setMemorySummary(
                        new ZGCMemorySummary(
                                trace.toKBytes(4),
                                trace.toKBytes(7)));
                publish(forwardReference.getGCEVent(getClock()));
            }
        } else {
            ZGCForwardReference forwardReference = getForwardRefForPhase(ZGCPhase.FULL);
            
        	// For Legacy ZGC (Java 17, non-generational) with no details (gc instead of gc*), only a single line
        	// is logged per event. As such, getForwardRefForPhase will return NULL. 
        	if (forwardReference == null) {
        		// Forward reference has not yet been created, so we'll create it now
        		ZGCCycleType type = ZGCCycleType.get(trace.getGroup(2));
        		forwardReference = new ZGCForwardReference(
        				getClock(), trace.getLongGroup(1), trace.gcCause(3,0), type, ZGCPhase.FULL);
        	}
        	
            forwardReference.setMemorySummary(
                    new ZGCMemorySummary(
                            trace.toKBytes(4),
                            trace.toKBytes(7)));
            publish(forwardReference.getGCEVent(getClock()));
        }
        // TODO - Get rid of this?

Review comment (suggestion):
Nitpick, but I have a slight preference for putting that logic into a function that effectively says what you said in the comment.  e.g. Not the hill I'm going to die on though :-)

// Comment
if (noMemorySummary()) {
....

Code after:
                        trace.toKBytes(3),
                        trace.toKBytes(6)));

        if (trace.getGroup(9) != null) {
            ref.setGcDuration(trace.getSeconds(9));
        }

        publish(ref.getGCEVent(getClock()));
    }

    private void memorySummary(GCLogTrace trace, String s) {
        if (diary.isGenerationalZGC()) {
            long gcId = trace.getLongGroup(1);
            
            if (gcCauseMap.containsKey(gcId)) {
            	gcCauseMap.remove(gcId);
            } 
            
            // Publish a non-detailed generational event if present.
            publishIfMemorySummaryMissing(trace);
            
        } else {
            ZGCForwardReference forwardReference = getForwardRefForPhase(ZGCPhase.FULL);
            
        	// For Legacy ZGC (Java 17, non-generational) with no details (gc instead of gc*), only a single line
        	// is logged per event. As such, getForwardRefForPhase will return NULL. 
        	if (forwardReference == null) {
        		// Forward reference has not yet been created, so we'll create it now
        		ZGCCycleType type = ZGCCycleType.get(trace.getGroup(2));
        		forwardReference = new ZGCForwardReference(
        				getClock(), trace.getLongGroup(1), trace.gcCause(3,0), type, ZGCPhase.FULL);
        	}
        	
            forwardReference.setMemorySummary(
                    new ZGCMemorySummary(
                            trace.toKBytes(4),
                            trace.toKBytes(7)));
            publish(forwardReference.getGCEVent(getClock()));
        }
        // TODO - Get rid of this?
        Arrays.fill(heapCapacity, 0L);
    }
    
    private void publishIfMemorySummaryMissing(GCLogTrace trace) {
    	if (trace == null)
    		return;
    	
        // We use the lack of a MemorySummary in the forwardReference as a sign
    	// that we need to publish a Generational no-details event.
   		ZGCCycleType cycleType = ZGCCycleType.get(trace.getGroup(2));
    	ZGCForwardReference forwardReference = ZGCCycleType.MAJOR.equals(cycleType) ?