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

Commits on Aug 19, 2015

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f349a2f View commit details
  2. Copy the full SHA
    eed64b7 View commit details
  3. Copy the full SHA
    6236e4e View commit details
  4. Copy the full SHA
    1becd15 View commit details
  5. Copy the full SHA
    1c8c9b1 View commit details

Commits on Aug 20, 2015

  1. [Truffle] Tidy up.

    chrisseaton committed Aug 20, 2015
    Copy the full SHA
    4938928 View commit details
4 changes: 3 additions & 1 deletion core/src/main/java/org/jruby/parser/ParserSupport.java
Original file line number Diff line number Diff line change
@@ -1362,7 +1362,9 @@ public String internalId() {
return "";
}

private static final String TRUFFLE_CORE_LOAD_PATH = Options.TRUFFLE_CORE_LOAD_PATH.load();

public static boolean skipTruffleRubiniusWarnings(RubyLexer lexer) {
return lexer.getFile().startsWith("core:/");
return lexer.getFile().startsWith(TRUFFLE_CORE_LOAD_PATH);
}
}
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/util/cli/Options.java
Original file line number Diff line number Diff line change
@@ -125,6 +125,8 @@ public class Options {
public static final Option<Boolean> IR_WRITING_DEBUG = bool(IR, "ir.writing.debug", false, "Debug writing JRuby IR file.");
public static final Option<String> IR_INLINE_COMPILER_PASSES = string(IR, "ir.inline_passes", "Specify comma delimeted list of passes to run after inlining a method.");

public static final Option<String> TRUFFLE_CORE_LOAD_PATH = string(TRUFFLE, "truffle.core.load_path", "truffle:/", "Directory to load the Truffle core library from.");

public static final Option<Integer> TRUFFLE_DISPATCH_POLYMORPHIC_MAX = integer(TRUFFLE, "truffle.dispatch.polymorphic.max", 8, "Maximum size of a polymorphic call site cache.");
public static final Option<Integer> TRUFFLE_ARRAYS_UNINITIALIZED_SIZE = integer(TRUFFLE, "truffle.arrays.uninitialized_size", 32, "How large an array to allocate when we have no other information to go on.");
public static final Option<Integer> TRUFFLE_ARRAYS_SMALL = integer(TRUFFLE, "truffle.arrays.small", 3, "Maximum size of an Array to consider small for optimisations.");
2 changes: 2 additions & 0 deletions spec/truffle/tags/core/kernel/caller_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fails:Kernel#caller returns an Array of caller locations using a custom offset
fails:Kernel#caller returns the locations as String instances
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fails:Thread::Backtrace::Location#inspect converts the call frame to a String
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fails:Thread::Backtrace::Location#to_s converts the call frame to a String
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@
import org.jruby.truffle.runtime.core.MethodFilter;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.truffle.runtime.methods.InternalMethod;
import org.jruby.truffle.runtime.subsystems.FeatureManager;
import org.jruby.truffle.runtime.loader.FeatureLoader;
import org.jruby.truffle.runtime.subsystems.ThreadManager.BlockingAction;
import org.jruby.truffle.translator.NodeWrapper;
import org.jruby.truffle.translator.TranslatorDriver;
@@ -1167,15 +1167,8 @@ public boolean load(DynamicObject file, boolean wrap) {

try {
getContext().loadFile(file.toString(), this);
} catch (RuntimeException e) {
// TODO (nirvdrum 05-Feb-15) This is ugly, but checked exceptions are wrapped up the call stack. We need to revisit this.
if (e.getCause() instanceof java.io.IOException) {
CompilerDirectives.transferToInterpreter();

throw new RaiseException(getContext().getCoreLibrary().loadErrorCannotLoad(file.toString(), this));
} else {
throw e;
}
} catch (IOException e) {
throw new RaiseException(getContext().getCoreLibrary().loadErrorCannotLoad(file.toString(), this));
}

return true;
@@ -1546,7 +1539,7 @@ public boolean require(DynamicObject featureString) {
}

try {
getContext().getFeatureManager().require(feature, this);
getContext().getFeatureLoader().require(feature, this);
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -1565,16 +1558,16 @@ public RequireRelativeNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization(guards = "isRubyString(feature)")
public boolean requireRelative(DynamicObject feature) {
final FeatureManager featureManager = getContext().getFeatureManager();
final FeatureLoader featureLoader = getContext().getFeatureLoader();

final String featureString = feature.toString();
final String featurePath;

if (featureManager.isAbsolutePath(featureString)) {
if (featureLoader.isAbsolutePath(featureString)) {
featurePath = featureString;
} else {
final Source source = RubyCallStack.getCallerFrame(getContext()).getCallNode().getEncapsulatingSourceSection().getSource();
final String sourcePath = featureManager.getSourcePath(source);
final String sourcePath = featureLoader.getSourcePath(source);

if (sourcePath == null) {
CompilerDirectives.transferToInterpreter();
@@ -1585,7 +1578,7 @@ public boolean requireRelative(DynamicObject feature) {
}

try {
featureManager.require(featurePath, this);
featureLoader.require(featurePath, this);
} catch (IOException e) {
throw new RuntimeException(e);
}
90 changes: 49 additions & 41 deletions truffle/src/main/java/org/jruby/truffle/runtime/RubyContext.java
Original file line number Diff line number Diff line change
@@ -50,6 +50,9 @@
import org.jruby.truffle.runtime.core.CoreLibrary;
import org.jruby.truffle.runtime.core.SymbolTable;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.truffle.runtime.loader.FeatureLoader;
import org.jruby.truffle.runtime.loader.SourceCache;
import org.jruby.truffle.runtime.loader.SourceLoader;
import org.jruby.truffle.runtime.methods.InternalMethod;
import org.jruby.truffle.runtime.object.ObjectIDOperations;
import org.jruby.truffle.runtime.rubinius.RubiniusConfiguration;
@@ -61,6 +64,7 @@
import org.jruby.util.cli.Options;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
@@ -87,7 +91,7 @@ public class RubyContext extends ExecutionContext implements TruffleContextInter
private final NativeSockets nativeSockets;

private final CoreLibrary coreLibrary;
private final FeatureManager featureManager;
private final FeatureLoader featureLoader;
private final TraceManager traceManager;
private final ObjectSpaceManager objectSpaceManager;
private final ThreadManager threadManager;
@@ -101,7 +105,7 @@ public class RubyContext extends ExecutionContext implements TruffleContextInter
private final CoverageTracker coverageTracker;
private final InstrumentationServerManager instrumentationServerManager;
private final AttachmentsManager attachmentsManager;
private final SourceManager sourceManager;
private final SourceCache sourceCache;
private final RubiniusConfiguration rubiniusConfiguration;

private final AtomicLong nextObjectID = new AtomicLong(ObjectIDOperations.FIRST_OBJECT_ID);
@@ -156,7 +160,7 @@ public RubyContext(Ruby runtime) {
rootLexicalScope = new LexicalScope(null, coreLibrary.getObjectClass());
coreLibrary.initialize();

featureManager = new FeatureManager(this);
featureLoader = new FeatureLoader(this);
traceManager = new TraceManager();
atExitManager = new AtExitManager(this);

@@ -176,7 +180,7 @@ public RubyContext(Ruby runtime) {
runningOnWindows = Platform.getPlatform().getOS() == OS_TYPE.WINDOWS;

attachmentsManager = new AttachmentsManager(this);
sourceManager = new SourceManager(this);
sourceCache = new SourceCache(new SourceLoader(this));
rubiniusConfiguration = RubiniusConfiguration.create(this);

final PrintStream configStandardOut = runtime.getInstanceConfig().getOutput();
@@ -202,39 +206,53 @@ public void initialize() {
DynamicObject receiver = coreLibrary.getGlobalVariablesObject();
final DynamicObject loadPath = (DynamicObject) receiver.get("$:", Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(receiver)).getContext().getCoreLibrary().getNilObject());

final String home = runtime.getInstanceConfig().getJRubyHome();
for (IRubyObject path : ((org.jruby.RubyArray) runtime.getLoadService().getLoadPath()).toJavaArray()) {
String pathString = path.toString();

// We don't want JRuby's stdlib paths, but we do want any extra paths set by -I and things like that
if (!(pathString.endsWith("lib/ruby/2.2/site_ruby")
|| pathString.endsWith("lib/ruby/shared")
|| pathString.endsWith("lib/ruby/stdlib"))) {

final List<String> excludedLibPaths = new ArrayList<>();
excludedLibPaths.add(new File(home, "lib/ruby/2.2/site_ruby").toString().replace('\\', '/'));
excludedLibPaths.add(new File(home, "lib/ruby/shared").toString().replace('\\', '/'));
excludedLibPaths.add(new File(home, "lib/ruby/stdlib").toString().replace('\\', '/'));
if (pathString.startsWith("uri:classloader:")) {
pathString = SourceLoader.JRUBY_SCHEME + pathString.substring("uri:classloader:".length());
}

for (IRubyObject path : ((org.jruby.RubyArray) runtime.getLoadService().getLoadPath()).toJavaArray()) {
if (!excludedLibPaths.contains(path.toString())) {
ArrayNodes.slowPush(loadPath, StringNodes.createString(coreLibrary.getStringClass(), new File(path.toString()).getAbsolutePath()));
ArrayNodes.slowPush(loadPath, StringNodes.createString(coreLibrary.getStringClass(), pathString));
}
}

// Load our own stdlib path

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

if (home.startsWith("uri:classloader:")) {
home = home.substring("uri:classloader:".length());

while (home.startsWith("/")) {
home = home.substring(1);
}

home = SourceLoader.JRUBY_SCHEME + "/" + home;
}

home = home + "/";

// Libraries copied unmodified from MRI
ArrayNodes.slowPush(loadPath, StringNodes.createString(coreLibrary.getStringClass(), new File(home, "lib/ruby/truffle/mri").toString()));
ArrayNodes.slowPush(loadPath, StringNodes.createString(coreLibrary.getStringClass(), home + "lib/ruby/truffle/mri"));

// Our own implementations
ArrayNodes.slowPush(loadPath, StringNodes.createString(coreLibrary.getStringClass(), new File(home, "lib/ruby/truffle/truffle").toString()));
ArrayNodes.slowPush(loadPath, StringNodes.createString(coreLibrary.getStringClass(), home + "lib/ruby/truffle/truffle"));

// Libraries from RubySL
for (String lib : Arrays.asList("rubysl-strscan", "rubysl-stringio",
"rubysl-complex", "rubysl-date", "rubysl-pathname",
"rubysl-tempfile", "rubysl-socket", "rubysl-securerandom",
"rubysl-timeout", "rubysl-webrick")) {
ArrayNodes.slowPush(loadPath, StringNodes.createString(coreLibrary.getStringClass(), new File(home, "lib/ruby/truffle/rubysl/" + lib + "/lib").toString()));
ArrayNodes.slowPush(loadPath, StringNodes.createString(coreLibrary.getStringClass(), home + "lib/ruby/truffle/rubysl/" + lib + "/lib"));
}

// Shims
ArrayNodes.slowPush(loadPath, StringNodes.createString(coreLibrary.getStringClass(), new File(home, "lib/ruby/truffle/shims").toString()));
ArrayNodes.slowPush(loadPath, StringNodes.createString(coreLibrary.getStringClass(), home + "lib/ruby/truffle/shims"));
}

public static String checkInstanceVariableName(RubyContext context, String name, Node currentNode) {
@@ -257,16 +275,16 @@ public boolean isRunningOnWindows() {
return runningOnWindows;
}

public void loadFile(String fileName, Node currentNode) {
if (new File(fileName).isAbsolute()) {
public void loadFile(String fileName, Node currentNode) throws IOException {
if (new File(fileName).isAbsolute() || fileName.startsWith("jruby:") || fileName.startsWith("truffle:")) {
loadFileAbsolute(fileName, currentNode);
} else {
loadFileAbsolute(this.getRuntime().getCurrentDirectory() + File.separator + fileName, currentNode);
loadFileAbsolute(new File(this.getRuntime().getCurrentDirectory() + File.separator + fileName).getCanonicalPath(), currentNode);
}
}

private void loadFileAbsolute(String fileName, Node currentNode) {
final Source source = sourceManager.forFile(fileName);
private void loadFileAbsolute(String fileName, Node currentNode) throws IOException {
final Source source = sourceCache.getSource(fileName);
load(source, currentNode, NodeWrapper.IDENTITY);
}

@@ -315,15 +333,6 @@ public Object instanceEval(ByteList code, Object self, Node currentNode) {
return instanceEval(code, self, "(eval)", currentNode);
}

public Object eval(Source source) {
return execute(source, UTF8Encoding.INSTANCE, TranslatorDriver.ParserContext.EVAL, getCoreLibrary().getMainObject(), null, null, new NodeWrapper() {
@Override
public RubyNode wrap(RubyNode node) {
return new SetMethodDeclarationContext(node.getContext(), node.getSourceSection(), Visibility.PRIVATE, "simple eval", node);
}
});
}

@TruffleBoundary
public Object eval(String code, DynamicObject binding, boolean ownScopeForAssignments, String filename, Node currentNode) {
assert RubyGuards.isRubyBinding(binding);
@@ -528,8 +537,8 @@ public CoreLibrary getCoreLibrary() {
return coreLibrary;
}

public FeatureManager getFeatureManager() {
return featureManager;
public FeatureLoader getFeatureLoader() {
return featureLoader;
}

public ObjectSpaceManager getObjectSpaceManager() {
@@ -600,8 +609,8 @@ public AttachmentsManager getAttachmentsManager() {
return attachmentsManager;
}

public SourceManager getSourceManager() {
return sourceManager;
public SourceCache getSourceCache() {
return sourceCache;
}

public RubiniusConfiguration getRubiniusConfiguration() {
@@ -623,14 +632,13 @@ public Object execute(final org.jruby.ast.RootNode rootNode) {
final String inputFile = rootNode.getPosition().getFile();
final Source source;

if (inputFile.equals("-e")) {
// Assume UTF-8 for the moment
source = Source.fromText(new String(runtime.getInstanceConfig().inlineScript(), StandardCharsets.UTF_8), "-e");
} else {
source = sourceManager.forFile(inputFile);
try {
source = sourceCache.getSource(inputFile);
} catch (IOException e) {
throw new RuntimeException(e);
}

featureManager.setMainScriptSource(source);
featureLoader.setMainScriptSource(source);

load(source, null, new NodeWrapper() {
@Override
Original file line number Diff line number Diff line change
@@ -46,15 +46,16 @@
import org.jruby.truffle.runtime.control.TruffleFatalException;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.truffle.runtime.layouts.ThreadBacktraceLocationLayoutImpl;
import org.jruby.truffle.runtime.layouts.ThreadLayoutImpl;
import org.jruby.truffle.runtime.layouts.ext.DigestLayoutImpl;
import org.jruby.truffle.runtime.loader.SourceLoader;
import org.jruby.truffle.runtime.methods.InternalMethod;
import org.jruby.truffle.runtime.rubinius.RubiniusTypes;
import org.jruby.truffle.runtime.signal.SignalOperations;
import org.jruby.truffle.translator.NodeWrapper;
import org.jruby.util.cli.Options;
import org.jruby.util.cli.OutputStrings;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -64,6 +65,8 @@

public class CoreLibrary {

public static final String CORE_LOAD_PATH = getCoreLoadPath();

private static final String CLI_RECORD_SEPARATOR = Options.CLI_RECORD_SEPARATOR.load();

private final RubyContext context;
@@ -163,6 +166,24 @@ public class CoreLibrary {

@CompilationFinal private InternalMethod basicObjectSendMethod;

private static String getCoreLoadPath() {
String path = Options.TRUFFLE_CORE_LOAD_PATH.load();

while (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}

if (path.startsWith("truffle:")) {
return path;
}

try {
return new File(path).getCanonicalPath();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private enum State {
INITIALIZING,
LOADING_RUBY_CORE,
@@ -628,7 +649,11 @@ public void initializeAfterMethodsAdded() {

try {
state = State.LOADING_RUBY_CORE;
loadRubyCore("core.rb");
try {
context.load(context.getSourceCache().getSource(CoreLibrary.CORE_LOAD_PATH + "/core.rb"), node, NodeWrapper.IDENTITY);
} catch (IOException e) {
throw new RuntimeException(e);
}
} catch (RaiseException e) {
final Object rubyException = e.getRubyException();

@@ -665,10 +690,6 @@ private void initializeRubiniusFFI() {
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(node, "TYPE_VARARGS", RubiniusTypes.TYPE_VARARGS);
}

public void loadRubyCore(String fileName) {
loadRubyCore(fileName, "core:/");
}

public void loadRubyCore(String fileName, String prefix) {
final Source source;

Loading