Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package com.oracle.svm.hosted;

import java.lang.annotation.Annotation;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -74,12 +75,15 @@
import com.oracle.svm.hosted.meta.HostedMetaAccess;
import com.oracle.svm.hosted.meta.HostedUniverse;
import com.oracle.svm.hosted.substitute.UnsafeAutomaticSubstitutionProcessor;
import com.oracle.svm.util.ReflectionUtil;

import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.MetaAccessProvider;
import jdk.vm.ci.meta.ResolvedJavaField;

public class HostedConfiguration {
@SuppressWarnings("unchecked") private static final Class<? extends Annotation> VALUE_BASED_ANNOTATION = //
(Class<? extends Annotation>) ReflectionUtil.lookupClass(false, "jdk.internal.ValueBased");

public HostedConfiguration() {
}
Expand Down Expand Up @@ -230,7 +234,10 @@ public AbstractAnalysisResultsBuilder createStaticAnalysisResultsBuilder(Inflati

public void collectMonitorFieldInfo(BigBang bb, HostedUniverse hUniverse, Set<AnalysisType> immutableTypes) {
/* First set the monitor field for types that always need it. */
getForceMonitorSlotTypes(bb).forEach(type -> setMonitorField(hUniverse, type));
for (AnalysisType type : getForceMonitorSlotTypes(bb)) {
assert !immutableTypes.contains(type);
setMonitorField(hUniverse, type);
}

/* Then decide what other types may need it. */
processedSynchronizedTypes(bb, hUniverse, immutableTypes);
Expand All @@ -253,11 +260,16 @@ protected void processedSynchronizedTypes(BigBang bb, HostedUniverse hUniverse,
}

/**
* Monitor fields on arrays would increase the array header too much. Also, types that must be
* immutable cannot have a monitor field.
* Monitor fields on arrays would enlarge the array header too much.
*
* Also, never burden @ValueBased classes with a monitor field, which in particular reduces
* sizes of boxed primitives. Using monitors with those types is discouraged (instances are
* often cached) and not guaranteed to work in the future.
*
* Types that must be immutable cannot have a monitor field.
*/
protected static void maybeSetMonitorField(HostedUniverse hUniverse, Set<AnalysisType> immutableTypes, AnalysisType type) {
if (!type.isArray() && !immutableTypes.contains(type)) {
if (!type.isArray() && !immutableTypes.contains(type) && !type.isAnnotationPresent(VALUE_BASED_ANNOTATION)) {
setMonitorField(hUniverse, type);
}
}
Expand Down