Reduce devmode memory usage by not caching bytecode. Instead of caching bytecode in a byte[] array in a TypeData in a CompiledClass, read it again from the DiskCache. It looks like the bytecode is only used once per compile, so the increased memory usage isn't worth the speedup. (Also, the OS typically caches files.) Testing: using our largest GWT app, this reduced memory consumption from 1170k (at idle after a gc) to 650k. The time for the first reload went from 1:34 to 1:31 and the second reload went from 4 to 5 seconds (measured up to the log message that the module is loaded). This seems well within the margin of error. Change-Id: I2306c8873cd4651de09ae61bf3f13b64fc4cb7a0 Review-Link: https://gwt-review.googlesource.com/#/c/1910/ Review by: mdempsky@google.com git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@11507 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/javac/CompiledClass.java b/dev/core/src/com/google/gwt/dev/javac/CompiledClass.java index 6740b7a..a206f0e 100644 --- a/dev/core/src/com/google/gwt/dev/javac/CompiledClass.java +++ b/dev/core/src/com/google/gwt/dev/javac/CompiledClass.java
@@ -15,7 +15,6 @@ */ package com.google.gwt.dev.javac; -import com.google.gwt.dev.javac.TypeOracleMediator.TypeData; import com.google.gwt.dev.jjs.InternalCompilerException; import com.google.gwt.dev.util.DiskCache; import com.google.gwt.dev.util.DiskCacheToken; @@ -83,7 +82,6 @@ private String signatureHash; private final String sourceName; - private transient TypeData typeData; private CompilationUnit unit; @@ -116,13 +114,12 @@ this.sourceName = orig.sourceName; this.classBytesToken = orig.classBytesToken; this.isLocal = orig.isLocal; - this.typeData = orig.typeData; this.unit = newUnit; this.signatureHash = orig.signatureHash; } /** - * Returns the bytes of the compiled class. + * Reads the bytes of the compiled class from the disk cache. */ public byte[] getBytes() { return classBytesToken.readByteArray(); @@ -164,15 +161,6 @@ return sourceName; } - public TypeData getTypeData() { - if (typeData == null) { - typeData = - new TypeData(getPackageName(), getSourceName(), getInternalName(), null, getBytes(), - getUnit().getLastModified()); - } - return typeData; - } - public CompilationUnit getUnit() { return unit; }
diff --git a/dev/core/src/com/google/gwt/dev/javac/TypeOracleMediator.java b/dev/core/src/com/google/gwt/dev/javac/TypeOracleMediator.java index 593c76a..7b81b12 100644 --- a/dev/core/src/com/google/gwt/dev/javac/TypeOracleMediator.java +++ b/dev/core/src/com/google/gwt/dev/javac/TypeOracleMediator.java
@@ -78,7 +78,7 @@ * A container to hold all the information we need to add one type to the * TypeOracle. */ - public static class TypeData { + static class TypeData { /** * Bytecode from compiled Java source. @@ -373,7 +373,8 @@ * Adds new units to an existing TypeOracle. * * @param logger logger to use - * @param typeDataList collection of data need to build types + * @param typeDataList collection of data need to build types. (Doesn't retain + * references to TypeData instances.) * @param argsLookup Allows the caller to pass the method argument names which * are not normally available in bytecode. */ @@ -501,6 +502,9 @@ return AnnotationProxyFactory.create(annotationClass, values); } + /** + * Doesn't retain a reference to the TypeData. + */ private JRealClassType createType(TypeData typeData, CollectClassData collectClassData, CollectClassData enclosingClassData) { int access = collectClassData.getAccess(); @@ -548,6 +552,9 @@ return resultType; } + /** + * Doesn't retain a reference to the TypeData. + */ private JRealClassType createType(TypeData typeData, Set<JRealClassType> unresolvedTypes, TypeOracleBuildContext context) {
diff --git a/dev/core/src/com/google/gwt/dev/javac/TypeOracleMediatorFromSource.java b/dev/core/src/com/google/gwt/dev/javac/TypeOracleMediatorFromSource.java index 2f92178..b4fce47 100644 --- a/dev/core/src/com/google/gwt/dev/javac/TypeOracleMediatorFromSource.java +++ b/dev/core/src/com/google/gwt/dev/javac/TypeOracleMediatorFromSource.java
@@ -42,9 +42,10 @@ // Create list including byte code for each type to add for (CompilationUnit unit : units) { - Collection<CompiledClass> compiledClasses = unit.getCompiledClasses(); - for (CompiledClass compiledClass : compiledClasses) { - classDataList.add(compiledClass.getTypeData()); + for (CompiledClass cc : unit.getCompiledClasses()) { + TypeData data = new TypeData(cc.getPackageName(), cc.getSourceName(), cc.getInternalName(), + null, cc.getBytes(), cc.getUnit().getLastModified()); + classDataList.add(data); } }