Skip to content

Commit

Permalink
Showing 5 changed files with 78 additions and 3 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
@@ -252,6 +252,7 @@ public class Options {
public static final Option<Integer> TRUFFLE_CLASS_CACHE = integer(TRUFFLE, "truffle.class.cache", TRUFFLE_DEFAULT_CACHE.load(), ".class and .metaclass cache size");
public static final Option<Integer> TRUFFLE_ENCODING_COMPATIBLE_QUERY_CACHE = integer(TRUFFLE, "truffle.encoding_compatible_query.cache", TRUFFLE_DEFAULT_CACHE.load(), "Encoding.compatible? cache size");
public static final Option<Integer> TRUFFLE_THREAD_CACHE = integer(TRUFFLE, "truffle.thread.cache", TRUFFLE_DEFAULT_CACHE.load(), "Cache size of operations that depend on a particular thread");
public static final Option<Integer> TRUFFLE_ROPE_CLASS_CACHE = integer(TRUFFLE, "truffle.rope_class.cache", 6, "Cache size for rope operations that depend on a concrete rope implementation to avoid virtual calls");

This comment has been minimized.

Copy link
@chrisseaton

chrisseaton Apr 3, 2016

Contributor

Is there a particular reason why this cache is 6 rather than TRUFFLE_DEFAULT_CACHE? Do you have just 6 concrete implementations? If so can you comment?


public static final Option<Boolean> TRUFFLE_CLONE_DEFAULT = bool(TRUFFLE, "truffle.clone.default", true, "Default option for cloning.");
public static final Option<Boolean> TRUFFLE_INLINE_DEFAULT = bool(TRUFFLE, "truffle.inline.default", true, "Default option for inlining.");
2 changes: 2 additions & 0 deletions test/truffle/compiler/pe/core/string_pe.rb
Original file line number Diff line number Diff line change
@@ -28,6 +28,8 @@

example "'aba'[0] == 'aca'[-1]", true

example "x = 'abc'; x == x.b", true

example "'abc'.ascii_only?", true
example "'こにちわ'.ascii_only?", false

69 changes: 67 additions & 2 deletions truffle/src/main/java/org/jruby/truffle/core/rope/RopeNodes.java
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.CreateCast;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
import com.oracle.truffle.api.dsl.Specialization;
@@ -29,10 +28,11 @@
import org.jcodings.specific.USASCIIEncoding;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.numeric.FixnumLowerNodeGen;
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.RubyNode;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;
import sun.misc.Unsafe;

import static org.jruby.truffle.core.rope.CodeRange.CR_7BIT;
import static org.jruby.truffle.core.rope.CodeRange.CR_BROKEN;
@@ -298,6 +298,10 @@ protected static boolean isMutableRope(Rope rope) {
})
public abstract static class MakeLeafRopeNode extends RubyNode {

public static MakeLeafRopeNode create(RubyContext context, SourceSection sourceSection) {
return RopeNodesFactory.MakeLeafRopeNodeGen.create(context, sourceSection, null, null, null, null);
}

public MakeLeafRopeNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}
@@ -563,4 +567,65 @@ private void printPreamble(int level) {
}

}

@NodeChildren({
@NodeChild(type = RubyNode.class, value = "rope"),
@NodeChild(type = RubyNode.class, value = "encoding"),
@NodeChild(type = RubyNode.class, value = "codeRange")
})
public abstract static class WithEncodingNode extends RubyNode {

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

public abstract Rope executeWithEncoding(Rope rope, Encoding encoding, CodeRange codeRange);

@Specialization(guards = "rope.getEncoding() == encoding")
public Rope withEncodingSameEncoding(Rope rope, Encoding encoding, CodeRange codeRange) {
return rope;
}

@Specialization(guards = {
"rope.getEncoding() != encoding",
"rope.getCodeRange() == codeRange"
})
public Rope withEncodingSameCodeRange(Rope rope, Encoding encoding, CodeRange codeRange) {
return rope.withEncoding(encoding, codeRange);
}

@Specialization(guards = {
"rope.getEncoding() != encoding",
"rope.getCodeRange() != codeRange",
"isAsciiCompatbileChange(rope, encoding)",

This comment has been minimized.

Copy link
@eregon

eregon Apr 4, 2016

Member

typo

"rope.getClass() == cachedRopeClass"
}, limit = "getCacheLimit()")
public Rope withEncodingCr7Bit(Rope rope, Encoding encoding, CodeRange codeRange,
@Cached("rope.getClass()") Class<? extends Rope> cachedRopeClass) {
return cachedRopeClass.cast(rope).withEncoding(encoding, CodeRange.CR_7BIT);
}

@Specialization(guards = {
"rope.getEncoding() != encoding",
"rope.getCodeRange() != codeRange",
"!isAsciiCompatbileChange(rope, encoding)"
})
public Rope withEncoding(Rope rope, Encoding encoding, CodeRange codeRange,
@Cached("create(getContext(), getSourceSection())") MakeLeafRopeNode makeLeafRopeNode) {
return makeLeafRopeNode.executeMake(rope.getBytes(), encoding, codeRange, NotProvided.INSTANCE);
}

protected static boolean isAsciiCompatbileChange(Rope rope, Encoding encoding) {
return rope.getCodeRange() == CR_7BIT && encoding.isAsciiCompatible();
}

protected static boolean is7Bit(Rope rope) {
return rope.getCodeRange() == CR_7BIT;
}

protected int getCacheLimit() {
return getContext().getOptions().ROPE_CLASS_CACHE;
}

}
}
Original file line number Diff line number Diff line change
@@ -667,13 +667,18 @@ public boolean asciiOnly(DynamicObject string) {
@CoreMethod(names = "b", taintFromSelf = true)
public abstract static class BNode extends CoreMethodArrayArgumentsNode {

@Child private RopeNodes.WithEncodingNode withEncodingNode;

public BNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
withEncodingNode = RopeNodesFactory.WithEncodingNodeGen.create(context, sourceSection, null, null, null);
}

@Specialization
public DynamicObject b(DynamicObject string) {
return createString(RopeOperations.withEncoding(rope(string), ASCIIEncoding.INSTANCE));
final Rope newRope = withEncodingNode.executeWithEncoding(rope(string), ASCIIEncoding.INSTANCE, CodeRange.CR_UNKNOWN);

return createString(newRope);
}

}
2 changes: 2 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_CLASS_CACHE;
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;
@@ -94,6 +95,7 @@ public class Options {
public final int CLASS_CACHE = TRUFFLE_CLASS_CACHE.load();
public final int ENCODING_COMPATIBILE_QUERY_CACHE = TRUFFLE_ENCODING_COMPATIBLE_QUERY_CACHE.load();
public final int THREAD_CACHE = TRUFFLE_THREAD_CACHE.load();
public final int ROPE_CLASS_CACHE = TRUFFLE_ROPE_CLASS_CACHE.load();

// Cloning and inlining

0 comments on commit 5653941

Please sign in to comment.