Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache proxies of newly constructed Java objects #3581

Merged
merged 3 commits into from
Jan 11, 2016

Conversation

smellsblue
Copy link
Contributor

This fixes #3576

I added a few related specs while I was at it (only the constructor one failed before my changes though).

I noticed the warning at spec/READ_ME_FIRST.txt, but wasn't sure if that applied to the java_integration specs, so if I should have added my spec elsewhere, please let me know.

@headius
Copy link
Member

headius commented Jan 8, 2016

Nice! I'll review tonight.

@kares
Copy link
Member

kares commented Jan 8, 2016

🌲 👍

@kares kares added this to the JRuby 9.0.5.0 milestone Jan 10, 2016
kares added a commit that referenced this pull request Jan 11, 2016
Cache proxies of newly constructed Java objects
@kares kares merged commit 1e2282a into jruby:master Jan 11, 2016
@headius
Copy link
Member

headius commented Jan 15, 2016

Finally getting back to this now.

@headius
Copy link
Member

headius commented Jan 15, 2016

Ok, this isn't quite right. This will unconditionally cache objects coming from all constructor calls whether the proxy cache is on or the class has been set to persistent.

If you look at InstanceMethodInvoker and trace through method.invokeDirect, after a long chain of calls (@kares we need to reduce this) it eventually gets back to Java.getInstance() which checks those flags and decides to cache or not.

@headius
Copy link
Member

headius commented Jan 15, 2016

This might be ok if we modify setAndCacheProxyObject to check those same flags.

@smellsblue
Copy link
Contributor Author

@headius thanks for taking a look! Sorry I didn't look deeply enough into the InstanceMethodInvoker path!

I'll take another pass and see if I can fix these problems, along with some more tests.

@smellsblue
Copy link
Contributor Author

@headius I'm wondering about something like this:

    private void setAndCacheProxyObject(ThreadContext context, JavaProxy proxy, Object object) {
        proxy.setObject(object);

        if (Java.OBJECT_PROXY_CACHE || Java.getProxyClassForObject(context.runtime, object).getCacheProxy()) {
            context.runtime.getJavaSupport().getObjectProxyCache().put(object, proxy);
        }
    }

However, I notice there is a RubyModule clazz parameter to all the call methods... is that already the proxy class I seek? I'll dig in a bit more, but if you know off-hand, that would be a big help :-)

@kares
Copy link
Member

kares commented Jan 16, 2016

right, did not realize. will fix it unless @smellsblue spins up another PR.

@headius
Copy link
Member

headius commented Jan 16, 2016

@smellsblue I believe that clazz is the class on which we're calling new, so you should be able to check for the class proxy directly.

@smellsblue
Copy link
Contributor Author

@kares @headius I just created a new PR to both fix the bug and add some specs around proxy caching: #3602

@headius using the clazz parameter seems to work, so I went with it... if you think there might be a scenario where the clazz isn't the right RubyClass, please let me know, though I may need some guidance on how to check if it is the right RubyClass before fetching it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ConstructorInvoker isn't storing the proxy in the ObjectProxyCache
3 participants