Skip to content
Merged
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 @@ -327,9 +327,7 @@ protected AnalysisTypeBuiltIn(ImageLayerWriter imageLayerWriter, ImageLayerLoade
@Override
public String encode(ObjectCopier.Encoder encoder, Object obj) {
AnalysisType type = (AnalysisType) obj;
if (!type.isReachable() && !imageLayerWriter.typesMap.containsKey(imageLayerWriter.imageLayerSnapshotUtil.getTypeIdentifier(type))) {
imageLayerWriter.persistType(type);
}
imageLayerWriter.persistType(type);
return String.valueOf(type.getId());
}

Expand All @@ -356,19 +354,13 @@ public String encode(ObjectCopier.Encoder encoder, Object obj) {
AnalysisMethod method = (AnalysisMethod) obj;
AnalysisType declaringClass = method.getDeclaringClass();
imageLayerWriter.elementsToPersist.add(new AnalysisFuture<>(() -> {
if (!method.isReachable() && !imageLayerWriter.methodsMap.containsKey(imageLayerWriter.imageLayerSnapshotUtil.getMethodIdentifier(method))) {
imageLayerWriter.persistAnalysisParsedGraph(method);
imageLayerWriter.persistMethod(method);
}
imageLayerWriter.persistAnalysisParsedGraph(method);
imageLayerWriter.persistMethod(method);
}));
for (AnalysisType parameter : method.toParameterList()) {
if (!parameter.isReachable() && !imageLayerWriter.typesMap.containsKey(imageLayerWriter.imageLayerSnapshotUtil.getTypeIdentifier(parameter))) {
imageLayerWriter.persistType(parameter);
}
}
if (!declaringClass.isReachable() && !imageLayerWriter.typesMap.containsKey(imageLayerWriter.imageLayerSnapshotUtil.getTypeIdentifier(declaringClass))) {
imageLayerWriter.persistType(declaringClass);
imageLayerWriter.persistType(parameter);
}
imageLayerWriter.persistType(declaringClass);
return String.valueOf(method.getId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -150,6 +149,7 @@ public class ImageLayerWriter {
protected final EconomicMap<String, Object> jsonMap;
protected final List<Integer> constantsToRelink;
private final Set<Integer> persistedTypeIds;
private final Set<Integer> persistedMethodIds;
protected final Map<String, EconomicMap<String, Object>> typesMap;
protected final Map<String, EconomicMap<String, Object>> methodsMap;
protected final Map<String, Map<String, Object>> fieldsMap;
Expand Down Expand Up @@ -212,7 +212,8 @@ public ImageLayerWriter(boolean useSharedLayerGraphs, ImageLayerSnapshotUtil ima
this.imageLayerSnapshotUtil = imageLayerSnapshotUtil;
this.jsonMap = EconomicMap.create();
this.constantsToRelink = new ArrayList<>();
this.persistedTypeIds = new HashSet<>();
this.persistedTypeIds = ConcurrentHashMap.newKeySet();
this.persistedMethodIds = ConcurrentHashMap.newKeySet();
this.typesMap = new ConcurrentHashMap<>();
this.methodsMap = new ConcurrentHashMap<>();
this.fieldsMap = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -325,9 +326,7 @@ protected void persistType(AnalysisType type) {
* Some persisted types are not reachable. In this case, the super class has to be
* persisted manually as well.
*/
if (!superclass.isReachable()) {
persistType(superclass);
}
persistType(superclass);
}
EconomicMap<String, Object> typeMap = EconomicMap.create();

Expand Down Expand Up @@ -384,7 +383,14 @@ public void checkTypeStability(AnalysisType type) {
}

public void persistMethod(AnalysisMethod method) {
if (!persistedMethodIds.add(method.getId())) {
return;
}
EconomicMap<String, Object> methodMap = getMethodMap(method);
persistMethod(method, methodMap);
}

protected void persistMethod(AnalysisMethod method, EconomicMap<String, Object> methodMap) {
Executable executable = method.getJavaMethod();

if (methodMap.containsKey(ID_TAG)) {
Expand Down Expand Up @@ -424,11 +430,6 @@ public void persistMethod(AnalysisMethod method) {
imageLayerWriterHelper.persistMethod(method, methodMap);
}

public boolean isMethodPersisted(AnalysisMethod method) {
String name = imageLayerSnapshotUtil.getMethodIdentifier(method);
return methodsMap.containsKey(name);
}

public void persistMethodGraphs() {
for (AnalysisMethod method : aUniverse.getMethods()) {
if (method.isReachable()) {
Expand All @@ -442,18 +443,22 @@ public void persistAnalysisParsedGraph(AnalysisMethod method) {

Object analyzedGraph = method.getGraph();
if (analyzedGraph instanceof AnalysisParsedGraph analysisParsedGraph) {
if (!persistGraph(analysisParsedGraph.getEncodedGraph(), methodMap, ANALYSIS_PARSED_GRAPH_TAG)) {
return;
if (!methodMap.containsKey(INTRINSIC_TAG)) {
if (!persistGraph(analysisParsedGraph.getEncodedGraph(), methodMap, ANALYSIS_PARSED_GRAPH_TAG)) {
return;
}
methodMap.put(INTRINSIC_TAG, analysisParsedGraph.isIntrinsic());
}
methodMap.put(INTRINSIC_TAG, analysisParsedGraph.isIntrinsic());
}
}

public void persistMethodStrengthenedGraph(AnalysisMethod method) {
EconomicMap<String, Object> methodMap = getMethodMap(method);

EncodedGraph analyzedGraph = method.getAnalyzedGraph();
persistGraph(analyzedGraph, methodMap, STRENGTHENED_GRAPH_TAG);
if (!methodMap.containsKey(STRENGTHENED_GRAPH_TAG)) {
EncodedGraph analyzedGraph = method.getAnalyzedGraph();
persistGraph(analyzedGraph, methodMap, STRENGTHENED_GRAPH_TAG);
}
}

private boolean persistGraph(EncodedGraph analyzedGraph, EconomicMap<String, Object> methodMap, String graphTag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ protected boolean shouldPersistMethod(AnalysisMethod method) {
}

@Override
public void persistMethod(AnalysisMethod method) {
super.persistMethod(method);
public void persistMethod(AnalysisMethod method, EconomicMap<String, Object> methodMap) {
super.persistMethod(method, methodMap);

// register this method as persisted for name resolution
HostedDynamicLayerInfo.singleton().recordPersistedMethod(hUniverse.lookup(method));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ protected void persistMethod(AnalysisMethod method, EconomicMap<String, Object>
if (method.wrapped instanceof FactoryMethod factoryMethod) {
methodMap.put(WRAPPED_METHOD_TAG, FACTORY_TAG);
AnalysisMethod targetConstructor = method.getUniverse().lookup(factoryMethod.getTargetConstructor());
if (!method.isReachable() && !imageLayerWriter.isMethodPersisted(targetConstructor)) {
imageLayerWriter.persistAnalysisParsedGraph(targetConstructor);
imageLayerWriter.persistMethod(targetConstructor);
}
imageLayerWriter.persistAnalysisParsedGraph(targetConstructor);
imageLayerWriter.persistMethod(targetConstructor);
methodMap.put(TARGET_CONSTRUCTOR_TAG, targetConstructor.getId());
methodMap.put(THROW_ALLOCATED_OBJECT_TAG, factoryMethod.throwAllocatedObject());
}
Expand Down