76
76
import org .jruby .internal .runtime .methods .DynamicMethod ;
77
77
import org .jruby .internal .runtime .methods .Framing ;
78
78
import org .jruby .internal .runtime .methods .JavaMethod ;
79
+ import org .jruby .internal .runtime .methods .NativeCallMethod ;
79
80
import org .jruby .internal .runtime .methods .ProcMethod ;
80
81
import org .jruby .internal .runtime .methods .Scoping ;
81
82
import org .jruby .internal .runtime .methods .SynchronizedDynamicMethod ;
120
121
import static org .jruby .anno .FrameField .BLOCK ;
121
122
import static org .jruby .anno .FrameField .CLASS ;
122
123
import static org .jruby .anno .FrameField .FILENAME ;
123
- import static org .jruby .anno .FrameField .JUMPTARGET ;
124
124
import static org .jruby .anno .FrameField .LASTLINE ;
125
125
import static org .jruby .anno .FrameField .LINE ;
126
126
import static org .jruby .anno .FrameField .METHODNAME ;
@@ -1645,29 +1645,44 @@ public synchronized void defineAliases(List<String> aliases, String oldName) {
1645
1645
private DynamicMethod searchForAliasMethod (Ruby runtime , String name ) {
1646
1646
DynamicMethod method = deepMethodSearch (name , runtime );
1647
1647
1648
- // if (method instanceof JavaMethod) {
1649
- // // JRUBY-2435: Aliasing eval and other "special" methods should display a warning
1650
- // // We warn because we treat certain method names as "special" for purposes of
1651
- // // optimization. Hopefully this will be enough to convince people not to alias
1652
- // // them.
1653
- // CallConfiguration callerReq = ((JavaMethod)method).getCallerRequirement();
1654
- //
1655
- // if (callerReq.framing() != Framing.None ||
1656
- // callerReq.scoping() != Scoping.None) {String baseName = getBaseName();
1657
- // char refChar = '#';
1658
- // String simpleName = getSimpleName();
1659
- //
1660
- // if (baseName == null && this instanceof MetaClass) {
1661
- // IRubyObject attached = ((MetaClass)this).getAttached();
1662
- // if (attached instanceof RubyModule) {
1663
- // simpleName = ((RubyModule)attached).getSimpleName();
1664
- // refChar = '.';
1665
- // }
1666
- // }
1667
- //
1668
- // runtime.getWarnings().warn(simpleName + refChar + name + " accesses caller's state and should not be aliased");
1669
- // }
1670
- // }
1648
+ if (method instanceof NativeCallMethod ) {
1649
+ // JRUBY-2435: Aliasing eval and other "special" methods should display a warning
1650
+ // We warn because we treat certain method names as "special" for purposes of
1651
+ // optimization. Hopefully this will be enough to convince people not to alias
1652
+ // them.
1653
+
1654
+ DynamicMethod .NativeCall nativeCall = ((NativeCallMethod ) method ).getNativeCall ();
1655
+
1656
+ // native-backed but not a direct call, ok
1657
+ if (nativeCall == null ) return method ;
1658
+
1659
+ Method javaMethod = nativeCall .getMethod ();
1660
+ JRubyMethod anno = javaMethod .getAnnotation (JRubyMethod .class );
1661
+
1662
+ if (anno == null ) return method ;
1663
+
1664
+ if (anno .reads ().length > 0 || anno .writes ().length > 0 ) {
1665
+
1666
+ MethodIndex .addMethodReadFields (name , anno .reads ());
1667
+ MethodIndex .addMethodWriteFields (name , anno .writes ());
1668
+
1669
+ if (runtime .isVerbose ()) {
1670
+ String baseName = getBaseName ();
1671
+ char refChar = '#' ;
1672
+ String simpleName = getSimpleName ();
1673
+
1674
+ if (baseName == null && this instanceof MetaClass ) {
1675
+ IRubyObject attached = ((MetaClass ) this ).getAttached ();
1676
+ if (attached instanceof RubyModule ) {
1677
+ simpleName = ((RubyModule ) attached ).getSimpleName ();
1678
+ refChar = '.' ;
1679
+ }
1680
+ }
1681
+
1682
+ runtime .getWarnings ().warning (simpleName + refChar + name + " accesses caller method's state and should not be aliased" );
1683
+ }
1684
+ }
1685
+ }
1671
1686
1672
1687
return method ;
1673
1688
}
@@ -2861,26 +2876,26 @@ public RubyModule undef_method(ThreadContext context, IRubyObject[] args) {
2861
2876
}
2862
2877
2863
2878
@ JRubyMethod (name = {"module_eval" , "class_eval" },
2864
- reads = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , JUMPTARGET , CLASS , FILENAME , SCOPE },
2865
- writes = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , JUMPTARGET , CLASS , FILENAME , SCOPE })
2879
+ reads = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , CLASS , FILENAME , SCOPE },
2880
+ writes = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , CLASS , FILENAME , SCOPE })
2866
2881
public IRubyObject module_eval (ThreadContext context , Block block ) {
2867
2882
return specificEval (context , this , block , EvalType .MODULE_EVAL );
2868
2883
}
2869
2884
@ JRubyMethod (name = {"module_eval" , "class_eval" },
2870
- reads = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , JUMPTARGET , CLASS , FILENAME , SCOPE },
2871
- writes = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , JUMPTARGET , CLASS , FILENAME , SCOPE })
2885
+ reads = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , CLASS , FILENAME , SCOPE },
2886
+ writes = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , CLASS , FILENAME , SCOPE })
2872
2887
public IRubyObject module_eval (ThreadContext context , IRubyObject arg0 , Block block ) {
2873
2888
return specificEval (context , this , arg0 , block , EvalType .MODULE_EVAL );
2874
2889
}
2875
2890
@ JRubyMethod (name = {"module_eval" , "class_eval" },
2876
- reads = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , JUMPTARGET , CLASS , FILENAME , SCOPE },
2877
- writes = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , JUMPTARGET , CLASS , FILENAME , SCOPE })
2891
+ reads = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , CLASS , FILENAME , SCOPE },
2892
+ writes = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , CLASS , FILENAME , SCOPE })
2878
2893
public IRubyObject module_eval (ThreadContext context , IRubyObject arg0 , IRubyObject arg1 , Block block ) {
2879
2894
return specificEval (context , this , arg0 , arg1 , block , EvalType .MODULE_EVAL );
2880
2895
}
2881
2896
@ JRubyMethod (name = {"module_eval" , "class_eval" },
2882
- reads = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , JUMPTARGET , CLASS , FILENAME , SCOPE },
2883
- writes = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , JUMPTARGET , CLASS , FILENAME , SCOPE })
2897
+ reads = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , CLASS , FILENAME , SCOPE },
2898
+ writes = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , CLASS , FILENAME , SCOPE })
2884
2899
public IRubyObject module_eval (ThreadContext context , IRubyObject arg0 , IRubyObject arg1 , IRubyObject arg2 , Block block ) {
2885
2900
return specificEval (context , this , arg0 , arg1 , arg2 , block , EvalType .MODULE_EVAL );
2886
2901
}
@@ -2890,8 +2905,8 @@ public IRubyObject module_eval(ThreadContext context, IRubyObject[] args, Block
2890
2905
}
2891
2906
2892
2907
@ JRubyMethod (name = {"module_exec" , "class_exec" },
2893
- reads = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , JUMPTARGET , CLASS , FILENAME , SCOPE },
2894
- writes = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , JUMPTARGET , CLASS , FILENAME , SCOPE })
2908
+ reads = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , CLASS , FILENAME , SCOPE },
2909
+ writes = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , CLASS , FILENAME , SCOPE })
2895
2910
public IRubyObject module_exec (ThreadContext context , Block block ) {
2896
2911
if (block .isGiven ()) {
2897
2912
return yieldUnder (context , this , IRubyObject .NULL_ARRAY , block , EvalType .MODULE_EVAL );
@@ -2901,8 +2916,8 @@ public IRubyObject module_exec(ThreadContext context, Block block) {
2901
2916
}
2902
2917
2903
2918
@ JRubyMethod (name = {"module_exec" , "class_exec" }, rest = true ,
2904
- reads = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , JUMPTARGET , CLASS , FILENAME , SCOPE },
2905
- writes = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , JUMPTARGET , CLASS , FILENAME , SCOPE })
2919
+ reads = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , CLASS , FILENAME , SCOPE },
2920
+ writes = {LASTLINE , BACKREF , VISIBILITY , BLOCK , SELF , METHODNAME , LINE , CLASS , FILENAME , SCOPE })
2906
2921
public IRubyObject module_exec (ThreadContext context , IRubyObject [] args , Block block ) {
2907
2922
if (block .isGiven ()) {
2908
2923
return yieldUnder (context , this , args , block , EvalType .MODULE_EVAL );
@@ -4465,14 +4480,14 @@ private static void define(RubyModule module, JavaMethodDescriptor desc, final S
4465
4480
CallConfiguration needs = CallConfiguration .valueOf (AnnotationHelper .getCallerCallConfigNameByAnno (jrubyMethod ));
4466
4481
4467
4482
if (needs .framing () == Framing .Full ) {
4468
- Collection <String > frameAwareMethods = new ArrayList <>(4 ); // added to a Set - thus no need for another Set
4469
- AnnotationHelper .addMethodNamesToSet (frameAwareMethods , simpleName , names , aliases );
4470
- MethodIndex .FRAME_AWARE_METHODS .addAll (frameAwareMethods );
4483
+ Map <String , JRubyMethod > frameAwareMethods = new HashMap <>(4 ); // added to a Set - thus no need for another Set
4484
+ AnnotationHelper .addMethodNamesToMap (frameAwareMethods , null , simpleName , names , aliases );
4485
+ MethodIndex .FRAME_AWARE_METHODS .addAll (frameAwareMethods . keySet () );
4471
4486
}
4472
4487
if (needs .scoping () == Scoping .Full ) {
4473
- Collection <String > scopeAwareMethods = new ArrayList <>(4 ); // added to a Set - thus no need for another Set
4474
- AnnotationHelper .addMethodNamesToSet (scopeAwareMethods , simpleName , names , aliases );
4475
- MethodIndex .SCOPE_AWARE_METHODS .addAll (scopeAwareMethods );
4488
+ Map <String , JRubyMethod > scopeAwareMethods = new HashMap <>(4 ); // added to a Set - thus no need for another Set
4489
+ AnnotationHelper .addMethodNamesToMap (scopeAwareMethods , null , simpleName , names , aliases );
4490
+ MethodIndex .SCOPE_AWARE_METHODS .addAll (scopeAwareMethods . keySet () );
4476
4491
}
4477
4492
4478
4493
RubyModule singletonClass ;
0 commit comments