Skip to content

Commit

Permalink
Showing 40 changed files with 853 additions and 545 deletions.
37 changes: 0 additions & 37 deletions spec/truffle/tags/core/process/getrlimit_tags.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,2 @@
fails:Process.getrlimit returns a two-element Array of Integers
fails:Process.getrlimit when passed an Object calls #to_int to convert to an Integer
fails:Process.getrlimit when passed an Object raises a TypeError if #to_int does not return an Integer
fails:Process.getrlimit when passed a Symbol coerces :AS into RLIMIT_AS
fails:Process.getrlimit when passed a Symbol coerces :CORE into RLIMIT_CORE
fails:Process.getrlimit when passed a Symbol coerces :CPU into RLIMIT_CPU
fails:Process.getrlimit when passed a Symbol coerces :DATA into RLIMIT_DATA
fails:Process.getrlimit when passed a Symbol coerces :FSIZE into RLIMIT_FSIZE
fails:Process.getrlimit when passed a Symbol coerces :NOFILE into RLIMIT_NOFILE
fails:Process.getrlimit when passed a Symbol coerces :STACK into RLIMIT_STACK
fails:Process.getrlimit when passed a Symbol coerces :MEMLOCK into RLIMIT_MEMLOCK
fails:Process.getrlimit when passed a Symbol coerces :NPROC into RLIMIT_NPROC
fails:Process.getrlimit when passed a Symbol coerces :RSS into RLIMIT_RSS
fails:Process.getrlimit when passed a Symbol raises ArgumentError when passed an unknown resource
fails:Process.getrlimit when passed a String coerces 'AS' into RLIMIT_AS
fails:Process.getrlimit when passed a String coerces 'CORE' into RLIMIT_CORE
fails:Process.getrlimit when passed a String coerces 'CPU' into RLIMIT_CPU
fails:Process.getrlimit when passed a String coerces 'DATA' into RLIMIT_DATA
fails:Process.getrlimit when passed a String coerces 'FSIZE' into RLIMIT_FSIZE
fails:Process.getrlimit when passed a String coerces 'NOFILE' into RLIMIT_NOFILE
fails:Process.getrlimit when passed a String coerces 'STACK' into RLIMIT_STACK
fails:Process.getrlimit when passed a String coerces 'MEMLOCK' into RLIMIT_MEMLOCK
fails:Process.getrlimit when passed a String coerces 'NPROC' into RLIMIT_NPROC
fails:Process.getrlimit when passed a String coerces 'RSS' into RLIMIT_RSS
fails:Process.getrlimit when passed a String raises ArgumentError when passed an unknown resource
fails:Process.getrlimit when passed on Object calls #to_str to convert to a String
fails:Process.getrlimit when passed on Object calls #to_int if #to_str does not return a String
fails:Process.getrlimit when passed a Symbol coerces :SBSIZE into RLIMIT_SBSIZE
fails:Process.getrlimit when passed a Symbol coerces :RTTIME into RLIMIT_RTTIME
fails:Process.getrlimit when passed a Symbol coerces :MSGQUEUE into RLIMIT_MSGQUEUE
fails:Process.getrlimit when passed a Symbol coerces :SIGPENDING into RLIMIT_SIGPENDING
fails:Process.getrlimit when passed a Symbol coerces :RTPRIO into RLIMIT_RTPRIO
fails:Process.getrlimit when passed a Symbol coerces :NICE into RLIMIT_NICE
fails:Process.getrlimit when passed a String coerces 'SBSIZE' into RLIMIT_SBSIZE
fails:Process.getrlimit when passed a String coerces 'RTTIME' into RLIMIT_RTTIME
fails:Process.getrlimit when passed a String coerces 'MSGQUEUE' into RLIMIT_MSGQUEUE
fails:Process.getrlimit when passed a String coerces 'SIGPENDING' into RLIMIT_SIGPENDING
fails:Process.getrlimit when passed a String coerces 'RTPRIO' into RLIMIT_RTPRIO
fails:Process.getrlimit when passed a String coerces 'NICE' into RLIMIT_NICE
38 changes: 0 additions & 38 deletions spec/truffle/tags/core/process/setrlimit_tags.txt

This file was deleted.

6 changes: 4 additions & 2 deletions tool/truffle/translate_rubinius_config.rb
Original file line number Diff line number Diff line change
@@ -11,8 +11,10 @@
puts " // Generated from tool/truffle/translate_rubinius_config.rb < ../rubinius/runtime/platform.conf"

ARGF.each do |line|
next unless /^(?<var>rbx(\.\w+)*) = (?<value>.+)$/ =~ line
next unless /^(?<var>rbx(\.\w+)*) = (?<value>.*)$/ =~ line
code = case value
when ""
0
when /^-?\d+$/
case Integer(value)
when (-2**31...2**31)
@@ -25,7 +27,7 @@
when "true"
value
else
"context.makeString(\"#{value}\")"
"string(context, \"#{value}\")"
end
puts " configuration.config(\"#{var}\", #{code});"
end
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.StringNodes;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.truffle.runtime.core.RubySymbol;
@@ -36,7 +37,7 @@ protected RubySymbol toSymbol(RubySymbol symbol) {

@Specialization
protected RubySymbol toSymbol(RubyString string) {
return getContext().getSymbol(string.getByteList());
return getContext().getSymbol(StringNodes.getByteList(string));
}

@Specialization
Original file line number Diff line number Diff line change
@@ -180,7 +180,7 @@ public InstanceEvalNode(RubyContext context, SourceSection sourceSection) {
public Object instanceEval(VirtualFrame frame, Object receiver, RubyString string, NotProvided block) {
CompilerDirectives.transferToInterpreter();

return getContext().instanceEval(string.getByteList(), receiver, this);
return getContext().instanceEval(StringNodes.getByteList(string), receiver, this);
}

@Specialization
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ public CompatibleQueryNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization
public Object isCompatible(RubyString first, RubyString second) {
final Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(first, second);
final Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(StringNodes.getCodeRangeable(first), StringNodes.getCodeRangeable(second));

if (compatibleEncoding != null) {
return RubyEncoding.getEncoding(compatibleEncoding);
@@ -79,7 +79,7 @@ public Object isCompatible(RubyEncoding first, RubyEncoding second) {
@TruffleBoundary
@Specialization
public Object isCompatible(RubyString first, RubyRegexp second) {
final Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(first.getByteList().getEncoding(), second.getRegex().getEncoding());
final Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(StringNodes.getByteList(first).getEncoding(), second.getRegex().getEncoding());

if (compatibleEncoding != null) {
return RubyEncoding.getEncoding(compatibleEncoding);
@@ -91,7 +91,7 @@ public Object isCompatible(RubyString first, RubyRegexp second) {
@TruffleBoundary
@Specialization
public Object isCompatible(RubyRegexp first, RubyString second) {
final Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(first.getRegex().getEncoding(), second.getByteList().getEncoding());
final Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(first.getRegex().getEncoding(), StringNodes.getByteList(second).getEncoding());

if (compatibleEncoding != null) {
return RubyEncoding.getEncoding(compatibleEncoding);
@@ -139,7 +139,7 @@ public Object isCompatible(RubySymbol first, RubyRegexp second) {
@TruffleBoundary
@Specialization
public Object isCompatible(RubyString first, RubySymbol second) {
final Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(first, second);
final Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(StringNodes.getCodeRangeable(first), second);

if (compatibleEncoding != null) {
return RubyEncoding.getEncoding(compatibleEncoding);
@@ -163,7 +163,7 @@ public Object isCompatible(RubySymbol first, RubySymbol second) {
@TruffleBoundary
@Specialization
public Object isCompatible(RubyString first, RubyEncoding second) {
final Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(first.getByteList().getEncoding(), second.getEncoding());
final Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(StringNodes.getByteList(first).getEncoding(), second.getEncoding());

if (compatibleEncoding != null) {
return RubyEncoding.getEncoding(compatibleEncoding);
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ public RubyRegexp executeRubyRegexp(VirtualFrame frame) {

for (int n = 0; n < children.length; n++) {
final Object child = children[n].execute(frame);
strings[n] = org.jruby.RubyString.newString(getContext().getRuntime(), ((RubyString) toS.call(frame, child, "to_s", null)).getByteList());
strings[n] = org.jruby.RubyString.newString(getContext().getRuntime(), StringNodes.getByteList(((RubyString) toS.call(frame, child, "to_s", null))));
}

// TODO 27-APR=2015 BJF Adding workaround to temporarily fix CGI error until Regex overhaul https://github.com/jruby/jruby/issues/2802
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
*/
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.ExplodeLoop;
@@ -80,7 +79,7 @@ private RubyString concat(RubyString[] strings) {
try {
builder.append19(getContext().toJRuby(string));
} catch (org.jruby.exceptions.RaiseException e) {
throw new RaiseException(getContext().getCoreLibrary().encodingCompatibilityErrorIncompatible(builder.getEncoding().getCharsetName(), string.getByteList().getEncoding().getCharsetName(), this));
throw new RaiseException(getContext().getCoreLibrary().encodingCompatibilityErrorIncompatible(builder.getEncoding().getCharsetName(), StringNodes.getByteList(string).getEncoding().getCharsetName(), this));
}
}
}
Original file line number Diff line number Diff line change
@@ -471,7 +471,7 @@ protected RubyBinding getCallerBinding(VirtualFrame frame) {
public Object eval(VirtualFrame frame, RubyString source, NotProvided binding, NotProvided filename, NotProvided lineNumber) {
CompilerDirectives.transferToInterpreter();

return getContext().eval(source.getByteList(), getCallerBinding(frame), true, this);
return getContext().eval(StringNodes.getByteList(source), getCallerBinding(frame), true, this);
}

@Specialization(guards = "isNil(noBinding)")
@@ -486,21 +486,21 @@ public Object eval(VirtualFrame frame, RubyString source, Object noBinding, Ruby
public Object eval(RubyString source, RubyBinding binding, NotProvided filename, NotProvided lineNumber) {
CompilerDirectives.transferToInterpreter();

return getContext().eval(source.getByteList(), binding, false, this);
return getContext().eval(StringNodes.getByteList(source), binding, false, this);
}

@Specialization
public Object eval(RubyString source, RubyBinding binding, RubyString filename, NotProvided lineNumber) {
CompilerDirectives.transferToInterpreter();

return getContext().eval(source.getByteList(), binding, false, filename.toString(), this);
return getContext().eval(StringNodes.getByteList(source), binding, false, filename.toString(), this);
}

@Specialization
public Object eval(RubyString source, RubyBinding binding, RubyString filename, int lineNumber) {
CompilerDirectives.transferToInterpreter();

return getContext().eval(source.getByteList(), binding, false, filename.toString(), this);
return getContext().eval(StringNodes.getByteList(source), binding, false, filename.toString(), this);
}

@Specialization(guards = "!isRubyBinding(badBinding)")
@@ -1709,7 +1709,7 @@ public RubyString formatUncached(
throw handleException(e);
}

return finishFormat(format.getByteList(), result);
return finishFormat(StringNodes.getByteList(format), result);
}

private RuntimeException handleException(PackException exception) {
@@ -1764,16 +1764,16 @@ private RubyString finishFormat(ByteList format, PackResult result) {
}

protected ByteList privatizeByteList(RubyString string) {
return string.getByteList().dup();
return StringNodes.getByteList(string).dup();
}

protected boolean byteListsEqual(RubyString string, ByteList byteList) {
return string.getByteList().equal(byteList);
return StringNodes.getByteList(string).equal(byteList);
}

protected CallTarget compileFormat(RubyString format) {
try {
return new FormatParser(getContext()).parse(format.getByteList());
return new FormatParser(getContext()).parse(StringNodes.getByteList(format));
} catch (FormatException e) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError(e.getMessage(), this));
Original file line number Diff line number Diff line change
@@ -85,7 +85,7 @@ public Object getIndex(RubyMatchData matchData, RubyString index, NotProvided le
CompilerDirectives.transferToInterpreter();

try {
final int i = matchData.getBackrefNumber(index.getByteList());
final int i = matchData.getBackrefNumber(StringNodes.getByteList(index));

return getIndex(matchData, i, NotProvided.INSTANCE);
}
@@ -257,7 +257,7 @@ public ToSNode(RubyContext context, SourceSection sourceSection) {
public RubyString toS(RubyMatchData matchData) {
CompilerDirectives.transferToInterpreter();

final ByteList bytes = matchData.getGlobal().getByteList().dup();
final ByteList bytes = StringNodes.getByteList(matchData.getGlobal()).dup();
return createString(bytes);
}
}
Original file line number Diff line number Diff line change
@@ -624,7 +624,7 @@ public Object classEval(VirtualFrame frame, RubyModule module, RubyString code,

private Object classEvalSource(VirtualFrame frame, RubyModule module, RubyString code, String file) {
RubyBinding binding = getCallerBinding(frame);
Encoding encoding = code.getByteList().getEncoding();
Encoding encoding = StringNodes.getByteList(code).getEncoding();

CompilerDirectives.transferToInterpreter();
Source source = Source.fromText(code.toString(), file);
Original file line number Diff line number Diff line change
@@ -150,7 +150,7 @@ public EscapeNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization
public RubyString escape(RubyString pattern) {
return createString(org.jruby.RubyRegexp.quote19(new ByteList(pattern.getByteList()), true).toString());
return createString(org.jruby.RubyRegexp.quote19(new ByteList(StringNodes.getByteList(pattern)), true).toString());
}

}
@@ -257,8 +257,8 @@ public QuoteNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization
public RubyString quote(RubyString raw) {
boolean isAsciiOnly = raw.getByteList().getEncoding().isAsciiCompatible() && raw.scanForCodeRange() == CR_7BIT;
return createString(org.jruby.RubyRegexp.quote19(raw.getByteList(), isAsciiOnly));
boolean isAsciiOnly = StringNodes.getByteList(raw).getEncoding().isAsciiCompatible() && StringNodes.scanForCodeRange(raw) == CR_7BIT;
return createString(org.jruby.RubyRegexp.quote19(StringNodes.getByteList(raw), isAsciiOnly));
}

@Specialization
Original file line number Diff line number Diff line change
@@ -18,30 +18,30 @@
public class StringGuards {

public static boolean isSingleByteOptimizable(RubyString string) {
return StringSupport.isSingleByteOptimizable(string, string.getByteList().getEncoding());
return StringSupport.isSingleByteOptimizable(StringNodes.getCodeRangeable(string), StringNodes.getByteList(string).getEncoding());
}

public static boolean isAsciiCompatible(RubyString string) {
return string.getByteList().getEncoding().isAsciiCompatible();
return StringNodes.getByteList(string).getEncoding().isAsciiCompatible();
}

public static boolean isSingleByteOptimizableOrAsciiCompatible(RubyString string) {
return isSingleByteOptimizable(string) || isAsciiCompatible(string);
}

public static boolean isSingleByte(RubyString string) {
return string.getByteList().getEncoding().isSingleByte();
return StringNodes.getByteList(string).getEncoding().isSingleByte();
}

public static boolean isValidOr7BitEncoding(RubyString string) {
return string.isCodeRangeValid() || CodeRangeSupport.isCodeRangeAsciiOnly(string);
return StringNodes.isCodeRangeValid(string) || CodeRangeSupport.isCodeRangeAsciiOnly(StringNodes.getCodeRangeable(string));
}

public static boolean isFixedWidthEncoding(RubyString string) {
return string.getByteList().getEncoding().isFixedWidth();
return StringNodes.getByteList(string).getEncoding().isFixedWidth();
}

public static boolean isValidUtf8(RubyString string) {
return string.isCodeRangeValid() && string.getByteList().getEncoding() instanceof UTF8Encoding;
return StringNodes.isCodeRangeValid(string) && StringNodes.getByteList(string).getEncoding() instanceof UTF8Encoding;
}
}
448 changes: 265 additions & 183 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -192,7 +192,7 @@ public DumpStringNode(RubyContext context, SourceSection sourceSection) {
public RubyString dumpString(RubyString string) {
final StringBuilder builder = new StringBuilder();

for (byte b : string.getByteList().unsafeBytes()) {
for (byte b : StringNodes.getByteList(string).unsafeBytes()) {
builder.append(String.format("\\x%02x", b));
}

Original file line number Diff line number Diff line change
@@ -2860,7 +2860,7 @@ public RubyString packUncached(
throw handleException(e);
}

return finishPack(format.getByteList(), result);
return finishPack(StringNodes.getByteList(format), result);
}

private RuntimeException handleException(PackException exception) {
@@ -2940,11 +2940,11 @@ public Object pack(VirtualFrame frame, RubyArray array, Object format) {
}

protected ByteList privatizeByteList(RubyString string) {
return string.getByteList().dup();
return StringNodes.getByteList(string).dup();
}

protected boolean byteListsEqual(RubyString string, ByteList byteList) {
return string.getByteList().equal(byteList);
return StringNodes.getByteList(string).equal(byteList);
}

protected CallTarget compileFormat(RubyString format) {
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
package org.jruby.truffle.nodes.dispatch;

import com.oracle.truffle.api.utilities.BranchProfile;
import org.jruby.truffle.nodes.core.StringNodes;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.truffle.runtime.core.RubySymbol;
@@ -38,7 +39,7 @@ public CachedDispatchNode(
if (cachedName instanceof RubySymbol) {
cachedNameAsSymbol = (RubySymbol) cachedName;
} else if (cachedName instanceof RubyString) {
cachedNameAsSymbol = context.getSymbol(((RubyString) cachedName).getByteList());
cachedNameAsSymbol = context.getSymbol(StringNodes.getByteList(((RubyString) cachedName)));
} else if (cachedName instanceof String) {
cachedNameAsSymbol = context.getSymbol((String) cachedName);
} else {
@@ -68,7 +69,7 @@ protected final boolean guardName(Object methodName) {
// TODO(CS, 11-Jan-15) this just repeats the above guard...
return cachedName == methodName;
} else if (cachedName instanceof RubyString) {
return (methodName instanceof RubyString) && ((RubyString) cachedName).getByteList().equal(((RubyString) methodName).getByteList());
return (methodName instanceof RubyString) && StringNodes.getByteList(((RubyString) cachedName)).equal(StringNodes.getByteList(((RubyString) methodName)));
} else {
throw new UnsupportedOperationException();
}
Original file line number Diff line number Diff line change
@@ -161,7 +161,7 @@ public UpdateNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization
public RubyBasicObject update(RubyBasicObject digestObject, RubyString message) {
final ByteList bytes = message.getByteList();
final ByteList bytes = StringNodes.getByteList(message);
getDigest(digestObject).update(bytes.getUnsafeBytes(), bytes.begin(), bytes.length());
return digestObject;
}
@@ -236,7 +236,7 @@ public BubbleBabbleNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization
public RubyString bubblebabble(RubyString message) {
final ByteList byteList = message.getByteList();
final ByteList byteList = StringNodes.getByteList(message);
return createString(BubbleBabble.bubblebabble(byteList.unsafeBytes(), byteList.begin(), byteList.length()));
}

Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ public int crc32(NotProvided message, NotProvided initial) {
@TruffleBoundary
@Specialization
public long crc32(RubyString message, NotProvided initial) {
final ByteList bytes = message.getByteList();
final ByteList bytes = StringNodes.getByteList(message);
final CRC32 crc32 = new CRC32();
crc32.update(bytes.unsafeBytes(), bytes.begin(), bytes.length());
return crc32.getValue();
@@ -62,7 +62,7 @@ public long crc32(RubyString message, int initial) {
@TruffleBoundary
@Specialization
public long crc32(RubyString message, long initial) {
final ByteList bytes = message.getByteList();
final ByteList bytes = StringNodes.getByteList(message);
final CRC32 crc32 = new CRC32();
crc32.update(bytes.unsafeBytes(), bytes.begin(), bytes.length());
return JZlib.crc32_combine(initial, crc32.getValue(), bytes.length());
@@ -90,7 +90,7 @@ public DeflateNode(RubyContext context, SourceSection sourceSection) {
public RubyString deflate(RubyString message, int level) {
final Deflater deflater = new Deflater(level);

final ByteList messageBytes = message.getByteList();
final ByteList messageBytes = StringNodes.getByteList(message);
deflater.setInput(messageBytes.unsafeBytes(), messageBytes.begin(), messageBytes.length());

final ByteList outputBytes = new ByteList(BUFFER_SIZE);
@@ -122,7 +122,7 @@ public InflateNode(RubyContext context, SourceSection sourceSection) {
public RubyString inflate(RubyString message) {
final Inflater inflater = new Inflater();

final ByteList messageBytes = message.getByteList();
final ByteList messageBytes = StringNodes.getByteList(message);
inflater.setInput(messageBytes.unsafeBytes(), messageBytes.begin(), messageBytes.length());

final ByteList outputBytes = new ByteList(BUFFER_SIZE);
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.MethodNodes;
import org.jruby.truffle.nodes.core.StringNodes;
import org.jruby.truffle.nodes.dispatch.DispatchAction;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.MissingBehavior;
@@ -241,7 +242,7 @@ public InteropStringIsBoxed(RubyContext context, SourceSection sourceSection) {
@Override
public Object execute(VirtualFrame frame) {
Object o = ForeignAccessArguments.getReceiver(frame.getArguments());
return o instanceof RubyString && ((RubyString) o).getByteList().length() == 1;
return o instanceof RubyString && StringNodes.getByteList(((RubyString) o)).length() == 1;
}
}

@@ -253,7 +254,7 @@ public InteropStringUnboxNode(RubyContext context, SourceSection sourceSection)

@Override
public Object execute(VirtualFrame frame) {
return ((RubyString) ForeignAccessArguments.getReceiver(frame.getArguments())).getByteList().get(0);
return StringNodes.getByteList(((RubyString) ForeignAccessArguments.getReceiver(frame.getArguments()))).get(0);
}
}

@@ -347,10 +348,10 @@ public Object execute(VirtualFrame frame) {
if (ForeignAccessArguments.getReceiver(frame.getArguments()) instanceof RubyString) {
final RubyString string = (RubyString) ForeignAccessArguments.getReceiver(frame.getArguments());
final int index = (int) ForeignAccessArguments.getArgument(frame.getArguments(), labelIndex);
if (index >= string.getByteList().length()) {
if (index >= StringNodes.getByteList(string).length()) {
return 0;
} else {
return (byte) string.getByteList().get(index);
return (byte) StringNodes.getByteList(string).get(index);
}
} else {
CompilerDirectives.transferToInterpreter();
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ public StringLiteralNode(RubyContext context, SourceSection sourceSection, ByteL
@Override
public RubyString execute(VirtualFrame frame) {
final RubyString string = createString(bytes.dup());
string.setCodeRange(codeRange);
StringNodes.setCodeRange(string, codeRange);

return string;
}
Original file line number Diff line number Diff line change
@@ -48,11 +48,11 @@ public PrependNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public RubiniusByteArray prepend(RubiniusByteArray bytes, RubyString string) {
final int prependLength = string.getByteList().getUnsafeBytes().length;
final int prependLength = StringNodes.getByteList(string).getUnsafeBytes().length;
final int originalLength = bytes.getBytes().getUnsafeBytes().length;
final int newLength = prependLength + originalLength;
final byte[] prependedBytes = new byte[newLength];
System.arraycopy(string.getByteList().getUnsafeBytes(), 0, prependedBytes, 0, prependLength);
System.arraycopy(StringNodes.getByteList(string).getUnsafeBytes(), 0, prependedBytes, 0, prependLength);
System.arraycopy(bytes.getBytes().getUnsafeBytes(), 0, prependedBytes, prependLength, originalLength);
return new RubiniusByteArray(getContext().getCoreLibrary().getByteArrayClass(), new ByteList(prependedBytes));
}
@@ -103,7 +103,7 @@ public LocateNode(RubyContext context, SourceSection sourceSection) {
@Specialization
public Object getByte(RubiniusByteArray bytes, RubyString pattern, int start, int length) {
final int index = new ByteList(bytes.getBytes().unsafeBytes(), start, length)
.indexOf(pattern.getByteList());
.indexOf(StringNodes.getByteList(pattern));

if (index == -1) {
return nil();
Original file line number Diff line number Diff line change
@@ -65,14 +65,14 @@ public Object encodingConverterPrimitiveConvert(RubyEncodingConverter encodingCo

// Taken from org.jruby.RubyConverter#primitive_convert.

source.modify();
source.clearCodeRange();
StringNodes.modify(source);
StringNodes.clearCodeRange(source);

target.modify();
target.clearCodeRange();
StringNodes.modify(target);
StringNodes.clearCodeRange(target);

final ByteList inBytes = source.getByteList();
final ByteList outBytes = target.getByteList();
final ByteList inBytes = StringNodes.getByteList(source);
final ByteList outBytes = StringNodes.getByteList(target);

final Ptr inPtr = new Ptr();
final Ptr outPtr = new Ptr();
@@ -85,8 +85,8 @@ public Object encodingConverterPrimitiveConvert(RubyEncodingConverter encodingCo
if (size == -1) {
size = 16; // in MRI, this is RSTRING_EMBED_LEN_MAX

if (size < source.getByteList().getRealSize()) {
size = source.getByteList().getRealSize();
if (size < StringNodes.getByteList(source).getRealSize()) {
size = StringNodes.getByteList(source).getRealSize();
}
}

@@ -120,8 +120,8 @@ public Object encodingConverterPrimitiveConvert(RubyEncodingConverter encodingCo

outBytes.setRealSize(outPtr.p - outBytes.begin());

source.getByteList().setRealSize(inBytes.getRealSize() - (inPtr.p - inBytes.getBegin()));
source.getByteList().setBegin(inPtr.p);
StringNodes.getByteList(source).setRealSize(inBytes.getRealSize() - (inPtr.p - inBytes.getBegin()));
StringNodes.getByteList(source).setBegin(inPtr.p);

if (growOutputBuffer && res == EConvResult.DestinationBufferFull) {
if (Integer.MAX_VALUE / 2 < size) {
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@

import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.core.StringNodes;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.*;

@@ -28,7 +29,7 @@ public EncodingGetObjectEncodingNode(RubyContext context, SourceSection sourceSe

@Specialization
public RubyEncoding encodingGetObjectEncoding(RubyString string) {
return RubyEncoding.getEncoding(string.getByteList().getEncoding());
return RubyEncoding.getEncoding(StringNodes.getByteList(string).getEncoding());
}

@Specialization
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@
import com.oracle.truffle.api.object.*;
import com.oracle.truffle.api.source.SourceSection;
import jnr.constants.platform.Errno;
import org.jruby.truffle.nodes.core.StringNodes;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyBasicObject;
@@ -159,7 +160,7 @@ public IOBufferUnshiftPrimitiveNode(RubyContext context, SourceSection sourceSec
public int unshift(VirtualFrame frame, RubyBasicObject ioBuffer, RubyString string, int startPosition) {
setWriteSynced(ioBuffer, false);

int stringSize = string.getByteList().realSize() - startPosition;
int stringSize = StringNodes.getByteList(string).realSize() - startPosition;
final int usedSpace = getUsed(ioBuffer);
final int availableSpace = IOBUFFER_SIZE - usedSpace;

@@ -170,7 +171,7 @@ public int unshift(VirtualFrame frame, RubyBasicObject ioBuffer, RubyString stri
ByteList storage = getStorage(ioBuffer).getBytes();

// Data is copied here - can we do something COW?
System.arraycopy(string.getByteList().unsafeBytes(), startPosition, storage.getUnsafeBytes(), usedSpace, stringSize);
System.arraycopy(StringNodes.getByteList(string).unsafeBytes(), startPosition, storage.getUnsafeBytes(), usedSpace, stringSize);

setUsed(ioBuffer, usedSpace + stringSize);

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

@Specialization
public int open(RubyString path, int mode, int permission) {
return posix().open(path.getByteList(), mode, permission);
return posix().open(StringNodes.getByteList(path), mode, permission);
}

}
@@ -239,7 +239,7 @@ public int truncate(RubyString path, int length) {

@Specialization
public int truncate(RubyString path, long length) {
final String pathString = RubyEncoding.decodeUTF8(path.getByteList().getUnsafeBytes(), path.getByteList().getBegin(), path.getByteList().getRealSize());
final String pathString = RubyEncoding.decodeUTF8(StringNodes.getByteList(path).getUnsafeBytes(), StringNodes.getByteList(path).getBegin(), StringNodes.getByteList(path).getRealSize());
final int result = posix().truncate(pathString, length);
if (result == -1) {
CompilerDirectives.transferToInterpreter();
@@ -280,12 +280,12 @@ public IOFNMatchPrimitiveNode(RubyContext context, SourceSection sourceSection)
@TruffleBoundary
@Specialization
public boolean fnmatch(RubyString pattern, RubyString path, int flags) {
return Dir.fnmatch(pattern.getByteList().getUnsafeBytes(),
pattern.getByteList().getBegin(),
pattern.getByteList().getBegin() + pattern.getByteList().getRealSize(),
path.getByteList().getUnsafeBytes(),
path.getByteList().getBegin(),
path.getByteList().getBegin() + path.getByteList().getRealSize(),
return Dir.fnmatch(StringNodes.getByteList(pattern).getUnsafeBytes(),
StringNodes.getByteList(pattern).getBegin(),
StringNodes.getByteList(pattern).getBegin() + StringNodes.getByteList(pattern).getRealSize(),
StringNodes.getByteList(path).getUnsafeBytes(),
StringNodes.getByteList(path).getBegin(),
StringNodes.getByteList(path).getBegin() + StringNodes.getByteList(path).getRealSize(),
flags) != Dir.FNM_NOMATCH;
}

@@ -415,13 +415,13 @@ public int write(VirtualFrame frame, RubyBasicObject file, RubyString string) {
final int fd = getDescriptor(file);

if (getContext().getDebugStandardOut() != null && fd == STDOUT) {
getContext().getDebugStandardOut().write(string.getByteList().unsafeBytes(), string.getByteList().begin(), string.getByteList().length());
return string.getByteList().length();
getContext().getDebugStandardOut().write(StringNodes.getByteList(string).unsafeBytes(), StringNodes.getByteList(string).begin(), StringNodes.getByteList(string).length());
return StringNodes.getByteList(string).length();
}

// We have to copy here as write starts at byte[0], and the ByteList may not

final ByteList byteList = string.getByteList();
final ByteList byteList = StringNodes.getByteList(string);

// TODO (eregon, 11 May 2015): review consistency under concurrent modification
final ByteBuffer buffer = ByteBuffer.wrap(byteList.unsafeBytes(), byteList.begin(), byteList.length());
Original file line number Diff line number Diff line change
@@ -217,6 +217,18 @@ public long setAtOffsetLong(RubyBasicObject pointer, int offset, int type, long
return value;
}

@Specialization(guards = "type == TYPE_ULONG")
public long setAtOffsetULong(RubyBasicObject pointer, int offset, int type, long value) {
getPointer(pointer).putLong(offset, value);
return value;
}

@Specialization(guards = "type == TYPE_ULL")
public long setAtOffsetULL(RubyBasicObject pointer, int offset, int type, long value) {
getPointer(pointer).putLongLong(offset, value);
return value;
}

}

@RubiniusPrimitive(name = "pointer_read_pointer")
@@ -255,6 +267,11 @@ public PointerGetAtOffsetPrimitiveNode(RubyContext context, SourceSection source
super(context, sourceSection);
}

@Specialization(guards = "type == TYPE_CHAR")
public int getAtOffsetChar(RubyBasicObject pointer, int offset, int type) {
return getPointer(pointer).getByte(offset);
}

@Specialization(guards = "type == TYPE_UCHAR")
public int getAtOffsetUChar(RubyBasicObject pointer, int offset, int type) {
return getPointer(pointer).getByte(offset);
@@ -280,6 +297,16 @@ public long getAtOffsetLong(RubyBasicObject pointer, int offset, int type) {
return getPointer(pointer).getLong(offset);
}

@Specialization(guards = "type == TYPE_ULONG")
public long getAtOffsetULong(RubyBasicObject pointer, int offset, int type) {
return getPointer(pointer).getLong(offset);
}

@Specialization(guards = "type == TYPE_ULL")
public long getAtOffsetULL(RubyBasicObject pointer, int offset, int type) {
return getPointer(pointer).getLongLong(offset);
}

@Specialization(guards = "type == TYPE_STRING")
public RubyString getAtOffsetString(RubyBasicObject pointer, int offset, int type) {
return createString(getPointer(pointer).getString(offset));
@@ -307,7 +334,7 @@ public PointerWriteStringPrimitiveNode(RubyContext context, SourceSection source

@Specialization
public RubyBasicObject address(RubyBasicObject pointer, RubyString string, int maxLength) {
final ByteList bytes = string.getByteList();
final ByteList bytes = StringNodes.getByteList(string);
final int length = Math.min(bytes.length(), maxLength);
getPointer(pointer).put(0, bytes.unsafeBytes(), bytes.begin(), length);
return pointer;
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ public AccessNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public int access(RubyString path, int mode) {
final String pathString = RubyEncoding.decodeUTF8(path.getByteList().getUnsafeBytes(), path.getByteList().getBegin(), path.getByteList().getRealSize());
final String pathString = RubyEncoding.decodeUTF8(StringNodes.getByteList(path).getUnsafeBytes(), StringNodes.getByteList(path).getBegin(), StringNodes.getByteList(path).getRealSize());
return posix().access(pathString, mode);
}

@@ -197,6 +197,27 @@ public int getGroups(int max, RubyBasicObject pointer) {

}

@CoreMethod(names = "getrlimit", isModuleFunction = true, required = 2)
public abstract static class GetRLimitNode extends CoreMethodArrayArgumentsNode {

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

@Specialization
public int getrlimit(int resource, RubyBasicObject pointer) {
final int result = posix().getrlimit(resource, PointerPrimitiveNodes.getPointer(pointer));

if (result == -1) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().errnoError(posix().errno(), this));
}

return result;
}

}

@CoreMethod(names = "getuid", isModuleFunction = true)
public abstract static class GetUIDNode extends CoreMethodArrayArgumentsNode {

@@ -240,7 +261,7 @@ public ReadlinkNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public int readlink(RubyString path, RubyBasicObject pointer, int bufsize) {
final String pathString = RubyEncoding.decodeUTF8(path.getByteList().getUnsafeBytes(), path.getByteList().getBegin(), path.getByteList().getRealSize());
final String pathString = RubyEncoding.decodeUTF8(StringNodes.getByteList(path).getUnsafeBytes(), StringNodes.getByteList(path).getBegin(), StringNodes.getByteList(path).getRealSize());

final int result = posix().readlink(pathString, PointerPrimitiveNodes.getPointer(pointer), bufsize);
if (result == -1) {
@@ -262,8 +283,8 @@ public LinkNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public int link(RubyString path, RubyString other) {
final String pathString = RubyEncoding.decodeUTF8(path.getByteList().getUnsafeBytes(), path.getByteList().getBegin(), path.getByteList().getRealSize());
final String otherString = RubyEncoding.decodeUTF8(other.getByteList().getUnsafeBytes(), other.getByteList().getBegin(), other.getByteList().getRealSize());
final String pathString = RubyEncoding.decodeUTF8(StringNodes.getByteList(path).getUnsafeBytes(), StringNodes.getByteList(path).getBegin(), StringNodes.getByteList(path).getRealSize());
final String otherString = RubyEncoding.decodeUTF8(StringNodes.getByteList(other).getUnsafeBytes(), StringNodes.getByteList(other).getBegin(), StringNodes.getByteList(other).getRealSize());
return posix().link(pathString, otherString);
}

@@ -278,7 +299,7 @@ public UnlinkNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public int unlink(RubyString path) {
return posix().unlink(RubyEncoding.decodeUTF8(path.getByteList().getUnsafeBytes(), path.getByteList().getBegin(), path.getByteList().getRealSize()));
return posix().unlink(RubyEncoding.decodeUTF8(StringNodes.getByteList(path).getUnsafeBytes(), StringNodes.getByteList(path).getBegin(), StringNodes.getByteList(path).getRealSize()));
}

}
@@ -306,7 +327,7 @@ public UtimesNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public int utimes(RubyString path, RubyBasicObject pointer) {
final String pathString = RubyEncoding.decodeUTF8(path.getByteList().getUnsafeBytes(), path.getByteList().getBegin(), path.getByteList().getRealSize());
final String pathString = RubyEncoding.decodeUTF8(StringNodes.getByteList(path).getUnsafeBytes(), StringNodes.getByteList(path).getBegin(), StringNodes.getByteList(path).getRealSize());

final int result = posix().utimes(pathString, PointerPrimitiveNodes.getPointer(pointer));
if (result == -1) {
@@ -439,6 +460,27 @@ public int setreuid(int uid, int id) {

}

@CoreMethod(names = "setrlimit", isModuleFunction = true, required = 2)
public abstract static class SetRLimitNode extends CoreMethodArrayArgumentsNode {

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

@Specialization
public int setrlimit(int resource, RubyBasicObject pointer) {
final int result = posix().setrlimit(resource, PointerPrimitiveNodes.getPointer(pointer));

if (result == -1) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().errnoError(posix().errno(), this));
}

return result;
}

}

@CoreMethod(names = "setruid", isModuleFunction = true, required = 1, lowerFixnumParameters = 0)
public abstract static class SetRuidNode extends CoreMethodArrayArgumentsNode {

@@ -532,8 +574,8 @@ public RenameNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public int rename(RubyString path, RubyString other) {
final String pathString = RubyEncoding.decodeUTF8(path.getByteList().getUnsafeBytes(), path.getByteList().getBegin(), path.getByteList().getRealSize());
final String otherString = RubyEncoding.decodeUTF8(other.getByteList().getUnsafeBytes(), other.getByteList().getBegin(), other.getByteList().getRealSize());
final String pathString = RubyEncoding.decodeUTF8(StringNodes.getByteList(path).getUnsafeBytes(), StringNodes.getByteList(path).getBegin(), StringNodes.getByteList(path).getRealSize());
final String otherString = RubyEncoding.decodeUTF8(StringNodes.getByteList(other).getUnsafeBytes(), StringNodes.getByteList(other).getBegin(), StringNodes.getByteList(other).getRealSize());
return posix().rename(pathString, otherString);
}

@@ -565,7 +607,7 @@ public RubyString getcwd(RubyString resultPath, int maxSize) {
// We just ignore maxSize - I think this is ok

final String path = getContext().getRuntime().getCurrentDirectory();
resultPath.getByteList().replace(path.getBytes(StandardCharsets.UTF_8));
StringNodes.getByteList(resultPath).replace(path.getBytes(StandardCharsets.UTF_8));
return resultPath;
}

@@ -706,8 +748,8 @@ public int getaddrinfo(RubyBasicObject hostName, RubyString serviceName, RubyBas
@Specialization
public int getaddrinfo(RubyString hostName, RubyString serviceName, RubyBasicObject hintsPointer, RubyBasicObject resultsPointer) {
return nativeSockets().getaddrinfo(
hostName.getByteList(),
serviceName.getByteList(),
StringNodes.getByteList(hostName),
StringNodes.getByteList(serviceName),
PointerPrimitiveNodes.getPointer(hintsPointer),
PointerPrimitiveNodes.getPointer(resultsPointer));
}
Original file line number Diff line number Diff line change
@@ -9,12 +9,12 @@
*/
package org.jruby.truffle.nodes.rubinius;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;

import org.joni.Matcher;
import org.jruby.truffle.nodes.core.StringNodes;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.*;
@@ -36,7 +36,7 @@ public RegexpInitializePrimitiveNode(RubyContext context, SourceSection sourceSe

@Specialization
public RubyRegexp initialize(RubyRegexp regexp, RubyString pattern, int options) {
regexp.initialize(this, pattern.getByteList(), options);
regexp.initialize(this, StringNodes.getByteList(pattern), options);
return regexp;
}

@@ -56,12 +56,12 @@ public Object searchRegion(RubyRegexp regexp, RubyString string, int start, int
throw new RaiseException(getContext().getCoreLibrary().typeError("uninitialized Regexp", this));
}

if (string.scanForCodeRange() == StringSupport.CR_BROKEN) {
if (StringNodes.scanForCodeRange(string) == StringSupport.CR_BROKEN) {
throw new RaiseException(getContext().getCoreLibrary().argumentError(
String.format("invalid byte sequence in %s", string.getByteList().getEncoding()), this));
String.format("invalid byte sequence in %s", StringNodes.getByteList(string).getEncoding()), this));
}

final Matcher matcher = regexp.getRegex().matcher(string.getByteList().bytes());
final Matcher matcher = regexp.getRegex().matcher(StringNodes.getByteList(string).bytes());

return regexp.matchCommon(string, false, false, matcher, start, end);
}
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
import com.oracle.truffle.api.source.SourceSection;
import jnr.posix.FileStat;
import org.jruby.RubyEncoding;
import org.jruby.truffle.nodes.core.StringNodes;
import org.jruby.truffle.nodes.objectstorage.ReadHeadObjectFieldNode;
import org.jruby.truffle.nodes.objectstorage.WriteHeadObjectFieldNode;
import org.jruby.truffle.runtime.RubyContext;
@@ -167,7 +168,7 @@ public StatStatPrimitiveNode(RubyContext context, SourceSection sourceSection) {
@Specialization
public int stat(RubyBasicObject rubyStat, RubyString path) {
final FileStat stat = posix().allocateStat();
final String pathString = RubyEncoding.decodeUTF8(path.getByteList().getUnsafeBytes(), path.getByteList().getBegin(), path.getByteList().getRealSize());
final String pathString = RubyEncoding.decodeUTF8(StringNodes.getByteList(path).getUnsafeBytes(), StringNodes.getByteList(path).getBegin(), StringNodes.getByteList(path).getRealSize());
final int code = posix().stat(pathString, stat);

if (code == 0) {

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -200,7 +200,7 @@ public TimeStrftimePrimitiveNode(RubyContext context, SourceSection sourceSectio
public RubyString timeStrftime(RubyTime time, RubyString format) {
final RubyDateFormatter rdf = getContext().getRuntime().getCurrentContext().getRubyDateFormatter();
// TODO CS 15-Feb-15 ok to just pass nanoseconds as 0?
return createString(rdf.formatToByteList(rdf.compilePattern(format.getByteList(), false), time.getDateTime(), 0, null));
return createString(rdf.formatToByteList(rdf.compilePattern(StringNodes.getByteList(format), false), time.getDateTime(), 0, null));
}

}
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.KernelNodes;
import org.jruby.truffle.nodes.core.KernelNodesFactory;
import org.jruby.truffle.nodes.core.StringNodes;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.nodes.dispatch.DispatchNode;
@@ -99,7 +100,7 @@ public ByteList toString(VirtualFrame frame, RubyString string) {
setTainted(frame);
}

return string.getByteList();
return StringNodes.getByteList(string);
}

@Specialization
@@ -116,7 +117,7 @@ public ByteList toString(VirtualFrame frame, RubyArray array) {
setTainted(frame);
}

return ((RubyString) value).getByteList();
return StringNodes.getByteList(((RubyString) value));
}

CompilerDirectives.transferToInterpreter();
@@ -142,7 +143,7 @@ public ByteList toString(VirtualFrame frame, Object object) {
setTainted(frame);
}

return ((RubyString) value).getByteList();
return StringNodes.getByteList(((RubyString) value));
}

if (inspectOnConversionFailure) {
@@ -152,7 +153,7 @@ public ByteList toString(VirtualFrame frame, Object object) {
getEncapsulatingSourceSection(), new RubyNode[]{null}));
}

return inspectNode.toS(frame, object).getByteList();
return StringNodes.getByteList(inspectNode.toS(frame, object));
}

CompilerDirectives.transferToInterpreter();
Original file line number Diff line number Diff line change
@@ -63,7 +63,6 @@
import java.io.File;
import java.io.PrintStream;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;

@@ -441,7 +440,7 @@ public IRubyObject toJRuby(RubyEncoding encoding) {
}

public org.jruby.RubyString toJRuby(RubyString string) {
final org.jruby.RubyString jrubyString = runtime.newString(string.getByteList().dup());
final org.jruby.RubyString jrubyString = runtime.newString(StringNodes.getByteList(string).dup());

final Object tainted = RubyBasicObject.getInstanceVariable(string, RubyBasicObject.TAINTED_IDENTIFIER);

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2013, 2015 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.runtime.core;

import org.jcodings.Encoding;
import org.jruby.truffle.nodes.core.StringNodes;
import org.jruby.util.ByteList;
import org.jruby.util.CodeRangeable;

public class CodeRangeableWrapper implements CodeRangeable {

private final RubyString string;

public CodeRangeableWrapper(RubyString string) {
this.string = string;
}

@Override
public int getCodeRange() {
return StringNodes.getCodeRange(string);
}

@Override
public int scanForCodeRange() {
return StringNodes.scanForCodeRange(string);
}

@Override
public boolean isCodeRangeValid() {
return StringNodes.isCodeRangeValid(string);
}

@Override
public final void setCodeRange(int newCodeRange) {
StringNodes.setCodeRange(string, newCodeRange);
}

@Override
public final void clearCodeRange() {
StringNodes.clearCodeRange(string);
}

@Override
public final void keepCodeRange() {
StringNodes.keepCodeRange(string);
}

@Override
public final void modify() {
StringNodes.modify(string);
}

@Override
public final void modify(int length) {
StringNodes.modify(string, length);
}

@Override
public final void modifyAndKeepCodeRange() {
StringNodes.modifyAndKeepCodeRange(string);
}

@Override
public Encoding checkEncoding(CodeRangeable other) {
return StringNodes.checkEncoding(string, other);
}

@Override
public ByteList getByteList() {
return StringNodes.getByteList(string);
}

}
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@
package org.jruby.truffle.runtime.core;

import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.interop.ForeignAccessFactory;
@@ -19,6 +18,8 @@
import com.oracle.truffle.api.object.*;

import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.runtime.Helpers;
import org.jruby.truffle.nodes.core.StringNodes;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.objects.Allocator;
import org.jruby.truffle.runtime.ModuleOperations;
@@ -205,7 +206,12 @@ public RubyBasicObject allocate(RubyContext context, RubyClass rubyClass, Node c
@Override
public String toString() {
CompilerAsserts.neverPartOfCompilation("should never use RubyBasicObject#toString to implement Ruby functionality");
return String.format("RubyBasicObject@%x<logicalClass=%s>", System.identityHashCode(this), logicalClass.getName());

if (this instanceof RubyString) {
return Helpers.decodeByteList(getContext().getRuntime(), StringNodes.getByteList(((RubyString) this)));
} else {
return String.format("RubyBasicObject@%x<logicalClass=%s>", System.identityHashCode(this), logicalClass.getName());
}
}

@TruffleBoundary
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@ public Object matchCommon(RubyString source, boolean operator, boolean setNamedC

@TruffleBoundary
public Object matchCommon(RubyString source, boolean operator, boolean setNamedCaptures, int startPos) {
final byte[] stringBytes = source.getByteList().bytes();
final byte[] stringBytes = StringNodes.getByteList(source).bytes();
final Matcher matcher = regex.matcher(stringBytes);
int range = stringBytes.length;

@@ -111,7 +111,7 @@ public Object matchCommon(RubyString source, boolean operator, boolean setNamedC

@TruffleBoundary
public Object matchCommon(RubyString source, boolean operator, boolean setNamedCaptures, Matcher matcher, int startPos, int range) {
final ByteList bytes = source.getByteList();
final ByteList bytes = StringNodes.getByteList(source);
final RubyContext context = getContext();

final Frame frame = Truffle.getRuntime().getCallerFrame().getFrame(FrameInstance.FrameAccess.READ_WRITE, false);
@@ -212,10 +212,10 @@ public Object matchCommon(RubyString source, boolean operator, boolean setNamedC
}

private RubyString makeString(RubyString source, int start, int length) {
final ByteList bytes = new ByteList(source.getByteList(), start, length);
final ByteList bytes = new ByteList(StringNodes.getByteList(source), start, length);
final RubyString ret = StringNodes.createString(source.getLogicalClass(), bytes);

ret.setCodeRange(source.getCodeRange());
StringNodes.setCodeRange(ret, StringNodes.getCodeRange(source));

return ret;
}
@@ -245,14 +245,14 @@ public void setThread(String name, Object value) {
public RubyString gsub(RubyString string, String replacement) {
final RubyContext context = getContext();

final byte[] stringBytes = string.getByteList().bytes();
final byte[] stringBytes = StringNodes.getByteList(string).bytes();

final Encoding encoding = string.getByteList().getEncoding();
final Encoding encoding = StringNodes.getByteList(string).getEncoding();
final Matcher matcher = regex.matcher(stringBytes);

int p = string.getByteList().getBegin();
int p = StringNodes.getByteList(string).getBegin();
int end = 0;
int range = p + string.getByteList().getRealSize();
int range = p + StringNodes.getByteList(string).getRealSize();
int lastMatchEnd = 0;

// We only ever care about the entire matched string, not each of the matched parts, so we can hard-code the index.
@@ -278,7 +278,7 @@ public RubyString gsub(RubyString string, String replacement) {
builder.append(StandardCharsets.UTF_8.decode(ByteBuffer.wrap(replacement.getBytes(StandardCharsets.UTF_8))));

lastMatchEnd = regionEnd;
end = StringSupport.positionEndForScan(string.getByteList(), matcher, encoding, p, range);
end = StringSupport.positionEndForScan(StringNodes.getByteList(string), matcher, encoding, p, range);
}

return StringNodes.createString(context.getCoreLibrary().getStringClass(), builder.toString());
@@ -308,12 +308,12 @@ public RubyString sub(String string, String replacement) {
public RubyString[] split(final RubyString string, final boolean useLimit, final int limit) {
final RubyContext context = getContext();

final ByteList bytes = string.getByteList();
final ByteList bytes = StringNodes.getByteList(string);
final byte[] byteArray = bytes.bytes();
final int begin = bytes.getBegin();
final int len = bytes.getRealSize();
final int range = begin + len;
final Encoding encoding = string.getByteList().getEncoding();
final Encoding encoding = StringNodes.getByteList(string).getEncoding();
final Matcher matcher = regex.matcher(byteArray);

final ArrayList<RubyString> strings = new ArrayList<>();
@@ -373,13 +373,13 @@ public RubyString[] split(final RubyString string, final boolean useLimit, final
public Object scan(RubyString string) {
final RubyContext context = getContext();

final byte[] stringBytes = string.getByteList().bytes();
final Encoding encoding = string.getByteList().getEncoding();
final byte[] stringBytes = StringNodes.getByteList(string).bytes();
final Encoding encoding = StringNodes.getByteList(string).getEncoding();
final Matcher matcher = regex.matcher(stringBytes);

int p = string.getByteList().getBegin();
int p = StringNodes.getByteList(string).getBegin();
int end = 0;
int range = p + string.getByteList().getRealSize();
int range = p + StringNodes.getByteList(string).getRealSize();

Object lastGoodMatchData = getContext().getCoreLibrary().getNilObject();

@@ -401,7 +401,7 @@ public Object scan(RubyString string) {
strings.add((RubyString) values[0]);

lastGoodMatchData = matchData;
end = StringSupport.positionEndForScan(string.getByteList(), matcher, encoding, p, range);
end = StringSupport.positionEndForScan(StringNodes.getByteList(string), matcher, encoding, p, range);
}

setThread("$~", lastGoodMatchData);
@@ -420,7 +420,7 @@ public Object scan(RubyString string) {
allMatches.add(ArrayNodes.createArray(context.getCoreLibrary().getArrayClass(), captures, captures.length));

lastGoodMatchData = matchData;
end = StringSupport.positionEndForScan(string.getByteList(), matcher, encoding, p, range);
end = StringSupport.positionEndForScan(StringNodes.getByteList(string), matcher, encoding, p, range);
}

setThread("$~", lastGoodMatchData);
Original file line number Diff line number Diff line change
@@ -9,113 +9,19 @@
*/
package org.jruby.truffle.runtime.core;

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.object.DynamicObject;
import org.jcodings.Encoding;
import org.jruby.runtime.Helpers;
import org.jruby.util.ByteList;
import org.jruby.util.CodeRangeable;
import org.jruby.util.StringSupport;

public class RubyString extends RubyBasicObject implements CodeRangeable {
public class RubyString extends RubyBasicObject {

public ByteList bytes;
public int codeRange = StringSupport.CR_UNKNOWN;
public CodeRangeableWrapper codeRangeableWrapper;

public RubyString(RubyClass stringClass, ByteList bytes, DynamicObject dynamicObject) {
super(stringClass, dynamicObject);
this.bytes = bytes;
}

@Override
@TruffleBoundary
public String toString() {
return Helpers.decodeByteList(getContext().getRuntime(), bytes);
}

@Override
public int getCodeRange() {
return codeRange;
}

@Override
@TruffleBoundary
public int scanForCodeRange() {
int cr = getCodeRange();

if (cr == StringSupport.CR_UNKNOWN) {
cr = slowCodeRangeScan();
setCodeRange(cr);
}

return cr;
}

@Override
public boolean isCodeRangeValid() {
return codeRange == StringSupport.CR_VALID;
}

@Override
public final void setCodeRange(int codeRange) {
this.codeRange = codeRange;
}

@Override
public final void clearCodeRange() {
codeRange = StringSupport.CR_UNKNOWN;
}

@Override
public final void keepCodeRange() {
if (getCodeRange() == StringSupport.CR_BROKEN) {
clearCodeRange();
}
}

@Override
public final void modify() {
// TODO (nirvdrum 16-Feb-15): This should check whether the underlying ByteList is being shared and copy if necessary.
bytes.invalidate();
}

@Override
public final void modify(int length) {
// TODO (nirvdrum Jan. 13, 2015): This should check whether the underlying ByteList is being shared and copy if necessary.
bytes.ensure(length);
bytes.invalidate();
}

@Override
public final void modifyAndKeepCodeRange() {
modify();
keepCodeRange();
}

@Override
@TruffleBoundary
public Encoding checkEncoding(CodeRangeable other) {
final Encoding encoding = StringSupport.areCompatible(this, other);

// TODO (nirvdrum 23-Mar-15) We need to raise a proper Truffle+JRuby exception here, rather than a non-Truffle JRuby exception.
if (encoding == null) {
throw getContext().getRuntime().newEncodingCompatibilityError(
String.format("incompatible character encodings: %s and %s",
getByteList().getEncoding().toString(),
other.getByteList().getEncoding().toString()));
}

return encoding;
}

@Override
public ByteList getByteList() {
return bytes;
}

@TruffleBoundary
private int slowCodeRangeScan() {
return StringSupport.codeRangeScan(bytes.getEncoding(), bytes);
}

}

Large diffs are not rendered by default.

57 changes: 56 additions & 1 deletion truffle/src/main/ruby/core/rubinius/common/process.rb
Original file line number Diff line number Diff line change
@@ -64,6 +64,39 @@ module Constants

FFI = Rubinius::FFI

class Rlimit < FFI::Struct
config "rbx.platform.rlimit", :rlim_cur, :rlim_max
end

def self.setrlimit(resource, cur_limit, max_limit=undefined)
resource = coerce_rlimit_resource(resource)
cur_limit = Rubinius::Type.coerce_to cur_limit, Integer, :to_int

unless undefined.equal? max_limit
max_limit = Rubinius::Type.coerce_to max_limit, Integer, :to_int
end

rlimit = Rlimit.new
rlimit[:rlim_cur] = cur_limit
rlimit[:rlim_max] = undefined.equal?(max_limit) ? cur_limit : max_limit

ret = FFI::Platform::POSIX.setrlimit(resource, rlimit.pointer)
Errno.handle if ret == -1
nil
end


def self.getrlimit(resource)
resource = coerce_rlimit_resource(resource)

lim_max = []
rlimit = Rlimit.new
ret = FFI::Platform::POSIX.getrlimit(resource, rlimit.pointer)
Errno.handle if ret == -1

[rlimit[:rlim_cur], rlimit[:rlim_max]]
end

def self.setsid
pgid = FFI::Platform::POSIX.setsid
Errno.handle if pgid == -1
@@ -293,7 +326,29 @@ def self.wait2(input_pid=-1, flags=nil)

[pid, status]
end


def self.coerce_rlimit_resource(resource)
case resource
when Integer
return resource
when Symbol, String
# do nothing
else
unless r = Rubinius::Type.check_convert_type(resource, String, :to_str)
return Rubinius::Type.coerce_to resource, Integer, :to_int
end

resource = r
end

constant = "RLIMIT_#{resource}"
unless const_defined? constant
raise ArgumentError, "invalid resource name: #{constant}"
end
const_get constant
end
private_class_method :coerce_rlimit_resource

#--
# TODO: Most of the fields aren't implemented yet.
# TODO: Also, these objects should only need to be constructed by

0 comments on commit 48d44b8

Please sign in to comment.