Skip to content

Commit d474a55

Browse files
committed
Also make callSiteId new for cloned instrs
Having a different call site but the same call site ID doesn't seem to make sense. Removing that additional clone parameter eliminates most clone constructors.
1 parent 833904b commit d474a55

25 files changed

Lines changed: 55 additions & 229 deletions

core/src/main/java/org/jruby/internal/runtime/AbstractIRMethod.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.jruby.compiler.Compilable;
3434
import org.jruby.internal.runtime.methods.DynamicMethod;
3535
import org.jruby.internal.runtime.methods.IRMethodArgs;
36+
import org.jruby.internal.runtime.methods.MixedModeIRMethod;
3637
import org.jruby.ir.IRFlags;
3738
import org.jruby.ir.IRMethod;
3839
import org.jruby.ir.IRScope;
@@ -169,7 +170,12 @@ public DynamicMethod dup() {
169170
@Override
170171
public Object clone() {
171172
try {
172-
return super.clone();
173+
AbstractIRMethod clone = (AbstractIRMethod) super.clone();
174+
clone.callCount = 0;
175+
if (clone instanceof MixedModeIRMethod mixedMode) {
176+
mixedMode.reset();
177+
}
178+
return clone;
173179
} catch (CloneNotSupportedException cnse) {
174180
throw new RuntimeException("not cloneable: " + this);
175181
}

core/src/main/java/org/jruby/internal/runtime/methods/MixedModeIRMethod.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ public DynamicMethod getActualMethod() {
6565
return actualMethod;
6666
}
6767

68+
public void reset() {
69+
this.callCount = 0;
70+
this.actualMethod = null;
71+
}
72+
6873
protected void post(InterpreterContext ic, ThreadContext context) {
6974
// update call stacks (pop: ..)
7075
context.popFrame();

core/src/main/java/org/jruby/ir/IRManager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import java.util.Iterator;
3636
import java.util.List;
3737
import java.util.Set;
38+
import java.util.concurrent.atomic.AtomicLong;
39+
3840
import org.jruby.ir.passes.DeadCodeElimination;
3941
import org.jruby.ir.passes.OptimizeDelegationPass;
4042
import org.jruby.ir.passes.OptimizeDynScopesPass;
@@ -94,6 +96,7 @@ public class IRManager {
9496
private final RubyInstanceConfig config;
9597
public final Ruby runtime;
9698
private IRBuilderFactory builderFactory;
99+
private AtomicLong callSiteCounter = new AtomicLong(1);
97100

98101
public IRManager(Ruby runtime, RubyInstanceConfig config) {
99102
this.runtime = runtime;
@@ -445,4 +448,8 @@ private ParseResult parse(ThreadContext context, FileResource file, String fileN
445448
public BuiltinClass getSymbolClass() {
446449
return symbolClass;
447450
}
451+
452+
public long nextCallSiteID() {
453+
return callSiteCounter.incrementAndGet();
454+
}
448455
}

core/src/main/java/org/jruby/ir/builder/IRBuilderAST.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2762,7 +2762,7 @@ public Operand buildYield(Variable result, YieldNode node) {
27622762
int[] flags = new int[] { 0 };
27632763
Operand value = buildYieldArgs(argNode, flags);
27642764

2765-
addInstr(new YieldInstr(result, getYieldClosureVariable(), value, flags[0], unwrap));
2765+
addInstr(new YieldInstr(scope, result, getYieldClosureVariable(), value, flags[0], unwrap));
27662766

27672767
return result;
27682768
}

core/src/main/java/org/jruby/ir/instructions/ArrayDerefInstr.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.jruby.ir.runtime.IRRuntimeHelpers;
1515
import org.jruby.ir.transformations.inlining.CloneInfo;
1616
import org.jruby.parser.StaticScope;
17-
import org.jruby.runtime.CallSite;
1817
import org.jruby.runtime.CallType;
1918
import org.jruby.runtime.DynamicScope;
2019
import org.jruby.runtime.ThreadContext;
@@ -36,16 +35,6 @@ public static ArrayDerefInstr create(IRScope scope, Variable result, Operand obj
3635
return new ArrayDerefInstr(scope, result, obj, arg0, flags);
3736
}
3837

39-
// clone constructor
40-
public ArrayDerefInstr(IRScope scope, Variable result, Operand obj, FrozenString arg0, int flags,
41-
CallSite callSite, long callSiteId) {
42-
super(scope, Operation.ARRAY_DEREF, CallType.FUNCTIONAL, result,
43-
scope.getManager().getRuntime().newSymbol(AREF), obj, new Operand[] {arg0}, flags, false,
44-
callSite, callSiteId);
45-
46-
key = arg0;
47-
}
48-
4938
// normal constructor
5039
public ArrayDerefInstr(IRScope scope, Variable result, Operand obj, FrozenString arg0, int flags) {
5140
super(scope, Operation.ARRAY_DEREF, CallType.FUNCTIONAL, result,
@@ -57,7 +46,7 @@ public ArrayDerefInstr(IRScope scope, Variable result, Operand obj, FrozenString
5746
@Override
5847
public Instr clone(CloneInfo ii) {
5948
return new ArrayDerefInstr(ii.getScope(), (Variable) getResult().cloneForInlining(ii),
60-
getReceiver().cloneForInlining(ii), key, getFlags(), getCallSite(), getCallSiteId());
49+
getReceiver().cloneForInlining(ii), key, getFlags());
6150
}
6251

6352
@Override

core/src/main/java/org/jruby/ir/instructions/AsStringInstr.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.jruby.ir.instructions;
22

3-
import org.jruby.compiler.NotCompilableException;
43
import org.jruby.ir.IRScope;
54
import org.jruby.ir.IRVisitor;
65
import org.jruby.ir.Operation;
@@ -13,7 +12,6 @@
1312
import org.jruby.ir.runtime.IRRuntimeHelpers;
1413
import org.jruby.ir.transformations.inlining.CloneInfo;
1514
import org.jruby.parser.StaticScope;
16-
import org.jruby.runtime.CallSite;
1715
import org.jruby.runtime.CallType;
1816
import org.jruby.runtime.DynamicScope;
1917
import org.jruby.runtime.ThreadContext;
@@ -38,31 +36,14 @@ public AsStringInstr(IRScope scope, Variable result, Operand source, boolean isP
3836
assert isPotentiallyRefined : "AsStringInstr should only be needed in refined scopes";
3937
}
4038

41-
private AsStringInstr(IRScope scope, Variable result, Operand source, boolean isPotentiallyRefined, CallSite callSite, long callSiteId) {
42-
super(
43-
scope,
44-
Operation.AS_STRING,
45-
CallType.FUNCTIONAL,
46-
result,
47-
scope.getManager().getRuntime().newSymbol(TO_S),
48-
nonNull(source),
49-
Operand.EMPTY_ARRAY,
50-
0,
51-
isPotentiallyRefined,
52-
callSite,
53-
callSiteId);
54-
55-
assert isPotentiallyRefined : "AsStringInstr should only be needed in refined scopes";
56-
}
57-
5839
private static Operand nonNull(Operand source) {
5940
return source == null ? MutableString.EMPTY_STRING : source;
6041
}
6142

6243
@Override
6344
public Instr clone(CloneInfo ii) {
6445
return new AsStringInstr(ii.getScope(), (Variable) getResult().cloneForInlining(ii),
65-
getReceiver().cloneForInlining(ii), isPotentiallyRefined(), getCallSite(), getCallSiteId());
46+
getReceiver().cloneForInlining(ii), isPotentiallyRefined());
6647
}
6748

6849
@Override

core/src/main/java/org/jruby/ir/instructions/AttrAssignInstr.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ public static AttrAssignInstr create(IRScope scope, Operand obj, RubySymbol attr
3636

3737
// clone constructor
3838
protected AttrAssignInstr(IRScope scope, CallType callType, RubySymbol name, Operand receiver,
39-
Operand[] args, int flags, boolean potentiallyRefined, CallSite callSite,
40-
long callSiteId) {
41-
super(scope, Operation.ATTR_ASSIGN, callType, name, receiver, args, NullBlock.INSTANCE, flags, potentiallyRefined, callSite, callSiteId);
39+
Operand[] args, int flags, boolean potentiallyRefined) {
40+
super(scope, Operation.ATTR_ASSIGN, callType, name, receiver, args, NullBlock.INSTANCE, flags, potentiallyRefined);
4241
}
4342

4443
// normal constructor
@@ -51,7 +50,7 @@ public AttrAssignInstr(IRScope scope, Operand obj, RubySymbol attr, Operand[] ar
5150
@Override
5251
public Instr clone(CloneInfo ii) {
5352
return new AttrAssignInstr(ii.getScope(), getCallType(), getName(), getReceiver().cloneForInlining(ii),
54-
cloneCallArgs(ii), getFlags(), isPotentiallyRefined(), getCallSite(), getCallSiteId());
53+
cloneCallArgs(ii), getFlags(), isPotentiallyRefined());
5554
}
5655

5756
@Override

core/src/main/java/org/jruby/ir/instructions/CallBase.java

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import static org.jruby.ir.IRFlags.*;
2626

2727
public abstract class CallBase extends NOperandInstr implements ClosureAcceptingInstr, Site {
28-
public static long callSiteCounter = 1;
2928
private static final EnumSet<FrameField> ALL = EnumSet.allOf(FrameField.class);
3029

3130
public transient long callSiteId;
@@ -49,33 +48,17 @@ public abstract class CallBase extends NOperandInstr implements ClosureAccepting
4948
// main constructor
5049
protected CallBase(IRScope scope, Operation op, CallType callType, RubySymbol name, Operand receiver,
5150
Operand[] args, Operand closure, int flags, boolean potentiallyRefined) {
52-
this(scope, op, callType, name, receiver, args, closure, flags, potentiallyRefined, null, callSiteCounter++);
53-
}
54-
55-
// clone constructor
56-
protected CallBase(IRScope scope, Operation op, CallType callType, RubySymbol name, Operand receiver,
57-
Operand[] args, Operand closure, int flags, boolean potentiallyRefined, CallSite callSite,
58-
long callSiteId) {
5951
super(op, arrayifyOperands(receiver, args, closure));
6052

6153
this.flags = flags;
62-
this.callSiteId = callSiteId;
54+
this.callSiteId = scope.getManager().nextCallSiteID();
6355
argsCount = args.length;
6456
hasClosure = closure != NullBlock.INSTANCE;
6557
this.name = name;
6658
this.callType = callType;
6759

6860
boolean effectivelyRefined = potentiallyRefined || (scope != null && scope.maybeUsingRefinements());
69-
boolean hasUnrefinedCallSite = callSite != null && !(callSite instanceof RefinedCachingCallSite);
70-
if (effectivelyRefined && hasUnrefinedCallSite) {
71-
callSite = null;
72-
}
73-
74-
if (callSite == null) {
75-
this.callSite = getCallSiteFor(scope, callType, name.idString(), callSiteId, hasLiteralClosure(), effectivelyRefined);
76-
} else {
77-
this.callSite = callSite;
78-
}
61+
this.callSite = getCallSiteFor(scope, callType, name.idString(), callSiteId, hasLiteralClosure(), effectivelyRefined);
7962

8063
splatMap = IRRuntimeHelpers.buildSplatMap(args);
8164
flagsComputed = false;

core/src/main/java/org/jruby/ir/instructions/CallInstr.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,13 @@
1111
import org.jruby.ir.instructions.specialized.OneOperandArgNoBlockCallInstr;
1212
import org.jruby.ir.instructions.specialized.TwoOperandArgNoBlockCallInstr;
1313
import org.jruby.ir.instructions.specialized.ZeroOperandArgNoBlockCallInstr;
14-
import org.jruby.ir.operands.Hash;
1514
import org.jruby.ir.operands.NullBlock;
1615
import org.jruby.ir.operands.Operand;
1716
import org.jruby.ir.operands.Variable;
1817
import org.jruby.ir.persistence.IRReaderDecoder;
1918
import org.jruby.ir.persistence.IRWriterEncoder;
2019
import org.jruby.ir.transformations.inlining.CloneInfo;
21-
import org.jruby.runtime.CallSite;
2220
import org.jruby.runtime.CallType;
23-
import org.jruby.util.KeyValuePair;
24-
25-
import java.util.List;
2621

2722
/*
2823
* args field: [self, receiver, *args]
@@ -66,16 +61,6 @@ public CallInstr(IRScope scope, CallType callType, Variable result, RubySymbol n
6661
this(scope, Operation.CALL, callType, result, name, receiver, args, closure, flags, potentiallyRefined);
6762
}
6863

69-
// clone constructor
70-
protected CallInstr(IRScope scope, Operation op, CallType callType, Variable result, RubySymbol name, Operand receiver,
71-
Operand[] args, Operand closure, int flags, boolean potentiallyRefined, CallSite callSite, long callSiteId) {
72-
super(scope, op, callType, name, receiver, args, closure, flags, potentiallyRefined, callSite, callSiteId);
73-
74-
assert result != null;
75-
76-
this.result = result;
77-
}
78-
7964
// normal constructor
8065
protected CallInstr(IRScope scope, Operation op, CallType callType, Variable result, RubySymbol name, Operand receiver,
8166
Operand[] args, Operand closure, int flags, boolean potentiallyRefined) {
@@ -141,8 +126,8 @@ public Instr clone(CloneInfo ii) {
141126
return new CallInstr(ii.getScope(), getOperation(), getCallType(), ii.getRenamedVariable(result), getName(),
142127
getReceiver().cloneForInlining(ii), cloneCallArgs(ii),
143128
getClosureArg().cloneForInlining(ii),
144-
getFlags(), isPotentiallyRefined(),
145-
getCallSite(), getCallSiteId());
129+
getFlags(), isPotentiallyRefined()
130+
);
146131
}
147132

148133
@Override

core/src/main/java/org/jruby/ir/instructions/ClassSuperInstr.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@
2222
public class ClassSuperInstr extends CallInstr {
2323
private final boolean isLiteralBlock;
2424

25-
// clone constructor
26-
protected ClassSuperInstr(IRScope scope, Variable result, Operand receiver, RubySymbol name, Operand[] args,
27-
Operand closure, int flags, boolean potentiallyRefined, CallSite callSite,
28-
long callSiteId) {
29-
super(scope, Operation.CLASS_SUPER, CallType.SUPER, result, name, receiver, args, closure, flags,
30-
potentiallyRefined, callSite, callSiteId);
31-
32-
isLiteralBlock = closure instanceof WrappedIRClosure;
33-
}
34-
3525
// normal constructor
3626
public ClassSuperInstr(IRScope scope, Variable result, Operand definingModule, RubySymbol name, Operand[] args,
3727
Operand closure, int flags, boolean isPotentiallyRefined) {
@@ -58,7 +48,7 @@ public boolean computeScopeFlags(IRScope scope, EnumSet<IRFlags> flags) {
5848
public Instr clone(CloneInfo ii) {
5949
return new ClassSuperInstr(ii.getScope(), ii.getRenamedVariable(getResult()), getDefiningModule().cloneForInlining(ii),
6050
name, cloneCallArgs(ii), getClosureArg().cloneForInlining(ii),
61-
getFlags(), isPotentiallyRefined(), getCallSite(), getCallSiteId());
51+
getFlags(), isPotentiallyRefined());
6252
}
6353

6454
public static ClassSuperInstr decode(IRReaderDecoder d) {

0 commit comments

Comments
 (0)