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: 6fb12a832ed5
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a4b81bcc88fe
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Dec 19, 2017

  1. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    aurelien-reeves Aurélien Reeves
    Copy the full SHA
    acdb21a View commit details
  2. Cache reflected method.

    headius committed Dec 19, 2017

    Verified

    This commit was signed with the committer’s verified signature.
    aurelien-reeves Aurélien Reeves
    Copy the full SHA
    a4b81bc View commit details
Showing with 37 additions and 24 deletions.
  1. +33 −23 core/src/main/java/org/jruby/RubyModule.java
  2. +4 −1 core/src/main/java/org/jruby/internal/runtime/methods/DynamicMethod.java
56 changes: 33 additions & 23 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -76,6 +76,7 @@
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.internal.runtime.methods.Framing;
import org.jruby.internal.runtime.methods.JavaMethod;
import org.jruby.internal.runtime.methods.NativeCallMethod;
import org.jruby.internal.runtime.methods.ProcMethod;
import org.jruby.internal.runtime.methods.Scoping;
import org.jruby.internal.runtime.methods.SynchronizedDynamicMethod;
@@ -1644,29 +1645,38 @@ public synchronized void defineAliases(List<String> aliases, String oldName) {
private DynamicMethod searchForAliasMethod(Ruby runtime, String name) {
DynamicMethod method = deepMethodSearch(name, runtime);

// if (method instanceof JavaMethod) {
// // JRUBY-2435: Aliasing eval and other "special" methods should display a warning
// // We warn because we treat certain method names as "special" for purposes of
// // optimization. Hopefully this will be enough to convince people not to alias
// // them.
// CallConfiguration callerReq = ((JavaMethod)method).getCallerRequirement();
//
// if (callerReq.framing() != Framing.None ||
// callerReq.scoping() != Scoping.None) {String baseName = getBaseName();
// char refChar = '#';
// String simpleName = getSimpleName();
//
// if (baseName == null && this instanceof MetaClass) {
// IRubyObject attached = ((MetaClass)this).getAttached();
// if (attached instanceof RubyModule) {
// simpleName = ((RubyModule)attached).getSimpleName();
// refChar = '.';
// }
// }
//
// runtime.getWarnings().warn(simpleName + refChar + name + " accesses caller's state and should not be aliased");
// }
// }
if (method instanceof NativeCallMethod) {
// JRUBY-2435: Aliasing eval and other "special" methods should display a warning
// We warn because we treat certain method names as "special" for purposes of
// optimization. Hopefully this will be enough to convince people not to alias
// them.

DynamicMethod.NativeCall nativeCall = ((NativeCallMethod) method).getNativeCall();

// native-backed but not a direct call, ok
if (nativeCall == null) return method;

Method javaMethod = nativeCall.getMethod();
JRubyMethod anno = javaMethod.getAnnotation(JRubyMethod.class);

if (anno == null) return method;

if (anno.reads().length > 0 || anno.writes().length > 0) {
String baseName = getBaseName();
char refChar = '#';
String simpleName = getSimpleName();

if (baseName == null && this instanceof MetaClass) {
IRubyObject attached = ((MetaClass)this).getAttached();
if (attached instanceof RubyModule) {
simpleName = ((RubyModule)attached).getSimpleName();
refChar = '.';
}
}

runtime.getWarnings().warning(simpleName + refChar + name + " accesses caller method's state and should not be aliased");
}
}

return method;
}
Original file line number Diff line number Diff line change
@@ -408,6 +408,7 @@ public static class NativeCall {
private final Class[] nativeSignature;
private final boolean statik;
private final boolean java;
private Method reflected;

public NativeCall(Class nativeTarget, String nativeName, Class nativeReturn, Class[] nativeSignature, boolean statik) {
this(nativeTarget, nativeName, nativeReturn, nativeSignature, statik, false);
@@ -460,8 +461,10 @@ public boolean hasBlock() {
* @return the reflected method corresponding to this NativeCall
*/
public Method getMethod() {
Method reflected = this.reflected;
if (reflected != null) return reflected;
try {
return nativeTarget.getDeclaredMethod(nativeName, nativeSignature);
return this.reflected = nativeTarget.getDeclaredMethod(nativeName, nativeSignature);
} catch (Exception e) {
throw new RuntimeException(e);
}