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: 8a79e244d8f3
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 65b84d2a2e25
Choose a head ref
  • 3 commits
  • 19 files changed
  • 1 contributor

Commits on Dec 11, 2016

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b56a070 View commit details
  2. Copy the full SHA
    8a5d186 View commit details
  3. Copy the full SHA
    65b84d2 View commit details
Showing with 104 additions and 116 deletions.
  1. +39 −71 truffle/src/main/java/org/jruby/truffle/algorithms/{Random.java → Randomizer.java}
  2. +28 −9 truffle/src/main/java/org/jruby/truffle/algorithms/SipHash.java
  3. +1 −1 truffle/src/main/java/org/jruby/truffle/{datastructures → collections}/BoundaryIterable.java
  4. +1 −1 truffle/src/main/java/org/jruby/truffle/{datastructures → collections}/BoundaryIterator.java
  5. +1 −1 truffle/src/main/java/org/jruby/truffle/{datastructures → collections}/IntHashMap.java
  6. +1 −1 truffle/src/main/java/org/jruby/truffle/{datastructures → collections}/Memo.java
  7. +1 −1 truffle/src/main/java/org/jruby/truffle/{datastructures → collections}/WeakValuedMap.java
  8. +1 −1 truffle/src/main/java/org/jruby/truffle/core/binding/TruffleBindingNodes.java
  9. +1 −1 truffle/src/main/java/org/jruby/truffle/core/hash/HashOperations.java
  10. +1 −1 truffle/src/main/java/org/jruby/truffle/core/regexp/ClassicRegexp.java
  11. +1 −1 truffle/src/main/java/org/jruby/truffle/core/rope/RopeOperations.java
  12. +4 −4 truffle/src/main/java/org/jruby/truffle/core/rubinius/RandomizerLayout.java
  13. +18 −17 truffle/src/main/java/org/jruby/truffle/core/rubinius/RandomizerPrimitiveNodes.java
  14. +1 −1 truffle/src/main/java/org/jruby/truffle/core/string/StringSupport.java
  15. +1 −1 truffle/src/main/java/org/jruby/truffle/core/thread/ThreadNodes.java
  16. +1 −1 truffle/src/main/java/org/jruby/truffle/language/CallStackManager.java
  17. +1 −1 truffle/src/main/java/org/jruby/truffle/language/TruffleBootNodes.java
  18. +1 −1 truffle/src/main/java/org/jruby/truffle/language/objects/shared/ShareInternalFieldsNode.java
  19. +1 −1 truffle/src/main/java/org/jruby/truffle/stdlib/psych/PsychParserNodes.java
Original file line number Diff line number Diff line change
@@ -25,64 +25,31 @@
***** END LICENSE BLOCK *****/
package org.jruby.truffle.algorithms;

import java.util.Arrays;
public class Randomizer {

public class Random {
public static int N = 624;
private static int M = 397;
private static int MATRIX_A = 0x9908b0df; /* constant vector a */
private static int UMASK = 0x80000000; /* most significant w-r bits */
private static int LMASK = 0x7fffffff; /* least significant r bits */

private static int MIXBITS(int u, int v) {
return (u & UMASK) | (v & LMASK);
}

private static int TWIST(int u, int v) {
return (MIXBITS(u, v) >>> 1) ^ (((v & 1) != 0) ? MATRIX_A : 0);
}
private static final int N = 624;
private static final int M = 397;
private static final int MATRIX_A = 0x9908b0df; /* constant vector a */
private static final int UMASK = 0x80000000; /* most significant w-r bits */
private static final int LMASK = 0x7fffffff; /* least significant r bits */

private final int[] state = new int[N];
private int left = 1;

public Random() {
}

public Random(int s) {
initGenrand(s);
}

public Random(int[] initKey) {
initByArray(initKey);
}
private int left = 1;

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (!(obj instanceof Random)) {
return false;
}
Random rhs = (Random) obj;
return (left == rhs.left) && Arrays.equals(state, rhs.state);
public Randomizer() {
}

@Override
public int hashCode() {
// Using 17 as the initializer, 37 as the multiplier.
return (629 + left) * 37 + Arrays.hashCode(state);
}

private void initGenrand(int s) {
public Randomizer(int s) {
state[0] = s;
for (int j = 1; j < N; j++) {
state[j] = (1812433253 * (state[j - 1] ^ (state[j - 1] >>> 30)) + j);
}
left = 1;
}

private void initByArray(int[] initKey) {
initGenrand(19650218);
public Randomizer(int[] initKey) {
this(19650218);
int len = initKey.length;
int i = 1;
int j = 0;
@@ -111,20 +78,16 @@ private void initByArray(int[] initKey) {
state[0] = 0x80000000;
}

private void nextState() {
int p = 0;

left = N;

for (int j = N - M + 1; --j > 0; p++) {
state[p] = state[p + M] ^ TWIST(state[p + 0], state[p + 1]);
}

for (int j = M; --j > 0; p++) {
state[p] = state[p + M - N] ^ TWIST(state[p + 0], state[p + 1]);
public static Randomizer randomFromLong(long seed) {
long v = Math.abs(seed);
if (v == (v & 0xffffffffL)) {
return new Randomizer((int) v);
} else {
int[] ints = new int[2];
ints[0] = (int) v;
ints[1] = (int) (v >> 32);
return new Randomizer(ints);
}

state[p] = state[p + M - N] ^ TWIST(state[p + 0], state[0]);
}

public int genrandInt32() {
@@ -146,24 +109,29 @@ public int genrandInt32() {
return y;
}

public int[] getState() {
return state;
private void nextState() {
int p = 0;

left = N;

for (int j = N - M + 1; --j > 0; p++) {
state[p] = state[p + M] ^ twist(state[p + 0], state[p + 1]);
}

for (int j = M; --j > 0; p++) {
state[p] = state[p + M - N] ^ twist(state[p + 0], state[p + 1]);
}

state[p] = state[p + M - N] ^ twist(state[p + 0], state[0]);
}

public int getLeft() {
return left;
private static int mixbits(int u, int v) {
return (u & UMASK) | (v & LMASK);
}

public static Random randomFromLong(long seed) {
long v = Math.abs(seed);
if (v == (v & 0xffffffffL)) {
return new Random((int) v);
} else {
int[] ints = new int[2];
ints[0] = (int) v;
ints[1] = (int) (v >> 32);
return new Random(ints);
}
private static int twist(int u, int v) {
return (mixbits(u, v) >>> 1) ^ (((v & 1) != 0) ? MATRIX_A : 0);
}


}
37 changes: 28 additions & 9 deletions truffle/src/main/java/org/jruby/truffle/algorithms/SipHash.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
/***** BEGIN LICENSE BLOCK *****
* Version: EPL 1.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Eclipse Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.eclipse.org/legal/epl-v10.html
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Written by nahi@ruby-lang.org
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the EPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the EPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****/
package org.jruby.truffle.algorithms;

import java.nio.ByteBuffer;

/**
* SipHash implementation with hand inlining the SIPROUND.
*
* To know details about SipHash, see;
* "a fast short-input PRF" https://www.131002.net/siphash/
*
* @author nahi@ruby-lang.org
*/
public class SipHash {

public static long hash24(long k0, long k1, byte[] data) {
return hash24(k0, k1, data, 0, data.length);
}

public static long hash24(long k0, long k1, byte[] src, int offset, int length) {
private static long hash24(long k0, long k1, byte[] src, int offset, int length) {
long v0 = 0x736f6d6570736575L ^ k0;
long v1 = 0x646f72616e646f6dL ^ k1;
long v2 = 0x6c7967656e657261L ^ k0;
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.datastructures;
package org.jruby.truffle.collections;

import com.oracle.truffle.api.CompilerDirectives;

Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.datastructures;
package org.jruby.truffle.collections;

import com.oracle.truffle.api.CompilerDirectives;

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jruby.truffle.datastructures;
package org.jruby.truffle.collections;

import java.util.AbstractCollection;
import java.util.AbstractSet;
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.datastructures;
package org.jruby.truffle.collections;

public class Memo<T> {

Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the EPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****/
package org.jruby.truffle.datastructures;
package org.jruby.truffle.collections;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
import org.jruby.truffle.builtins.CoreClass;
import org.jruby.truffle.builtins.CoreMethod;
import org.jruby.truffle.builtins.CoreMethodArrayArgumentsNode;
import org.jruby.truffle.datastructures.Memo;
import org.jruby.truffle.collections.Memo;

@CoreClass("Truffle::Binding")
public abstract class TruffleBindingNodes {
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.string.StringUtils;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.datastructures.BoundaryIterable;
import org.jruby.truffle.collections.BoundaryIterable;

import java.util.Collections;
import java.util.Iterator;
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@
import org.jruby.truffle.core.string.EncodingUtils;
import org.jruby.truffle.core.string.StringSupport;
import org.jruby.truffle.parser.ReOptions;
import org.jruby.truffle.datastructures.WeakValuedMap;
import org.jruby.truffle.collections.WeakValuedMap;

import java.nio.charset.StandardCharsets;
import java.util.Iterator;
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@
import org.jruby.truffle.core.string.StringSupport;
import org.jruby.truffle.core.string.StringUtils;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.datastructures.Memo;
import org.jruby.truffle.collections.Memo;

import java.nio.ByteBuffer;
import java.nio.charset.Charset;
Original file line number Diff line number Diff line change
@@ -12,8 +12,8 @@
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.object.DynamicObjectFactory;
import com.oracle.truffle.api.object.dsl.Layout;
import org.jruby.truffle.algorithms.Randomizer;
import org.jruby.truffle.core.basicobject.BasicObjectLayout;
import org.jruby.truffle.algorithms.Random;

@Layout
public interface RandomizerLayout extends BasicObjectLayout {
@@ -22,9 +22,9 @@ DynamicObjectFactory createRandomizerShape(DynamicObject logicalClass,
DynamicObject metaClass);

DynamicObject createRandomizer(DynamicObjectFactory factory,
Random random);
Randomizer randomizer);

Random getRandom(DynamicObject object);
void setRandom(DynamicObject object, Random value);
Randomizer getRandomizer(DynamicObject object);
void setRandomizer(DynamicObject object, Randomizer value);

}
Loading