24
24
25
25
public abstract class CallBase extends NOperandInstr implements ClosureAcceptingInstr {
26
26
private static long callSiteCounter = 1 ;
27
+ private static final EnumSet <FrameField > ALL = EnumSet .allOf (FrameField .class );
27
28
28
29
public transient final long callSiteId ;
29
30
private final CallType callType ;
@@ -62,26 +63,7 @@ protected CallBase(Operation op, CallType callType, String name, Operand receive
62
63
procNew = false ;
63
64
this .potentiallyRefined = potentiallyRefined ;
64
65
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 );
85
67
}
86
68
87
69
@ Override
@@ -264,7 +246,7 @@ public boolean computeScopeFlags(IRScope scope) {
264
246
String mname = getName ();
265
247
if (mname .equals ("local_variables" )) {
266
248
flags .add (REQUIRES_DYNSCOPE );
267
- } else if (potentiallySend (mname ) && argsCount >= 1 ) {
249
+ } else if (potentiallySend (mname , argsCount ) ) {
268
250
Operand meth = getArg1 ();
269
251
if (meth instanceof StringLiteral && "local_variables" .equals (((StringLiteral )meth ).getString ())) {
270
252
flags .add (REQUIRES_DYNSCOPE );
@@ -315,7 +297,7 @@ private boolean computeEvalFlag() {
315
297
}
316
298
317
299
// 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 ) ) {
319
301
Operand meth = getArg1 ();
320
302
if (!(meth instanceof StringLiteral )) return true ; // We don't know
321
303
@@ -338,7 +320,7 @@ private boolean computeRequiresCallersBindingFlag() {
338
320
String mname = getName ();
339
321
if (MethodIndex .SCOPE_AWARE_METHODS .contains (mname )) {
340
322
return true ;
341
- } else if (potentiallySend (mname ) && argsCount >= 1 ) {
323
+ } else if (potentiallySend (mname , argsCount ) ) {
342
324
Operand meth = getArg1 ();
343
325
if (!(meth instanceof StringLiteral )) return true ; // We don't know -- could be anything
344
326
@@ -393,7 +375,7 @@ private boolean computeRequiresCallersFrameFlag() {
393
375
// Known frame-aware methods.
394
376
return true ;
395
377
396
- } else if (potentiallySend (mname ) && argsCount >= 1 ) {
378
+ } else if (potentiallySend (mname , argsCount ) ) {
397
379
Operand meth = getArg1 ();
398
380
String name ;
399
381
if (meth instanceof Stringable ) {
@@ -413,8 +395,34 @@ private boolean computeRequiresCallersFrameFlag() {
413
395
return false ;
414
396
}
415
397
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
+ }
418
426
}
419
427
420
428
private void computeFlags () {
0 commit comments