Gin in hosted mode

5 views
Skip to first unread message

Дмитрий Николаев

unread,
Jul 17, 2009, 2:42:34 AM7/17/09
to google-gin
Hi!
Seems when I use GIN I must often restart hosted browser at all
(shutdown - start).
Refreshing page and erstarting server by button won't help.
(Provisioning errors sometimes happend)

Alen Vrecko

unread,
Jul 17, 2009, 8:09:40 AM7/17/09
to google-gin
GIN uses gwt generator to create an implementation of the Ginjector.
But afaik generators are only run once per hosted mode. Therefore if
you change any code that is related to GWT.create(...) and refresh you
will get errors.

Cheers
Alen

Alen Vrecko

unread,
Jul 17, 2009, 5:14:35 PM7/17/09
to google-gin
My post is incorrect. Generators are indeed rerun in a refresh. I
confused it with changing the actual generator code. I remember
refresh didn't work when I was writing the generator. But that is
another story. Anyway in GIN case maybe there is some caching
involved.

Cheers
Alen

Alen Vrecko

unread,
Jul 17, 2009, 5:51:44 PM7/17/09
to google-gin
Hm. If you change your bindings in a module the gin generator is still
using the old bindings instead of making a new instance of the changed
class. At previous post I should have said when I was writing some
generator not the generator. Never mind.

Alen Vrecko

unread,
Jul 20, 2009, 3:16:16 AM7/20/09
to google-gin
Sorry for the spam. Thought I add this for completeness. I find it
interesting. Correct me if I am wrong.

The real reason why refresh button doesn't work 100% with GIN is
basically class loading issue. When you start hosted mode gin classes
and your classes (that use gin) get loaded. Nothing spectacular here.
The point is in how hosted mode loads your gwt client code. For the
client code it uses a special ClassLoader. When you press refresh the
sources are transformed into bytecode but end up at HostedMode's
special ClassLoader. On the other hand the generator instance is
loaded in the ClassLoader that loaded the HostedMode and thus only
sees your original class files. Normally this isn't an issue since
generators work with TypeOracle/JClassType which are up to date to
refreshed code. But GIN is doing stuff on the classes itself i.e.
instantiating an instance of a GinModule etc. Therefore it doesn't see
the latest code.

For fun I've managed to convince Gin to use classes from my own
ClassLoader. The custom loader then hacks into gwt's latest class
definitions(byte[]) and Gin can then see the latest module code. It is
working but it feels just wrong;)

Cheers
Alen

Brian Stoler

unread,
Jul 20, 2009, 8:36:58 AM7/20/09
to googl...@googlegroups.com
Hi Alen,

That seems plausible. I don't know a lot about how GWT hosted mode classloading works, but that would certainly explain things. So that essentially means that a generator that acts reflectively over parts of the client source won't see changes in the client source?

Could you try reporting this (with any patch you have) to the GWT mailing list? Would be great to get a proper fix there.

Thanks,
-brian

2009/7/20 Alen Vrecko <alen_...@yahoo.com>

Alen Vrecko

unread,
Jul 20, 2009, 2:41:43 PM7/20/09
to google-gin
Hi, Brian.

> So that
> essentially means that a generator that acts reflectively over parts of the
> client source won't see changes in the client source?

Yes. To put it in more concrete words. The client code is loaded in
CompilingClassLoader. For example you cannot do
Foo.class.getClassLoader() in client code for obvious reasons. But if
you are debugging hosted mode and inspect the Foo class with the
debugger you can see that the class loader is of type
CompilingClassLoader.

On the other hand if you debug the generator code and inspect the same
Foo class (technically it really isn't the same class since Class is
also determined by the ClassLoader not just byte[] ;) ) you will see
it is loaded by some derivate of the System ClassLoader usually
sun.misc.Launcher..some inner class. What matters is that it is not
the same ClassLoader (:

> Could you try reporting this (with any patch you have) to the GWT mailing
> list? Would be great to get a proper fix there.

Sure. Gladly. I have a very long day behind me so will write to gwt
mailing list tomorrow.

Agreed. We have a perfectly valid use case here to use reflection. It
should just work.

As far as my solution goes it is more of a proof of concepts. I
thought about patching gwt itself but it was easier for me to just to
modify gin. I am a big fan of TDD and stuff like Mockito but the code
I wrote is just for seeing how things works and not some production
code. Will post it later on gwt mailing list.

On the other hand I have tons of free time on my hands. I just might
write a proper gwt fix for this (no promises) - I am thinking in the
lines of loading the generators in the CompilingClassLoader or
something similar...

Btw: Thank you guys for your work on GIN. For me it is a must have if
I am writing gwt code:) A pleasure to work with.

Cheers
Alen

>
> Thanks,
> -brian
>
> 2009/7/20 Alen Vrecko <alen_vre...@yahoo.com>
Reply all
Reply to author
Forward
0 new messages