Skip to content

Commit

Permalink
Showing 13 changed files with 627 additions and 674 deletions.
5 changes: 1 addition & 4 deletions bin/jruby+truffle
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/usr/bin/env bash
"exec" "`dirname $BASH_SOURCE[0]`/jruby" "$0" "$@"

require File.join(JRuby.runtime.instance_config.jruby_home, 'lib/ruby/truffle/jruby+truffle/runner')

JRubyTruffleRunner.new
exec `dirname $BASH_SOURCE[0]`/jruby `dirname $BASH_SOURCE[0]`/../lib/ruby/truffle/jruby+truffle/bin/jruby+truffle "$@"
5 changes: 5 additions & 0 deletions lib/ruby/truffle/jruby+truffle/bin/jruby+truffle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby

require_relative '../lib/runner.rb'

JRubyTruffleRunner.new
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.runtime.Visibility;
import org.jruby.truffle.core.array.ArrayHelpers;
import org.jruby.truffle.core.array.ArrayOperations;
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.language.RubyNode;
@@ -40,6 +41,7 @@
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.methods.InternalMethod;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@@ -201,19 +203,18 @@ public InstanceVariablesNode(RubyContext context, SourceSection sourceSection) {
@Specialization
public DynamicObject instanceVariables(DynamicObject self) {
List<Object> keys = self.getShape().getKeyList();
final Object[] instanceVariableNames = keys.toArray(new Object[keys.size()]);

final Object[] instanceVariableNames = keys.toArray(new Object[keys.size()]);
Arrays.sort(instanceVariableNames);

final DynamicObject array = Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);

final List<Object> names = new ArrayList<>();
for (Object name : instanceVariableNames) {
if (name instanceof String) {
ArrayOperations.append(array, getSymbol((String) name));
names.add(getSymbol((String) name));
}
}

return array;
final int size = names.size();
return ArrayHelpers.createArray(getContext(), names.toArray(new Object[size]), size);
}

}
14 changes: 9 additions & 5 deletions truffle/src/main/java/org/jruby/truffle/core/BindingNodes.java
Original file line number Diff line number Diff line change
@@ -9,6 +9,9 @@
*/
package org.jruby.truffle.core;

import java.util.ArrayList;
import java.util.List;

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.Cached;
@@ -20,6 +23,8 @@
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.core.array.ArrayHelpers;
import org.jruby.truffle.core.array.ArrayOperations;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.locals.ReadFrameSlotNode;
@@ -291,19 +296,18 @@ public DynamicObject localVariables(DynamicObject binding) {

@TruffleBoundary
public static DynamicObject listLocalVariables(RubyContext context, Frame frame) {
final DynamicObject array = Layouts.ARRAY.createArray(context.getCoreLibrary().getArrayFactory(), null, 0);

final List<Object> names = new ArrayList<>();
while (frame != null) {
for (FrameSlot slot : frame.getFrameDescriptor().getSlots()) {
if (slot.getIdentifier() instanceof String && !((String) slot.getIdentifier()).startsWith("rubytruffle_temp_frame_on_stack_marker")) {
ArrayOperations.append(array, context.getSymbol((String) slot.getIdentifier()));
names.add(context.getSymbol((String) slot.getIdentifier()));
}
}

frame = RubyArguments.getDeclarationFrame(frame.getArguments());
}

return array;
final int size = names.size();
return ArrayHelpers.createArray(context, names.toArray(new Object[size]), size);
}
}

20 changes: 11 additions & 9 deletions truffle/src/main/java/org/jruby/truffle/core/ClassNodes.java
Original file line number Diff line number Diff line change
@@ -73,20 +73,21 @@ public static DynamicObject createBootClass(RubyContext context, DynamicObject c

model.rubyModuleObject = rubyClass;

final ModuleFields fields = Layouts.MODULE.getFields(rubyClass);
if (model.lexicalParent == null) { // bootstrap or anonymous module
Layouts.MODULE.getFields(rubyClass).setFullName(Layouts.MODULE.getFields(rubyClass).givenBaseName);
fields.setFullName(fields.givenBaseName);
} else {
Layouts.MODULE.getFields(rubyClass).getAdoptedByLexicalParent(context, model.lexicalParent, model.givenBaseName, null);
fields.getAdoptedByLexicalParent(context, model.lexicalParent, model.givenBaseName, null);
}

if (superclass != null) {
assert RubyGuards.isRubyClass(superclass);
assert RubyGuards.isRubyClass(rubyClass);

Layouts.MODULE.getFields(rubyClass).parentModule = Layouts.MODULE.getFields(superclass).start;
fields.parentModule = Layouts.MODULE.getFields(superclass).start;
Layouts.MODULE.getFields(superclass).addDependent(rubyClass);

Layouts.MODULE.getFields(rubyClass).newVersion();
fields.newVersion();
}

return rubyClass;
@@ -119,19 +120,20 @@ public static DynamicObject createRubyClass(RubyContext context, DynamicObject c

model.rubyModuleObject = rubyClass;

final ModuleFields fields = Layouts.MODULE.getFields(rubyClass);
if (model.lexicalParent != null) {
Layouts.MODULE.getFields(rubyClass).getAdoptedByLexicalParent(context, model.lexicalParent, model.givenBaseName, null);
} else if (Layouts.MODULE.getFields(rubyClass).givenBaseName != null) { // bootstrap module
Layouts.MODULE.getFields(rubyClass).setFullName(Layouts.MODULE.getFields(rubyClass).givenBaseName);
fields.getAdoptedByLexicalParent(context, model.lexicalParent, model.givenBaseName, null);
} else if (fields.givenBaseName != null) { // bootstrap module
fields.setFullName(fields.givenBaseName);
}

if (superclass != null) {
assert RubyGuards.isRubyClass(superclass);

Layouts.MODULE.getFields(rubyClass).parentModule = Layouts.MODULE.getFields(superclass).start;
fields.parentModule = Layouts.MODULE.getFields(superclass).start;
Layouts.MODULE.getFields(superclass).addDependent(rubyClass);

Layouts.MODULE.getFields(rubyClass).newVersion();
fields.newVersion();
}

DynamicObjectFactory factory = Layouts.CLASS.getInstanceFactory(superclass);
22 changes: 11 additions & 11 deletions truffle/src/main/java/org/jruby/truffle/core/EncodingNodes.java
Original file line number Diff line number Diff line change
@@ -43,44 +43,44 @@
public abstract class EncodingNodes {

// Both are mutated only in CoreLibrary.initializeEncodingConstants().
private static DynamicObject[] encodingList = new DynamicObject[EncodingDB.getEncodings().size()];
private static Map<String, DynamicObject> lookup = new HashMap<>();
private static final DynamicObject[] ENCODING_LIST = new DynamicObject[EncodingDB.getEncodings().size()];
private static final Map<String, DynamicObject> LOOKUP = new HashMap<>();

@TruffleBoundary
public static synchronized DynamicObject getEncoding(Encoding encoding) {
return lookup.get(new String(encoding.getName(), StandardCharsets.UTF_8).toLowerCase(Locale.ENGLISH));
return LOOKUP.get(new String(encoding.getName(), StandardCharsets.UTF_8).toLowerCase(Locale.ENGLISH));
}

@TruffleBoundary
public static DynamicObject getEncoding(String name) {
return lookup.get(name.toLowerCase(Locale.ENGLISH));
return LOOKUP.get(name.toLowerCase(Locale.ENGLISH));
}

public static DynamicObject getEncoding(int index) {
return encodingList[index];
return ENCODING_LIST[index];
}

@TruffleBoundary
public static void storeEncoding(int encodingListIndex, DynamicObject encoding) {
assert RubyGuards.isRubyEncoding(encoding);
encodingList[encodingListIndex] = encoding;
lookup.put(Layouts.ENCODING.getName(encoding).toString().toLowerCase(Locale.ENGLISH), encoding);
ENCODING_LIST[encodingListIndex] = encoding;
LOOKUP.put(Layouts.ENCODING.getName(encoding).toString().toLowerCase(Locale.ENGLISH), encoding);
}

@TruffleBoundary
public static void storeAlias(String aliasName, DynamicObject encoding) {
assert RubyGuards.isRubyEncoding(encoding);
lookup.put(aliasName.toLowerCase(Locale.ENGLISH), encoding);
LOOKUP.put(aliasName.toLowerCase(Locale.ENGLISH), encoding);
}

public static DynamicObject newEncoding(DynamicObject encodingClass, Encoding encoding, byte[] name, int p, int end, boolean dummy) {
return createRubyEncoding(encodingClass, encoding, new ByteList(name, p, end), dummy);
}

public static Object[] cloneEncodingList() {
final Object[] clone = new Object[encodingList.length];
final Object[] clone = new Object[ENCODING_LIST.length];

System.arraycopy(encodingList, 0, clone, 0, encodingList.length);
System.arraycopy(ENCODING_LIST, 0, clone, 0, ENCODING_LIST.length);

return clone;
}
@@ -459,7 +459,7 @@ public EncodingMapNode(RubyContext context, SourceSection sourceSection) {
public Object encodingMap(VirtualFrame frame) {
Object ret = newLookupTableNode.call(frame, getContext().getCoreLibrary().getLookupTableClass(), "new", null);

final DynamicObject[] encodings = encodingList;
final DynamicObject[] encodings = ENCODING_LIST;
for (int i = 0; i < encodings.length; i++) {
final Object upcased = upcaseNode.call(frame, createString(Layouts.ENCODING.getName(encodings[i])), "upcase", null);
final Object key = toSymNode.call(frame, upcased, "to_sym", null);
15 changes: 8 additions & 7 deletions truffle/src/main/java/org/jruby/truffle/core/ModuleFields.java
Original file line number Diff line number Diff line change
@@ -129,17 +129,18 @@ public void initCopy(DynamicObject from) {
assert RubyGuards.isRubyModule(from);

// Do not copy name, the copy is an anonymous module
this.methods.putAll(Layouts.MODULE.getFields(from).methods);
this.constants.putAll(Layouts.MODULE.getFields(from).constants);
this.classVariables.putAll(Layouts.MODULE.getFields(from).classVariables);
final ModuleFields fields = Layouts.MODULE.getFields(from);
this.methods.putAll(fields.methods);
this.constants.putAll(fields.constants);
this.classVariables.putAll(fields.classVariables);

if (Layouts.MODULE.getFields(from).start.getParentModule() != Layouts.MODULE.getFields(from)) {
this.parentModule = Layouts.MODULE.getFields(from).start.getParentModule();
if (fields.start.getParentModule() != fields) {
this.parentModule = fields.start.getParentModule();
} else {
this.parentModule = Layouts.MODULE.getFields(from).parentModule;
this.parentModule = fields.parentModule;
}

for (DynamicObject ancestor : Layouts.MODULE.getFields(from).ancestors()) {
for (DynamicObject ancestor : fields.ancestors()) {
Layouts.MODULE.getFields(ancestor).addDependent(rubyModuleObject);
}
}
16 changes: 10 additions & 6 deletions truffle/src/main/java/org/jruby/truffle/core/ModuleNodes.java
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@
import org.jcodings.specific.UTF8Encoding;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.array.ArrayHelpers;
import org.jruby.truffle.core.array.ArrayOperations;
import org.jruby.truffle.core.string.StringNodes;
import org.jruby.truffle.core.string.StringNodesFactory;
@@ -70,6 +71,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

@CoreClass(name = "Module")
@@ -790,16 +792,18 @@ public ClassVariablesNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@TruffleBoundary
@Specialization
public DynamicObject getClassVariables(DynamicObject module) {
CompilerDirectives.transferToInterpreter();

final DynamicObject array = Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);
final Map<String, Object> allClassVariables = ModuleOperations.getAllClassVariables(module);
final int size = allClassVariables.size();
final Object[] store = new Object[size];

for (String variable : ModuleOperations.getAllClassVariables(module).keySet()) {
ArrayOperations.append(array, getSymbol(variable));
int i = 0;
for (String variable : allClassVariables.keySet()) {
store[i++] = getSymbol(variable);
}
return array;
return ArrayHelpers.createArray(getContext(), store, size);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.jruby.truffle.core.array;

import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.Layouts;

import com.oracle.truffle.api.object.DynamicObject;

public abstract class ArrayHelpers {

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

public static int getSize(DynamicObject array) {
return Layouts.ARRAY.getSize(array);
}

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

public static DynamicObject createArray(RubyContext context, Object store, int size) {
return Layouts.ARRAY.createArray(context.getCoreLibrary().getArrayFactory(), store, size);
}

}
1,146 changes: 529 additions & 617 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
@@ -17,10 +17,10 @@
import org.jruby.util.StringSupport;

public enum CodeRange {
CR_UNKNOWN(0),
CR_7BIT(16),
CR_VALID(32),
CR_BROKEN(48);
CR_UNKNOWN(StringSupport.CR_UNKNOWN),
CR_7BIT(StringSupport.CR_7BIT),
CR_VALID(StringSupport.CR_VALID),
CR_BROKEN(StringSupport.CR_BROKEN);

private final int jrubyValue;

Original file line number Diff line number Diff line change
@@ -12,12 +12,14 @@
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.Source;

import org.jcodings.specific.UTF8Encoding;
import org.jruby.truffle.language.ModuleOperations;
import org.jruby.truffle.language.RubyConstant;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.array.ArrayMirror;
import org.jruby.truffle.core.array.ArrayReflector;
import org.jruby.truffle.core.array.ArrayUtils;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.core.array.ArrayOperations;
import org.jruby.truffle.core.string.StringOperations;
@@ -143,13 +145,11 @@ private RequireResult tryToRequireFile(String path, Node currentNode) throws IOE
try {
context.loadFile(expandedPath, currentNode);
} catch (RaiseException e) {
final ArrayMirror mirror = ArrayReflector.reflect((Object[]) Layouts.ARRAY.getStore(loadedFeatures));
final Object[] store = (Object[]) Layouts.ARRAY.getStore(loadedFeatures);
final int length = Layouts.ARRAY.getSize(loadedFeatures);
for (int i = length - 1; i >= 0; i--) {
if (mirror.get(i) == pathString) {
for (int j = length - 1; j > i; j--) {
mirror.set(i - 1, mirror.get(i));
}
if (store[i] == pathString) {
ArrayUtils.arraycopy(store, i + 1, store, i, length - i - 1);
Layouts.ARRAY.setSize(loadedFeatures, length - 1);
break;
}

0 comments on commit 069d815

Please sign in to comment.