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

Commits on May 14, 2015

  1. [Truffle] Set the logicalClass of class Class more cleanly.

    * So we need less unsafeSet* calls.
    * Also use the given name when we have no lexicalParent.
    eregon committed May 14, 2015
    Copy the full SHA
    f76b3fc View commit details
  2. Copy the full SHA
    f9fd23c View commit details
  3. [Truffle] Make a node to load required libraries with -r.

    * So we can make a proper call and backtrace.
    eregon committed May 14, 2015
    Copy the full SHA
    99bcc89 View commit details
8 changes: 5 additions & 3 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -930,16 +930,18 @@ private TruffleContextInterface loadTruffleContext() {
throw new RuntimeException("Truffle backend not available", e);
}

final TruffleContextInterface truffleBridge;
final TruffleContextInterface truffleContext;

try {
Constructor<?> con = clazz.getConstructor(Ruby.class);
truffleBridge = (TruffleContextInterface) con.newInstance(this);
truffleContext = (TruffleContextInterface) con.newInstance(this);
} catch (Exception e) {
throw new RuntimeException("Error while calling the constructor of Truffle's RubyContext", e);
}

return truffleBridge;
truffleContext.initialize();

return truffleContext;
}

public void shutdownTruffleContextIfRunning() {
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/TruffleContextInterface.java
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@ enum BacktraceFormatter {
IMPL_DEBUG
}

void initialize();

Object execute(org.jruby.ast.RootNode rootNode);

void shutdown();
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 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
*/
package org.jruby.truffle.nodes.core;

import java.util.Collection;

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;

/** Load libraries required from the command line (-r LIBRARY) */
public class LoadRequiredLibrariesNode extends RubyNode {

@Child CallDispatchHeadNode requireNode;

public LoadRequiredLibrariesNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
requireNode = DispatchHeadNodeFactory.createMethodCallOnSelf(context);
}

@Override
public Object execute(VirtualFrame frame) {
Object self = RubyArguments.getSelf(frame.getArguments());
Collection<String> requiredLibraries = getContext().getRuntime().getInstanceConfig().getRequiredLibraries();

for (String requiredLibrary : requiredLibraries) {
requireNode.call(frame, self, "require", null, getContext().makeString(requiredLibrary));
}

return nil();
}

}
32 changes: 12 additions & 20 deletions truffle/src/main/java/org/jruby/truffle/runtime/RubyContext.java
Original file line number Diff line number Diff line change
@@ -20,8 +20,10 @@
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.tools.CoverageTracker;

import jnr.posix.POSIX;
import jnr.posix.POSIXFactory;

import org.jcodings.Encoding;
import org.jcodings.specific.ASCIIEncoding;
import org.jcodings.specific.UTF8Encoding;
@@ -34,6 +36,7 @@
import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.nodes.control.SequenceNode;
import org.jruby.truffle.nodes.core.BignumNodes;
import org.jruby.truffle.nodes.core.LoadRequiredLibrariesNode;
import org.jruby.truffle.nodes.core.SetTopLevelBindingNode;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.exceptions.TopLevelRaiseHandler;
@@ -165,8 +168,11 @@ public RubyContext(Ruby runtime) {
rubiniusConfiguration = new RubiniusConfiguration(this);

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

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

coreLibrary.initializeAfterMethodsAdded();
@@ -215,22 +221,6 @@ public RubyContext(Ruby runtime) {

// Shims
loadPath.slowPush(makeString(new File(home, "lib/ruby/truffle/shims").toString()));

// Load libraries required from the command line (-r LIBRARY)
for (String requiredLibrary : runtime.getInstanceConfig().getRequiredLibraries()) {
try {
featureManager.require(requiredLibrary, null);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (RaiseException e) {
// Translate LoadErrors for JRuby since we're outside an ExceptionTranslatingNode.
if (e.getRubyException().getLogicalClass() == coreLibrary.getLoadErrorClass()) {
throw runtime.newLoadError(e.getRubyException().getMessage().toString(), requiredLibrary);
} else {
throw e;
}
}
}
}

public static String checkInstanceVariableName(RubyContext context, String name, Node currentNode) {
@@ -664,9 +654,11 @@ public Object execute(final org.jruby.ast.RootNode rootNode) {
public RubyNode wrap(RubyNode node) {
RubyContext context = node.getContext();
SourceSection sourceSection = node.getSourceSection();
return SequenceNode.sequence(context, sourceSection,
new SetTopLevelBindingNode(context, sourceSection),
new TopLevelRaiseHandler(context, sourceSection, node));
return new TopLevelRaiseHandler(context, sourceSection,
SequenceNode.sequence(context, sourceSection,
new SetTopLevelBindingNode(context, sourceSection),
new LoadRequiredLibrariesNode(context, sourceSection),
node));
}
});
return coreLibrary.getNilObject();
Original file line number Diff line number Diff line change
@@ -198,16 +198,12 @@ public CoreLibrary(RubyContext context) {

// Create the cyclic classes and modules

classClass = RubyClass.createBootClass(context, null, "Class", new RubyClass.ClassAllocator());
basicObjectClass = RubyClass.createBootClass(context, classClass, "BasicObject", new RubyBasicObject.BasicObjectAllocator());
objectClass = RubyClass.createBootClass(context, classClass, "Object", basicObjectClass.getAllocator());
moduleClass = RubyClass.createBootClass(context, classClass, "Module", new RubyModule.ModuleAllocator());
classClass = RubyClass.createClassClass(context, new RubyClass.ClassAllocator());
basicObjectClass = RubyClass.createBootClass(classClass, null, "BasicObject", new RubyBasicObject.BasicObjectAllocator());
objectClass = RubyClass.createBootClass(classClass, basicObjectClass, "Object", basicObjectClass.getAllocator());
moduleClass = RubyClass.createBootClass(classClass, objectClass, "Module", new RubyModule.ModuleAllocator());

// Close the cycles
classClass.unsafeSetLogicalClass(classClass);

objectClass.unsafeSetSuperclass(basicObjectClass);
moduleClass.unsafeSetSuperclass(objectClass);
classClass.unsafeSetSuperclass(moduleClass);

classClass.getAdoptedByLexicalParent(objectClass, "Class", node);
Original file line number Diff line number Diff line change
@@ -59,9 +59,10 @@ protected RubyBasicObject(RubyContext context, RubyClass rubyClass) {
private RubyBasicObject(RubyContext context, RubyClass rubyClass, DynamicObject dynamicObject) {
this.dynamicObject = dynamicObject;

if (rubyClass != null) {
unsafeSetLogicalClass(rubyClass);
if (rubyClass == null && this instanceof RubyClass) { // For class Class
rubyClass = (RubyClass) this;
}
unsafeSetLogicalClass(rubyClass);
}

protected void unsafeSetLogicalClass(RubyClass newLogicalClass) {
Original file line number Diff line number Diff line change
@@ -29,12 +29,17 @@ public class RubyClass extends RubyModule {
private final boolean isSingleton;
private final RubyModule attached;

/** Special constructor for class Class */
public static RubyClass createClassClass(RubyContext context, Allocator allocator) {
return new RubyClass(context, null, null, null, "Class", false, null, allocator);
}

/**
* This constructor supports initialization and solves boot-order problems and should not
* normally be used from outside this class.
*/
public static RubyClass createBootClass(RubyContext context, RubyClass classClass, String name, Allocator allocator) {
return new RubyClass(context, classClass, null, null, name, false, null, allocator);
public static RubyClass createBootClass(RubyClass classClass, RubyClass superclass, String name, Allocator allocator) {
return new RubyClass(classClass.getContext(), classClass, null, superclass, name, false, null, allocator);
}

public RubyClass(RubyContext context, RubyModule lexicalParent, RubyClass superclass, String name, Allocator allocator) {
Original file line number Diff line number Diff line change
@@ -112,7 +112,9 @@ protected RubyModule(RubyContext context, RubyClass selfClass, RubyModule lexica

unmodifiedAssumption = new CyclicAssumption(name + " is unmodified");

if (lexicalParent != null) {
if (lexicalParent == null) {
this.name = name;
} else {
getAdoptedByLexicalParent(lexicalParent, name, currentNode);
}
}
Original file line number Diff line number Diff line change
@@ -151,11 +151,10 @@ public RubyRootNode parse(Node currentNode, RubyContext context, Source source,
RubyNode truffleNode;

if (rootNode.getBodyNode() == null || rootNode.getBodyNode() instanceof org.jruby.ast.NilNode) {
translator.parentSourceSection.push(sharedMethodInfo.getSourceSection());

translator.parentSourceSection.push(sourceSection);
try {
truffleNode = new DefinedWrapperNode(context, null,
new ObjectLiteralNode(context, null, context.getCoreLibrary().getNilObject()),
truffleNode = new DefinedWrapperNode(context, sourceSection,
new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getNilObject()),
"nil");
} finally {
translator.parentSourceSection.pop();