Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 57405c158ae7
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0ab1c79d1534
Choose a head ref
  • 8 commits
  • 11 files changed
  • 1 contributor

Commits on Oct 4, 2015

  1. 2
    Copy the full SHA
    dce5d91 View commit details
  2. Copy the full SHA
    49dcfc7 View commit details
  3. Copy the full SHA
    879c871 View commit details
  4. Copy the full SHA
    9fe79e8 View commit details
  5. Copy the full SHA
    8e79a13 View commit details
  6. Copy the full SHA
    9747902 View commit details
  7. [Truffle] code formatting

    pitr-ch committed Oct 4, 2015
    Copy the full SHA
    f978a38 View commit details
  8. 2
    Copy the full SHA
    0ab1c79 View commit details
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
@@ -15,6 +15,7 @@
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;
import com.oracle.truffle.api.utilities.ConditionProfile;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.methods.ExceptionTranslatingNode;
import org.jruby.truffle.runtime.RubyContext;
@@ -34,6 +35,7 @@ public class TryNode extends RubyNode {
@Child private ClearExceptionVariableNode clearExceptionVariableNode;

private final BranchProfile elseProfile = BranchProfile.create();
private final boolean elsePresentProfile;
private final BranchProfile controlFlowProfile = BranchProfile.create();
private final BranchProfile raiseExceptionProfile = BranchProfile.create();

@@ -42,6 +44,7 @@ public TryNode(RubyContext context, SourceSection sourceSection, ExceptionTransl
this.tryPart = tryPart;
this.rescueParts = rescueParts;
this.elsePart = elsePart;
elsePresentProfile = elsePart != null;
clearExceptionVariableNode = new ClearExceptionVariableNode(context, sourceSection);
}

@@ -70,7 +73,10 @@ public Object execute(VirtualFrame frame) {
}

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

if (elsePresentProfile) {
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
@@ -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
@@ -14,7 +14,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;
@@ -45,6 +47,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);
}