Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
Conflicts:
	tool/jt.rb
	truffle/src/main/java/org/jruby/truffle/nodes/control/TraceNode.java
	truffle/src/main/java/org/jruby/truffle/runtime/subsystems/AttachmentsManager.java
chrisseaton committed Oct 5, 2015
2 parents 6bad2bd + b204d86 commit 3b3bea1
Showing 17 changed files with 136 additions and 36 deletions.
7 changes: 5 additions & 2 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -177,6 +177,7 @@ private static class EnsureBlockInfo {
Label end;
Label dummyRescueBlockLabel;
Variable savedGlobalException;
boolean needsBacktrace;

// Label of block that will rescue exceptions raised by ensure code
Label bodyRescuer;
@@ -201,6 +202,7 @@ public EnsureBlockInfo(IRScope s, RescueNode n, IRLoop l, Label bodyRescuer) {
innermostLoop = l;
matchingRescueNode = n;
this.bodyRescuer = bodyRescuer;
needsBacktrace = true;
}

public void addInstr(Instr i) {
@@ -231,6 +233,8 @@ public void cloneIntoHostScope(IRBuilder builder) {

// $! should be restored before the ensure block is run
if (savedGlobalException != null) {
// We need make sure on all outgoing paths in optimized short-hand rescues we restore the backtrace
if (!needsBacktrace) builder.addInstr(builder.manager.needsBacktrace(true));
builder.addInstr(new PutGlobalVarInstr("$!", savedGlobalException));
}

@@ -3047,6 +3051,7 @@ private Operand buildRescueInternal(RescueNode rescueNode, EnsureBlockInfo ensur
Label rBeginLabel = getNewLabel();
Label rEndLabel = ensure.end;
Label rescueLabel = getNewLabel(); // Label marking start of the first rescue code.
ensure.needsBacktrace = needsBacktrace;

addInstr(new LabelInstr(rBeginLabel));

@@ -3121,8 +3126,6 @@ private Operand buildRescueInternal(RescueNode rescueNode, EnsureBlockInfo ensur
// Build the actual rescue block(s)
buildRescueBodyInternal(rescueNode.getRescueNode(), rv, exc, rEndLabel);

if (!needsBacktrace) addInstr(manager.needsBacktrace(true));

activeRescueBlockStack.pop();
return rv;
}
Original file line number Diff line number Diff line change
@@ -56,7 +56,8 @@ module SecureRandom
def self.random_bytes(n=nil)
n ||= 16

if defined? OpenSSL::Random
# TODO (pitr 04-Oct-2015): pending PR https://github.com/rubysl/rubysl-securerandom/pull/1
if defined?(OpenSSL::Random) && OpenSSL::Random != Random
@pid = 0 if !defined?(@pid)
pid = $$
if @pid != pid
6 changes: 5 additions & 1 deletion lib/ruby/truffle/truffle/zlib.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1
@@ -53,6 +53,10 @@ def self.crc32(*args)
Truffle::Zlib.crc32(*args)
end

def self.adler32(*args)
Truffle::Zlib.adler32(*args)
end

module Deflate

def self.deflate(message, level=DEFAULT_COMPRESSION)
8 changes: 6 additions & 2 deletions spec/ruby/language/rescue_spec.rb
Original file line number Diff line number Diff line change
@@ -76,25 +76,29 @@ def exception_list
end

it "will execute an else block only if no exceptions were raised" do
begin
result = begin
ScratchPad << :one
rescue
ScratchPad << :does_not_run
else
ScratchPad << :two
:val
end
result.should == :val
ScratchPad.recorded.should == [:one, :two]
end

it "will not execute an else block if an exception was raised" do
begin
result = begin
ScratchPad << :one
raise "an error occurred"
rescue
ScratchPad << :two
:val
else
ScratchPad << :does_not_run
end
result.should == :val
ScratchPad.recorded.should == [:one, :two]
end

5 changes: 0 additions & 5 deletions spec/truffle/tags/library/zlib/adler32_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -61,6 +61,7 @@ class JRubyTruffleRunner
debug: ['-d', '--debug', 'JVM remote debugging', assign_new_value, false],
require: ['-r', '--require FILE', 'Files to require, same as Ruby\'s -r', add_to_array, []],
require_pattern: ['--require-pattern DIR_GLOB_PATTERN', 'Files matching the pattern will be required', add_to_array, []],
exclude_pattern: ['--exclude-pattern REGEXP', 'Files matching the regexp will not be required by --require-pattern', add_to_array, []],
load_path: ['-I', '--load-path LOAD_PATH', 'Paths to add to load path, same as Ruby\'s -I', add_to_array, []],
executable: ['-S', '--executable NAME', 'finds and runs an executable of a gem', assign_new_value, nil],
jexception: ['--jexception', 'print Java exceptions', assign_new_value, false]
@@ -310,7 +311,10 @@ def subcommand_run(vm_options, rest)

core_load_path = "#{jruby_path}/truffle/src/main/ruby"
@options[:run][:require_pattern].each do |pattern|
Dir.glob(pattern) { |v| @options[:run][:require] << File.expand_path(v) }
Dir.glob(pattern) do |file|
next if @options[:run][:exclude_pattern].any? { |p| /#{p}/ =~ file }
@options[:run][:require] << File.expand_path(file)
end
end

cmd_options = [
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ public SetTopLevelBindingNode(RubyContext context, SourceSection sourceSection)

@Override
public Object execute(VirtualFrame frame) {
final DynamicObject binding = Layouts.BINDING.createBinding(getContext().getCoreLibrary().getBindingFactory(), frame.materialize());
final DynamicObject binding = BindingNodes.createBinding(getContext(), frame.materialize());
Layouts.MODULE.getFields(getContext().getCoreLibrary().getObjectClass()).setConstant(this, "TOPLEVEL_BINDING", binding);
return nil();
}
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@ public MaterializedFrame visitFrame(FrameInstance frameInstance) {

});

return Layouts.BINDING.createBinding(getContext().getCoreLibrary().getBindingFactory(), frame);
return BindingNodes.createBinding(getContext(), frame);
}

}
Original file line number Diff line number Diff line change
@@ -70,7 +70,10 @@ public Object execute(VirtualFrame frame) {
}

elseProfile.enter();
elsePart.executeVoid(frame);

if (elsePart != null) {
result = elsePart.execute(frame);
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -342,7 +342,7 @@ public DynamicObject createString(VirtualFrame frame, DynamicObject value, Dynam
// TODO (pitr 21-Jun-2015): raise on underflow

private DynamicObject createWithMode(VirtualFrame frame, Type value, DynamicObject self,
String constantName, String errorMessage) {
String constantName, String errorMessage) {
setupModeCall();
setupGetIntegerConstant();
setupBooleanCast();
@@ -1183,7 +1183,7 @@ private void setupLimitIntegerCast() {
"!isNormalZero(b)" })
public Object divmod(VirtualFrame frame, DynamicObject a, DynamicObject b) {
final BigDecimal[] result = divmodBigDecimal(Layouts.BIG_DECIMAL.getValue(a), Layouts.BIG_DECIMAL.getValue(b));
Object[] store = new Object[]{createBigDecimal(frame, result[0]), createBigDecimal(frame, result[1])};
Object[] store = new Object[]{ createBigDecimal(frame, result[0]), createBigDecimal(frame, result[1]) };
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), store, store.length);
}

@@ -1193,7 +1193,7 @@ public Object divmod(VirtualFrame frame, DynamicObject a, DynamicObject b) {
"isNormalZero(a)",
"!isNormalZero(b)" })
public Object divmodZeroDividend(VirtualFrame frame, DynamicObject a, DynamicObject b) {
Object[] store = new Object[]{createBigDecimal(frame, BigDecimal.ZERO), createBigDecimal(frame, BigDecimal.ZERO)};
Object[] store = new Object[]{ createBigDecimal(frame, BigDecimal.ZERO), createBigDecimal(frame, BigDecimal.ZERO) };
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), store, store.length);
}

@@ -1214,7 +1214,7 @@ public Object divmodSpecial(VirtualFrame frame, DynamicObject a, DynamicObject b
final Type bType = Layouts.BIG_DECIMAL.getType(b);

if (aType == Type.NAN || bType == Type.NAN) {
Object[] store = new Object[]{createBigDecimal(frame, Type.NAN), createBigDecimal(frame, Type.NAN)};
Object[] store = new Object[]{ createBigDecimal(frame, Type.NAN), createBigDecimal(frame, Type.NAN) };
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), store, store.length);
}

@@ -1224,7 +1224,7 @@ public Object divmodSpecial(VirtualFrame frame, DynamicObject a, DynamicObject b
}

if (aType == Type.NEGATIVE_ZERO || (aType == Type.NORMAL && isNormalZero(a))) {
Object[] store = new Object[]{createBigDecimal(frame, BigDecimal.ZERO), createBigDecimal(frame, BigDecimal.ZERO)};
Object[] store = new Object[]{ createBigDecimal(frame, BigDecimal.ZERO), createBigDecimal(frame, BigDecimal.ZERO) };
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), store, store.length);
}

@@ -1238,12 +1238,12 @@ public Object divmodSpecial(VirtualFrame frame, DynamicObject a, DynamicObject b

final Type type = new Type[]{ Type.NEGATIVE_INFINITY, Type.NAN, Type.POSITIVE_INFINITY }[sign + 1];

Object[] store = new Object[]{createBigDecimal(frame, type), createBigDecimal(frame, Type.NAN)};
Object[] store = new Object[]{ createBigDecimal(frame, type), createBigDecimal(frame, Type.NAN) };
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), store, store.length);
}

if (bType == Type.POSITIVE_INFINITY || bType == Type.NEGATIVE_INFINITY) {
Object[] store = new Object[]{createBigDecimal(frame, BigDecimal.ZERO), createBigDecimal(frame, a)};
Object[] store = new Object[]{ createBigDecimal(frame, BigDecimal.ZERO), createBigDecimal(frame, a) };
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), store, store.length);
}

@@ -1916,8 +1916,8 @@ public PrecsNode(RubyContext context, SourceSection sourceSection) {
public Object precsNormal(DynamicObject value) {
final BigDecimal bigDecimalValue = Layouts.BIG_DECIMAL.getValue(value).abs();
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), new int[]{
bigDecimalValue.stripTrailingZeros().unscaledValue().toString().length(),
nearestBiggerMultipleOf4(bigDecimalValue.unscaledValue().toString().length())}, 2);
bigDecimalValue.stripTrailingZeros().unscaledValue().toString().length(),
nearestBiggerMultipleOf4(bigDecimalValue.unscaledValue().toString().length()) }, 2);
}

@Specialization(guards = "!isNormal(value)")
62 changes: 61 additions & 1 deletion truffle/src/main/java/org/jruby/truffle/nodes/ext/ZlibNodes.java
Original file line number Diff line number Diff line change
@@ -25,10 +25,12 @@
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

import java.lang.reflect.Field;
import java.util.zip.CRC32;
import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
import java.util.zip.Adler32;

@CoreClass(name = "Truffle::Zlib")
public abstract class ZlibNodes {
@@ -69,7 +71,7 @@ public long crc32(DynamicObject message, long initial) {
}

@TruffleBoundary
@Specialization(guards = {"isRubyString(message)", "isRubyBignum(initial)"})
@Specialization(guards = { "isRubyString(message)", "isRubyBignum(initial)" })
public long crc32(DynamicObject message, DynamicObject initial) {
throw new RaiseException(getContext().getCoreLibrary().rangeError("bignum too big to convert into `unsigned long'", this));
}
@@ -148,4 +150,62 @@ public DynamicObject inflate(DynamicObject message) {

}

@CoreMethod(names = "adler32", isModuleFunction = true, required = 0, optional = 2, lowerFixnumParameters = 1)
public abstract static class Adler32Node extends CoreMethodArrayArgumentsNode {

private static final Field ADLER_PRIVATE_FIELD;

static {
try {
ADLER_PRIVATE_FIELD = Adler32.class.getDeclaredField("adler");
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
}
ADLER_PRIVATE_FIELD.setAccessible(true);
}

public Adler32Node(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public long adler32(NotProvided string, NotProvided adler) {
return new Adler32().getValue();
}

@Specialization
@TruffleBoundary
public long adler32(DynamicObject string, NotProvided adler) {
final ByteList bytes = Layouts.STRING.getByteList(string);
final Adler32 adler32 = new Adler32();
adler32.update(bytes.unsafeBytes());
return adler32.getValue();
}

@Specialization
@TruffleBoundary
public long adler32(DynamicObject string, int adler) {
final ByteList bytes = Layouts.STRING.getByteList(string);
final Adler32 adler32 = new Adler32();

try {
ADLER_PRIVATE_FIELD.setInt(adler32, adler);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}

adler32.update(bytes.unsafeBytes());
return adler32.getValue();
}

@Specialization(guards = "isRubyBignum(adler)")
@TruffleBoundary
public long adler32(DynamicObject string, DynamicObject adler) {
throw new RaiseException(
getContext().getCoreLibrary().rangeError("bignum too big to convert into `unsigned long'", this));

}

}

}
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
* Declaration context for methods:
* <ul>
* <li>visibility</li>
* <li>default definee (which module to define on)</li>
* <li>default definee / current module (which module to define on)</li>
* </ul>
*/
public class DeclarationContext {
@@ -62,11 +62,15 @@ public static void changeVisibility(Frame frame, Visibility newVisibility) {
final Frame visibilityFrame = lookupVisibility(frame);
final DeclarationContext oldDeclarationContext = RubyArguments.getDeclarationContext(visibilityFrame.getArguments());
if (newVisibility != oldDeclarationContext.visibility) {
final DeclarationContext newDeclarationContext = new DeclarationContext(newVisibility, oldDeclarationContext.defaultDefinee);
RubyArguments.setDeclarationContext(visibilityFrame.getArguments(), newDeclarationContext);
RubyArguments.setDeclarationContext(visibilityFrame.getArguments(), oldDeclarationContext.withVisibility(newVisibility));
}
}

private DeclarationContext withVisibility(Visibility visibility) {
assert visibility != null;
return new DeclarationContext(visibility, defaultDefinee);
}

public DynamicObject getModuleToDefineMethods(VirtualFrame frame, RubyContext context, SingletonClassNode singletonClassNode) {
switch (defaultDefinee) {
case LEXICAL_SCOPE:
@@ -82,7 +86,7 @@ public DynamicObject getModuleToDefineMethods(VirtualFrame frame, RubyContext co
}

public static final DeclarationContext MODULE = new DeclarationContext(Visibility.PUBLIC, DefaultDefinee.LEXICAL_SCOPE);
public static final DeclarationContext METHOD = new DeclarationContext(null, DefaultDefinee.LEXICAL_SCOPE);
public static final DeclarationContext METHOD = new DeclarationContext(Visibility.PUBLIC, DefaultDefinee.LEXICAL_SCOPE);
public static final DeclarationContext BLOCK = new DeclarationContext(null, DefaultDefinee.LEXICAL_SCOPE);
public static final DeclarationContext TOP_LEVEL = new DeclarationContext(Visibility.PRIVATE, DefaultDefinee.LEXICAL_SCOPE);
public static final DeclarationContext INSTANCE_EVAL = new DeclarationContext(Visibility.PUBLIC, DefaultDefinee.SINGLETON_CLASS);
Original file line number Diff line number Diff line change
@@ -42,8 +42,7 @@ public MethodDefinitionNode(RubyContext context, SourceSection sourceSection, St
public InternalMethod executeMethod(VirtualFrame frame) {
final DynamicObject dummyModule = getContext().getCoreLibrary().getObjectClass();
final Visibility dummyVisibility = Visibility.PUBLIC;
return new InternalMethod(sharedMethodInfo, name, dummyModule, dummyVisibility, false, callTarget,
frame.materialize() /* Currently used for visibility, will be fixed when we keep visibility in some better place */);
return new InternalMethod(sharedMethodInfo, name, dummyModule, dummyVisibility, false, callTarget, null);
}

@Override
Original file line number Diff line number Diff line change
@@ -147,8 +147,8 @@ public static RubyConstant lookupScopedConstant(RubyContext context, DynamicObje
}

while ((next = fullName.indexOf("::", start)) != -1) {
String segment = fullName.substring(start, next);
RubyConstant constant = lookupConstantWithInherit(context, module, segment, inherit, currentNode);
final String segment = fullName.substring(start, next);
final RubyConstant constant = lookupConstantWithInherit(context, module, segment, inherit, currentNode);
if (constant == null) {
return null;
} else if (RubyGuards.isRubyModule(constant.getValue())) {
@@ -160,7 +160,12 @@ public static RubyConstant lookupScopedConstant(RubyContext context, DynamicObje
start = next + 2;
}

String lastSegment = fullName.substring(start);
final String lastSegment = fullName.substring(start);
if (!IdUtil.isValidConstantName19(lastSegment)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(context.getCoreLibrary().nameError(String.format("wrong constant name %s", fullName), fullName, currentNode));
}

return lookupConstantWithInherit(context, module, lastSegment, inherit, currentNode);
}

Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.nodes.control.SequenceNode;
import org.jruby.truffle.nodes.core.BindingNodes;
import org.jruby.truffle.nodes.core.LoadRequiredLibrariesNode;
import org.jruby.truffle.nodes.core.SetTopLevelBindingNode;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
@@ -228,7 +229,7 @@ public Object inlineRubyHelper(Node currentNode, String expression, Object... ar

public Object inlineRubyHelper(Node currentNode, Frame frame, String expression, Object... arguments) {
final MaterializedFrame evalFrame = setupInlineRubyFrame(frame, arguments);
final DynamicObject binding = Layouts.BINDING.createBinding(getCoreLibrary().getBindingFactory(), evalFrame);
final DynamicObject binding = BindingNodes.createBinding(this, evalFrame);
return eval(ParserContext.INLINE, ByteList.create(expression), binding, true, "inline-ruby", currentNode);
}

Original file line number Diff line number Diff line change
@@ -13,7 +13,9 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyCallStack;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.array.ArrayUtils;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.truffle.runtime.loader.SourceLoader;
@@ -44,6 +46,21 @@ public static BacktraceFormatter createDefaultFormatter(RubyContext context) {
return new BacktraceFormatter(context, flags);
}

// for debugging
public static List<String> rubyBacktrace(RubyContext context) {
return BacktraceFormatter.createDefaultFormatter(context).formatBacktrace(null, RubyCallStack.getBacktrace(null));
}

// for debugging
public static String printableRubyBacktrace(RubyContext context) {
final StringBuilder builder = new StringBuilder();
for (String line : rubyBacktrace(context)) {
builder.append("\n");
builder.append(line);
}
return builder.toString().substring(1);
}

public BacktraceFormatter(RubyContext context, EnumSet<FormattingFlags> flags) {
this.context = context;
this.flags = flags;
Original file line number Diff line number Diff line change
@@ -2646,7 +2646,7 @@ public RubyNode visitRescueNode(org.jruby.ast.RescueNode node) {
RubyNode elsePart;

if (node.getElseNode() == null || node.getElseNode().getPosition() == InvalidSourcePosition.INSTANCE) {
elsePart = nilNode(sourceSection);
elsePart = null; //nilNode(sourceSection);
} else {
elsePart = node.getElseNode().accept(this);
}

0 comments on commit 3b3bea1

Please sign in to comment.