use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.
the class UniverseBuilder method collectMonitorFieldInfo.
// @formatter:off
// /**
// * New version of the method that uses the static analysis results collected by the static
// * analysis results builder instead of accessing the type states directly.
// */
// @SuppressWarnings("try")
// private void collectHashCodeFieldInfo() {
//
// AnalysisMethod method = null;
// try {
// method = aMetaAccess.lookupJavaMethod(System.class.getMethod("identityHashCode", Object.class));
// } catch (NoSuchMethodException | SecurityException e) {
// throw shouldNotReachHere();
// }
// if (method == null) {
// return;
// }
//
// try (Indent indent = Debug.logAndIndent("check types for which identityHashCode is invoked")) {
//
// // Check which types may be a parameter of System.identityHashCode (which is invoked by
// // Object.hashCode).
//
// HostedMethod hMethod = hUniverse.methods.get(method);
// JavaTypeProfile paramProfile = hMethod.getProfilingInfo().getParameterTypeProfile(0);
//
// if (paramProfile == null) {
//
// // This is the case if the identityHashCode parameter type is unknown. So all
// // classes get the hashCode field.
// // But this is only a fail-safe, because it cannot happen in the current
// // implementation of the analysis pass.
//
// Debug.log("all types need a hashCode field");
// for (HostedType hType : hUniverse.getTypes()) {
// if (hType.isInstanceClass()) {
// ((HostedInstanceClass) hType).setNeedHashCodeField();
// }
// }
// hUniverse.getObjectClass().setNeedHashCodeField();
// } else {
//
// // Mark all paramter types of System.identityHashCode to have a hash-code field.
//
// for (ProfiledType type : paramProfile.getTypes()) {
// Debug.log("type %s is argument to identityHashCode", type);
//
// /*
// * Array types get a hash-code field by default. So we only have to deal with
// * instance types here.
// */
// if (type.getType().isInstanceClass()) {
// HostedInstanceClass hType = (HostedInstanceClass) hUniverse.lookup(type.getType());
// hType.setNeedHashCodeField();
// }
// }
// }
// }
// }
// @formatter:on
private void collectMonitorFieldInfo(BigBang bb) {
if (!SubstrateOptions.MultiThreaded.getValue()) {
/* No locking information needed in single-threaded mode. */
return;
}
TypeState allSynchronizedTypeState = bb.getAllSynchronizedTypeState();
for (AnalysisType aType : allSynchronizedTypeState.types()) {
if (canHaveMonitorFields(aType)) {
final HostedInstanceClass hostedInstanceClass = (HostedInstanceClass) hUniverse.lookup(aType);
hostedInstanceClass.setNeedMonitorField();
}
}
}
use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.
the class StaticAnalysisResultsBuilder method makeResults.
public StaticAnalysisResults makeResults(AnalysisMethod method) {
MethodTypeFlow methodFlow = method.getTypeFlow();
MethodFlowsGraph originalFlows = methodFlow.getOriginalMethodFlows();
ArrayList<JavaTypeProfile> paramProfiles = new ArrayList<>(originalFlows.getParameters().length);
for (int i = 0; i < originalFlows.getParameters().length; i++) {
JavaTypeProfile paramProfile = makeTypeProfile(methodFlow.foldTypeFlow(bb, originalFlows.getParameter(i)));
if (paramProfile != null) {
ensureSize(paramProfiles, i);
paramProfiles.set(i, paramProfile);
}
}
JavaTypeProfile[] parameterTypeProfiles = null;
if (paramProfiles.size() > 0) {
parameterTypeProfiles = paramProfiles.toArray(new JavaTypeProfile[paramProfiles.size()]);
}
JavaTypeProfile resultTypeProfile = makeTypeProfile(methodFlow.foldTypeFlow(bb, originalFlows.getResult()));
ArrayList<BytecodeEntry> entries = new ArrayList<>(method.getCodeSize());
for (InstanceOfTypeFlow originalInstanceOf : originalFlows.getInstaceOfFlows()) {
if (BytecodeLocation.hasValidBci(originalInstanceOf.getLocation())) {
int bci = originalInstanceOf.getLocation().getBci();
/* Fold the instanceof flows. */
TypeState instanceOfTypeState = methodFlow.foldTypeFlow(bb, originalInstanceOf);
originalInstanceOf.setState(bb, instanceOfTypeState);
JavaTypeProfile typeProfile = makeTypeProfile(instanceOfTypeState);
if (typeProfile != null) {
ensureSize(entries, bci);
assert entries.get(bci) == null : "In " + method.format("%h.%n(%p)") + " a profile with bci=" + bci + " already exists: " + entries.get(bci);
entries.set(bci, createBytecodeEntry(method, bci, typeProfile, null, null));
}
}
}
for (InvokeTypeFlow originalInvoke : originalFlows.getInvokes()) {
if (BytecodeLocation.hasValidBci(originalInvoke.getLocation())) {
int bci = originalInvoke.getLocation().getBci();
TypeState invokeTypeState = TypeState.forEmpty();
if (originalInvoke.getTargetMethod().hasReceiver()) {
invokeTypeState = methodFlow.foldTypeFlow(bb, originalInvoke.getReceiver());
originalInvoke.setState(bb, invokeTypeState);
}
TypeFlow<?> originalReturn = originalInvoke.getActualReturn();
TypeState returnTypeState = null;
if (originalReturn != null) {
returnTypeState = methodFlow.foldTypeFlow(bb, originalReturn);
originalReturn.setState(bb, returnTypeState);
}
JavaTypeProfile typeProfile = makeTypeProfile(invokeTypeState);
JavaMethodProfile methodProfile = makeMethodProfile(originalInvoke.getCallees());
JavaTypeProfile invokeResultTypeProfile = originalReturn == null ? null : makeTypeProfile(returnTypeState);
if (typeProfile != null || methodProfile != null || invokeResultTypeProfile != null) {
ensureSize(entries, bci);
assert entries.get(bci) == null : "In " + method.format("%h.%n(%p)") + " a profile with bci=" + bci + " already exists: " + entries.get(bci);
entries.set(bci, createBytecodeEntry(method, bci, typeProfile, methodProfile, invokeResultTypeProfile));
}
}
}
if (PointstoOptions.PrintSynchronizedAnalysis.getValue(bb.getOptions())) {
originalFlows.getMonitorEntries().stream().filter(m -> m.getState().typesCount() > 20).sorted(Comparator.comparingInt(m2 -> m2.getState().typesCount())).forEach(monitorEnter -> {
TypeState monitorEntryState = monitorEnter.getState();
String typesString = monitorEntryState.closeToAllInstantiated(bb) ? "close to all instantiated" : StreamSupport.stream(monitorEntryState.types().spliterator(), false).map(AnalysisType::getName).collect(Collectors.joining(", "));
StringBuilder strb = new StringBuilder();
strb.append("Location: ");
String methodName = method.format("%h.%n(%p)");
int bci = monitorEnter.getLocation().getBci();
if (bci != BytecodeLocation.UNKNOWN_BCI) {
StackTraceElement traceElement = method.asStackTraceElement(bci);
String sourceLocation = traceElement.getFileName() + ":" + traceElement.getLineNumber();
strb.append("@(").append(methodName).append(":").append(bci).append(")");
strb.append("=(").append(sourceLocation).append(")");
} else {
strb.append("@(").append(methodName).append(")");
}
strb.append("\n");
strb.append("Synchronized types #: ").append(monitorEntryState.typesCount()).append("\n");
strb.append("Types: ").append(typesString).append("\n");
System.out.println(strb);
});
}
BytecodeEntry first = null;
for (int i = entries.size() - 1; i >= 0; i--) {
BytecodeEntry cur = entries.get(i);
if (cur != null) {
cur.next = first;
first = cur;
}
}
return createStaticAnalysisResults(method, parameterTypeProfiles, resultTypeProfile, first);
}
use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.
the class MultiTypeState method typesIterator.
/**
* It iterates over the types bit set and gets the types using
* {@link AnalysisUniverse#getType(int)}. The types are iterated in ascending order of their IDs
* by way of bit set iteration.
*/
@Override
public Iterator<AnalysisType> typesIterator() {
return new Iterator<AnalysisType>() {
/**
* Initialize to the index of the first set bit.
*/
private int currentTypeId = typesBitSet.nextSetBit(0);
@Override
public boolean hasNext() {
return currentTypeId >= 0;
}
@Override
public AnalysisType next() {
AnalysisType next = bigbang.getUniverse().getType(currentTypeId);
currentTypeId = typesBitSet.nextSetBit(currentTypeId + 1);
return next;
}
};
}
use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.
the class UnknownTypeState method forContextInsensitiveTypeState.
/**
* Simplifies a type state by replacing all context sensitive objects with context insensitive
* objects.
*/
public static TypeState forContextInsensitiveTypeState(BigBang bb, TypeState state) {
if (!PointstoOptions.AllocationSiteSensitiveHeap.getValue(bb.getOptions()) || state.isEmpty() || state.isNull() || state.isUnknown()) {
/* The type state is already context insensitive. */
return state;
} else {
if (state.isSingleTypeState()) {
AnalysisType type = state.exactType();
AnalysisObject analysisObject = type.getContextInsensitiveAnalysisObject();
return new SingleTypeState(bb, state.canBeNull(), bb.analysisPolicy().makePoperties(bb, analysisObject), analysisObject);
} else {
MultiTypeState multiState = (MultiTypeState) state;
AnalysisObject[] objectsArray = new AnalysisObject[multiState.typesCount()];
int i = 0;
for (AnalysisType type : multiState.types()) {
objectsArray[i++] = type.getContextInsensitiveAnalysisObject();
}
/*
* For types use the already created bit set. Since the original type state is
* immutable its types bit set cannot change.
*/
BitSet typesBitSet = multiState.typesBitSet;
int properties = bb.analysisPolicy().makePoperties(bb, objectsArray);
return new MultiTypeState(bb, multiState.canBeNull(), properties, typesBitSet, objectsArray);
}
}
}
use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.
the class MethodTypeFlowBuilder method processNewInstance.
protected void processNewInstance(NewInstanceNode node, TypeFlowsOfNodes state) {
AnalysisType type = (AnalysisType) node.instanceClass();
assert type.isInstantiated();
Object key = uniqueKey(node);
BytecodeLocation allocationLabel = bb.analysisPolicy().createAllocationSite(bb, key, method);
TypeFlowBuilder<?> newInstanceBuilder = TypeFlowBuilder.create(bb, node, NewInstanceTypeFlow.class, () -> {
NewInstanceTypeFlow newInstance = createNewInstanceTypeFlow(node, type, allocationLabel);
/* Instance fields of a new object are initialized to null state in AnalysisField. */
methodFlow.addAllocation(newInstance);
return newInstance;
});
state.add(node, newInstanceBuilder);
}
Aggregations