Skip to content

Reduce overhead of binding Java classes and methods#5832

Merged
headius merged 12 commits intojruby:masterfrom
headius:java_binding_optz
Sep 16, 2019
Merged

Reduce overhead of binding Java classes and methods#5832
headius merged 12 commits intojruby:masterfrom
headius:java_binding_optz

Conversation

@headius
Copy link
Member

@headius headius commented Aug 13, 2019

This is a work-in-progress to reduce the overhead of our initial setup and binding of Ruby proxy classes for Java classes.

There's a number of places in this binding logic where we re-scan or re-partition methods, as well as creating a large number of transient data objects that are thrown away once the class is bound. I will be trying to find a way to pipeline more of this process to avoid the intermediate state objects.

This reduces the amount of method scanning needed to boot up a
given class. The filtered ClassValues filter out methods that will
not be accessible, and then goes on to separate out the static
methods.
@headius headius force-pushed the java_binding_optz branch from 31ece51 to 6b45d64 Compare August 13, 2019 20:41
headius added 10 commits August 13, 2019 16:08
For classes which have no static methods to bind, this was
creating a map unnecessarily. There will never be classes that
have no instance methods (since they all eventually descend from
object) but the consistency seems better here.
For Map iteration, this avoids creating intermediate Set and
Iterator objects, plus all the transient Map.Entry objects. For
List iteration, this eliminates the Iterator. Both cases may
require allocating the lambda object and introduce boot-time
overhead to instantiate the lambda class, but overall this patch
should reduce allocation along these paths.
This may not improve load times since we only do this once for
each bound class, rather than doing it for classes in that bound
class's hierarchy.
Note it's not really lazy yet because RubyToJavaInvoker calls
initialize immediately and most upstream logic eagerly prepares
the payload.

This commit also removes the intermedate installer for
constructors.
* Avoid repeated security exceptions by caching empty method lists
* Localize more method-gathering state and logic into
  MethodGatherer class
* Clean up some visibility and organization.
@headius headius added this to the JRuby 9.2.9.0 milestone Aug 21, 2019
@headius headius merged commit 7c32098 into jruby:master Sep 16, 2019
@headius headius deleted the java_binding_optz branch September 16, 2019 19:45
headius added a commit to headius/jruby that referenced this pull request Nov 26, 2019
* Private classes were considered for method binding even though
  we no longer set them accessible on Java 9+ when they have not
  already been opened. This resulted in Java 9+ environments
  producing method errors when they attempted to dispatch to those
  methods on private classes.
* In order to fix the above for private classes with public
  interfaces, this patch also fixes how we traverse a class's
  implemented interfaces. Possibly from changes in jruby#5832, we were
  not walking an interface's superinterfaces, causing us to only
  walk one level in such cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant