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

Commits on Oct 7, 2015

  1. Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    167416c View commit details
  2. Copy the full SHA
    f06f04e View commit details
Original file line number Diff line number Diff line change
@@ -41,12 +41,11 @@

public class CoreMethodNodeManager {

private final DynamicObject objectClass;
private final RubyContext context;
private final SingletonClassNode singletonClassNode;

public CoreMethodNodeManager(DynamicObject objectClass, SingletonClassNode singletonClassNode) {
assert RubyGuards.isRubyClass(objectClass);
this.objectClass = objectClass;
public CoreMethodNodeManager(RubyContext context, SingletonClassNode singletonClassNode) {
this.context = context;
this.singletonClassNode = singletonClassNode;
}

@@ -68,15 +67,13 @@ private DynamicObject getSingletonClass(Object object) {
}

private void addCoreMethod(MethodDetails methodDetails) {
final RubyContext context = Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(objectClass)).getContext();

DynamicObject module;
String fullName = methodDetails.getClassAnnotation().name();

if (fullName.equals("main")) {
module = getSingletonClass(context.getCoreLibrary().getMainObject());
} else {
module = objectClass;
module = context.getCoreLibrary().getObjectClass();

for (String moduleName : fullName.split("::")) {
final RubyConstant constant = ModuleOperations.lookupConstant(context, module, moduleName);
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ public DynamicObject initialize(DynamicObject self, Object source, Object destin
// by Rubinius. Rubinius will do the heavy lifting of parsing the options hash and setting the `@options`
// ivar to the resulting int for EConv flags. Since we don't pass the proper data structures to EncodingUtils,
// we must override the flags after its had a pass in order to correct the bad flags value.
ecflags[0] = rubiniusToJRubyFlags((int) self.get("@options", Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(self)).getContext().getCoreLibrary().getNilObject()));
ecflags[0] = rubiniusToJRubyFlags((int) self.get("@options", getContext().getCoreLibrary().getNilObject()));

EConv econv = EncodingUtils.econvOpenOpts(runtime.getCurrentContext(), encNames[0], encNames[1], ecflags[0], ecopts[0]);

Original file line number Diff line number Diff line change
@@ -33,22 +33,20 @@
public abstract class ExceptionNodes {

@TruffleBoundary
public static DynamicObject asRubyStringArray(DynamicObject exception) {
public static DynamicObject asRubyStringArray(RubyContext context, DynamicObject exception) {
assert RubyGuards.isRubyException(exception);
assert Layouts.EXCEPTION.getBacktrace(exception) != null;

final RubyContext context = Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(exception)).getContext();

final List<String> lines = new BacktraceFormatter(context, EnumSet.of(BacktraceFormatter.FormattingFlags.OMIT_FROM_PREFIX))
.formatBacktrace(exception, Layouts.EXCEPTION.getBacktrace(exception));

final Object[] array = new Object[lines.size()];

for (int n = 0;n < lines.size(); n++) {
array[n] = Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(exception)).getContext().getCoreLibrary().getStringClass()), StringOperations.encodeByteList(lines.get(n), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null);
array[n] = Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(context.getCoreLibrary().getStringClass()), StringOperations.encodeByteList(lines.get(n), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null);
}

return Layouts.ARRAY.createArray(Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(exception)).getContext().getCoreLibrary().getArrayFactory(), array, array.length);
return Layouts.ARRAY.createArray(context.getCoreLibrary().getArrayFactory(), array, array.length);
}

public static void setMessage(DynamicObject exception, Object message) {
@@ -100,7 +98,7 @@ public Object backtrace(DynamicObject exception) {
if (customBacktrace != null) {
return customBacktrace;
} else if (Layouts.EXCEPTION.getBacktrace(exception) != null) {
return asRubyStringArray(exception);
return asRubyStringArray(getContext(), exception);
} else {
return nil();
}
Original file line number Diff line number Diff line change
@@ -49,25 +49,25 @@ public static Object[] getCaptures(DynamicObject matchData) {
return ArrayUtils.extractRange(Layouts.MATCH_DATA.getValues(matchData), 1, Layouts.MATCH_DATA.getValues(matchData).length);
}

public static Object begin(DynamicObject matchData, int index) {
public static Object begin(RubyContext context, DynamicObject matchData, int index) {
assert RubyGuards.isRubyMatchData(matchData);
final int b = (Layouts.MATCH_DATA.getRegion(matchData) == null) ? Layouts.MATCH_DATA.getBegin(matchData) : Layouts.MATCH_DATA.getRegion(matchData).beg[index];

if (b < 0) {
return Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(matchData)).getContext().getCoreLibrary().getNilObject();
return context.getCoreLibrary().getNilObject();
}

updateCharOffset(matchData);

return Layouts.MATCH_DATA.getCharOffsets(matchData).beg[index];
}

public static Object end(DynamicObject matchData, int index) {
public static Object end(RubyContext context, DynamicObject matchData, int index) {
assert RubyGuards.isRubyMatchData(matchData);
int e = (Layouts.MATCH_DATA.getRegion(matchData) == null) ? Layouts.MATCH_DATA.getEnd(matchData) : Layouts.MATCH_DATA.getRegion(matchData).end[index];

if (e < 0) {
return Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(matchData)).getContext().getCoreLibrary().getNilObject();
return context.getCoreLibrary().getNilObject();
}

final CodeRangeable sourceWrapped = StringOperations.getCodeRangeable(Layouts.MATCH_DATA.getSource(matchData));
@@ -304,7 +304,7 @@ public Object begin(DynamicObject matchData, int index) {
getContext().getCoreLibrary().indexError(String.format("index %d out of matches", index), this));

} else {
return MatchDataNodes.begin(matchData, index);
return MatchDataNodes.begin(getContext(), matchData, index);
}
}
}
@@ -342,7 +342,7 @@ public Object end(DynamicObject matchData, int index) {
getContext().getCoreLibrary().indexError(String.format("index %d out of matches", index), this));

} else {
return MatchDataNodes.end(matchData, index);
return MatchDataNodes.end(getContext(), matchData, index);
}
}
}
Original file line number Diff line number Diff line change
@@ -110,7 +110,7 @@ public AddNode(RubyContext context, SourceSection sourceSection) {

@Specialization(guards = "isRubyString(other)")
public DynamicObject add(DynamicObject string, DynamicObject other) {
final Encoding enc = StringOperations.checkEncoding(string, StringOperations.getCodeRangeable(other), this);
final Encoding enc = StringOperations.checkEncoding(getContext(), string, StringOperations.getCodeRangeable(other), this);
final DynamicObject ret = Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringSupport.addByteLists(StringOperations.getByteList(string), StringOperations.getByteList(other)), StringSupport.CR_UNKNOWN, null);

if (taintResultNode == null) {
@@ -786,7 +786,7 @@ private int countSlow(DynamicObject string, DynamicObject... otherStrings) {

assert RubyGuards.isRubyString(otherStr);

enc = StringOperations.checkEncoding(string, StringOperations.getCodeRangeable(otherStr), this);
enc = StringOperations.checkEncoding(getContext(), string, StringOperations.getCodeRangeable(otherStr), this);
tables = StringSupport.trSetupTable(StringOperations.getByteList(otherStr), getContext().getRuntime(), table, tables, false, enc);
}

@@ -902,7 +902,7 @@ private Object deleteBangSlow(DynamicObject string, DynamicObject... otherString
assert RubyGuards.isRubyString(string);

DynamicObject otherString = otherStrings[0];
Encoding enc = StringOperations.checkEncoding(string, StringOperations.getCodeRangeable(otherString), this);
Encoding enc = StringOperations.checkEncoding(getContext(), string, StringOperations.getCodeRangeable(otherString), this);

boolean[] squeeze = new boolean[StringSupport.TRANS_SIZE + 1];
StringSupport.TrTables tables = StringSupport.trSetupTable(StringOperations.getByteList(otherString),
@@ -912,7 +912,7 @@ private Object deleteBangSlow(DynamicObject string, DynamicObject... otherString
for (int i = 1; i < otherStrings.length; i++) {
assert RubyGuards.isRubyString(otherStrings[i]);

enc = StringOperations.checkEncoding(string, StringOperations.getCodeRangeable(otherStrings[i]), this);
enc = StringOperations.checkEncoding(getContext(), string, StringOperations.getCodeRangeable(otherStrings[i]), this);
tables = StringSupport.trSetupTable(StringOperations.getByteList(otherStrings[i]), getContext().getRuntime(), squeeze, tables, false, enc);
}

@@ -1750,15 +1750,15 @@ public Object squeezeBang(VirtualFrame frame, DynamicObject string, Object... ar
private Object performSqueezeBang(DynamicObject string, DynamicObject[] otherStrings) {

DynamicObject otherStr = otherStrings[0];
Encoding enc = StringOperations.checkEncoding(string, StringOperations.getCodeRangeable(otherStr), this);
Encoding enc = StringOperations.checkEncoding(getContext(), string, StringOperations.getCodeRangeable(otherStr), this);
final boolean squeeze[] = new boolean[StringSupport.TRANS_SIZE + 1];
StringSupport.TrTables tables = StringSupport.trSetupTable(StringOperations.getByteList(otherStr), getContext().getRuntime(), squeeze, null, true, enc);

boolean singlebyte = StringOperations.singleByteOptimizable(string) && StringOperations.singleByteOptimizable(otherStr);

for (int i = 1; i < otherStrings.length; i++) {
otherStr = otherStrings[i];
enc = StringOperations.checkEncoding(string, StringOperations.getCodeRangeable(otherStr));
enc = StringOperations.checkEncoding(getContext(), string, StringOperations.getCodeRangeable(otherStr), this);
singlebyte = singlebyte && StringOperations.singleByteOptimizable(otherStr);
tables = StringSupport.trSetupTable(StringOperations.getByteList(otherStr), getContext().getRuntime(), squeeze, tables, false, enc);
}
Original file line number Diff line number Diff line change
@@ -650,9 +650,9 @@ public DynamicObject objectTypeOf(DynamicObject value) {
}

@CoreMethod(names = "spawn_process", onSingleton = true, required = 3)
public abstract static class SpawnProcess extends CoreMethodArrayArgumentsNode {
public abstract static class SpawnProcessNode extends CoreMethodArrayArgumentsNode {

public SpawnProcess(RubyContext context, SourceSection sourceSection) {
public SpawnProcessNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@@ -665,7 +665,7 @@ public int spawn(DynamicObject command,
DynamicObject environmentVariables) {

final long longPid = call(
StringOperations.getString(command),
StringOperations.getString(getContext(), command),
toStringArray(arguments),
toStringArray(environmentVariables));
assert longPid <= Integer.MAX_VALUE;
@@ -687,7 +687,7 @@ private String[] toStringArray(DynamicObject rubyStrings) {

for (int i = 0; i < size; i++) {
assert Layouts.STRING.isString(unconvertedStrings[i]);
strings[i] = StringOperations.getString((DynamicObject) unconvertedStrings[i]);
strings[i] = StringOperations.getString(getContext(), (DynamicObject) unconvertedStrings[i]);
}

return strings;
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ public Object execute(VirtualFrame frame) {
@TruffleBoundary
private Object readMatchReference() {
DynamicObject receiver = Layouts.THREAD.getThreadLocals(getContext().getThreadManager().getCurrentThread());
final Object match = receiver.get("$~", Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(receiver)).getContext().getCoreLibrary().getNilObject());
final Object match = receiver.get("$~", nil());

if (match == null || match == nil()) {
return nil();
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ public DynamicObject getNormalObjectSingletonClass(DynamicObject object) {
attached = object;
}

final String name = String.format("#<Class:#<%s:0x%x>>", Layouts.MODULE.getFields(logicalClass).getName(), ObjectIDOperations.verySlowGetObjectID(object));
final String name = String.format("#<Class:#<%s:0x%x>>", Layouts.MODULE.getFields(logicalClass).getName(), ObjectIDOperations.verySlowGetObjectID(getContext(), object));
final DynamicObject singletonClass = ClassNodes.createSingletonClassOfObject(getContext(), logicalClass, attached, name);
propagateFrozen(object, singletonClass);

Original file line number Diff line number Diff line change
@@ -151,7 +151,7 @@ public IOOpenPrimitiveNode(RubyContext context, SourceSection sourceSection) {

@Specialization(guards = "isRubyString(path)")
public int open(DynamicObject path, int mode, int permission) {
return posix().open(StringOperations.getString(path), mode, permission);
return posix().open(StringOperations.getString(getContext(), path), mode, permission);
}

}
@@ -171,7 +171,7 @@ public int truncate(DynamicObject path, int length) {

@Specialization(guards = "isRubyString(path)")
public int truncate(DynamicObject path, long length) {
final int result = posix().truncate(StringOperations.getString(path), length);
final int result = posix().truncate(StringOperations.getString(getContext(), path), length);
if (result == -1) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().errnoError(posix().errno(), this));
@@ -360,7 +360,7 @@ public IOReopenPathPrimitiveNode(RubyContext context, SourceSection sourceSectio
@TruffleBoundary
public void performReopenPath(DynamicObject file, DynamicObject path, int mode) {
int fd = Layouts.IO.getDescriptor(file);
final String pathString = StringOperations.getString(path);
final String pathString = StringOperations.getString(getContext(), path);

int otherFd = posix().open(pathString, mode, 666);
if (otherFd < 0) {
Original file line number Diff line number Diff line change
@@ -918,7 +918,7 @@ public Object stringByteIndex(DynamicObject string, DynamicObject pattern, int o
return nil();
}

final Encoding encoding = StringOperations.checkEncoding(string, StringOperations.getCodeRangeable(pattern), this);
final Encoding encoding = StringOperations.checkEncoding(getContext(), string, StringOperations.getCodeRangeable(pattern), this);
int p = StringOperations.getByteList(string).getBegin();
final int e = p + StringOperations.getByteList(string).getRealSize();
int pp = StringOperations.getByteList(pattern).getBegin();
Original file line number Diff line number Diff line change
@@ -270,7 +270,7 @@ public void initialize() {
// Set the load path

DynamicObject receiver = coreLibrary.getGlobalVariablesObject();
final DynamicObject loadPath = (DynamicObject) receiver.get("$:", Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(receiver)).getContext().getCoreLibrary().getNilObject());
final DynamicObject loadPath = (DynamicObject) receiver.get("$:", coreLibrary.getNilObject());

for (IRubyObject path : ((org.jruby.RubyArray) runtime.getLoadService().getLoadPath()).toJavaArray()) {
String pathString = path.toString();
@@ -495,7 +495,7 @@ public org.jruby.RubyString toJRubyString(DynamicObject string) {

final org.jruby.RubyString jrubyString = runtime.newString(StringOperations.getByteList(string).dup());

final Object tainted = string.get(Layouts.TAINTED_IDENTIFIER, Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(string)).getContext().getCoreLibrary().getNilObject());
final Object tainted = string.get(Layouts.TAINTED_IDENTIFIER, coreLibrary.getNilObject());

if (tainted instanceof Boolean && (boolean) tainted) {
jrubyString.setTaint(true);
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ public ForeignAccessFactory getForeignAccessFactory() {
}

private RubyContext getContext() {
return Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(Layouts.BASIC_OBJECT.getLogicalClass(this))).getContext();
return Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(this)).getContext();
}

}
Original file line number Diff line number Diff line change
@@ -520,7 +520,7 @@ private void addCoreMethods() {
arrayMaxBlock = new ArrayNodes.MaxBlock(context);

// Bring in core method nodes
CoreMethodNodeManager coreMethodNodeManager = new CoreMethodNodeManager(objectClass, node.getSingletonClassNode());
CoreMethodNodeManager coreMethodNodeManager = new CoreMethodNodeManager(context, node.getSingletonClassNode());

Main.printTruffleTimeMetric("before-load-truffle-nodes");
coreMethodNodeManager.addCoreMethodNodes(ArrayNodesFactory.getFactories());
@@ -583,8 +583,8 @@ private void initializeGlobalVariables() {

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("$:", globals.get("$LOAD_PATH", Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(globals)).getContext().getCoreLibrary().getNilObject()), 0);
globals.define("$\"", globals.get("$LOADED_FEATURES", Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(globals)).getContext().getCoreLibrary().getNilObject()), 0);
globals.define("$:", globals.get("$LOAD_PATH", nilObject), 0);
globals.define("$\"", globals.get("$LOADED_FEATURES", nilObject), 0);
globals.define("$,", nilObject, 0);
globals.define("$0", Layouts.STRING.createString(stringFactory, StringOperations.encodeByteList(context.getRuntime().getInstanceConfig().displayedFileName(), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null), 0);

@@ -1403,11 +1403,11 @@ public DynamicObject getGlobalVariablesObject() {
}

public DynamicObject getLoadPath() {
return (DynamicObject) globalVariablesObject.get("$LOAD_PATH", Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(globalVariablesObject)).getContext().getCoreLibrary().getNilObject());
return (DynamicObject) globalVariablesObject.get("$LOAD_PATH", context.getCoreLibrary().getNilObject());
}

public DynamicObject getLoadedFeatures() {
return (DynamicObject) globalVariablesObject.get("$LOADED_FEATURES", Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(globalVariablesObject)).getContext().getCoreLibrary().getNilObject());
return (DynamicObject) globalVariablesObject.get("$LOADED_FEATURES", context.getCoreLibrary().getNilObject());
}

public DynamicObject getMainObject() {
Loading