|
107 | 107 | import org.jruby.runtime.Constants; |
108 | 108 | import org.jruby.runtime.Helpers; |
109 | 109 | import org.jruby.runtime.IRBlockBody; |
| 110 | +import org.jruby.runtime.JavaSites; |
110 | 111 | import org.jruby.runtime.MethodFactory; |
111 | 112 | import org.jruby.runtime.MethodIndex; |
112 | 113 | import org.jruby.runtime.ObjectAllocator; |
|
118 | 119 | import org.jruby.runtime.builtin.IRubyObject; |
119 | 120 | import org.jruby.runtime.builtin.Variable; |
120 | 121 | import org.jruby.runtime.callsite.CacheEntry; |
| 122 | +import org.jruby.runtime.callsite.CachingCallSite; |
121 | 123 | import org.jruby.runtime.load.LoadService; |
122 | 124 | import org.jruby.runtime.marshal.MarshalDumper; |
123 | 125 | import org.jruby.runtime.marshal.MarshalLoader; |
@@ -3199,7 +3201,22 @@ public boolean hasModuleInHierarchy(RubyModule type) { |
3199 | 3201 |
|
3200 | 3202 | @Override |
3201 | 3203 | public int hashCode() { |
3202 | | - return id; |
| 3204 | + RubyClass metaClass = this.metaClass; |
| 3205 | + |
| 3206 | + // may be null during boot |
| 3207 | + if (metaClass == null) return id; |
| 3208 | + |
| 3209 | + Ruby runtime = metaClass.getClassRuntime(); |
| 3210 | + |
| 3211 | + if (runtime.isBooting()) return id; |
| 3212 | + |
| 3213 | + ThreadContext context = runtime.getCurrentContext(); |
| 3214 | + CachingCallSite hash = sites(context).hash; |
| 3215 | + |
| 3216 | + if (hash.isBuiltin(this)) return id; |
| 3217 | + |
| 3218 | + // we truncate for Java hashcode |
| 3219 | + return (int) hash.call(context, this, this).convertToInteger().getLongValue(); |
3203 | 3220 | } |
3204 | 3221 |
|
3205 | 3222 | @JRubyMethod(name = "hash") |
@@ -6985,6 +7002,10 @@ private class RefinementStore { |
6985 | 7002 | .from(boolean.class, ThreadContext.class, IRubyObject.class, int.class) |
6986 | 7003 | .invokeStaticQuiet(LOOKUP, RubyModule.class, "testModuleMatch"); |
6987 | 7004 |
|
| 7005 | + public static JavaSites.ModuleSites sites(ThreadContext context) { |
| 7006 | + return context.sites.Module; |
| 7007 | + } |
| 7008 | + |
6988 | 7009 | @Deprecated |
6989 | 7010 | public IRubyObject const_get(IRubyObject symbol) { |
6990 | 7011 | return const_get(getCurrentContext(), symbol); |
|
0 commit comments