Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

switch over some obvious things to use getConstantInvalidator(String)

  • Loading branch information...
commit d3d3329775fd66b7d3b987f33fa3ca76315f3766 1 parent 7ffac36
@charliesome authored
View
4 src/org/jruby/ast/Colon2ConstNode.java
@@ -65,12 +65,12 @@ private boolean isCached(ThreadContext context, RubyModule target, IRubyObject v
// We could probably also detect if LHS value came out of cache and avoid some of this
return
value != null &&
- generation == context.runtime.getConstantInvalidator().getData() &&
+ generation == invalidator(context).getData() &&
hash == target.hashCode();
}
public IRubyObject reCache(ThreadContext context, RubyModule target) {
- Object newGeneration = context.runtime.getConstantInvalidator().getData();
+ Object newGeneration = invalidator(context).getData();
IRubyObject value = target.getConstantFromNoConstMissing(name, false);
cachedValue = value;
View
19 src/org/jruby/ast/Colon3Node.java
@@ -43,6 +43,7 @@
import org.jruby.runtime.Block;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
+import org.jruby.runtime.opto.Invalidator;
import org.jruby.util.ByteList;
import org.jruby.util.DefinedMessage;
@@ -54,6 +55,7 @@
protected String name;
private volatile transient IRubyObject cachedValue;
private volatile Object generation;
+ private Invalidator invalidator;
public Colon3Node(ISourcePosition position, String name) {
super(position);
@@ -86,6 +88,7 @@ public String getName() {
public void setName(String name) {
this.name = name;
+ this.invalidator = null;
}
/** Get parent module/class that this module represents */
@@ -132,12 +135,12 @@ public IRubyObject getValue(ThreadContext context) {
}
private boolean isCached(ThreadContext context, IRubyObject value) {
- return value != null && generation == context.runtime.getConstantInvalidator().getData();
+ return value != null && generation == invalidator(context).getData();
}
public IRubyObject reCache(ThreadContext context, String name) {
Ruby runtime = context.runtime;
- Object newGeneration = runtime.getConstantInvalidator().getData();
+ Object newGeneration = invalidator(context).getData();
IRubyObject value = runtime.getObject().getConstantFromNoConstMissing(name, false);
cachedValue = value;
@@ -146,4 +149,16 @@ public IRubyObject reCache(ThreadContext context, String name) {
return value;
}
+
+ protected Invalidator invalidator(ThreadContext context) {
+ if (invalidator != null) {
+ return invalidator;
+ }
+ synchronized (this) {
+ if (invalidator == null) {
+ invalidator = context.runtime.getConstantInvalidator(name);
+ }
+ return invalidator;
+ }
+ }
}
View
20 src/org/jruby/ast/ConstNode.java
@@ -41,6 +41,7 @@
import org.jruby.runtime.Block;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
+import org.jruby.runtime.opto.Invalidator;
import org.jruby.util.ByteList;
import org.jruby.util.DefinedMessage;
@@ -51,6 +52,7 @@
private String name;
private volatile transient IRubyObject cachedValue = null;
private Object generation = -1;
+ private Invalidator invalidator;
public ConstNode(ISourcePosition position, String name) {
super(position);
@@ -83,6 +85,7 @@ public String getName() {
public void setName(String name) {
this.name = name;
+ this.invalidator = null;
}
@Override
@@ -106,12 +109,13 @@ public IRubyObject getValue(ThreadContext context) {
}
private boolean isCached(ThreadContext context, IRubyObject value) {
- return value != null && generation == context.runtime.getConstantInvalidator().getData();
+ return value != null && generation == invalidator(context).getData();
}
public IRubyObject reCache(ThreadContext context, String name) {
- Object newGeneration = context.runtime.getConstantInvalidator().getData();
+ Object newGeneration = invalidator(context).getData();
IRubyObject value = context.getCurrentStaticScope().getConstant(name);
+ this.name = name;
cachedValue = value;
@@ -119,4 +123,16 @@ public IRubyObject reCache(ThreadContext context, String name) {
return value;
}
+
+ protected Invalidator invalidator(ThreadContext context) {
+ if (invalidator != null) {
+ return invalidator;
+ }
+ synchronized (this) {
+ if (invalidator == null) {
+ invalidator = context.runtime.getConstantInvalidator(name);
+ }
+ return invalidator;
+ }
+ }
}
View
4 src/org/jruby/ast/executable/RuntimeCache.java
@@ -415,7 +415,7 @@ private boolean isCached(ThreadContext context, IRubyObject value, int index) {
}
public IRubyObject reCache(ThreadContext context, StaticScope scope, String name, int index) {
- Object newGeneration = context.runtime.getConstantInvalidator().getData();
+ Object newGeneration = context.runtime.getConstantInvalidator(name).getData();
IRubyObject value = scope.getConstant(name);
constants[index] = value;
if (value != null) {
@@ -440,7 +440,7 @@ private boolean isCachedFrom(RubyModule target, ThreadContext context, IRubyObje
}
public IRubyObject reCacheFrom(RubyModule target, ThreadContext context, String name, int index) {
- Object newGeneration = context.runtime.getConstantInvalidator().getData();
+ Object newGeneration = context.runtime.getConstantInvalidator(name).getData();
IRubyObject value = target.getConstantFromNoConstMissing(name, false);
constants[index] = value;
if (value != null) {
View
2  src/org/jruby/embed/variable/Argv.java
@@ -132,7 +132,7 @@ public void inject() {
if (rubyModule == null) return;
rubyModule.storeConstant(name, irubyObject);
- receiver.getRuntime().getConstantInvalidator().invalidate();
+ receiver.getRuntime().getConstantInvalidator(name).invalidate();
fromRuby = true;
}
View
2  src/org/jruby/embed/variable/Constant.java
@@ -225,7 +225,7 @@ public void inject() {
} else {
receiver.getMetaClass().storeConstant(name, irubyObject);
}
- receiver.getRuntime().getConstantInvalidator().invalidate();
+ receiver.getRuntime().getConstantInvalidator(name).invalidate();
initialized = true;
}
View
18 src/org/jruby/ir/instructions/InheritanceSearchConstInstr.java
@@ -12,6 +12,7 @@
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
+import org.jruby.runtime.opto.Invalidator;
import java.util.Map;
@@ -30,6 +31,7 @@
private volatile transient Object cachedConstant = null;
private volatile int hash = -1;
private volatile Object generation = -1;
+ private volatile Invalidator invalidator;
public InheritanceSearchConstInstr(Variable result, Operand currentModule, String constName, boolean noPrivateConsts) {
super(Operation.INHERITANCE_SEARCH_CONST);
@@ -76,7 +78,7 @@ private Object cache(Ruby runtime, RubyModule module) {
constant = UndefinedValue.UNDEFINED;
} else {
// recache
- generation = runtime.getConstantInvalidator().getData();
+ generation = runtime.getConstantInvalidator(constName).getData();
hash = module.hashCode();
cachedConstant = constant;
}
@@ -84,7 +86,7 @@ private Object cache(Ruby runtime, RubyModule module) {
}
private boolean isCached(Ruby runtime, RubyModule target, Object value) {
- return value != null && generation == runtime.getConstantInvalidator().getData() && hash == target.hashCode();
+ return value != null && generation == invalidator(runtime).getData() && hash == target.hashCode();
}
@Override
@@ -119,4 +121,16 @@ public String getConstName() {
public boolean isNoPrivateConsts() {
return noPrivateConsts;
}
+
+ private Invalidator invalidator(Ruby runtime) {
+ if (invalidator != null) {
+ return invalidator;
+ }
+ synchronized (this) {
+ if (invalidator == null) {
+ invalidator = runtime.getConstantInvalidator(constName);
+ }
+ return invalidator;
+ }
+ }
}
View
18 src/org/jruby/ir/instructions/LexicalSearchConstInstr.java
@@ -13,6 +13,7 @@
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
+import org.jruby.runtime.opto.Invalidator;
import java.util.Map;
@@ -29,6 +30,7 @@
// Constant caching
private volatile transient Object cachedConstant = null;
private Object generation = -1;
+ private volatile Invalidator invalidator;
public LexicalSearchConstInstr(Variable result, Operand definingScope, String constName) {
super(Operation.LEXICAL_SEARCH_CONST);
@@ -78,14 +80,14 @@ private Object cache(ThreadContext context, DynamicScope currDynScope, IRubyObje
constant = UndefinedValue.UNDEFINED;
} else {
// recache
- generation = runtime.getConstantInvalidator().getData();
+ generation = invalidator(runtime).getData();
cachedConstant = constant;
}
return constant;
}
private boolean isCached(Ruby runtime, Object value) {
- return value != null && generation == runtime.getConstantInvalidator().getData();
+ return value != null && generation == invalidator(runtime).getData();
}
@Override
@@ -101,4 +103,16 @@ public Object interpret(ThreadContext context, DynamicScope currDynScope, IRubyO
public void visit(IRVisitor visitor) {
visitor.LexicalSearchConstInstr(this);
}
+
+ private Invalidator invalidator(Ruby runtime) {
+ if (invalidator != null) {
+ return invalidator;
+ }
+ synchronized (this) {
+ if (invalidator == null) {
+ invalidator = runtime.getConstantInvalidator(constName);
+ }
+ return invalidator;
+ }
+ }
}
View
18 src/org/jruby/ir/instructions/SearchConstInstr.java
@@ -12,6 +12,7 @@
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
+import org.jruby.runtime.opto.Invalidator;
import java.util.Map;
@@ -28,6 +29,7 @@
// Constant caching
private volatile transient Object cachedConstant = null;
private Object generation = -1;
+ private volatile Invalidator invalidator;
public SearchConstInstr(Variable result, String constName, Operand startingScope, boolean noPrivateConsts) {
super(Operation.SEARCH_CONST);
@@ -85,7 +87,7 @@ private Object cache(ThreadContext context, DynamicScope currDynScope, IRubyObje
constant = module.callMethod(context, "const_missing", context.runtime.fastNewSymbol(constName));
} else {
// recache
- generation = runtime.getConstantInvalidator().getData();
+ generation = runtime.getConstantInvalidator(constName).getData();
cachedConstant = constant;
}
@@ -93,7 +95,7 @@ private Object cache(ThreadContext context, DynamicScope currDynScope, IRubyObje
}
private boolean isCached(Ruby runtime, Object value) {
- return value != null && generation == runtime.getConstantInvalidator().getData();
+ return value != null && generation == invalidator(runtime).getData();
}
@Override
@@ -121,4 +123,16 @@ public String getConstName() {
public boolean isNoPrivateConsts() {
return noPrivateConsts;
}
+
+ private Invalidator invalidator(Ruby runtime) {
+ if (invalidator != null) {
+ return invalidator;
+ }
+ synchronized (this) {
+ if (invalidator == null) {
+ invalidator = runtime.getConstantInvalidator(constName);
+ }
+ return invalidator;
+ }
+ }
}
View
4 src/org/jruby/ir/targets/Bootstrap.java
@@ -767,7 +767,7 @@ public static boolean testType(RubyClass original, ThreadContext context, IRubyO
public static IRubyObject searchConst(MutableCallSite site, String constName, ThreadContext context, StaticScope staticScope) throws Throwable {
Ruby runtime = context.runtime;
- SwitchPoint switchPoint = (SwitchPoint)runtime.getConstantInvalidator().getData();
+ SwitchPoint switchPoint = (SwitchPoint)runtime.getConstantInvalidator(constName).getData();
IRubyObject value = staticScope.getConstant(constName);
if (value == null) {
@@ -797,7 +797,7 @@ public static IRubyObject inheritanceSearchConst(MutableCallSite site, String co
throw runtime.newTypeError(cmVal + " is not a type/class");
}
- SwitchPoint switchPoint = (SwitchPoint)runtime.getConstantInvalidator().getData();
+ SwitchPoint switchPoint = (SwitchPoint)runtime.getConstantInvalidator(constName).getData();
IRubyObject value = module.getConstantFromNoConstMissing(constName, false);
if (value == null) {
View
6 src/org/jruby/runtime/invokedynamic/InvokeDynamicSupport.java
@@ -760,7 +760,7 @@ public static void checkpointFallback(MutableCallSite site, ThreadContext contex
public static IRubyObject constantFallback(RubyConstantCallSite site,
AbstractScript script, ThreadContext context, int scopeIndex) {
- SwitchPoint switchPoint = (SwitchPoint)context.runtime.getConstantInvalidator().getData();
+ SwitchPoint switchPoint = (SwitchPoint)context.runtime.getConstantInvalidator(site.name()).getData();
StaticScope scope = script.getScope(scopeIndex);
IRubyObject value = scope.getConstant(site.name());
@@ -789,7 +789,7 @@ public static IRubyObject constantFallback(RubyConstantCallSite site,
public static boolean constantBooleanFallback(RubyConstantCallSite site,
AbstractScript script, ThreadContext context, int scopeIndex) {
- SwitchPoint switchPoint = (SwitchPoint)context.runtime.getConstantInvalidator().getData();
+ SwitchPoint switchPoint = (SwitchPoint)context.runtime.getConstantInvalidator(site.name()).getData();
StaticScope scope = script.getScope(scopeIndex);
IRubyObject value = scope.getConstant(site.name());
@@ -993,4 +993,4 @@ public static MethodHandle findVirtual(Class target, String name, MethodType typ
private static String extractSourceInfo(VariableSite site) {
return " (" + site.file() + ":" + site.line() + ")";
}
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.