in core/org.openjdk.jmc.flightrecorder.rules.jdk/src/main/java/org/openjdk/jmc/flightrecorder/rules/jdk/compilation/CodeCacheRule.java [137:255]
private Result getResult(IItemCollection items, IPreferenceValueProvider valueProvider) {
EventAvailability eventAvailability = RulesToolkit.getEventAvailability(items, JdkTypeIDs.CODE_CACHE_FULL,
JdkTypeIDs.VM_INFO, JdkTypeIDs.CODE_CACHE_STATISTICS, JdkTypeIDs.CODE_CACHE_CONFIG);
if (eventAvailability != EventAvailability.ENABLED && eventAvailability != EventAvailability.AVAILABLE) {
return RulesToolkit.getEventAvailabilityResult(this, items, eventAvailability, JdkTypeIDs.CODE_CACHE_FULL,
JdkTypeIDs.VM_INFO, JdkTypeIDs.CODE_CACHE_STATISTICS, JdkTypeIDs.CODE_CACHE_CONFIG);
}
eventAvailability = RulesToolkit.getEventAvailability(items, JdkTypeIDs.CODE_CACHE_CONFIG);
if (eventAvailability != EventAvailability.AVAILABLE) {
return RulesToolkit.getEventAvailabilityResult(this, items, eventAvailability,
JdkTypeIDs.CODE_CACHE_CONFIG);
}
// 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) {
String shortDescription = Messages.getString(Messages.CodeCacheRuleFactory_TEXT_WARN);
String longDescription = shortDescription + "<p>" //$NON-NLS-1$
+ Messages.getString(Messages.CodeCacheRuleFactory_TEXT_WARN_LONG) + "<p>" //$NON-NLS-1$
+ Messages.getString(Messages.CodeCacheRuleFactory_BLOG_REFERENCE);
return new Result(this, 100, shortDescription, longDescription, JdkQueries.CODE_CACHE_FULL);
}
IQuantity infoPreferenceValue = valueProvider.getPreferenceValue(CODE_CACHE_SIZE_INFO_PERCENT);
IQuantity warningPreferenceValue = valueProvider.getPreferenceValue(CODE_CACHE_SIZE_WARN_PERCENT);
double allocationRatioScore = 0;
String shortDescription = null;
String longDescription = null;
if (hasSegmentedCodeCache(items)) {
if (!ccType.hasAttribute(JdkAttributes.PROFILED_SIZE)) {
return RulesToolkit.getMissingAttributeResult(this, ccType, JdkAttributes.PROFILED_SIZE);
}
IQuantity profiledAggregate = items
.getAggregate(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(Aggregators.min(JdkAttributes.PROFILED_SIZE))));
} else {
profiledRatio = UnitLookup.PERCENT_UNITY.quantity(1.0);
}
IQuantity nonProfiledAggregate = items
.getAggregate(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(Aggregators.min(JdkAttributes.NON_PROFILED_SIZE))));
} else {
nonProfiledRatio = UnitLookup.PERCENT_UNITY.quantity(1.0);
}
IQuantity nonNMethodsRatio = UnitLookup.PERCENT_UNITY.quantity(items
.getAggregate(Aggregators.filter(Aggregators.min(JdkAttributes.UNALLOCATED),
ItemFilters.matches(JdkAttributes.CODE_HEAP, NON_NMETHODS_NAME)))
.ratioTo(items.getAggregate(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);
if (heaps.size() > 0) {
if (heaps.size() > 1) {
shortDescription = MessageFormat.format(
Messages.getString(Messages.CodeCacheRuleFactory_WARN_SEGMENTED_HEAPS_SHORT_DESCRIPTION),
StringToolkit.join(heaps, ",")); //$NON-NLS-1$
} else {
shortDescription = MessageFormat.format(
Messages.getString(Messages.CodeCacheRuleFactory_WARN_SEGMENTED_HEAP_SHORT_DESCRIPTION),
heaps.get(0));
}
longDescription = shortDescription + " " //$NON-NLS-1$
+ Messages.getString(Messages.CodeCacheRuleFactory_WARN_LONG_DESCRIPTION) + "<p>" //$NON-NLS-1$
+ Messages.getString(Messages.CodeCacheRuleFactory_DEFAULT_LONG_DESCRIPTION) + "<p>" //$NON-NLS-1$
+ Messages.getString(Messages.CodeCacheRuleFactory_BLOG_REFERENCE);
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);
}
IQuantity codeCacheReserved = items
.getAggregate(Aggregators.min(JdkTypeIDs.CODE_CACHE_CONFIG, JdkAttributes.RESERVED_SIZE));
IQuantity unallocated = items
.getAggregate(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));
shortDescription = MessageFormat.format(Messages.getString(Messages.CodeCacheRuleFactory_JDK8_TEXT_WARN),
unallocatedCodeCachePercent.displayUsing(IDisplayable.AUTO));
longDescription = shortDescription + "<p>" //$NON-NLS-1$
+ Messages.getString(Messages.CodeCacheRuleFactory_DEFAULT_LONG_DESCRIPTION) + "<p>" //$NON-NLS-1$
+ Messages.getString(Messages.CodeCacheRuleFactory_BLOG_REFERENCE);
}
if (allocationRatioScore >= 25) {
// FIXME: Include configured value of code cache size in long description
return new Result(this, allocationRatioScore, shortDescription, longDescription);
}
// FIXME: Show calculated free value also in ok text
return new Result(this, allocationRatioScore, Messages.getString(Messages.CodeCacheRuleFactory_TEXT_OK));
}