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

Commits on Feb 11, 2016

  1. Copy the full SHA
    f4d6315 View commit details
  2. Copy the full SHA
    4e9320f View commit details
  3. Copy the full SHA
    3900df6 View commit details
Showing with 178 additions and 225 deletions.
  1. +70 −115 truffle/src/main/java/org/jruby/truffle/RubyContext.java
  2. +5 −5 truffle/src/main/java/org/jruby/truffle/core/CoreLibrary.java
  3. +1 −1 truffle/src/main/java/org/jruby/truffle/core/LoadRequiredLibrariesNode.java
  4. +3 −3 truffle/src/main/java/org/jruby/truffle/core/ProcessNodes.java
  5. +1 −1 truffle/src/main/java/org/jruby/truffle/core/encoding/EncodingConverterNodes.java
  6. +9 −9 truffle/src/main/java/org/jruby/truffle/core/encoding/EncodingNodes.java
  7. +8 −7 truffle/src/main/java/org/jruby/truffle/core/kernel/KernelNodes.java
  8. +4 −4 truffle/src/main/java/org/jruby/truffle/core/regexp/InterpolatedRegexpNode.java
  9. +4 −4 truffle/src/main/java/org/jruby/truffle/core/regexp/RegexpNodes.java
  10. +1 −1 truffle/src/main/java/org/jruby/truffle/core/rubinius/FixnumPrimitiveNodes.java
  11. +2 −2 truffle/src/main/java/org/jruby/truffle/core/rubinius/IOPrimitiveNodes.java
  12. +2 −2 truffle/src/main/java/org/jruby/truffle/core/rubinius/PosixNodes.java
  13. +1 −1 truffle/src/main/java/org/jruby/truffle/core/rubinius/RandomizerPrimitiveNodes.java
  14. +1 −1 truffle/src/main/java/org/jruby/truffle/core/rubinius/RegexpPrimitiveNodes.java
  15. +2 −2 truffle/src/main/java/org/jruby/truffle/core/rubinius/StringPrimitiveNodes.java
  16. +1 −1 truffle/src/main/java/org/jruby/truffle/core/rubinius/TimePrimitiveNodes.java
  17. +7 −7 truffle/src/main/java/org/jruby/truffle/core/rubinius/VMPrimitiveNodes.java
  18. +21 −21 truffle/src/main/java/org/jruby/truffle/core/string/StringNodes.java
  19. +2 −2 truffle/src/main/java/org/jruby/truffle/core/string/StringOperations.java
  20. +3 −3 truffle/src/main/java/org/jruby/truffle/extra/TrufflePrimitiveNodes.java
  21. +2 −2 truffle/src/main/java/org/jruby/truffle/language/RubyNode.java
  22. +1 −1 truffle/src/main/java/org/jruby/truffle/language/RubyObjectType.java
  23. +1 −1 truffle/src/main/java/org/jruby/truffle/language/Warnings.java
  24. +1 −1 truffle/src/main/java/org/jruby/truffle/language/exceptions/TopLevelRaiseHandler.java
  25. +1 −1 truffle/src/main/java/org/jruby/truffle/language/globals/UpdateVerbosityNode.java
  26. +2 −5 truffle/src/main/java/org/jruby/truffle/language/globals/WriteProgramNameNode.java
  27. +3 −3 truffle/src/main/java/org/jruby/truffle/language/loader/FeatureLoader.java
  28. +1 −1 truffle/src/main/java/org/jruby/truffle/language/loader/SourceLoader.java
  29. +3 −3 truffle/src/main/java/org/jruby/truffle/language/translator/BodyTranslator.java
  30. +3 −3 truffle/src/main/java/org/jruby/truffle/language/translator/TranslatorDriver.java
  31. +1 −1 truffle/src/main/java/org/jruby/truffle/platform/TrufflePOSIXHandler.java
  32. +8 −8 truffle/src/main/java/org/jruby/truffle/stdlib/BigDecimalNodes.java
  33. +1 −1 truffle/src/main/java/org/jruby/truffle/stdlib/psych/PsychEmitterNodes.java
  34. +2 −2 truffle/src/main/java/org/jruby/truffle/stdlib/psych/PsychParserNodes.java
185 changes: 70 additions & 115 deletions truffle/src/main/java/org/jruby/truffle/RubyContext.java
Original file line number Diff line number Diff line change
@@ -19,13 +19,10 @@
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.tools.CoverageTracker;
import jnr.ffi.LibraryLoader;
import jnr.posix.POSIX;
import org.jcodings.Encoding;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.Ruby;
import org.jruby.ext.ffi.Platform;
import org.jruby.ext.ffi.Platform.OS_TYPE;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.truffle.core.CoreLibrary;
@@ -57,7 +54,6 @@
import org.jruby.truffle.language.loader.SourceLoader;
import org.jruby.truffle.language.methods.DeclarationContext;
import org.jruby.truffle.language.methods.InternalMethod;
import org.jruby.truffle.language.objects.ObjectIDOperations;
import org.jruby.truffle.language.translator.TranslatorDriver;
import org.jruby.truffle.language.translator.TranslatorDriver.ParserContext;
import org.jruby.truffle.platform.*;
@@ -77,7 +73,6 @@
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicLong;

/**
* The global state of a running Ruby system.
@@ -86,7 +81,7 @@ public class RubyContext extends ExecutionContext {

private static volatile RubyContext latestInstance;

private final Ruby runtime;
private final Ruby jrubyRuntime;

private final Options options;

@@ -118,7 +113,7 @@ public class RubyContext extends ExecutionContext {

private org.jruby.ast.RootNode initialJRubyRootNode;

public RubyContext(Ruby runtime, TruffleLanguage.Env env) {
public RubyContext(Ruby jrubyRuntime, TruffleLanguage.Env env) {
options = new Options();

if (options.CALL_GRAPH) {
@@ -129,7 +124,7 @@ public RubyContext(Ruby runtime, TruffleLanguage.Env env) {

latestInstance = this;

assert runtime != null;
assert jrubyRuntime != null;
this.env = env;

compilerOptions = Truffle.getRuntime().createCompilerOptions();
@@ -163,7 +158,7 @@ public RubyContext(Ruby runtime, TruffleLanguage.Env env) {

safepointManager = new SafepointManager(this);

this.runtime = runtime;
this.jrubyRuntime = jrubyRuntime;

warnings = new Warnings(this);

@@ -198,75 +193,16 @@ public RubyContext(Ruby runtime, TruffleLanguage.Env env) {
attachmentsManager = new AttachmentsManager(this);
sourceCache = new SourceCache(new SourceLoader(this));

final PrintStream configStandardOut = runtime.getInstanceConfig().getOutput();
final PrintStream configStandardOut = jrubyRuntime.getInstanceConfig().getOutput();
debugStandardOut = (configStandardOut == System.out) ? null : configStandardOut;

initialize();
}

public boolean onGraal() {
return Truffle.getRuntime().getName().toLowerCase(Locale.ENGLISH).contains("graal");
}

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

assert block == null || RubyGuards.isRubyProc(block);

final InternalMethod method = ModuleOperations.lookupMethod(coreLibrary.getMetaClass(object), methodName);

if (method == null || method.isUndefined()) {
return null;
}

return method.getCallTarget().call(
RubyArguments.pack(null, null, method, DeclarationContext.METHOD, null, object, block, arguments));
}

/* For debugging in Java. */
public static Object debugEval(String code) {
CompilerAsserts.neverPartOfCompilation();
final FrameInstance currentFrameInstance = Truffle.getRuntime().getCurrentFrame();
final Frame currentFrame = currentFrameInstance.getFrame(FrameAccess.MATERIALIZE, true);
return getLatestInstance().inlineRubyHelper(null, currentFrame, code);
}

@TruffleBoundary
public Object inlineRubyHelper(Node currentNode, String expression, Object... arguments) {
return inlineRubyHelper(currentNode, Truffle.getRuntime().getCurrentFrame().getFrame(FrameAccess.MATERIALIZE, true), expression, arguments);
}

public Object inlineRubyHelper(Node currentNode, Frame frame, String expression, Object... arguments) {
final MaterializedFrame evalFrame = setupInlineRubyFrame(frame, arguments);
final DynamicObject binding = BindingNodes.createBinding(this, evalFrame);
return eval(ParserContext.INLINE, StringOperations.createByteList(expression), binding, true, "inline-ruby", currentNode);
}

private MaterializedFrame setupInlineRubyFrame(Frame frame, Object... arguments) {
CompilerDirectives.transferToInterpreter();
final MaterializedFrame evalFrame = Truffle.getRuntime().createMaterializedFrame(
RubyArguments.pack(null, null, RubyArguments.getMethod(frame.getArguments()), DeclarationContext.INSTANCE_EVAL, null, RubyArguments.getSelf(frame.getArguments()), null, new Object[]{}),
new FrameDescriptor(frame.getFrameDescriptor().getDefaultValue()));

if (arguments.length % 2 == 1) {
throw new UnsupportedOperationException("odd number of name-value pairs for arguments");
}

for (int n = 0; n < arguments.length; n += 2) {
evalFrame.setObject(evalFrame.getFrameDescriptor().findOrAddFrameSlot(arguments[n]), arguments[n + 1]);
}

return evalFrame;
}

private void initialize() {
// Give the core library manager a chance to tweak some of those methods

coreLibrary.initializeAfterMethodsAdded();

// Set program arguments

for (IRubyObject arg : ((org.jruby.RubyArray) runtime.getObject().getConstant("ARGV")).toJavaArray()) {
for (IRubyObject arg : ((org.jruby.RubyArray) this.jrubyRuntime.getObject().getConstant("ARGV")).toJavaArray()) {
assert arg != null;

ArrayOperations.append(coreLibrary.getArgv(), StringOperations.createString(this, StringOperations.encodeRope(arg.toString(), UTF8Encoding.INSTANCE)));
@@ -277,7 +213,7 @@ private void initialize() {
DynamicObject receiver = coreLibrary.getGlobalVariablesObject();
final DynamicObject loadPath = (DynamicObject) receiver.get("$:", coreLibrary.getNilObject());

for (IRubyObject path : ((org.jruby.RubyArray) runtime.getLoadService().getLoadPath()).toJavaArray()) {
for (IRubyObject path : ((org.jruby.RubyArray) this.jrubyRuntime.getLoadService().getLoadPath()).toJavaArray()) {
String pathString = path.toString();

if (!(pathString.endsWith("lib/ruby/2.2/site_ruby")
@@ -294,7 +230,7 @@ private void initialize() {

// Load our own stdlib path

String home = runtime.getInstanceConfig().getJRubyHome();
String home = this.jrubyRuntime.getInstanceConfig().getJRubyHome();

if (home.startsWith("uri:classloader:")) {
home = home.substring("uri:classloader:".length());
@@ -326,6 +262,61 @@ private void initialize() {
ArrayOperations.append(loadPath, StringOperations.createString(this, StringOperations.encodeRope(home + "lib/ruby/truffle/shims", UTF8Encoding.INSTANCE)));
}

public boolean onGraal() {
return Truffle.getRuntime().getName().toLowerCase(Locale.ENGLISH).contains("graal");
}

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

assert block == null || RubyGuards.isRubyProc(block);

final InternalMethod method = ModuleOperations.lookupMethod(coreLibrary.getMetaClass(object), methodName);

if (method == null || method.isUndefined()) {
return null;
}

return method.getCallTarget().call(
RubyArguments.pack(null, null, method, DeclarationContext.METHOD, null, object, block, arguments));
}

/* For debugging in Java. */
public static Object debugEval(String code) {
CompilerAsserts.neverPartOfCompilation();
final FrameInstance currentFrameInstance = Truffle.getRuntime().getCurrentFrame();
final Frame currentFrame = currentFrameInstance.getFrame(FrameAccess.MATERIALIZE, true);
return getLatestInstance().inlineRubyHelper(null, currentFrame, code);
}

@TruffleBoundary
public Object inlineRubyHelper(Node currentNode, String expression, Object... arguments) {
return inlineRubyHelper(currentNode, Truffle.getRuntime().getCurrentFrame().getFrame(FrameAccess.MATERIALIZE, true), expression, arguments);
}

public Object inlineRubyHelper(Node currentNode, Frame frame, String expression, Object... arguments) {
final MaterializedFrame evalFrame = setupInlineRubyFrame(frame, arguments);
final DynamicObject binding = BindingNodes.createBinding(this, evalFrame);
return eval(ParserContext.INLINE, StringOperations.createByteList(expression), binding, true, "inline-ruby", currentNode);
}

private MaterializedFrame setupInlineRubyFrame(Frame frame, Object... arguments) {
CompilerDirectives.transferToInterpreter();
final MaterializedFrame evalFrame = Truffle.getRuntime().createMaterializedFrame(
RubyArguments.pack(null, null, RubyArguments.getMethod(frame.getArguments()), DeclarationContext.INSTANCE_EVAL, null, RubyArguments.getSelf(frame.getArguments()), null, new Object[]{}),
new FrameDescriptor(frame.getFrameDescriptor().getDefaultValue()));

if (arguments.length % 2 == 1) {
throw new UnsupportedOperationException("odd number of name-value pairs for arguments");
}

for (int n = 0; n < arguments.length; n += 2) {
evalFrame.setObject(evalFrame.getFrameDescriptor().findOrAddFrameSlot(arguments[n]), arguments[n + 1]);
}

return evalFrame;
}

// TODO (eregon, 10/10/2015): this check could be done when a Symbol is created to be much cheaper
public static String checkInstanceVariableName(RubyContext context, String name, Node currentNode) {
// if (!IdUtil.isValidInstanceVariableName(name)) {
@@ -347,10 +338,6 @@ public static String checkClassVariableName(RubyContext context, String name, No
}

public void loadFile(String fileName, Node currentNode) throws IOException {
loadFileAbsolute(fileName, currentNode);
}

private void loadFileAbsolute(String fileName, Node currentNode) throws IOException {
final Source source = sourceCache.getSource(fileName);
load(source, currentNode);
}
@@ -434,13 +421,13 @@ public Object makeTuple(VirtualFrame frame, CallDispatchHeadNode newTupleNode, O
@TruffleBoundary
public IRubyObject toJRuby(Object object) {
if (object == getCoreLibrary().getNilObject()) {
return runtime.getNil();
return jrubyRuntime.getNil();
} else if (object instanceof Boolean) {
return runtime.newBoolean((boolean) object);
return jrubyRuntime.newBoolean((boolean) object);
} else if (RubyGuards.isRubyString(object)) {
return toJRubyString((DynamicObject) object);
} else if (RubyGuards.isRubyEncoding(object)) {
return runtime.getEncodingService().rubyEncodingFromObject(runtime.newString(Layouts.ENCODING.getName((DynamicObject) object)));
return jrubyRuntime.getEncodingService().rubyEncodingFromObject(jrubyRuntime.newString(Layouts.ENCODING.getName((DynamicObject) object)));
} else {
throw new UnsupportedOperationException();
}
@@ -449,7 +436,7 @@ public IRubyObject toJRuby(Object object) {
@TruffleBoundary
public org.jruby.RubyString toJRubyString(DynamicObject string) {
assert RubyGuards.isRubyString(string);
return runtime.newString(StringOperations.rope(string).toByteListCopy());
return jrubyRuntime.newString(StringOperations.rope(string).toByteListCopy());
}

@TruffleBoundary
@@ -486,8 +473,8 @@ public DynamicObject toTruffle(org.jruby.RubyException jrubyException, RubyNode
throw new UnsupportedOperationException();
}

public Ruby getRuntime() {
return runtime;
public Ruby getJRubyRuntime() {
return jrubyRuntime;
}

public CoreLibrary getCoreLibrary() {
@@ -522,10 +509,6 @@ public SafepointManager getSafepointManager() {
return safepointManager;
}

public ThreadLocalRandom getRandom() {
return ThreadLocalRandom.current();
}

public LexicalScope getRootLexicalScope() {
return rootLexicalScope;
}
@@ -554,24 +537,8 @@ public SourceCache getSourceCache() {
return sourceCache;
}

public RubiniusConfiguration getRubiniusConfiguration() {
return getNativePlatform().getRubiniusConfiguration();
}

public POSIX getPosix() {
return getNativePlatform().getPosix();
}

public Sockets getNativeSockets() {
return getNativePlatform().getSockets();
}

public ClockGetTime getLibCClockGetTime() {
return getNativePlatform().getClockGetTime();
}

public Object execute(final org.jruby.ast.RootNode rootNode) {
coreLibrary.getGlobalVariablesObject().define("$0", toTruffle(runtime.getGlobalVariables().get("$0")), 0);
coreLibrary.getGlobalVariablesObject().define("$0", toTruffle(jrubyRuntime.getGlobalVariables().get("$0")), 0);

String inputFile = rootNode.getPosition().getFile();
final Source source;
@@ -606,10 +573,6 @@ public Object execute(final org.jruby.ast.RootNode rootNode) {
return execute(ParserContext.TOP_LEVEL, DeclarationContext.TOP_LEVEL, newRootNode, null, coreLibrary.getMainObject());
}

public DynamicObject runAtExitHooks() {
return atExitManager.runAtExitHooks();
}

public void shutdown() {
atExitManager.runSystemExitHooks();

@@ -678,10 +641,6 @@ public NativePlatform getNativePlatform() {
return nativePlatform;
}

public ProcessName getProcessName() {
return getNativePlatform().getProcessName();
}

public static void appendToFile(String fileName, String message) {
try (PrintStream stream = new PrintStream(new FileOutputStream(fileName, true), true, StandardCharsets.UTF_8.name())) {
stream.println(message);
@@ -694,8 +653,4 @@ public CallGraph getCallGraph() {
return callGraph;
}

public SignalManager getSignalManager() {
return getNativePlatform().getSignalManager();
}

}
10 changes: 5 additions & 5 deletions truffle/src/main/java/org/jruby/truffle/core/CoreLibrary.java
Original file line number Diff line number Diff line change
@@ -641,11 +641,11 @@ private void initializeGlobalVariables() {
globals.define("$\"", globals.get("$LOADED_FEATURES", nilObject), 0);
globals.define("$,", nilObject, 0);
globals.define("$*", argv, 0);
globals.define("$0", StringOperations.createString(context, StringOperations.encodeRope(context.getRuntime().getInstanceConfig().displayedFileName(), UTF8Encoding.INSTANCE)), 0);
globals.define("$0", StringOperations.createString(context, StringOperations.encodeRope(context.getJRubyRuntime().getInstanceConfig().displayedFileName(), UTF8Encoding.INSTANCE)), 0);

globals.define("$DEBUG", context.getRuntime().isDebug(), 0);
globals.define("$DEBUG", context.getJRubyRuntime().isDebug(), 0);

Object value = context.getRuntime().warningsEnabled() ? context.getRuntime().isVerbose() : nilObject;
Object value = context.getJRubyRuntime().warningsEnabled() ? context.getJRubyRuntime().isVerbose() : nilObject;
globals.define("$VERBOSE", value, 0);

final DynamicObject defaultRecordSeparator = StringOperations.createString(context, StringOperations.encodeRope(CLI_RECORD_SEPARATOR, UTF8Encoding.INSTANCE));
@@ -797,7 +797,7 @@ private void initializeRubiniusFFI() {
}

public void initializeEncodingConstants() {
getContext().getRuntime().getEncodingService().defineEncodings(new EncodingService.EncodingDefinitionVisitor() {
getContext().getJRubyRuntime().getEncodingService().defineEncodings(new EncodingService.EncodingDefinitionVisitor() {
@Override
public void defineEncoding(EncodingDB.Entry encodingEntry, byte[] name, int p, int end) {
DynamicObject re = EncodingNodes.newEncoding(encodingClass, null, name, p, end, encodingEntry.isDummy());
@@ -810,7 +810,7 @@ public void defineConstant(int encodingListIndex, String constName) {
}
});

getContext().getRuntime().getEncodingService().defineAliases(new EncodingService.EncodingAliasVisitor() {
getContext().getJRubyRuntime().getEncodingService().defineAliases(new EncodingService.EncodingAliasVisitor() {
@Override
public void defineAlias(int encodingListIndex, String constName) {
DynamicObject re = EncodingNodes.getEncoding(encodingListIndex);
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().getRuntime().getInstanceConfig().getRequiredLibraries();
return getContext().getJRubyRuntime().getInstanceConfig().getRequiredLibraries();
}

}
Loading