-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Truffle] Move non-nodes from StringNodes to StringOperations.
- 9.4.12.0
- 9.4.11.0
- 9.4.10.0
- 9.4.9.0
- 9.4.8.0
- 9.4.7.0
- 9.4.6.0
- 9.4.5.0
- 9.4.4.0
- 9.4.3.0
- 9.4.2.0
- 9.4.1.0
- 9.4.0.0
- 9.3.15.0
- 9.3.14.0
- 9.3.13.0
- 9.3.12.0
- 9.3.11.0
- 9.3.10.0
- 9.3.9.0
- 9.3.8.0
- 9.3.7.0
- 9.3.6.0
- 9.3.5.0
- 9.3.4.0
- 9.3.3.0
- 9.3.2.0
- 9.3.1.0
- 9.3.0.0
- 9.2.21.0
- 9.2.20.1
- 9.2.20.0
- 9.2.19.0
- 9.2.18.0
- 9.2.17.0
- 9.2.16.0
- 9.2.15.0
- 9.2.14.0
- 9.2.13.0
- 9.2.12.0
- 9.2.11.1
- 9.2.11.0
- 9.2.10.0
- 9.2.9.0
- 9.2.8.0
- 9.2.7.0
- 9.2.6.0
- 9.2.5.0
- 9.2.4.1
- 9.2.4.0
- 9.2.3.0
- 9.2.2.0
- 9.2.1.0
- 9.2.0.0
- 9.1.17.0
- 9.1.16.0
- 9.1.15.0
- 9.1.14.0
- 9.1.13.0
- 9.1.12.0
- 9.1.11.0
- 9.1.10.0
- 9.1.9.0
- 9.1.8.0
- 9.1.7.0
- 9.1.6.0
- 9.1.5.0
- 9.1.4.0
- 9.1.3.0
- 9.1.2.0
- 9.1.1.0
- 9.1.0.0
- 9.0.5.0
- 9.0.4.0
- 9.0.3.0
- 9.0.1.0
1 parent
4fd99e3
commit 89b2e50
Showing
15 changed files
with
285 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
241 changes: 53 additions & 188 deletions
241
truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletions
174
truffle/src/main/java/org/jruby/truffle/runtime/core/StringOperations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
/* | ||
* 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 | ||
* | ||
* Contains code modified from JRuby's RubyString.java | ||
* | ||
* Copyright (C) 2001 Alan Moore <alan_moore@gmx.net> | ||
* Copyright (C) 2001-2002 Benoit Cerrina <b.cerrina@wanadoo.fr> | ||
* Copyright (C) 2001-2004 Jan Arne Petersen <jpetersen@uni-bonn.de> | ||
* Copyright (C) 2002-2004 Anders Bengtsson <ndrsbngtssn@yahoo.se> | ||
* Copyright (C) 2002-2006 Thomas E Enebo <enebo@acm.org> | ||
* Copyright (C) 2004 Stefan Matthias Aust <sma@3plus4.de> | ||
* Copyright (C) 2004 David Corbin <dcorbin@users.sourceforge.net> | ||
* Copyright (C) 2005 Tim Azzopardi <tim@tigerfive.com> | ||
* Copyright (C) 2006 Miguel Covarrubias <mlcovarrubias@gmail.com> | ||
* Copyright (C) 2006 Ola Bini <ola@ologix.com> | ||
* Copyright (C) 2007 Nick Sieger <nicksieger@gmail.com> | ||
* | ||
*/ | ||
package org.jruby.truffle.runtime.core; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.nodes.Node; | ||
import com.oracle.truffle.api.object.DynamicObject; | ||
import org.jcodings.Encoding; | ||
import org.jruby.runtime.Helpers; | ||
import org.jruby.truffle.nodes.RubyGuards; | ||
import org.jruby.truffle.runtime.control.RaiseException; | ||
import org.jruby.truffle.runtime.layouts.Layouts; | ||
import org.jruby.util.ByteList; | ||
import org.jruby.util.CodeRangeable; | ||
import org.jruby.util.StringSupport; | ||
import org.jruby.util.io.EncodingUtils; | ||
|
||
public abstract class StringOperations { | ||
|
||
// Since ByteList.toString does not decode properly | ||
@CompilerDirectives.TruffleBoundary | ||
public static String getString(DynamicObject string) { | ||
return Helpers.decodeByteList(Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(string)).getContext().getRuntime(), Layouts.STRING.getByteList(string)); | ||
} | ||
|
||
public static StringCodeRangeableWrapper getCodeRangeable(DynamicObject string) { | ||
StringCodeRangeableWrapper wrapper = Layouts.STRING.getCodeRangeableWrapper(string); | ||
|
||
if (wrapper == null) { | ||
wrapper = new StringCodeRangeableWrapper(string); | ||
Layouts.STRING.setCodeRangeableWrapper(string, wrapper); | ||
} | ||
|
||
return wrapper; | ||
} | ||
|
||
@CompilerDirectives.TruffleBoundary | ||
public static int scanForCodeRange(DynamicObject string) { | ||
int cr = Layouts.STRING.getCodeRange(string); | ||
|
||
if (cr == StringSupport.CR_UNKNOWN) { | ||
cr = slowCodeRangeScan(string); | ||
Layouts.STRING.setCodeRange(string, cr); | ||
} | ||
|
||
return cr; | ||
} | ||
|
||
public static boolean isCodeRangeValid(DynamicObject string) { | ||
return Layouts.STRING.getCodeRange(string) == StringSupport.CR_VALID; | ||
} | ||
|
||
public static void clearCodeRange(DynamicObject string) { | ||
Layouts.STRING.setCodeRange(string, StringSupport.CR_UNKNOWN); | ||
} | ||
|
||
public static void keepCodeRange(DynamicObject string) { | ||
if (Layouts.STRING.getCodeRange(string) == StringSupport.CR_BROKEN) { | ||
clearCodeRange(string); | ||
} | ||
} | ||
|
||
public static void modify(DynamicObject string) { | ||
// TODO (nirvdrum 16-Feb-15): This should check whether the underlying ByteList is being shared and copy if necessary. | ||
Layouts.STRING.getByteList(string).invalidate(); | ||
} | ||
|
||
public static void modify(DynamicObject string, int length) { | ||
// TODO (nirvdrum Jan. 13, 2015): This should check whether the underlying ByteList is being shared and copy if necessary. | ||
Layouts.STRING.getByteList(string).ensure(length); | ||
Layouts.STRING.getByteList(string).invalidate(); | ||
} | ||
|
||
public static void modifyAndKeepCodeRange(DynamicObject string) { | ||
modify(string); | ||
keepCodeRange(string); | ||
} | ||
|
||
@CompilerDirectives.TruffleBoundary | ||
public static Encoding checkEncoding(DynamicObject string, CodeRangeable other) { | ||
final Encoding encoding = StringSupport.areCompatible(getCodeRangeable(string), 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 Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(string)).getContext().getRuntime().newEncodingCompatibilityError( | ||
String.format("incompatible character encodings: %s and %s", | ||
Layouts.STRING.getByteList(string).getEncoding().toString(), | ||
other.getByteList().getEncoding().toString())); | ||
} | ||
|
||
return encoding; | ||
} | ||
|
||
@CompilerDirectives.TruffleBoundary | ||
private static int slowCodeRangeScan(DynamicObject string) { | ||
final ByteList byteList = Layouts.STRING.getByteList(string); | ||
return StringSupport.codeRangeScan(byteList.getEncoding(), byteList); | ||
} | ||
|
||
public static void forceEncoding(DynamicObject string, Encoding encoding) { | ||
modify(string); | ||
clearCodeRange(string); | ||
StringSupport.associateEncoding(getCodeRangeable(string), encoding); | ||
clearCodeRange(string); | ||
} | ||
|
||
public static int length(DynamicObject string) { | ||
if (CompilerDirectives.injectBranchProbability( | ||
CompilerDirectives.FASTPATH_PROBABILITY, | ||
StringSupport.isSingleByteOptimizable(getCodeRangeable(string), Layouts.STRING.getByteList(string).getEncoding()))) { | ||
|
||
return Layouts.STRING.getByteList(string).getRealSize(); | ||
|
||
} else { | ||
return StringSupport.strLengthFromRubyString(getCodeRangeable(string)); | ||
} | ||
} | ||
|
||
public static int normalizeIndex(int length, int index) { | ||
return ArrayOperations.normalizeIndex(length, index); | ||
} | ||
|
||
public static int normalizeIndex(DynamicObject rubyString, int index) { | ||
return normalizeIndex(length(rubyString), index); | ||
} | ||
|
||
public static int clampExclusiveIndex(DynamicObject string, int index) { | ||
assert RubyGuards.isRubyString(string); | ||
return ArrayOperations.clampExclusiveIndex(Layouts.STRING.getByteList(string).length(), index); | ||
} | ||
|
||
@CompilerDirectives.TruffleBoundary | ||
public static Encoding checkEncoding(DynamicObject string, CodeRangeable other, Node node) { | ||
final Encoding encoding = StringSupport.areCompatible(getCodeRangeable(string), other); | ||
|
||
if (encoding == null) { | ||
throw new RaiseException( | ||
Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(string)).getContext().getCoreLibrary().encodingCompatibilityErrorIncompatible( | ||
Layouts.STRING.getByteList(string).getEncoding().toString(), | ||
other.getByteList().getEncoding().toString(), | ||
node) | ||
); | ||
} | ||
|
||
return encoding; | ||
} | ||
|
||
public static boolean singleByteOptimizable(DynamicObject string) { | ||
return StringSupport.isSingleByteOptimizable(getCodeRangeable(string), EncodingUtils.STR_ENC_GET(getCodeRangeable(string))); | ||
} | ||
|
||
} |