Skip to content

Commit dc764f8

Browse files
committed
Merge branch 'master' into truffle-head
2 parents 672834f + 4948b9b commit dc764f8

File tree

227 files changed

+2873
-1598
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+2873
-1598
lines changed

antlib/extra.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ build jruby-complete.jar
2525
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
2626
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
2727
<arg value='-cp'/>
28-
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.18-SNAPSHOT.jar'/>
28+
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.19-SNAPSHOT.jar'/>
2929
<arg value='org.jruby.Main'/>
3030
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
3131
<arg value='-r./test/ruby19_env.rb'/>
@@ -137,7 +137,7 @@ build jruby-complete.jar
137137
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
138138
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
139139
<arg value='-cp'/>
140-
<arg value='core/target/test-classes:test/target/test-classes:maven/jruby-complete/target/jruby-complete-1.7.18-SNAPSHOT.jar'/>
140+
<arg value='core/target/test-classes:test/target/test-classes:maven/jruby-complete/target/jruby-complete-1.7.19-SNAPSHOT.jar'/>
141141
<arg value='org.jruby.Main'/>
142142
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
143143
<arg value='-r./test/ruby19_env.rb'/>
@@ -153,7 +153,7 @@ build jruby-complete.jar
153153
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
154154
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
155155
<arg value='-cp'/>
156-
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.18-SNAPSHOT.jar'/>
156+
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.19-SNAPSHOT.jar'/>
157157
<arg value='org.jruby.Main'/>
158158
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
159159
<arg value='-r./test/ruby19_env.rb'/>
@@ -169,7 +169,7 @@ build jruby-complete.jar
169169
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
170170
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
171171
<arg value='-cp'/>
172-
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.18-SNAPSHOT.jar'/>
172+
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.19-SNAPSHOT.jar'/>
173173
<arg value='org.jruby.Main'/>
174174
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
175175
<arg value='-r./test/ruby19_env.rb'/>
@@ -461,7 +461,7 @@ build jruby-complete.jar
461461
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
462462
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
463463
<arg value='-cp'/>
464-
<arg value='core/target/test-classes:test/target/test-classes:maven/jruby-complete/target/jruby-complete-1.7.18-SNAPSHOT.jar'/>
464+
<arg value='core/target/test-classes:test/target/test-classes:maven/jruby-complete/target/jruby-complete-1.7.19-SNAPSHOT.jar'/>
465465
<arg value='org.jruby.Main'/>
466466
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
467467
<arg value='-r./test/ruby19_env.rb'/>
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/***** BEGIN LICENSE BLOCK *****
2+
* Version: EPL 1.0/GPL 2.0/LGPL 2.1
3+
*
4+
* The contents of this file are subject to the Eclipse Public
5+
* License Version 1.0 (the "License"); you may not use this file
6+
* except in compliance with the License. You may obtain a copy of
7+
* the License at http://www.eclipse.org/legal/epl-v10.html
8+
*
9+
* Software distributed under the License is distributed on an "AS
10+
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11+
* implied. See the License for the specific language governing
12+
* rights and limitations under the License.
13+
*
14+
* Copyright (C) 2001 Alan Moore <alan_moore@gmx.net>
15+
* Copyright (C) 2001-2002 Jan Arne Petersen <jpetersen@uni-bonn.de>
16+
* Copyright (C) 2002 Anders Bengtsson <ndrsbngtssn@yahoo.se>
17+
* Copyright (C) 2004 Charles O Nutter <headius@headius.com>
18+
* Copyright (C) 2004 Stefan Matthias Aust <sma@3plus4.de>
19+
*
20+
* Alternatively, the contents of this file may be used under the terms of
21+
* either of the GNU General Public License Version 2 or later (the "GPL"),
22+
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
23+
* in which case the provisions of the GPL or the LGPL are applicable instead
24+
* of those above. If you wish to allow use of your version of this file only
25+
* under the terms of either the GPL or the LGPL, and not to allow others to
26+
* use your version of this file under the terms of the EPL, indicate your
27+
* decision by deleting the provisions above and replace them with the notice
28+
* and other provisions required by the GPL or the LGPL. If you do not delete
29+
* the provisions above, a recipient may use your version of this file under
30+
* the terms of any one of the EPL, the GPL or the LGPL.
31+
***** END LICENSE BLOCK *****/
32+
package org.jruby;
33+
34+
import org.jruby.anno.JRubyClass;
35+
import org.jruby.anno.JRubyMethod;
36+
import org.jruby.ext.jruby.JRubyLibrary;
37+
import org.jruby.internal.runtime.methods.DynamicMethod;
38+
import org.jruby.internal.runtime.methods.ProcMethod;
39+
import org.jruby.internal.runtime.methods.UndefinedMethod;
40+
import org.jruby.runtime.Block;
41+
import org.jruby.runtime.BlockBody;
42+
import org.jruby.runtime.ClassIndex;
43+
import org.jruby.runtime.CompiledBlockCallback19;
44+
import org.jruby.runtime.CompiledBlockLight19;
45+
import org.jruby.runtime.Helpers;
46+
import org.jruby.runtime.ObjectAllocator;
47+
import org.jruby.runtime.PositionAware;
48+
import org.jruby.runtime.ThreadContext;
49+
import org.jruby.runtime.Visibility;
50+
import org.jruby.runtime.builtin.IRubyObject;
51+
import org.jruby.runtime.marshal.DataType;
52+
53+
/**
54+
* The RubyMethod class represents a RubyMethod object.
55+
*
56+
* You can get such a method by calling the "method" method of an object.
57+
*
58+
* Note: This was renamed from Method.java
59+
*
60+
* @author jpetersen
61+
* @since 0.2.3
62+
*/
63+
public abstract class AbstractRubyMethod extends RubyObject implements DataType {
64+
protected RubyModule implementationModule;
65+
protected String methodName;
66+
protected RubyModule originModule;
67+
protected String originName;
68+
protected DynamicMethod method;
69+
70+
protected AbstractRubyMethod(Ruby runtime, RubyClass rubyClass) {
71+
super(runtime, rubyClass);
72+
}
73+
74+
public DynamicMethod getMethod() {
75+
return method;
76+
}
77+
78+
/** Returns the number of arguments a method accepted.
79+
*
80+
* @return the number of arguments of a method.
81+
*/
82+
@JRubyMethod(name = "arity")
83+
public RubyFixnum arity() {
84+
return getRuntime().newFixnum(method.getArity().getValue());
85+
}
86+
87+
@JRubyMethod(name = "eql?", required = 1)
88+
public IRubyObject op_eql19(ThreadContext context, IRubyObject other) {
89+
return op_equal(context, other);
90+
}
91+
92+
public abstract AbstractRubyMethod rbClone();
93+
94+
@JRubyMethod(name = "name")
95+
public IRubyObject name(ThreadContext context) {
96+
return context.runtime.newSymbol(methodName);
97+
}
98+
99+
public String getMethodName() {
100+
return methodName;
101+
}
102+
103+
@JRubyMethod(name = "owner")
104+
public IRubyObject owner(ThreadContext context) {
105+
return implementationModule;
106+
}
107+
108+
@JRubyMethod(name = "source_location")
109+
public IRubyObject source_location(ThreadContext context) {
110+
Ruby runtime = context.runtime;
111+
112+
String filename = getFilename();
113+
if (filename != null) {
114+
return runtime.newArray(runtime.newString(filename), runtime.newFixnum(getLine()));
115+
}
116+
117+
return context.runtime.getNil();
118+
}
119+
120+
public String getFilename() {
121+
DynamicMethod realMethod = method.getRealMethod(); // Follow Aliases
122+
if (realMethod instanceof PositionAware) {
123+
PositionAware poser = (PositionAware) realMethod;
124+
return poser.getFile();
125+
}
126+
return null;
127+
}
128+
129+
public int getLine() {
130+
DynamicMethod realMethod = method.getRealMethod(); // Follow Aliases
131+
if (realMethod instanceof PositionAware) {
132+
PositionAware poser = (PositionAware) realMethod;
133+
return poser.getLine() + 1;
134+
}
135+
return -1;
136+
}
137+
138+
@JRubyMethod(name = "parameters")
139+
public IRubyObject parameters(ThreadContext context) {
140+
return JRubyLibrary.MethodExtensions.methodArgs(this);
141+
}
142+
143+
protected IRubyObject super_method(ThreadContext context, IRubyObject receiver, RubyModule superClass) {
144+
if (superClass == null) return context.runtime.getNil();
145+
146+
DynamicMethod newMethod = superClass.searchMethod(methodName);
147+
if (newMethod == UndefinedMethod.INSTANCE) return context.runtime.getNil();
148+
149+
if (receiver == null) {
150+
return RubyUnboundMethod.newUnboundMethod(superClass, methodName, superClass, originName, newMethod);
151+
} else {
152+
return RubyMethod.newMethod(superClass, methodName, superClass, originName, newMethod, receiver);
153+
}
154+
}
155+
}
156+

core/src/main/java/org/jruby/Ruby.java

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,21 @@
3939
***** END LICENSE BLOCK *****/
4040
package org.jruby;
4141

42+
import org.jruby.ast.ArrayNode;
43+
import org.jruby.ast.BlockNode;
44+
import org.jruby.ast.CallNode;
45+
import org.jruby.ast.FCallNode;
46+
import org.jruby.ast.GlobalAsgnNode;
47+
import org.jruby.ast.GlobalVarNode;
48+
import org.jruby.ast.NewlineNode;
49+
import org.jruby.ast.VCallNode;
50+
import org.jruby.ast.WhileNode;
4251
import org.jruby.compiler.Constantizable;
4352
import org.jruby.compiler.NotCompilableException;
4453
import org.jruby.ext.jruby.JRubyLibrary;
4554
import org.jruby.ext.thread.ThreadLibrary;
4655
import org.jruby.ir.IRScriptBody;
56+
import org.jruby.lexer.yacc.ISourcePosition;
4757
import org.jruby.parser.StaticScope;
4858
import org.objectweb.asm.util.TraceClassVisitor;
4959

@@ -457,12 +467,6 @@ public IRubyObject evalScriptlet(String script, DynamicScope scope) {
457467

458468
try {
459469
return Interpreter.getInstance().execute(this, rootNode, context.getFrameSelf());
460-
} catch (JumpException.ReturnJump rj) {
461-
throw newLocalJumpError(RubyLocalJumpError.Reason.RETURN, (IRubyObject)rj.getValue(), "unexpected return");
462-
} catch (JumpException.BreakJump bj) {
463-
throw newLocalJumpError(RubyLocalJumpError.Reason.BREAK, (IRubyObject)bj.getValue(), "unexpected break");
464-
} catch (JumpException.RedoJump rj) {
465-
throw newLocalJumpError(RubyLocalJumpError.Reason.REDO, (IRubyObject)rj.getValue(), "unexpected redo");
466470
} finally {
467471
context.postEvalScriptlet();
468472
}
@@ -634,6 +638,10 @@ public IRubyObject runWithGetsLoop(Node scriptNode, boolean printing, boolean pr
634638
public IRubyObject runWithGetsLoop(Node scriptNode, boolean printing, boolean processLineEnds, boolean split) {
635639
ThreadContext context = getCurrentContext();
636640

641+
// We do not want special scope types in IR so we ammend the AST tree to contain the elements representing
642+
// a while gets; ...your code...; end
643+
scriptNode = addGetsLoop((RootNode) scriptNode, printing, processLineEnds, split);
644+
637645
Script script = null;
638646
boolean compile = getInstanceConfig().getCompileMode().shouldPrecompileCLI();
639647
if (compile) {
@@ -656,52 +664,50 @@ public IRubyObject runWithGetsLoop(Node scriptNode, boolean printing, boolean pr
656664
}
657665
}
658666

659-
if (processLineEnds) {
660-
getGlobalVariables().set("$\\", getGlobalVariables().get("$/"));
661-
}
662-
663667
// we do pre and post load outside the "body" versions to pre-prepare
664668
// and pre-push the dynamic scope we need for lastline
665669
Helpers.preLoad(context, ((RootNode) scriptNode).getStaticScope().getVariables());
666670

667671
try {
668-
while (RubyKernel.gets(context, getTopSelf(), IRubyObject.NULL_ARRAY).isTrue()) {
669-
loop: while (true) { // Used for the 'redo' command
670-
try {
671-
if (processLineEnds) {
672-
getGlobalVariables().get("$_").callMethod(context, "chop!");
673-
}
674-
675-
if (split) {
676-
getGlobalVariables().set("$F", getGlobalVariables().get("$_").callMethod(context, "split"));
677-
}
678-
679-
if (script != null) {
680-
runScriptBody(script);
681-
} else {
682-
runInterpreterBody(scriptNode);
683-
}
684-
685-
if (printing) RubyKernel.print(context, getKernel(), new IRubyObject[] {getGlobalVariables().get("$_")});
686-
break loop;
687-
} catch (JumpException.RedoJump rj) {
688-
// do nothing, this iteration restarts
689-
} catch (JumpException.NextJump nj) {
690-
// recheck condition
691-
break loop;
692-
} catch (JumpException.BreakJump bj) {
693-
// end loop
694-
return (IRubyObject) bj.getValue();
695-
}
696-
}
672+
if (script != null) {
673+
runScriptBody(script);
674+
} else {
675+
runInterpreterBody(scriptNode);
697676
}
677+
698678
} finally {
699679
Helpers.postLoad(context);
700680
}
701681

702682
return getNil();
703683
}
704684

685+
// Modifies incoming source for -n, -p, and -F
686+
private RootNode addGetsLoop(RootNode oldRoot, boolean printing, boolean processLineEndings, boolean split) {
687+
ISourcePosition pos = oldRoot.getPosition();
688+
BlockNode newBody = new BlockNode(pos);
689+
690+
if (processLineEndings) newBody.add(new GlobalAsgnNode(pos, "$\\", new GlobalVarNode(pos, "$/")));
691+
692+
BlockNode whileBody;
693+
if (oldRoot.getBodyNode() instanceof BlockNode) { // common case n stmts
694+
whileBody = (BlockNode) oldRoot.getBodyNode();
695+
} else { // single expr script
696+
whileBody = new BlockNode(pos);
697+
whileBody.add(oldRoot.getBodyNode());
698+
}
699+
700+
GlobalVarNode dollarUnderscore = new GlobalVarNode(pos, "$_");
701+
702+
newBody.add(new WhileNode(pos, new VCallNode(pos, "gets"), whileBody));
703+
704+
if (printing) whileBody.prepend(new FCallNode(pos, "puts", new ArrayNode(pos, dollarUnderscore), null));
705+
if (split) whileBody.prepend(new GlobalAsgnNode(pos, "$F", new CallNode(pos, dollarUnderscore, "split", null, null)));
706+
if (processLineEndings) whileBody.prepend(new CallNode(pos, dollarUnderscore, "chop!", null, null));
707+
708+
return new RootNode(pos, oldRoot.getScope(), newBody);
709+
}
710+
705711
/**
706712
* Run the specified script without any of the loop-processing wrapper
707713
* code.
@@ -1706,7 +1712,6 @@ private void initBuiltins() {
17061712
addLazyBuiltin("io/wait.jar", "io/wait", "org.jruby.ext.io.wait.IOWaitLibrary");
17071713
addLazyBuiltin("etc.jar", "etc", "org.jruby.ext.etc.EtcLibrary");
17081714
addLazyBuiltin("weakref.rb", "weakref", "org.jruby.ext.weakref.WeakRefLibrary");
1709-
addLazyBuiltin("native_delegate.jar", "native_delegate", "org.jruby.ext.delegate.NativeDelegateLibrary");
17101715
addLazyBuiltin("timeout.rb", "timeout", "org.jruby.ext.timeout.Timeout");
17111716
addLazyBuiltin("socket.jar", "socket", "org.jruby.ext.socket.SocketLibrary");
17121717
addLazyBuiltin("rbconfig.rb", "rbconfig", "org.jruby.ext.rbconfig.RbConfigLibrary");
@@ -1724,7 +1729,6 @@ private void initBuiltins() {
17241729

17251730
// TODO: implement something for these?
17261731
addBuiltinIfAllowed("continuation.rb", Library.DUMMY);
1727-
addBuiltinIfAllowed("io/nonblock.rb", Library.DUMMY);
17281732

17291733
// for backward compatibility
17301734
loadService.provide("enumerator.jar"); // can't be in RubyEnumerator because LoadService isn't ready then

core/src/main/java/org/jruby/RubyGC.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,7 @@ public static IRubyObject stress_set(ThreadContext context, IRubyObject recv, IR
108108
@JRubyMethod(module = true, visibility = PRIVATE)
109109
public static IRubyObject count(ThreadContext context, IRubyObject recv) {
110110
try {
111-
int count = 0;
112-
for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
113-
count += bean.getCollectionCount();
114-
}
111+
int count = getCollectionCount();
115112
return context.runtime.newFixnum(count);
116113
} catch (Throwable t) {
117114
return RubyFixnum.minus_one(context.runtime);
@@ -122,4 +119,21 @@ private static void emptyImplementationWarning(Ruby runtime, ID id, String name)
122119
runtime.getWarnings().warnOnce(id,
123120
name + " does nothing on JRuby");
124121
}
122+
123+
public static int getCollectionCount() {
124+
int count = 0;
125+
for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
126+
count += bean.getCollectionCount();
127+
}
128+
return count;
129+
}
130+
131+
public static long getCollectionTime() {
132+
long time = 0;
133+
for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
134+
time += bean.getCollectionTime();
135+
}
136+
return time;
137+
}
138+
125139
}

core/src/main/java/org/jruby/RubyIO.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,10 +2303,11 @@ private IRubyObject gets(ThreadContext context, IRubyObject[] args) {
23032303
}
23042304

23052305
public boolean getBlocking() {
2306-
if (openFile.selectChannel() != null) {
2307-
return openFile.selectChannel().isBlocking();
2308-
}
2309-
return true;
2306+
return openFile.isBlocking();
2307+
}
2308+
2309+
public void setBlocking(boolean blocking) {
2310+
openFile.setBlocking(getRuntime(), blocking);
23102311
}
23112312

23122313
@JRubyMethod(name = "fcntl")

0 commit comments

Comments
 (0)