Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.jruby.management.InlineStats;
import org.jruby.parser.ParserManager;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Builtins;
import org.jruby.runtime.JavaSites;
import org.jruby.runtime.TraceEventManager;
import org.jruby.runtime.backtrace.RubyStackTraceElement;
Expand Down Expand Up @@ -4801,6 +4802,30 @@ void addProfiledMethod(final String id, final DynamicMethod method) {
getProfilingService().addProfiledMethod(id, method);
}

/**
* Get the builtin bits array for fast-path checks.
* This array is shared across all ThreadContexts in this runtime.
*
* @return the builtin bits array
*/
public short[] getBuiltinBits() {
return builtinBits;
}

/**
* Called when a method is defined on a class that might invalidate
* builtin optimizations.
*
* @param module the module/class where the method was defined
* @param method the method name
*/
void invalidateBuiltin(RubyModule module, String method) {
// Don't invalidate during initial core boot (we're defining builtins!)
if (!isBootingCore()) {
Builtins.invalidateBuiltin(builtinBits, module.getClassIndex(), method);
}
}

/**
* Increment the count of exceptions generated by code in this runtime.
*/
Expand Down Expand Up @@ -5180,6 +5205,9 @@ public interface RecursiveFunctionEx<T> extends ThreadContext.RecursiveFunctionE
private final Invalidator checkpointInvalidator;
private ThreadService threadService;

/** Bit flags tracking which builtin methods have been redefined (thread-local builtin tracking system) */
private final short[] builtinBits = Builtins.allocate();

private final POSIX posix;
private POSIX nativePosix;

Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/RubyFixnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,12 @@ private static RubyInteger negate(ThreadContext context, final long value) {
*/
@Override
public IRubyObject op_plus(ThreadContext context, IRubyObject other) {
// TODO: Add builtin check for production use:
// if (!Builtins.checkIntegerPlus(context)) {
// return RuntimeHelpers.invokeSuper(context, this, other, Block.NULL_BLOCK);
// }
// This provides 5x faster method dispatch when Integer#+ is not redefined.

if (other instanceof RubyFixnum fixnum) {
return op_plus(context, fixnum.value);
}
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ public DynamicMethod putMethod(ThreadContext context, String id, DynamicMethod m
}

context.runtime.addProfiledMethod(id, method);
context.runtime.invalidateBuiltin(methodLocation, id);
return method;
}

Expand Down
Loading
Loading