Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Jan 7, 2015
2 parents 672834f + 4948b9b commit dc764f8
Show file tree
Hide file tree
Showing 227 changed files with 2,873 additions and 1,598 deletions.
10 changes: 5 additions & 5 deletions antlib/extra.xml
Expand Up @@ -25,7 +25,7 @@ build jruby-complete.jar
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
<arg value='-cp'/>
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.18-SNAPSHOT.jar'/>
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.19-SNAPSHOT.jar'/>
<arg value='org.jruby.Main'/>
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
<arg value='-r./test/ruby19_env.rb'/>
Expand Down Expand Up @@ -137,7 +137,7 @@ build jruby-complete.jar
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
<arg value='-cp'/>
<arg value='core/target/test-classes:test/target/test-classes:maven/jruby-complete/target/jruby-complete-1.7.18-SNAPSHOT.jar'/>
<arg value='core/target/test-classes:test/target/test-classes:maven/jruby-complete/target/jruby-complete-1.7.19-SNAPSHOT.jar'/>
<arg value='org.jruby.Main'/>
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
<arg value='-r./test/ruby19_env.rb'/>
Expand All @@ -153,7 +153,7 @@ build jruby-complete.jar
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
<arg value='-cp'/>
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.18-SNAPSHOT.jar'/>
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.19-SNAPSHOT.jar'/>
<arg value='org.jruby.Main'/>
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
<arg value='-r./test/ruby19_env.rb'/>
Expand All @@ -169,7 +169,7 @@ build jruby-complete.jar
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
<arg value='-cp'/>
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.18-SNAPSHOT.jar'/>
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.19-SNAPSHOT.jar'/>
<arg value='org.jruby.Main'/>
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
<arg value='-r./test/ruby19_env.rb'/>
Expand Down Expand Up @@ -461,7 +461,7 @@ build jruby-complete.jar
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
<arg value='-cp'/>
<arg value='core/target/test-classes:test/target/test-classes:maven/jruby-complete/target/jruby-complete-1.7.18-SNAPSHOT.jar'/>
<arg value='core/target/test-classes:test/target/test-classes:maven/jruby-complete/target/jruby-complete-1.7.19-SNAPSHOT.jar'/>
<arg value='org.jruby.Main'/>
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
<arg value='-r./test/ruby19_env.rb'/>
Expand Down
156 changes: 156 additions & 0 deletions core/src/main/java/org/jruby/AbstractRubyMethod.java
@@ -0,0 +1,156 @@
/***** BEGIN LICENSE BLOCK *****
* Version: EPL 1.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Eclipse Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.eclipse.org/legal/epl-v10.html
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Copyright (C) 2001 Alan Moore <alan_moore@gmx.net>
* Copyright (C) 2001-2002 Jan Arne Petersen <jpetersen@uni-bonn.de>
* Copyright (C) 2002 Anders Bengtsson <ndrsbngtssn@yahoo.se>
* Copyright (C) 2004 Charles O Nutter <headius@headius.com>
* Copyright (C) 2004 Stefan Matthias Aust <sma@3plus4.de>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the EPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the EPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****/
package org.jruby;

import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.ext.jruby.JRubyLibrary;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.internal.runtime.methods.ProcMethod;
import org.jruby.internal.runtime.methods.UndefinedMethod;
import org.jruby.runtime.Block;
import org.jruby.runtime.BlockBody;
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.CompiledBlockCallback19;
import org.jruby.runtime.CompiledBlockLight19;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.PositionAware;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.marshal.DataType;

/**
* The RubyMethod class represents a RubyMethod object.
*
* You can get such a method by calling the "method" method of an object.
*
* Note: This was renamed from Method.java
*
* @author jpetersen
* @since 0.2.3
*/
public abstract class AbstractRubyMethod extends RubyObject implements DataType {
protected RubyModule implementationModule;
protected String methodName;
protected RubyModule originModule;
protected String originName;
protected DynamicMethod method;

protected AbstractRubyMethod(Ruby runtime, RubyClass rubyClass) {
super(runtime, rubyClass);
}

public DynamicMethod getMethod() {
return method;
}

/** Returns the number of arguments a method accepted.
*
* @return the number of arguments of a method.
*/
@JRubyMethod(name = "arity")
public RubyFixnum arity() {
return getRuntime().newFixnum(method.getArity().getValue());
}

@JRubyMethod(name = "eql?", required = 1)
public IRubyObject op_eql19(ThreadContext context, IRubyObject other) {
return op_equal(context, other);
}

public abstract AbstractRubyMethod rbClone();

@JRubyMethod(name = "name")
public IRubyObject name(ThreadContext context) {
return context.runtime.newSymbol(methodName);
}

public String getMethodName() {
return methodName;
}

@JRubyMethod(name = "owner")
public IRubyObject owner(ThreadContext context) {
return implementationModule;
}

@JRubyMethod(name = "source_location")
public IRubyObject source_location(ThreadContext context) {
Ruby runtime = context.runtime;

String filename = getFilename();
if (filename != null) {
return runtime.newArray(runtime.newString(filename), runtime.newFixnum(getLine()));
}

return context.runtime.getNil();
}

public String getFilename() {
DynamicMethod realMethod = method.getRealMethod(); // Follow Aliases
if (realMethod instanceof PositionAware) {
PositionAware poser = (PositionAware) realMethod;
return poser.getFile();
}
return null;
}

public int getLine() {
DynamicMethod realMethod = method.getRealMethod(); // Follow Aliases
if (realMethod instanceof PositionAware) {
PositionAware poser = (PositionAware) realMethod;
return poser.getLine() + 1;
}
return -1;
}

@JRubyMethod(name = "parameters")
public IRubyObject parameters(ThreadContext context) {
return JRubyLibrary.MethodExtensions.methodArgs(this);
}

protected IRubyObject super_method(ThreadContext context, IRubyObject receiver, RubyModule superClass) {
if (superClass == null) return context.runtime.getNil();

DynamicMethod newMethod = superClass.searchMethod(methodName);
if (newMethod == UndefinedMethod.INSTANCE) return context.runtime.getNil();

if (receiver == null) {
return RubyUnboundMethod.newUnboundMethod(superClass, methodName, superClass, originName, newMethod);
} else {
return RubyMethod.newMethod(superClass, methodName, superClass, originName, newMethod, receiver);
}
}
}

86 changes: 45 additions & 41 deletions core/src/main/java/org/jruby/Ruby.java
Expand Up @@ -39,11 +39,21 @@
***** END LICENSE BLOCK *****/
package org.jruby;

import org.jruby.ast.ArrayNode;
import org.jruby.ast.BlockNode;
import org.jruby.ast.CallNode;
import org.jruby.ast.FCallNode;
import org.jruby.ast.GlobalAsgnNode;
import org.jruby.ast.GlobalVarNode;
import org.jruby.ast.NewlineNode;
import org.jruby.ast.VCallNode;
import org.jruby.ast.WhileNode;
import org.jruby.compiler.Constantizable;
import org.jruby.compiler.NotCompilableException;
import org.jruby.ext.jruby.JRubyLibrary;
import org.jruby.ext.thread.ThreadLibrary;
import org.jruby.ir.IRScriptBody;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.parser.StaticScope;
import org.objectweb.asm.util.TraceClassVisitor;

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

try {
return Interpreter.getInstance().execute(this, rootNode, context.getFrameSelf());
} catch (JumpException.ReturnJump rj) {
throw newLocalJumpError(RubyLocalJumpError.Reason.RETURN, (IRubyObject)rj.getValue(), "unexpected return");
} catch (JumpException.BreakJump bj) {
throw newLocalJumpError(RubyLocalJumpError.Reason.BREAK, (IRubyObject)bj.getValue(), "unexpected break");
} catch (JumpException.RedoJump rj) {
throw newLocalJumpError(RubyLocalJumpError.Reason.REDO, (IRubyObject)rj.getValue(), "unexpected redo");
} finally {
context.postEvalScriptlet();
}
Expand Down Expand Up @@ -634,6 +638,10 @@ public IRubyObject runWithGetsLoop(Node scriptNode, boolean printing, boolean pr
public IRubyObject runWithGetsLoop(Node scriptNode, boolean printing, boolean processLineEnds, boolean split) {
ThreadContext context = getCurrentContext();

// We do not want special scope types in IR so we ammend the AST tree to contain the elements representing
// a while gets; ...your code...; end
scriptNode = addGetsLoop((RootNode) scriptNode, printing, processLineEnds, split);

Script script = null;
boolean compile = getInstanceConfig().getCompileMode().shouldPrecompileCLI();
if (compile) {
Expand All @@ -656,52 +664,50 @@ public IRubyObject runWithGetsLoop(Node scriptNode, boolean printing, boolean pr
}
}

if (processLineEnds) {
getGlobalVariables().set("$\\", getGlobalVariables().get("$/"));
}

// we do pre and post load outside the "body" versions to pre-prepare
// and pre-push the dynamic scope we need for lastline
Helpers.preLoad(context, ((RootNode) scriptNode).getStaticScope().getVariables());

try {
while (RubyKernel.gets(context, getTopSelf(), IRubyObject.NULL_ARRAY).isTrue()) {
loop: while (true) { // Used for the 'redo' command
try {
if (processLineEnds) {
getGlobalVariables().get("$_").callMethod(context, "chop!");
}

if (split) {
getGlobalVariables().set("$F", getGlobalVariables().get("$_").callMethod(context, "split"));
}

if (script != null) {
runScriptBody(script);
} else {
runInterpreterBody(scriptNode);
}

if (printing) RubyKernel.print(context, getKernel(), new IRubyObject[] {getGlobalVariables().get("$_")});
break loop;
} catch (JumpException.RedoJump rj) {
// do nothing, this iteration restarts
} catch (JumpException.NextJump nj) {
// recheck condition
break loop;
} catch (JumpException.BreakJump bj) {
// end loop
return (IRubyObject) bj.getValue();
}
}
if (script != null) {
runScriptBody(script);
} else {
runInterpreterBody(scriptNode);
}

} finally {
Helpers.postLoad(context);
}

return getNil();
}

// Modifies incoming source for -n, -p, and -F
private RootNode addGetsLoop(RootNode oldRoot, boolean printing, boolean processLineEndings, boolean split) {
ISourcePosition pos = oldRoot.getPosition();
BlockNode newBody = new BlockNode(pos);

if (processLineEndings) newBody.add(new GlobalAsgnNode(pos, "$\\", new GlobalVarNode(pos, "$/")));

BlockNode whileBody;
if (oldRoot.getBodyNode() instanceof BlockNode) { // common case n stmts
whileBody = (BlockNode) oldRoot.getBodyNode();
} else { // single expr script
whileBody = new BlockNode(pos);
whileBody.add(oldRoot.getBodyNode());
}

GlobalVarNode dollarUnderscore = new GlobalVarNode(pos, "$_");

newBody.add(new WhileNode(pos, new VCallNode(pos, "gets"), whileBody));

if (printing) whileBody.prepend(new FCallNode(pos, "puts", new ArrayNode(pos, dollarUnderscore), null));
if (split) whileBody.prepend(new GlobalAsgnNode(pos, "$F", new CallNode(pos, dollarUnderscore, "split", null, null)));
if (processLineEndings) whileBody.prepend(new CallNode(pos, dollarUnderscore, "chop!", null, null));

return new RootNode(pos, oldRoot.getScope(), newBody);
}

/**
* Run the specified script without any of the loop-processing wrapper
* code.
Expand Down Expand Up @@ -1706,7 +1712,6 @@ private void initBuiltins() {
addLazyBuiltin("io/wait.jar", "io/wait", "org.jruby.ext.io.wait.IOWaitLibrary");
addLazyBuiltin("etc.jar", "etc", "org.jruby.ext.etc.EtcLibrary");
addLazyBuiltin("weakref.rb", "weakref", "org.jruby.ext.weakref.WeakRefLibrary");
addLazyBuiltin("native_delegate.jar", "native_delegate", "org.jruby.ext.delegate.NativeDelegateLibrary");
addLazyBuiltin("timeout.rb", "timeout", "org.jruby.ext.timeout.Timeout");
addLazyBuiltin("socket.jar", "socket", "org.jruby.ext.socket.SocketLibrary");
addLazyBuiltin("rbconfig.rb", "rbconfig", "org.jruby.ext.rbconfig.RbConfigLibrary");
Expand All @@ -1724,7 +1729,6 @@ private void initBuiltins() {

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

// for backward compatibility
loadService.provide("enumerator.jar"); // can't be in RubyEnumerator because LoadService isn't ready then
Expand Down
22 changes: 18 additions & 4 deletions core/src/main/java/org/jruby/RubyGC.java
Expand Up @@ -108,10 +108,7 @@ public static IRubyObject stress_set(ThreadContext context, IRubyObject recv, IR
@JRubyMethod(module = true, visibility = PRIVATE)
public static IRubyObject count(ThreadContext context, IRubyObject recv) {
try {
int count = 0;
for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
count += bean.getCollectionCount();
}
int count = getCollectionCount();
return context.runtime.newFixnum(count);
} catch (Throwable t) {
return RubyFixnum.minus_one(context.runtime);
Expand All @@ -122,4 +119,21 @@ private static void emptyImplementationWarning(Ruby runtime, ID id, String name)
runtime.getWarnings().warnOnce(id,
name + " does nothing on JRuby");
}

public static int getCollectionCount() {
int count = 0;
for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
count += bean.getCollectionCount();
}
return count;
}

public static long getCollectionTime() {
long time = 0;
for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
time += bean.getCollectionTime();
}
return time;
}

}
9 changes: 5 additions & 4 deletions core/src/main/java/org/jruby/RubyIO.java
Expand Up @@ -2303,10 +2303,11 @@ private IRubyObject gets(ThreadContext context, IRubyObject[] args) {
}

public boolean getBlocking() {
if (openFile.selectChannel() != null) {
return openFile.selectChannel().isBlocking();
}
return true;
return openFile.isBlocking();
}

public void setBlocking(boolean blocking) {
openFile.setBlocking(getRuntime(), blocking);
}

@JRubyMethod(name = "fcntl")
Expand Down

0 comments on commit dc764f8

Please sign in to comment.