Skip to content

Tie become_java! and concrete extension (fixes #4165)#6141

Merged
headius merged 21 commits intojruby:masterfrom
byteit101:concrete_java
Sep 9, 2020
Merged

Tie become_java! and concrete extension (fixes #4165)#6141
headius merged 21 commits intojruby:masterfrom
byteit101:concrete_java

Conversation

@byteit101
Copy link
Member

@byteit101 byteit101 commented Mar 26, 2020

Still in progress, but allow concrete class extension to define non-extended fields and signatures (required for jrubyfx to use the built in FXMLLoader that uses reflection on passed in classes)

Notable questions:

  • ClassJavaAddons: how to check for java proxies vs failed reification
  • Is adding two arguments everywhere the best way to send them down to the asm layer?
  • MethodData generalization: are the LocalMethodData constants reasonable?
  • MethodData.getDeclaringClass ???

@headius
Copy link
Member

headius commented Mar 27, 2020

Putting this on my todo list to review... perhaps early next week? Maybe you have some thoughts @kares?

@headius headius requested review from enebo, headius and kares March 27, 2020 20:32
@headius headius added this to the JRuby 9.3.0.0 milestone Mar 27, 2020
@byteit101
Copy link
Member Author

While investigating annotations, it appears that jrubyc and become_java! have different syntaxes:

java_annotation 'Deprecated'
java_signature 'void my_method()'

vs

java_signature '@Deprecated void my_method()'

jrubyc uses at least the former and become_java! only saves the latter. As such, I've implemented parameters for the latter, but that brings up what to do with fields. Should java_field support annotation parsing or should java_annotation be used instead, and probably expanded for methods too?

@byteit101
Copy link
Member Author

As per conversation on matrix with @enebo, This PR now has the following API changes:
java_annotation is deprecated and warns on useless calls. https://github.com/jruby/jruby/wiki/JRuby-Reference#java_annotation should be updated
java_signature now supports annotations that have parameters (previously only supported unnamed parameters)
java_field now supports annotations (previously didn't support annotations)

end

def java_annotation(anno)
STDERR.puts "java_annotation is deprecated. Use java_signature '@#{anno} ...' instead. Called from: #{caller.first}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: we probably just want to use warn or some kind of warnings on the native end.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah use Kernel#warn or Warnings#warn so it can be silenced if necessary.

@kares
Copy link
Member

kares commented Apr 11, 2020

Great work so far Patrick!

Think it makes sense to have as its going, I did like the previous java_annotation 'Deprecated' wout the @ prefix but for java_field etc it's more reasonable to have Java-like syntax @Deprecated ....

Not sure if current scope imports are respected (or whether they worked using java_annotation) but it would be nice to not have to always use fully-qualified Java class names in annotations.

Copy link
Member

@headius headius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small changes. I will address your original questions in a separate comment.

* Copyright (C) 2002 Jan Arne Petersen <jpetersen@uni-bonn.de>
* Copyright (C) 2002-2004 Anders Bengtsson <ndrsbngtssn@yahoo.se>
* Copyright (C) 2004 Thomas E Enebo <enebo@acm.org>
* Copyright (C) 2004 Stefan Matthias Aust <sma@3plus4.de>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove attributions unrelated to this file. If you really want to add yourself, go ahead, but since the audit trail is in git I don't believe we need to have these.

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix license header

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix license header


/**
*
* @author enebo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Author @enebo?


}
else
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style issues here and other places... close brace and open brace should be on same line as else, if's open brace should be on same line, etc.

end

def java_annotation(anno)
STDERR.puts "java_annotation is deprecated. Use java_signature '@#{anno} ...' instead. Called from: #{caller.first}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah use Kernel#warn or Warnings#warn so it can be silenced if necessary.

@headius
Copy link
Member

headius commented Sep 1, 2020

Addressing the original 4 question bullets:

  • ClassJavaAddons: how to check for java proxies vs failed reification

I'm not sure exactly what you mean. What you have seems fine to me, maybe?

  • Is adding two arguments everywhere the best way to send them down to the asm layer?

Usually if I feel like I'm passing around the same arguments too many places, it might be time for a data object that contains all of them together. It's not a huge deal either way for this PR, but perhaps we can refactor this to be more OO and not have to pass so many params all over.

  • MethodData generalization: are the LocalMethodData constants reasonable?

I think these are fine as-is.

  • MethodData.getDeclaringClass ???

If this is no longer being used then it's fine to remove.

}
if (reifiedClass == null) {
throw context.runtime.newTypeError("requested class " + klass.getName() + " was not reifiable");
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@headius This bit of code does not distinguish between Failed Reified Ruby classes and Concretized Classes. getReified is null if either it's a failure to reify or a java proxy class. Should the logic be split between those two cases, and if so, how?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, so you think maybe we need another way to know a given class is a java proxy class. Perhaps we add another boolean flag to RubyClass like isJavaSubclass or isJavaProxy?

Copy link
Member Author

@byteit101 byteit101 Sep 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so you think maybe we need...

No, I am asking if we do. I have no strong opinion on these internals, but I do think the error message could be a misleading if we care to tell users about the difference between concrete vs reified, so I'm wondering if you think we should disambiguate.
Secondarily, I think it's safe for this code path to be retried for failed reified and failed concrete multiple times, but that might have implications I'm not aware of

@byteit101
Copy link
Member Author

Usually if I feel like I'm passing around the same arguments too many places, it might be time for a data object that contains all of them together. It's not a huge deal either way for this PR, but perhaps we can refactor this to be more OO and not have to pass so many params all over.

The reason I hesitated was because all of the items came from the ruby class, and so the obvious thing was to just pass the ruby class down, but I wasn't sure if that would break existing encapsulation design too much. Creating a small mirror of RubyClass things also seemed kind of silly if we could just use RubyClass

@headius
Copy link
Member

headius commented Sep 3, 2020

I am fine merging this once review comments are addressed and CI is green. Thank you for your help and patience @byteit101!

@byteit101 byteit101 changed the title WIP: tie become_java! and concrete extension (fixes #4165) Tie become_java! and concrete extension (fixes #4165) Sep 3, 2020
@headius
Copy link
Member

headius commented Sep 3, 2020

This might help the failures (annotation API is no longer part of JDK):

https://gist.github.com/headius/cde16ee9fe14767549ed0036ec0a04dc

@headius headius merged commit 763be8b into jruby:master Sep 9, 2020
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.

3 participants