Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: bbceb691e009
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b5f7a9b99a7f
Choose a head ref
  • 3 commits
  • 2 files changed
  • 1 contributor

Commits on Sep 13, 2016

  1. Only do attr binding if arity is appropriate. See #4148

    I'm still baffled as to why we'd be following either of these
    paths for a plain Ruby method (ActiveSupport's "delegate" method
    in #4148) but this should at least prevent us from attempting to
    bind those methods at attrs.
    headius committed Sep 13, 2016
    Copy the full SHA
    3b24d24 View commit details
  2. Copy the full SHA
    e6fd29f View commit details
  3. Copy the full SHA
    b5f7a9b View commit details
Showing with 22 additions and 14 deletions.
  1. +18 −14 core/src/main/java/org/jruby/ir/targets/Bootstrap.java
  2. +4 −0 core/src/main/java/org/jruby/ir/targets/InvokeSite.java
32 changes: 18 additions & 14 deletions core/src/main/java/org/jruby/ir/targets/Bootstrap.java
Original file line number Diff line number Diff line change
@@ -362,7 +362,7 @@ static MethodHandle buildGenericHandle(InvokeSite site, DynamicMethod method, Ru
}

static MethodHandle buildAttrHandle(InvokeSite site, DynamicMethod method, IRubyObject self, RubyClass dispatchClass) {
if (method instanceof AttrReaderMethod) {
if (method instanceof AttrReaderMethod && site.arity == 0) {
AttrReaderMethod attrReader = (AttrReaderMethod) method;
String varName = attrReader.getVariableName();

@@ -371,29 +371,29 @@ static MethodHandle buildAttrHandle(InvokeSite site, DynamicMethod method, IRuby

// Ruby to attr reader
if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) {
// if (accessor instanceof FieldVariableAccessor) {
// LOG.info(site.name() + "\tbound as field attr reader " + logMethod(method) + ":" + ((AttrReaderMethod)method).getVariableName());
// } else {
// LOG.info(site.name() + "\tbound as attr reader " + logMethod(method) + ":" + ((AttrReaderMethod)method).getVariableName());
// }
if (accessor instanceof FieldVariableAccessor) {
LOG.info(site.name() + "\tbound as field attr reader " + logMethod(method) + ":" + ((AttrReaderMethod)method).getVariableName());
} else {
LOG.info(site.name() + "\tbound as attr reader " + logMethod(method) + ":" + ((AttrReaderMethod)method).getVariableName());
}
}

return createAttrReaderHandle(site, self, dispatchClass.getRealClass(), accessor);
} else if (method instanceof AttrWriterMethod) {
} else if (method instanceof AttrWriterMethod && site.arity == 1) {
AttrWriterMethod attrReader = (AttrWriterMethod)method;
String varName = attrReader.getVariableName();

// we getVariableAccessorForWrite here so it is eagerly created and we don't cache the DUMMY
VariableAccessor accessor = dispatchClass.getRealClass().getVariableAccessorForWrite(varName);

// Ruby to attr reader
// if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) {
// if (accessor instanceof FieldVariableAccessor) {
// LOG.info(site.name() + "\tbound as field attr writer " + logMethod(method) + ":" + ((AttrWriterMethod) method).getVariableName());
// } else {
// LOG.info(site.name() + "\tbound as attr writer " + logMethod(method) + ":" + ((AttrWriterMethod) method).getVariableName());
// }
// }
if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) {
if (accessor instanceof FieldVariableAccessor) {
LOG.info(site.name() + "\tbound as field attr writer " + logMethod(method) + ":" + ((AttrWriterMethod) method).getVariableName());
} else {
LOG.info(site.name() + "\tbound as attr writer " + logMethod(method) + ":" + ((AttrWriterMethod) method).getVariableName());
}
}

return createAttrWriterHandle(site, self, dispatchClass.getRealClass(), accessor);
}
@@ -963,6 +963,10 @@ public static CallSite prepareBlock(Lookup lookup, String name, MethodType type,
return new ConstantCallSite(blockMaker);
}

private static String logMethod(DynamicMethod method) {
return "[#" + method.getSerialNumber() + " " + method.getImplementationClass() + "]";
}

private static final Binder BINDING_MAKER_BINDER = Binder.from(Binding.class, ThreadContext.class, IRubyObject.class, DynamicScope.class);

private static final MethodHandle FRAME_SCOPE_BINDING = BINDING_MAKER_BINDER.invokeStaticQuiet(LOOKUP, Bootstrap.class, "frameScopeBinding");
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/ir/targets/InvokeSite.java
Original file line number Diff line number Diff line change
@@ -339,6 +339,10 @@ public static boolean testClass(Object object, Class clazz) {
return object.getClass() == clazz;
}

public String toString() {
return "InvokeSite[name=" + name() + ",arity=" + arity + ",type=" + type() + ",file=" + file + ",line=" + line + "]";
}

private static final MethodHandle TEST_CLASS = Binder
.from(boolean.class, Object.class, Class.class)
.invokeStaticQuiet(lookup(), InvokeSite.class, "testClass");