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

Commits on Dec 21, 2016

  1. Copy the full SHA
    e059e94 View commit details
  2. 6
    Copy the full SHA
    496d0c0 View commit details
  3. Copy the full SHA
    cb76897 View commit details
  4. Copy the full SHA
    9f5136f View commit details
Original file line number Diff line number Diff line change
@@ -13,8 +13,6 @@
import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyContext;

import java.lang.reflect.Array;

public abstract class ArrayHelpers {

public static Object getStore(DynamicObject array) {
@@ -41,8 +39,7 @@ public static void setStoreAndSize(DynamicObject array, Object store, int size)
* @param size
*/
public static void setSize(DynamicObject array, int size) {
assert getStore(array) != null || size == 0;
assert getStore(array) == null || Array.getLength(getStore(array)) >= size;
assert ArrayOperations.getStoreCapacity(array) >= size;
Layouts.ARRAY.setSize(array, size);
}

Original file line number Diff line number Diff line change
@@ -13,6 +13,9 @@
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.ConditionProfile;

import java.lang.reflect.Array;

import org.jruby.truffle.Layouts;

public abstract class ArrayOperations {
@@ -45,12 +48,27 @@ 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));
return ArrayReflector.reflect(getBackingStore(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));
return ArrayReflector.reflect(getBackingStore(array)).iterableUntil(Layouts.ARRAY.getSize(array));
}

@TruffleBoundary
public static Object getBackingStore(DynamicObject array) {
return Layouts.ARRAY.getStore(array);
}

@TruffleBoundary
public static int getStoreCapacity(DynamicObject array) {
Object store = getBackingStore(array);
if (store == null) {
return 0;
} else {
return Array.getLength(store);
}
}

}
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ public void setStore(DynamicObject array, Object store) {

public void setStoreAndSize(DynamicObject array, Object store, int size) {
setStore(array, store);
Layouts.ARRAY.setSize(array, size);
ArrayHelpers.setSize(array, size);
}

@Override
Original file line number Diff line number Diff line change
@@ -16,13 +16,11 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;

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

@NodeChildren({
@NodeChild(value="array", type=RubyNode.class),
@@ -80,31 +78,33 @@ public Object writeExtendByOne(DynamicObject array, int index, Object value,
// Writing beyond the end of an array - may need to generalize to Object[] or otherwise extend

@Specialization(guards = {
"!isObjectArray(array)", "!isInBounds(array, index)", "!isExtendingByOne(array, index)",
})
"!isInBounds(array, index)", "!isExtendingByOne(array, index)", "strategy.matches(array)", "!strategy.accepts(nil())"
}, limit = "ARRAY_STRATEGIES")
public Object writeBeyondPrimitive(DynamicObject array, int index, Object value,
@Cached("of(array)") ArrayStrategy strategy,
@Cached("create(getContext())") ArrayGeneralizeNode generalizeNode) {
final int newSize = index + 1;
final Object[] objectStore = generalizeNode.executeGeneralize(array, newSize);
for (int n = getSize(array); n < index; n++) {
for (int n = strategy.getSize(array); n < index; n++) {
objectStore[n] = nil();
}
objectStore[index] = value;
setStoreAndSize(array, objectStore, newSize);
strategy.setStoreAndSize(array, objectStore, newSize);
return value;
}

@Specialization(guards = {
"isObjectArray(array)", "!isInBounds(array, index)", "!isExtendingByOne(array, index)"
"!isInBounds(array, index)", "!isExtendingByOne(array, index)", "strategy.matches(array)", "strategy.accepts(nil())"
})
public Object writeBeyondObject(DynamicObject array, int index, Object value,
@Cached("of(array)") ArrayStrategy strategy,
@Cached("create(getContext())") ArrayEnsureCapacityNode ensureCapacityNode) {
ensureCapacityNode.executeEnsureCapacity(array, index + 1);
final Object[] objectStore = ((Object[]) Layouts.ARRAY.getStore(array));
for (int n = getSize(array); n < index; n++) {
objectStore[n] = nil();
final ArrayMirror store = strategy.newMirror(array);
for (int n = strategy.getSize(array); n < index; n++) {
store.set(n, nil());
}
objectStore[index] = value;
store.set(index, value);
setSize(array, index + 1);
return value;
}
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.core.string.StringUtils;
import org.jruby.truffle.interop.RubyMessageResolutionAccessor;
import org.jruby.truffle.language.objects.shared.SharedObjects;

public class RubyObjectType extends ObjectType {

@@ -36,8 +37,9 @@ public String toString(DynamicObject object) {
} else if (RubyGuards.isRubyModule(object)) {
return Layouts.MODULE.getFields(object).getName();
} else {
return StringUtils.format("DynamicObject@%x<logicalClass=%s>", System.identityHashCode(object),
Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(object)).getName());
final String className = Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(object)).getName();
final Object isShared = SharedObjects.isShared(object) ? "(shared)" : "";
return StringUtils.format("DynamicObject@%x<%s>%s", System.identityHashCode(object), className, isShared);
}
}

Original file line number Diff line number Diff line change
@@ -37,6 +37,9 @@ public WriteGlobalVariableNode(RubyContext context, SourceSection sourceSection,
public Object writeTryToKeepConstant(Object value,
@Cached("getStorage()") GlobalVariableStorage storage,
@Cached("storage.getValue()") Object previousValue) {
// NOTE: we still do the volatile write to get the proper memory barrier,
// as the global variable could be used as a publication mechanism.
storage.setValueInternal(value);
return previousValue;
}