Skip to content

Commit

Permalink
Merge remote-tracking branch 'robovm/master' into JEP181/nestbased_ac…
Browse files Browse the repository at this point in the history
…cess_control
  • Loading branch information
dkimitsa committed Jul 11, 2022
2 parents d33db05 + a53bb3e commit 45b38a1
Show file tree
Hide file tree
Showing 126 changed files with 1,183 additions and 447 deletions.
2 changes: 1 addition & 1 deletion compiler/cacerts/full/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.mobidevelop.robovm</groupId>
<artifactId>robovm-cacerts-parent</artifactId>
<version>2.3.17-SNAPSHOT</version>
<version>2.3.19-SNAPSHOT</version>
</parent>

<artifactId>robovm-cacerts-full</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion compiler/cacerts/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.mobidevelop.robovm</groupId>
<artifactId>robovm-compiler-parent</artifactId>
<version>2.3.17-SNAPSHOT</version>
<version>2.3.19-SNAPSHOT</version>
</parent>

<artifactId>robovm-cacerts-parent</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion compiler/cocoatouch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.mobidevelop.robovm</groupId>
<artifactId>robovm-compiler-parent</artifactId>
<version>2.3.17-SNAPSHOT</version>
<version>2.3.19-SNAPSHOT</version>
</parent>

<artifactId>robovm-cocoatouch</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion compiler/compiler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.mobidevelop.robovm</groupId>
<artifactId>robovm-compiler-parent</artifactId>
<version>2.3.17-SNAPSHOT</version>
<version>2.3.19-SNAPSHOT</version>
</parent>

<artifactId>robovm-compiler</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@
import org.robovm.compiler.config.Config.TreeShakerMode;
import org.robovm.compiler.config.StripArchivesConfig.StripArchivesBuilder;
import org.robovm.compiler.log.ConsoleLogger;
import org.robovm.compiler.plugin.LaunchPlugin;
import org.robovm.compiler.plugin.Plugin;
import org.robovm.compiler.plugin.PluginArgument;
import org.robovm.compiler.plugin.TargetPlugin;
import org.robovm.compiler.plugin.*;
import org.robovm.compiler.target.ConsoleTarget;
import org.robovm.compiler.target.LaunchParameters;
import org.robovm.compiler.target.ios.*;
Expand Down Expand Up @@ -439,6 +436,11 @@ public void failure(Clazz clazz, Throwable t) {
dependencyGraph.add(clazz, rootClasses.contains(clazz), forceLinkMethods);
linkClasses.add(clazz);

// notify plugins
for (CompilerPlugin plugin : config.getCompilerPlugins()) {
plugin.afterClassDependenciesResolved(config, clazz);
}

if (compileDependencies) {
addMetaInfImplementations(config.getClazzes(), clazz, linkClasses, compileQueue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.robovm.compiler.clazz.MethodInfo;
import org.robovm.compiler.config.Arch;
import org.robovm.compiler.config.Config;
import org.robovm.compiler.config.Environment;
import org.robovm.compiler.config.OS;
import org.robovm.compiler.llvm.Alias;
import org.robovm.compiler.llvm.AliasRef;
Expand Down Expand Up @@ -228,7 +227,7 @@ public class ClassCompiler {
private final TrampolineCompiler trampolineResolver;
private final ObjCMemberPlugin.MethodCompiler objcMethodCompiler;

private final ByteArrayOutputStream output = new ByteArrayOutputStream(256 * 1024);
private final ByteArrayOutputStream output = new ByteArrayOutputStream(4 * 1024 * 1024);

public ClassCompiler(Config config) {
this.config = config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,10 @@ public void link(Set<Clazz> classes) throws IOException {
}
}

config.getTarget().build(objectFiles);
File binaryFile = config.getTarget().build(objectFiles);
for (CompilerPlugin plugin : config.getCompilerPlugins()) {
plugin.afterLinker(config, binaryFile);
}
}

private void generateMachineCode(final Config config, ModuleBuilder[] mbs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public abstract class AbstractPath implements Path {
protected final Clazzes clazzes;
protected final int index;
protected Set<Clazz> clazzSet = null;
protected Set<Package> packageSet = null;
protected boolean inBootclasspath = false;
protected Map<String, Clazz> generatedClasses = new HashMap<String, Clazz>();
protected boolean disposed = false;
protected boolean inBootclasspath;
protected Map<String, Clazz> generatedClasses = new HashMap<>();
protected final File generatedClassDir;

AbstractPath(File file, Clazzes clazzes, int index, boolean inBootclasspath) {
Expand All @@ -57,6 +57,8 @@ public File getFile() {
}

public Set<Clazz> listClasses() {
if (disposed)
throw new IllegalStateException("Path was disposed!");
if (clazzSet == null) {
clazzSet = doListClasses();
}
Expand Down Expand Up @@ -119,5 +121,11 @@ public boolean equals(Object obj) {
public String toString() {
return file.toString();
}


@Override
public void disposeBuildData() {
disposed = true;
clazzSet = null;
generatedClasses = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.apache.commons.io.IOUtils;
import soot.SootClass;
import soot.SootMethod;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
Expand Down Expand Up @@ -205,4 +206,18 @@ public int compareTo(Clazz o) {
public String toString() {
return className;
}

/**
* Drops Soot object and releases all its resolved bodies
*/
public void shrinkSoot() {
if (sootClass != null) {
// dropping all bodies
for (SootMethod m: sootClass.getMethods()) {
if (m.hasActiveBody())
m.releaseActiveBody();
}
sootClass = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public class ClazzInfo implements Serializable {
private String name;
private String internalName;
private String superclassName;
private final List<String> interfaceNames = new ArrayList<String>();
private final List<MethodInfo> methods = new ArrayList<MethodInfo>();
private final Set<String> catchNames = new HashSet<String>();
private Map<String, Dependency> dependencies = new HashMap<String,Dependency>();
private final Set<String> checkcasts = new HashSet<String>();
private final Set<String> instanceofs = new HashSet<String>();
private final Set<String> invokes = new HashSet<String>();
private final List<String> interfaceNames = new ArrayList<>();
private final List<MethodInfo> methods = new ArrayList<>();
private final Set<String> catchNames = new HashSet<>();
private Map<String, Dependency> dependencies = new HashMap<>();
private final Set<String> checkcasts = new HashSet<>();
private final Set<String> instanceofs = new HashSet<>();
private final Set<String> invokes = new HashSet<>();
private boolean isStruct;
private boolean isEnum;

Expand Down Expand Up @@ -190,7 +190,7 @@ public void setInterfaceNames(List<String> interfaceNames) {
}

public List<ClazzInfo> getInterfaces() {
List<ClazzInfo> result = new ArrayList<ClazzInfo>();
List<ClazzInfo> result = new ArrayList<>();
for (String ifname : interfaceNames) {
result.add(loadClazzInfo(ifname));
}
Expand All @@ -207,7 +207,7 @@ public void setCatchNames(Set<String> catchNames) {
}

public List<ClazzInfo> getCatches() {
List<ClazzInfo> result = new ArrayList<ClazzInfo>();
List<ClazzInfo> result = new ArrayList<>();
for (String n : catchNames) {
result.add(loadClazzInfo(n));
}
Expand Down Expand Up @@ -268,11 +268,11 @@ public void addSuperMethodDependency(String owner, String name, String desc, boo
}

public void clearDependencies() {
dependencies = new HashMap<String, Dependency>();
dependencies = new HashMap<>();
}

public Set<Dependency> getDependencies() {
return new HashSet<Dependency>(dependencies.values());
return new HashSet<>(dependencies.values());
}

public Set<Dependency> getAllDependencies() {
Expand Down Expand Up @@ -360,4 +360,10 @@ public boolean equals(Object obj) {
}
return true;
}

public void dropDependencyData() {
for (MethodInfo mi : getMethods())
mi.dropDependencyData();
dependencies = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,21 @@
*/
public class Clazzes {
private final Config config;
private final List<Path> bootclasspathPaths = new ArrayList<Path>();
private final List<Path> classpathPaths = new ArrayList<Path>();
private final List<Path> paths = new ArrayList<Path>();
private final Map<String, Clazz> cache = new HashMap<String, Clazz>();
private final List<Clazz> allClasses = new ArrayList<Clazz>();
private final List<Path> bootclasspathPaths = new ArrayList<>();
private final List<Path> classpathPaths = new ArrayList<>();
private final List<Path> paths = new ArrayList<>();
private final Map<String, Clazz> cache = new HashMap<>();
private final List<Clazz> allClasses = new ArrayList<>();

private boolean sootInitialized = false;

// disposed state
private boolean sootDisposed = false;
private boolean contentDisposed = false;

public Clazzes(Config config, List<File> bootclasspath, List<File> classpath) throws IOException {
this.config = config;
Set<File> seen = new HashSet<File>();
Set<File> seen = new HashSet<>();
addPaths(bootclasspath, bootclasspathPaths, seen, true);
addPaths(classpath, classpathPaths, seen, false);
paths.addAll(bootclasspathPaths);
Expand Down Expand Up @@ -123,6 +127,7 @@ private boolean isEmpty(File dir) {
}

private void populateCache() {
requiresContent();
for (Path p : paths) {
for (Clazz clazz : p.listClasses()) {
if (!cache.containsKey(clazz.getInternalName())) {
Expand All @@ -134,6 +139,7 @@ private void populateCache() {
}

public Clazz load(String internalName) {
requiresContent();
Clazz clazz = cache.get(internalName);
if (clazz == null) {
// Could be a generated class
Expand Down Expand Up @@ -175,10 +181,12 @@ public List<Path> getPaths() {
}

public List<Clazz> listClasses() {
requiresContent();
return Collections.unmodifiableList(allClasses);
}

SootClass getSootClass(Clazz clazz) {
requiresSoot();
if (!sootInitialized) {
initializeSoot(this);
sootInitialized = true;
Expand Down Expand Up @@ -210,6 +218,42 @@ private static String getSootClasspath(Clazzes clazzes) {
return sb.toString();
}

/**
* sanity: checks if soot was disposed
*/
private void requiresSoot() {
if (sootDisposed)
throw new IllegalStateException("Soot has been disposed !");
}

/**
* releases soot resources, singletons once these are not required anymore to reduce memory pressure
* after this point soot is not usable anymore
*/
public void disposeSoot() {
requiresSoot();
soot.G.reset();
sootDisposed = true;
}


private void requiresContent() {
if (contentDisposed)
throw new IllegalStateException("Content has been disposed !");
}

/**
* drops caches and all classes data. after this point this data is not accessible
*/
public void disposeData() {
requiresContent();
cache.clear();
allClasses.clear();
for (Path p : paths)
p.disposeBuildData();
contentDisposed = true;
}

private static void initializeSoot(Clazzes clazzes) {
soot.G.reset();
Options.v().set_output_format(Options.output_format_jimple);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ public boolean equals(Object obj) {
return true;
}

public void dropDependencyData() {
dependencies = null;
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@ public interface Path {
boolean contains(String file);

InputStream open(String file) throws IOException;

/**
* Dispose any cached data to reduce memory footprint
*/
void disposeBuildData();
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@
import org.robovm.compiler.config.tools.Tools;
import org.robovm.compiler.llvm.DataLayout;
import org.robovm.compiler.log.Logger;
import org.robovm.compiler.plugin.CompilerPlugin;
import org.robovm.compiler.plugin.LaunchPlugin;
import org.robovm.compiler.plugin.Plugin;
import org.robovm.compiler.plugin.PluginArgument;
import org.robovm.compiler.plugin.TargetPlugin;
import org.robovm.compiler.plugin.*;
import org.robovm.compiler.plugin.annotation.AnnotationImplPlugin;
import org.robovm.compiler.plugin.debug.DebugInformationPlugin;
import org.robovm.compiler.plugin.debug.DebuggerLaunchPlugin;
Expand Down Expand Up @@ -259,7 +255,8 @@ protected Config(UUID uuid) {
new ByteBufferJava9ApiPlugin(),
new LambdaPlugin(),
new DebugInformationPlugin(),
new DebuggerLaunchPlugin()
new DebuggerLaunchPlugin(),
new BuildGarbageCollectorPlugin()
));
this.loadPluginsFromClassPath();
}
Expand Down Expand Up @@ -404,6 +401,8 @@ public StripArchivesConfig getStripArchivesConfig() {
}

public DependencyGraph getDependencyGraph() {
if (dependencyGraph == null)
throw new IllegalStateException(".dependencyGraph has been disposed!");
return dependencyGraph;
}

Expand Down Expand Up @@ -504,14 +503,29 @@ public File getOsArchDepLibDir() {
}

public Clazzes getClazzes() {
if (clazzes == null)
throw new IllegalStateException(".clazzes has been disposed!");
return clazzes;
}

public void disposeBuildData() {
// not null clazzes as some data like allPath is required post-build (e.g. to stripArchives)
clazzes.disposeData();
dependencyGraph = null;
vtableCache = null;
itableCache = null;
marshalerLookup = null;
}

public VTable.Cache getVTableCache() {
if (vtableCache == null)
throw new IllegalStateException(".vtableCache has been disposed!");
return vtableCache;
}

public ITable.Cache getITableCache() {
if (itableCache == null)
throw new IllegalStateException(".itableCache has been disposed!");
return itableCache;
}

Expand Down
Loading

0 comments on commit 45b38a1

Please sign in to comment.