Revision: 6065 Author: [email protected] Date: Tue Sep 1 15:34:28 2009 Log: Merging trunk c6051 & c6052 into this branch.
Review by: jgw http://code.google.com/p/google-web-toolkit/source/detail?r=6065 Added: /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/jjs/AbstractCompiler.java /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/jjs/JavaScriptCompiler.java Modified: /branches/snapshot-2009.08.21-r5989/branch-info.txt /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/CompilePerms.java /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/Permutation.java /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/Precompile.java /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/jjs/UnifiedAst.java /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/shell/JsValueGlue.java /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/shell/rewrite/WriteJsoImpl.java ======================================= --- /dev/null +++ /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/jjs/AbstractCompiler.java Tue Sep 1 15:34:28 2009 @@ -0,0 +1,49 @@ +/* + * Copyright 2009 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.dev.jjs; + +import com.google.gwt.core.ext.TreeLogger; +import com.google.gwt.core.ext.UnableToCompleteException; +import com.google.gwt.dev.cfg.ModuleDef; +import com.google.gwt.dev.jdt.RebindPermutationOracle; + +/** + * A Compiler used to compile a GWT project into artifacts. + */ +public interface AbstractCompiler { + /** + * Performs a precompilation, returning an object that can then be used to + * compile individual permutations.. + * + * @param logger the logger to use + * @param module the module to compile + * @param rpo the RebindPermutationOracle + * @param declEntryPts the set of entry classes declared in a GWT module; + * these will be automatically rebound + * @param additionalRootTypes additional classes that should serve as code + * roots; will not be rebound; may be <code>null</code> + * @param options the compiler options + * @param singlePermutation if true, do not pre-optimize the resulting AST or + * allow serialization of the result + * @return the unified AST used to drive permutation compiles + * @throws UnableToCompleteException if an error other than + * {...@link OutOfMemoryError} occurs + */ + UnifiedAst precompile(TreeLogger logger, ModuleDef module, + RebindPermutationOracle rpo, String[] declEntryPts, + String[] additionalRootTypes, JJSOptions options, + boolean singlePermutation) throws UnableToCompleteException; +} ======================================= --- /dev/null +++ /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/jjs/JavaScriptCompiler.java Tue Sep 1 15:34:28 2009 @@ -0,0 +1,36 @@ +/* + * Copyright 2009 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.dev.jjs; + +import com.google.gwt.core.ext.TreeLogger; +import com.google.gwt.core.ext.UnableToCompleteException; +import com.google.gwt.dev.cfg.ModuleDef; +import com.google.gwt.dev.jdt.RebindPermutationOracle; + +/** + * Uses the default compiler {...@link JavaToJavaScriptCompiler}. + */ +public class JavaScriptCompiler implements AbstractCompiler { + + public UnifiedAst precompile(TreeLogger logger, ModuleDef module, + RebindPermutationOracle rpo, String[] declEntryPts, + String[] additionalRootTypes, JJSOptions options, + boolean singlePermutation) throws UnableToCompleteException { + return JavaToJavaScriptCompiler.precompile(logger, module, rpo, + declEntryPts, additionalRootTypes, options, singlePermutation); + } + +} ======================================= --- /branches/snapshot-2009.08.21-r5989/branch-info.txt Tue Aug 25 13:07:35 2009 +++ /branches/snapshot-2009.08.21-r5989/branch-info.txt Tue Sep 1 15:34:28 2009 @@ -9,3 +9,4 @@ /trunk 6010 was merged (r6011) into snapshot $ svn merge -c6010 https://google-web-toolkit.googlecode.com/svn/trunk +/trunk c6051 & c6052 were merged (r6064) into snapshot ======================================= --- /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/CompilePerms.java Tue Jul 28 12:27:56 2009 +++ /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/CompilePerms.java Tue Sep 1 15:34:28 2009 @@ -18,7 +18,6 @@ import com.google.gwt.core.ext.TreeLogger; import com.google.gwt.core.ext.UnableToCompleteException; import com.google.gwt.dev.CompileTaskRunner.CompileTask; -import com.google.gwt.dev.jjs.JavaToJavaScriptCompiler; import com.google.gwt.dev.jjs.PermutationResult; import com.google.gwt.dev.jjs.UnifiedAst; import com.google.gwt.dev.util.FileBackedObject; @@ -185,7 +184,7 @@ public static PermutationResult compile(TreeLogger logger, Permutation permutation, UnifiedAst unifiedAst) throws UnableToCompleteException { - return JavaToJavaScriptCompiler.compilePermutation(logger, unifiedAst, + return unifiedAst.compilePermutation(logger, permutation.getRebindAnswers(), permutation.getPropertyOracles(), permutation.getId()); } ======================================= --- /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/Permutation.java Tue Dec 23 16:45:21 2008 +++ /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/Permutation.java Tue Sep 1 15:34:28 2009 @@ -19,9 +19,10 @@ import java.io.Serializable; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import java.util.Set; import java.util.SortedMap; +import java.util.SortedSet; import java.util.TreeMap; /** @@ -58,11 +59,17 @@ } public SortedMap<String, String> getRebindAnswers() { - return rebindAnswers; + return Collections.unmodifiableSortedMap(rebindAnswers); } - public void mergeFrom(Permutation other) { - assert rebindAnswers.equals(other.rebindAnswers); + public void mergeFrom(Permutation other, SortedSet<String> liveRebindRequests) { + if (getClass().desiredAssertionStatus()) { + for (String rebindRequest : liveRebindRequests) { + String myAnswer = rebindAnswers.get(rebindRequest); + String otherAnswer = other.rebindAnswers.get(rebindRequest); + assert myAnswer.equals(otherAnswer); + } + } assert !propertyOracles.isEmpty(); assert !other.propertyOracles.isEmpty(); propertyOracles.addAll(other.propertyOracles); @@ -72,8 +79,4 @@ public void putRebindAnswer(String requestType, String resultType) { rebindAnswers.put(requestType, resultType); } - - public void reduceRebindAnswers(Set<String> liveRebindRequests) { - rebindAnswers.keySet().retainAll(liveRebindRequests); - } -} +} ======================================= --- /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/Precompile.java Mon Aug 17 09:47:12 2009 +++ /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/Precompile.java Tue Sep 1 15:34:28 2009 @@ -31,9 +31,10 @@ import com.google.gwt.dev.javac.StandardGeneratorContext; import com.google.gwt.dev.jdt.RebindOracle; import com.google.gwt.dev.jdt.RebindPermutationOracle; +import com.google.gwt.dev.jjs.AbstractCompiler; import com.google.gwt.dev.jjs.JJSOptions; import com.google.gwt.dev.jjs.JJSOptionsImpl; -import com.google.gwt.dev.jjs.JavaToJavaScriptCompiler; +import com.google.gwt.dev.jjs.JavaScriptCompiler; import com.google.gwt.dev.jjs.JsOutputOption; import com.google.gwt.dev.jjs.UnifiedAst; import com.google.gwt.dev.shell.CheckForUpdates; @@ -448,7 +449,7 @@ generatorResourcesDir); // Never optimize on a validation run. jjsOptions.setOptimizePrecompile(false); - JavaToJavaScriptCompiler.precompile(logger, module, rpo, declEntryPts, + getCompiler(module).precompile(logger, module, rpo, declEntryPts, additionalRootTypes, jjsOptions, true); return true; } catch (UnableToCompleteException e) { @@ -456,6 +457,28 @@ return false; } } + + private static AbstractCompiler getCompiler(ModuleDef module) { + ConfigurationProperty compilerClassProp = module.getProperties().createConfiguration( + "x.compiler.class", false); + String compilerClassName = compilerClassProp.getValue(); + if (compilerClassName == null || compilerClassName.length() == 0) { + return new JavaScriptCompiler(); + } + Throwable caught; + try { + Class<?> compilerClass = Class.forName(compilerClassName); + return (AbstractCompiler) compilerClass.newInstance(); + } catch (ClassNotFoundException e) { + caught = e; + } catch (InstantiationException e) { + caught = e; + } catch (IllegalAccessException e) { + caught = e; + } + throw new RuntimeException("Unable to instantiate compiler class '" + + compilerClassName + "'", caught); + } private static Precompilation precompile(TreeLogger logger, JJSOptions jjsOptions, ModuleDef module, int permutationBase, @@ -481,7 +504,7 @@ module, compilationState, generatedArtifacts, allPermutations, genDir, generatorResourcesDir); PerfLogger.start("Precompile"); - UnifiedAst unifiedAst = JavaToJavaScriptCompiler.precompile(logger, + UnifiedAst unifiedAst = getCompiler(module).precompile(logger, module, rpo, declEntryPts, null, jjsOptions, rpo.getPermuationCount() == 1); PerfLogger.end(); @@ -490,15 +513,18 @@ Permutation[] permutations = rpo.getPermutations(); // Sort the permutations by an ordered key to ensure determinism. SortedMap<String, Permutation> merged = new TreeMap<String, Permutation>(); + SortedSet<String> liveRebindRequests = unifiedAst.getRebindRequests(); for (Permutation permutation : permutations) { - permutation.reduceRebindAnswers(unifiedAst.getRebindRequests()); - // Arbitrarily choose as a key the stringified map of rebind answers. - String rebindResultsString = permutation.getRebindAnswers().toString(); - if (merged.containsKey(rebindResultsString)) { - Permutation existing = merged.get(rebindResultsString); - existing.mergeFrom(permutation); + // Construct a key from the stringified map of live rebind answers. + SortedMap<String, String> rebindAnswers = new TreeMap<String, String>( + permutation.getRebindAnswers()); + rebindAnswers.keySet().retainAll(liveRebindRequests); + String key = rebindAnswers.toString(); + if (merged.containsKey(key)) { + Permutation existing = merged.get(key); + existing.mergeFrom(permutation, liveRebindRequests); } else { - merged.put(rebindResultsString, permutation); + merged.put(key, permutation); } } return new Precompilation(unifiedAst, merged.values(), permutationBase, ======================================= --- /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java Mon Aug 17 13:00:36 2009 +++ /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java Tue Sep 1 15:34:28 2009 @@ -191,9 +191,10 @@ * @param unifiedAst the result of a * {...@link #precompile(TreeLogger, WebModeCompilerFrontEnd, String[], JJSOptions, boolean)} * @param rebindAnswers the set of rebind answers to resolve all outstanding - * rebind decisions - * @param propertyOracles All property oracles corresponding to this - * permutation. + * rebind decisions for this permutation + * @param propertyOracles all property oracles corresponding to this + * permutation + * @param permutationId the unique id of this permutation * @return the output JavaScript * @throws UnableToCompleteException if an error other than * {...@link OutOfMemoryError} occurs ======================================= --- /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/jjs/UnifiedAst.java Fri Nov 21 07:53:38 2008 +++ /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/jjs/UnifiedAst.java Tue Sep 1 15:34:28 2009 @@ -15,6 +15,9 @@ */ package com.google.gwt.dev.jjs; +import com.google.gwt.core.ext.PropertyOracle; +import com.google.gwt.core.ext.TreeLogger; +import com.google.gwt.core.ext.UnableToCompleteException; import com.google.gwt.dev.jjs.ast.JProgram; import com.google.gwt.dev.js.ast.JsProgram; import com.google.gwt.dev.util.PerfLogger; @@ -26,6 +29,7 @@ import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Collections; +import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -34,7 +38,7 @@ * Represents a unified, non-permutation specific AST. This AST is used to drive * per-permutation compiles. */ -public final class UnifiedAst implements Serializable { +public class UnifiedAst implements Serializable { /** * Encapsulates the combined programs. @@ -128,6 +132,37 @@ rebindRequests)); this.serializedAst = singlePermutation ? null : serializeAst(initialAst); } + + /** + * Copy constructor, invalidates the original. + */ + UnifiedAst(UnifiedAst other) { + this.options = other.options; + this.initialAst = other.initialAst; + other.initialAst = null; // steal its copy + this.rebindRequests = other.rebindRequests; + this.serializedAst = other.serializedAst; + } + + /** + * Compiles a particular permutation. + * + * @param logger the logger to use + * @param rebindAnswers the set of rebind answers to resolve all outstanding + * rebind decisions for this permutation + * @param propertyOracles all property oracles corresponding to this + * permutation + * @param permutationId the unique id of this permutation + * @return the permutation result + * @throws UnableToCompleteException if an error other than + * {...@link OutOfMemoryError} occurs + */ + public PermutationResult compilePermutation(TreeLogger logger, + Map<String, String> rebindAnswers, PropertyOracle[] propertyOracles, + int permutationId) throws UnableToCompleteException { + return JavaToJavaScriptCompiler.compilePermutation(logger, this, + rebindAnswers, propertyOracles, permutationId); + } /** * Returns the active set of JJS options associated with this compile. ======================================= --- /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/shell/JsValueGlue.java Tue Apr 29 08:38:38 2008 +++ /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/shell/JsValueGlue.java Tue Sep 1 15:34:28 2009 @@ -214,7 +214,6 @@ // Instantiate the JSO class. Class<?> jsoType = Class.forName(JSO_IMPL_CLASS, true, classLoader); Constructor<?> ctor = jsoType.getDeclaredConstructor(); - ctor.setAccessible(true); jso = ctor.newInstance(); // Set the reference field to this JsValue using reflection. ======================================= --- /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/shell/rewrite/WriteJsoImpl.java Tue Feb 24 14:28:39 2009 +++ /branches/snapshot-2009.08.21-r5989/dev/core/src/com/google/gwt/dev/shell/rewrite/WriteJsoImpl.java Tue Sep 1 15:34:28 2009 @@ -93,6 +93,17 @@ writeTrampoline(entry.getKey(), entry.getValue()); } } + + @Override + public MethodVisitor visitMethod(int access, String name, String desc, + String signature, String[] exceptions) { + if (isCtor(name)) { + // make the JavaScriptObject$ constructor public + access &= ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED); + access |= Opcodes.ACC_PUBLIC; + } + return super.visitMethod(access, name, desc, signature, exceptions); + } /** * JSO methods are implemented as flyweight style, with the instance being --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
