Skip to content
Browse files

teach RuntimeCache about invalidator per constant name

  • Loading branch information...
1 parent 5155146 commit 64e7635de18e1b593b0fc8cef3be811e09e42a95 @charliesome committed
Showing with 9 additions and 3 deletions.
  1. +9 −3 src/org/jruby/ast/executable/RuntimeCache.java
View
12 src/org/jruby/ast/executable/RuntimeCache.java
@@ -25,6 +25,7 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.callsite.CacheEntry;
+import org.jruby.runtime.opto.Invalidator;
import org.jruby.util.ByteList;
import org.jruby.util.DefinedMessage;
import org.jruby.util.RegexpOptions;
@@ -375,6 +376,7 @@ public final void initConstants(int size) {
constants = new IRubyObject[size];
constantTargetHashes = new int[size];
constantGenerations = new Object[size];
+ constantInvalidators = new Invalidator[size];
Arrays.fill(constantGenerations, -1);
Arrays.fill(constantTargetHashes, -1);
}
@@ -411,13 +413,15 @@ public IRubyObject getValue(ThreadContext context, StaticScope scope, String nam
}
private boolean isCached(ThreadContext context, IRubyObject value, int index) {
- return value != null && constantGenerations[index] == context.runtime.getConstantInvalidator().getData();
+ return value != null && constantGenerations[index] == constantInvalidators[index].getData();
}
public IRubyObject reCache(ThreadContext context, StaticScope scope, String name, int index) {
- Object newGeneration = context.runtime.getConstantInvalidator(name).getData();
+ Invalidator invalidator = context.runtime.getConstantInvalidator(name);
+ Object newGeneration = invalidator.getData();
IRubyObject value = scope.getConstant(name);
constants[index] = value;
+ constantInvalidators[index] = invalidator;
if (value != null) {
constantGenerations[index] = newGeneration;
}
@@ -436,7 +440,7 @@ public IRubyObject getValueFrom(RubyModule target, ThreadContext context, String
}
private boolean isCachedFrom(RubyModule target, ThreadContext context, IRubyObject value, int index) {
- return value != null && constantGenerations[index] == context.runtime.getConstantInvalidator().getData() && constantTargetHashes[index] == target.hashCode();
+ return value != null && constantGenerations[index] == constantInvalidators[index].getData() && constantTargetHashes[index] == target.hashCode();
}
public IRubyObject reCacheFrom(RubyModule target, ThreadContext context, String name, int index) {
@@ -446,6 +450,7 @@ public IRubyObject reCacheFrom(RubyModule target, ThreadContext context, String
if (value != null) {
constantGenerations[index] = newGeneration;
constantTargetHashes[index] = target.hashCode();
+ constantInvalidators[index] = context.runtime.getConstantInvalidator(name);
}
return value;
}
@@ -673,4 +678,5 @@ private CacheEntry getCacheEntry(int index) {
private static final Object[] EMPTY_OBJS = {};
public Object[] constantGenerations = EMPTY_OBJS;
public int[] constantTargetHashes = EMPTY_INTS;
+ public Invalidator[] constantInvalidators = {};
}

0 comments on commit 64e7635

Please sign in to comment.
Something went wrong with that request. Please try again.