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: 2c9291913d39
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2f4badb9b1d8
Choose a head ref
  • 3 commits
  • 5 files changed
  • 1 contributor

Commits on Mar 4, 2016

  1. Copy the full SHA
    28f8e2a View commit details
  2. Copy the full SHA
    a3038e9 View commit details
  3. [Truffle] Remove ArrayOperations.append.

    * Inline and adapt in its only caller.
    eregon committed Mar 4, 2016
    Copy the full SHA
    2f4badb View commit details
Original file line number Diff line number Diff line change
@@ -645,7 +645,7 @@ private void initializeGlobalVariables() {
DynamicObject globals = globalVariablesObject;

globals.define("$LOAD_PATH", Layouts.ARRAY.createArray(Layouts.CLASS.getInstanceFactory(arrayClass), null, 0), 0);
globals.define("$LOADED_FEATURES", Layouts.ARRAY.createArray(Layouts.CLASS.getInstanceFactory(arrayClass), null, 0), 0);
globals.define("$LOADED_FEATURES", Layouts.ARRAY.createArray(Layouts.CLASS.getInstanceFactory(arrayClass), new Object[0], 0), 0);
globals.define("$:", globals.get("$LOAD_PATH", nilObject), 0);
globals.define("$\"", globals.get("$LOADED_FEATURES", nilObject), 0);
globals.define("$,", nilObject, 0);
Original file line number Diff line number Diff line change
@@ -10,12 +10,10 @@
package org.jruby.truffle.core.array;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.ConditionProfile;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.language.RubyGuards;

import java.util.Arrays;

public abstract class ArrayOperations {

@@ -45,20 +43,14 @@ public static int clampExclusiveIndex(int length, int index) {
}
}

@TruffleBoundary
public static Object[] toObjectArray(DynamicObject array) {
return ArrayReflector.reflect(Layouts.ARRAY.getStore(array)).getBoxedCopy(Layouts.ARRAY.getSize(array));
}

@TruffleBoundary
public static Iterable<Object> toIterable(DynamicObject array) {
return ArrayReflector.reflect(Layouts.ARRAY.getStore(array)).iterableUntil(Layouts.ARRAY.getSize(array));
}

public static void append(DynamicObject array, Object value) {
assert RubyGuards.isRubyArray(array);
Layouts.ARRAY.setStore(array, Arrays.copyOf(ArrayUtils.box(Layouts.ARRAY.getStore(array)), Layouts.ARRAY.getSize(array) + 1));
Layouts.ARRAY.setSize(array, Layouts.ARRAY.getSize(array));
((Object[]) Layouts.ARRAY.getStore(array))[Layouts.ARRAY.getSize(array)] = value;
Layouts.ARRAY.setSize(array, Layouts.ARRAY.getSize(array) + 1);
}

}
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@
package org.jruby.truffle.core.array;

import com.oracle.truffle.api.CompilerAsserts;

import java.lang.reflect.Array;
import java.util.Arrays;

@@ -389,6 +388,12 @@ public static void arraycopy(Object[] src, int srcPos, Object[] dest, int destPo
System.arraycopy(src, srcPos, dest, destPos, length);
}

public static Object[] copyOf(Object[] array, int newLength) {
final Object[] copy = new Object[newLength];
System.arraycopy(array, 0, copy, 0, Math.min(array.length, newLength));
return copy;
}

public static Object[] grow(Object[] array, int newLength) {
assert newLength >= array.length;
final Object[] copy = new Object[newLength];
Original file line number Diff line number Diff line change
@@ -24,9 +24,9 @@
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.methods.DeclarationContext;
import org.jruby.truffle.language.parser.ParserContext;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;

public class FeatureLoader {

@@ -167,8 +167,17 @@ private boolean isFeatureLoaded(String feature) {

private void addToLoadedFeatures(DynamicObject feature) {
final DynamicObject loadedFeatures = context.getCoreLibrary().getLoadedFeatures();
final int size = Layouts.ARRAY.getSize(loadedFeatures);
final Object[] store = (Object[]) Layouts.ARRAY.getStore(loadedFeatures);

ArrayOperations.append(loadedFeatures, feature);
if (size < store.length) {
store[size] = feature;
} else {
final Object[] newStore = ArrayUtils.grow(store, ArrayUtils.capacityForOneMore(store.length));
newStore[size] = feature;
Layouts.ARRAY.setStore(loadedFeatures, newStore);
}
Layouts.ARRAY.setSize(loadedFeatures, size + 1);
}

private void removeFromLoadedFeatures(DynamicObject feature) {
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@
package org.jruby.truffle.language.supercall;

import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.ExplodeLoop;
import com.oracle.truffle.api.object.DynamicObject;
@@ -21,8 +20,6 @@
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;

import java.util.Arrays;

/**
* Get the arguments of a super call with implicit arguments (using the ones of the surrounding method).
*/
@@ -50,13 +47,12 @@ public final Object execute(VirtualFrame frame) {
}

if (hasRestParameter) {
CompilerDirectives.transferToInterpreter();
// TODO (eregon, 22 July 2015): Assumes rest arg is last, not true if post or keyword args.
final Object restArg = superArguments[superArguments.length - 1];
final int restArgIndex = reloadNodes.length - 1;
final Object restArg = superArguments[restArgIndex];
assert RubyGuards.isRubyArray(restArg);
final Object[] restArgs = ArrayOperations.toObjectArray((DynamicObject) restArg);
final int restArgIndex = reloadNodes.length - 1;
superArguments = Arrays.copyOf(superArguments, restArgIndex + restArgs.length);
superArguments = ArrayUtils.copyOf(superArguments, restArgIndex + restArgs.length);
ArrayUtils.arraycopy(restArgs, 0, superArguments, restArgIndex, restArgs.length);
}