protected void memory()

in analysis/gc-log/src/main/java/org/eclipse/jifa/gclog/diagnoser/EventAbnormalDetector.java [127:198]


    protected void memory() {
        List<MemoryArea> areasToCheck = new ArrayList<>(5);
        if (model.isGenerational()) {
            areasToCheck.add(YOUNG);
            areasToCheck.add(OLD);
        }
        if (model.hasHumongousArea()) {
            areasToCheck.add(HUMONGOUS);
        }
        areasToCheck.add(HEAP);
        areasToCheck.add(METASPACE);


        for (GCEvent event : model.getGcCollectionEvents()) {
            GCMemoryItem heap = event.getMemoryItem(HEAP);
            long heapCapacity = heap != null ? heap.getPostCapacity() : UNKNOWN_INT;
            for (MemoryArea area : areasToCheck) {
                GCMemoryItem memory = event.getMemoryItem(area);
                if (memory == null) {
                    continue;
                }

                // post capacity
                long capacity = memory.getPostCapacity();
                if (capacity != UNKNOWN_INT && heapCapacity != UNKNOWN_INT && (area == YOUNG || area == OLD)) {
                    // only check one case: generation capacity is too small
                    long threshold = (long) (config.getSmallGenerationThreshold() * heapCapacity / 100);
                    if (capacity <= threshold) {
                        addAbnormal(event, area == YOUNG ? BAD_YOUNG_GEN_CAPACITY : BAD_OLD_GEN_CAPACITY);
                    }
                }

                // post used
                long postUsed = memory.getPostUsed();
                if (area == YOUNG || postUsed == UNKNOWN_INT) {
                    continue;
                }
                // check one case: used is too high after gc
                if (area == OLD) {
                    // FIXME: in JDK8, printed g1 post capacity may be much smaller than eden preused of the next
                    //  young gc. Maybe we need to improve this check
                    if (capacity != UNKNOWN_INT && (event.isFullGC() || event.isTrue(GC_AT_END_OF_OLD_CYCLE))) {
                        long threshold = (long) (capacity * config.getHighOldUsageThreshold() / 100);
                        if (postUsed > threshold) {
                            addAbnormal(event, BAD_OLD_USED);
                        }
                    }
                } else if (area == HUMONGOUS) {
                    if (heapCapacity != UNKNOWN_INT) {
                        long threshold = (long) (heapCapacity * config.getHighHumongousUsageThreshold() / 100);
                        if (postUsed >= threshold) {
                            addAbnormal(event, BAD_HUMONGOUS_USED);
                        }
                    }
                } else if (area == HEAP) {
                    if (capacity != UNKNOWN_INT && (event.isFullGC() || event.isTrue(GC_AT_END_OF_OLD_CYCLE))) {
                        long threshold = (long) (capacity * config.getHighOldUsageThreshold() / 100);
                        if (postUsed > threshold) {
                            addAbnormal(event, BAD_HEAP_USED);
                        }
                    }
                } else if (area == METASPACE) {
                    if (capacity != UNKNOWN_INT && (event.isFullGC() || event.isTrue(GC_AFTER_REMARK))) {
                        long threshold = (long) (capacity * config.getHighMetaspaceUsageThreshold() / 100);
                        if (postUsed > threshold) {
                            addAbnormal(event, BAD_METASPACE_USED);
                        }
                    }
                }
            }
        }
    }