Skip to content

Commit 3eddbcb

Browse files
committedDec 22, 2017
Merge branch 'split_frame'
2 parents 9b16c5c + 34aae7c commit 3eddbcb

33 files changed

+751
-220
lines changed
 

Diff for: ‎core/src/main/java/org/jruby/Ruby.java

+15-8
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
import org.jruby.parser.StaticScope;
6666
import org.jruby.runtime.JavaSites;
6767
import org.jruby.runtime.invokedynamic.InvokeDynamicSupport;
68-
import org.jruby.runtime.opto.ConstantInvalidator;
6968
import org.jruby.util.MRIRecursionGuard;
7069
import org.jruby.util.StrptimeParser;
7170
import org.jruby.util.StrptimeToken;
@@ -176,13 +175,10 @@
176175
import java.lang.invoke.MethodHandle;
177176
import java.lang.ref.WeakReference;
178177
import java.net.BindException;
179-
import java.net.PortUnreachableException;
180-
import java.nio.channels.ClosedChannelException;
181178
import java.nio.charset.Charset;
182179
import java.security.SecureRandom;
183180
import java.util.ArrayList;
184181
import java.util.Arrays;
185-
import java.util.Collections;
186182
import java.util.EnumMap;
187183
import java.util.EnumSet;
188184
import java.util.HashMap;
@@ -3004,13 +3000,24 @@ public void loadExtension(String extName, BasicLibraryService extension, boolean
30043000

30053001
public void addBoundMethod(String className, String methodName, String rubyName) {
30063002
Map<String, String> javaToRuby = boundMethods.get(className);
3007-
if (javaToRuby == null) {
3008-
javaToRuby = new HashMap<String, String>();
3009-
boundMethods.put(className, javaToRuby);
3010-
}
3003+
if (javaToRuby == null) boundMethods.put(className, javaToRuby = new HashMap<>());
30113004
javaToRuby.put(methodName, rubyName);
30123005
}
30133006

3007+
public void addBoundMethodsPacked(String className, String packedTuples) {
3008+
String[] names = Helpers.SEMICOLON_PATTERN.split(packedTuples);
3009+
for (int i = 0; i < names.length; i += 2) {
3010+
addBoundMethod(className, names[i], names[i+1]);
3011+
}
3012+
}
3013+
3014+
public void addSimpleBoundMethodsPacked(String className, String packedNames) {
3015+
String[] names = Helpers.SEMICOLON_PATTERN.split(packedNames);
3016+
for (String name : names) {
3017+
addBoundMethod(className, name, name);
3018+
}
3019+
}
3020+
30143021
public Map<String, Map<String, String>> getBoundMethods() {
30153022
return boundMethods;
30163023
}

Diff for: ‎core/src/main/java/org/jruby/RubyBasicObject.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -1744,33 +1744,33 @@ public IRubyObject send(ThreadContext context, IRubyObject[] args, Block block)
17441744
}
17451745

17461746
@JRubyMethod(name = "instance_eval",
1747-
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, JUMPTARGET, CLASS, FILENAME, SCOPE},
1748-
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, JUMPTARGET, CLASS, FILENAME, SCOPE})
1747+
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE},
1748+
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE})
17491749
public IRubyObject instance_eval19(ThreadContext context, Block block) {
17501750
return specificEval(context, getInstanceEvalClass(), block, EvalType.INSTANCE_EVAL);
17511751
}
17521752
@JRubyMethod(name = "instance_eval",
1753-
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, JUMPTARGET, CLASS, FILENAME, SCOPE},
1754-
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, JUMPTARGET, CLASS, FILENAME, SCOPE})
1753+
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE},
1754+
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE})
17551755
public IRubyObject instance_eval19(ThreadContext context, IRubyObject arg0, Block block) {
17561756
return specificEval(context, getInstanceEvalClass(), arg0, block, EvalType.INSTANCE_EVAL);
17571757
}
17581758
@JRubyMethod(name = "instance_eval",
1759-
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, JUMPTARGET, CLASS, FILENAME, SCOPE},
1760-
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, JUMPTARGET, CLASS, FILENAME, SCOPE})
1759+
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE},
1760+
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE})
17611761
public IRubyObject instance_eval19(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) {
17621762
return specificEval(context, getInstanceEvalClass(), arg0, arg1, block, EvalType.INSTANCE_EVAL);
17631763
}
17641764
@JRubyMethod(name = "instance_eval",
1765-
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, JUMPTARGET, CLASS, FILENAME, SCOPE},
1766-
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, JUMPTARGET, CLASS, FILENAME, SCOPE})
1765+
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE},
1766+
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE})
17671767
public IRubyObject instance_eval19(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
17681768
return specificEval(context, getInstanceEvalClass(), arg0, arg1, arg2, block, EvalType.INSTANCE_EVAL);
17691769
}
17701770

17711771
@JRubyMethod(name = "instance_exec", optional = 3, rest = true,
1772-
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, JUMPTARGET, CLASS, FILENAME, SCOPE},
1773-
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, JUMPTARGET, CLASS, FILENAME, SCOPE})
1772+
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE},
1773+
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE})
17741774
public IRubyObject instance_exec19(ThreadContext context, IRubyObject[] args, Block block) {
17751775
if (!block.isGiven()) {
17761776
throw context.runtime.newLocalJumpErrorNoBlock();

Diff for: ‎core/src/main/java/org/jruby/RubyKernel.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -788,8 +788,8 @@ public static RubyBinding binding(ThreadContext context, IRubyObject recv, Block
788788
}
789789

790790
@JRubyMethod(name = "binding", module = true, visibility = PRIVATE,
791-
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, JUMPTARGET, CLASS, FILENAME, SCOPE},
792-
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, JUMPTARGET, CLASS, FILENAME, SCOPE})
791+
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE},
792+
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE})
793793
public static RubyBinding binding19(ThreadContext context, IRubyObject recv, Block block) {
794794
return RubyBinding.newBinding(context.runtime, context.currentBinding());
795795
}
@@ -1002,8 +1002,8 @@ public static IRubyObject eval(ThreadContext context, IRubyObject recv, IRubyObj
10021002
}
10031003

10041004
@JRubyMethod(name = "eval", required = 1, optional = 3, module = true, visibility = PRIVATE,
1005-
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, JUMPTARGET, CLASS, FILENAME, SCOPE},
1006-
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, JUMPTARGET, CLASS, FILENAME, SCOPE})
1005+
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE},
1006+
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE})
10071007
public static IRubyObject eval19(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
10081008
return evalCommon(context, recv, args, evalBinding19);
10091009
}

Diff for: ‎core/src/main/java/org/jruby/RubyModule.java

+57-42
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import org.jruby.internal.runtime.methods.DynamicMethod;
7777
import org.jruby.internal.runtime.methods.Framing;
7878
import org.jruby.internal.runtime.methods.JavaMethod;
79+
import org.jruby.internal.runtime.methods.NativeCallMethod;
7980
import org.jruby.internal.runtime.methods.ProcMethod;
8081
import org.jruby.internal.runtime.methods.Scoping;
8182
import org.jruby.internal.runtime.methods.SynchronizedDynamicMethod;
@@ -120,7 +121,6 @@
120121
import static org.jruby.anno.FrameField.BLOCK;
121122
import static org.jruby.anno.FrameField.CLASS;
122123
import static org.jruby.anno.FrameField.FILENAME;
123-
import static org.jruby.anno.FrameField.JUMPTARGET;
124124
import static org.jruby.anno.FrameField.LASTLINE;
125125
import static org.jruby.anno.FrameField.LINE;
126126
import static org.jruby.anno.FrameField.METHODNAME;
@@ -1645,29 +1645,44 @@ public synchronized void defineAliases(List<String> aliases, String oldName) {
16451645
private DynamicMethod searchForAliasMethod(Ruby runtime, String name) {
16461646
DynamicMethod method = deepMethodSearch(name, runtime);
16471647

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+
}
16711686

16721687
return method;
16731688
}
@@ -2861,26 +2876,26 @@ public RubyModule undef_method(ThreadContext context, IRubyObject[] args) {
28612876
}
28622877

28632878
@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})
28662881
public IRubyObject module_eval(ThreadContext context, Block block) {
28672882
return specificEval(context, this, block, EvalType.MODULE_EVAL);
28682883
}
28692884
@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})
28722887
public IRubyObject module_eval(ThreadContext context, IRubyObject arg0, Block block) {
28732888
return specificEval(context, this, arg0, block, EvalType.MODULE_EVAL);
28742889
}
28752890
@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})
28782893
public IRubyObject module_eval(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) {
28792894
return specificEval(context, this, arg0, arg1, block, EvalType.MODULE_EVAL);
28802895
}
28812896
@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})
28842899
public IRubyObject module_eval(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
28852900
return specificEval(context, this, arg0, arg1, arg2, block, EvalType.MODULE_EVAL);
28862901
}
@@ -2890,8 +2905,8 @@ public IRubyObject module_eval(ThreadContext context, IRubyObject[] args, Block
28902905
}
28912906

28922907
@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})
28952910
public IRubyObject module_exec(ThreadContext context, Block block) {
28962911
if (block.isGiven()) {
28972912
return yieldUnder(context, this, IRubyObject.NULL_ARRAY, block, EvalType.MODULE_EVAL);
@@ -2901,8 +2916,8 @@ public IRubyObject module_exec(ThreadContext context, Block block) {
29012916
}
29022917

29032918
@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})
29062921
public IRubyObject module_exec(ThreadContext context, IRubyObject[] args, Block block) {
29072922
if (block.isGiven()) {
29082923
return yieldUnder(context, this, args, block, EvalType.MODULE_EVAL);
@@ -4465,14 +4480,14 @@ private static void define(RubyModule module, JavaMethodDescriptor desc, final S
44654480
CallConfiguration needs = CallConfiguration.valueOf(AnnotationHelper.getCallerCallConfigNameByAnno(jrubyMethod));
44664481

44674482
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());
44714486
}
44724487
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());
44764491
}
44774492

44784493
RubyModule singletonClass;

0 commit comments

Comments
 (0)
Please sign in to comment.