Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f519167

Browse files
committedDec 19, 2017
Clean up CallBase frame field processing.
1 parent ea8825d commit f519167

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed
 

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

+34-26
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
public abstract class CallBase extends NOperandInstr implements ClosureAcceptingInstr {
2626
private static long callSiteCounter = 1;
27+
private static final EnumSet<FrameField> ALL = EnumSet.allOf(FrameField.class);
2728

2829
public transient final long callSiteId;
2930
private final CallType callType;
@@ -62,26 +63,7 @@ protected CallBase(Operation op, CallType callType, String name, Operand receive
6263
procNew = false;
6364
this.potentiallyRefined = potentiallyRefined;
6465

65-
// now grab a reference to frame fields this method name is known to be associated with
66-
67-
if (potentiallySend(name) && argsCount >= 1) {
68-
// Might be a #send, use the frame reads and writes of what it might call
69-
Operand meth = getArg1();
70-
String aliasName;
71-
if (meth instanceof Stringable) {
72-
aliasName = ((Stringable) meth).getString();
73-
frameReads = MethodIndex.METHOD_FRAME_READS.getOrDefault(aliasName, Collections.EMPTY_SET);
74-
frameWrites = MethodIndex.METHOD_FRAME_WRITES.getOrDefault(aliasName, Collections.EMPTY_SET);
75-
} else {
76-
// We don't know -- could be anything
77-
frameReads = EnumSet.allOf(FrameField.class);
78-
frameWrites = EnumSet.allOf(FrameField.class);
79-
}
80-
} else {
81-
frameReads = MethodIndex.METHOD_FRAME_READS.getOrDefault(name, Collections.EMPTY_SET);
82-
frameWrites = MethodIndex.METHOD_FRAME_WRITES.getOrDefault(name, Collections.EMPTY_SET);
83-
}
84-
66+
captureFrameReadsAndWrites(name);
8567
}
8668

8769
@Override
@@ -264,7 +246,7 @@ public boolean computeScopeFlags(IRScope scope) {
264246
String mname = getName();
265247
if (mname.equals("local_variables")) {
266248
flags.add(REQUIRES_DYNSCOPE);
267-
} else if (potentiallySend(mname) && argsCount >= 1) {
249+
} else if (potentiallySend(mname, argsCount)) {
268250
Operand meth = getArg1();
269251
if (meth instanceof StringLiteral && "local_variables".equals(((StringLiteral)meth).getString())) {
270252
flags.add(REQUIRES_DYNSCOPE);
@@ -315,7 +297,7 @@ private boolean computeEvalFlag() {
315297
}
316298

317299
// Calls to 'send' where the first arg is either unknown or is eval or send (any others?)
318-
if (potentiallySend(mname) && argsCount >= 1) {
300+
if (potentiallySend(mname, argsCount)) {
319301
Operand meth = getArg1();
320302
if (!(meth instanceof StringLiteral)) return true; // We don't know
321303

@@ -338,7 +320,7 @@ private boolean computeRequiresCallersBindingFlag() {
338320
String mname = getName();
339321
if (MethodIndex.SCOPE_AWARE_METHODS.contains(mname)) {
340322
return true;
341-
} else if (potentiallySend(mname) && argsCount >= 1) {
323+
} else if (potentiallySend(mname, argsCount)) {
342324
Operand meth = getArg1();
343325
if (!(meth instanceof StringLiteral)) return true; // We don't know -- could be anything
344326

@@ -393,7 +375,7 @@ private boolean computeRequiresCallersFrameFlag() {
393375
// Known frame-aware methods.
394376
return true;
395377

396-
} else if (potentiallySend(mname) && argsCount >= 1) {
378+
} else if (potentiallySend(mname, argsCount)) {
397379
Operand meth = getArg1();
398380
String name;
399381
if (meth instanceof Stringable) {
@@ -413,8 +395,34 @@ private boolean computeRequiresCallersFrameFlag() {
413395
return false;
414396
}
415397

416-
private static boolean potentiallySend(String name) {
417-
return name.equals("send") || name.equals("__send__") || name.equals("public_send");
398+
private static boolean potentiallySend(String name, int argsCount) {
399+
return (name.equals("send") || name.equals("__send__") || name.equals("public_send")) && argsCount >= 1;
400+
}
401+
402+
/**
403+
* Determine based on the method name what frame fields it is likely to need.
404+
*
405+
* @param name the name of the method that will be called
406+
*/
407+
private void captureFrameReadsAndWrites() {
408+
// grab a reference to frame fields this method name is known to be associated with
409+
if (potentiallySend(getName(), argsCount)) {
410+
// Might be a #send, use the frame reads and writes of what it might call
411+
Operand meth = getArg1();
412+
String aliasName;
413+
if (meth instanceof Stringable) {
414+
aliasName = ((Stringable) meth).getString();
415+
frameReads = MethodIndex.METHOD_FRAME_READS.getOrDefault(aliasName, Collections.EMPTY_SET);
416+
frameWrites = MethodIndex.METHOD_FRAME_WRITES.getOrDefault(aliasName, Collections.EMPTY_SET);
417+
} else {
418+
// We don't know -- could be anything
419+
frameReads = ALL;
420+
frameWrites = ALL;
421+
}
422+
} else {
423+
frameReads = MethodIndex.METHOD_FRAME_READS.getOrDefault(name, Collections.EMPTY_SET);
424+
frameWrites = MethodIndex.METHOD_FRAME_WRITES.getOrDefault(name, Collections.EMPTY_SET);
425+
}
418426
}
419427

420428
private void computeFlags() {

0 commit comments

Comments
 (0)
Please sign in to comment.