Skip to content

[build] make generated .class files deterministic#7784

Merged
kares merged 2 commits intojruby:jruby-9.3from
kares:deterministic-generated-class
May 25, 2023
Merged

[build] make generated .class files deterministic#7784
kares merged 2 commits intojruby:jruby-9.3from
kares:deterministic-generated-class

Conversation

@kares
Copy link
Member

@kares kares commented May 7, 2023

This PR contains 2 commits which should make the generated .class files more deterministic.

Essentially the problem is Class#getDeclaredMethods returns an undefined order, so even when a simple patch is applied to a stable version one ends up with a ton of .class files (mostly the "INVOKER" ones) modified in the resulting artifact (jruby-base.jar).


sample diff after re-compiling and decompiling org/jruby/RubyArray\$INVOKER\$i\$all_p.class using javap (nothing was changed against stable 9.3.10.0 the difference is likely just a different Java or OS version):

16,17c16,17
<   public org.jruby.runtime.builtin.IRubyObject call(org.jruby.runtime.ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.RubyModule, java.lang.String, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.Block);
<     descriptor: (Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/RubyModule;Ljava/lang/String;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/Block;)Lorg/jruby/runtime/builtin/IRubyObject;
---
>   public org.jruby.runtime.builtin.IRubyObject call(org.jruby.runtime.ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.RubyModule, java.lang.String, org.jruby.runtime.Block);
>     descriptor: (Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/RubyModule;Ljava/lang/String;Lorg/jruby/runtime/Block;)Lorg/jruby/runtime/builtin/IRubyObject;
23,25c23,24
<        7: aload         6
<        9: invokevirtual #28                 // Method org/jruby/RubyArray.all_p:(Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/Block;)Lorg/jruby/runtime/builtin/IRubyObject;
<       12: areturn
---
>        7: invokevirtual #28                 // Method org/jruby/RubyArray.all_p:(Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/Block;)Lorg/jruby/runtime/builtin/IRubyObject;
>       10: areturn
27,28c26,27
<   public org.jruby.runtime.builtin.IRubyObject call(org.jruby.runtime.ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.RubyModule, java.lang.String, org.jruby.runtime.Block);
<     descriptor: (Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/RubyModule;Ljava/lang/String;Lorg/jruby/runtime/Block;)Lorg/jruby/runtime/builtin/IRubyObject;
---
>   public org.jruby.runtime.builtin.IRubyObject call(org.jruby.runtime.ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.RubyModule, java.lang.String, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.Block);
>     descriptor: (Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/RubyModule;Ljava/lang/String;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/Block;)Lorg/jruby/runtime/builtin/IRubyObject;
34,35c33,35
<        7: invokevirtual #32                 // Method org/jruby/RubyArray.all_p:(Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/Block;)Lorg/jruby/runtime/builtin/IRubyObject;
<       10: areturn
---
>        7: aload         6
>        9: invokevirtual #32                 // Method org/jruby/RubyArray.all_p:(Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/Block;)Lorg/jruby/runtime/builtin/IRubyObject;
>       12: areturn

NOTE: all of the code touched here should only be used during compilation - thus "if compiles" should be fairly low risk.

@kares kares added this to the JRuby 9.3.11.0 milestone May 7, 2023
@kares kares merged commit 197c161 into jruby:jruby-9.3 May 25, 2023
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