Skip to content

Commit

Permalink
Showing 4 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -60,10 +60,7 @@ public String[] toStringNonOperandArgs() {

private Object cache(Ruby runtime, RubyModule module) {
Object constant = noPrivateConsts ? module.getConstantFromNoConstMissing(constName, false) : module.getConstantNoConstMissing(constName);
if (constant == null) {
constant = UndefinedValue.UNDEFINED;
} else {
// recache
if (constant != null) {
Invalidator invalidator = runtime.getConstantInvalidator(constName);
cache = new ConstantCache((IRubyObject)constant, invalidator.getData(), invalidator, module.hashCode());
}
@@ -92,7 +89,7 @@ public Object interpret(ThreadContext context, StaticScope currScope, DynamicSco
ConstantCache cache = this.cache;
Object result = !ConstantCache.isCachedFrom(module, cache) ? cache(context.runtime, module) : cache.value;

if (result == UndefinedValue.UNDEFINED) {
if (result == null) {
result = module.callMethod(context, "const_missing", context.runtime.fastNewSymbol(constName));
}

12 changes: 11 additions & 1 deletion core/src/main/java/org/jruby/ir/targets/ConstantLookupSite.java
Original file line number Diff line number Diff line change
@@ -98,8 +98,9 @@ public IRubyObject searchConst(ThreadContext context, StaticScope staticScope) {
return constant;
}

public IRubyObject searchModuleForConst(ThreadContext context, RubyModule module) {
public IRubyObject searchModuleForConst(ThreadContext context, IRubyObject cmVal) {
// Lexical lookup
RubyModule module = (RubyModule) cmVal;
Ruby runtime = context.getRuntime();
IRubyObject constant = publicOnly ? module.getConstantFromNoConstMissing(name, false) : module.getConstantNoConstMissing(name);

@@ -114,13 +115,22 @@ public IRubyObject searchModuleForConst(ThreadContext context, RubyModule module
MethodHandle target = Binder.from(type())
.drop(0, 2)
.constant(constant);

MethodHandle fallback = getTarget();
if (fallback == null) {
fallback = Binder.from(type())
.insert(0, this)
.invokeVirtualQuiet(Bootstrap.LOOKUP, "searchModuleForConst");
}

// test that module is same as before
MethodHandle test = Binder.from(type().changeReturnType(boolean.class))
.drop(0, 1)
.insert(1, module.id)
.invokeStaticQuiet(Bootstrap.LOOKUP, Bootstrap.class, "testArg0ModuleMatch");

target = guardWithTest(test, target, fallback);

setTarget(switchPoint.guardWithTest(target, fallback));

if (Options.INVOKEDYNAMIC_LOG_CONSTANTS.load()) {
Original file line number Diff line number Diff line change
@@ -716,7 +716,7 @@ public void searchConst(String name, boolean noPrivateConsts) {
}

public void searchModuleForConst(String name, boolean noPrivateConsts) {
adapter.invokedynamic("searchModuleForConst", sig(JVM.OBJECT, params(ThreadContext.class, RubyModule.class)), ConstantLookupSite.BOOTSTRAP, name, noPrivateConsts ? 1 : 0);
adapter.invokedynamic("searchModuleForConst", sig(JVM.OBJECT, params(ThreadContext.class, IRubyObject.class)), ConstantLookupSite.BOOTSTRAP, name, noPrivateConsts ? 1 : 0);
}

public void inheritanceSearchConst(String name, boolean noPrivateConsts) {
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Original file line number Diff line number Diff line change
@@ -1924,6 +1924,7 @@ public void SearchModuleForConstInstr(SearchModuleForConstInstr instr) {
visit(instr.getCurrentModule());

jvmMethod().searchModuleForConst(instr.getConstName(), instr.isNoPrivateConsts());
jvmStoreLocal(instr.getResult());
}

@Override

0 comments on commit e6a5867

Please sign in to comment.