Skip to content

Commit

Permalink
Showing 11 changed files with 48 additions and 49 deletions.
1 change: 1 addition & 0 deletions spec/truffle/tags/core/string/modulo_tags.txt
Original file line number Diff line number Diff line change
@@ -80,3 +80,4 @@ fails:String#% behaves as if calling Kernel#Float for %g arguments, when the pas
fails:String#% behaves as if calling Kernel#Float for %G arguments, when the passed argument does not respond to #to_ary
fails:String#% behaves as if calling Kernel#Float for %G arguments, when the passed argument is hexadecimal string
fails:String#% when format string contains %<> formats should raise ArgumentError if no hash given
fails:String#% when format string contains %{} sections should raise ArgumentError if no hash given
3 changes: 3 additions & 0 deletions test/truffle/compiler/pe/pe.rb
Original file line number Diff line number Diff line change
@@ -56,6 +56,9 @@ def tagged_counter_example(code)
if ARGV.first
require File.expand_path(ARGV.first)
else
example "14", 14
counter_example "rand"

require_relative 'language/controlflow_pe.rb'
require_relative 'language/closures_pe.rb'
require_relative 'language/constant_pe.rb'
5 changes: 3 additions & 2 deletions truffle/src/main/java/org/jruby/truffle/core/CoreLibrary.java
Original file line number Diff line number Diff line change
@@ -550,8 +550,9 @@ public CoreLibrary(RubyContext context) {
digestClass = defineClass(truffleModule, basicObjectClass, "Digest");
Layouts.CLASS.setInstanceFactoryUnsafe(digestClass, DigestLayoutImpl.INSTANCE.createDigestShape(digestClass, digestClass));

// No need for new version since it's null before which is not cached
assert Layouts.CLASS.getSuperclass(basicObjectClass) == null;
Layouts.CLASS.setSuperclass(basicObjectClass, nilObject);
Layouts.MODULE.getFields(basicObjectClass).newVersion();
}

private static DynamicObjectFactory alwaysFrozen(DynamicObjectFactory factory) {
@@ -644,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
@@ -142,17 +142,11 @@ public Backtrace getBacktrace(Node currentNode,

final ArrayList<Activation> activations = new ArrayList<>();

/*
* TODO(cs): if this materializing the frames proves really expensive
* we might want to make it optional - I think it's only used for some
* features beyond what MRI does like printing locals in backtraces.
*/

if (omit == 0 && currentNode != null && Truffle.getRuntime().getCurrentFrame() != null) {
final MaterializedFrame currentFrame = Truffle.getRuntime().getCurrentFrame()
.getFrame(FrameInstance.FrameAccess.MATERIALIZE, true).materialize();
final InternalMethod method = RubyArguments.getMethod(Truffle.getRuntime().getCurrentFrame()
.getFrame(FrameInstance.FrameAccess.READ_ONLY, true));

activations.add(new Activation(currentNode, currentFrame));
activations.add(new Activation(currentNode, method));
}

final Memo<Boolean> firstFrame = new Memo<>(true);
@@ -176,8 +170,10 @@ public Object visitFrame(FrameInstance frameInstance) {
if (!filterNullSourceSection
|| !(frameInstance.getCallNode().getEncapsulatingSourceSection() == null
|| frameInstance.getCallNode().getEncapsulatingSourceSection().getSource() == null)) {
activations.add(new Activation(frameInstance.getCallNode(),
frameInstance.getFrame(FrameInstance.FrameAccess.MATERIALIZE, true).materialize()));
final InternalMethod method = RubyArguments.getMethod(frameInstance
.getFrame(FrameInstance.FrameAccess.READ_ONLY, true));

activations.add(new Activation(frameInstance.getCallNode(), method));
}
}

Original file line number Diff line number Diff line change
@@ -9,28 +9,28 @@
*/
package org.jruby.truffle.language.backtrace;

import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.nodes.Node;
import org.jruby.truffle.language.methods.InternalMethod;

public class Activation {

public static final Activation OMITTED_LIMIT = new Activation(null, null);
public static final Activation OMITTED_UNUSED = new Activation(null, null);

private final Node callNode;
private final MaterializedFrame materializedFrame;
private final InternalMethod method;

public Activation(Node callNode, MaterializedFrame materializedFrame) {
public Activation(Node callNode, InternalMethod method) {
this.callNode = callNode;
this.materializedFrame = materializedFrame;
this.method = method;
}

public Node getCallNode() {
return callNode;
}

public MaterializedFrame getMaterializedFrame() {
return materializedFrame;
public InternalMethod getMethod() {
return method;
}

}
Original file line number Diff line number Diff line change
@@ -149,7 +149,7 @@ private String formatInLine(List<Activation> activations, DynamicObject exceptio

if (isCore(sourceSection) && !flags.contains(FormattingFlags.INCLUDE_CORE_FILES)) {
reportedSourceSection = nextUserSourceSection(activations, 1);
reportedName = RubyArguments.getMethod(activation.getMaterializedFrame().getArguments()).getName();
reportedName = activation.getMethod().getName();
} else {
reportedSourceSection = sourceSection;
reportedName = reportedSourceSection.getIdentifier();
@@ -224,7 +224,7 @@ public String formatLine(List<Activation> activations, int n) {
reportedSourceSection = nextUserSourceSection(activations, n);

try {
reportedName = RubyArguments.getMethod(activation.getMaterializedFrame().getArguments()).getName();
reportedName = activation.getMethod().getName();
} catch (Exception e) {
reportedName = "???";
}
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);
}

Original file line number Diff line number Diff line change
@@ -96,13 +96,9 @@ public void run(MaterializedFrame frame, Node currentNode) {
} break;

case "frame": {
currentFrameIndex = Integer.parseInt(tokenizer.nextToken());

currentFrame = context.getCallStack()
.getBacktrace(currentNode)
.getActivations()
.get(currentFrameIndex).getMaterializedFrame();
} break;
// TODO CS 4-Mar-2015
throw new UnsupportedOperationException();
}

default: {
try {

0 comments on commit fd0865a

Please sign in to comment.