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: 58218050b8cd
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cd02e9f4e6e0
Choose a head ref
  • 4 commits
  • 4 files changed
  • 2 contributors

Commits on May 27, 2016

  1. [Truffle] Added a new internal method for taking ownership of an arra…

    …y store from another array.
    
    This is intended to be a faster version of Array#replace when we know that the source array won't be used anywhere else.
    nirvdrum committed May 27, 2016
    Copy the full SHA
    c36096b View commit details

Commits on May 31, 2016

  1. Copy the full SHA
    fdb8373 View commit details
  2. Copy the full SHA
    bece4dc View commit details
  3. Merge pull request #3936 from jruby/truffle-array-store-replacement

    [Truffle] Added a new internal method for taking ownership of an array store from another array.
    nirvdrum committed May 31, 2016
    Copy the full SHA
    cd02e9f View commit details
42 changes: 42 additions & 0 deletions spec/truffle/specs/truffle/array/steal_storage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (c) 2016 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
# OTHER DEALINGS IN THE SOFTWARE.

require_relative '../../../../ruby/spec_helper'

describe "Truffle::Array.steal_storage" do
def storage(ary)
Truffle::Debug.array_storage(ary)
end

before :each do
@array = %i[first second third]
end

it "should no-op when called on itself" do
copy = @array.dup

Truffle::Array.steal_storage(@array, @array)

storage(@array).should == "Object[]"
@array.should == copy
end

it "should take ownership of the store" do
other = [1, 2, 3, 4, 5]
other_copy = other.dup

Truffle::Array.steal_storage(@array, other)

storage(@array).should == "int[]"
@array.should == other_copy

storage(other).should == "null"
other.empty?.should == true
end
end
3 changes: 3 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/core/CoreLibrary.java
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@
import org.jruby.truffle.builtins.CoreMethodNodeManager;
import org.jruby.truffle.core.array.ArrayNodes;
import org.jruby.truffle.core.array.ArrayNodesFactory;
import org.jruby.truffle.core.array.TruffleArrayNodesFactory;
import org.jruby.truffle.core.basicobject.BasicObjectNodesFactory;
import org.jruby.truffle.core.binding.BindingNodesFactory;
import org.jruby.truffle.core.binding.TruffleBindingNodesFactory;
@@ -585,6 +586,7 @@ public CoreLibrary(RubyContext context) {
defineModule(truffleModule, "Graal");
defineModule(truffleModule, "Ropes");
defineModule(truffleModule, "GC");
defineModule(truffleModule, "Array");
final DynamicObject attachments = defineModule(truffleModule, "Attachments");
defineModule(attachments, "Internal");
defineModule(truffleModule, "Boot");
@@ -758,6 +760,7 @@ public void addCoreMethods() {
coreMethodNodeManager.addCoreMethodNodes(TruffleProcessNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(TruffleDebugNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(TruffleBindingNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(TruffleArrayNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(BCryptNodesFactory.getFactories());

coreMethodNodeManager.allMethodInstalled();
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2016 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
*/
package org.jruby.truffle.core.array;

import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.object.DynamicObject;
import org.jruby.truffle.builtins.CoreClass;
import org.jruby.truffle.builtins.CoreMethod;
import org.jruby.truffle.builtins.CoreMethodArrayArgumentsNode;

import static org.jruby.truffle.core.array.ArrayHelpers.getSize;
import static org.jruby.truffle.core.array.ArrayHelpers.getStore;
import static org.jruby.truffle.core.array.ArrayHelpers.setStoreAndSize;

@CoreClass("Truffle::Array")
public class TruffleArrayNodes {

@CoreMethod(names = "steal_storage", onSingleton = true, required = 2)
public abstract static class TakeOwnershipOfStoreNode extends CoreMethodArrayArgumentsNode {

@Specialization(guards = "array == other")
public DynamicObject takeOwnershipOfStoreNoOp(DynamicObject array, DynamicObject other) {
return array;
}

@Specialization(guards = { "array != other", "isRubyArray(other)" })
public DynamicObject takeOwnershipOfStore(DynamicObject array, DynamicObject other) {
final int size = getSize(other);
final Object store = getStore(other);
setStoreAndSize(array, store, size);
setStoreAndSize(other, null, 0);

return array;
}

}

}
18 changes: 10 additions & 8 deletions truffle/src/main/ruby/core/array.rb
Original file line number Diff line number Diff line change
@@ -811,7 +811,7 @@ def flatten!(level=-1)

out = new_reserved size
if recursively_flatten(self, out, level)
replace(out)
Truffle::Array.steal_storage(self, out)
return self
end

@@ -987,7 +987,7 @@ def keep_if(&block)

Truffle.check_frozen

replace select(&block)
Truffle::Array.steal_storage(self, select(&block))
end

def last(n=undefined)
@@ -1337,7 +1337,7 @@ def rotate!(cnt=1)
return self if length == 0 || length == 1

ary = rotate(cnt)
replace ary
Truffle::Array.steal_storage(self, ary)
end

class SampleRandom
@@ -1467,7 +1467,7 @@ def select!(&block)
Truffle.check_frozen

ary = select(&block)
replace ary unless size == ary.size
Truffle::Array.steal_storage(self, ary) unless size == ary.size
end

def set_index(index, ent, fin=undefined)
@@ -1748,7 +1748,7 @@ def sort_by!(&block)

return to_enum(:sort_by!) { size } unless block_given?

replace sort_by(&block)
Truffle::Array.steal_storage(self, sort_by(&block))
end

# Sorts this Array in-place. See #sort.
@@ -2044,7 +2044,7 @@ def mergesort!
width *= 2
end

replace(source) if source != self
Truffle::Array.steal_storage(self, source)

self
end
@@ -2108,7 +2108,7 @@ def mergesort_block!(block)
width *= 2
end

replace(source) if source != self
Truffle::Array.steal_storage(self, source)

self
end
@@ -2397,7 +2397,9 @@ def element_reference_fallback(method_name, args)
end

def sort!(&block)
replace sort(&block)
Truffle.check_frozen

Truffle::Array.steal_storage(self, sort(&block))
end
public :sort!
end