Comment #5 on issue 342 by sberlin: Disable Just-in-time bindings
http://code.google.com/p/google-guice/issues/detail?id=342
Took a stab at this this weekend (because having it enables some nice
optimizations
for child injectors not having to lookup bindings in parent injectors)..
Works
pretty much as expected. Only downside is it adds a new ugly boolean
parameter to a
bunch of methods in order for everything to work. The basic idea is
there's a new
Guice.createInjectorBuilder & Injector.createChildInjectorBuilder method
that exposes
some methods including a new disableJit method. That passes it off to the
InjectorShell.Builder which constructs the InjectorImpl with the jitDisabled
parameter. There's a new JitBindingsTest to make sure things work. Things
that
changed to support jitDisabled:
- InternalFactory.get has a new 'linked' method. True if you're getting
as a result
of a linked binding. This is necessary so that implicit jit bindings still
work
[bind(Interface.class).to(Impl.class) -- Impl is an implicit JIT binding]
FactoryProxy (linked bindings) & BoundProviderFactory (linked provider
bindings) both
pass true. Other callers pass false or pass on the parameter from their
caller.
- InjectorImpl.getJustInTimeBinding & getBindingOrThrow has a
new 'allowJit'
parameter which will let it fail if JIT bindings aren't allowed from the
caller and
JIT is disabled. InjectorImpl.createUnitializedBinding has a
new 'jitBinding'
parameter, so that a ConstructorBindingImpl knows if it's created by a JIT
binding,
to let its InternalFactory fail if it was constructed through a JIT binding
& JIT was
disabled.
- ConstructorBindingImpl.create & Factory take a new 'failIfNotLinked'
parameter
(the Factory takes a few more, to create a good looking error message) so
that an
implicit JIT binding will refuse to create itself if it wasn't retrieved
through a
linked binding.
To apply the patch, first copy InjectorBuilder to InjectorBuilderImpl, then
apply the
patch. (The patch will delete internal.InjectorBuilder, add an interface
in the
parent package, and tweak some parts of InjectorBuilderImpl. I couldn't
figure out
how to tell svn diff to include renaming... am more of a CVS user.)
I tested the patch out on LimeWire's codebase & we had ~100 JIT bindings
that failed,
as expected. Would be great to fix this, turn JIT off, and let child
injectors be a
little better about not creating JIT bindings in the parent.
Attachments:
changes.txt 50.7 KB
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-guice-dev?hl=en
-~----------~----~----~----~------~----~------~--~---