On Mon, Mar 14, 2011 at 3:03 PM, Grzegorz Kossakowski <
[email protected]> wrote:

> 1. What's the difference between TypeMap and TypeOracle and why they
> seem to have overlapping functionality?
>

In GWT, there are two major pieces of infrastructure that deal with
representing Java language input.

1) A reflection of the user's type model for the purposes of running
generators.  Approximately equivalent to the kind of information you can get
via Java reflection.  Models types, fields, and methods, but not method
bodies.  The entire machinery around this can be loosely referred to as
"TypeOracle", which is the primary interface for accessing this type model.
 Generators use this type model to generate code.  This infrastructure is
used in both dev mode and web mode, as Generators run in both contexts.

2) The GWT AST, which is essentially a source-level representation of the
user's Java code, including method bodies, which is optimized and translated
into JavaScript.  May be referred to as GWTC, the compiler, the web-mode
compiler, etc.  Mostly lives in com.google.gwt.dev.jjs (which stands for
'Java to JavaScript').  TypeMap is a small implementation detail that's only
useful for the JDT AST -> GWT AST translation.


> 2. Why TypeOracleMediator operates on bytecode whereas gwtc is
> supposed to work with java source, or jdt's asts?
>

Historically, we've run JDT twice.  Once to build TypeOracle, and once to
build the GWT AST.  Efforts have been made to transition TypeOracle to be
built from bytecode, which would eliminate one of these JDT runs in favor of
using external (presumably IDE-built) class files.


> 3. How emulation of object orientation is implemented in gwt?
>

Using JavaScript prototype chains, and mangling method signatures such that
any given override of a method has a globally unique name in the compiled
output.  Try compiling with -style PRETTY or DETAILED and inspect the
output.


> 4. What are main phases in gwtc's execution. What are dependencies?
>

JavaToJavaScriptCompiler .precompile() is what I would consider the main
high-level algorithm.  But here's a text overview.

1) Build TypeOracle from the initial set of available source units
(CompilationStateBuilder).
2) Begin running the web mode compile (WebModeCompilerFrontEnd).
3) As the web mode compile runs, we encounter GWT.create() calls
(FindDeferredBindingSitesVisitor).
4) Use the rebind infrastructure to resolve rebind requests.  This may
entail running Generators, which generate new code.
5) Newly-generated types get added to CompilationState + TypeOracle in a bit
of a loop-back process.
6) Newly-generated types may themselves contain GWT.create() calls, looping
back through step 4.
7) Eventually, all our code is generated.  Get rid of TypeOracle, we don't
need it anymore.
8) GenerateJavaAST turns the JDT AST into the GWT AST.
9) Normalize certain difficult constructs.
10) Optimize.
11) Post-optimization normalizes to turn high-level Java constructs into
JS-specific implementation details (but still Java AST).
12) GenerateJavaScriptAST
13) Optimize JS AST
14) Produce JS source text.


> I'd like to know where TypeMap is being built and why it's done twice.
>

It should only get built once.


> Also, TypeOracle seems to be highly mutable data structure. When it
> gets updated and why?
>

>From the outside, it should be seen as "append only".  Existing state should
be effectively immutable.  It gets updated because Generators produce new
types as the compile proceeds.


> Do you guys have anything (slides, blog posts, discussions, etc.) that
> would help me to better understand those matters?
>

Here's wiki entries for TypeOracle / CompilationState.  The first is
outdated by useful to understand the second one.

http://code.google.com/p/google-web-toolkit/wiki/CompilationUnit_1_5
http://code.google.com/p/google-web-toolkit/wiki/CompilationUnit

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

Reply via email to