Make serializable some classes that are going to participate in remote build strategy

This commit is contained in:
Alexey Andreev 2017-03-13 23:11:51 +03:00
parent 6b31e13cbb
commit 56398f58f9
15 changed files with 142 additions and 90 deletions

View File

@ -15,58 +15,98 @@
*/ */
package org.teavm.callgraph; package org.teavm.callgraph;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.*; import java.util.*;
import org.teavm.model.FieldReference; import org.teavm.model.FieldReference;
import org.teavm.model.MethodReference; import org.teavm.model.MethodReference;
/** public class DefaultCallGraph implements CallGraph, Serializable {
* private transient Map<MethodReference, DefaultCallGraphNode> nodes = new HashMap<>();
* @author Alexey Andreev private List<Map.Entry<MethodReference, DefaultCallGraphNode>> nodeList;
*/ private transient Map<FieldReference, Set<DefaultFieldAccessSite>> fieldAccessSites = new HashMap<>();
public class DefaultCallGraph implements CallGraph { private List<Map.Entry<FieldReference, DefaultFieldAccessSite>> fieldAccessSiteList;
private Map<MethodReference, DefaultCallGraphNode> nodes = new HashMap<>(); private transient Map<String, Set<DefaultClassAccessSite>> classAccessSites = new HashMap<>();
private Map<FieldReference, Set<DefaultFieldAccessSite>> fieldAccessSites = new HashMap<>(); private List<Map.Entry<String, DefaultClassAccessSite>> classAccessSiteList;
private Map<String, Set<DefaultClassAccessSite>> classAccessSites = new HashMap<>();
@Override @Override
public DefaultCallGraphNode getNode(MethodReference method) { public DefaultCallGraphNode getNode(MethodReference method) {
DefaultCallGraphNode node = nodes.get(method); ensureDeserialized();
if (node == null) { return nodes.computeIfAbsent(method, k -> new DefaultCallGraphNode(this, method));
node = new DefaultCallGraphNode(this, method);
nodes.put(method, node);
}
return nodes.get(method);
} }
@Override @Override
public Collection<DefaultFieldAccessSite> getFieldAccess(FieldReference reference) { public Collection<DefaultFieldAccessSite> getFieldAccess(FieldReference reference) {
ensureDeserialized();
Set<DefaultFieldAccessSite> resultSet = fieldAccessSites.get(reference); Set<DefaultFieldAccessSite> resultSet = fieldAccessSites.get(reference);
return resultSet != null ? Collections.unmodifiableSet(resultSet) return resultSet != null ? Collections.unmodifiableSet(resultSet) : Collections.emptySet();
: Collections.<DefaultFieldAccessSite>emptySet();
} }
void addFieldAccess(DefaultFieldAccessSite accessSite) { void addFieldAccess(DefaultFieldAccessSite accessSite) {
Set<DefaultFieldAccessSite> sites = fieldAccessSites.get(accessSite.getField()); ensureDeserialized();
if (sites == null) { fieldAccessSites.computeIfAbsent(accessSite.getField(), k -> new HashSet<>()).add(accessSite);
sites = new HashSet<>();
fieldAccessSites.put(accessSite.getField(), sites);
}
sites.add(accessSite);
} }
@Override @Override
public Collection<DefaultClassAccessSite> getClassAccess(String className) { public Collection<DefaultClassAccessSite> getClassAccess(String className) {
ensureDeserialized();
Set<DefaultClassAccessSite> resultSet = classAccessSites.get(className); Set<DefaultClassAccessSite> resultSet = classAccessSites.get(className);
return resultSet != null ? Collections.unmodifiableSet(resultSet) return resultSet != null ? Collections.unmodifiableSet(resultSet) : Collections.emptySet();
: Collections.<DefaultClassAccessSite>emptySet();
} }
void addClassAccess(DefaultClassAccessSite accessSite) { void addClassAccess(DefaultClassAccessSite accessSite) {
Set<DefaultClassAccessSite> sites = classAccessSites.get(accessSite.getClassName()); ensureDeserialized();
if (sites == null) { classAccessSites.computeIfAbsent(accessSite.getClassName(), k -> new HashSet<>()).add(accessSite);
sites = new HashSet<>();
classAccessSites.put(accessSite.getClassName(), sites);
} }
sites.add(accessSite);
private void ensureDeserialized() {
if (nodes != null) {
return;
}
nodes = new HashMap<>();
for (Map.Entry<MethodReference, DefaultCallGraphNode> entry : nodeList) {
nodes.put(entry.getKey(), entry.getValue());
}
nodeList = null;
fieldAccessSites = new HashMap<>();
for (Map.Entry<FieldReference, DefaultFieldAccessSite> entry : fieldAccessSiteList) {
fieldAccessSites.computeIfAbsent(entry.getKey(), k -> new HashSet<>()).add(entry.getValue());
}
fieldAccessSiteList = null;
classAccessSites = new HashMap<>();
for (Map.Entry<String, DefaultClassAccessSite> entry : classAccessSiteList) {
classAccessSites.computeIfAbsent(entry.getKey(), k -> new HashSet<>()).add(entry.getValue());
}
classAccessSiteList = null;
}
private void writeObject(ObjectOutputStream out) throws IOException {
ensureDeserialized();
nodeList = new ArrayList<>(nodes.entrySet());
fieldAccessSiteList = new ArrayList<>();
for (Map.Entry<FieldReference, Set<DefaultFieldAccessSite>> entry : fieldAccessSites.entrySet()) {
for (DefaultFieldAccessSite site : entry.getValue()) {
fieldAccessSiteList.add(new AbstractMap.SimpleEntry<>(entry.getKey(), site));
}
}
classAccessSiteList = new ArrayList<>();
for (Map.Entry<String, Set<DefaultClassAccessSite>> entry : classAccessSites.entrySet()) {
for (DefaultClassAccessSite site : entry.getValue()) {
classAccessSiteList.add(new AbstractMap.SimpleEntry<>(entry.getKey(), site));
}
}
out.defaultWriteObject();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
} }
} }

View File

@ -15,6 +15,10 @@
*/ */
package org.teavm.callgraph; package org.teavm.callgraph;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -25,20 +29,19 @@ import org.teavm.model.FieldReference;
import org.teavm.model.MethodReference; import org.teavm.model.MethodReference;
import org.teavm.model.TextLocation; import org.teavm.model.TextLocation;
/** public class DefaultCallGraphNode implements CallGraphNode, Serializable {
*
* @author Alexey Andreev
*/
public class DefaultCallGraphNode implements CallGraphNode {
private DefaultCallGraph graph; private DefaultCallGraph graph;
private MethodReference method; private MethodReference method;
private Set<DefaultCallSite> callSites = new HashSet<>(); private transient Set<DefaultCallSite> callSites = new HashSet<>();
private List<DefaultCallSite> callSiteList;
private transient Set<DefaultCallSite> safeCallSites; private transient Set<DefaultCallSite> safeCallSites;
private List<DefaultCallSite> callerCallSites = new ArrayList<>(); private List<DefaultCallSite> callerCallSites = new ArrayList<>();
private transient List<DefaultCallSite> safeCallersCallSites; private transient List<DefaultCallSite> safeCallersCallSites;
private Set<DefaultFieldAccessSite> fieldAccessSites = new HashSet<>(); private transient Set<DefaultFieldAccessSite> fieldAccessSites = new HashSet<>();
private List<DefaultFieldAccessSite> fieldAccessSiteList;
private transient Set<DefaultFieldAccessSite> safeFieldAccessSites; private transient Set<DefaultFieldAccessSite> safeFieldAccessSites;
private Set<DefaultClassAccessSite> classAccessSites = new HashSet<>(); private transient Set<DefaultClassAccessSite> classAccessSites = new HashSet<>();
private List<DefaultClassAccessSite> classAccessSiteList;
private transient Set<DefaultClassAccessSite> safeClassAccessSites; private transient Set<DefaultClassAccessSite> safeClassAccessSites;
DefaultCallGraphNode(DefaultCallGraph graph, MethodReference method) { DefaultCallGraphNode(DefaultCallGraph graph, MethodReference method) {
@ -58,6 +61,7 @@ public class DefaultCallGraphNode implements CallGraphNode {
@Override @Override
public Collection<DefaultCallSite> getCallSites() { public Collection<DefaultCallSite> getCallSites() {
ensureDeserialized();
if (safeCallSites == null) { if (safeCallSites == null) {
safeCallSites = Collections.unmodifiableSet(callSites); safeCallSites = Collections.unmodifiableSet(callSites);
} }
@ -66,6 +70,7 @@ public class DefaultCallGraphNode implements CallGraphNode {
@Override @Override
public Collection<DefaultCallSite> getCallerCallSites() { public Collection<DefaultCallSite> getCallerCallSites() {
ensureDeserialized();
if (safeCallersCallSites == null) { if (safeCallersCallSites == null) {
safeCallersCallSites = Collections.unmodifiableList(callerCallSites); safeCallersCallSites = Collections.unmodifiableList(callerCallSites);
} }
@ -73,6 +78,7 @@ public class DefaultCallGraphNode implements CallGraphNode {
} }
public boolean addCallSite(MethodReference method, TextLocation location) { public boolean addCallSite(MethodReference method, TextLocation location) {
ensureDeserialized();
DefaultCallGraphNode callee = graph.getNode(method); DefaultCallGraphNode callee = graph.getNode(method);
DefaultCallSite callSite = new DefaultCallSite(location, callee, this); DefaultCallSite callSite = new DefaultCallSite(location, callee, this);
if (callSites.add(callSite)) { if (callSites.add(callSite)) {
@ -89,6 +95,7 @@ public class DefaultCallGraphNode implements CallGraphNode {
@Override @Override
public Collection<DefaultFieldAccessSite> getFieldAccessSites() { public Collection<DefaultFieldAccessSite> getFieldAccessSites() {
ensureDeserialized();
if (safeFieldAccessSites == null) { if (safeFieldAccessSites == null) {
safeFieldAccessSites = Collections.unmodifiableSet(fieldAccessSites); safeFieldAccessSites = Collections.unmodifiableSet(fieldAccessSites);
} }
@ -96,6 +103,7 @@ public class DefaultCallGraphNode implements CallGraphNode {
} }
public boolean addFieldAccess(FieldReference field, TextLocation location) { public boolean addFieldAccess(FieldReference field, TextLocation location) {
ensureDeserialized();
DefaultFieldAccessSite site = new DefaultFieldAccessSite(location, this, field); DefaultFieldAccessSite site = new DefaultFieldAccessSite(location, this, field);
if (fieldAccessSites.add(site)) { if (fieldAccessSites.add(site)) {
graph.addFieldAccess(site); graph.addFieldAccess(site);
@ -107,6 +115,7 @@ public class DefaultCallGraphNode implements CallGraphNode {
@Override @Override
public Collection<? extends ClassAccessSite> getClassAccessSites() { public Collection<? extends ClassAccessSite> getClassAccessSites() {
ensureDeserialized();
if (safeClassAccessSites == null) { if (safeClassAccessSites == null) {
safeClassAccessSites = Collections.unmodifiableSet(classAccessSites); safeClassAccessSites = Collections.unmodifiableSet(classAccessSites);
} }
@ -114,6 +123,7 @@ public class DefaultCallGraphNode implements CallGraphNode {
} }
public boolean addClassAccess(String className, TextLocation location) { public boolean addClassAccess(String className, TextLocation location) {
ensureDeserialized();
DefaultClassAccessSite site = new DefaultClassAccessSite(location, this, className); DefaultClassAccessSite site = new DefaultClassAccessSite(location, this, className);
if (classAccessSites.add(site)) { if (classAccessSites.add(site)) {
graph.addClassAccess(site); graph.addClassAccess(site);
@ -122,4 +132,31 @@ public class DefaultCallGraphNode implements CallGraphNode {
return false; return false;
} }
} }
private void ensureDeserialized() {
if (callSites != null) {
return;
}
callSites = new HashSet<>(callSiteList);
callSiteList = null;
fieldAccessSites = new HashSet<>(fieldAccessSiteList);
fieldAccessSiteList = null;
classAccessSites = new HashSet<>(classAccessSiteList);
classAccessSiteList = null;
}
private void writeObject(ObjectOutputStream out) throws IOException {
ensureDeserialized();
callSiteList = new ArrayList<>(callSites);
fieldAccessSiteList = new ArrayList<>(fieldAccessSites);
classAccessSiteList = new ArrayList<>(classAccessSites);
out.defaultWriteObject();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
}
} }

View File

@ -15,14 +15,11 @@
*/ */
package org.teavm.callgraph; package org.teavm.callgraph;
import java.io.Serializable;
import java.util.Objects; import java.util.Objects;
import org.teavm.model.TextLocation; import org.teavm.model.TextLocation;
/** public class DefaultCallSite implements CallSite, Serializable {
*
* @author Alexey Andreev
*/
public class DefaultCallSite implements CallSite {
private TextLocation location; private TextLocation location;
private DefaultCallGraphNode callee; private DefaultCallGraphNode callee;
private DefaultCallGraphNode caller; private DefaultCallGraphNode caller;

View File

@ -15,14 +15,11 @@
*/ */
package org.teavm.callgraph; package org.teavm.callgraph;
import java.io.Serializable;
import java.util.Objects; import java.util.Objects;
import org.teavm.model.TextLocation; import org.teavm.model.TextLocation;
/** public class DefaultClassAccessSite implements ClassAccessSite, Serializable {
*
* @author Alexey Andreev
*/
public class DefaultClassAccessSite implements ClassAccessSite {
private TextLocation location; private TextLocation location;
private CallGraphNode callee; private CallGraphNode callee;
private String className; private String className;

View File

@ -15,15 +15,12 @@
*/ */
package org.teavm.callgraph; package org.teavm.callgraph;
import java.io.Serializable;
import java.util.Objects; import java.util.Objects;
import org.teavm.model.FieldReference; import org.teavm.model.FieldReference;
import org.teavm.model.TextLocation; import org.teavm.model.TextLocation;
/** public class DefaultFieldAccessSite implements FieldAccessSite, Serializable {
*
* @author Alexey Andreev
*/
public class DefaultFieldAccessSite implements FieldAccessSite {
private TextLocation location; private TextLocation location;
private CallGraphNode callee; private CallGraphNode callee;
private FieldReference field; private FieldReference field;

View File

@ -15,14 +15,11 @@
*/ */
package org.teavm.diagnostics; package org.teavm.diagnostics;
import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
import org.teavm.model.*; import org.teavm.model.*;
/** public class Problem implements Serializable {
*
* @author Alexey Andreev
*/
public class Problem {
private ProblemSeverity severity; private ProblemSeverity severity;
private CallLocation location; private CallLocation location;
private String text; private String text;

View File

@ -17,10 +17,6 @@ package org.teavm.diagnostics;
import java.util.List; import java.util.List;
/**
*
* @author Alexey Andreev
*/
public interface ProblemProvider { public interface ProblemProvider {
List<Problem> getProblems(); List<Problem> getProblems();

View File

@ -15,11 +15,9 @@
*/ */
package org.teavm.diagnostics; package org.teavm.diagnostics;
/** import java.io.Serializable;
*
* @author Alexey Andreev public enum ProblemSeverity implements Serializable {
*/
public enum ProblemSeverity {
ERROR, ERROR,
WARNING WARNING
} }

View File

@ -15,9 +15,10 @@
*/ */
package org.teavm.model; package org.teavm.model;
import java.io.Serializable;
import java.util.Objects; import java.util.Objects;
public class CallLocation { public class CallLocation implements Serializable {
private MethodReference method; private MethodReference method;
private TextLocation sourceLocation; private TextLocation sourceLocation;

View File

@ -15,11 +15,9 @@
*/ */
package org.teavm.model; package org.teavm.model;
/** import java.io.Serializable;
*
* @author Alexey Andreev public class FieldReference implements Serializable {
*/
public class FieldReference {
private String className; private String className;
private String fieldName; private String fieldName;

View File

@ -17,6 +17,7 @@ package org.teavm.model;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.annotation.JsonValue;
import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
/** /**
@ -30,7 +31,7 @@ import java.util.Arrays;
* *
* @author Alexey Andreev * @author Alexey Andreev
*/ */
public class MethodReference { public class MethodReference implements Serializable {
private String className; private String className;
private String name; private String name;
private ValueType[] signature; private ValueType[] signature;

View File

@ -15,11 +15,9 @@
*/ */
package org.teavm.model; package org.teavm.model;
/** import java.io.Serializable;
*
* @author Alexey Andreev public enum PrimitiveType implements Serializable {
*/
public enum PrimitiveType {
BOOLEAN, BOOLEAN,
CHARACTER, CHARACTER,
BYTE, BYTE,

View File

@ -15,9 +15,10 @@
*/ */
package org.teavm.model; package org.teavm.model;
import java.io.Serializable;
import java.util.Objects; import java.util.Objects;
public class TextLocation { public class TextLocation implements Serializable {
private String fileName; private String fileName;
private int line = -1; private int line = -1;

View File

@ -15,15 +15,11 @@
*/ */
package org.teavm.model; package org.teavm.model;
import java.io.Serializable;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public abstract class ValueType implements Serializable {
/**
*
* @author Alexey Andreev
*/
public abstract class ValueType {
volatile String reprCache; volatile String reprCache;
private static final Map<Class<?>, ValueType> primitiveMap = new HashMap<>(); private static final Map<Class<?>, ValueType> primitiveMap = new HashMap<>();

View File

@ -15,11 +15,9 @@
*/ */
package org.teavm.vm; package org.teavm.vm;
/** import java.io.Serializable;
*
* @author Alexey Andreev public enum TeaVMProgressFeedback implements Serializable {
*/
public enum TeaVMProgressFeedback {
CONTINUE, CONTINUE,
CANCEL CANCEL
} }