Joel has agreed to handle the review of this branch.  Now that all of
the web-mode tests pass with -XdisableClassMetadata, I'm calling the
branch done-enough for review and integration.  Here's a quick summary
of tha changes made.

 svn merge -r4602:HEAD
http://google-web-toolkit.googlecode.com/svn/changes/bobv/elide_rpc_type_names_r4602

Major changes:
  - Added configuration property to change generated RPC code to
replace type names on the wire with short idents.
    - Allow JSNI to refer to class literals via (@com.foo.Bar::class) syntax.
  - Adds an -XdisableClassMetadata flag to reduce the functionality of
java.lang.Class in compiled code.
    - Class.getName() -> returns "Class$<hashCode()>"
    - Class.getSuperclass() -> returns null


Changes grouped by functional area:

Add -XdisableClassMetadata flag:
 dev/core/src/com/google/gwt/dev/HostedModeBase.java
                     |    2     2 +     0 -     0 !
 dev/core/src/com/google/gwt/dev/Precompile.java
                     |   10     10 +    0 -     0 !
 dev/core/src/com/google/gwt/dev/jjs/JJSOptions.java
                     |    5     3 +     2 -     0 !
 dev/core/src/com/google/gwt/dev/jjs/JJSOptionsImpl.java
                     |   10     10 +    0 -     0 !
 dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
                     |    2     1 +     1 -     0 !
 dev/core/src/com/google/gwt/dev/util/arg/ArgHandlerDisableClassMetadata.java
              |   46    46 +    0 -     0 !
 dev/core/src/com/google/gwt/dev/util/arg/OptionDisableClassMetadata.java
                  |   25        25 +    0 -     0 !

Just option-handling code to define the flag.



Allow JSNI access to ::class literals:
 dev/core/src/com/google/gwt/dev/jjs/ast/JArrayType.java
                     |    1     1 +     0 -     0 !
 dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java
                     |   35     21 +    14 -    0 !
 dev/core/src/com/google/gwt/dev/js/rhino/TokenStream.java
                     |   11     11 +    0 -     0 !
 dev/core/src/com/google/gwt/dev/shell/CompilingClassLoader.java
                     |   46     41 +    5 -     0 !
 dev/core/src/com/google/gwt/dev/shell/DispatchClassInfo.java
                     |    4     3 +     1 -     0 !
 dev/core/src/com/google/gwt/dev/shell/JavaDispatchImpl.java
                     |   25     22 +    3 -     0 !
 dev/core/src/com/google/gwt/dev/shell/SyntheticClassMember.java
                     |   46     46 +    0 -     0 !
 dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
                     |   42     42 +    0 -     0 !

The idea is that in web mode, the compiler will implicitly add a field
named ::class to every type that's defined.  It's necessary to have
JProgram traverse all defined JArrayTypes as well as having JArrayType
traverse its fields to make this just work with existing JSNI dispatch
code.

In hosted mode, we make ::class act as though there's actually a Field
in the class with that name.  The SyntheticClassMember is used since
Field is a final type.

TokenStream is modified slightly to allow @com.foo.Bar[][]::class
syntax for referring to array types.  Primitive types are referenced
as @Z::class.



Implement metadata removal:
 /dev/core/src/com/google/gwt/dev/jjs/ast/JClassLiteral.java
                      |   23    22 +    1 -     0 !
 dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java
                     |   76     65 +    11 -    0 !
 user/super/com/google/gwt/emul/java/lang/Class.java
                     |   26     22 +    4 -     0 !
 user/super/com/google/gwt/emul/java/lang/Enum.java
                     |    7     6 +     1 -     0 !
 user/super/com/google/gwt/emul/java/lang/System.java
                     |   21     12 +    9 -     0 !
 user/super/com/google/gwt/emul/java/util/Arrays.java
                     |    8     4 +     4 -     0 !

Class literals for array types are now able to specify their component
type, which removes the dependency on type names from old JRE
emulation code.

GenerateJavaAST rewrites java.lang.Class to remove reads from the
typename field.  Calls to Class.createForArray() have an extra
parameter specifying the component type.  Class literals for enum
types are always created with Class.createForEnum().  In the general
case, the generated JS for a regular Class literal is simply
"foo_classList = new Class();".




Generated code improvements:
 dev/core/src/com/google/gwt/dev/js/JsInliner.java
                     |  172     139 +   33 -    0 !

Reduces "var foo; foo = bar; return foo;" to "bar".  Allows inlining
of expressions into the top-level JsProgram, except for top-level
function invocations.  This allows class literal construction for
regular classes to be "new Class()".




Run web-mode tests with -XdisableClassMetadata flag on:
 user/build.xml
                     |    9     9 +     0 -     0 !




Remove type names from RPC:
 user/src/com/google/gwt/user/RemoteService.gwt.xml
                     |    5     5 +     0 -     0 !
 user/src/com/google/gwt/user/RemoteServiceObfuscateTypeNames.gwt.xml
                     |   28     28 +    0 -     0 !
 user/src/com/google/gwt/user/client/rpc/impl/AbstractSerializationStream.java
             |   16     15 +    1 -     0 !
 
user/src/com/google/gwt/user/client/rpc/impl/AbstractSerializationStreamWriter.java
       |    3   2 +     1 -     0 !
 
user/src/com/google/gwt/user/client/rpc/impl/ClientSerializationStreamWriter.java
         |   84         39 +    45 -    0 !
 user/src/com/google/gwt/user/client/rpc/impl/Serializer.java
                     |    4     2 +     2 -     0 !
 user/src/com/google/gwt/user/client/rpc/impl/SerializerBase.java
                     |  156     156 +   0 -     0 !
 user/src/com/google/gwt/user/rebind/rpc/ProxyCreator.java
                     |   83     70 +    13 -    0 !
 user/src/com/google/gwt/user/rebind/rpc/TypeSerializerCreator.java
                     |  314     116 +   198 -   0 !
 user/src/com/google/gwt/user/server/rpc/RPC.java
                     |  137     98 +    39 -    0 !
 user/src/com/google/gwt/user/server/rpc/RPCRequest.java
                     |   12     11 +    1 -     0 !
 user/src/com/google/gwt/user/server/rpc/RemoteServiceServlet.java
                     |    3     2 +     1 -     0 !
 user/src/com/google/gwt/user/server/rpc/SerializationPolicyLoader.java
                    |   23      16 +    7 -     0 !
 user/src/com/google/gwt/user/server/rpc/impl/LegacySerializationPolicy.java
               |  101   48 +    53 -    0 !
 
user/src/com/google/gwt/user/server/rpc/impl/ServerSerializationStreamReader.java
         |   32         23 +    9 -     0 !
 
user/src/com/google/gwt/user/server/rpc/impl/ServerSerializationStreamWriter.java
         |   82         46 +    36 -    0 !
 user/src/com/google/gwt/user/server/rpc/impl/StandardSerializationPolicy.java
             |   51     44 +    7 -     0 !
 user/src/com/google/gwt/user/server/rpc/impl/TypeNameObfuscator.java
                     |   62     62 +    0 -     0 !

Obfuscated type names are an opt-in feature because it requires the
use of the RPC policy file on the server.  Users should turn this on
by inheriting the RemoteServiceObfuscateTypeNames module, rather than
relying on any particulars of the implementation.

The serialization policy file has two additional fields: the wire-name
of the type and the computed signature.  Client-side RPC code that
sets up the method and signature tables now uses wire-names and class
literals instead of type names.  It's easiest to see the change by
running with the -gen option and looking at
Service_TypeSerializer.java

A private interface, TypeNameObfuscator, is added onto the
StandardSerializationPolicy to provide (de)obfuscation of wire-names
to the server-side SerializationStreams.  The client-side code doesn't
need this service, because the obfuscation is baked in.

If a module that was compiled with obfuscated type names is used with
the LegacySerializationPolicy, the user will get an error message at
runtime, because there's no mapping data between obfuscated names and
real type names.  The same applies to developers with their own
implementations of SerializationPolicy that obviously wouldn't
implement the private TypeNameObfuscator interface.




Update tests:
 user/test/com/google/gwt/dev/jjs/test/ClassObjectTest.java
                     |   99     63 +    36 -    0 !
 user/test/com/google/gwt/dev/jjs/test/CompilerTest.java
                     |    5     5 +     0 -     0 !
 user/test/com/google/gwt/dev/jjs/test/CoverageTest.java
                     |    9     7 +     2 -     0 !
 user/test/com/google/gwt/dev/jjs/test/JsoTest.java
                     |   14     10 +    4 -     0 !
 user/test/com/google/gwt/dev/jjs/test/MiscellaneousTest.java
                     |   52     37 +    15 -    0 !
 user/test/com/google/gwt/i18n/client/I18NTest.java
                     |    6     3 +     3 -     0 !
 user/test/com/google/gwt/user/RPCSuite.java
                     |   32     26 +    6 -     0 !
 user/test/com/google/gwt/user/RPCSuiteWithObfuscation.gwt.xml
                     |   18     18 +    0 -     0 !
 
user/test/com/google/gwt/user/client/rpc/CollectionsTestWithTypeObfuscation.java
          |   26        26 +    0 -     0 !
 
user/test/com/google/gwt/user/client/rpc/CustomFieldSerializerTestWithTypeObfuscation.java
|   26  26 +    0 -     0 !
 user/test/com/google/gwt/user/client/rpc/EnumsTestWithTypeObfuscation.java
                |   26  26 +    0 -     0 !
 
user/test/com/google/gwt/user/client/rpc/InheritanceTestWithTypeObfuscation.java
          |   26        26 +    0 -     0 !
 user/test/com/google/gwt/user/client/rpc/ObjectGraphTest.java
                     |   26     24 +    2 -     0 !
 
user/test/com/google/gwt/user/client/rpc/ObjectGraphTestWithTypeObfuscation.java
          |   31        31 +    0 -     0 !
 user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTest.java
                    |    8      4 +     4 -     0 !
 
user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTestWithTypeObfuscation.java
 |   27         27 +    0 -     0 !
 
user/test/com/google/gwt/user/client/rpc/UnicodeEscapingTestWithTypeObfuscation.java
      |   26    26 +    0 -     0 !
 user/test/com/google/gwt/user/client/rpc/ValueTypesTest.java
                     |    1     1 +     0 -     0 !
 user/test/com/google/gwt/user/client/rpc/ValueTypesTestWithTypeObfuscation.java
           |   27       27 +    0 -     0 !
 user/test/com/google/gwt/user/server/rpc/RPCRequestTest.java
                     |    4     2 +     2 -     0 !
 user/test/com/google/gwt/user/server/rpc/RPCTest.java
                     |  139     119 +   20 -    0 !
 user/test/com/google/gwt/user/server/rpc/SerializationPolicyLoaderTest.java
               |   21   19 +    2 -     0 !
 
user/test/com/google/gwt/user/server/rpc/impl/StandardSerializationPolicyTest.java
        |   10  8 +     2 -     0 !

Runs RPC with and without type-name obfuscation.
Change tests to be sensitive to -XdisableClassMetadata flag.



Total:
 64 files changed, 1907 insertions(+), 600 deletions(-)

-- 
Bob Vawter
Google Web Toolkit Team

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to