in src/core/org.openjdk.jmc.flightrecorder.rules.jdk/src/main/java/org/openjdk/jmc/flightrecorder/rules/jdk/compilation/CodeCacheRule.java [167:275]
private IResult getResult(
IItemCollection items, IPreferenceValueProvider valueProvider, IResultValueProvider resultProvider) {
// Check if this is an early unsupported recording
IItemCollection ccItems = items.apply(JdkFilters.CODE_CACHE_CONFIGURATION);
IType<IItem> ccType = RulesToolkit.getType(ccItems, JdkTypeIDs.CODE_CACHE_CONFIG);
IQuantity ccFullCount = items.getAggregate(JdkAggregators.CODE_CACHE_FULL_COUNT);
if (ccFullCount != null && ccFullCount.doubleValue() > 0) {
return ResultBuilder.createFor(this, valueProvider).setSeverity(Severity.WARNING)
.setSummary(Messages.getString(Messages.CodeCacheRuleFactory_TEXT_WARN))
.setExplanation(Messages.getString(Messages.CodeCacheRuleFactory_TEXT_WARN_LONG))
.setSolution(Messages.getString(Messages.CodeCacheRuleFactory_BLOG_REFERENCE)).build();
}
IQuantity infoPreferenceValue = valueProvider.getPreferenceValue(CODE_CACHE_SIZE_INFO_PERCENT);
IQuantity warningPreferenceValue = valueProvider.getPreferenceValue(CODE_CACHE_SIZE_WARN_PERCENT);
double allocationRatioScore = 0;
String longDescription = null;
ResultBuilder builder = ResultBuilder.createFor(this, valueProvider);
if (hasSegmentedCodeCache(items)) {
if (!ccType.hasAttribute(JdkAttributes.PROFILED_SIZE)) {
return RulesToolkit.getMissingAttributeResult(this, ccType, JdkAttributes.PROFILED_SIZE, valueProvider);
}
IQuantity profiledAggregate = items.getAggregate(
(IAggregator<IQuantity, ?>) Aggregators.filter(Aggregators.min(JdkAttributes.UNALLOCATED),
ItemFilters.matches(JdkAttributes.CODE_HEAP, PROFILED_NAME)));
IQuantity profiledRatio = null;
if (profiledAggregate != null) {
profiledRatio = UnitLookup.PERCENT_UNITY.quantity(profiledAggregate.ratioTo(
items.getAggregate((IAggregator<IQuantity, ?>) Aggregators.min(JdkAttributes.PROFILED_SIZE))));
} else {
profiledRatio = UnitLookup.PERCENT_UNITY.quantity(1.0);
}
IQuantity nonProfiledAggregate = items.getAggregate(
(IAggregator<IQuantity, ?>) Aggregators.filter(Aggregators.min(JdkAttributes.UNALLOCATED),
ItemFilters.matches(JdkAttributes.CODE_HEAP, NON_PROFILED_NAME)));
IQuantity nonProfiledRatio = null;
if (nonProfiledAggregate != null) {
nonProfiledRatio = UnitLookup.PERCENT_UNITY.quantity(nonProfiledAggregate.ratioTo(items
.getAggregate((IAggregator<IQuantity, ?>) Aggregators.min(JdkAttributes.NON_PROFILED_SIZE))));
} else {
nonProfiledRatio = UnitLookup.PERCENT_UNITY.quantity(1.0);
}
IQuantity nonNMethodsRatio = UnitLookup.PERCENT_UNITY.quantity(items
.getAggregate(
(IAggregator<IQuantity, ?>) Aggregators.filter(Aggregators.min(JdkAttributes.UNALLOCATED),
ItemFilters.matches(JdkAttributes.CODE_HEAP, NON_NMETHODS_NAME)))
.ratioTo(items.getAggregate(
(IAggregator<IQuantity, ?>) Aggregators.min(JdkAttributes.NON_NMETHOD_SIZE))));
List<CodeHeapData> heaps = new ArrayList<>();
addIfHalfFull(profiledRatio, heaps, PROFILED_NAME);
addIfHalfFull(nonProfiledRatio, heaps, NON_PROFILED_NAME);
addIfHalfFull(nonNMethodsRatio, heaps, NON_NMETHODS_NAME);
IQuantity worstRatio;
Collections.sort(heaps);
builder.addResult(CODE_HEAPS, heaps);
if (heaps.size() > 0) {
if (heaps.size() > 1) {
builder.setSummary(
Messages.getString(Messages.CodeCacheRuleFactory_WARN_SEGMENTED_HEAPS_SHORT_DESCRIPTION));
} else {
builder.setSummary(
Messages.getString(Messages.CodeCacheRuleFactory_WARN_SEGMENTED_HEAP_SHORT_DESCRIPTION));
}
longDescription = Messages.getString(Messages.CodeCacheRuleFactory_WARN_LONG_DESCRIPTION) + "\n" //$NON-NLS-1$
+ Messages.getString(Messages.CodeCacheRuleFactory_DEFAULT_LONG_DESCRIPTION) + "\n" //$NON-NLS-1$
+ Messages.getString(Messages.CodeCacheRuleFactory_BLOG_REFERENCE);
builder.setExplanation(longDescription);
worstRatio = heaps.get(0).getRatio();
} else {
/*
* FIXME: JMC-5606 - If we end up in this block, then descriptions will not be set.
* Either set some reasonable result descriptions or change the code so that we
* don't get null descriptions when we create the result.
*/
List<IQuantity> ratios = Arrays.asList(profiledRatio, nonProfiledRatio, nonNMethodsRatio);
Collections.sort(ratios);
worstRatio = ratios.get(0);
}
allocationRatioScore = RulesToolkit.mapExp100(100 - worstRatio.doubleValueIn(UnitLookup.PERCENT),
infoPreferenceValue.doubleValueIn(UnitLookup.PERCENT),
warningPreferenceValue.doubleValueIn(UnitLookup.PERCENT));
} else {
if (!ccType.hasAttribute(JdkAttributes.RESERVED_SIZE)) {
return RulesToolkit.getMissingAttributeResult(this, ccType, JdkAttributes.RESERVED_SIZE, valueProvider);
}
IQuantity codeCacheReserved = items.getAggregate((IAggregator<IQuantity, ?>) Aggregators
.min(JdkTypeIDs.CODE_CACHE_CONFIG, JdkAttributes.RESERVED_SIZE));
IQuantity unallocated = items.getAggregate((IAggregator<IQuantity, ?>) Aggregators
.min(JdkTypeIDs.CODE_CACHE_STATISTICS, JdkAttributes.UNALLOCATED));
IQuantity unallocatedCodeCachePercent = UnitLookup.PERCENT_UNITY
.quantity(unallocated.ratioTo(codeCacheReserved));
allocationRatioScore = RulesToolkit.mapExp100(
100 - unallocatedCodeCachePercent.doubleValueIn(UnitLookup.PERCENT),
infoPreferenceValue.doubleValueIn(UnitLookup.PERCENT),
warningPreferenceValue.doubleValueIn(UnitLookup.PERCENT));
builder.setSummary(Messages.getString(Messages.CodeCacheRuleFactory_JDK8_TEXT_WARN))
.addResult(CODE_CACHE_FREE_RATIO, unallocatedCodeCachePercent);
longDescription = Messages.getString(Messages.CodeCacheRuleFactory_DEFAULT_LONG_DESCRIPTION) + "\n" //$NON-NLS-1$
+ Messages.getString(Messages.CodeCacheRuleFactory_BLOG_REFERENCE);
builder.setExplanation(longDescription);
}
if (allocationRatioScore >= 25) {
// FIXME: Include configured value of code cache size in long description
return builder.setSeverity(Severity.get(allocationRatioScore))
.addResult(TypedResult.SCORE, UnitLookup.NUMBER_UNITY.quantity(allocationRatioScore)).build();
}
// FIXME: Show calculated free value also in ok text
return builder.setSeverity(Severity.OK).setSummary(Messages.getString(Messages.CodeCacheRuleFactory_TEXT_OK))
.addResult(TypedResult.SCORE, UnitLookup.NUMBER_UNITY.quantity(allocationRatioScore)).build();
}