Skip to content
Closed
Show file tree
Hide file tree
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 @@ -103,6 +103,10 @@ void setFieldValues(Object[] fieldValues) {
AnalysisError.guarantee(success, "Unexpected field values reference for constant %s", this);
}

public boolean nullFieldValues() {
return getConstantData().fieldValues == null;
}

/**
* {@link InstanceData#fieldValues} are only set once, in {@link #setFieldValues(Object[])} and
* shouldn't be accessed before set, i.e., read access is guarded by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,7 @@ public void onFieldRead(AnalysisField field) {
* GR-52421: the field state needs to be serialized from the base layer analysis
*/
if (field.getJavaKind().isObject()) {
AnalysisType fieldType = field.getType();
if (fieldType.isArray() || (fieldType.isInstanceClass() && !fieldType.isAbstract())) {
fieldType.registerAsInstantiated(field);
}
bb.injectFieldTypes(field, List.of(fieldType), true);
bb.injectFieldTypes(field, List.of(field.getType()), true);
}
return;
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,18 @@ public class ImageLayerSnapshotUtil {
public static final String CAN_BE_STATICALLY_BOUND_TAG = "can be statically bound";
public static final String IS_CONSTRUCTOR_TAG = "is constructor";
public static final String IS_SYNTHETIC_TAG = "is synthetic";
public static final String CODE_TAG = "code";
public static final String CODE_SIZE_TAG = "code size";
public static final String METHOD_HANDLE_INTRINSIC_TAG = "method handle intrinsic";
public static final String IS_VIRTUAL_ROOT_METHOD = "is virtual root method";
public static final String IS_DIRECT_ROOT_METHOD = "is direct root method";
public static final String IS_INVOKED = "is invoked";
public static final String IS_IMPLEMENTATION_INVOKED = "is implementation invoked";
public static final String IS_INTRINSIC_METHOD = "is intrinsic method";
public static final String ANNOTATIONS_TAG = "annotations";
public static final String IS_INSTANTIATED = "is instantiated";
public static final String IS_UNSAFE_ALLOCATED = "is unsafe allocated";
public static final String IS_REACHABLE = "is reachable";
public static final String CLASS_NAME_TAG = "class name";
public static final String MODIFIERS_TAG = "modifiers";
public static final String POSITION_TAG = "position";
Expand Down Expand Up @@ -109,6 +119,7 @@ public class ImageLayerSnapshotUtil {
public static final String THROW_ALLOCATED_OBJECT_TAG = "throw allocated object";
public static final String IDENTITY_HASH_CODE_TAG = "identityHashCode";
public static final String HUB_IDENTITY_HASH_CODE_TAG = "hub identityHashCode";
public static final String IS_INITIALIZED_AT_BUILD_TIME_TAG = "is initialized at build time";
public static final String ID_TAG = "id";
public static final String ANALYSIS_PARSED_GRAPH_TAG = "analysis parsed graph";
public static final String STRENGTHENED_GRAPH_TAG = "strengthened graph";
Expand Down Expand Up @@ -204,8 +215,8 @@ public GraphEncoder getGraphEncoder(ImageLayerWriter imageLayerWriter) {
}

@SuppressWarnings("unused")
public GraphDecoder getGraphDecoder(ImageLayerLoader imageLayerLoader, SnippetReflectionProvider snippetReflectionProvider) {
return new GraphDecoder(EncodedGraph.class.getClassLoader(), imageLayerLoader);
public GraphDecoder getGraphDecoder(ImageLayerLoader imageLayerLoader, AnalysisMethod analysisMethod, SnippetReflectionProvider snippetReflectionProvider) {
return new GraphDecoder(EncodedGraph.class.getClassLoader(), imageLayerLoader, analysisMethod);
}

public static class GraphEncoder extends ObjectCopier.Encoder {
Expand All @@ -215,7 +226,7 @@ public GraphEncoder(List<Field> externalValues, ImageLayerWriter imageLayerWrite
addBuiltin(new NodeClassBuiltIn());
addBuiltin(new ImageHeapConstantBuiltIn(imageLayerWriter, null));
addBuiltin(new AnalysisTypeBuiltIn(imageLayerWriter, null));
addBuiltin(new AnalysisMethodBuiltIn(imageLayerWriter, null));
addBuiltin(new AnalysisMethodBuiltIn(imageLayerWriter, null, null));
addBuiltin(new AnalysisFieldBuiltIn(imageLayerWriter, null));
addBuiltin(new FieldLocationIdentityBuiltIn(imageLayerWriter, null));
addBuiltin(new NamedLocationIdentityArrayBuiltIn());
Expand All @@ -224,12 +235,12 @@ public GraphEncoder(List<Field> externalValues, ImageLayerWriter imageLayerWrite

public static class GraphDecoder extends ObjectCopier.Decoder {
@SuppressWarnings("this-escape")
public GraphDecoder(ClassLoader classLoader, ImageLayerLoader imageLayerLoader) {
public GraphDecoder(ClassLoader classLoader, ImageLayerLoader imageLayerLoader, AnalysisMethod analysisMethod) {
super(classLoader);
addBuiltin(new NodeClassBuiltIn());
addBuiltin(new ImageHeapConstantBuiltIn(null, imageLayerLoader));
addBuiltin(new AnalysisTypeBuiltIn(null, imageLayerLoader));
addBuiltin(new AnalysisMethodBuiltIn(null, imageLayerLoader));
addBuiltin(new AnalysisMethodBuiltIn(null, imageLayerLoader, analysisMethod));
addBuiltin(new AnalysisFieldBuiltIn(null, imageLayerLoader));
addBuiltin(new FieldLocationIdentityBuiltIn(null, imageLayerLoader));
addBuiltin(new NamedLocationIdentityArrayBuiltIn());
Expand Down Expand Up @@ -304,11 +315,13 @@ protected Object decode(ObjectCopier.Decoder decoder, Class<?> concreteType, Str
public static class AnalysisMethodBuiltIn extends ObjectCopier.Builtin {
private final ImageLayerWriter imageLayerWriter;
private final ImageLayerLoader imageLayerLoader;
private final AnalysisMethod analysisMethod;

protected AnalysisMethodBuiltIn(ImageLayerWriter imageLayerWriter, ImageLayerLoader imageLayerLoader) {
protected AnalysisMethodBuiltIn(ImageLayerWriter imageLayerWriter, ImageLayerLoader imageLayerLoader, AnalysisMethod analysisMethod) {
super(AnalysisMethod.class, PointsToAnalysisMethod.class);
this.imageLayerWriter = imageLayerWriter;
this.imageLayerLoader = imageLayerLoader;
this.analysisMethod = analysisMethod;
}

@Override
Expand All @@ -334,7 +347,11 @@ public String encode(ObjectCopier.Encoder encoder, Object obj) {

@Override
protected Object decode(ObjectCopier.Decoder decoder, Class<?> concreteType, String encoding, String encoded) {
return imageLayerLoader.getAnalysisMethod(Integer.parseInt(encoded));
int id = Integer.parseInt(encoded);
if (id == analysisMethod.getId()) {
return analysisMethod;
}
return imageLayerLoader.getAnalysisMethod(id);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.CLASS_JAVA_NAME_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.CLASS_NAME_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.CODE_SIZE_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.CODE_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.COMPONENT_TYPE_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.CONSTANTS_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.CONSTANTS_TO_RELINK_TAG;
Expand All @@ -54,14 +55,23 @@
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.INTERFACES_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.INTRINSIC_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.IS_CONSTRUCTOR_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.IS_DIRECT_ROOT_METHOD;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.IS_ENUM_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.IS_IMPLEMENTATION_INVOKED;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.IS_INITIALIZED_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.IS_INSTANTIATED;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.IS_INTERFACE_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.IS_INTERNAL_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.IS_INTRINSIC_METHOD;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.IS_INVOKED;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.IS_LINKED_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.IS_REACHABLE;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.IS_SYNTHETIC_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.IS_UNSAFE_ALLOCATED;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.IS_VAR_ARGS_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.IS_VIRTUAL_ROOT_METHOD;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.METHODS_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.METHOD_HANDLE_INTRINSIC_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.MODIFIERS_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.NAME_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.NEXT_FIELD_ID_TAG;
Expand Down Expand Up @@ -117,6 +127,7 @@
import jdk.graal.compiler.util.json.JsonWriter;
import jdk.vm.ci.meta.JavaConstant;
import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.MethodHandleAccessProvider.IntrinsicMethod;
import jdk.vm.ci.meta.PrimitiveConstant;
import jdk.vm.ci.meta.ResolvedJavaField;

Expand Down Expand Up @@ -295,6 +306,10 @@ protected void persistType(AnalysisType type, EconomicMap<String, Object> typeMa
}
typeMap.put(INTERFACES_TAG, Arrays.stream(type.getInterfaces()).map(AnalysisType::getId).toList());
typeMap.put(ANNOTATIONS_TAG, Arrays.stream(AnnotationAccess.getAnnotationTypes(type)).map(Class::getName).toList());

typeMap.put(IS_INSTANTIATED, type.isInstantiated());
typeMap.put(IS_UNSAFE_ALLOCATED, type.isUnsafeAllocated());
typeMap.put(IS_REACHABLE, type.isReachable());
}

/**
Expand Down Expand Up @@ -327,9 +342,23 @@ public void persistMethod(AnalysisMethod method) {
methodMap.put(MODIFIERS_TAG, method.getModifiers());
methodMap.put(IS_CONSTRUCTOR_TAG, method.isConstructor());
methodMap.put(IS_SYNTHETIC_TAG, method.isSynthetic());
byte[] code = method.getCode();
if (code != null) {
methodMap.put(CODE_TAG, getString(JavaKind.Byte, method.getCode()));
}
methodMap.put(CODE_SIZE_TAG, method.getCodeSize());
IntrinsicMethod intrinsicMethod = aUniverse.getBigbang().getConstantReflectionProvider().getMethodHandleAccess().lookupMethodHandleIntrinsic(method);
if (intrinsicMethod != null) {
methodMap.put(METHOD_HANDLE_INTRINSIC_TAG, intrinsicMethod.name());
}
methodMap.put(ANNOTATIONS_TAG, Arrays.stream(AnnotationAccess.getAnnotationTypes(method)).map(Class::getName).toList());

methodMap.put(IS_VIRTUAL_ROOT_METHOD, method.isVirtualRootMethod());
methodMap.put(IS_DIRECT_ROOT_METHOD, method.isDirectRootMethod());
methodMap.put(IS_INVOKED, method.isSimplyInvoked());
methodMap.put(IS_IMPLEMENTATION_INVOKED, method.isSimplyImplementationInvoked());
methodMap.put(IS_INTRINSIC_METHOD, method.isIntrinsicMethod());

imageLayerWriterHelper.persistMethod(method, methodMap);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public AnalysisField(AnalysisUniverse universe, ResolvedJavaField wrappedField)
sinkFlow = new ContextInsensitiveFieldTypeFlow(this, getType());
}

if (universe.hostVM().useBaseLayer()) {
if (universe.hostVM().useBaseLayer() && declaringClass.isInBaseLayer()) {
int fid = universe.getImageLayerLoader().lookupHostedFieldInBaseLayer(this);
if (fid != -1) {
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ protected AnalysisMethod(AnalysisUniverse universe, ResolvedJavaMethod wrapped,
qualifiedName = format("%H.%n(%P)");
modifiers = wrapped.getModifiers();

if (universe.hostVM().useBaseLayer()) {
if (universe.hostVM().useBaseLayer() && declaringClass.isInBaseLayer()) {
int mid = universe.getImageLayerLoader().lookupHostedMethodInBaseLayer(this);
if (mid != -1) {
/*
Expand Down Expand Up @@ -520,6 +520,10 @@ public boolean isDirectRootMethod() {
return AtomicUtils.isSet(this, isDirectRootMethodUpdater);
}

public boolean isSimplyInvoked() {
return AtomicUtils.isSet(this, isInvokedUpdater);
}

public boolean isSimplyImplementationInvoked() {
return AtomicUtils.isSet(this, isImplementationInvokedUpdater);
}
Expand All @@ -531,7 +535,7 @@ public boolean isInvoked() {
return isIntrinsicMethod() || isVirtualRootMethod() || isDirectRootMethod() || AtomicUtils.isSet(this, isInvokedUpdater);
}

protected Object getInvokedReason() {
public Object getInvokedReason() {
return isInvoked;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ public JavaType lookupAllowUnresolved(JavaType rawType) {
AnalysisType result = optionalLookup(type);
if (result == null) {
result = createType(type);
if (hostVM.useBaseLayer()) {
imageLayerLoader.initializeBaseLayerType(result);
}
}
assert typesById[result.getId()].equals(result) : result;
return result;
Expand Down Expand Up @@ -372,11 +375,20 @@ private AnalysisField createField(ResolvedJavaField field) {
return null;
}
AnalysisField newValue = analysisFactory.createField(this, field);
AnalysisField oldValue = fields.putIfAbsent(field, newValue);
if (oldValue == null && newValue.isInBaseLayer()) {
getImageLayerLoader().initializeBaseLayerField(newValue);
AnalysisField result = fields.computeIfAbsent(field, f -> {
if (newValue.isInBaseLayer()) {
getImageLayerLoader().addBaseLayerField(newValue);
}
return newValue;
});

if (result.equals(newValue)) {
if (newValue.isInBaseLayer()) {
getImageLayerLoader().initializeBaseLayerField(newValue);
}
}
return oldValue != null ? oldValue : newValue;

return result;
}

@Override
Expand Down Expand Up @@ -418,15 +430,22 @@ private AnalysisMethod createMethod(ResolvedJavaMethod method) {
return null;
}
AnalysisMethod newValue = analysisFactory.createMethod(this, method);
AnalysisMethod oldValue = methods.putIfAbsent(method, newValue);
AnalysisMethod result = methods.computeIfAbsent(method, m -> {
if (newValue.isInBaseLayer()) {
getImageLayerLoader().addBaseLayerMethod(newValue);
}
return newValue;
});

if (oldValue == null) {
if (result.equals(newValue)) {
if (newValue.isInBaseLayer()) {
getImageLayerLoader().initializeBaseLayerMethod(newValue);
}

prepareMethodImplementations(newValue);
}
return oldValue != null ? oldValue : newValue;

return result;
}

/** Prepare information that {@link AnalysisMethod#collectMethodImplementations} needs. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import jdk.vm.ci.meta.ExceptionHandler;
import jdk.vm.ci.meta.LineNumberTable;
import jdk.vm.ci.meta.LocalVariableTable;
import jdk.vm.ci.meta.MethodHandleAccessProvider.IntrinsicMethod;
import jdk.vm.ci.meta.ProfilingInfo;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.ResolvedJavaType;
Expand All @@ -59,10 +60,12 @@ public class BaseLayerMethod extends BaseLayerElement implements ResolvedJavaMet
private final boolean isConstructor;
private final int modifiers;
private final boolean isSynthetic;
private final byte[] code;
private final int codeSize;
private final IntrinsicMethod methodHandleIntrinsic;

public BaseLayerMethod(int id, AnalysisType declaringClass, String name, boolean isVarArgs, ResolvedSignature<AnalysisType> signature, boolean canBeStaticallyBound, boolean isConstructor,
int modifiers, boolean isSynthetic, int codeSize, Annotation[] annotations) {
int modifiers, boolean isSynthetic, byte[] code, int codeSize, IntrinsicMethod methodHandleIntrinsic, Annotation[] annotations) {
super(annotations);
this.id = id;
this.declaringClass = declaringClass.getWrapped();
Expand All @@ -73,16 +76,22 @@ public BaseLayerMethod(int id, AnalysisType declaringClass, String name, boolean
this.isConstructor = isConstructor;
this.modifiers = modifiers;
this.isSynthetic = isSynthetic;
this.code = code;
this.codeSize = codeSize;
this.methodHandleIntrinsic = methodHandleIntrinsic;
}

public int getBaseLayerId() {
return id;
}

public IntrinsicMethod getMethodHandleIntrinsic() {
return methodHandleIntrinsic;
}

@Override
public byte[] getCode() {
throw GraalError.unimplemented("This method is incomplete and should not be used.");
return code;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class BaseLayerType extends BaseLayerElement implements ResolvedJavaType,
private final boolean isInterface;
private final boolean isEnum;
private final boolean isInitialized;
private final boolean isInitializedAtBuildTime;
private final boolean isLinked;
private final String sourceFileName;
private final ResolvedJavaType enclosingType;
Expand All @@ -64,15 +65,17 @@ public class BaseLayerType extends BaseLayerElement implements ResolvedJavaType,
private final ResolvedJavaType[] interfaces;
private final ResolvedJavaType objectType;

public BaseLayerType(String name, int baseLayerId, int modifiers, boolean isInterface, boolean isEnum, boolean isInitialized, boolean isLinked, String sourceFileName,
ResolvedJavaType enclosingType, ResolvedJavaType componentType, ResolvedJavaType superClass, ResolvedJavaType[] interfaces, ResolvedJavaType objectType, Annotation[] annotations) {
public BaseLayerType(String name, int baseLayerId, int modifiers, boolean isInterface, boolean isEnum, boolean isInitialized, boolean initializedAtBuildTime, boolean isLinked,
String sourceFileName, ResolvedJavaType enclosingType, ResolvedJavaType componentType, ResolvedJavaType superClass, ResolvedJavaType[] interfaces, ResolvedJavaType objectType,
Annotation[] annotations) {
super(annotations);
this.name = name.substring(0, name.length() - 1) + BASE_LAYER_SUFFIX;
this.baseLayerId = baseLayerId;
this.modifiers = modifiers;
this.isInterface = isInterface;
this.isEnum = isEnum;
this.isInitialized = isInitialized;
this.isInitializedAtBuildTime = initializedAtBuildTime;
this.isLinked = isLinked;
this.sourceFileName = sourceFileName;
this.enclosingType = enclosingType;
Expand Down Expand Up @@ -332,4 +335,8 @@ public ResolvedJavaType unwrapTowardsOriginalType() {
public int getBaseLayerId() {
return baseLayerId;
}

public boolean initializedAtBuildTime() {
return isInitializedAtBuildTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ public void duringAnalysis(DuringAnalysisAccess access) {
throw VMError.shouldNotReachHere(ex);
}

int numTypes = impl.getUniverse().getTypes().size();
mapsToRescan.forEach(impl::rescanObject);
if (numTypes != impl.getUniverse().getTypes().size()) {
access.requireAnalysisIteration();
}
}
}
Loading