Skip to content

Commit

Permalink
Fix regression in module_function behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Mar 22, 2018
1 parent b4b496a commit fab136d
Showing 1 changed file with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@
import org.jruby.util.log.LoggerFactory;

public class MixedModeIRMethod extends AbstractIRMethod implements Compilable<DynamicMethod> {
private static final Logger LOG = LoggerFactory.getLogger(MixedModeIRMethod.class);

private boolean displayedCFG = false; // FIXME: Remove when we find nicer way of logging CFG

private volatile int callCount = 0;
private volatile InterpretedIRMethod baseMethod;
private final InterpretedIRMethod baseMethod;
private volatile DynamicMethod jittedMethod;

public MixedModeIRMethod(IRScope method, Visibility visibility, RubyModule implementationClass) {
Expand All @@ -42,6 +38,15 @@ public MixedModeIRMethod(IRScope method, Visibility visibility, RubyModule imple
}
}

protected MixedModeIRMethod(MixedModeIRMethod copy) {
super(copy.getIRScope(), copy.getVisibility(), copy.getImplementationClass());

this.serialNumber = copy.serialNumber;
this.callCount = copy.callCount;
this.baseMethod = copy.baseMethod;
this.jittedMethod = copy.jittedMethod;
}

public DynamicMethod getActualMethod() {
return jittedMethod != null ? jittedMethod : baseMethod;
}
Expand Down Expand Up @@ -125,19 +130,28 @@ public String getClassName(ThreadContext context) {
return className;
}

@Override
public DynamicMethod dup() {
MixedModeIRMethod x = (MixedModeIRMethod) super.dup();
x.callCount = callCount;
x.baseMethod = baseMethod;

return x;
}

public void setCallCount(int callCount) {
synchronized (this) {
this.callCount = callCount;
}
}

@Override
public DynamicMethod dup() {
return new MixedModeIRMethod(this);
}

@Override
public void setImplementationClass(RubyModule implClass) {
super.setImplementationClass(implClass);
baseMethod.setImplementationClass(implClass);
if (jittedMethod != null) jittedMethod.setImplementationClass(implClass);
}

@Override
public void setDefinedClass(RubyModule definedClass) {
super.setDefinedClass(definedClass);
baseMethod.setDefinedClass(definedClass);
if (jittedMethod != null) jittedMethod.setDefinedClass(definedClass);
}
}

0 comments on commit fab136d

Please sign in to comment.