[ji] lazy loading of Java (proxy) class extensions #5161
Conversation
No prob, will review. Have you managed to measure anything yet? |
quick test of
... gets us around 5% on my machine |
} | ||
|
||
@JRubyModule(name = "Java::JavaLang::Iterable", include = "Enumerable") | ||
public static class Iterable { | ||
|
||
static RubyModule define(final Ruby runtime) { | ||
final RubyModule Iterable = Java.getProxyClass(runtime, java.lang.Iterable.class); | ||
static RubyModule define(final Ruby runtime, final RubyModule Iterable) { |
headius
May 14, 2018
Member
Could we use a different name for these? I find it extremely confusing when I look at the code and I see "Iterable" meaning two different things.
Could we use a different name for these? I find it extremely confusing when I look at the code and I see "Iterable" meaning two different things.
headius
May 14, 2018
Member
Note that at this point in the code, Iterable now means three different things: the inner class, the variable, and (to me at a glance) the actual Java Iterable class. It's quite confusing.
Note that at this point in the code, Iterable now means three different things: the inner class, the variable, and (to me at a glance) the actual Java Iterable class. It's quite confusing.
headius
May 14, 2018
Member
Same comment applies to all other such names below. I understand that it might look a bit nicer to some, but this flies against typical Java local variable naming convention.
It's somewhat confusing that the extension classes have the same names as the Java class they extend, but that seems like less of an issue to me than the local variables having yet again the same name.
Same comment applies to all other such names below. I understand that it might look a bit nicer to some, but this flies against typical Java local variable naming convention.
It's somewhat confusing that the extension classes have the same names as the Java class they extend, but that seems like less of an issue to me than the local variables having yet again the same name.
kares
May 15, 2018
Author
Member
okay, will take a look into that
okay, will take a look into that
|
||
private static final boolean IMMEDIATE = false; | ||
|
||
private static final JavaExtensions INSTANCE = new JavaExtensions(); |
headius
May 14, 2018
Member
This should not be static; a better place would be for it to live on the javasupport Java instance attached to the runtime.
It is weak on the value, but it also anchors a class as its key. The classes we currently extend are system-level classes, but this may be used in the future for classes loaded as part of JRuby or within extensions (e.g. jruby-openssl) that load into their own classloaders, and this reference will prevent them from being collected.
It also is not compatible with multiple JRuby instances in the same JVM, since only the first one will register (and eventually apply) an extension. The others will race to insert the extension or remove it when applying that extension.
This should not be static; a better place would be for it to live on the javasupport Java instance attached to the runtime.
It is weak on the value, but it also anchors a class as its key. The classes we currently extend are system-level classes, but this may be used in the future for classes loaded as part of JRuby or within extensions (e.g. jruby-openssl) that load into their own classloaders, and this reference will prevent them from being collected.
It also is not compatible with multiple JRuby instances in the same JVM, since only the first one will register (and eventually apply) an extension. The others will race to insert the extension or remove it when applying that extension.
headius
May 14, 2018
Member
Oh somehow my review used an older version that was still static. I see you have fixed that, thanks!
Oh somehow my review used an older version that was still static. I see you have fixed that, thanks!
exactly - its plugged in right around proxy-class initialization which is already race condition tuned (some tests are in place) |
assert previous == null; | ||
} | ||
|
||
public static void define(final Class javaClass, final RubyModule proxyClass) { |
enebo
May 18, 2018
Member
Seems like runtime could be a parameter here to match put().
Seems like runtime could be a parameter here to match put().
enebo
May 18, 2018
Member
It also seems to line up more with Iterable stuff below which also have runtime.
It also seems to line up more with Iterable stuff below which also have runtime.
Seems reasonable to me. I guess only fear is proxy class initialization concurrency, but that has not actually changed at all in this PR so seems fine. |
also ... we could safely add more extensions now and do not have to worry much about bloating load times
did not run any numbers yet, but hopefully we do not do much JI internally on
gem list
,rake
etc