Skip to content

Commit

Permalink
Showing 3 changed files with 45 additions and 4 deletions.
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/util/cli/Options.java
Original file line number Diff line number Diff line change
@@ -231,6 +231,7 @@ public class Options {
public static final Option<Integer> TRUFFLE_ARRAY_UNINITIALIZED_SIZE = integer(TRUFFLE, "truffle.array.uninitialized_size", 32, "How large an Array to allocate when we have no other information to go on.");
public static final Option<Integer> TRUFFLE_ARRAY_SMALL = integer(TRUFFLE, "truffle.array.small", 3, "Maximum size of an Array to consider small for optimisations.");
public static final Option<Integer> TRUFFLE_HASH_PACKED_ARRAY_MAX = integer(TRUFFLE, "truffle.hash.packed_array.max", 3, "Maximum size of a Hash to consider using the packed array storage strategy for.");
public static final Option<Boolean> TRUFFLE_ROPE_LAZY_SUBSTRINGS = bool(TRUFFLE, "truffle.rope.lazy_substrings", true, "Indicates whether a substring operation on a rope should be performed lazily.");

public static final Option<Integer> TRUFFLE_DEFAULT_CACHE = integer(TRUFFLE, "truffle.default_cache", 8, "Default size for caches.");

45 changes: 41 additions & 4 deletions truffle/src/main/java/org/jruby/truffle/core/rope/RopeNodes.java
Original file line number Diff line number Diff line change
@@ -153,13 +153,21 @@ public Rope substringConcatRope(ConcatRope base, int offset, int byteLength,

private Rope makeSubstring(Rope base, int offset, int byteLength, ConditionProfile is7BitProfile, ConditionProfile isBinaryStringProfile) {
if (is7BitProfile.profile(base.getCodeRange() == CR_7BIT)) {
return new SubstringRope(base, offset, byteLength, byteLength, CR_7BIT);
if (getContext().getOptions().ROPE_LAZY_SUBSTRINGS) {
return new SubstringRope(base, offset, byteLength, byteLength, CR_7BIT);
} else {
return new AsciiOnlyLeafRope(base.extractRange(offset, byteLength), base.getEncoding());
}
}

// We short-circuit here to avoid the costly process of recalculating information we already know, such as
// whether the string has a valid code range.
if (isBinaryStringProfile.profile(base.getEncoding() == ASCIIEncoding.INSTANCE)) {
return new SubstringRope(base, offset, byteLength, byteLength, CR_VALID);
if (getContext().getOptions().ROPE_LAZY_SUBSTRINGS) {
return new SubstringRope(base, offset, byteLength, byteLength, CR_VALID);
} else {
return new ValidLeafRope(base.extractRange(offset, byteLength), base.getEncoding(), byteLength);
}
}

return makeSubstringNon7Bit(base, offset, byteLength);
@@ -177,7 +185,29 @@ private Rope makeSubstringNon7Bit(Rope base, int offset, int byteLength) {
}
*/

return new SubstringRope(base, offset, byteLength, characterLength, codeRange);
if (getContext().getOptions().ROPE_LAZY_SUBSTRINGS) {
return new SubstringRope(base, offset, byteLength, characterLength, codeRange);
} else {
final byte[] bytes = base.extractRange(offset, byteLength);

switch (codeRange) {
case CR_VALID: {
return new ValidLeafRope(bytes, base.getEncoding(), characterLength);
}

case CR_BROKEN: {
return new InvalidLeafRope(bytes, base.getEncoding());
}

case CR_7BIT: {
return new AsciiOnlyLeafRope(bytes, base.getEncoding());
}

default: {
throw new UnsupportedOperationException("Don't know how to make leaf rope for code range: " + codeRange);
}
}
}
}

protected static boolean sameAsBase(Rope base, int offset, int byteLength) {
@@ -391,7 +421,14 @@ public LeafRope makeValidLeafRope(byte[] bytes, Encoding encoding, CodeRange cod
characterLength += q - p;
p = q;
}
p += StringSupport.encFastMBCLen(bytes, p, e, encoding);
int delta = StringSupport.encFastMBCLen(bytes, p, e, encoding);

if (delta < 0) {
CompilerDirectives.transferToInterpreter();
throw new UnsupportedOperationException("Code rang is reported as valid, but is invalid for the given encoding: " + encoding.toString());
}

p += delta;
characterLength++;
}

3 changes: 3 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/language/Options.java
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@
import static org.jruby.util.cli.Options.TRUFFLE_PACK_RECOVER_LOOP_MIN;
import static org.jruby.util.cli.Options.TRUFFLE_PACK_UNROLL_LIMIT;
import static org.jruby.util.cli.Options.TRUFFLE_PLATFORM_USE_JAVA;
import static org.jruby.util.cli.Options.TRUFFLE_ROPE_LAZY_SUBSTRINGS;
import static org.jruby.util.cli.Options.TRUFFLE_SYMBOL_TO_PROC_CACHE;
import static org.jruby.util.cli.Options.TRUFFLE_THREAD_CACHE;
import static org.jruby.util.cli.Options.TRUFFLE_UNPACK_CACHE;
@@ -72,6 +73,8 @@ public class Options {

public final int HASH_PACKED_ARRAY_MAX = TRUFFLE_HASH_PACKED_ARRAY_MAX.load();

public final boolean ROPE_LAZY_SUBSTRINGS = TRUFFLE_ROPE_LAZY_SUBSTRINGS.load();

// Caches

public final int METHOD_LOOKUP_CACHE = TRUFFLE_METHOD_LOOKUP_CACHE.load();

0 comments on commit 3d3ab2b

Please sign in to comment.