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 May 3, 2015
2 parents 83327ee + bb9b30f commit ff7d4fe
Show file tree
Hide file tree
Showing 20 changed files with 237 additions and 22 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -75,7 +75,6 @@ matrix:
allow_failures:
- env: COMMAND=test/truffle/run.sh
- env: PHASE='-Ptruffle-mri-tests'
- env: PHASE='-Ptruffle-specs-core'


branches:
Expand Down
4 changes: 4 additions & 0 deletions spec/truffle/tags/core/file/grpowned_tags.txt
@@ -1,2 +1,6 @@
fails:File.grpowned? takes non primary groups into account
fails(windows):File.grpowned? returns false if the file exist
fails:FileTest.grpowned? accepts an object that has a #to_path method
fails:FileTest.grpowned? returns true if the file exist
fails:File.grpowned? accepts an object that has a #to_path method
fails:File.grpowned? returns true if the file exist
1 change: 0 additions & 1 deletion spec/truffle/tags/core/file/stat/blksize_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/file/stat/blocks_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/file/stat/dev_major_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/file/stat/dev_minor_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/file/stat/dev_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/file/stat/grpowned_tags.txt
@@ -1,4 +1,2 @@
fails:File::Stat#grpowned? takes non primary groups into account
fails(windows):File::Stat#grpowned? returns false if the file exist
fails:File::Stat#grpowned? returns true if the file exist
fails:File::Stat#grpowned? accepts an object that has a #to_path method
1 change: 0 additions & 1 deletion spec/truffle/tags/core/file/stat/ino_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/file/stat/rdev_major_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/file/stat/rdev_minor_tags.txt

This file was deleted.

1 change: 1 addition & 0 deletions spec/truffle/tags/core/kernel/at_exit_tags.txt
Expand Up @@ -5,3 +5,4 @@ slow:Kernel.at_exit gives access to the last raised exception
fails:Kernel.at_exit allows calling exit inside at_exit handler
fails:Kernel.at_exit runs in reverse order of registration
fails:Kernel.at_exit runs after all other code
fails:Kernel.at_exit gives access to the last raised exception
2 changes: 1 addition & 1 deletion test/pom.rb
Expand Up @@ -23,7 +23,7 @@ def truffle_spec_config(spec_type, generate_report)
(if generate_report
'<arg value="--format" /><arg value="${jruby.home}/spec/truffle/truffle_formatter.rb" />'
else
'<arg value="--format" /><arg value="summary" /><arg value="-V" />' # Produce some new lines for Travis+Maven
'<arg value="--format" /><arg value="specdoc" />' # Need lots of output to keep Travis happy
end) +
"<arg value=\":#{spec_type}\" />" +
'</exec>' +
Expand Down
9 changes: 3 additions & 6 deletions test/pom.xml
Expand Up @@ -692,8 +692,7 @@
<arg value="--excl-tag" />
<arg value="fails" />
<arg value="--format" />
<arg value="summary" />
<arg value="-V" />
<arg value="specdoc" />
<arg value=":language" />
</exec>
</target>
Expand Down Expand Up @@ -738,8 +737,7 @@
<arg value="--excl-tag" />
<arg value="fails" />
<arg value="--format" />
<arg value="summary" />
<arg value="-V" />
<arg value="specdoc" />
<arg value=":core" />
</exec>
</target>
Expand Down Expand Up @@ -784,8 +782,7 @@
<arg value="--excl-tag" />
<arg value="fails" />
<arg value="--format" />
<arg value="summary" />
<arg value="-V" />
<arg value="specdoc" />
<arg value=":library" />
</exec>
</target>
Expand Down
170 changes: 170 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/nodes/array/AppendOneNode.java
@@ -0,0 +1,170 @@
/*
* 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
*/
package org.jruby.truffle.nodes.array;

import com.oracle.truffle.api.dsl.*;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.ArrayGuards;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.util.ArrayUtils;

import java.util.Arrays;

@NodeChildren({
@NodeChild("array"),
@NodeChild("value"),
})
@ImportStatic(ArrayGuards.class)
public abstract class AppendOneNode extends RubyNode {

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

public abstract RubyArray executeAppendOne(RubyArray array, Object value);

// Append into an array with null storage

@Specialization(guards = "isNull(array)")
public RubyArray appendNull(RubyArray array, int value) {
array.setStore(new int[]{value}, 1);
return array;
}

@Specialization(guards = "isNull(array)")
public RubyArray appendNull(RubyArray array, long value) {
array.setStore(new long[]{value}, 1);
return array;
}

@Specialization(guards = "isNull(array)")
public RubyArray appendNull(RubyArray array, Object value) {
array.setStore(new Object[]{value}, 1);
return array;
}

// Append into empty, but non-null storage; we would be better off reusing any existing space, but don't worry for now

@Specialization(guards = {"!isNull(array)", "isEmpty(array)"})
public RubyArray appendEmpty(RubyArray array, int value) {
array.setStore(new int[]{value}, 1);
return array;
}

@Specialization(guards = {"!isNull(array)", "isEmpty(array)"})
public RubyArray appendEmpty(RubyArray array, long value) {
array.setStore(new long[]{value}, 1);
return array;
}

@Specialization(guards ={"!isNull(array)", "isEmpty(array)"})
public RubyArray appendEmpty(RubyArray array, Object value) {
array.setStore(new Object[]{value}, 1);
return array;
}

// Append of the correct type

@Specialization(guards = "isIntegerFixnum(array)")
public RubyArray appendInteger(RubyArray array, int value,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
final int oldSize = array.getSize();
final int newSize = oldSize + 1;

int[] store = (int[]) array.getStore();

if (extendProfile.profile(newSize > store.length)) {
store = Arrays.copyOf(store, ArrayUtils.capacity(store.length, newSize));
}

store[oldSize] = value;
array.setStore(store, newSize);
return array;
}

@Specialization(guards = "isLongFixnum(array)")
public RubyArray appendLong(RubyArray array, long value,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
final int oldSize = array.getSize();
final int newSize = oldSize + 1;

long[] store = (long[]) array.getStore();

if (extendProfile.profile(newSize > store.length)) {
store = Arrays.copyOf(store, ArrayUtils.capacity(store.length, newSize));
}

store[oldSize] = value;
array.setStore(store, newSize);
return array;
}

@Specialization(guards = "isObject(array)")
public RubyArray appendObject(RubyArray array, Object value,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
final int oldSize = array.getSize();
final int newSize = oldSize + 1;

Object[] store = (Object[]) array.getStore();

if (extendProfile.profile(newSize > store.length)) {
store = Arrays.copyOf(store, ArrayUtils.capacity(store.length, newSize));
}

store[oldSize] = value;
array.setStore(store, newSize);
return array;
}

// Append forcing a generalization

@Specialization(guards = "isIntegerFixnum(array)")
public RubyArray appendLongIntoInteger(RubyArray array, long value) {
final int oldSize = array.getSize();
final int newSize = oldSize + 1;

final int[] oldStore = (int[]) array.getStore();
long[] newStore = ArrayUtils.longCopyOf(oldStore, ArrayUtils.capacity(oldStore.length, newSize));

newStore[oldSize] = value;
array.setStore(newStore, newSize);
return array;
}

@Specialization(guards = {"isIntegerFixnum(array)", "!isInteger(value)", "!isLong(value)"})
public RubyArray appendObjectIntoInteger(RubyArray array, Object value) {
final int oldSize = array.getSize();
final int newSize = oldSize + 1;

final int[] oldStore = (int[]) array.getStore();
Object[] newStore = ArrayUtils.box(oldStore, ArrayUtils.capacity(oldStore.length, newSize) - oldStore.length);

newStore[oldSize] = value;
array.setStore(newStore, newSize);
return array;
}

@Specialization(guards = {"isLongFixnum(array)", "!isInteger(value)", "!isLong(value)"})
public RubyArray appendObjectIntoLong(RubyArray array, Object value) {
final int oldSize = array.getSize();
final int newSize = oldSize + 1;

final long[] oldStore = (long[]) array.getStore();
Object[] newStore = ArrayUtils.box(oldStore, ArrayUtils.capacity(oldStore.length, newSize) - oldStore.length);

newStore[oldSize] = value;
array.setStore(newStore, newSize);
return array;
}

}
Expand Up @@ -22,6 +22,7 @@
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;
import com.oracle.truffle.api.utilities.ConditionProfile;
import org.jcodings.specific.USASCIIEncoding;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.truffle.nodes.CoreSourceSection;
Expand Down Expand Up @@ -3178,7 +3179,24 @@ public Object popObjectWithNumObj(VirtualFrame frame, RubyArray array, Object ob

}

@CoreMethod(names = {"push", "<<", "__append__"}, argumentsAsArray = true, raiseIfFrozenSelf = true)
@CoreMethod(names = "<<", raiseIfFrozenSelf = true, required = 1)
public abstract static class ShiftIntoNode extends ArrayCoreMethodNode {

@Child private AppendOneNode appendOneNode;

public ShiftIntoNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
appendOneNode = AppendOneNodeGen.create(context, sourceSection, null, null);
}

@Specialization
public RubyArray pushNullEmptySingleIntegerFixnum(RubyArray array, Object value) {
return appendOneNode.executeAppendOne(array, value);
}

}

@CoreMethod(names = {"push", "__append__"}, argumentsAsArray = true, raiseIfFrozenSelf = true)
public abstract static class PushNode extends ArrayCoreMethodNode {

private final BranchProfile extendBranch = BranchProfile.create();
Expand Down
Expand Up @@ -110,8 +110,6 @@ public static boolean isSmallArrayOfPairs(Object[] args) {
return false;
}

final Object[] store = (Object[]) array.getStore();

if (PackedArrayStrategy.MAX_ELEMENTS > PackedArrayStrategy.MAX_ENTRIES) {
return false;
}
Expand Down
Expand Up @@ -125,6 +125,8 @@ public Object downto(VirtualFrame frame, int from, double to, RubyProc block) {
@CoreMethod(names = "times", needsBlock = true)
public abstract static class TimesNode extends YieldingCoreMethodNode {

// TODO CS 2-May-15 we badly need OSR in this node

@Child private FixnumOrBignumNode fixnumOrBignum;

private final BranchProfile breakProfile = BranchProfile.create();
Expand Down
Expand Up @@ -280,6 +280,34 @@ public int flock(int fd, int constant) {

}

@CoreMethod(names = "major", isModuleFunction = true, required = 1, lowerFixnumParameters = 0)
public abstract static class MajorNode extends CoreMethodArrayArgumentsNode {

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

@Specialization
public int major(int dev) {
return (dev >> 24) & 255;
}

}

@CoreMethod(names = "minor", isModuleFunction = true, required = 1, lowerFixnumParameters = 0)
public abstract static class MinorNode extends CoreMethodArrayArgumentsNode {

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

@Specialization
public int minor(int dev) {
return (dev & 16777215);
}

}

@CoreMethod(names = "rmdir", isModuleFunction = true, required = 1)
public abstract static class RmdirNode extends PointerPrimitiveNodes.ReadAddressPrimitiveNode {

Expand Down
Expand Up @@ -10,6 +10,7 @@
package org.jruby.truffle.runtime.util;

import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives;
import org.jruby.truffle.nodes.RubyNode;

import java.lang.reflect.Array;
Expand Down Expand Up @@ -284,7 +285,13 @@ public static void copy(Object source, Object[] destination, int destinationStar
}

public static long[] longCopyOf(int[] ints) {
final long[] longs = new long[ints.length];
return longCopyOf(ints, ints.length);
}

public static long[] longCopyOf(int[] ints, int newLength) {
assert newLength >= ints.length;

final long[] longs = new long[newLength];

for (int n = 0; n < ints.length; n++) {
longs[n] = ints[n];
Expand All @@ -293,6 +300,7 @@ public static long[] longCopyOf(int[] ints) {
return longs;
}

@CompilerDirectives.TruffleBoundary
public static int capacity(int current, int needed) {
if (needed < 16) {
return 16;
Expand Down

0 comments on commit ff7d4fe

Please sign in to comment.