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: 231392d84794
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ac1f28e5428d
Choose a head ref
  • 14 commits
  • 16 files changed
  • 1 contributor

Commits on Nov 5, 2016

  1. Copy the full SHA
    f1686ce View commit details
  2. Copy the full SHA
    d0b2d8a View commit details
  3. Copy the full SHA
    5fc2efc View commit details
  4. [Truffle] If you just need the instance configuration, get that from …

    …the context rather than interop.
    chrisseaton committed Nov 5, 2016
    Copy the full SHA
    47d5616 View commit details
  5. Copy the full SHA
    a6ddd16 View commit details
  6. Copy the full SHA
    af45352 View commit details
  7. Copy the full SHA
    d9c16cf View commit details
  8. Copy the full SHA
    bc75edd View commit details
  9. Copy the full SHA
    3a80d27 View commit details
  10. Copy the full SHA
    fac47c5 View commit details
  11. Copy the full SHA
    8d246bd View commit details
  12. Copy the full SHA
    8d286f3 View commit details
  13. Copy the full SHA
    e30e983 View commit details
  14. Copy the full SHA
    ac1f28e View commit details
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ public int execute(String path) {
"See https://github.com/jruby/jruby/wiki/Truffle-FAQ#how-do-i-get-jrubytruffle");
}

context.getJRubyInterop().setOriginalInputFile(path);
context.setOriginalInputFile(path);

return engine.eval(loadSource("Truffle::Boot.run_jruby_root", "run_jruby_root")).as(Integer.class);
}
58 changes: 54 additions & 4 deletions truffle/src/main/java/org/jruby/truffle/RubyContext.java
Original file line number Diff line number Diff line change
@@ -14,9 +14,11 @@
import com.oracle.truffle.api.ExecutionContext;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.TruffleLanguage;
import com.oracle.truffle.api.TruffleOptions;
import com.oracle.truffle.api.instrumentation.Instrumenter;
import com.oracle.truffle.api.object.DynamicObject;
import org.jruby.Ruby;
import org.jruby.RubyInstanceConfig;
import org.jruby.truffle.builtins.PrimitiveManager;
import org.jruby.truffle.core.CoreLibrary;
import org.jruby.truffle.core.CoreMethods;
@@ -40,6 +42,7 @@
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.SafepointManager;
import org.jruby.truffle.language.arguments.RubyArguments;
import org.jruby.truffle.language.control.JavaException;
import org.jruby.truffle.language.loader.CodeLoader;
import org.jruby.truffle.language.loader.FeatureLoader;
import org.jruby.truffle.language.loader.SourceCache;
@@ -54,15 +57,21 @@
import org.jruby.truffle.tools.callgraph.CallGraph;
import org.jruby.truffle.tools.callgraph.SimpleWriter;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.security.CodeSource;

public class RubyContext extends ExecutionContext {

private final TruffleLanguage.Env env;
private final Ruby jrubyRuntime;

private final RubyInstanceConfig instanceConfig;
private final String jrubyHome;
private String originalInputFile;

private final Options options = new Options();
private final RopeTable ropeTable = new RopeTable();
@@ -102,9 +111,10 @@ public class RubyContext extends ExecutionContext {

private String currentDirectory;

public RubyContext(Ruby jrubyRuntime, TruffleLanguage.Env env) {
this.jrubyRuntime = jrubyRuntime;
this.jrubyInterop = new JRubyInterop(this, jrubyRuntime);
public RubyContext(RubyInstanceConfig instanceConfig, Ruby jrubyRuntime, TruffleLanguage.Env env) {
this.instanceConfig = instanceConfig;
jrubyHome = findJRubyHome();
this.jrubyInterop = new JRubyInterop(jrubyRuntime);
this.env = env;
this.currentDirectory = System.getProperty("user.dir");

@@ -196,6 +206,31 @@ public RubyContext(Ruby jrubyRuntime, TruffleLanguage.Env env) {
}
}

private String findJRubyHome() {
if (!TruffleOptions.AOT && System.getenv("JRUBY_HOME") == null && System.getProperty("jruby.home") == null) {
// Set JRuby home automatically for GraalVM
final CodeSource codeSource = Ruby.class.getProtectionDomain().getCodeSource();
if (codeSource != null) {
final File currentJarFile;
try {
currentJarFile = new File(codeSource.getLocation().toURI());
} catch (URISyntaxException e) {
throw new JavaException(e);
}

if (currentJarFile.getName().equals("ruby.jar")) {
String jarDir = currentJarFile.getParent();
if (new File(jarDir, "lib").isDirectory()) {
instanceConfig.setJRubyHome(jarDir);
return jarDir;
}
}
}
}

return instanceConfig.getJRubyHome();
}

public Object send(Object object, String methodName, DynamicObject block, Object... arguments) {
CompilerAsserts.neverPartOfCompilation();

@@ -385,4 +420,19 @@ public void setCurrentDirectory(String currentDirectory) {
this.currentDirectory = currentDirectory;
}

public RubyInstanceConfig getInstanceConfig() {
return instanceConfig;
}

public void setOriginalInputFile(String originalInputFile) {
this.originalInputFile = originalInputFile;
}

public String getOriginalInputFile() {
return originalInputFile;
}

public String getJRubyHome() {
return jrubyHome;
}
}
12 changes: 7 additions & 5 deletions truffle/src/main/java/org/jruby/truffle/RubyLanguage.java
Original file line number Diff line number Diff line change
@@ -60,18 +60,20 @@ private RubyLanguage() {
public RubyContext createContext(Env env) {
final JRubyContextWrapper runtimeWrapper = (JRubyContextWrapper) env.importSymbol(JRubyTruffleImpl.RUNTIME_SYMBOL);

final RubyInstanceConfig instanceConfig;
final Ruby runtime;

if (runtimeWrapper == null) {
RubyInstanceConfig config = new RubyInstanceConfig();
config.processArgumentsWithRubyopts();
config.setCompileMode(RubyInstanceConfig.CompileMode.TRUFFLE);
runtime = Ruby.newInstance(config);
instanceConfig = new RubyInstanceConfig();
instanceConfig.processArgumentsWithRubyopts();
instanceConfig.setCompileMode(RubyInstanceConfig.CompileMode.TRUFFLE);
runtime = Ruby.newInstance(instanceConfig);
} else {
runtime = runtimeWrapper.getRuby();
instanceConfig = runtime.getInstanceConfig();
}

return new RubyContext(runtime, env);
return new RubyContext(instanceConfig, runtime, env);
}

@Override
6 changes: 3 additions & 3 deletions truffle/src/main/java/org/jruby/truffle/core/CoreLibrary.java
Original file line number Diff line number Diff line change
@@ -841,7 +841,7 @@ private void initializeGlobalVariables() {

globals.put("$,", nilObject);
globals.put("$*", argv);
globals.put("$0", StringOperations.createString(context, StringOperations.encodeRope(context.getJRubyInterop().getDisplayedFileName(), UTF8Encoding.INSTANCE)));
globals.put("$0", StringOperations.createString(context, StringOperations.encodeRope(context.getInstanceConfig().displayedFileName(), UTF8Encoding.INSTANCE)));

globals.put("$DEBUG", context.getJRubyInterop().isDebug());

@@ -1127,7 +1127,7 @@ public void initializeEncodingManager() {
initializeEncodingAliases();

// External should always have a value, but Encoding.external_encoding{,=} will lazily setup
final String externalEncodingName = getContext().getJRubyInterop().getExternalEncoding();
final String externalEncodingName = getContext().getInstanceConfig().getExternalEncoding();
if (externalEncodingName != null && !externalEncodingName.equals("")) {
final DynamicObject loadedEncoding = getContext().getEncodingManager().getRubyEncoding(externalEncodingName);
if (loadedEncoding == null) {
@@ -1140,7 +1140,7 @@ public void initializeEncodingManager() {
getContext().getEncodingManager().setDefaultExternalEncoding(getContext().getEncodingManager().getLocaleEncoding());
}

final String internalEncodingName = getContext().getJRubyInterop().getInternalEncoding();
final String internalEncodingName = getContext().getInstanceConfig().getInternalEncoding();
if (internalEncodingName != null && !internalEncodingName.equals("")) {
final DynamicObject rubyEncoding = getContext().getEncodingManager().getRubyEncoding(internalEncodingName);
if (rubyEncoding == null) {
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ public Object execute(VirtualFrame frame) {

@TruffleBoundary
private Collection<String> getRequiredLibraries() {
return getContext().getJRubyInterop().getRequiredLibraries();
return getContext().getInstanceConfig().getRequiredLibraries();
}

}
Original file line number Diff line number Diff line change
@@ -96,10 +96,7 @@ public DynamicObject defaultInternal(VirtualFrame frame, Object encoding) {
toStrNode = insert(ToStrNodeGen.create(getContext(), null, null));
}

final DynamicObject encodingName = toStrNode.executeToStr(frame, encoding);
getContext().getJRubyInterop().setDefaultInternalEncoding(EncodingOperations.getEncoding(getContext().getEncodingManager().getRubyEncoding(encodingName.toString())));

return encodingName;
return toStrNode.executeToStr(frame, encoding);
}

}
Original file line number Diff line number Diff line change
@@ -854,7 +854,7 @@ public abstract static class GetsNode extends CoreMethodArrayArgumentsNode {
@Specialization
public DynamicObject gets() {
// TODO(CS): having some trouble interacting with JRuby stdin - so using this hack
final InputStream in = getContext().getJRubyInterop().getInput();
final InputStream in = getContext().getInstanceConfig().getInput();

Encoding encoding = getContext().getEncodingManager().getDefaultExternalEncoding();

Original file line number Diff line number Diff line change
@@ -19,9 +19,10 @@
import org.jruby.truffle.builtins.PrimitiveArrayArgumentsNode;
import org.jruby.truffle.core.rope.CodeRange;
import org.jruby.truffle.core.rope.RopeOperations;
import org.jruby.util.Random;

import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Random;

public abstract class RandomizerPrimitiveNodes {

@@ -30,7 +31,7 @@ public static abstract class RandomizerAllocatePrimitiveNode extends PrimitiveAr

@Specialization
public DynamicObject randomizerAllocate() {
return Layouts.RANDOMIZER.createRandomizer(coreLibrary().getRandomizerFactory(), new Random());
return Layouts.RANDOMIZER.createRandomizer(coreLibrary().getRandomizerFactory(), new org.jruby.util.Random());
}

}
@@ -51,12 +52,12 @@ public DynamicObject randomizerSeed(DynamicObject randomizer, long seed) {
}

@TruffleBoundary
protected static Random randomFromBigInteger(BigInteger seed) {
protected static org.jruby.util.Random randomFromBigInteger(BigInteger seed) {
return RubyRandom.RandomType.randomFromBigInteger(seed);
}

@TruffleBoundary
protected static Random randomFromLong(long seed) {
protected static org.jruby.util.Random randomFromLong(long seed) {
return RubyRandom.RandomType.randomFromLong(seed);
}

@@ -68,7 +69,7 @@ public static abstract class RandomizerRandFloatPrimitiveNode extends PrimitiveA
@Specialization
public double randomizerRandFloat(DynamicObject randomizer) {
// Logic copied from org.jruby.util.Random
final Random r = Layouts.RANDOMIZER.getRandom(randomizer);
final org.jruby.util.Random r = Layouts.RANDOMIZER.getRandom(randomizer);
final int a = randomInt(r) >>> 5;
final int b = randomInt(r) >>> 6;
return (a * 67108864.0 + b) * (1.0 / 9007199254740992.0);
@@ -81,18 +82,18 @@ public static abstract class RandomizerRandIntPrimitiveNode extends PrimitiveArr

@Specialization
public int randomizerRandInt(DynamicObject randomizer, int limit) {
final Random r = Layouts.RANDOMIZER.getRandom(randomizer);
final org.jruby.util.Random r = Layouts.RANDOMIZER.getRandom(randomizer);
return (int) randInt(r, (long) limit);
}

@Specialization
public long randomizerRandInt(DynamicObject randomizer, long limit) {
final Random r = Layouts.RANDOMIZER.getRandom(randomizer);
final org.jruby.util.Random r = Layouts.RANDOMIZER.getRandom(randomizer);
return randInt(r, limit);
}

@TruffleBoundary
protected static long randInt(Random r, long limit) {
protected static long randInt(org.jruby.util.Random r, long limit) {
return RubyRandom.randLimitedFixnumInner(r, limit);
}

@@ -101,12 +102,31 @@ protected static long randInt(Random r, long limit) {
@Primitive(name = "randomizer_gen_seed")
public static abstract class RandomizerGenSeedPrimitiveNode extends PrimitiveArrayArgumentsNode {

// Single instance of Random per host VM

private static Random random;

@TruffleBoundary
@Specialization
public DynamicObject randomizerGenSeed(DynamicObject randomizerClass) {
final BigInteger seed = RubyRandom.randomSeedBigInteger(getContext().getJRubyInterop().getRandom());
final BigInteger seed = RubyRandom.randomSeedBigInteger(getRandom());
return createBignum(seed);
}

private Random getRandom() {
if (random == null) {
// We don't care about racing to create this

try {
random = new SecureRandom();
} catch (Throwable t) {
// TODO CS 5-Nov-16 should we warn about this?
random = new Random();
}
}

return random;
}
}

@Primitive(name = "randomizer_bytes", lowerFixnum = 1)
@@ -115,7 +135,7 @@ public static abstract class RandomizerBytesPrimitiveNode extends PrimitiveArray
@TruffleBoundary
@Specialization
public DynamicObject genRandBytes(DynamicObject randomizer, int length) {
final Random random = Layouts.RANDOMIZER.getRandom(randomizer);
final org.jruby.util.Random random = Layouts.RANDOMIZER.getRandom(randomizer);
final byte[] bytes = new byte[length];
int idx = 0;
for (; length >= 4; length -= 4) {
@@ -137,7 +157,7 @@ public DynamicObject genRandBytes(DynamicObject randomizer, int length) {
}

@TruffleBoundary
private static int randomInt(Random random) {
private static int randomInt(org.jruby.util.Random random) {
return random.genrandInt32();
}

Loading