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

Commits on Apr 19, 2016

  1. Copy the full SHA
    135d1eb View commit details
  2. Copy the full SHA
    1f26812 View commit details
  3. Copy the full SHA
    b932df7 View commit details
  4. Copy the full SHA
    7f7656b View commit details
  5. [Truffle] Use ArrayMirror and cleanup for Array#{delete_at,each,each_…

    …with_index,fill,initialize}.
    eregon committed Apr 19, 2016
    Copy the full SHA
    db093e8 View commit details
Original file line number Diff line number Diff line change
@@ -34,8 +34,7 @@ public Object execute(VirtualFrame frame) {

if (isFrozenNode.executeIsFrozen(result)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(coreExceptions().frozenError(
Layouts.MODULE.getFields(coreLibrary().getLogicalClass(result)).getName(), this));
throw new RaiseException(coreExceptions().frozenError(result, this));
}

return result;
Original file line number Diff line number Diff line change
@@ -23,13 +23,13 @@ public class ReturnEnumeratorIfNoBlockNode extends RubyNode {

@Child private RubyNode method;
@Child private CallDispatchHeadNode toEnumNode;
private final String methodName;
private final DynamicObject methodSymbol;
private final ConditionProfile noBlockProfile = ConditionProfile.createBinaryProfile();

public ReturnEnumeratorIfNoBlockNode(String methodName, RubyNode method) {
super(method.getContext(), method.getEncapsulatingSourceSection());
this.method = method;
this.methodName = methodName;
this.methodSymbol = getSymbol(methodName);
}

@Override
@@ -42,13 +42,10 @@ public Object execute(VirtualFrame frame) {
toEnumNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext()));
}

final Object[] arguments = ArrayUtils.unshift(RubyArguments.getArguments(frame), getSymbol(methodName));
final Object[] arguments = ArrayUtils.unshift(RubyArguments.getArguments(frame), methodSymbol);
return toEnumNode.call(frame, RubyArguments.getSelf(frame), "to_enum", null, arguments);

} else {

return method.execute(frame);

}
}

Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ public static int getSize(DynamicObject array) {
}

public static void setStoreAndSize(DynamicObject array, Object store, int size) {
assert !(store instanceof ArrayMirror);
Layouts.ARRAY.setStore(array, store);
Layouts.ARRAY.setSize(array, size);
}
606 changes: 115 additions & 491 deletions truffle/src/main/java/org/jruby/truffle/core/array/ArrayNodes.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -116,7 +116,8 @@ public DynamicObject argumentError(Rope message, Node currentNode, Throwable jav
// RuntimeError

@TruffleBoundary
public DynamicObject frozenError(String className, Node currentNode) {
public DynamicObject frozenError(Object object, Node currentNode) {
String className = Layouts.MODULE.getFields(context.getCoreLibrary().getLogicalClass(object)).getName();
return runtimeError(String.format("can't modify frozen %s", className), currentNode);
}

Original file line number Diff line number Diff line change
@@ -107,12 +107,7 @@ public Object execute(VirtualFrame frame) {
Object key = keyValues[n * 2].execute(frame);

if (stringKeyProfile.profile(RubyGuards.isRubyString(key))) {
if (isFrozenNode == null) {
CompilerDirectives.transferToInterpreter();
isFrozenNode = insert(IsFrozenNodeGen.create(getContext(), getSourceSection(), null));
}

if (!isFrozenNode.executeIsFrozen(key)) {
if (!isFrozen(key)) {
key = freezeNode.call(frame, dupNode.call(frame, key, "dup", null), "freeze", null);
}
}
@@ -138,6 +133,14 @@ public Object execute(VirtualFrame frame) {
return Layouts.HASH.createHash(coreLibrary().getHashFactory(), store, size, null, null, null, null, false);
}

protected boolean isFrozen(Object object) {
if (isFrozenNode == null) {
CompilerDirectives.transferToInterpreter();
isFrozenNode = insert(IsFrozenNodeGen.create(getContext(), getSourceSection(), null));
}
return isFrozenNode.executeIsFrozen(object);
}

}

public static class GenericHashLiteralNode extends HashLiteralNode {
Original file line number Diff line number Diff line change
@@ -2010,7 +2010,6 @@ public abstract static class UntaintNode extends CoreMethodArrayArgumentsNode {

public UntaintNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
isFrozenNode = IsFrozenNodeGen.create(context, sourceSection, null);
isTaintedNode = IsTaintedNodeGen.create(context, sourceSection, null);
writeTaintNode = WriteObjectFieldNodeGen.create(Layouts.TAINTED_IDENTIFIER);
}
@@ -2021,15 +2020,19 @@ public Object taint(DynamicObject object) {
return object;
}

if (isFrozenNode.executeIsFrozen(object)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(coreExceptions().frozenError(Layouts.MODULE.getFields(coreLibrary().getLogicalClass(object)).getName(), this));
}

checkFrozen(object);
writeTaintNode.execute(object, false);
return object;
}

protected void checkFrozen(Object object) {
if (isFrozenNode == null) {
CompilerDirectives.transferToInterpreter();
isFrozenNode = insert(IsFrozenNodeGen.create(getContext(), getSourceSection(), null));
}
isFrozenNode.raiseIfFrozen(object);
}

}

}
Original file line number Diff line number Diff line change
@@ -28,10 +28,10 @@
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.literal.ObjectLiteralNode;
import org.jruby.truffle.language.methods.InternalMethod;
import org.jruby.truffle.language.objects.IsFrozenNode;
import org.jruby.truffle.language.objects.IsFrozenNodeGen;
import org.jruby.truffle.language.objects.ObjectGraphNode;
import org.jruby.truffle.language.objects.ObjectIDOperations;

import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Collections;
@@ -160,18 +160,18 @@ public void initCopy(DynamicObject from) {
public void checkFrozen(RubyContext context, Node currentNode) {
if (context.getCoreLibrary() != null && verySlowIsFrozen(context, rubyModuleObject)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(context.getCoreExceptions().frozenError(Layouts.MODULE.getFields(getLogicalClass()).getName(), currentNode));
throw new RaiseException(context.getCoreExceptions().frozenError(rubyModuleObject, currentNode));
}
}

// TODO CS 20-Aug-15 this needs to go
public static boolean verySlowIsFrozen(RubyContext context, Object object) {
final RubyNode node = IsFrozenNodeGen.create(context, null, new ObjectLiteralNode(context, null, object));
final IsFrozenNode node = IsFrozenNodeGen.create(context, null, null);
new Node() {
@Child RubyNode child = node;
}.adoptChildren();

return (boolean) node.execute(null);
return (boolean) node.executeIsFrozen(object);
}

public void insertAfter(DynamicObject module) {
Original file line number Diff line number Diff line change
@@ -97,10 +97,8 @@
import org.jruby.util.CodeRangeable;
import org.jruby.util.ConvertDouble;
import org.jruby.util.StringSupport;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

import static org.jruby.truffle.core.rope.RopeConstants.EMPTY_ASCII_8BIT_ROPE;
import static org.jruby.truffle.core.string.StringOperations.encoding;
import static org.jruby.truffle.core.string.StringOperations.rope;
@@ -1177,15 +1175,9 @@ public DynamicObject initialize(DynamicObject self, NotProvided from) {

@Specialization(guards = "isRubyString(from)")
public DynamicObject initialize(DynamicObject self, DynamicObject from) {
if (isFrozenNode == null) {
CompilerDirectives.transferToInterpreter();
isFrozenNode = insert(IsFrozenNodeGen.create(getContext(), getSourceSection(), null));
}

if (isFrozenNode.executeIsFrozen(self)) {
if (isFrozen(self)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(
coreExceptions().frozenError(Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(self)).getName(), this));
throw new RaiseException(coreExceptions().frozenError(self, this));
}

StringOperations.setRope(self, rope(from));
@@ -1202,6 +1194,15 @@ public DynamicObject initialize(VirtualFrame frame, DynamicObject self, Object f

return initialize(self, toStrNode.executeToStr(frame, from));
}

protected boolean isFrozen(Object object) {
if (isFrozenNode == null) {
CompilerDirectives.transferToInterpreter();
isFrozenNode = insert(IsFrozenNodeGen.create(getContext(), getSourceSection(), null));
}
return isFrozenNode.executeIsFrozen(object);
}

}

@CoreMethod(names = "initialize_copy", required = 1)
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@

package org.jruby.truffle.language.objects;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
@@ -18,6 +19,7 @@
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.control.RaiseException;

@NodeChild(value = "child")
public abstract class IsFrozenNode extends RubyNode {
@@ -28,6 +30,13 @@ public IsFrozenNode(RubyContext context, SourceSection sourceSection) {

public abstract boolean executeIsFrozen(Object object);

public void raiseIfFrozen(Object object) {
if (executeIsFrozen(object)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(coreExceptions().frozenError(object, this));
}
}

@Specialization
public boolean isFrozen(boolean object) {
return true;
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
*/
package org.jruby.truffle.language.objects;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.NodeChild;
@@ -150,23 +151,30 @@ protected DynamicObject getSingletonClassForInstance(DynamicObject object) {
final DynamicObject singletonClass = ClassNodes.createSingletonClassOfObject(
getContext(), logicalClass, object, name);

if (isFrozenNode == null) {
isFrozenNode = insert(IsFrozenNodeGen.create(getContext(), getSourceSection(), null));
}

if (isFrozenNode.executeIsFrozen(object)) {
if (freezeNode == null) {
freezeNode = insert(FreezeNodeGen.create(getContext(), getSourceSection(), null));
}

freezeNode.executeFreeze(singletonClass);
if (isFrozen(object)) {
freeze(singletonClass);
}

Layouts.BASIC_OBJECT.setMetaClass(object, singletonClass);

return singletonClass;
}

public void freeze(final DynamicObject singletonClass) {
if (freezeNode == null) {
freezeNode = insert(FreezeNodeGen.create(getContext(), getSourceSection(), null));
}
freezeNode.executeFreeze(singletonClass);
}

protected boolean isFrozen(Object object) {
if (isFrozenNode == null) {
CompilerDirectives.transferToInterpreter();
isFrozenNode = insert(IsFrozenNodeGen.create(getContext(), getSourceSection(), null));
}
return isFrozenNode.executeIsFrozen(object);
}

protected int getCacheLimit() {
return getContext().getOptions().CLASS_CACHE;
}
Original file line number Diff line number Diff line change
@@ -66,9 +66,7 @@ protected WriteObjectFieldNode createWriteTaintNode() {
}

private Object frozen(Object object) {
throw new RaiseException(coreExceptions().frozenError(
Layouts.MODULE.getFields(coreLibrary().getLogicalClass(object)).getName(),
this));
throw new RaiseException(coreExceptions().frozenError(object, this));
}

}
Original file line number Diff line number Diff line change
@@ -49,8 +49,7 @@ public Object execute(VirtualFrame frame) {

writeNode.execute((DynamicObject) object, value);
} else {
throw new RaiseException(coreExceptions().frozenError(
Layouts.MODULE.getFields(coreLibrary().getLogicalClass(object)).getName(), this));
throw new RaiseException(coreExceptions().frozenError(object, this));
}

return value;